From 885d118b31651bf381b40f6bf10cbd8b28cdc915 Mon Sep 17 00:00:00 2001
From: Tomeu Vizoso <tomeu.vizoso@collabora.co.uk>
Date: Mon, 6 Sep 2010 17:48:08 +0200
Subject: [PATCH] Set param-register to False after a RegistrationExists error #2296

---
 src/jarabe/model/neighborhood.py |   23 ++++++++++++++++++++++-
 1 files changed, 22 insertions(+), 1 deletions(-)

diff --git a/src/jarabe/model/neighborhood.py b/src/jarabe/model/neighborhood.py
index 3e89855..9ec6322 100644
--- a/src/jarabe/model/neighborhood.py
+++ b/src/jarabe/model/neighborhood.py
@@ -199,11 +199,31 @@ class _Account(gobject.GObject):
         logging.debug('_Account.__got_connection_cb %r', connection_path)
 
         if connection_path == '/':
-            # Account has no connection, wait until it has one.
+            self._check_registration_error()
             return
 
         self._prepare_connection(connection_path)
 
+    def _check_registration_error(self):
+        """
+        See if a previous connection attempt failed and we need to unset
+        the register flag.
+        """
+        bus = dbus.Bus()
+        obj = bus.get_object(ACCOUNT_MANAGER_SERVICE, self.object_path)
+        obj.Get(ACCOUNT, 'ConnectionError',
+                reply_handler=self.__got_connection_error_cb,
+                error_handler=partial(self.__error_handler_cb,
+                                      'Account.GetConnectionError'))
+
+    def __got_connection_error_cb(self, error):
+        logging.debug('_Account.__got_connection_error_cb %r', error)
+        if error == 'org.freedesktop.Telepathy.Error.RegistrationExists':
+            bus = dbus.Bus()
+            obj = bus.get_object(ACCOUNT_MANAGER_SERVICE, self.object_path)
+            obj.UpdateParameters({'register': False}, [],
+                                 dbus_interface=ACCOUNT)
+
     def __account_property_changed_cb(self, properties):
         logging.debug('_Account.__account_property_changed_cb %r %r %r',
                       self.object_path, properties.get('Connection', None),
@@ -211,6 +231,7 @@ class _Account(gobject.GObject):
         if 'Connection' not in properties:
             return
         if properties['Connection'] == '/':
+            self._check_registration_error()
             self._connection = None
         elif self._connection is None:
             self._prepare_connection(properties['Connection'])
-- 
1.7.2.2

