services/presence/: Make Activities responsible for tracking their members.

Add a signal to notify the PS when all members have gone away.
This commit is contained in:
Simon McVittie 2007-05-29 16:12:05 +01:00
parent 9d812430bf
commit 6957446167
2 changed files with 19 additions and 9 deletions

View File

@ -48,8 +48,17 @@ class Activity(ExportedGObject):
__gtype_name__ = "Activity" __gtype_name__ = "Activity"
__gsignals__ = { __gsignals__ = {
'validity-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, 'validity-changed':
([gobject.TYPE_BOOLEAN])) # 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__ = { __gproperties__ = {
@ -381,6 +390,7 @@ class Activity(ExportedGObject):
""" """
if buddy not in self._buddies: if buddy not in self._buddies:
self._buddies.append(buddy) self._buddies.append(buddy)
buddy.add_activity(self)
if self.props.valid: if self.props.valid:
self.BuddyJoined(buddy.object_path()) self.BuddyJoined(buddy.object_path())
@ -396,9 +406,13 @@ class Activity(ExportedGObject):
""" """
if buddy in self._buddies: if buddy in self._buddies:
self._buddies.remove(buddy) self._buddies.remove(buddy)
buddy.remove_activity(self)
if self.props.valid: if self.props.valid:
self.BuddyLeft(buddy.object_path()) self.BuddyLeft(buddy.object_path())
if not self._buddies:
self.emit('disappeared')
def _handle_share_join(self, tp, text_channel): def _handle_share_join(self, tp, text_channel):
"""Called when a join to a network activity was successful. """Called when a join to a network activity was successful.

View File

@ -219,11 +219,12 @@ class PresenceService(ExportedGObject):
activity.connect("validity-changed", activity.connect("validity-changed",
self._activity_validity_changed_cb) self._activity_validity_changed_cb)
activity.connect("disappeared", self._activity_disappeared_cb)
self._activities[activity_id] = activity self._activities[activity_id] = activity
return activity return activity
def _remove_activity(self, activity): def _activity_disappeared_cb(self, activity):
_logger.debug("remove activity %s" % activity.props.id) _logger.debug("activity %s disappeared" % activity.props.id)
self.ActivityDisappeared(activity.object_path()) self.ActivityDisappeared(activity.object_path())
del self._activities[activity.props.id] del self._activities[activity.props.id]
@ -259,7 +260,6 @@ class PresenceService(ExportedGObject):
if activity is not None: if activity is not None:
activity.buddy_joined(buddy) activity.buddy_joined(buddy)
buddy.add_activity(activity)
activities_left = old_activities - new_activities activities_left = old_activities - new_activities
for act in activities_left: for act in activities_left:
@ -269,10 +269,6 @@ class PresenceService(ExportedGObject):
continue continue
activity.buddy_left(buddy) 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): def _activity_invitation(self, tp, act_id):
activity = self._activities.get(act_id) activity = self._activities.get(act_id)