Class: Yast::CWMClass

Inherits:
Module
  • Object
show all
Defined in:
../../src/modules/CWM.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) AdjustButtons(_next, back, abort, help)

Adjust the labels of the bottom buttons of the wizard sequencer

Parameters:

  • next (String)

    label of the “Next” button

  • back (String)

    string label of the “Back” button

  • abort (String)

    string label of the “Abort” button

  • help (String)

    string label of the additional “Help” button (if needed)



874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
# File '../../src/modules/CWM.rb', line 874

def AdjustButtons(_next, back, abort, help)
  # FIXME: there is no point in the help parameter, since we cannot hide the Help
  # button anyway, get rid of it, it's not used at all
  help = "" if UI.HasSpecialWidget(:Wizard)
  help = "" if help == nil
  _next = "" if _next == nil
  back = "" if back == nil
  abort = "" if abort == nil
  if _next != ""
    Wizard.SetNextButton(:next, _next)
  else
    Wizard.HideNextButton
  end

  if abort != ""
    Wizard.SetAbortButton(:abort, abort)
  else
    Wizard.HideAbortButton
  end

  if back != ""
    Wizard.SetBackButton(:back, back)
  else
    Wizard.HideBackButton
  end

  nil
end

- (Object) cleanupWidgets(widgets)

Cleanup after dialog was finished (independently on what event) global only because of testsuites

Parameters:

  • widgets (Array<Hash{String => Object>})

    list of maps represenging widgets



395
396
397
398
399
400
401
402
403
404
405
406
407
408
# File '../../src/modules/CWM.rb', line 395

def cleanupWidgets(widgets)
  widgets = deep_copy(widgets)
  Builtins.foreach(widgets) do |w|
    @processed_widget = deep_copy(w)
    toEval = Convert.convert(
      Ops.get(w, "clean_up"),
      :from => "any",
      :to   => "void (string)"
    )
    toEval.call(Ops.get_string(w, "_cwm_key", "")) if toEval != nil
  end

  nil
end

- (Array) CreateWidgets(names, source)

Read widgets with listed names

Parameters:

  • names (Array<String>)

    a list of strings/symbols names of widgets

  • source (Hash <String, Hash{String => Object>})

    a map containing the widgets

Returns:

  • (Array)

    of maps representing widgets



707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
# File '../../src/modules/CWM.rb', line 707

def CreateWidgets(names, source)
  names = deep_copy(names)
  source = deep_copy(source)
  ValidateMaps(source) # FIXME find better place
  ret = Builtins.maplist(names) do |w|
    m = Ops.get(source, w, {})
    # leave add here in order to make a copy of the structure
    # eval isn't usable because the map may contain terms, that can't
    # be evaluated here
    m = Builtins.add(m, "_cwm_key", w)
    deep_copy(m)
  end
  ret = Builtins.maplist(ret) { |w| prepareWidget(w) }
  deep_copy(ret)
end

- (Object) DisableButtons(buttons)

Disable given bottom buttons of the wizard sequencer



858
859
860
861
862
863
864
865
866
867
# File '../../src/modules/CWM.rb', line 858

def DisableButtons(buttons)
  buttons = deep_copy(buttons)
  Builtins.foreach(buttons) do |button|
    Wizard.DisableBackButton if button == "back_button"
    Wizard.DisableAbortButton if button == "abort_button"
    Wizard.DisableNextButton if button == "next_button"
  end

  nil
end

- (Object) GetLowestTimeout(widgets)



280
281
282
283
284
285
286
287
288
289
290
291
# File '../../src/modules/CWM.rb', line 280

def GetLowestTimeout(widgets)
  widgets = deep_copy(widgets)
  minimum = 0
  Builtins.foreach(widgets) do |w|
    timeout = Ops.get_integer(w, "ui_timeout", 0)
    if Ops.less_than(timeout, minimum) && Ops.greater_than(timeout, 0) ||
        minimum == 0
      minimum = timeout
    end
  end
  minimum
end

- (Hash) GetProcessedWidget

Return description map of currently processed widget

Returns:

  • (Hash)

    description map of currently processed widget



414
415
416
# File '../../src/modules/CWM.rb', line 414

def GetProcessedWidget
  deep_copy(@processed_widget)
end

- (Object) handleDebug

A hook to handle Alt-Ctrl-Shift-D



766
767
768
769
770
# File '../../src/modules/CWM.rb', line 766

