[Sugar-devel] [PATCH] Protected-Activities-Support.3
Kandarp Kaushik
kandarp at seeta.in
Sat Sep 4 15:41:10 EDT 2010
---
data/sugar.schemas.in | 14 ++++++++++++++
src/jarabe/desktop/activitieslist.py | 23 +++++++++++++++--------
src/jarabe/model/bundleregistry.py | 11 +++++++++++
3 files changed, 40 insertions(+), 8 deletions(-)
diff --git a/data/sugar.schemas.in b/data/sugar.schemas.in
index b9606ba..9b4ec87 100644
--- a/data/sugar.schemas.in
+++ b/data/sugar.schemas.in
@@ -329,5 +329,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 e14d0f7..4d5d3c5 100644
--- a/src/jarabe/desktop/activitieslist.py
+++ b/src/jarabe/desktop/activitieslist.py
@@ -400,14 +400,7 @@ 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
+ self._add_erase_option( activity_info )
registry = bundleregistry.get_registry()
self._activity_changed_sid = registry.connect('bundle_changed',
@@ -416,6 +409,20 @@ class ActivityListPalette(ActivityPalette):
self.connect('destroy', self.__destroy_cb)
+ def _add_erase_option(self, activity_info):
+ """Add Erase option to the GUI for user or unprotected 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 86a2738..2eb2ed4 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
@@ -65,6 +66,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()
@@ -302,6 +310,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