2 * Copyright © 2010 Codethink Limited
3 * Copyright © 2011 Canonical Limited
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the licence, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
23 #include "gsettingsschema-internal.h"
24 #include "gsettings.h"
26 #include "gvdb/gvdb-reader.h"
34 * SECTION:gsettingsschema
35 * @short_description: Introspecting and controlling the loading of
38 * The #GSettingsSchemaSource and #GSettingsSchema APIs provide a
39 * mechanism for advanced control over the loading of schemas and a
40 * mechanism for introspecting their content.
42 * Plugin loading systems that wish to provide plugins a way to access
43 * settings face the problem of how to make the schemas for these
44 * settings visible to GSettings. Typically, a plugin will want to ship
45 * the schema along with itself and it won't be installed into the
46 * standard system directories for schemas.
48 * #GSettingsSchemaSource provides a mechanism for dealing with this by
49 * allowing the creation of a new 'schema source' from which schemas can
50 * be acquired. This schema source can then become part of the metadata
51 * associated with the plugin and queried whenever the plugin requires
52 * access to some settings.
54 * Consider the following example:
60 * GSettingsSchemaSource *schema_source;
65 * initialise_plugin (const gchar *dir)
71 * plugin->schema_source =
72 * g_settings_new_schema_source_from_directory (dir,
73 * g_settings_schema_source_get_default (), FALSE, NULL);
83 * plugin_get_settings (Plugin *plugin,
84 * const gchar *schema_id)
86 * GSettingsSchema *schema;
88 * if (schema_id == NULL)
89 * schema_id = plugin->identifier;
91 * schema = g_settings_schema_source_lookup (plugin->schema_source,
96 * ... disable the plugin or abort, etc ...
99 * return g_settings_new_full (schema, NULL, NULL);
103 * The code above shows how hooks should be added to the code that
104 * initialises (or enables) the plugin to create the schema source and
105 * how an API can be added to the plugin system to provide a convenient
106 * way for the plugin to access its settings, using the schemas that it
109 * From the standpoint of the plugin, it would need to ensure that it
110 * ships a gschemas.compiled file as part of itself, and then simply do
115 * GSettings *settings;
118 * settings = plugin_get_settings (self, NULL);
119 * some_value = g_settings_get_int (settings, "some-value");
124 * It's also possible that the plugin system expects the schema source
125 * files (ie: .gschema.xml files) instead of a gschemas.compiled file.
126 * In that case, the plugin loading system must compile the schemas for
127 * itself before attempting to create the settings source.
135 * This is an opaque structure type. You may not access it directly.
139 struct _GSettingsSchema
141 GSettingsSchemaSource *source;
142 const gchar *gettext_domain;
153 * G_TYPE_SETTINGS_SCHEMA_SOURCE:
155 * A boxed #GType corresponding to #GSettingsSchemaSource.
159 G_DEFINE_BOXED_TYPE (GSettingsSchemaSource, g_settings_schema_source, g_settings_schema_source_ref, g_settings_schema_source_unref)
162 * G_TYPE_SETTINGS_SCHEMA:
164 * A boxed #GType corresponding to #GSettingsSchema.
168 G_DEFINE_BOXED_TYPE (GSettingsSchema, g_settings_schema, g_settings_schema_ref, g_settings_schema_unref)
171 * GSettingsSchemaSource:
173 * This is an opaque structure type. You may not access it directly.
177 struct _GSettingsSchemaSource
179 GSettingsSchemaSource *parent;
186 static GSettingsSchemaSource *schema_sources;
189 * g_settings_schema_source_ref:
190 * @source: a #GSettingsSchemaSource
192 * Increase the reference count of @source, returning a new reference.
194 * Returns: a new reference to @source
198 GSettingsSchemaSource *
199 g_settings_schema_source_ref (GSettingsSchemaSource *source)
201 g_atomic_int_inc (&source->ref_count);
207 * g_settings_schema_source_unref:
208 * @source: a #GSettingsSchemaSource
210 * Decrease the reference count of @source, possibly freeing it.
215 g_settings_schema_source_unref (GSettingsSchemaSource *source)
217 if (g_atomic_int_dec_and_test (&source->ref_count))
219 if (source == schema_sources)
220 g_error ("g_settings_schema_source_unref() called too many times on the default schema source");
223 g_settings_schema_source_unref (source->parent);
224 gvdb_table_unref (source->table);
225 g_free (source->directory);
227 g_slice_free (GSettingsSchemaSource, source);
232 * g_settings_schema_source_new_from_directory:
233 * @directory: the filename of a directory
234 * @parent: (allow-none): a #GSettingsSchemaSource, or %NULL
235 * @trusted: %TRUE, if the directory is trusted
236 * @error: a pointer to a #GError pointer set to %NULL, or %NULL
238 * Attempts to create a new schema source corresponding to the contents
239 * of the given directory.
241 * This function is not required for normal uses of #GSettings but it
242 * may be useful to authors of plugin management systems.
244 * The directory should contain a file called
245 * <filename>gschemas.compiled</filename> as produced by
246 * <command>glib-compile-schemas</command>.
248 * If @trusted is %TRUE then <filename>gschemas.compiled</filename> is
249 * trusted not to be corrupted. This assumption has a performance
250 * advantage, but can result in crashes or inconsistent behaviour in the
251 * case of a corrupted file. Generally, you should set @trusted to
252 * %TRUE for files installed by the system and to %FALSE for files in
253 * the home directory.
255 * If @parent is non-%NULL then there are two effects.
257 * First, if g_settings_schema_source_lookup() is called with the
258 * @recursive flag set to %TRUE and the schema can not be found in the
259 * source, the lookup will recurse to the parent.
261 * Second, any references to other schemas specified within this
262 * source (ie: <literal>child</literal> or <literal>extends</literal>)
263 * references may be resolved from the @parent.
265 * For this second reason, except in very unusual situations, the
266 * @parent should probably be given as the default schema source, as
267 * returned by g_settings_schema_source_get_default().
271 GSettingsSchemaSource *
272 g_settings_schema_source_new_from_directory (const gchar *directory,
273 GSettingsSchemaSource *parent,
277 GSettingsSchemaSource *source;
281 filename = g_build_filename (directory, "gschemas.compiled", NULL);
282 table = gvdb_table_new (filename, trusted, error);
288 source = g_slice_new (GSettingsSchemaSource);
289 source->directory = g_strdup (directory);
290 source->parent = parent ? g_settings_schema_source_ref (parent) : NULL;
291 source->table = table;
292 source->ref_count = 1;
298 try_prepend_dir (const gchar *directory)
300 GSettingsSchemaSource *source;
302 source = g_settings_schema_source_new_from_directory (directory, schema_sources, TRUE, NULL);
304 /* If we successfully created it then prepend it to the global list */
306 schema_sources = source;
310 initialise_schema_sources (void)
312 static gsize initialised;
314 /* need a separate variable because 'schema_sources' may legitimately
315 * be null if we have zero valid schema sources
317 if G_UNLIKELY (g_once_init_enter (&initialised))
319 const gchar * const *dirs;
323 /* iterate in reverse: count up, then count down */
324 dirs = g_get_system_data_dirs ();
325 for (i = 0; dirs[i]; i++);
331 dirname = g_build_filename (dirs[i], "glib-2.0", "schemas", NULL);
332 try_prepend_dir (dirname);
336 if ((path = g_getenv ("GSETTINGS_SCHEMA_DIR")) != NULL)
337 try_prepend_dir (path);
339 g_once_init_leave (&initialised, TRUE);
344 * g_settings_schema_source_get_default:
346 * Gets the default system schema source.
348 * This function is not required for normal uses of #GSettings but it
349 * may be useful to authors of plugin management systems or to those who
350 * want to introspect the content of schemas.
352 * If no schemas are installed, %NULL will be returned.
354 * The returned source may actually consist of multiple schema sources
355 * from different directories, depending on which directories were given
356 * in <envar>XDG_DATA_DIRS</envar> and
357 * <envar>GSETTINGS_SCHEMA_DIR</envar>. For this reason, all lookups
358 * performed against the default source should probably be done
361 * Returns: (transfer none): the default schema source
365 GSettingsSchemaSource *
366 g_settings_schema_source_get_default (void)
368 initialise_schema_sources ();
370 return schema_sources;
374 * g_settings_schema_source_lookup:
375 * @source: a #GSettingsSchemaSource
376 * @schema_id: a schema ID
377 * @recursive: %TRUE if the lookup should be recursive
379 * Looks up a schema with the identifier @schema_id in @source.
381 * This function is not required for normal uses of #GSettings but it
382 * may be useful to authors of plugin management systems or to those who
383 * want to introspect the content of schemas.
385 * If the schema isn't found directly in @source and @recursive is %TRUE
386 * then the parent sources will also be checked.
388 * If the schema isn't found, %NULL is returned.
390 * Returns: (transfer full): a new #GSettingsSchema
395 g_settings_schema_source_lookup (GSettingsSchemaSource *source,
396 const gchar *schema_id,
399 GSettingsSchema *schema;
402 g_return_val_if_fail (source != NULL, NULL);
403 g_return_val_if_fail (schema_id != NULL, NULL);
405 table = gvdb_table_get_table (source->table, schema_id);
407 if (table == NULL && recursive)
408 for (source = source->parent; source; source = source->parent)
409 if ((table = gvdb_table_get_table (source->table, schema_id)))
415 schema = g_slice_new0 (GSettingsSchema);
416 schema->source = g_settings_schema_source_ref (source);
417 schema->ref_count = 1;
418 schema->id = g_strdup (schema_id);
419 schema->table = table;
420 schema->path = g_settings_schema_get_string (schema, ".path");
421 schema->gettext_domain = g_settings_schema_get_string (schema, ".gettext-domain");
423 if (schema->gettext_domain)
424 bind_textdomain_codeset (schema->gettext_domain, "UTF-8");
430 steal_item (gpointer key,
434 gchar ***ptr = user_data;
436 *(*ptr)++ = (gchar *) key;
441 static const gchar * const *non_relocatable_schema_list;
442 static const gchar * const *relocatable_schema_list;
443 static gsize schema_lists_initialised;
446 ensure_schema_lists (void)
448 if (g_once_init_enter (&schema_lists_initialised))
450 GSettingsSchemaSource *source;
451 GHashTable *single, *reloc;
456 initialise_schema_sources ();
458 /* We use hash tables to avoid duplicate listings for schemas that
459 * appear in more than one file.
461 single = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
462 reloc = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
464 for (source = schema_sources; source; source = source->parent)
466 list = gvdb_table_list (source->table, "");
468 /* empty schema cache file? */
472 for (i = 0; list[i]; i++)
474 if (!g_hash_table_lookup (single, list[i]) &&
475 !g_hash_table_lookup (reloc, list[i]))
479 table = gvdb_table_get_table (source->table, list[i]);
480 g_assert (table != NULL);
482 if (gvdb_table_has_value (table, ".path"))
483 g_hash_table_insert (single, g_strdup (list[i]), NULL);
485 g_hash_table_insert (reloc, g_strdup (list[i]), NULL);
487 gvdb_table_unref (table);
494 ptr = g_new (const gchar *, g_hash_table_size (single) + 1);
495 non_relocatable_schema_list = ptr;
496 g_hash_table_foreach_steal (single, steal_item, &ptr);
497 g_hash_table_unref (single);
500 ptr = g_new (const gchar *, g_hash_table_size (reloc) + 1);
501 relocatable_schema_list = ptr;
502 g_hash_table_foreach_steal (reloc, steal_item, &ptr);
503 g_hash_table_unref (reloc);
506 g_once_init_leave (&schema_lists_initialised, TRUE);
511 * g_settings_list_schemas:
513 * Gets a list of the #GSettings schemas installed on the system. The
514 * returned list is exactly the list of schemas for which you may call
515 * g_settings_new() without adverse effects.
517 * This function does not list the schemas that do not provide their own
518 * paths (ie: schemas for which you must use
519 * g_settings_new_with_path()). See
520 * g_settings_list_relocatable_schemas() for that.
522 * Returns: (element-type utf8) (transfer none): a list of #GSettings
523 * schemas that are available. The list must not be modified or
528 const gchar * const *
529 g_settings_list_schemas (void)
531 ensure_schema_lists ();
533 return non_relocatable_schema_list;
537 * g_settings_list_relocatable_schemas:
539 * Gets a list of the relocatable #GSettings schemas installed on the
540 * system. These are schemas that do not provide their own path. It is
541 * usual to instantiate these schemas directly, but if you want to you
542 * can use g_settings_new_with_path() to specify the path.
544 * The output of this function, taken together with the output of
545 * g_settings_list_schemas() represents the complete list of all
548 * Returns: (element-type utf8) (transfer none): a list of relocatable
549 * #GSettings schemas that are available. The list must not be
554 const gchar * const *
555 g_settings_list_relocatable_schemas (void)
557 ensure_schema_lists ();
559 return relocatable_schema_list;
563 * g_settings_schema_ref:
564 * @schema: a #GSettingsSchema
566 * Increase the reference count of @schema, returning a new reference.
568 * Returns: a new reference to @schema
573 g_settings_schema_ref (GSettingsSchema *schema)
575 g_atomic_int_inc (&schema->ref_count);
581 * g_settings_schema_unref:
582 * @schema: a #GSettingsSchema
584 * Decrease the reference count of @schema, possibly freeing it.
589 g_settings_schema_unref (GSettingsSchema *schema)
591 if (g_atomic_int_dec_and_test (&schema->ref_count))
593 g_settings_schema_source_unref (schema->source);
594 gvdb_table_unref (schema->table);
595 g_free (schema->items);
598 g_slice_free (GSettingsSchema, schema);
603 g_settings_schema_get_string (GSettingsSchema *schema,
606 const gchar *result = NULL;
609 if ((value = gvdb_table_get_raw_value (schema->table, key)))
611 result = g_variant_get_string (value, NULL);
612 g_variant_unref (value);
619 g_settings_schema_get_value (GSettingsSchema *schema,
625 value = gvdb_table_get_raw_value (schema->table, key);
627 if G_UNLIKELY (value == NULL || !g_variant_is_of_type (value, G_VARIANT_TYPE_TUPLE))
628 g_error ("Settings schema '%s' does not contain a key named '%s'", schema->id, key);
630 iter = g_variant_iter_new (value);
631 g_variant_unref (value);
637 * g_settings_schema_get_path:
638 * @schema: a #GSettingsSchema
640 * Gets the path associated with @schema, or %NULL.
642 * Schemas may be single-instance or relocatable. Single-instance
643 * schemas correspond to exactly one set of keys in the backend
644 * database: those located at the path returned by this function.
646 * Relocatable schemas can be referenced by other schemas and can
647 * threfore describe multiple sets of keys at different locations. For
648 * relocatable schemas, this function will return %NULL.
650 * Returns: (transfer none): the path of the schema, or %NULL
655 g_settings_schema_get_path (GSettingsSchema *schema)
661 g_settings_schema_get_gettext_domain (GSettingsSchema *schema)
663 return schema->gettext_domain;
667 g_settings_schema_has_key (GSettingsSchema *schema,
670 return gvdb_table_has_value (schema->table, key);
674 g_settings_schema_list (GSettingsSchema *schema,
679 if (schema->items == NULL)
684 list = gvdb_table_list (schema->table, "");
685 len = list ? g_strv_length (list) : 0;
687 schema->items = g_new (GQuark, len);
690 for (i = 0; i < len; i++)
691 if (list[i][0] != '.')
693 if (g_str_has_suffix (list[i], "/"))
695 /* This is a child. Check to make sure that
696 * instantiating the child would actually work before we
697 * return it from list() and cause a crash.
699 GSettingsSchemaSource *source;
700 GVariant *child_schema;
701 GvdbTable *child_table;
703 child_schema = gvdb_table_get_raw_value (schema->table, list[i]);
709 for (source = schema_sources; source; source = source->parent)
710 if ((child_table = gvdb_table_get_table (source->table, g_variant_get_string (child_schema, NULL))))
713 g_variant_unref (child_schema);
715 /* Schema is not found -> don't add it to the list */
716 if (child_table == NULL)
719 /* Make sure the schema is relocatable or at the
722 if (gvdb_table_has_value (child_table, ".path"))
728 path = gvdb_table_get_raw_value (child_table, ".path");
729 expected = g_strconcat (schema->path, list[i], NULL);
730 same = g_str_equal (expected, g_variant_get_string (path, NULL));
731 g_variant_unref (path);
736 gvdb_table_unref (child_table);
741 gvdb_table_unref (child_table);
742 /* Else, it's good... */
745 schema->items[j++] = g_quark_from_string (list[i]);
752 *n_items = schema->n_items;
753 return schema->items;
757 * g_settings_schema_get_id:
758 * @schema: a #GSettingsSchema
760 * Get the ID of @schema.
762 * Returns: (transfer none): the ID
765 g_settings_schema_get_id (GSettingsSchema *schema)
771 endian_fixup (GVariant **value)
773 #if G_BYTE_ORDER == G_BIG_ENDIAN
776 tmp = g_variant_byteswap (*value);
777 g_variant_unref (*value);
783 g_settings_schema_key_init (GSettingsSchemaKey *key,
784 GSettingsSchema *schema,
791 memset (key, 0, sizeof *key);
793 iter = g_settings_schema_get_value (schema, name);
795 key->schema = g_settings_schema_ref (schema);
796 key->default_value = g_variant_iter_next_value (iter);
797 endian_fixup (&key->default_value);
798 key->type = g_variant_get_type (key->default_value);
799 key->name = g_intern_string (name);
801 while (g_variant_iter_next (iter, "(y*)", &code, &data))
806 /* translation requested */
807 g_variant_get (data, "(y&s)", &key->lc_char, &key->unparsed);
811 /* enumerated types... */
817 key->is_flags = TRUE;
821 /* ..., choices, aliases */
822 key->strinfo = g_variant_get_fixed_array (data, &key->strinfo_length, sizeof (guint32));
826 g_variant_get (data, "(**)", &key->minimum, &key->maximum);
827 endian_fixup (&key->minimum);
828 endian_fixup (&key->maximum);
832 g_warning ("unknown schema extension '%c'", code);
836 g_variant_unref (data);
839 g_variant_iter_free (iter);
843 g_settings_schema_key_clear (GSettingsSchemaKey *key)
846 g_variant_unref (key->minimum);
849 g_variant_unref (key->maximum);
851 g_variant_unref (key->default_value);
853 g_settings_schema_unref (key->schema);
857 g_settings_schema_key_type_check (GSettingsSchemaKey *key,
860 g_return_val_if_fail (value != NULL, FALSE);
862 return g_variant_is_of_type (value, key->type);
866 g_settings_schema_key_range_check (GSettingsSchemaKey *key,
869 if (key->minimum == NULL && key->strinfo == NULL)
872 if (g_variant_is_container (value))
878 g_variant_iter_init (&iter, value);
879 while (ok && (child = g_variant_iter_next_value (&iter)))
881 ok = g_settings_schema_key_range_check (key, child);
882 g_variant_unref (child);
890 return g_variant_compare (key->minimum, value) <= 0 &&
891 g_variant_compare (value, key->maximum) <= 0;
894 return strinfo_is_string_valid (key->strinfo, key->strinfo_length,
895 g_variant_get_string (value, NULL));
899 g_settings_schema_key_range_fixup (GSettingsSchemaKey *key,
904 if (g_settings_schema_key_range_check (key, value))
905 return g_variant_ref (value);
907 if (key->strinfo == NULL)
910 if (g_variant_is_container (value))
912 GVariantBuilder builder;
916 g_variant_iter_init (&iter, value);
917 g_variant_builder_init (&builder, g_variant_get_type (value));
919 while ((child = g_variant_iter_next_value (&iter)))
923 fixed = g_settings_schema_key_range_fixup (key, child);
924 g_variant_unref (child);
928 g_variant_builder_clear (&builder);
932 g_variant_builder_add_value (&builder, fixed);
933 g_variant_unref (fixed);
936 return g_variant_ref_sink (g_variant_builder_end (&builder));
939 target = strinfo_string_from_alias (key->strinfo, key->strinfo_length,
940 g_variant_get_string (value, NULL));
941 return target ? g_variant_ref_sink (g_variant_new_string (target)) : NULL;
946 g_settings_schema_key_get_translated_default (GSettingsSchemaKey *key)
948 const gchar *translated;
949 GError *error = NULL;
953 domain = g_settings_schema_get_gettext_domain (key->schema);
955 if (key->lc_char == '\0')
956 /* translation not requested for this key */
959 if (key->lc_char == 't')
960 translated = g_dcgettext (domain, key->unparsed, LC_TIME);
962 translated = g_dgettext (domain, key->unparsed);
964 if (translated == key->unparsed)
965 /* the default value was not translated */
968 /* try to parse the translation of the unparsed default */
969 value = g_variant_parse (key->type, translated, NULL, NULL, &error);
973 g_warning ("Failed to parse translated string '%s' for "
974 "key '%s' in schema '%s': %s", key->unparsed, key->name,
975 g_settings_schema_get_id (key->schema), error->message);
976 g_warning ("Using untranslated default instead.");
977 g_error_free (error);
980 else if (!g_settings_schema_key_range_check (key, value))
982 g_warning ("Translated default '%s' for key '%s' in schema '%s' "
983 "is outside of valid range", key->unparsed, key->name,
984 g_settings_schema_get_id (key->schema));
985 g_variant_unref (value);
993 g_settings_schema_key_to_enum (GSettingsSchemaKey *key,
999 it_worked = strinfo_enum_from_string (key->strinfo, key->strinfo_length,
1000 g_variant_get_string (value, NULL),
1003 /* 'value' can only come from the backend after being filtered for validity,
1004 * from the translation after being filtered for validity, or from the schema
1005 * itself (which the schema compiler checks for validity). If this assertion
1006 * fails then it's really a bug in GSettings or the schema compiler...
1008 g_assert (it_worked);
1014 g_settings_schema_key_from_enum (GSettingsSchemaKey *key,
1017 const gchar *string;
1019 string = strinfo_string_from_enum (key->strinfo, key->strinfo_length, value);
1024 return g_variant_new_string (string);
1028 g_settings_schema_key_to_flags (GSettingsSchemaKey *key,
1036 g_variant_iter_init (&iter, value);
1037 while (g_variant_iter_next (&iter, "&s", &flag))
1042 it_worked = strinfo_enum_from_string (key->strinfo, key->strinfo_length, flag, &flag_value);
1043 /* as in g_settings_to_enum() */
1044 g_assert (it_worked);
1046 result |= flag_value;
1053 g_settings_schema_key_from_flags (GSettingsSchemaKey *key,
1056 GVariantBuilder builder;
1059 g_variant_builder_init (&builder, G_VARIANT_TYPE ("as"));
1061 for (i = 0; i < 32; i++)
1062 if (value & (1u << i))
1064 const gchar *string;
1066 string = strinfo_string_from_enum (key->strinfo, key->strinfo_length, 1u << i);
1070 g_variant_builder_clear (&builder);
1074 g_variant_builder_add (&builder, "s", string);
1077 return g_variant_builder_end (&builder);
1080 G_DEFINE_BOXED_TYPE (GSettingsSchemaKey, g_settings_schema_key, g_settings_schema_key_ref, g_settings_schema_key_unref)
1083 * g_settings_schema_key_ref:
1084 * @key: a #GSettingsSchemaKey
1086 * Increase the reference count of @key, returning a new reference.
1088 * Returns: a new reference to @key
1092 GSettingsSchemaKey *
1093 g_settings_schema_key_ref (GSettingsSchemaKey *key)
1095 g_return_val_if_fail (key != NULL, NULL);
1097 g_atomic_int_inc (&key->ref_count);
1103 * g_settings_schema_key_unref:
1104 * @key: a #GSettingsSchemaKey
1106 * Decrease the reference count of @key, possibly freeing it.
1111 g_settings_schema_key_unref (GSettingsSchemaKey *key)
1113 g_return_if_fail (key != NULL);
1115 if (g_atomic_int_dec_and_test (&key->ref_count))
1117 g_settings_schema_key_clear (key);
1119 g_slice_free (GSettingsSchemaKey, key);
1124 * g_settings_schema_get_key:
1125 * @schema: a #GSettingsSchema
1126 * @name: the name of a key
1128 * Gets the key named @name from @schema.
1130 * It is a programmer error to request a key that does not exist. See
1131 * g_settings_schema_list_keys().
1133 * Returns: (transfer full): the #GSettingsSchemaKey for @name
1137 GSettingsSchemaKey *
1138 g_settings_schema_get_key (GSettingsSchema *schema,
1141 GSettingsSchemaKey *key;
1143 g_return_val_if_fail (schema != NULL, NULL);
1144 g_return_val_if_fail (name != NULL, NULL);
1146 key = g_slice_new (GSettingsSchemaKey);
1147 g_settings_schema_key_init (key, schema, name);