def handleDebug
  Builtins.y2debug("Handling a debugging event")

  nil
end

- (Symbol) handleWidgets(widgets, event_descr)

Handle change of widget after event generated global only because of testsuites

Parameters:

  • widgets (Array<Hash{String => Object>})

    list of maps represenging widgets

  • event_descr (Hash)

    map event that occured

Returns:

  • (Symbol)

    modified action (sometimes may be needed) or nil



348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
# File '../../src/modules/CWM.rb', line 348

def handleWidgets(widgets, event_descr)
  widgets = deep_copy(widgets)
  event_descr = deep_copy(event_descr)
  ret = nil
  Builtins.foreach(widgets) do |w|
    if ret == nil
      @processed_widget = deep_copy(w)
      events = Ops.get_list(w, "handle_events", [])
      toEval = Convert.convert(
        Ops.get(w, "handle"),
        :from => "any",
        :to   => "symbol (string, map)"
      )
      if toEval != nil &&
          (events == [] ||
            Builtins.contains(events, Ops.get(event_descr, "ID")))
        ret = toEval.call(Ops.get_string(w, "_cwm_key", ""), event_descr)
      end
    end
  end
  ret
end

- (Object) InitNull(key)

Do-nothing replacement for a widget initialization function. Used for push buttons if all the other widgets have a fallback.

Parameters:

  • key (String)

    id of the widget



983
984
985
# File '../../src/modules/CWM.rb', line 983

def InitNull(key)
  nil
end

- (Object) initWidgets(widgets)

Set widgets according to internally stored settings global only because of testsuites

Parameters:

  • widgets (Array<Hash{String => Object>})

    list of maps representing widgets



318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
# File '../../src/modules/CWM.rb', line 318

def initWidgets(widgets)
  widgets = deep_copy(widgets)
  Builtins.foreach(widgets) do |w|
    # set initial properties
    valid_chars = Ops.get_string(w, "valid_chars")
    if valid_chars != nil
      UI.ChangeWidget(
        Id(Ops.get_string(w, "_cwm_key", "")),
        :ValidChars,
        valid_chars
      )
    end
    # set initial values
    @processed_widget = deep_copy(w)
    toEval = Convert.convert(
      Ops.get(w, "init"),
      :from => "any",
      :to   => "void (string)"
    )
    toEval.call(Ops.get_string(w, "_cwm_key", "")) if toEval != nil
  end

  nil
end

- (Object) main



35
36
37
38
39
40
41
42
43
44
45
46
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
# File '../../src/modules/CWM.rb', line 35

def main
  Yast.import "UI"
  textdomain "base"

  Yast.import "Label"
  Yast.import "Report"
  Yast.import "Wizard"

  # local variables

  # Widget that is being currently processed
  @processed_widget = {}

  # All widgets of the current dialog, in the correct order
  @current_dialog_widgets = []

  # stack of settings of nested calls of CWM
  @settings_stack = []

  # Handler to be called after validation of a dialog fails
  @validation_failed_handler = nil

  # UI containers, layout helpers that contain other widgets.  Used by
  # functions that recurse through "contents" to decide whether to go
  # deeper.
  @ContainerWidgets = [
    :Frame,
    :RadioButtonGroup,
    :VBox,
    :HBox,
    :MarginBox,
    :MinWidth,
    :MinHeight,
    :MinSize,
    :Left,
    :Right,
    :Top,
    :Bottom,
    :HCenter,
    :VCenter,
    :HVCenter,
    :HSquash,
    :VSquash,
    :HVSquash,
    :HWeight,
    :VWeight
  ]
end

- (Object) mergeFunctions(widgets, functions)

Add fallback functions to a widget global only because of testsuites

Parameters:

  • widgets (Array<Hash{String => Object>})

    a list of widget desctiption maps

  • functions (Hash)

    map of functions

Returns:

  • a list of modified widget description maps



297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
# File '../../src/modules/CWM.rb', line 297

def mergeFunctions(widgets, functions)
  widgets = deep_copy(widgets)
  functions = deep_copy(functions)
  functions = Builtins.filter(functions) { |k, v| Ops.is_string?(k) }
  fallback_functions = Convert.convert(
    functions,
    :from => "map",
    :to   => "map <string, any>"
  )
  Builtins.maplist(widgets) do |w|
    Convert.convert(
      Builtins.union(fallback_functions, w),
      :from => "map",
      :to   => "map <string, any>"
    )
  end
end

- (String) MergeHelps(widgets)

