Module: Yast::SoundComplexInclude

Defined in:
../../src/include/sound/complex.rb

Instance Method Summary (collapse)

Instance Method Details

- (Array) createHWTable

creates summary table with card labels and thier states (running/not running/dissappeared)

Returns:

  • (Array)

    table contents



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File '../../src/include/sound/complex.rb', line 47

def createHWTable
  Builtins.y2milestone("unconfigured_cards: %1", Sound.unconfigured_cards)
  Builtins.y2milestone("modules_conf: %1", Sound.modules_conf)

  ret = []

  if Sound.modules_conf != nil &&
      Ops.greater_than(Builtins.size(Sound.modules_conf), 0)
    Builtins.foreach(Sound.modules_conf) do |card|
      descr = []
      if Ops.get_string(card, ["options", "index"], "") != nil
        descr = Builtins.add(
          descr,
          Builtins.sformat(
            _("Configured as sound card number %1"),
            Ops.get_string(card, ["options", "index"], "")
          )
        )
      end
      if Ops.get(card, "module") != nil
        descr = Builtins.add(
          descr,
          Builtins.sformat(
            _("Driver %1"),
            Ops.get_string(card, "module", "")
          )
        )
      end
      pkgs = Sound.RequiredPackagesToInstallSummary(
        Ops.get_string(card, "module", "")
      )
      if Ops.greater_than(Builtins.size(pkgs), 0)
        descr = Builtins.add(descr, pkgs)
      end
      r = {
        "id"          => Ops.get_string(card, "unique_key", ""),
        "table_descr" => [
          Ops.get_string(card, ["options", "index"], ""),
          Ops.get_string(card, "model", "")
        ],
        "rich_descr"  => WizardHW.CreateRichTextDescription(
          Ops.get_string(card, "model", ""),
          descr
        )
      }
      ret = Builtins.add(ret, r)
    end
  end

  # sort the cards by index
  ret = Builtins.sort(ret) do |card1, card2|
    Ops.less_than(
      Builtins.tointeger(Ops.get_string(card1, ["table_descr", 0], "0")),
      Builtins.tointeger(Ops.get_string(card2, ["table_descr", 0], "0"))
    )
  end

  if Sound.unconfigured_cards != nil &&
      Ops.greater_than(Builtins.size(Sound.unconfigured_cards), 0)
    Builtins.foreach(Sound.unconfigured_cards) do |card|
      descr = []
      if Ops.get(card, "module") != nil
        descr = Builtins.add(
          descr,
          Builtins.sformat(
            _("Driver %1"),
            Ops.get_string(card, "module", "")
          )
        )
      end
      r = {
        "id"          => Ops.get_string(card, "unique_key", ""),
        "table_descr" => [
          _("Not configured"),
          Ops.get_string(card, "model", "")
        ],
        "rich_descr"  => WizardHW.CreateRichTextDescription(
          Ops.get_string(card, "model", ""),
          WizardHW.UnconfiguredDevice
        )
      }
      ret = Builtins.add(ret, r)
    end
  end

  Builtins.y2debug("table content: %1", ret)

  deep_copy(ret)
end

- (Object) Edit



293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
# File '../../src/include/sound/complex.rb', line 293

def Edit
  ret = nil
  idx_conf = getCardIndex2(
    Convert.convert(
      Sound.modules_conf,
      :from => "list <map>",
      :to   => "list <map <string, any>>"
    ),
    Sound.selected_uniq
  )
  idx_det = getCardIndex2(
    Convert.convert(
      Sound.unconfigured_cards,
      :from => "list <map>",
      :to   => "list <map <string, any>>"
    ),
    Sound.selected_uniq
  )

  Builtins.y2milestone(
    "uniq (%1) in configured: %2, in detected: %3",
    Sound.selected_uniq,
    idx_conf,
    idx_det
  )

  # the card is already configured
  if idx_conf != nil
    Builtins.y2milestone("reconfiguring card %1", Sound.selected_uniq)
    Sound.card_id = idx_conf
    ret = :edit_conf
  elsif idx_det != nil
    Builtins.y2milestone("adding new card %1", Sound.selected_uniq)
    Sound.card_id = idx_det
    ret = :edit_new
  else
    Builtins.y2error("card %1 was not found!", Sound.selected_uniq)
    ret = :not_found
  end

  ret
end

- (Object) EditConfigured



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# File '../../src/include/sound/complex.rb', line 215

