diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2007-05-25 11:06:57 (GMT) |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2007-05-25 11:06:57 (GMT) |
commit | fdd8c315cf473731193187fb2b50a4b4a62c4928 (patch) | |
tree | c5cf1a28c231259d5407fa16e7f6d324775d8d90 /services | |
parent | 7b0d65a21147388790dc6e490d8735d93759762e (diff) |
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!
Diffstat (limited to 'services')
-rw-r--r-- | services/presence/buddy.py | 46 |
1 files changed, 10 insertions, 36 deletions
diff --git a/services/presence/buddy.py b/services/presence/buddy.py index b411270..714b816 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 |