fix typo
[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", "ColorActions"],
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 your 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                 self["ButtonYellow_Check"].show()
842                 self["ButtonYellowtext"].show()
843
844         def doStep2(self):
845                 self["Adapter"].setText(iNetwork.getFriendlyAdapterName(self.iface))
846                 self["Adapter"].setForegroundColorNum(2)
847                 self["Adaptertext"].setForegroundColorNum(1)
848                 self["AdapterInfo_Text"].setForegroundColorNum(1)
849                 self["AdapterInfo_OK"].show()
850                 self.steptimer = True
851                 self.nextStepTimer.start(3000)
852
853         def doStep3(self):
854                 self["Networktext"].setForegroundColorNum(1)
855                 self.getLinkState(self.iface)
856                 self["NetworkInfo_Text"].setForegroundColorNum(1)
857                 self.steptimer = True
858                 self.nextStepTimer.start(3000)
859
860         def doStep4(self):
861                 self["Dhcptext"].setForegroundColorNum(1)
862                 if iNetwork.getAdapterAttribute(self.iface, 'dhcp') is True:
863                         self["Dhcp"].setForegroundColorNum(2)
864                         self["Dhcp"].setText(_("enabled"))
865                         self["DhcpInfo_Check"].setPixmapNum(0)
866                 else:
867                         self["Dhcp"].setForegroundColorNum(1)
868                         self["Dhcp"].setText(_("disabled"))
869                         self["DhcpInfo_Check"].setPixmapNum(1)
870                 self["DhcpInfo_Check"].show()
871                 self["DhcpInfo_Text"].setForegroundColorNum(1)
872                 self.steptimer = True
873                 self.nextStepTimer.start(3000)
874
875         def doStep5(self):
876                 self["IPtext"].setForegroundColorNum(1)
877                 ret = iNetwork.checkNetworkState()
878                 if ret == True:
879                         self["IP"].setForegroundColorNum(2)
880                         self["IP"].setText(_("confirmed"))
881                         self["IPInfo_Check"].setPixmapNum(0)
882                 else:
883                         self["IP"].setForegroundColorNum(1)
884                         self["IP"].setText(_("unconfirmed"))
885                         self["IPInfo_Check"].setPixmapNum(1)
886                 self["IPInfo_Check"].show()
887                 self["IPInfo_Text"].setForegroundColorNum(1)
888                 self.steptimer = True
889                 self.nextStepTimer.start(3000)
890
891         def doStep6(self):
892                 self.steptimer = False
893                 self.nextStepTimer.stop()
894                 self["DNStext"].setForegroundColorNum(1)
895                 ret = iNetwork.checkDNSLookup()
896                 if ret == True:
897                         self["DNS"].setForegroundColorNum(2)
898                         self["DNS"].setText(_("confirmed"))
899                         self["DNSInfo_Check"].setPixmapNum(0)
900                 else:
901                         self["DNS"].setForegroundColorNum(1)
902                         self["DNS"].setText(_("unconfirmed"))
903                         self["DNSInfo_Check"].setPixmapNum(1)
904                 self["DNSInfo_Check"].show()
905                 self["DNSInfo_Text"].setForegroundColorNum(1)
906                 
907                 self["EditSettings_Text"].show()
908                 self["EditSettingsButton"].setPixmapNum(1)
909                 self["EditSettings_Text"].setForegroundColorNum(2) # active
910                 self["EditSettingsButton"].show()
911                 self["ButtonYellow_Check"].setPixmapNum(1)
912                 self["ButtonGreentext"].setText(_("Restart test"))
913                 self["ButtonGreen_Check"].setPixmapNum(0)
914                 self["shortcutsgreen"].setEnabled(False)
915                 self["shortcutsgreen_restart"].setEnabled(True)
916                 self["shortcutsyellow"].setEnabled(False)
917                 self["updown_actions"].setEnabled(True)
918                 self.activebutton = 6
919
920         def KeyGreen(self):
921                 self["shortcutsgreen"].setEnabled(False)
922                 self["shortcutsyellow"].setEnabled(True)
923                 self["updown_actions"].setEnabled(False)
924                 self["ButtonYellow_Check"].setPixmapNum(0)
925                 self["ButtonGreen_Check"].setPixmapNum(1)
926                 self.steptimer = True
927                 self.nextStepTimer.start(1000)
928
929         def KeyGreenRestart(self):
930                 self.nextstep = 0
931                 self.layoutFinished()
932                 self["Adapter"].setText((""))
933                 self["Network"].setText((""))
934                 self["Dhcp"].setText((""))
935                 self["IP"].setText((""))
936                 self["DNS"].setText((""))
937                 self["AdapterInfo_Text"].setForegroundColorNum(0)
938                 self["NetworkInfo_Text"].setForegroundColorNum(0)
939                 self["DhcpInfo_Text"].setForegroundColorNum(0)
940                 self["IPInfo_Text"].setForegroundColorNum(0)
941                 self["DNSInfo_Text"].setForegroundColorNum(0)
942                 self["shortcutsgreen_restart"].setEnabled(False)
943                 self["shortcutsgreen"].setEnabled(False)
944                 self["shortcutsyellow"].setEnabled(True)
945                 self["updown_actions"].setEnabled(False)
946                 self["ButtonYellow_Check"].setPixmapNum(0)
947                 self["ButtonGreen_Check"].setPixmapNum(1)
948                 self.steptimer = True
949                 self.nextStepTimer.start(1000)
950
951         def KeyOK(self):
952                 self["infoshortcuts"].setEnabled(True)
953                 self["shortcuts"].setEnabled(False)
954                 if self.activebutton == 1: # Adapter Check
955                         self["InfoText"].setText(_("This test detects your configured LAN-Adapter."))
956                         self["InfoTextBorder"].show()
957                         self["InfoText"].show()
958                         self["ButtonRedtext"].setText(_("Back"))
959                 if self.activebutton == 2: #LAN Check
960                         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"))
961                         self["InfoTextBorder"].show()
962                         self["InfoText"].show()
963                         self["ButtonRedtext"].setText(_("Back"))
964                 if self.activebutton == 3: #DHCP Check
965                         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."))
966                         self["InfoTextBorder"].show()
967                         self["InfoText"].show()
968                         self["ButtonRedtext"].setText(_("Back"))
969                 if self.activebutton == 4: # IP Check
970                         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"))
971                         self["InfoTextBorder"].show()
972                         self["InfoText"].show()
973                         self["ButtonRedtext"].setText(_("Back"))
974                 if self.activebutton == 5: # DNS Check
975                         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"))
976                         self["InfoTextBorder"].show()
977                         self["InfoText"].show()
978                         self["ButtonRedtext"].setText(_("Back"))
979                 if self.activebutton == 6: # Edit Settings
980                         self.session.open(AdapterSetup,self.iface)
981
982         def KeyYellow(self):
983                 self.nextstep = 0
984                 self["shortcutsgreen_restart"].setEnabled(True)
985                 self["shortcutsgreen"].setEnabled(False)
986                 self["shortcutsyellow"].setEnabled(False)
987                 self["ButtonGreentext"].setText(_("Restart test"))
988                 self["ButtonYellow_Check"].setPixmapNum(1)
989                 self["ButtonGreen_Check"].setPixmapNum(0)
990                 self.steptimer = False
991                 self.nextStepTimer.stop()
992
993         def layoutFinished(self):
994                 self["shortcutsyellow"].setEnabled(False)
995                 self["AdapterInfo_OK"].hide()
996                 self["NetworkInfo_Check"].hide()
997                 self["DhcpInfo_Check"].hide()
998                 self["IPInfo_Check"].hide()
999                 self["DNSInfo_Check"].hide()
1000                 self["EditSettings_Text"].hide()
1001                 self["EditSettingsButton"].hide()
1002                 self["InfoText"].hide()
1003                 self["InfoTextBorder"].hide()
1004                 self["ButtonYellow_Check"].hide()
1005                 self["ButtonYellowtext"].hide()
1006
1007         def setLabels(self):
1008                 self["Adaptertext"] = MultiColorLabel(_("LAN Adapter"))
1009                 self["Adapter"] = MultiColorLabel()
1010                 self["AdapterInfo"] = MultiPixmap()
1011                 self["AdapterInfo_Text"] = MultiColorLabel(_("Show Info"))
1012                 self["AdapterInfo_OK"] = Pixmap()
1013                 
1014                 if self.iface == 'wlan0' or self.iface == 'ath0':
1015                         self["Networktext"] = MultiColorLabel(_("Wireless Network"))
1016                 else:
1017                         self["Networktext"] = MultiColorLabel(_("Local Network"))
1018                 
1019                 self["Network"] = MultiColorLabel()
1020                 self["NetworkInfo"] = MultiPixmap()
1021                 self["NetworkInfo_Text"] = MultiColorLabel(_("Show Info"))
1022                 self["NetworkInfo_Check"] = MultiPixmap()
1023                 
1024                 self["Dhcptext"] = MultiColorLabel(_("DHCP"))
1025                 self["Dhcp"] = MultiColorLabel()
1026                 self["DhcpInfo"] = MultiPixmap()
1027                 self["DhcpInfo_Text"] = MultiColorLabel(_("Show Info"))
1028                 self["DhcpInfo_Check"] = MultiPixmap()
1029                 
1030                 self["IPtext"] = MultiColorLabel(_("IP Address"))
1031                 self["IP"] = MultiColorLabel()
1032                 self["IPInfo"] = MultiPixmap()
1033                 self["IPInfo_Text"] = MultiColorLabel(_("Show Info"))
1034                 self["IPInfo_Check"] = MultiPixmap()
1035                 
1036                 self["DNStext"] = MultiColorLabel(_("Nameserver"))
1037                 self["DNS"] = MultiColorLabel()
1038                 self["DNSInfo"] = MultiPixmap()
1039                 self["DNSInfo_Text"] = MultiColorLabel(_("Show Info"))
1040                 self["DNSInfo_Check"] = MultiPixmap()
1041                 
1042                 self["EditSettings_Text"] = MultiColorLabel(_("Edit settings"))
1043                 self["EditSettingsButton"] = MultiPixmap()
1044                 
1045                 self["ButtonRedtext"] = Label(_("Close"))
1046                 self["ButtonRed"] = Pixmap()
1047
1048                 self["ButtonGreentext"] = Label(_("Start test"))
1049                 self["ButtonGreen_Check"] = MultiPixmap()
1050                 
1051                 self["ButtonYellowtext"] = Label(_("Stop test"))
1052                 self["ButtonYellow_Check"] = MultiPixmap()
1053                 
1054                 self["InfoTextBorder"] = Pixmap()
1055                 self["InfoText"] = Label()
1056
1057         def getLinkState(self,iface):
1058                 if iface == 'wlan0' or iface == 'ath0':
1059                         try:
1060                                 from Plugins.SystemPlugins.WirelessLan.Wlan import Wlan
1061                                 w = Wlan(iface)
1062                                 stats = w.getStatus()
1063                                 if stats['BSSID'] == "00:00:00:00:00:00":
1064                                         self["Network"].setForegroundColorNum(1)
1065                                         self["Network"].setText(_("disconnected"))
1066                                         self["NetworkInfo_Check"].setPixmapNum(1)
1067                                         self["NetworkInfo_Check"].show()
1068                                 else:
1069                                         self["Network"].setForegroundColorNum(2)
1070                                         self["Network"].setText(_("connected"))
1071                                         self["NetworkInfo_Check"].setPixmapNum(0)
1072                                         self["NetworkInfo_Check"].show()
1073                         except:
1074                                         self["Network"].setForegroundColorNum(1)
1075                                         self["Network"].setText(_("disconnected"))
1076                                         self["NetworkInfo_Check"].setPixmapNum(1)
1077                                         self["NetworkInfo_Check"].show()
1078                 else:
1079                         iNetwork.getLinkState(iface,self.dataAvail)
1080
1081         def dataAvail(self,data):
1082                 self.output = data.strip()
1083                 result = self.output.split('\n')
1084                 pattern = re_compile("Link detected: yes")
1085                 for item in result:
1086                         if re_search(pattern, item):
1087                                 self["Network"].setForegroundColorNum(2)
1088                                 self["Network"].setText(_("connected"))
1089                                 self["NetworkInfo_Check"].setPixmapNum(0)
1090                         else:
1091                                 self["Network"].setForegroundColorNum(1)
1092                                 self["Network"].setText(_("disconnected"))
1093                                 self["NetworkInfo_Check"].setPixmapNum(1)
1094                 self["NetworkInfo_Check"].show()
1095
1096