Commit 1ec09812 authored by Jeremy Whiting's avatar Jeremy Whiting

core: Add set_persona_stores method to Backend.

eds: Implement set_persona_stores in eds backend.
parent 81a1d481
...@@ -47,6 +47,7 @@ public class Folks.Backends.Eds.Backend : Folks.Backend ...@@ -47,6 +47,7 @@ public class Folks.Backends.Eds.Backend : Folks.Backend
private HashMap<string, PersonaStore> _persona_stores; private HashMap<string, PersonaStore> _persona_stores;
private Map<string, PersonaStore> _persona_stores_ro; private Map<string, PersonaStore> _persona_stores_ro;
private E.SourceRegistry _ab_sources; private E.SourceRegistry _ab_sources;
private Set<string>? _storeids;
/** /**
* {@inheritDoc} * {@inheritDoc}
...@@ -71,20 +72,81 @@ public class Folks.Backends.Eds.Backend : Folks.Backend ...@@ -71,20 +72,81 @@ public class Folks.Backends.Eds.Backend : Folks.Backend
this._remove_address_book (store); this._remove_address_book (store);
} }
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public override void enable_persona_store (PersonaStore store) public override void enable_persona_store (PersonaStore store)
{ {
if (!this._persona_stores.has_key (store.id)) if (this._persona_stores.has_key (store.id) == false)
{
this._add_persona_store (store);
}
}
private void _add_persona_store (PersonaStore store, bool notify = true)
{
store.removed.connect (this._store_removed_cb);
this._persona_stores.set (store.id, store);
this.persona_store_added (store);
if (notify)
{
this.notify_property ("persona-stores");
}
}
/**
* {@inheritDoc}
*/
public override void set_persona_stores (Set<string>? storeids)
{
this._storeids = storeids;
bool stores_changed = false;
/* First handle adding any missing persona stores. */
foreach (string id in storeids)
{
if (this._persona_stores.has_key (id) == false)
{
E.Source? s = this._ab_sources.ref_source (id);
if (s == null)
{
warning ("Unable to reference EDS source with ID %s", id);
continue;
}
var store =
new Edsf.PersonaStore.with_source_registry (this._ab_sources, s);
this._add_persona_store (store, false);
stores_changed = true;
}
}
/* Keep persona stores to remove in a separate array so we don't
* invalidate the list we are iterating over. */
PersonaStore[] stores_to_remove = {};
foreach (PersonaStore store in this._persona_stores.values)
{
if (!storeids.contains (store.id))
{
stores_to_remove += store;
stores_changed = true;
}
}
for (int i = 0; i < stores_to_remove.length; ++i)
{
this._remove_address_book (stores_to_remove[i], false);
}
/* Finally, if anything changed, emit the persona-stores notification. */
if (stores_changed)
{ {
store.removed.connect (this._store_removed_cb);
this._persona_stores.set (store.id, store);
this.notify_property ("persona-stores"); this.notify_property ("persona-stores");
this.persona_store_added (store);
} }
} }
...@@ -100,6 +162,7 @@ public class Folks.Backends.Eds.Backend : Folks.Backend ...@@ -100,6 +162,7 @@ public class Folks.Backends.Eds.Backend : Folks.Backend
{ {
this._persona_stores = new HashMap<string, PersonaStore> (); this._persona_stores = new HashMap<string, PersonaStore> ();
this._persona_stores_ro = this._persona_stores.read_only_view; this._persona_stores_ro = this._persona_stores.read_only_view;
this._storeids = null;
} }
/** /**
...@@ -236,6 +299,12 @@ public class Folks.Backends.Eds.Backend : Folks.Backend ...@@ -236,6 +299,12 @@ public class Folks.Backends.Eds.Backend : Folks.Backend
{ {
continue; continue;
} }
if (this._storeids != null &&
!(uid in this._storeids))
{
continue;
}
if (!this._persona_stores.has_key (uid)) if (!this._persona_stores.has_key (uid))
{ {
...@@ -268,14 +337,17 @@ public class Folks.Backends.Eds.Backend : Folks.Backend ...@@ -268,14 +337,17 @@ public class Folks.Backends.Eds.Backend : Folks.Backend
this.enable_persona_store (store); this.enable_persona_store (store);
} }
private void _remove_address_book (Folks.PersonaStore store) private void _remove_address_book (Folks.PersonaStore store, bool notify = true)
{ {
debug ("Removing address book '%s'.", store.id); debug ("Removing address book '%s'.", store.id);
this.persona_store_removed (store); this.persona_store_removed (store);
this._persona_stores.unset (store.id); this._persona_stores.unset (store.id);
this.notify_property ("persona-stores"); if (notify)
{
this.notify_property ("persona-stores");
}
store.removed.disconnect (this._store_removed_cb); store.removed.disconnect (this._store_removed_cb);
} }
......
...@@ -116,6 +116,24 @@ public abstract class Folks.Backend : Object ...@@ -116,6 +116,24 @@ public abstract class Folks.Backend : Object
*/ */
public abstract void enable_persona_store (PersonaStore store); public abstract void enable_persona_store (PersonaStore store);
/**
* Set the {@link PersonaStore}s to use in this backend.
*
* This will cause {@link Backend.persona_store_removed} signals to be emitted
* for all removed stores, followed by {@link Backend.persona_store_added}
* signals for all added stores. As these signals are emitted, the sets of
* individuals in any associated {@link IndividualAggregator}s will be
* updated, and {@link IndividualAggregator.individuals_changed} may be
* emitted multiple times as appropriate. A property change notification for
* {@link Backend.persona_stores} will be emitted last.
* Note: pass null storeids to use all available persona stores.
*
* @param storeids a Set of {@link PersonaStore} IDs to use.
*
* @since UNRELEASED
*/
public abstract void set_persona_stores (Set<string>? storeids);
/** /**
* Emitted when a {@link PersonaStore} is added to the backend. * Emitted when a {@link PersonaStore} is added to the backend.
* *
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment