• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

yast / yast-autoinstallation / 7347071288

28 Dec 2023 11:13AM UTC coverage: 69.009% (+0.4%) from 68.607%
7347071288

push

github

web-flow
Merge pull request #874 from yast/rubocop_update

Rubocop update

94 of 254 new or added lines in 51 files covered. (37.01%)

22 existing lines in 13 files now uncovered.

6373 of 9235 relevant lines covered (69.01%)

10.29 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

2.91
/src/include/autoinstall/general_dialogs.rb
1
# File:  clients/autoinst_general.ycp
2
# Package:  Autoinstallation Configuration System
3
# Summary:  General Settings
4
# Authors:  Anas Nashif<nashif@suse.de>
5
#
6
# $Id$
7
module Yast
1✔
8
  module AutoinstallGeneralDialogsInclude
1✔
9
    def initialize_autoinstall_general_dialogs(_include_target)
1✔
10
      textdomain "autoinst"
1✔
11
      Yast.import "GetInstArgs"
1✔
12
      Yast.import "Label"
1✔
13
    end
14

15
    # Main dialog
16
    # @return [Symbol]
17
    def ModeDialog
1✔
18
      mode = deep_copy(AutoinstGeneral.mode)
×
19
      signature_handling = deep_copy(AutoinstGeneral.signature_handling)
×
20
      confirm = Ops.get_boolean(mode, "confirm", true)
×
21
      second_stage = Ops.get_boolean(mode, "second_stage", true)
×
22
      halt = Ops.get_boolean(mode, "halt", false)
×
23
      halt_second = Ops.get_boolean(mode, "final_halt", false)
×
24
      reboot_second = Ops.get_boolean(mode, "final_reboot", false)
×
25

26
      accept_unsigned_file = Ops.get_boolean(
×
27
        signature_handling,
28
        "accept_unsigned_file",
29
        false
30
      )
31
      accept_file_without_checksum = Ops.get_boolean(
×
32
        signature_handling,
33
        "accept_file_without_checksum",
34
        false
35
      )
36
      accept_verification_failed = Ops.get_boolean(
×
37
        signature_handling,
38
        "accept_verification_failed",
39
        false
40
      )
41
      accept_unknown_gpg_key = Ops.get_boolean(
×
42
        signature_handling,
43
        "accept_unknown_gpg_key",
44
        false
45
      )
46
      import_gpg_key = Ops.get_boolean(
×
47
        signature_handling,
48
        "import_gpg_key",
49
        false
50
      )
51
      accept_non_trusted_gpg_key = Ops.get_boolean(
×
52
        signature_handling,
53
        "accept_non_trusted_gpg_key",
54
        false
55
      )
56

57
      contents = HVSquash(
×
58
        VBox(
59
          Left(CheckBox(Id(:confirm), _("Con&firm installation?"), confirm)),
60
          Left(
61
            CheckBox(
62
              Id(:second_stage),
63
              _("AutoYaST Second Stage"),
64
              second_stage
65
            )
66
          ),
67
          Left(
68
            CheckBox(
69
              Id(:halt),
70
              _("Turn Off the Machine after the First Stage"),
71
              halt
72
            )
73
          ),
74
          Left(
75
            CheckBox(
76
              Id(:halt_second),
77
              _("Turn off the Machine after the Second Stage"),
78
              halt_second
79
            )
80
          ),
81
          Left(
82
            CheckBox(
83
              Id(:reboot_second),
84
              _("Reboot the Machine after the Second Stage"),
85
              reboot_second
86
            )
87
          ),
88
          Left(Label(_("Signature Handling"))),
89
          Left(
90
            CheckBox(
91
              Id(:accept_unsigned_file),
92
              _("Accept &Unsigned Files"),
93
              accept_unsigned_file
94
            )
95
          ),
96
          Left(
97
            CheckBox(
98
              Id(:accept_file_without_checksum),
99
              _("Accept Files without a &Checksum"),
100
              accept_file_without_checksum
101
            )
102
          ),
103
          Left(
104
            CheckBox(
105
              Id(:accept_verification_failed),
106
              _("Accept Failed &Verifications"),
107
              accept_verification_failed
108
            )
109
          ),
110
          Left(
111
            CheckBox(
112
              Id(:accept_unknown_gpg_key),
113
              _("Accept Unknown &GPG Keys"),
114
              accept_unknown_gpg_key
115
            )
116
          ),
117
          Left(
118
            CheckBox(
119
              Id(:accept_non_trusted_gpg_key),
120
              _("Accept Untrusted GPG Keys"),
121
              accept_non_trusted_gpg_key
122
            )
123
          ),
124
          Left(
125
            CheckBox(
126
              Id(:import_gpg_key),
127
              _("Import &New GPG Keys"),
128
              import_gpg_key
129
            )
130
          )
131
        )
132
      )
133

134
      help_text = _(
×
135
        "<P>\n" \
136
        "The options in this dialog control the behavior of the AutoYaST during\n" \
137
        "automatic installation.\n" \
138
        "</P>\n"
139
      )
140
      help_text = Ops.add(
×
141
        help_text,
142
        _(
143
          "<P>\n" \
144
          "The installation confirmation option is selected by default\n" \
145
          "to avoid unwanted installation. It stops the system\n" \
146
          "during installation and shows a summary of requested operations in the\n" \
147
          "usual proposal screen.  Uncheck this option to install " \
148
          "automatically without interruption.\n" \
149
          "</P>\n"
150
        )
151
      )
152
      help_text = Ops.add(
×
153
        help_text,
154
        _(
155
          "<P>\n" \
156
          "If you turn off the second stage of AutoYaST, the " \
157
          "installation continues in manual mode\n" \
158
          "after the first reboot (after package installation).\n" \
159
          "</P>\n"
160
        )
161
      )
