~ubuntu-branches/ubuntu/precise/folks/precise

« back to all changes in this revision

Viewing changes to backends/tracker/tr-backend.vala

  • Committer: Bazaar Package Importer
  • Author(s): Ken VanDine
  • Date: 2011-06-10 11:28:11 UTC
  • mfrom: (1.2.11 upstream) (4.2.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20110610112811-whyeodbo9mjezxfp
Tags: 0.5.2-1ubuntu1
* Merge with Debian experimental, remaining Ubuntu changes:
  - debian/control:
    + Add Vcs-Bzr link

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2011 Collabora Ltd.
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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/>.
 
16
 *
 
17
 * Authors:
 
18
 *       Travis Reitter <travis.reitter@collabora.co.uk>
 
19
 *       Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk>
 
20
 */
 
21
 
 
22
using Folks;
 
23
using Folks.Backends.Tr;
 
24
using GLib;
 
25
using Gee;
 
26
 
 
27
extern const string BACKEND_NAME;
 
28
 
 
29
/**
 
30
 * A backend which connects to Tracker and creates a {@link PersonaStore}
 
31
 * for each service.
 
32
 */
 
33
public class Folks.Backends.Tr.Backend : Folks.Backend
 
34
{
 
35
  private bool _is_prepared = false;
 
36
  private HashMap<string, PersonaStore> _persona_stores;
 
37
  private Map<string, PersonaStore> _persona_stores_ro;
 
38
 
 
39
  /**
 
40
   * {@inheritDoc}
 
41
   */
 
42
  public override string name { get { return BACKEND_NAME; } }
 
43
 
 
44
  /**
 
45
   * {@inheritDoc}
 
46
   */
 
47
  public override Map<string, PersonaStore> persona_stores
 
48
    {
 
49
      get { return this._persona_stores_ro; }
 
50
    }
 
51
 
 
52
  /**
 
53
   * {@inheritDoc}
 
54
   */
 
55
  public Backend ()
 
56
    {
 
57
      this._persona_stores = new HashMap<string, PersonaStore> ();
 
58
      this._persona_stores_ro = this._persona_stores.read_only_view;
 
59
    }
 
60
 
 
61
  /**
 
62
   * Whether this Backend has been prepared.
 
63
   *
 
64
   * See {@link Folks.Backend.is_prepared}.
 
65
   */
 
66
  public override bool is_prepared
 
67
    {
 
68
      get { return this._is_prepared; }
 
69
    }
 
70
 
 
71
  /**
 
72
   * {@inheritDoc}
 
73
   *
 
74
   */
 
75
  public override async void prepare () throws GLib.Error
 
76
    {
 
77
      lock (this._is_prepared)
 
78
        {
 
79
          if (!this._is_prepared)
 
80
            {
 
81
              this._add_default_persona_store ();
 
82
              this._is_prepared = true;
 
83
              this.notify_property ("is-prepared");
 
84
            }
 
85
        }
 
86
    }
 
87
 
 
88
  /**
 
89
   * {@inheritDoc}
 
90
   */
 
91
  public override async void unprepare () throws GLib.Error
 
92
    {
 
93
      foreach (var persona_store in this._persona_stores.values)
 
94
        {
 
95
          this.persona_store_removed (persona_store);
 
96
        }
 
97
 
 
98
      this._persona_stores.clear ();
 
99
      this.notify_property ("persona-stores");
 
100
 
 
101
      this._is_prepared = false;
 
102
      this.notify_property ("is-prepared");
 
103
    }
 
104
 
 
105
  /**
 
106
   * Add a the default Persona Store.
 
107
   */
 
108
  private void _add_default_persona_store ()
 
109
    {
 
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);
 
115
    }
 
116
 
 
117
  private void _store_removed_cb (Folks.PersonaStore store)
 
118
    {
 
119
      store.removed.disconnect (this._store_removed_cb);
 
120
      this.persona_store_removed (store);
 
121
      this.persona_stores.unset (store.id);
 
122
    }
 
123
}