Merge branch 'master' of git.opendreambox.org:/git/enigma2
[enigma2.git] / lib / python / Screens / NetworkSetup.py
index c26302faa242932be20cf3d3099bb8f9d3a3a567..6bfe54ad6406c7103c273c09ac3d130ff38c1cc1 100755 (executable)
@@ -50,8 +50,8 @@ class NetworkAdapterSelection(Screen,HelpableScreen):
                Screen.__init__(self, session)
                HelpableScreen.__init__(self)
                
-               self.wlan_errortext = _("No working wireless networkadapter found.\nPlease verify that you have attached a compatible WLAN USB Stick and your Network is configured correctly.")
-               self.lan_errortext = _("No working local networkadapter found.\nPlease verify that you have attached a network cable and your Network is configured correctly.")
+               self.wlan_errortext = _("No working wireless network adapter found.\nPlease verify that you have attached a compatible WLAN device and your network is configured correctly.")
+               self.lan_errortext = _("No working local network adapter found.\nPlease verify that you have attached a network cable and your network is configured correctly.")
                self.oktext = _("Press OK on your remote control to continue.")
                self.restartLanRef = None
                
@@ -67,18 +67,18 @@ class NetworkAdapterSelection(Screen,HelpableScreen):
                        
                self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
                        {
-                       "cancel": (self.close, _("exit networkinterface list")),
+                       "cancel": (self.close, _("exit network interface list")),
                        "ok": (self.okbuttonClick, _("select interface")),
                        })
 
                self["ColorActions"] = HelpableActionMap(self, "ColorActions",
                        {
-                       "red": (self.close, _("exit networkinterface list")),   
+                       "red": (self.close, _("exit network interface list")),  
                        })
                
                self["DefaultInterfaceAction"] = HelpableActionMap(self, "ColorActions",
                        {
-                       "blue": (self.setDefaultInterface, [_("Set interface as default Interface"),_("* Only available if more then one interface is active.")] ),     
+                       "blue": (self.setDefaultInterface, [_("Set interface as default Interface"),_("* Only available if more than one interface is active.")] ),     
                        })
                
                self.list = []
@@ -90,7 +90,6 @@ class NetworkAdapterSelection(Screen,HelpableScreen):
                self.onClose.append(self.cleanup)
                
        def updateList(self):
-               iNetwork.getInterfaces()
                self.list = []
                default_gw = None
                num_configured_if = len(iNetwork.getConfiguredAdapters())
@@ -273,37 +272,41 @@ class NameserverSetup(Screen, ConfigListScreen, HelpableScreen):
                        self.createSetup()
        
 class AdapterSetup(Screen, ConfigListScreen, HelpableScreen):
-       def __init__(self, session, iface,essid=None, aplist=None):
+       def __init__(self, session, networkinfo, essid=None, aplist=None):
                Screen.__init__(self, session)
                HelpableScreen.__init__(self)
                self.session = session
-               self.iface = iface
-               self.essid = essid
-               self.aplist = aplist
+               if isinstance(networkinfo, (list, tuple)):
+                       self.iface = networkinfo[0]
+                       self.essid = networkinfo[1]
+                       self.aplist = networkinfo[2]
+               else:
+                       self.iface = networkinfo
+                       self.essid = essid
+                       self.aplist = aplist
                self.extended = None
                self.applyConfigRef = None
                self.finished_cb = None
                self.oktext = _("Press OK on your remote control to continue.")
                self.oldInterfaceState = iNetwork.getAdapterAttribute(self.iface, "up")
-               #iNetwork.getInterfaces()
-               
+
                self.createConfig()
 
                self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
                        {
-                       "cancel": (self.close, _("exit networkadapter setup menu")),
+                       "cancel": (self.cancel, _("exit network adapter setup menu")),
                        "ok": (self.ok, _("select menu entry")),
                        })
 
                self["ColorActions"] = HelpableActionMap(self, "ColorActions",
                        {
-                       "red": (self.cancel, _("exit networkadapter configuration")),
+                       "red": (self.cancel, _("exit network adapter configuration")),
                        "blue": (self.KeyBlue, _("open nameserver configuration")),
                        })
 
                self["VirtualKB"] = HelpableActionMap(self, "ColorActions",
                        {
-                       "green": (self.KeyGreen, [_("open virtual keyboard input help"),_("* Only available when entering hidden ssid or network key")] ),                                      
+                       "green": (self.KeyGreen, [_("open virtual keyboard input help"),_("* Only available when entering hidden SSID or network key")] ),                                      
                        })
 
                self["actions"] = NumberActionMap(["SetupActions"],
@@ -413,7 +416,6 @@ class AdapterSetup(Screen, ConfigListScreen, HelpableScreen):
                                        self.aps = self.w.getNetworkList()
                                        if self.aps is not None:
                                                print "[NetworkSetup.py] got Accespoints!"
-                                               print self.aps
                                                for ap in self.aps:
                                                        a = self.aps[ap]
                                                        if a['active']:
@@ -518,7 +520,7 @@ class AdapterSetup(Screen, ConfigListScreen, HelpableScreen):
                if self.iface == "wlan0" or self.iface == "ath0" :      
                        if self["config"].getCurrent() == self.hiddenSSID:
                                if config.plugins.wlan.essid.value == 'hidden...':
-                                       self.session.openWithCallback(self.VirtualKeyBoardSSIDCallback, VirtualKeyBoard, title = (_("Enter WLAN networkname/SSID:")), text = config.plugins.wlan.essid.value)
+                                       self.session.openWithCallback(self.VirtualKeyBoardSSIDCallback, VirtualKeyBoard, title = (_("Enter WLAN network name/SSID:")), text = config.plugins.wlan.essid.value)
                        if self["config"].getCurrent() == self.encryptionKey:
                                self.session.openWithCallback(self.VirtualKeyBoardKeyCallback, VirtualKeyBoard, title = (_("Enter WLAN passphrase/key:")), text = config.plugins.wlan.encryption.psk.value)
        
@@ -602,7 +604,7 @@ class AdapterSetup(Screen, ConfigListScreen, HelpableScreen):
                                iNetwork.deactivateInterface(self.iface)
                        iNetwork.writeNetworkConfig()                   
                        iNetwork.restartNetwork(self.applyConfigDataAvail)
-                       self.applyConfigRef = self.session.openWithCallback(self.applyConfigfinishedCB, MessageBox, _("Please wait while activating your network configuration..."), type = MessageBox.TYPE_INFO, enable_input = False)
+                       self.applyConfigRef = self.session.openWithCallback(self.applyConfigfinishedCB, MessageBox, _("Please wait for activation of your network configuration..."), type = MessageBox.TYPE_INFO, enable_input = False)
                else:
                        self.cancel()
                        
@@ -618,10 +620,10 @@ class AdapterSetup(Screen, ConfigListScreen, HelpableScreen):
                if data is True:
                        num_configured_if = len(iNetwork.getConfiguredAdapters())
                        if num_configured_if >= 2:
-                               self.session.openWithCallback(self.secondIfaceFoundCB, MessageBox, _("Your network configuration has been activated.\nA second configured interface has been found.\n\nDo you want to disable the second networkinterface?"), default = True)
+                               self.session.openWithCallback(self.secondIfaceFoundCB, MessageBox, _("Your network configuration has been activated.\nA second configured interface has been found.\n\nDo you want to disable the second network interface?"), default = True)
                        else:
                                if self.finished_cb:
-                                       self.session.openWithCallback(self.finished_cb, MessageBox, _("Your network configuration has been activated."), type = MessageBox.TYPE_INFO, timeout = 10)
+                                       self.session.openWithCallback(lambda x : self.finished_cb(), MessageBox, _("Your network configuration has been activated."), type = MessageBox.TYPE_INFO, timeout = 10)
                                else:
                                        self.session.openWithCallback(self.ConfigfinishedCB, MessageBox, _("Your network configuration has been activated."), type = MessageBox.TYPE_INFO, timeout = 10)
        
@@ -629,7 +631,7 @@ class AdapterSetup(Screen, ConfigListScreen, HelpableScreen):
                if data is False:
                        self.close('ok')
                else:
-                       configuredInterfaces = configuredNetworkAdapters
+                       configuredInterfaces = iNetwork.getConfiguredAdapters()
                        for interface in configuredInterfaces:
                                if interface == self.iface:
                                        continue
@@ -638,17 +640,26 @@ class AdapterSetup(Screen, ConfigListScreen, HelpableScreen):
                                self.applyConfig(True)
                        
        def ConfigfinishedCB(self,data):
-               if data is True:
-                       self.close('ok')
+               if data is not None:
+                       if data is True:
+                               self.close('ok')
 
        def cancel(self):
-               iNetwork.setAdapterAttribute(self.iface, "up", self.oldInterfaceState)
-               self.activateInterfaceEntry.value = self.oldInterfaceState
-               if self.activateInterfaceEntry.value is False:
-                       iNetwork.deactivateInterface(self.iface)
-               iNetwork.getInterfaces()
-               self.close('cancel')
+               if self.oldInterfaceState is False:
+                       iNetwork.deactivateInterface(self.iface,self.deactivateInterfaceCB)
+               else:
+                       self.close('cancel')
 
+       def deactivateInterfaceCB(self,data):
+               if data is not None:
+                       if data is True:
+                               iNetwork.getInterfaces(self.cancelCB)
+       
+       def cancelCB(self,data):                        
+               if data is not None:
+                       if data is True:
+                               self.close('cancel')
+                               
        def runAsync(self, finished_cb):
                self.finished_cb = finished_cb
                self.ok()
@@ -663,7 +674,7 @@ class AdapterSetup(Screen, ConfigListScreen, HelpableScreen):
                
        def cleanup(self):
                iNetwork.stopLinkStateConsole()
-               iNetwork.stopRestartConsole()   
+       
 
 class AdapterSetupConfiguration(Screen, HelpableScreen):
        def __init__(self, session,iface):
@@ -687,7 +698,7 @@ class AdapterSetupConfiguration(Screen, HelpableScreen):
                
                self.oktext = _("Press OK on your remote control to continue.")
                self.reboottext = _("Your Dreambox will restart after pressing OK on your remote control.")
-               self.errortext = _("No working wireless interface found.\n Please verify that you have attached a compatible WLAN device or enable you local network interface.")       
+               self.errortext = _("No working wireless network interface found.\n Please verify that you have attached a compatible WLAN device or enable your local network interface.")      
                
                self["WizardActions"] = HelpableActionMap(self, "WizardActions",
                        {
@@ -719,10 +730,9 @@ class AdapterSetupConfiguration(Screen, HelpableScreen):
                        "right": self.right,
                }, -2)
                
-               iNetwork.getInterfaces(self.updateStatusbar)
+               self.updateStatusbar()
                self.onLayoutFinish.append(self.layoutFinished)
                self.onClose.append(self.cleanup)
-               self.onHide.append(self.cleanup)
 
        def ok(self):
                if self["menulist"].getCurrent()[1] == 'edit':
@@ -770,7 +780,7 @@ class AdapterSetupConfiguration(Screen, HelpableScreen):
                                ifobj = Wireless(self.iface) # a Wireless NIC Object
                                self.wlanresponse = ifobj.getStatistics()
                                if self.wlanresponse[0] != 19:
-                                       self.session.openWithCallback(self.AdapterSetupClosed, WlanStatus,self.iface)
+                                       self.session.openWithCallback(self.WlanStatusClosed, WlanStatus,self.iface)
                                else:
                                        # Display Wlan not available Message
                                        self.showErrorMessage()
@@ -830,19 +840,14 @@ class AdapterSetupConfiguration(Screen, HelpableScreen):
                
                if self.iface == 'wlan0' or self.iface == 'ath0':
                        try:
-                               from Plugins.SystemPlugins.WirelessLan.Wlan import Wlan
-                               w = Wlan(self.iface)
-                               stats = w.getStatus()
-                               if stats['BSSID'] == "00:00:00:00:00:00":
-                                       self["statuspic"].setPixmapNum(1)
-                               else:
-                                       self["statuspic"].setPixmapNum(0)
-                               self["statuspic"].show()
+                               from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus,Status
                        except:
                                        self["statuspic"].setPixmapNum(1)
                                        self["statuspic"].show()
+                       else:
+                               iStatus.getDataForInterface(self.iface,self.getInfoCB)
                else:
-                       self.getLinkState(self.iface)
+                       iNetwork.getLinkState(self.iface,self.dataAvail)
 
        def doNothing(self):
                pass
@@ -894,25 +899,37 @@ class AdapterSetupConfiguration(Screen, HelpableScreen):
                                        ifobj = Wireless(self.iface) # a Wireless NIC Object
                                        self.wlanresponse = ifobj.getStatistics()
                                        if self.wlanresponse[0] != 19:
-                                               self.session.openWithCallback(self.AdapterSetupClosed, WlanStatus,self.iface)
+                                               self.session.openWithCallback(self.WlanStatusClosed, WlanStatus,self.iface)
                                        else:
                                                # Display Wlan not available Message
                                                self.showErrorMessage()
                        else:
                                self.mainmenu = self.genMainMenu()
                                self["menulist"].l.setList(self.mainmenu)
-                               iNetwork.getInterfaces(self.updateStatusbar)
+                               self.updateStatusbar()
                else:
                        self.mainmenu = self.genMainMenu()
                        self["menulist"].l.setList(self.mainmenu)
-                       iNetwork.getInterfaces(self.updateStatusbar)
+                       self.updateStatusbar()
+
+       def WlanStatusClosed(self, *ret):
+               if ret is not None and len(ret):
+                       from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus,Status
+                       iStatus.stopWlanConsole()
+                       self.mainmenu = self.genMainMenu()
+                       self["menulist"].l.setList(self.mainmenu)
+                       self.updateStatusbar()
 
        def WlanScanClosed(self,*ret):
                if ret[0] is not None:
                        self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup, self.iface,ret[0],ret[1])
                else:
