diff --git a/sugar/activity/activity.py b/sugar/activity/activity.py index 53602536..a15c846f 100644 --- a/sugar/activity/activity.py +++ b/sugar/activity/activity.py @@ -62,6 +62,7 @@ class Activity(Window, gtk.Container): self._activity_id = handle.activity_id self._pservice = presenceservice.get_instance() self._service = None + self._share_sigid = None service = handle.get_presence_service() if service: @@ -100,11 +101,20 @@ class Activity(Window, gtk.Container): self._service.join() self.present() + def _share_cb(self, ps, success, service, err): + self._pservice.disconnect(self._share_sigid) + if success: + logging.debug('Share of activity %s successful.' % self.get_id()) + self._service = service + self._shared = True + else: + logging.debug('Share of activity %s failed: %s.' % (self.get_id(), err)) + def share(self): - """Share the activity on the network.""" - logging.debug('Share activity %s on the network.' % self.get_id()) - self._service = self._pservice.share_activity(self) - self._shared = True + """Request that the activity be shared on the network.""" + logging.debug('Requesting share of activity %s.' % self.get_id()) + self._share_sigid = self._pservice.connect("activity-shared", self._share_cb) + self._pservice.share_activity(self) def execute(self, command, args): """Execute the given command with args""" diff --git a/sugar/presence/presenceservice.py b/sugar/presence/presenceservice.py index 604439b4..9b7bd3c3 100644 --- a/sugar/presence/presenceservice.py +++ b/sugar/presence/presenceservice.py @@ -16,6 +16,7 @@ # Boston, MA 02111-1307, USA. import dbus, dbus.glib, gobject +import logging import buddy, activity @@ -59,7 +60,10 @@ class PresenceService(gobject.GObject): 'activity-appeared': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])), 'activity-disappeared': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, - ([gobject.TYPE_PYOBJECT])) + ([gobject.TYPE_PYOBJECT])), + 'activity-shared': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, + ([gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT, + gobject.TYPE_PYOBJECT])) } _PS_BUDDY_OP = DBUS_PATH + "/Buddies/" @@ -178,12 +182,20 @@ class PresenceService(gobject.GObject): return None return self._new_object(owner_op) + def _share_activity_cb(self, activity, op): + self.emit("activity-shared", True, self._new_object(op), None) + + def _share_activity_error_cb(self, activity, err): + logging.debug("Error sharing activity %s: %s" % (activity.get_id(), err)) + self.emit("activity-shared", False, None, err) + def share_activity(self, activity, properties={}): actid = activity.get_id() atype = activity.get_service_name() name = activity.props.title - serv_op = self._ps.ShareActivity(actid, atype, name, properties) - return self._new_object(serv_op) + 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)) class _MockPresenceService(gobject.GObject):