From 7c4201fc25846bd2405fc5f9098b16602fa7adfe Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 11 Jun 2007 16:51:49 +0000 Subject: Make PresenceService, rather than ServerPlugin, responsible for watching D-Bus buddy properties --- diff --git a/src/presenceservice.py b/src/presenceservice.py index 22e76c3..c8f4cb2 100644 --- a/src/presenceservice.py +++ b/src/presenceservice.py @@ -26,7 +26,7 @@ from dbus.gobject_service import ExportedGObject from dbus.mainloop.glib import DBusGMainLoop from telepathy.client import ManagerRegistry, Connection from telepathy.interfaces import (CONN_MGR_INTERFACE, CONN_INTERFACE, - CONN_INTERFACE_AVATARS) + CONN_INTERFACE_AVATARS, CONN_INTERFACE_ALIASING) from telepathy.constants import (CONNECTION_STATUS_CONNECTING, CONNECTION_STATUS_CONNECTED, CONNECTION_STATUS_DISCONNECTED) @@ -113,8 +113,6 @@ class PresenceService(ExportedGObject): self._server_plugin.connect('status', self._server_status_cb) self._server_plugin.connect('contact-online', self._contact_online) self._server_plugin.connect('contact-offline', self._contact_offline) - self._server_plugin.connect('buddy-properties-changed', - self._buddy_properties_changed) self._server_plugin.connect('activity-invitation', self._activity_invitation) self._server_plugin.connect('private-invitation', @@ -178,12 +176,40 @@ class PresenceService(ExportedGObject): 'ActivitiesChanged', buddy_activities_changed) self._conn_matches[conn].append(m) + if CONN_INTERFACE_BUDDY_INFO in conn: + def buddy_properties_changed(contact, properties): + self._buddy_properties_changed(tp, contact, properties) + m = conn[CONN_INTERFACE_BUDDY_INFO].connect_to_signal( + 'PropertiesChanged', buddy_properties_changed) + self._conn_matches[conn].append(m) + + def buddy_curact_changed(contact, act_id, room): + if (act_id == '' or not util.validate_activity_id(act_id) or + room == 0): + act_id = '' + room = 0 + self._buddy_properties_changed(tp, contact, + {'current-activity': act_id}) + # FIXME: do something useful with the room handle? + m = conn[CONN_INTERFACE_BUDDY_INFO].connect_to_signal( + 'CurrentActivityChanged', buddy_curact_changed) + self._conn_matches[conn].append(m) + def avatar_updated(contact, avatar_token): self._avatar_updated(tp, contact, avatar_token) m = conn[CONN_INTERFACE_AVATARS].connect_to_signal('AvatarUpdated', avatar_updated) self._conn_matches[conn].append(m) + if CONN_INTERFACE_ALIASING in conn: + def aliases_changed(aliases): + for contact, alias in aliases: + self._buddy_properties_changed(tp, contact, + {'nick': alias}) + m = conn[CONN_INTERFACE_ALIASING].connect_to_signal( + 'AliasesChanged', aliases_changed) + self._conn_matches[conn].append(m) + def _tp_disconnected(self, tp): if tp.self_handle is not None: self._handles_buddies.setdefault(tp, {}).pop( diff --git a/src/server_plugin.py b/src/server_plugin.py index b1060b2..c50b877 100644 --- a/src/server_plugin.py +++ b/src/server_plugin.py @@ -84,13 +84,6 @@ class ServerPlugin(gobject.GObject): # Connection status changed. # args: status, reason as for Telepathy StatusChanged (gobject.SIGNAL_RUN_FIRST, None, [int, int]), - 'buddy-properties-changed': - # OLPC buddy properties changed; as for PropertiesChanged - # args: - # contact handle: int - # properties: dict {name: str => property: object} - # FIXME: are these all the properties or just those that changed? - (gobject.SIGNAL_RUN_FIRST, None, [object, object]), 'activity-invitation': # We were invited to join an activity # args: @@ -328,18 +321,6 @@ class ServerPlugin(gobject.GObject): _logger.debug('OLPC information not available') return False - m = self._conn[CONN_INTERFACE_BUDDY_INFO].connect_to_signal( - 'PropertiesChanged', self._buddy_properties_changed_cb) - self._matches.append(m) - m = self._conn[CONN_INTERFACE_BUDDY_INFO].connect_to_signal( - 'CurrentActivityChanged', - self._buddy_current_activity_changed_cb) - self._matches.append(m) - - self._conn[CONN_INTERFACE_ALIASING].connect_to_signal('AliasesChanged', - self._alias_changed_cb) - self._matches.append(m) - # Request presence for everyone we're subscribed to self._conn[CONN_INTERFACE_PRESENCE].RequestPresence(subscribe_handles) return True @@ -542,42 +523,6 @@ class ServerPlugin(gobject.GObject): for handle in now_offline: self._contact_offline(handle) - def _alias_changed_cb(self, aliases): - """Handle update of aliases for all users""" - for handle, alias in aliases: - prop = {'nick': alias} - #print "Buddy %s alias changed to %s" % (handle, alias) - if (self._online_contacts.has_key(handle) and - self._online_contacts[handle]): - self._buddy_properties_changed_cb(handle, prop) - - def _buddy_properties_changed_cb(self, handle, properties): - """Handle update of given user (handle)'s properties""" - if handle == self._conn[CONN_INTERFACE].GetSelfHandle(): - # ignore network events for Owner property changes since those - # are handled locally - return - if (self._online_contacts.has_key(handle) and - self._online_contacts[handle]): - self.emit("buddy-properties-changed", handle, properties) - - def _buddy_current_activity_changed_cb(self, handle, activity, channel): - """Handle update of given user (handle)'s current activity""" - - if handle == self._conn[CONN_INTERFACE].GetSelfHandle(): - # ignore network events for Owner current activity changes since - # those are handled locally - return - if (not self._online_contacts.has_key(handle) or - not self._online_contacts[handle]): - return - - if not len(activity) or not util.validate_activity_id(activity): - activity = None - prop = {'current-activity': activity} - _logger.debug("Handle %s: current activity now %s", handle, activity) - self._buddy_properties_changed_cb(handle, prop) - def _new_channel_cb(self, object_path, channel_type, handle_type, handle, suppress_handler): """Handle creation of a new channel -- cgit v0.9.1