Enigma2-{Network,NetworkWizard,WirelessLan}: more work on wireless lan / networking...
[enigma2.git] / lib / python / Plugins / SystemPlugins / NetworkWizard / NetworkWizard.py
index e99309a90d45c0f8ea3c1266485b257a6b4718b0..cb954bb23b7bfdd00e8fec6efce8cb91260ee572 100755 (executable)
@@ -4,33 +4,11 @@ from Screens.Rc import Rc
 from Screens.MessageBox import MessageBox
 from Components.Pixmap import Pixmap, MovingPixmap, MultiPixmap
 from Components.Sources.Boolean import Boolean
 from Screens.MessageBox import MessageBox
 from Components.Pixmap import Pixmap, MovingPixmap, MultiPixmap
 from Components.Sources.Boolean import Boolean
-from Components.config import config, ConfigBoolean, configfile, ConfigYesNo, NoSave, ConfigSubsection, ConfigText, getConfigListEntry, ConfigSelection, ConfigPassword
 from Components.Network import iNetwork
 from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_SKIN_IMAGE
 from enigma import eTimer
 from os import system
 
 from Components.Network import iNetwork
 from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_SKIN_IMAGE
 from enigma import eTimer
 from os import system
 
-config.misc.firstrun = ConfigBoolean(default = True)
-list = []
-list.append("WEP")
-list.append("WPA")
-list.append("WPA2")
-list.append("WPA/WPA2")
-
-weplist = []
-weplist.append("ASCII")
-weplist.append("HEX")
-
-config.plugins.wlan = ConfigSubsection()
-config.plugins.wlan.essid = NoSave(ConfigText(default = "home", fixed_size = False))
-config.plugins.wlan.hiddenessid = NoSave(ConfigText(default = "home", fixed_size = False))
-
-config.plugins.wlan.encryption = ConfigSubsection()
-config.plugins.wlan.encryption.enabled = NoSave(ConfigYesNo(default = False))
-config.plugins.wlan.encryption.type = NoSave(ConfigSelection(list, default = "WPA/WPA2" ))
-config.plugins.wlan.encryption.wepkeytype = NoSave(ConfigSelection(weplist, default = "ASCII"))
-config.plugins.wlan.encryption.psk = NoSave(ConfigPassword(default = "mysecurewlan", fixed_size = False))
-
 class NetworkWizard(WizardLanguage, Rc):
        skin = """
                <screen position="0,0" size="720,576" title="Welcome..." flags="wfNoBorder" >
 class NetworkWizard(WizardLanguage, Rc):
        skin = """
                <screen position="0,0" size="720,576" title="Welcome..." flags="wfNoBorder" >
@@ -79,7 +57,6 @@ class NetworkWizard(WizardLanguage, Rc):
                self.AdapterRef = None
                self.APList = None
                self.newAPlist = None
                self.AdapterRef = None
                self.APList = None
                self.newAPlist = None
-               self.WlanList = None
                self.oldlist = None
                
                self.originalInterfaceState = {}
                self.oldlist = None
                
                self.originalInterfaceState = {}
@@ -101,6 +78,11 @@ class NetworkWizard(WizardLanguage, Rc):
                self.checkOldInterfaceState()
                pass
 
                self.checkOldInterfaceState()
                pass
 
+       def back(self):
+               self.stopScan()
+               self.ap = None
+               WizardLanguage.back(self)
+               
        def stopScan(self):
                self.rescanTimer.stop()
                if self.w is not None:
        def stopScan(self):
                self.rescanTimer.stop()
                if self.w is not None:
@@ -110,7 +92,6 @@ class NetworkWizard(WizardLanguage, Rc):
 
        def getInstalledInterfaceCount(self):
                self.originalInterfaceState = {}
 
        def getInstalledInterfaceCount(self):
                self.originalInterfaceState = {}
-               self.stopScan()
                self.Adapterlist = iNetwork.getAdapterList()
                self.InstalledInterfaceCount = len(self.Adapterlist)
                if self.Adapterlist is not None:
                self.Adapterlist = iNetwork.getAdapterList()
                self.InstalledInterfaceCount = len(self.Adapterlist)
                if self.Adapterlist is not None:
@@ -127,7 +108,7 @@ class NetworkWizard(WizardLanguage, Rc):
                                if not iNetwork.isWirelessInterface(self.selectedInterface):
                                        self.NextStep = 'nwconfig'
                                else:
                                if not iNetwork.isWirelessInterface(self.selectedInterface):
                                        self.NextStep = 'nwconfig'
                                else:
-                                       self.NextStep = 'scanwlan'
+                                       self.NextStep = 'asknetworktype'
                                self.checkInterface(self.selectedInterface)
                        else:
                                self.NextStep = 'selectinterface'
                                self.checkInterface(self.selectedInterface)
                        else:
                                self.NextStep = 'selectinterface'
