[Sugar-devel] [PATCH sugar] Make sure that we have a connection before we set our properties SL #3119

Simon Schampijer simon at schampijer.de
Fri Oct 7 13:47:34 EDT 2011


The issue here is that we di not have a connection yet, when
the name owner changes. It is safer to listen to the connection
watcher when a connection is added (which was the original code).
Tested as working fine in gabble and salut.

Signed-off-by: Simon Schampijer <simon at laptop.org>
---
 src/jarabe/model/buddy.py |   34 +++++++---------------------------
 1 files changed, 7 insertions(+), 27 deletions(-)

diff --git a/src/jarabe/model/buddy.py b/src/jarabe/model/buddy.py
index 8f17d7e..c9b6bcd 100644
--- a/src/jarabe/model/buddy.py
+++ b/src/jarabe/model/buddy.py
@@ -20,8 +20,6 @@ import logging
 import gobject
 import gconf
 import dbus
-from telepathy.client import Connection
-from telepathy.interfaces import CONNECTION
 
 from sugar.graphics.xocolor import XoColor
 from sugar.profile import get_profile
@@ -107,34 +105,19 @@ class OwnerBuddyModel(BaseBuddyModel):
         self.connect('notify::nick', self.__property_changed_cb)
         self.connect('notify::color', self.__property_changed_cb)
 
-        bus = dbus.SessionBus()
-        bus.add_signal_receiver(
-                self.__name_owner_changed_cb,
-                signal_name='NameOwnerChanged',
-                dbus_interface='org.freedesktop.DBus')
-
-        bus_object = bus.get_object(dbus.BUS_DAEMON_NAME, dbus.BUS_DAEMON_PATH)
-        for service in bus_object.ListNames(
-                dbus_interface=dbus.BUS_DAEMON_IFACE):
-            if service.startswith(CONNECTION + '.'):
-                path = '/%s' % service.replace('.', '/')
-                Connection(service, path, bus,
-                           ready_handler=self.__connection_ready_cb)
-
-    def __connection_ready_cb(self, connection):
-        self._sync_properties_on_connection(connection)
+        self._conn_watcher = connection_watcher.get_instance()
+        self._conn_watcher.connect('connection-added',
+                                   self.__connection_added_cb)
+        self._sync_properties()
 
-    def __name_owner_changed_cb(self, name, old, new):
-        if name.startswith(CONNECTION + '.') and not old and new:
-            path = '/' + name.replace('.', '/')
-            Connection(name, path, ready_handler=self.__connection_ready_cb)
+    def __connection_added_cb(self, conn_watcher, connection):
+        self._sync_properties_on_connection(connection)
 
     def __property_changed_cb(self, buddy, pspec):
         self._sync_properties()
 
     def _sync_properties(self):
-        conn_watcher = connection_watcher.get_instance()
-        for connection in conn_watcher.get_connections():
+        for connection in self._conn_watcher.get_connections():
             self._sync_properties_on_connection(connection)
 
     def _sync_properties_on_connection(self, connection):
@@ -157,9 +140,6 @@ class OwnerBuddyModel(BaseBuddyModel):
     def __error_handler_cb(self, error):
         raise RuntimeError(error)
 
-    def __connection_added_cb(self, conn_watcher, connection):
-        self._sync_properties_on_connection(connection)
-
     def is_owner(self):
         return True
 
-- 
1.7.4.4



More information about the Sugar-devel mailing list