Ticket #1814: sugar-1814.patch

File sugar-1814.patch, 11.5 KB (added by alsroot, 13 years ago)
  • src/jarabe/desktop/activitieslist.py

    From 1a32f508e70ccbfe2f9dad65260727222c7a727b Mon Sep 17 00:00:00 2001
    From: Aleksey Lim <alsroot@member.fsf.org>
    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 b from sugar.activity.activityhandle import ActivityHandle 
    3636from jarabe.model import bundleregistry
    3737from jarabe.view.palettes import ActivityPalette
    3838from jarabe.view import launcher
     39from jarabe.journal import misc
    3940
    4041class ActivitiesTreeView(gtk.TreeView):
    4142    __gtype_name__ = 'SugarActivitiesTreeView'
    class ActivitiesTreeView(gtk.TreeView): 
    143144        registry = bundleregistry.get_registry()
    144145        bundle = registry.get_bundle(row[ListModel.COLUMN_BUNDLE_ID])
    145146
    146         activity_id = activityfactory.create_activity_id()
    147 
    148         client = gconf.client_get_default()
    149         xo_color = XoColor(client.get_string('/desktop/sugar/user/color'))
    150 
    151         launcher.add_launcher(activity_id, bundle.get_icon(), xo_color)
    152         activityfactory.create(bundle, ActivityHandle(activity_id))
     147        misc.launch(bundle)
    153148
    154149    def set_filter(self, query):
    155150        self._query = query.lower()
  • src/jarabe/desktop/favoritesview.py

    diff --git a/src/jarabe/desktop/favoritesview.py b/src/jarabe/desktop/favoritesview.py
    index 9f3c37b..a843741 100644
    a b class ActivityIcon(CanvasIcon): 
    484484        if self._resume_mode and self._journal_entries:
    485485            self._resume(self._journal_entries[0])
    486486        else:
    487             client = gconf.client_get_default()
    488             xo_color = XoColor(client.get_string('/desktop/sugar/user/color'))
    489 
    490             activity_id = activityfactory.create_activity_id()
    491             launcher.add_launcher(activity_id,
    492                                   self._activity_info.get_icon(),
    493                                   xo_color)
    494 
    495             handle = ActivityHandle(activity_id)
    496             activityfactory.create(self._activity_info, handle)
     487            misc.launch(self._activity_info)
    497488
    498489    def get_bundle_id(self):
    499490        return self._activity_info.get_bundle_id()
  • src/jarabe/desktop/meshbox.py

    diff --git a/src/jarabe/desktop/meshbox.py b/src/jarabe/desktop/meshbox.py
    index a04922b..10aa514 100644
    a b from jarabe.desktop.spreadlayout import SpreadLayout 
    4747from jarabe.desktop import keydialog
    4848from jarabe.model import bundleregistry
    4949from jarabe.model import network
    50 from jarabe.model import shell
    5150from jarabe.model.network import Settings
    5251from jarabe.model.network import IP4Config
    5352from jarabe.model.network import WirelessSecurity
    5453from jarabe.model.network import AccessPoint
    5554from jarabe.model.olpcmesh import OlpcMeshManager
     55from jarabe.journal import misc
    5656
    5757_NM_SERVICE = 'org.freedesktop.NetworkManager'
    5858_NM_IFACE = 'org.freedesktop.NetworkManager'
    class ActivityView(hippo.CanvasBox): 
    654654        icon.destroy()
    655655
    656656    def _clicked_cb(self, item):
    657         shell_model = shell.get_model()
    658         activity = shell_model.get_activity_by_id(self._model.get_id())
    659         if activity:
    660             activity.get_window().activate(gtk.get_current_event_time())
    661             return
    662 
    663657        bundle_id = self._model.get_bundle_id()
    664658        bundle = bundleregistry.get_registry().get_bundle(bundle_id)
    665659
    666         launcher.add_launcher(self._model.get_id(),
    667                               bundle.get_icon(),
    668                               self._model.get_color())
    669 
    670         handle = ActivityHandle(self._model.get_id())
    671         activityfactory.create(bundle, handle)
     660        misc.launch(bundle, activity_id=self._model.get_id(),
     661                color=self._model.get_color())
    672662
    673663    def set_filter(self, query):
    674664        text_to_check = self._model.activity.props.name.lower() + \
  • src/jarabe/frame/activitiestray.py

    diff --git a/src/jarabe/frame/activitiestray.py b/src/jarabe/frame/activitiestray.py
    index b5762ee..b7bf621 100644
    a b from jarabe.view.pulsingicon import PulsingIcon 
    4949from jarabe.view import launcher
    5050from jarabe.frame.frameinvoker import FrameWidgetInvoker
    5151from jarabe.frame.notification import NotificationIcon
     52from jarabe.journal import misc
    5253import jarabe.frame
    5354
    5455
    class ActivityInviteButton(BaseInviteButton): 
    164165
    165166    def _launch(self):
    166167        """Join the activity in the invite."""
    167 
    168         shell_model = shell.get_model()
    169         activity = shell_model.get_activity_by_id(self._activity_model.get_id())
    170         if activity:
    171             activity.get_window().activate(gtk.get_current_event_time())
    172             return
    173 
    174168        registry = bundleregistry.get_registry()
    175169        bundle = registry.get_bundle(self._bundle_id)
    176170
    177         launcher.add_launcher(self._activity_model.get_id(),
    178                               bundle.get_icon(),
    179                               self._activity_model.get_color())
    180 
    181         handle = ActivityHandle(self._activity_model.get_id())
    182         activityfactory.create(bundle, handle)
     171        misc.launch(bundle, color=self._activity_model.get_color())
    183172
    184173class PrivateInviteButton(BaseInviteButton):
    185174    """Invite to a private one to one channel"""
    class PrivateInviteButton(BaseInviteButton): 
    223212
    224213    def _launch(self):
    225214        """Start the activity with private channel."""
    226         activityfactory.create_with_uri(self._bundle, self._private_channel)
     215        misc.launch(self._bundle, uri=self._private_channel)
    227216
    228217class BaseInvitePalette(Palette):
    229218    """Palette for frame or notification icon for invites."""
    class ActivityInvitePalette(BaseInvitePalette): 
    272261            self.set_primary_text(self._bundle_id)
    273262
    274263    def _join(self):
    275         handle = ActivityHandle(self._activity_model.get_id())
    276         activityfactory.create(self._bundle, handle)
     264        misc.launch(self._bundle, activity_id=self._activity_model.get_id())
    277265
    278266    def _decline(self):
    279267        invites = owner.get_model().get_invites()
    class PrivateInvitePalette(BaseInvitePalette): 
    298286            self.set_primary_text(self._bundle_id)
    299287
    300288    def _join(self):
    301         activityfactory.create_with_uri(self._bundle, self._private_channel)
     289        misc.launch(self._bundle, uri=self._private_channel)
    302290
    303291        invites = owner.get_model().get_invites()
    304292        invites.remove_private_channel(self._private_channel)
  • src/jarabe/journal/misc.py

    diff --git a/src/jarabe/journal/misc.py b/src/jarabe/journal/misc.py
    index 24ad216..65e5221 100644
    a b def resume(metadata, bundle_id=None): 
    168168                        bundle.get_bundle_id())
    169169        installed_bundle = registry.get_bundle(bundle.get_bundle_id())
    170170        if installed_bundle:
    171             activityfactory.create(installed_bundle)
     171            launch(installed_bundle)
    172172        else:
    173173            logging.error('Bundle %r is not installed.',
    174174                          bundle.get_bundle_id())
    def resume(metadata, bundle_id=None): 
    192192        logging.debug('activityfactory.creating with uri %s', uri)
    193193
    194194        activity_bundle = registry.get_bundle(activities[0].get_bundle_id())
    195         activityfactory.create_with_uri(activity_bundle, bundle.get_start_uri())
     195        launch(activity_bundle, uri=uri)
     196
    196197    else:
    197198        activity_id = metadata.get('activity_id', '')
    198199
    199         if activity_id:
    200             shell_model = shell.get_model()
    201             activity = shell_model.get_activity_by_id(activity_id)
    202             if activity:
    203                 activity.get_window().activate(gtk.get_current_event_time())
    204                 return
    205 
    206200        if bundle_id is None:
    207201            activities = get_activities(metadata)
    208202            if not activities:
    def resume(metadata, bundle_id=None): 
    213207
    214208        bundle = registry.get_bundle(bundle_id)
    215209
    216 
    217210        if metadata.get('mountpoint', '/') == '/':
    218211            object_id = metadata['uid']
    219212        else:
    220213            object_id = model.copy(metadata, '/')
    221214
    222         if activity_id:
    223             launcher.add_launcher(activity_id, bundle.get_icon(),
    224                     get_icon_color(metadata))
    225             handle = ActivityHandle(object_id=object_id,
    226                                     activity_id=activity_id)
    227             activityfactory.create(bundle, handle)
    228         else:
    229             activityfactory.create_with_object_id(bundle, object_id)
     215        launch(bundle, activity_id=activity_id, object_id=object_id,
     216                color=get_icon_color(metadata))
     217
     218def launch(bundle, activity_id=None, object_id=None, uri=None, color=None):
     219    if activity_id is None:
     220        activity_id = activityfactory.create_activity_id()
     221
     222    logging.debug('launch bundle_id=%s activity_id=%s object_id=%s uri=%s',
     223            bundle.get_bundle_id(), activity_id, object_id, uri)
     224
     225    shell_model = shell.get_model()
     226    activity = shell_model.get_activity_by_id(activity_id)
     227    if activity is not None:
     228        logging.debug('re-launch %r', activity.get_window())
     229        activity.get_window().activate(gtk.get_current_event_time())
     230        return
     231
     232    if color is None:
     233        client = gconf.client_get_default()
     234        color = XoColor(client.get_string('/desktop/sugar/user/color'))
     235
     236    launcher.add_launcher(activity_id, bundle.get_icon(), color)
     237    activity_handle = ActivityHandle(activity_id=activity_id,
     238            object_id=object_id, uri=uri)
     239    activityfactory.create(bundle, activity_handle)
    230240
    231241def is_activity_bundle(metadata):
    232242    mime_type = metadata.get('mime_type', '')
  • src/jarabe/model/shell.py

    diff --git a/src/jarabe/model/shell.py b/src/jarabe/model/shell.py
    index e03e0f7..c1380d1 100644
    a b class ShellModel(gobject.GObject): 
    559559            raise ValueError("Activity service name '%s'" \
    560560                             " was not found in the bundle registry."
    561561                             % service_name)
     562
     563        home_activity = self.get_activity_by_id(activity_id)
     564        if home_activity is not None:
     565            self._remove_activity(home_activity)
     566
    562567        home_activity = Activity(activity_info, activity_id)
    563568        home_activity.props.launching = True
    564569        self._add_activity(home_activity)
  • src/jarabe/view/palettes.py

    diff --git a/src/jarabe/view/palettes.py b/src/jarabe/view/palettes.py
    index 2beceff..0c0e957 100644
    a b from sugar.activity import activityfactory 
    3232from sugar.activity.activityhandle import ActivityHandle
    3333
    3434from jarabe.model import shell
    35 from jarabe.view import launcher
    3635from jarabe.view.viewsource import setup_view_source
     36from jarabe.journal import misc
    3737
    3838class BasePalette(Palette):
    3939    def __init__(self, home_activity):
    class ActivityPalette(Palette): 
    133133
    134134    def __start_activate_cb(self, menu_item):
    135135        self.popdown(immediate=True)
    136 
    137         client = gconf.client_get_default()
    138         xo_color = XoColor(client.get_string('/desktop/sugar/user/color'))
    139 
    140         activity_id = activityfactory.create_activity_id()
    141         launcher.add_launcher(activity_id,
    142                               self._activity_info.get_icon(),
    143                               xo_color)
    144 
    145         handle = ActivityHandle(activity_id)
    146         activityfactory.create(self._activity_info, handle)
     136        misc.launch(self._activity_info)
    147137
    148138class JournalPalette(BasePalette):
    149139    def __init__(self, home_activity):