From 6957446167d756f9edd86d54e90dbfbb8a6f7809 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 29 May 2007 16:12:05 +0100 Subject: [PATCH] services/presence/: Make Activities responsible for tracking their members. Add a signal to notify the PS when all members have gone away. --- services/presence/activity.py | 18 ++++++++++++++++-- services/presence/presenceservice.py | 10 +++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/services/presence/activity.py b/services/presence/activity.py index be60f1e2..0743b2b8 100644 --- a/services/presence/activity.py +++ b/services/presence/activity.py @@ -48,8 +48,17 @@ class Activity(ExportedGObject): __gtype_name__ = "Activity" __gsignals__ = { - 'validity-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, - ([gobject.TYPE_BOOLEAN])) + 'validity-changed': + # The activity's validity has changed. + # An activity is valid if its name, color, type and ID have been + # set. + # Arguments: + # validity: bool + (gobject.SIGNAL_RUN_FIRST, None, [bool]), + 'disappeared': + # Nobody is in this activity any more. + # No arguments. + (gobject.SIGNAL_RUN_FIRST, None, []), } __gproperties__ = { @@ -381,6 +390,7 @@ class Activity(ExportedGObject): """ if buddy not in self._buddies: self._buddies.append(buddy) + buddy.add_activity(self) if self.props.valid: self.BuddyJoined(buddy.object_path()) @@ -396,9 +406,13 @@ class Activity(ExportedGObject): """ if buddy in self._buddies: self._buddies.remove(buddy) + buddy.remove_activity(self) if self.props.valid: self.BuddyLeft(buddy.object_path()) + if not self._buddies: + self.emit('disappeared') + def _handle_share_join(self, tp, text_channel): """Called when a join to a network activity was successful. diff --git a/services/presence/presenceservice.py b/services/presence/presenceservice.py index 4f84a3b2..84814f08 100644 --- a/services/presence/presenceservice.py +++ b/services/presence/presenceservice.py @@ -219,11 +219,12 @@ class PresenceService(ExportedGObject): activity.connect("validity-changed", self._activity_validity_changed_cb) + activity.connect("disappeared", self._activity_disappeared_cb) self._activities[activity_id] = activity return activity - def _remove_activity(self, activity): - _logger.debug("remove activity %s" % activity.props.id) + def _activity_disappeared_cb(self, activity): + _logger.debug("activity %s disappeared" % activity.props.id) self.ActivityDisappeared(activity.object_path()) del self._activities[activity.props.id] @@ -259,7 +260,6 @@ class PresenceService(ExportedGObject): if activity is not None: activity.buddy_joined(buddy) - buddy.add_activity(activity) activities_left = old_activities - new_activities for act in activities_left: @@ -269,10 +269,6 @@ class PresenceService(ExportedGObject): continue activity.buddy_left(buddy) - buddy.remove_activity(activity) - - if not activity.get_joined_buddies(): - self._remove_activity(activity) def _activity_invitation(self, tp, act_id): activity = self._activities.get(act_id)