[glib/wip/gsettings-list] GSettings: implement _list method for GMemorySettingsBackend



commit 7b7667c18a8a3550a3e1ce92eefdef1db4408339
Author: Rodrigo Moya <rodrigo gnome-db org>
Date:   Thu Nov 4 13:18:52 2010 +0100

    GSettings: implement _list method for GMemorySettingsBackend

 gio/gkeyfilesettingsbackend.c |   10 +++++++
 gio/gmemorysettingsbackend.c  |   57 ++++++++++++++++++++++++++++++++++++++++-
 gio/gsettings.c               |    2 +-
 3 files changed, 67 insertions(+), 2 deletions(-)
---
diff --git a/gio/gkeyfilesettingsbackend.c b/gio/gkeyfilesettingsbackend.c
index f681ba9..d59e6a9 100644
--- a/gio/gkeyfilesettingsbackend.c
+++ b/gio/gkeyfilesettingsbackend.c
@@ -19,6 +19,7 @@
  *
  * Authors: Vincent Untz <vuntz gnome org>
  *          Ryan Lortie <desrt desrt ca>
+ *          Rodrigo Moya <rodrigo gnome org>
  */
 
 #include "config.h"
@@ -369,6 +370,14 @@ g_keyfile_settings_backend_get_permission (GSettingsBackend *backend,
   return g_object_ref (kfsb->permission);
 }
 
+static gchar **
+g_keyfile_settings_backend_list (GSettingsBackend    *backend,
+				 const gchar         *path,
+				 const gchar * const *schema_items)
+{
+  GKeyfileSettingsBackend *kfsb = G_KEYFILE_SETTINGS_BACKEND (backend);
+}
+
 static void
 keyfile_to_tree (GKeyfileSettingsBackend *kfsb,
                  GTree                   *tree,
@@ -536,6 +545,7 @@ g_keyfile_settings_backend_class_init (GKeyfileSettingsBackendClass *class)
   class->reset = g_keyfile_settings_backend_reset;
   class->get_writable = g_keyfile_settings_backend_get_writable;
   class->get_permission = g_keyfile_settings_backend_get_permission;
+  class->list = g_keyfile_settings_backend_list;
   /* No need to implement subscribed/unsubscribe: the only point would be to
    * stop monitoring the file when there's no GSettings anymore, which is no
    * big win. */
diff --git a/gio/gmemorysettingsbackend.c b/gio/gmemorysettingsbackend.c
index dc37f04..a282a7e 100644
--- a/gio/gmemorysettingsbackend.c
+++ b/gio/gmemorysettingsbackend.c
@@ -16,7 +16,8 @@
  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  * Boston, MA 02111-1307, USA.
  *
- * Author: Ryan Lortie <desrt desrt ca>
+ * Authors: Ryan Lortie <desrt desrt ca>
+ *          Rodrigo Moya <rodrigo gnome org>
  */
 
 #include "config.h"
@@ -226,6 +227,59 @@ g_memory_settings_backend_get_permission (GSettingsBackend *backend,
   return g_simple_permission_new (TRUE);
 }
 
+static gchar **
+g_memory_settings_backend_list (GSettingsBackend    *backend,
+				const gchar         *path,
+				const gchar * const *schema_items)
+{
+  gchar **result = NULL;
+  GHashTable *table;
+  GMemorySettingsBackend *memory = G_MEMORY_SETTINGS_BACKEND (backend);
+
+  table = g_memory_settings_backend_get_table (memory, &path);
+  if (table != NULL)
+    {
+      GHashTableIter iter;
+      gchar *key_name;
+      guint i;
+      GSList *list = NULL;
+
+      while (g_hash_table_iter_next (&iter, (gpointer *) &key_name, NULL))
+        {
+	  gboolean in_schema_items = FALSE;
+
+	  for (i = 0; i < g_strv_length (schema_items); i++)
+	    {
+	      if (g_str_equal (key_name, schema_items[i]))
+	        {
+		  /* It's in both lists, so return it */
+		  list = g_slist_append (list, key_name);
+		  in_schema_items = TRUE;
+		}
+	    }
+	  if (!in_schema_items)
+	    {
+	      /* Has been added by the user */
+	      list = g_slist_append (list, key_name);
+	    }
+	}
+
+      result = g_new0 (gchar *, g_slist_length (list) + 1);
+      i = 0;
+      while (list != NULL)
+        {
+	  result[i] = g_strdup ((const gchar *) list->data);
+	  i++;
+
+	  list = g_slist_remove (list, list->data);
+	}
+
+      result[i] = NULL;
+    }
+
+  return result;
+}
+
 static void
 g_memory_settings_backend_finalize (GObject *object)
 {
@@ -256,5 +310,6 @@ g_memory_settings_backend_class_init (GMemorySettingsBackendClass *class)
   backend_class->reset = g_memory_settings_backend_reset;
   backend_class->get_writable = g_memory_settings_backend_get_writable;
   backend_class->get_permission = g_memory_settings_backend_get_permission;
+  backend_class->list = g_memory_settings_backend_list;
   object_class->finalize = g_memory_settings_backend_finalize;
 }
diff --git a/gio/gsettings.c b/gio/gsettings.c
index 365ddd1..ffa0189 100644
--- a/gio/gsettings.c
+++ b/gio/gsettings.c
@@ -2826,7 +2826,7 @@ g_settings_list_keys (GSettings *settings)
  * time and you should connect to the "children-changed" signal to watch
  * for those changes.  Note that there is a race condition here: you may
  * request a child after listing it only for it to have been destroyed
- * in the meantime.  For this reason, g_settings_get_chuld() may return
+ * in the meantime.  For this reason, g_settings_get_child() may return
  * %NULL even for a child that was listed by this function.
  *
  * For GSettings objects that are not lists, you should probably not be



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