ACC SHELL

Path : /proc/self/root/usr/share/YaST2/include/bootloader/routines/
File Upload :
Current File : //proc/self/root/usr/share/YaST2/include/bootloader/routines/dialogs.ycp

/**
 * File:
 *      include/bootloader/routines/ui.ycp
 *
 * Module:
 *      Bootloader installation and configuration
 *
 * Summary:
 *      User interface for bootloader installation/configuration
 *
 * Authors:
 *      Jiri Srain <jsrain@suse.cz>
 *
 * $Id: dialogs.ycp 58289 2009-08-06 11:50:12Z juhliarik $
 *
 */


{
textdomain "bootloader";

import "BootCommon";
import "CWM";
import "Label";
import "Mode";
import "Popup";
import "Wizard";
import "Bootloader";
import "Stage";

include "bootloader/routines/popups.ycp";
include "bootloader/routines/section_widgets.ycp";
include "bootloader/routines/global_widgets.ycp";

/**
 * Test for abort.
 * @return true if abort was pressed
 */
boolean testAbort () {
    if (Mode::commandline ())
	return false;
    if (`abort == UI::PollInput ())
    {
	if (! Stage::initial ())
	    UI::CloseDialog ();
	return true;
    }
    return false;
}

/**
 * Read settings dialog
 * @return `abort if aborted and `next otherwise
 */
symbol ReadDialog() {
    Bootloader::test_abort = testAbort;
    Wizard::RestoreHelp (getInitProgressHelp ());
    boolean ret = Bootloader::Read();
    return ret ? `next : `abort;
}

/**
 * Write settings dialog
 * @return `abort if aborted and `next otherwise
 */
symbol WriteDialog() {
    if (! Stage::initial ())
	Bootloader::test_abort = testAbort;
    Wizard::RestoreHelp (getSaveProgressHelp ());
    boolean ret = Bootloader::Write();
    return ret ? `next : `abort;
}


string return_tab = "sections";


/**
 * Run dialog for kernel section editation
 * @return symbol for wizard sequencer
 */
symbol MainDialog () {
    y2milestone ("Running Main Dialog");
    term contents = `VBox (
	"tab",
	`Right ("adv_button")
    );

    // F#300779 - Install diskless client (NFS-root) 
    // kokso: additional warning that root partition is nfs type -> bootloader will not be installed
    string device = BootCommon::getBootDisk();

    if ((device == "/dev/nfs") && (Mode::installation()))
    {
	Popup::Message(_("The boot partition is of type NFS. Bootloader cannot be installed."));
        y2milestone("dialogs::MainDialog() -> Boot partition is nfs type, bootloader will not be installed.");
	return `next;
    }
    // F#300779: end

    list<string> widget_names = ["tab", "adv_button"];
    map<string,map<string,any> > widget_descr = $[];
    widget_descr = (map<string,map<string,any> >) union (CommonGlobalWidgets (), Bootloader::blWidgetMaps ());

    widget_descr["tab"] = CWMTab::CreateWidget($[
	"tab_order": ["sections", "installation"],
	"tabs": TabsDescr (),
	"widget_descr": widget_descr,
	"initial_tab" : return_tab,
    ]);
    widget_descr["tab", "no_help"] = "";

    // dialog caption
    string caption = _("Boot Loader Settings");
    symbol ret = CWM::ShowAndRun ($[
	"widget_descr" : widget_descr,
	"widget_names" : widget_names,
	"contents" : contents,
	"caption" : caption,
	"back_button" : "",
	"abort_button" :Label::CancelButton (),
	"next_button" : Label::OKButton (),
	"fallback_functions" : global_handlers,
    ]);
    if (ret != `back && ret != `abort && ret != `cancel)
    {
	return_tab = CWMTab::LastTab ();
    }
    return ret;
}

/**
 * Run dialog with detailed settings
 * @param type string specification of the type of detail settings
 * @return symbol for wizard sequencer
 */
symbol DetailsDialog (string type) {
    map<string,symbol()> dialogs = Bootloader::blDialogs ();
    if (! haskey (dialogs, type))
    {
	Report::Message (
	    // message
	    _("There are no options to set for the current boot loader."));
	return `back;
    }
    symbol () dialog = (symbol())dialogs[type]:nil;
    return dialog ();
}

/**
 * Run dialog for kernel section editation
 * @return symbol for wizard sequencer
 */
symbol CommonKernelSectionDialog () {
    y2milestone ("Running kernel section dialog");
    string lt = Bootloader::getLoaderType ();
    term contents = `HBox (`HSpacing (2), `VBox (
        `VStretch (),
	// heading
        `Left (`Heading (_("Kernel Section"))),
	`VSpacing (1),
	"name",
        `VStretch (),
	// frame
        `Frame (_("Section Settings"), `HBox (`HSpacing (2), `VBox (
            `VSpacing (1),
	    `HBox 
	    (
            	`Left("noverifyroot"),
		`HSpacing(2),
	    	`Left("enable_selinux")
	    ),
	    "image",
	    "initrd",
            `HBox (
		`HWeight (1, "root"),
		`HWeight (1, "vgamode")
	    ),
	    "append",
            `VSpacing (1)
        ), `HSpacing (2))),
        `VStretch ()
    ), `HSpacing (2));

    list<string> widget_names = ["name", "image", "initrd", "root", "vgamode", "append"
                                ,"noverifyroot", "enable_selinux"];

    map<string,map<string,any> > widget_descr = $[];
    if (lt != "grub")
       widget_descr = (map<string,map<string,any> >) union (CommonSectionWidgets (), Bootloader::blWidgetMaps ());
    else
       widget_descr = (map<string,map<string,any> >) union (CommonGlobalWidgets (), CommonSectionWidgets ());


   // dialog caption
    string caption = _("Boot Loader Settings: Section Management");
    return CWM::ShowAndRun ($[
	"widget_descr" : widget_descr,
	"widget_names" : widget_names,
	"contents" : contents,
	"caption" : caption,
	"back_button" : Label::BackButton (),
	"abort_button" : Label::CancelButton (),
	"next_button" : Label::OKButton (),
	"fallback_functions" : section_handlers,
    ]);
}

/**
 * Run dialog for kernel section editation
 * @return symbol for wizard sequencer
 */
symbol PpcIseriesKernelSectionDialog () {
    y2milestone ("Running kernel section dialog");
    term contents = `HBox (`HSpacing (2), `VBox (
        `VStretch (),
	// heading
        `Left (`Heading (_("Kernel Section"))),
	`VSpacing (1),
	"name",
        `VStretch (),
	// frame
        `Frame (_("Section Settings"), `HBox (`HSpacing (2), `VBox (
            `VSpacing (1),
	    `HBox 
	    (
            	`Left("optional"),
		`HSpacing(2),
	    	`Left("enable_selinux")
	    ),
	    "image",
	    "initrd",
            "root",
	    "append",
            `Left("copy"),
            `VSpacing (1)
        ), `HSpacing (2))),
        `VStretch ()
    ), `HSpacing (2));

    list<string> widget_names = ["name", "image", "initrd", "root", "optional",
      "append", "copy", "enable_selinux"];

    map<string,map<string,any> > widget_descr = $[];
    widget_descr = (map<string,map<string,any> >) union (CommonGlobalWidgets (), CommonSectionWidgets ());


   // dialog caption
    string caption = _("Boot Loader Settings: Section Management");
    return CWM::ShowAndRun ($[
	"widget_descr" : widget_descr,
	"widget_names" : widget_names,
	"contents" : contents,
	"caption" : caption,
	"back_button" : Label::BackButton (),
	"abort_button" : Label::CancelButton (),
	"next_button" : Label::OKButton (),
	"fallback_functions" : section_handlers,
    ]);
}
/**
 * Run dialog for kernel section editation
 * @return symbol for wizard sequencer
 */
