home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2007 January, February, March & April
/
Chip-Cover-CD-2007-02.iso
/
boot
/
i386
/
root
/
usr
/
share
/
YaST2
/
modules
/
NetworkPopup.ycp
< prev
next >
Wrap
Text File
|
2006-11-29
|
4KB
|
166 lines
/**
* File:
* NetworkPopup.ycp
*
* Summary:
* Popup dialogs for browsing the local network
*
* Authors:
* Martin Vidner <mvidner@suse.cz>
* Ladislav Slezak <lslezak@suse.cz>
*
* $Id: NetworkPopup.ycp 33492 2006-10-18 12:02:47Z kmachalkova $
*
* Network browsing dialogs - all hosts, NFS servers, exports of the NFS server
*
*/
{
module "NetworkPopup";
textdomain "base";
import "Label";
import "NetworkDevices";
// cache all found hosts on the local network
list<string> found_hosts = nil;
// cache all found NFS servers on the local network
list<string> found_nfs_servers = nil;
/**
* Let the user choose one of a list of items
* @param title selectionbox title
* @param items a list of items
* @param selected preselected a value in the list
* @return one item or nil
*/
global define string ChooseItem (string title, list<string> items, string selected) ``{
string item = nil;
list Items = maplist(string i, items, ``{
string device_name = NetworkDevices::GetValue(i, "NAME");
if (size(device_name) > 30) {
device_name = substring (device_name, 0, 27) + "...";
}
// translators: table item, informing that IP address is assigned via DHCP
return `item(`id(i), NetworkDevices::GetDeviceType(i), device_name, (NetworkDevices::GetValue(i, "BOOTPROTO") == "dhcp" ?
_("DHCP address"): NetworkDevices::GetValue(i, "IPADDR")), i);
}
);
UI::OpenDialog (
`VBox (
`HSpacing (60),
`HBox (
// translators: table header - details about the network device
`Table(`id(`items), `header(_("Device Type"),_("Device Name"),_("IP Address"),_("Device ID")), Items),
`VSpacing(10)
),
`HBox (
`PushButton (`id(`ok), `opt(`default, `key_F10),
Label::OKButton()),
`PushButton (`id(`cancel), `opt(`key_F9),
Label::CancelButton())
)
));
UI::ChangeWidget(`id(`items), `CurrentItem, selected);
UI::SetFocus (`id (`items));
symbol ret = nil;
do
{
ret = (symbol)UI::UserInput();
}
while (ret != `cancel && ret != `ok);
if (ret == `ok)
{
item = (string)UI::QueryWidget (`id (`items), `CurrentItem);
}
UI::CloseDialog();
return item;
}
/**
* Give me NFS server name on the local network
*
* display dialog with all local NFS servers
* @param selected preselected a value in the list
* @return a hostname or nil if "Cancel" was pressed
*/
global define string NFSServer(string selected) ``{
if (found_nfs_servers == nil)
{
// label message
UI::OpenDialog(`Label(_("Scanning for hosts on this LAN...")));
found_nfs_servers = (list<string>)SCR::Read(.net.hostnames.rpc, "nfs");
UI::CloseDialog();
if (found_nfs_servers == nil)
{
found_nfs_servers = [];
}
else
{
// sort list of servers
found_nfs_servers = sort(found_nfs_servers);
}
}
// selection box label
string ret = ChooseItem(_("&NFS Servers"), found_nfs_servers, selected);
return ret;
}
/**
* Give me one host name on the local network
*
* display dialog with all hosts on the local network
* @param selected preselect a value in the list
* @return a hostname or nil if "Cancel" was pressed
*/
global define string HostName(string selected) ``{
if (found_hosts == nil)
{
// label message
UI::OpenDialog(`Label(_("Scanning for hosts on this LAN...")));
found_hosts = (list<string>)sort((list)SCR::Read(.net.hostnames));
UI::CloseDialog();
if (found_hosts == nil)
{
found_hosts = [];
}
}
// selection box label
string ret = ChooseItem(_("Re&mote Hosts"), found_hosts, selected);
return ret;
}
/**
* Give me export path of selected server
*
* display dialog with all exported directories from the selected server
* @param server a NFS server name
* @param selected preselected a value in the list
* @return an export or nil if "Cancel" was pressed
*/
global define string NFSExport(string server, string selected) ``{
list<string> dirs = (list<string>)SCR::Read(.net.showexports, server);
if (dirs == nil)
{
dirs = [];
}
// selection box label
string ret = ChooseItem(_("&Exported Directories"), dirs, selected);
return ret;
}
}