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):
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 self.selectedInterface = None
74 self.AdapterRef = None
79 self.originalAth0State = None
80 self.originalEth0State = None
81 self.originalWlan0State = None
82 self.originalInterfaceStateChanged = False
84 self.rescanTimer = eTimer()
85 self.rescanTimer.callback.append(self.rescanTimerFired)
86 self.getInstalledInterfaceCount()
87 self.isWlanPluginInstalled()
89 def exitWizardQuestion(self, ret = False):
95 self.rescanTimer.stop()
99 def getInstalledInterfaceCount(self):
100 self.rescanTimer.stop()
101 self.Adapterlist = iNetwork.getAdapterList()
102 self.InstalledInterfaceCount = len(self.Adapterlist)
103 self.originalAth0State = iNetwork.getAdapterAttribute('ath0', 'up')
104 self.originalEth0State = iNetwork.getAdapterAttribute('eth0', 'up')
105 self.originalWlan0State = iNetwork.getAdapterAttribute('wlan0', 'up')
107 def checkOldInterfaceState(self):
108 # disable up interface if it was originally down and config is unchanged.
109 if self.originalAth0State is False and self.originalInterfaceStateChanged is False:
110 if iNetwork.checkforInterface('ath0') is True:
111 iNetwork.deactivateInterface('ath0')
112 if self.originalEth0State is False and self.originalInterfaceStateChanged is False:
113 if iNetwork.checkforInterface('eth0') is True:
114 iNetwork.deactivateInterface('eth0')
115 if self.originalWlan0State is False and self.originalInterfaceStateChanged is False:
116 if iNetwork.checkforInterface('wlan0') is True:
117 iNetwork.deactivateInterface('wlan0')
119 def listInterfaces(self):
120 self.rescanTimer.stop()
121 self.checkOldInterfaceState()
122 list = [(iNetwork.getFriendlyAdapterName(x),x) for x in iNetwork.getAdapterList()]
123 list.append((_("Exit network wizard"), "end"))
126 def InterfaceSelectionMade(self, index):
127 self.selectedInterface = index
128 self.InterfaceSelect(index)
130 def InterfaceSelect(self, index):
132 self.NextStep = 'end'
133 elif index == 'eth0':
134 self.NextStep = 'nwconfig'
136 self.NextStep = 'scanwlan'
138 def InterfaceSelectionMoved(self):
139 self.InterfaceSelect(self.selection)
141 def checkInterface(self,iface):
142 self.rescanTimer.stop()
143 if self.Adapterlist is None:
144 self.Adapterlist = iNetwork.getAdapterList()
145 if self.NextStep is not 'end':
146 if len(self.Adapterlist) == 0:
147 #Reset Network to defaults if network broken
148 iNetwork.resetNetworkConfig('lan', self.resetNetworkConfigCB)
149 self.resetRef = self.session.openWithCallback(self.resetNetworkConfigFinished, MessageBox, _("Please wait while we prepare your network interfaces..."), type = MessageBox.TYPE_INFO, enable_input = False)
150 if iface in ('eth0', 'wlan0', 'ath0'):
151 if iface in iNetwork.configuredNetworkAdapters and len(iNetwork.configuredNetworkAdapters) == 1:
152 if iNetwork.getAdapterAttribute(iface, 'up') is True:
153 self.isInterfaceUp = True
155 self.isInterfaceUp = False
156 self.currStep = self.getStepWithID(self.NextStep)
157 self.afterAsyncCode()
159 self.isInterfaceUp = iNetwork.checkforInterface(iface)
160 self.currStep = self.getStepWithID(self.NextStep)
161 self.afterAsyncCode()
163 self.resetNetworkConfigFinished(False)
165 def resetNetworkConfigFinished(self,data):
167 self.currStep = self.getStepWithID(self.NextStep)
168 self.afterAsyncCode()
170 self.currStep = self.getStepWithID(self.NextStep)
171 self.afterAsyncCode()
173 def resetNetworkConfigCB(self,callback,iface):
174 if callback is not None:
176 iNetwork.getInterfaces(self.getInterfacesFinished)
178 def getInterfacesFinished(self, data):
180 if iNetwork.getAdapterAttribute(self.selectedInterface, 'up') is True:
181 self.isInterfaceUp = True
183 self.isInterfaceUp = False
184 self.resetRef.close(True)
186 print "we should never come here!"
188 def AdapterSetupEnd(self, iface):
189 self.originalInterfaceStateChanged = True
190 if iNetwork.getAdapterAttribute(iface, "dhcp") is True:
191 iNetwork.checkNetworkState(self.AdapterSetupEndFinished)
192 self.AdapterRef = self.session.openWithCallback(self.AdapterSetupEndCB, MessageBox, _("Please wait while we test your network..."), type = MessageBox.TYPE_INFO, enable_input = False)
194 self.currStep = self.getStepWithID("confdns")
195 self.afterAsyncCode()
197 def AdapterSetupEndCB(self,data):
199 if self.selectedInterface in ('wlan0', 'ath0'):
200 if self.WlanPluginInstalled == True:
201 from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus
202 iStatus.getDataForInterface(self.selectedInterface,self.checkWlanStateCB)
204 self.currStep = self.getStepWithID("checklanstatusend")
205 self.afterAsyncCode()
207 self.currStep = self.getStepWithID("checklanstatusend")
208 self.afterAsyncCode()
210 def AdapterSetupEndFinished(self,data):
212 self.InterfaceState = True
214 self.InterfaceState = False
215 self.AdapterRef.close(True)
217 def checkWlanStateCB(self,data,status):
220 if status is not None:
221 text1 = _("Your Dreambox is now ready to use.\n\nYour internet connection is working now.\n\n")
222 text2 = _('Accesspoint:') + "\t" + status[self.selectedInterface]["acesspoint"] + "\n"
223 text3 = _('SSID:') + "\t" + status[self.selectedInterface]["essid"] + "\n"
224 text4 = _('Link Quality:') + "\t" + status[self.selectedInterface]["quality"]+"%" + "\n"
225 text5 = _('Signal Strength:') + "\t" + status[self.selectedInterface]["signal"] + "\n"
226 text6 = _('Bitrate:') + "\t" + status[self.selectedInterface]["bitrate"] + "\n"
227 text7 = _('Encryption:') + " " + status[self.selectedInterface]["encryption"] + "\n"
228 text8 = _("Please press OK to continue.")
229 infotext = text1 + text2 + text3 + text4 + text5 + text7 +"\n" + text8
230 self.currStep = self.getStepWithID("checkWlanstatusend")
232 self.afterAsyncCode()
234 def checkNetwork(self):
235 iNetwork.checkNetworkState(self.checkNetworkStateCB)
236 self.checkRef = self.session.openWithCallback(self.checkNetworkCB, MessageBox, _("Please wait while we test your network..."), type = MessageBox.TYPE_INFO, enable_input = False)
238 def checkNetworkCB(self,data):
240 if self.selectedInterface in ('wlan0', 'ath0'):
241 if self.WlanPluginInstalled == True:
242 from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus
243 iStatus.getDataForInterface(self.selectedInterface,self.checkWlanStateCB)
245 self.currStep = self.getStepWithID("checklanstatusend")
246 self.afterAsyncCode()
248 self.currStep = self.getStepWithID("checklanstatusend")
249 self.afterAsyncCode()
251 def checkNetworkStateCB(self,data):
253 self.InterfaceState = True
255 self.InterfaceState = False
256 self.checkRef.close(True)
258 def rescanTimerFired(self):
259 self.rescanTimer.stop()
262 def updateAPList(self):
263 self.oldlist = self.APList
267 currentListEntry = None
268 newList = self.listAccessPoints()
270 for oldentry in self.oldlist:
271 if oldentry not in newList:
272 newList.append(oldentry)
274 for newentry in newList:
275 if newentry[1] == "hidden...":
277 self.newAPlist.append(newentry)
279 if len(self.newAPlist):
280 if "hidden..." not in self.newAPlist:
281 self.newAPlist.append(( _("enter hidden network SSID"), "hidden..." ))
283 if (self.wizard[self.currStep].has_key("dynamiclist")):
284 currentListEntry = self["list"].getCurrent()
286 for entry in self.newAPlist:
287 if entry == currentListEntry:
290 self.wizard[self.currStep]["evaluatedlist"] = self.newAPlist
291 self['list'].setList(self.newAPlist)
292 self["list"].setIndex(newListIndex)
293 self["list"].updateList(self.newAPlist)
295 def listAccessPoints(self):
298 from Plugins.SystemPlugins.WirelessLan.Wlan import Wlan
300 self.APList.append( ( _("No networks found"),_("unavailable") ) )
303 self.w = Wlan(self.selectedInterface)
304 aps = self.w.getNetworkList()
306 print "[NetworkWizard.py] got Accespoints!"
312 tmplist.append( (a['bssid'], a['essid']) )
313 complist.append( (a['bssid'], a['essid']) )
315 for entry in tmplist:
317 for compentry in complist:
318 if compentry[0] == entry[0]:
319 complist.remove(compentry)
320 for entry in complist:
321 self.APList.append( (entry[1], entry[1]) )
323 if "hidden..." not in self.APList:
324 self.APList.append(( _("enter hidden network SSID"), "hidden..." ))
326 self.rescanTimer.start(3000)
329 def AccessPointsSelectionMade(self, index):
333 if (self.wizard[self.currStep].has_key("dynamiclist")):
334 currList = self['list'].list
335 for entry in currList:
336 self.WlanList.append( (entry[1], entry[0]) )
337 self.AccessPointsSelect(index)
339 def AccessPointsSelect(self, index):
340 self.NextStep = 'wlanconfig'
342 def AccessPointsSelectionMoved(self):
343 self.AccessPointsSelect(self.selection)
345 def checkWlanSelection(self):
346 self.rescanTimer.stop()
347 self.currStep = self.getStepWithID(self.NextStep)
349 def isWlanPluginInstalled(self):
351 from Plugins.SystemPlugins.WirelessLan.Wlan import Wlan
353 self.WlanPluginInstalled = False
355 self.WlanPluginInstalled = True