[hamster-applet] shuffled functions of getting activities for category and for autocomplete. fixed bug with prefs uns
- From: Toms Baugis <tbaugis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [hamster-applet] shuffled functions of getting activities for category and for autocomplete. fixed bug with prefs uns
- Date: Sat, 15 May 2010 10:28:40 +0000 (UTC)
commit a425c8c0d05c6fdb34fe0fc1777fc061898832a7
Author: Toms Bauģis <toms baugis gmail com>
Date: Sat May 15 11:28:33 2010 +0100
shuffled functions of getting activities for category and for autocomplete. fixed bug with prefs unsorted category coming up with all the activities
src/hamster/client.py | 8 +++---
src/hamster/db.py | 42 ++++++++++++---------------------
src/hamster/preferences.py | 4 +-
src/hamster/storage.py | 10 ++++----
src/hamster/widgets/activityentry.py | 2 +-
5 files changed, 27 insertions(+), 39 deletions(-)
---
diff --git a/src/hamster/client.py b/src/hamster/client.py
index 4a0eef4..5d5d01d 100644
--- a/src/hamster/client.py
+++ b/src/hamster/client.py
@@ -106,12 +106,12 @@ class Storage(gobject.GObject):
end_date,
search_terms)]
- def get_autocomplete_activities(self, search = ""):
+ def get_activities(self, search = ""):
"""returns list of activities name matching search criteria.
results are sorted by most recent usage.
search is case insensitive
"""
- return self.conn.GetAutocompleteActivities(search)
+ return self.conn.GetActivities(search)
def get_categories(self):
"""returns list of categories"""
@@ -206,11 +206,11 @@ class Storage(gobject.GObject):
category_name, description, temporary)
- def get_activities(self, category_id = None):
+ def get_category_activities(self, category_id = None):
"""Return activities for category. If category is not specified, will
return activities that have no category"""
category_id = category_id or -1
- return self.conn.GetActivities(category_id)
+ return self.conn.GetCategoryActivities(category_id)
def get_category_id(self, category_name):
"""returns category id by name"""
diff --git a/src/hamster/db.py b/src/hamster/db.py
index de6e130..a579ae7 100644
--- a/src/hamster/db.py
+++ b/src/hamster/db.py
@@ -746,39 +746,27 @@ class Storage(storage.Storage):
"DELETE FROM facts where id = ?"]
self.execute(statements, [(fact_id,)] * 2)
- def __get_activities(self, category_id = None):
+ def __get_category_activities(self, category_id):
"""returns list of activities, if category is specified, order by name
otherwise - by activity_order"""
- if category_id:
- query = """
- SELECT a.id, a.name, a.activity_order, a.category_id, b.name as category
- FROM activities a
- LEFT JOIN categories b on coalesce(b.id, -1) = a.category_id
- WHERE category_id = ?
- AND deleted is null
- """
-
- # unsorted entries we sort by name - others by ID
- if category_id == -1:
- query += "ORDER BY lower(a.name)"
- else:
- query += "ORDER BY a.activity_order"
-
- activities = self.fetchall(query, (category_id, ))
+ query = """
+ SELECT a.id, a.name, a.activity_order, a.category_id, b.name as category
+ FROM activities a
+ LEFT JOIN categories b on coalesce(b.id, -1) = a.category_id
+ WHERE category_id = ?
+ AND deleted is null
+ """
+ # unsorted entries we sort by name - others by ID
+ if category_id == -1:
+ query += "ORDER BY lower(a.name)"
else:
- query = """
- SELECT a.id, a.name, a.activity_order, a.category_id, b.name as category
- FROM activities a
- LEFT JOIN categories b on coalesce(b.id, -1) = a.category_id
- WHERE deleted IS NULL
- ORDER BY lower(a.name)
- """
- activities = self.fetchall(query)
+ query += "ORDER BY a.activity_order"
+
+ activities = self.fetchall(query, (category_id, ))
- return activities
- def __get_autocomplete_activities(self, search):
+ def __get_activities(self, search):
"""returns list of activities for autocomplete,
activity names converted to lowercase"""
diff --git a/src/hamster/preferences.py b/src/hamster/preferences.py
index 6d3bf55..561e522 100755
--- a/src/hamster/preferences.py
+++ b/src/hamster/preferences.py
@@ -75,7 +75,7 @@ class ActivityStore(gtk.ListStore):
if category_id is None:
return
- activity_list = runtime.storage.get_activities(category_id)
+ activity_list = runtime.storage.get_category_activities(category_id)
for activity in activity_list:
self.append([activity['id'],
@@ -468,7 +468,7 @@ class PreferencesEditor:
category_id = model[path][2]
#look for dupes
- activities = runtime.storage.get_activities(category_id)
+ activities = runtime.storage.get_category_activities(category_id)
for activity in activities:
if activity['name'].lower() == new_text.lower():
if id == -1: # that was a new category
diff --git a/src/hamster/storage.py b/src/hamster/storage.py
index ea7c248..f175fbc 100644
--- a/src/hamster/storage.py
+++ b/src/hamster/storage.py
@@ -260,12 +260,12 @@ class Storage(dbus.service.Object):
return result
@dbus.service.method("org.gnome.Hamster", in_signature='i', out_signature='aa{sv}')
- def GetActivities(self, category_id = None):
- if not category_id or category_id == -1:
+ def GetCategoryActivities(self, category_id = None):
+ if not category_id:
category_id = None
res = []
- for activity in self.__get_activities(category_id = category_id):
+ for activity in self.__get_category_activities(category_id = category_id):
activity = dict(activity)
activity['category'] = activity['category'] or ''
@@ -275,9 +275,9 @@ class Storage(dbus.service.Object):
@dbus.service.method("org.gnome.Hamster", in_signature='s', out_signature='aa{sv}')
- def GetAutocompleteActivities(self, search = ""):
+ def GetActivities(self, search = ""):
res = []
- for activity in self.__get_autocomplete_activities(search):
+ for activity in self.__get_activities(search):
activity = dict(activity)
activity['category'] = activity['category'] or ''
res.append(activity)
diff --git a/src/hamster/widgets/activityentry.py b/src/hamster/widgets/activityentry.py
index 534b966..8a56f9a 100644
--- a/src/hamster/widgets/activityentry.py
+++ b/src/hamster/widgets/activityentry.py
@@ -211,7 +211,7 @@ class ActivityEntry(gtk.Entry):
input_activity = stuff.parse_activity_input(self.filter)
# do not cache as ordering and available options change over time
- self.activities = runtime.storage.get_autocomplete_activities(input_activity.activity_name)
+ self.activities = runtime.storage.get_activities(input_activity.activity_name)
self.external_activities = self.external.get_activities(input_activity.activity_name)
self.activities.extend(self.external_activities)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]