[gnome-documents] all: hide/show documents for unavailable GOA resources
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents] all: hide/show documents for unavailable GOA resources
- Date: Fri, 2 Sep 2011 21:56:12 +0000 (UTC)
commit 797194a70c0c837ce2cc0c31cd230d652254d670
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Fri Sep 2 17:54:57 2011 -0400
all: hide/show documents for unavailable GOA resources
This keeps gnome-documents in sync with the Online Accounts panel
setting for the Documents switch.
src/application.js | 33 +++++++++------
src/global.js | 1 +
src/query.js | 11 ++++-
src/sources.js | 99 ++++++++++++++++++++++++++++++++--------------
src/trackerController.js | 4 +-
5 files changed, 100 insertions(+), 48 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index 0a1af62..a6f8bff 100644
--- a/src/application.js
+++ b/src/application.js
@@ -27,6 +27,7 @@ const GtkClutter = imports.gi.GtkClutter;
const EvDoc = imports.gi.EvinceDocument;
const Gdk = imports.gi.Gdk;
const Gio = imports.gi.Gio;
+const Goa = imports.gi.Goa;
const Gtk = imports.gi.Gtk;
const GLib = imports.gi.GLib;
const Tracker = imports.gi.Tracker;
@@ -135,22 +136,28 @@ Application.prototype = {
this.quit();
}
- // now create the source manager
- Global.sourceManager = new Sources.SourceManager(Lang.bind(this, this._onSourceManagerCreated));
+ Goa.Client.new(null, Lang.bind(this,
+ function(object, res) {
+ try {
+ Global.goaClient = Goa.Client.new_finish(res);
+ } catch (e) {
+ log('Unable to create the GOA client: ' + e.toString());
+ this.quit();
+ }
+
+ Global.sourceManager = new Sources.SourceManager();
+ Global.selectionController = new SelectionController.SelectionController();
+ Global.queryBuilder = new Query.QueryBuilder();
+ Global.documentManager = new Documents.DocumentManager();
+ Global.trackerController = new TrackerController.TrackerController();
+ Global.changeMonitor = new ChangeMonitor.TrackerChangeMonitor();
+
+ this._mainWindow = new MainWindow.MainWindow();
+ this.activate();
+ }));
}));
},
- _onSourceManagerCreated: function() {
- Global.selectionController = new SelectionController.SelectionController();
- Global.queryBuilder = new Query.QueryBuilder();
- Global.documentManager = new Documents.DocumentManager();
- Global.trackerController = new TrackerController.TrackerController();
- Global.changeMonitor = new ChangeMonitor.TrackerChangeMonitor();
-
- this._mainWindow = new MainWindow.MainWindow();
- this.activate();
- },
-
activate: function() {
this._mainWindow.window.present();
},
diff --git a/src/global.js b/src/global.js
index 90eea45..18252ac 100644
--- a/src/global.js
+++ b/src/global.js
@@ -24,6 +24,7 @@ let categoryManager = null;
let connection = null;
let documentManager = null;
let errorHandler = null;
+let goaClient = null;
let offsetController = null;
let queryBuilder = null;
let selectionController = null;
diff --git a/src/query.js b/src/query.js
index 560eb36..15a4a79 100644
--- a/src/query.js
+++ b/src/query.js
@@ -72,10 +72,15 @@ QueryBuilder.prototype = {
},
buildFilterNotLocal: function() {
- let filter =
- '(fn:contains(rdf:type(?urn), \"RemoteDataObject\"))';
+ let sparql = '(';
+ let remoteSources = Global.sourceManager.getRemoteSources();
- return filter;
+ for (idx in remoteSources)
+ sparql += ('(nie:dataSource(?urn) = "%s") || ').format(remoteSources[idx].resourceUrn);
+
+ sparql += 'false)';
+
+ return sparql;
},
_buildFilterSearch: function() {
diff --git a/src/sources.js b/src/sources.js
index bd441b6..1061963 100644
--- a/src/sources.js
+++ b/src/sources.js
@@ -84,51 +84,56 @@ Source.prototype = {
},
_buildFilterResource: function() {
- let filter =
- ('(nie:dataSource(?urn) = "%s")').format(this.resourceUrn);
+ let filter = '(false)';
+
+ if (this.resourceUrn)
+ filter = ('(nie:dataSource(?urn) = "%s")').format(this.resourceUrn);
return filter;
}
};
-function SourceManager(initCallback) {
- this._init(initCallback);
+function SourceManager() {
+ this._init();
};
SourceManager.prototype = {
- _init: function(initCallback) {
- this._client = null;
+ _init: function() {
this._sources = {};
+ this._activeSource = null;
- this._initCallback = initCallback;
-
- // two outstanding ops for the local sources, and one for the GOA client
- this._outstandingOps = 3;
+ // two outstanding ops for the local sources
+ this._outstandingOps = 2;
// Translators: this refers to documents
let source = new Source({ id: 'all',
name: _("All"),
- initCallback: Lang.bind(this, this._initSourceCollector) });
+ initCallback: Lang.bind(this, this._asyncSourceCollector) });
this._sources[source.id] = source;
// Translators: this refers to local documents
source = new Source({ id: 'local',
name: _("Local"),
- initCallback: Lang.bind(this, this._initSourceCollector) });
+ initCallback: Lang.bind(this, this._asyncSourceCollector) });
this._sources[source.id] = source;
- Goa.Client.new(null, Lang.bind(this, this._onGoaClientCreated));
+ Global.goaClient.connect('account-changed', Lang.bind(this, this._refreshGoaAccounts));
+ Global.goaClient.connect('account-removed', Lang.bind(this, this._refreshGoaAccounts));
+ this._refreshGoaAccounts();
},
- _onGoaClientCreated: function(object, res) {
- try {
- this._client = Goa.Client.new_finish(res);
- } catch (e) {
- log('Unable to create the GOA client: ' + e.toString());
- return;
+ _refreshGoaAccounts: function() {
+ let haveGoa = false;
+ let foundGoa = false;
+
+ for (idx in this._sources) {
+ if (this._sources[idx].object) {
+ haveGoa = true;
+ delete this._sources[idx];
+ }
}
- let accounts = this._client.get_accounts();
+ let accounts = Global.goaClient.get_accounts();
let modified = false;
accounts.forEach(Lang.bind(this,
@@ -139,41 +144,57 @@ SourceManager.prototype = {
if (!object.get_documents())
return;
+ foundGoa = true;
+
this._outstandingOps++;
let source = new Source({ object: object,
- initCallback: Lang.bind(this, this._initSourceCollector) });
+ initCallback: Lang.bind(this, this._asyncSourceCollector) });
this._sources[source.id] = source;
}));
+ if (!foundGoa && haveGoa)
+ this.emit('sources-changed');
+
let activeSourceId = Global.settings.get_string('active-source');
- this.setActiveSourceId(activeSourceId);
+ if (this._sources[activeSourceId])
+ activeSourceId = 'all';
- this._initSourceCollector();
+ this.setActiveSourceId(activeSourceId);
},
- _initSourceCollector: function() {
+ _asyncSourceCollector: function() {
this._outstandingOps--;
if (this._outstandingOps == 0)
- this._initCallback();
+ this.emit('sources-changed');
},
setActiveSourceId: function(id) {
- if (!this._sources[id])
+ let source = this._sources[id];
+
+ if (!source)
return;
- this.activeSource = this._sources[id];
- Global.settings.set_string('active-source', this.activeSource.id);
+ // wait for the uninitialized source to return and
+ // emit sources-changed instead
+ if (this.object && !this.resourceUrn)
+ return;
+
+ if (this._activeSource == source)
+ return;
+
+ this._activeSource = source;
+ Global.settings.set_string('active-source', this._activeSource.id);
this.emit('active-source-changed');
},
getActiveSourceId: function() {
- return this.activeSource.id;
+ return this._activeSource.id;
},
getActiveSourceFilter: function() {
- return this.activeSource.getFilter();
+ return this._activeSource.getFilter();
},
getSourceByUrn: function(resourceUrn) {
@@ -190,6 +211,17 @@ SourceManager.prototype = {
getSources: function() {
return this._sources;
+ },
+
+ getRemoteSources: function() {
+ let remoteSources = {};
+
+ for (idx in this._sources) {
+ if (this._sources[idx].resourceUrn)
+ remoteSources[idx] = this._sources[idx];
+ }
+
+ return remoteSources;
}
};
Signals.addSignalMethods(SourceManager.prototype);
@@ -210,6 +242,13 @@ SourceModel.prototype = {
_init: function() {
this.model = Gd.create_sources_store();
this._sourceManager = Global.sourceManager;
+ this._sourceManager.connect('sources-changed', Lang.bind(this, this._refreshModel));
+
+ this._refreshModel();
+ },
+
+ _refreshModel: function() {
+ this.model.clear();
let iter = this.model.append();
Gd.sources_store_set(this.model, iter,
diff --git a/src/trackerController.js b/src/trackerController.js
index 7e803b0..26902d4 100644
--- a/src/trackerController.js
+++ b/src/trackerController.js
@@ -42,6 +42,8 @@ TrackerController.prototype = {
this._refreshMinerNow();
this._sourceManager = Global.sourceManager;
+ this._sourceManager.connect('sources-changed',
+ Lang.bind(this, this._refresh));
this._sourceManager.connect('active-source-changed',
Lang.bind(this, this._refresh));
@@ -56,8 +58,6 @@ TrackerController.prototype = {
this._filterController = Global.filterController;
this._filterController.connect('filter-changed',
Lang.bind(this, this._onFilterChanged));
-
- this._refresh();
},
_refreshMinerNow: function() {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]