/**
 * File:	include/network/summary.ycp
 * Package:	Network configuration
 * Summary:	Summary and overview functions
 * Authors:	Michal Svec <msvec@suse.cz>
 *
 * $Id: summary.ycp 20262 2004-11-09 15:02:30Z mvidner $
 *
 * All config settings are stored in a global variable Devices.
 * All hardware settings are stored in a global variable Hardware.
 * Deleted devices are in the global list DELETED.
 */

{

textdomain "network";

import "String";

/**
 * Return textual device type
 * @param type device type
 * @return textual form of device type
 * @example DeviceType("eth") -> "Ethernet"
 */
define string DeviceType(string type) {

    if(issubstring(type, "#"))
	/* Device type label */
	// This is what used to be Virtual Interface (eth0:1).
	// In our data model, additional addresses for an interface
	// are represented as its sub-interfaces.
	// And also we frequently confuse "device" and "interface"
	// :-(
	return _("Additional Address");

    map device_types = $[
	/* Device type label */
	"arc"	: _("ARCnet"),
	/* Device type label */
	"atm"	: _("ATM"),
	/* Device type label */
	"bnep"	: _("Bluetooth"),
	/* Device type label */
	"ci"	: _("CLAW"),
	/* Device type label */
	"contr"	: _("ISDN"),
	/* Device type label */
	"ctc"	: _("CTC"),
	/* Device type label */
	"dsl"	: _("DSL"),
	/* Device type label */
	"dummy"	: _("Dummy"),
	/* Device type label */
	"escon"	: _("ESCON"),
	/* Device type label */
	"eth"	: _("Ethernet"),
	/* Device type label */
	"fddi"	: _("FDDI"),
	/* Device type label */
	"hippi"	: _("HIPPI"),
	/* Device type label */
	"hsi"	: _("Hipersockets"),
	/* Device type label */
	"ippp"	: _("ISDN"),
	/* Device type label */
	"irlan"	: _("IrDA"),
	/* Device type label */
	"irda"	: _("IrDA"),
	/* Device type label */
	"isdn"	: _("ISDN"),
	/* Device type label */
	"iucv"	: _("IUCV"),
	/* Device type label */
	"lcs"	: _("OSA LCS"),
	/* Device type label */
	"lo"	: _("Loopback"),
	/* Device type label */
	"modem"	: _("Modem"),
	/* Device type label */
	"myri"	: _("Myrinet"),
	/* Device type label */
	"net"	: _("ISDN"),
	/* Device type label */
	"plip"	: _("Parallel Line"),
	/* Device type label */
	"ppp"	: _("Modem"),
	/* Device type label */
	"qeth"	: _("QETH"),
	/* Device type label */
	"sit"	: _("IPv6-in-IPv4"),
	/* Device type label */
	"slip"	: _("Serial Line"),
	/* Device type label */
	"tr"	: _("Token Ring"),
	/* Device type label */
	"usb"	: _("USB"),
	/* Device type label */
	"vmnet"	: _("VMWare"),
	/* Device type label */
	"wlan"	: _("Wireless"),
	/* Device type label */
	"xp"	: _("XPNET"),
    ];

    if(haskey(device_types, type))
	return device_types[type]:"";

    string type1 = String::FirstChunk (type, "-");
    if(haskey(device_types, type1))
	return device_types[type1]:"";

    y2error("Unknown type: %1", type);
    return type;
}

/**
 * Create list of Table items
 * @param types list of types
 * @param cur current type
 * @return Table items
 */
define list<term> BuildTypesList(list<string> types, string cur) {
    return maplist(string t, types, {
	return `item(`id(t), DeviceType(t), t == cur);
    });
}

/**
 * Create table widget for the overview screens with correct spacings
 * @param caption table caption
 * @param header table header
 * @param contents table contents
 * @param first table is first of the two tables
 * @return table widget
 */
define term OverviewTableContents(string caption, term header, list contents, boolean first) {

    term addbutton = nil;
    term editbutton = nil;
    term deletebutton = nil;
    if(first) {
	/* Pushbutton label */
	addbutton = `PushButton(`id(`add), `opt(`key_F3), _("A&dd"));
	/* Pushbutton label */
	editbutton = `PushButton(`id(`edit), `opt(`key_F4), _("&Edit"));
	/* Pushbutton label */
	deletebutton = `PushButton(`id(`delete), `opt(`key_F5), _("De&lete"));
    }
    else {
	/* Pushbutton label (different shortcut) */
	addbutton = `PushButton(`id(`Add), _("&Add"));
	/* Pushbutton label (different shortcut) */
	editbutton = `PushButton(`id(`Edit), _("Ed&it"));
	/* Pushbutton label (different shortcut) */
	deletebutton = `PushButton(`id(`Delete), _("Dele&te"));
    }

    return `HBox(`HSpacing(1.5), `VBox(
	`VSpacing(0.0),
	caption != ""? `Left(`Heading(caption)) : `VSpacing(0.0),
	`Table(
	    `id(first?`table:`Table),
	    `opt(`notify),
	    header,
	    contents
	),
	`VSpacing(0.4),
	`HBox(
	    `opt(`hstretch),
	    addbutton,
	    editbutton,
	    deletebutton
	),
	`VSpacing(0.5)
    ), `HSpacing(1.5));

}

/**
 * Create table widget for the overview screens
 * @param header table header
 * @param contents table contents
 * @return table widget
 */
define term OverviewTable(term header, list contents) {
    return `VBox(
	`VSpacing(0.5),
	OverviewTableContents("", header, contents, true)
    );
}

/**
 * Create two table widgets for the overview screens
 * @param caption1 first table caption
 * @param header1 first table header
 * @param contents1 first table contents
 * @param caption2 second table caption
 * @param header2 second table header
 * @param contents2 second table contents
 * @return table widget
 */
define term OverviewTableDouble(string caption1, term header1, list contents1, string caption2, term header2, list contents2) {

    return `VBox(
	`VSpacing(0.5),
	OverviewTableContents(caption1, header1, contents1, true),
	OverviewTableContents(caption2, header2, contents2, false)
    );

}

/*
    list overviewdev = [
	`item(`id(0), "0", "ISDN", "ippp0", "Hisax ISDN"),
    ];
    list overviewif = [
	`item(`id(0), "0", "ippp", "Contactel", "1.2.3.4", "4.3.2.1"),
	`item(`id(1), "1", "ippp", "Czech Online", "1.2.3.6", "6.3.2.1"),
    ];

    y2debug("overviewdev=%1", overviewdev);
    y2debug("overviewif=%1", overviewif);

    import "Wizard";
    import "Label";
    Wizard::CreateDialog();
    term contents = nil;

    contents = OverviewTable(
	`header(_("No."), _("Type"), _("Device"), _("Hardware")),
	overviewdev
    );

    Wizard::SetContentsButtons("Network cards configuration overview", contents, "helptext",
	    Label::BackButton(), Label::FinishButton());

    UI::UserInput();

    contents = OverviewTableDouble(
	"ISDN devices",
	`header(_("No."), _("Type"), _("Device"), _("Hardware")),
	overviewdev,
	"Providers",
	`header(_("No."), _("Type"), _("Connection"), _("IP"), _("Remote IP")),
	overviewif
    );

    Wizard::SetContentsButtons("ISDN configuration overview", contents, "helptext",
	    Label::BackButton(), Label::FinishButton());

    UI::UserInput();

*/

/* EOF */
}