162

163
      help_text = Ops.add(
×
164
        help_text,
165
        _(
166
          "<P>\n" \
167
          "For signature handling, read the AutoYaST documentation.\n" \
168
          "</P>\n"
169
        )
170
      )
171

172
      Wizard.SetContents(_("Other Options"), contents, help_text, true, true)
×
173

174
      Wizard.HideAbortButton
×
175
      Wizard.SetNextButton(:next, Label.NextButton)
×
176

177
      ret = nil
×
NEW
178
      loop do
×
179
        ret = UI.UserInput
×
180
        if ret == :next
×
181
          confirm = Convert.to_boolean(UI.QueryWidget(Id(:confirm), :Value))
×
182
          second_stage = Convert.to_boolean(
×
183
            UI.QueryWidget(Id(:second_stage), :Value)
184
          )
185
          halt = Convert.to_boolean(UI.QueryWidget(Id(:halt), :Value))
×
186
          halt_second = Convert.to_boolean(
×
187
            UI.QueryWidget(Id(:halt_second), :Value)
188
          )
189
          reboot_second = Convert.to_boolean(
×
190
            UI.QueryWidget(Id(:reboot_second), :Value)
191
          )
192

193
          Ops.set(mode, "second_stage", second_stage)
×
194
          Ops.set(mode, "confirm", confirm)
×
195
          Ops.set(mode, "halt", halt)
×
196
          Ops.set(mode, "final_halt", halt_second)
×
197
          Ops.set(mode, "final_reboot", reboot_second)
×
198
          AutoinstGeneral.mode = deep_copy(mode)
×
199

200
          Ops.set(
×
201
            signature_handling,
202
            "accept_unsigned_file",
203
            Convert.to_boolean(
204
              UI.QueryWidget(Id(:accept_unsigned_file), :Value)
205
            )
206
          )
207
          Ops.set(
×
208
            signature_handling,
209
            "accept_file_without_checksum",
210
            Convert.to_boolean(
211
              UI.QueryWidget(Id(:accept_file_without_checksum), :Value)
212
            )
213
          )
214
          Ops.set(
×
215
            signature_handling,
216
            "accept_verification_failed",
217
            Convert.to_boolean(
218
              UI.QueryWidget(Id(:accept_verification_failed), :Value)
219
            )
220
          )
221
          Ops.set(
×
222
            signature_handling,
223
            "accept_unknown_gpg_key",
224
            Convert.to_boolean(
225
              UI.QueryWidget(Id(:accept_unknown_gpg_key), :Value)
226
            )
227
          )
228
          Ops.set(
×
229
            signature_handling,
230
            "import_gpg_key",
231
            Convert.to_boolean(UI.QueryWidget(Id(:import_gpg_key), :Value))
232
          )
233
          Ops.set(
×
234
            signature_handling,
235
            "accept_non_trusted_gpg_key",
236
            Convert.to_boolean(
237
              UI.QueryWidget(Id(:accept_non_trusted_gpg_key), :Value)
238
            )
239
          )
240
          AutoinstGeneral.signature_handling = deep_copy(signature_handling)
×
241
        end
NEW
242
        break if ret == :next || ret == :back || ret == :cancel
×
243
      end
UNCOV
244
      Convert.to_symbol(ret)
×
245
    end
246

247
    def newQuestion(stage, dialog, askList, title, defaultValues)
1✔
248
      askList = deep_copy(askList)
×
249
      defaultValues = deep_copy(defaultValues)
×
250
      ret = :x
×
251
      selection = []
×
252
      selId = 0
×
253
      if Ops.greater_than(
×
254
        Builtins.size(Ops.get_list(defaultValues, "selection", [])),
255
        0
256
      )
257
        Builtins.foreach(Ops.get_list(defaultValues, "selection", [])) do |m|
×
258
          selection = Builtins.add(
×
259
            selection,
260
            Item(
261
              Id(selId),
262
              Ops.get_string(m, "label", ""),
263
              Ops.get_string(m, "value", "")
264
            )
265
          )
266
          selId = Ops.add(selId, 1)
×
267
        end
268
      end
269
      selId = 0
×
270

