diff options
author | Dan Williams <dcbw@localhost.localdomain> | 2007-01-06 21:29:13 (GMT) |
---|---|---|
committer | Dan Williams <dcbw@localhost.localdomain> | 2007-01-06 21:29:13 (GMT) |
commit | b27257fadb7f198c3072a2480c3711b7b57cd43f (patch) | |
tree | 23d80f2d28dd20a2cb0c7e2808e5f2fba452b730 /shell/view | |
parent | f50d9f5f9a972f7149c4a57f225e00d7e48834c6 (diff) |
Make shell responsible for activity ID generation
Enables tracking of activity launch throughout the whole process, so that
the shell can be aware of the activity ID from the moment the activity
is started by the shell, until the activity becomes active. Previously,
the activity itself generated its own ID and told the shell what it was.
Diffstat (limited to 'shell/view')
-rw-r--r-- | shell/view/Shell.py | 51 | ||||
-rw-r--r-- | shell/view/clipboardicon.py | 3 |
2 files changed, 48 insertions, 6 deletions
diff --git a/shell/view/Shell.py b/shell/view/Shell.py index f3f6ca0..169ee35 100644 --- a/shell/view/Shell.py +++ b/shell/view/Shell.py @@ -68,6 +68,8 @@ class Shell(gobject.GObject): self._frame = Frame(self) self._frame.show_and_hide(3) + self._pservice = PresenceService.get_instance() + #self.start_activity('org.laptop.JournalActivity') def _handle_camera_key(self): @@ -190,13 +192,11 @@ class Shell(gobject.GObject): return self._model def join_activity(self, bundle_id, activity_id): - pservice = PresenceService.get_instance() - activity = self.get_activity(activity_id) if activity: activity.present() else: - activity_ps = pservice.get_activity(activity_id) + activity_ps = self._pservice.get_activity(activity_id) if activity_ps: # Get the service name for this activity, if @@ -218,10 +218,51 @@ class Shell(gobject.GObject): else: logging.error('Cannot start activity.') + def _find_unique_activity_id(self): + # create a new unique activity ID + i = 0 + act_id = None + while i < 10: + act_id = sugar.util.unique_id() + i += 1 + + # check through existing activities + found = False + for xid, act_host in self._hosts.items(): + if act_host.get_id() == act_id: + found = True + break + if found: + act_id = None + continue + + # check through network activities + activities = self._pservice.get_activities() + for act in activities: + if act_id == act.get_id(): + found = True + break + if found: + act_id = None + continue + + return act_id + def start_activity(self, activity_type): logging.debug('Shell.start_activity') - activity = ActivityFactory.create(activity_type) - activity.start() + act_id = self._find_unique_activity_id() + if not act_id: + logging.error("Couldn't find available activity ID.") + return None + + try: + logging.debug("Shell.start_activity will start %s:%s" % (activity_type, act_id)) + activity = ActivityFactory.create(activity_type) + except dbus.DBusException, e: + logging.debug("Couldn't start activity '%s':\n %s" % (activity_type, e)) + return None + + activity.start(act_id) return activity def set_zoom_level(self, level): diff --git a/shell/view/clipboardicon.py b/shell/view/clipboardicon.py index ade37bd..4e702d3 100644 --- a/shell/view/clipboardicon.py +++ b/shell/view/clipboardicon.py @@ -4,6 +4,7 @@ from sugar.graphics.menuicon import MenuIcon from view.clipboardmenu import ClipboardMenu from sugar.activity import ActivityFactory from sugar.clipboard import clipboardservice +from sugar import util class ClipboardIcon(MenuIcon): @@ -53,7 +54,7 @@ class ClipboardIcon(MenuIcon): if activity_id: activity = ActivityFactory.create(activity_id) - activity.start() + activity.start(util.unique_id()) activity.execute("open_document", [self._object_id]) def _popup_action_cb(self, popup, action): |