From 07a1ba636483f25ebf7b5fcc2f496dfb70ebb0ef Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 08 Jun 2007 15:03:12 +0000 Subject: Make GenericOwner responsible for setting its own activity/current-activity --- diff --git a/src/activity.py b/src/activity.py index 40c3ed9..8f7cff1 100644 --- a/src/activity.py +++ b/src/activity.py @@ -519,7 +519,7 @@ class Activity(ExportedGObject): def _joined_cb(self, text_channel): """XXX - not documented yet """ - self._tp.emit_joined_activity(self._id, self._room) + self._ps.owner.add_owner_activity(self._tp, self._id, self._room) verb = self._join_is_sharing and 'Share' or 'Join' diff --git a/src/buddy.py b/src/buddy.py index b550fc0..766fdfb 100644 --- a/src/buddy.py +++ b/src/buddy.py @@ -166,7 +166,8 @@ class Buddy(ExportedGObject): self._object_id = object_id self._object_path = dbus.ObjectPath(_BUDDY_PATH + object_id) - self._activities = {} # Activity ID -> Activity + #: activity ID -> activity + self._activities = {} self._activity_sigids = {} self.handles = {} # tp client -> handle @@ -569,6 +570,9 @@ class GenericOwner(Buddy): self._key_hash = kwargs.pop("key_hash", None) self._registered = kwargs.pop("registered", False) + #: Telepathy plugin -> dict { activity ID -> room handle } + self._activities_by_connection = {} + self._ip4_addr_monitor = psutils.IP4AddressMonitor.get_instance() self._ip4_addr_monitor.connect("address-changed", self._ip4_address_changed_cb) @@ -580,6 +584,54 @@ class GenericOwner(Buddy): self._bus = bus + def add_owner_activity(self, tp, activity_id, activity_room): + # FIXME: this probably duplicates something else (_activities?) + # but for now I'll keep the same duplication as before. + # Equivalent code used to be in ServerPlugin. + id_to_act = self._activities_by_connection.setdefault(tp, {}) + id_to_act[activity_id] = activity_room + + self._set_self_activities(tp) + + def _set_self_activities(self, tp): + """Forward set of joined activities to network + + uses SetActivities on BuddyInfo channel + """ + conn = tp.get_connection() + conn[CONN_INTERFACE_BUDDY_INFO].SetActivities( + self._activities_by_connection[tp].iteritems(), + reply_handler=_noop, + error_handler=lambda e: + _logger.warning("setting activities failed: %s", e)) + + def _set_self_current_activity(self, tp): + """Forward our current activity (or "") to network + """ + cur_activity = self._current_activity + if not cur_activity: + cur_activity = "" + cur_activity_handle = 0 + else: + id_to_act = self._activities_by_connection.setdefault(tp, {}) + cur_activity_handle = id_to_act.get(cur_activity) + if cur_activity_handle is None: + # don't advertise a current activity that's not shared on + # this connection + # FIXME: this gives us a different current activity on each + # connection - need to make sure clients are OK with this + # (at the moment, PS isn't!) + cur_activity = "" + + _logger.debug("Setting current activity to '%s' (handle %s)", + cur_activity, cur_activity_handle) + conn = tp.get_connection() + conn[CONN_INTERFACE_BUDDY_INFO].SetCurrentActivity(cur_activity, + cur_activity_handle, + reply_handler=_noop, + error_handler=lambda e: + _logger.warning("setting current activity failed: %s", e)) + def _set_self_alias(self, tp): self_handle = self.handles[tp] conn = tp.get_connection() @@ -610,9 +662,8 @@ class GenericOwner(Buddy): # Hack; send twice to make sure the server gets it gobject.timeout_add(1000, lambda: self._set_self_alias(tp_client)) - # FIXME: using private API, for now - tp_client._set_self_activities() - tp_client._set_self_current_activity() + self._set_self_activities(tp_client) + self._set_self_current_activity(tp_client) self._set_self_avatar(tp_client) @@ -660,7 +711,7 @@ class GenericOwner(Buddy): for tp in self.handles.iterkeys(): if changed_props.has_key("current-activity"): - tp._set_self_current_activity() + self._set_self_current_activity(tp) if changed_props.has_key("nick"): self._set_self_alias(tp) diff --git a/src/server_plugin.py b/src/server_plugin.py index 4a9d947..7d72c7a 100644 --- a/src/server_plugin.py +++ b/src/server_plugin.py @@ -142,8 +142,6 @@ class ServerPlugin(gobject.GObject): # activity id -> handle self._activities = {} - # (activity_id, handle of the activity channel) - self._joined_activities = [] self._owner = owner self.self_handle = None @@ -359,62 +357,16 @@ class ServerPlugin(gobject.GObject): self._conn[CONN_INTERFACE_PRESENCE].RequestPresence(subscribe_handles) return True - def emit_joined_activity(self, activity_id, room): - self._joined_activities.append((activity_id, room)) - self._set_self_activities() - def suggest_room_for_activity(self, activity_id): """Suggest a room to use to share the given activity. """ # FIXME: figure out why the server can't figure this out itself return activity_id + '@conference.' + self._account['server'] - def _ignore_success_cb(self): - """Ignore an event (null-operation)""" - def _log_error_cb(self, msg, err): """Log a message (error) at debug level with prefix msg""" _logger.debug("Error %s: %s", msg, err) - def _set_self_activities(self): - """Forward set of joined activities to network - - uses SetActivities on BuddyInfo channel - """ - self._conn[CONN_INTERFACE_BUDDY_INFO].SetActivities( - self._joined_activities, - reply_handler=self._ignore_success_cb, - error_handler=lambda e: self._log_error_cb("setting activities", e)) - - def _set_self_current_activity(self): - """Forward our current activity (or "") to network - - uses SetCurrentActivity on BuddyInfo channel - """ - cur_activity = self._owner.props.current_activity - cur_activity_handle = 0 - if not cur_activity: - cur_activity = "" - else: - cur_activity_handle = self._get_handle_for_activity(cur_activity) - if not cur_activity_handle: - # dont advertise a current activity that's not shared - cur_activity = "" - - _logger.debug("Setting current activity to '%s' (handle %s)", - cur_activity, cur_activity_handle) - self._conn[CONN_INTERFACE_BUDDY_INFO].SetCurrentActivity(cur_activity, - cur_activity_handle, - reply_handler=self._ignore_success_cb, - error_handler=lambda e: self._log_error_cb("setting current activity", e)) - - def _get_handle_for_activity(self, activity_id): - """Retrieve current handle for given activity or None""" - for (act, handle) in self._joined_activities: - if activity_id == act: - return handle - return None - def _reconnect_cb(self): """Attempt to reconnect to the server""" self.start() @@ -499,7 +451,6 @@ class ServerPlugin(gobject.GObject): for handle in self._online_contacts.keys(): self._contact_offline(handle) self._online_contacts = {} - self._joined_activities = [] self._activities = {} if self._reconnect_id > 0: -- cgit v0.9.1