@@ -137,19 +118,19 @@ class NetworkWizard(WizardLanguage, Rc):
                        if not iNetwork.isWirelessInterface(self.selectedInterface):
                                self.NextStep = 'nwconfig'
                        else:
                        if not iNetwork.isWirelessInterface(self.selectedInterface):
                                self.NextStep = 'nwconfig'
                        else:
-                               self.NextStep = 'scanwlan'
+                               self.NextStep = 'asknetworktype'
                        self.checkInterface(self.selectedInterface)
 
        def checkOldInterfaceState(self):
                # disable up interface if it was originally down and config is unchanged.
                if self.originalInterfaceStateChanged is False:
                        for interface in self.originalInterfaceState.keys():
                        self.checkInterface(self.selectedInterface)
 
        def checkOldInterfaceState(self):
                # disable up interface if it was originally down and config is unchanged.
                if self.originalInterfaceStateChanged is False:
                        for interface in self.originalInterfaceState.keys():
-                               if self.originalInterfaceState[interface]["up"] is False:
-                                       if iNetwork.checkforInterface(interface) is True:
-                                               system("ifconfig " + interface + " down")
+                               if interface == self.selectedInterface:
+                                       if self.originalInterfaceState[interface]["up"] is False:
+                                               if iNetwork.checkforInterface(interface) is True:
+                                                       system("ifconfig " + interface + " down")
 
        def listInterfaces(self):
 
        def listInterfaces(self):
-               self.stopScan()
                self.checkOldInterfaceState()
                list = [(iNetwork.getFriendlyAdapterName(x),x) for x in iNetwork.getAdapterList()]
                list.append((_("Exit network wizard"), "end"))
                self.checkOldInterfaceState()
                list = [(iNetwork.getFriendlyAdapterName(x),x) for x in iNetwork.getAdapterList()]
                list.append((_("Exit network wizard"), "end"))
@@ -165,7 +146,7 @@ class NetworkWizard(WizardLanguage, Rc):
                elif index == 'eth0':
                        self.NextStep = 'nwconfig'
                else:
                elif index == 'eth0':
                        self.NextStep = 'nwconfig'
                else:
-                       self.NextStep = 'scanwlan'
+                       self.NextStep = 'asknetworktype'
 
        def InterfaceSelectionMoved(self):
                self.InterfaceSelect(self.selection)
 
        def InterfaceSelectionMoved(self):
                self.InterfaceSelect(self.selection)
@@ -251,7 +232,7 @@ class NetworkWizard(WizardLanguage, Rc):
                        if data is True:
                                if status is not None:
                                        text1 = _("Your Dreambox is now ready to use.\n\nYour internet connection is working now.\n\n")
                        if data is True:
                                if status is not None:
                                        text1 = _("Your Dreambox is now ready to use.\n\nYour internet connection is working now.\n\n")
-                                       text2 = _('Accesspoint:') + "\t" + str(status[self.selectedInterface]["acesspoint"]) + "\n"
+                                       text2 = _('Accesspoint:') + "\t" + str(status[self.selectedInterface]["accesspoint"]) + "\n"
                                        text3 = _('SSID:') + "\t" + str(status[self.selectedInterface]["essid"]) + "\n"
                                        text4 = _('Link Quality:') + "\t" + str(status[self.selectedInterface]["quality"])+ "\n"
                                        text5 = _('Signal Strength:') + "\t" + str(status[self.selectedInterface]["signal"]) + "\n"
                                        text3 = _('SSID:') + "\t" + str(status[self.selectedInterface]["essid"]) + "\n"
                                        text4 = _('Link Quality:') + "\t" + str(status[self.selectedInterface]["quality"])+ "\n"
                                        text5 = _('Signal Strength:') + "\t" + str(status[self.selectedInterface]["signal"]) + "\n"
@@ -261,7 +242,7 @@ class NetworkWizard(WizardLanguage, Rc):
                                        infotext = text1 + text2 + text3 + text4 + text5 + text7 +"\n" + text8
                                        self.currStep = self.getStepWithID("checkWlanstatusend")
                                        self.Text = infotext
                                        infotext = text1 + text2 + text3 + text4 + text5 + text7 +"\n" + text8
                                        self.currStep = self.getStepWithID("checkWlanstatusend")
                                        self.Text = infotext
-                                       if str(status[self.selectedInterface]["acesspoint"]) == "Not-Associated":
+                                       if str(status[self.selectedInterface]["accesspoint"]) == "Not-Associated":
                                                self.InterfaceState = False
                                        self.afterAsyncCode()
 
                                                self.InterfaceState = False
                                        self.afterAsyncCode()
 
@@ -306,42 +287,32 @@ class NetworkWizard(WizardLanguage, Rc):
                                newList.append(oldentry)
                                
                for newentry in newList:
                                newList.append(oldentry)
                                
                for newentry in newList:
