[Sugar-devel] [PATCH] Added Protected-Activities-Support to sugar (SL#2087)

Kandarp Kaushik kandarp at seeta.in
Wed Sep 8 13:13:38 EDT 2010


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 |   24 +++++++++++++++---------
 src/jarabe/model/bundleregistry.py   |   11 +++++++++++
 3 files changed, 40 insertions(+), 9 deletions(-)

diff --git a/data/sugar.schemas.in b/data/sugar.schemas.in
index 2e6b820..cfa7edf 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>Bundle IDs of protected activities</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..f2ce7cb 100644
--- a/src/jarabe/desktop/activitieslist.py
+++ b/src/jarabe/desktop/activitieslist.py
@@ -400,22 +400,28 @@ 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()
+        self._add_erase_option( registry, activity_info )
 
-            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',
                 self.__activity_changed_cb)
         self._update_favorite_item()
 
         self.connect('destroy', self.__destroy_cb)
 
+    def _add_erase_option(self, registry, activity_info):
+        """Add Erase option to the GUI for user activities."""
+        if not activity_info.is_user_activity():
+            return
+        if registry.is_activity_protected(self._bundle_id):
+            return
+        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
+
     def __destroy_cb(self, palette):
         self.disconnect(self._activity_changed_sid)
 
diff --git a/src/jarabe/model/bundleregistry.py b/src/jarabe/model/bundleregistry.py
index b96de86..3e6b97a 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,13 @@ class BundleRegistry(gobject.GObject):
         self._last_defaults_mtime = -1
         self._favorite_bundles = {}
 
+        client = gconf.client_get_default()
+        try:
+            self._protected_activities = client.get_list('/desktop/sugar/protected_activities',
+                gconf.VALUE_STRING)
+        except Exception:
+            self._protected_activities = []
+
         try:
             self._load_favorites()
         except Exception:
@@ -312,6 +320,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.7.1



More information about the Sugar-devel mailing list