hamster-applet r617 - trunk/hamster
- From: tbaugis svn gnome org
- To: svn-commits-list gnome org
- Subject: hamster-applet r617 - trunk/hamster
- Date: Thu, 30 Oct 2008 08:47:06 +0000 (UTC)
Author: tbaugis
Date: Thu Oct 30 08:47:06 2008
New Revision: 617
URL: http://svn.gnome.org/viewvc/hamster-applet?rev=617&view=rev
Log:
avoid dupes in activities.
fixes bug 555694
Modified:
trunk/hamster/db.py
trunk/hamster/preferences.py
Modified: trunk/hamster/db.py
==============================================================================
--- trunk/hamster/db.py (original)
+++ trunk/hamster/db.py Thu Oct 30 08:47:06 2008
@@ -408,6 +408,12 @@
self.execute("update activities set activity_order = ? where id = ?", (priority2, id1) )
def __add_activity(self, name, category_id = None):
+ # first check that we don't have anything like that yet
+ activity_id = self.__get_activity_by_name(name, category_id)
+ if activity_id:
+ return activity_id
+
+ #now do the create bit
category_id = category_id or -1
new_rec = self.fetchone("select max(id) + 1 , max(activity_order) + 1 from activities")
new_id, new_order = new_rec[0] or 1, new_rec[1] or 1
Modified: trunk/hamster/preferences.py
==============================================================================
--- trunk/hamster/preferences.py (original)
+++ trunk/hamster/preferences.py Thu Oct 30 08:47:06 2008
@@ -303,9 +303,18 @@
id = tree_row[0]
if id == -1:
+ #search for activities with same name
+ activities = storage.get_activities(category_id)
+ for activity in activities:
+ if activity['name'].lower() == name:
+ self.select_activity(activity['id'])
+ return False
+
tree_row[0] = storage.add_activity(name, category_id)
else:
storage.update_activity(id, name, category_id)
+
+ return True
# callbacks
def category_edited_cb(self, cell, path, new_text, model):
@@ -322,8 +331,15 @@
def activity_name_edited_cb(self, cell, path, new_text, model):
model[path][1] = new_text
- self.update_activity(model[path])
- return True
+ res = self.update_activity(model[path])
+
+ # if update fails on new activity - it's because it is a dupe
+ # so we remove it
+ if not res and model[path][0] == -1:
+ self.activity_store.remove(model.get_iter(path))
+
+ return res
+
def category_changed_cb(self, selection, model):
""" enables and disables action buttons depending on selected item """
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]