[glib] gsettings: add get/set_{,u}int64



commit 5cea1c861def0251a10cd4de01908aaf3276c72d
Author: Marc-Antoine Perennou <Marc-Antoine Perennou com>
Date:   Mon Sep 21 13:02:45 2015 +0200

    gsettings: add get/set_{,u}int64
    
    https://bugzilla.gnome.org/show_bug.cgi?id=755898
    
    Signed-off-by: Marc-Antoine Perennou <Marc-Antoine Perennou com>

 docs/reference/gio/gio-sections.txt |    4 +
 gio/gsettings.c                     |  114 +++++++++++++++++++++++++++++++++++
 gio/gsettings.h                     |   14 ++++
 gio/tests/gsettings.c               |   10 +++
 4 files changed, 142 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/gio/gio-sections.txt b/docs/reference/gio/gio-sections.txt
index 6010a0f..d5620da 100644
--- a/docs/reference/gio/gio-sections.txt
+++ b/docs/reference/gio/gio-sections.txt
@@ -2614,8 +2614,12 @@ g_settings_get_boolean
 g_settings_set_boolean
 g_settings_get_int
 g_settings_set_int
+g_settings_get_int64
+g_settings_set_int64
 g_settings_get_uint
 g_settings_set_uint
+g_settings_get_uint64
+g_settings_set_uint64
 g_settings_get_double
 g_settings_set_double
 g_settings_get_string
