Cleanup the Activity API, code needs more love.

This commit is contained in:
Marco Pesenti Gritti
2007-02-22 00:57:49 +01:00
parent 0d7bdeb20a
commit 0b6b6cd6ac
4 changed files with 15 additions and 57 deletions
+8 -22
View File
@@ -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
+6 -9
View File
@@ -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):
-17
View File
@@ -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)