[folks] Add support to switch primary backend either by GConf or an env var
- From: Raul Gutierrez Segales <raulgs src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] Add support to switch primary backend either by GConf or an env var
- Date: Fri, 1 Apr 2011 20:55:34 +0000 (UTC)
commit 467672197a8225a4c9b91e541e80afe53fdbbfd4
Author: Raul Gutierrez Segales <raul gutierrez segales collabora co uk>
Date: Mon Mar 28 11:49:44 2011 +0100
Add support to switch primary backend either by GConf or an env var
configure.ac | 2 +
folks/Makefile.am | 3 ++
folks/individual-aggregator.vala | 58 ++++++++++++++++++++++++++++++++-----
3 files changed, 55 insertions(+), 8 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 6c51708..a12f8b4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -83,6 +83,7 @@ TP_GLIB_REQUIRED=0.13.1
VALA_REQUIRED=0.11.6
VALADOC_REQUIRED=0.2.1
TRACKER_SPARQL_REQUIRED=0.10
+GCONF2_REQUIRED=2.31
PKG_CHECK_MODULES([GLIB],
[glib-2.0 >= $GLIB_REQUIRED
@@ -90,6 +91,7 @@ PKG_CHECK_MODULES([GLIB],
PKG_CHECK_MODULES([GMODULE], [gmodule-no-export-2.0])
PKG_CHECK_MODULES([GIO], [gio-2.0 >= $GLIB_REQUIRED])
PKG_CHECK_MODULES([DBUS_GLIB], [dbus-glib-1])
+PKG_CHECK_MODULES([GCONF2], [gconf-2.0 >= $GCONF2_REQUIRED])
# FIXME: We depend on libgee < 0.7 because 0.7 breaks API. bgo#627746
PKG_CHECK_MODULES([GEE], [gee-1.0 < 0.7])
diff --git a/folks/Makefile.am b/folks/Makefile.am
index 4700b6b..4013118 100644
--- a/folks/Makefile.am
+++ b/folks/Makefile.am
@@ -46,6 +46,7 @@ libfolks_la_VALAFLAGS = \
--pkg gmodule-2.0 \
--pkg gio-2.0 \
--pkg gee-1.0 \
+ --pkg gconf-2.0 \
--vapi folks.vapi \
-H folks.h \
$(NULL)
@@ -55,6 +56,7 @@ libfolks_la_CFLAGS = \
$(GLIB_CFLAGS) \
$(GMODULE_CFLAGS) \
$(GEE_CFLAGS) \
+ $(GCONF2_CFLAGS) \
$(NULL)
libfolks_la_LIBADD = \
@@ -62,6 +64,7 @@ libfolks_la_LIBADD = \
$(GLIB_LIBS) \
$(GMODULE_LIBS) \
$(GEE_LIBS) \
+ $(GCONF2_LIBS) \
$(NULL)
# The quoting here is unnecessary but harmless, and has the useful side-effect
diff --git a/folks/individual-aggregator.vala b/folks/individual-aggregator.vala
index 6c0bb78..c1f3ebf 100644
--- a/folks/individual-aggregator.vala
+++ b/folks/individual-aggregator.vala
@@ -63,6 +63,9 @@ public class Folks.IndividualAggregator : Object
private HashTable<string, Individual> _link_map;
private bool _linking_enabled = true;
private bool _is_prepared = false;
+ private string _configured_writeable_store_type_id;
+ private static const string _FOLKS_CONFIG_KEY =
+ "/system/folks/backends/primary_store";
/**
* Whether { link IndividualAggregator.prepare} has successfully completed for
@@ -76,6 +79,23 @@ public class Folks.IndividualAggregator : Object
}
/**
+ * Our configured primary (writeable) store.
+ *
+ * Which one to use is decided (in order or precedence)
+ * by:
+ *
+ * - the FOLKS_WRITEABLE_STORE env var (mostly for debugging)
+ * - the GConf key set in _FOLKS_CONFIG_KEY (system set store)
+ * - going with the `key-file` store as the fall-back option
+ *
+ * @since UNRELEASED
+ */
+ public PersonaStore primary_store
+ {
+ get { return this._writeable_store; }
+ }
+
+ /**
* A table mapping { link Individual.id}s to their { link Individual}s.
*
* This is the canonical set of { link Individual}s provided by this
@@ -142,6 +162,28 @@ public class Folks.IndividualAggregator : Object
this._backends = new HashSet<Backend> ();
+ /* Check out the configured writeable store */
+ var store_type_id = Environment.get_variable ("FOLKS_WRITEABLE_STORE");
+ if (store_type_id != null)
+ {
+ this._configured_writeable_store_type_id = store_type_id;
+ }
+ else
+ {
+ this._configured_writeable_store_type_id = "key-file";
+ try
+ {
+ unowned GConf.Client client = GConf.Client.get_default ();
+ GConf.Value? val = client.get (this._FOLKS_CONFIG_KEY);
+ if (val != null)
+ this._configured_writeable_store_type_id = val.get_string ();
+ }
+ catch (GLib.Error e)
+ {
+ /* We ignore errors and go with the default store */
+ }
+ }
+
var disable_linking = Environment.get_variable ("FOLKS_DISABLE_LINKING");
if (disable_linking != null)
disable_linking = disable_linking.strip ().down ();
@@ -214,9 +256,9 @@ public class Folks.IndividualAggregator : Object
{
var store_id = this._get_store_full_id (store.type_id, store.id);
- /* FIXME: We hardcode the key-file backend's singleton PersonaStore as the
- * only trusted and writeable PersonaStore for now. */
- if (store.type_id == "key-file")
+ /* We use the configured PersonaStore as the only trusted and writeable
+ * PersonaStore. */
+ if (store.type_id == this._configured_writeable_store_type_id)
{
store.is_writeable = true;
store.trust_level = PersonaStoreTrust.FULL;
@@ -665,10 +707,10 @@ public class Folks.IndividualAggregator : Object
private void _trust_level_changed_cb (Object object, ParamSpec pspec)
{
- /* FIXME: For the moment, assert that only the key-file backend's
- * singleton PersonaStore is trusted. */
+ /* Only our writeable_store can be fully trusted. */
var store = (PersonaStore) object;
- if (store.type_id == "key-file")
+ if (this._writeable_store != null &&
+ store.type_id == this._writeable_store.type_id)
assert (store.trust_level == PersonaStoreTrust.FULL);
else
assert (store.trust_level != PersonaStoreTrust.FULL);
@@ -861,8 +903,8 @@ public class Folks.IndividualAggregator : Object
/* Create a new persona in the writeable store which links together the
* given personas */
- /* FIXME: We hardcode this to use the key-file backend for now */
- assert (this._writeable_store.type_id == "key-file");
+ assert (this._writeable_store.type_id ==
+ this._configured_writeable_store_type_id);
/* `protocols_addrs_set` will be passed to the new Kf.Persona */
var protocols_addrs_set =
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]