def EditConfigured
  ret = nil
  idx_conf = getCardIndex(
    Convert.convert(
      Sound.modules_conf,
      :from => "list <map>",
      :to   => "list <map <string, any>>"
    ),
    Sound.selected_uniq
  )
  idx_list = getCardIndex2(
    Convert.convert(
      Sound.modules_conf,
      :from => "list <map>",
      :to   => "list <map <string, any>>"
    ),
    Sound.selected_uniq
  )

  # the card is already configured
  if idx_conf != nil && idx_list != nil
    Builtins.y2milestone("Configuring card %1", Sound.selected_uniq)
    entry = Ops.get(Sound.modules_conf, idx_list, {})
    oldentry = deep_copy(entry)
    begin
      res = sound_options(entry)
      if Ops.get(res, "ui") == :next
        entry = Ops.get_map(res, "return", {})
        entry = add_common_options(entry, idx_conf)

        # update card data
        Sound.modules_conf = Builtins.maplist(Sound.modules_conf) do |card|
          if Ops.get_string(card, "unique_key", "") != Sound.selected_uniq
            next deep_copy(card)
          else
            next deep_copy(entry)
          end
        end

        Builtins.y2milestone("updated config: %1", Sound.modules_conf)

        if oldentry != entry
          # popup question text
          if Popup.YesNo(
              _(
                "To apply changes, the sound system\n" +
                  "must be restarted.\n" +
                  "Restart sound system now?\n"
              )
            )
            Builtins.y2milestone("Restarting sound system...")
            sound_stop
            started = sound_start_tmp(true)
            Builtins.y2milestone("... restart done: %1", started)

            if !started
              Report.Error(
                _(
                  "Restart of the sound system has failed.\nCheck options of the driver.\n"
                )
              )
              ret = :again
              next
            end
          end
        end
        ret = :next
      elsif Ops.get(res, "ui") == :abort || Ops.get(res, "ui") == :cancel
        ret = :abort
      else
        ret = Ops.get_symbol(res, "ui")
      end
    end while ret == :again
  end

  ret
end

- (Object) enableButtons(val)

function for enabling relevant controls in complex dialog

Parameters:

  • val (Boolean)

    boolean enable/disable



174
175
176
177
178
179
180
# File '../../src/include/sound/complex.rb', line 174

def enableButtons(val)
  UI.ChangeWidget(Id(:b_delete), :Enabled, val)
  UI.ChangeWidget(Id(:b_options), :Enabled, val)
  UI.ChangeWidget(Id(:b_volume), :Enabled, val)

  nil
end

- (Object) getCardIndex(scards, uniq)



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File '../../src/include/sound/complex.rb', line 137

def getCardIndex(scards, uniq)
  scards = deep_copy(scards)
  ret = nil

  Builtins.foreach(scards) do |scard|
    if Ops.get(scard, "unique_key") == uniq
      if Ops.get(scard, ["options", "index"]) != nil
        ret = Builtins.tointeger(Ops.get(scard, ["options", "index"]))
      end
    end
  end if scards != nil

  Builtins.y2debug("found at index: %1", ret)

  ret
end

- (Object) getCardIndex2(scards, uniq)



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File '../../src/include/sound/complex.rb', line 154

def getCardIndex2(scards, uniq)
  scards = deep_copy(scards)
  ret = nil

  if scards != nil
    i = 0
    Builtins.foreach(scards) do |scard|
      ret = i if Ops.get(scard, "unique_key") == uniq
      i = Ops.add(i, 1)
    end
  end

  Builtins.y2debug("found at index: %1", ret)

  ret
end

- (Object) HardwareDialog

A dialog showing the detected cards and allowing to configure them.

Returns:

  • (Object)

    The value of the resulting UserInput.



484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
# File '../../src/include/sound/complex.rb', line 484

