From 1a32f508e70ccbfe2f9dad65260727222c7a727b Mon Sep 17 00:00:00 2001 From: Aleksey Lim Date: Thu, 11 Mar 2010 15:55:05 +0000 Subject: Use only one entry point for activity launch #1814 diff --git a/src/jarabe/desktop/activitieslist.py b/src/jarabe/desktop/activitieslist.py index 87f2af0..e14d0f7 100644 --- a/src/jarabe/desktop/activitieslist.py +++ b/src/jarabe/desktop/activitieslist.py @@ -36,6 +36,7 @@ from sugar.activity.activityhandle import ActivityHandle from jarabe.model import bundleregistry from jarabe.view.palettes import ActivityPalette from jarabe.view import launcher +from jarabe.journal import misc class ActivitiesTreeView(gtk.TreeView): __gtype_name__ = 'SugarActivitiesTreeView' @@ -143,13 +144,7 @@ class ActivitiesTreeView(gtk.TreeView): registry = bundleregistry.get_registry() bundle = registry.get_bundle(row[ListModel.COLUMN_BUNDLE_ID]) - activity_id = activityfactory.create_activity_id() - - client = gconf.client_get_default() - xo_color = XoColor(client.get_string('/desktop/sugar/user/color')) - - launcher.add_launcher(activity_id, bundle.get_icon(), xo_color) - activityfactory.create(bundle, ActivityHandle(activity_id)) + misc.launch(bundle) def set_filter(self, query): self._query = query.lower() diff --git a/src/jarabe/desktop/favoritesview.py b/src/jarabe/desktop/favoritesview.py index 9f3c37b..a843741 100644 --- a/src/jarabe/desktop/favoritesview.py +++ b/src/jarabe/desktop/favoritesview.py @@ -484,16 +484,7 @@ class ActivityIcon(CanvasIcon): if self._resume_mode and self._journal_entries: self._resume(self._journal_entries[0]) else: - client = gconf.client_get_default() - xo_color = XoColor(client.get_string('/desktop/sugar/user/color')) - - activity_id = activityfactory.create_activity_id() - launcher.add_launcher(activity_id, - self._activity_info.get_icon(), - xo_color) - - handle = ActivityHandle(activity_id) - activityfactory.create(self._activity_info, handle) + misc.launch(self._activity_info) def get_bundle_id(self): return self._activity_info.get_bundle_id() diff --git a/src/jarabe/desktop/meshbox.py b/src/jarabe/desktop/meshbox.py index a04922b..10aa514 100644 --- a/src/jarabe/desktop/meshbox.py +++ b/src/jarabe/desktop/meshbox.py @@ -47,12 +47,12 @@ from jarabe.desktop.spreadlayout import SpreadLayout from jarabe.desktop import keydialog from jarabe.model import bundleregistry from jarabe.model import network -from jarabe.model import shell from jarabe.model.network import Settings from jarabe.model.network import IP4Config from jarabe.model.network import WirelessSecurity from jarabe.model.network import AccessPoint from jarabe.model.olpcmesh import OlpcMeshManager +from jarabe.journal import misc _NM_SERVICE = 'org.freedesktop.NetworkManager' _NM_IFACE = 'org.freedesktop.NetworkManager' @@ -654,21 +654,11 @@ class ActivityView(hippo.CanvasBox): icon.destroy() def _clicked_cb(self, item): - shell_model = shell.get_model() - activity = shell_model.get_activity_by_id(self._model.get_id()) - if activity: - activity.get_window().activate(gtk.get_current_event_time()) - return - bundle_id = self._model.get_bundle_id() bundle = bundleregistry.get_registry().get_bundle(bundle_id) - launcher.add_launcher(self._model.get_id(), - bundle.get_icon(), - self._model.get_color()) - - handle = ActivityHandle(self._model.get_id()) - activityfactory.create(bundle, handle) + misc.launch(bundle, activity_id=self._model.get_id(), + color=self._model.get_color()) def set_filter(self, query): text_to_check = self._model.activity.props.name.lower() + \ diff --git a/src/jarabe/frame/activitiestray.py b/src/jarabe/frame/activitiestray.py index b5762ee..b7bf621 100644 --- a/src/jarabe/frame/activitiestray.py +++ b/src/jarabe/frame/activitiestray.py @@ -49,6 +49,7 @@ from jarabe.view.pulsingicon import PulsingIcon from jarabe.view import launcher from jarabe.frame.frameinvoker import FrameWidgetInvoker from jarabe.frame.notification import NotificationIcon +from jarabe.journal import misc import jarabe.frame @@ -164,22 +165,10 @@ class ActivityInviteButton(BaseInviteButton): def _launch(self): """Join the activity in the invite.""" - - shell_model = shell.get_model() - activity = shell_model.get_activity_by_id(self._activity_model.get_id()) - if activity: - activity.get_window().activate(gtk.get_current_event_time()) - return - registry = bundleregistry.get_registry() bundle = registry.get_bundle(self._bundle_id) - launcher.add_launcher(self._activity_model.get_id(), - bundle.get_icon(), - self._activity_model.get_color()) - - handle = ActivityHandle(self._activity_model.get_id()) - activityfactory.create(bundle, handle) + misc.launch(bundle, color=self._activity_model.get_color()) class PrivateInviteButton(BaseInviteButton): """Invite to a private one to one channel""" @@ -223,7 +212,7 @@ class PrivateInviteButton(BaseInviteButton): def _launch(self): """Start the activity with private channel.""" - activityfactory.create_with_uri(self._bundle, self._private_channel) + misc.launch(self._bundle, uri=self._private_channel) class BaseInvitePalette(Palette): """Palette for frame or notification icon for invites.""" @@ -272,8 +261,7 @@ class ActivityInvitePalette(BaseInvitePalette): self.set_primary_text(self._bundle_id) def _join(self): - handle = ActivityHandle(self._activity_model.get_id()) - activityfactory.create(self._bundle, handle) + misc.launch(self._bundle, activity_id=self._activity_model.get_id()) def _decline(self): invites = owner.get_model().get_invites() @@ -298,7 +286,7 @@ class PrivateInvitePalette(BaseInvitePalette): self.set_primary_text(self._bundle_id) def _join(self): - activityfactory.create_with_uri(self._bundle, self._private_channel) + misc.launch(self._bundle, uri=self._private_channel) invites = owner.get_model().get_invites() invites.remove_private_channel(self._private_channel) diff --git a/src/jarabe/journal/misc.py b/src/jarabe/journal/misc.py index 24ad216..65e5221 100644 --- a/src/jarabe/journal/misc.py +++ b/src/jarabe/journal/misc.py @@ -168,7 +168,7 @@ def resume(metadata, bundle_id=None): bundle.get_bundle_id()) installed_bundle = registry.get_bundle(bundle.get_bundle_id()) if installed_bundle: - activityfactory.create(installed_bundle) + launch(installed_bundle) else: logging.error('Bundle %r is not installed.', bundle.get_bundle_id()) @@ -192,17 +192,11 @@ def resume(metadata, bundle_id=None): logging.debug('activityfactory.creating with uri %s', uri) activity_bundle = registry.get_bundle(activities[0].get_bundle_id()) - activityfactory.create_with_uri(activity_bundle, bundle.get_start_uri()) + launch(activity_bundle, uri=uri) + else: activity_id = metadata.get('activity_id', '') - if activity_id: - shell_model = shell.get_model() - activity = shell_model.get_activity_by_id(activity_id) - if activity: - activity.get_window().activate(gtk.get_current_event_time()) - return - if bundle_id is None: activities = get_activities(metadata) if not activities: @@ -213,20 +207,36 @@ def resume(metadata, bundle_id=None): bundle = registry.get_bundle(bundle_id) - if metadata.get('mountpoint', '/') == '/': object_id = metadata['uid'] else: object_id = model.copy(metadata, '/') - if activity_id: - launcher.add_launcher(activity_id, bundle.get_icon(), - get_icon_color(metadata)) - handle = ActivityHandle(object_id=object_id, - activity_id=activity_id) - activityfactory.create(bundle, handle) - else: - activityfactory.create_with_object_id(bundle, object_id) + launch(bundle, activity_id=activity_id, object_id=object_id, + color=get_icon_color(metadata)) + +def launch(bundle, activity_id=None, object_id=None, uri=None, color=None): + if activity_id is None: + activity_id = activityfactory.create_activity_id() + + logging.debug('launch bundle_id=%s activity_id=%s object_id=%s uri=%s', + bundle.get_bundle_id(), activity_id, object_id, uri) + + shell_model = shell.get_model() + activity = shell_model.get_activity_by_id(activity_id) + if activity is not None: + logging.debug('re-launch %r', activity.get_window()) + activity.get_window().activate(gtk.get_current_event_time()) + return + + if color is None: + client = gconf.client_get_default() + color = XoColor(client.get_string('/desktop/sugar/user/color')) + + launcher.add_launcher(activity_id, bundle.get_icon(), color) + activity_handle = ActivityHandle(activity_id=activity_id, + object_id=object_id, uri=uri) + activityfactory.create(bundle, activity_handle) def is_activity_bundle(metadata): mime_type = metadata.get('mime_type', '') diff --git a/src/jarabe/model/shell.py b/src/jarabe/model/shell.py index e03e0f7..c1380d1 100644 --- a/src/jarabe/model/shell.py +++ b/src/jarabe/model/shell.py @@ -559,6 +559,11 @@ class ShellModel(gobject.GObject): raise ValueError("Activity service name '%s'" \ " was not found in the bundle registry." % service_name) + + home_activity = self.get_activity_by_id(activity_id) + if home_activity is not None: + self._remove_activity(home_activity) + home_activity = Activity(activity_info, activity_id) home_activity.props.launching = True self._add_activity(home_activity) diff --git a/src/jarabe/view/palettes.py b/src/jarabe/view/palettes.py index 2beceff..0c0e957 100644 --- a/src/jarabe/view/palettes.py +++ b/src/jarabe/view/palettes.py @@ -32,8 +32,8 @@ from sugar.activity import activityfactory from sugar.activity.activityhandle import ActivityHandle from jarabe.model import shell -from jarabe.view import launcher from jarabe.view.viewsource import setup_view_source +from jarabe.journal import misc class BasePalette(Palette): def __init__(self, home_activity): @@ -133,17 +133,7 @@ class ActivityPalette(Palette): def __start_activate_cb(self, menu_item): self.popdown(immediate=True) - - client = gconf.client_get_default() - xo_color = XoColor(client.get_string('/desktop/sugar/user/color')) - - activity_id = activityfactory.create_activity_id() - launcher.add_launcher(activity_id, - self._activity_info.get_icon(), - xo_color) - - handle = ActivityHandle(activity_id) - activityfactory.create(self._activity_info, handle) + misc.launch(self._activity_info) class JournalPalette(BasePalette): def __init__(self, home_activity): -- 1.6.5.3