Subject: [PATCH] Protected activities list

From: Martin Abente <[email-masked]>
Date: Wed, 7 Jul 2010 11:32:30 -0400

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/data/Makefile.am
+++ b/data/Makefile.am
@@ -11,6 +11,7 @@ sugar-100.gtkrc: gtkrc.em
 sugardir = $(pkgdatadir)/data
 sugar_DATA =			\
 	activities.defaults	\
+	activities.protected	\
 	kbdconfig		\
 	mime.defaults		\
 	GPLv2			\
diff --git a/data/activities.protected b/data/activities.protected
new file mode 100644
index 0000000..e3907ba
--- /dev/null
+++ b/data/activities.protected
@@ -0,0 +1,14 @@
+# Protected activities list
+
+org.laptop.WebActivity
+org.laptop.Calculate
+org.laptop.Chat
+org.vpri.EtoysActivity
+org.laptop.ImageViewerActivity
+org.laptop.sugar.Jukebox
+org.laptop.Log
+org.laptop.Pippy
+org.laptop.sugar.ReadActivity
+org.laptop.Terminal
+org.laptop.TurtleArtActivity
+org.laptop.AbiWordActivity
diff --git a/src/jarabe/desktop/activitieslist.py b/src/jarabe/desktop/activitieslist.py
index 0bd5aab..ac9cadf 100644
--- a/src/jarabe/desktop/activitieslist.py
+++ b/src/jarabe/desktop/activitieslist.py
@@ -405,14 +405,15 @@ class ActivityListPalette(ActivityPalette):
         self.menu.append(self._favorite_item)
         self._favorite_item.show()
 
-        if activity_info.is_user_activity():
-            menu_item = MenuItem(_('Erase'), 'list-remove')
-            menu_item.connect('activate', self.__erase_activate_cb)
-            self.menu.append(menu_item)
-            menu_item.show()
-
-            if not os.access(activity_info.get_path(), os.W_OK):
-                menu_item.props.sensitive = False
+        if activity_info.is_user_activity() and \
+            not registry.protects_activity(self._bundle_id):
+                menu_item = MenuItem(_('Erase'), 'list-remove')
+                menu_item.connect('activate', self.__erase_activate_cb)
+                self.menu.append(menu_item)
+                menu_item.show()
+
+                if not os.access(activity_info.get_path(), os.W_OK):
+                    menu_item.props.sensitive = False
 
         registry = bundleregistry.get_registry()
         self._activity_changed_sid = registry.connect('bundle_changed',
diff --git a/src/jarabe/model/bundleregistry.py b/src/jarabe/model/bundleregistry.py
index ae42583..20b095e 100644
--- a/src/jarabe/model/bundleregistry.py
+++ b/src/jarabe/model/bundleregistry.py
@@ -65,11 +65,13 @@ class BundleRegistry(gobject.GObject):
 
         self._last_defaults_mtime = -1
         self._favorite_bundles = {}
+        self._protected_activities = []
 
         try:
             self._load_favorites()
-        except Exception:
-            logging.exception('Error while loading favorite_activities.')
+            self._load_protected()
+        except Exception, e:
+            logging.exception('Error while loading activities defaults: %s' % str(e))
 
         self._merge_default_favorites()
 
@@ -126,6 +128,19 @@ class BundleRegistry(gobject.GObject):
             self._last_defaults_mtime = float(favorites_data['defaults-mtime'])
             self._favorite_bundles = favorite_bundles
 
+    def _load_protected(self):
+        f = open(os.path.join(config.data_path, 'activities.protected'), 'r')
+
+        for line in f.readlines():
+            line = line.strip()
+            if line and not line.startswith('#'):
+                self._protected_activities.append(line)
+
+        f.close()
+
+    def protects_activity(self, bundle_id):
+        return (bundle_id in self._protected_activities)
+
     def _merge_default_favorites(self):
         default_activities = []
         defaults_path = os.path.join(config.data_path, 'activities.defaults')
-- 
1.6.0.4