/**
 * File:	include/nis_server/dialogs.ycp
 * Package:	Configuration of nisServer
 * Summary:	Dialogs definitions
 * Authors:	Martin Vidner <mvidner@suse.cz>
 *              Dan Vesely <dan@suse.cz>
 *
 * $Id: ui.ycp 20039 2004-10-29 07:34:42Z jsuchome $
 */

{
    textdomain "nis_server";

    import "Label";
    import "Message";
    import "NisServer";
    import "Package";
    import "Popup";
    import "Wizard";

    include "nis_server/what.ycp";
    include "nis_server/slave.ycp";
    include "nis_server/master.ycp";
    include "nis_server/details.ycp";
    include "nis_server/slaves.ycp";
    include "nis_server/maps.ycp";
    include "nis_server/securenets.ycp";

    /**
     * Read settings dialog
     * @return `abort if aborted and `next otherwise
     */
    define symbol ReadDialog() ``{
	boolean ret = NisServer::Read();
	return ret ? `next : `abort;
    }

    /**
     * Write settings dialog
     * @return `abort if aborted and `next otherwise
     */
    define symbol WriteDialog() ``{
	Wizard::RestoreNextButton();
	Wizard::DisableNextButton();
	UI::ChangeWidget (`id (`abort), `Enabled, false);

	boolean ret = NisServer::Write();
	return ret ? `next : `abort;
    }

    /**
     * Popup to confirm after finish is pressed
     * @return `yes or `back
     */
    define symbol FinishPopup () ``{
	if (Popup::ContinueCancelHeadline (
		// To translators: ContinueCancel Popup headline
		_("Finish"),
		// To translators: ContinueCancel Popup
		_("Really save configuration ?")))
	{
	    return `yes;
	}
	return `back;
    }

    /**
     * Popup to confirm vhen exitting without saving
     * @return `exit or `back
     */
    define symbol ExitPopup () ``{
	if (Popup::YesNoHeadline (
		// To translators: YesNo Popup headline
		_("Exit"),
		// To translators: YesNo Popup
		_("Really exit configuration without saving ?")))
	{
	    return `exit;
	}
	return `back;
    }

    /**
     * Popup with details error
     * @return `ok
     */
    define symbol DetailsPopup () ``{

				// To translators: popup label
	Popup::LongText (_("Error details"), `RichText (NisServer::error_details), 50, 20 );
	return `ok;
    }

    /**
     * Popup displaying configuration result
     * @return `ok or `details
     */
    define symbol ResultPopup () ``{

	string message = "";
	if (size (NisServer::error_msg) > 0)
	{
				// To translators: popup label
	    message = sformat (_("Error during configuration:\n%1"),
			       NisServer::error_msg);

				// To translators: Error popup
	    return Popup::AnyQuestion (Label::ErrorMsg(), message, Label::OKButton(), _("&Details"), `focus_yes) ? `ok : `details;
	}
	else
	{
	    if (NisServer::start_ypbind &&
		NisServer::old_domainname != "" &&
		NisServer::old_domainname != NisServer::domain)
	    {
		// To translators: final popup
		Popup::Warning (Message::DomainHasChangedMustReboot());
	    }
	}

	return `ok;
    }

    /**
     * Checks if the YP server package is installed
     * and calls installation if not
     * @return `master or `slave
     */
    define symbol InstallServer () ``{
	if (!Package::InstalledAll (NisServer::required_packages))
	{
	    Package::DoInstallAndRemove (NisServer::required_packages, []);
	}

	return NisServer::ui_what;
    }
}
