From fdd8c315cf473731193187fb2b50a4b4a62c4928 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 25 May 2007 12:06:57 +0100 Subject: [PATCH] services/presence/buddy: Use add_signal_receiver to connect signals. This means we don't need to care whether the Sugar shell is actually running - if it is, we'll get its signals, and if it's not, obviously it can't send us any signals! --- services/presence/buddy.py | 46 +++++++++----------------------------- 1 file changed, 10 insertions(+), 36 deletions(-) diff --git a/services/presence/buddy.py b/services/presence/buddy.py index b411270a..714b8165 100644 --- a/services/presence/buddy.py +++ b/services/presence/buddy.py @@ -605,48 +605,22 @@ class ShellOwner(GenericOwner): nick=nick, color=color, icon=icon, server=server, key_hash=key_hash, registered=registered) - # Connect to the shell to get notifications on Owner object - # property changes - try: - self._connect_to_shell() - except dbus.DBusException: - pass + # Ask to get notifications on Owner object property changes in the + # shell. If it's not currently running, no problem - we'll get the + # signals when it does run + for (signal, cb) in (('IconChanged', self._icon_changed_cb), + ('ColorChanged', self._color_changed_cb), + ('NickChanged', self._nick_changed_cb)): + self._bus.add_signal_receiver(cb, signal_name=signal, + dbus_interface=self._SHELL_OWNER_INTERFACE, + bus_name=self._SHELL_SERVICE, + path=self._SHELL_PATH) def set_registered(self, value): """Handle notification that we have been registered""" if value: profile.set_server_registered() - def _name_owner_changed_cb(self, name, old, new): - # chain up to superclass - GenericOwner._name_owner_changed_cb(self, name, old, new) - - if name != self._SHELL_SERVICE: - return - if (old and len(old)) and (not new and not len(new)): - # shell went away - self._shell_owner = None - elif (not old and not len(old)) and (new and len(new)): - # shell started - self._connect_to_shell() - - def _connect_to_shell(self): - """Connect to the Sugar Shell service to watch for events - - Connects the various XChanged events on the Sugar Shell - service to our _x_changed_cb methods. - """ - obj = self._bus.get_object(self._SHELL_SERVICE, self._SHELL_PATH) - self._shell_owner = dbus.Interface(obj, self._SHELL_OWNER_INTERFACE) - self._shell_owner.connect_to_signal('IconChanged', - self._icon_changed_cb) - self._shell_owner.connect_to_signal('ColorChanged', - self._color_changed_cb) - self._shell_owner.connect_to_signal('NickChanged', - self._nick_changed_cb) - self._shell_owner.connect_to_signal('CurrentActivityChanged', - self._cur_activity_changed_cb) - def _icon_changed_cb(self, icon): """Handle icon change, set property to generate event""" self.props.icon = icon