symbol PpcKernelSectionDialog () {
    y2milestone ("Running kernel section dialog");
    term contents = `HBox (`HSpacing (2), `VBox (
        `VStretch (),
	// heading
        `Left (`Heading (_("Kernel Section"))),
	`VSpacing (1),
	"name",
        `VStretch (),
	// frame
        `Frame (_("Section Settings"), `HBox (`HSpacing (2), `VBox (
            `VSpacing (1),
            `HBox 
	    (
            	`Left("optional"),
		`HSpacing(2),
	    	`Left("enable_selinux")
	    ),
	    "image",
	    "initrd",
            "root",
	    "append",
            `VSpacing (1)
        ), `HSpacing (2))),
        `VStretch ()
    ), `HSpacing (2));

    list<string> widget_names = ["name", "image", "initrd", "root", "optional",
      "append", "enable_selinux"];

    map<string,map<string,any> > widget_descr = $[];
    widget_descr = (map<string,map<string,any> >) union (CommonGlobalWidgets (), CommonSectionWidgets ());


   // dialog caption
    string caption = _("Boot Loader Settings: Section Management");
    return CWM::ShowAndRun ($[
	"widget_descr" : widget_descr,
	"widget_names" : widget_names,
	"contents" : contents,
	"caption" : caption,
	"back_button" : Label::BackButton (),
	"abort_button" : Label::CancelButton (),
	"next_button" : Label::OKButton (),
	"fallback_functions" : section_handlers,
    ]);
}

symbol ZiplKernelSectionDialog () {
    y2milestone ("Running kernel section dialog");
    string lt = Bootloader::getLoaderType ();
    term contents = `HBox (`HSpacing (2), `VBox (
        `VStretch (),
	// heading
        `Left (`Heading (_("Kernel Section"))),
	`VSpacing (1),
	"name",
        `VStretch (),
	// frame
        `Frame (_("Section Settings"), `HBox (`HSpacing (2), `VBox (
            `VSpacing (1),
	    `Left("enable_selinux"),
            "target",
	    "image",
	    "initrd",
	    "root",
	    "append",
            "parmfile",
            `VSpacing (1)
        ), `HSpacing (2))),
        `VStretch ()
    ), `HSpacing (2));

    list<string> widget_names = ["name", "image", "initrd", "root",  "append"
                                ,"parmfile","target", "enable_selinux"];

    map<string,map<string,any> > widget_descr = $[];
    widget_descr = (map<string,map<string,any> >) union (CommonGlobalWidgets (), CommonSectionWidgets ());


   // dialog caption
    string caption = _("Boot Loader Settings: Section Management");
    return CWM::ShowAndRun ($[
	"widget_descr" : widget_descr,
	"widget_names" : widget_names,
	"contents" : contents,
	"caption" : caption,
	"back_button" : Label::BackButton (),
	"abort_button" : Label::CancelButton (),
	"next_button" : Label::OKButton (),
	"fallback_functions" : section_handlers,
    ]);
}

symbol KernelSectionDialog() {
  string bootloader = Bootloader::getLoaderType();
  if (bootloader == "zipl"){
    return ZiplKernelSectionDialog();
  } else if (bootloader == "ppc"){
    if (Arch::board_iseries()){
      return PpcIseriesKernelSectionDialog();
    } else {
      return PpcKernelSectionDialog();
    }
  } else{
    return CommonKernelSectionDialog();
  }
}

symbol XenSectionDialog () {
    y2milestone ("Running kernel section dialog");
    string lt = Bootloader::getLoaderType ();
    term contents = `HBox (`HSpacing (2), `VBox (
        `VStretch (),
	// heading
        `Left (`Heading (_("Xen Section"))),
	`VSpacing (1),
	"name",
        `VStretch (),
	// frame
        `Frame (_("Section Settings"), `HBox (`HSpacing (2), `VBox (
            `VSpacing (1),
            "xen",
	    "image",
	    "initrd",
            `HBox (
		`HWeight (1, "root"),
		`HWeight (1, "vgamode")
	    ),
	    "append",
            "xen_append",
            `VSpacing (1)
        ), `HSpacing (2))),
        `VStretch ()
    ), `HSpacing (2));

    list<string> widget_names = ["name", "image", "initrd", "root", "vgamode", "append"
                                ,"xen_append","xen"];
    map<string,map<string,any> > widget_descr = $[];
    if (lt != "grub")
       widget_descr = (map<string,map<string,any> >) union (CommonSectionWidgets (), Bootloader::blWidgetMaps ());
    else
       widget_descr = (map<string,map<string,any> >) union (CommonGlobalWidgets (), CommonSectionWidgets ());
   // dialog caption
    string caption = _("Boot Loader Settings: Section Management");
    return CWM::ShowAndRun ($[
	"widget_descr" : widget_descr,
	"widget_names" : widget_names,
	"contents" : contents,
	"caption" : caption,
	"back_button" : Label::BackButton (),
	"abort_button" : Label::CancelButton (),
	"next_button" : Label::OKButton (),
	"fallback_functions" : section_handlers,
    ]);
}

symbol GrubMenuSectionDialog () {
    y2milestone ("Running kernel section dialog");
    string lt = Bootloader::getLoaderType ();
    term contents = `HBox (`HSpacing (2), `VBox (
        `VStretch (),
	// heading
        `Left (`Heading (_("Menu Section"))),
	`VSpacing (1),
	"name",
        `VStretch (),
	// frame
        `Frame (_("Section Settings"), `HBox (`HSpacing (2), `VBox (
            `VSpacing (1),
            "root",
	    "configfile",
            `VSpacing (1)
        ), `HSpacing (2))),
        `VStretch ()
    ), `HSpacing (2));

    list<string> widget_names = ["name", "root", "configfile"];
    map<string,map<string,any> > widget_descr = $[];
    widget_descr = (map<string,map<string,any> >) union (CommonGlobalWidgets (), CommonSectionWidgets ());
   // dialog caption
    string caption = _("Boot Loader Settings: Section Management");
    return CWM::ShowAndRun ($[
	"widget_descr" : widget_descr,
	"widget_names" : widget_names,
	"contents" : contents,
	"caption" : caption,
	"back_button" : Label::BackButton (),
	"abort_button" : Label::CancelButton (),
	"next_button" : Label::OKButton (),
	"fallback_functions" : section_handlers,
    ]);
}

symbol ZiplMenuSectionDialog () {
    y2milestone ("Running kernel section dialog");
    term contents = `HBox (`HSpacing (2), `VBox (
        `VStretch (),
	// heading
        `Left (`Heading (_("Menu Section"))),
	`VSpacing (1),
	"name",
        `VStretch (),
	// frame
        `Frame (_("Section Settings"), `HBox (`HSpacing (2), `VBox (
            `VSpacing (1),
            "target",
	    "list",
	    "default",
	    "timeout",
            `Left("prompt"),
            `VSpacing (1)
        ), `HSpacing (2))),
        `VStretch ()
    ), `HSpacing (2));

    list<string> widget_names = ["name", "target", "default","list","timeout","prompt"];
    map<string,map<string,any> > widget_descr = $[];
    widget_descr = (map<string,map<string,any> >) union (CommonGlobalWidgets (), CommonSectionWidgets ());
   // dialog caption
    string caption = _("Boot Loader Settings: Section Management");
    return CWM::ShowAndRun ($[
	"widget_descr" : widget_descr,
	"widget_names" : widget_names,
	"contents" : contents,
	"caption" : caption,
	"back_button" : Label::BackButton (),
	"abort_button" : Label::CancelButton (),
	"next_button" : Label::OKButton (),
	"fallback_functions" : section_handlers,
    ]);
}

symbol DumpSectionDialog () {
    y2milestone ("Running kernel section dialog");
    term contents = `HBox (`HSpacing (2), `VBox (
        `VStretch (),
	// heading
        `Left (`Heading (_("Dump Section"))),
	`VSpacing (1),
	"name",
        `VStretch (),
	// frame
        `Frame (_("Section Settings"), `HBox (`HSpacing (2), `VBox (
            `VSpacing (1),
            "target",
	    "dumpto",
	    "dumptofs",
            `VSpacing (1)
        ), `HSpacing (2))),
        `VStretch ()
    ), `HSpacing (2));

    list<string> widget_names = ["name", "target", "dumpto","dumptofs"];
    map<string,map<string,any> > widget_descr = $[];
    widget_descr = (map<string,map<string,any> >) union (CommonGlobalWidgets (), CommonSectionWidgets ());
   // dialog caption
    string caption = _("Boot Loader Settings: Section Management");
    return CWM::ShowAndRun ($[
	"widget_descr" : widget_descr,
	"widget_names" : widget_names,
	"contents" : contents,
	"caption" : caption,
	"back_button" : Label::BackButton (),
	"abort_button" : Label::CancelButton (),
	"next_button" : Label::OKButton (),
	"fallback_functions" : section_handlers,
    ]);
}

symbol MenuSectionDialog() {
  string bootloader = Bootloader::getLoaderType();
  if (bootloader == "grub"){
    return GrubMenuSectionDialog();
  } else if (bootloader == "zipl"){
    return ZiplMenuSectionDialog();
  }
}

symbol PPCChainloaderSectionDialog () {
    y2milestone ("Running chainloader section dialog");
    string lt = Bootloader::getLoaderType ();
    term contents = `HBox (`HSpacing (4), `VBox (
	// label
        `Left (`Heading (_("Other System Section"))),
        `VSpacing (2),
	"name",
        `VStretch (),
        // part two - section settings
        `HBox (
	// frame
        `Frame (_("Section Settings"), `HBox (`HSpacing (2), `VBox (
            `VSpacing (2),
            `Left("other"),
            `VSpacing (2)
        ), `HSpacing (2)))),
        `VStretch ()
    ), `HSpacing (4));

    list<string> widget_names = ["name", "other"]; 
    map<string,map<string,any> > widget_descr = $[];

    widget_descr = (map<string,map<string,any> >) union (CommonGlobalWidgets (), CommonSectionWidgets ());


    // dialog caption
    string caption = _("Boot Loader Settings: Section Management");
    return CWM::ShowAndRun ($[
	"widget_descr" : widget_descr,
	"widget_names" : widget_names,
	"contents" : contents,
	"caption" : caption,
	"back_button" : Label::BackButton (),
	"abort_button" : Label::CancelButton (),
	"next_button" : Label::OKButton (),
	"fallback_functions" : section_handlers,
    ]);
}
/**
 * Run dialog for kernel section editation
 * @return symbol for wizard sequencer
 */
symbol CommonChainloaderSectionDialog () {
    y2milestone ("Running chainloader section dialog");
    string lt = Bootloader::getLoaderType ();
    term contents = `HBox (`HSpacing (4), `VBox (
	// label
        `Left (`Heading (_("Other System Section"))),
        `VSpacing (2),
	"name",
        `VStretch (),
        // part two - section settings
        `HBox (
	// frame
        `Frame (_("Section Settings"), `HBox (`HSpacing (2), `VBox (
            `VSpacing (2),
            `Left("chainloader"),
            `Left("makeactive"),
            `Left("noverifyroot"),
            `Left("remap"),
            `Left(`HSquash("blockoffset")),
            `VSpacing (2)
        ), `HSpacing (2)))),
        `VStretch ()
    ), `HSpacing (4));

    list<string> widget_names = ["name", "chainloader", "makeactive", 
        "noverifyroot", "remap", "blockoffset"];
    map<string,map<string,any> > widget_descr = $[];

    if (lt != "grub")
       widget_descr = (map<string,map<string,any> >) union (CommonGlobalWidgets (), Bootloader::blWidgetMaps ());
    else
       widget_descr = (map<string,map<string,any> >) union (CommonGlobalWidgets (), CommonSectionWidgets ());


    // dialog caption
    string caption = _("Boot Loader Settings: Section Management");
    return CWM::ShowAndRun ($[
	"widget_descr" : widget_descr,
	"widget_names" : widget_names,
	"contents" : contents,
	"caption" : caption,
	"back_button" : Label::BackButton (),
	"abort_button" : Label::CancelButton (),
	"next_button" : Label::OKButton (),
	"fallback_functions" : section_handlers,
    ]);
}

