/**
 * File:	clients/lan_proposal.ycp
 * Package:	Network configuration
 * Summary:	Lan configuration proposal
 * Authors:	Michal Svec <msvec@suse.cz>
 *
 * $Id: lan_proposal.ycp 20958 2005-01-25 16:34:37Z mvidner $
 */

{

textdomain "network";

/* The main () */
y2milestone("----------------------------------------");
y2milestone("Lan proposal started");
y2milestone("Arguments: %1", WFM::Args());

import "Arch";
import "Lan";
import "Linuxrc";
import "Progress";

include "network/lan/wizards.ycp";

list args = WFM::Args();

string func = args[0]:"";
map param = args[1]:$[];
map ret = $[];

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

    if(force_reset || !Lan::proposal_valid) {
	Lan::proposal_valid = true;
	/* Popup text */
	BusyPopup(_("Detecting network cards..."));
	boolean progress_orig = Progress::set (false);
	Lan::Read();
	Lan::Propose();
	Progress::set (progress_orig);
	BusyPopupClose();
    }
    list sum = Lan::Summary("summary");
    proposal = sum[0]:"";

    ret = $[
	"preformatted_proposal" : proposal,
	"warning_level" : warning_level,
	"warning" : warning,
    ];
}
/* run the module */
else if(func == "AskUser") {
    map stored = Lan::Export();
    symbol seq = LanAutoSequence();
    if(seq != `next) Lan::Import(stored);
    ret = $[
	"workflow_sequence" : seq
    ];
}
/* create titles */
else if(func == "Description") {
    ret = $[
	/* RichText label */
	"rich_text_title" : _("Network Interfaces"),
	/* Menu label */
	"menu_title" : _("&Network Interfaces"),
	"id" : "lan",
    ];
}
/* write the proposal */
else if (func == "Write") {
    if (PackagesInstall (Lan::Packages ()) != `next)
    {
	// popup already shown
	y2error("Packages installation failure, not saving");
    }
    else if (Arch::s390 () || Linuxrc::vnc () || Linuxrc::usessh () )
	Lan::WriteOnly();
    else {
	Lan::Write();
	// With a little help from my friends:
	// Let yast2-printer listen for CUPS broadcasts
	SCR::Execute(.target.bash_background, "test -f /usr/lib/YaST2/bin/listen_remote_ipp && /usr/lib/YaST2/bin/listen_remote_ipp 120");
    }
}
/* unknown function */
else {
    y2error("unknown function: %1", func);
}

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

/* EOF */
}
