Ticket #2087: 0001-Protected-Activities-Support.patch.2

File 0001-Protected-Activities-Support.patch.2, 4.1 KB (added by tch, 11 years ago)
Line 
1From 47678b9155b0c7d970e2c503aadb6e9024317473 Mon Sep 17 00:00:00 2001
2From: Martin Abente <mabente@paraguayeduca.org>
3Date: Thu, 19 Aug 2010 13:55:21 -0400
4Subject: [PATCH] Protected Activities Support
5Organization: Paraguay Educa
6
7Activities deletion causes troubles during classes. Teachers from
8Paraguay and Uruguay asked for a mechanism to protect activities
9from being easily deleted.
10
11This patch provides a mechanism that uses a gconf value to determine
12which activities will not contain the erase option at the list view
13palette.
14
15The gconf value contains a list of activities bundle indentifiers.
16
17More information at http://bugs.sugarlabs.org/ticket/2087
18
19Signed-off-by: Martin Abente <mabente@paraguayeduca.org>
20---
21 data/sugar.schemas.in                |   14 ++++++++++++++
22 src/jarabe/desktop/activitieslist.py |   17 +++++++++--------
23 src/jarabe/model/bundleregistry.py   |    7 +++++++
24 3 files changed, 30 insertions(+), 8 deletions(-)
25
26diff --git a/data/sugar.schemas.in b/data/sugar.schemas.in
27index 2e6b820..5733627 100644
28--- a/data/sugar.schemas.in
29+++ b/data/sugar.schemas.in
30@@ -343,5 +343,19 @@
31       </locale>
32     </schema>
33 
34+    <schema>
35+      <key>/schemas/desktop/sugar/protected_activities</key>
36+      <applyto>/desktop/sugar/protected_activities</applyto>
37+      <owner>sugar</owner>
38+      <type>list</type>
39+      <list_type>string</list_type>
40+      <default>[]</default>
41+      <locale name="C">
42+        <short>Protected Activities Bundle Indentifiers</short>
43+        <long>Users will not be allowed to erase these
44+        activities through the list view.</long>
45+      </locale>
46+    </schema>
47+
48   </schemalist>
49 </gconfschemafile>
50diff --git a/src/jarabe/desktop/activitieslist.py b/src/jarabe/desktop/activitieslist.py
51index c14d31e..3ad882f 100644
52--- a/src/jarabe/desktop/activitieslist.py
53+++ b/src/jarabe/desktop/activitieslist.py
54@@ -400,14 +400,15 @@ class ActivityListPalette(ActivityPalette):
55         self.menu.append(self._favorite_item)
56         self._favorite_item.show()
57 
58-        if activity_info.is_user_activity():
59-            menu_item = MenuItem(_('Erase'), 'list-remove')
60-            menu_item.connect('activate', self.__erase_activate_cb)
61-            self.menu.append(menu_item)
62-            menu_item.show()
63-
64-            if not os.access(activity_info.get_path(), os.W_OK):
65-                menu_item.props.sensitive = False
66+        if activity_info.is_user_activity() and \
67+            not registry.is_activity_protected(self._bundle_id):
68+                menu_item = MenuItem(_('Erase'), 'list-remove')
69+                menu_item.connect('activate', self.__erase_activate_cb)
70+                self.menu.append(menu_item)
71+                menu_item.show()
72+
73+                if not os.access(activity_info.get_path(), os.W_OK):
74+                    menu_item.props.sensitive = False
75 
76         registry = bundleregistry.get_registry()
77         self._activity_changed_sid = registry.connect('bundle_changed',
78diff --git a/src/jarabe/model/bundleregistry.py b/src/jarabe/model/bundleregistry.py
79index b96de86..1c839d7 100644
80--- a/src/jarabe/model/bundleregistry.py
81+++ b/src/jarabe/model/bundleregistry.py
82@@ -19,6 +19,7 @@ import os
83 import logging
84 import traceback
85 
86+import gconf
87 import gobject
88 import gio
89 import simplejson
90@@ -66,6 +67,9 @@ class BundleRegistry(gobject.GObject):
91         self._last_defaults_mtime = -1
92         self._favorite_bundles = {}
93 
94+        client = gconf.client_get_default()
95+        self._protected_activities = client.get_list('/desktop/sugar/protected_activities',
96+                                                      gconf.VALUE_STRING)
97         try:
98             self._load_favorites()
99         except Exception:
100@@ -312,6 +316,9 @@ class BundleRegistry(gobject.GObject):
101         key = self._get_favorite_key(bundle_id, version)
102         return key in self._favorite_bundles
103 
104+    def is_activity_protected(self, bundle_id):
105+        return bundle_id in self._protected_activities
106+
107     def set_bundle_position(self, bundle_id, version, x, y):
108         key = self._get_favorite_key(bundle_id, version)
109         if key not in self._favorite_bundles:
110--
1111.6.0.4
112