[gnome-documents] model: store the resource URN for each entry in the model
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents] model: store the resource URN for each entry in the model
- Date: Thu, 21 Jul 2011 06:26:25 +0000 (UTC)
commit aad47f37b48bb1c56480b473b2c2f891d3dfdd15
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Thu Jul 21 02:06:28 2011 -0400
model: store the resource URN for each entry in the model
We will need it to get back the optional GOA account ID later.
src/lib/gd-utils.c | 9 ++-
src/lib/gd-utils.h | 3 +-
src/trackerModel.js | 133 ++++++++++++++++++++++++++++++++++++---------------
3 files changed, 102 insertions(+), 43 deletions(-)
---
diff --git a/src/lib/gd-utils.c b/src/lib/gd-utils.c
index 267cee1..01c66f4 100644
--- a/src/lib/gd-utils.c
+++ b/src/lib/gd-utils.c
@@ -37,13 +37,14 @@
GtkListStore *
gd_create_list_store (void)
{
- return gtk_list_store_new (6,
+ return gtk_list_store_new (7,
G_TYPE_STRING, // URN
G_TYPE_STRING, // URI
G_TYPE_STRING, // TITLE
G_TYPE_STRING, // AUTHOR
G_TYPE_STRING, // MTIME
- GDK_TYPE_PIXBUF); // ICON
+ GDK_TYPE_PIXBUF, // ICON
+ G_TYPE_STRING); // RESOURCE_URN
}
void
@@ -54,7 +55,8 @@ gd_store_set (GtkListStore *store,
const gchar *title,
const gchar *author,
const gchar *mtime,
- GdkPixbuf *icon)
+ GdkPixbuf *icon,
+ const gchar *resource_urn)
{
gtk_list_store_set (store, iter,
0, urn,
@@ -63,6 +65,7 @@ gd_store_set (GtkListStore *store,
3, author,
4, mtime,
5, icon,
+ 6, resource_urn,
-1);
}
diff --git a/src/lib/gd-utils.h b/src/lib/gd-utils.h
index 3307904..4080128 100644
--- a/src/lib/gd-utils.h
+++ b/src/lib/gd-utils.h
@@ -33,7 +33,8 @@ void gd_store_set (GtkListStore *store,
const gchar *title,
const gchar *author,
const gchar *mtime,
- GdkPixbuf *icon);
+ GdkPixbuf *icon,
+ const gchar *resource_urn);
void gd_store_update_icon (GtkListStore *store,
GtkTreeIter *iter,
diff --git a/src/trackerModel.js b/src/trackerModel.js
index 624da59..1856082 100644
--- a/src/trackerModel.js
+++ b/src/trackerModel.js
@@ -40,7 +40,8 @@ const ModelColumns = {
AUTHOR: 3,
MTIME: 4,
ICON: 5,
- N_COLUMNS: 6
+ RESOURCE_URN: 6,
+ N_COLUMNS: 7
};
const OFFSET_STEP = 50;
@@ -53,7 +54,8 @@ const TrackerColumns = {
MTIME: 4,
TOTAL_COUNT: 5,
IDENTIFIER: 6,
- TYPE: 7
+ TYPE: 7,
+ RESOURCE_URN: 8
};
const _FILE_ATTRIBUTES = 'standard::icon,standard::content-type,thumbnail::path,time::modified';
@@ -245,6 +247,7 @@ QueryBuilder.prototype = {
this._buildTotalCounter(searchString, filterId) +
'nao:identifier(?urn) ' +
'rdf:type(?urn) ' +
+ 'nie:dataSource(?urn) ' +
'WHERE { ' +
this._buildTypeFilter('?urn') +
'OPTIONAL { ?urn nco:creator ?creator . } ' +
@@ -302,6 +305,7 @@ TrackerModel.prototype = {
let title = cursor.get_string(TrackerColumns.TITLE)[0];
let author = cursor.get_string(TrackerColumns.AUTHOR)[0];
let mtime = cursor.get_string(TrackerColumns.MTIME)[0];
+ let resourceUrn = cursor.get_string(TrackerColumns.RESOURCE_URN)[0];
this.itemCount = cursor.get_integer(TrackerColumns.TOTAL_COUNT);
@@ -317,7 +321,7 @@ TrackerModel.prototype = {
treePath = this.model.get_path(iter);
Gd.store_set(this.model, iter,
- urn, uri, title, author, mtime, loader.pixbuf);
+ urn, uri, title, author, mtime, loader.pixbuf, resourceUrn);
}));
loader.connect('icon-updated', Lang.bind(this,
@@ -363,6 +367,7 @@ TrackerModel.prototype = {
let mtime = cursor.get_string(TrackerColumns.MTIME)[0];
let identifier = cursor.get_string(TrackerColumns.IDENTIFIER)[0];
let type = cursor.get_string(TrackerColumns.TYPE)[0];
+ let resourceUrn = cursor.get_string(TrackerColumns.RESOURCE_URN)[0];
this.itemCount = cursor.get_integer(TrackerColumns.TOTAL_COUNT);
@@ -373,7 +378,7 @@ TrackerModel.prototype = {
let iter = this.model.append();
Gd.store_set(this.model, iter,
- urn, identifier, title, author, mtime, pixbuf);
+ urn, identifier, title, author, mtime, pixbuf, resourceUrn);
},
_addRowFromCursor: function(cursor) {
@@ -416,7 +421,7 @@ TrackerModel.prototype = {
},
_performCurrentQuery: function() {
- this._connection.query_async(this._builder.buildQuery(this.offset, this._filter, this._sourceId),
+ this._connection.query_async(this._builder.buildQuery(this.offset, this._filter, this._resourceUrn),
null, Lang.bind(this, this._onQueryExecuted));
},
@@ -424,38 +429,45 @@ TrackerModel.prototype = {
this.emit('count-updated', this.itemCount, this.offset);
},
- populateForOverview: function() {
- this._sourceId = 'all';
- this.offset = 0;
- this._filter = '';
-
- this._performCurrentQuery();
- },
+ sourceIdFromResourceUrn: function(resourceUrn, callback) {
+ //FIXME: is this right?
+ if(resourceUrn[0] != '<')
+ resourceUrn = '<' + resourceUrn + '>';
- loadMore: function() {
- this.offset += OFFSET_STEP;
- this._performCurrentQuery();
- },
+ 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;
+ }
- setFilter: function(filter) {
- this.model.clear();
+ cursor.next_async(null, Lang.bind(this,
+ function(object, res) {
+ try {
+ let valid = cursor.next_finish(res);
- this.offset = 0;
- this._filter = filter;
+ if (!valid) {
+ callback(null);
+ return;
+ }
+ } catch (e) {
+ log('Unable to resolve resource URN -> account ID: ' + e.toString());
+ }
- this._performCurrentQuery();
+ let sourceId = cursor.get_string(0)[0];
+ callback(sourceId);
+ }));
+ }));
},
- setAccountFilter: function(id) {
- if (id == 'all' || id == 'local') {
- this._sourceId = id;
-
- this.model.clear();
- this._performCurrentQuery();
- }
-
+ resourceUrnFromSourceId: function(sourceId, callback) {
this._connection.query_async
- (('SELECT ?urn WHERE { ?urn a nie:DataSource; nao:identifier \"goa:documents:%s\" }').format(id),
+ (('SELECT ?urn WHERE { ?urn a nie:DataSource; nao:identifier \"goa:documents:%s\" }').format(sourceId),
null, Lang.bind(this,
function(object, res) {
let cursor = null;
@@ -470,22 +482,65 @@ TrackerModel.prototype = {
try {
let valid = cursor.next_finish(res);
- if (!valid)
+ if (!valid) {
+ callback(null);
return;
+ }
} catch (e) {
log('Unable to resolve account ID -> resource URN: ' + e.toString());
}
let urn = cursor.get_string(0)[0];
- if (urn) {
- this._sourceId = urn;
-
- this.model.clear();
- this._performCurrentQuery();
- }
+ callback(urn);
}));
+ }));
+ },
+
+ populateForOverview: function(resourceUrn) {
+ this._resourceUrn = resourceUrn;
+ this.offset = 0;
+ this._filter = '';
+
+ this._performCurrentQuery();
+ },
+
+ loadMore: function() {
+ this.offset += OFFSET_STEP;
+ this._performCurrentQuery();
+ },
+
+ setFilter: function(filter) {
+ this.model.clear();
+
+ this.offset = 0;
+ this._filter = filter;
+
+ this._performCurrentQuery();
+ },
+
+ setAccountFilter: function(id) {
+ if (id == 'all' || id == 'local') {
+ this._resourceUrn = id;
+
+ this.model.clear();
+ this._performCurrentQuery();
+
+ return;
+ }
+
+ this.resourceUrnFromSourceId(id, Lang.bind(this,
+ function(resourceUrn) {
+ this.model.clear();
+
+ if (resourceUrn) {
+ this._resourceUrn = resourceUrn;
+ this._performCurrentQuery();
+ } else {
+ this.offset = 0;
+ this.itemCount = 0;
+ this._emitCountUpdated();
}
- ));
+ }));
}
};
-Signals.addSignalMethods(TrackerModel.prototype);
\ No newline at end of file
+Signals.addSignalMethods(TrackerModel.prototype);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]