[gnome-documents/wip/abono/sort-by: 2/3] query, view: Change the ORDER BY clause
- From: Alessandro Bono <abono src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents/wip/abono/sort-by: 2/3] query, view: Change the ORDER BY clause
- Date: Wed, 4 Nov 2015 23:52:19 +0000 (UTC)
commit 708ae48f542fe155ee8c88e5ed9d7a5fd3487397
Author: Alessandro Bono <shadow openaliasbox org>
Date: Mon Oct 19 21:43:11 2015 +0200
query, view: Change the ORDER BY clause
src/query.js | 34 ++++++++++++++++++++++++----------
src/trackerController.js | 25 ++++++++++++++++++++++---
2 files changed, 46 insertions(+), 13 deletions(-)
---
diff --git a/src/query.js b/src/query.js
index f1dd34b..548bfcd 100644
--- a/src/query.js
+++ b/src/query.js
@@ -19,6 +19,7 @@
*
*/
+const Gd = imports.gi.Gd;
const GdPrivate = imports.gi.GdPrivate;
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
@@ -124,11 +125,11 @@ const QueryBuilder = new Lang.Class({
return whereSparql;
},
- _buildQueryInternal: function(global, flags, offsetController) {
+ _buildQueryInternal: function(global, flags, offsetController, sortBy) {
let whereSparql = this._buildWhere(global, flags);
let tailSparql = '';
- // order results by mtime
+ // order results depending on sortBy
if (global) {
let offset = 0;
let step = Search.OFFSET_STEP;
@@ -138,18 +139,31 @@ const QueryBuilder = new Lang.Class({
step = offsetController.getOffsetStep();
}
- tailSparql +=
- 'ORDER BY DESC (?mtime)' +
- ('LIMIT %d OFFSET %d').format(step, offset);
+ switch (sortBy) {
+ case Gd.MainColumns.PRIMARY_TEXT:
+ tailSparql += 'ORDER BY ASC(?title) ASC(?filename)';
+ break;
+ case Gd.MainColumns.SECONDARY_TEXT:
+ tailSparql += 'ORDER BY ASC(?author)';
+ break;
+ case Gd.MainColumns.MTIME:
+ tailSparql += 'ORDER BY DESC(?mtime)';
+ break;
+ default:
+ tailSparql += 'ORDER BY DESC(?mtime)';
+ break;
+ }
+
+ tailSparql += ('LIMIT %d OFFSET %d').format(step, offset);
}
let sparql =
'SELECT DISTINCT ?urn ' + // urn
'nie:url(?urn) ' + // uri
- 'nfo:fileName(?urn)' + // filename
+ 'nfo:fileName(?urn) AS ?filename ' + // filename
'nie:mimeType(?urn)' + // mimetype
- 'nie:title(?urn) ' + // title
- 'tracker:coalesce(nco:fullname(?creator), nco:fullname(?publisher), \'\') ' + // author
+ 'nie:title(?urn) AS ?title ' + // title
+ 'tracker:coalesce(nco:fullname(?creator), nco:fullname(?publisher), \'\') AS ?author ' + //
author
'tracker:coalesce(nfo:fileLastModified(?urn), nie:contentLastModified(?urn)) AS ?mtime ' + //
mtime
'nao:identifier(?urn) ' + // identifier
'rdf:type(?urn) ' + // type
@@ -168,8 +182,8 @@ const QueryBuilder = new Lang.Class({
return this._createQuery(sparql);
},
- buildGlobalQuery: function(flags, offsetController) {
- return this._createQuery(this._buildQueryInternal(true, flags, offsetController));
+ buildGlobalQuery: function(flags, offsetController, sortBy) {
+ return this._createQuery(this._buildQueryInternal(true, flags, offsetController, sortBy));
},
buildCountQuery: function(flags) {
diff --git a/src/trackerController.js b/src/trackerController.js
index 3a71a4c..14c8e9a 100644
--- a/src/trackerController.js
+++ b/src/trackerController.js
@@ -27,6 +27,7 @@ const Query = imports.query;
const Utils = imports.utils;
const WindowMode = imports.windowMode;
+const Gd = imports.gi.Gd;
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const _ = imports.gettext.gettext;
@@ -120,6 +121,7 @@ const TrackerController = new Lang.Class({
this._querying = false;
this._isStarted = false;
this._refreshPending = false;
+ this._sortBy = null;
// useful for debugging
this._lastQueryTime = 0;
@@ -135,6 +137,10 @@ const TrackerController = new Lang.Class({
this._offsetController = this.getOffsetController();
this._offsetController.connect('offset-changed', Lang.bind(this, this._performCurrentQuery));
+
+ this._sortSettingsId = Application.application.connect('action-state-changed::sort-by',
+ Lang.bind(this, this._updateSortForSettings));
+ this._updateSortForSettings();
},
getOffsetController: function() {
@@ -272,6 +278,16 @@ const TrackerController = new Lang.Class({
this._refreshPending = true;
},
+ _updateSortForSettings: function() {
+ let sortBy = Application.settings.get_enum('sort-by');
+
+ if(this._sortBy == sortBy)
+ return;
+
+ this._sortBy = sortBy;
+ this._refreshInternal(RefreshFlags.RESET_OFFSET);
+ },
+
start: function() {
if (this._isStarted)
return;
@@ -310,7 +326,8 @@ const TrackerCollectionsController = new Lang.Class({
flags = Query.QueryFlags.COLLECTIONS;
return Application.queryBuilder.buildGlobalQuery(flags,
- Application.offsetCollectionsController);
+ Application.offsetCollectionsController,
+ this._sortBy);
},
});
@@ -328,7 +345,8 @@ const TrackerDocumentsController = new Lang.Class({
getQuery: function() {
return Application.queryBuilder.buildGlobalQuery(Query.QueryFlags.DOCUMENTS,
- Application.offsetDocumentsController);
+ Application.offsetDocumentsController,
+ this._sortBy);
},
});
@@ -367,6 +385,7 @@ const TrackerSearchController = new Lang.Class({
getQuery: function() {
return Application.queryBuilder.buildGlobalQuery(Query.QueryFlags.SEARCH,
- Application.offsetSearchController);
+ Application.offsetSearchController,
+ this._sortBy);
},
});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]