/**
 * File:	include/network/lan/hardware.ycp
 * Package:	Network configuration
 * Summary:	Hardware dialogs
 * Authors:	Michal Svec <msvec@suse.cz>
 *
 * $Id: hardware.ycp 21341 2005-02-07 16:15:59Z mvidner $
 */

{

textdomain "network";

import "Arch";
import "Label";
import "Lan";
import "NetworkDevices";
import "NetworkModules";
import "Popup";
import "Wizard";

include "network/summary.ycp";

/**
 * Manual network card configuration dialog
 * @return dialog result
 */
define any HardwareDialog() {

    ScreenName("lan-hardware");

    /* Manual dialog caption */
    string caption = _("Manual Network Card Configuration");

    /* Manual dialog help 1/4 */
    string help = _("<p>Here, set up your networking device.
The values are written to <i>/etc/sysconfig/hardware/hwcfg-*</i>.</p>
") +

    /* Manual dialog help 2/4 */
_("<p><b>Options</b> for the module should be written in the format
<i>option</i>=<i>value</i>. Each entry should be space separated,
for example, <i>io=0x300 irq=5</i>. <b>Note:</b> If  two cards are configured
with the same module name, options will be merged while saving.</p>");

    if(!(Lan::operation == `edit /* FIXME: unique || Lan::unique != "" */ || Arch::s390 () == true))

    /* Manual dialog help 3/4 */
help = help + _("<p>Get a list of available network cards by pressing
<b>Select from List</b>.</p>") +

    /* Manual dialog help 4/4 */
_("<p>If you have a <b>PCMCIA</b> network card, select PCMCIA.
If you have a <b>USB</b> network card, select USB.</p>
");

    if(Arch::s390 ())
	/* Manual dialog help 5/4 */
	help = _("<p>Here, set up your networking device. The values will be
written to <i>/etc/modprobe.conf</i> or <i>/etc/chandev.conf</i>.</p>
") +

	/* Manual dialog help 6/4 */
_("<p>Options for the module should be written in the format specified
in the <b>IBM Device Drivers and Installation Commands</b> manual.</p>");

    string modul = NetworkModules::Alias; // FIXME: MOD Lan::Module["module"]:"";
    string options = NetworkModules::Options; // FIXME: MOD Lan::Module["options"]:"";

    string mtu = Lan::mtu;
    string hotplug = Lan::hotplug;
    y2milestone("hotplug=%1", Lan::hotplug);

    string type = Lan::type;
    if(type == "") {
	y2error("Shouldn't happen -- type is empty. Assuming eth.");
	type = "eth";
    }
    string realtype = NetworkDevices::RealType(type, hotplug);
    string device = Lan::device;
    string default_device = Lan::device;
    // #38213, remember device id when we switch back from pcmcia/usb
    string non_hotplug_device_id = device;
    string hwcfg = Lan::nm_name;

    // FIXME duplicated in address.ycp
    list<string> device_types = [ "arc", "bnep", "dummy", "eth", "fddi", "myri", "tr", "usb", "wlan" ];

    if(Arch::s390 ())
	device_types = [ "eth", "tr", "hsi", "ctc", "escon", "iucv", "qeth", "lcs" ];

    if(Arch::ia64 ())
	device_types = add(device_types, "xp");

    if(issubstring(device, "bus-pcmcia"))
	hotplug = "pcmcia";
    else if(issubstring(device, "bus-usb"))
	hotplug = "usb";
    y2milestone("hotplug=%1", Lan::hotplug);

    term CheckBoxes = `HBox(
	`HSpacing(1.5),
	/* CheckBox label */
	`CheckBox(`id(`pcmcia), `opt(`notify), _("&PCMCIA"), hotplug == "pcmcia"),
	`HSpacing(1.5),
	/* CheckBox label */
	`CheckBox(`id(`usb), `opt(`notify), _("&USB"), hotplug == "usb"),
	`HSpacing(1.5)
    );

    /* Placeholders (translations) */
    term XBox = `HBox(
	/* ComboBox label */
	`ComboBox(`id(`hotplug), `opt(`notify), _("&Hotplug Type"), []),
	/* CheckBox label */
	`CheckBox(`id(`pci), `opt(`notify), _("P&CI"), hotplug == "pci"),
	`HSpacing(1.5)
    );

    /* Pushbutton label */
    term ListButton = `PushButton(`id(`list), _("Select from &List"));

    /* Disable PCMCIA and USB checkboxex on Edit and s390 */
    if(Lan::operation == `edit /* FIXME: unique || Lan::unique != "" */ || Arch::s390 () == true)
	CheckBoxes = `VSpacing(0);

    /* Frame label */
    term KernelBox = `Frame(_("&Kernel Module"), `HBox(`HSpacing(0.5), `VBox(
	`VSpacing(0.4),
	/* Text entry label */
	`TextEntry(`id(`hwcfg), _("&Hardware Configuration Name"), hwcfg),
	`HBox(
	    /* Text entry label */
	    `TextEntry(`id(`modul), _("&Module Name"), modul),
	    `HSpacing(0.2),
	    `TextEntry(`id(`options), Label::Options (), options)
	),
	`VSpacing(0.4),
	CheckBoxes,
	`VSpacing(0.4)
    ),`HSpacing(0.5)));

    list devices = Lan::FreeDevices(realtype); // TODO: id-, bus-, ... here
    if(!contains(devices, device)) devices = prepend(devices, device);

    term DeviceNumberBox = `ReplacePoint(`id(`rnum),
	/* TextEntry label */
	`ComboBox (`id(`num), `opt(`editable, `hstretch), _("&Configuration Name"), [device]));

    /* TextEntry label */
    term MTUBox = `TextEntry(`id(`mtu), _("M&aximum Transfer Unit (MTU)"), mtu);
    MTUBox = `VSpacing(0);
    // FIXME: help missing

    /* Manual dialog contents */
    term TypeNameWidgets = 
	    /* Frame label */
	    `Frame(_("Network &Configuration"),`VBox(
		`VSpacing(0.2),
		`HBox(
		    `HSpacing(0.5),
		    `ComboBox(`id(`dev), `opt(`hstretch, `notify),
			/* ComboBox label */
			_("&Device Type"), BuildTypesList(device_types, type)),
		    `HSpacing(1.5),
		    DeviceNumberBox,
		    `HSpacing(0.5)
		),
		`VSpacing(0.2)
	    ));

    /* Add hardware -> don't allow some changes (card type) */
    // FIXME: devname if(Lan::operation == `add && Lan::unique != "") {
    if(false) {

	string typ = DeviceType(type);
	if(hotplug == "pcmcia") typ = typ + " (PCMCIA)";
	if(hotplug == "usb") typ = typ + " (USB)";

	TypeNameWidgets =
		/* Frame label */
		`Frame(_("Configuration Name"),`VBox(
		    `VSpacing(0.2),
		    `HBox(
			`HSpacing(0.9),
			`VBox(
			    /* Label text */
			    `Left(`Label(_("Device Type:"))),
			    `VSpacing(0.2),
			    `Left(`Label(`opt(`outputField), typ))
			),
			`HSpacing(0.5),
			DeviceNumberBox,
			`HSpacing(0.5)
		    ),
		    `VSpacing(0.2)
		));
    }

    /* Edit -> don't allow some changes */
    // FIXME: devname if(true /* FIXME: devname Lan::operation == `edit */) {
    if(Lan::operation == `edit /* FIXME: unique || Lan::unique != "" */) {

	ListButton = `VSpacing(0);

	TypeNameWidgets =
		`Left(`HSquash(`Left(`VBox(
		    `HBox(
			/* Label text */
			`HWeight(1, `Right(`Label(_("Configuration Name")))),
			`HSpacing(0.5),
			`HWeight(1, `Left(`Label(`opt(`outputField), NetworkDevices::device_name(realtype, device))))
		    ),
		    `VSpacing(0.5),
		    `HBox(
			/* Label text */
			`HWeight(1, `Right(`Label(_("Hardware Name")))),
			`HSpacing(0.5),
			`HWeight(1, `Left(`Label(`opt(`outputField), hwcfg)))
		    )
		))));
    }

    /* Frame label */
    term ButtonBox = `HBox(
	`HStretch(),
	`HSpacing(0.5),
	ListButton,
	`HSpacing(0.5),
	`HStretch()
    );

    term contents = `HBox(
	`HSpacing(2),
	`VBox(
	    `VSpacing(0.5),
	    TypeNameWidgets,
	    `VSpacing(1.5),
	    KernelBox,
	    `VSpacing(0.4),
	    MTUBox,
	    `VSpacing(1.5),
	    ButtonBox,
	    `VSpacing(0.5)
	    ),
	`HSpacing(2)
	);

    if(Lan::operation == `edit /* FIXME: unique || Lan::unique != "" */)
	Wizard::SetContentsButtons(caption, contents, help,
		Label::BackButton(), Label::OKButton());
    else
	Wizard::SetContentsButtons(caption, contents, help,
		Label::BackButton(), Label::NextButton());

    boolean no_hotplug = hotplug == "";
    boolean no_hotplug_dummy = no_hotplug && type != "dummy";
    UI::ChangeWidget(`id(`modul), `Enabled, no_hotplug_dummy);
    UI::ChangeWidget(`id(`options), `Enabled, no_hotplug_dummy);
    ChangeWidgetIfExists(`id(`list), `Enabled, no_hotplug_dummy);
    ChangeWidgetIfExists(`id(`hwcfg), `Enabled, no_hotplug);
    ChangeWidgetIfExists(`id(`usb), `Enabled, (hotplug == "usb" || hotplug == "") && type != "dummy");
    ChangeWidgetIfExists(`id(`pcmcia), `Enabled, (hotplug == "pcmcia" || hotplug == "") && type != "dummy");
    ChangeWidgetIfExists(`id(`num), `ValidChars, NetworkDevices::ValidCharsIfcfg ());
    ChangeWidgetIfExists(`id(`hwcfg), `ValidChars, NetworkModules::ValidCharsHwcfg ());

    any ret = nil;
    while(true) {
	ret = UI::UserInput();

	/* abort? */
	if(ret == `abort || ret == `cancel) {
	    if(ReallyAbort()) break;
	    else continue;
	}
	/* change device type or pcmcia/usb card? */
	else if(ret == `pcmcia || ret == `usb || ret == `dev) {

	    if(UI::WidgetExists(`id(`pcmcia)) || UI::WidgetExists(`id(`usb))) {
		if(UI::QueryWidget(`id(`pcmcia), `Value) == true)
		    hotplug = "pcmcia";
		else if(UI::QueryWidget(`id(`usb), `Value) == true)
		    hotplug = "usb";
		else
		    hotplug = "";
	    }
	    y2debug("hotplug=%1", hotplug);

	    if(UI::WidgetExists(`id(`dev))) {
		type = (string) UI::QueryWidget(`id(`dev), `Value);
		realtype = NetworkDevices::RealType(type, hotplug);
	    }
	    y2debug("type=%1", type);
	    y2debug("realtype=%1", realtype);

	    if(type == "usb") {
		UI::ChangeWidget(`id(`usb), `Value, true);
		hotplug = "usb";
	    }

	    no_hotplug = hotplug == "";
	    no_hotplug_dummy = no_hotplug && type != "dummy";
	    UI::ChangeWidget(`id(`modul), `Enabled, no_hotplug_dummy);
	    UI::ChangeWidget(`id(`options), `Enabled, no_hotplug_dummy);
	    ChangeWidgetIfExists(`id(`list), `Enabled, no_hotplug_dummy);
	    ChangeWidgetIfExists(`id(`hwcfg), `Enabled, no_hotplug);
	    ChangeWidgetIfExists(`id(`usb), `Enabled, (hotplug == "usb" || hotplug == "") && type != "dummy");
	    ChangeWidgetIfExists(`id(`pcmcia), `Enabled, (hotplug == "pcmcia" || hotplug == "") && type != "dummy");

	    // list devices = Lan::FreeDevices(realtype);
	    // default_device = (string) devices[0]:"";
	    /* TextEntry label */
	    // UI::ReplaceWidget(`id(`rnum), `TextEntry(`id(`num), `opt(`hstretch), _("&Configuration Name"), Lan::nm_name));

	    device = (string) UI::QueryWidget (`id (`num), `Value);
	    if (device != "bus-usb" && device != "bus-pcmcia")
	    {
		non_hotplug_device_id = device;
	    }

	    if(hotplug == "usb")
		device = "bus-usb";
	    else if(hotplug == "pcmcia")
		device = "bus-pcmcia";
	    else
		device = non_hotplug_device_id;

	    UI::ChangeWidget(`id(`num), `Value, device);

	    if(Arch::s390 ()) {
		if(type == "tr" || type == "lcs") modul = "lcs";
		if(type == "hsi" || type == "qeth") modul = "qeth";
		if(type == "ctc" || type == "escon") modul = "ctc";
		if(type == "iucv") modul = "netiucv";
		UI::ChangeWidget(`id(`modul), `Value, modul);
	    }
	    if(type == "xp") {
		modul = "xpnet";
		UI::ChangeWidget(`id(`modul), `Value, modul);
	    }
	    else if (type == "dummy") // #44582
	    {
		hwcfg = (string) UI::QueryWidget (`id (`hwcfg), `Value);

		modul = "dummy";
		options = sformat ("-o dummy-%1", hwcfg);
		UI::ChangeWidget(`id(`modul), `Value, modul);
		UI::ChangeWidget(`id(`options), `Value, options);
	    }

	    continue;
	}
	else if(ret == `back) {
	    break;
	}
	/* select from the list *//*
	else if(ret == `list) {
	    Lan::type = type;
	    Lan::device = tointeger(UI::QueryWidget(`id(`num), `Value));
	    break;
	} */
	else if(ret == `next || ret == `list) {
	    /* FIXME: check_* */

	    if(UI::WidgetExists(`id(`hwcfg))) {
		hwcfg = (string) UI::QueryWidget (`id (`hwcfg), `Value);
		if (Lan::operation == `add || hwcfg != Lan::nm_name) {
		    if (contains (NetworkModules::ListM(""), hwcfg)) {
			UI::SetFocus (`id (`hwcfg));
			/* Popup text */
			Popup::Error(sformat(_("Hardware configuration %1 already exists.
Choose a different one."), hwcfg));
			continue;
		    }
		}
	    }

	    if(Lan::operation == `add && UI::WidgetExists(`id(`num))) {
		string nm = (string) UI::QueryWidget(`id(`num), `Value);
		if(Lan::operation == `add || (device != Lan::device && type != Lan::type)) {
		    if(contains(NetworkDevices::List(""), NetworkDevices::device_name(type, nm))) {
			/* Popup text */
			Popup::Error(sformat(_("Configuration name %1 (%2) already exists.
Choose a different one."), nm, NetworkDevices::device_name(type, nm)));
			UI::SetFocus(`id(`num));
			continue;
		    }
		}
	    }

	    if(UI::WidgetExists(`id(`num))) {
		string devic = (string) UI::QueryWidget(`id(`num), `Value);
		if(false /* devic != default_device */) {
		    y2warning("Default device: %1 -> %2", default_device, devic);
		    /* Popup text */
		    string pop = _("You changed the default device number.

This possibility is only intended for systems with built-in network cards
or cards with multiple interfaces. If you do not have such network card,
this would probably result in a nonfunctional network configuration.

Really continue?
");
		    if(Popup::YesNoHeadline(Label::WarningMsg(), pop) == true) {
			y2warning("Default device changed!");
			break;
		    }
		    else continue;
		}
	    }
	    break;
	}
	else {
	    y2error("Unexpected return code: %1", ret);
	    continue;
	}
    }

    if(ret == `next || ret == `list) {
	NetworkModules::Alias /* FIXME: MOD Lan::Module["module"] */ = (string) UI::QueryWidget(`id(`modul), `Value);
	NetworkModules::Options /* FIXME: MOD Lan::Module["options"] */ = (string) UI::QueryWidget(`id(`options), `Value);

	if(UI::WidgetExists(`id(`hwcfg))) {
	    Lan::nm_name_old = Lan::nm_name;
	    Lan::nm_name = (string) UI::QueryWidget(`id(`hwcfg), `Value);
	}

	if(UI::WidgetExists(`id(`mtu)))
	    Lan::mtu = (string) UI::QueryWidget(`id(`mtu), `Value);

	if(UI::WidgetExists(`id(`num)))
	    Lan::device = (string) UI::QueryWidget(`id(`num), `Value);

	if(UI::WidgetExists(`id(`pcmcia)) || UI::WidgetExists(`id(`usb))) {
	    if(UI::QueryWidget(`id(`pcmcia), `Value) == true)
		Lan::hotplug = "pcmcia";
	    else if(UI::QueryWidget(`id(`usb), `Value) == true)
		Lan::hotplug = "usb";
	    else
		Lan::hotplug = "";
	}
	Lan::hotplug = "";

	if(UI::WidgetExists(`id(`dev))) {
	    type = (string) UI::QueryWidget(`id(`dev), `Value);
	    Lan::type = type;
	}

	y2milestone("type=%1",type);
    }

    /* s390 screen not used #19542
    if(ret == `next && Lan::type == "hsi") ret = `s390;
    */
    return ret;
}

/**
 * Call back for a manual selection from the list
 * @return dialog result
 */
define any SelectionDialog() {

    ScreenName("lan-hardware-selection");

    string type = Lan::type;
    integer selected = 0;

    /* map NetworkCards */
    include "network/lan/cards.ycp";

    list<map> hwlist = NetworkCards[type]:[];
    list cards = hwlist2items(hwlist, 0);

    /* Manual selection caption */
    string caption = _("Manual Network Card Selection");

    /* Manual selection help */
    string helptext = _("<p>Select the network card to configure. Search
for a particular network card by entering the name in the search entry.</p>");

    /* Manual selection contents */
    term contents = `VBox(
	`VSpacing(0.5),
	/* Selection box label */
	`ReplacePoint(`id(`rp), `SelectionBox(`id(`cards), _("&Network Card"), cards)),
	`VSpacing(0.5),
	/* Text entry field */
	`TextEntry(`id(`search), `opt(`notify), _("&Search")),
	`VSpacing(0.5)
    );

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

    UI::SetFocus(`id(`cards));

    any ret = nil;
    while(true) {
	ret = UI::UserInput();

	/* abort? */
	if(ret == `abort || ret == `cancel) {
	    if(ReallyAbort()) break;
	    else continue;
	}
	else if(ret == `search) {

	    string entry = (string) UI::QueryWidget(`id(`search), `Value);

	    list l = filter(term e, (list<term>) cards, {
		return tolower(substring(e[1]:"", 0, size(entry))) == tolower(entry);
	    });

	    if(size(entry) == 0) selected = 0;
	    if(size(l) > 0) selected = l[0, 0, 0]:0;

	    cards = [];
	    cards = hwlist2items(hwlist, selected);

	    /* Selection box title */
	    UI::ReplaceWidget(`id(`rp), `SelectionBox(`id(`cards), _("&Network Card"), cards));
	}
	else if(ret == `back) {
	    break;
	}
	else if(ret == `next) {
	    /* FIXME: check_* */
	    break;
	}
	else {
	    y2error("Unexpected return code: %1", ret);
	    continue;
	}
    }

    if(ret == `next) {
	selected = (integer) UI::QueryWidget(`id(`cards), `CurrentItem);
	if(selected == nil) selected = 0;
	map card = hwlist[selected]:$[];
	Lan::description = card["name"]:"";

	NetworkModules::Alias /* FIXME: MOD Lan::Module["module"] */ = card["module"]:"";
	NetworkModules::Options /* FIXME: MOD Lan::Module["options"] */ = card["options"]:"";
    }

    return ret;
}

/**
 * S/390 devices configuration dialog
 * @return dialog result
 */
define any S390Dialog() {

    ScreenName("lan-hardware-s390");

    /* S/390 dialog caption */
    string caption = _("S/390 Network Card Configuration");

    string helptext = "";
    term contents = `Empty ();

    if(Lan::type == "qeth") {
	contents = `HBox(
	    `HSpacing(6),
	    /* Frame label */
	    `Frame(_("S/390 Device Settings"), `HBox(`HSpacing(2), `VBox(
		`VSpacing(1),
		/* TextEntry label */
		`TextEntry(`id(`chan_mode), _("&Port Name"), Lan::chan_mode),
		`VSpacing(1),
		/* TextEntry label */
		`TextEntry(`id(`qeth_options), Label::Options (), Lan::qeth_options),
		`VSpacing(1),
		/* CheckBox label */
		`Left(`CheckBox(`id(`ipa_takeover), _("&Enable IPA Takeover"))),
		`VSpacing(1)
		), `HSpacing(2))),
	    `HSpacing(6)
	);
	/* S/390 dialog help: QETH Port name */
	helptext = _("<p>Enter the <b>Port Name</b> for this interface (case-sensitive).</p>") +
	/* S/390 dialog help: QETH Options */
	_("<p>Enter any additional <b>Options</b> for this interface (separated by spacess).</p>") +
	_("<p>Select <b>Enable IPA Takeover</b> if IP address takeover should be enabled for this interface.</p>");
    }

    if(Lan::type == "hsi") {
	contents = `HBox(
	    `HSpacing(6),
	    /* Frame label */
	    `Frame(_("S/390 Device Settings"), `HBox(`HSpacing(2), `VBox(
		`VSpacing(1),
		/* TextEntry label */
		`TextEntry(`id(`qeth_options), Label::Options (), Lan::qeth_options),
		`VSpacing(1),
		/* CheckBox label */
		`Left(`CheckBox(`id(`ipa_takeover), _("&Enable IPA Takeover"))),
		`VSpacing(1)
		), `HSpacing(2))),
	    `HSpacing(6)
	);
	/* S/390 dialog help: QETH */
	helptext = _("<p>Enter any additional <b>Options</b> for this interface (separated by spaces).</p>") +
	_("<p>Select <b>Enable IPA Takeover</b> if IP address takeover should be enabled for this interface.</p>");
    }

    if(Lan::type == "lcs") {
	contents = `HBox(
	    `HSpacing(6),
	    /* Frame label */
	    `Frame(_("S/390 Device Settings"), `HBox(`HSpacing(2), `VBox(
		`VSpacing(1),
		/* TextEntry label */
		`TextEntry(`id(`chan_mode), _("&Port Number"), Lan::chan_mode),
		`VSpacing(1)
		), `HSpacing(2))),
	    `HSpacing(6)
	);
	/* S/390 dialog help: LCS */
	helptext = _("<p>Choose the <b>Port Number</b> for this interface.</p>");
    }

    list ctcitems = [
	/* ComboBox item: CTC device protocol */
	`item(`id("0"), _("Compatibility Mode")),
	/* ComboBox item: CTC device protocol */
	`item(`id("1"), _("Extended Mode")),
	/* ComboBox item: CTC device protocol */
	`item(`id("2"), _("CTC-Based tty (Linux to Linux Connections)")),
	/* ComboBox item: CTC device protocol */
	`item(`id("3"), _("Compatibility Mode with OS/390 and z/OS")),
    ];

    if(Lan::type == "ctc") {
	contents = `HBox(
	    `HSpacing(6),
	    /* Frame label */
	    `Frame(_("S/390 Device Settings"), `HBox(`HSpacing(2), `VBox(
		`VSpacing(1),
		/* TextEntry label */
		`ComboBox(`id(`chan_mode), _("&Protocol"), ctcitems),
		`VSpacing(1)
		), `HSpacing(2))),
	    `HSpacing(6)
	);
	/* S/390 dialog help: CTC */
	helptext = _("<p>Choose the <b>Protocol</b> for this interface.</p>");
    }

    if(Lan::type == "iucv") {
	contents = `HBox(
	    `HSpacing(6),
	    /* Frame label */
	    `Frame(_("S/390 Device Settings"), `HBox(`HSpacing(2), `VBox(
		`VSpacing(1),
		/* TextEntry label, #42789 */
		`TextEntry(`id(`chan_mode), _("&Peer Name"), ""),
		`VSpacing(1)
		), `HSpacing(2))),
	    `HSpacing(6)
	);
	/* S/390 dialog help: IUCV, #42789 */
	helptext = _("<p>Enter the name of the IUCV peer,
for example, the z/VM user name with which to connect (case-sensitive).</p>
");
    }

    Wizard::SetContentsButtons(caption, contents, helptext,
	    Label::BackButton(), Label::NextButton());

    if(Lan::type == "ctc") 
        UI::ChangeWidget(`id(`chan_mode), `Value, Lan::chan_mode);

    if (Lan::type == "hsi" || Lan::type == "qeth")
        UI::ChangeWidget(`id(`ipa_takeover), `Value, Lan::ipa_takeover);

    if (Lan::type != "hsi")
        UI::SetFocus(`id(`chan_mode));
    else
        UI::SetFocus(`id(`qeth_options));

    // FIXME: no spaces
    // UI::ChangeWidget(`id(`key), `ValidChars, "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_:;");

    any ret = nil;
    while(true) {
	ret = UI::UserInput();

	if(ret == `abort || ret == `cancel) {
	    if(ReallyAbort()) break;
	    else continue;
	}
	else if(ret == `back) {
	    break;
	}
	else if(ret == `next) {
	    break;
	}
	else if(ret == `mode) {
	    continue;
	}
	else {
	    y2error("Unexpected return code: %1", ret);
	    continue;
	}
    }

    if(ret == `next) {
	if(Lan::type == "iucv") {
	    Lan::nm_name = "iucv-id-" + (string) UI::QueryWidget(`id(`chan_mode), `Value);
	    Lan::device = "id-" + (string) UI::QueryWidget(`id(`chan_mode), `Value);
	}
	else if (Lan::type != "hsi")
	       Lan::chan_mode = (string) UI::QueryWidget(`id(`chan_mode), `Value);
	if(Lan::type == "qeth" || Lan::type == "hsi") {
	    Lan::qeth_options = (string) UI::QueryWidget(`id(`qeth_options), `Value);
	    Lan::ipa_takeover = (boolean) UI::QueryWidget(`id(`ipa_takeover), `Value);
	}

    }

    return ret;
}

/* EOF */
}
