[Sugar-devel] [PATCH 4/4] disconnect on passphrase cancel #1805

James Cameron quozl at laptop.org
Wed Apr 21 21:11:21 EDT 2010


When a passphrase dialog is cancelled, no further attempt to connect
is made, and the icon is not marked as favourite.  Fixes #1805.
Details:

1.  a backlink to the NMSettings object is placed in each
NMSettingsConnection object,

2.  NMSettings.clear_connections method is adjusted to better fit the
semantics of the previously proposed 0.88 patch,

3.  a new delete_connection method is added to NMSettings,

4.  the connection is deleted when the SecretsResponse.set_error
method is called, thus preventing further attempts to connect and
marking the network as no longer a favourite,

5.  a new wipe method is added to NMSettingsConnection for removing a
network from the connections file; the method was copied from save,

6.  a new delete method is added to NMSettingsConnection for deleting
a network (see #4 above), the connection is removed from the
NMSettings dictionary first so that when the Removed signal is
cascaded into the mesh box the favourite badge will be removed.
---
 src/jarabe/model/network.py |   47 ++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 44 insertions(+), 3 deletions(-)

diff --git a/src/jarabe/model/network.py b/src/jarabe/model/network.py
index e43dba0..021d1a3 100644
--- a/src/jarabe/model/network.py
+++ b/src/jarabe/model/network.py
@@ -208,6 +208,7 @@ class NMSettings(dbus.service.Object):
         pass
 
     def add_connection(self, ssid, conn):
+        conn._nm_settings = self
         self.connections[ssid] = conn
         conn.secrets_request.connect(self.__secrets_request_cb)
         self.NewConnection(conn.path)
@@ -217,9 +218,15 @@ class NMSettings(dbus.service.Object):
                                   response=kwargs['response'])
 
     def clear_connections(self):
-        for connection in self.connections.values():
-            connection.Removed()
-        self.connections = {}
+        for uuid in self.connections.keys():
+            conn = self.connections[uuid]
+            conn.Removed()
+            self.connections.pop(uuid)
+
+    def delete_connection(self, conn):
+        for uuid in self.connections.keys():
+            if self.connections[uuid] == conn:
+                self.connections.pop(uuid)
 
 class SecretsResponse(object):
     ''' Intermediate object to report the secrets from the dialog
@@ -235,6 +242,7 @@ class SecretsResponse(object):
         self._reply_cb(secrets.get_dict())
 
     def set_error(self, error):
+        self._connection.delete()
         self._error_cb(error)
 
 class NMSettingsConnection(dbus.service.Object):
@@ -359,6 +367,39 @@ class NMSettingsConnection(dbus.service.Object):
         else:
             reply(self._secrets.get_dict())
 
+    def wipe(self):
+        """ remove the connection from the stored connections file """
+        profile_path = env.get_profile_path()
+        config_path = os.path.join(profile_path, 'nm', 'connections.cfg')
+
+        config = ConfigParser.ConfigParser()
+        try:
+            try:
+                if not config.read(config_path):
+                    logging.error('Error reading the nm config file')
+                    return
+            except ConfigParser.ParsingError, e:
+                logging.error('Error reading the nm config file: %s' % e)
+                return
+            identifier = self._settings.connection.id
+
+            if identifier in config.sections():
+                config.remove_section(identifier)
+        except ConfigParser.Error, e:
+            logging.error('Error constructing %s: %s' % (identifier, e))
+        else:
+            f = open(config_path, 'w')
+            try:
+                config.write(f)
+            except ConfigParser.Error, e:
+                logging.error('Can not write %s error: %s' % (config_path, e))
+            f.close()
+
+    def delete(self):
+        self._nm_settings.delete_connection(self)
+        self.wipe()
+        self.Removed()
+
 class AccessPoint(gobject.GObject):
     __gsignals__ = {
         'props-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
-- 
1.7.0


-- 
James Cameron
http://quozl.linux.org.au/


More information about the Sugar-devel mailing list