[PATCH] Protected Activities Support

Martin Abente mabente at paraguayeduca.org
Thu Aug 19 13:55:21 EDT 2010


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.

More information at http://bugs.sugarlabs.org/ticket/2087

Signed-off-by: Martin Abente <mabente at paraguayeduca.org>
---
 data/sugar.schemas.in                |   14 ++++++++++++++
 src/jarabe/desktop/activitieslist.py |   17 +++++++++--------
 src/jarabe/model/bundleregistry.py   |    7 +++++++
 3 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/data/sugar.schemas.in b/data/sugar.schemas.in
index 2e6b820..5733627 100644
--- a/data/sugar.schemas.in
+++ b/data/sugar.schemas.in
@@ -343,5 +343,19 @@
       </locale>
     </schema>

+    <schema>
+      <key>/schemas/desktop/sugar/protected_activities</key>
+      <applyto>/desktop/sugar/protected_activities</applyto>
+      <owner>sugar</owner>
+      <type>list</type>
+      <list_type>string</list_type>
+      <default>[]</default>
+      <locale name="C">
+        <short>Protected Activities Bundle Indentifiers</short>
+        <long>Users will not be allowed to erase these
+        activities through the list view.</long>
+      </locale>
+    </schema>
+
   </schemalist>
 </gconfschemafile>
diff --git a/src/jarabe/desktop/activitieslist.py
b/src/jarabe/desktop/activitieslist.py
index c14d31e..3ad882f 100644
--- a/src/jarabe/desktop/activitieslist.py
+++ b/src/jarabe/desktop/activitieslist.py
@@ -400,14 +400,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.is_activity_protected(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 b96de86..1c839d7 100644
--- a/src/jarabe/model/bundleregistry.py
+++ b/src/jarabe/model/bundleregistry.py
@@ -19,6 +19,7 @@ import os
 import logging
 import traceback

+import gconf
 import gobject
 import gio
 import simplejson
@@ -66,6 +67,9 @@ class BundleRegistry(gobject.GObject):
         self._last_defaults_mtime = -1
         self._favorite_bundles = {}

+        client = gconf.client_get_default()
+        self._protected_activities =
client.get_list('/desktop/sugar/protected_activities',
+                                                      gconf.VALUE_STRING)
         try:
             self._load_favorites()
         except Exception:
@@ -312,6 +316,9 @@ class BundleRegistry(gobject.GObject):
         key = self._get_favorite_key(bundle_id, version)
         return key in self._favorite_bundles

+    def is_activity_protected(self, bundle_id):
+        return bundle_id in self._protected_activities
+
     def set_bundle_position(self, bundle_id, version, x, y):
         key = self._get_favorite_key(bundle_id, version)
         if key not in self._favorite_bundles:
-- 
1.6.0.4


More information about the Sugar-devel mailing list