Commit 82fcfeb3 authored by Allison Karlitskaya's avatar Allison Karlitskaya Committed by Matthias Clasen

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
parent 36e093a3
......@@ -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);
}
/**
......
......@@ -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)
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment