Ticket #611: sugar-611.patch

File sugar-611.patch, 4.3 KB (added by alsroot, 14 years ago)
  • src/jarabe/journal/palettes.py

    From b22daa48b480a929344a0a9cd825d98e9f2ead94 Mon Sep 17 00:00:00 2001
    From: Aleksey Lim <alsroot@member.fsf.org>
    Date: Sun, 27 Sep 2009 00:49:14 +0000
    Subject: Resuming an ogg file from journal resumes Browse which just re-saves to journal again #611
    
    ---
     src/jarabe/journal/palettes.py     |    5 ++++
     src/jarabe/model/bundleregistry.py |   15 ++++++++++++-
     src/jarabe/model/mimeregistry.py   |   41 ++++++++++++++++++++++++++++++++++++
     3 files changed, 60 insertions(+), 1 deletions(-)
     create mode 100644 src/jarabe/model/mimeregistry.py
    
    diff --git a/src/jarabe/journal/palettes.py b/src/jarabe/journal/palettes.py
    index e0dfbf4..01017fc 100644
    a b from sugar import mime 
    3131from jarabe.model import bundleregistry
    3232from jarabe.model import friends
    3333from jarabe.model import filetransfer
     34from jarabe.model import mimeregistry
    3435from jarabe.journal import misc
    3536from jarabe.journal import model
    3637
    class StartWithMenu(gtk.Menu): 
    217218            menu_item.show()
    218219
    219220    def __item_activate_cb(self, menu_item, service_name):
     221        mime_type = self._metadata.get('mime_type', '')
     222        if mime_type:
     223            mime = mimeregistry.get_registry()
     224            mime.set_default_activity(mime_type, service_name)
    220225        misc.resume(self._metadata, service_name)
    221226
    222227
  • src/jarabe/model/bundleregistry.py

    diff --git a/src/jarabe/model/bundleregistry.py b/src/jarabe/model/bundleregistry.py
    index b754952..844caa8 100644
    a b from sugar.bundle.bundle import MalformedBundleException, \ 
    3131from sugar import env
    3232
    3333from jarabe import config
     34from jarabe.model import mimeregistry
    3435
    3536class BundleRegistry(gobject.GObject):
    3637    """Tracks the available activity bundles"""
    class BundleRegistry(gobject.GObject): 
    244245
    245246    def get_activities_for_type(self, mime_type):
    246247        result = []
     248
     249        mime = mimeregistry.get_registry()
     250        default_bundle_id = mime.get_default_activity(mime_type)
     251        default_bundle = None
     252
    247253        for bundle in self._bundles:
    248254            if bundle.get_mime_types() and mime_type in bundle.get_mime_types():
    249                 if self.get_default_for_type(mime_type) == \
     255
     256                if bundle.get_bundle_id() == default_bundle_id:
     257                    default_bundle = bundle
     258                elif self.get_default_for_type(mime_type) == \
    250259                        bundle.get_bundle_id():
    251260                    result.insert(0, bundle)
    252261                else:
    253262                    result.append(bundle)
     263
     264        if default_bundle is not None:
     265            result.insert(0, default_bundle)
     266
    254267        return result
    255268
    256269    def get_default_for_type(self, mime_type):
  • new file src/jarabe/model/mimeregistry.py

    diff --git a/src/jarabe/model/mimeregistry.py b/src/jarabe/model/mimeregistry.py
    new file mode 100644
    index 0000000..53480b2
    - +  
     1# Copyright (C) 2009 Aleksey Lim
     2#
     3# This program is free software; you can redistribute it and/or modify
     4# it under the terms of the GNU General Public License as published by
     5# the Free Software Foundation; either version 2 of the License, or
     6# (at your option) any later version.
     7#
     8# This program is distributed in the hope that it will be useful,
     9# but WITHOUT ANY WARRANTY; without even the implied warranty of
     10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11# GNU General Public License for more details.
     12#
     13# You should have received a copy of the GNU General Public License
     14# along with this program; if not, write to the Free Software
     15# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     16
     17import gconf
     18
     19
     20_DEFAULTS_KEY = '/desktop/sugar/journal/defaults'
     21_instance = None
     22
     23
     24class MimeRegistry(object):
     25
     26    def __init__(self):
     27        # TODO move here all mime_type related code from jarabe modules
     28        self._gconf = gconf.client_get_default()
     29
     30    def get_default_activity(self, mime_type):
     31        return self._gconf.get_string(_DEFAULTS_KEY + '/' + mime_type)
     32
     33    def set_default_activity(self, mime_type, bundle_id):
     34        self._gconf.set_string(_DEFAULTS_KEY + '/' + mime_type, bundle_id)
     35
     36
     37def get_registry():
     38    global _instance
     39    if _instance is None:
     40        _instance = MimeRegistry()
     41    return _instance