Module: Yast::BootloaderGrubOptionsInclude

Defined in:
src/include/bootloader/grub/options.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) DisksOrderWidget



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
246
247
248
249
250
251
252
253
254
255
256
# File 'src/include/bootloader/grub/options.rb', line 213

def DisksOrderWidget
  contents = HBox(
    HSpacing(2),
    VBox(
      VSpacing(1),
      SelectionBox(Id(:disks), Opt(:notify), _("D&isks"), []),
      HBox(
        HStretch(),
        PushButton(Id(:add), Opt(:key_F3), Label.AddButton),
        PushButton(Id(:delete), Opt(:key_F5), Label.DeleteButton),
        HStretch()
      ),
      VSpacing(1)
    ),
    HSquash(
      VBox(
        VStretch(),
        PushButton(Id(:up), Opt(:hstretch), _("&Up")),
        PushButton(Id(:down), Opt(:hstretch), _("&Down")),
        VStretch()
      )
    ),
    HSpacing(2)
  )
  {
    "widget"            => :custom,
    "custom_widget"     => contents,
    "init"              => fun_ref(method(:InitDiskOrder), "void (string)"),
    "handle"            => fun_ref(
      method(:HandleDiskOrder),
      "symbol (string, map)"
    ),
    "store"             => fun_ref(
      method(:StoreDiskOrder),
      "void (string, map)"
    ),
    "help"              => Ops.get(@grub_help_messages, "disk_order", ""),
    "validate_type"     => :function,
    "validate_function" => fun_ref(
      method(:ValidateDiskOrder),
      "boolean (string, map)"
    )
  }
end

- (Object) GetItemID(t)



98
99
100
101
102
103
104
105
# File 'src/include/bootloader/grub/options.rb', line 98

def GetItemID(t)
  t = deep_copy(t)
  Ops.get_string(
    Builtins.argsof(Ops.get_term(Builtins.argsof(t), 0) { Id("") }),
    0,
    ""
  )
end

- (Yast::Term) grubBootLoaderLocationWidget

Create Frame “Boot Loader Location”

Returns:

  • (Yast::Term)

    with widgets



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
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
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
# File 'src/include/bootloader/grub/options.rb', line 402

def grubBootLoaderLocationWidget
  if BootStorage.can_boot_from_partition
    partition_boot = BootStorage.BootPartitionDevice == BootStorage.RootPartitionDevice ?
      Left(CheckBox(Id("boot_root"), _("Boot from &Root Partition"))) :
      Left(CheckBox(Id("boot_boot"), _("Boo&t from Boot Partition")))
  else
    partition_boot = Empty()
  end

  contents = VBox(
    VSpacing(1),
    Frame(
      _("Boot Loader Location"),
      VBox(
        HBox(
          HSpacing(1),
          VBox(
            Left(
              CheckBox(Id("boot_mbr"), _("Boot from &Master Boot Record"))
            ),
            partition_boot,
            BootStorage.ExtendedPartitionDevice ?
              Left(
                CheckBox(
                  Id("boot_extended"),
                  _("Boot from &Extended Partition")
                )
              ) :
              Empty()
          )
        )
      )
    ),
    VSpacing(1)
  )

  if !BootCommon.PartitionInstallable
    contents = VBox(
      Frame(
        _("Boot Loader Location"),
        VBox(
          HBox(
            HSpacing(1),
            VBox(
              Left(
                CheckBox(Id("boot_mbr"), _("Boot from &Master Boot Record"))
              ),
              Left(
                CheckBox(
                  Id("boot_custom"),
                  Opt(:notify),
                  _("C&ustom Boot Partition")
                )
              ),
              Left(
                ComboBox(
                  Id("boot_custom_list"),
                  Opt(:editable, :hstretch),
                  "",
                  []
                )
              ),
              VStretch()
            )
          )
        )
      ),
      VStretch()
    )
  end

  if BootCommon.VerifyMDArray
    contents = VBox(
      Frame(
        _("Boot Loader Location"),
        VBox(
          HBox(
            HSpacing(1),
            VBox(
              Left(
                CheckBox(Id("boot_mbr"), _("Boot from &Master Boot Record"))
              ),
              Left(
                CheckBox(
                  Id("enable_redundancy"),
                  _("Enable Red&undancy for MD Array")
                )
              ),
              Left(
                CheckBox(
                  Id("boot_custom"),
                  Opt(:notify),
                  _("C&ustom Boot Partition")
                )
              ),
              Left(
                ComboBox(
                  Id("boot_custom_list"),
                  Opt(:editable, :hstretch),
                  "",
                  []
                )
              ),
              VStretch()
            )
          )
        )
      ),
      VStretch()
    )
  end
  {
    "widget"        => :custom,
    "custom_widget" => contents,
    "init"          => fun_ref(
      method(:InitBootLoaderLocationWidget),
      "void (string)"
    ),
    "handle"        => fun_ref(
      method(:HandleBootLoaderLocationWidget),
      "symbol (string, map)"
    ),
    "store"         => fun_ref(
      method(:StoreBootLoaderLocationWidget),
      "void (string, map)"
    ),
    "help"          => HelpBootLoaderLocationWidget()
  }
