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

2010-09-08 Thread Kandarp Kaushik
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
+  ownersugar/owner
+  typelist/type
+  list_typestring/list_type
+  default[]/default
+  locale name=C
+shortBundle IDs of protected activities/short
+longUsers 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

___
Sugar-devel mailing list
Sugar-devel@lists.sugarlabs.org
http://lists.sugarlabs.org/listinfo/sugar-devel


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

2010-09-08 Thread Sascha Silbe
Excerpts from Kandarp Kaushik's message of Wed Sep 08 19:13:38 +0200 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.

s/at the list view palette/in the Home View/

The Home View might support additional layouts in the future that show
the erase option as well.

[data/sugar.schemas.in]
 +longUsers will not be allowed to erase these
 +activities through the list view./long

Dito.

[src/jarabe/desktop/activitieslist.py]
 +self._add_erase_option( registry, activity_info )

Please remove the extra spaces after / before parentheses. pylint would
have told you this.

 +if not activity_info.is_user_activity():
 +return
 +if registry.is_activity_protected(self._bundle_id):
 +return

A newline at this point (i.e. after the last guard) would improve
readability IMO.

[src/jarabe/model/bundleregistry.py]
 +try:
 +self._protected_activities = 
 client.get_list('/desktop/sugar/protected_activities',

Line too long (80 chars is the limit). Just put the string literal on the
next line, indented by four additional spaces. If it fits, merge in the
remaining part.

 +gconf.VALUE_STRING)
 +except Exception:
 +self._protected_activities = []

Please only catch specific exceptions, otherwise you might hide some
failures / bugs.

Have we reached consensus on the design, BTW? The patch still hides
the erase option instead of deactivating it.

Sascha

--
http://sascha.silbe.org/
http://www.infra-silbe.de/


signature.asc
Description: PGP signature
___
Sugar-devel mailing list
Sugar-devel@lists.sugarlabs.org
http://lists.sugarlabs.org/listinfo/sugar-devel


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

2010-09-08 Thread Daniel Drake
On 8 September 2010 11:13, Kandarp Kaushik kand...@seeta.in wrote:
 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.

Your efforts to help move tickets along are appreciated but you are
adding disruption to the process.

Where a review process has started on trac, please keep the patch
reviews on trac.
(sending an email with a link to the ticket, requesting on-trac review
is of course acceptable and a good idea where review has stalled)

In this case we have multiple people working on the same bug with
different versions of the same patch being submitted in 2 different
places on the same day.

You have also erased authorship information which is not a very nice
gesture to the original developer.

To reviewers: my suggestion is to ignore the patch in this thread,
review the latest version of the patch on trac:
http://bugs.sugarlabs.org/ticket/2087
The one on trac incorporates feedback from the design team, is a tiny
bit cleaner, and retains correct authorship information.

Daniel
___
Sugar-devel mailing list
Sugar-devel@lists.sugarlabs.org
http://lists.sugarlabs.org/listinfo/sugar-devel