Module: Yast::BootloaderRoutinesGlobalWidgetsInclude

Defined in:
src/include/bootloader/routines/global_widgets.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) CommonGlobalWidgets

Get general widgets for global bootloader options

Returns:

  • a map describing all general widgets for global options



315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
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
# File 'src/include/bootloader/routines/global_widgets.rb', line 315

def CommonGlobalWidgets
  if @_common_global_widgets != nil
    return deep_copy(@_common_global_widgets)
  end
  @_common_global_widgets = {
    "adv_button"     => getAdvancedButtonWidget,
    "loader_type"    => {
      "widget"            => :func,
      "widget_func"       => fun_ref(
        method(:LoaderTypeComboWidget),
        "term ()"
      ),
      "init"              => fun_ref(
        method(:LoaderTypeComboInit),
        "void (string)"
      ),
      "handle"            => fun_ref(
        method(:LoaderTypeComboHandle),
        "symbol (string, map)"
      ),
      "help"              => LoaderTypeHelp()
    },
    "loader_options" => {
      "widget"        => :push_button,
      # push button
      "label"         => _("Boot &Loader Options"),
      "handle_events" => ["loader_options"],
      "handle"        => fun_ref(
        method(:LoaderOptionsButtonHandle),
        "symbol (string, map)"
      ),
      "help"          => LoaderOptionsHelp()
    },
    #FIXME: after deleting all using of metadata delete widget from
    # from CommonGlobalWidgets the button is only for GRUB...
    "inst_details"   => {
      "widget"        => :push_button,
      # push button
      "label"         => _(
        "Boot Loader Installation &Details"
      ),
      "handle_events" => ["inst_details"],
      "handle"        => fun_ref(
        method(:InstDetailsButtonHandle),
        "symbol (string, map)"
      ),
      "help"          => InstDetailsHelp()
    }
  }



  deep_copy(@_common_global_widgets)
end

- (Object) getAdvancedButtonWidget

Get map of widget

Returns:

  • a map of widget



300
301
302
303
304
305
306
307
308
309
310
311
# File 'src/include/bootloader/routines/global_widgets.rb', line 300

def getAdvancedButtonWidget
  {
    "widget"        => :custom,
    "custom_widget" => ReplacePoint(Id(:adv_rp), VBox()),
    "handle"        => fun_ref(
      method(:resetButtonHandle),
      "symbol (string, map)"
    ),
    "init"          => fun_ref(method(:resetButtonInit), "void (string)"),
    "help"          => getAdvancedButtonHelp
  }
end

- (Object) GlobalOptionInit(widget)

Init function of widget

Parameters:

  • widget (String)

    string id of the widget



51
52
53
54
55
56
57
58
59
60
# File 'src/include/bootloader/routines/global_widgets.rb', line 51

def GlobalOptionInit(widget)
  return if widget == "adv_button"
  UI.ChangeWidget(
    Id(widget),
    :Value,
    Ops.get(BootCommon.globals, widget, "")
  )

  nil
end

- (Object) GlobalOptionStore(widget, event)

Store function of a widget

Parameters:

  • widget (String)

    string widget key

  • event (Hash)

    map event that caused the operation



65
66
67
68
69
70
71
72
73
74
75
# File 'src/include/bootloader/routines/global_widgets.rb', line 65

def GlobalOptionStore(widget, event)
  event = deep_copy(event)
  return if widget == "adv_button"
  Ops.set(
    BootCommon.globals,
    widget,
    Convert.to_string(UI.QueryWidget(Id(widget), :Value))
  )

  nil
end

- (Object) initialize_bootloader_routines_global_widgets(include_target)



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'src/include/bootloader/routines/global_widgets.rb', line 19

