/**
 * File:
 *   inst_disk.ycp
 *
 * Module:
 *   Configuration of disk
 *   - schedular for partitioning lvm and raid modules
 *
 * Summary:
 *   Main file
 *
 * Authors:
 *   Michael Hager <mike@suse.de>
 *
 * $Id: inst_disk.ycp 19964 2004-10-26 15:37:35Z fehr $
 *
 * Main file for disk configuration. Uses all other files.
 *
 */

{


/***
 * <h3>Configuration of the disk</h3>
 */
   y2milestone( "start disk");

import "Arch";
import "Wizard";
import "Mode";
import "Storage";
import "Sequencer";

textdomain "storage";

include "partitioning/signatures.ycp";
include "partitioning/custom_part_helptexts.ycp";
include "partitioning/custom_part_dialogs.ycp";
include "partitioning/custom_part_lib.ycp";
include "partitioning/raid_lib.ycp";
include "partitioning/raid_ui.ycp";
include "partitioning/loop.ycp";
include "partitioning/lvm_pv_lib.ycp";
include "partitioning/partition_defines.ycp";
include "partitioning/custom_part_check_generated.ycp";

    y2milestone( "PartMode %1 ProposalActive %2 ", Storage::GetPartMode(),
                 Storage::GetPartProposalActive() );


    if( !Storage::GetCustomDisplay() && Storage::GetPartMode() != "CUSTOM" &&
         Storage::GetPartMode() != "PROP_MODIFY" )
      return Storage::GetExitKey();

    Storage::CreateTargetBackup("disk");

    /******************************************************************/
    // All raid-modules communicate via the following global variables
    // and as usual via user_settings:
    /******************************************************************/

    boolean installation = Stage::initial ();

    y2milestone( " running in instsys %1", installation );


define symbol InitSettings( boolean in ) 
    ``{
    return `next;
    }


    map aliases = $[
	"RaidTypeWizard"     : ``(ChooseRaidType(`wizard  )),
	"RaidDeviceWizard"   : ``(RaidDevices(`wizard  )),
	"RaidDeviceSettings" : ``(RaidDevices(`settings)),
        "LoopCreateWizard"   : ``(LoopSetup(false)),
        "LoopEditWizard"     : ``(LoopSetup(true)),
	"RaidExpertWizard"   : ``(RaidExpertWizard()),
	"RaidMpAutodetect"   : ``(RaidMultipathAuto()),
	"ReallyInstPrepdisk" : ``(ReallyInstPrepdisk()),
	"LvmPv"		     : ``(WFM::CallFunction("inst_lvm_pv", [true, true])),
	"LvmLv"		     : ``(WFM::CallFunction("inst_lvm_lv", [true, true])),
	"S390Zfcp"	     : ``(WFM::call("xfcp")),
	"S390Dasd"	     : ``(WFM::call("dasd")),
	"Evms"               : ``(WFM::CallFunction("inst_evms", [true, true])),
	"Custom"             : ``(WFM::CallFunction("inst_custom_part", [true, true])),
	"PrepDiskEnd"        : ``(WFM::CallFunction("inst_prepdisk", [true, true])),
	"PrepDiskApply"      : ``(WFM::CallFunction("inst_prepdisk", [true, true])),
	"ReInitSettings"     : ``(InitSettings(installation)),
	"abort"              : ``(AbortDialog())
    ];


    map sequence = $[
	"ws_start"           : "Custom",

        "RaidTypeWizard"     : $[ `abort   : "abort",
				  `cancel  : `cancel,
				  `mp_auto : "RaidMpAutodetect",
				  `next    : "RaidDeviceWizard" ],

        "RaidDeviceWizard"   : $[ `abort  : "abort",
				  `cancel : `cancel,
                                  `next   : "RaidExpertWizard" ],

        "RaidMpAutodetect"   : $[ `abort  : "abort",
				  `cancel : `cancel,
                                  `next   : "Custom" ],

	"RaidExpertWizard"   : $[ `abort  : "abort",
				  `cancel : `cancel,
                                  `next   : "Custom" ],

	"RaidDeviceSettings" : $[ `abort  : "abort",
				  `cancel : `cancel,
				  `next   : "Custom" ],

	"LoopCreateWizard"   : $[ `abort  : "abort",
				  `cancel : `cancel,
                                  `next   : "Custom" ],

	"LoopEditWizard"     : $[ `abort  : "abort",
				  `cancel : `cancel,
                                  `next   : "Custom"],

	"ReallyInstPrepdisk" : $[ `abort  : `abort,
				  `cancel : `cancel,
                                  `finish : "PrepDiskEnd",
				  `apply  : "PrepDiskApply" ],

        "Custom"             : $[ `abort         : "abort",
				  `cancel        : `cancel,
                                  `raid_wizard   : "RaidTypeWizard",
				  `raid_settings : "RaidDeviceSettings",
                                  `loop_create   : "LoopCreateWizard",
                                  `loop_edit     : "LoopEditWizard",
				  `backtoi       : `back,
				  `sysnext       : "ReallyInstPrepdisk",
				  `lvm           : "LvmPv",
				  `lvmlv         : "LvmLv",
				  `zfcp          : "S390Zfcp",
				  `dasd          : "S390Dasd",
				  `evms          : "Evms",
                                  `again         : "Custom",
                                  `apply         : "PrepDiskApply",
                                  `instnext      : `next ],

	"LvmPv"		    :  $[ `abort  : "abort",
				  `cancel : `cancel,
				  `next   : "LvmLv" ],

	"LvmLv"		    :  $[ `abort  : "abort",
				  `cancel : `cancel,
				  `next   :  "Custom" ],

	"Evms"		    :  $[ `abort  : "abort",
				  `cancel : `cancel,
				  `next   :  "Custom" ],

	"S390Zfcp"	    :  $[ `abort  : "abort",
				  `cancel : `cancel,
				  `next   : "Custom" ],

	"S390Dasd"	    :  $[ `abort  : "abort",
				  `cancel : `cancel,
				  `next   : "Custom" ],

	"PrepDiskApply"     :  $[ `abort  : "abort",
				  `cancel : `cancel,
                                  `back   : "ReInitSettings",
                                  `next   : "ReInitSettings" ],

	"PrepDiskEnd"       :  $[ `abort  : "abort",
				  `cancel : `cancel,
                                  `back   : "ReInitSettings",
                                  `next   : `next ],

	"ReInitSettings"    :  $[ `abort  : "abort",
				  `cancea : `cancel,
				  `next   : "Custom" ],

        "abort"             :  $[ `yes    : `abort,
				  `cancel : `cancel]
    ];


    if ( Mode::normal () )  {
        Wizard::CreateDialog();
        Wizard::SetDesktopIcon("disk");
    }

    /*************************************************/
    /*   Let s do the work ...                       */
    /*************************************************/
    symbol ret = Sequencer::Run(aliases, sequence);
    /*************************************************/
    y2milestone( "Sequencer ret=%1 Mode::normal ()=%2", ret, Mode::normal () );


    if( Mode::normal () )
	{
	UI::CloseDialog();
	}
    else
	{
	if( ret == `back )
	    {
	    Storage::RestoreTargetBackup("disk");
	    }
	else if( ret == `next )
	    {
	    Storage::DisposeTargetBackup("disk");
	    Storage::SetPartProposalActive(false);
	    }
	}

    y2milestone("Disk module finished");
    Storage::SaveExitKey( ret );
    return( ret );
}
