[gnome-builder] libide/core: add GSettingsSchemaKey helpers to IdeLayeredSettings



commit 2580cee1cc75ee2396d9c9ffba58f549479bbd19
Author: Christian Hergert <chergert redhat com>
Date:   Tue Jul 26 13:57:17 2022 -0700

    libide/core: add GSettingsSchemaKey helpers to IdeLayeredSettings
    
    When wrappin this API for IdeSettings, it can be convenient to use the
    internal memory settings to get access to schema information.

 src/libide/core/ide-layered-settings-private.h | 111 +++++++++++++------------
 src/libide/core/ide-layered-settings.c         |  50 +++++++++++
 2 files changed, 107 insertions(+), 54 deletions(-)
---
diff --git a/src/libide/core/ide-layered-settings-private.h b/src/libide/core/ide-layered-settings-private.h
index b902dfeaf..66a870f24 100644
--- a/src/libide/core/ide-layered-settings-private.h
+++ b/src/libide/core/ide-layered-settings-private.h
@@ -28,59 +28,62 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (IdeLayeredSettings, ide_layered_settings, IDE, LAYERED_SETTINGS, GObject)
 
-IdeLayeredSettings *ide_layered_settings_new               (const char              *schema_id,
-                                                            const char              *path);
-GVariant           *ide_layered_settings_get_default_value (IdeLayeredSettings      *self,
-                                                            const char              *key);
-GVariant           *ide_layered_settings_get_user_value    (IdeLayeredSettings      *self,
-                                                            const char              *key);
-GVariant           *ide_layered_settings_get_value         (IdeLayeredSettings      *self,
-                                                            const char              *key);
-void                ide_layered_settings_set_value         (IdeLayeredSettings      *self,
-                                                            const char              *key,
-                                                            GVariant                *value);
-gboolean            ide_layered_settings_get_boolean       (IdeLayeredSettings      *self,
-                                                            const char              *key);
-double              ide_layered_settings_get_double        (IdeLayeredSettings      *self,
-                                                            const char              *key);
-int                 ide_layered_settings_get_int           (IdeLayeredSettings      *self,
-                                                            const char              *key);
-char               *ide_layered_settings_get_string        (IdeLayeredSettings      *self,
-                                                            const char              *key);
-guint               ide_layered_settings_get_uint          (IdeLayeredSettings      *self,
-                                                            const char              *key);
-void                ide_layered_settings_set_boolean       (IdeLayeredSettings      *self,
-                                                            const char              *key,
-                                                            gboolean                 val);
-void                ide_layered_settings_set_double        (IdeLayeredSettings      *self,
-                                                            const char              *key,
-                                                            double                   val);
-void                ide_layered_settings_set_int           (IdeLayeredSettings      *self,
-                                                            const char              *key,
-                                                            int                      val);
-void                ide_layered_settings_set_string        (IdeLayeredSettings      *self,
-                                                            const char              *key,
-                                                            const char              *val);
-void                ide_layered_settings_set_uint          (IdeLayeredSettings      *self,
-                                                            const char              *key,
-                                                            guint                    val);
-void                ide_layered_settings_append            (IdeLayeredSettings      *self,
-                                                            GSettings               *settings);
-void                ide_layered_settings_bind              (IdeLayeredSettings      *self,
-                                                            const char              *key,
-                                                            gpointer                 object,
-                                                            const char              *property,
-                                                            GSettingsBindFlags       flags);
-void                ide_layered_settings_bind_with_mapping (IdeLayeredSettings      *self,
-                                                            const char              *key,
-                                                            gpointer                 object,
-                                                            const char              *property,
-                                                            GSettingsBindFlags       flags,
-                                                            GSettingsBindGetMapping  get_mapping,
-                                                            GSettingsBindSetMapping  set_mapping,
-                                                            gpointer                 user_data,
-                                                            GDestroyNotify           destroy);
-void                ide_layered_settings_unbind            (IdeLayeredSettings      *self,
-                                                            const char              *property);
+IdeLayeredSettings  *ide_layered_settings_new               (const char              *schema_id,
+                                                             const char              *path);
+GSettingsSchemaKey  *ide_layered_settings_get_key           (IdeLayeredSettings      *self,
+                                                             const char              *key);
+char               **ide_layered_settings_list_keys         (IdeLayeredSettings      *self);
+GVariant            *ide_layered_settings_get_default_value (IdeLayeredSettings      *self,
+                                                             const char              *key);
+GVariant            *ide_layered_settings_get_user_value    (IdeLayeredSettings      *self,
+                                                             const char              *key);
+GVariant            *ide_layered_settings_get_value         (IdeLayeredSettings      *self,
+                                                             const char              *key);
+void                 ide_layered_settings_set_value         (IdeLayeredSettings      *self,
+                                                             const char              *key,
+                                                             GVariant                *value);
+gboolean             ide_layered_settings_get_boolean       (IdeLayeredSettings      *self,
+                                                             const char              *key);
+double               ide_layered_settings_get_double        (IdeLayeredSettings      *self,
+                                                             const char              *key);
+int                  ide_layered_settings_get_int           (IdeLayeredSettings      *self,
+                                                             const char              *key);
+char                *ide_layered_settings_get_string        (IdeLayeredSettings      *self,
+                                                             const char              *key);
+guint                ide_layered_settings_get_uint          (IdeLayeredSettings      *self,
+                                                             const char              *key);
+void                 ide_layered_settings_set_boolean       (IdeLayeredSettings      *self,
+                                                             const char              *key,
+                                                             gboolean                 val);
+void                 ide_layered_settings_set_double        (IdeLayeredSettings      *self,
+                                                             const char              *key,
+                                                             double                   val);
+void                 ide_layered_settings_set_int           (IdeLayeredSettings      *self,
+                                                             const char              *key,
+                                                             int                      val);
+void                 ide_layered_settings_set_string        (IdeLayeredSettings      *self,
+                                                             const char              *key,
+                                                             const char              *val);
+void                 ide_layered_settings_set_uint          (IdeLayeredSettings      *self,
+                                                             const char              *key,
+                                                             guint                    val);
+void                 ide_layered_settings_append            (IdeLayeredSettings      *self,
+                                                             GSettings               *settings);
+void                 ide_layered_settings_bind              (IdeLayeredSettings      *self,
+                                                             const char              *key,
+                                                             gpointer                 object,
+                                                             const char              *property,
+                                                             GSettingsBindFlags       flags);
+void                 ide_layered_settings_bind_with_mapping (IdeLayeredSettings      *self,
+                                                             const char              *key,
+                                                             gpointer                 object,
+                                                             const char              *property,
+                                                             GSettingsBindFlags       flags,
+                                                             GSettingsBindGetMapping  get_mapping,
+                                                             GSettingsBindSetMapping  set_mapping,
+                                                             gpointer                 user_data,
+                                                             GDestroyNotify           destroy);
+void                 ide_layered_settings_unbind            (IdeLayeredSettings      *self,
+                                                             const char              *property);
 
 G_END_DECLS