-                       if newentry[1] == "hidden...":
-                               continue
                        self.newAPlist.append(newentry)
                        self.newAPlist.append(newentry)
-               
-               if len(self.newAPlist):
-                       if "hidden..." not in self.newAPlist:
-                               self.newAPlist.append(( _("enter hidden network SSID"), "hidden..." ))
 
 
+               if len(self.newAPlist):
                        if (self.wizard[self.currStep].has_key("dynamiclist")):
                                currentListEntry = self["list"].getCurrent()
                        if (self.wizard[self.currStep].has_key("dynamiclist")):
                                currentListEntry = self["list"].getCurrent()
-                               idx = 0
-                               for entry in self.newAPlist:
-                                       if entry == currentListEntry:
-                                               newListIndex = idx
-                                       idx +=1
+                               if currentListEntry is not None:
+                                       idx = 0
+                                       for entry in self.newAPlist:
+                                               if entry == currentListEntry:
+                                                       newListIndex = idx
+                                               idx +=1
                                self.wizard[self.currStep]["evaluatedlist"] = self.newAPlist
                                self['list'].setList(self.newAPlist)
                                self.wizard[self.currStep]["evaluatedlist"] = self.newAPlist
                                self['list'].setList(self.newAPlist)
-                               self["list"].setIndex(newListIndex)
+                               if newListIndex is not None:
+                                       self["list"].setIndex(newListIndex)
                                self["list"].updateList(self.newAPlist)
 
        def listAccessPoints(self):
                self.APList = []
                if self.WlanPluginInstalled is False:
                                self["list"].updateList(self.newAPlist)
 
        def listAccessPoints(self):
                self.APList = []
                if self.WlanPluginInstalled is False:
-                       self.APList.append( ( _("No networks found"),_("unavailable") ) )
-                       return self.APList
+                       self.APList.append( ( _("No networks found"), None ) )
                else:
                else:
-                       try:
-                               from Plugins.SystemPlugins.WirelessLan.Wlan import iWlan
-                               iWlan.setInterface(self.selectedInterface)
-                               self.w = iWlan.getInterface()
-                               aps = iWlan.getNetworkList()
-                       except ValueError:
-                               self.APList = []
-                               self.APList.append( ( _("No networks found"),_("unavailable") ) )
-                               return self.APList
-
+                       from Plugins.SystemPlugins.WirelessLan.Wlan import iWlan
+                       iWlan.setInterface(self.selectedInterface)
+                       self.w = iWlan.getInterface()
+                       aps = iWlan.getNetworkList()
                        if aps is not None:
                                print "[NetworkWizard.py] got Accespoints!"
                                tmplist = []
                        if aps is not None:
                                print "[NetworkWizard.py] got Accespoints!"
                                tmplist = []
@@ -359,28 +330,16 @@ class NetworkWizard(WizardLanguage, Rc):
                                                                complist.remove(compentry)
                                for entry in complist:
                                        self.APList.append( (entry[1], entry[1]) )
                                                                complist.remove(compentry)
                                for entry in complist:
                                        self.APList.append( (entry[1], entry[1]) )
-       
-                       if "hidden..." not in self.APList:
-                               self.APList.append(( _("enter hidden network SSID"), "hidden..." ))
+                       if not len(aps):
+                               self.APList.append( ( _("No networks found"), None ) )
                        
                        
-                       self.rescanTimer.start(5000)
-                       return self.APList
-
-       def AccessPointsSelectionMade(self, index):
-               self.ap = index
-               self.WlanList = []
-               currList = []
-               if (self.wizard[self.currStep].has_key("dynamiclist")):
-                       currList = self['list'].list
-                       for entry in currList:
-                               self.WlanList.append( (entry[1], entry[0]) )
-               self.AccessPointsSelect(index)
+               self.rescanTimer.start(4000)
+               return self.APList
 
 
-       def AccessPointsSelect(self, index):
-               self.NextStep = 'wlanconfig'
 
        def AccessPointsSelectionMoved(self):
 
        def AccessPointsSelectionMoved(self):
-               self.AccessPointsSelect(self.selection)
+               self.ap = self.selection
+               self.NextStep = 'wlanconfig'
 
        def checkWlanSelection(self):
                self.stopScan()
 
        def checkWlanSelection(self):
                self.stopScan()
@@ -413,7 +372,7 @@ class NetworkWizard(WizardLanguage, Rc):
                        self.selectedInterface = "eth0"
                        self.NextStep = 'nwconfig'
                else:
                        self.selectedInterface = "eth0"
                        self.NextStep = 'nwconfig'
                else:
-                       self.NextStep = 'scanwlan'
+                       self.NextStep = 'asknetworktype'
 
        def ChoicesSelectionMoved(self):
                pass
 
        def ChoicesSelectionMoved(self):
                pass