[glib/wip/settings-backend: 14/14] GSettings: add g_settings_is_set()



commit 7f361b41ae67ed1ccb4fe51204191386122c8c68
Author: Ryan Lortie <desrt desrt ca>
Date:   Sun Jul 29 11:10:18 2012 +0200

    GSettings: add g_settings_is_set()
    
    Also add the equivalent vfunc to the backend.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=668233

 docs/reference/gio/gio-sections.txt |    1 +
 gio/gio.symbols                     |    1 +
 gio/gsettings.c                     |   41 ++++++++++++++++++++++++++++++++++-
 gio/gsettingsbackend.c              |   18 +++++++++++++++
 gio/gsettingsbackend.h              |    3 ++
 gio/gsettingsbackendinternal.h      |    3 ++
 6 files changed, 66 insertions(+), 1 deletions(-)
---
diff --git a/docs/reference/gio/gio-sections.txt b/docs/reference/gio/gio-sections.txt
index e709e83..83cf760 100644
--- a/docs/reference/gio/gio-sections.txt
+++ b/docs/reference/gio/gio-sections.txt
@@ -2367,6 +2367,7 @@ g_settings_new_full
 g_settings_sync
 g_settings_get_value
 g_settings_set_value
+g_settings_is_set
 g_settings_is_writable
 g_settings_delay
 g_settings_apply
diff --git a/gio/gio.symbols b/gio/gio.symbols
index 02806f6..6e3c20b 100644
--- a/gio/gio.symbols
+++ b/gio/gio.symbols
@@ -1175,6 +1175,7 @@ g_settings_get_child
 g_settings_get_has_unapplied
 g_settings_get_type
 g_settings_get_value
+g_settings_is_set
 g_settings_is_writable
 g_settings_new
 g_settings_new_with_backend
diff --git a/gio/gsettings.c b/gio/gsettings.c
index 46229a4..10da1a6 100644
--- a/gio/gsettings.c
+++ b/gio/gsettings.c
@@ -2033,7 +2033,7 @@ g_settings_get_has_unapplied (GSettings *settings)
   return g_settings_backend_get_has_unapplied (settings->priv->backend);
 }
 
-/* Extra API (reset, sync, get_child, is_writable, list_*, ranges) {{{1 */
+/* Extra API (reset, sync, get_child, is_set, is_writable, list_*, ranges) {{{1 */
 /**
  * g_settings_reset:
  * @settings: a #GSettings object
@@ -2105,6 +2105,45 @@ g_settings_is_writable (GSettings   *settings,
 }
 
 /**
+ * g_settings_is_set:
+ * @settings: a #GSettings object
+ * @name: the name of a key
+ *
+ * Determines if a key is "set".
+ *
+ * A key being set means (more or less) that g_settings_set() has been
+ * called on it more recently than the last call to g_settings_reset().
+ * This does not include system-level default settings.
+ *
+ * Another way of looking at it is that g_settings_reset() will only
+ * change the value of a key if it was already set.  It is possible,
+ * however, that a key is explicitly set to the default value.
+ *
+ * Keys that are "set" will not change if the default value for the key
+ * is changed (ie: by the system administrator) unless it is also locked
+ * down.
+ *
+ * Returns: %TRUE if the key is set
+ *
+ * Since: 2.34
+ **/
+gboolean
+g_settings_is_set (GSettings   *settings,
+                   const gchar *key)
+{
+  gboolean set;
+  gchar *path;
+
+  g_return_val_if_fail (G_IS_SETTINGS (settings), FALSE);
+
+  path = g_strconcat (settings->priv->path, key, NULL);
+  set = g_settings_backend_is_set (settings->priv->backend, path);
+  g_free (path);
+
+  return set;
+}
+
+/**
  * g_settings_get_child:
  * @settings: a #GSettings object
  * @name: the name of the 'child' schema
diff --git a/gio/gsettingsbackend.c b/gio/gsettingsbackend.c
index bd21477..744a991 100644
--- a/gio/gsettingsbackend.c
+++ b/gio/gsettingsbackend.c
@@ -606,6 +606,24 @@ g_settings_backend_get_writable (GSettingsBackend *backend,
 }
 
 /*< private >
+ * g_settings_backend_is_set:
+ * @backend: a #GSettingsBackend Implementation
+ * @key: the name of a key
+ *
+ * Finds out if a key is "set".  See g_settings_is_set().
+ *
+ * Returns: %TRUE if the key is set
+ */
+gboolean
+g_settings_backend_is_set (GSettingsBackend *backend,
+                           const gchar      *key)
+{
+  return G_SETTINGS_BACKEND_GET_CLASS (backend)
+    ->is_set (backend, key);
+}
+
+
+/*< private >
  * g_settings_backend_unsubscribe:
  * @backend: a #GSettingsBackend
  * @name: a key or path to subscribe to
diff --git a/gio/gsettingsbackend.h b/gio/gsettingsbackend.h
index 8f1e6c6..bfda6e8 100644
--- a/gio/gsettingsbackend.h
+++ b/gio/gsettingsbackend.h
@@ -70,6 +70,9 @@ struct _GSettingsBackendClass
                                          const GVariantType  *expected_type,
                                          gboolean             default_value);
 
+  gboolean           (* is_set)         (GSettingsBackend    *backend,
+                                         const gchar         *key);
+
   gboolean           (* get_writable)   (GSettingsBackend    *backend,
                                          const gchar         *key);
 
diff --git a/gio/gsettingsbackendinternal.h b/gio/gsettingsbackendinternal.h
index 1649987..3aead35 100644
--- a/gio/gsettingsbackendinternal.h
+++ b/gio/gsettingsbackendinternal.h
@@ -53,6 +53,9 @@ G_GNUC_INTERNAL
 void                    g_settings_backend_reset                        (GSettingsBackend     *backend,
                                                                          const gchar          *key);
 G_GNUC_INTERNAL
+gboolean                g_settings_backend_is_set                       (GSettingsBackend     *backend,
+                                                                         const char           *key);
+G_GNUC_INTERNAL
 gboolean                g_settings_backend_get_writable                 (GSettingsBackend     *backend,
                                                                          const char           *key);
 G_GNUC_INTERNAL



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