[Dextrose] [sugar PATCH] Check if a activity is already present in activities-list, before (re-)adding it.
Ajay Garg
ajay at activitycentral.com
Fri Mar 2 23:54:52 EST 2012
This follows from the fix for http://bugs.sugarlabs.org/ticket/2818,
available at ::
https://dev.laptop.org.au/projects/xo-au/repository/revisions/2b13f6cc48a4aba6db7c1bc1d6eaec7ce5388fd0/diff
https://dev.laptop.org.au/projects/xo-au/repository/revisions/9642a414f217c6c2f37ace653db324040cc17813/diff
http://git.sugarlabs.org/dextrose/mainline/commit/2c78ee35e184907b0c63bbc56316fedd36aa8fc3
and patchworks at:
http://patchwork.sugarlabs.org/patch/1213/
http://patchwork.sugarlabs.org/patch/1214/
Anyhow, this is a good check, since there may be multiple 'bundle-added'
and 'bundle-changed' signals emitting from multiple places in sugar.
src/jarabe/desktop/activitieslist.py | 15 +++++++++++++++
1 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/src/jarabe/desktop/activitieslist.py b/src/jarabe/desktop/activitieslist.py
index 5f79090..c48a5dc 100644
--- a/src/jarabe/desktop/activitieslist.py
+++ b/src/jarabe/desktop/activitieslist.py
@@ -204,6 +204,15 @@ class ListModel(gtk.TreeModelSort):
self._model.remove(row.iter)
return
+ def _is_activity_bundle_in_model_already(self, activity_info):
+ bundle_id = activity_info.get_bundle_id()
+ version = activity_info.get_activity_version()
+ for row in self._model:
+ if row[ListModel.COLUMN_BUNDLE_ID] == bundle_id and \
+ row[ListModel.COLUMN_VERSION] == version:
+ return True
+ return False
+
def _add_activity(self, activity_info):
if activity_info.get_bundle_id() == 'org.laptop.JournalActivity':
return
@@ -212,6 +221,12 @@ class ListModel(gtk.TreeModelSort):
version = activity_info.get_activity_version()
registry = bundleregistry.get_registry()
+
+ # If the activity bundle is already a part of
+ # activities-list, do not re-add it.
+ if self._is_activity_bundle_in_model_already(activity_info):
+ return
+
favorite = registry.is_bundle_favorite(activity_info.get_bundle_id(),
version)
--
1.7.4.4
More information about the Dextrose
mailing list