/**
 * Module:		software_proposal.ycp
 *
 * Author:		Klaus Kaempf <kkaempf@suse.de>
 *
 * Purpose:		Proposal function dispatcher - software.
 *
 *			See also file proposal-API.txt for details.
 */
{
    textdomain "packager";

    import "Packages";
    import "Storage";

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

    if ( func == "MakeProposal" )
    {
	boolean force_reset      = param["force_reset"     ]:false;
	boolean language_changed = param["language_changed"]:false;

	boolean reinit = false;
	boolean partition_changed = false;

	if ( Packages::timestamp != Storage::GetTargetChangeTime() )
	{
	    // don't set flag partition_changed if it's the first "change"
	    if ( Packages::timestamp != 0 )
	    {
		partition_changed = true;
	    }
	}
	// save information about target change time in module Packages
	Packages::timestamp = Storage::GetTargetChangeTime();

	if ( language_changed || partition_changed )
	{
	    reinit = true;
	}
	y2milestone("package proposal: %1, %2",  force_reset, reinit );
	ret = Packages::Proposal( force_reset,		// user decision: reset to default
				  reinit );		// reinitialize due to language or partition change

	if ( language_changed && !force_reset)
	{
	    // if the  language has changed the software proposal is reset to the default settings
	    if ( !Packages::desktop_dialog_shown )
	    {
	      if (! haskey (ret, "warning"))
	      {
		// the language_changed flag has NOT been set by the NLD frame
		ret = add( ret, "warning", _("The software proposal is reset to default values.") );
	      }
	    }
	    else
	    {
		Packages::desktop_dialog_shown = false;
	    }
	}
    }
    else if ( func == "AskUser" )
    {
	boolean has_next = param["has_next"]:false;

	// call some function that displays a user dialog
	// or a sequence of dialogs here:
	//
	// sequence = DummyMod::AskUser( has_next );

	any chosen_id = param["chosen_id"]:nil;
	if (chosen_id == "mediacheck")
	{
	    symbol result = (symbol)WFM::CallFunction("checkmedia", WFM::Args());
	    ret = $[ "workflow_sequence" : result ];
	}
	else
	{
	    symbol result = `again;

	    while ( result == `again )
	    {
		result = (symbol) WFM::CallFunction ("inst_sw_select", [true, true]);
	    }

	    // Fill return map

	    ret = $[ "workflow_sequence" : result ];
	}
    }
    else if ( func == "Description" )
    {
	// Fill return map.
	//
	// Static values do just nicely here, no need to call a function.

	ret =
	    $[
	      // this is a heading
	      "rich_text_title"	:	_( "Software"  ),
	      // this is a menu entry
	      "menu_title"	:	_( "&Software" ),
	      "id"		:	"software_stuff"
	    ];
    }

    return ret;
}