end

- (Symbol) HandleBootLoaderLocationWidget(widget, event)

handle function of a widget

Parameters:

  • widget (String)

    string widget key

  • event (Hash)

    map event that caused the operation

Returns:

  • (Symbol)


319
320
321
322
323
324
325
326
327
328
329
330
# File 'src/include/bootloader/grub/options.rb', line 319

def HandleBootLoaderLocationWidget(widget, event)
  event = deep_copy(event)
  ret = Ops.get(event, "ID")
  if ret == "boot_custom"
    if Convert.to_boolean(UI.QueryWidget(Id("boot_custom"), :Value))
      UI.ChangeWidget(Id("boot_custom_list"), :Enabled, true)
    else
      UI.ChangeWidget(Id("boot_custom_list"), :Enabled, false)
    end
  end
  nil
end

- (Object) HandleDiskOrder(widget, event)



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'src/include/bootloader/grub/options.rb', line 151

def HandleDiskOrder(widget, event)
  action = event["ID"]
  changed = false
  disksOrder = UI.QueryWidget(Id(:disks), :Items)
  current = UI.QueryWidget(Id(:disks), :CurrentItem)
  pos = 0
  while pos < disksOrder.size &&
      GetItemID(disksOrder[pos] || term(:Item, Id(""))) != current
    pos += 1
  end
  Builtins.y2debug("Calling handle disk order with action #{action} and selected on pos #{pos}")


  case action
  when :up
    changed = true
	# swap elements
    disksOrder.insert(pos - 1, disksOrder.delete_at(pos))
    pos -= 1
  when :down
    changed = true
	# swap elements
    disksOrder.insert(pos + 1, disksOrder.delete_at(pos))
    pos += 1
  when :delete
    changed = true
    disksOrder = Builtins.remove(disksOrder, pos)
    pos = pos > 0 ? pos -1 : 0
    UI.ChangeWidget(
      Id(:disks),
      :CurrentItem,
      GetItemID(disksOrder[pos] || term(:Item, Id("")))
    )
  when :add
    new_dev = NewDevicePopup()
    if new_dev != ""
      changed = true
      disksOrder << Item(Id(new_dev), new_dev)
    end
  end

  #disabling & enabling up/down, do it after change
  UI.ChangeWidget(Id(:up), :Enabled, pos > 0 && pos < disksOrder.size)
  UI.ChangeWidget(Id(:down), :Enabled, pos < disksOrder.size - 1)

  UI.ChangeWidget(Id(:disks), :Items, disksOrder) if changed

  nil
end

- (Symbol) HandlePasswdWidget(widget, event)

Handle function of a widget

Parameters:

  • widget (String)

    string id of the widget

  • event (Hash)

    map event description of event that occured

Returns:

  • (Symbol)

    always nil



39
40
41
42
43
44
45
46
47
# File 'src/include/bootloader/grub/options.rb', line 39

def HandlePasswdWidget(widget, event)
  event = deep_copy(event)
  if Ops.get(event, "ID") == :use_pas
    enabled = Convert.to_boolean(UI.QueryWidget(Id(:use_pas), :Value))
    UI.ChangeWidget(Id(:pw1), :Enabled, enabled)
    UI.ChangeWidget(Id(:pw2), :Enabled, enabled)
  end
  nil
end

- (String) HelpBootLoaderLocationWidget

FIXME: merge help text to one for BootLoaderLocationWidget Function merge help text from ../grub/helps.ycp

Returns:

  • (String)

    help text for widget BootLoaderLocationWidget



377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
# File 'src/include/bootloader/grub/options.rb', line 377