symbol ChainloaderSectionDialog () {
  if ( Bootloader::getLoaderType() == "ppc" ){
    return PPCChainloaderSectionDialog();
  } else {
    return CommonChainloaderSectionDialog();
  }
}

/**
 * Run dialog for kernel section editation
 * @return symbol for wizard sequencer
 */
symbol AddNewSectionDialog () {
    y2milestone ("Running new section dialog");
    string lt = Bootloader::getLoaderType ();
    term contents = `HBox (`HStretch (), `VBox (
	`VStretch (),
	"section_type",
	`VStretch ()
    ), `HStretch ());

    list<string> widget_names = ["section_type"];
    map<string,map<string,any> > widget_descr = $[];
    if (lt == "ppc" )
       widget_descr = (map<string,map<string,any> >) union (CommonGlobalWidgets (), Bootloader::blWidgetMaps ());
    else
       widget_descr = (map<string,map<string,any> >) union (CommonGlobalWidgets (), CommonSectionWidgets ());

    // dialog caption
    string caption = _("Boot Loader Settings: Section Management");
    return CWM::ShowAndRun ($[
	"widget_descr" : widget_descr,
	"widget_names" : widget_names,
	"contents" : contents,
	"caption" : caption,
	"back_button" : Label::BackButton (),
	"abort_button" : Label::CancelButton (),
	"next_button" : Label::NextButton (),
    ]);
}

