From 0b6b6cd6acfedd3bfc326623ad0ccff21c5c4d5e Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Wed, 21 Feb 2007 23:57:49 +0000 Subject: Cleanup the Activity API, code needs more love. --- (limited to 'sugar') diff --git a/sugar/activity/activity.py b/sugar/activity/activity.py index befcc31..3b7d9ce 100644 --- a/sugar/activity/activity.py +++ b/sugar/activity/activity.py @@ -26,16 +26,19 @@ from sugar import env class Activity(gtk.Window): """Base Activity class that all other Activities derive from.""" - def __init__(self, activity_handle): + def __init__(self, handle): gtk.Window.__init__(self) self.connect('destroy', self._destroy_cb) self._shared = False - self._activity_id = None - self._service = None + self._activity_id = handle.activity_id self._pservice = PresenceService.get_instance() + service = handle.get_presence_service() + if service: + self._join(service) + self.realize() group = gtk.Window() @@ -44,14 +47,6 @@ class Activity(gtk.Window): self._bus = ActivityService(self) - def start(self, activity_id): - """Start the activity.""" - if self._activity_id != None: - logging.warning('The activity has been already started.') - return - - self._activity_id = activity_id - self.present() def get_type(self): @@ -70,13 +65,8 @@ class Activity(gtk.Window): """Get the unique activity identifier.""" return self._activity_id - def join(self, activity_ps): - """Join an activity shared on the network.""" - if self._activity_id != None: - logging.warning('The activity has been already started.') - return - self._activity_id = activity_ps.get_id() - + def _join(self, service): + self._service = service self._shared = True # Publish the default service, it's a copy of @@ -103,10 +93,6 @@ class Activity(gtk.Window): self._service = self._pservice.share_activity(self, default_type) self._shared = True - def execute(self, command, args): - """Execute the given command with args""" - return False - def _destroy_cb(self, window): if self._bus: del self._bus diff --git a/sugar/activity/activityfactory.py b/sugar/activity/activityfactory.py index 6148466..90b49f7 100644 --- a/sugar/activity/activityfactory.py +++ b/sugar/activity/activityfactory.py @@ -36,14 +36,13 @@ class ActivityCreationHandler(gobject.GObject): 'error': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])), - 'success': (gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - ([gobject.TYPE_PYOBJECT])) } def __init__(self, service_name, activity_handle): gobject.GObject.__init__(self) + self._service_name = service_name + if activity_handle: self._activity_handle = activity_handle else: @@ -91,14 +90,12 @@ class ActivityCreationHandler(gobject.GObject): return act_id def _reply_handler(self, xid): - bus = dbus.SessionBus() - proxy_obj = bus.get_object(_ACTIVITY_SERVICE_NAME + '%d' % xid, - _ACTIVITY_SERVICE_PATH + "/%s" % xid) - activity = dbus.Interface(proxy_obj, _ACTIVITY_INTERFACE) - self.emit('success', activity) + logging.debug("Activity created %s (%s)." % + (self._activity_handle.activity_id, self._service_name)) def _error_handler(self, err): - logging.debug("Couldn't create activity: %s" % err) + logging.debug("Couldn't create activity %s (%s): %s" % + (self._activity_handle.activity_id, self._service_name, err)) self.emit('error', err) def create(service_name, activity_handle=None): diff --git a/sugar/activity/activityservice.py b/sugar/activity/activityservice.py index 5c1654a..c5a99e0 100644 --- a/sugar/activity/activityservice.py +++ b/sugar/activity/activityservice.py @@ -40,18 +40,6 @@ class ActivityService(dbus.service.Object): dbus.service.Object.__init__(self, bus_name, object_path) self._activity = activity - self._pservice = PresenceService.get_instance() - - @dbus.service.method(_ACTIVITY_INTERFACE) - def start(self, activity_id): - """Start the activity in unshared mode.""" - self._activity.start(activity_id) - - @dbus.service.method(_ACTIVITY_INTERFACE) - def join(self, activity_ps_path): - """Join the activity specified by its presence service path.""" - activity_ps = self._pservice.get(activity_ps_path) - return self._activity.join(activity_ps) @dbus.service.method(_ACTIVITY_INTERFACE) def share(self): @@ -72,8 +60,3 @@ class ActivityService(dbus.service.Object): def get_shared(self): """Returns True if the activity is shared on the mesh.""" return self._activity.get_shared() - - @dbus.service.method(_ACTIVITY_INTERFACE, - in_signature="sas", out_signature="b") - def execute(self, command, args): - return self._activity.execute(command, args) -- cgit v0.9.1