Networksetup update
[enigma2.git] / lib / python / Screens / NetworkSetup.py
1 from Screen import Screen
2 from Components.ActionMap import ActionMap,NumberActionMap
3 from Screens.MessageBox import MessageBox
4 from Screens.InputBox import InputBox
5 from Screens.Standby import *
6 from Components.Network import iNetwork
7 from Components.Label import Label,MultiColorLabel
8 from Components.Pixmap import Pixmap,MultiPixmap
9 from Components.MenuList import MenuList
10 from Components.config import config, ConfigYesNo, ConfigIP, NoSave, ConfigText, ConfigSelection, getConfigListEntry, ConfigNothing
11 from Components.ConfigList import ConfigListScreen
12 from Components.PluginComponent import plugins
13 from Components.MultiContent import MultiContentEntryText, MultiContentEntryPixmapAlphaTest
14 from Plugins.Plugin import PluginDescriptor
15 from enigma import eTimer
16 from os import path as os_path, system as os_system, unlink
17 from re import compile as re_compile, search as re_search
18 from Tools.Directories import resolveFilename, SCOPE_PLUGINS
19
20 from Tools.Directories import SCOPE_SKIN_IMAGE,SCOPE_PLUGINS, resolveFilename
21 from Tools.LoadPixmap import LoadPixmap
22 from enigma import RT_HALIGN_LEFT, eListboxPythonMultiContent, gFont
23
24 class InterfaceList(MenuList):
25         def __init__(self, list, enableWrapAround=False):
26                 MenuList.__init__(self, list, enableWrapAround, eListboxPythonMultiContent)
27                 self.l.setFont(0, gFont("Regular", 20))
28                 self.l.setItemHeight(30)
29
30 def InterfaceEntryComponent(index,name,default,active ):
31         res = [ (index) ]
32         res.append(MultiContentEntryText(pos=(80, 5), size=(430, 25), font=0, text=name))
33         if default is True:
34                 png = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/buttons/button_blue.png"))
35         if default is False:
36                 png = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/buttons/button_blue_off.png"))
37         res.append(MultiContentEntryPixmapAlphaTest(pos=(10, 5), size=(25, 25), png = png))
38         if active is True:
39                 png2 = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/icons/lock_on.png"))
40         if active is False:
41                 png2 = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/icons/lock_error.png"))
42         res.append(MultiContentEntryPixmapAlphaTest(pos=(40, 1), size=(25, 25), png = png2))
43         return res
44
45
46 class NetworkAdapterSelection(Screen):
47         def __init__(self, session):
48                 Screen.__init__(self, session)
49
50                 self.wlan_errortext = _("No working wireless networkadapter found.\nPlease verify that you have attached a compatible WLAN USB Stick and your Network is configured correctly.")
51                 self.lan_errortext = _("No working local networkadapter found.\nPlease verify that you have attached a network cable and your Network is configured correctly.")
52                 
53                 self["ButtonBluetext"] = Label(_("Set as default Interface"))
54                 self["ButtonRedtext"] = Label(_("Close"))
55                 self["introduction"] = Label(_("Press OK to edit the settings."))
56                 
57                 self.adapters = [(iNetwork.getFriendlyAdapterName(x),x) for x in iNetwork.getAdapterList()]
58
59                 if len(self.adapters) == 0:
60                         self.onFirstExecBegin.append(self.NetworkFallback)
61
62                 self.list = []
63                 self["list"] = InterfaceList(self.list)
64                 self.updateList()
65                 self["actions"] = ActionMap(["OkCancelActions", "ColorActions"],
66                 {
67                         "ok": self.okbuttonClick,
68                         "cancel": self.close,
69                         "blue": self.setDefaultInterface,                       
70                         "red": self.close
71                 }, -2)
72
73                 if len(self.adapters) == 1:
74                         self.onFirstExecBegin.append(self.okbuttonClick)
75
76         def updateList(self):
77                 iNetwork.getInterfaces()
78                 self.list = []
79                 default_gw = None
80                 num_configured_if = len(iNetwork.configuredInterfaces)
81                 if num_configured_if < 2 and os_path.exists("/etc/default_gw"):
82                         unlink("/etc/default_gw")
83                         
84                 if os_path.exists("/etc/default_gw"):
85                         fp = file('/etc/default_gw', 'r')
86                         result = fp.read()
87                         fp.close()
88                         default_gw = result
89
90                 if len(self.adapters) == 0: # no interface available => display only eth0
91                         self.list.append(InterfaceEntryComponent("eth0",iNetwork.getFriendlyAdapterName('eth0'),True,True ))
92                 else:
93                         for x in self.adapters:
94                                 if x[1] == default_gw:
95                                         default_int = True
96                                 else:
97                                         default_int = False
98                                 if iNetwork.getAdapterAttribute(x[1], 'up') is True:
99                                         active_int = True
100                                 else:
101                                         active_int = False
102                                 self.list.append(InterfaceEntryComponent(index = x[1],name = _(x[0]),default=default_int,active=active_int ))
103                 self["list"].l.setList(self.list)
104
105         def setDefaultInterface(self):
106                 selection = self["list"].getCurrent()
107                 num_if = len(self.list)
108                 old_default_gw = None
109                 if os_path.exists("/etc/default_gw"):
110                         fp = open('/etc/default_gw', 'r')
111                         old_default_gw = fp.read()
112                         fp.close()
113                 if num_if > 1 and (not old_default_gw or old_default_gw != selection[0]):
114                         fp = open('/etc/default_gw', 'w+')
115                         fp.write(selection[0])
116                         fp.close()
117                         iNetwork.restartNetwork()
118                         self.updateList()
119                 elif old_default_gw and num_if < 2:
120                         unlink("/etc/default_gw")
121                         iNetwork.restartNetwork()
122                         self.updateList()
123
124         def okbuttonClick(self):
125                 selection = self["list"].getCurrent()
126                 print "selection",selection
127                 if selection is not None:
128                         self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetupConfiguration, selection[0])
129
130         def AdapterSetupClosed(self, *ret):
131                 if len(self.adapters) == 1:
132                         self.close()
133                 else:
134                         self.updateList()
135
136         def NetworkFallback(self):
137                 if iNetwork.configuredInterfaces.has_key('wlan0') is True:
138                         self.session.openWithCallback(self.ErrorMessageClosed, MessageBox, self.wlan_errortext, type = MessageBox.TYPE_INFO,timeout = 10)
139                 if iNetwork.configuredInterfaces.has_key('ath0') is True:
140                         self.session.openWithCallback(self.ErrorMessageClosed, MessageBox, self.wlan_errortext, type = MessageBox.TYPE_INFO,timeout = 10)
141                 else:
142                         self.session.openWithCallback(self.ErrorMessageClosed, MessageBox, self.lan_errortext, type = MessageBox.TYPE_INFO,timeout = 10)
143
144         def ErrorMessageClosed(self, *ret):
145                 if iNetwork.configuredInterfaces.has_key('wlan0') is True:
146                         self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetupConfiguration, 'wlan0')
147                 elif iNetwork.configuredInterfaces.has_key('ath0') is True:
148                         self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetupConfiguration, 'ath0')
149                 else:
150                         self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetupConfiguration, 'eth0')
151
152 class NameserverSetup(Screen, ConfigListScreen):
153         def __init__(self, session):
154                 Screen.__init__(self, session)
155                 iNetwork.getInterfaces()
156                 self.backupNameserverList = iNetwork.getNameserverList()[:]
157                 print "backup-list:", self.backupNameserverList
158                 
159                 self["ButtonGreentext"] = Label(_("Add"))
160                 self["ButtonYellowtext"] = Label(_("Delete"))
161                 self["ButtonRedtext"] = Label(_("Close"))
162                 self["introduction"] = Label(_("Press OK to activate the settings."))
163                 self.createConfig()
164                 
165                 self["actions"] = ActionMap(["OkCancelActions", "ColorActions"],
166                 {
167                         "ok": self.ok,
168                         "cancel": self.cancel,
169                         "red": self.cancel,
170                         "green": self.add,
171                         "yellow": self.remove
172                 }, -2)
173                 
174                 self.list = []
175                 ConfigListScreen.__init__(self, self.list)
176                 self.createSetup()
177
178         def createConfig(self):
179                 self.nameservers = iNetwork.getNameserverList()
180                 self.nameserverEntries = []
181                 
182                 for nameserver in self.nameservers:
183                         self.nameserverEntries.append(NoSave(ConfigIP(default=nameserver)))
184
185         def createSetup(self):
186                 self.list = []
187                 
188                 for i in range(len(self.nameserverEntries)):
189                         self.list.append(getConfigListEntry(_("Nameserver %d") % (i + 1), self.nameserverEntries[i]))
190                 
191                 self["config"].list = self.list
192                 self["config"].l.setList(self.list)
193
194         def ok(self):
195                 iNetwork.clearNameservers()
196                 for nameserver in self.nameserverEntries:
197                         iNetwork.addNameserver(nameserver.value)
198                 iNetwork.writeNameserverConfig()
199                 self.close()
200
201         def run(self):
202                 self.ok()
203
204         def cancel(self):
205                 iNetwork.clearNameservers()
206                 print "backup-list:", self.backupNameserverList
207                 for nameserver in self.backupNameserverList:
208                         iNetwork.addNameserver(nameserver)
209                 self.close()
210
211         def add(self):
212                 iNetwork.addNameserver([0,0,0,0])
213                 self.createConfig()
214                 self.createSetup()
215
216         def remove(self):
217                 print "currentIndex:", self["config"].getCurrentIndex()
218                 
219                 index = self["config"].getCurrentIndex()
220                 if index < len(self.nameservers):
221                         iNetwork.removeNameserver(self.nameservers[index])
222                         self.createConfig()
223                         self.createSetup()
224         
225 class AdapterSetup(Screen, ConfigListScreen):
226         def __init__(self, session, iface,essid=None, aplist=None):
227                 Screen.__init__(self, session)
228                 self.session = session
229                 self.iface = iface
230                 self.essid = essid
231                 self.aplist = aplist
232                 self.extended = None
233                 self.oldInterfaceState = iNetwork.getAdapterAttribute(self.iface, "up")
234                 iNetwork.getInterfaces()
235
236                 self.createConfig()
237                 
238                 self["actions"] = NumberActionMap(["SetupActions"],
239                 {
240                         "ok": self.ok,
241                         "cancel": self.cancel,
242                         "red": self.cancel,
243                         "blue": self.KeyBlue,
244                 }, -2)
245                 
246                 self.list = []
247                 ConfigListScreen.__init__(self, self.list,session = self.session)
248                 self.createSetup()
249                 self.onLayoutFinish.append(self.layoutFinished)
250                 
251                 self["DNS1text"] = Label(_("Primary DNS"))
252                 self["DNS2text"] = Label(_("Secondary DNS"))
253                 self["DNS1"] = Label()
254                 self["DNS2"] = Label()
255                 
256                 self["introduction"] = Label(_("Current settings:"))
257                 
258                 self["IPtext"] = Label(_("IP Address"))
259                 self["Netmasktext"] = Label(_("Netmask"))
260                 self["Gatewaytext"] = Label(_("Gateway"))
261                 
262                 self["IP"] = Label()
263                 self["Mask"] = Label()
264                 self["Gateway"] = Label()
265                 
266                 self["BottomBG"] = Pixmap()
267                 self["Adaptertext"] = Label(_("Network:"))
268                 self["Adapter"] = Label()
269                 self["introduction2"] = Label(_("Press OK to activate the settings."))
270                 self["ButtonRed"] = Pixmap()
271                 self["ButtonRedtext"] = Label(_("Close"))
272                 self["ButtonBlue"] = Pixmap()
273                 self["ButtonBluetext"] = Label(_("Edit DNS"))
274
275         def layoutFinished(self):
276                 self["DNS1"].setText(self.primaryDNS.getText())
277                 self["DNS2"].setText(self.secondaryDNS.getText())
278                 if self.ipConfigEntry.getText() is not None:
279                         self["IP"].setText(self.ipConfigEntry.getText())
280                 else:
281                         self["IP"].setText([0,0,0,0])
282                 self["Mask"].setText(self.netmaskConfigEntry.getText())
283                 if iNetwork.getAdapterAttribute(self.iface, "gateway"):
284                         self["Gateway"].setText(self.gatewayConfigEntry.getText())
285                 else:
286                         self["Gateway"].hide()
287                         self["Gatewaytext"].hide()
288                 self["Adapter"].setText(iNetwork.getFriendlyAdapterName(self.iface))
289
290         def createConfig(self):
291                 self.InterfaceEntry = None
292                 self.dhcpEntry = None
293                 self.gatewayEntry = None
294                 self.SSIDscan = None
295                 self.wlanSSID = None
296                 self.manualwlanSSID = None
297                 self.encryptionEnabled = None
298                 self.encryptionKey = None
299                 self.nwlist = None
300                 self.wsconfig = None
301                 self.default = None
302                 
303                 if self.iface == "wlan0" or self.iface == "ath0" :
304                         from Plugins.SystemPlugins.WirelessLan.Wlan import wpaSupplicant,Wlan
305                         self.ws = wpaSupplicant()
306                         list = []
307                         list.append(_("WEP"))
308                         list.append(_("WPA"))
309                         list.append(_("WPA2"))
310                         if self.aplist is not None:
311                                 self.nwlist = self.aplist
312                                 self.nwlist.sort(key = lambda x: x[0])
313                         else:
314                                 self.nwlist = []
315                                 self.w = None
316                                 self.aps = None
317                                 try:
318                                         self.w = Wlan(self.iface)
319                                         self.aps = self.w.getNetworkList()
320                                         if self.aps is not None:
321                                                 print "[NetworkSetup.py] got Accespoints!"
322                                                 for ap in aps:
323                                                         a = aps[ap]
324                                                         if a['active']:
325                                                                 if a['essid'] == "":
326                                                                         a['essid'] = a['bssid']
327                                                                 self.nwlist.append( a['essid'])
328                                         self.nwlist.sort(key = lambda x: x[0])
329                                 except:
330                                         self.nwlist.append("No Networks found")
331
332                         self.wsconfig = self.ws.loadConfig()
333                         self.default = self.essid or self.wsconfig['ssid']
334                         if self.default not in self.nwlist:
335                                 self.nwlist.append(self.default)
336                         config.plugins.wlan.essidscan = NoSave(ConfigYesNo(default = self.wsconfig['ssidscan']))
337                         if self.wsconfig['ssidscan'] is True:
338                                 config.plugins.wlan.essid = NoSave(ConfigSelection(self.nwlist, default = self.default ))
339                         else:
340                                 config.plugins.wlan.essid = NoSave(ConfigText(default = self.default, visible_width = 50, fixed_size = False))
341                         config.plugins.wlan.encryption.enabled = NoSave(ConfigYesNo(default = self.wsconfig['encryption'] ))
342                         config.plugins.wlan.encryption.type = NoSave(ConfigSelection(list, default = self.wsconfig['encryption_type'] ))
343                         config.plugins.wlan.encryption.psk = NoSave(ConfigText(default = self.wsconfig['key'], visible_width = 50, fixed_size = False))
344                 
345                 self.activateInterfaceEntry = NoSave(ConfigYesNo(default=iNetwork.getAdapterAttribute(self.iface, "up") or False))
346                 self.dhcpConfigEntry = NoSave(ConfigYesNo(default=iNetwork.getAdapterAttribute(self.iface, "dhcp") or False))
347                 self.ipConfigEntry = NoSave(ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "ip")) or [0,0,0,0])
348                 self.netmaskConfigEntry = NoSave(ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "netmask") or [255,0,0,0]))
349                 if iNetwork.getAdapterAttribute(self.iface, "gateway"):
350                         self.dhcpdefault=True
351                 else:
352                         self.dhcpdefault=False
353                 self.hasGatewayConfigEntry = NoSave(ConfigYesNo(default=self.dhcpdefault or False))
354                 self.gatewayConfigEntry = NoSave(ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "gateway") or [0,0,0,0]))
355                 nameserver = (iNetwork.getNameserverList() + [[0,0,0,0]] * 2)[0:2]
356                 self.primaryDNS = NoSave(ConfigIP(default=nameserver[0]))
357                 self.secondaryDNS = NoSave(ConfigIP(default=nameserver[1]))
358
359         def createSetup(self):
360                 self.list = []
361                 self.InterfaceEntry = getConfigListEntry(_("Use Interface"), self.activateInterfaceEntry)
362                 
363                 self.list.append(self.InterfaceEntry)
364                 if self.activateInterfaceEntry.value:
365                         self.dhcpEntry = getConfigListEntry(_("Use DHCP"), self.dhcpConfigEntry)
366                         self.list.append(self.dhcpEntry)
367                         if not self.dhcpConfigEntry.value:
368                                 self.list.append(getConfigListEntry(_('IP Address'), self.ipConfigEntry))
369                                 self.list.append(getConfigListEntry(_('Netmask'), self.netmaskConfigEntry))
370                                 self.gatewayEntry = getConfigListEntry(_('Use a gateway'), self.hasGatewayConfigEntry)
371                                 self.list.append(self.gatewayEntry)
372                                 if self.hasGatewayConfigEntry.value:
373                                         self.list.append(getConfigListEntry(_('Gateway'), self.gatewayConfigEntry))
374                         
375                         self.extended = None            
376                         for p in plugins.getPlugins(PluginDescriptor.WHERE_NETWORKSETUP):
377                                 callFnc = p.__call__["ifaceSupported"](self.iface)
378                                 if callFnc is not None:
379                                         if p.__call__.has_key("WlanPluginEntry"): # internally used only for WLAN Plugin
380                                                 self.extended = callFnc
381                                                 if p.__call__.has_key("configStrings"):
382                                                         self.configStrings = p.__call__["configStrings"]
383                                                 else:
384                                                         self.configStrings = None
385                                                 self.SSIDscan = getConfigListEntry(_("Automatic SSID lookup"), config.plugins.wlan.essidscan)
386                                                 self.list.append(self.SSIDscan)
387                                                 self.wlanSSID = getConfigListEntry(_("Network SSID"), config.plugins.wlan.essid)
388                                                 self.list.append(self.wlanSSID)
389                                                 self.encryptionEnabled = getConfigListEntry(_("Encryption"), config.plugins.wlan.encryption.enabled)
390                                                 self.list.append(self.encryptionEnabled)
391                                                 
392                                                 if config.plugins.wlan.encryption.enabled.value:
393                                                         self.list.append(getConfigListEntry(_("Encryption Type"), config.plugins.wlan.encryption.type))
394                                                         self.encryptionKey = getConfigListEntry(_("Encryption Key"), config.plugins.wlan.encryption.psk)                                                
395                                                         self.list.append(self.encryptionKey)
396                 
397                 self["config"].list = self.list
398                 self["config"].l.setList(self.list)
399
400         def KeyBlue(self):
401                 self.session.openWithCallback(self.NameserverSetupClosed, NameserverSetup)
402
403         def newConfig(self):
404                 print self["config"].getCurrent()
405                 if self["config"].getCurrent() == self.InterfaceEntry:
406                         self.createSetup()
407                 if self["config"].getCurrent() == self.dhcpEntry:
408                         self.createSetup()
409                 if self["config"].getCurrent() == self.gatewayEntry:
410                         self.createSetup()
411                 if self.iface == "wlan0" or self.iface == "ath0" :      
412                         if self["config"].getCurrent() == self.SSIDscan:
413                                 if config.plugins.wlan.essidscan.value is True:
414                                         config.plugins.wlan.essid = NoSave(ConfigSelection(self.nwlist, default = self.default ))
415                                 else:
416                                         config.plugins.wlan.essid = NoSave(ConfigText(default = self.default, visible_width = 50, fixed_size = False))
417                                 self.createSetup()
418                         if self["config"].getCurrent() == self.encryptionEnabled:
419                                 self.createSetup()
420                 
421         def keyLeft(self):
422                 ConfigListScreen.keyLeft(self)
423                 self.newConfig()
424
425         def keyRight(self):
426                 ConfigListScreen.keyRight(self)
427                 self.newConfig()
428
429         def ok(self):
430                 iNetwork.setAdapterAttribute(self.iface, "up", self.activateInterfaceEntry.value)
431                 iNetwork.setAdapterAttribute(self.iface, "dhcp", self.dhcpConfigEntry.value)
432                 iNetwork.setAdapterAttribute(self.iface, "ip", self.ipConfigEntry.value)
433                 iNetwork.setAdapterAttribute(self.iface, "netmask", self.netmaskConfigEntry.value)
434                 if self.hasGatewayConfigEntry.value:
435                         iNetwork.setAdapterAttribute(self.iface, "gateway", self.gatewayConfigEntry.value)
436                 else:
437                         iNetwork.removeAdapterAttribute(self.iface, "gateway")
438                 if self.extended is not None and self.configStrings is not None:
439                         iNetwork.setAdapterAttribute(self.iface, "configStrings", self.configStrings(self.iface))
440                         self.ws.writeConfig()
441                 if self.activateInterfaceEntry.value is False:
442                         iNetwork.deactivateInterface(self.iface)
443                 iNetwork.writeNetworkConfig()
444                 iNetwork.deactivateNetworkConfig()
445                 iNetwork.activateNetworkConfig()
446                 self.close()
447
448         def cancel(self):
449                 iNetwork.setAdapterAttribute(self.iface, "up", self.oldInterfaceState)
450                 self.activateInterfaceEntry.value = self.oldInterfaceState
451                 if self.activateInterfaceEntry.value is False:
452                         iNetwork.deactivateInterface(self.iface)
453                 iNetwork.getInterfaces()
454                 self.close()
455
456         def run(self):
457                 self.ok()
458
459         def NameserverSetupClosed(self, *ret):
460                 iNetwork.loadNameserverConfig()
461                 nameserver = (iNetwork.getNameserverList() + [[0,0,0,0]] * 2)[0:2]
462                 self.primaryDNS = NoSave(ConfigIP(default=nameserver[0]))
463                 self.secondaryDNS = NoSave(ConfigIP(default=nameserver[1]))
464                 self.createSetup()
465                 self.layoutFinished()
466         
467
468 class AdapterSetupConfiguration(Screen):
469         def __init__(self, session,iface):
470                 Screen.__init__(self, session)
471                 self.session = session
472                 self.iface = iface
473                 self.mainmenu = self.genMainMenu()
474                 self["menulist"] = MenuList(self.mainmenu)
475                 self["description"] = Label()
476                 self["IFtext"] = Label()
477                 self["IF"] = Label()
478                 self["BottomBG"] = Label()
479                 self["Statustext"] = Label()
480                 self["statuspic"] = MultiPixmap()
481                 self["statuspic"].hide()
482                 self["BottomBG"] = Pixmap()
483                 self["ButtonRed"] = Pixmap()
484                 self["ButtonRedtext"] = Label(_("Close"))
485                 
486                 self.oktext = _("Press OK on your remote control to continue.")
487                 self.reboottext = _("Your Dreambox will restart after pressing OK on your remote control.")
488                 self.errortext = _("No working wireless interface found.\n Please verify that you have attached a compatible WLAN device or enable you local network interface.")       
489                 
490                 self["actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
491                 {
492                         "ok": self.ok,
493                         "back": self.close,
494                         "up": self.up,
495                         "down": self.down,
496                         "red": self.close,
497                         "left": self.left,
498                         "right": self.right,
499                 }, -2)
500                 
501                 iNetwork.getInterfaces()
502                 self.onLayoutFinish.append(self.layoutFinished)
503                 self.updateStatusbar()
504
505         def ok(self):
506                 if self["menulist"].getCurrent()[1] == 'edit':
507                         if self.iface == 'wlan0' or self.iface == 'ath0':
508                                 try:
509                                         from Plugins.SystemPlugins.WirelessLan.plugin import WlanScan
510                                         from Plugins.SystemPlugins.WirelessLan.iwlibs import Wireless
511                                 except ImportError:
512                                         self.session.open(MessageBox, _("The wireless LAN plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
513                                 else:
514                                         ifobj = Wireless(self.iface) # a Wireless NIC Object
515                                         self.wlanresponse = ifobj.getStatistics()
516                                         if self.wlanresponse[0] != 19: # Wlan Interface found.
517                                                 self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup,self.iface)
518                                         else:
519                                                 # Display Wlan not available Message
520                                                 self.showErrorMessage()
521                         else:
522                                 self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup,self.iface)
523                 if self["menulist"].getCurrent()[1] == 'test':
524                         self.session.open(NetworkAdapterTest,self.iface)
525                 if self["menulist"].getCurrent()[1] == 'dns':
526                         self.session.open(NameserverSetup)
527                 if self["menulist"].getCurrent()[1] == 'scanwlan':
528                         try:
529                                 from Plugins.SystemPlugins.WirelessLan.plugin import WlanScan
530                                 from Plugins.SystemPlugins.WirelessLan.iwlibs import Wireless
531                         except ImportError:
532                                 self.session.open(MessageBox, _("The wireless LAN plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
533                         else:
534                                 ifobj = Wireless(self.iface) # a Wireless NIC Object
535                                 self.wlanresponse = ifobj.getStatistics()
536                                 if self.wlanresponse[0] != 19:
537                                         self.session.openWithCallback(self.WlanScanClosed, WlanScan, self.iface)
538                                 else:
539                                         # Display Wlan not available Message
540                                         self.showErrorMessage()
541                 if self["menulist"].getCurrent()[1] == 'wlanstatus':
542                         try:
543                                 from Plugins.SystemPlugins.WirelessLan.plugin import WlanStatus
544                                 from Plugins.SystemPlugins.WirelessLan.iwlibs import Wireless
545                         except ImportError:
546                                 self.session.open(MessageBox, _("The wireless LAN plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
547                         else:   
548                                 ifobj = Wireless(self.iface) # a Wireless NIC Object
549                                 self.wlanresponse = ifobj.getStatistics()
550                                 if self.wlanresponse[0] != 19:
551                                         self.session.openWithCallback(self.AdapterSetupClosed, WlanStatus,self.iface)
552                                         #self.session.open(WlanStatus,self.iface)
553                                 else:
554                                         # Display Wlan not available Message
555                                         self.showErrorMessage()
556                 if self["menulist"].getCurrent()[1] == 'lanrestart':
557                         self.session.openWithCallback(self.restartLan, MessageBox, (_("Are you sure you want to restart your network interfaces?\n\n") + self.oktext ) )
558                 if self["menulist"].getCurrent()[1] == 'openwizard':
559                         from Plugins.SystemPlugins.NetworkWizard.NetworkWizard import NetworkWizard
560                         self.session.openWithCallback(self.AdapterSetupClosed, NetworkWizard)
561                 if self["menulist"].getCurrent()[1][0] == 'extendedSetup':
562                         self.extended = self["menulist"].getCurrent()[1][2]
563                         self.extended(self.session, self.iface)
564         
565         def up(self):
566                 self["menulist"].up()
567                 self.loadDescription()
568
569         def down(self):
570                 self["menulist"].down()
571                 self.loadDescription()
572
573         def left(self):
574                 self["menulist"].pageUp()
575                 self.loadDescription()
576
577         def right(self):
578                 self["menulist"].pageDown()
579                 self.loadDescription()
580
581         def layoutFinished(self):
582                 idx = 0
583                 self["menulist"].moveToIndex(idx)
584                 self.loadDescription()
585
586         def loadDescription(self):
587                 if self["menulist"].getCurrent()[1] == 'edit':
588                         self["description"].setText(_("Edit the network configuration of your Dreambox.\n" ) + self.oktext )
589                 if self["menulist"].getCurrent()[1] == 'test':
590                         self["description"].setText(_("Test the network configuration of your Dreambox.\n" ) + self.oktext )
591                 if self["menulist"].getCurrent()[1] == 'dns':
592                         self["description"].setText(_("Edit the Nameserver configuration of your Dreambox.\n" ) + self.oktext )
593                 if self["menulist"].getCurrent()[1] == 'scanwlan':
594                         self["description"].setText(_("Scan your network for wireless Access Points and connect to them using your WLAN USB Stick\n" ) + self.oktext )
595                 if self["menulist"].getCurrent()[1] == 'wlanstatus':
596                         self["description"].setText(_("Shows the state of your wireless LAN connection.\n" ) + self.oktext )
597                 if self["menulist"].getCurrent()[1] == 'lanrestart':
598                         self["description"].setText(_("Restart your network connection and interfaces.\n" ) + self.oktext )
599                 if self["menulist"].getCurrent()[1] == 'openwizard':
600                         self["description"].setText(_("Use the Networkwizard to configure your Network\n" ) + self.oktext )
601                 if self["menulist"].getCurrent()[1][0] == 'extendedSetup':
602                         self["description"].setText(_(self["menulist"].getCurrent()[1][1]) + self.oktext )
603                 
604         def updateStatusbar(self):
605                 self["IFtext"].setText(_("Network:"))
606                 self["IF"].setText(iNetwork.getFriendlyAdapterName(self.iface))
607                 self["Statustext"].setText(_("Link:"))
608                 
609                 if self.iface == 'wlan0' or self.iface == 'ath0':
610                         try:
611                                 from Plugins.SystemPlugins.WirelessLan.Wlan import Wlan
612                                 w = Wlan(self.iface)
613                                 stats = w.getStatus()
614                                 if stats['BSSID'] == "00:00:00:00:00:00":
615                                         self["statuspic"].setPixmapNum(1)
616                                 else:
617                                         self["statuspic"].setPixmapNum(0)
618                                 self["statuspic"].show()
619                         except:
620                                         self["statuspic"].setPixmapNum(1)
621                                         self["statuspic"].show()
622                 else:
623                         self.getLinkState(self.iface)
624
625         def doNothing(self):
626                 pass
627
628         def genMainMenu(self):
629                 menu = []
630                 menu.append((_("Adapter settings"), "edit"))
631                 menu.append((_("Nameserver settings"), "dns"))
632                 menu.append((_("Network test"), "test"))
633                 menu.append((_("Restart network"), "lanrestart"))
634
635                 self.extended = None
636                 self.extendedSetup = None               
637                 for p in plugins.getPlugins(PluginDescriptor.WHERE_NETWORKSETUP):
638                         callFnc = p.__call__["ifaceSupported"](self.iface)
639                         if callFnc is not None:
640                                 self.extended = callFnc
641                                 print p.__call__
642                                 if p.__call__.has_key("WlanPluginEntry"): # internally used only for WLAN Plugin
643                                         menu.append((_("Scan Wireless Networks"), "scanwlan"))
644                                         if iNetwork.getAdapterAttribute(self.iface, "up"):
645                                                 menu.append((_("Show WLAN Status"), "wlanstatus"))
646                                 else:
647                                         if p.__call__.has_key("menuEntryName"):
648                                                 menuEntryName = p.__call__["menuEntryName"](self.iface)
649                                         else:
650                                                 menuEntryName = _('Extended Setup...')
651                                         if p.__call__.has_key("menuEntryDescription"):
652                                                 menuEntryDescription = p.__call__["menuEntryDescription"](self.iface)
653                                         else:
654                                                 menuEntryDescription = _('Extended Networksetup Plugin...')
655                                         self.extendedSetup = ('extendedSetup',menuEntryDescription, self.extended)
656                                         menu.append((menuEntryName,self.extendedSetup))                                 
657                         
658                 if os_path.exists(resolveFilename(SCOPE_PLUGINS, "SystemPlugins/NetworkWizard/networkwizard.xml")):
659                         menu.append((_("NetworkWizard"), "openwizard"))
660
661                 return menu
662
663         def AdapterSetupClosed(self, *ret):
664                 self.mainmenu = self.genMainMenu()
665                 self["menulist"].l.setList(self.mainmenu)
666                 iNetwork.getInterfaces()
667                 self.updateStatusbar()
668
669         def WlanScanClosed(self,*ret):
670                 if ret[0] is not None:
671                         self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup, self.iface,ret[0],ret[1])
672                 else:
673                         self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup, self.iface,None,ret[0])
674
675
676         def restartLan(self, ret = False):
677                 if (ret == True):
678                         iNetwork.restartNetwork()
679
680         def getLinkState(self,iface):
681                 iNetwork.getLinkState(iface,self.dataAvail)
682
683         def dataAvail(self,data):
684                 self.output = data.strip()
685                 result = self.output.split('\n')
686                 pattern = re_compile("Link detected: yes")
687                 for item in result:
688                         if re_search(pattern, item):
689                                 self["statuspic"].setPixmapNum(0)
690                         else:
691                                 self["statuspic"].setPixmapNum(1)
692                 self["statuspic"].show()
693
694         def showErrorMessage(self):
695                 self.session.open(MessageBox, self.errortext, type = MessageBox.TYPE_INFO,timeout = 10 )
696
697
698 class NetworkAdapterTest(Screen):       
699         def __init__(self, session,iface):
700                 Screen.__init__(self, session)
701                 self.iface = iface
702                 iNetwork.getInterfaces()
703                 self.setLabels()
704                 
705                 self["updown_actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
706                 {
707                         "ok": self.KeyOK,
708                         "blue": self.KeyOK,
709                         "up": lambda: self.updownhandler('up'),
710                         "down": lambda: self.updownhandler('down'),
711                 
712                 }, -2)
713                 
714                 self["shortcuts"] = ActionMap(["ShortcutActions","WizardActions"],
715                 {
716                         "red": self.close,
717                         "back": self.close,
718                 }, -2)
719                 self["infoshortcuts"] = ActionMap(["ShortcutActions","WizardActions"],
720                 {
721                         "red": self.closeInfo,
722                         "back": self.closeInfo,
723                 }, -2)
724                 self["shortcutsgreen"] = ActionMap(["ShortcutActions"],
725                 {
726                         "green": self.KeyGreen,
727                 }, -2)
728                 self["shortcutsgreen_restart"] = ActionMap(["ShortcutActions"],
729                 {
730                         "green": self.KeyGreenRestart,
731                 }, -2)
732                 self["shortcutsyellow"] = ActionMap(["ShortcutActions"],
733                 {
734                         "yellow": self.KeyYellow,
735                 }, -2)
736                 
737                 self["shortcutsgreen_restart"].setEnabled(False)
738                 self["updown_actions"].setEnabled(False)
739                 self["infoshortcuts"].setEnabled(False)
740                 self.onClose.append(self.delTimer)      
741                 self.onLayoutFinish.append(self.layoutFinished)
742                 self.steptimer = False
743                 self.nextstep = 0
744                 self.activebutton = 0
745                 self.nextStepTimer = eTimer()
746                 self.nextStepTimer.callback.append(self.nextStepTimerFire)
747
748         def closeInfo(self):
749                 self["shortcuts"].setEnabled(True)              
750                 self["infoshortcuts"].setEnabled(False)
751                 self["InfoText"].hide()
752                 self["InfoTextBorder"].hide()
753                 self["ButtonRedtext"].setText(_("Close"))
754
755         def delTimer(self):
756                 del self.steptimer
757                 del self.nextStepTimer
758
759         def nextStepTimerFire(self):
760                 self.nextStepTimer.stop()
761                 self.steptimer = False
762                 self.runTest()
763
764         def updownhandler(self,direction):
765                 if direction == 'up':
766                         if self.activebutton >=2:
767                                 self.activebutton -= 1
768                         else:
769                                 self.activebutton = 6
770                         self.setActiveButton(self.activebutton)
771                 if direction == 'down':
772                         if self.activebutton <=5:
773                                 self.activebutton += 1
774                         else:
775                                 self.activebutton = 1
776                         self.setActiveButton(self.activebutton)
777
778         def setActiveButton(self,button):
779                 if button == 1:
780                         self["EditSettingsButton"].setPixmapNum(0)
781                         self["EditSettings_Text"].setForegroundColorNum(0)
782                         self["NetworkInfo"].setPixmapNum(0)
783                         self["NetworkInfo_Text"].setForegroundColorNum(1)
784                         self["AdapterInfo"].setPixmapNum(1)               # active
785                         self["AdapterInfo_Text"].setForegroundColorNum(2) # active
786                 if button == 2:
787                         self["AdapterInfo_Text"].setForegroundColorNum(1)
788                         self["AdapterInfo"].setPixmapNum(0)
789                         self["DhcpInfo"].setPixmapNum(0)
790                         self["DhcpInfo_Text"].setForegroundColorNum(1)
791                         self["NetworkInfo"].setPixmapNum(1)               # active
792                         self["NetworkInfo_Text"].setForegroundColorNum(2) # active
793                 if button == 3:
794                         self["NetworkInfo"].setPixmapNum(0)
795                         self["NetworkInfo_Text"].setForegroundColorNum(1)
796                         self["IPInfo"].setPixmapNum(0)
797                         self["IPInfo_Text"].setForegroundColorNum(1)
798                         self["DhcpInfo"].setPixmapNum(1)                  # active
799                         self["DhcpInfo_Text"].setForegroundColorNum(2)    # active
800                 if button == 4:
801                         self["DhcpInfo"].setPixmapNum(0)
802                         self["DhcpInfo_Text"].setForegroundColorNum(1)
803                         self["DNSInfo"].setPixmapNum(0)
804                         self["DNSInfo_Text"].setForegroundColorNum(1)
805                         self["IPInfo"].setPixmapNum(1)                  # active
806                         self["IPInfo_Text"].setForegroundColorNum(2)    # active                
807                 if button == 5:
808                         self["IPInfo"].setPixmapNum(0)
809                         self["IPInfo_Text"].setForegroundColorNum(1)
810                         self["EditSettingsButton"].setPixmapNum(0)
811                         self["EditSettings_Text"].setForegroundColorNum(0)
812                         self["DNSInfo"].setPixmapNum(1)                 # active
813                         self["DNSInfo_Text"].setForegroundColorNum(2)   # active
814                 if button == 6:
815                         self["DNSInfo"].setPixmapNum(0)
816                         self["DNSInfo_Text"].setForegroundColorNum(1)
817                         self["EditSettingsButton"].setPixmapNum(1)         # active
818                         self["EditSettings_Text"].setForegroundColorNum(2) # active
819                         self["AdapterInfo"].setPixmapNum(0)
820                         self["AdapterInfo_Text"].setForegroundColorNum(1)
821                         
822         def runTest(self):
823                 next = self.nextstep
824                 if next == 0:
825                         self.doStep1()
826                 elif next == 1:
827                         self.doStep2()
828                 elif next == 2:
829                         self.doStep3()
830                 elif next == 3:
831                         self.doStep4()
832                 elif next == 4:
833                         self.doStep5()
834                 elif next == 5:
835                         self.doStep6()
836                 self.nextstep += 1
837
838         def doStep1(self):
839                 self.steptimer = True
840                 self.nextStepTimer.start(3000)
841
842         def doStep2(self):
843                 self["Adapter"].setText(iNetwork.getFriendlyAdapterName(self.iface))
844                 self["Adapter"].setForegroundColorNum(2)
845                 self["Adaptertext"].setForegroundColorNum(1)
846                 self["AdapterInfo_Text"].setForegroundColorNum(1)
847                 self["AdapterInfo_OK"].show()
848                 self.steptimer = True
849                 self.nextStepTimer.start(3000)
850
851         def doStep3(self):
852                 self["Networktext"].setForegroundColorNum(1)
853                 self.getLinkState(self.iface)
854                 self["NetworkInfo_Text"].setForegroundColorNum(1)
855                 self.steptimer = True
856                 self.nextStepTimer.start(3000)
857
858         def doStep4(self):
859                 self["Dhcptext"].setForegroundColorNum(1)
860                 if iNetwork.getAdapterAttribute(self.iface, 'dhcp') is True:
861                         self["Dhcp"].setForegroundColorNum(2)
862                         self["Dhcp"].setText(_("enabled"))
863                         self["DhcpInfo_Check"].setPixmapNum(0)
864                 else:
865                         self["Dhcp"].setForegroundColorNum(1)
866                         self["Dhcp"].setText(_("disabled"))
867                         self["DhcpInfo_Check"].setPixmapNum(1)
868                 self["DhcpInfo_Check"].show()
869                 self["DhcpInfo_Text"].setForegroundColorNum(1)
870                 self.steptimer = True
871                 self.nextStepTimer.start(3000)
872
873         def doStep5(self):
874                 self["IPtext"].setForegroundColorNum(1)
875                 ret = iNetwork.checkNetworkState()
876                 if ret == True:
877                         self["IP"].setForegroundColorNum(2)
878                         self["IP"].setText(_("confirmed"))
879                         self["IPInfo_Check"].setPixmapNum(0)
880                 else:
881                         self["IP"].setForegroundColorNum(1)
882                         self["IP"].setText(_("unconfirmed"))
883                         self["IPInfo_Check"].setPixmapNum(1)
884                 self["IPInfo_Check"].show()
885                 self["IPInfo_Text"].setForegroundColorNum(1)
886                 self.steptimer = True
887                 self.nextStepTimer.start(3000)
888
889         def doStep6(self):
890                 self.steptimer = False
891                 self.nextStepTimer.stop()
892                 self["DNStext"].setForegroundColorNum(1)
893                 ret = iNetwork.checkDNSLookup()
894                 if ret == True:
895                         self["DNS"].setForegroundColorNum(2)
896                         self["DNS"].setText(_("confirmed"))
897                         self["DNSInfo_Check"].setPixmapNum(0)
898                 else:
899                         self["DNS"].setForegroundColorNum(1)
900                         self["DNS"].setText(_("unconfirmed"))
901                         self["DNSInfo_Check"].setPixmapNum(1)
902                 self["DNSInfo_Check"].show()
903                 self["DNSInfo_Text"].setForegroundColorNum(1)
904                 
905                 self["EditSettings_Text"].show()
906                 self["EditSettingsButton"].setPixmapNum(1)
907                 self["EditSettings_Text"].setForegroundColorNum(2) # active
908                 self["EditSettingsButton"].show()
909                 self["ButtonYellow_Check"].setPixmapNum(1)
910                 self["ButtonGreentext"].setText(_("Restart test"))
911                 self["ButtonGreen_Check"].setPixmapNum(0)
912                 self["shortcutsgreen"].setEnabled(False)
913                 self["shortcutsgreen_restart"].setEnabled(True)
914                 self["shortcutsyellow"].setEnabled(False)
915                 self["updown_actions"].setEnabled(True)
916                 self.activebutton = 6
917
918         def KeyGreen(self):
919                 self["shortcutsgreen"].setEnabled(False)
920                 self["shortcutsyellow"].setEnabled(True)
921                 self["updown_actions"].setEnabled(False)
922                 self["ButtonYellow_Check"].setPixmapNum(0)
923                 self["ButtonGreen_Check"].setPixmapNum(1)
924                 self.steptimer = True
925                 self.nextStepTimer.start(1000)
926
927         def KeyGreenRestart(self):
928                 self.nextstep = 0
929                 self.layoutFinished()
930                 self["Adapter"].setText((""))
931                 self["Network"].setText((""))
932                 self["Dhcp"].setText((""))
933                 self["IP"].setText((""))
934                 self["DNS"].setText((""))
935                 self["AdapterInfo_Text"].setForegroundColorNum(0)
936                 self["NetworkInfo_Text"].setForegroundColorNum(0)
937                 self["DhcpInfo_Text"].setForegroundColorNum(0)
938                 self["IPInfo_Text"].setForegroundColorNum(0)
939                 self["DNSInfo_Text"].setForegroundColorNum(0)
940                 self["shortcutsgreen_restart"].setEnabled(False)
941                 self["shortcutsgreen"].setEnabled(False)
942                 self["shortcutsyellow"].setEnabled(True)
943                 self["updown_actions"].setEnabled(False)
944                 self["ButtonYellow_Check"].setPixmapNum(0)
945                 self["ButtonGreen_Check"].setPixmapNum(1)
946                 self.steptimer = True
947                 self.nextStepTimer.start(1000)
948
949         def KeyOK(self):
950                 self["infoshortcuts"].setEnabled(True)
951                 self["shortcuts"].setEnabled(False)
952                 if self.activebutton == 1: # Adapter Check
953                         self["InfoText"].setText(_("This test detects your configured LAN-Adapter."))
954                         self["InfoTextBorder"].show()
955                         self["InfoText"].show()
956                         self["ButtonRedtext"].setText(_("Back"))
957                 if self.activebutton == 2: #LAN Check
958                         self["InfoText"].setText(_("This test checks whether a network cable is connected to your LAN-Adapter.\nIf you get a \"disconnected\" message:\n- verify that a network cable is attached\n- verify that the cable is not broken"))
959                         self["InfoTextBorder"].show()
960                         self["InfoText"].show()
961                         self["ButtonRedtext"].setText(_("Back"))
962                 if self.activebutton == 3: #DHCP Check
963                         self["InfoText"].setText(_("This test checks whether your LAN Adapter is set up for automatic IP Address configuration with DHCP.\nIf you get a \"disabled\" message:\n - then your LAN Adapter is configured for manual IP Setup\n- verify thay you have entered correct IP informations in the AdapterSetup dialog.\nIf you get an \"enabeld\" message:\n-verify that you have a configured and working DHCP Server in your network."))
964                         self["InfoTextBorder"].show()
965                         self["InfoText"].show()
966                         self["ButtonRedtext"].setText(_("Back"))
967                 if self.activebutton == 4: # IP Check
968                         self["InfoText"].setText(_("This test checks whether a valid IP Address is found for your LAN Adapter.\nIf you get a \"unconfirmed\" message:\n- no valid IP Address was found\n- please check your DHCP, cabling and adapter setup"))
969                         self["InfoTextBorder"].show()
970                         self["InfoText"].show()
971                         self["ButtonRedtext"].setText(_("Back"))
972                 if self.activebutton == 5: # DNS Check
973                         self["InfoText"].setText(_("This test checks for configured Nameservers.\nIf you get a \"unconfirmed\" message:\n- please check your DHCP, cabling and Adapter setup\n- if you configured your Nameservers manually please verify your entries in the \"Nameserver\" Configuration"))
974                         self["InfoTextBorder"].show()
975                         self["InfoText"].show()
976                         self["ButtonRedtext"].setText(_("Back"))
977                 if self.activebutton == 6: # Edit Settings
978                         self.session.open(AdapterSetup,self.iface)
979
980         def KeyYellow(self):
981                 self.nextstep = 0
982                 self["shortcutsgreen_restart"].setEnabled(True)
983                 self["shortcutsgreen"].setEnabled(False)
984                 self["shortcutsyellow"].setEnabled(False)
985                 self["ButtonGreentext"].setText(_("Restart test"))
986                 self["ButtonYellow_Check"].setPixmapNum(1)
987                 self["ButtonGreen_Check"].setPixmapNum(0)
988                 self.steptimer = False
989                 self.nextStepTimer.stop()
990
991         def layoutFinished(self):
992                 self["shortcutsyellow"].setEnabled(False)
993                 self["AdapterInfo_OK"].hide()
994                 self["NetworkInfo_Check"].hide()
995                 self["DhcpInfo_Check"].hide()
996                 self["IPInfo_Check"].hide()
997                 self["DNSInfo_Check"].hide()
998                 self["EditSettings_Text"].hide()
999                 self["EditSettingsButton"].hide()
1000                 self["InfoText"].hide()
1001                 self["InfoTextBorder"].hide()
1002
1003         def setLabels(self):
1004                 self["Adaptertext"] = MultiColorLabel(_("LAN Adapter"))
1005                 self["Adapter"] = MultiColorLabel()
1006                 self["AdapterInfo"] = MultiPixmap()
1007                 self["AdapterInfo_Text"] = MultiColorLabel(_("Show Info"))
1008                 self["AdapterInfo_OK"] = Pixmap()
1009                 
1010                 if self.iface == 'wlan0' or self.iface == 'ath0':
1011                         self["Networktext"] = MultiColorLabel(_("Wireless Network"))
1012                 else:
1013                         self["Networktext"] = MultiColorLabel(_("Local Network"))
1014                 
1015                 self["Network"] = MultiColorLabel()
1016                 self["NetworkInfo"] = MultiPixmap()
1017                 self["NetworkInfo_Text"] = MultiColorLabel(_("Show Info"))
1018                 self["NetworkInfo_Check"] = MultiPixmap()
1019                 
1020                 self["Dhcptext"] = MultiColorLabel(_("DHCP"))
1021                 self["Dhcp"] = MultiColorLabel()
1022                 self["DhcpInfo"] = MultiPixmap()
1023                 self["DhcpInfo_Text"] = MultiColorLabel(_("Show Info"))
1024                 self["DhcpInfo_Check"] = MultiPixmap()
1025                 
1026                 self["IPtext"] = MultiColorLabel(_("IP Address"))
1027                 self["IP"] = MultiColorLabel()
1028                 self["IPInfo"] = MultiPixmap()
1029                 self["IPInfo_Text"] = MultiColorLabel(_("Show Info"))
1030                 self["IPInfo_Check"] = MultiPixmap()
1031                 
1032                 self["DNStext"] = MultiColorLabel(_("Nameserver"))
1033                 self["DNS"] = MultiColorLabel()
1034                 self["DNSInfo"] = MultiPixmap()
1035                 self["DNSInfo_Text"] = MultiColorLabel(_("Show Info"))
1036                 self["DNSInfo_Check"] = MultiPixmap()
1037                 
1038                 self["EditSettings_Text"] = MultiColorLabel(_("Edit settings"))
1039                 self["EditSettingsButton"] = MultiPixmap()
1040                 
1041                 self["ButtonRedtext"] = Label(_("Close"))
1042                 self["ButtonRed"] = Pixmap()
1043
1044                 self["ButtonGreentext"] = Label(_("Start test"))
1045                 self["ButtonGreen_Check"] = MultiPixmap()
1046                 
1047                 self["ButtonYellowtext"] = Label(_("Stop test"))
1048                 self["ButtonYellow_Check"] = MultiPixmap()
1049                 
1050                 self["InfoTextBorder"] = Pixmap()
1051                 self["InfoText"] = Label()
1052
1053         def getLinkState(self,iface):
1054                 if iface == 'wlan0' or iface == 'ath0':
1055                         try:
1056                                 from Plugins.SystemPlugins.WirelessLan.Wlan import Wlan
1057                                 w = Wlan(iface)
1058                                 stats = w.getStatus()
1059                                 if stats['BSSID'] == "00:00:00:00:00:00":
1060                                         self["Network"].setForegroundColorNum(1)
1061                                         self["Network"].setText(_("disconnected"))
1062                                         self["NetworkInfo_Check"].setPixmapNum(1)
1063                                         self["NetworkInfo_Check"].show()
1064                                 else:
1065                                         self["Network"].setForegroundColorNum(2)
1066                                         self["Network"].setText(_("connected"))
1067                                         self["NetworkInfo_Check"].setPixmapNum(0)
1068                                         self["NetworkInfo_Check"].show()
1069                         except:
1070                                         self["Network"].setForegroundColorNum(1)
1071                                         self["Network"].setText(_("disconnected"))
1072                                         self["NetworkInfo_Check"].setPixmapNum(1)
1073                                         self["NetworkInfo_Check"].show()
1074                 else:
1075                         iNetwork.getLinkState(iface,self.dataAvail)
1076
1077         def dataAvail(self,data):
1078                 self.output = data.strip()
1079                 result = self.output.split('\n')
1080                 pattern = re_compile("Link detected: yes")
1081                 for item in result:
1082                         if re_search(pattern, item):
1083                                 self["Network"].setForegroundColorNum(2)
1084                                 self["Network"].setText(_("connected"))
1085                                 self["NetworkInfo_Check"].setPixmapNum(0)
1086                         else:
1087                                 self["Network"].setForegroundColorNum(1)
1088                                 self["Network"].setText(_("disconnected"))
1089                                 self["NetworkInfo_Check"].setPixmapNum(1)
1090                 self["NetworkInfo_Check"].show()
1091
1092