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):
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 = None
71 self.selectedInterface = None
75 self.AdapterRef = None
80 self.originalAth0State = None
81 self.originalEth0State = None
82 self.originalWlan0State = None
83 self.originalInterfaceStateChanged = False
85 self.rescanTimer = eTimer()
86 self.rescanTimer.callback.append(self.rescanTimerFired)
87 self.getInstalledInterfaceCount()
88 self.isWlanPluginInstalled()
90 def exitWizardQuestion(self, ret = False):
96 self.rescanTimer.stop()
100 def getInstalledInterfaceCount(self):
101 self.rescanTimer.stop()
102 self.Adapterlist = iNetwork.getAdapterList()
103 self.InstalledInterfaceCount = len(self.Adapterlist)
104 self.originalAth0State = iNetwork.getAdapterAttribute('ath0', 'up')
105 self.originalEth0State = iNetwork.getAdapterAttribute('eth0', 'up')
106 self.originalWlan0State = iNetwork.getAdapterAttribute('wlan0', 'up')
108 def checkOldInterfaceState(self):
109 # disable up interface if it was originally down and config is unchanged.
110 if self.originalAth0State is False and self.originalInterfaceStateChanged is False:
111 if iNetwork.checkforInterface('ath0') is True:
112 iNetwork.deactivateInterface('ath0')
113 if self.originalEth0State is False and self.originalInterfaceStateChanged is False:
114 if iNetwork.checkforInterface('eth0') is True:
115 iNetwork.deactivateInterface('eth0')
116 if self.originalWlan0State is False and self.originalInterfaceStateChanged is False:
117 if iNetwork.checkforInterface('wlan0') is True:
118 iNetwork.deactivateInterface('wlan0')
120 def listInterfaces(self):
121 self.rescanTimer.stop()
122 self.checkOldInterfaceState()
123 list = [(iNetwork.getFriendlyAdapterName(x),x) for x in iNetwork.getAdapterList()]
124 list.append((_("Exit network wizard"), "end"))
127 def InterfaceSelectionMade(self, index):
128 self.selectedInterface = index
129 self.InterfaceSelect(index)
131 def InterfaceSelect(self, index):
133 self.NextStep = 'end'
134 elif index == 'eth0':
135 self.NextStep = 'nwconfig'
137 self.NextStep = 'scanwlan'
139 def InterfaceSelectionMoved(self):
140 self.InterfaceSelect(self.selection)
142 def checkInterface(self,iface):
143 self.rescanTimer.stop()
144 if self.Adapterlist is None:
145 self.Adapterlist = iNetwork.getAdapterList()
146 if self.NextStep is not 'end':
147 if len(self.Adapterlist) == 0:
148 #Reset Network to defaults if network broken
149 iNetwork.resetNetworkConfig('lan', self.resetNetworkConfigCB)
150 self.resetRef = self.session.openWithCallback(self.resetNetworkConfigFinished, MessageBox, _("Please wait while we prepare your network interfaces..."), type = MessageBox.TYPE_INFO, enable_input = False)
151 if iface in ('eth0', 'wlan0', 'ath0'):
152 if iface in iNetwork.configuredNetworkAdapters and len(iNetwork.configuredNetworkAdapters) == 1:
153 if iNetwork.getAdapterAttribute(iface, 'up') is True:
154 self.isInterfaceUp = True
156 self.isInterfaceUp = False
157 self.currStep = self.getStepWithID(self.NextStep)
158 self.afterAsyncCode()
160 self.isInterfaceUp = iNetwork.checkforInterface(iface)
161 self.currStep = self.getStepWithID(self.NextStep)
162 self.afterAsyncCode()
164 self.resetNetworkConfigFinished(False)
166 def resetNetworkConfigFinished(self,data):
168 self.currStep = self.getStepWithID(self.NextStep)
169 self.afterAsyncCode()
171 self.currStep = self.getStepWithID(self.NextStep)
172 self.afterAsyncCode()
174 def resetNetworkConfigCB(self,callback,iface):
175 if callback is not None:
177 iNetwork.getInterfaces(self.getInterfacesFinished)
179 def getInterfacesFinished(self, data):
181 if iNetwork.getAdapterAttribute(self.selectedInterface, 'up') is True:
182 self.isInterfaceUp = True
184 self.isInterfaceUp = False
185 self.resetRef.close(True)
187 print "we should never come here!"
189 def AdapterSetupEnd(self, iface):
190 self.originalInterfaceStateChanged = True
191 if iNetwork.getAdapterAttribute(iface, "dhcp") is True:
192 iNetwork.checkNetworkState(self.AdapterSetupEndFinished)
193 self.AdapterRef = self.session.openWithCallback(self.AdapterSetupEndCB, MessageBox, _("Please wait while we test your network..."), type = MessageBox.TYPE_INFO, enable_input = False)
195 self.currStep = self.getStepWithID("confdns")
196 self.afterAsyncCode()
198 def AdapterSetupEndCB(self,data):
200 if self.selectedInterface in ('wlan0', 'ath0'):
201 if self.WlanPluginInstalled == True:
202 from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus
203 iStatus.getDataForInterface(self.selectedInterface,self.checkWlanStateCB)
205 self.currStep = self.getStepWithID("checklanstatusend")
206 self.afterAsyncCode()
208 self.currStep = self.getStepWithID("checklanstatusend")
209 self.afterAsyncCode()
211 def AdapterSetupEndFinished(self,data):
213 self.InterfaceState = True
215 self.InterfaceState = False
216 self.AdapterRef.close(True)
218 def checkWlanStateCB(self,data,status):
221 if status is not None:
222 text1 = _("Your Dreambox is now ready to use.\n\nYour internet connection is working now.\n\n")
223 text2 = _('Accesspoint:') + "\t" + status[self.selectedInterface]["acesspoint"] + "\n"
224 text3 = _('SSID:') + "\t" + status[self.selectedInterface]["essid"] + "\n"
225 text4 = _('Link Quality:') + "\t" + status[self.selectedInterface]["quality"]+"%" + "\n"
226 text5 = _('Signal Strength:') + "\t" + status[self.selectedInterface]["signal"] + "\n"
227 text6 = _('Bitrate:') + "\t" + status[self.selectedInterface]["bitrate"] + "\n"
228 text7 = _('Encryption:') + " " + status[self.selectedInterface]["encryption"] + "\n"
229 text8 = _("Please press OK to continue.")
230 infotext = text1 + text2 + text3 + text4 + text5 + text7 +"\n" + text8
231 self.currStep = self.getStepWithID("checkWlanstatusend")
233 self.afterAsyncCode()
235 def checkNetwork(self):
236 iNetwork.checkNetworkState(self.checkNetworkStateCB)
237 self.checkRef = self.session.openWithCallback(self.checkNetworkCB, MessageBox, _("Please wait while we test your network..."), type = MessageBox.TYPE_INFO, enable_input = False)
239 def checkNetworkCB(self,data):
241 if self.selectedInterface in ('wlan0', 'ath0'):
242 if self.WlanPluginInstalled == True:
243 from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus
244 iStatus.getDataForInterface(self.selectedInterface,self.checkWlanStateCB)
246 self.currStep = self.getStepWithID("checklanstatusend")
247 self.afterAsyncCode()
249 self.currStep = self.getStepWithID("checklanstatusend")
250 self.afterAsyncCode()
252 def checkNetworkStateCB(self,data):
254 self.InterfaceState = True
256 self.InterfaceState = False
257 self.checkRef.close(True)
259 def rescanTimerFired(self):
260 self.rescanTimer.stop()
263 def updateAPList(self):
264 self.oldlist = self.APList
268 currentListEntry = None
269 newList = self.listAccessPoints()
271 for oldentry in self.oldlist:
272 if oldentry not in newList:
273 newList.append(oldentry)
275 for newentry in newList:
276 if newentry[1] == "hidden...":
278 self.newAPlist.append(newentry)
280 if len(self.newAPlist):
281 if "hidden..." not in self.newAPlist:
282 self.newAPlist.append(( _("enter hidden network SSID"), "hidden..." ))
284 if (self.wizard[self.currStep].has_key("dynamiclist")):
285 currentListEntry = self["list"].getCurrent()
287 for entry in self.newAPlist:
288 if entry == currentListEntry:
291 self.wizard[self.currStep]["evaluatedlist"] = self.newAPlist
292 self['list'].setList(self.newAPlist)
293 self["list"].setIndex(newListIndex)
294 self["list"].updateList(self.newAPlist)
296 def listAccessPoints(self):
299 from Plugins.SystemPlugins.WirelessLan.Wlan import Wlan
301 self.APList.append( ( _("No networks found"),_("unavailable") ) )
304 self.w = Wlan(self.selectedInterface)
305 aps = self.w.getNetworkList()
307 print "[NetworkWizard.py] got Accespoints!"
313 tmplist.append( (a['bssid'], a['essid']) )
314 complist.append( (a['bssid'], a['essid']) )
316 for entry in tmplist:
318 for compentry in complist:
319 if compentry[0] == entry[0]:
320 complist.remove(compentry)
321 for entry in complist:
322 self.APList.append( (entry[1], entry[1]) )
324 if "hidden..." not in self.APList:
325 self.APList.append(( _("enter hidden network SSID"), "hidden..." ))
327 self.rescanTimer.start(3000)
330 def AccessPointsSelectionMade(self, index):
334 if (self.wizard[self.currStep].has_key("dynamiclist")):
335 currList = self['list'].list
336 for entry in currList:
337 self.WlanList.append( (entry[1], entry[0]) )
338 self.AccessPointsSelect(index)
340 def AccessPointsSelect(self, index):
341 self.NextStep = 'wlanconfig'
343 def AccessPointsSelectionMoved(self):
344 self.AccessPointsSelect(self.selection)
346 def checkWlanSelection(self):
347 self.rescanTimer.stop()
348 self.currStep = self.getStepWithID(self.NextStep)
350 def isWlanPluginInstalled(self):
352 from Plugins.SystemPlugins.WirelessLan.Wlan import Wlan
354 self.WlanPluginInstalled = False
356 self.WlanPluginInstalled = True