Ticket #2087: 0001-Protected-Activities-Support-2087.patch

File 0001-Protected-Activities-Support-2087.patch, 4.4 KB (added by tch, 11 years ago)
  • data/sugar.schemas.in

    From 4a35dee9424a40e600539f4a7c64e09d925aafa8 Mon Sep 17 00:00:00 2001
    From: Martin Abente <mabente@paraguayeduca.org>
    Date: Wed, 8 Sep 2010 11:11:07 -0400
    Subject: [PATCH] Protected Activities Support #2087
    Organization: Paraguay Educa
    
    Activities deletion causes troubles during classes. Teachers from
    Paraguay and Uruguay asked for a mechanism to protect activities
    from being easily deleted.
    
    This patch provides a mechanism that uses a gconf value to determine
    which activities will not contain the erase option at the list view
    palette.
    
    The gconf value contains a list of activities bundle indentifiers.
    ---
     data/sugar.schemas.in                |   14 ++++++++++++++
     src/jarabe/desktop/activitieslist.py |   22 ++++++++++++++--------
     src/jarabe/model/bundleregistry.py   |   10 ++++++++++
     3 files changed, 38 insertions(+), 8 deletions(-)
    
    diff --git a/data/sugar.schemas.in b/data/sugar.schemas.in
    index 2e6b820..cfa7edf 100644
    a b  
    343343      </locale>
    344344    </schema>
    345345
     346    <schema>
     347      <key>/schemas/desktop/sugar/protected_activities</key>
     348      <applyto>/desktop/sugar/protected_activities</applyto>
     349      <owner>sugar</owner>
     350      <type>list</type>
     351      <list_type>string</list_type>
     352      <default>[]</default>
     353      <locale name="C">
     354        <short>Bundle IDs of protected activities</short>
     355        <long>Users will not be allowed to erase these
     356        activities through the list view.</long>
     357      </locale>
     358    </schema>
     359
    346360  </schemalist>
    347361</gconfschemafile>
  • src/jarabe/desktop/activitieslist.py

    diff --git a/src/jarabe/desktop/activitieslist.py b/src/jarabe/desktop/activitieslist.py
    index c14d31e..a3246d7 100644
    a b class ActivityListPalette(ActivityPalette): 
    400400        self.menu.append(self._favorite_item)
    401401        self._favorite_item.show()
    402402
    403         if activity_info.is_user_activity():
    404             menu_item = MenuItem(_('Erase'), 'list-remove')
    405             menu_item.connect('activate', self.__erase_activate_cb)
    406             self.menu.append(menu_item)
    407             menu_item.show()
    408 
    409             if not os.access(activity_info.get_path(), os.W_OK):
    410                 menu_item.props.sensitive = False
     403        self._add_erase_option(registry, activity_info)
    411404
    412405        registry = bundleregistry.get_registry()
    413406        self._activity_changed_sid = registry.connect('bundle_changed',
    class ActivityListPalette(ActivityPalette): 
    416409
    417410        self.connect('destroy', self.__destroy_cb)
    418411
     412    def _add_erase_option(self, registry, activity_info):
     413        if not activity_info.is_user_activity():
     414            return
     415
     416        menu_item = MenuItem(_('Erase'), 'list-remove')
     417        menu_item.connect('activate', self.__erase_activate_cb)
     418        self.menu.append(menu_item)
     419        menu_item.show()
     420
     421        if not os.access(activity_info.get_path(), os.W_OK) or \
     422            registry.is_activity_protected(self._bundle_id):
     423                menu_item.props.sensitive = False
     424
    419425    def __destroy_cb(self, palette):
    420426        self.disconnect(self._activity_changed_sid)
    421427
  • src/jarabe/model/bundleregistry.py

    diff --git a/src/jarabe/model/bundleregistry.py b/src/jarabe/model/bundleregistry.py
    index b96de86..44f331a 100644
    a b import os 
    1919import logging
    2020import traceback
    2121
     22import gconf
    2223import gobject
    2324import gio
    2425import simplejson
    class BundleRegistry(gobject.GObject): 
    6667        self._last_defaults_mtime = -1
    6768        self._favorite_bundles = {}
    6869
     70        client = gconf.client_get_default()
     71        self._protected_activities = client.get_list('/desktop/sugar/protected_activities',
     72                                                    gconf.VALUE_STRING)
     73        if self._protected_activities is None:
     74            self._protected_activities = []
     75
    6976        try:
    7077            self._load_favorites()
    7178        except Exception:
    class BundleRegistry(gobject.GObject): 
    312319        key = self._get_favorite_key(bundle_id, version)
    313320        return key in self._favorite_bundles
    314321
     322    def is_activity_protected(self, bundle_id):
     323        return bundle_id in self._protected_activities
     324
    315325    def set_bundle_position(self, bundle_id, version, x, y):
    316326        key = self._get_favorite_key(bundle_id, version)
    317327        if key not in self._favorite_bundles: