[hamster-applet] Sort suggestions accordig to most recent use
- From: Patryk Zawadzki <pzawadzki src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [hamster-applet] Sort suggestions accordig to most recent use
- Date: Wed, 20 Jan 2010 11:04:06 +0000 (UTC)
commit 60d3628325f57b2ee7c70e3cc1534dc79d94d604
Author: Patryk Zawadzki <patrys pld-linux org>
Date: Wed Jan 20 12:03:08 2010 +0100
Sort suggestions accordig to most recent use
hamster/db.py | 19 ++++++++++++-------
hamster/storage.py | 4 ++--
hamster/widgets/activityentry.py | 24 +++++++++++-------------
3 files changed, 25 insertions(+), 22 deletions(-)
---
diff --git a/hamster/db.py b/hamster/db.py
index ed9f743..b0c7ade 100644
--- a/hamster/db.py
+++ b/hamster/db.py
@@ -745,25 +745,30 @@ class Storage(storage.Storage):
SELECT a.*, b.name as category
FROM activities a
LEFT JOIN categories b on coalesce(b.id, -1) = a.category_id
- WHERE deleted is null
+ WHERE deleted IS NULL
ORDER BY lower(a.name)
"""
activities = self.fetchall(query)
return activities
- def __get_autocomplete_activities(self):
+ def __get_autocomplete_activities(self, search):
"""returns list of activities for autocomplete,
activity names converted to lowercase"""
query = """
- SELECT lower(a.name) as name, b.name as category
+ SELECT lower(a.name) AS name, 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)
+ LEFT JOIN categories b ON coalesce(b.id, -1) = a.category_id
+ LEFT JOIN facts f ON a.id = f.activity_id
+ WHERE deleted IS NULL
+ AND a.name LIKE ? ESCAPE '\\'
+ GROUP BY a.id
+ ORDER BY min(f.start_time) DESC, lower(a.name)
+ LIMIT 50
"""
- activities = self.fetchall(query)
+ search = search.replace('\\', '\\\\').replace('%', '\\%').replace('_', '\\_')
+ activities = self.fetchall(query, (u'%s%%' % search, ))
return activities
diff --git a/hamster/storage.py b/hamster/storage.py
index e33ab50..4b94b20 100644
--- a/hamster/storage.py
+++ b/hamster/storage.py
@@ -104,8 +104,8 @@ class Storage(object):
def get_activities(self, category_id = None):
return self.__get_activities(category_id = category_id)
- def get_autocomplete_activities(self):
- return self.__get_autocomplete_activities()
+ def get_autocomplete_activities(self, search):
+ return self.__get_autocomplete_activities(search)
def get_last_activity(self):
return self.__get_last_activity()
diff --git a/hamster/widgets/activityentry.py b/hamster/widgets/activityentry.py
index 8bc5ee3..59e1468 100644
--- a/hamster/widgets/activityentry.py
+++ b/hamster/widgets/activityentry.py
@@ -168,8 +168,7 @@ class ActivityEntry(gtk.Entry):
self.select_region(len(self.filter), len(self.filter) + prefix_length)
def refresh_activities(self):
- # scratch activities and categories so that they get repopulated on demand
- self.activities = None
+ # scratch category cache so it gets repopulated on demand
self.categories = None
def populate_suggestions(self):
@@ -181,12 +180,12 @@ class ActivityEntry(gtk.Entry):
if self.activities and self.categories and self.filter == self.get_text().decode('utf8', 'replace')[:cursor]:
return #same thing, no need to repopulate
- self.activities = self.activities or runtime.storage.get_autocomplete_activities()
- self.categories = self.categories or runtime.storage.get_category_list()
-
-
self.filter = self.get_text().decode('utf8', 'replace')[:cursor]
+ # do not cache as ordering and available options change over time
+ self.activities = runtime.storage.get_autocomplete_activities(self.filter)
+ self.categories = self.categories or runtime.storage.get_category_list()
+
input_activity = stuff.parse_activity_input(self.filter)
time = ''
@@ -211,15 +210,14 @@ class ActivityEntry(gtk.Entry):
else:
key = input_activity.activity_name.decode('utf8', 'replace').lower()
for activity in self.activities:
- if input_activity.activity_name == "" or activity['name'].decode('utf8', 'replace').lower().startswith(key):
- fillable = activity['name']
- if activity['category']:
- fillable += "@%s" % activity['category']
+ fillable = activity['name']
+ if activity['category']:
+ fillable += "@%s" % activity['category']
- if time: #as we also support deltas, for the time we will grab anything up to first space
- fillable = "%s %s" % (self.filter.split(" ", 1)[0], fillable)
+ if time: #as we also support deltas, for the time we will grab anything up to first space
+ fillable = "%s %s" % (self.filter.split(" ", 1)[0], fillable)
- store.append([fillable, activity['name'], activity['category'], time])
+ store.append([fillable, activity['name'], activity['category'], time])
def after_activity_update(self, widget, event):
self.refresh_activities()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]