[Sugar-devel] [PATCH sugar 4/4] fix network disconnect (SL#1608, SL#1802)

Sascha Silbe sascha-pgp at silbe.org
Fri Jan 21 08:10:35 EST 2011


User interface changes:

- enable the disconnect button on the access point menu in the
  neighbourhood view, (rather than the button doing nothing),

- fix the disconnect button on the wireless device icon in the frame
  so that the disconnection remains effective [1], (rather than
  disconnecting and then reconnecting automatically),

Based on a patch by James Cameron <quozl at laptop.org>.

[1] http://mail.gnome.org/archives/networkmanager-list/2011-January/msg00007.html

Signed-off-by: Sascha Silbe <sascha-pgp at silbe.org>

diff --git a/extensions/deviceicon/network.py b/extensions/deviceicon/network.py
index bc2492d..4c4f339 100644
--- a/extensions/deviceicon/network.py
+++ b/extensions/deviceicon/network.py
@@ -564,20 +564,12 @@ class WirelessDeviceView(ToolButton):
         self._icon.props.base_color = self._color
 
     def __deactivate_connection_cb(self, palette, data=None):
-        if self._active_ap_op is not None:
-            obj = self._bus.get_object(_NM_SERVICE, _NM_PATH)
-            netmgr = dbus.Interface(obj, _NM_IFACE)
-            netmgr_props = dbus.Interface(netmgr, dbus.PROPERTIES_IFACE)
-            active_connections_o = netmgr_props.Get(_NM_IFACE,
-                                                    'ActiveConnections')
+        if self._mode == network.NM_802_11_MODE_INFRA:
+            connection = network.find_connection_by_ssid(self._name)
+            if connection:
+                connection.disable_autoconnect()
 
-            for conn_o in active_connections_o:
-                obj = self._bus.get_object(_NM_IFACE, conn_o)
-                props = dbus.Interface(obj, dbus.PROPERTIES_IFACE)
-                ap_op = props.Get(_NM_ACTIVE_CONN_IFACE, 'SpecificObject')
-                if ap_op == self._active_ap_op:
-                    netmgr.DeactivateConnection(conn_o)
-                    break
+        network.disconnect_access_points([self._active_ap_op])
 
     def __activate_reply_cb(self, connection):
         logging.debug('Network created: %s', connection)
diff --git a/src/jarabe/desktop/networkviews.py b/src/jarabe/desktop/networkviews.py
index 4282a75..5e0a809 100644
--- a/src/jarabe/desktop/networkviews.py
+++ b/src/jarabe/desktop/networkviews.py
@@ -265,7 +265,13 @@ class WirelessNetworkView(CanvasPulsingIcon):
             self.props.base_color = self._color
 
     def _disconnect_activate_cb(self, item):
-        pass
+        if self._mode == network.NM_802_11_MODE_INFRA:
+            connection = network.find_connection_by_ssid(self._name)
+            if connection:
+                connection.disable_autoconnect()
+
+        ap_paths = self._access_points.keys()
+        network.disconnect_access_points(ap_paths)
 
     def _add_ciphers_from_flags(self, flags, pairwise):
         ciphers = []
diff --git a/src/jarabe/model/network.py b/src/jarabe/model/network.py
index 037f90f..847fa80 100644
--- a/src/jarabe/model/network.py
+++ b/src/jarabe/model/network.py
@@ -130,11 +130,16 @@ NM_802_11_DEVICE_CAP_RSN = 0x00000020
 
 SETTINGS_SERVICE = 'org.freedesktop.NetworkManagerUserSettings'
 
+NM_SERVICE = 'org.freedesktop.NetworkManager'
+NM_IFACE = 'org.freedesktop.NetworkManager'
+NM_PATH = '/org/freedesktop/NetworkManager'
+NM_DEVICE_IFACE = 'org.freedesktop.NetworkManager.Device'
 NM_SETTINGS_PATH = '/org/freedesktop/NetworkManagerSettings'
 NM_SETTINGS_IFACE = 'org.freedesktop.NetworkManagerSettings'
 NM_CONNECTION_IFACE = 'org.freedesktop.NetworkManagerSettings.Connection'
 NM_SECRETS_IFACE = 'org.freedesktop.NetworkManagerSettings.Connection.Secrets'
 NM_ACCESSPOINT_IFACE = 'org.freedesktop.NetworkManager.AccessPoint'
+NM_ACTIVE_CONN_IFACE = 'org.freedesktop.NetworkManager.Connection.Active'
 
 GSM_USERNAME_PATH = '/desktop/sugar/network/gsm/username'
 GSM_PASSWORD_PATH = '/desktop/sugar/network/gsm/password'
@@ -591,6 +596,14 @@ class NMSettingsConnection(dbus.service.Object):
             # pylint: disable=W0702
             logging.exception('Error calling libc.__res_init')
 
+    def disable_autoconnect(self):
+        if self._settings.connection.type != NM_CONNECTION_TYPE_GSM and \
+               self._settings.connection.autoconnect:
+            self._settings.connection.autoconnect = False
+            self._settings.connection.timestamp = None
+            self.Updated(self._settings.get_dict())
+            self.save()
+
     def set_secrets(self, secrets):
         self._secrets = secrets
         if self._settings.connection.type == \
@@ -968,3 +981,27 @@ def clear_wifi_connections():
 
     config_path = _get_wifi_connections_path()
     _create_wifi_connections(config_path)
+
+
+def disconnect_access_points(ap_paths):
+    """
+    Disconnect all devices connected to any of the given access points.
+    """
+    bus = dbus.SystemBus()
+    netmgr_obj = bus.get_object(NM_SERVICE, NM_PATH)
+    netmgr = dbus.Interface(netmgr_obj, NM_IFACE)
+    netmgr_props = dbus.Interface(netmgr, dbus.PROPERTIES_IFACE)
+    active_connection_paths = netmgr_props.Get(NM_IFACE, 'ActiveConnections')
+
+    for conn_path in active_connection_paths:
+        conn_obj = bus.get_object(NM_IFACE, conn_path)
+        conn_props = dbus.Interface(conn_obj, dbus.PROPERTIES_IFACE)
+        ap_path = conn_props.Get(NM_ACTIVE_CONN_IFACE, 'SpecificObject')
+        if ap_path == '/' or ap_path not in ap_paths:
+            continue
+
+        dev_paths = conn_props.Get(NM_ACTIVE_CONN_IFACE, 'Devices')
+        for dev_path in dev_paths:
+            dev_obj = bus.get_object(NM_SERVICE, dev_path)
+            dev = dbus.Interface(dev_obj, NM_DEVICE_IFACE)
+            dev.Disconnect()
-- 
1.7.2.3



More information about the Sugar-devel mailing list