Class: Bootloader::ConsoleWidget

Inherits:
CWM::CustomWidget
  • Object
show all
Includes:
Grub2Widget
Defined in:
src/lib/bootloader/grub2_widgets.rb

Overview

Represents graphical and serial console for bootloader

Instance Method Summary (collapse)

Methods included from Grub2Widget

#grub2, #grub_default, #password, #sections, #stage1

Constructor Details

- (ConsoleWidget) initialize

Returns a new instance of ConsoleWidget



446
447
448
# File 'src/lib/bootloader/grub2_widgets.rb', line 446

def initialize
  textdomain "bootloader"
end

Instance Method Details

- (Object) contents



450
451
452
453
454
455
# File 'src/lib/bootloader/grub2_widgets.rb', line 450

def contents
  VBox(
    graphical_console_frame,
    serial_console_frame
  )
end

- (Object) handle(event)



511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
# File 'src/lib/bootloader/grub2_widgets.rb', line 511

def handle(event)
  return if event["ID"] != :browsegfx

  theme_dir = "/boot/grub2/themes/openSUSE"
  theme_dir = "/boot/grub2" unless ::Dir.exist?(theme_dir)

  file = Yast::UI.AskForExistingFile(
    theme_dir,
    "*.txt",
    _("Choose new graphical theme file")
  )

  Yast::UI.ChangeWidget(Id(:theme), :Value, file) if file

  nil
end

- (Object) init



457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
# File 'src/lib/bootloader/grub2_widgets.rb', line 457

def init
  enable = grub_default.terminal == :serial
  Yast::UI.ChangeWidget(Id(:console_frame), :Value, enable)
  args = grub_default.serial_console || ""
  Yast::UI.ChangeWidget(Id(:console_args), :Value, args)

  enable = grub_default.terminal == :gfxterm
  Yast::UI.ChangeWidget(Id(:gfxterm_frame), :Value, enable)

  Yast::UI.ChangeWidget(Id(:gfxmode), :Items, vga_modes_items)
  mode = grub_default.gfxmode

  # there's mode specified, use it
  Yast::UI.ChangeWidget(Id(:gfxmode), :Value, mode) if mode && mode != ""

  Yast::UI.ChangeWidget(Id(:theme), :Value, grub_default.theme || "")
end

- (Object) store



489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
# File 'src/lib/bootloader/grub2_widgets.rb', line 489

def store
  use_serial = Yast::UI.QueryWidget(Id(:console_frame), :Value)
  use_gfxterm = Yast::UI.QueryWidget(Id(:gfxterm_frame), :Value)

  use_gfxterm = false if use_gfxterm && use_serial

  if use_serial
    console_value = Yast::UI.QueryWidget(Id(:console_args), :Value)
    BootloaderFactory.current.enable_serial_console(console_value)
  elsif use_gfxterm
    grub_default.terminal = :gfxterm
  else
    grub_default.terminal = :console
  end

  mode = Yast::UI.QueryWidget(Id(:gfxmode), :Value)
  grub_default.gfxmode = mode if mode != ""

  theme = Yast::UI.QueryWidget(Id(:theme), :Value)
  grub_default.theme = theme if theme != ""
end

- (Object) validate



475
476
477
478
479
480
481
482
483
484
485
486
487
# File 'src/lib/bootloader/grub2_widgets.rb', line 475

def validate
  if Yast::UI.QueryWidget(Id(:console_frame), :Value)
    console_value = Yast::UI.QueryWidget(Id(:console_args), :Value)
    if console_value.strip.empty?
      Yast::Report.Error(
        _("To enable serial console you must provide the corresponding arguments.")
      )
      Yast::UI.SetFocus(Id(:console_args))
      return false
    end
  end
  true
end