/**
 * File:	include/profile-manager/wizards.ycp
 * Package:	Configuration of profile-manager
 * Summary:	Wizards definitions
 * Authors:	Jiri Suchomel <jsuchome@suse.cz>
 *
 * $Id: wizards.ycp 18579 2004-08-13 13:29:24Z jsuchome $
 */

{

textdomain "profile-manager";

import "Label";
import "Popup";
import "ProfileManager";
import "Report";
import "Sequencer";
import "Wizard";

include "profile-manager/complex.ycp";

/**
 * Finishing module after clicking windowmanager "close window" button
 * @return symbol next (-> write all)
 */
define symbol Cancel() ``{

    ProfileManager::canceled = true;
    return `next; //FIXME cancel should really cancel!!
}


/**
 * Main sequence of profile-manager
 * @return sequence result
 */
define any MainSequence (string switch_to) ``{
    map aliases =
	$[
	    "main"	:	``( MainDialog () ),
	    "options"	:	``( OptionsDialog () ),
	    "switch"	:	``( SwitchDialog () ),
	    "details"	:	``( DetailsSwitchDialog ()),
	    "edit"	:	``( ProfileSettingsDialog () ),
	    "cancel"	:	``( Cancel() ),
	    "resources"	:	``( ConfigureResourcesDialog() )
	];

    map sequence = $[
	"ws_start" : "main",
	"main" :
	$[
	    `abort	: `abort,
	    `cancel	: "cancel",
	    `next	: `next,
	    `switch_button : "switch",
	    `options_button: "options",
	    `edit_button: "edit",
	],
	"switch" :
	$[
	    `abort	: `abort,
	    `cancel	: "cancel",
	    `details	: "details",
	    `next	: "main"
	],
	"details" :
	$[
	    `abort	: "cancel",
	    `cancel	: "cancel",
	    `next	: "switch"
	],
	"options" :
	$[
	    `abort	: `abort,
	    `cancel	: "cancel",
	    `next	: "main",
	    `resources	: "resources"
	],
	"edit" :
	$[
	    `abort	: `abort,
	    `cancel	: "cancel",
	    `next	: "main"
	],
	"resources":
	$[
	    `abort	: "cancel",
	    `cancel	: "cancel",
	    `next	: "options"
	],
	"cancel" :
	$[
	    `next	: `next
	]
    ];

    if (switch_to != "")
    {
//TODO do not show ReadDialog???
	if (haskey (ProfileManager::profiles, switch_to))
	{
	    sequence["ws_start"]	= "switch";
	    sequence["switch", `next]	= `next;
	    sequence["switch", `abort]	= "cancel";
	    if (!PreparePopup (switch_to))
		return `abort;
	    Wizard::HideAbortButton();
	}
	else
	{
	    // error popup
	    Report::Error (sformat (_("There is no profile '%1'"), switch_to));
	    return Cancel ();
	}
    }
    any ret = Sequencer::Run (aliases, sequence);
    if (ret == `back && switch_to != "")
	return Cancel ();
    return ret;
}

/**
 * Whole configuration of profile-manager
 * @return sequence result
 */
define symbol ProfileManagerSequence (string switch_to) ``{

    map aliases = $[
	"read"	: [ ``( ReadDialog() ), true ],
	"main"	:   ``( MainSequence (switch_to) ),
	"write"	: [ ``( WriteDialog() ), true ]
    ];

    map sequence = $[
	"ws_start" : "read",
	"read" : $[
	    `abort	: `abort,
	    `next	: "main"
	],
	"main" : $[
	    `abort	: `abort,
	    `next	: "write"
	],
	"write" : $[
	    `abort	: `abort,
	    `next	: `next
	]
    ];

    Wizard::CreateDialog();
    Wizard::SetDesktopIcon("profile-manager");
    any ret = Sequencer::Run (aliases, sequence);
    UI::CloseDialog();

    return (symbol) ret;
}

/**
 * Whole configuration of profile-manager but without reading and writing.
 * For use with autoinstallation.
 * @return sequence result
 */
define symbol ProfileManagerAutoSequence() ``{
    // Caption of the initialize process
    string caption = _("Profile Manager Configuration");
    // Lable of the initialize process
    term contents = `Label(_("Initializing ..."));

    Wizard::CreateDialog();
    Wizard::SetDesktopIcon("profile-manager");
    Wizard::SetContentsButtons(caption, contents, "",
	    Label::BackButton(), Label::NextButton());

    any ret = MainSequence ("");

    UI::CloseDialog();
    return (symbol) ret;
}

/* EOF */
}
