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
13 config.misc.firstrun = ConfigBoolean(default = True)
18 list.append("WPA/WPA2")
21 weplist.append("ASCII")
24 config.plugins.wlan = ConfigSubsection()
25 config.plugins.wlan.essid = NoSave(ConfigText(default = "home", fixed_size = False))
26 config.plugins.wlan.hiddenessid = NoSave(ConfigText(default = "home", fixed_size = False))
28 config.plugins.wlan.encryption = ConfigSubsection()
29 config.plugins.wlan.encryption.enabled = NoSave(ConfigYesNo(default = False))
30 config.plugins.wlan.encryption.type = NoSave(ConfigSelection(list, default = "WPA/WPA2" ))
31 config.plugins.wlan.encryption.wepkeytype = NoSave(ConfigSelection(weplist, default = "ASCII"))
32 config.plugins.wlan.encryption.psk = NoSave(ConfigPassword(default = "mysecurewlan", fixed_size = False))
34 class NetworkWizard(WizardLanguage, Rc):
36 <screen position="0,0" size="720,576" title="Welcome..." flags="wfNoBorder" >
37 <widget name="text" position="153,40" size="340,300" font="Regular;22" />
38 <widget source="list" render="Listbox" position="53,340" size="440,180" scrollbarMode="showOnDemand" >
39 <convert type="StringList" />
41 <widget name="config" position="53,340" zPosition="1" size="440,180" transparent="1" scrollbarMode="showOnDemand" />
42 <ePixmap pixmap="skin_default/buttons/button_red.png" position="40,225" zPosition="0" size="15,16" transparent="1" alphatest="on" />
43 <widget name="languagetext" position="55,225" size="95,30" font="Regular;18" />
44 <widget name="wizard" pixmap="skin_default/wizard.png" position="40,50" zPosition="10" size="110,174" alphatest="on" />
45 <widget name="rc" pixmaps="skin_default/rc.png,skin_default/rcold.png" position="500,50" zPosition="10" size="154,500" alphatest="on" />
46 <widget name="arrowdown" pixmap="skin_default/arrowdown.png" position="-100,-100" zPosition="11" size="37,70" alphatest="on" />
47 <widget name="arrowdown2" pixmap="skin_default/arrowdown.png" position="-100,-100" zPosition="11" size="37,70" alphatest="on" />
48 <widget name="arrowup" pixmap="skin_default/arrowup.png" position="-100,-100" zPosition="11" size="37,70" alphatest="on" />
49 <widget name="arrowup2" pixmap="skin_default/arrowup.png" position="-100,-100" zPosition="11" size="37,70" alphatest="on" />
50 <widget source="VKeyIcon" render="Pixmap" pixmap="skin_default/buttons/key_text.png" position="40,260" zPosition="0" size="35,25" transparent="1" alphatest="on" >
51 <convert type="ConditionalShowHide" />
53 <widget name="HelpWindow" pixmap="skin_default/buttons/key_text.png" position="125,170" zPosition="1" size="1,1" transparent="1" alphatest="on" />
55 def __init__(self, session, interface = None):
56 self.xmlfile = resolveFilename(SCOPE_PLUGINS, "SystemPlugins/NetworkWizard/networkwizard.xml")
57 WizardLanguage.__init__(self, session, showSteps = False, showStepSlider = False)
59 self.session = session
60 self["wizard"] = Pixmap()
61 self["HelpWindow"] = Pixmap()
62 self["HelpWindow"].hide()
63 self["VKeyIcon"] = Boolean(False)
65 self.InstalledInterfaceCount = None
66 self.Adapterlist = None
67 self.InterfaceState = None
68 self.isInterfaceUp = None
69 self.WlanPluginInstalled = False
72 if interface is not None:
73 self.selectedInterface = interface
75 self.selectedInterface = None
79 self.AdapterRef = None
85 self.originalInterfaceState = {}
86 self.originalInterfaceStateChanged = False
88 self.rescanTimer = eTimer()
89 self.rescanTimer.callback.append(self.rescanTimerFired)
90 self.getInstalledInterfaceCount()
91 self.isWlanPluginInstalled()
93 def exitWizardQuestion(self, ret = False):
101 self.checkOldInterfaceState()
105 self.rescanTimer.stop()
106 if self.w is not None:
107 from Plugins.SystemPlugins.WirelessLan.Wlan import iWlan
108 iWlan.stopGetNetworkList()
111 def getInstalledInterfaceCount(self):
112 self.originalInterfaceState = {}
114 self.Adapterlist = iNetwork.getAdapterList()
115 self.InstalledInterfaceCount = len(self.Adapterlist)
116 if self.Adapterlist is not None:
117 if self.InstalledInterfaceCount == 1 and self.selectedInterface is None:
118 self.selectedInterface = self.Adapterlist[0]
119 for interface in iNetwork.getAdapterList():
120 self.originalInterfaceState[interface] = {}
121 self.originalInterfaceState[interface]["up"] = iNetwork.getAdapterAttribute(interface, 'up')
123 def selectInterface(self):
124 self.InterfaceState = None
125 if self.selectedInterface is None:
126 if self.InstalledInterfaceCount <= 1:
127 if not iNetwork.isWirelessInterface(self.selectedInterface):
128 self.NextStep = 'nwconfig'
130 self.NextStep = 'scanwlan'
131 self.checkInterface(self.selectedInterface)
133 self.NextStep = 'selectinterface'
134 self.currStep = self.getStepWithID(self.NextStep)
135 self.afterAsyncCode()
137 if not iNetwork.isWirelessInterface(self.selectedInterface):
138 self.NextStep = 'nwconfig'
140 self.NextStep = 'scanwlan'
141 self.checkInterface(self.selectedInterface)
143 def checkOldInterfaceState(self):
144 # disable up interface if it was originally down and config is unchanged.
145 if self.originalInterfaceStateChanged is False:
146 for interface in self.originalInterfaceState.keys():
147 if self.originalInterfaceState[interface]["up"] is False:
148 if iNetwork.checkforInterface(interface) is True:
149 system("ifconfig " + interface + " down")
151 def listInterfaces(self):
153 self.checkOldInterfaceState()
154 list = [(iNetwork.getFriendlyAdapterName(x),x) for x in iNetwork.getAdapterList()]
155 list.append((_("Exit network wizard"), "end"))
158 def InterfaceSelectionMade(self, index):
159 self.selectedInterface = index
160 self.InterfaceSelect(index)
162 def InterfaceSelect(self, index):
164 self.NextStep = 'end'
165 elif index == 'eth0':
166 self.NextStep = 'nwconfig'
168 self.NextStep = 'scanwlan'
170 def InterfaceSelectionMoved(self):
171 self.InterfaceSelect(self.selection)
173 def checkInterface(self,iface):
175 if self.Adapterlist is None:
176 self.Adapterlist = iNetwork.getAdapterList()
177 if self.NextStep is not 'end':
178 if len(self.Adapterlist) == 0:
179 #Reset Network to defaults if network broken
180 iNetwork.resetNetworkConfig('lan', self.resetNetworkConfigCB)
181 self.resetRef = self.session.openWithCallback(self.resetNetworkConfigFinished, MessageBox, _("Please wait while we prepare your network interfaces..."), type = MessageBox.TYPE_INFO, enable_input = False)
182 if iface in iNetwork.getInstalledAdapters():
183 if iface in iNetwork.configuredNetworkAdapters and len(iNetwork.configuredNetworkAdapters) == 1:
184 if iNetwork.getAdapterAttribute(iface, 'up') is True:
185 self.isInterfaceUp = True
187 self.isInterfaceUp = False
188 self.currStep = self.getStepWithID(self.NextStep)
189 self.afterAsyncCode()
191 self.isInterfaceUp = iNetwork.checkforInterface(iface)
192 self.currStep = self.getStepWithID(self.NextStep)
193 self.afterAsyncCode()
195 self.resetNetworkConfigFinished(False)
197 def resetNetworkConfigFinished(self,data):
199 self.currStep = self.getStepWithID(self.NextStep)
200 self.afterAsyncCode()
202 self.currStep = self.getStepWithID(self.NextStep)
203 self.afterAsyncCode()
205 def resetNetworkConfigCB(self,callback,iface):
206 if callback is not None:
208 iNetwork.getInterfaces(self.getInterfacesFinished)
210 def getInterfacesFinished(self, data):
212 if iNetwork.getAdapterAttribute(self.selectedInterface, 'up') is True:
213 self.isInterfaceUp = True
215 self.isInterfaceUp = False
216 self.resetRef.close(True)
218 print "we should never come here!"
220 def AdapterSetupEnd(self, iface):
221 self.originalInterfaceStateChanged = True
222 if iNetwork.getAdapterAttribute(iface, "dhcp") is True:
223 iNetwork.checkNetworkState(self.AdapterSetupEndFinished)
224 self.AdapterRef = self.session.openWithCallback(self.AdapterSetupEndCB, MessageBox, _("Please wait while we test your network..."), type = MessageBox.TYPE_INFO, enable_input = False)
226 self.currStep = self.getStepWithID("confdns")
227 self.afterAsyncCode()
229 def AdapterSetupEndCB(self,data):
231 if iNetwork.isWirelessInterface(self.selectedInterface):
232 if self.WlanPluginInstalled == True:
233 from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus
234 iStatus.getDataForInterface(self.selectedInterface,self.checkWlanStateCB)
236 self.currStep = self.getStepWithID("checklanstatusend")
237 self.afterAsyncCode()
239 self.currStep = self.getStepWithID("checklanstatusend")
240 self.afterAsyncCode()
242 def AdapterSetupEndFinished(self,data):
244 self.InterfaceState = True
246 self.InterfaceState = False
247 self.AdapterRef.close(True)
249 def checkWlanStateCB(self,data,status):
252 if status is not None:
253 text1 = _("Your Dreambox is now ready to use.\n\nYour internet connection is working now.\n\n")
254 text2 = _('Accesspoint:') + "\t" + str(status[self.selectedInterface]["acesspoint"]) + "\n"
255 text3 = _('SSID:') + "\t" + str(status[self.selectedInterface]["essid"]) + "\n"
256 text4 = _('Link Quality:') + "\t" + str(status[self.selectedInterface]["quality"])+ "\n"
257 text5 = _('Signal Strength:') + "\t" + str(status[self.selectedInterface]["signal"]) + "\n"
258 text6 = _('Bitrate:') + "\t" + str(status[self.selectedInterface]["bitrate"]) + "\n"
259 text7 = _('Encryption:') + " " + str(status[self.selectedInterface]["encryption"]) + "\n"
260 text8 = _("Please press OK to continue.")
261 infotext = text1 + text2 + text3 + text4 + text5 + text7 +"\n" + text8
262 self.currStep = self.getStepWithID("checkWlanstatusend")
264 if str(status[self.selectedInterface]["acesspoint"]) == "Not-Associated":
265 self.InterfaceState = False
266 self.afterAsyncCode()
268 def checkNetwork(self):
269 iNetwork.checkNetworkState(self.checkNetworkStateCB)
270 self.checkRef = self.session.openWithCallback(self.checkNetworkCB, MessageBox, _("Please wait while we test your network..."), type = MessageBox.TYPE_INFO, enable_input = False)
272 def checkNetworkCB(self,data):
274 if iNetwork.isWirelessInterface(self.selectedInterface):
275 if self.WlanPluginInstalled == True:
276 from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus
277 iStatus.getDataForInterface(self.selectedInterface,self.checkWlanStateCB)
279 self.currStep = self.getStepWithID("checklanstatusend")
280 self.afterAsyncCode()
282 self.currStep = self.getStepWithID("checklanstatusend")
283 self.afterAsyncCode()
285 def checkNetworkStateCB(self,data):
287 self.InterfaceState = True
289 self.InterfaceState = False
290 self.checkRef.close(True)
292 def rescanTimerFired(self):
293 self.rescanTimer.stop()
296 def updateAPList(self):
297 self.oldlist = self.APList
301 currentListEntry = None
302 newList = self.listAccessPoints()
304 for oldentry in self.oldlist:
305 if oldentry not in newList:
306 newList.append(oldentry)
308 for newentry in newList:
309 if newentry[1] == "hidden...":
311 self.newAPlist.append(newentry)
313 if len(self.newAPlist):
314 if "hidden..." not in self.newAPlist:
315 self.newAPlist.append(( _("enter hidden network SSID"), "hidden..." ))
317 if (self.wizard[self.currStep].has_key("dynamiclist")):
318 currentListEntry = self["list"].getCurrent()
320 for entry in self.newAPlist:
321 if entry == currentListEntry:
324 self.wizard[self.currStep]["evaluatedlist"] = self.newAPlist
325 self['list'].setList(self.newAPlist)
326 self["list"].setIndex(newListIndex)
327 self["list"].updateList(self.newAPlist)
329 def listAccessPoints(self):
331 if self.WlanPluginInstalled is False:
332 self.APList.append( ( _("No networks found"),_("unavailable") ) )
336 from Plugins.SystemPlugins.WirelessLan.Wlan import iWlan
337 iWlan.setInterface(self.selectedInterface)
338 self.w = iWlan.getInterface()
339 aps = iWlan.getNetworkList()
342 self.APList.append( ( _("No networks found"),_("unavailable") ) )
346 print "[NetworkWizard.py] got Accespoints!"
352 tmplist.append( (a['bssid'], a['essid']) )
353 complist.append( (a['bssid'], a['essid']) )
355 for entry in tmplist:
357 for compentry in complist:
358 if compentry[0] == entry[0]:
359 complist.remove(compentry)
360 for entry in complist:
361 self.APList.append( (entry[1], entry[1]) )
363 if "hidden..." not in self.APList:
364 self.APList.append(( _("enter hidden network SSID"), "hidden..." ))
366 self.rescanTimer.start(5000)
369 def AccessPointsSelectionMade(self, index):
373 if (self.wizard[self.currStep].has_key("dynamiclist")):
374 currList = self['list'].list
375 for entry in currList:
376 self.WlanList.append( (entry[1], entry[0]) )
377 self.AccessPointsSelect(index)
379 def AccessPointsSelect(self, index):
380 self.NextStep = 'wlanconfig'
382 def AccessPointsSelectionMoved(self):
383 self.AccessPointsSelect(self.selection)
385 def checkWlanSelection(self):
387 self.currStep = self.getStepWithID(self.NextStep)
389 def isWlanPluginInstalled(self):
391 from Plugins.SystemPlugins.WirelessLan.Wlan import iWlan
393 self.WlanPluginInstalled = False
395 self.WlanPluginInstalled = True
397 def listChoices(self):
400 if self.WlanPluginInstalled == True:
401 list.append((_("Configure your wireless LAN again"), "scanwlan"))
402 list.append((_("Configure your internal LAN"), "nwconfig"))
403 list.append((_("Exit network wizard"), "end"))
406 def ChoicesSelectionMade(self, index):
407 self.ChoicesSelect(index)
409 def ChoicesSelect(self, index):
411 self.NextStep = 'end'
412 elif index == 'nwconfig':
413 self.selectedInterface = "eth0"
414 self.NextStep = 'nwconfig'
416 self.NextStep = 'scanwlan'
418 def ChoicesSelectionMoved(self):