[gnome-documents] sources: move source filter handling to Sources



commit 8a88e364fa6d9dce2a094382af288299c43e1b15
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Thu Aug 25 15:17:45 2011 -0400

    sources: move source filter handling to Sources

 src/sources.js      |   55 ++++++++++++++++++++++++++++++++++++++++++++++++-
 src/trackerModel.js |   56 +-------------------------------------------------
 2 files changed, 55 insertions(+), 56 deletions(-)
---
diff --git a/src/sources.js b/src/sources.js
index 8609a9f..b7b8855 100644
--- a/src/sources.js
+++ b/src/sources.js
@@ -24,6 +24,8 @@ const Mainloop = imports.mainloop;
 const Signals = imports.signals;
 
 const Gd = imports.gi.Gd;
+const Gio = imports.gi.Gio;
+const GLib = imports.gi.GLib;
 const Goa = imports.gi.Goa;
 const Gtk = imports.gi.Gtk;
 const Pango = imports.gi.Pango;
@@ -57,6 +59,55 @@ Source.prototype = {
                     this._initCallback();
                 }));
         }
+    },
+
+    getFilter: function(subject) {
+        if (this.id == 'local')
+            return this._buildFilterLocal(subject);
+
+        if (this.id == 'all')
+            return this._buildFilterLocal(subject) + ') || (' + this._buildFilterNotLocal(subject);
+
+        return this._buildFilterResource(subject);
+    },
+
+    _buildFilterLocal: function(subject) {
+        let path;
+        let desktopURI;
+        let documentsURI;
+
+        path = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_DESKTOP);
+        if (path)
+            desktopURI = Gio.file_new_for_path(path).get_uri();
+        else
+            desktopURI = '';
+
+        path = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_DOCUMENTS);
+        if (path)
+            documentsURI = Gio.file_new_for_path(path).get_uri();
+        else
+            documentsURI = '';
+
+        let filter =
+            ('((fn:starts-with (nie:url(%s), "%s")) || ' +
+             '(fn:starts-with (nie:url(%s), "%s")))').format(subject, desktopURI,
+                                                             subject, documentsURI);
+
+        return filter;
+    },
+
+    _buildFilterNotLocal: function(subject) {
+        let filter =
+            ('(fn:contains(rdf:type(%s), \"RemoteDataObject\"))').format(subject);
+
+        return filter;
+    },
+
+    _buildFilterResource: function(subject, resourceUrn) {
+        let filter =
+            ('(nie:dataSource(%s) = "<%s>")').format(subject, resourceUrn);
+
+        return filter;
     }
 };
 
@@ -138,8 +189,8 @@ SourceManager.prototype = {
         return this.activeSource.id;
     },
 
-    getActiveSourceUrn: function() {
-        return this.activeSource.resourceUrn;
+    getActiveSourceFilter: function(subject) {
+        return this.activeSource.getFilter(subject);
     }
 };
 Signals.addSignalMethods(SourceManager.prototype);
diff --git a/src/trackerModel.js b/src/trackerModel.js
index 3c80e73..77838bc 100644
--- a/src/trackerModel.js
+++ b/src/trackerModel.js
@@ -78,63 +78,11 @@ QueryBuilder.prototype = {
         return filter;
     },
 
-    _buildFilterLocal: function(subject) {
-        let path;
-        let desktopURI;
-        let documentsURI;
-
-        path = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_DESKTOP);
-        if (path)
-            desktopURI = Gio.file_new_for_path(path).get_uri();
-        else
-            desktopURI = '';
-
-        path = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_DOCUMENTS);
-        if (path)
-            documentsURI = Gio.file_new_for_path(path).get_uri();
-        else
-            documentsURI = '';
-
-        let filter =
-            this._buildFilterSearch(subject) +
-            ('((fn:starts-with (nie:url(%s), "%s")) || ' +
-             '(fn:starts-with (nie:url(%s), "%s")))').format(subject, desktopURI,
-                                                             subject, documentsURI);
-
-        return filter;
-    },
-
-    _buildFilterNotLocal: function(subject) {
-        let filter =
-            this._buildFilterSearch(subject) +
-            ('(fn:contains(rdf:type(%s), \"RemoteDataObject\"))').format(subject);
-
-        return filter;
-    },
-
-    _buildFilterResource: function(subject, resourceUrn) {
-        let filter =
-            this._buildFilterSearch(subject) +
-            ('(nie:dataSource(%s) = "<%s>")').format(subject, resourceUrn);
-
-        return filter;
-    },
-
     _buildFilterString: function(subject) {
-        let filterId = Global.sourceManager.getActiveSourceUrn();
         let sparql = 'FILTER ((';
 
-        if (filterId == 'local' || filterId == 'all')
-            sparql += this._buildFilterLocal(subject);
-
-        if (filterId == 'all')
-            sparql += ') || (';
-
-        if (filterId != 'local' && filterId != 'all')
-            sparql += this._buildFilterResource(subject, filterId);
-        else if (filterId == 'all')
-            sparql += this._buildFilterNotLocal(subject);
-
+        sparql += this._buildFilterSearch(subject);
+        sparql += Global.sourceManager.getActiveSourceFilter(subject);
         sparql += ')) ';
 
         return sparql;



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