/**
 *
 * File:
 *   what.ycp
 *
 * Module:
 *   Network/YPServer
 *
 * Summary:
 *   YPServer module.
 *
 * Authors:
 *   Dan Vesely <dan@suse.cz>
 *
 * $Id: what.ycp 18066 2004-07-12 11:40:21Z mvidner $
 *
 * YPServer module part.
 *
 */


{

    textdomain "nis_server";

    import "Wizard";
    import "Label";
    import "Popup";
    import "NisServer";
    include "nis_server/routines.ycp";

    /**
     * Dialog for choosing the way of the flow
     * @return `abort, `exit, `nothing, `master, `slave or `finish
     */
    define symbol WhatToConfigure () ``{

	// help text 1/2
	string helptext = _("<p>Select whether to configure the NIS server as a <b>master</b> or a
<b>slave</b> or not to configure a NIS server.</p>
");

	symbol detected = NisServer::ui_what;
	term labels = `VBox ();
	labels = add (labels, `VSpacing (1.5));

	string master_setup_label = "";
	string slave_setup_label  = "";
	string none_setup_label   = "";

	if (detected == `none)
	{
	    // help text 2/2
	    helptext = helptext + _("<p>The NIS server package will be <b>installed</b> first if you want to
configure it.</p>");

				// To translators: label in the dialog
	    labels = add (labels, `Left (`Label (_("No NIS Software is installed."))));
				// To translators: label in the dialog
	    labels = add (labels, `Left (`Label (_("No NIS Server is configured."))));

				// To translators: label in the dialog
	    master_setup_label = _("Install and set up an NIS &Master Server");
				// To translators: label in the dialog
	    slave_setup_label  = _("Install and set up an NIS &Slave Server");
				// To translators: label in the dialog
	    none_setup_label   = _("&Do nothing and leave set up");
	}
	else if (isYPServerConfigured ())
	{
	    boolean isMaster = (detected == `master);

	    labels = add (labels, `Left (`Label (_("NIS Software is installed."))));
	    string slave_or_master = isMaster ?
	    // To translators: part of the label in the dialog
		_("Master") :
	    // To translators: part of the label in the dialog
		_("Slave");
	    // To translators: label in the dialog, %1 is Master or Slave above
	    labels = add (labels, `Left (`Label (sformat (_("A NIS %1 Server is configured."),
							  slave_or_master))));

	    // To translators: label in the dialog
	    string reconfigure_master = _("Reconfigure NIS &Master Server");
	    // To translators: label in the dialog
	    string change_to_master = _("Change to NIS &Master Server");
	    // To translators: label in the dialog
	    string reconfigure_slave = _("Reconfigure NIS &Slave Server");
	    // To translators: label in the dialog
	    string change_to_slave = _("Change to NIS &Slave Server");

	    master_setup_label = isMaster? reconfigure_master: change_to_master;
	    slave_setup_label  = isMaster? change_to_slave: reconfigure_slave;
	    // To translators: label in the dialog
	    none_setup_label   = _("&Deactivate any NIS server configuration");
	}
	else
	{
				// To translators: label in the dialog
	    labels = add (labels, `Left (`Label (_("NIS Software is installed."))));
				// To translators: label in the dialog
	    labels = add (labels, `Left (`Label (_("No NIS Server is configured."))));

				// To translators: checkbox label
	    master_setup_label = _("Create NIS &Master Server");
				// To translators: checkbox label
	    slave_setup_label  = _("Create NIS &Slave Server");
				// To translators: checkbox label
	    none_setup_label   = _("&Do nothing and leave set up");
	}

	term info = `HBox ();
				// To translators: label in the dialog
	info = add (info, `VBox (`Label (_("Current status:"))));
	info = add (info, `HSpacing (4));
	info = add (info, labels);
	term buttons  = `VBox ();
	buttons = add (buttons, `VSpacing (0.5));
	buttons = add (buttons, `Left(`RadioButton (`id (`master), `opt(`notify), master_setup_label, detected == `master)));
	buttons = add (buttons, `VSpacing (0.2));
	buttons = add (buttons, `Left(`RadioButton (`id (`slave), `opt(`notify), slave_setup_label, detected == `slave)));
	buttons = add (buttons, `VSpacing (0.2));
	buttons = add (buttons, `Left(`RadioButton (`id (`none), `opt(`notify), none_setup_label, detected == `none)));
	buttons = add (buttons, `VSpacing (0.5));

	buttons = `HBox (`HSpacing (0.5),
			 buttons,
			 `HSpacing (0.5));

	buttons = `HVSquash (`RadioButtonGroup (`id(`rb), buttons));

	term contents = `VBox ();
	contents = add (contents, info);
	contents = add (contents, `VSpacing ());
	// To translators: frame label
	contents = add (contents, `VCenter(`Frame (_("Select what you want to do"), buttons)));
	contents = add (contents, `VStretch ());

	// To translators: dialog label
	Wizard::SetContents (_("Network Information Service (NIS) Server Setup"), contents, helptext, true, true);

	symbol ui = nil;
	symbol current_button = nil;

	repeat
	{
	    current_button = (symbol) UI::QueryWidget (`id (`rb), `CurrentButton);

	    if (current_button == `none)
	    {
		Wizard::SetNextButton(`finish, Label::FinishButton() );
	    }
	    else if (contains ([`master, `slave], current_button))
	    {
		Wizard::RestoreNextButton();
	    }

	    Wizard::SetFocusToNextButton();

	    ui = (symbol) UI::UserInput ();
	    if (ui == `cancel)
	    {
		ui = `abort;
	    }

	    if (ui == `abort && !Popup::ReallyAbort (true)) ui = `again;

	}
	until (contains ([`back, `next, `abort, `finish], ui));

	if (ui == `abort)
	{
	    return `abort;
	}
	if (ui == `back)
	{
	    return `exit;
	}
	if (ui == `finish && (detected == `none || !isYPServerConfigured ()))
	{
	    return `nothing;
	}

	current_button = (symbol) UI::QueryWidget (`id (`rb), `CurrentButton);
	NisServer::ui_what = current_button;
	return ui == `next ? current_button : ui;
    }
}
