~ubuntu-branches/ubuntu/quantal/folks/quantal

« back to all changes in this revision

Viewing changes to backends/eds/lib/edsf-persona-store.vala

  • Committer: Package Import Robot
  • Author(s): Robert Ancell
  • Date: 2012-09-12 09:48:10 UTC
  • mfrom: (1.6.2)
  • Revision ID: package-import@ubuntu.com-20120912094810-6zlx8889hcovxj7p
Tags: 0.7.4.1-0ubuntu1
* New upstream bugfix release
* debian/control:
  - Bump build-depends on libglib2.0-dev, valac-0.18, libvala-0.18-dev
* debian/libfolks-eds25.symbols:
* debian/libfolks25.symbols:
  - Updated

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
/* The following function is needed in order to use the async SourceRegistry
32
32
 * constructor. FIXME: https://bugzilla.gnome.org/show_bug.cgi?id=659886 */
33
33
[CCode (cname = "e_source_registry_new", cheader_filename = "libedataserver/libedataserver.h", finish_function = "e_source_registry_new_finish")]
34
 
public extern static async E.SourceRegistry create_source_registry (GLib.Cancellable? cancellable = null) throws GLib.Error;
 
34
internal extern static async E.SourceRegistry create_source_registry (GLib.Cancellable? cancellable = null) throws GLib.Error;
35
35
 
36
36
/**
37
 
 * A persona store.
38
 
 * It will create {@link Persona}s for each contacts on the main addressbook.
 
37
 * A persona store representing a single EDS address book.
 
38
 *
 
39
 * The persona store will contain {@link Edsf.Persona}s for each contact in the
 
40
 * address book it represents.
39
41
 */
