WirelesslanSetup : fix iwconfig problem, virtual key screen and so on..
[vuplus_dvbapp] / lib / python / Plugins / SystemPlugins / WirelessLanSetup / plugin.py
1 from Screens.Screen import Screen
2 from Screens.MessageBox import MessageBox
3 from Screens.InputBox import InputBox
4 from Screens.Standby import *
5 from Screens.VirtualKeyBoard import VirtualKeyBoard
6 from Screens.HelpMenu import HelpableScreen
7 from Components.Network import iNetwork
8 from Screens.NetworkSetup import NameserverSetup
9 from Components.Sources.StaticText import StaticText
10 from Components.Sources.Boolean import Boolean
11 from Components.Sources.List import List
12 from Components.Label import Label,MultiColorLabel
13 from Components.Pixmap import Pixmap,MultiPixmap
14 from Components.MenuList import MenuList
15 from Components.config import config, ConfigYesNo, ConfigIP, NoSave, ConfigText, ConfigPassword, ConfigSelection, getConfigListEntry, ConfigNothing
16 from Components.config import ConfigInteger, ConfigSubsection
17 from Components.ConfigList import ConfigListScreen
18 from Components.PluginComponent import plugins
19 from Components.MultiContent import MultiContentEntryText, MultiContentEntryPixmapAlphaTest
20 from Components.ActionMap import ActionMap, NumberActionMap, HelpableActionMap
21 from Components.Console import Console
22 from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_CURRENT_SKIN
23 from Tools.LoadPixmap import LoadPixmap
24 from Plugins.Plugin import PluginDescriptor
25 from enigma import eTimer, ePoint, eSize, RT_HALIGN_LEFT, eListboxPythonMultiContent, gFont
26 from os import path as os_path, system as os_system, unlink,listdir
27 from re import compile as re_compile, search as re_search
28 from Tools.Directories import fileExists
29 import time
30
31 class WlanSelection(Screen,HelpableScreen):
32         skin = """
33         <screen name="WlanSelection" position="209,48" size="865,623" title="Wireless Network Configuration..." flags="wfNoBorder" backgroundColor="transparent">
34                 <ePixmap pixmap="Vu_HD/Bg_EPG_view.png" zPosition="-1" position="0,0" size="865,623" alphatest="on" />
35                 <ePixmap pixmap="Vu_HD/menu/ico_title_Setup.png" position="32,41" size="40,40" alphatest="blend"  transparent="1" />
36                 <eLabel text="Wireless Network Adapter Selection..." position="90,50" size="600,32" font="Semiboldit;32" foregroundColor="#5d5d5d" backgroundColor="#27b5b9bd" transparent="1" />
37                 <ePixmap pixmap="Vu_HD/icons/clock.png" position="750,55" zPosition="1" size="20,20" alphatest="blend" />
38                 <widget source="global.CurrentTime" render="Label" position="770,57" zPosition="1" size="50,20" font="Regular;20" foregroundColor="#1c1c1c" backgroundColor="#27d9dee2" halign="right" transparent="1">
39                         <convert type="ClockToText">Format:%H:%M</convert>
40                 </widget>
41                 <ePixmap pixmap="Vu_HD/buttons/red.png" position="45,98" size="25,25" alphatest="blend" />
42                 <ePixmap pixmap="Vu_HD/buttons/green.png" position="240,98" size="25,25" alphatest="blend" />
43                 <widget source="key_red" render="Label" position="66,97" zPosition="1" size="150,25" font="Regular;20" halign="center" valign="center" backgroundColor="darkgrey" foregroundColor="#1c1c1c" transparent="1" />
44                 <widget source="key_green" render="Label" position="268,97" zPosition="1" size="150,25" font="Regular;20" halign="center" valign="center" backgroundColor="darkgrey" foregroundColor="#1c1c1c" transparent="1" />
45                 <ePixmap pixmap="Vu_HD/border_menu.png" position="120,140" zPosition="-1" size="342,358" transparent="1" alphatest="blend" />
46                 <widget name="menulist" position="130,150" size="322,338" transparent="1" backgroundColor="#27d9dee2" zPosition="10" scrollbarMode="showOnDemand" />
47                 <widget source="description" render="Label" position="500,140" size="280,360" font="Regular;19" halign="center" valign="center" backgroundColor="#c5c9cc" transparent="1"/>
48         </screen>"""
49         
50         def __init__(self, session):
51                 Screen.__init__(self,session)
52                 HelpableScreen.__init__(self)
53                 self.mainmenu = self.getWlandevice()
54                 self["menulist"] = MenuList(self.mainmenu)
55                 self["key_red"] = StaticText(_("Close"))
56                 self["key_green"] = StaticText(_("Select"))
57                 self["description"] = StaticText()
58                 self["description"].setText(_("Select Wireless Lan module. \n" ))
59                 self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
60                 {
61                         "ok": (self.ok, _("select interface")),
62                         "cancel": (self.close, _("exit network interface list")),
63                 })
64
65                 self["ColorActions"] = HelpableActionMap(self, "ColorActions",
66                 {
67                         "green": (self.ok, _("select interface")),
68                         "red": (self.close, _("exit network interface list")),
69                 })
70
71         def ok(self):
72 #               print len(self["menulist"].list)
73                 if len(self["menulist"].list) == 0:
74                         self.session.open(MessageBox, (_("Can not find any WirelessLan Module\n")),MessageBox.TYPE_ERROR,5 )
75                         return
76                 ifaces=self["menulist"].getCurrent()[1]
77                 if ifaces == None:
78                         pass
79                 else:
80                         self.session.open(WlanSetup,ifaces)
81
82         def getWlandevice(self):
83                 list = []
84                 for x in iNetwork.getAdapterList():
85                         if x.startswith('eth'):
86                                 continue
87                         description=self.getAdapterDescription(x)
88                         if description == "Unknown network adapter":
89                                 list.append((description,x))
90                         else:
91                                 list.append((description + " (%s)"%x,x))
92                 return list
93
94         def getAdapterDescription(self, iface):
95                 classdir = "/sys/class/net/" + iface + "/device/"
96                 driverdir = "/sys/class/net/" + iface + "/device/driver/"
97                 if os_path.exists(classdir):
98                         files = listdir(classdir)
99                         if 'driver' in files:
100                                 if os_path.realpath(driverdir).endswith('rtw_usb_drv'):
101                                         return _("Realtak")+ " " + _("WLAN adapter.")
102                                 elif os_path.realpath(driverdir).endswith('ath_pci'):
103                                         return _("Atheros")+ " " + _("WLAN adapter.")
104                                 elif os_path.realpath(driverdir).endswith('zd1211b'):
105                                         return _("Zydas")+ " " + _("WLAN adapter.")
106                                 elif os_path.realpath(driverdir).endswith('rt73'):
107                                         return _("Ralink")+ " " + _("WLAN adapter.")
108                                 elif os_path.realpath(driverdir).endswith('rt73usb'):
109                                         return _("Ralink")+ " " + _("WLAN adapter.")
110                                 else:
111                                         return str(os_path.basename(os_path.realpath(driverdir))) + " " + _("WLAN adapter")
112                         else:
113                                 return _("Unknown network adapter")
114                 else:
115                         return _("Unknown network adapter")
116
117 class WlanSetup(Screen,HelpableScreen):
118         skin = """
119         <screen name="WlanSetup" position="209,48" size="865,623" title="Wireless Network Configuration..." flags="wfNoBorder" backgroundColor="transparent">   
120                 <ePixmap pixmap="Vu_HD/Bg_EPG_view.png" zPosition="-1" position="0,0" size="865,623" alphatest="on" />
121                 <ePixmap pixmap="Vu_HD/menu/ico_title_Setup.png" position="32,41" size="40,40" alphatest="blend"  transparent="1" />
122                 <eLabel text="Wireless Network Setup Menu..." position="90,50" size="600,32" font="Semiboldit;32" foregroundColor="#5d5d5d" backgroundColor="#27b5b9bd" transparent="1" />
123                 <ePixmap pixmap="Vu_HD/icons/clock.png" position="750,55" zPosition="1" size="20,20" alphatest="blend" />
124                 <widget source="global.CurrentTime" render="Label" position="770,57" zPosition="1" size="50,20" font="Regular;20" foregroundColor="#1c1c1c" backgroundColor="#27d9dee2" halign="right" transparent="1">
125                         <convert type="ClockToText">Format:%H:%M</convert>
126                 </widget>
127                 <ePixmap pixmap="Vu_HD/buttons/red.png" position="45,98" size="25,25" alphatest="blend" />
128                 <ePixmap pixmap="Vu_HD/buttons/green.png" position="240,98" size="25,25" alphatest="blend" />
129                 <widget source="key_red" render="Label" position="66,97" zPosition="1" size="150,25" font="Regular;20" halign="center" valign="center" backgroundColor="darkgrey" foregroundColor="#1c1c1c" transparent="1" />
130                 <widget source="key_green" render="Label" position="268,97" zPosition="1" size="150,25" font="Regular;20" halign="center" valign="center" backgroundColor="darkgrey" foregroundColor="#1c1c1c" transparent="1" />
131                 <ePixmap pixmap="Vu_HD/border_menu.png" position="120,140" zPosition="-1" size="342,358" transparent="1" alphatest="blend" />
132                 <widget name="menulist" position="130,150" size="322,338" transparent="1" backgroundColor="#27d9dee2" zPosition="10" scrollbarMode="showOnDemand" />
133                 <widget source="description" render="Label" position="500,140" size="280,360" font="Regular;19" halign="center" valign="center" backgroundColor="#c5c9cc" transparent="1"/>
134         </screen>"""
135         def __init__(self, session, ifaces):
136                 Screen.__init__(self, session)
137                 HelpableScreen.__init__(self)
138                 self.session = session
139                 self.iface = ifaces
140                 self.restartLanRef = None
141                 self.LinkState = None
142                 self.mainmenu = self.MakeMenu()
143                 self["menulist"] = MenuList(self.mainmenu)
144                 self["key_red"] = StaticText(_("Close"))
145                 self["key_green"] = StaticText(_("Select"))
146                 self["description"] = StaticText()
147                 self["IFtext"] = StaticText()
148                 self["IF"] = StaticText()
149                 self["Statustext"] = StaticText()
150                 self["statuspic"] = MultiPixmap()
151                 self["statuspic"].hide()
152                 self.onLayoutFinish.append(self.loadDescription)
153                 
154                 self.oktext = _("Press OK on your remote control to continue.")
155                 
156                 self["WizardActions"] = HelpableActionMap(self, "WizardActions",
157                         {
158                         "up": (self.up, _("move up to previous entry")),
159                         "down": (self.down, _("move down to next entry")),
160                         "left": (self.left, _("move up to first entry")),
161                         "right": (self.right, _("move down to last entry")),
162                         })
163                 
164                 self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
165                         {
166                         "cancel": (self.close, _("exit networkadapter setup menu")),
167                         "ok": (self.ok, _("select menu entry")),
168                         })
169
170                 self["ColorActions"] = HelpableActionMap(self, "ColorActions",
171                         {
172                         "red": (self.close, _("exit networkadapter setup menu")),
173                         "green": (self.ok, _("select menu entry")),
174                         })
175
176                 self["actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
177                 {
178                         "ok": self.ok,
179                         "back": self.close,
180                         "up": self.up,
181                         "down": self.down,
182                         "red": self.close,
183                         "left": self.left,
184                         "right": self.right,
185                 }, -2)
186
187         def loadDescription(self):
188                 if self["menulist"].getCurrent()[1] == 'setting':
189                         self["description"].setText(_("Edit the network configuration of your STB.\n" ) + self.oktext )
190                 if self["menulist"].getCurrent()[1] == 'scanap':
191                         self["description"].setText(_("Scan your network for wireless access points and connect to them using your selected wireless device.\n" ) + self.oktext )
192                 if self["menulist"].getCurrent()[1] == 'dns':
193                         self["description"].setText(_("Edit the Nameserver configuration of your STB.\n" ) + self.oktext )
194                 if self["menulist"].getCurrent()[1] == 'status':
195                         self["description"].setText(_("Shows the state of your wireless LAN connection.\n" ) + self.oktext )
196                 if self["menulist"].getCurrent()[1] == 'test':
197                         self["description"].setText(_("Test the network configuration of your STB.\n" ) + self.oktext )
198                 if self["menulist"].getCurrent()[1] == 'restart':
199                         self["description"].setText(_("Restart your network connection and interfaces.\n" ) + self.oktext )
200
201         def up(self):
202                 self["menulist"].up()
203                 self.loadDescription()
204
205         def down(self):
206                 self["menulist"].down()
207                 self.loadDescription()
208
209         def left(self):
210                 self["menulist"].pageUp()
211                 self.loadDescription()
212
213         def right(self):
214                 self["menulist"].pageDown()
215                 self.loadDescription()
216
217         def ok(self):
218                 if self["menulist"].getCurrent()[1] == 'setting':
219                         self.session.openWithCallback(self.checklist, WlanConfig, self.iface)
220                 elif self["menulist"].getCurrent()[1] == 'scanap':
221                         self.session.open(WlanScanAp, self.iface)
222                 elif self["menulist"].getCurrent()[1] == 'dns':
223                         self.session.open(NameserverSetup)
224                 elif self["menulist"].getCurrent()[1] == 'status':
225                         self.session.open(Wlanstatus, self.iface)
226                 elif self["menulist"].getCurrent()[1] == 'test':
227                         self.session.openWithCallback(self.checklist,NetworkAdapterTest,self.iface)
228                 elif self["menulist"].getCurrent()[1] == 'restart':
229                         self.session.openWithCallback(self.restartLan, MessageBox, (_("Are you sure you want to restart your network interfaces?\n\n") + self.oktext ) )
230
231         def checklist(self):
232                 self["menulist"].setList(self.MakeMenu())
233
234         def MakeMenu(self):
235                 menu = []
236                 menu.append((_("Adapter settings"), "setting"))
237                 menu.append((_("Scan Wireless AP"), "scanap"))
238                 menu.append((_("Nameserver settings"), "dns"))
239                 if iNetwork.getAdapterAttribute(self.iface, "up"):
240                         menu.append((_("Show WLAN Status"), "status"))
241                 menu.append((_("Network test"), "test"))
242                 menu.append((_("Restart network"), "restart"))
243
244                 return menu
245
246         def restartLan(self, ret = False):
247                 if (ret == True):
248                         iNetwork.restartNetwork(self.restartLanDataAvail)
249                         self.restartLanRef = self.session.openWithCallback(self.restartfinishedCB, MessageBox, _("Please wait while your network is restarting..."), type = MessageBox.TYPE_INFO, enable_input = False)
250
251         def restartLanDataAvail(self, data):
252                 if data is True:
253                         iNetwork.getInterfaces(self.getInterfacesDataAvail)
254
255         def getInterfacesDataAvail(self, data):
256                 if data is True:
257                         self.restartLanRef.close(True)
258
259         def restartfinishedCB(self,data):
260                 if data is True:
261                         self.session.open(MessageBox, _("Finished restarting your network"), type = MessageBox.TYPE_INFO, timeout = 5, default = False)
262
263 wlanconfig = ConfigSubsection()
264 wlanconfig.usedevice = ConfigSelection(default = "off", choices = [
265         ("off", _("off")), ("on", _("on"))])
266 wlanconfig.usedhcp = ConfigSelection(default = "off", choices = [
267         ("off", _("no")), ("on", _("yes"))])
268 wlanconfig.essid = ConfigSelection(default = "none", choices = ["none"])
269 wlanconfig.encrypt = ConfigSelection(default = "off", choices = [
270         ("off", _("no")), ("on", _("yes"))])
271 wlanconfig.method = ConfigSelection(default = "wep", choices = [
272         ("wep", _("WEP")), ("wpa", _("WPA")), ("wpa2", _("WPA2")),("wpa/wpa2", _("WPA/WPA2"))])
273 wlanconfig.keytype = ConfigSelection(default = "ascii", choices = [
274         ("ascii", _("ASCII")), ("hex", _("HEX"))])
275 wlanconfig.key = ConfigText(default = "XXXXXXXX", visible_width = 50, fixed_size = False)
276 wlanconfig.usegateway = ConfigSelection(default = "off", choices = [
277         ("off", _("no")), ("on", _("yes"))])
278 wlanconfig.ip    = ConfigIP([0,0,0,0])
279 wlanconfig.netmask = ConfigIP([0,0,0,0])
280 wlanconfig.gateway = ConfigIP([0,0,0,0])
281
282 selectap = None 
283 class WlanConfig(Screen, ConfigListScreen, HelpableScreen):
284         skin = """
285         <screen name="WlanConfig" position="209,48" size="865,623" title="Wireless Network Configuration..." flags="wfNoBorder" backgroundColor="transparent">  
286                 <ePixmap pixmap="Vu_HD/Bg_EPG_view.png" zPosition="-1" position="0,0" size="865,623" alphatest="on" />
287                 <ePixmap pixmap="Vu_HD/menu/ico_title_Setup.png" position="32,41" size="40,40" alphatest="blend"  transparent="1" />
288                 <eLabel text="Wireless Network Configuration..." position="90,50" size="600,32" font="Semiboldit;32" foregroundColor="#5d5d5d" backgroundColor="#27b5b9bd" transparent="1" />
289                 <ePixmap pixmap="Vu_HD/icons/clock.png" position="750,55" zPosition="1" size="20,20" alphatest="blend" />
290                 <widget source="global.CurrentTime" render="Label" position="770,57" zPosition="1" size="50,20" font="Regular;20" foregroundColor="#1c1c1c" backgroundColor="#27d9dee2" halign="right" transparent="1">
291                         <convert type="ClockToText">Format:%H:%M</convert>
292                 </widget>
293                 <ePixmap pixmap="Vu_HD/buttons/red.png" position="45,98" size="25,25" alphatest="blend" />
294                 <ePixmap pixmap="Vu_HD/buttons/green.png" position="240,98" size="25,25" alphatest="blend" />
295                 <widget source="key_red" render="Label" position="66,97" zPosition="1" size="150,25" font="Regular;20" halign="center" valign="center" backgroundColor="darkgrey" foregroundColor="#1c1c1c" transparent="1" />
296                 <widget source="key_grean" render="Label" position="268,97" zPosition="1" size="150,25" font="Regular;20" halign="center" valign="center" backgroundColor="darkgrey" foregroundColor="#1c1c1c" transparent="1" />
297                 <ePixmap pixmap="Vu_HD/border_menu.png" position="120,140" zPosition="-1" size="342,358" transparent="1" alphatest="blend" />
298                 <widget name="config" position="130,150" size="322,338" transparent="1" backgroundColor="#27d9dee2" zPosition="10" scrollbarMode="showOnDemand" />
299                 <eLabel text="IP Address : " position="500,160" size="200,26" font="Semiboldit;22" foregroundColor="#5d5d5d" backgroundColor="#27b5b9bd" transparent="1" />             
300                 <widget source="ipaddress" render="Label" position="530,190" zPosition="1" size="150,26" font="Regular;20" halign="center" valign="center" backgroundColor="#27b5b9bd" foregroundColor="#1c1c1c" transparent="1" />             
301                 <eLabel text="NetMask : " position="500,220" size="200,26" font="Semiboldit;22" foregroundColor="#5d5d5d" backgroundColor="#27b5b9bd" transparent="1" />                
302                 <widget source="netmask" render="Label" position="530,250" zPosition="1" size="150,26" font="Regular;20" halign="center" valign="center" backgroundColor="#27b5b9bd" foregroundColor="#1c1c1c" transparent="1" />               
303                 <eLabel text="Gateway : " position="500,280" size="200,26" font="Semiboldit;22" foregroundColor="#5d5d5d" backgroundColor="#27b5b9bd" transparent="1" />                
304                 <widget source="gateway" render="Label" position="530,310" zPosition="1" size="150,26" font="Regular;20" halign="center" valign="center" backgroundColor="#27b5b9bd" foregroundColor="#1c1c1c" transparent="1" />               
305         </screen>"""
306
307         def __init__(self, session, iface):
308                 Screen.__init__(self,session)
309                 self.session = session
310                 self["key_red"] = StaticText(_("Close"))
311                 self["key_grean"] = StaticText(_("Ok"))
312                 self["ipaddress"] = StaticText(_("[ N/A ]"))
313                 self["netmask"] = StaticText(_("[ N/A ]"))              
314                 self["gateway"] = StaticText(_("[ N/A ]"))
315                 self["OkCancelActions"] = ActionMap(["ShortcutActions", "SetupActions" ],
316                 {
317                         "ok": self.saveWlanConfig,
318                         "green": self.saveWlanConfig,
319                         "cancel": self.keyCancel,
320                         "red": self.keyCancel,
321                 }, -2)
322                 self.iface = iface
323                 self.ssid = None
324                 self.ap_scan = None
325                 self.scan_ssid = None
326                 self.key_mgmt = None
327                 self.proto = None
328                 self.key_type = None
329                 self.encryption_key = None
330                 self.wlanscanap = None
331 #               self.scanAPcount =5
332                 self.scanAPcount =1
333                 self.list = []
334                 ConfigListScreen.__init__(self, self.list,session = self.session)
335                 self.oldInterfaceState = iNetwork.getAdapterAttribute(self.iface, "up")
336                 self.readWpaSupplicantConf()
337                 self.scanAPFailedTimer = eTimer()
338                 self.scanAPFailedTimer.callback.append(self.scanAPFailed)
339                 self.scanAplistTimer = eTimer()
340                 self.scanAplistTimer.callback.append(self.scanApList)
341                 self.Console = Console()
342 #               self.scanAplistTimer.start(100,True)
343                 iNetwork.getInterfaces(self.readWlanSettings)
344
345         def readWlanSettings(self,ret=None):
346                 if ret is not True:
347                         print "getInterfaces Fail... "
348                 if iNetwork.getAdapterAttribute(self.iface, "up") == True:
349                         default_tmp = "on"
350                 else:
351                         default_tmp = "off"
352                 wlanconfig.usedevice = ConfigSelection(default=default_tmp, choices = [("off", _("off")), ("on", _("on"))])
353
354                 if iNetwork.getAdapterAttribute(self.iface, "dhcp"):
355                         default_tmp = "on"
356                 else:
357                         default_tmp = "off"
358                 wlanconfig.usedhcp = ConfigSelection(default=default_tmp, choices = [("off", _("no")), ("on", _("yes"))])
359
360                 wlanconfig.ip = ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "ip")) or [0,0,0,0]
361
362                 wlanconfig.netmask = ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "netmask") or [255,0,0,0])
363                 if iNetwork.getAdapterAttribute(self.iface, "gateway"):
364                         default_tmp = "on"
365                 else:
366                         default_tmp = "off"
367                 wlanconfig.usegateway = ConfigSelection(default = default_tmp, choices = [("off", _("no")), ("on", _("yes"))])
368
369                 wlanconfig.gateway = ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "gateway") or [0,0,0,0])
370
371                 self["ipaddress"].setText(_(self.formatip(iNetwork.getAdapterAttribute(self.iface, "ip"))))
372                 self["netmask"].setText(_(self.formatip(iNetwork.getAdapterAttribute(self.iface, "netmask"))))
373                 self["gateway"].setText(_(self.formatip(iNetwork.getAdapterAttribute(self.iface, "gateway"))))
374
375                 if self.encryption_key is not None:
376                         default_tmp = "on"
377                 else:
378                         default_tmp = "off"
379                 wlanconfig.encrypt = ConfigSelection(default = default_tmp, choices = [("off", _("no")), ("on", _("yes"))])
380
381                 if self.key_mgmt=="NONE":
382                         default_tmp = "wep"
383                 elif self.key_mgmt == "WPA-PSK":
384                         if self.proto == "WPA":
385                                 default_tmp = "wpa"
386                         elif self.proto == "RSN":
387                                 default_tmp = "wpa2"
388                         elif self.proto in ( "WPA RSN", "WPA WPA2"):
389                                 default_tmp = "wpa/wpa2"
390                         else:
391                                 default_tmp = "wpa"
392                 else:
393                         default_tmp = "wep"
394
395                 wlanconfig.method = ConfigSelection(default = default_tmp, choices = [
396                         ("wep", _("WEP")), ("wpa", _("WPA")), ("wpa2", _("WPA2")),("wpa/wpa2", _("WPA/WPA2"))])
397
398                 if self.key_type == 0:
399                         default_tmp = "hex"
400                 else:
401                         default_tmp = "ascii"
402                 wlanconfig.keytype = ConfigSelection(default = default_tmp, choices = [
403                         ("ascii", _("ASCII")), ("hex", _("HEX"))])
404                 default_tmp = self.encryption_key or "XXXXXXXX"
405                 wlanconfig.key = ConfigText(default = default_tmp, visible_width = 50, fixed_size = False)
406                 self.scanAplistTimer.start(100,True)
407
408         def readWpaSupplicantConf(self):
409                 try:
410                         if fileExists("/etc/wpa_supplicant.conf"):
411                                 wpafd = open("/etc/wpa_supplicant.conf","r")
412                                 if wpafd >0:
413                                         data = wpafd.readline()
414                                         while len(data) > 0:
415 #                                               print "####readWpaSupplicantConf, data : ",data
416                                                 data = data.lstrip()
417                                                 if len(data) == 0:
418                                                         data = wpafd.readline()
419                                                         continue
420                                                 if data.startswith('ssid=') and len(data) > 6:
421                                                         self.ssid = data[6:-2]
422                                                 elif data.startswith('ap_scan=') :
423                                                         self.ap_scan = data[8:]
424 #                                                       print "####readWpaSupplicantConf, ap_scan : ",self.ap_scan
425                                                 elif data.startswith('scan_ssid=') and len(data) > 10:
426                                                         self.scan_ssid = data[10:-1]
427                                                 elif data.startswith('key_mgmt=') and len(data) > 9:
428                                                         self.key_mgmt = data[9:-1]
429                                                 elif data.startswith('proto=') and len(data) > 6:
430                                                         self.proto = data[6:-1]
431                                                 elif data.startswith('wep_key0="') and len(data) > 11:
432                                                         self.key_type = 1 # ascii
433                                                         self.encryption_key = data[10:-2]
434                                                 elif data.startswith('wep_key0=') and len(data) > 9:
435                                                         self.key_type = 0 # hex
436                                                         self.encryption_key = data[9:-1]
437                                                 elif data.startswith('psk="') and len(data) > 6:
438                                                         self.key_type = 1 # ascii
439                                                         self.encryption_key = data[5:-2]
440                                                 elif data.startswith('psk=') and len(data) > 4:
441                                                         self.key_type = 0 # hex
442                                                         self.encryption_key = data[4:-1]
443                                                 data = wpafd.readline()
444                                         print self.ssid,self.scan_ssid,self.key_mgmt,self.proto,self.key_type,self.encryption_key
445                                         wpafd.close()
446                                 else:
447                                         print 'read error'
448                         else:
449                                 pass
450                 except:
451                         print 'failed loading wpasupplicant.conf'
452
453         def createConfig(self):
454                 self.configList=[]
455                 self.usedeviceEntry = getConfigListEntry(_("Use Device"), wlanconfig.usedevice)
456                 self.usedhcpEntry = getConfigListEntry(_("Use DHCP"), wlanconfig.usedhcp)
457                 self.essidEntry = getConfigListEntry(_("ESSID"), wlanconfig.essid)
458                 self.hiddenessidEntry = getConfigListEntry(_("Input Hidden ESSID"), wlanconfig.hiddenessid)
459                 self.encryptEntry = getConfigListEntry(_("Encrypt"), wlanconfig.encrypt)
460                 self.methodEntry = getConfigListEntry(_("Method"), wlanconfig.method)
461                 self.keytypeEntry = getConfigListEntry(_("Key Type"), wlanconfig.keytype)
462                 self.keyEntry = getConfigListEntry(_("KEY"), wlanconfig.key)
463
464                 self.ipEntry = getConfigListEntry(_("IP"), wlanconfig.ip)
465                 self.netmaskEntry = getConfigListEntry(_("NetMask"), wlanconfig.netmask)
466
467                 self.usegatewayEntry = getConfigListEntry(_("Use Gateway"), wlanconfig.usegateway)
468                 self.gatewayEntry = getConfigListEntry(_("Gateway"), wlanconfig.gateway)
469
470                 self.configList.append( self.usedeviceEntry )
471                 if wlanconfig.usedevice.value is "on":
472                         self.configList.append( self.usedhcpEntry )
473                         if wlanconfig.usedhcp.value is "off":
474                                 self.configList.append(self.ipEntry)
475                                 self.configList.append(self.netmaskEntry)
476                                 self.configList.append(self.usegatewayEntry)
477                                 if wlanconfig.usegateway.value is "on":
478                                         self.configList.append(self.gatewayEntry)
479                         self.configList.append( self.essidEntry )
480 #                       print "#### wlanconfig.essid.value : ",wlanconfig.essid.value
481                         if wlanconfig.essid.value == 'Input hidden ESSID':
482                                 self.configList.append( self.hiddenessidEntry )
483                         self.configList.append( self.encryptEntry )
484                         if wlanconfig.encrypt.value is "on" :
485                                 self.configList.append( self.methodEntry )
486                                 self.configList.append( self.keytypeEntry )
487                                 self.configList.append( self.keyEntry )
488
489                 self["config"].list = self.configList
490                 self["config"].l.setList(self.configList)
491 #               if not self.selectionChanged in self["config"].onSelectionChanged:
492 #                       self["config"].onSelectionChanged.append(self.selectionChanged)
493
494         def scanApList(self):
495                 self.apList = []
496                 self.configurationmsg = self.session.open(MessageBox, _("Please wait for scanning AP..."), type = MessageBox.TYPE_INFO, enable_input = False)
497                 cmd = "ifconfig "+self.iface+" up"
498                 print 'cmd ',cmd
499                 os_system(cmd)
500                 self.wlanscanap = Console()
501                 cmd = "iwlist "+self.iface+" scan"
502                 print 'cmd ',cmd
503                 self.wlanscanap.ePopen(cmd, self.apListFinnished,self.apListParse)
504
505         def apListFinnished(self, result, retval,extra_args):
506                 (callback) = extra_args
507                 if self.wlanscanap is not None:
508                         if retval == 0:
509                                 self.wlanscanap = None
510                                 content = result.splitlines()
511                                 first = content[0].split()
512                                 completed = False
513                                 for x in first:
514                                         if x == 'completed':
515                                                 completed = True
516                                 if completed == True:
517                                         callback(result)
518                                 else:
519                                         callback(0)
520                         else:
521                                 callback(0)
522
523         def apListParse(self,data):
524                 global selectap
525                 if data == 0:
526                         if self.scanAPcount >0:
527                                 self.scanAPcount -=1
528                                 self.configurationmsg.close(True)
529                                 time.sleep(3)
530                                 self.scanAplistTimer.start(500,True)
531                                 return
532                         else:
533                                 self.configurationmsg.close(True)
534                                 self.scanAPFailedTimer.start(500,True)
535                                 return
536                 else:
537                         self.apList = []
538 #                       self.scanAPcount =5
539                         self.scanAPcount =0
540                         list = data.splitlines()
541                         for x in list:
542                                 xx = x.lstrip()
543                                 if xx.startswith('ESSID:') and len(xx)>8 and xx[7:-1]not in self.apList:
544                                         self.apList.append(xx[7:-1])
545                         self.apList.append('Input hidden ESSID')
546 #                       print "###### selectap : ",selectap
547                         if selectap is not None and selectap in self.apList:
548                                 wlanconfig.essid = ConfigSelection(default=selectap,choices = self.apList)
549                         elif self.ap_scan is not None and self.ap_scan.strip() == '2':
550                                 wlanconfig.essid = ConfigSelection(default='Input hidden ESSID',choices = self.apList)
551                         elif self.ssid is not None and self.ssid in self.apList:
552                                 wlanconfig.essid = ConfigSelection(default=self.ssid,choices = self.apList)
553                         else:
554                                 wlanconfig.essid = ConfigSelection(choices = self.apList)
555                         if self.ssid is not None:
556                                 wlanconfig.hiddenessid = ConfigText(default = self.ssid, visible_width = 50, fixed_size = False)
557                         else:
558                                 wlanconfig.hiddenessid = ConfigText(default = "<Input ESSID>", visible_width = 50, fixed_size = False)
559                 self.configurationmsg.close(True)
560                 self.createConfig()
561
562         def scanAPFailed(self):
563                 self.session.openWithCallback(self.keyCancel ,MessageBox, _("Scan AP Failed"), MessageBox.TYPE_ERROR,10)
564
565         def keyLeft(self):
566                 ConfigListScreen.keyLeft(self)
567                 self.newConfig()
568
569         def keyRight(self):
570                 ConfigListScreen.keyRight(self)
571                 self.newConfig()
572
573         def newConfig(self):
574                 if self["config"].getCurrent() == self.usedeviceEntry or self["config"].getCurrent() == self.encryptEntry \
575                         or self["config"].getCurrent() == self.usedhcpEntry or self["config"].getCurrent() == self.usegatewayEntry \
576                         or self["config"].getCurrent() == self.essidEntry:
577                         self.createConfig()
578
579         def saveWlanConfig(self):
580                 if self["config"].getCurrent() == self.keyEntry or self["config"].getCurrent() == self.hiddenessidEntry :
581                         self["config"].getCurrent()[1].onDeselect(self.session)
582                 if self["config"].isChanged():
583                         self.session.openWithCallback(self.checkNetworkShares, MessageBox, (_("Are you sure you want to restart your network interfaces?\n") ) )
584                 else:
585                         self.session.openWithCallback(self.checkNetworkShares, MessageBox, (_("Network configuration is not changed....\n\nAre you sure you want to restart your network interfaces?\n") ) )
586
587         def checkNetworkShares(self,ret = False):
588                 if ret == False:
589                         if self["config"].getCurrent() == self.keyEntry or self["config"].getCurrent() == self.hiddenessidEntry :
590                                 self["config"].getCurrent()[1].onSelect(self.session)
591                         return
592                 if not self.Console:
593                         self.Console = Console()
594                 cmd = "cat /proc/mounts"
595                 self.Console.ePopen(cmd, self.checkSharesFinished, self.confirmAnotherIfaces)
596
597         def checkSharesFinished(self, result, retval, extra_args):
598                 callback = extra_args
599                 print "checkMountsFinished : result : \n",result
600                 networks = ['nfs','smbfs','ncp','coda']
601                 for line in result.splitlines():
602                         split = line.strip().split(' ',3)
603                         if split[2] in networks:
604                                 self.session.open(MessageBox, ("NOT deconfiguring network interfaces :\n network shares still mounted\n"), type = MessageBox.TYPE_ERROR, timeout = 10)
605                                 callback(False)
606                                 if self["config"].getCurrent() == self.keyEntry or self["config"].getCurrent() == self.hiddenessidEntry :
607                                         self["config"].getCurrent()[1].onSelect(self.session)
608                                 return
609                 callback(True)
610
611         def confirmAnotherIfaces(self, ret = False):
612                 if ret == False:
613                         return
614                 else:
615                         num_configured_if = len(iNetwork.getConfiguredAdapters())
616                         if num_configured_if >= 1:
617                                 if num_configured_if == 1 and self.iface in iNetwork.getConfiguredAdapters():
618                                         self.writeWlanConfig(False)
619                                 else:
620                                         self.session.openWithCallback(self.writeWlanConfig, MessageBox, _("A second configured interface has been found.\n\nDo you want to disable the second network interface?"), default = True)
621                         else:
622                                 self.writeWlanConfig(False)
623
624         def writeWlanConfig(self,ret = False):
625                 if ret == True:
626                         configuredInterfaces = iNetwork.getConfiguredAdapters()
627                         for interface in configuredInterfaces:
628                                 if interface == self.iface:
629                                         continue
630                                 iNetwork.setAdapterAttribute(interface, "up", False)
631                                 iNetwork.deactivateInterface(interface)
632                 ret=self.writeWpasupplicantConf()
633                 if ret == -1:
634                         self.session.open(MessageBox, _("wpa_supplicant.conf open error."), type = MessageBox.TYPE_ERROR, timeout = 10)
635                         return
636                 elif ret == -2:
637                         self.session.open(MessageBox, _("hidden ESSID empty"), type = MessageBox.TYPE_ERROR, timeout = 10)
638                         return
639
640                 if wlanconfig.usedevice.value=="on":
641                         iNetwork.setAdapterAttribute(self.iface, "up", True)
642                         if wlanconfig.usedhcp.value =="on":
643                                 iNetwork.setAdapterAttribute(self.iface, "dhcp", True)
644                         else:
645                                 iNetwork.setAdapterAttribute(self.iface, "dhcp", False)
646                                 iNetwork.setAdapterAttribute(self.iface, "ip", wlanconfig.ip.value)
647                                 iNetwork.setAdapterAttribute(self.iface, "netmask", wlanconfig.netmask.value)
648                                 if wlanconfig.usegateway.value == "on":
649                                         iNetwork.setAdapterAttribute(self.iface, "gateway", wlanconfig.gateway.value)
650                 else:
651                         iNetwork.setAdapterAttribute(self.iface, "up", False)
652                         iNetwork.deactivateInterface(self.iface)
653                 contents = "\tpre-up wpa_supplicant -i"+self.iface+" -c/etc/wpa_supplicant.conf -B -D"+iNetwork.detectWlanModule(self.iface)+"\n"
654                 contents += "\tpost-down wpa_cli terminate\n\n"
655                 iNetwork.setAdapterAttribute(self.iface, "configStrings", contents)
656                 iNetwork.writeNetworkConfig()
657                 iNetwork.restartNetwork(self.updateCurrentInterfaces)
658                 self.configurationmsg = None
659                 self.configurationmsg = self.session.openWithCallback(self.configFinished, MessageBox, _("Please wait for activation of your network configuration..."), type = MessageBox.TYPE_INFO, enable_input = False)
660
661         def writeWpasupplicantConf(self):
662                 wpafd = open("/etc/wpa_supplicant.conf","w")
663                 if wpafd > 0:
664                         contents = "#WPA Supplicant Configuration by STB\n"
665                         contents += "ctrl_interface=/var/run/wpa_supplicant\n"
666                         contents += "eapol_version=1\n"
667                         contents += "fast_reauth=1\n"
668
669                         if wlanconfig.essid.value == 'Input hidden ESSID':
670                                 contents += "ap_scan=2\n"
671                         else :
672                                 contents += "ap_scan=1\n"
673                         contents += "network={\n"
674                         if wlanconfig.essid.value == 'Input hidden ESSID':
675                                 if len(wlanconfig.hiddenessid.value) == 0:
676                                         wpafd.close()
677                                         return -2
678                                 contents += "\tssid=\""+wlanconfig.hiddenessid.value+"\"\n"
679                         else :
680                                 contents += "\tssid=\""+wlanconfig.essid.value+"\"\n"
681                         contents += "\tscan_ssid=0\n"
682                         if wlanconfig.encrypt.value == "on":
683                                 if wlanconfig.method.value =="wep":
684                                         contents += "\tkey_mgmt=NONE\n"
685                                         contents += "\twep_key0="
686                                 elif wlanconfig.method.value == "wpa":
687                                         contents += "\tkey_mgmt=WPA-PSK\n"
688                                         contents += "\tproto=WPA\n"
689                                         contents += "\tpairwise=CCMP TKIP\n"
690                                         contents += "\tgroup=CCMP TKIP\n"
691                                         contents += "\tpsk="
692                                 elif wlanconfig.method.value == "wpa2":
693                                         contents += "\tkey_mgmt=WPA-PSK\n"
694                                         contents += "\tproto=RSN\n"
695                                         contents += "\tpairwise=CCMP TKIP\n"
696                                         contents += "\tgroup=CCMP TKIP\n"
697                                         contents += "\tpsk="
698                                 else:
699                                         contents += "\tkey_mgmt=WPA-PSK\n"
700                                         contents += "\tproto=WPA RSN\n"
701                                         contents += "\tpairwise=CCMP TKIP\n"
702                                         contents += "\tgroup=CCMP TKIP\n"
703                                         contents += "\tpsk="
704                                 if wlanconfig.keytype.value == "ascii":
705                                         contents += "\""+wlanconfig.key.value+"\"\n"
706                                 else:
707                                         contents += wlanconfig.key.value+"\n"
708                         else:
709                                 contents += "\tkey_mgmt=NONE\n"
710                         contents += "}\n"
711                         print "content = \n"+contents
712                         wpafd.write(contents)
713                         wpafd.close()
714                         return 0
715                 else :
716                         self.session.open(MessageBox, _("wpa_supplicant.conf open error."), type = MessageBox.TYPE_ERROR, timeout = 10)
717                         return -1
718         def updateCurrentInterfaces(self,ret):
719                 if ret is True:
720                         iNetwork.getInterfaces(self.configurationMsgClose)
721
722         def configurationMsgClose(self,ret):
723                 if ret is True and self.configurationmsg is not None:
724                         self.configurationmsg.close(True)
725
726         def configFinished(self,data):
727                 global selectap
728                 if data is True:
729                         self.session.openWithCallback(self.configFinishedCB, MessageBox, _("Your network configuration has been activated."), type = MessageBox.TYPE_INFO, timeout = 10)
730                         selectap = wlanconfig.essid.value
731
732         def configFinishedCB(self,data):
733                 if data is not None:
734                         if data is True:
735                                 self.close()
736         
737         def formatip(self, iplist):
738                 list = []
739                 list = iplist
740 #               print "iplist : ",iplist
741                 try:
742                         if len(iplist) == 4:
743                                 result = str(iplist[0])+"."+str(iplist[1])+"."+str(iplist[2])+"."+str(iplist[3])
744                         else:
745                                 result ="0.0.0.0"
746 #                       print "result : ",result
747                         return result
748                 except:
749                         return "[N/A]"
750                         
751         def keyCancelConfirm(self, result):
752                 if not result:
753                         return
754                 if self.oldInterfaceState is False:
755                         iNetwork.setAdapterAttribute(self.iface, "up", False)
756                         iNetwork.deactivateInterface(self.iface,self.keyCancelCB)
757                 else:
758                         self.close()
759
760         def keyCancel(self,yesno = True):
761                 if self["config"].isChanged():
762                         self.session.openWithCallback(self.keyCancelConfirm, MessageBox, _("Really close without saving settings?"))
763                 else:
764                         self.keyCancelConfirm(True)
765
766         def keyCancelCB(self,data):
767                 if data is not None:
768                         if data is True:
769                                 self.close()
770
771 #       def selectionChanged(self):
772 #               current = self["config"].getCurrent()
773 #               print current
774
775 class WlanScanAp(Screen,HelpableScreen):
776         skin = """
777         <screen name="WlanScanAp" position="209,48" size="865,623" title="Wireless Network Configuration..." flags="wfNoBorder" backgroundColor="transparent">
778                 <ePixmap pixmap="Vu_HD/Bg_EPG_view.png" zPosition="-1" position="0,0" size="865,623" alphatest="on" />
779                 <ePixmap pixmap="Vu_HD/menu/ico_title_Setup.png" position="32,41" size="40,40" alphatest="blend"  transparent="1" />
780                 <eLabel text="Wireless Network AP Scan..." position="90,50" size="600,32" font="Semiboldit;32" foregroundColor="#5d5d5d" backgroundColor="#27b5b9bd" transparent="1" />
781                 <ePixmap pixmap="Vu_HD/icons/clock.png" position="750,55" zPosition="1" size="20,20" alphatest="blend" />
782                 <widget source="global.CurrentTime" render="Label" position="770,57" zPosition="1" size="50,20" font="Regular;20" foregroundColor="#1c1c1c" backgroundColor="#27d9dee2" halign="right" transparent="1">
783                         <convert type="ClockToText">Format:%H:%M</convert>
784                 </widget>
785                 <ePixmap pixmap="Vu_HD/buttons/red.png" position="45,98" size="25,25" alphatest="blend" />
786                 <ePixmap pixmap="Vu_HD/buttons/green.png" position="240,98" size="25,25" alphatest="blend" />
787                 <ePixmap pixmap="Vu_HD/buttons/blue.png" position="630,98" size="25,25" alphatest="blend" />
788                 <widget source="key_red" render="Label" position="66,97" zPosition="1" size="150,25" font="Regular;20" halign="center" valign="center" backgroundColor="darkgrey" foregroundColor="#1c1c1c" transparent="1" />
789                 <widget source="key_green" render="Label" position="268,97" zPosition="1" size="150,25" font="Regular;20" halign="center" valign="center" backgroundColor="darkgrey" foregroundColor="#1c1c1c" transparent="1" />
790                 <widget source="key_blue" render="Label" position="665,97" zPosition="1" size="150,25" font="Regular;20" halign="center" valign="center" backgroundColor="darkgrey" foregroundColor="#1c1c1c" transparent="1" />
791                 <ePixmap pixmap="Vu_HD/border_menu.png" position="120,140" zPosition="-1" size="342,358" transparent="1" alphatest="blend" />
792                 <widget name="menulist" position="130,150" size="322,338" transparent="1" backgroundColor="#27d9dee2" zPosition="10" scrollbarMode="showOnDemand" />
793                 <widget source="Address" render="Label" position="490,220" zPosition="1" size="300,30" font="Regular;20" halign="center" valign="center" backgroundColor="#27b5b9bd" foregroundColor="#1c1c1c" transparent="1" />               
794                 <widget source="ESSID" render="Label" position="490,250" zPosition="1" size="300,30" font="Regular;20" halign="center" valign="center" backgroundColor="#27b5b9bd" foregroundColor="#1c1c1c" transparent="1" />
795                 <widget source="Protocol" render="Label" position="490,280" zPosition="1" size="300,30" font="Regular;20" halign="center" valign="center" backgroundColor="#27b5b9bd" foregroundColor="#1c1c1c" transparent="1" />      
796                 <widget source="Frequency" render="Label" position="490,310" zPosition="1" size="300,30" font="Regular;20" halign="center" valign="center" backgroundColor="#27b5b9bd" foregroundColor="#1c1c1c" transparent="1" />     
797                 <widget source="Encryption key" render="Label" position="490,340" zPosition="1" size="300,30" font="Regular;20" halign="center" valign="center" backgroundColor="#27b5b9bd" foregroundColor="#1c1c1c" transparent="1" />        
798                 <widget source="BitRate" render="Label" position="490,370" zPosition="1" size="300,60" font="Regular;20" halign="center" valign="center" backgroundColor="#27b5b9bd" foregroundColor="#1c1c1c" transparent="1" />
799         </screen>"""
800
801         def __init__(self, session, iface):
802                 Screen.__init__(self,session)
803                 HelpableScreen.__init__(self)
804                 self.session = session
805                 self.iface = iface
806                 self.wlanscanap = None
807 #               self.scanAPcount = 5
808                 self.scanAPcount = 1
809                 self.apList = {}
810                 self.SetApList = []
811
812                 self["WizardActions"] = HelpableActionMap(self, "WizardActions",
813                 {
814                         "up": (self.up, _("move up to previous entry")),
815                         "down": (self.down, _("move down to next entry")),
816                         "left": (self.left, _("move up to first entry")),
817                         "right": (self.right, _("move down to last entry")),
818                 })
819
820                 self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
821                 {
822                         "cancel": (self.close, _("exit")),
823                         "ok": (self.ok, "select AP"),
824                 })
825
826                 self["ColorActions"] = HelpableActionMap(self, "ColorActions",
827                 {
828                         "red": (self.close, _("exit")),
829                         "green": (self.ok, "select AP"),
830                         "blue": (self.startWlanConfig, "Edit Wireless settings"),
831                 })
832
833                 self["actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
834                 {
835                         "ok": self.ok,
836                         "back": self.close,
837                         "up": self.up,
838                         "down": self.down,
839                         "red": self.close,
840                         "left": self.left,
841                         "right": self.right,
842                 }, -2)
843
844                 self["menulist"] = MenuList(self.SetApList)
845                 self["key_red"] = StaticText(_("Close"))
846                 self["key_green"] = StaticText(_("Select"))
847                 self["key_blue"] = StaticText(_("EditSetting"))
848                 self["Address"] = StaticText(_("Scanning AP List.."))
849                 self["ESSID"] = StaticText(_("Wait a moment"))
850                 self["Protocol"] = StaticText(" ")
851                 self["Frequency"] = StaticText(" ")
852                 self["Encryption key"] = StaticText(" ")
853                 self["BitRate"] = StaticText(" ")
854                 self.scanAPFailedTimer = eTimer()
855                 self.scanAPFailedTimer.callback.append(self.scanAPFailed)
856                 self.scanAplistTimer = eTimer()
857                 self.scanAplistTimer.callback.append(self.scanApList)
858                 self.scanAplistTimer.start(100,True)
859                 
860         def left(self):
861                 self["menulist"].pageUp()
862                 self.displayApInfo()
863         
864         def right(self):
865                 self["menulist"].pageDown()
866                 self.displayApInfo()
867
868         def up(self):
869                 self["menulist"].up()
870                 self.displayApInfo()
871                 
872         def down(self):
873                 self["menulist"].down()
874                 self.displayApInfo()
875
876         def ok(self):
877                 global selectap
878                 selectAp=self["menulist"].getCurrent()[0]
879                 selectap = selectAp
880                 self.close()
881
882         def startWlanConfig(self):
883                 global selectap
884                 selectAp=self["menulist"].getCurrent()[0]
885                 selectap = selectAp
886                 self.session.open(WlanConfig,self.iface)
887 #               self.close()
888
889         def scanApList(self):
890         #       print "self.scanAPcount : ",self.scanAPcount
891                 self.apList = {}
892                 self.SetApList = []
893                 self.configurationmsg = self.session.open(MessageBox, _("Please wait for scanning AP..."), type = MessageBox.TYPE_INFO, enable_input = False)
894                 os_system('ifconfig '+self.iface+" up")
895                 self.wlanscanap = Console()
896                 cmd = "iwlist "+self.iface+" scan"
897                 print cmd
898                 self.wlanscanap.ePopen(cmd, self.iwlistfinnished,self.APListParse)
899
900         def iwlistfinnished(self, result, retval,extra_args):
901 #               print "iwlistfinnished"
902                 (statecallback) = extra_args
903                 if self.wlanscanap is not None:
904 #                       print "retval = ",retval
905                         if retval == 0:
906                                 self.wlanscanap = None
907                                 content = result.splitlines()
908                                 first = content[0].split()
909                                 completed = False
910                                 for x in first:
911                                         if x == 'completed':
912                                                 completed = True
913                                 if completed == True:
914                                         statecallback(result)
915                                 else:
916                                         statecallback(0)
917                         else:
918                                 statecallback(0)
919
920         def APListParse(self,data):
921                 if data == 0:
922                         if self.scanAPcount >0:
923                                 self.scanAPcount -=1
924                                 self.configurationmsg.close(True)
925                                 time.sleep(3)
926                                 self.scanAplistTimer.start(500,True)
927                                 return
928                         else:
929                                 self.configurationmsg.close(True)
930                                 self.scanAPFailedTimer.start(500,True)
931                                 return
932                 else:
933 #                       print data
934                         self.apList = {}
935 #                       self.scanAPcount =5
936                         self.scanAPcount =0
937                         list = data.splitlines()
938                         for line in list:
939 #                               print "line : ",line
940                                 if line.strip().startswith("Cell"): #  Cell 01 - Address: 00:26:66:5C:EF:24
941                                         parts = line.strip().split(" ")
942                                         current_ap_id = int(parts[1])
943                                         self.apList[current_ap_id]={}
944                                         self.apList[current_ap_id]["Address"]=parts[4]
945                                 elif line.strip().startswith("ESSID"):
946                                         self.apList[current_ap_id]["ESSID"]=line.strip()[6:].strip('"')
947                                         self.SetApList.append( (self.apList[current_ap_id]["ESSID"],current_ap_id) )
948                                 elif line.strip().startswith("Protocol"):
949                                         self.apList[current_ap_id]["Protocol"]=line.strip()[9:]
950                                 elif line.strip().startswith("Frequency"):
951                                         self.apList[current_ap_id]["Frequency"]=line.strip()[10:]
952                                 elif line.strip().startswith("Encryption key"):
953                                         self.apList[current_ap_id]["Encryption key"]=line.strip()[15:]
954                                 elif line.strip().startswith("Bit Rates"):
955                                         self.apList[current_ap_id]["BitRate"]=line.strip()[10:]
956                         print self.apList
957                         print len(self.apList)
958                 self.configurationmsg.close(True)
959                 self.displayApInfo()
960
961         def scanAPFailed(self):
962                 self.session.openWithCallback(self.ScanAPclose,MessageBox, _("Scan AP Failed"), MessageBox.TYPE_ERROR,10)
963
964         def displayApInfo(self):
965                 if len(self.apList) >0:
966                         self["menulist"].setList(self.SetApList)
967                         index = self["menulist"].getCurrent()[1]
968                         for key in ["Address", "ESSID", "Protocol", "Frequency", "Encryption key", "BitRate"]:
969                                 if self.apList[index].has_key(key):
970                                         self[key].setText((key+":  "+self.apList[index][key]))
971                                 else:
972                                         self[key].setText(("None"))
973                 else:
974                         self.session.openWithCallback(self.ScanAPclose, MessageBox, _("No AP detected."), type = MessageBox.TYPE_INFO, timeout = 10)
975
976         def ScanAPclose(self,data):
977                 self.close()
978
979 class NetworkAdapterTest(Screen):
980         def __init__(self, session,iface):
981                 Screen.__init__(self, session)
982                 self.iface = iface
983                 self.oldInterfaceState = iNetwork.getAdapterAttribute(self.iface, "up")
984                 self.setLabels()
985                 self.onClose.append(self.cleanup)
986                 self.onHide.append(self.cleanup)
987                 
988                 self["updown_actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
989                 {
990                         "ok": self.KeyOK,
991                         "blue": self.KeyOK,
992                         "up": lambda: self.updownhandler('up'),
993                         "down": lambda: self.updownhandler('down'),
994                 
995                 }, -2)
996                 
997                 self["shortcuts"] = ActionMap(["ShortcutActions","WizardActions"],
998                 {
999                         "red": self.cancel,
1000                         "back": self.cancel,
1001                 }, -2)
1002                 self["infoshortcuts"] = ActionMap(["ShortcutActions","WizardActions"],
1003                 {
1004                         "red": self.closeInfo,
1005                         "back": self.closeInfo,
1006                 }, -2)
1007                 self["shortcutsgreen"] = ActionMap(["ShortcutActions"],
1008                 {
1009                         "green": self.KeyGreen,
1010                 }, -2)
1011                 self["shortcutsgreen_restart"] = ActionMap(["ShortcutActions"],
1012                 {
1013                         "green": self.KeyGreenRestart,
1014                 }, -2)
1015                 self["shortcutsyellow"] = ActionMap(["ShortcutActions"],
1016                 {
1017                         "yellow": self.KeyYellow,
1018                 }, -2)
1019                 
1020                 self["shortcutsgreen_restart"].setEnabled(False)
1021                 self["updown_actions"].setEnabled(False)
1022                 self["infoshortcuts"].setEnabled(False)
1023                 self.onClose.append(self.delTimer)      
1024                 self.onLayoutFinish.append(self.layoutFinished)
1025                 self.steptimer = False
1026                 self.nextstep = 0
1027                 self.activebutton = 0
1028                 self.nextStepTimer = eTimer()
1029                 self.nextStepTimer.callback.append(self.nextStepTimerFire)
1030
1031         def cancel(self):
1032                 if self.oldInterfaceState is False:
1033                         iNetwork.setAdapterAttribute(self.iface, "up", self.oldInterfaceState)
1034                         iNetwork.deactivateInterface(self.iface)
1035                 self.close()
1036
1037         def closeInfo(self):
1038                 self["shortcuts"].setEnabled(True)              
1039                 self["infoshortcuts"].setEnabled(False)
1040                 self["InfoText"].hide()
1041                 self["InfoTextBorder"].hide()
1042                 self["key_red"].setText(_("Close"))
1043
1044         def delTimer(self):
1045                 del self.steptimer
1046                 del self.nextStepTimer
1047
1048         def nextStepTimerFire(self):
1049                 self.nextStepTimer.stop()
1050                 self.steptimer = False
1051                 self.runTest()
1052
1053         def updownhandler(self,direction):
1054                 if direction == 'up':
1055                         if self.activebutton >=2:
1056                                 self.activebutton -= 1
1057                         else:
1058                                 self.activebutton = 6
1059                         self.setActiveButton(self.activebutton)
1060                 if direction == 'down':
1061                         if self.activebutton <=5:
1062                                 self.activebutton += 1
1063                         else:
1064                                 self.activebutton = 1
1065                         self.setActiveButton(self.activebutton)
1066
1067         def setActiveButton(self,button):
1068                 if button == 1:
1069                         self["EditSettingsButton"].setPixmapNum(0)
1070                         self["EditSettings_Text"].setForegroundColorNum(0)
1071                         self["NetworkInfo"].setPixmapNum(0)
1072                         self["NetworkInfo_Text"].setForegroundColorNum(1)
1073                         self["AdapterInfo"].setPixmapNum(1)               # active
1074                         self["AdapterInfo_Text"].setForegroundColorNum(2) # active
1075                 if button == 2:
1076                         self["AdapterInfo_Text"].setForegroundColorNum(1)
1077                         self["AdapterInfo"].setPixmapNum(0)
1078                         self["DhcpInfo"].setPixmapNum(0)
1079                         self["DhcpInfo_Text"].setForegroundColorNum(1)
1080                         self["NetworkInfo"].setPixmapNum(1)               # active
1081                         self["NetworkInfo_Text"].setForegroundColorNum(2) # active
1082                 if button == 3:
1083                         self["NetworkInfo"].setPixmapNum(0)
1084                         self["NetworkInfo_Text"].setForegroundColorNum(1)
1085                         self["IPInfo"].setPixmapNum(0)
1086                         self["IPInfo_Text"].setForegroundColorNum(1)
1087                         self["DhcpInfo"].setPixmapNum(1)                  # active
1088                         self["DhcpInfo_Text"].setForegroundColorNum(2)    # active
1089                 if button == 4:
1090                         self["DhcpInfo"].setPixmapNum(0)
1091                         self["DhcpInfo_Text"].setForegroundColorNum(1)
1092                         self["DNSInfo"].setPixmapNum(0)
1093                         self["DNSInfo_Text"].setForegroundColorNum(1)
1094                         self["IPInfo"].setPixmapNum(1)                  # active
1095                         self["IPInfo_Text"].setForegroundColorNum(2)    # active                
1096                 if button == 5:
1097                         self["IPInfo"].setPixmapNum(0)
1098                         self["IPInfo_Text"].setForegroundColorNum(1)
1099                         self["EditSettingsButton"].setPixmapNum(0)
1100                         self["EditSettings_Text"].setForegroundColorNum(0)
1101                         self["DNSInfo"].setPixmapNum(1)                 # active
1102                         self["DNSInfo_Text"].setForegroundColorNum(2)   # active
1103                 if button == 6:
1104                         self["DNSInfo"].setPixmapNum(0)
1105                         self["DNSInfo_Text"].setForegroundColorNum(1)
1106                         self["EditSettingsButton"].setPixmapNum(1)         # active
1107                         self["EditSettings_Text"].setForegroundColorNum(2) # active
1108                         self["AdapterInfo"].setPixmapNum(0)
1109                         self["AdapterInfo_Text"].setForegroundColorNum(1)
1110                         
1111         def runTest(self):
1112                 next = self.nextstep
1113                 if next == 0:
1114                         self.doStep1()
1115                 elif next == 1:
1116                         self.doStep2()
1117                 elif next == 2:
1118                         self.doStep3()
1119                 elif next == 3:
1120                         self.doStep4()
1121                 elif next == 4:
1122                         self.doStep5()
1123                 elif next == 5:
1124                         self.doStep6()
1125                 self.nextstep += 1
1126
1127         def doStep1(self):
1128                 self.steptimer = True
1129                 self.nextStepTimer.start(3000)
1130                 self["key_yellow"].setText(_("Stop test"))
1131
1132         def doStep2(self):
1133                 self["Adapter"].setText(iNetwork.getFriendlyAdapterName(self.iface))
1134                 self["Adapter"].setForegroundColorNum(2)
1135                 self["Adaptertext"].setForegroundColorNum(1)
1136                 self["AdapterInfo_Text"].setForegroundColorNum(1)
1137                 self["AdapterInfo_OK"].show()
1138                 self.steptimer = True
1139                 self.nextStepTimer.start(3000)
1140
1141         def doStep3(self):
1142                 self["Networktext"].setForegroundColorNum(1)
1143                 self["Network"].setText(_("Please wait..."))
1144                 self.AccessPointInfo(self.iface)
1145                 self["NetworkInfo_Text"].setForegroundColorNum(1)
1146                 self.steptimer = True
1147                 self.nextStepTimer.start(3000)
1148
1149         def doStep4(self):
1150                 self["Dhcptext"].setForegroundColorNum(1)
1151                 if iNetwork.getAdapterAttribute(self.iface, 'dhcp') is True:
1152                         self["Dhcp"].setForegroundColorNum(2)
1153                         self["Dhcp"].setText(_("enabled"))
1154                         self["DhcpInfo_Check"].setPixmapNum(0)
1155                 else:
1156                         self["Dhcp"].setForegroundColorNum(1)
1157                         self["Dhcp"].setText(_("disabled"))
1158                         self["DhcpInfo_Check"].setPixmapNum(1)
1159                 self["DhcpInfo_Check"].show()
1160                 self["DhcpInfo_Text"].setForegroundColorNum(1)
1161                 self.steptimer = True
1162                 self.nextStepTimer.start(3000)
1163
1164         def doStep5(self):
1165                 self["IPtext"].setForegroundColorNum(1)
1166                 self["IP"].setText(_("Please wait..."))
1167                 iNetwork.checkNetworkState(self.NetworkStatedataAvail)
1168
1169         def doStep6(self):
1170                 self.steptimer = False
1171                 self.nextStepTimer.stop()
1172                 self["DNStext"].setForegroundColorNum(1)
1173                 self["DNS"].setText(_("Please wait..."))
1174                 iNetwork.checkDNSLookup(self.DNSLookupdataAvail)
1175
1176         def KeyGreen(self):
1177                 self["shortcutsgreen"].setEnabled(False)
1178                 self["shortcutsyellow"].setEnabled(True)
1179                 self["updown_actions"].setEnabled(False)
1180                 self["key_yellow"].setText("")
1181                 self["key_green"].setText("")
1182                 self.steptimer = True
1183                 self.nextStepTimer.start(1000)
1184
1185         def KeyGreenRestart(self):
1186                 self.nextstep = 0
1187                 self.layoutFinished()
1188                 self["Adapter"].setText((""))
1189                 self["Network"].setText((""))
1190                 self["Dhcp"].setText((""))
1191                 self["IP"].setText((""))
1192                 self["DNS"].setText((""))
1193                 self["AdapterInfo_Text"].setForegroundColorNum(0)
1194                 self["NetworkInfo_Text"].setForegroundColorNum(0)
1195                 self["DhcpInfo_Text"].setForegroundColorNum(0)
1196                 self["IPInfo_Text"].setForegroundColorNum(0)
1197                 self["DNSInfo_Text"].setForegroundColorNum(0)
1198                 self["shortcutsgreen_restart"].setEnabled(False)
1199                 self["shortcutsgreen"].setEnabled(False)
1200                 self["shortcutsyellow"].setEnabled(True)
1201                 self["updown_actions"].setEnabled(False)
1202                 self["key_yellow"].setText("")
1203                 self["key_green"].setText("")
1204                 self.steptimer = True
1205                 self.nextStepTimer.start(1000)
1206
1207         def KeyOK(self):
1208                 self["infoshortcuts"].setEnabled(True)
1209                 self["shortcuts"].setEnabled(False)
1210                 if self.activebutton == 1: # Adapter Check
1211                         self["InfoText"].setText(_("This test detects your configured Wireless LAN-Adapter."))
1212                         self["InfoTextBorder"].show()
1213                         self["InfoText"].show()
1214                         self["key_red"].setText(_("Back"))
1215                 if self.activebutton == 2: #LAN Check
1216                         self["InfoText"].setText(_("This test checks whether a network cable is connected to your Wireless LAN-Adapter."))
1217                         self["InfoTextBorder"].show()
1218                         self["InfoText"].show()
1219                         self["key_red"].setText(_("Back"))
1220                 if self.activebutton == 3: #DHCP Check
1221                         self["InfoText"].setText(_("This test checks whether your Wireless LAN Adapter is set up for automatic IP Address configuration with DHCP.\nIf you get a \"disabled\" message:\n - then your Wireless 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."))
1222                         self["InfoTextBorder"].show()
1223                         self["InfoText"].show()
1224                         self["key_red"].setText(_("Back"))
1225                 if self.activebutton == 4: # IP Check
1226                         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"))
1227                         self["InfoTextBorder"].show()
1228                         self["InfoText"].show()
1229                         self["key_red"].setText(_("Back"))
1230                 if self.activebutton == 5: # DNS Check
1231                         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"))
1232                         self["InfoTextBorder"].show()
1233                         self["InfoText"].show()
1234                         self["key_red"].setText(_("Back"))
1235                 if self.activebutton == 6: # Edit Settings
1236                         self.session.open(WlanConfig,self.iface)
1237                         self["shortcuts"].setEnabled(True)              
1238                         self["infoshortcuts"].setEnabled(False)
1239
1240         def KeyYellow(self):
1241                 self.nextstep = 0
1242                 self["shortcutsgreen_restart"].setEnabled(True)
1243                 self["shortcutsgreen"].setEnabled(False)
1244                 self["shortcutsyellow"].setEnabled(False)
1245                 self["key_green"].setText(_("Restart test"))
1246                 self["key_yellow"].setText("")
1247                 self.steptimer = False
1248                 self.nextStepTimer.stop()
1249
1250         def layoutFinished(self):
1251                 self.setTitle(_("Network test: ") + iNetwork.getFriendlyAdapterName(self.iface) )
1252                 self["shortcutsyellow"].setEnabled(False)
1253                 self["AdapterInfo_OK"].hide()
1254                 self["NetworkInfo_Check"].hide()
1255                 self["DhcpInfo_Check"].hide()
1256                 self["IPInfo_Check"].hide()
1257                 self["DNSInfo_Check"].hide()
1258                 self["EditSettings_Text"].hide()
1259                 self["EditSettingsButton"].hide()
1260                 self["InfoText"].hide()
1261                 self["InfoTextBorder"].hide()
1262                 self["key_yellow"].setText("")
1263
1264         def setLabels(self):
1265                 self["Adaptertext"] = MultiColorLabel(_("LAN Adapter"))
1266                 self["Adapter"] = MultiColorLabel()
1267                 self["AdapterInfo"] = MultiPixmap()
1268                 self["AdapterInfo_Text"] = MultiColorLabel(_("Show Info"))
1269                 self["AdapterInfo_OK"] = Pixmap()
1270                 
1271                 if self.iface in iNetwork.wlan_interfaces:
1272                         self["Networktext"] = MultiColorLabel(_("Wireless Network"))
1273                 else:
1274                         self["Networktext"] = MultiColorLabel(_("Local Network"))
1275                 
1276                 self["Network"] = MultiColorLabel()
1277                 self["NetworkInfo"] = MultiPixmap()
1278                 self["NetworkInfo_Text"] = MultiColorLabel(_("Show Info"))
1279                 self["NetworkInfo_Check"] = MultiPixmap()
1280                 
1281                 self["Dhcptext"] = MultiColorLabel(_("DHCP"))
1282                 self["Dhcp"] = MultiColorLabel()
1283                 self["DhcpInfo"] = MultiPixmap()
1284                 self["DhcpInfo_Text"] = MultiColorLabel(_("Show Info"))
1285                 self["DhcpInfo_Check"] = MultiPixmap()
1286                 
1287                 self["IPtext"] = MultiColorLabel(_("IP Address"))
1288                 self["IP"] = MultiColorLabel()
1289                 self["IPInfo"] = MultiPixmap()
1290                 self["IPInfo_Text"] = MultiColorLabel(_("Show Info"))
1291                 self["IPInfo_Check"] = MultiPixmap()
1292                 
1293                 self["DNStext"] = MultiColorLabel(_("Nameserver"))
1294                 self["DNS"] = MultiColorLabel()
1295                 self["DNSInfo"] = MultiPixmap()
1296                 self["DNSInfo_Text"] = MultiColorLabel(_("Show Info"))
1297                 self["DNSInfo_Check"] = MultiPixmap()
1298                 
1299                 self["EditSettings_Text"] = MultiColorLabel(_("Edit settings"))
1300                 self["EditSettingsButton"] = MultiPixmap()
1301                 
1302                 self["key_red"] = StaticText(_("Close"))
1303                 self["key_green"] = StaticText(_("Start test"))
1304                 self["key_yellow"] = StaticText(_("Stop test"))
1305                 
1306                 self["InfoTextBorder"] = Pixmap()
1307                 self["InfoText"] = Label()
1308
1309         def NetworkStatedataAvail(self,data):
1310                 if data <= 2:
1311                         self["IP"].setForegroundColorNum(2)
1312                         self["IP"].setText(_("confirmed"))
1313                         self["IPInfo_Check"].setPixmapNum(0)
1314                 else:
1315                         self["IP"].setForegroundColorNum(1)
1316                         self["IP"].setText(_("unconfirmed"))
1317                         self["IPInfo_Check"].setPixmapNum(1)
1318                 self["IPInfo_Check"].show()
1319                 self["IPInfo_Text"].setForegroundColorNum(1)            
1320                 self.steptimer = True
1321                 self.nextStepTimer.start(3000)          
1322                 
1323         def DNSLookupdataAvail(self,data):
1324                 if data <= 2:
1325                         self["DNS"].setForegroundColorNum(2)
1326                         self["DNS"].setText(_("confirmed"))
1327                         self["DNSInfo_Check"].setPixmapNum(0)
1328                 else:
1329                         self["DNS"].setForegroundColorNum(1)
1330                         self["DNS"].setText(_("unconfirmed"))
1331                         self["DNSInfo_Check"].setPixmapNum(1)
1332                 self["DNSInfo_Check"].show()
1333                 self["DNSInfo_Text"].setForegroundColorNum(1)
1334                 self["EditSettings_Text"].show()
1335                 self["EditSettingsButton"].setPixmapNum(1)
1336                 self["EditSettings_Text"].setForegroundColorNum(2) # active
1337                 self["EditSettingsButton"].show()
1338                 self["key_yellow"].setText("")
1339                 self["key_green"].setText(_("Restart test"))
1340                 self["shortcutsgreen"].setEnabled(False)
1341                 self["shortcutsgreen_restart"].setEnabled(True)
1342                 self["shortcutsyellow"].setEnabled(False)
1343                 self["updown_actions"].setEnabled(True)
1344                 self.activebutton = 6
1345
1346         def getInfoCB(self,status):
1347                 if status is not None:
1348                         if status.startswith("No Connection") or status.startswith("Not-Associated") or status == False:
1349                                 self["Network"].setForegroundColorNum(1)
1350                                 self["Network"].setText(_("disconnected"))
1351                                 self["NetworkInfo_Check"].setPixmapNum(1)
1352                                 self["NetworkInfo_Check"].show()
1353                         else:
1354                                 self["Network"].setForegroundColorNum(2)
1355                                 self["Network"].setText(_("connected"))
1356                                 self["NetworkInfo_Check"].setPixmapNum(0)
1357                                 self["NetworkInfo_Check"].show()
1358                                                 
1359         def cleanup(self):
1360                 iNetwork.stopLinkStateConsole()
1361                 iNetwork.stopDNSConsole()
1362
1363         def AccessPointInfo(self,iface):
1364                 cmd = "iwconfig %s"%iface
1365                 self.iwconfigConsole = Console()
1366                 self.iwconfigConsole.ePopen(cmd,self.readAP,self.getInfoCB)
1367
1368         def readAP(self,result,retval,extra_args):
1369                 (callback) = extra_args
1370                 self.apState = None
1371                 if self.iwconfigConsole is not None:
1372                         if retval == 0:
1373                                 self.iwconfigConsole = None
1374                                 for content in result.splitlines():
1375                                         if 'Access Point' in content:
1376                                                 self.apState = content.strip().split('Access Point: ')[1]
1377                                                 callback(self.apState)
1378                                                 return
1379                 callback(self.apState)
1380                 
1381 class Wlanstatus(Screen):
1382         skin = """
1383         <screen name="Wlanstatus" position="209,48" size="865,623" title="Wireless Network Configuration..." flags="wfNoBorder" backgroundColor="transparent">
1384                 <ePixmap pixmap="Vu_HD/Bg_EPG_view.png" zPosition="-1" position="0,0" size="865,623" alphatest="on" />
1385                 <ePixmap pixmap="Vu_HD/menu/ico_title_Setup.png" position="32,41" size="40,40" alphatest="blend"  transparent="1" />
1386                 <eLabel text="Wireless Network Status..." position="90,50" size="600,32" font="Semiboldit;32" foregroundColor="#5d5d5d" backgroundColor="#27b5b9bd" transparent="1" />
1387                 <ePixmap pixmap="Vu_HD/icons/clock.png" position="750,55" zPosition="1" size="20,20" alphatest="blend" />
1388                 <widget source="global.CurrentTime" render="Label" position="770,57" zPosition="1" size="50,20" font="Regular;20" foregroundColor="#1c1c1c" backgroundColor="#27d9dee2" halign="right" transparent="1">
1389                         <convert type="ClockToText">Format:%H:%M</convert>
1390                 </widget>
1391                 <ePixmap pixmap="Vu_HD/buttons/red.png" position="45,98" size="25,25" alphatest="blend" />
1392                 <widget source="key_red" render="Label" position="66,97" zPosition="1" size="150,25" font="Regular;20" halign="center" valign="center" backgroundColor="darkgrey" foregroundColor="#1c1c1c" transparent="1" />
1393                 <widget source="status" render="Label" position="110,200" size="650,400" transparent="1" font="Regular;20" foregroundColor="#1c1c1c" backgroundColor="#27d9dee2" zPosition="1" />
1394         </screen>"""
1395         def __init__(self, session,iface):
1396                 Screen.__init__(self,session)
1397                 self.session = session
1398                 self.iface = iface
1399                 self["status"] = StaticText(_("Wait a moment..."))
1400                 self["key_red"] = StaticText(_("Close"))
1401                 self["OkCancelActions"] = ActionMap(["ShortcutActions", "SetupActions" ],
1402                 {
1403                         "ok": self.ok,
1404                         "cancel": self.close,
1405                         "red": self.close,
1406                 }, -2)
1407                 self.readstatus()
1408
1409         def readstatus(self):
1410                 self.wlanstatus = Console()
1411                 cmd1 = "iwconfig "+self.iface
1412                 self.wlanstatus.ePopen(cmd1, self.iwconfigfinnished,self.statusdisplay)
1413
1414         def iwconfigfinnished(self, result, retval,extra_args):
1415                 try:
1416                         (statecallback) = extra_args
1417                         if self.wlanstatus is not None:
1418                                 if retval == 0:
1419                                         statecallback(result)
1420                                 else:
1421                                         statecallback(0)
1422                 except:
1423                         self.close()
1424
1425
1426         def statusdisplay(self,data):
1427                 if data == 0:
1428                         self["status"].setText(_("No information..."))
1429                 else:
1430                         self["status"].setText(data)
1431
1432         def ok(self):
1433                 pass
1434
1435 def openconfig(session, **kwargs):
1436         session.open(WlanSelection)
1437
1438 def selSetup(menuid, **kwargs):
1439         list=[]
1440         if menuid != "system":
1441                 return [ ]
1442         else:
1443                 for x in iNetwork.getAdapterList():
1444                         if x.startswith('eth'):
1445                                 continue
1446                         list.append(x)
1447                 if len(list):
1448                         return [(_("Wireless LAN Setup"), openconfig, "wlansetup_config", 80)]
1449                 else:
1450                         return [ ]
1451         return [ ]
1452
1453 def Plugins(**kwargs):
1454         return  PluginDescriptor(name=_("Wireless LAN Setup"), description="Wireless LAN Setup", where = PluginDescriptor.WHERE_MENU, fnc=selSetup)