271
      contents = HVSquash(
×
272
        VBox(
273
          TextEntry(
274
            Id(:frametitle),
275
            _("Frame Title"),
276
            Ops.get_string(defaultValues, "frametitle", "")
277
          ),
278
          TextEntry(
279
            Id(:question),
280
            _("Question"),
281
            Ops.get_string(defaultValues, "question", "")
282
          ),
283
          IntField(
284
            Id(:timeout),
285
            _("Timeout (zero means no timeout)"),
286
            0,
287
            999,
288
            Ops.get_integer(defaultValues, "timeout", 0)
289
          ),
290
          TextEntry(
291
            Id(:defaultVal),
292
            "Default",
293
            Ops.get_string(defaultValues, "default", "")
294
          ),
295
          Left(
296
            RadioButtonGroup(
297
              Id(:type),
298
              HBox(
299
                RadioButton(
300
                  Id(:t_text),
301
                  Opt(:notify, :immediate),
302
                  "Text",
303
                  Ops.get_string(defaultValues, "type", "text") == "text"
304
                ),
305
                RadioButton(
306
                  Id(:t_symbol),
307
                  Opt(:notify, :immediate),
308
                  "Symbol",
309
                  Ops.get_string(defaultValues, "type", "text") == "symbol"
310
                ),
311
                RadioButton(
312
                  Id(:t_boolean),
313
                  Opt(:notify, :immediate),
314
                  "Boolean",
315
                  Ops.get_string(defaultValues, "type", "text") == "boolean"
316
                ),
317
                RadioButton(
318
                  Id(:t_integer),
319
                  Opt(:notify, :immediate),
320
                  "Integer",
321
                  Ops.get_string(defaultValues, "type", "text") == "integer"
322
                ),
323
                CheckBox(
324
                  Id(:password),
325
                  _("Password"),
326
                  Ops.get_boolean(defaultValues, "password", false)
327
                )
328
              )
329
            )
330
          ),
331
          TextEntry(
332
            Id(:path),
333
            _("Pathlist for answers (multiple paths are separated by space)"),
334
            Builtins.mergestring(
335
              Ops.get_list(defaultValues, "pathlist", []),
336
              " "
337
            )
338
          ),
339
          TextEntry(
340
            Id(:file),
341
            _("Store answer in this file"),
342
            Ops.get_string(defaultValues, "file", "")
343
          ),
344
          Label(_("Selection List for type 'Symbol'")),
345
          HBox(
346
            MinSize(
347
              10,
348
              5,
349
              Table(Id(:selection), Header(_("Label"), _("Value")), selection)
350
            ),
351
            VBox(
352
              PushButton(
353
                Id(:delSelection),
354
                Opt(:default, :hstretch),
355
                Label.DeleteButton
356
              )
357
            )
358
          ),
359
          HBox(
360
            TextEntry(Id(:selLabel), Opt(:notify, :immediate), _("Label"), ""),
361
            TextEntry(Id(:selValue), Opt(:notify, :immediate), _("Value"), ""),
362
            PushButton(
363
              Id(:addSelection),
364
              Opt(:default, :hstretch),
365
              Label.AddButton
366
            )
367
          ),
368
          HBox(
369
            PushButton(Id(:ok), Opt(:default, :hstretch), Label.OKButton),
370
            PushButton(Id(:abort), Opt(:default, :hstretch), Label.AbortButton)
371
          )
372
        )
373
      )
374
      UI.OpenDialog(Opt(:decorated), contents)
×
375
      UI.ChangeWidget(Id(:selLabel), :Enabled, false)
×
376
      UI.ChangeWidget(Id(:selValue), :Enabled, false)
×
377
      UI.ChangeWidget(Id(:selection), :Enabled, false)
×
378
      UI.ChangeWidget(Id(:password), :Enabled, false)
×
379

NEW
380
      case Ops.get_string(defaultValues, "type", "text")
×
381
      when "text"
382
        UI.ChangeWidget(Id(:password), :Enabled, true)
×
383
      when "symbol"
384
        UI.ChangeWidget(Id(:selLabel), :Enabled, true)
×
385
        UI.ChangeWidget(Id(:selValue), :Enabled, true)
×
386
        UI.ChangeWidget(Id(:selection), :Enabled, true)
×
387
      end
NEW
388
      loop do
×
389
        if Builtins.size(
×
390
          Convert.to_list(UI.QueryWidget(Id(:selection), :Items))
391
        ) == 0
392
          UI.ChangeWidget(Id(:delSelection), :Enabled, false)
×
393
        else
394
          UI.ChangeWidget(Id(:delSelection), :Enabled, true)
×
395
        end
396
        if Builtins.size(
×
397
          Convert.to_string(UI.QueryWidget(Id(:selLabel), :Value))
398
        ) == 0 ||
399
            Builtins.size(
400
              Convert.to_string(UI.QueryWidget(Id(:selValue), :Value))
401
            ) == 0
402
          UI.ChangeWidget(Id(:addSelection), :Enabled, false)
×
403
        else
404
          UI.ChangeWidget(Id(:addSelection), :Enabled, true)
×
405
        end
406
        ret = Convert.to_symbol(UI.UserInput)
×
NEW
407
        case ret
×
408
        when :addSelection
409
          label = Convert.to_string(UI.QueryWidget(Id(:selLabel), :Value))
×
410
          val = Convert.to_string(UI.QueryWidget(Id(:selValue), :Value))
×
411
          selection = Builtins.add(selection, Item(Id(selId), label, val))
×
412
          selId = Ops.add(selId, 1)
×
413
          UI.ChangeWidget(Id(:selection), :Items, selection)
×
414
        when :t_symbol
415
          UI.ChangeWidget(Id(:selLabel), :Enabled, true)
×
416
          UI.ChangeWidget(Id(:selValue), :Enabled, true)
×
417
          UI.ChangeWidget(Id(:selection), :Enabled, true)
×
418
          UI.ChangeWidget(Id(:password), :Enabled, false)
×
419
        when :t_text
420
          UI.ChangeWidget(Id(:selLabel), :Enabled, false)
×
421
          UI.ChangeWidget(Id(:selValue), :Enabled, false)
×
422
          UI.ChangeWidget(Id(:selection), :Enabled, false)
×
423
          UI.ChangeWidget(Id(:password), :Enabled, true)
×
424
        when :t_boolean, :t_integer
425
          UI.ChangeWidget(Id(:selLabel), :Enabled, false)
×
426
          UI.ChangeWidget(Id(:selValue), :Enabled, false)
×
427
          UI.ChangeWidget(Id(:selection), :Enabled, false)
×
428
          UI.ChangeWidget(Id(:password), :Enabled, false)
×
429
        when :delSelection
430
          currSelId = Convert.to_integer(
×
431
            UI.QueryWidget(Id(:selection), :CurrentItem)
432
          )
433
          selection = Builtins.filter(selection) do |s|
×
434
            l = Builtins.argsof(s)
×
435
            Ops.get_term(l, 0) { Id(-1) } != Id(currSelId)
×
436
          end