Merge helps from the widgets

Parameters:

  • widgets (Array<Hash{String => Object>})

    a list of widget description maps

Returns:

  • (String)

    merged helps of the widgets



727
728
729
730
731
732
# File '../../src/modules/CWM.rb', line 727

def MergeHelps(widgets)
  widgets = deep_copy(widgets)
  helps = Builtins.maplist(widgets) { |w| Ops.get_string(w, "help") }
  helps = Builtins.filter(helps) { |h| h != nil }
  Builtins.mergestring(helps, "\n")
end

- (Object) OkCancelBox

Create a term with OK and Cancel buttons placed horizontally

Returns:

  • the term (HBox)



420
421
422
423
424
425
426
427
428
429
430
431
432
433
# File '../../src/modules/CWM.rb', line 420

def OkCancelBox
  ButtonBox(
    PushButton(
      Id(:_tp_ok),
      Opt(:key_F10, :default, :okButton),
      Label.OKButton
    ),
    PushButton(
      Id(:_tp_cancel),
      Opt(:key_F9, :cancelButton),
      Label.CancelButton
    )
  )
end

- (Object) PopSettings

Pop the settings of the currently run dialog from the stack



97
98
99
100
101
102
103
104
# File '../../src/modules/CWM.rb', line 97

def PopSettings
  current_dialog = Ops.get(@settings_stack, 0, {})
  Ops.set(@settings_stack, 0, nil)
  @settings_stack = Builtins.filter(@settings_stack) { |e| e != nil }
  @current_dialog_widgets = Ops.get_list(current_dialog, "widgets", [])

  nil
end

- (Object) PrepareDialog(dialog, widgets)

Prepare the dialog, replace strings in the term with appropriate widgets

Parameters:

  • dialog (Yast::Term)

    term dialog containing strings

  • widgets (Array<Hash{String => Object>})

    list of widget description maps

Returns:

  • updated term ready to be used as a dialog



739
740
741
742
743
744
745
746
747
748
749
# File '../../src/modules/CWM.rb', line 739

def PrepareDialog(dialog, widgets)
  dialog = deep_copy(dialog)
  widgets = deep_copy(widgets)
  args = Builtins.size(dialog)
  return deep_copy(dialog) if args == 0
  m = Builtins.listmap(widgets) do |w|
    widget_key = Ops.get_string(w, "_cwm_key", "")
    { widget_key => w }
  end
  ProcessTerm(dialog, m)
end

- (Hash) prepareWidget(widget_descr)

Prepare a widget for usage

Parameters:

  • widget_descr (Hash{String => Object})

    map widget description map

Returns:

  • (Hash)

    modified widget description map



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
# File '../../src/modules/CWM.rb', line 492

def prepareWidget(widget_descr)
  widget_descr = deep_copy(widget_descr)
  w = deep_copy(widget_descr)
  widget = Ops.get_symbol(w, "widget", :inputfield)

  if Ops.get(w, "widget") == :empty
    Ops.set(w, "widget", VBox())
  elsif Ops.get(w, "widget") == :custom &&
      Ops.get(w, "custom_widget") != nil
    Ops.set(w, "widget", Ops.get_term(w, "custom_widget") { VSpacing(0) })
  elsif Ops.get(w, "widget") == :func
    toEval = Convert.convert(
      Ops.get(w, "widget_func"),
      :from => "any",
      :to   => "term ()"
    )
    if toEval != nil
      Ops.set(w, "widget", toEval.call)
    else
      Ops.set(w, "widget", VBox())
    end
  else
    id_term = Id(Ops.get_string(w, "_cwm_key", ""))
    opt_term = Opt()
    Builtins.foreach(Ops.get_list(w, "opt", [])) do |o|
      opt_term = Builtins.add(opt_term, o)
    end
    label = Ops.get_string(w, "label", Ops.get_string(w, "_cwm_key", ""))

    if widget == :inputfield || widget == :textentry
      # backward compatibility
      if !Builtins.contains(Builtins.argsof(opt_term), :hstretch)
        opt_term = Builtins.add(opt_term, :hstretch)
      end
      Ops.set(w, "widget", InputField(id_term, opt_term, label))
    elsif widget == :password
      Ops.set(w, "widget", Password(id_term, opt_term, label))
    elsif widget == :checkbox
      Ops.set(w, "widget", CheckBox(id_term, opt_term, label))
    elsif widget == :combobox
      Ops.set(
        w,
        "widget",
        ComboBox(
          id_term,
          opt_term,
          label,
          Builtins.maplist(Ops.get_list(w, "items", [])) do |i|
            Item(Id(Ops.get(i, 0, "")), Ops.get(i, 1, Ops.get(i, 0, "")))
          end
        )
      )
    elsif widget == :selection_box
      Ops.set(
        w,
        "widget",
        SelectionBox(
          id_term,
          opt_term,
          label,
          Builtins.maplist(Ops.get_list(w, "items", [])) do |i|
            Item(Id(Ops.get(i, 0, "")), Ops.get(i, 1, Ops.get(i, 0, "")))
          end
        )
      )
    elsif widget == :multi_selection_box
      Ops.set(
        w,
        "widget",
        MultiSelectionBox(
          id_term,
          opt_term,
          label,
          Builtins.maplist(Ops.get_list(w, "items", [])) do |i|
            Item(Id(Ops.get(i, 0, "")), Ops.get(i, 1, Ops.get(i, 0, "")))
          end
        )
      )
    elsif widget == :intfield
      min = Ops.get_integer(w, "minimum", 0)
      max = Ops.get_integer(w, "maximum", 2147483647)
      Ops.set(
        w,
        "widget",
        IntField(id_term, opt_term, label, min, max, min)
      )
    elsif widget == :radio_buttons
      hspacing = Ops.get_integer(w, "hspacing", 0)
      vspacing = Ops.get_integer(w, "vspacing", 0)
      buttons = VBox(VSpacing(vspacing))
      Builtins.foreach(Ops.get_list(w, "items", [])) do |i|
        buttons = Builtins.add(
          buttons,
          Left(
            RadioButton(
              Id(Ops.get(i, 0, "")),
              opt_term,
              Ops.get(i, 1, Ops.get(i, 0, ""))
            )
          )
        )
        buttons = Builtins.add(buttons, VSpacing(vspacing))
      end
      Ops.set(
        w,
        "widget",
        Frame(
          label,
          HBox(
            HSpacing(hspacing),
            RadioButtonGroup(id_term, buttons),
            HSpacing(hspacing)
          )
        )
      )
    elsif widget == :radio_button
      Ops.set(w, "widget", RadioButton(id_term, opt_term, label))
    elsif widget == :push_button
      Ops.set(w, "widget", PushButton(id_term, opt_term, label))
    elsif widget == :menu_button
      Ops.set(
        w,
        "widget",
        MenuButton(
          id_term,
          opt_term,
          label,
          Builtins.maplist(Ops.get_list(w, "items", [])) do |i|
            Item(Id(Ops.get(i, 0, "")), Ops.get(i, 1, Ops.get(i, 0, "")))
          end
        )
      )
    elsif widget == :multi_line_edit
      Ops.set(w, "widget", MultiLineEdit(id_term, opt_term, label))
    elsif widget == :richtext
      Ops.set(w, "widget", RichText(id_term, opt_term, ""))
    end
  end
  Ops.set(w, "custom_widget", nil) # not needed any more
  deep_copy(w)
end

- (Yast::Term) ProcessTerm(t, widgets)

Process term with the dialog, replace strings in the term with appropriate widgets

Parameters:

  • t (Yast::Term)

    term dialog containing strings

  • widgets (Hash <String, Hash{String => Object>})

    map of widget name -> widget description map

Returns:

  • (Yast::Term)

    updated term ready to be used as a dialog



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
136
137
138
139
140
141
# File '../../src/modules/CWM.rb', line 111

def ProcessTerm(t, widgets)
  t = deep_copy(t)
  widgets = deep_copy(widgets)
  args = Builtins.size(t)
  return deep_copy(t) if args == 0
  ret = Builtins.toterm(
    Builtins.substring(Builtins.sformat("%1", Builtins.symbolof(t)), 1)
  )
  index = 0
  current = Builtins.symbolof(t)
  while Ops.less_than(index, args)
    arg = Ops.get(t, index)
    if current == :Frame && index == 0 # no action
      Builtins.y2debug("Leaving untouched %1", arg)
    elsif Ops.is_term?(arg) && arg != nil # recurse
      s = Builtins.symbolof(Convert.to_term(arg))
      if Builtins.contains(@ContainerWidgets, s)
        arg = ProcessTerm(Convert.to_term(arg), widgets)
      end
    elsif Ops.is_string?(arg) # action
      arg = Ops.get_term(
        widgets,
        [Convert.to_string(arg), "widget"],
        VBox()
      )
    end
    ret = Builtins.add(ret, arg)
    index = Ops.add(index, 1)
  end
  deep_copy(ret)