def HardwareDialog
  show_fonts = false
  Builtins.maplist(Sound.modules_conf) do |card|
    show_fonts = true if HasFonts(card)
  end

  extra_buttons = [
    # menu item
    [:mixer, _("&Volume...")],
    # menu item
    [:play_test, _("Play &Test Sound")],
    # menu item
    [:seq, _("&Start Sequencer")],
    # menu item
    [:primary, _("Set as the &Primary Card")],
    # menu item
    [:pulseaudio, _("PulseAudio &Configuration...")]
  ]

  if show_fonts
    # menu item, do not translate "SoundFont" term (see http://en.wikipedia.org/wiki/Sound_font)
    extra_buttons = Builtins.add(
      extra_buttons,
      [:fonts, _("&Install SoundFonts...")]
    )
  end

  # dialog title
  WizardHW.CreateHWDialog(
    _("Sound Configuration"),
    Ops.get_string(Sound.STRINGS, "ComplexDialog", ""),
    # table header
    [_("Index"), _("Card Model")],
    extra_buttons
  )

  Wizard.SetNextButton(:next, Label.OKButton)
  Wizard.SetAbortButton(:abort, Label.CancelButton)
  Wizard.HideBackButton if !Mode.installation

  ret = :_dummy
  begin
    SetItems()

    # initialize selected_card
    @selected_card = WizardHW.SelectedItem if @selected_card == ""

    # set previously selected card
    WizardHW.SetSelectedItem(@selected_card)

    ev = WizardHW.WaitForEvent
    Builtins.y2milestone("WaitForEvent: %1", ev)

    ui = Ops.get_symbol(ev, ["event", "ID"])

    # remember the selected card
    @selected_card = Ops.get_string(ev, "selected", "")

    if ui == :add
      ret = :add
    elsif ui == :cancel || ui == :abort
      if ReallyAbort()
        ret = :abort
        break
      else
        ui = :skip_event
      end
    elsif ui == :delete
      uniq = WizardHW.SelectedItem
      idx = getCardIndex2(
        Convert.convert(
          Sound.modules_conf,
          :from => "list <map>",
          :to   => "list <map <string, any>>"
        ),
        uniq
      )
      Builtins.y2milestone("Sound card index: %1", idx)

      if idx != nil
        Sound.card_id = idx
        ret = :delete
      end
    elsif ui == :edit
      Sound.selected_uniq = WizardHW.SelectedItem
      ret = :edit
    elsif ui == :mixer
      uniq = WizardHW.SelectedItem
      idx = getCardIndex(
        Convert.convert(
          Sound.modules_conf,
          :from => "list <map>",
          :to   => "list <map <string, any>>"
        ),
        uniq
      )

      if idx != nil
        Sound.card_id = idx
        ret = :mixer
      end
    elsif ui == :fonts
      InstallFonts("", true)
    elsif ui == :seq
      SequencerPopup()
    # configure the current card as primary
    elsif ui == :primary
      uniq = WizardHW.SelectedItem
      # sound card index
      idx = getCardIndex2(
        Convert.convert(
          Sound.modules_conf,
          :from => "list <map>",
          :to   => "list <map <string, any>>"
        ),
        uniq
      )
      # alsa index (snd-card-X)
      idx2 = getCardIndex(
        Convert.convert(
          Sound.modules_conf,
          :from => "list <map>",
          :to   => "list <map <string, any>>"
        ),
        uniq
      )

      if idx != nil && idx2 != 0
        # set the primary card
        SetPrimaryCard(idx, idx2)
      end
    elsif ui == :pulseaudio
      PulseAudioPopup()
    elsif ui == :play_test
      uniq = WizardHW.SelectedItem
      # alsa index (snd-card-X)
      card_id = getCardIndex(
        Convert.convert(
          Sound.modules_conf,
          :from => "list <map>",
          :to   => "list <map <string, any>>"
        ),
        uniq
      )

      if card_id != nil && Ops.greater_or_equal(card_id, 0)
        Builtins.y2milestone("Playing test: card: %1", card_id)
        msg = PlayTest(card_id)

        Popup.Message(msg) if msg != ""
      else
        Builtins.y2warning("Invalid index '%1' for card: %2", card_id, uniq)
      end
    else
      ret = ui
    end
  end while !Builtins.contains(
    [:back, :abort, :next, :add, :edit, :delete, :mixer],
    ret
  )

  Wizard.RestoreNextButton
  Wizard.RestoreBackButton if !Mode.installation

  { "ui" => ret }
end

- (Object) initialize_sound_complex(include_target)



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File '../../src/include/sound/complex.rb', line 22

def initialize_sound_complex(include_target)
  Yast.import "UI"

  textdomain "sound"

  Yast.import "Wizard"
  Yast.import "Label"
  Yast.import "Popup"
  Yast.import "Mode"
  Yast.import "WizardHW"
  Yast.import "Report"
  Yast.import "PulseAudio"

  Yast.import "Sound"
  Yast.include include_target, "sound/mixer.rb"
  Yast.include include_target, "sound/options.rb"
  Yast.include include_target, "sound/volume.rb"
  Yast.include include_target, "sound/volume_routines.rb" # PlayTest()

  @selected_card = ""
end

- (Object) Mixer



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File '../../src/include/sound/complex.rb', line 192

def Mixer
  ret = nil
  res = {}

  if Mode.config
    dialog_result = VolumeDialog(
      Ops.get(Sound.modules_conf, Sound.card_id, {}),
      true,
      Sound.card_id
    )

    Ops.set(res, "ui", dialog_result)
  else
    res = mixerDialog(Sound.card_id)
  end

  ret = Ops.get_symbol(res, "ui")

  ret = :abort if ret == :cancel

  ret
end

- (Object) PulseAudioPopup



336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
# File '../../src/include/sound/complex.rb', line 336

