diff options
author | Ryan Lortie <desrt@desrt.ca> | 2010-06-14 17:29:41 -0400 |
---|---|---|
committer | Ryan Lortie <desrt@desrt.ca> | 2010-06-16 18:17:53 -0400 |
commit | 597290d5c81bf889a694e286ea2434655b82a404 (patch) | |
tree | cf05113d0cf1cf277dd097b7c945059df5486c9f /gio/gsettingsbackend.c | |
parent | b205dc77cb14f67818eaac23d0eb3f5d1b867921 (diff) |
GSettings: major refactor. Add enums, range.
Diffstat (limited to 'gio/gsettingsbackend.c')
-rw-r--r-- | gio/gsettingsbackend.c | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/gio/gsettingsbackend.c b/gio/gsettingsbackend.c index dd225936c..044ef48be 100644 --- a/gio/gsettingsbackend.c +++ b/gio/gsettingsbackend.c @@ -732,7 +732,8 @@ g_settings_backend_changed_tree (GSettingsBackend *backend, * g_settings_backend_read: * @backend: a #GSettingsBackend implementation * @key: the key to read - * @expected_type: a #GVariantType hint + * @expected_type: a #GVariantType + * @default_value: if the default value should be returned * @returns: the value that was read, or %NULL * * Reads a key. This call will never block. @@ -740,11 +741,13 @@ g_settings_backend_changed_tree (GSettingsBackend *backend, * If the key exists, the value associated with it will be returned. * If the key does not exist, %NULL will be returned. * - * If @expected_type is given, it serves as a type hint to the backend. - * If you expect a key of a certain type then you should give - * @expected_type to increase your chances of getting it. Some backends - * may ignore this argument and return values of a different type; it is - * mostly used by backends that don't store strong type information. + * The returned value will be of the type given in @expected_type. If + * the backend stored a value of a different type then %NULL will be + * returned. + * + * If @default_value is %TRUE then this gets the default value from the + * backend (ie: the one that the backend would contain if + * g_settings_reset() were called). */ GVariant * g_settings_backend_read (GSettingsBackend *backend, @@ -752,8 +755,18 @@ g_settings_backend_read (GSettingsBackend *backend, const GVariantType *expected_type, gboolean default_value) { - return G_SETTINGS_BACKEND_GET_CLASS (backend) + GVariant *value; + + value = G_SETTINGS_BACKEND_GET_CLASS (backend) ->read (backend, key, expected_type, default_value); + + if G_UNLIKELY (value && !g_variant_is_of_type (value, expected_type)) + { + g_variant_unref (value); + value = NULL; + } + + return value; } /*< private > |