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

File 0001-Protected-Activities-Support-2087.patch.2, 4.3 KB (added by tch, 11 years ago)
Line 
1From 5a63e31ef7a2ef0fc1dbc266dccb2fce4954d770 Mon Sep 17 00:00:00 2001
2From: Martin Abente <mabente@paraguayeduca.org>
3Date: Wed, 8 Sep 2010 11:11:07 -0400
4Subject: [PATCH] Protected Activities Support #2087
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---
17 data/sugar.schemas.in                |   14 ++++++++++++++
18 src/jarabe/desktop/activitieslist.py |   18 +++++++++++-------
19 src/jarabe/model/bundleregistry.py   |   12 ++++++++++++
20 3 files changed, 37 insertions(+), 7 deletions(-)
21
22diff --git a/data/sugar.schemas.in b/data/sugar.schemas.in
23index 2e6b820..cfa7edf 100644
24--- a/data/sugar.schemas.in
25+++ b/data/sugar.schemas.in
26@@ -343,5 +343,19 @@
27       </locale>
28     </schema>
29 
30+    <schema>
31+      <key>/schemas/desktop/sugar/protected_activities</key>
32+      <applyto>/desktop/sugar/protected_activities</applyto>
33+      <owner>sugar</owner>
34+      <type>list</type>
35+      <list_type>string</list_type>
36+      <default>[]</default>
37+      <locale name="C">
38+        <short>Bundle IDs of protected activities</short>
39+        <long>Users will not be allowed to erase these
40+        activities through the list view.</long>
41+      </locale>
42+    </schema>
43+
44   </schemalist>
45 </gconfschemafile>
46diff --git a/src/jarabe/desktop/activitieslist.py b/src/jarabe/desktop/activitieslist.py
47index c14d31e..56b3b5f 100644
48--- a/src/jarabe/desktop/activitieslist.py
49+++ b/src/jarabe/desktop/activitieslist.py
50@@ -401,13 +401,7 @@ class ActivityListPalette(ActivityPalette):
51         self._favorite_item.show()
52 
53         if activity_info.is_user_activity():
54-            menu_item = MenuItem(_('Erase'), 'list-remove')
55-            menu_item.connect('activate', self.__erase_activate_cb)
56-            self.menu.append(menu_item)
57-            menu_item.show()
58-
59-            if not os.access(activity_info.get_path(), os.W_OK):
60-                menu_item.props.sensitive = False
61+            self._add_erase_option(registry, activity_info)
62 
63         registry = bundleregistry.get_registry()
64         self._activity_changed_sid = registry.connect('bundle_changed',
65@@ -416,6 +410,16 @@ class ActivityListPalette(ActivityPalette):
66 
67         self.connect('destroy', self.__destroy_cb)
68 
69+    def _add_erase_option(self, registry, activity_info):
70+        menu_item = MenuItem(_('Erase'), 'list-remove')
71+        menu_item.connect('activate', self.__erase_activate_cb)
72+        self.menu.append(menu_item)
73+        menu_item.show()
74+
75+        if not os.access(activity_info.get_path(), os.W_OK) or \
76+            registry.is_activity_protected(self._bundle_id):
77+                menu_item.props.sensitive = False
78+
79     def __destroy_cb(self, palette):
80         self.disconnect(self._activity_changed_sid)
81 
82diff --git a/src/jarabe/model/bundleregistry.py b/src/jarabe/model/bundleregistry.py
83index b96de86..699e339 100644
84--- a/src/jarabe/model/bundleregistry.py
85+++ b/src/jarabe/model/bundleregistry.py
86@@ -19,6 +19,7 @@ import os
87 import logging
88 import traceback
89 
90+import gconf
91 import gobject
92 import gio
93 import simplejson
94@@ -66,6 +67,14 @@ class BundleRegistry(gobject.GObject):
95         self._last_defaults_mtime = -1
96         self._favorite_bundles = {}
97 
98+        client = gconf.client_get_default()
99+        self._protected_activities = client.get_list(
100+                                    '/desktop/sugar/protected_activities',
101+                                     gconf.VALUE_STRING)
102+
103+        if self._protected_activities is None:
104+            self._protected_activities = []
105+
106         try:
107             self._load_favorites()
108         except Exception:
109@@ -312,6 +321,9 @@ class BundleRegistry(gobject.GObject):
110         key = self._get_favorite_key(bundle_id, version)
111         return key in self._favorite_bundles
112 
113+    def is_activity_protected(self, bundle_id):
114+        return bundle_id in self._protected_activities
115+
116     def set_bundle_position(self, bundle_id, version, x, y):
117         key = self._get_favorite_key(bundle_id, version)
118         if key not in self._favorite_bundles:
119--
1201.6.0.4
121