/**
 * File:	clients/tv_auto.ycp
 * Package:	TV cards configuration
 * Summary:	Client for autoinstallation
 * Authors:	Jan Holesovsky <kendy@suse.cz>
 *
 * $Id: tv_auto.ycp 16001 2004-03-11 07:59:45Z jhumpol $
 *
 * This is a client for autoinstallation. It takes its arguments,
 * goes through the configuration and returns the settings.
 * Does not do any changes to the configuration.
 */

/**
 * @param first a map of tv settings
 * @example
 *    map mm = $[ "cards" : [] ];
 *    map ret = WFM::CallModule ("tv_auto", [ mm ]);
 */

{

    textdomain "tv";

    import "Label";
    import "Tv";
    import "Wizard";

    include "tv/ui.ycp";

    list args = WFM::Args ();
    if ( size (args) <= 0 )
    {
	y2error ("Did not get the settings, probably some mistake...");
	return nil;
    }
    if ( !is ( WFM::Args (0), map ) )
    {
	y2error ("Bad argument for tv_auto: %1", WFM::Args (0));
	return nil;
    }

    // The settings are in the first argument
    map settings = args[0]:$[];
    y2milestone("Imported: (%1)", settings);

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

    string caption = _("Initializing TV and Radio Card Configuration");
    term contents = `Label (_("Initializing ..."));

    // Construct the dialogs
    Wizard::CreateDialog();
    Wizard::SetDesktopIcon("tv");
    Wizard::SetContentsButtons ( caption,
				 contents,
				 "",
				 Label::BackButton (),
				 Label::NextButton ());
    Wizard::RestoreHelp (ReadDialogHelp ());

    // Read the settings from the current system
    if (! Tv::Read ( callback ))
    {
	return nil;
    }
    // and patch them with the imported data
    Tv::Import ( settings );

    if (MainSequence () == `next)
    {
	settings = Tv::Export ();
    }
    else
    {
	settings = $[];
    }
    return settings;

/* EOF */
}