def PulseAudioPopup
  if !Mode.config && PulseAudio.Enabled == nil
    Builtins.y2error(
      "PulseAudio status is nil - the setup script is missing?"
    )
    # error popup message
    Popup.Error(_("PulseAudio is not installed or cannot be configured."))
    return
  end

  dlg = HBox(
    HSpacing(1),
    VBox(
      VSpacing(0.5),
      # frame label
      Frame(
        _("PulseAudio Configuration"),
        VBox(
          VSpacing(0.5),
          Left(
            CheckBox(
              Id(:pulseaudio),
              # check box label
              _("&Enable PulseAudio Support"),
              PulseAudio.Enabled == true
            )
          ),
          VSpacing(0.5)
        )
      ),
      VSpacing(Opt(:vstretch), 1),
      ButtonBox(
        PushButton(Id(:ok), Opt(:default, :key_F10), Label.OKButton),
        PushButton(Id(:cancel), Opt(:key_F9), Label.CancelButton)
      ),
      VSpacing(0.5)
    ),
    HSpacing(1)
  )

  UI.OpenDialog(Opt(:decorated), dlg)

  ui = Convert.to_symbol(UI.UserInput)

  if ui == :ok
    # get the current value
    value = Convert.to_boolean(UI.QueryWidget(Id(:pulseaudio), :Value))

    # set the value
    PulseAudio.Enable(value)
  end

  UI.CloseDialog

  nil
end

- (Object) SequencerPopup



393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
# File '../../src/include/sound/complex.rb', line 393

def SequencerPopup
  dlg = HBox(
    HSpacing(1),
    VBox(
      VSpacing(0.5),
      # frame label
      Frame(
        _("Advanced Options"),
        VBox(
          VSpacing(0.5),
          Left(
            CheckBox(
              Id(:sequencer),
              # check box label
              _("&Start Sequencer (Load MIDI Drivers)"),
              Ops.get_string(Sound.rc_vars, "LOAD_ALSA_SEQ", "no") == "yes"
            )
          ),
          VSpacing(0.5)
        )
      ),
      VSpacing(Opt(:vstretch), 1),
      ButtonBox(
        PushButton(Id(:ok), Opt(:default, :key_F10), Label.OKButton),
        PushButton(Id(:cancel), Opt(:key_F9), Label.CancelButton)
      ),
      VSpacing(0.5)
    ),
    HSpacing(1)
  )

  UI.OpenDialog(Opt(:decorated), dlg)

  ui = Convert.to_symbol(UI.UserInput)

  if ui == :ok
    # get current value
    value = Convert.to_boolean(UI.QueryWidget(Id(:sequencer), :Value)) ? "yes" : "no"

    # set the value
    Sound.rc_vars = Builtins.add(Sound.rc_vars, "LOAD_ALSA_SEQ", value)
  end

  UI.CloseDialog

  nil
end

- (Object) SetItems



182
183
184
185
186
187
188
189
190
# File '../../src/include/sound/complex.rb', line 182

def SetItems
  # create description for WizardHW
  items = createHWTable
  Builtins.y2debug("items: %1", items)

  WizardHW.SetContents(items)

  nil
end

- (Object) SetPrimaryCard(card_index, alsa_index)

Configure the selected sound card as the primary (default) card.

Parameters:

  • card_index (Fixnum)

    index of the selected card in the internal structure

  • alsa_index (Fixnum)

    index of the selected card in ALSA



444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
# File '../../src/include/sound/complex.rb', line 444

def SetPrimaryCard(card_index, alsa_index)
  Builtins.y2milestone(
    "Setting card %1 (snd-card-%2) as the primary card",
    card_index,
    alsa_index
  )
  Builtins.y2debug("Before configuration: %1", Sound.modules_conf)

  index = 0
  Sound.modules_conf = Builtins.maplist(Sound.modules_conf) do |sound_card|
    # the new primary sound_card
    if index == card_index
      Ops.set(sound_card, ["options", "index"], "0")
      Ops.set(sound_card, "alias", "snd-card-0")
      Builtins.y2milestone("New primary card: %1", sound_card)
    # the old primary sound_card
    elsif Ops.get_string(sound_card, ["options", "index"], "") == "0"
      Ops.set(
        sound_card,
        ["options", "index"],
        Builtins.tostring(alsa_index)
      )
      Ops.set(
        sound_card,
        "alias",
        Builtins.sformat("snd-card-%1", alsa_index)
      )
      Builtins.y2milestone("Previous primary card: %1", sound_card)
    end
    index = Ops.add(index, 1)
    deep_copy(sound_card)
  end

  Builtins.y2debug("After configuration: %1", Sound.modules_conf)

  nil
end

- (Hash) sound_complex

just calls ComplexDialog

Returns:

  • (Hash)

    passed from ComplexDialog



657
658
659
660
661
662
663
# File '../../src/include/sound/complex.rb', line 657

def sound_complex
  to_delete = []
  config_mode = false

  HardwareDialog() 
  #    return ComplexDialog ();
end