ACC SHELL

Path : /usr/share/YaST2/include/sysconfig/
File Upload :
Current File : //usr/share/YaST2/include/sysconfig/dialogs.ycp

/**
 * File:	include/sysconfig/dialogs.ycp
 * Package:	Configuration of sysconfig
 * Summary:	Dialogs definitions
 * Authors:	Ladislav Slezak <lslezak@suse.cz>
 *
 * $Id: dialogs.ycp 37399 2007-04-11 13:54:49Z lslezak $
 */

{

textdomain "sysconfig";

import "Sysconfig";

import "Popup";
import "Label";

include "sysconfig/helps.ycp";
include "sysconfig/routines.ycp";

/**
 * Display search dialog
 * @return map Search option values selected in the dialog
 */
 define map display_search_dialog()
``{
    UI::OpenDialog( `opt(`decorated ),
		`VBox(`HSpacing(60),
		    // search popup window header
		      `Heading(_("Search for a Configuration Variable")),
		      `VSpacing(0.5),
		      `HBox(`VSpacing(10),
			    `HSpacing(2),
			    `VBox(
				`VSpacing(1),
				// text entry label
				`TextEntry(`id(`search_entry), _("&Search for:")),
				`VSpacing(1),
				// check box label
				`Left(`CheckBox(`id(`ignore), _("&Case Sensitive Search"), false)),
				// check box label
				`Left(`CheckBox(`id(`nkey), _("Search &Variable Name"), true)),
				// check box label
				`Left(`CheckBox(`id(`ndescr), _("Search &description"), true)),
				// check box label
				`Left(`CheckBox(`id(`nvalue), _("Search &value"), false)),
				`VSpacing(1)
				),
			    `HSpacing(2)
			  ),
		      `VSpacing(0.5),
		      `HBox(
			  // push button label
			  `PushButton(`id(`ok), `opt(`default, `key_F10), Label::OKButton()),
			  // push button label
			  `PushButton(`id(`cancel), `opt(`key_F9), Label::CancelButton())
			  )
		    )
	);

    UI::SetFocus(`id(`search_entry));

    symbol ui = (symbol)UI::UserInput();

    while (ui != `ok && ui != `cancel)
    {
	ui = (symbol)UI::UserInput();
    }

    map ret = $[];

    if (ui == `ok)
    {
	ret = add(ret, "search", (string)UI::QueryWidget(`id(`search_entry), `Value));
	ret = add(ret, "insensitive", !((boolean)UI::QueryWidget(`id(`ignore), `Value)));
	ret = add(ret, "varname", (boolean)UI::QueryWidget(`id(`nkey), `Value));
	ret = add(ret, "value", (boolean)UI::QueryWidget(`id(`nvalue), `Value));
	ret = add(ret, "description", (boolean)UI::QueryWidget(`id(`ndescr), `Value));
    }

    UI::CloseDialog();
    return ret;
}

/**
 * Display dialog with selected variables
 * @param header Heading in the dialog
 * @param label Label in the dialog
 * @param table_content Table content list
 * @param ok_label OK button label
 * @param cancel_label Cancel button label
 * @param checkboxlabel Optional check box widget is displayed when size of checkboxlabel is greater than zero
 * @param checkboxvalue Check box value
 * @return map Selected variable, checkbox value (nil if it wasn't used), user input values
 */
 define map<string, any> display_variables_dialog(string header, string label, list table_content, string ok_label, string cancel_label, string checkboxlabel, boolean checkboxvalue) ``{

    UI::OpenDialog(`opt(`decorated),
	`HBox(
	    `VSpacing(17),
	    `VBox(`HSpacing(70),
		//heading of popup
		`Heading(header),
		`Label(label),
		`VSpacing(0.5),

		// table column header
		`Table(`id(`table),`header(_("Name"), _("NEW VALUE"), _("Old Value"), _("File"), _("Description")), table_content),
		(size(checkboxlabel) > 0) ? `CheckBox(`id(`chbox), checkboxlabel, checkboxvalue) : `Empty(),
		`VSpacing(0.5),
		`HBox(
		    // push button label
		    `PushButton(`id(`action), `opt(`default, `key_F10), ok_label),
		    // push button label
		    `PushButton(`id(`cancel), `opt(`key_F9), cancel_label)
		)
	    )
        )
    );

    symbol ret = (symbol)UI::UserInput();
    string selected = (string)UI::QueryWidget(`id(`table), `CurrentItem);
    boolean box = nil;

    if (size(checkboxlabel) > 0)
    {
	box = (boolean)(UI::QueryWidget(`id(`chbox), `Value));
    }

    UI::CloseDialog();

    return $[ "ui" : ret, "selected" : selected, "checkbox" : box ];
}


/**
 * Display dialog for new variable. This dialog is used at autoinstalation config mode
 * only - some packages may not be available at configure time, but they will be present
 * at installation, so it is possible to change them even if they are not displayed.
 * @return map Map with keys "ui" (`ok or `cancel - user input), "name" (name of
 * the new variable), "file" (location of variable) and "value" (value to write)
 */
 define map add_new_variable()
``{
    UI::OpenDialog(`opt(`decorated),
	`VBox(
	    `HBox(
		// text entry label
		`TextEntry(`id(`name), _("&Variable Name"), ""),
		// text entry label
		`TextEntry(`id(`value), _("V&alue"), "")
	    ),
	    `VSpacing(1),
	    `HBox(
		// text entry label
		`TextEntry(`id(`file), _("&File Name"), "")
	    ),
	    `VSpacing(1),
	    `HBox(
		`PushButton(`id(`ok), `opt(`key_F10), Label::OKButton()),
		`PushButton(`id(`cancel), `opt(`key_F9), Label::CancelButton())
	    )
	)
    );

    symbol ui = nil;

    string name = "";
    string file = "";

    while(ui != `ok && ui != `cancel)
    {
	ui = (symbol)UI::UserInput();

	name = (string)UI::QueryWidget(`id(`name), `Value);
	file = (string)UI::QueryWidget(`id(`file), `Value);

	if (ui == `ok)
	{
	    if (name == "")
	    {
		// warning popup message - variable name is empty
		Popup::Warning(_("Missing variable name value."));
		ui = nil;
	    }
	    else if (size(file) <= 1)
	    {
		// warning popup message - file name is empty
		Popup::Warning(_("Missing file name value."));
		ui = nil;
	    }
	    else if (substring(file, 0, 1) != "/")
	    {
		// warning popup message - file name is required with absolute path
		Popup::Warning(_("Missing absolute path in file name."));
		ui = nil;
	    }
	}
    }

    string value = (string)UI::QueryWidget(`id(`value), `Value);

    UI::CloseDialog();

    return $[ "ui" : ui, "name" : name, "value" : value, "file" : file ];
}

/* EOF */
}

ACC SHELL 2018