diff --git a/src/libide/core/ide-layered-settings.c b/src/libide/core/ide-layered-settings.c
index 77bedf158..5b98fafdd 100644
--- a/src/libide/core/ide-layered-settings.c
+++ b/src/libide/core/ide-layered-settings.c
@@ -459,3 +459,53 @@ ide_layered_settings_unbind (IdeLayeredSettings *self,
   g_settings_unbind (ide_layered_settings_get_primary_settings (self), property);
   g_settings_unbind (self->memory_backend, property);
 }
+
+/**
+ * ide_layered_settings_get_key:
+ * @self: a #IdeLayeredSettings
+ * @key: the name of the setting
+ *
+ * Gets the #GSettingsSchemaKey denoted by @key.
+ *
+ * It is a programming error to call this with a key that does not exist.
+ *
+ * Returns: (transfer full): a #GSettingsSchemaKey
+ */
+GSettingsSchemaKey *
+ide_layered_settings_get_key (IdeLayeredSettings *self,
+                              const char         *key)
+{
+  g_autoptr(GSettingsSchema) schema = NULL;
+
+  g_return_val_if_fail (IDE_IS_LAYERED_SETTINGS (self), NULL);
+  g_return_val_if_fail (key != NULL, NULL);
+
+  g_object_get (self->memory_settings,
+                "settings-schema", &schema,
+                NULL);
+
+  return g_settings_schema_get_key (schema, key);
+}
+
+/**
+ * ide_layered_settings_list_keys:
+ * @self: a #IdeLayeredSettings
+ *
+ * Lists the available keys.
+ *
+ * Returns: (transfer full) (array zero-terminated=1) (element-type utf8):
+ *   an array of keys that can be retrieved from the #IdeLayeredSettings.
+ */
+char **
+ide_layered_settings_list_keys (IdeLayeredSettings *self)
+{
+  g_autoptr(GSettingsSchema) schema = NULL;
+
+  g_return_val_if_fail (IDE_IS_LAYERED_SETTINGS (self), NULL);
+
+  g_object_get (self->memory_settings,
+                "settings-schema", &schema,
+                NULL);
+
+  return g_settings_schema_list_keys (schema);
+}


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