def initialize_bootloader_routines_global_widgets(include_target)
  textdomain "bootloader"

  Yast.import "CWM"
  Yast.import "CWMTab"
  Yast.import "CWMTable"
  Yast.import "Label"
  Yast.import "Mode"
  Yast.import "Storage"
  Yast.import "StorageDevices"
  Yast.import "Bootloader"
  Yast.import "Progress"
  Yast.import "PackageSystem"
  Yast.import "Package"
  Yast.import "Message"



  Yast.include include_target, "bootloader/routines/helps.rb"

  # Map of default (fallback) handlers for widget events on global widgets
  @global_handlers = {
    "init"  => fun_ref(method(:GlobalOptionInit), "void (string)"),
    "store" => fun_ref(method(:GlobalOptionStore), "void (string, map)")
  }

  # Cache for CommonGlobalWidgets function
  @_common_global_widgets = nil
end

- (Symbol) InstDetailsButtonHandle(widget, event)

Handle function of a widget

Parameters:

  • widget (String)

    string widget key

  • event (Hash)

    map event description of event that occured

Returns:

  • (Symbol)

    to return to wizard sequencer, or nil



81
82
83
84
85
86
87
88
89
# File 'src/include/bootloader/routines/global_widgets.rb', line 81

def InstDetailsButtonHandle(widget, event)
  event = deep_copy(event)
  lt = Bootloader.getLoaderType
  if lt == "none" || lt == "default"
    NoLoaderAvailable()
    return nil
  end
  :inst_details
end

- (Symbol) LoaderOptionsButtonHandle(widget, event)

Handle function of a widget

Parameters:

  • widget (String)

    string widget key

  • event (Hash)

    map event description of event that occured

Returns:

  • (Symbol)

    to return to wizard sequencer, or nil



95
96
97
98
99
100
101
102
103
# File 'src/include/bootloader/routines/global_widgets.rb', line 95

def LoaderOptionsButtonHandle(widget, event)
  event = deep_copy(event)
  lt = Bootloader.getLoaderType
  if lt == "none" || lt == "default"
    NoLoaderAvailable()
    return nil
  end
  :loader_details
end

- (Symbol) LoaderTypeComboHandle(key, event)

Handle function of a widget

Parameters:

  • key (String)

    any widget key

  • event (Hash)

    map event description of event that occured

Returns:

  • (Symbol)

    to return to wizard sequencer, or nil



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'src/include/bootloader/routines/global_widgets.rb', line 133

def LoaderTypeComboHandle(key, event)
  event = deep_copy(event)
  return if event["ID"] != key # FIXME can it happen at all?
  old_bl = Bootloader.getLoaderType
  new_bl = UI.QueryWidget(Id(key), :Value).to_s

  return nil if old_bl == new_bl

  if new_bl == "none"
    # popup - Continue/Cancel
    if Popup.ContinueCancel(
        _(
          "\n" +
            "If you do not install any boot loader, the system\n" +
            "might not start.\n" +
            "\n" +
            "Proceed?\n"
        )
      )
      BootCommon.setLoaderType("none")
      BootCommon.location_changed = true
    end
    return :redraw
  end

  if ["grub2", "grub2-efi"].include? (new_bl)
    BootCommon.setLoaderType(new_bl)
    Bootloader.Propose
    BootCommon.location_changed = true
    BootCommon.changed = true
    return :redraw
  end

  raise "Unexpected value of loader type '#{new_bl}'"
end

- (Object) LoaderTypeComboInit(widget)

Init function of widget

Parameters:

  • widget (String)

    string id of the widget



123
124
125
126
127
# File 'src/include/bootloader/routines/global_widgets.rb', line 123

def LoaderTypeComboInit(widget)
  UI.ChangeWidget(Id(widget), :Value, Bootloader.getLoaderType)

  nil
end

- (Yast::Term) LoaderTypeComboWidget

Get the widget for boot laoder selection combo

Returns:

  • (Yast::Term)

    the widget



109
110
111
112
113
114
115
116
117
118
119
# File 'src/include/bootloader/routines/global_widgets.rb', line 109

