ACC SHELL
/**
* 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 59211 2009-10-26 15:55:25Z mzugec $
*
* Network browsing dialogs - all hosts, NFS servers, exports of the NFS server
*
*/
{
module "NetworkPopup";
textdomain "base";
import "Label";
import "NetworkInterfaces";
// 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 = NetworkInterfaces::GetValue(i, "NAME");
if ( (device_name == nil) || (device_name == "") ) {
//TRANSLATORS: Informs that device name is not known
device_name = _("Unknown device");
}
if (size(device_name) > 30) {
device_name = substring (device_name, 0, 27) + "...";
}
string ip_addr = (NetworkInterfaces::GetValue(i, "BOOTPROTO") == "dhcp" ?
// TRANSLATORS: Informs that the IP address is assigned via DHCP
_("DHCP address") :
NetworkInterfaces::GetValue(i, "IPADDR"));
if ( (ip_addr == nil) || (ip_addr == "")) {
// TRANSLATORS: table item, informing that device has no IP address
ip_addr = _("No IP address assigned");
}
string conn = _("No");
if (NetworkInterfaces::IsConnected(i)) conn = _("Yes");
return `item(`id(i), NetworkInterfaces::GetDeviceType(i), device_name, ip_addr, i, conn);
}
);
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"), _("Connected")), Items),
`VSpacing(10)
),
`ButtonBox (
`PushButton (`id(`ok), `opt(`default, `key_F10, `okButton), Label::OKButton()),
`PushButton (`id(`cancel), `opt(`key_F9, `cancelButton), 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;
}
/**
* 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
*/
define string ChooseItemSimple (string title, list<string> items, string selected) ``{
string item = nil;
list Items = maplist(string i, items, ``{
return `item(`id(i), i, i == selected);
}
);
UI::OpenDialog (
`VBox (
`HSpacing (40),
`HBox (
`SelectionBox (`id (`items), title, Items),
`VSpacing(10)
),
`ButtonBox (
`PushButton (`id(`ok), `opt(`default, `key_F10, `okButton), Label::OKButton()),
`PushButton (`id(`cancel), `opt(`key_F9, `cancelButton), Label::CancelButton())
)
));
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...")));
// #71064
// this works also if ICMP broadcasts are ignored
string cmd = "/usr/sbin/rpcinfo -b mountd 1 | cut -d ' ' -f 2 | sort -u";
map out = (map) SCR::Execute (.target.bash_output, cmd);
found_nfs_servers = filter (string s, splitstring (out["stdout"]:"", "\n"), ``( s != ""));
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 = ChooseItemSimple(_("&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 = ChooseItemSimple(_("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 = ChooseItemSimple(_("&Exported Directories"), dirs, selected);
return ret;
}
}
ACC SHELL 2018