end

- (Object) PushSettings

Push the settings of the currently run dialog to the stack



87
88
89
90
91
92
93
94
# File '../../src/modules/CWM.rb', line 87

def PushSettings
  @settings_stack = Builtins.prepend(
    @settings_stack,
    { "widgets" => @current_dialog_widgets }
  )

  nil
end

- (Object) ReplaceWidgetHelp(widget, help)

Replace help for a particular widget

Parameters:

  • widget (String)

    string widget ID of widget to replace help

  • help (String)

    string new help to the widget



754
755
756
757
758
759
760
761
762
763
# File '../../src/modules/CWM.rb', line 754

def ReplaceWidgetHelp(widget, help)
  @current_dialog_widgets = Builtins.maplist(@current_dialog_widgets) do |w|
    Ops.set(w, "help", help) if Ops.get_string(w, "_cwm_key", "") == widget
    deep_copy(w)
  end
  help = MergeHelps(@current_dialog_widgets)
  Wizard.RestoreHelp(help)

  nil
end

- (Symbol) Run(widgets, functions)

Generic function to create dialog and handle it's events

Parameters:

  • widgets (Array<Hash{String => Object>})

    list of widget maps

  • functions (Hash)

    map initialize/save/handle fallbacks if not specified with the widgets.

Returns:

  • (Symbol)

    wizard sequencer symbol



777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
# File '../../src/modules/CWM.rb', line 777

def Run(widgets, functions)
  widgets = deep_copy(widgets)
  functions = deep_copy(functions)
  widgets = mergeFunctions(widgets, functions)
  PushSettings()
  @current_dialog_widgets = deep_copy(widgets)
  initWidgets(widgets)

  # allow a handler to enable/disable widgets before the first real
  # UserInput takes place
  UI.FakeUserInput({ "ID" => "_cwm_wakeup" })

  ret = nil
  save_exits = [:next, :ok]
  save = false
  event_descr = {}
  timeout = GetLowestTimeout(widgets)
  while ret != :back && ret != :abort && !save
    if Ops.greater_than(timeout, 0)
      event_descr = UI.WaitForEvent(timeout)
    else
      event_descr = UI.WaitForEvent
    end
    ret = Ops.get(event_descr, "ID")
    if Ops.get_string(event_descr, "EventType", "") == "DebugEvent"
      handleDebug
    end
    handle_ret = handleWidgets(widgets, event_descr)
    if handle_ret != nil ||
        Ops.is_symbol?(ret) && Builtins.contains(save_exits, ret)
      save = true
      if handle_ret != nil
        ret = handle_ret
        Ops.set(event_descr, "ID", ret)
      end
    end

    ret = :abort if ret == :cancel
    if ret == :abort
      if Ops.get(functions, :abort) != nil
        toEval = Convert.convert(
          Ops.get(functions, :abort),
          :from => "any",
          :to   => "boolean ()"
        )
        if toEval != nil
          eval_ret = toEval.call
          ret = eval_ret ? :abort : nil
        end
      end
    elsif ret == :back
      if Ops.get(functions, :back) != nil
        toEval = Convert.convert(
          Ops.get(functions, :back),
          :from => "any",
          :to   => "boolean ()"
        )
        if toEval != nil
          eval_ret = toEval.call
          ret = eval_ret ? :back : nil
        end
      end
    end

    next if ret == nil

    ret = nil if !validateWidgets(widgets, event_descr) if save

    if ret == nil
      save = false
      next
    end
  end
  saveWidgets(widgets, event_descr) if save
  cleanupWidgets(widgets)
  PopSettings()
  Convert.to_symbol(ret)
end

- (Object) saveWidgets(widgets, event)

Save changes of widget after event generated global only because of testsuites CWMTab uses it too

Parameters:

  • widgets (Array<Hash{String => Object>})

    list of maps represenging widgets

  • event (Hash)

    map event that occured



376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
# File '../../src/modules/CWM.rb', line 376

def saveWidgets(widgets, event)
  widgets = deep_copy(widgets)
  event = deep_copy(event)
  Builtins.foreach(widgets) do |w|
    @processed_widget = deep_copy(w)
    toEval = Convert.convert(
      Ops.get(w, "store"),
      :from => "any",
      :to   => "void (string, map)"
    )
    toEval.call(Ops.get_string(w, "_cwm_key", ""), event) if toEval != nil
  end

  nil