437
          UI.ChangeWidget(Id(:selection), :Items, selection)
×
438
        when :ok
439
          max = -1
×
440
          Builtins.foreach(askList) do |m|
×
441
            if Ops.get_string(m, "stage", "initial") == stage &&
×
442
                Ops.get_integer(m, "dialog", 0) == dialog &&
443
                Ops.greater_than(Ops.get_integer(m, "element", -1), max)
444
              max = Ops.get_integer(m, "element", -1)
×
445
            end
446
          end
447
          max = Ops.add(max, 1)
×
448
          newVal = {
449
            "default"  => Convert.to_string(
×
450
              UI.QueryWidget(Id(:defaultVal), :Value)
451
            ),
452
            "title"    => title,
453
            "stage"    => stage,
454
            "dialog"   => dialog,
455
            "element"  => Ops.get_integer(defaultValues, "element", max),
456
            "script"   => Ops.get_map(defaultValues, "script", {}),
457
            "question" => Convert.to_string(
458
              UI.QueryWidget(Id(:question), :Value)
459
            )
460
          }
461
          if Convert.to_string(UI.QueryWidget(Id(:frametitle), :Value)) != ""
×
462
            Ops.set(
×
463
              newVal,
464
              "frametitle",
465
              Convert.to_string(UI.QueryWidget(Id(:frametitle), :Value))
466
            )
467
          end
468
          if Convert.to_integer(UI.QueryWidget(Id(:timeout), :Value)) != 0
×
469
            Ops.set(
×
470
              newVal,
471
              "timeout",
472
              Convert.to_integer(UI.QueryWidget(Id(:timeout), :Value))
473
            )
474
          end
NEW
475
          case Convert.to_symbol(UI.QueryWidget(Id(:type), :CurrentButton))
×
476
          when :t_symbol
477
            Ops.set(newVal, "type", "symbol")
×
478
          when :t_boolean
479
            Ops.set(newVal, "type", "boolean")
×
480
          when :t_integer
481
            Ops.set(newVal, "type", "integer")
×
482
          end
483
          if Convert.to_string(UI.QueryWidget(Id(:path), :Value)) != ""
×
484
            Ops.set(
×
485
              newVal,
486
              "pathlist",
487
              Builtins.splitstring(
488
                Convert.to_string(UI.QueryWidget(Id(:path), :Value)),
489
                " "
490
              )
491
            )
492
          end
493
          if Convert.to_string(UI.QueryWidget(Id(:file), :Value)) != ""
×
494
            Ops.set(
×
495
              newVal,
496
              "file",
497
              Convert.to_string(UI.QueryWidget(Id(:file), :Value))
498
            )
499
          end
500
          if Convert.to_symbol(UI.QueryWidget(Id(:type), :CurrentButton)) == :t_text
×
501
            Ops.set(
×
502
              newVal,
503
              "password",
504
              Convert.to_boolean(UI.QueryWidget(Id(:password), :Value))
505
            )
506
          end
507
          if Ops.greater_than(Builtins.size(selection), 0)
×
508
            r = []
×
509
            Builtins.foreach(selection) do |t|
×
510
              l = Builtins.argsof(t)
×
511
              r = Builtins.add(
×
512
                r,
513
                "label" => Ops.get_string(l, 1, ""),
514
                "value" => Ops.get_string(l, 2, "")
515
              )
516
            end
517
            Ops.set(newVal, "selection", r)
×
518
          end
519
          askList = if Builtins.size(defaultValues) == 0
×
520
            Builtins.add(askList, newVal)
×
521
          else
522
            Builtins.maplist(askList) do |d|
×
523
              if Ops.get_string(d, "stage", "initial") == stage &&
×
524
                  Ops.get_integer(d, "dialog", -1) == dialog &&
525
                  Ops.get_integer(d, "element", -1) ==
526
                      Ops.get_integer(defaultValues, "element", -1)
527
                d = deep_copy(newVal)
×
528
              end
529
              deep_copy(d)
×
530
            end
531
          end
532
        end
NEW
533
        break if ret == :abort || ret == :ok
×
534
      end
UNCOV
535
      UI.CloseDialog
×
536

537
      deep_copy(askList)
×
538
    end
539

540
    def askDialog
1✔
541
      askList = Convert.convert(
×
542
        AutoinstGeneral.askList,
543
        from: "list",
544
        to:   "list <map>"
545
      )
546
      title = ""
×
547
      help = ""
×
548
      dialogs = []
×
549
      questions = []
×
550
      elementCount = {}
×
551

552
      id_counter = 0
×
553
      askList = Builtins.maplist(askList) do |dialog|
×
554
        id_counter = Ops.get_integer(dialog, "dialog", id_counter)
×
555
        Ops.set(dialog, "dialog", id_counter)
×
556
        Ops.set(elementCount, id_counter, 0) if !Builtins.haskey(elementCount, id_counter)
×
557
        Ops.set(
×
558
          dialog,
559
          "element",
560
          Ops.get_integer(
561
            dialog,
562
            "element",
563
            Ops.get(elementCount, id_counter, -1)
564
          )
565
        )
566
        Ops.set(
×
567
          elementCount,
568
          id_counter,
569
          Ops.add(Ops.get(elementCount, id_counter, -1), 1)
570
        )
571
        id_counter = Ops.add(id_counter, 1)
×
572
        deep_copy(dialog)
×
573
      end
574
      askList = Builtins.sort(askList) do |x, y|
×
575
        Ops.less_than(
×
576
          Ops.get_integer(x, "dialog", -2),
577
          Ops.get_integer(y, "dialog", -1)
578
        ) ||
