small pat/pmt scan fix
[enigma2.git] / lib / python / Screens / NetworkSetup.py
index 8cc473fc105ddcc3f0ff9cbbd18c81c4398b1e9b..29f9705f3f3f4aa985e441ff7dd420001208a829 100644 (file)
@@ -12,7 +12,7 @@ from Components.PluginComponent import plugins
 from Components.MultiContent import MultiContentEntryText, MultiContentEntryPixmapAlphaTest
 from Plugins.Plugin import PluginDescriptor
 from enigma import eTimer
-from os import path as os_path, system as os_system
+from os import path as os_path, system as os_system, unlink
 from re import compile as re_compile, search as re_search
 from Tools.Directories import resolveFilename, SCOPE_PLUGINS
 
@@ -45,7 +45,7 @@ def InterfaceEntryComponent(index,name,default,active ):
 class NetworkAdapterSelection(Screen):
        def __init__(self, session):
                Screen.__init__(self, session)
-               iNetwork.getInterfaces()
+
                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.")
                
@@ -74,8 +74,14 @@ class NetworkAdapterSelection(Screen):
 
        def updateList(self):
                print "update list"
+               iNetwork.getInterfaces()
                self.list = []
                default_gw = None
+               num_configured_if = len(iNetwork.configuredInterfaces)
+               print "num_configured_if :",num_configured_if 
+               if num_configured_if < 2 and os_path.exists("/etc/default_gw"):
+                       unlink("/etc/default_gw")
+                       
                if os_path.exists("/etc/default_gw"):
                        fp = file('/etc/default_gw', 'r')
                        result = fp.read()
@@ -99,19 +105,23 @@ class NetworkAdapterSelection(Screen):
 
        def setDefaultInterface(self):
                selection = self["list"].getCurrent()
-               backupdefault_gw = None
+               num_if = len(self.list)
+               old_default_gw = None
                if os_path.exists("/etc/default_gw"):
-                       fp = file('/etc/default_gw', 'r')
-                       backupdefault_gw  = fp.read()
+                       fp = open('/etc/default_gw', 'r')
+                       old_default_gw = fp.read()
                        fp.close()
-               if selection[0] != backupdefault_gw:
-                       os_system("rm -rf /etc/default_gw")
-                       fp = file('/etc/default_gw', 'w')       
-                       fp.write(selection[0])                          
+               if num_if > 1 and (not old_default_gw or old_default_gw != selection[0]):
+                       fp = open('/etc/default_gw', 'w+')
+                       fp.write(selection[0])
                        fp.close()
                        iNetwork.restartNetwork()
-               self.updateList()
-                       
+                       self.updateList()
+               elif old_default_gw and num_if < 2:
+                       unlink("/etc/default_gw")
+                       iNetwork.restartNetwork()
+                       self.updateList()
+
        def okbuttonClick(self):
                selection = self["list"].getCurrent()
                print "selection",selection
@@ -121,6 +131,8 @@ class NetworkAdapterSelection(Screen):
        def AdapterSetupClosed(self, *ret):
                if len(self.adapters) == 1:
                        self.close()
+               else:
+                       self.updateList()
 
        def NetworkFallback(self):
                if iNetwork.configuredInterfaces.has_key('wlan0') is True:
@@ -378,23 +390,24 @@ class AdapterSetup(Screen, ConfigListScreen):
 
        def ok(self):
                iNetwork.setAdapterAttribute(self.iface, "up", self.activateInterfaceEntry.value)
-               if self.activateInterfaceEntry.value is True:
-                       iNetwork.setAdapterAttribute(self.iface, "dhcp", self.dhcpConfigEntry.value)
-                       iNetwork.setAdapterAttribute(self.iface, "ip", self.ipConfigEntry.value)
-                       iNetwork.setAdapterAttribute(self.iface, "netmask", self.netmaskConfigEntry.value)
-                       if self.hasGatewayConfigEntry.value:
-                               iNetwork.setAdapterAttribute(self.iface, "gateway", self.gatewayConfigEntry.value)
-                       else:
-                               iNetwork.removeAdapterAttribute(self.iface, "gateway")
-                       if self.extended is not None and self.configStrings is not None:
-                               iNetwork.setAdapterAttribute(self.iface, "configStrings", self.configStrings(self.iface))
-                               self.ws.writeConfig()
+               #if self.activateInterfaceEntry.value is True:
+               iNetwork.setAdapterAttribute(self.iface, "dhcp", self.dhcpConfigEntry.value)
+               iNetwork.setAdapterAttribute(self.iface, "ip", self.ipConfigEntry.value)
+               iNetwork.setAdapterAttribute(self.iface, "netmask", self.netmaskConfigEntry.value)
+               if self.hasGatewayConfigEntry.value:
+                       iNetwork.setAdapterAttribute(self.iface, "gateway", self.gatewayConfigEntry.value)
                else:
-                       iNetwork.removeAdapterAttribute(self.iface, "ip")
-                       iNetwork.removeAdapterAttribute(self.iface, "netmask")
                        iNetwork.removeAdapterAttribute(self.iface, "gateway")
+               if self.extended is not None and self.configStrings is not None:
+                       iNetwork.setAdapterAttribute(self.iface, "configStrings", self.configStrings(self.iface))
+                       self.ws.writeConfig()
+               #else:
+               #       iNetwork.removeAdapterAttribute(self.iface, "ip")
+               #       iNetwork.removeAdapterAttribute(self.iface, "netmask")
+               #       iNetwork.removeAdapterAttribute(self.iface, "gateway")
+               #       iNetwork.deactivateInterface(self.iface)
+               if self.activateInterfaceEntry.value is False:
                        iNetwork.deactivateInterface(self.iface)
-
                iNetwork.deactivateNetworkConfig()
                iNetwork.writeNetworkConfig()
                iNetwork.activateNetworkConfig()