[gnome-documents] all: implement the Shared category
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents] all: implement the Shared category
- Date: Mon, 29 Aug 2011 18:59:35 +0000 (UTC)
commit 4bbfbabadea6ea5f5ddccec174c85e84853c44ad
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Mon Aug 29 14:58:38 2011 -0400
all: implement the Shared category
src/categories.js | 30 +++++++++++++++++++----
src/documents.js | 33 ++++++++++++++++++++-----
src/query.js | 69 +++++++++++++++++++++++++++++++++++++++++++----------
src/sources.js | 36 +--------------------------
4 files changed, 109 insertions(+), 59 deletions(-)
---
diff --git a/src/categories.js b/src/categories.js
index 43191b3..8fc11f8 100644
--- a/src/categories.js
+++ b/src/categories.js
@@ -24,6 +24,8 @@ const Signals = imports.signals;
const _ = imports.gettext.gettext;
+const Global = imports.global;
+
function Category(id, name, icon) {
this._init(id, name, icon);
};
@@ -35,11 +37,23 @@ Category.prototype = {
this.icon = icon;
},
- getFilter: function() {
+ getWhere: function() {
if (this.id == 'favorites')
return '{ ?urn nao:hasTag nao:predefined-tag-favorite }';
- return '';
+ // require to have a contributor, and creator, and they should be different
+ if (this.id == 'shared')
+ return '{ ?urn nco:contributor ?contributor . ?urn nco:creator ?creator FILTER (?contributor != ?creator ) }';
+
+ return '{ }';
+ },
+
+ getFilter: function(subject) {
+ // require to be not local
+ if (this.id == 'shared')
+ return Global.queryBuilder.buildFilterNotLocal(subject);
+
+ return '(true)';
}
};
@@ -54,9 +68,11 @@ CategoryManager.prototype = {
this.categories.push(new Category('recent', _("New and Recent"), ''));
this.categories.push(new Category('favorites', _("Favorites"), 'emblem-favorite-symbolic'));
- this.categories.push(new Category('private', _("Private"), 'channel-secure-symbolic'));
this.categories.push(new Category('shared', _("Shared with you"), 'emblem-shared-symbolic'));
+ // unimplemented
+ this.categories.push(new Category('private', _("Private"), 'channel-secure-symbolic'));
+
this.setActiveCategoryId('recent');
},
@@ -78,8 +94,12 @@ CategoryManager.prototype = {
return this.activeCategory.id;
},
- getActiveCategoryFilter: function() {
- return this.activeCategory.getFilter();
+ getActiveCategoryWhere: function() {
+ return this.activeCategory.getWhere();
+ },
+
+ getActiveCategoryFilter: function(subject) {
+ return this.activeCategory.getFilter(subject);
}
};
Signals.addSignalMethods(CategoryManager.prototype);
diff --git a/src/documents.js b/src/documents.js
index 5713634..259ba3b 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -53,7 +53,10 @@ DocCommon.prototype = {
this.pixbuf = null;
this.defaultAppName = null;
- this._populateFromCursor(cursor);
+ this.favorite = false;
+ this.shared = false;
+
+ this.populateFromCursor(cursor);
this._refreshIconId =
Global.settings.connect('changed::list-view',
@@ -82,7 +85,7 @@ DocCommon.prototype = {
function(object, res) {
let valid = object.next_finish(res);
if (valid)
- this._populateFromCursor(object);
+ this.populateFromCursor(object);
}));
} catch (e) {
log('Unable to refresh file information: ' + e.toString());
@@ -91,7 +94,7 @@ DocCommon.prototype = {
}));
},
- _populateFromCursor: function(cursor) {
+ populateFromCursor: function(cursor) {
this.uri = cursor.get_string(Query.QueryColumns.URI)[0];
this.urn = cursor.get_string(Query.QueryColumns.URN)[0];
this.title = cursor.get_string(Query.QueryColumns.TITLE)[0];
@@ -116,11 +119,21 @@ DocCommon.prototype = {
},
checkEmblemsAndUpdateInfo: function() {
- if (this.favorite) {
- let emblemIcon = new Gio.ThemedIcon({ name: 'emblem-favorite' });
- let emblem = new Gio.Emblem({ icon: emblemIcon });
+ let emblemIcons = [];
+
+ if (this.favorite)
+ emblemIcons.push(new Gio.ThemedIcon({ name: 'emblem-favorite' }));
+ if (this.shared)
+ emblemIcons.push(new Gio.ThemedIcon({ name: 'emblem-shared' }));
+
+ if (emblemIcons.length > 0) {
let emblemedIcon = new Gio.EmblemedIcon({ gicon: this.pixbuf });
- emblemedIcon.add_emblem(emblem);
+
+ emblemIcons.forEach(
+ function(emblemIcon) {
+ let emblem = new Gio.Emblem({ icon: emblemIcon });
+ emblemedIcon.add_emblem(emblem);
+ });
let theme = Gtk.IconTheme.get_default();
@@ -336,6 +349,12 @@ GoogleDocument.prototype = {
}));
},
+ populateFromCursor: function(cursor) {
+ this.shared = cursor.get_boolean(Query.QueryColumns.SHARED);
+
+ DocCommon.prototype.populateFromCursor.call(this, cursor);
+ },
+
setFavorite: function(favorite) {
DocCommon.prototype.setFavorite.call(this, favorite);
this._createGDataEntry(null, Lang.bind(this,
diff --git a/src/query.js b/src/query.js
index 187c47f..cc0389f 100644
--- a/src/query.js
+++ b/src/query.js
@@ -21,6 +21,9 @@
const Global = imports.global;
+const Gio = imports.gi.Gio;
+const GLib = imports.gi.GLib;
+
const QueryColumns = {
URN: 0,
URI: 1,
@@ -31,7 +34,8 @@ const QueryColumns = {
TYPE: 6,
RESOURCE_URN: 7,
FAVORITE: 8,
- TOTAL_COUNT: 9 // only in global query
+ SHARED: 9,
+ TOTAL_COUNT: 10 // only in global query
};
function QueryBuilder() {
@@ -42,6 +46,38 @@ QueryBuilder.prototype = {
_init: function() {
},
+ 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;
+ },
+
_buildFilterSearch: function(subject) {
let filter =
('fn:contains ' +
@@ -52,13 +88,15 @@ QueryBuilder.prototype = {
},
_buildFilterString: function(subject) {
- let sparql = 'FILTER ((';
+ let sparql = 'FILTER (';
- sparql += this._buildFilterSearch(subject);
- sparql += ') && (';
- sparql += Global.sourceManager.getActiveSourceFilter(subject);
+ sparql += '(' + this._buildFilterSearch(subject) + ')';
+ sparql += ' && ';
+ sparql += '(' + Global.sourceManager.getActiveSourceFilter(subject) + ')';
+ sparql += ' && ';
+ sparql += '(' + Global.categoryManager.getActiveCategoryFilter(subject) + ')';
- sparql += '))';
+ sparql += ')';
return sparql;
},
@@ -84,21 +122,25 @@ QueryBuilder.prototype = {
return sparql;
},
+ _buildOptional: function() {
+ let sparql =
+ 'OPTIONAL { ?urn nco:creator ?creator . } ' +
+ 'OPTIONAL { ?urn nco:publisher ?publisher . } ';
+
+ return sparql;
+ },
+
_buildQueryInternal: function(global) {
let globalSparql =
- 'WHERE { ' +
- 'OPTIONAL { ?urn nco:creator ?creator . } ' +
- 'OPTIONAL { ?urn nco:publisher ?publisher . } ' +
- '}';
+ 'WHERE { ' + this._buildOptional() + '}';
if (global) {
globalSparql =
(this._buildTotalCounter() + // totalCount
'WHERE { ' +
this._buildTypeFilter('?urn') +
- 'OPTIONAL { ?urn nco:creator ?creator . } ' +
- 'OPTIONAL { ?urn nco:publisher ?publisher . } ' +
- Global.categoryManager.getActiveCategoryFilter() +
+ this._buildOptional() +
+ Global.categoryManager.getActiveCategoryWhere() +
this._buildFilterString('?urn') +
' } ' +
'ORDER BY DESC (?mtime)' +
@@ -116,6 +158,7 @@ QueryBuilder.prototype = {
'rdf:type(?urn) ' + // type
'nie:dataSource(?urn) ' + // resource URN
'( EXISTS { ?urn nao:hasTag nao:predefined-tag-favorite } ) ' + // favorite
+ '( EXISTS { ?urn nco:contributor ?contributor FILTER ( ?contributor != ?creator ) } ) ' + // shared
globalSparql;
return sparql;
diff --git a/src/sources.js b/src/sources.js
index 91e5a8a..d9ed694 100644
--- a/src/sources.js
+++ b/src/sources.js
@@ -75,46 +75,14 @@ Source.prototype = {
getFilter: function(subject) {
if (this.id == 'local')
- return this._buildFilterLocal(subject);
+ return Global.queryBuilder.buildFilterLocal(subject);
if (this.id == 'all')
- return this._buildFilterLocal(subject) + ' || ' + this._buildFilterNotLocal(subject);
+ return Global.queryBuilder.buildFilterLocal(subject) + ' || ' + Global.queryBuilder.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) {
let filter =
('(nie:dataSource(%s) = "%s")').format(subject, this.resourceUrn);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]