ACC SHELL

Path : /usr/share/YaST2/include/bootloader/routines/
File Upload :
Current File : //usr/share/YaST2/include/bootloader/routines/popups.ycp

/**
 * File:
 *      include/bootloader/routines/popups.ycp
 *
 * Module:
 *      Bootloader installation and configuration
 *
 * Summary:
 *      Popups for being used inside bootloader configurator
 *
 * Authors:
 *      Jiri Srain <jsrain@suse.cz>
 *      Olaf Dabrunz <od@suse.de>
 *
 * $Id: popups.ycp 56824 2009-04-16 15:20:53Z juhliarik $
 *
 */


{

    textdomain "bootloader";

    import "Encoding";
    import "Label";
    import "Misc";
    import "Mode";
    import "Popup";
    import "Report";
    import "String";

/**
 * Inform about not available functionality when no loader selected
 */
void NoLoaderAvailable () {
    // popup message
    Popup::Message (_("This function is not available if the boot
loader is not specified."));
}

    /**
      * Display question
      * @param name string name of currently selected section (to clone)
      * @return boolean true if answered yes
      */
     boolean askClone (string name) ``{
	// yes-no popup
	return Popup::YesNo (sformat (_("Clone the selected section '%1' instead
of creating a new empty section?
"), name));
    }
    /**
      * Display question
      * @return boolean true if answered yes
      */
     boolean confirmAbortPopup () ``{
	// yes-no popup question
	return Popup::YesNo (_("Really leave the boot loader configuration without saving?
All changes will be lost.
"));
    }

    /**
      * Display question
      * @return boolean true if answered yes
      */
     boolean resetSectsPopup () ``{
	// yes-no popup question
	return Popup::YesNo (_("Really reset your settings for sections?
All your changes made in section management will be lost.
"));
    }

    /**
      * Display question
      * @param title string section title
      * @return boolean true if answered yes
      */
     boolean confirmSectionDeletePopup (string title) ``{
	// yes-no popup question
	return Popup::YesNo (sformat(_("Really delete section %1?"), title));
    }

    /**
      * Display question
      * @return boolean true if answered yes
      */
     boolean resetAllPopup () ``{
	// yes-no popup question
	return Popup::YesNo (_("Really reset all
your settings? All your changes will be lost.
"));
    }

    /**
      * Display error
      */
     void setLocationErrorPopup () ``{
	// error popup
	Report::Error (_("Set the boot loader location."));
    }

    /**
      * Display error
      */
     void emptyPasswdErrorPopup () ``{
	// error popup
	Report::Error (_("The password must not be empty."));
    }

    /**
      * Display error
      */
     void passwdMissmatchPopup () ``{
	// error popup
	Report::Error (_("'Password' and 'Retype password'
do not match. Retype the password."));
    }

    /**
      * Display popup about change of section
      * @param sect_name string section name
      */
     void displayDiskChangePopup (string sect_name) ``{
	// message popup, %1 is sectino label
	Popup::Message (sformat (_("The disk settings have changed.
Check section %1 settings.
"), sect_name));
    }

    /**
      * Display popup
      */
     void displayFilesEditedPopup () ``{
	// message popup
	Popup::Message (_("The disk settings have changed and you edited boot loader
configuration files manually. Check the boot loader settings.
"));
    }

    /**
      * Ask for change of bootloader location because of device unavailability
      * @param string reason text stating why the location should be re-proposed
      * @return boolean yes if shall be reset
      */
     global boolean askLocationResetPopup (string reason) ``{
	// yes-no popup
	return Popup::YesNo(sformat(_("%1Set default boot loader location?
"), reason));
    }

    /**
      * Show the popup before saving to floppy, handle actions
      * @return true on success
      */
     boolean saveToFLoppyPopup () ``{
	boolean retval = true;
	boolean format = false;
	symbol fs = `no;
	list items = [
		// combobox item
	    `item (`id (`no), _("Do Not Create a File System")),
		// combobox item
	    `item (`id (`ext2), _("Create an ext2 File System")),
	];
	if (SCR::Read (.target.size, "/sbin/mkfs.msdos") != -1)
		// combobox item
	   items = add (items, `item (`id (`fat), _("Create a FAT File System")));
	term contents = `VBox (
		// label
	    `Label (_("The boot loader boot sector will be written
to a floppy disk. Insert a floppy disk
and confirm with OK.
")),
	    `VSpacing (1),
	    // checkbox
	    `Left (`CheckBox (`id (`format), _("&Low Level Format"), false)),
	    `VSpacing (1),
	    // combobox
	    `Left (`ComboBox (`id (`fs), _("&Create File System"), items)),
	    `VSpacing (1),
	    `PushButton (`id (`ok), Label::OKButton ())
	);
	UI::OpenDialog (contents);
	any ret = nil;
	while (ret != `ok)
	{
	    ret = UI::UserInput ();
	}
	if (ret == `ok)
	{
	    format = (boolean)UI::QueryWidget (`id (`format), `Value);
	    fs = (symbol)UI::QueryWidget (`id (`fs), `Value);
	}
	UI::CloseDialog ();
	// FIXME: loader_device cannot be used for grub anymore; but this
	// function should not be used anymore anyway, because BootFloppy has
	// been disabled.
	string dev = BootCommon::loader_device;
	if (format)
	{
	    boolean tmpretval = true;
	    y2milestone ("Low level formating floppy");
	    while (true)
	    {
		tmpretval = 0 == SCR::Execute
		    (.target.bash, sformat ("/usr/bin/fdformat %1", dev));
		if (tmpretval)
		    break;
		// yes-no popup
		if (! Popup::YesNo (_("Low level format failed. Try again?")))
		    break;
	    }
	    retval = retval && tmpretval;
	}
	if (fs == `ext2)
	{
	    y2milestone ("Creating ext2 on floppy");
            boolean tmpretval = 0 == SCR::Execute
		(.target.bash, sformat ("/sbin/mkfs.ext2 %1", dev));
	    if (! tmpretval)
		// error report
		Report::Error (_("Creating file system failed."));
            retval = retval && tmpretval;
        }
	else if (fs == `fat)
	{
	    y2milestone ("Creating msdosfs on floppy");
	    boolean tmpretval = 0 == SCR::Execute
		(.target.bash, sformat ("/sbin/mkfs.msdos %1", dev));
	    if (! tmpretval)
		// error report
		Report::Error (_("Creating file system failed."));
	    retval = retval && tmpretval;
	}
	return retval;
    }

    /**
      * Display error
      */
     void usedNameErrorPopup () ``{
        // error popup
        Report::Error (_("The name selected is already used.
Use a different one.
"));
    }

    /**
      * Display error
      * @return true if shall retry
      */
     boolean writeErrorPopup () ``{
        // yes-no popup
	return Popup::YesNo (_("An error occurred during boot loader
installation. Retry boot loader configuration?
"));
    }


    /**
      * Display popup
      */
     void displayGfxMenuChangePopup () ``{
	// message popup, gfxmenu is option name, leave as is
	Popup::Message (_("The disk settings have changed.
Check the gfxmenu settings.
"));
    }

    /**
      * Display yes-no popup
      * @return true if confirmed
      */
     boolean confirmOptionDeletePopup () ``{
	// yes-no popup
	return Popup::YesNo (_("Really delete the selected option?"));
    }

    /**
      * Display error popup with log
      * @param header string error header
      * @param log string logfile contents
      */
     void errorWithLogPopup (string header, string log) ``{
	if (log == nil)
	    // FIXME too generic, but was already translated
	    log = _("Unable to install the boot loader.");
	term text = `RichText( `opt(`plainText), log );
	UI::OpenDialog(`opt ( `decorated ),
	    `VBox (`HSpacing(75),
		`Heading(header),
		// heading
		`HBox(
		    `VSpacing(14),
		    text      // e.g. `Richtext()
		),
		`PushButton( `id(`ok_help), `opt(`default), Label::OKButton() )
	    )
	);

	UI::SetFocus(`id(`ok_help) );
	any r = UI::UserInput();
	UI::CloseDialog();
    }

    /**
      * Display popup
      */
     void displayNoSupportPopup () ``{
	// message popup
	Popup::Message (_("Sorry, there are currently
no options to set here."));
    }

    /**
      * Display popup
      */
     void noBootloaderPopup () ``{
	// error report
	Report::Error (_("Unable to install the boot loader."));
    }

    /**
      * Display popup
      * @param bootloader string printable name of used bootloader
      */
     void floppyWrittenPopup (string bootloader) ``{
	string confirm_boot_msg = Misc::boot_msg;
	// data saved to floppy disk
	// popup, %1 is bootloader name
	string msg = sformat (_("The %1 boot sector has been written to the floppy disk."),
	    bootloader);
	msg = msg + "\n"
	    // popup - continuing - alternative 1 ...
	    + _("Leave the floppy disk in the drive. The system will now be rebooted.");

	if ( size (confirm_boot_msg) > 0 )
	{
	    msg = msg + "\n\n" + confirm_boot_msg;
	}
	Misc::boot_msg = "";
        // empty that  Misc::boot_msg indicate the message has been displayed
	Popup::TimedOKCancel(msg, 10);
    }

    /**
      * Display popup - confirmation befopre restoring MBR
      * @param device string device to restore to
      * @return boolean true of MBR restore confirmed
      */
     boolean restoreMBRPopup (string device) ``{
	map stat = (map)SCR::Read (.target.stat, "/boot/backup_mbr");
	integer ctime = stat["ctime"]:0;
	string command = sformat (
	    "date --date='1970-01-01 00:00:00 %1 seconds'",
	    ctime);
	map out = (map)SCR::Execute (.target.bash_output, command);
	string c_time = out["stdout"]:"";
	c_time = String::FirstChunk (c_time, "\n");
	c_time = (string)UI::Recode (Encoding::console, "UTF-8", c_time);

	// warning popup. %1 is device name, %2 is date/time in form of
	// 'date' command output
	string msg = sformat (_("Warning!

Current MBR of %1 will now be rewritten with MBR
saved at %2.

Only the booting code in the MBR will be rewritten.
The partition table remains unchanged.

Continue?
"), device, c_time);

	term dialog = `HBox (
	    `HSpacing (1),
	    `VBox (
		`VSpacing (0.2),
		`Label (msg),
		`HBox(
		    // PushButton
		   `PushButton (`id (`yes), _("&Yes, Rewrite")),
		   `HStretch (),
		   `PushButton (`id (`no), `opt (`default), Label::NoButton ())
		),
		`VSpacing (0.2)
	    ),
	    `HSpacing(1)
	);

	UI::OpenDialog (`opt (`decorated, `warncolor), dialog);

	symbol  button = nil;
	repeat
	{
	    button = (symbol)UI::UserInput ();
	} until (button == `yes || button == `no);

	UI::CloseDialog();

	return (button == `yes);
    }
}

ACC SHELL 2018