def LoaderTypeComboWidget
  ComboBox(
    Id("loader_type"),
    Opt(:notify),
    # combo box
    _("&Boot Loader"),
    Builtins.maplist(BootCommon.getBootloaders) do |l|
      Item(Id(l), BootCommon.getLoaderName(l, :combo))
    end
  )
end

- (Symbol) resetButtonHandle(widget, event)

Handle function of a widget

Parameters:

  • widget (String)

    any widget key

  • event (Hash)

    map event description of event that occured

Returns:

  • (Symbol)

    to return to wizard sequencer, or nil



249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
# File 'src/include/bootloader/routines/global_widgets.rb', line 249

def resetButtonHandle(widget, event)
  event = deep_copy(event)
  op = Ops.get(event, "ID")
  return :manual if op == :manual
  if op == :restore_mbr
    doit = restoreMBRPopup(BootCommon.mbrDisk)
    Builtins.y2milestone("Rewrite MBR with saved one: %1", doit)
    if doit
      ret = BootCommon.restoreMBR(BootCommon.mbrDisk)
      if ret
        # message popup
        Popup.Message(_("MBR restored successfully."))
      else
        # message popup
        Popup.Message(_("Failed to restore MBR."))
      end
    end
    return nil
  end

  if !(Ops.is_symbol?(op) &&
      Builtins.contains(
        [:scratch, :reread, :propose_deep, :propose],
        Convert.to_symbol(op)
      ))
    return nil
  end
  Bootloader.Reset
  if op == :scratch
    Builtins.y2debug("Not reading anything for starting from scratch")
  elsif op == :reread
    Bootloader.Read
  elsif op == :init
    # Bootloader::blSave (false, false, false);
    ret = BootCommon.InitializeBootloader
    ret = false if ret == nil

    Popup.Warning(_("Writing bootloader settings failed.")) if !ret
  elsif op == :propose
    Bootloader.Propose
  end

  :redraw
end

- (Object) resetButtonInit(widget)

Init function of widget

Parameters:

  • widget (String)

    any id of the widget



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
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
# File 'src/include/bootloader/routines/global_widgets.rb', line 174

def resetButtonInit(widget)
  items = []
  items = Builtins.add(
    items,
    Item(
      Id(:manual),
      # menu button entry
      _("E&dit Configuration Files")
    )
  )
  if BootCommon.getBooleanAttrib("propose")
    items = Builtins.add(
      items,
      # menubutton item, keep as short as possible
      Item(Id(:propose), _("&Propose New Configuration"))
    )
  end
  if BootCommon.getBooleanAttrib("scratch")
    items = Builtins.add(
      items,
      # menubutton item, keep as short as possible
      Item(Id(:scratch), _("&Start from Scratch"))
    )
  end
  if (Mode.normal || Mode.config || Mode.repair) &&
      BootCommon.getBooleanAttrib("read")
    items = Builtins.add(
      items,
      # menubutton item, keep as short as possible
      Item(Id(:reread), _("&Reread Configuration from Disk"))
    )
  end
  additional_entries = Convert.to_list(
    BootCommon.getAnyTypeAttrib("additional_entries", [])
  )
  items = Builtins.merge(items, additional_entries)

  if (Mode.normal || Mode.repair) &&
      BootCommon.getBooleanAttrib("restore_mbr") &&
      Ops.greater_than(
        SCR.Read(path(".target.size"), "/boot/backup_mbr"),
        0
      )
    items = Builtins.add(
      items,
      # menubutton item, keep as short as possible
      Item(Id(:restore_mbr), _("Restore MBR of Hard Disk"))
    )
  end

  if Mode.normal || Mode.repair
    items = Builtins.add(
      items,
      # menubutton item, keep as short as possible
      Item(Id(:init), _("Write bootloader boot code to disk"))
    )
  end

  if Ops.greater_than(Builtins.size(items), 0)
    UI.ReplaceWidget(
      Id(:adv_rp),
      # menu button
      MenuButton(Id(:reset), _("Other"), items)
    )
  else
    UI.ReplaceWidget(Id(:adv_rp), VSpacing(0))
  end

  nil
end