[folks] Support the 'all-others' wildcard group in BACKEND_STORE_KEY_FILE.



commit db4fe26826df1abbee0440d5714863264f969cd2
Author: Travis Reitter <travis reitter collabora co uk>
Date:   Mon Feb 14 23:25:33 2011 -0800

    Support the 'all-others' wildcard group in BACKEND_STORE_KEY_FILE.
    
    Helps bgo#642351 - BACKEND_STORE_KEY_FILE format should support a wildcard entry

 folks/backend-store.vala |   52 +++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 51 insertions(+), 1 deletions(-)
---
diff --git a/folks/backend-store.vala b/folks/backend-store.vala
index a5ae50d..7f0e743 100644
--- a/folks/backend-store.vala
+++ b/folks/backend-store.vala
@@ -52,6 +52,20 @@ public class Folks.BackendStore : Object {
   private Debug _debug;
 
   /**
+   * This keyword in the keyfile acts as a wildcard for all backends not already
+   * listed in the same file.
+   *
+   * This is particularly useful for tests which want to ensure they're only
+   * operating with backends they were designed for (and thus may not be able to
+   * enumerate entries for).
+   *
+   * To avoid conflicts, backends must not use this as a name.
+   *
+   * @since 0.3.UNRELEASED
+   */
+  public static string KEY_FILE_GROUP_ALL_OTHERS = "all-others";
+
+  /**
    * Emitted when a backend has been added to the BackendStore.
    *
    * This will not be emitted until after { link BackendStore.load_backends}
@@ -320,6 +334,31 @@ public class Folks.BackendStore : Object {
 
   private bool _backend_is_enabled (string name)
     {
+      var all_others_enabled = true;
+      try
+        {
+          all_others_enabled = this._backends_key_file.get_boolean (
+              this.KEY_FILE_GROUP_ALL_OTHERS, "enabled");
+        }
+      catch (KeyFileError e)
+        {
+          if (!(e is KeyFileError.GROUP_NOT_FOUND) &&
+              !(e is KeyFileError.KEY_NOT_FOUND))
+            {
+              warning ("Couldn't determine whether to enable or disable " +
+                  "backends not listed in backend key file. Defaulting to %s.",
+                  all_others_enabled ? "enabled" : "disabled");
+            }
+          else
+            {
+              debug ("No catch-all entry in the backend key file. %s " +
+                  "unlisted backends.",
+                  all_others_enabled ? "Enabling" : "Disabling");
+            }
+
+          /* fall back to the default in case of any level of failure */
+        }
+
       var enabled = true;
       try
         {
@@ -327,7 +366,18 @@ public class Folks.BackendStore : Object {
         }
       catch (KeyFileError e)
         {
-          if (!(e is KeyFileError.GROUP_NOT_FOUND) &&
+          /* if there's no entry for this backend, use the default set above */
+          if ((e is KeyFileError.GROUP_NOT_FOUND) ||
+              (e is KeyFileError.KEY_NOT_FOUND))
+            {
+              debug ("Found no entry for backend '%s'.enabled in backend " +
+                  "keyfile. %s according to '%s' setting.",
+                  name,
+                  all_others_enabled ? "Enabling" : "Disabling",
+                  this.KEY_FILE_GROUP_ALL_OTHERS);
+              enabled = all_others_enabled;
+            }
+          else if (!(e is KeyFileError.GROUP_NOT_FOUND) &&
               !(e is KeyFileError.KEY_NOT_FOUND))
             {
               warning ("Couldn't check enabled state of backend '%s': %s\n" +



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]