[gpointing-device-settings] add gpds_gconf_get_float().



commit 5abbf66b495813ebcd538da621e2177c467a651b
Author: Hiroyuki Ikezoe <poincare ikezoe net>
Date:   Thu Jan 14 19:11:55 2010 +0900

    add gpds_gconf_get_float().

 src/gpds-gconf.c  |   18 ++++++++++++++++++
 src/gpds-gconf.h  |    3 +++
 test/test-gconf.c |   13 +++++++++++++
 3 files changed, 34 insertions(+), 0 deletions(-)
---
diff --git a/src/gpds-gconf.c b/src/gpds-gconf.c
index b75e037..a0dfefa 100644
--- a/src/gpds-gconf.c
+++ b/src/gpds-gconf.c
@@ -71,6 +71,24 @@ gpds_gconf_get_int (GConfClient *gconf, const gchar *key, gint *value)
 }
 
 gboolean
+gpds_gconf_get_float (GConfClient *gconf, const gchar *key, gdouble *value)
+{
+    GConfValue *gconf_value;
+    gboolean exist_value = FALSE;
+
+    gconf_value = gconf_client_get(gconf, key, NULL);
+    if (gconf_value) {
+        if (gconf_value->type == GCONF_VALUE_FLOAT) {
+            *value = gconf_value_get_float(gconf_value);
+            exist_value = TRUE;
+        }
+        gconf_value_free(gconf_value);
+    }
+
+    return exist_value;
+}
+
+gboolean
 gpds_gconf_get_string (GConfClient *gconf, const gchar *key, gchar **value)
 {
     GConfValue *gconf_value;
diff --git a/src/gpds-gconf.h b/src/gpds-gconf.h
index da7355f..a7468a8 100644
--- a/src/gpds-gconf.h
+++ b/src/gpds-gconf.h
@@ -36,6 +36,9 @@ gboolean     gpds_gconf_get_boolean       (GConfClient *gconf,
 gboolean     gpds_gconf_get_int           (GConfClient *gconf,
                                            const gchar *key,
                                            gboolean *value);
+gboolean     gpds_gconf_get_float         (GConfClient *gconf,
+                                           const gchar *key,
+                                           gdouble *value);
 gboolean     gpds_gconf_get_string        (GConfClient *gconf,
                                            const gchar *key,
                                            gchar **value);
diff --git a/test/test-gconf.c b/test/test-gconf.c
index 943b7f2..9ae0d7c 100644
--- a/test/test-gconf.c
+++ b/test/test-gconf.c
@@ -6,11 +6,13 @@ void test_get_key_from_path (void);
 void test_get_non_existent (void);
 void test_boolean (void);
 void test_int (void);
+void test_float (void);
 void test_string (void);
 
 static gchar *gconf_key;
 static gboolean boolean_value;
 static gint int_value;
+static gdouble float_value;
 static gchar *string_value;
 static GConfClient *gconf;
 static GError *error;
@@ -86,6 +88,17 @@ test_int (void)
 }
 
 void
+test_float (void)
+{
+    gconf_key = make_unique_key();
+    gconf_client_set_float(gconf, gconf_key, 0.99, &error);
+    gcut_assert_error(error);
+
+    cut_assert_true(gpds_gconf_get_float(gconf, gconf_key, &float_value));
+    cut_assert_equal_double(0.99, 0.0001, float_value);
+}
+
+void
 test_string (void)
 {
     gconf_key = make_unique_key();



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]