GSettingsSchemaKey: add introspection APIs

Add g_settings_schema_has_key() and _get_range(), _range_check(),
_get_value_type(), _get_default_value() methods on GSettingsSchemaKey.

Deprecate the equivalent APIs on GSettings.

https://bugzilla.gnome.org/show_bug.cgi?id=683017
This commit is contained in:
Ryan Lortie
2013-10-27 17:03:04 -07:00
parent c0865fbaf2
commit bcb030a474
6 changed files with 208 additions and 112 deletions

View File

@@ -2315,80 +2315,22 @@ g_settings_list_children (GSettings *settings)
*
* Queries the range of a key.
*
* This function will return a #GVariant that fully describes the range
* of values that are valid for @key.
*
* The type of #GVariant returned is <literal>(sv)</literal>. The
* string describes the type of range restriction in effect. The type
* and meaning of the value contained in the variant depends on the
* string.
*
* If the string is <literal>'type'</literal> then the variant contains
* an empty array. The element type of that empty array is the expected
* type of value and all values of that type are valid.
*
* If the string is <literal>'enum'</literal> then the variant contains
* an array enumerating the possible values. Each item in the array is
* a possible valid value and no other values are valid.
*
* If the string is <literal>'flags'</literal> then the variant contains
* an array. Each item in the array is a value that may appear zero or
* one times in an array to be used as the value for this key. For
* example, if the variant contained the array <literal>['x',
* 'y']</literal> then the valid values for the key would be
* <literal>[]</literal>, <literal>['x']</literal>,
* <literal>['y']</literal>, <literal>['x', 'y']</literal> and
* <literal>['y', 'x']</literal>.
*
* Finally, if the string is <literal>'range'</literal> then the variant
* contains a pair of like-typed values -- the minimum and maximum
* permissible values for this key.
*
* This information should not be used by normal programs. It is
* considered to be a hint for introspection purposes. Normal programs
* should already know what is permitted by their own schema. The
* format may change in any way in the future -- but particularly, new
* forms may be added to the possibilities described above.
*
* It is a programmer error to give a @key that isn't contained in the
* schema for @settings.
*
* You should free the returned value with g_variant_unref() when it is
* no longer needed.
*
* Returns: a #GVariant describing the range
*
* Since: 2.28
*
* Deprecated:2.40:Use g_settings_schema_key_get_range() instead.
**/
GVariant *
g_settings_get_range (GSettings *settings,
const gchar *key)
{
GSettingsSchemaKey skey;
const gchar *type;
GVariant *range;
g_settings_schema_key_init (&skey, settings->priv->schema, key);
if (skey.minimum)
{
range = g_variant_new ("(**)", skey.minimum, skey.maximum);
type = "range";
}
else if (skey.strinfo)
{
range = strinfo_enumerate (skey.strinfo, skey.strinfo_length);
type = skey.is_flags ? "flags" : "enum";
}
else
{
range = g_variant_new_array (skey.type, NULL, 0);
type = "type";
}
range = g_settings_schema_key_get_range (&skey);
g_settings_schema_key_clear (&skey);
return g_variant_ref_sink (g_variant_new ("(sv)", type, range));
return range;
}
/**
@@ -2400,16 +2342,11 @@ g_settings_get_range (GSettings *settings,
* Checks if the given @value is of the correct type and within the
* permitted range for @key.
*
* This API is not intended to be used by normal programs -- they should
* already know what is permitted by their own schemas. This API is
* meant to be used by programs such as editors or commandline tools.
*
* It is a programmer error to give a @key that isn't contained in the
* schema for @settings.
*
* Returns: %TRUE if @value is valid for @key
*
* Since: 2.28
*
* Deprecated:2.40:Use g_settings_schema_key_range_check() instead.
**/
gboolean
g_settings_range_check (GSettings *settings,
@@ -2420,8 +2357,7 @@ g_settings_range_check (GSettings *settings,
gboolean good;
g_settings_schema_key_init (&skey, settings->priv->schema, key);
good = g_settings_schema_key_type_check (&skey, value) &&
g_settings_schema_key_range_check (&skey, value);
good = g_settings_schema_key_range_check (&skey, value);
g_settings_schema_key_clear (&skey);
return good;
@@ -3074,7 +3010,7 @@ g_settings_action_get_state_hint (GAction *action)
GSettingsAction *gsa = (GSettingsAction *) action;
/* no point in reimplementing this... */
return g_settings_get_range (gsa->settings, gsa->key.name);
return g_settings_schema_key_get_range (&gsa->key);
}
static void