NEW
579
          (Ops.get_integer(x, "dialog", -2) == Ops.get_integer(y, "dialog", -1) &&
×
580
            Ops.less_than(
581
              Ops.get_integer(x, "element", -2),
582
              Ops.get_integer(y, "element", -1)
583
            ))
584
      end
585
      done = { "initial" => [] }
×
586
      Builtins.foreach(askList) do |m|
×
587
        if Ops.get_string(m, "stage", "initial") == "initial" &&
×
588
            !Builtins.contains(
589
              Ops.get(done, "initial", []),
590
              Ops.get_integer(m, "dialog", -1)
591
            )
592
          dialogs = Builtins.add(
×
593
            dialogs,
594
            Item(
595
              Id(Ops.get_integer(m, "dialog", -1)),
596
              Ops.get_string(m, "title", "")
597
            )
598
          )
599
          if title == ""
×
600
            title = Ops.get_string(m, "title", "")
×
601
            help = Ops.get_string(m, "help", "")
×
602
          end
603
          Ops.set(
×
604
            done,
605
            "initial",
606
            Builtins.add(
607
              Ops.get(done, "initial", []),
608
              Ops.get_integer(m, "dialog", -1)
609
            )
610
          )
611
        end
612
      end
613
      d = Builtins.filter(askList) do |dummy|
×
614
        Ops.get_integer(dummy, "dialog", -2) ==
×
615
          Ops.get_integer(askList, [0, "dialog"], 0) &&
616
          "initial" == Ops.get_string(dummy, "stage", "initital")
617
      end
618
      Builtins.foreach(d) do |m|
×
619
        id_counter = Ops.get_integer(m, "element", id_counter)
×
620
        questions = Builtins.add(
×
621
          questions,
622
          Item(Id(id_counter), Ops.get_string(m, "question", ""))
623
        )
624
        id_counter = Ops.add(id_counter, 1)
×
625
      end
626
      contents = HVSquash(
×
627
        VBox(
628
          RadioButtonGroup(
629
            Id(:stage),
630
            HBox(
631
              RadioButton(
632
                Id(:stage_initial),
633
                Opt(:notify, :immediate),
634
                _("1st Stage"),
635
                true
636
              ),
637
              RadioButton(
638
                Id(:stage_cont),
639
                Opt(:notify, :immediate),
640
                _("2nd Stage")
641
              )
642
            )
643
          ),
644
          TextEntry(Id(:dialogTitle), _("Dialog Title"), title),
645
          MultiLineEdit(Id(:hlp), _("Helptext"), help),
646
          HBox(
647
            PushButton(
648
              Id(:addDialog),
649
              Opt(:default, :hstretch),
650
              _("Add to Dialog List")
651
            ),
652
            PushButton(
653
              Id(:applyDialog),
654
              Opt(:default, :hstretch),
655
              _("Apply changes to dialog")
656
            )
657
          ),
658
          MinSize(
659
            10,
660
            5,
661
            SelectionBox(
662
              Id(:dialogs),
663
              Opt(:notify, :immediate),
664
              _("Title"),
665
              dialogs
666
            )
667
          ),
668
          HBox(
669
            PushButton(
670
              Id(:deleteDialog),
671
              Opt(:default, :hstretch),
672
              _("Delete Dialog")
673
            ),
674
            PushButton(Id(:dialogUp), Opt(:default, :hstretch), _("Dialog up")),
675
            PushButton(
676
              Id(:dialogDown),
677
              Opt(:default, :hstretch),
678
              _("Dialog down")
679
            )
680
          ),
681
          Label(_("Questions in dialog")),
682
          MinSize(10, 5, SelectionBox(Id(:questions), _("Question"), questions)),
683
          HBox(
684
            PushButton(
685
              Id(:addQuestion),
686
              Opt(:default, :hstretch),
687
              _("Add Question")
688
            ),
689
            PushButton(
690
              Id(:editQuestion),
691
              Opt(:default, :hstretch),
692
              _("Edit Question")
693
            ),
694
            PushButton(
695
              Id(:deleteQuestion),
696
              Opt(:default, :hstretch),
697
              _("Delete Question")
698
            ),
699
            PushButton(
700
              Id(:questionUp),
701
              Opt(:default, :hstretch),
702
              _("Question up")
703
            ),
704
            PushButton(
705
              Id(:questionDown),
706
              Opt(:default, :hstretch),
707
              _("Question down")
708
            )
709
          )
710
        )
711
      )
712
      help_text = _("<P></P>")
×
713
      Wizard.SetContents(_("ASK Options"), contents, help_text, true, true)
×
714

715
      Wizard.HideAbortButton
×
716
      Wizard.SetNextButton(:next, Label.FinishButton)
×
717

718
      ret = nil
×
719
      dialog_id = -1
×
720
      element_id = -1
×
NEW
721
      loop do
×
722
        if Builtins.size(Convert.to_list(UI.QueryWidget(Id(:dialogs), :Items))) == 0
×
723
          UI.ChangeWidget(Id(:addQuestion), :Enabled, false)
×
724
          UI.ChangeWidget(Id(:editQuestion), :Enabled, false)
×
725
          UI.ChangeWidget(Id(:questionUp), :Enabled, false)
×
726
          UI.ChangeWidget(Id(:deleteDialog), :Enabled, false)
×
727
        else
728
          UI.ChangeWidget(Id(:addQuestion), :Enabled, true)
×
729
          UI.ChangeWidget(Id(:editQuestion), :Enabled, true)
×
730
          UI.ChangeWidget(Id(:deleteDialog), :Enabled, true)
×
731
        end
732
        if Ops.greater_than(
×
733
          Builtins.size(
734
            Convert.to_list(UI.QueryWidget(Id(:questions), :Items))
735
          ),
736
          1
737
        )
