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;
38
* It will create {@link Persona}s for each contacts on the main addressbook.
37
* A persona store representing a single EDS address book.
39
* The persona store will contain {@link Edsf.Persona}s for each contact in the
40
* address book it represents.
40
42
public class Edsf.PersonaStore : Folks.PersonaStore
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)
178
return this._always_writeable_properties_empty;
181
return PersonaStore._always_writeable_properties_empty;
181
184
return this._always_writeable_properties;
224
227
* @param s the e-d-s source being represented by the persona store
227
* @deprecated 0.7.2 Use {@link Edsf.PersonaStore.with_source_registry}
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)
233
235
string eds_uid = s.get_uid ();
234
236
string eds_name = s.get_display_name ();
243
245
* Create a new PersonaStore.
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.
316
318
* Add a new {@link Persona} to the PersonaStore.
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)
964
assert (this._pending_personas == null); /* no initial query */
962
965
this._is_quiescent = true;
963
966
this.notify_property ("is-quiescent");
1272
1275
yield ((!) this._addressbook).modify_contact (contact, null);
1274
timeout_id = Timeout.add_seconds (this._property_change_timeout, () =>
1277
timeout_id = Timeout.add_seconds (PersonaStore._property_change_timeout, () =>
1276
1279
/* Failure! Return to _commit_modified_property() without setting
1277
1280
* received_notification. */
2074
2077
Set<string> anti_links)
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);
2079
2082
var persona_uid =
2080
2083
Folks.Persona.build_uid (BACKEND_NAME, this.id, contact.id);
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);
2094
2097
contact.add_attribute ((owned) attr);
2098
2101
private void _contacts_added_cb (GLib.List<E.Contact> contacts)
2100
var added_personas = new HashSet<Persona> ();
2101
lock (this._personas)
2103
foreach (E.Contact c in contacts)
2105
var iid = Edsf.Persona.build_iid_from_contact (this.id, c);
2106
if (this._personas.has_key (iid) == false)
2108
var persona = new Persona (this, c);
2109
this._personas.set (persona.iid, persona);
2110
added_personas.add (persona);
2115
if (added_personas.size > 0)
2103
HashSet<Persona> added_personas;
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)
2110
/* Lazily create pending_personas. */
2111
if (this._pending_personas == null)
2113
this._pending_personas = new HashSet<Persona> ();
2116
added_personas = this._pending_personas;
2120
added_personas = new HashSet<Persona> ();
2123
foreach (E.Contact c in contacts)
2125
var iid = Edsf.Persona.build_iid_from_contact (this.id, c);
2126
if (this._personas.has_key (iid) == false)
2128
var persona = new Persona (this, c);
2129
this._personas.set (persona.iid, persona);
2130
added_personas.add (persona);
2134
if (added_personas.size > 0 && this._is_quiescent == true)
2117
2136
this._emit_personas_changed (added_personas, null);
2144
2163
removed_personas.add ((!) persona);
2145
2164
this._personas.unset (((!) persona).iid);
2166
/* Handle the case where a contact is removed before the persona
2167
* store has reached quiescence. */
2168
if (this._pending_personas != null)
2170
this._pending_personas.remove ((!) persona);
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)
2217
this._emit_personas_changed (this._pending_personas, null);
2218
this._pending_personas = null;
2182
2221
this._is_quiescent = true;
2183
2222
this.notify_property ("is-quiescent");