[gnome-documents] searchbar: implement filter by type



commit 6df02b3016d2d9101c517aa0a2ca8b4f841aff1d
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Sun Oct 30 02:21:20 2011 -0400

    searchbar: implement filter by type

 src/manager.js           |   31 ++++++++++++++++++++++++++++---
 src/query.js             |   11 +----------
 src/searchbar.js         |   36 +++++++++++++++---------------------
 src/trackerController.js |    2 ++
 4 files changed, 46 insertions(+), 34 deletions(-)
---
diff --git a/src/manager.js b/src/manager.js
index 814bbb9..d8141a1 100644
--- a/src/manager.js
+++ b/src/manager.js
@@ -111,10 +111,35 @@ BaseManager.prototype = {
 
     getFilter: function() {
         let item = this.getActiveItem();
-        if (item && item.getFilter())
-            return item.getFilter();
+        let retval = '';
 
-        return '';
+        if (item.id == 'all')
+            retval = this._getAllFilter();
+        else if (item && item.getFilter())
+            retval = item.getFilter();
+
+        return retval;
+    },
+
+    _getAllFilter: function() {
+        let filter = '';
+        let first = true;
+
+        for (idx in this._items) {
+            let item = this._items[idx];
+
+            if (item.id == 'all')
+                continue;
+
+            if (first)
+                first = false;
+            else
+                filter += ' || ';
+
+            filter += item.getFilter();
+        }
+
+        return '(' + filter + ')';
     },
 
     processNewItems: function(newItems) {
diff --git a/src/query.js b/src/query.js
index cf5778f..82a1b7b 100644
--- a/src/query.js
+++ b/src/query.js
@@ -105,15 +105,6 @@ QueryBuilder.prototype = {
         return sparql;
     },
 
-    _buildFilterType: function() {
-        let filter =
-            '(fn:contains(rdf:type(?urn), \"nfo#PaginatedTextDocument\") ||'
-            + 'fn:contains(rdf:type(?urn), \"nfo#Spreadsheet\") ||'
-            + 'fn:contains(rdf:type(?urn), \"nfo#Presentation\"))';
-
-        return filter;
-    },
-
     _buildFilterString: function() {
         let sparql = 'FILTER (';
 
@@ -123,7 +114,7 @@ QueryBuilder.prototype = {
         sparql += ' && ';
         sparql += Global.categoryManager.getFilter();
         sparql += ' && ';
-        sparql += this._buildFilterType();
+        sparql += Global.searchTypeManager.getFilter();
 
         sparql += ')';
 
diff --git a/src/searchbar.js b/src/searchbar.js
index dc6fb69..d224a0b 100644
--- a/src/searchbar.js
+++ b/src/searchbar.js
@@ -44,6 +44,11 @@ SearchType.prototype = {
     _init: function(params) {
         this.id = params.id;
         this.name = params.name;
+        this._filter = (params.filter) ? (params.filter) : '';
+    },
+
+    getFilter: function() {
+        return this._filter;
     }
 };
 
@@ -59,16 +64,18 @@ SearchTypeManager.prototype = {
 
         this.addItem(new SearchType({ id: 'all',
                                       name: _("All") }));
-        this.addItem(new SearchType({ id: 'collections',
-                                      name: _("Collections") }));
         this.addItem(new SearchType({ id: 'pdf',
-                                      name: _("PDF Files") }));
+                                      name: _("PDF Documents"),
+                                      filter: 'fn:contains(nie:mimeType(?urn), \"application/pdf\")' }));
         this.addItem(new SearchType({ id: 'presentations',
-                                      name: _("Presentations") }));
+                                      name: _("Presentations"),
+                                      filter: 'fn:contains(rdf:type(?urn), \"nfo#Presentation\")' }));
         this.addItem(new SearchType({ id: 'spreadsheets',
-                                      name: _("Spreadsheets") }));
+                                      name: _("Spreadsheets"),
+                                      filter: 'fn:contains(rdf:type(?urn), \"nfo#Spreadsheet\")'}));
         this.addItem(new SearchType({ id: 'textdocs',
-                                      name: _("Text Documents") }));
+                                      name: _("Text Documents"),
+                                      filter: 'fn:contains(rdf:type(?urn), \"nfo#PaginatedTextDocument\")' }));
 
         this.setActiveItemById('all');
     }
@@ -89,24 +96,11 @@ SearchMatch.prototype = {
     },
 
     getFilter: function() {
-        let res = null;
-
-        if (this.id == SEARCH_MATCH_ALL)
-            res = (this._getFilterById(SEARCH_MATCH_TITLE) +
-                    ' || ' +
-                    this._getFilterById(SEARCH_MATCH_AUTHOR));
-        if (!res)
-            res = this._getFilterById(this.id);
-
-        return '(' + res + ')';
-    },
-
-    _getFilterById: function(id) {
-        if (id == SEARCH_MATCH_TITLE)
+        if (this.id == SEARCH_MATCH_TITLE)
             return ('fn:contains ' +
                     '(fn:lower-case (tracker:coalesce(nie:title(?urn), nfo:fileName(?urn))), ' +
                     '"%s")').format(Global.searchFilterController.getString());
-        if (id == SEARCH_MATCH_AUTHOR)
+        if (this.id == SEARCH_MATCH_AUTHOR)
             return ('fn:contains ' +
                     '(fn:lower-case (tracker:coalesce(nco:fullname(?creator), nco:fullname(?publisher))), ' +
                     '"%s")').format(Global.searchFilterController.getString());
diff --git a/src/trackerController.js b/src/trackerController.js
index f030b6c..12ad9c6 100644
--- a/src/trackerController.js
+++ b/src/trackerController.js
@@ -63,6 +63,8 @@ TrackerController.prototype = {
                                               Lang.bind(this, this._onSearchRefresh));
         Global.searchMatchManager.connect('active-changed',
                                           Lang.bind(this, this._onSearchMatchChanged));
+        Global.searchTypeManager.connect('active-changed',
+                                         Lang.bind(this, this._onSearchRefresh));
 
         // perform initial query
         this._refresh();



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