738
          UI.ChangeWidget(Id(:questionUp), :Enabled, true)
×
739
          UI.ChangeWidget(Id(:questionDown), :Enabled, true)
×
740
          UI.ChangeWidget(Id(:deleteQuestion), :Enabled, true)
×
741
        else
742
          UI.ChangeWidget(Id(:questionUp), :Enabled, false)
×
743
          UI.ChangeWidget(Id(:questionDown), :Enabled, false)
×
744
          UI.ChangeWidget(Id(:deleteQuestion), :Enabled, false)
×
745
        end
746
        if Ops.greater_than(
×
747
          Builtins.size(Convert.to_list(UI.QueryWidget(Id(:dialogs), :Items))),
748
          1
749
        )
750
          UI.ChangeWidget(Id(:dialogUp), :Enabled, true)
×
751
          UI.ChangeWidget(Id(:dialogDown), :Enabled, true)
×
752
        else
753
          UI.ChangeWidget(Id(:dialogUp), :Enabled, false)
×
754
          UI.ChangeWidget(Id(:dialogDown), :Enabled, false)
×
755
        end
756

757
        ret = UI.UserInput
×
758
        stage = "initial"
×
759
        if Convert.to_symbol(UI.QueryWidget(Id(:stage), :CurrentButton)) == :stage_cont
×
760
          stage = "cont"
×
761
        end
762
        id_counter2 = 0
×
763
        dialogs = []
×
764
        askList = Builtins.maplist(askList) do |dialog|
×
765
          id_counter2 = Ops.get_integer(dialog, "dialog", id_counter2)
×
766
          if Ops.get_string(dialog, "stage", "initial") == stage
×
767
            dialogs = Builtins.add(
×
768
              dialogs,
769
              Item(Id(id_counter2), Ops.get_string(dialog, "title", ""))
770
            )
771
          end
772
          deep_copy(dialog)
×
773
        end
NEW
774
        case ret
×
775
        when :addQuestion
UNCOV
776
          l = Builtins.argsof(
×
777
            Ops.get(
778
              dialogs,
779
              Convert.to_integer(UI.QueryWidget(Id(:dialogs), :CurrentItem)),
780
              term(:empty)
781
            )
782
          )
783
          askList = newQuestion(
×
784
            stage,
785
            Convert.to_integer(UI.QueryWidget(Id(:dialogs), :CurrentItem)),
786
            askList,
787
            Ops.get_string(l, 1, ""),
788
            {}
789
          )
790
        when :editQuestion
791
          m = {}
×
792
          Builtins.foreach(askList) do |dummy|
×
793
            if Ops.get_integer(dummy, "dialog", -1) ==
×
794
                Convert.to_integer(UI.QueryWidget(Id(:dialogs), :CurrentItem)) &&
795
                Ops.get_integer(dummy, "element", -2) ==
796
                    Convert.to_integer(
797
                      UI.QueryWidget(Id(:questions), :CurrentItem)
798
                    )
799
              m = deep_copy(dummy)
×
800
            end
801
          end
802
          l = Builtins.argsof(
×
803
            Ops.get(
804
              dialogs,
805
              Convert.to_integer(UI.QueryWidget(Id(:dialogs), :CurrentItem)),
806
              term(:empty)
807
            )
808
          )
809
          askList = newQuestion(
×
810
            stage,
811
            Convert.to_integer(UI.QueryWidget(Id(:dialogs), :CurrentItem)),
812
            askList,
813
            Ops.get_string(l, 1, ""),
814
            m
815
          )
816
        when :deleteQuestion
817
          dialog_id = Convert.to_integer(
×
818
            UI.QueryWidget(Id(:dialogs), :CurrentItem)
819
          )
820
          element_id = Convert.to_integer(
×
821
            UI.QueryWidget(Id(:questions), :CurrentItem)
822
          )
823
          askList = Builtins.filter(askList) do |dialog|
×
824
            !(Ops.get_integer(dialog, "dialog", -1) == dialog_id &&
×
825
              Ops.get_integer(dialog, "element", -1) == element_id)
826
          end
827
        when :deleteDialog
828
          dialog_id = Convert.to_integer(
×
829
            UI.QueryWidget(Id(:dialogs), :CurrentItem)
830
          )
831
          askList = Builtins.filter(askList) do |dialog|
×
832
            Ops.get_integer(dialog, "dialog", -1) != dialog_id
×
833
          end
834
        when :applyDialog
835
          askList = Builtins.maplist(askList) do |d3|
×
836
            if Ops.get_integer(d3, "dialog", -1) ==
×
837
                Convert.to_integer(UI.QueryWidget(Id(:dialogs), :CurrentItem)) &&
838
                Ops.get_string(d3, "stage", "initial") == stage
839
              Ops.set(
×
840
                d3,
841
                "help",
842
                Convert.to_string(UI.QueryWidget(Id(:hlp), :Value))
843
              )
844
              Ops.set(
×
845
                d3,
846
                "title",
847
                Convert.to_string(UI.QueryWidget(Id(:dialogTitle), :Value))
848
              )
849
              help = Ops.get_string(d3, "help", "")
×
850
            end
851
            deep_copy(d3)
×
852
          end
853
        when :dialogUp
854
          dialog_id = Convert.to_integer(
×
855
            UI.QueryWidget(Id(:dialogs), :CurrentItem)
856
          )
857
          upperDialog = -10
×
858
          Builtins.foreach(askList) do |dialog|
×
859
            if Ops.get_integer(dialog, "dialog", -2) == dialog_id &&
×
860
                Ops.get_string(dialog, "stage", "initial") == stage
861
              raise Break
×
862
            end
