/**
 * File:
 *   idedma_auto.ycp
 *
 * Package:
 *   Configuration of IDE DMA mode
 *
 * Summary:
 *   Client for autoinstallation
 *
 * Authors:
 *   Ladislav Slezak <lslezak@suse.cz>
 *
 * $Id: idedma_auto.ycp 15079 2004-03-01 15:45:52Z lslezak $
 *
 * This is a client for autoinstallation. It takes its arguments,
 * goes through the configuration and return the setting.
 * Does not do any changes to the configuration.
 */

/**
 * @param first a map of idedma settings
 * @return boolean success of operation
 * @example map mm = $[ "dma_on" : false, ...];
 * @example map ret = WFM::CallModule ("idedma_auto", [ mm ]);
 */

{
textdomain "tune";
import "Idedma";
include "idedma/ui.ycp";

/* The main () */
y2milestone("---------------------------------");
y2milestone("Idedma autoinst client started");
any ret = nil;
string func = "";
list<map> param = [];


/* Check arguments */
if(size((list)WFM::Args()) > 0 && is(WFM::Args(0), string))
{
    func = (string)WFM::Args(0);

    if (size((list)WFM::Args()) > 1 && is(WFM::Args(1), list))
    {
	param = (list<map>) WFM::Args(1);
    }
}

y2debug("func=%1", func);
y2debug("param=%1", param);

// predefined devices - we don't know which devices will be present in the target system
// allow setting any possible IDE device to any DMA mode
list<map<string,any> > empty_settings = [
	$[ "current_dma" : nil, "dev_name" : "/dev/hda", "device" : _("Unknown"), "device_type" : _("Unknown"), "dma_modes":["mdma0", "mdma1", "mdma2", "udma0", "udma1", "udma2", "udma3", "udma4", "udma5", "udma6"], "dma_setting":"nochange"],
	$[ "current_dma" : nil, "dev_name" : "/dev/hdb", "device" : _("Unknown"), "device_type" : _("Unknown"), "dma_modes":["mdma0", "mdma1", "mdma2", "udma0", "udma1", "udma2", "udma3", "udma4", "udma5", "udma6"], "dma_setting":"nochange"],
	$[ "current_dma" : nil, "dev_name" : "/dev/hdc", "device" : _("Unknown"), "device_type" : _("Unknown"), "dma_modes":["mdma0", "mdma1", "mdma2", "udma0", "udma1", "udma2", "udma3", "udma4", "udma5", "udma6"], "dma_setting":"nochange"],
	$[ "current_dma" : nil, "dev_name" : "/dev/hdd", "device" : _("Unknown"), "device_type" : _("Unknown"), "dma_modes":["mdma0", "mdma1", "mdma2", "udma0", "udma1", "udma2", "udma3", "udma4", "udma5", "udma6"], "dma_setting":"nochange"],
	$[ "current_dma" : nil, "dev_name" : "/dev/hde", "device" : _("Unknown"), "device_type" : _("Unknown"), "dma_modes":["mdma0", "mdma1", "mdma2", "udma0", "udma1", "udma2", "udma3", "udma4", "udma5", "udma6"], "dma_setting":"nochange"],
	$[ "current_dma" : nil, "dev_name" : "/dev/hdf", "device" : _("Unknown"), "device_type" : _("Unknown"), "dma_modes":["mdma0", "mdma1", "mdma2", "udma0", "udma1", "udma2", "udma3", "udma4", "udma5", "udma6"], "dma_setting":"nochange"],
	$[ "current_dma" : nil, "dev_name" : "/dev/hdg", "device" : _("Unknown"), "device_type" : _("Unknown"), "dma_modes":["mdma0", "mdma1", "mdma2", "udma0", "udma1", "udma2", "udma3", "udma4", "udma5", "udma6"], "dma_setting":"nochange"],
	$[ "current_dma" : nil, "dev_name" : "/dev/hdh", "device" : _("Unknown"), "device_type" : _("Unknown"), "dma_modes":["mdma0", "mdma1", "mdma2", "udma0", "udma1", "udma2", "udma3", "udma4", "udma5", "udma6"], "dma_setting":"nochange"],
	$[ "current_dma" : nil, "dev_name" : "/dev/hdi", "device" : _("Unknown"), "device_type" : _("Unknown"), "dma_modes":["mdma0", "mdma1", "mdma2", "udma0", "udma1", "udma2", "udma3", "udma4", "udma5", "udma6"], "dma_setting":"nochange"],
	$[ "current_dma" : nil, "dev_name" : "/dev/hdj", "device" : _("Unknown"), "device_type" : _("Unknown"), "dma_modes":["mdma0", "mdma1", "mdma2", "udma0", "udma1", "udma2", "udma3", "udma4", "udma5", "udma6"], "dma_setting":"nochange"],
	$[ "current_dma" : nil, "dev_name" : "/dev/hdk", "device" : _("Unknown"), "device_type" : _("Unknown"), "dma_modes":["mdma0", "mdma1", "mdma2", "udma0", "udma1", "udma2", "udma3", "udma4", "udma5", "udma6"], "dma_setting":"nochange"],
	$[ "current_dma" : nil, "dev_name" : "/dev/hdl", "device" : _("Unknown"), "device_type" : _("Unknown"), "dma_modes":["mdma0", "mdma1", "mdma2", "udma0", "udma1", "udma2", "udma3", "udma4", "udma5", "udma6"], "dma_setting":"nochange"]
];

/* Import data*/
if(func == "Import")
{
    if (size(param) == 0)
    {
	param = empty_settings;
    }
    ret = Idedma::Import((list<map<string,any> >)param);
}
/* create a summary */
else if(func == "Summary")
{
    // show only configured devices, richtext output
    ret = Idedma::Summary(false, true);
}
else if (func == "Packages")
{
	ret = $[];
}
else if (func == "Reset")
{
    ret = Idedma::Import(empty_settings);
}
else if (func == "Change")
{
    ret = IdedmaAutoSequence();
}
else if (func == "Export")
{
    ret = Idedma::Export();
}
else if (func == "Write")
{
    import "Progress";
    Progress::off();
    ret = Idedma::Write();
    Progress::on();
}
/* unknown function */
else
{
    y2error("unknown function: %1", func);
    ret =  false;
}

y2debug("ret=%1", ret);
y2milestone("Idedma autoinst client finished");
y2milestone("----------------------------------");

return ret;

}


