[folks] keyfile: Add enable/disable_persona_store to keyfile backend. keyfile: Add set_persona_stores to key
- From: Jeremy Whiting <jpwhiting src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] keyfile: Add enable/disable_persona_store to keyfile backend. keyfile: Add set_persona_stores to key
- Date: Wed, 10 Oct 2012 20:16:02 +0000 (UTC)
commit 0ffb154fa48282484fef6776f9435c41cbe149aa
Author: Jeremy Whiting <jpwhiting kde org>
Date: Wed Sep 26 15:35:02 2012 -0600
keyfile: Add enable/disable_persona_store to keyfile backend.
keyfile: Add set_persona_stores to keyfile backend.
backends/key-file/kf-backend.vala | 129 +++++++++++++++++++++++++++++++++----
1 files changed, 116 insertions(+), 13 deletions(-)
---
diff --git a/backends/key-file/kf-backend.vala b/backends/key-file/kf-backend.vala
index bb29a74..e118ebd 100644
--- a/backends/key-file/kf-backend.vala
+++ b/backends/key-file/kf-backend.vala
@@ -80,6 +80,83 @@ public class Folks.Backends.Kf.Backend : Folks.Backend
/**
* { inheritDoc}
*/
+ public override void enable_persona_store (Folks.PersonaStore store)
+ {
+ if (this._persona_stores.has_key (store.id) == false)
+ {
+ this._add_store ((Kf.PersonaStore) store);
+ }
+ }
+
+ /**
+ * { inheritDoc}
+ */
+ public override void disable_persona_store (Folks.PersonaStore store)
+ {
+ if (this._persona_stores.has_key (store.id))
+ {
+ this._store_removed_cb (store);
+ }
+ }
+
+ private File _get_default_file (string basename = "relationships")
+ {
+ string filename = basename + ".ini";
+ File file = File.new_for_path (Environment.get_user_data_dir ());
+ file = file.get_child ("folks");
+ file = file.get_child (filename);
+ return file;
+ }
+
+ /**
+ * { inheritDoc}
+ * In this implementation storeids are assumed to be base filenames for
+ * ini files under user_data_dir()/folks/ like the default relationships
+ * { link PersonaStore}.
+ */
+ public override void set_persona_stores (Set<string>? storeids)
+ {
+ /* All ids represent ini files in user_data_dir/folks/ */
+
+ bool added_stores = false;
+ PersonaStore[] removed_stores = {};
+
+ /* First handle adding any missing persona stores. */
+ foreach (string id in storeids)
+ {
+ if (this._persona_stores.has_key (id) == false)
+ {
+ File file = this._get_default_file (id);
+
+ PersonaStore store = new Kf.PersonaStore (file);
+ this._add_store (store, false);
+ added_stores = true;
+ }
+ }
+
+ foreach (PersonaStore store in this._persona_stores.values)
+ {
+ if (!storeids.contains (store.id))
+ {
+ removed_stores += store;
+ }
+ }
+
+ for (int i = 0; i < removed_stores.length; ++i)
+ {
+ this._remove_store ((Kf.PersonaStore) removed_stores[i], false);
+ }
+
+ /* Finally, if anything changed, emit the persona-stores notification. */
+ if (added_stores || removed_stores.length > 0)
+ {
+ this.notify_property ("persona-stores");
+ }
+ }
+
+ /**
+ * { inheritDoc}
+ */
public Backend ()
{
Object ();
@@ -112,9 +189,7 @@ public class Folks.Backends.Kf.Backend : Folks.Backend
"FOLKS_BACKEND_KEY_FILE_PATH");
if (path == null)
{
- file = File.new_for_path (Environment.get_user_data_dir ());
- file = file.get_child ("folks");
- file = file.get_child ("relationships.ini");
+ file = this._get_default_file ();
debug ("Using built-in key file '%s' (override with " +
"environment variable FOLKS_BACKEND_KEY_FILE_PATH)",
@@ -130,12 +205,8 @@ public class Folks.Backends.Kf.Backend : Folks.Backend
/* Create the PersonaStore for the key file */
PersonaStore store = new Kf.PersonaStore (file);
-
- this._persona_stores.set (store.id, store);
- store.removed.connect (this._store_removed_cb);
- this.notify_property ("persona-stores");
-
- this.persona_store_added (store);
+
+ this._add_store (store);
this._is_prepared = true;
this.notify_property ("is-prepared");
@@ -152,6 +223,41 @@ public class Folks.Backends.Kf.Backend : Folks.Backend
}
/**
+ * Utility function to add a persona store.
+ *
+ * @param store the store to add.
+ * @param notify whether or not to emit notification signals.
+ */
+ private void _add_store (PersonaStore store, bool notify = true)
+ {
+ this._persona_stores.set (store.id, store);
+ store.removed.connect (this._store_removed_cb);
+ this.persona_store_added (store);
+ if (notify)
+ {
+ this.notify_property ("persona-stores");
+ }
+ }
+
+ /**
+ * Utility function to remove a persona store.
+ *
+ * @param store the store to remove.
+ * @param notify whether or not to emit notification signals.
+ */
+ private void _remove_store (PersonaStore store, bool notify = true)
+ {
+ store.removed.disconnect (this._store_removed_cb);
+ this._persona_stores.unset (store.id);
+ this.persona_store_removed (store);
+
+ if (notify)
+ {
+ this.notify_property ("persona-stores");
+ }
+ }
+
+ /**
* { inheritDoc}
*/
public override async void unprepare () throws GLib.Error
@@ -187,9 +293,6 @@ public class Folks.Backends.Kf.Backend : Folks.Backend
private void _store_removed_cb (Folks.PersonaStore store)
{
- store.removed.disconnect (this._store_removed_cb);
- this.persona_store_removed (store);
- this._persona_stores.unset (store.id);
- this.notify_property ("persona-stores");
+ this._remove_store ((Kf.PersonaStore) store);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]