863

864
            if Ops.get_string(dialog, "stage", "initial") == stage
×
865
              upperDialog = Ops.get_integer(dialog, "dialog", -2)
×
866
            end
867
          end
868
          askList = Builtins.maplist(askList) do |dialog|
×
869
            if upperDialog != -10 &&
×
870
                Ops.get_integer(dialog, "dialog", -1) == dialog_id &&
871
                Ops.get_string(dialog, "stage", "initial") == stage
872
              Ops.set(dialog, "dialog", upperDialog)
×
873
            elsif Ops.get_integer(dialog, "dialog", -1) == upperDialog &&
×
874
                Ops.get_string(dialog, "stage", "initial") == stage
875
              Ops.set(dialog, "dialog", dialog_id)
×
876
            end
877
            deep_copy(dialog)
×
878
          end
879
          UI.ChangeWidget(Id(:dialogs), :CurrentItem, upperDialog)
×
880
        when :dialogDown
881
          dialog_id = Convert.to_integer(
×
882
            UI.QueryWidget(Id(:dialogs), :CurrentItem)
883
          )
884
          lowerDialog = -10
×
885
          found = false
×
886
          Builtins.foreach(askList) do |dialog|
×
887
            if found && Ops.get_string(dialog, "stage", "initial") == stage
×
888
              lowerDialog = Ops.get_integer(dialog, "dialog", -2)
×
889
              raise Break
×
890
            end
891
            found = true if Ops.get_integer(dialog, "dialog", -2) == dialog_id
×
892
          end
893
          askList = Builtins.maplist(askList) do |dialog|
×
894
            if lowerDialog != -10 &&
×
895
                Ops.get_integer(dialog, "dialog", -1) == dialog_id &&
896
                Ops.get_string(dialog, "stage", "initial") == stage
897
              Ops.set(dialog, "dialog", lowerDialog)
×
898
            elsif Ops.get_integer(dialog, "dialog", -1) == lowerDialog &&
×
899
                Ops.get_string(dialog, "stage", "initial") == stage
900
              Ops.set(dialog, "dialog", dialog_id)
×
901
            end
902
            deep_copy(dialog)
×
903
          end
904
          UI.ChangeWidget(Id(:dialogs), :CurrentItem, lowerDialog)
×
905
        when :questionUp
906
          dialog_id = Convert.to_integer(
×
907
            UI.QueryWidget(Id(:dialogs), :CurrentItem)
908
          )
909
          element_id = Convert.to_integer(
×
910
            UI.QueryWidget(Id(:questions), :CurrentItem)
911
          )
912
          upper = -10
×
913
          Builtins.foreach(askList) do |dialog|
×
914
            if dialog_id == Ops.get_integer(dialog, "dialog", -1) &&
×
915
                Ops.get_string(dialog, "stage", "initial") == stage &&
916
                Ops.less_than(
917
                  Ops.get_integer(dialog, "element", -1),
918
                  element_id
919
                )
920
              upper = Ops.get_integer(dialog, "element", -1)
×
921
            end
922
          end
923
          askList = Builtins.maplist(askList) do |dialog|
×
924
            if dialog_id == Ops.get_integer(dialog, "dialog", -1)
×
925
              if upper != -10 &&
×
926
                  Ops.get_integer(dialog, "element", -1) == element_id &&
927
                  Ops.get_string(dialog, "stage", "initial") == stage
928
                Ops.set(dialog, "element", upper)
×
929
              elsif Ops.get_integer(dialog, "element", -1) == upper &&
×
930
                  Ops.get_string(dialog, "stage", "initial") == stage
931
                Ops.set(dialog, "element", element_id)
×
932
              end
933
            end
934
            deep_copy(dialog)
×
935
          end
936
        when :questionDown
937
          dialog_id = Convert.to_integer(
×
938
            UI.QueryWidget(Id(:dialogs), :CurrentItem)
939
          )
940
          element_id = Convert.to_integer(
×
941
            UI.QueryWidget(Id(:questions), :CurrentItem)
942
          )
943
          lower = -10
×
944
          found = false
×
945
          Builtins.foreach(askList) do |dialog|
×
946
            if found && Ops.get_string(dialog, "stage", "initial") == stage &&
×
947
                Ops.get_integer(dialog, "dialog", -1) == dialog_id
948
              lower = Ops.get_integer(dialog, "element", -2)
×
949
              raise Break
×
950
            end
951
            if Ops.get_integer(dialog, "dialog", -2) == dialog_id &&
×
952
                Ops.get_integer(dialog, "element", -2) == element_id
953
              found = true
×
954
            end
955
          end
956
          askList = Builtins.maplist(askList) do |dialog|
×
957
            if lower != -10 &&
×
958
                Ops.get_integer(dialog, "dialog", -1) == dialog_id &&
959
                Ops.get_string(dialog, "stage", "initial") == stage &&
960
                Ops.get_integer(dialog, "element", -1) == element_id
961
              Ops.set(dialog, "element", lower)
×
962
            elsif Ops.get_integer(dialog, "dialog", -1) == dialog_id &&
×
963
                Ops.get_string(dialog, "stage", "initial") == stage &&
964
                Ops.get_integer(dialog, "element", -1) == lower
965
              Ops.set(dialog, "element", element_id)
×
966
            end
967
            deep_copy(dialog)
×
968
          end
969
        when :addDialog
970
          max = -1
×
NEW
971
          Builtins.foreach(askList) do |ask_item|
×
NEW
972
            if Ops.get_string(ask_item, "stage", "initial") == stage &&
×
973
                Ops.greater_than(Ops.get_integer(ask_item, "dialog", 0), max)