def HelpBootLoaderLocationWidget
  ret = ""
  ret = Ops.get(@grub_help_messages, "boot_mbr", "")
  ret = Ops.add(ret, "\n")
  ret = Ops.add(ret, Ops.get(@grub_help_messages, "boot_custom", ""))
  ret = Ops.add(ret, "\n")
  if BootCommon.VerifyMDArray
    ret = Ops.add(
      ret,
      Ops.get(@grub_help_messages, "enable_redundancy", "")
    )
  else
    ret = Ops.add(ret, Ops.get(@grub_help_messages, "boot_root", ""))
    ret = Ops.add(ret, "\n")
    ret = Ops.add(ret, Ops.get(@grub_help_messages, "boot_boot", ""))
    ret = Ops.add(ret, "\n")
    ret = Ops.add(ret, Ops.get(@grub_help_messages, "boot_extended", ""))
  end
  ret
end

- (Object) InitBootLoaderLocationWidget(widget)

Init function of a widget

Parameters:

  • widget (String)

    string widget key



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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
# File 'src/include/bootloader/grub/options.rb', line 260

def InitBootLoaderLocationWidget(widget)
  boot_devices = BootStorage.getPartitionList(:boot, "grub")
  value = ""
  if BootCommon.VerifyMDArray
    if BootCommon.enable_md_array_redundancy
      UI.ChangeWidget(Id("enable_redundancy"), :Value, true)
    else
      UI.ChangeWidget(Id("enable_redundancy"), :Value, false)
    end

    value = Ops.get(BootCommon.globals, "boot_mbr")
    UI.ChangeWidget(Id("boot_mbr"), :Value, value == "true" ? true : false)
  else
    list_global_target_keys = [
      "boot_mbr",
      "boot_boot",
      "boot_root",
      "boot_extended"
    ]
    Builtins.foreach(list_global_target_keys) do |key|
      value = Ops.get(BootCommon.globals, key)
      if value != nil
        UI.ChangeWidget(Id(key), :Value, value == "true" ? true : false)
      end
    end
    UI.ChangeWidget(Id("boot_custom_list"), :Items, boot_devices)

    if BootStorage.BootPartitionDevice == BootStorage.RootPartitionDevice
      UI.ChangeWidget(Id("boot_boot"), :Enabled, false)
    else
      UI.ChangeWidget(Id("boot_boot"), :Enabled, true)
    end

    if BootStorage.ExtendedPartitionDevice != nil
      UI.ChangeWidget(Id("boot_extended"), :Enabled, true)
    else
      UI.ChangeWidget(Id("boot_extended"), :Enabled, false)
    end
  end

  if !Builtins.haskey(BootCommon.globals, "boot_custom") ||
      Ops.get(BootCommon.globals, "boot_custom", "") == ""
    UI.ChangeWidget(Id("boot_custom_list"), :Enabled, false)
  else
    UI.ChangeWidget(Id("boot_custom"), :Value, true)
    UI.ChangeWidget(Id("boot_custom_list"), :Enabled, true)
    UI.ChangeWidget(
      Id("boot_custom_list"),
      :Value,
      Ops.get(BootCommon.globals, "boot_custom", "")
    )
  end

  nil
end

- (Object) InitDiskOrder(widget)



89
90
91
92
93
94
95
96
# File 'src/include/bootloader/grub/options.rb', line 89

def InitDiskOrder(widget)
  disksOrder = BootStorage.DisksOrder

  UI.ChangeWidget(Id(:disks), :Items, disksOrder)
  UI.ChangeWidget(Id(:disks), :CurrentItem, Ops.get(disksOrder, 0, ""))

  nil
end

- (Object) initialize_bootloader_grub_options(include_target)



23
24
25
26
27
28
29
30
31
32
33
# File 'src/include/bootloader/grub/options.rb', line 23

def initialize_bootloader_grub_options(include_target)
  textdomain "bootloader"

  Yast.import "Label"
  Yast.import "BootStorage"

  Yast.include include_target, "bootloader/routines/common_options.rb"
  Yast.include include_target, "bootloader/routines/popups.rb"
  Yast.include include_target, "bootloader/routines/helps.rb"
  Yast.include include_target, "bootloader/grub/helps.rb"
end

- (Object) NewDevicePopup



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'src/include/bootloader/grub/options.rb', line 126

def NewDevicePopup
  popup = VBox(
    VSpacing(1),
    # textentry header
    InputField(Id(:devname), Opt(:hstretch), _("&Device")),
    VSpacing(1),
    HBox(
      HStretch(),
      PushButton(Id(:ok), Opt(:key_F10, :default), Label.OKButton),
      HStretch(),
      PushButton(Id(:cancel), Opt(:key_F8), Label.CancelButton),
      HStretch()
    ),
    VSpacing(1)
  )
  UI.OpenDialog(popup)
  UI.SetFocus(:devname)
  pushed = UI.UserInput
  new_dev = UI.QueryWidget(Id(:devname), :Value)
  UI.CloseDialog

  pushed == :ok ? new_dev : ""
