From cfb054124936cd8256703ed172a9417b7fe3811e Mon Sep 17 00:00:00 2001 From: Morgan Collett Date: Tue, 21 Aug 2007 11:39:05 +0100 Subject: [PATCH 1/4] Clean up leave() and callbacks --- sugar/presence/activity.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sugar/presence/activity.py b/sugar/presence/activity.py index 2df8793d..bdfc74f5 100644 --- a/sugar/presence/activity.py +++ b/sugar/presence/activity.py @@ -167,16 +167,17 @@ class Activity(gobject.GObject): return bus_name, connection, channels def _leave_cb(self): - # XXX Is this the right thing to do? + """Callback for async action of leaving shared activity.""" self.emit("joined", False, "left activity") def _leave_error_cb(self, err): - # XXX We are closing down anyway + """Callback for error in async leaving of shared activity. + + XXX Add logging!""" pass def leave(self): """Leave this shared activity""" - # FIXME self._joined = False self._activity.Leave(reply_handler=self._leave_cb, error_handler=self._leave_error_cb) From d09b8d3ea43bb877c39e0f2e169cf3d885521ff2 Mon Sep 17 00:00:00 2001 From: Morgan Collett Date: Tue, 21 Aug 2007 12:08:33 +0100 Subject: [PATCH 2/4] Document _share_activity_cb --- sugar/presence/presenceservice.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sugar/presence/presenceservice.py b/sugar/presence/presenceservice.py index 4a92dd30..81835fc8 100644 --- a/sugar/presence/presenceservice.py +++ b/sugar/presence/presenceservice.py @@ -357,7 +357,11 @@ class PresenceService(gobject.GObject): return self._new_object(owner_op) def _share_activity_cb(self, activity, op): - """Notify with GObject event of successful sharing of activity""" + """Notify with GObject event of successful sharing of activity + + op -- full dbus path of the new object, must be + prefixed with either of _PS_BUDDY_OP or _PS_ACTIVITY_OP + """ psact = self._new_object(op) psact._joined = True self.emit("activity-shared", True, psact, None) From 52f2bea3ed542e65f22664b5c837280fdab6960d Mon Sep 17 00:00:00 2001 From: Morgan Collett Date: Wed, 22 Aug 2007 15:54:12 +0100 Subject: [PATCH 3/4] Use new PresenceService API for sharing by invitation only --- sugar/activity/activity.py | 21 +++++++++++++++------ sugar/presence/presenceservice.py | 13 +++++++++---- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/sugar/activity/activity.py b/sugar/activity/activity.py index 553b1a1a..f63174a7 100644 --- a/sugar/activity/activity.py +++ b/sugar/activity/activity.py @@ -448,13 +448,22 @@ class Activity(Window, gtk.Container): self._shared_activity = activity self.emit('shared') - def share(self): - """Request that the activity be shared on the network.""" + def share(self, private=False): + """Request that the activity be shared on the network. + + private -- bool: True to share by invitation only, + False to advertise as shared to everyone. + """ + # FIXME: Make private=True to turn on the by-invitation-only scope if self._shared_activity and self._shared_activity.props.joined: - raise RuntimeError("Activity %s already shared." % self._activity_id) - logging.debug('Requesting share of activity %s.' % self._activity_id) - self._share_id = self._pservice.connect("activity-shared", self._internal_share_cb) - self._pservice.share_activity(self) + raise RuntimeError("Activity %s already shared." % + self._activity_id) + verb = private and 'private' or 'public' + logging.debug('Requesting %s share of activity %s.' % + (verb, self._activity_id)) + self._share_id = self._pservice.connect("activity-shared", + self._internal_share_cb) + self._pservice.share_activity(self, private) def _realize_cb(self, window): wm.set_bundle_id(window.window, self.get_service_name()) diff --git a/sugar/presence/presenceservice.py b/sugar/presence/presenceservice.py index 81835fc8..238012d2 100644 --- a/sugar/presence/presenceservice.py +++ b/sugar/presence/presenceservice.py @@ -371,10 +371,14 @@ class PresenceService(gobject.GObject): _logger.debug("Error sharing activity %s: %s" % (activity.get_id(), err)) self.emit("activity-shared", False, None, err) - def share_activity(self, activity, properties={}): - """Ask presence service to ask the activity to share itself + def share_activity(self, activity, private=True): + """Ask presence service to ask the activity to share itself publicly. + + activity -- sugar.activity.activity.Activity instance + private -- bool: True to share by invitation only, + False to advertise as shared to everyone. - Uses the ShareActivity method on the service to ask for the + Uses the AdvertiseActivity method on the service to ask for the sharing of the given activity. Arranges to emit activity-shared event with: @@ -395,7 +399,8 @@ class PresenceService(gobject.GObject): atype = activity.get_service_name() name = activity.props.title - self._ps.ShareActivity(actid, atype, name, properties, + # FIXME: Test, then make this AdvertiseActivity: + self._ps.ShareActivity(actid, atype, name, private, reply_handler=lambda *args: self._share_activity_cb(activity, *args), error_handler=lambda *args: self._share_activity_error_cb(activity, *args)) From d2261e405136845217a8f769995ebeb832b9ffac Mon Sep 17 00:00:00 2001 From: Morgan Collett Date: Thu, 23 Aug 2007 13:48:16 +0100 Subject: [PATCH 4/4] Fix sharing publicly --- sugar/activity/activity.py | 2 +- sugar/presence/presenceservice.py | 29 +++++++++++++++++++---------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/sugar/activity/activity.py b/sugar/activity/activity.py index eea76a8d..3f782b51 100644 --- a/sugar/activity/activity.py +++ b/sugar/activity/activity.py @@ -484,7 +484,7 @@ class Activity(Window, gtk.Container): (verb, self._activity_id)) self._share_id = self._pservice.connect("activity-shared", self._internal_share_cb) - self._pservice.share_activity(self, private) + self._pservice.share_activity(self, private=private) def _realize_cb(self, window): wm.set_bundle_id(window.window, self.get_service_name()) diff --git a/sugar/presence/presenceservice.py b/sugar/presence/presenceservice.py index 238012d2..f4f102d7 100644 --- a/sugar/presence/presenceservice.py +++ b/sugar/presence/presenceservice.py @@ -371,12 +371,8 @@ class PresenceService(gobject.GObject): _logger.debug("Error sharing activity %s: %s" % (activity.get_id(), err)) self.emit("activity-shared", False, None, err) - def share_activity(self, activity, private=True): + def share_activity(self, activity, properties={}, private=True): """Ask presence service to ask the activity to share itself publicly. - - activity -- sugar.activity.activity.Activity instance - private -- bool: True to share by invitation only, - False to advertise as shared to everyone. Uses the AdvertiseActivity method on the service to ask for the sharing of the given activity. Arranges to emit activity-shared @@ -389,20 +385,33 @@ class PresenceService(gobject.GObject): returns None """ actid = activity.get_id() + _logger.debug('XXXX in share_activity') # Ensure the activity is not already shared/joined for obj in self._objcache.values(): if not isinstance(object, Activity): continue if obj.props.id == actid or obj.props.joined: - raise RuntimeError("Activity %s is already shared." % actid) + raise RuntimeError("Activity %s is already shared." % + actid) atype = activity.get_service_name() name = activity.props.title - # FIXME: Test, then make this AdvertiseActivity: - self._ps.ShareActivity(actid, atype, name, private, - reply_handler=lambda *args: self._share_activity_cb(activity, *args), - error_handler=lambda *args: self._share_activity_error_cb(activity, *args)) + if private: + _logger.debug('XXXX private, so calling InviteActivity') + self._ps.InviteActivity(actid, atype, name, properties, + reply_handler=lambda *args: \ + self._share_activity_cb(activity, *args), + error_handler=lambda *args: \ + self._share_activity_error_cb(activity, *args)) + else: + # FIXME: Test, then make this AdvertiseActivity: + _logger.debug('XXXX not private, so calling ShareActivity') + self._ps.ShareActivity(actid, atype, name, properties, + reply_handler=lambda *args: \ + self._share_activity_cb(activity, *args), + error_handler=lambda *args: \ + self._share_activity_error_cb(activity, *args)) def get_preferred_connection(self): """Gets the preferred telepathy connection object that an activity