From 19c8532d09fe19d27ef4b6822e0e0ed9e478bf28 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 20 Jul 2007 11:15:11 +0000 Subject: Ensure activity uniquness in the shell --- (limited to 'sugar/activity/activityfactory.py') diff --git a/sugar/activity/activityfactory.py b/sugar/activity/activityfactory.py index d1480b2..fe2a8bd 100644 --- a/sugar/activity/activityfactory.py +++ b/sugar/activity/activityfactory.py @@ -90,24 +90,32 @@ class ActivityCreationHandler(gobject.GObject): self._activity_handle = activity_handle bus = dbus.SessionBus() + + bus_object = bus.get_object(_SHELL_SERVICE, _SHELL_PATH) + self._shell = dbus.Interface(bus_object, _SHELL_IFACE) + object_path = '/' + service_name.replace('.', '/') proxy_obj = bus.get_object(service_name, object_path, follow_name_owner_changes=True) - factory = dbus.Interface(proxy_obj, _ACTIVITY_FACTORY_INTERFACE) + self._factory = dbus.Interface(proxy_obj, _ACTIVITY_FACTORY_INTERFACE) - factory.create(self._activity_handle.get_dict(), - reply_handler=self._no_reply_handler, - error_handler=self._create_error_handler) - - bus = dbus.SessionBus() - bus_object = bus.get_object(_SHELL_SERVICE, _SHELL_PATH) - self._shell = dbus.Interface(bus_object, _SHELL_IFACE) + if self.get_activity_id() != None: + self._shell.ActivateActivity(self.get_activity_id(), + reply_handler=self._activate_reply_handler, + error_handler=self._activate_error_handler) + else: + self._launch_activity() + def _launch_activity(self): self._shell.NotifyLaunch( - service_name, self.get_activity_id(), + self._service_name, self.get_activity_id(), reply_handler=self._no_reply_handler, error_handler=self._notify_launch_error_handler) + self._factory.create(self._activity_handle.get_dict(), + reply_handler=self._no_reply_handler, + error_handler=self._create_error_handler) + def get_activity_id(self): """Retrieve the unique identity for this activity""" return self._activity_handle.activity_id @@ -121,6 +129,13 @@ class ActivityCreationHandler(gobject.GObject): def _notify_launch_error_handler(self, err): logging.debug('Notify launch failed %s' % err) + def _activate_reply_handler(self, activated): + if not activated: + self._launch_activity() + + def _activate_error_handler(self, err): + logging.debug("Activity activation request failed %s" % err) + def _create_reply_handler(self, xid): logging.debug("Activity created %s (%s)." % (self._activity_handle.activity_id, self._service_name)) -- cgit v0.9.1