end

- (Object) passwd_content



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'src/include/bootloader/grub/options.rb', line 69

def passwd_content
  HBox(
    CheckBoxFrame(
      Id(:use_pas),
      _("Prot&ect Boot Loader with Password"),
      true,
      HBox(
        HSpacing(2),
        # text entry
        Password(Id(:pw1), Opt(:hstretch), _("&Password")),
        # text entry
        HSpacing(2),
        Password(Id(:pw2), Opt(:hstretch), _("Re&type Password")),
        HStretch()
      )
    )
  )
end

- (Object) StoreBootLoaderLocationWidget(widget, event)

Store function of a widget

Parameters:

  • widget (String)

    string widget key

  • event (Hash)

    map event that caused the operation



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
# File 'src/include/bootloader/grub/options.rb', line 336

def StoreBootLoaderLocationWidget(widget, event)
  event = deep_copy(event)
  if BootCommon.VerifyMDArray
    BootCommon.enable_md_array_redundancy = Convert.to_boolean(
      UI.QueryWidget(Id("enable_redundancy"), :Value)
    )
    Ops.set(
      BootCommon.globals,
      "boot_mbr",
      Convert.to_boolean(UI.QueryWidget(Id("boot_mbr"), :Value)) ? "true" : "false"
    )
  else
    list_global_target_keys = [
      "boot_mbr",
      "boot_boot",
      "boot_root",
      "boot_extended"
    ]
    Builtins.foreach(list_global_target_keys) do |key|
      value = Convert.to_boolean(UI.QueryWidget(Id(key), :Value)) ? "true" : "false"
      Ops.set(BootCommon.globals, key, value)
    end
  end
  if Convert.to_boolean(UI.QueryWidget(Id("boot_custom"), :Value))
    Ops.set(
      BootCommon.globals,
      "boot_custom",
      Convert.to_string(UI.QueryWidget(Id("boot_custom_list"), :Value))
    )
  else
    #bnc#544809 Custom Boot Partition cannot be deleted
    Ops.set(BootCommon.globals, "boot_custom", "")
  end

  nil
end

- (Object) StoreDiskOrder(widget, event)



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'src/include/bootloader/grub/options.rb', line 107

def StoreDiskOrder(widget, event)
  event = deep_copy(event)
  disksOrder = Convert.convert(
    UI.QueryWidget(Id(:disks), :Items),
    :from => "any",
    :to   => "list <term>"
  )
  result = Builtins.maplist(disksOrder) { |t| GetItemID(t) }
  BootCommon.mbrDisk = Ops.get(result, 0, "")
  index = 0
  BootStorage.device_mapping = Builtins.listmap(result) do |d|
    indexs = Builtins.tostring(index)
    index = Ops.add(index, 1)
    { d => Builtins.sformat("hd%1", indexs) }
  end

  nil
end

- (Object) ValidateDiskOrder(key, event)



201
202
203
204
205
206
207
208
209
210
211
# File 'src/include/bootloader/grub/options.rb', line 201

def ValidateDiskOrder(key, event)
  event = deep_copy(event)
  disksOrder = Convert.convert(
    UI.QueryWidget(Id(:disks), :Items),
    :from => "any",
    :to   => "list <term>"
  )
  return true if Ops.greater_than(Builtins.size(disksOrder), 0)
  Popup.Warning(_("Device map must contain at least one device"))
  false
end

- (Boolean) ValidatePasswdWidget(key, event)

Validate function of a popup

Parameters:

  • key (String)

    any widget key

  • event (Hash)

    map event that caused validation

Returns:

  • (Boolean)

    true if widget settings ok



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'src/include/bootloader/grub/options.rb', line 53

def ValidatePasswdWidget(key, event)
  event = deep_copy(event)
  return true if !Convert.to_boolean(UI.QueryWidget(Id(:use_pas), :Value))
  if UI.QueryWidget(Id(:pw1), :Value) == ""
    emptyPasswdErrorPopup
    UI.SetFocus(Id(:pw1))
    return false
  end
  if UI.QueryWidget(Id(:pw1), :Value) == UI.QueryWidget(Id(:pw2), :Value)
    return true
  end
  passwdMissmatchPopup
  UI.SetFocus(Id(:pw1))
  false
end