-                       self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup, self.iface,None,None)
-
+                       from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus,Status
+                       iStatus.stopWlanConsole()
+                       self.mainmenu = self.genMainMenu()
+                       self["menulist"].l.setList(self.mainmenu)
+                       self.updateStatusbar()
+                       
        def restartLan(self, ret = False):
                if (ret == True):
                        iNetwork.restartNetwork(self.restartLanDataAvail)
@@ -930,9 +947,6 @@ class AdapterSetupConfiguration(Screen, HelpableScreen):
                if data is True:
                        self.session.open(MessageBox, _("Finished restarting your network"), type = MessageBox.TYPE_INFO, timeout = 10, default = False)
 
-       def getLinkState(self,iface):
-               iNetwork.getLinkState(iface,self.dataAvail)
-
        def dataAvail(self,data):
                self.output = data.strip()
                result = self.output.split('\n')
@@ -949,15 +963,32 @@ class AdapterSetupConfiguration(Screen, HelpableScreen):
                
        def cleanup(self):
                iNetwork.stopLinkStateConsole()
-
+               iNetwork.stopDeactivateInterfaceConsole()
+               try:
+                       from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus,Status
+               except ImportError:
+                       pass
+               else:
+                       iStatus.stopWlanConsole()
+
+       def getInfoCB(self,data,status):
+               if data is not None:
+                       if data is True:
+                               if status is not None:
+                                       if status[self.iface]["acesspoint"] == "No Connection" or status[self.iface]["acesspoint"] == "Not-Associated" or status[self.iface]["acesspoint"] == False:
+                                               self["statuspic"].setPixmapNum(1)
+                                       else:
+                                               self["statuspic"].setPixmapNum(0)
+                                       self["statuspic"].show()
 
 class NetworkAdapterTest(Screen):      
        def __init__(self, session,iface):
                Screen.__init__(self, session)
                self.iface = iface
                self.oldInterfaceState = iNetwork.getAdapterAttribute(self.iface, "up")
