From 49fa69e05eb6d2a29fc1de8af93e65c4dd45ad72 Mon Sep 17 00:00:00 2001 From: Ryan Lortie Date: Thu, 31 Mar 2011 12:44:40 +0530 Subject: [PATCH] Add 'uint' convenience functions for GSettings Without getting into a debate about the reasons why you may or may not want to use unsigned integers, it's sufficient to note that people have been using them and requesting this functionality. Bug #641755. --- docs/reference/gio/gio-sections.txt | 2 ++ gio/gio.symbols | 2 ++ gio/gsettings.c | 56 +++++++++++++++++++++++++++++++++++++ gio/gsettings.h | 5 ++++ 4 files changed, 65 insertions(+) diff --git a/docs/reference/gio/gio-sections.txt b/docs/reference/gio/gio-sections.txt index 3a0962e..b2c732b 100644 --- a/docs/reference/gio/gio-sections.txt +++ b/docs/reference/gio/gio-sections.txt @@ -2217,6 +2217,8 @@ g_settings_get_boolean g_settings_set_boolean g_settings_get_int g_settings_set_int +g_settings_get_uint +g_settings_set_uint g_settings_get_double g_settings_set_double g_settings_get_string diff --git a/gio/gio.symbols b/gio/gio.symbols index b46da2c..e68e102 100644 --- a/gio/gio.symbols +++ b/gio/gio.symbols @@ -1592,6 +1592,8 @@ g_settings_set_value g_settings_unbind g_settings_get_int g_settings_set_int +g_settings_get_uint +g_settings_set_uint g_settings_get_string g_settings_set_string g_settings_get_strv diff --git a/gio/gsettings.c b/gio/gsettings.c index 9c8f32b..d7c5f30 100644 --- a/gio/gsettings.c +++ b/gio/gsettings.c @@ -1818,6 +1818,62 @@ g_settings_set_int (GSettings *settings, } /** + * g_settings_get_uint: + * @settings: a #GSettings object + * @key: the key to get the value for + * @returns: an unsigned integer + * + * Gets the value that is stored at @key in @settings. + * + * A convenience variant of g_settings_get() for 32-bit unsigned + * integers. + * + * It is a programmer error to give a @key that isn't specified as + * having a uint32 type in the schema for @settings. + * + * Since: 2.30 + */ +guint +g_settings_get_uint (GSettings *settings, + const gchar *key) +{ + GVariant *value; + guint result; + + value = g_settings_get_value (settings, key); + result = g_variant_get_uint32 (value); + g_variant_unref (value); + + return result; +} + +/** + * g_settings_set_uint: + * @settings: a #GSettings object + * @key: the name of the key to set + * @value: the value to set it to + * @returns: %TRUE if setting the key succeeded, + * %FALSE if the key was not writable + * + * Sets @key in @settings to @value. + * + * A convenience variant of g_settings_set() for 32-bit unsigned + * integers. + * + * It is a programmer error to give a @key that isn't specified as + * having a uint32 type in the schema for @settings. + * + * Since: 2.30 + */ +gboolean +g_settings_set_uint (GSettings *settings, + const gchar *key, + guint value) +{ + return g_settings_set_value (settings, key, g_variant_new_uint32 (value)); +} + +/** * g_settings_get_double: * @settings: a #GSettings object * @key: the key to get the value for diff --git a/gio/gsettings.h b/gio/gsettings.h index a58756d..8db2f75 100644 --- a/gio/gsettings.h +++ b/gio/gsettings.h @@ -110,6 +110,11 @@ gint g_settings_get_int (GSettin gboolean g_settings_set_int (GSettings *settings, const gchar *key, gint value); +guint g_settings_get_uint (GSettings *settings, + const gchar *key); +gboolean g_settings_set_uint (GSettings *settings, + const gchar *key, + guint value); gchar * g_settings_get_string (GSettings *settings, const gchar *key); gboolean g_settings_set_string (GSettings *settings, -- 2.7.4