hamster-applet r616 - trunk/hamster



Author: tbaugis
Date: Thu Oct 30 08:25:08 2008
New Revision: 616
URL: http://svn.gnome.org/viewvc/hamster-applet?rev=616&view=rev

Log:
small refactoring - use "add_" instead of "insert_" prefix to mark
function that adds something.
also fixed a bug created 10 minutes ago, with "None" category being created

Modified:
   trunk/hamster/db.py
   trunk/hamster/preferences.py
   trunk/hamster/storage.py

Modified: trunk/hamster/db.py
==============================================================================
--- trunk/hamster/db.py	(original)
+++ trunk/hamster/db.py	Thu Oct 30 08:25:08 2008
@@ -55,7 +55,7 @@
         
         self.execute(statement, (category_id, max_order, id))
     
-    def __insert_category(self, name):
+    def __add_category(self, name):
         new_rec = self.fetchone("select max(id) +1, max(category_order) + 1  from categories")
 
         id, order = new_rec[0] or 1, new_rec[1] or 1
@@ -199,12 +199,12 @@
             if category_name:
                 category_id = self.__get_category_by_name(category_name)
                 if not category_id:
-                    category_id = self.__insert_category(category_name)
+                    category_id = self.__add_category(category_name)
         
         activity_id = self.__get_activity_by_name(activity_name, category_id)
 
         if not activity_id:
-            activity_id = self.__insert_activity(activity_name, category_id)
+            activity_id = self.__add_activity(activity_name, category_id)
 
 
         # now fetch facts for the specified day and check if we have to
@@ -407,7 +407,8 @@
         self.execute("update activities set activity_order = ? where id = ?", (priority1, id2) )
         self.execute("update activities set activity_order = ? where id = ?", (priority2, id1) )
 
-    def __insert_activity(self, name, category_id = -1):
+    def __add_activity(self, name, category_id = None):
+        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
 
@@ -657,13 +658,13 @@
         category_count = self.fetchone("select count(*) from categories")[0]
         
         if category_count == 0:
-            work_cat_id = self.__insert_category(_(work_category["name"]))
+            work_cat_id = self.__add_category(_(work_category["name"]))
             for entry in work_category["entries"]:
-                self.__insert_activity(_(entry), work_cat_id)
+                self.__add_activity(_(entry), work_cat_id)
         
-            nonwork_cat_id = self.__insert_category(_(nonwork_category["name"]))
+            nonwork_cat_id = self.__add_category(_(nonwork_category["name"]))
             for entry in nonwork_category["entries"]:
-                self.__insert_activity(_(entry), nonwork_cat_id)
+                self.__add_activity(_(entry), nonwork_cat_id)
         
         
         

Modified: trunk/hamster/preferences.py
==============================================================================
--- trunk/hamster/preferences.py	(original)
+++ trunk/hamster/preferences.py	Thu Oct 30 08:25:08 2008
@@ -303,7 +303,7 @@
         id = tree_row[0]
         
         if id == -1:
-            tree_row[0] = storage.insert_activity(name, category_id)
+            tree_row[0] = storage.add_activity(name, category_id)
         else:
             storage.update_activity(id, name, category_id)
 
@@ -314,7 +314,7 @@
         name = model[path][1]
         
         if id == -2:
-            id = storage.insert_category(name)
+            id = storage.add_category(name)
             model[path][0] = id
         elif id > -1:  #ignore unsorted category (id = -1)
             storage.update_category(id, name)

Modified: trunk/hamster/storage.py
==============================================================================
--- trunk/hamster/storage.py	(original)
+++ trunk/hamster/storage.py	Thu Oct 30 08:25:08 2008
@@ -93,8 +93,8 @@
         self.__update_activity(id, name, category_id)
         self.dispatch('activity_updated', ())
     
-    def insert_activity(self, name, category_id = -1):
-        new_id = self.__insert_activity(name, category_id)
+    def add_activity(self, name, category_id = -1):
+        new_id = self.__add_activity(name, category_id)
         self.dispatch('activity_updated', ())
         return new_id
 
@@ -102,8 +102,8 @@
         self.__update_category(id, name)
         self.dispatch('activity_updated', ())
 
-    def insert_category(self, name):
-        res = self.__insert_category(name)
+    def add_category(self, name):
+        res = self.__add_category(name)
         self.dispatch('activity_updated', ())
         return res
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]