Class: Bootloader::Grub2Widget::ConsoleWidget

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

Overview

Represents graphical and serial console setup for bootloader

Allows to configure terminal for grub. It can configure grub to use either graphical terminal, console or console over serial line.

Graphical or serial terminal has to be selected explicitly. Either one of them or both at once. Native console is configured as a fallback when nothing else is selected.

Instance Method Summary collapse

Methods included from Grub2Helper

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

Constructor Details

#initializeConsoleWidget

Returns a new instance of ConsoleWidget.



615
616
617
618
619
# File 'src/lib/bootloader/grub2_widgets.rb', line 615

def initialize
  textdomain "bootloader"

  super
end

Instance Method Details

#contentsObject



621
622
623
624
625
626
# File 'src/lib/bootloader/grub2_widgets.rb', line 621

def contents
  VBox(
    graphical_console_frame,
    serial_console_frame
  )
end

#handle(event) ⇒ Object



697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
# File 'src/lib/bootloader/grub2_widgets.rb', line 697

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

#helpObject



628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
# File 'src/lib/bootloader/grub2_widgets.rb', line 628

def help
  # Translators: do not translate the quoted parts like "unit"
  _(
    "<p><b>Graphical console</b> when checked it allows to use various " \
    "display resolutions. The <tt>auto</tt> option tries to find " \
    "the best one when booting starts.</p>\n" \
    "<p><b>Serial console</b> when checked it redirects the boot output " \
    "to a serial device like <tt>ttyS0</tt>. " \
    "At least the <tt>--unit</tt> option has to be specified, " \
    "and the complete syntax is <tt>%s</tt>. " \
    "Other parts are optional and if not set, a default is used. " \
    "<tt>NUM</tt> in commands stands for a positive number like 8. " \
    "Example parameters are <tt>serial --speed=38400 --unit=0</tt>.</p>"
  ) % syntax
end

#initObject



644
645
646
647
648
649
650
651
# File 'src/lib/bootloader/grub2_widgets.rb', line 644

def init
  init_console
  init_gfxterm

  Yast::UI.ChangeWidget(Id(:theme), :Value, grub_default.theme || "")
rescue RuntimeError
  raise ::Bootloader::UnsupportedOption, "GRUB_TERMINAL"
end

#storeObject



675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
# File 'src/lib/bootloader/grub2_widgets.rb', line 675

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

  grub_default.terminal = []
  grub_default.terminal = [:gfxterm] if use_gfxterm

  if use_serial
    console_value = Yast::UI.QueryWidget(Id(:console_args), :Value)
    BootloaderFactory.current.enable_serial_console(console_value)
  elsif use_console
    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

#validateObject



653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
# File 'src/lib/bootloader/grub2_widgets.rb', line 653

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
    if ::Bootloader::SerialConsole.load_from_console_args(console_value).nil?
      # Translators: do not translate "unit"
      msg = _("To enable the serial console you must provide the corresponding arguments.\n" \
              "The \"unit\" argument is required, the complete syntax is:\n%s") % syntax
      Yast::Report.Error(msg)
      Yast::UI.SetFocus(Id(:console_args))
      return false
    end
  end
  true
end