2
* Copyright (c) 2011 Red Hat, Inc.
4
* Gnome Documents is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by the
6
* Free Software Foundation; either version 2 of the License, or (at your
7
* option) any later version.
9
* Gnome Documents is distributed in the hope that it will be useful, but
10
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* You should have received a copy of the GNU General Public License along
15
* with Gnome Documents; if not, write to the Free Software Foundation,
16
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
* Author: Cosimo Cecchi <cosimoc@redhat.com>
22
const Lang = imports.lang;
24
const Gio = imports.gi.Gio;
25
const Goa = imports.gi.Goa;
26
const _ = imports.gettext.gettext;
28
const Global = imports.global;
29
const Manager = imports.manager;
36
const Source = new Lang.Class({
39
_init: function(params) {
45
this.object = params.object;
46
let account = params.object.get_account();
48
this.id = 'gd:goa-account:' + account.id;
49
this.name = account.provider_name;
50
this.icon = Gio.icon_new_for_string(account.provider_icon);
53
this.name = params.name;
56
this.builtin = params.builtin;
59
getFilter: function() {
60
if (this.id == SourceStock.LOCAL)
61
return Global.queryBuilder.buildFilterLocal();
63
if (this.id == SourceStock.ALL)
64
return '(' + Global.queryBuilder.buildFilterLocal() + ' || '
65
+ Global.queryBuilder.buildFilterNotLocal() + ')';
67
return this._buildFilterResource();
70
_buildFilterResource: function() {
71
let filter = '(false)';
74
filter = ('(nie:dataSource(?urn) = "%s")').format(this.id);
80
const SourceManager = new Lang.Class({
81
Name: 'SourceManager',
82
Extends: Manager.BaseManager,
85
this.parent(_("Sources"));
87
// Translators: this refers to documents
88
let source = new Source({ id: SourceStock.ALL,
93
// Translators: this refers to local documents
94
source = new Source({ id: SourceStock.LOCAL,
99
Global.goaClient.connect('account-added', Lang.bind(this, this._refreshGoaAccounts));
100
Global.goaClient.connect('account-changed', Lang.bind(this, this._refreshGoaAccounts));
101
Global.goaClient.connect('account-removed', Lang.bind(this, this._refreshGoaAccounts));
103
this._refreshGoaAccounts();
104
this.setActiveItemById(SourceStock.ALL);
107
_refreshGoaAccounts: function() {
109
let accounts = Global.goaClient.get_accounts();
111
accounts.forEach(Lang.bind(this,
113
if (!object.get_account())
116
if (!object.get_documents())
119
let source = new Source({ object: object });
120
newItems[source.id] = source;
123
this.processNewItems(newItems);
126
hasOnlineSources: function() {
127
let hasOnline = false;
137
hasProviderType: function(providerType) {
139
this.forEachItem(Lang.bind(this,
144
let account = source.object.get_account();
151
if (account.provider_type == providerType)