end

- (Object) SetValidationFailedHandler(handler)

Set handler to be called after validation of a dialog failed

Parameters:

  • handler (void ())

    a function reference to be caled. If nil, nothing is called



905
906
907
908
909
910
# File '../../src/modules/CWM.rb', line 905

def SetValidationFailedHandler(handler)
  handler = deep_copy(handler)
  @validation_failed_handler = deep_copy(handler)

  nil
end

- (Object) ShowAndRun(settings)

Display the dialog and run its event loop

Parameters:

  • settings (Hash{String => Object})

    a map of all settings needed to run the dialog



914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
# File '../../src/modules/CWM.rb', line 914

def ShowAndRun(settings)
  settings = deep_copy(settings)
  widget_descr = Ops.get_map(settings, "widget_descr", {})
  contents = Ops.get_term(settings, "contents", VBox())
  widget_names = Convert.convert(
    Ops.get(settings, "widget_names") { StringsOfTerm(contents) },
    :from => "any",
    :to   => "list <string>"
  )
  caption = Ops.get_string(settings, "caption", "")
  back_button = Ops.get_string(settings, "back_button") { Label.BackButton }
  next_button = Ops.get_string(settings, "next_button") { Label.NextButton }
  abort_button = Ops.get_string(settings, "abort_button") do
    Label.AbortButton
  end
  fallback = Ops.get_map(settings, "fallback_functions", {})

  w = CreateWidgets(widget_names, widget_descr)
  help = MergeHelps(w)
  contents = PrepareDialog(contents, w)
  Wizard.SetContentsButtons(
    caption,
    contents,
    help,
    back_button,
    next_button
  )
  AdjustButtons(next_button, back_button, abort_button, nil)
  DisableButtons(Ops.get_list(settings, "disable_buttons", []))
  Run(w, fallback)
end

- (Symbol) ShowAndRunOrig(widget_names, widget_descr, contents, caption, back_button, next_button, fallback)

Display the dialog and run its event loop

Parameters:

  • widget_names (Array<String>)

    list of names of widgets that will be used in the dialog

  • widget_descr (Hash <String, Hash{String => Object>})

    map description map of all widgets

  • contents (Yast::Term)

    term contents of the dialog, identifiers instead of widgets

  • caption (String)

    string dialog caption

  • back_button (String)

    string label of the back button

  • next_button (String)

    string label of the next button

  • fallback (Hash)

    map initialize/save/handle fallbacks if not specified with the widgets.

Returns:

  • (Symbol)

    wizard sequencer symbol



960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
# File '../../src/modules/CWM.rb', line 960

def ShowAndRunOrig(widget_names, widget_descr, contents, caption, back_button, next_button, fallback)
  widget_names = deep_copy(widget_names)
  widget_descr = deep_copy(widget_descr)
  contents = deep_copy(contents)
  fallback = deep_copy(fallback)
  ShowAndRun(
    {
      "widget_names"       => widget_names,
      "widget_descr"       => widget_descr,
      "contents"           => contents,
      "caption"            => caption,
      "back_button"        => back_button,
      "next_button"        => next_button,
      "fallback_functions" => fallback
    }
  )
end

- (Object) StoreNull(key, event)

Do-nothing replacement for a widget storing function. Used for push buttons if all the other widgets have a fallback.

Parameters:

  • key (String)

    id of the widget

  • event (Hash)

    the event being handled



991
992
993
994
# File '../../src/modules/CWM.rb', line 991

def StoreNull(key, event)
  event = deep_copy(event)
  nil
end

- (String) StringsOfTerm(t)

Process term with the dialog, return all strings. To be used as an argument for widget_names until they are obsoleted.

Parameters:

  • t (Yast::Term)

    term dialog containing strings

Returns:

  • (String)

    s found in the term



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File '../../src/modules/CWM.rb', line 147

def StringsOfTerm(t)
  t = deep_copy(t)
  rets = []
  args = Builtins.size(t)
  index = 0
  while Ops.less_than(index, args)
    arg = Ops.get(t, index)
    current = Builtins.symbolof(t)
    if current == :Frame && index == 0 # no action
      Builtins.y2debug("Leaving untouched %1", arg)
    elsif Ops.is_term?(arg) && arg != nil # recurse
      s = Builtins.symbolof(Convert.to_term(arg))
      if Builtins.contains(@ContainerWidgets, s)
        rets = Ops.add(rets, StringsOfTerm(Convert.to_term(arg)))
      end
    elsif Ops.is_string?(arg) # action
      rets = Builtins.add(rets, Convert.to_string(arg))
    end
    index = Ops.add(index, 1)
  end
  deep_copy(rets)