NEW
974
              max = Ops.get_integer(ask_item, "dialog", 0)
×
975
            end
976
          end
977
          max = Ops.add(max, 1)
×
978
          askList = Builtins.add(
×
979
            askList,
980
            "dialog"   => max,
981
            "title"    => Convert.to_string(
982
              UI.QueryWidget(Id(:dialogTitle), :Value)
983
            ),
984
            "help"     => Convert.to_string(UI.QueryWidget(Id(:hlp), :Value)),
985
            "question" => _("Edit Question"),
986
            "element"  => 0,
987
            "stage"    => stage
988
          )
989
        end
990
        questions = []
×
991
        askList = Builtins.sort(askList) do |x, y|
×
992
          Ops.less_than(
×
993
            Ops.get_integer(x, "dialog", -2),
994
            Ops.get_integer(y, "dialog", -1)
995
          ) ||
NEW
996
            (Ops.get_integer(x, "dialog", -2) == Ops.get_integer(y, "dialog", -1) &&
×
997
              Ops.less_than(
998
                Ops.get_integer(x, "element", -2),
999
                Ops.get_integer(y, "element", -1)
1000
              ))
1001
        end
1002
        dialogs = []
×
1003
        done2 = { "initial" => [], "cont" => [] }
×
NEW
1004
        Builtins.foreach(askList) do |ask_item|
×
NEW
1005
          if Ops.get_string(ask_item, "stage", "initial") == stage &&
×
1006
              !Builtins.contains(
1007
                Ops.get(done2, stage, []),
1008
                Ops.get_integer(ask_item, "dialog", -1)
1009
              )
1010
            dialogs = Builtins.add(
×
1011
              dialogs,
1012
              Item(
1013
                Id(Ops.get_integer(ask_item, "dialog", -1)),
1014
                Ops.get_string(ask_item, "title", "")
1015
              )
1016
            )
1017
            Ops.set(
×
1018
              done2,
1019
              stage,
1020
              Builtins.add(
1021
                Ops.get(done2, stage, []),
1022
                Ops.get_integer(ask_item, "dialog", -1)
1023
              )
1024
            )
1025
          end
1026
        end
1027
        dialog_id = Convert.to_integer(
×
1028
          UI.QueryWidget(Id(:dialogs), :CurrentItem)
1029
        )
1030
        UI.ChangeWidget(Id(:dialogs), :Items, dialogs)
×
1031
        if ret == :stage_cont || ret == :stage_initial || dialog_id.nil?
×
1032
          UI.ChangeWidget(Id(:dialogs), :CurrentItem, 0)
×
1033
        else
1034
          UI.ChangeWidget(Id(:dialogs), :CurrentItem, dialog_id)
×
1035
        end
1036
        dialog_id = Convert.to_integer(
×
1037
          UI.QueryWidget(Id(:dialogs), :CurrentItem)
1038
        )
1039
        d2 = Builtins.filter(askList) do |dummy|
×
1040
          Ops.get_integer(dummy, "dialog", -2) == dialog_id &&
×
1041
            stage == Ops.get_string(dummy, "stage", "initital")
1042
        end
1043
        d2 = Builtins.sort(d2) do |x, y|
×
1044
          Ops.less_than(
×
1045
            Ops.get_integer(x, "element", -2),
1046
            Ops.get_integer(y, "element", -1)
1047
          )
1048
        end
1049
        UI.ChangeWidget(
×
1050
          Id(:dialogTitle),
1051
          :Value,
1052
          Ops.get_string(d2, [0, "title"], "")
1053
        )
1054
        UI.ChangeWidget(Id(:hlp), :Value, Ops.get_string(d2, [0, "help"], ""))
×
1055
        id_counter2 = 0
×
NEW
1056
        Builtins.foreach(d2) do |ask_item|
×
NEW
1057
          id_counter2 = Ops.get_integer(ask_item, "element", id_counter2)
×
UNCOV
1058
          questions = Builtins.add(
×
1059
            questions,
1060
            Item(Id(id_counter2), Ops.get_string(ask_item, "question", ""))
1061
          )
1062
          id_counter2 = Ops.add(id_counter2, 1)
×
1063
        end
1064
        UI.ChangeWidget(Id(:questions), :Items, questions)
×
1065
        UI.ChangeWidget(Id(:dialogs), :CurrentItem, dialog_id)
×
1066

1067
        AutoinstGeneral.askList = deep_copy(askList) if ret == :next
×
NEW
1068
        break if ret == :next || ret == :back || ret == :cancel
×
1069
      end
UNCOV
1070
      Convert.to_symbol(ret)
×
1071
    end
1072

1073
    # Dialog for General Settings
1074
    # @return [Symbol]
1075
    def generalSequence
1✔
1076
      dialogs = {
1077
        "mode" => lambda do
×
1078
          ModeDialog()
×
1079
        end,
1080
        "ask"  => lambda do
1081
          askDialog
×
1082
        end
1083
      }
1084

1085
      sequence = {
1086
        "ws_start" => "mode",
×
1087
        "mode"     => { next: "ask", abort: :abort },
1088
        "ask"      => { next: :finish }
1089
      }
1090
      # Translators: dialog caption
1091
      caption = _("General Settings")
×
1092
      contents = Label(_("Initializing ..."))
×
1093

1094
      Wizard.CreateDialog
×
1095
      Wizard.SetContents(caption, contents, "", true, true)
×
1096

1097
      ret = Sequencer.Run(dialogs, sequence)
×
1098

1099
      Wizard.CloseDialog
×
1100
      Builtins.y2milestone(" generalSequence returns: %1", ret)
×
1101
      Convert.to_symbol(ret)
×
1102
    end
1103
  end
1104
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc