Merge branch 'bug_203_fix_wrong_networkstate'
authoracid-burn <acid-burn@opendreambox.org>
Wed, 23 Dec 2009 06:15:51 +0000 (07:15 +0100)
committeracid-burn <acid-burn@opendreambox.org>
Wed, 23 Dec 2009 06:15:51 +0000 (07:15 +0100)
Conflicts:
lib/python/Plugins/SystemPlugins/WirelessLan/plugin.py
lib/python/Screens/NetworkSetup.py

lib/python/Components/Network.py
lib/python/Plugins/SystemPlugins/WirelessLan/plugin.py
lib/python/Screens/NetworkSetup.py

index f65d6090c3c8e699d901ab6778cd0ad97f2ee8a4..bd10d9c3e2360da293c93e077100259bca3b04dd 100755 (executable)
@@ -24,6 +24,7 @@ class Network:
                self.activateConsole = Console()
                self.resetNetworkConsole = Console()
                self.DnsConsole = Console()
+               self.PingConsole = Console()
                self.config_ready = None
                self.getInterfaces()
 
@@ -475,10 +476,17 @@ class Network:
 
        def getLinkStateFinished(self, result, retval,extra_args):
                (callback) = extra_args
+
                if self.LinkConsole is not None:
                        if len(self.LinkConsole.appContainers) == 0:
                                callback(result)
                        
+       def stopPingConsole(self):
+               if self.PingConsole is not None:
+                       if len(self.PingConsole.appContainers):
+                               for name in self.PingConsole.appContainers.keys():
+                                       self.PingConsole.kill(name)
+
        def stopLinkStateConsole(self):
                if self.LinkConsole is not None:
                        if len(self.LinkConsole.appContainers):
index a78857a674632ac0869d76e8ed71ee0763374072..c71037c53d2946a8dfe393bfbe1cd9d404adba7d 100755 (executable)
@@ -130,7 +130,7 @@ class WlanStatus(Screen):
 
        def exit(self):
                self.timer.stop()
-               self.close()    
+               self.close(True)        
 
        def updateStatusbar(self):
                self["BSSID"].setText(_("Please wait..."))
@@ -262,8 +262,11 @@ class WlanScan(Screen):
                self.updateAPList()
 
        def buildEntryComponent(self, essid, bssid, encrypted, iface, maxrate, signal):
+<<<<<<< HEAD:lib/python/Plugins/SystemPlugins/WirelessLan/plugin.py
                print "buildEntryComponent",essid
                print "buildEntryComponent",bssid
+=======
+>>>>>>> bug_203_fix_wrong_networkstate:lib/python/Plugins/SystemPlugins/WirelessLan/plugin.py
                divpng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/div-h.png"))
                encryption = encrypted and _("Yes") or _("No")
                if bssid == 'hidden...':
index 9461242d4d9b80a5a2ef5a3ec10558e4a9339b65..3e9354ead818872950be3067608a96ffb11a4db4 100755 (executable)
@@ -665,6 +665,7 @@ class AdapterSetupConfiguration(Screen, HelpableScreen):
                self.session = session
                self.iface = iface
                self.restartLanRef = None
+               self.LinkState = None
                self.mainmenu = self.genMainMenu()
                self["menulist"] = MenuList(self.mainmenu)
                self["key_red"] = StaticText(_("Close"))
@@ -714,6 +715,7 @@ class AdapterSetupConfiguration(Screen, HelpableScreen):
                self.onClose.append(self.cleanup)
 
        def ok(self):
+               self.cleanup()
                if self["menulist"].getCurrent()[1] == 'edit':
                        if self.iface == 'wlan0' or self.iface == 'ath0':
                                try:
@@ -812,6 +814,8 @@ class AdapterSetupConfiguration(Screen, HelpableScreen):
                        self["description"].setText(_(self["menulist"].getCurrent()[1][1]) + self.oktext )
                
        def updateStatusbar(self, data = None):