40
42
public class Edsf.PersonaStore : Folks.PersonaStore
41
43
{
44
46
  private bool _is_prepared = false;
45
47
  private bool _prepare_pending = false;
46
48
  private bool _is_quiescent = false;
 
49
  private HashSet<Persona>? _pending_personas = null; /* null before prepare()*/
47
50
  private E.BookClient? _addressbook = null; /* null before prepare() */
48
51
  private E.BookClientView? _ebookview = null; /* null before prepare() */
49
52
  private E.SourceRegistry? _source_registry = null; /* null before prepare() */
175
178
          if (this._addressbook == null ||
176
179
              ((!) this._addressbook).readonly == true)
177
180
            {
178
 
              return this._always_writeable_properties_empty;
 
181
              return PersonaStore._always_writeable_properties_empty;
179
182
            }
180
183
 
181
184
          return this._always_writeable_properties;
224
227
   * @param s the e-d-s source being represented by the persona store
225
228
   *
226
229
   * @since 0.6.0
227
 
   * @deprecated 0.7.2 Use {@link Edsf.PersonaStore.with_source_registry}
228
230
   */
229
231
  [Deprecated (since = "0.7.2",
230
232
      replacement = "Edsf.PersonaStore.with_source_registry()")]
231
 
  public PersonaStore (E.SourceRegistry r, E.Source s)
 
233
  public PersonaStore (E.Source s)
232
234
    {
233
235
      string eds_uid = s.get_uid ();
234
236
      string eds_name = s.get_display_name ();
243
245
   * Create a new PersonaStore.
244
246
   *
245
247
   * Create a new persona store to store the {@link Persona}s for the contacts
246
 
   * in `s`. Passing a re-used source registry to the constructor (compared to
 
248
   * in ``s``. Passing a re-used source registry to the constructor (compared to
247
249
   * the old {@link Edsf.PersonaStore} constructor) saves a lot of time and
248
250
   * D-Bus round trips.
249
251
   *
315
317
  /**
316
318
   * Add a new {@link Persona} to the PersonaStore.
317
319
   *
318
 
   * Accepted keys for `details` are:
 
320
   * Accepted keys for ``details`` are:
319
321
   * - PersonaStore.detail_key (PersonaDetail.AVATAR)
320
322
   * - PersonaStore.detail_key (PersonaDetail.BIRTHDAY)
321
323
   * - PersonaStore.detail_key (PersonaDetail.EMAIL_ADDRESSES)
959
961
           * a quiescent state immediately. */
960
962
          if (do_initial_query == false && this._is_quiescent == false)
961
963
            {
 
964
              assert (this._pending_personas == null); /* no initial query */
962
965
              this._is_quiescent = true;
963
966
              this.notify_property ("is-quiescent");
964
967
            }
1271
1274
           * above. */
1272
1275
          yield ((!) this._addressbook).modify_contact (contact, null);
1273
1276
 
1274
 
          timeout_id = Timeout.add_seconds (this._property_change_timeout, () =>
 
1277
          timeout_id = Timeout.add_seconds (PersonaStore._property_change_timeout, () =>
1275
1278
            {
1276
1279
              /* Failure! Return to _commit_modified_property() without setting
1277
1280
               * received_notification. */
2074
2077
      Set<string> anti_links)
2075
2078
    {
2076
2079
      var vcard = (E.VCard) contact;
2077
 
      vcard.remove_attributes (null, this.anti_links_attribute_name);
 
2080
      vcard.remove_attributes (null, PersonaStore.anti_links_attribute_name);
2078
2081
 
2079
2082
      var persona_uid =
2080
2083
          Folks.Persona.build_uid (BACKEND_NAME, this.id, contact.id);
2088
2091
            }
2089
2092
 
2090
2093
          var attr = new E.VCardAttribute (null,
2091
 
              this.anti_links_attribute_name);
 
2094
              PersonaStore.anti_links_attribute_name);
2092
2095
          attr.add_value (anti_link_uid);
2093
2096
 
2094
2097
          contact.add_attribute ((owned) attr);
2097
2100
 
2098
2101
  private void _contacts_added_cb (GLib.List<E.Contact> contacts)
2099
2102
    {
2100
 
      var added_personas = new HashSet<Persona> ();
2101
 
      lock (this._personas)
2102
 
        {
2103
 
          foreach (E.Contact c in contacts)
2104
 
            {
2105
 
              var iid = Edsf.Persona.build_iid_from_contact (this.id, c);
2106
 
              if (this._personas.has_key (iid) == false)
2107
 
                {
2108
 
                  var persona = new Persona (this, c);
2109
 
                  this._personas.set (persona.iid, persona);
2110
 
                  added_personas.add (persona);
2111
 
                }
2112
 
            }
2113
 
        }
2114
 
 
2115
 
      if (added_personas.size > 0)
 
2103
      HashSet<Persona> added_personas;
 
2104
 
 
2105
      /* If the persona store hasn't yet reached quiescence, queue up the
 
2106
       * personas and emit a notification about them later; see
 
2107
       * _contacts_complete_cb() for details. */
 
2108
      if (this._is_quiescent == false)
 
2109
        {
 
2110
          /* Lazily create pending_personas. */
 
2111
          if (this._pending_personas == null)
 
2112
            {
 
2113
              this._pending_personas = new HashSet<Persona> ();
 
2114
            }
 
2115
 
 
2116
          added_personas = this._pending_personas;
 
2117
        }
 
2118
      else
 
2119
        {
 
2120
          added_personas = new HashSet<Persona> ();
 
2121
        }
 
2122
 
 
2123
      foreach (E.Contact c in contacts)
 
2124
        {
 
2125
          var iid = Edsf.Persona.build_iid_from_contact (this.id, c);
 
2126
          if (this._personas.has_key (iid) == false)
 
2127
            {
 
2128
              var persona = new Persona (this, c);
 
2129
              this._personas.set (persona.iid, persona);
 
2130
              added_personas.add (persona);
 
2131
            }
 
2132
        }
 
2133
 
 
2134
      if (added_personas.size > 0 && this._is_quiescent == true)
2116
2135
        {
2117
2136
          this._emit_personas_changed (added_personas, null);
2118
2137
        }
2143
2162
            {
2144
2163
              removed_personas.add ((!) persona);
2145
2164
              this._personas.unset (((!) persona).iid);
 
2165
 
 
2166
              /* Handle the case where a contact is removed before the persona
 
2167
               * store has reached quiescence. */
 
2168
              if (this._pending_personas != null)
 
2169
                {
 
2170
                  this._pending_personas.remove ((!) persona);
 
2171
                }
2146
2172
            }
2147
2173
        }
2148
2174
 
2179
2205
              return;
2180
2206
            }
2181
2207
 
 
2208
          /* Emit a notification about all the personas which were found in the
 
2209
           * initial query. They're queued up in _contacts_added_cb() and only
 
2210
           * emitted here as _contacts_added_cb() may be called many times
 
2211
           * before _contacts_complete_cb() is called. For example, EDS seems to
 
2212
           * like emitting contacts in batches of 16 at the moment.
 
2213
           * Queueing the personas up and emitting a single notification is a
 
2214
           * lot more efficient for the individual aggregator to handle. */
 
2215
          if (this._pending_personas != null)
 
2216
            {
 
2217
              this._emit_personas_changed (this._pending_personas, null);
 
2218
              this._pending_personas = null;
 
2219
            }
 
2220
 
2182
2221
          this._is_quiescent = true;
2183
2222
          this.notify_property ("is-quiescent");
2184
2223
        }