/**
 * File:	clients/bluetooth_proposal.ycp
 * Package:	Configuration of bluetooth
 * Summary:	Proposal function dispatcher.
 * Authors:	Ladislav Slezak <lslezak@suse.cz>
 *
 * $Id: bluetooth_proposal.ycp 22321 2005-03-07 14:24:05Z lslezak $
 *
 * Proposal function dispatcher for bluetooth configuration.
 * See source/installation/proposal/proposal-API.txt
 */

{

textdomain "bluetooth";

import "Bluetooth";
import "Progress";

/* The main () */
y2milestone("----------------------------------------");
y2milestone("Bluetooth proposal started");

string func = (string) WFM::Args(0);
map param = (map) WFM::Args(1);
map ret = $[];

/* create a textual proposal */
if(func == "MakeProposal") {
    string warning = nil;
    symbol warning_level = nil;
    boolean force_reset = param["force_reset"]:false;

    if(force_reset || !Bluetooth::proposal_valid) {
        Bluetooth::proposal_valid = true;
	Progress::off();

	// open progress popup window
	UI::OpenDialog(`VBox(`Label(_("Detecting Bluetooth adapters..."))));
	Bluetooth::Read();
	// detect Bluetooth device and propose configuration
	Bluetooth::Propose();

	// close progress popup
	UI::CloseDialog();
	Progress::on();
    }
    string proposal = Bluetooth::Summary();

    ret = $[
	"preformatted_proposal" : proposal,
	"warning_level" : warning_level,
	"warning" : warning,
    ];
}
/* run the module */
else if(func == "AskUser") {
    // are required packages installed?
    boolean pkginstalled = Bluetooth::InstallPackages();

    if (pkginstalled)
    {

	if (Bluetooth::config_read == false)
	{
	    // workaround - ini-agent doesn't reread file content
	    // so start it completely again
	    SCR::UnmountAgent(.sysconfig.bluetooth);

	    Bluetooth::Read();
	    Bluetooth::config_read = true;
	}

	map stored = Bluetooth::Export();
	symbol seq = (symbol) WFM::CallFunction("bluetooth", [.propose]);
	if(seq != `next) Bluetooth::Import(stored);
	y2debug("stored=%1",stored);
	y2debug("seq=%1",seq);
	ret = $[
	    "workflow_sequence" : seq
	];
    }
    else
    {
	ret = $[
	    "workflow_sequence" : `abort
	];
    }
}
/* create titles */
else if(func == "Description") {
    ret = $[
	/* Rich text title for Bluetooth in proposals */
	"rich_text_title" : _("Bluetooth"),
	/* Menu title for Bluetooth in proposals */
	"menu_title" : _("&Bluetooth"),
	"id" : "bluetooth",
    ];
}
/* write the proposal */
else if(func == "Write") {
    Progress::off();
    Bluetooth::Write();
    Progress::off();
}
/* unknown function */
else {
    y2error("unknown function: %1", func);
}

/* Finish */
y2debug("ret=%1",ret);
y2milestone("Bluetooth proposal finished");
y2milestone("----------------------------------------");
return ret;

/* EOF */
}
