/**
 *
 * File:
 *   card_wizard.ycp
 *
 * Module:
 *   Sound
 *
 * Authors:
 *   Dan Meszaros <dmeszar@suse.cz>
 *
 * $Id: card_wizard.ycp 15494 2004-03-05 14:26:21Z jsuchome $
 *
 * One sound card setup wizard.
 *
 */
{

import "Sequencer";
import "Sound";


include "sound/ui.ycp";
include "sound/options.ycp"; // sound_options
include "sound/volume.ycp"; // sound_volume
include "sound/routines.ycp"; // add_common_options, add_alias

/**
 * wrapper function for running first card config dialog (There will be shown
 * possibilities for next configuration steps (quick/normal/expert)
 */
define symbol _showName (integer card_id, integer flags) ``{

    string modelname	= Sound::save_entry["model"]:"";
    string modname	= Sound::save_entry["module"]:"";
    boolean has_joy	= false;

    if (Sound::db_modules[modname, "joystick"]:$[] != $[])
    {
	has_joy = true;
    }

    map res	= DisplayName (
	modelname, Sound::save_entry["alias"]:"", card_id, flags, has_joy);

    symbol ui	= res["ui"]:`back;

    if (ui != `back && ui != `abort)
	Thinkpad600E_cs4236_hack (card_id);

    return ui;
}

/**
 * wrapper function for running Options dialog (during expert configuration)
 */
define symbol _options (integer card_id) ``{

    map res	= sound_options(Sound::save_entry);
    symbol ui	= res["ui"]:`back;
    if (ui == `next)
    {
	Sound::save_entry = res["return"]:$[];
        Sound::save_entry = add_common_options(Sound::save_entry, card_id);
    }
    return ui;
}

/**
 * wrapper function for quick configuration (just modprobe)
 */
define symbol _quick (integer card_id, boolean finish, list save_info)
``{
    map res = sound_volume (Sound::save_entry, card_id, finish, true,save_info);
    symbol ui	= res["ui"]:`back;
    return ui;
}

/**
 * wrapper function for normal configuration (modprobe + volume setting)
 */
define symbol _volume (integer card_id, boolean finish, list save_info)
``{
    map res = sound_volume(Sound::save_entry, card_id, finish, false,save_info);
    symbol ui	= res["ui"]:`back;
    return ui;
}

/**
 * Wizard steps: 1. displayname<br>
 * 2. modprobe and volume settings
 * @param card_entry the card to configure
 * @param card_id index of configured car
 * @param flags defines which radioboxes has to be enabled
 *		(0x1 - first, 0x2 second, 0x4 third...)
 * @param finish true if no complex dialog is to be called
 *		(then the popup "Config will be saved.." will appear)
 * @return map with save info, as required by sound_write for one cards
 */
define map OneCardWizard (map card_entry, integer card_id, integer flags,
				 boolean finish, list save_info) ``{

	map aliases = $[
		"name"	    : ``(_showName (card_id, flags)),
		"options"   : ``(_options (card_id)),
		"volume"    : ``(_volume (card_id, finish, save_info)),
		"optVolume" : ``(_volume (card_id, finish, save_info)),
		"quick"	    : ``(_quick (card_id, finish, save_info))
	];

	map sequence = $[
	    "ws_start": "name",
	    "name":
	    $[
		`quick: "quick",
		`skip : `back,
	        `next:  "volume",
	        `options: "options",
		`abort:	`abort
	    ],
	    "options":
	    $[
	        `next: "optVolume",
	        `abort: `abort
	    ],
	    "volume":
	    $[
		`next: `next,
		`abort: `abort
	    ],
	    "optVolume":
	    $[
		`next: `next,
		`abort: `abort
	    ],
	    "quick":
	    $[
		`next: `next,
		`abort: `abort
	    ]
	];
    Sound::save_entry	= (map) eval (card_entry);
    Sound::save_entry	= add_common_options (Sound::save_entry, card_id);
    Sound::save_entry	= add_alias (Sound::save_entry, card_id);

    symbol ui	= Sequencer::Run (aliases, sequence);
    return $["ui": ui, "return": Sound::save_entry];
}


// EOF
}