end

- (Boolean) ValidateBasicType(value, type)

Validate the value against the basic type

Parameters:

  • value (Object)

    any a value to validate

  • type (String)

    string type information

Returns:

  • (Boolean)

    true on success or if do not know how to validate



174
175
176
177
178
179
180
181
182
183
184
185
186
# File '../../src/modules/CWM.rb', line 174

def ValidateBasicType(value, type)
  value = deep_copy(value)
  return Ops.is_term?(value) if type == "term"
  return Ops.is_string?(value) if type == "string"
  return Ops.is_symbol?(value) if type == "symbol"
  return Ops.is_list?(value) if type == "list"
  return Ops.is_map?(value) if type == "map"
  return Ops.is_boolean?(value) if type == "boolean"
  return Ops.is_integer?(value) if type == "integer"

  Builtins.y2error("Unknown value type %1", type)
  true
end

- (Boolean) ValidateMaps(widgets)

Validate widget description map, check for maps structure Also checks option description maps if present

Parameters:

  • widgets (Hash <String, Hash{String => Object>})

    map widgets description map

Returns:

  • (Boolean)

    true on success



439
440
441
442
443
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
481
482
483
484
485
486
487
# File '../../src/modules/CWM.rb', line 439

def ValidateMaps(widgets)
  widgets = deep_copy(widgets)
  ret = true
  Builtins.foreach(widgets) do |k, v|
    Builtins.foreach(v) do |kk, vv|
      ret = ValidateValueType(kk, vv, k) && ret
    end
    to_check = []
    if Ops.get(v, "widget") == :custom
      to_check = ["custom_widget"]
    elsif Ops.get(v, "widget") == :empty
      to_check = []
    else
      to_check = ["label", "widget"]
    end
    if !Builtins.haskey(v, "no_help")
      to_check = Convert.convert(
        Builtins.merge(to_check, ["help"]),
        :from => "list",
        :to   => "list <string>"
      )
    end
    Builtins.foreach(to_check) do |key|
      if key != "label" ||
          Ops.get(v, "widget") != :radio_buttons &&
            Ops.get(v, "widget") != :custom &&
            Ops.get(v, "widget") != :func
        ret = ValidateValueContents(key, Ops.get(v, key), k) && ret
      end
    end
    if Ops.get(v, "widget") == :custom
      ret = ValidateValueContents(
        "custom_widget",
        Ops.get(v, "custom_widget"),
        k
      ) && ret
    end
    # validate widget-specific entries
    if Builtins.haskey(v, "_cwm_do_validate")
      val_func = Convert.convert(
        Ops.get(v, "_cwm_do_validate"),
        :from => "any",
        :to   => "boolean (string, map <string, any>)"
      )
      ret = val_func.call(k, v) && ret if val_func != nil
    end
  end
  ret
end

- (Boolean) ValidateValueContents(key, value, widget)

Validate value of entry of the widget/option description map Also checks option description maps if present

Parameters:

  • key (String)

    string key of the map entry

  • value (Object)

    any value of the map entry

  • widget (String)

    any name of the widget/option

Returns:

  • (Boolean)

    true if validation succeeded



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
# File '../../src/modules/CWM.rb', line 253

def ValidateValueContents(key, value, widget)
  value = deep_copy(value)
  error = ""
  if key == "label"
    s = Convert.to_string(value)
    if s == nil || Builtins.size(s) == 0
      error = "Empty label"
    elsif Builtins.size(Builtins.filterchars(s, "&")) != 1
      error = "Label has no shortcut or more than 1 shortcuts"
    end
  elsif key == "help"
    s = Convert.to_string(value)
    error = "Empty help" if s == nil
  elsif key == "widget"
    s = Convert.to_symbol(value)
    error = "No widget specified" if s == nil
  elsif key == "custom_widget"
    s = Convert.to_term(value)
    error = "No custom widget specified" if s == nil
  end

  return true if error == ""

  Builtins.y2error("Error on key %1 of widget %2: %3", key, widget, error)
  false
end

- (Boolean) ValidateValueType(key, value, widget)