-               iNetwork.getInterfaces()
                self.setLabels()
+               self.onClose.append(self.cleanup)
+               self.onHide.append(self.cleanup)
                
                self["updown_actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
                {
@@ -1115,6 +1146,7 @@ class NetworkAdapterTest(Screen):
 
        def doStep3(self):
                self["Networktext"].setForegroundColorNum(1)
+               self["Network"].setText(_("Please wait..."))
                self.getLinkState(self.iface)
                self["NetworkInfo_Text"].setForegroundColorNum(1)
                self.steptimer = True
@@ -1287,24 +1319,14 @@ class NetworkAdapterTest(Screen):
        def getLinkState(self,iface):
                if iface == 'wlan0' or iface == 'ath0':
                        try:
-                               from Plugins.SystemPlugins.WirelessLan.Wlan import Wlan
-                               w = Wlan(iface)
-                               stats = w.getStatus()
-                               if stats['BSSID'] == "00:00:00:00:00:00":
-                                       self["Network"].setForegroundColorNum(1)
-                                       self["Network"].setText(_("disconnected"))
-                                       self["NetworkInfo_Check"].setPixmapNum(1)
-                                       self["NetworkInfo_Check"].show()
-                               else:
-                                       self["Network"].setForegroundColorNum(2)
-                                       self["Network"].setText(_("connected"))
-                                       self["NetworkInfo_Check"].setPixmapNum(0)
-                                       self["NetworkInfo_Check"].show()
+                               from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus,Status
                        except:
                                        self["Network"].setForegroundColorNum(1)
                                        self["Network"].setText(_("disconnected"))
                                        self["NetworkInfo_Check"].setPixmapNum(1)
                                        self["NetworkInfo_Check"].show()
+                       else:
+                               iStatus.getDataForInterface(self.iface,self.getInfoCB)
                else:
                        iNetwork.getLinkState(iface,self.LinkStatedataAvail)
 
@@ -1324,7 +1346,6 @@ class NetworkAdapterTest(Screen):
                self["NetworkInfo_Check"].show()
 
        def NetworkStatedataAvail(self,data):
-               print "DATA",data
                if data <= 2:
                        self["IP"].setForegroundColorNum(2)
                        self["IP"].setText(_("confirmed"))
@@ -1339,7 +1360,6 @@ class NetworkAdapterTest(Screen):
                self.nextStepTimer.start(3000)          
                
        def DNSLookupdataAvail(self,data):
-               print "DATA",data
                if data <= 2:
                        self["DNS"].setForegroundColorNum(2)
                        self["DNS"].setText(_("confirmed"))
@@ -1362,5 +1382,29 @@ class NetworkAdapterTest(Screen):
                self["shortcutsyellow"].setEnabled(False)
                self["updown_actions"].setEnabled(True)
                self.activebutton = 6
-               
-               
\ No newline at end of file
+
+       def getInfoCB(self,data,status):
+               if data is not None:
+                       if data is True:
+                               if status is not None:
+                                       if status[self.iface]["acesspoint"] == "No Connection" or status[self.iface]["acesspoint"] == "Not-Associated" or status[self.iface]["acesspoint"] == False:
+                                               self["Network"].setForegroundColorNum(1)
+                                               self["Network"].setText(_("disconnected"))
+                                               self["NetworkInfo_Check"].setPixmapNum(1)
+                                               self["NetworkInfo_Check"].show()
+                                       else:
+                                               self["Network"].setForegroundColorNum(2)
+                                               self["Network"].setText(_("connected"))
+                                               self["NetworkInfo_Check"].setPixmapNum(0)
+                                               self["NetworkInfo_Check"].show()
+                                               
+       def cleanup(self):
+               iNetwork.stopLinkStateConsole()
+               iNetwork.stopDNSConsole()
+               try:
+                       from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus,Status
+               except ImportError:
+                       pass
+               else:
+                       iStatus.stopWlanConsole()
+