Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTomeu Vizoso <tomeu@sugarlabs.org>2009-01-11 11:18:27 (GMT)
committer Tomeu Vizoso <tomeu@sugarlabs.org>2009-01-11 11:18:27 (GMT)
commitf583b08ca882d127f1df75d893cb5884649f21c7 (patch)
tree42b3a2f56d3a66bff896105a2e254291c74f70d9 /src
parentdca9571f19408b92f83cfca99a1da843e5e04dc8 (diff)
Add support for text queries on removable devices
Diffstat (limited to 'src')
-rw-r--r--src/jarabe/journal/journaltoolbox.py18
-rw-r--r--src/jarabe/journal/listview.py3
-rw-r--r--src/jarabe/journal/model.py33
3 files changed, 37 insertions, 17 deletions
diff --git a/src/jarabe/journal/journaltoolbox.py b/src/jarabe/journal/journaltoolbox.py
index 0fcb357..7bf483e 100644
--- a/src/jarabe/journal/journaltoolbox.py
+++ b/src/jarabe/journal/journaltoolbox.py
@@ -177,25 +177,15 @@ class SearchToolbar(gtk.Toolbar):
query['mime_type'] = mime_types
else:
query['activity'] = self._what_search_combo.props.value
+
if self._when_search_combo.props.value:
date_from, date_to = self._get_date_range()
query['mtime'] = {'start': date_from, 'end': date_to}
+
if self._search_entry.props.text:
text = self._search_entry.props.text.strip()
-
- if not text.startswith('"'):
- query_text = ''
- words = text.split(' ')
- for word in words:
- if word:
- if query_text:
- query_text += ' '
- query_text += word + '*'
- else:
- query_text = text
-
- if query_text:
- query['query'] = query_text
+ if text:
+ query['query'] = text
return query
diff --git a/src/jarabe/journal/listview.py b/src/jarabe/journal/listview.py
index 70f720e..3a5a909 100644
--- a/src/jarabe/journal/listview.py
+++ b/src/jarabe/journal/listview.py
@@ -244,7 +244,8 @@ class BaseListView(gtk.HBox):
self._progress_bar.show()
def _stop_progress_bar(self):
- self.remove(self.get_children()[0])
+ for widget in self.get_children():
+ self.remove(widget)
self._progress_bar = None
self.pack_start(self._canvas)
diff --git a/src/jarabe/journal/model.py b/src/jarabe/journal/model.py
index d0e4766..920fa1f 100644
--- a/src/jarabe/journal/model.py
+++ b/src/jarabe/journal/model.py
@@ -21,6 +21,7 @@ import time
import shutil
from stat import S_IFMT, S_IFDIR, S_IFREG
import traceback
+import re
import gobject
import dbus
@@ -208,6 +209,18 @@ class DatastoreResultSet(BaseResultSet):
"""Encapsulates the result of a query on the datastore
"""
def __init__(self, query):
+
+ if query.get('query', '') and not query['query'].startswith('"'):
+ query_text = ''
+ words = query['query'].split(' ')
+ for word in words:
+ if word:
+ if query_text:
+ query_text += ' '
+ query_text += word + '*'
+
+ query['query'] = query_text
+
BaseResultSet.__init__(self, query)
def find(self, query):
@@ -229,6 +242,19 @@ class InplaceResultSet(BaseResultSet):
self._pending_directories = 0
self._stopped = False
+ query_text = query.get('query', '')
+ if query_text.startswith('"') and query_text.endswith('"'):
+ self._regex = re.compile('*%s*' % query_text.strip(['"']))
+ elif query_text:
+ expression = ''
+ for word in query_text.split(' '):
+ if expression:
+ expression += '|'
+ expression += '.*%s.*' % word
+ self._regex = re.compile(expression, re.IGNORECASE)
+ else:
+ self._regex = None
+
def setup(self):
self._file_list = []
self._recurse_dir(self._mount_point)
@@ -278,7 +304,9 @@ class InplaceResultSet(BaseResultSet):
gobject.idle_add(lambda s=full_path: self._recurse_dir(s))
elif S_IFMT(stat.st_mode) == S_IFREG:
- self._file_list.append((full_path, stat, int(stat.st_mtime)))
+ if self._regex is None or self._regex.match(full_path):
+ file_info = (full_path, stat, int(stat.st_mtime))
+ self._file_list.append(file_info)
self.progress.send(self)
except Exception, e:
@@ -298,7 +326,8 @@ def _get_file_metadata(path, stat):
'mime_type': gio.content_type_guess(filename=path),
'activity': '',
'activity_id': '',
- 'icon-color': client.get_string('/desktop/sugar/user/color')}
+ 'icon-color': client.get_string('/desktop/sugar/user/color'),
+ 'description': path}
_datastore = None
def _get_datastore():