+               self.mainmenu = self.genMainMenu()
+               self["menulist"].l.setList(self.mainmenu)
                self["IFtext"].setText(_("Network:"))
                self["IF"].setText(iNetwork.getFriendlyAdapterName(self.iface))
                self["Statustext"].setText(_("Link:"))
@@ -881,20 +885,14 @@ class AdapterSetupConfiguration(Screen, HelpableScreen):
                                                # Display Wlan not available Message
                                                self.showErrorMessage()
                        else:
-                               self.mainmenu = self.genMainMenu()
-                               self["menulist"].l.setList(self.mainmenu)
                                self.updateStatusbar()
                else:
-                       self.mainmenu = self.genMainMenu()
-                       self["menulist"].l.setList(self.mainmenu)
                        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):
@@ -903,8 +901,6 @@ class AdapterSetupConfiguration(Screen, HelpableScreen):
                else:
                        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):
@@ -926,15 +922,19 @@ class AdapterSetupConfiguration(Screen, HelpableScreen):
                        self.session.open(MessageBox, _("Finished restarting your network"), type = MessageBox.TYPE_INFO, timeout = 10, default = False)
 
        def dataAvail(self,data):
-               self.output = data.strip()
-               result = self.output.split('\n')
-               pattern = re_compile("Link detected: yes")
-               for item in result:
-                       if re_search(pattern, item):
-                               self["statuspic"].setPixmapNum(0)
-                       else:
-                               self["statuspic"].setPixmapNum(1)
-               self["statuspic"].show()
+               self.LinkState = None
+               for line in data.splitlines():
+                       line = line.strip()
+                       if 'Link detected:' in line:
+                               if "yes" in line:
+                                       self.LinkState = True
+                               else:
+                                       self.LinkState = False
+               if self.LinkState == True:
+                       iNetwork.checkNetworkState(self.checkNetworkCB)
+               else:
+                       self["statuspic"].setPixmapNum(1)
+                       self["statuspic"].show()                        
 
        def showErrorMessage(self):
                self.session.open(MessageBox, self.errortext, type = MessageBox.TYPE_INFO,timeout = 10 )
@@ -942,6 +942,7 @@ class AdapterSetupConfiguration(Screen, HelpableScreen):
        def cleanup(self):
                iNetwork.stopLinkStateConsole()
                iNetwork.stopDeactivateInterfaceConsole()
+               iNetwork.stopPingConsole()
                try:
                        from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus
                except ImportError:
@@ -950,14 +951,33 @@ class AdapterSetupConfiguration(Screen, HelpableScreen):
                        iStatus.stopWlanConsole()
 
        def getInfoCB(self,data,status):
+               self.LinkState = None
                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.LinkState = False
                                                self["statuspic"].setPixmapNum(1)
+                                               self["statuspic"].show()
                                        else:
-                                               self["statuspic"].setPixmapNum(0)
-                                       self["statuspic"].show()
+                                               self.LinkState = True
+                                               iNetwork.checkNetworkState(self.checkNetworkCB)
+
+       def checkNetworkCB(self,data):
+               if iNetwork.getAdapterAttribute(self.iface, "up") is True:
+                       if self.LinkState is True:
+                               if data <= 2:
+                                       self["statuspic"].setPixmapNum(0)
+                               else:
+                                       self["statuspic"].setPixmapNum(1)
+                               self["statuspic"].show()        
+                       else:
+                               self["statuspic"].setPixmapNum(1)
+                               self["statuspic"].show()
+               else:
+                       self["statuspic"].setPixmapNum(1)
+                       self["statuspic"].show()
+
 
 class NetworkAdapterTest(Screen):      
        def __init__(self, session,iface):
@@ -1376,4 +1396,4 @@ class NetworkAdapterTest(Screen):
                        pass
                else:
                        iStatus.stopWlanConsole()
-                       
+