[folks] Add BackendStore.[enable|disable]_backend() methods
- From: Travis Reitter <treitter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] Add BackendStore.[enable|disable]_backend() methods
- Date: Thu, 4 Nov 2010 00:40:29 +0000 (UTC)
commit 1ed00cda2a890412bf301073f6daa6578e28509b
Author: Philip Withnall <philip withnall collabora co uk>
Date: Thu Sep 16 16:32:09 2010 +0100
Add BackendStore.[enable|disable]_backend() methods
These update the BackendStore's key file and save it asynchronously, but
don't load or unload the backends.
Helps bgo#629081.
NEWS | 2 +
folks/backend-store.vala | 53 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 55 insertions(+), 0 deletions(-)
---
diff --git a/NEWS b/NEWS
index f924136..faa4af4 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,8 @@ Overview of changes from libfolks 0.3.1 to libfolks 0.3.2
API changes:
* Added BackendStore.prepare() and BackendStore::is-prepared
+* Add BackendStore.enable_backend().
+* Add BackendStore.disable_backend().
Overview of changes from libfolks 0.3.0 to libfolks 0.3.1
==========================================================
diff --git a/folks/backend-store.vala b/folks/backend-store.vala
index 33dfb5c..c8cc427 100644
--- a/folks/backend-store.vala
+++ b/folks/backend-store.vala
@@ -275,6 +275,38 @@ public class Folks.BackendStore : Object {
return this.backend_hash.values;
}
+ /**
+ * Enable a backend.
+ *
+ * Mark a backend as enabled, such that the BackendStore will always attempt
+ * to load it when { link BackendStore.load_backends} is called. This will
+ * not load the backend if it's not currently loaded.
+ *
+ * @param name the name of the backend to enable
+ * @since 0.3.2
+ */
+ public async void enable_backend (string name)
+ {
+ this.backends_key_file.set_boolean (name, "enabled", true);
+ yield this.save_key_file ();
+ }
+
+ /**
+ * Disable a backend.
+ *
+ * Mark a backend as disabled, such that it won't be loaded even when the
+ * client application is restarted. This will not remove the backend if it's
+ * already loaded.
+ *
+ * @param name the name of the backend to disable
+ * @since 0.3.2
+ */
+ public async void disable_backend (string name)
+ {
+ this.backends_key_file.set_boolean (name, "enabled", false);
+ yield this.save_key_file ();
+ }
+
private async void load_modules_from_dir (File dir)
{
debug ("Searching for modules in folder '%s' ..", dir.get_path ());
@@ -450,4 +482,25 @@ public class Folks.BackendStore : Object {
}
}
}
+
+ private async void save_key_file ()
+ {
+ string key_file_data = this.backends_key_file.to_data ();
+
+ debug ("Saving backend key file '%s'.", this.config_file.get_path ());
+
+ try
+ {
+ /* Note: We have to use key_file_data.size () here to get its length
+ * in _bytes_ rather than _characters_. bgo#628930 */
+ yield this.config_file.replace_contents_async (key_file_data,
+ key_file_data.size (), null, false, FileCreateFlags.PRIVATE,
+ null);
+ }
+ catch (Error e)
+ {
+ warning ("Could not write updated backend key file '%s': %s",
+ this.config_file.get_path (), e.message);
+ }
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]