[gnome-documents] query: whitelist extra Tracker locations in query filter
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents] query: whitelist extra Tracker locations in query filter
- Date: Wed, 14 Nov 2012 18:58:28 +0000 (UTC)
commit 3d0fa86b6addc1cdec3e70042636484783a64ddb
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Wed Nov 14 13:55:09 2012 -0500
query: whitelist extra Tracker locations in query filter
If the user adds a non-default locations to Tracker, Documents should
pick it up when querying the database.
https://bugzilla.gnome.org/show_bug.cgi?id=686739
src/query.js | 62 ++++++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 50 insertions(+), 12 deletions(-)
---
diff --git a/src/query.js b/src/query.js
index f4be70b..fe5f693 100644
--- a/src/query.js
+++ b/src/query.js
@@ -47,6 +47,8 @@ const QueryFlags = {
};
const LOCAL_COLLECTIONS_IDENTIFIER = 'gd:collection:local:';
+const TRACKER_SCHEMA = 'org.freedesktop.Tracker.Miner.Files';
+const TRACKER_KEY_RECURSIVE_DIRECTORIES = 'index-recursive-directories';
const Query = new Lang.Class({
Name: 'Query',
@@ -63,21 +65,57 @@ const QueryBuilder = new Lang.Class({
_init: function() {
},
- buildFilterLocal: function() {
- let path;
- let filters = [];
+ _getTrackerLocations: function() {
+ let settings = new Gio.Settings({ schema: TRACKER_SCHEMA });
+ let locations = settings.get_strv(TRACKER_KEY_RECURSIVE_DIRECTORIES);
+ let files = [];
+
+ locations.forEach(Lang.bind(this,
+ function(location) {
+ // ignore special XDG placeholders, since we handle those internally
+ if (location[0] == '&' || location[0] == '$')
+ return;
+
+ let trackerFile = Gio.file_new_for_commandline_arg(location);
+
+ // also ignore XDG locations if they are present with their full path
+ for (let idx = 0; idx < GLib.UserDirectory.N_DIRECTORIES; idx++) {
+ let file = Gio.file_new_for_path(GLib.get_user_special_dir(idx));
+ if (trackerFile.equal(file))
+ return;
+ }
+
+ files.push(trackerFile);
+ }));
- path = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_DESKTOP);
- if (path)
- filters.push('(fn:contains (nie:url(?urn), "%s"))'.format(Gio.file_new_for_path(path).get_uri()));
+ return files;
+ },
+
+ _getBuiltinLocations: function() {
+ let files = [];
+ let xdgDirs = [GLib.UserDirectory.DIRECTORY_DESKTOP,
+ GLib.UserDirectory.DIRECTORY_DOCUMENTS,
+ GLib.UserDirectory.DIRECTORY_DOWNLOAD];
+
+ xdgDirs.forEach(Lang.bind(this,
+ function(dir) {
+ let path = GLib.get_user_special_dir(dir);
+ if (path)
+ files.push(Gio.file_new_for_path(path));
+ }));
+
+ return files;
+ },
- path = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_DOCUMENTS);
- if (path)
- filters.push('(fn:contains (nie:url(?urn), "%s"))'.format(Gio.file_new_for_path(path).get_uri()));
+ buildFilterLocal: function() {
+ let locations = this._getBuiltinLocations();
+ locations = locations.concat(this._getTrackerLocations());
- path = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_DOWNLOAD);
- if (path)
- filters.push('(fn:contains (nie:url(?urn), "%s"))'.format(Gio.file_new_for_path(path).get_uri()));
+ let filters = [];
+ locations.forEach(Lang.bind(this,
+ function(location) {
+ filters.push('(fn:contains (nie:url(?urn), "%s"))'.format(location.get_uri()));
+ }));
filters.push('(fn:starts-with (nao:identifier(?urn), "gd:collection:local:"))');
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]