[glib] GSettingsSchema: add g_settings_schema_list_keys()



commit 82fcfeb3b065d7cc4d53e80776f9b476df7c2137
Author: Ryan Lortie <desrt desrt ca>
Date:   Wed Nov 19 12:40:22 2014 -0500

    GSettingsSchema: add g_settings_schema_list_keys()
    
    The list of keys in a GSettings object depends entirely on the schema,
    so it makes sense to expose this API there.
    
    Move the implementation out of gsettings.c and into gsettingsschema.c,
    replacing the earlier with a simple call to the new location.
    
    We don't do the same for children because the children can change.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=740308

 gio/gsettings.c       |   18 +-----------------
 gio/gsettingsschema.c |   41 +++++++++++++++++++++++++++++++++++++++++
 gio/gsettingsschema.h |    3 +++
 3 files changed, 45 insertions(+), 17 deletions(-)
---
diff --git a/gio/gsettings.c b/gio/gsettings.c
index 67bd3d8..666a48a 100644
--- a/gio/gsettings.c
+++ b/gio/gsettings.c
@@ -2308,23 +2308,7 @@ g_settings_get_child (GSettings   *settings,
 gchar **
 g_settings_list_keys (GSettings *settings)
 {
-  const GQuark *keys;
-  gchar **strv;
-  gint n_keys;
-  gint i, j;
-
-  keys = g_settings_schema_list (settings->priv->schema, &n_keys);
-  strv = g_new (gchar *, n_keys + 1);
-  for (i = j = 0; i < n_keys; i++)
-    {
-      const gchar *key = g_quark_to_string (keys[i]);
-
-      if (!g_str_has_suffix (key, "/"))
-        strv[j++] = g_strdup (key);
-    }
-  strv[j] = NULL;
-
-  return strv;
+  return g_settings_schema_list_keys (settings->priv->schema);
 }
 
 /**
diff --git a/gio/gsettingsschema.c b/gio/gsettingsschema.c
index e3966fd..9555c0a 100644
--- a/gio/gsettingsschema.c
+++ b/gio/gsettingsschema.c
@@ -1036,6 +1036,8 @@ g_settings_schema_list_children (GSettingsSchema *schema)
   gint n_keys;
   gint i, j;
 
+  g_return_val_if_fail (schema != NULL, NULL);
+
   keys = g_settings_schema_list (schema, &n_keys);
   strv = g_new (gchar *, n_keys + 1);
   for (i = j = 0; i < n_keys; i++)
@@ -1056,6 +1058,45 @@ g_settings_schema_list_children (GSettingsSchema *schema)
   return strv;
 }
 
+/**
+ * g_settings_schema_list_keys:
+ * @schema: a #GSettingsSchema
+ *
+ * Introspects the list of keys on @schema.
+ *
+ * You should probably not be calling this function from "normal" code
+ * (since you should already know what keys are in your schema).  This
+ * function is intended for introspection reasons.
+ *
+ * Returns: (transfer full) (element-type utf8): a list of the keys on
+ *   @schema
+ *
+ * Since: 2.46
+ */
+gchar **
+g_settings_schema_list_keys (GSettingsSchema *schema)
+{
+  const GQuark *keys;
+  gchar **strv;
+  gint n_keys;
+  gint i, j;
+
+  g_return_val_if_fail (schema != NULL, NULL);
+
+  keys = g_settings_schema_list (schema, &n_keys);
+  strv = g_new (gchar *, n_keys + 1);
+  for (i = j = 0; i < n_keys; i++)
+    {
+      const gchar *key = g_quark_to_string (keys[i]);
+
+      if (!g_str_has_suffix (key, "/"))
+        strv[j++] = g_strdup (key);
+    }
+  strv[j] = NULL;
+
+  return strv;
+}
+
 const GQuark *
 g_settings_schema_list (GSettingsSchema *schema,
                         gint            *n_items)
diff --git a/gio/gsettingsschema.h b/gio/gsettingsschema.h
index d16d78a..de81e37 100644
--- a/gio/gsettingsschema.h
+++ b/gio/gsettingsschema.h
@@ -74,6 +74,9 @@ GSettingsSchemaKey *    g_settings_schema_get_key                       (GSettin
 GLIB_AVAILABLE_IN_2_40
 gboolean                g_settings_schema_has_key                       (GSettingsSchema        *schema,
                                                                          const gchar            *name);
+GLIB_AVAILABLE_IN_2_46
+gchar**                 g_settings_schema_list_keys                     (GSettingsSchema        *schema);
+
 
 GLIB_AVAILABLE_IN_2_44
 gchar **                g_settings_schema_list_children                 (GSettingsSchema        *schema);


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