/**
 * Module:	inst_dirinstall.ycp
 *
 * Authors:	Anas Nashif <nashif@suse.de>
 *
 * Purpose:	Ask the user for various options for dir install.
 * $Id: dirinstall_options.ycp 21866 2005-02-23 13:50:15Z jsrain $
 */

{
    textdomain "packager";

    import "DirInstall";
    import "Installation";
    import "Wizard";
    import "Popup";

    // screen title for installation into directory options
    string title = _("Directory Install Options");

    // build and show dialog

    Wizard::OpenAcceptDialog ();

    term contents = `HVSquash(
			      `VBox(
						// text entry
				    `Left(`TextEntry(`id(`target), _("Root Directory (not \"/\"):"), DirInstall::target)),
						// check box
                                    `Left(`CheckBox(`id(`suseconfig), _("Run YaST and SuSEconfig on First Boot"), DirInstall::runme_at_boot)),
						// check box
                                    `Left(`CheckBox(`id(`makeimage), `opt(`notify), _("Create Ima&ge"), DirInstall::makeimage)),
						// text entry
                                    `Left(`TextEntry(`id(`imagename), _("Ima&ge Name:"), DirInstall::image_name)),
                                    `VSquash(
                                        `HBox(
						// text entry
                                            `TextEntry(`id(`imagedir), _("&Image Directory:"), DirInstall::image_dir),
                                            `VBox(
                                                `VSpacing(),
						// push button
                                                `Bottom(`PushButton(`id(`open_dir), _("Select &Directory")))
                                                )
                                            )
                                        )
                                  )
            );

    // help text for dirinstall options 1/2
    string help_text = _("<p>Choose a directory to which to install. Depending on the software selection, make sure
enough space is available.</p>
");
    // help text for dirinstall options 2/2
    help_text = help_text + _("<p>Additionally, you can create an archive image of the directory using tar. To create an 
image, specify the name and the location in the respective fields.</p>
");

    Wizard::SetContents (title, contents, help_text, (boolean) WFM::Args(0),
			 (boolean) WFM::Args(1));


    any ret = nil;

    while (true)
    {
        boolean image = (boolean)UI::QueryWidget(`id(`makeimage), `Value);
        if (image)
        {
            UI::ChangeWidget(`id(`imagename) , `Enabled, true);
            UI::ChangeWidget(`id(`imagedir) , `Enabled, true);
            UI::ChangeWidget(`id(`open_dir) , `Enabled, true);
        }
        else
        {
            UI::ChangeWidget(`id(`imagename) , `Enabled, false);
            UI::ChangeWidget(`id(`imagedir) , `Enabled, false);
            UI::ChangeWidget(`id(`open_dir) , `Enabled, false);
        }
	ret = Wizard::UserInput ();

	if (ret == `abort && Popup::ConfirmAbort (`painless))
	    break;

	if (ret == `cancel || ret == `back)
	    break;
	if (ret == `open_dir)
        {
	    // directory selection header
            any dir = UI::AskForExistingDirectory( DirInstall::image_dir,  _("Select Directory"));
            if (dir != nil)
            {
                UI::ChangeWidget(`id(`imagedir), `Value, (string)dir);
            }
            continue;
        }
	if (ret == `next)
	{
	    string target =(string) UI::QueryWidget (`id(`target), `Value);
	    boolean runme_at_boot = (boolean) UI::QueryWidget (`id(`suseconfig), `Value);
            DirInstall::makeimage = (boolean) UI::QueryWidget (`id(`makeimage), `Value);
            DirInstall::image_name = (string) UI::QueryWidget (`id(`imagename), `Value);
            DirInstall::image_dir = (string) UI::QueryWidget (`id(`imagedir), `Value);

            if(target == "" || target == "/")
            {
		// popup message
                Popup::Message (_("Specify a root directory. This does not mean /"));
		continue;
	    }


	    DirInstall::target = target;
            Installation::destdir = target;
	    DirInstall::runme_at_boot = runme_at_boot;
	    break;
	}
    }

    Wizard::CloseDialog ();

    return ret;
}
