From 47678b9155b0c7d970e2c503aadb6e9024317473 Mon Sep 17 00:00:00 2001
From: Martin Abente <mabente@paraguayeduca.org>
Date: Thu, 19 Aug 2010 13:55:21 -0400
Subject: [PATCH] Protected Activities Support
Organization: Paraguay Educa
Activities deletion causes troubles during classes. Teachers from
Paraguay and Uruguay asked for a mecanism to protect activities
from being easily deleted.
This patch provides a mecanism 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.
More information at http://bugs.sugarlabs.org/ticket/2087
Signed-off-by: Martin Abente <mabente@paraguayeduca.org>
---
data/sugar.schemas.in | 14 ++++++++++++++
src/jarabe/desktop/activitieslist.py | 17 +++++++++--------
src/jarabe/model/bundleregistry.py | 7 +++++++
3 files changed, 30 insertions(+), 8 deletions(-)
diff --git a/data/sugar.schemas.in b/data/sugar.schemas.in
index 2e6b820..5733627 100644
a
|
b
|
|
343 | 343 | </locale> |
344 | 344 | </schema> |
345 | 345 | |
| 346 | <schema> |
| 347 | <key>/schemas/desktop/sugar/protected_activities</key> |
| 348 | <applyto>/desktop/sugar/protected_activities</applyto> |
| 349 | <owner>sugar</owner> |
| 350 | <type>list</type> |
| 351 | <list_type>string</list_type> |
| 352 | <default>[]</default> |
| 353 | <locale name="C"> |
| 354 | <short>Protected Activities Bundle Indentifiers</short> |
| 355 | <long>Users will not be allowed to erase these |
| 356 | activities through the list view.</long> |
| 357 | </locale> |
| 358 | </schema> |
| 359 | |
346 | 360 | </schemalist> |
347 | 361 | </gconfschemafile> |
diff --git a/src/jarabe/desktop/activitieslist.py b/src/jarabe/desktop/activitieslist.py
index c14d31e..3ad882f 100644
a
|
b
|
class ActivityListPalette(ActivityPalette): |
400 | 400 | self.menu.append(self._favorite_item) |
401 | 401 | self._favorite_item.show() |
402 | 402 | |
403 | | if activity_info.is_user_activity(): |
404 | | menu_item = MenuItem(_('Erase'), 'list-remove') |
405 | | menu_item.connect('activate', self.__erase_activate_cb) |
406 | | self.menu.append(menu_item) |
407 | | menu_item.show() |
408 | | |
409 | | if not os.access(activity_info.get_path(), os.W_OK): |
410 | | menu_item.props.sensitive = False |
| 403 | if activity_info.is_user_activity() and \ |
| 404 | not registry.is_activity_protected(self._bundle_id): |
| 405 | menu_item = MenuItem(_('Erase'), 'list-remove') |
| 406 | menu_item.connect('activate', self.__erase_activate_cb) |
| 407 | self.menu.append(menu_item) |
| 408 | menu_item.show() |
| 409 | |
| 410 | if not os.access(activity_info.get_path(), os.W_OK): |
| 411 | menu_item.props.sensitive = False |
411 | 412 | |
412 | 413 | registry = bundleregistry.get_registry() |
413 | 414 | self._activity_changed_sid = registry.connect('bundle_changed', |
diff --git a/src/jarabe/model/bundleregistry.py b/src/jarabe/model/bundleregistry.py
index b96de86..1c839d7 100644
a
|
b
|
import os |
19 | 19 | import logging |
20 | 20 | import traceback |
21 | 21 | |
| 22 | import gconf |
22 | 23 | import gobject |
23 | 24 | import gio |
24 | 25 | import simplejson |
… |
… |
class BundleRegistry(gobject.GObject): |
66 | 67 | self._last_defaults_mtime = -1 |
67 | 68 | self._favorite_bundles = {} |
68 | 69 | |
| 70 | client = gconf.client_get_default() |
| 71 | self._protected_activities = client.get_list('/desktop/sugar/protected_activities', |
| 72 | gconf.VALUE_STRING) |
69 | 73 | try: |
70 | 74 | self._load_favorites() |
71 | 75 | except Exception: |
… |
… |
class BundleRegistry(gobject.GObject): |
312 | 316 | key = self._get_favorite_key(bundle_id, version) |
313 | 317 | return key in self._favorite_bundles |
314 | 318 | |
| 319 | def is_activity_protected(self, bundle_id): |
| 320 | return bundle_id in self._protected_activities |
| 321 | |
315 | 322 | def set_bundle_position(self, bundle_id, version, x, y): |
316 | 323 | key = self._get_favorite_key(bundle_id, version) |
317 | 324 | if key not in self._favorite_bundles: |