/**
 * File:	include/security/users.ycp
 * Package:	Security configuration
 * Summary:	Users dialogs definitions
 * Authors:	Michal Svec <msvec@suse.cz>
 *
 * $Id: users.ycp 13417 2004-01-23 09:12:29Z msvec $
 */

{

textdomain "security";

import "Label";
import "Popup";
import "Wizard";

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

/**
 * Adduser dialog
 * @return dialog result
 */
define symbol AdduserDialog() ``{

    /* Adduser dialog caption */
    string caption = _("Adding User");
    string help = HELPS["adduser"]:"";

    /* Adduser dialog contents */
    term contents = `VBox(
	VSeparator(),
	/* Frame label */
	XFrame(1.8,0.5,_("User ID Limitations"),`HBox(
	settings2widget("UID_MIN"),
	`HSpacing(1.5),
	settings2widget("UID_MAX")
	)),
	`VSpacing(0.7),
	/* Frame label */
	XFrame(1.8,0.5,_("Group ID Limitations"),`HBox(
	settings2widget("GID_MIN"),
	`HSpacing(1.5),
	settings2widget("GID_MAX")
	)),
	`VSpacing(1.7)
    );

    contents = `HVCenter(`HVSquash(`HBox(`HSpacing(5),`VBox(`VSpacing(2),`ReplacePoint(`id(`rp_main),contents),`VSpacing(2)),`HSpacing(5))));
    Wizard::SetContentsButtons(caption, contents, help,
	    Label::BackButton(), Label::NextButton());

    any ret = nil;
    while(true) {
	ret = UI::UserInput();

	/* abort? */
	if(ret == `abort || ret == `cancel) {
	    if(ReallyAbort()) break;
	    else continue;
	}
	/* back */
	else if(ret == `back) {
	    break;
	}
	/* next */
	else if(ret == `next) {
	    if(checkMinMax("UID_MIN","UID_MAX") != true) {
		/* Popup text */
		Popup::Error(_("The minimum user ID cannot be larger than maximum"));
		continue;
	    }
	    if(checkMinMax("GID_MIN","GID_MAX") != true) {
		/* Popup text */
		Popup::Error(_("The minimum group IDs cannot be larger than maximum"));
		continue;
	    }
	    break;
	}
	else {
	    y2error("Unexpected return code: %1", ret);
	    continue;
	}
    }

    if(ret == `next) {
	widget2settings("GID_MIN");
	widget2settings("GID_MAX");
	widget2settings("UID_MIN");
	widget2settings("UID_MAX");
    }

    return (symbol) ret;
}

/* EOF */
}
