/**
 * File:	include/users/complex.ycp
 * Package:	Configuration of users and groups
 * Summary:	Dialogs definitions
 * Authors:	Johannes Buchhold <jbuch@suse.de>,
 *		Jiri Suchomel <jsuchome@suse.cz>
 *
 * $Id: complex.ycp 21037 2005-01-28 13:26:32Z jsuchome $
 */

{

textdomain "users";

import "Autologin";
import "Label";
import "Ldap";
import "Popup";
import "Report";
import "Security";
import "Stage";
import "Users";
import "UsersCache";
import "Wizard";

include "users/helps.ycp";

/**
 * Return a modification status
 * @return true if data was modified
 */
define boolean Modified() ``{
    return Users::Modified () || Autologin::modified;
}


/**
 * Read settings dialog
 * @param useUI boolean use user interface (change progress bar)
 * @return symbol `next if success, else `abort
 */
define symbol ReadDialog (boolean useUI) ``{

    // Set help text
    if ( useUI ) Wizard::RestoreHelp ( ReadDialogHelp () );

    // A callback function for abort
    block<boolean> abort = ``{
        return UI::PollInput () == `abort;
    };

    Users::SetGUI (useUI);
    symbol ret = `next;
    if (Users::Read () != "")
    {
	ret = `back;
	if (Stage::cont ())
	    ret = `nextmodule;
    }
    Users::SetGUI (true);
    return ret;
}

/**
 * Write settings dialog
 * @param useUI boolean use user interface (change progress bar)
 * @return symbol `next if success, else `abort
 */
define symbol WriteDialog (boolean useUI) ``{

    // Set help text
    if ( useUI ) Wizard::RestoreHelp ( WriteDialogHelp () );

    if (Users::LDAPModified () && (Ldap::anonymous || Ldap::bind_pass == nil))
    {
	// ask for real LDAP password if reading was anonymous
	Ldap::SetBindPassword (Ldap::LDAPAskAndBind (false));
	if (Ldap::bind_pass == nil)
	{
	    // popup text
	    if (Popup::YesNo (_("Really abort the writing process?")))
		return `back;
	}
    }

    Users::SetGUI (useUI);
    symbol ret = `next;
    if (Users::Write () != "")
    {
	if (!Stage::cont ()) ret = `abort;
    }
    Users::SetGUI (true);
    return ret;
}

/**
 * Set the module into installation mode with
 * first dialog for single user addition
 * @return symbol for wizard sequencer
 */
define symbol usersInstStart () ``{
    Users::SetStartDialog ("user_add") ;
    Users::AddUser ($[]);
    return `next;
}

/**
 * The dialog that appears when the [Abort] button is pressed.
 * @return `abort if user really wants to abort
 */
define symbol ReallyAbort() ``{

    boolean ret = true;

    if ( ! Stage::cont () )
    {
        ret = Popup::ReallyAbort (Modified());
    }
    else
    {
        ret = Popup::ConfirmAbort (`incomplete);
    }

    if( ret )
    {
        return `abort;
    }
    else return `back;
}


/* EOF */
}
