Ticket #2087: 0001-Protected-activities-list.patch

File 0001-Protected-activities-list.patch, 4.3 KB (added by tch, 11 years ago)
  • data/Makefile.am

    From da2f3c80ed902e40270deb4b584ca654aea6b35d Mon Sep 17 00:00:00 2001
    From: Martin Abente <mabente@paraguayeduca.org>
    Date: Wed, 7 Jul 2010 11:32:30 -0400
    Subject: [PATCH] Protected activities list
    Organization: Paraguay Educa
    
    Does not allow sugar to display erase option
    for activities that are included in the
    activities.protected list.
    
    This feature was requested by many teachers
    from different diployments, in example Paraguay.
    ---
     data/Makefile.am                     |    1 +
     data/activities.protected            |   14 ++++++++++++++
     src/jarabe/desktop/activitieslist.py |   17 +++++++++--------
     src/jarabe/model/bundleregistry.py   |   19 +++++++++++++++++--
     4 files changed, 41 insertions(+), 10 deletions(-)
     create mode 100644 data/activities.protected
    
    diff --git a/data/Makefile.am b/data/Makefile.am
    index 6a62d23..e34930b 100644
    a b sugar-100.gtkrc: gtkrc.em 
    1111sugardir = $(pkgdatadir)/data
    1212sugar_DATA =                    \
    1313        activities.defaults     \
     14        activities.protected    \
    1415        kbdconfig               \
    1516        mime.defaults           \
    1617        GPLv2                   \
  • new file data/activities.protected

    diff --git a/data/activities.protected b/data/activities.protected
    new file mode 100644
    index 0000000..e3907ba
    - +  
     1# Protected activities list
     2
     3org.laptop.WebActivity
     4org.laptop.Calculate
     5org.laptop.Chat
     6org.vpri.EtoysActivity
     7org.laptop.ImageViewerActivity
     8org.laptop.sugar.Jukebox
     9org.laptop.Log
     10org.laptop.Pippy
     11org.laptop.sugar.ReadActivity
     12org.laptop.Terminal
     13org.laptop.TurtleArtActivity
     14org.laptop.AbiWordActivity
  • src/jarabe/desktop/activitieslist.py

    diff --git a/src/jarabe/desktop/activitieslist.py b/src/jarabe/desktop/activitieslist.py
    index 0bd5aab..ac9cadf 100644
    a b class ActivityListPalette(ActivityPalette): 
    405405        self.menu.append(self._favorite_item)
    406406        self._favorite_item.show()
    407407
    408         if activity_info.is_user_activity():
    409             menu_item = MenuItem(_('Erase'), 'list-remove')
    410             menu_item.connect('activate', self.__erase_activate_cb)
    411             self.menu.append(menu_item)
    412             menu_item.show()
    413 
    414             if not os.access(activity_info.get_path(), os.W_OK):
    415                 menu_item.props.sensitive = False
     408        if activity_info.is_user_activity() and \
     409            not registry.protects_activity(self._bundle_id):
     410                menu_item = MenuItem(_('Erase'), 'list-remove')
     411                menu_item.connect('activate', self.__erase_activate_cb)
     412                self.menu.append(menu_item)
     413                menu_item.show()
     414
     415                if not os.access(activity_info.get_path(), os.W_OK):
     416                    menu_item.props.sensitive = False
    416417
    417418        registry = bundleregistry.get_registry()
    418419        self._activity_changed_sid = registry.connect('bundle_changed',
  • src/jarabe/model/bundleregistry.py

    diff --git a/src/jarabe/model/bundleregistry.py b/src/jarabe/model/bundleregistry.py
    index ae42583..20b095e 100644
    a b class BundleRegistry(gobject.GObject): 
    6565
    6666        self._last_defaults_mtime = -1
    6767        self._favorite_bundles = {}
     68        self._protected_activities = []
    6869
    6970        try:
    7071            self._load_favorites()
    71         except Exception:
    72             logging.exception('Error while loading favorite_activities.')
     72            self._load_protected()
     73        except Exception, e:
     74            logging.exception('Error while loading activities defaults: %s' % str(e))
    7375
    7476        self._merge_default_favorites()
    7577
    class BundleRegistry(gobject.GObject): 
    126128            self._last_defaults_mtime = float(favorites_data['defaults-mtime'])
    127129            self._favorite_bundles = favorite_bundles
    128130
     131    def _load_protected(self):
     132        f = open(os.path.join(config.data_path, 'activities.protected'), 'r')
     133
     134        for line in f.readlines():
     135            line = line.strip()
     136            if line and not line.startswith('#'):
     137                self._protected_activities.append(line)
     138
     139        f.close()
     140
     141    def protects_activity(self, bundle_id):
     142        return (bundle_id in self._protected_activities)
     143
    129144    def _merge_default_favorites(self):
    130145        default_activities = []
    131146        defaults_path = os.path.join(config.data_path, 'activities.defaults')