1 from Screens.Wizard import wizardManager, WizardSummary
2 from Screens.WizardLanguage import WizardLanguage
3 from Screens.Rc import Rc
4 from Screens.MessageBox import MessageBox
5 from Components.Pixmap import Pixmap, MovingPixmap, MultiPixmap
6 from Components.Sources.Boolean import Boolean
7 from Components.config import config, ConfigBoolean, configfile, ConfigYesNo, NoSave, ConfigSubsection, ConfigText, getConfigListEntry, ConfigSelection, ConfigPassword
8 from Components.Network import iNetwork
9 from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_SKIN_IMAGE
10 from enigma import eTimer
12 config.misc.firstrun = ConfigBoolean(default = True)
17 list.append("WPA/WPA2")
20 weplist.append("ASCII")
23 config.plugins.wlan = ConfigSubsection()
24 config.plugins.wlan.essid = NoSave(ConfigText(default = "home", fixed_size = False))
25 config.plugins.wlan.hiddenessid = NoSave(ConfigText(default = "home", fixed_size = False))
27 config.plugins.wlan.encryption = ConfigSubsection()
28 config.plugins.wlan.encryption.enabled = NoSave(ConfigYesNo(default = False))
29 config.plugins.wlan.encryption.type = NoSave(ConfigSelection(list, default = "WPA/WPA2" ))
30 config.plugins.wlan.encryption.wepkeytype = NoSave(ConfigSelection(weplist, default = "ASCII"))
31 config.plugins.wlan.encryption.psk = NoSave(ConfigPassword(default = "mysecurewlan", fixed_size = False))
33 class NetworkWizard(WizardLanguage, Rc):
35 <screen position="0,0" size="720,576" title="Welcome..." flags="wfNoBorder" >
36 <widget name="text" position="153,40" size="340,300" font="Regular;22" />
37 <widget source="list" render="Listbox" position="53,340" size="440,180" scrollbarMode="showOnDemand" >
38 <convert type="StringList" />
40 <widget name="config" position="53,340" zPosition="1" size="440,180" transparent="1" scrollbarMode="showOnDemand" />
41 <ePixmap pixmap="skin_default/buttons/button_red.png" position="40,225" zPosition="0" size="15,16" transparent="1" alphatest="on" />
42 <widget name="languagetext" position="55,225" size="95,30" font="Regular;18" />
43 <widget name="wizard" pixmap="skin_default/wizard.png" position="40,50" zPosition="10" size="110,174" alphatest="on" />
44 <widget name="rc" pixmaps="skin_default/rc.png,skin_default/rcold.png" position="500,50" zPosition="10" size="154,500" alphatest="on" />
45 <widget name="arrowdown" pixmap="skin_default/arrowdown.png" position="-100,-100" zPosition="11" size="37,70" alphatest="on" />
46 <widget name="arrowdown2" pixmap="skin_default/arrowdown.png" position="-100,-100" zPosition="11" size="37,70" alphatest="on" />
47 <widget name="arrowup" pixmap="skin_default/arrowup.png" position="-100,-100" zPosition="11" size="37,70" alphatest="on" />
48 <widget name="arrowup2" pixmap="skin_default/arrowup.png" position="-100,-100" zPosition="11" size="37,70" alphatest="on" />
49 <widget source="VKeyIcon" render="Pixmap" pixmap="skin_default/buttons/key_text.png" position="40,260" zPosition="0" size="35,25" transparent="1" alphatest="on" >
50 <convert type="ConditionalShowHide" />
52 <widget name="HelpWindow" pixmap="skin_default/buttons/key_text.png" position="125,170" zPosition="1" size="1,1" transparent="1" alphatest="on" />
54 def __init__(self, session, interface = None):
55 self.xmlfile = resolveFilename(SCOPE_PLUGINS, "SystemPlugins/NetworkWizard/networkwizard.xml")
56 WizardLanguage.__init__(self, session, showSteps = False, showStepSlider = False)
58 self.session = session
59 self["wizard"] = Pixmap()
60 self["HelpWindow"] = Pixmap()
61 self["HelpWindow"].hide()
62 self["VKeyIcon"] = Boolean(False)
64 self.InstalledInterfaceCount = None
65 self.Adapterlist = None
66 self.InterfaceState = None
67 self.isInterfaceUp = None
68 self.WlanPluginInstalled = None
70 if interface is not None:
71 self.selectedInterface = interface
73 self.selectedInterface = None
77 self.AdapterRef = None
82 self.originalAth0State = None
83 self.originalEth0State = None
84 self.originalWlan0State = None
85 self.originalInterfaceStateChanged = False
87 self.rescanTimer = eTimer()
88 self.rescanTimer.callback.append(self.rescanTimerFired)
89 self.getInstalledInterfaceCount()
90 self.isWlanPluginInstalled()
92 def exitWizardQuestion(self, ret = False):
98 self.rescanTimer.stop()
100 self.checkOldInterfaceState()
103 def getInstalledInterfaceCount(self):
104 self.rescanTimer.stop()
105 self.Adapterlist = iNetwork.getAdapterList()
106 self.InstalledInterfaceCount = len(self.Adapterlist)
107 if self.Adapterlist is not None:
108 if self.InstalledInterfaceCount == 1 and self.selectedInterface is None:
109 self.selectedInterface = self.Adapterlist[0]
110 self.originalAth0State = iNetwork.getAdapterAttribute('ath0', 'up')
111 self.originalEth0State = iNetwork.getAdapterAttribute('eth0', 'up')
112 self.originalWlan0State = iNetwork.getAdapterAttribute('wlan0', 'up')
114 def selectInterface(self):
115 self.InterfaceState = None
116 if self.selectedInterface is None and self.InstalledInterfaceCount <= 1:
117 if self.selectedInterface == 'eth0':
118 self.NextStep = 'nwconfig'
120 self.NextStep = 'scanwlan'
121 self.checkInterface(self.selectedInterface)
122 elif self.selectedInterface is not None and self.InstalledInterfaceCount <= 1:
123 if self.selectedInterface == 'eth0':
124 self.NextStep = 'nwconfig'
126 self.NextStep = 'scanwlan'
127 self.checkInterface(self.selectedInterface)
128 elif self.selectedInterface is None and self.InstalledInterfaceCount > 1:
129 self.NextStep = 'selectinterface'
130 self.currStep = self.getStepWithID(self.NextStep)
131 self.afterAsyncCode()
132 elif self.selectedInterface is not None and self.InstalledInterfaceCount > 1:
133 if self.selectedInterface == 'eth0':
134 self.NextStep = 'nwconfig'
136 self.NextStep = 'scanwlan'
137 self.checkInterface(self.selectedInterface)
139 self.NextStep = 'selectinterface'
140 self.currStep = self.getStepWithID(self.NextStep)
141 self.afterAsyncCode()
143 def checkOldInterfaceState(self):
144 # disable up interface if it was originally down and config is unchanged.
145 if self.originalAth0State is False and self.originalInterfaceStateChanged is False:
146 if iNetwork.checkforInterface('ath0') is True:
147 iNetwork.deactivateInterface('ath0')
148 if self.originalEth0State is False and self.originalInterfaceStateChanged is False:
149 if iNetwork.checkforInterface('eth0') is True:
150 iNetwork.deactivateInterface('eth0')
151 if self.originalWlan0State is False and self.originalInterfaceStateChanged is False:
152 if iNetwork.checkforInterface('wlan0') is True:
153 iNetwork.deactivateInterface('wlan0')
155 def listInterfaces(self):
156 self.rescanTimer.stop()
157 self.checkOldInterfaceState()
158 list = [(iNetwork.getFriendlyAdapterName(x),x) for x in iNetwork.getAdapterList()]
159 list.append((_("Exit network wizard"), "end"))
162 def InterfaceSelectionMade(self, index):
163 self.selectedInterface = index
164 self.InterfaceSelect(index)
166 def InterfaceSelect(self, index):
168 self.NextStep = 'end'
169 elif index == 'eth0':
170 self.NextStep = 'nwconfig'
172 self.NextStep = 'scanwlan'
174 def InterfaceSelectionMoved(self):
175 self.InterfaceSelect(self.selection)
177 def checkInterface(self,iface):
178 self.rescanTimer.stop()
179 if self.Adapterlist is None:
180 self.Adapterlist = iNetwork.getAdapterList()
181 if self.NextStep is not 'end':
182 if len(self.Adapterlist) == 0:
183 #Reset Network to defaults if network broken
184 iNetwork.resetNetworkConfig('lan', self.resetNetworkConfigCB)
185 self.resetRef = self.session.openWithCallback(self.resetNetworkConfigFinished, MessageBox, _("Please wait while we prepare your network interfaces..."), type = MessageBox.TYPE_INFO, enable_input = False)
186 if iface in ('eth0', 'wlan0', 'ath0'):
187 if iface in iNetwork.configuredNetworkAdapters and len(iNetwork.configuredNetworkAdapters) == 1:
188 if iNetwork.getAdapterAttribute(iface, 'up') is True:
189 self.isInterfaceUp = True
191 self.isInterfaceUp = False
192 self.currStep = self.getStepWithID(self.NextStep)
193 self.afterAsyncCode()
195 self.isInterfaceUp = iNetwork.checkforInterface(iface)
196 self.currStep = self.getStepWithID(self.NextStep)
197 self.afterAsyncCode()
199 self.resetNetworkConfigFinished(False)
201 def resetNetworkConfigFinished(self,data):
203 self.currStep = self.getStepWithID(self.NextStep)
204 self.afterAsyncCode()
206 self.currStep = self.getStepWithID(self.NextStep)
207 self.afterAsyncCode()
209 def resetNetworkConfigCB(self,callback,iface):
210 if callback is not None:
212 iNetwork.getInterfaces(self.getInterfacesFinished)
214 def getInterfacesFinished(self, data):
216 if iNetwork.getAdapterAttribute(self.selectedInterface, 'up') is True:
217 self.isInterfaceUp = True
219 self.isInterfaceUp = False
220 self.resetRef.close(True)
222 print "we should never come here!"
224 def AdapterSetupEnd(self, iface):
225 self.originalInterfaceStateChanged = True
226 if iNetwork.getAdapterAttribute(iface, "dhcp") is True:
227 iNetwork.checkNetworkState(self.AdapterSetupEndFinished)
228 self.AdapterRef = self.session.openWithCallback(self.AdapterSetupEndCB, MessageBox, _("Please wait while we test your network..."), type = MessageBox.TYPE_INFO, enable_input = False)
230 self.currStep = self.getStepWithID("confdns")
231 self.afterAsyncCode()
233 def AdapterSetupEndCB(self,data):
235 if self.selectedInterface in ('wlan0', 'ath0'):
236 if self.WlanPluginInstalled == True:
237 from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus
238 iStatus.getDataForInterface(self.selectedInterface,self.checkWlanStateCB)
240 self.currStep = self.getStepWithID("checklanstatusend")
241 self.afterAsyncCode()
243 self.currStep = self.getStepWithID("checklanstatusend")
244 self.afterAsyncCode()
246 def AdapterSetupEndFinished(self,data):
248 self.InterfaceState = True
250 self.InterfaceState = False
251 self.AdapterRef.close(True)
253 def checkWlanStateCB(self,data,status):
256 if status is not None:
257 text1 = _("Your Dreambox is now ready to use.\n\nYour internet connection is working now.\n\n")
258 text2 = _('Accesspoint:') + "\t" + str(status[self.selectedInterface]["acesspoint"]) + "\n"
259 text3 = _('SSID:') + "\t" + str(status[self.selectedInterface]["essid"]) + "\n"
260 text4 = _('Link Quality:') + "\t" + str(status[self.selectedInterface]["quality"])+"%" + "\n"
261 text5 = _('Signal Strength:') + "\t" + str(status[self.selectedInterface]["signal"]) + "\n"
262 text6 = _('Bitrate:') + "\t" + str(status[self.selectedInterface]["bitrate"]) + "\n"
263 text7 = _('Encryption:') + " " + str(status[self.selectedInterface]["encryption"]) + "\n"
264 text8 = _("Please press OK to continue.")
265 infotext = text1 + text2 + text3 + text4 + text5 + text7 +"\n" + text8
266 self.currStep = self.getStepWithID("checkWlanstatusend")
268 if str(status[self.selectedInterface]["acesspoint"]) == "Not-Associated":
269 self.InterfaceState = False
270 self.afterAsyncCode()
272 def checkNetwork(self):
273 iNetwork.checkNetworkState(self.checkNetworkStateCB)
274 self.checkRef = self.session.openWithCallback(self.checkNetworkCB, MessageBox, _("Please wait while we test your network..."), type = MessageBox.TYPE_INFO, enable_input = False)
276 def checkNetworkCB(self,data):
278 if self.selectedInterface in ('wlan0', 'ath0'):
279 if self.WlanPluginInstalled == True:
280 from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus
281 iStatus.getDataForInterface(self.selectedInterface,self.checkWlanStateCB)
283 self.currStep = self.getStepWithID("checklanstatusend")
284 self.afterAsyncCode()
286 self.currStep = self.getStepWithID("checklanstatusend")
287 self.afterAsyncCode()
289 def checkNetworkStateCB(self,data):
291 self.InterfaceState = True
293 self.InterfaceState = False
294 self.checkRef.close(True)
296 def rescanTimerFired(self):
297 self.rescanTimer.stop()
300 def updateAPList(self):
301 self.oldlist = self.APList
305 currentListEntry = None
306 newList = self.listAccessPoints()
308 for oldentry in self.oldlist:
309 if oldentry not in newList:
310 newList.append(oldentry)
312 for newentry in newList:
313 if newentry[1] == "hidden...":
315 self.newAPlist.append(newentry)
317 if len(self.newAPlist):
318 if "hidden..." not in self.newAPlist:
319 self.newAPlist.append(( _("enter hidden network SSID"), "hidden..." ))
321 if (self.wizard[self.currStep].has_key("dynamiclist")):
322 currentListEntry = self["list"].getCurrent()
324 for entry in self.newAPlist:
325 if entry == currentListEntry:
328 self.wizard[self.currStep]["evaluatedlist"] = self.newAPlist
329 self['list'].setList(self.newAPlist)
330 self["list"].setIndex(newListIndex)
331 self["list"].updateList(self.newAPlist)
333 def listAccessPoints(self):
336 from Plugins.SystemPlugins.WirelessLan.Wlan import Wlan
338 self.APList.append( ( _("No networks found"),_("unavailable") ) )
342 self.w = Wlan(self.selectedInterface)
343 aps = self.w.getNetworkList()
346 self.APList.append( ( _("No networks found"),_("unavailable") ) )
350 print "[NetworkWizard.py] got Accespoints!"
356 tmplist.append( (a['bssid'], a['essid']) )
357 complist.append( (a['bssid'], a['essid']) )
359 for entry in tmplist:
361 for compentry in complist:
362 if compentry[0] == entry[0]:
363 complist.remove(compentry)
364 for entry in complist:
365 self.APList.append( (entry[1], entry[1]) )
367 if "hidden..." not in self.APList:
368 self.APList.append(( _("enter hidden network SSID"), "hidden..." ))
370 self.rescanTimer.start(3000)
373 def AccessPointsSelectionMade(self, index):
377 if (self.wizard[self.currStep].has_key("dynamiclist")):
378 currList = self['list'].list
379 for entry in currList:
380 self.WlanList.append( (entry[1], entry[0]) )
381 self.AccessPointsSelect(index)
383 def AccessPointsSelect(self, index):
384 self.NextStep = 'wlanconfig'
386 def AccessPointsSelectionMoved(self):
387 self.AccessPointsSelect(self.selection)
389 def checkWlanSelection(self):
390 self.rescanTimer.stop()
391 self.currStep = self.getStepWithID(self.NextStep)
393 def isWlanPluginInstalled(self):
395 from Plugins.SystemPlugins.WirelessLan.Wlan import Wlan
397 self.WlanPluginInstalled = False
399 self.WlanPluginInstalled = True
401 def listChoices(self):
402 self.rescanTimer.stop()
404 if self.WlanPluginInstalled == True:
405 list.append((_("Configure your wireless LAN again"), "scanwlan"))
406 list.append((_("Configure your internal LAN"), "nwconfig"))
407 list.append((_("Exit network wizard"), "end"))
410 def ChoicesSelectionMade(self, index):
411 self.ChoicesSelect(index)
413 def ChoicesSelect(self, index):
415 self.NextStep = 'end'
416 elif index == 'nwconfig':
417 self.selectedInterface = "eth0"
418 self.NextStep = 'nwconfig'
420 self.NextStep = 'scanwlan'
422 def ChoicesSelectionMoved(self):