/**
 * File:	include/network/lan/details.ycp
 * Package:	Network configuration
 * Summary:	Network card details dialogs
 * Authors:	Michal Svec <msvec@suse.cz>
 *
 * $Id: details.ycp 22129 2005-03-02 10:04:23Z locilka $
 */

{

textdomain "network";

import "CWM";
import "Label";
import "Lan";
import "NetworkDevices";
import "Popup";
import "SuSEFirewall4Network";
import "Wizard";

include "network/routines.ycp";
include "network/widgets.ycp";

/**
 * Dialog for detailed network card options
 * @return dialog result
 */
define any DetailsDialog() {

    ScreenName("lan-details");

    widget_descr["STARTMODE"] = MakeStartmode (
	["auto", "ifplugd", "hotplug", "manual", "off", ]);

    /* Details dialog caption */
    string caption = _("Detailed Network Card Settings");

    /* Details dialog help 1 */
    string help = _("<p>Configure the detailed network card settings here.</p>") +

    /* Details dialog help 2 */
    _("<p>You can set the maximum transfer unit (<b>MTU</b>) of an interface.</p>") +

	widget_descr["STARTMODE", "help"]:""+
	widget_descr["USERCONTROL", "help"]:""+

	// Details dialog help
	_("<p>Select the <b>Firewall Zone</b> to put the interface in. If you
select a zone, the firewall will be enabled. If you do not and other 
firewalled interfaces exist, the firewall
will stay enabled but all traffic will be blocked for this
interface. If you do not select a zone and no others exist, 
the firewall will be disabled.</p>");

    string interface = NetworkDevices::device_name (Lan::type, Lan::device);
    string mtu = Lan::mtu;
    string startmode = Lan::startmode;
    boolean usercontrol = Lan::usercontrol;

    list<map> widgets = CWM::CreateWidgets (
	["USERCONTROL", "STARTMODE", ],
	widget_descr);

    /* Details dialog contents */
    term contents = `HBox(
	`HSpacing(6),
	/* Frame label */
	`Frame(_("Detailed Network Card Settings"), `HBox(`HSpacing(2), `VBox(
	    `VSpacing(1),
	    /* TextEntry label */
	    `Left(`TextEntry(`id(`mtu), _("&MTU"), mtu)),
	    `VSpacing(0.5),
	    // STARTMODE
	    `Left(widgets[1, "widget"]:`Empty ()),
	    `VSpacing(0.5),
	    // USERCONTROL
	    // 0 is index to CreateWidgets... ugly
	    `Left(widgets[0, "widget"]:`Empty ()),
	    `VSpacing(0.5),
	    `Left (`ComboBox (
		       `id (`zone),
		       // Combo Box label
		       _("Firewall &Zone"),
		       SuSEFirewall4Network::FirewallZonesComboBoxItems ()
		       )),
	    `VSpacing(1)
	    ), `HSpacing(2))),
	`HSpacing(6)
    );

    Wizard::SetContentsButtons(caption, contents, help,
	    Label::BackButton(), Label::OKButton());

    UI::ChangeWidget (`id ("USERCONTROL"), `Value, usercontrol);
    UI::ChangeWidget (`id ("STARTMODE"), `Value, startmode);
    UI::ChangeWidget (`id (`zone), `Value, SuSEFirewall4Network::GetZoneOfInterface (interface));

    any ret = nil;
    while(true) {

	ret = UI::UserInput();

	/* abort? */
	if(ret == `abort || ret == `cancel) {
	    if(ReallyAbort()) break;
	    else continue;
	}
	/* back */
	else if(ret == `back) {
	    break;
	}
	else if(ret == `next) {
	    /* check* */
	    break;
	}
	else {
	    y2error("Unexpected retcode: %1", ret);
	    continue;
	}

    }

    /* update the configuration */
    if(ret == `next) {
	Lan::startmode = (string) UI::QueryWidget(`id("STARTMODE"), `Value);
	Lan::usercontrol = (boolean) UI::QueryWidget (`id ("USERCONTROL"), `Value);
	string zone = (string) UI::QueryWidget(`id(`zone), `Value);
	SuSEFirewall4Network::ProtectByFirewall (interface, zone, zone != "");
	Lan::mtu = (string) UI::QueryWidget(`id(`mtu), `Value);
    }

    return ret;
}


/* EOF */
}