/**
 * Switch the section type to be edited
 * @return symbol for wizard sequencer to determine which dialog to show
 */
symbol EditSectionSwitch () {
    string type = BootCommon::current_section["type"]:"";
    if (type == "chainloader" || type == "other")
	return `chainloader;
    if (type == "xen")
        return `xen;
    if (type == "menu")
        return `menus;
    if (type == "dump")
        return `dump;
    if (type == "image")
	return `kernel;
    else
	return `kernel;
}

/**
 * Store the modified section
 * @return symbol always `next
 */
symbol StoreSection () {
    BootCommon::current_section["__changed"] = true;
    if (BootCommon::current_section["type"]:"" == "xen")
    {
       BootCommon::current_section = (map<string,any>)union (
           $[
	       // bug #400526 there is not xenpae anymore...
               "xen" : "/boot/xen.gz",
               "xen_append" : "",
           ],
           BootCommon::current_section);
    }
    y2milestone ("Storing section: index:  %1, contents: %2",
	BootCommon::current_section_index,
	BootCommon::current_section);
    if (BootCommon::current_section_index == -1)
    {
	BootCommon::sections
	    = add (BootCommon::sections, BootCommon::current_section);
    }
    else
    {
	BootCommon::sections[BootCommon::current_section_index]
	    = BootCommon::current_section;
    }
    return `next;
}

    /**
      * Run dialog
      * @return symbol for wizard sequencer
      */
    symbol runEditFilesDialog () ``{
	Bootloader::blSave (false, false, false);
	map<string,string> files = BootCommon::GetFilesContents ();
	string defaultv = files["default"]:"";
	files = filter (string k, string v, files, ``(k != "default"));
        list filenames = [];
        foreach (string k, string v, files, ``{
            filenames = add (filenames, k);
        });
	term cb = nil;
	if (size (files) > 1)
	    cb = `ComboBox (`id (`filename), `opt (`notify, `hstretch),
		// combobox label
		_("&Filename"), filenames);
	else
	    // label. %1 is name of file (eg. /etc/lilo.conf
	    cb = `Left (`Label (sformat (_("Filename: %1"), filenames[0]:"")));

	term contents = `HBox (`HSpacing (2), `VBox (
            `VSpacing (2),
	    cb,
            `VSpacing (2),
            `MultiLineEdit (`id (`file), `opt (`hstretch, `vstretch),
		// multiline edit header
                _("Fi&le Contents")),
            `VSpacing (2)
	), `HSpacing (2));

	// dialog caption
        string caption = _("Expert Manual Configuration");
        string help = getExpertManualHelp ();

        list exits = [`back, `next, `abort, `ok, `apply, `accept];

        Wizard::SetContentsButtons (caption, contents, help,
            Label::BackButton (), Label::OKButton ());

	Wizard::RestoreBackButton ();
	Wizard::RestoreAbortButton ();

	string filename = filenames[0]:"";
	if (defaultv != "")
	    filename = defaultv;
	if (size (files) > 1)
	    UI::ChangeWidget (`id (`filename), `Value, filename);
	UI::ChangeWidget (`id (`file), `Value, files[filename]:"");

        any ret = nil;
        while (ret == nil || ! contains (exits, ret))
        {
            ret = UI::UserInput ();
	    if (ret == `filename)
	    {
		files[filename] = (string)UI::QueryWidget (`id (`file), `Value);
		filename = (string)UI::QueryWidget (`id (`filename), `Value);
		UI::ChangeWidget (`id (`file), `Value, files[filename]:"");
	    }
	    if (ret == `next)
	    {
		files[filename] = (string)UI::QueryWidget (`id (`file), `Value);
		BootCommon::SetFilesContents (files);
		Bootloader::blRead (false, false);
		BootCommon::changed = true;
		BootCommon::location_changed = true;
	    }
	    if (ret == `abort)
	    {
		if (! confirmAbortPopup ())
		    ret = nil;
	    }
        }
        return (symbol)ret;
    }


}

ACC SHELL 2018