[gnome-documents] all: split tracker-related utilities into its own script
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents] all: split tracker-related utilities into its own script
- Date: Mon, 22 Aug 2011 19:42:40 +0000 (UTC)
commit 944bfb14966d878c3677c3f08572709f91d0696b
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Sun Aug 21 17:59:41 2011 +0200
all: split tracker-related utilities into its own script
src/Makefile-js.am | 1 +
src/mainWindow.js | 3 +-
src/trackerModel.js | 76 +++------------------------------------------
src/trackerUtils.js | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 93 insertions(+), 72 deletions(-)
---
diff --git a/src/Makefile-js.am b/src/Makefile-js.am
index 962e109..f086d60 100644
--- a/src/Makefile-js.am
+++ b/src/Makefile-js.am
@@ -12,6 +12,7 @@ dist_js_DATA = \
sidebar.js \
spinnerBox.js \
trackerModel.js \
+ trackerUtils.js \
utils.js \
view.js \
format.js \
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 026ad90..45bc186 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -37,6 +37,7 @@ const IconView = imports.iconView;
const ListView = imports.listView;
const Preview = imports.preview;
const SpinnerBox = imports.spinnerBox;
+const TrackerUtils = imports.trackerUtils;
const _ = imports.gettext.gettext;
@@ -199,7 +200,7 @@ MainWindow.prototype = {
this._loaderTimeout = 0;
}
- this._model.sourceIdFromResourceUrn(resource, Lang.bind(this,
+ TrackerUtils.sourceIdFromResourceUrn(this._model.connection, resource, Lang.bind(this,
function(sourceId) {
this._loaderCancellable = new Gio.Cancellable();
this._pdfLoader = new Gd.PdfLoader({ source_id: sourceId });
diff --git a/src/trackerModel.js b/src/trackerModel.js
index 75bd471..49b3ff6 100644
--- a/src/trackerModel.js
+++ b/src/trackerModel.js
@@ -31,6 +31,7 @@ const Gd = imports.gi.Gd;
const DocFactory = imports.docFactory;
const Main = imports.main;
+const TrackerUtils = imports.trackerUtils;
const Utils = imports.utils;
const ModelColumns = {
@@ -200,7 +201,7 @@ TrackerModel.prototype = {
_initConnection: function() {
Tracker.SparqlConnection.get_async(null, Lang.bind(this, function(object, res) {
try {
- this._connection = Tracker.SparqlConnection.get_finish(res);
+ this.connection = Tracker.SparqlConnection.get_finish(res);
} catch (e) {
log('Unable to connect to the tracker database: ' + e.toString());
Main.application.quit();
@@ -268,81 +269,14 @@ TrackerModel.prototype = {
},
_performCurrentQuery: function() {
- this._connection.query_async(this._builder.buildQuery(this.offset, this._filter, this._resourceUrn),
- null, Lang.bind(this, this._onQueryExecuted));
+ this.connection.query_async(this._builder.buildQuery(this.offset, this._filter, this._resourceUrn),
+ null, Lang.bind(this, this._onQueryExecuted));
},
_emitCountUpdated: function() {
this.emit('count-updated', this.itemCount, this.offset);
},
- sourceIdFromResourceUrn: function(resourceUrn, callback) {
- //FIXME: is this right?
- if(resourceUrn[0] != '<')
- resourceUrn = '<' + resourceUrn + '>';
-
- this._connection.query_async
- (('SELECT ?id WHERE { %s a nie:DataSource; nao:identifier ?id }').format(resourceUrn),
- null, Lang.bind(this,
- function(object, res) {
- let cursor = null;
- try {
- cursor = object.query_finish(res);
- } catch (e) {
- log('Unable to resolve resource URN -> account ID: ' + e.toString());
- return;
- }
-
- cursor.next_async(null, Lang.bind(this,
- function(object, res) {
- try {
- let valid = cursor.next_finish(res);
-
- if (!valid) {
- callback(null);
- return;
- }
- } catch (e) {
- log('Unable to resolve resource URN -> account ID: ' + e.toString());
- }
-
- let sourceId = cursor.get_string(0)[0];
- callback(sourceId);
- }));
- }));
- },
-
- resourceUrnFromSourceId: function(sourceId, callback) {
- this._connection.query_async
- (('SELECT ?urn WHERE { ?urn a nie:DataSource; nao:identifier \"goa:documents:%s\" }').format(sourceId),
- null, Lang.bind(this,
- function(object, res) {
- let cursor = null;
- try {
- cursor = object.query_finish(res);
- } catch (e) {
- log('Unable to resolve account ID -> resource URN: ' + e.toString());
- }
-
- cursor.next_async(null, Lang.bind(this,
- function(object, res) {
- try {
- let valid = cursor.next_finish(res);
-
- if (!valid) {
- callback(null);
- return;
- }
- } catch (e) {
- log('Unable to resolve account ID -> resource URN: ' + e.toString());
- }
-
- let urn = cursor.get_string(0)[0];
- callback(urn);
- }));
- }));
- },
-
populateForOverview: function(resourceUrn, filter) {
this.offset = 0;
this._filter = filter;
@@ -374,7 +308,7 @@ TrackerModel.prototype = {
return;
}
- this.resourceUrnFromSourceId(id, Lang.bind(this,
+ TrackerUtils.resourceUrnFromSourceId(this.connection, id, Lang.bind(this,
function(resourceUrn) {
this.model.clear();
diff --git a/src/trackerUtils.js b/src/trackerUtils.js
new file mode 100644
index 0000000..846f5e8
--- /dev/null
+++ b/src/trackerUtils.js
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2011 Red Hat, Inc.
+ *
+ * Gnome Documents is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * Gnome Documents is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with Gnome Documents; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author: Cosimo Cecchi <cosimoc redhat com>
+ *
+ */
+
+function sourceIdFromResourceUrn(connection, resourceUrn, callback) {
+ //FIXME: is this right?
+ if(resourceUrn[0] != '<')
+ resourceUrn = '<' + resourceUrn + '>';
+
+ connection.query_async
+ (('SELECT ?id WHERE { %s a nie:DataSource; nao:identifier ?id }').format(resourceUrn), null,
+ function(object, res) {
+ let cursor = null;
+ try {
+ cursor = object.query_finish(res);
+ } catch (e) {
+ log('Unable to resolve resource URN -> account ID: ' + e.toString());
+ return;
+ }
+
+ cursor.next_async(null,
+ function(object, res) {
+ try {
+ let valid = cursor.next_finish(res);
+
+ if (!valid) {
+ callback(null);
+ return;
+ }
+ } catch (e) {
+ log('Unable to resolve resource URN -> account ID: ' + e.toString());
+ }
+
+ let sourceId = cursor.get_string(0)[0];
+ callback(sourceId);
+ });
+ });
+}
+
+function resourceUrnFromSourceId(connection, sourceId, callback) {
+ connection.query_async
+ (('SELECT ?urn WHERE { ?urn a nie:DataSource; nao:identifier \"goa:documents:%s\" }').format(sourceId), null,
+ function(object, res) {
+ let cursor = null;
+ try {
+ cursor = object.query_finish(res);
+ } catch (e) {
+ log('Unable to resolve account ID -> resource URN: ' + e.toString());
+ }
+
+ cursor.next_async(null,
+ function(object, res) {
+ try {
+ let valid = cursor.next_finish(res);
+
+ if (!valid) {
+ callback(null);
+ return;
+ }
+ } catch (e) {
+ log('Unable to resolve account ID -> resource URN: ' + e.toString());
+ }
+
+ let urn = cursor.get_string(0)[0];
+ callback(urn);
+ });
+ });
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]