diff --git a/gio/gsettings.c b/gio/gsettings.c
index e421e0c..3841b54 100644
--- a/gio/gsettings.c
+++ b/gio/gsettings.c
@@ -1874,6 +1874,62 @@ g_settings_set_int (GSettings   *settings,
 }
 
 /**
+ * g_settings_get_int64:
+ * @settings: a #GSettings object
+ * @key: the key to get the value for
+ *
+ * Gets the value that is stored at @key in @settings.
+ *
+ * A convenience variant of g_settings_get() for 64-bit integers.
+ *
+ * It is a programmer error to give a @key that isn't specified as
+ * having a int64 type in the schema for @settings.
+ *
+ * Returns: a 64-bit integer
+ *
+ * Since: 2.50
+ */
+gint64
+g_settings_get_int64 (GSettings   *settings,
+                      const gchar *key)
+{
+  GVariant *value;
+  gint64 result;
+
+  value = g_settings_get_value (settings, key);
+  result = g_variant_get_int64 (value);
+  g_variant_unref (value);
+
+  return result;
+}
+
+/**
+ * g_settings_set_int64:
+ * @settings: a #GSettings object
+ * @key: the name of the key to set
+ * @value: the value to set it to
+ *
+ * Sets @key in @settings to @value.
+ *
+ * A convenience variant of g_settings_set() for 64-bit integers.
+ *
+ * It is a programmer error to give a @key that isn't specified as
+ * having a int64 type in the schema for @settings.
+ *
+ * Returns: %TRUE if setting the key succeeded,
+ *     %FALSE if the key was not writable
+ *
+ * Since: 2.50
+ */
+gboolean
+g_settings_set_int64 (GSettings   *settings,
+                      const gchar *key,
+                      gint64       value)
+{
+  return g_settings_set_value (settings, key, g_variant_new_int64 (value));
+}
+
+/**
  * g_settings_get_uint:
  * @settings: a #GSettings object
  * @key: the key to get the value for
@@ -1932,6 +1988,64 @@ g_settings_set_uint (GSettings   *settings,
 }
 
 /**
+ * g_settings_get_uint64:
+ * @settings: a #GSettings object
+ * @key: the key to get the value for
+ *
+ * Gets the value that is stored at @key in @settings.
+ *
+ * A convenience variant of g_settings_get() for 64-bit unsigned
+ * integers.
+ *
+ * It is a programmer error to give a @key that isn't specified as
+ * having a uint64 type in the schema for @settings.
+ *
+ * Returns: a 64-bit unsigned integer
+ *
+ * Since: 2.50
+ */
+guint64
+g_settings_get_uint64 (GSettings   *settings,
+                       const gchar *key)
+{
+  GVariant *value;
+  guint64 result;
+
+  value = g_settings_get_value (settings, key);
+  result = g_variant_get_uint64 (value);
+  g_variant_unref (value);
+
+  return result;
+}
+
+/**
+ * g_settings_set_uint64:
+ * @settings: a #GSettings object
+ * @key: the name of the key to set
+ * @value: the value to set it to
+ *
+ * Sets @key in @settings to @value.
+ *
+ * A convenience variant of g_settings_set() for 64-bit unsigned
+ * integers.
+ *
+ * It is a programmer error to give a @key that isn't specified as
+ * having a uint64 type in the schema for @settings.
+ *
+ * Returns: %TRUE if setting the key succeeded,
+ *     %FALSE if the key was not writable
+ *
+ * Since: 2.50
+ */
+gboolean
+g_settings_set_uint64 (GSettings   *settings,
+                       const gchar *key,
+                       guint64      value)
+{
+  return g_settings_set_value (settings, key, g_variant_new_uint64 (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 5e781d9..ef7020e 100644
--- a/gio/gsettings.h
+++ b/gio/gsettings.h
@@ -138,6 +138,13 @@ GLIB_AVAILABLE_IN_ALL
 gboolean                g_settings_set_int                              (GSettings          *settings,
                                                                          const gchar        *key,
                                                                          gint                value);
+GLIB_AVAILABLE_IN_2_50
+gint64                  g_settings_get_int64                            (GSettings          *settings,
+                                                                         const gchar        *key);
+GLIB_AVAILABLE_IN_2_50
+gboolean                g_settings_set_int64                            (GSettings          *settings,
+                                                                         const gchar        *key,
+                                                                         gint64              value);
 GLIB_AVAILABLE_IN_2_32
 guint                   g_settings_get_uint                             (GSettings          *settings,
                                                                          const gchar        *key);
@@ -145,6 +152,13 @@ GLIB_AVAILABLE_IN_2_32
 gboolean                g_settings_set_uint                             (GSettings          *settings,
                                                                          const gchar        *key,
                                                                          guint               value);
+GLIB_AVAILABLE_IN_2_50
+guint64                 g_settings_get_uint64                           (GSettings          *settings,
+                                                                         const gchar        *key);
+GLIB_AVAILABLE_IN_2_50
+gboolean                g_settings_set_uint64                           (GSettings          *settings,
+                                                                         const gchar        *key,
+                                                                         guint64             value);
 GLIB_AVAILABLE_IN_ALL
 gchar *                 g_settings_get_string                           (GSettings          *settings,
                                                                          const gchar        *key);
diff --git a/gio/tests/gsettings.c b/gio/tests/gsettings.c
index ee8e8fa..86cc85c 100644
--- a/gio/tests/gsettings.c
+++ b/gio/tests/gsettings.c
@@ -1180,6 +1180,16 @@ test_simple_binding (void)
   g_object_get (obj, "uint", &u, NULL);
   g_assert_cmpuint (u, ==, 54321);
 
+  g_settings_bind (settings, "uint64", obj, "uint64", G_SETTINGS_BIND_DEFAULT);
+
+  g_object_set (obj, "uint64", 12345, NULL);
+  g_assert_cmpuint (g_settings_get_uint64 (settings, "uint64"), ==, 12345);
+
+  g_settings_set_uint64 (settings, "uint64", 54321);
+  u = 1111;
+  g_object_get (obj, "uint64", &u, NULL);
+  g_assert_cmpuint (u, ==, 54321);
+
   g_settings_bind (settings, "int64", obj, "int64", G_SETTINGS_BIND_DEFAULT);
 
   g_object_set (obj, "int64", (gint64) G_MAXINT64, NULL);


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