Validate type of entry of the widget/option description map Also checks option description maps if present

Parameters:

  • key (String)

    string key of the map entry

  • value (Object)

    any value of the map entry

  • widget (String)

    any name of the widget/option

Returns:

  • (Boolean)

    true if validation succeeded



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
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
# File '../../src/modules/CWM.rb', line 194

def ValidateValueType(key, value, widget)
  value = deep_copy(value)
  types = {
    # general
    "widget"        => "symbol",
    "custom_widget" => "term",
    "handle_events" => "list",
    "help"          => "string",
    "label"         => "string",
    "opt"           => "list",
    "ui_timeout"    => "integer",
    "validate_type" => "symbol",
    # int field
    "minimum"       => "integer",
    "maximum"       => "integer",
    "_cwm_attrib"   => "map",
    "fallback"      => "map"
  }
  type = Ops.get(types, key)
  success = true
  if type == nil
    if key == "widget_func"
      success = Ops.is(value, "term ()")
    elsif key == "init"
      success = Ops.is(value, "void (string)")
    elsif key == "handle"
      success = Ops.is(value, "symbol (string, map)")
    elsif key == "store"
      success = Ops.is(value, "void (string, map)")
    elsif key == "cleanup"
      success = Ops.is(value, "void (string)")
    elsif key == "validate_function"
      success = Ops.is(value, "boolean (string, map)")
    elsif key == "items"
      success = Ops.is(value, "list <list <string>>")
    elsif key == "_cwm_do_validate"
      success = Ops.is(value, "boolean (string, map <string, any>)")
    end
  else
    success = ValidateBasicType(value, type)
  end

  if !success
    Builtins.y2error(
      "Wrong type of option %1 in description map of %2",
      key,
      widget
    )
  end

  success
end

- (Object) validateWidget(widget, event, key)

Validate single widget

Parameters:

  • widget (Hash{String => Object})

    widget description map

  • event (Hash)

    map event that caused validation

  • key (String)

    widget key for validation by function

Returns:

  • true if validation succeeded



639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
# File '../../src/modules/CWM.rb', line 639

def validateWidget(widget, event, key)
  widget = deep_copy(widget)
  event = deep_copy(event)
  @processed_widget = deep_copy(widget)
  failed = false
  val_type = Ops.get_symbol(widget, "validate_type")
  if val_type == :function || val_type == :function_no_popup
    toEval = Convert.convert(
      Ops.get(widget, "validate_function"),
      :from => "any",
      :to   => "boolean (string, map)"
    )
    failed = !toEval.call(key, event) if toEval != nil
  elsif val_type == :regexp
    regexp = Ops.get_string(widget, "validate_condition", "")
    if !Builtins.regexpmatch(
        Convert.to_string(UI.QueryWidget(Id(:_tp_value), :Value)),
        regexp
      )
      failed = true
    end
  elsif val_type == :list
    possible = Ops.get_list(widget, "validate_condition", [])
    if !Builtins.contains(possible, UI.QueryWidget(Id(:_tp_value), :Value))
      failed = true
    end
  end

  if failed && val_type != :function
    error = Ops.get_string(widget, "validate_help", "")
    if error == ""
      wname = Ops.get_string(
        widget,
        "label",
        Ops.get_string(widget, "_cwm_key", "")
      )
      wname = Builtins.deletechars(wname, "&")
      # message popup, %1 is a label of some widget
      error = Builtins.sformat(_("The value of %1 is invalid."), wname)
    end
    UI.SetFocus(Id(Ops.get_string(widget, "_cwm_key", "")))
    Report.Error(error)
  end
  !failed
end

- (Boolean) validateWidgets(widgets, event)

Validate dialog contents for allow it to be saved

Parameters:

  • widgets (Array<Hash{String => Object>})

    list of widgets to validate

  • event (Hash)

    map event that caused validation

Returns:

  • (Boolean)

    true if everything is OK, false if something is wrong



689
690
691
692
693
694
695
696
697
698
699
700
701
# File '../../src/modules/CWM.rb', line 689

def validateWidgets(widgets, event)
  widgets = deep_copy(widgets)
  event = deep_copy(event)
  result = true
  Builtins.foreach(widgets) do |w|
    widget_key = Ops.get_string(w, "_cwm_key", "")
    result = result && validateWidget(w, event, widget_key)
  end
  if !result && @validation_failed_handler != nil
    @validation_failed_handler.call
  end
  result
end