2
* Copyright (C) 2011 Collabora Ltd.
4
* This library is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License as published by
6
* the Free Software Foundation, either version 2.1 of the License, or
7
* (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU Lesser General Public License for more details.
14
* You should have received a copy of the GNU Lesser General Public License
15
* along with this library. If not, see <http://www.gnu.org/licenses/>.
18
* Travis Reitter <travis.reitter@collabora.co.uk>
19
* Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk>
23
using Folks.Backends.Tr;
27
extern const string BACKEND_NAME;
30
* A backend which connects to Tracker and creates a {@link PersonaStore}
33
public class Folks.Backends.Tr.Backend : Folks.Backend
35
private bool _is_prepared = false;
36
private HashMap<string, PersonaStore> _persona_stores;
37
private Map<string, PersonaStore> _persona_stores_ro;
42
public override string name { get { return BACKEND_NAME; } }
47
public override Map<string, PersonaStore> persona_stores
49
get { return this._persona_stores_ro; }
57
this._persona_stores = new HashMap<string, PersonaStore> ();
58
this._persona_stores_ro = this._persona_stores.read_only_view;
62
* Whether this Backend has been prepared.
64
* See {@link Folks.Backend.is_prepared}.
66
public override bool is_prepared
68
get { return this._is_prepared; }
75
public override async void prepare () throws GLib.Error
77
lock (this._is_prepared)
79
if (!this._is_prepared)
81
this._add_default_persona_store ();
82
this._is_prepared = true;
83
this.notify_property ("is-prepared");
91
public override async void unprepare () throws GLib.Error
93
foreach (var persona_store in this._persona_stores.values)
95
this.persona_store_removed (persona_store);
98
this._persona_stores.clear ();
99
this.notify_property ("persona-stores");
101
this._is_prepared = false;
102
this.notify_property ("is-prepared");
106
* Add a the default Persona Store.
108
private void _add_default_persona_store ()
110
var store = new Trf.PersonaStore ();
111
this._persona_stores.set (store.id, store);
112
store.removed.connect (this._store_removed_cb);
113
this.notify_property ("persona-stores");
114
this.persona_store_added (store);
117
private void _store_removed_cb (Folks.PersonaStore store)
119
store.removed.disconnect (this._store_removed_cb);
120
this.persona_store_removed (store);
121
this.persona_stores.unset (store.id);