[gnome-builder] libide/tweaks: add bind helpers and getters



commit 18c43811f0bcfbde5ae7a43a92b270a25a12f5be
Author: Christian Hergert <chergert redhat com>
Date:   Thu Aug 18 17:39:18 2022 -0700

    libide/tweaks: add bind helpers and getters
    
    This just makes some consuming code easier to write.

 src/libide/tweaks/ide-tweaks-settings.c | 73 +++++++++++++++++++++++++++++++--
 src/libide/tweaks/ide-tweaks-settings.h | 49 ++++++++++++++--------
 2 files changed, 103 insertions(+), 19 deletions(-)
---
diff --git a/src/libide/tweaks/ide-tweaks-settings.c b/src/libide/tweaks/ide-tweaks-settings.c
index c73f30876..3da376afe 100644
--- a/src/libide/tweaks/ide-tweaks-settings.c
+++ b/src/libide/tweaks/ide-tweaks-settings.c
@@ -277,16 +277,83 @@ ide_tweaks_settings_bind (IdeTweaksSettings  *self,
                           gpointer            instance,
                           const char         *property,
                           GSettingsBindFlags  bind_flags)
+{
+  g_return_if_fail (IDE_IS_TWEAKS_SETTINGS (self));
+  g_return_if_fail (key != NULL);
+  g_return_if_fail (G_IS_OBJECT (instance));
+  g_return_if_fail (property != NULL);
+
+  ide_tweaks_settings_bind_with_mapping (self, key, instance, property, bind_flags,
+                                         NULL, NULL, NULL, NULL);
+}
+
+/**
+ * ide_tweaks_settings_bind_with_mapping: (skip)
+ * @self: a #IdeTweaksSettings
+ * @key: the key
+ * @instance: the instance to bind to
+ * @property: the property of @instance
+ * @bind_flags: the flags for binding
+ * @get_mapping: a function that gets called to convert values
+ *    from @settings to @object, or %NULL to use the default GIO mapping
+ * @set_mapping: a function that gets called to convert values
+ *    from @object to @settings, or %NULL to use the default GIO mapping
+ * @user_data: data that gets passed to @get_mapping and @set_mapping
+ * @destroy: #GDestroyNotify function for @user_data
+ *
+ */
+void
+ide_tweaks_settings_bind_with_mapping (IdeTweaksSettings       *self,
+                                       const char              *key,
+                                       gpointer                 instance,
+                                       const char              *property,
+                                       GSettingsBindFlags       bind_flags,
+                                       GSettingsBindGetMapping  get_mapping,
+                                       GSettingsBindSetMapping  set_mapping,
+                                       gpointer                 user_data,
+                                       GDestroyNotify           destroy)
 {
   g_autoptr(IdeSettings) settings = NULL;
   IdeTweaksItem *root;
 
   g_return_if_fail (IDE_IS_TWEAKS_SETTINGS (self));
   g_return_if_fail (key != NULL);
-  g_return_if_fail (G_IS_OBJECT (instance));
-  g_return_if_fail (property != NULL);
 
   root = ide_tweaks_item_get_ancestor (IDE_TWEAKS_ITEM (self), IDE_TYPE_TWEAKS);
   settings = IDE_SETTINGS (ide_tweaks_settings_create_action_group (self, IDE_TWEAKS (root)));
-  ide_settings_bind (settings, key, instance, property, bind_flags);
+  ide_settings_bind_with_mapping (settings, key, instance, property, bind_flags,
+                                  get_mapping, set_mapping, user_data, destroy);
+}
+
+char *
+ide_tweaks_settings_get_string (IdeTweaksSettings *self,
+                                const char        *key)
+{
+  g_autoptr(IdeSettings) settings = NULL;
+  IdeTweaksItem *root;
+
+  g_return_val_if_fail (IDE_IS_TWEAKS_SETTINGS (self), NULL);
+  g_return_val_if_fail (key != NULL, NULL);
+
+  root = ide_tweaks_item_get_ancestor (IDE_TWEAKS_ITEM (self), IDE_TYPE_TWEAKS);
+  settings = IDE_SETTINGS (ide_tweaks_settings_create_action_group (self, IDE_TWEAKS (root)));
+
+  return ide_settings_get_string (settings, key);
+}
+
+void
+ide_tweaks_settings_set_string (IdeTweaksSettings *self,
+                                const char        *key,
+                                const char        *value)
+{
+  g_autoptr(IdeSettings) settings = NULL;
+  IdeTweaksItem *root;
+
+  g_return_if_fail (IDE_IS_TWEAKS_SETTINGS (self));
+  g_return_if_fail (key != NULL);
+
+  root = ide_tweaks_item_get_ancestor (IDE_TWEAKS_ITEM (self), IDE_TYPE_TWEAKS);
+  settings = IDE_SETTINGS (ide_tweaks_settings_create_action_group (self, IDE_TWEAKS (root)));
+
+  ide_settings_set_string (settings, key, value);
 }
diff --git a/src/libide/tweaks/ide-tweaks-settings.h b/src/libide/tweaks/ide-tweaks-settings.h
index 215b12ffb..fa1b7c0fc 100644
--- a/src/libide/tweaks/ide-tweaks-settings.h
+++ b/src/libide/tweaks/ide-tweaks-settings.h
@@ -33,28 +33,45 @@ G_DECLARE_FINAL_TYPE (IdeTweaksSettings, ide_tweaks_settings, IDE, TWEAKS_SETTIN
 IDE_AVAILABLE_IN_ALL
 IdeTweaksSettings *ide_tweaks_settings_new                  (void);
 IDE_AVAILABLE_IN_ALL
-const char        *ide_tweaks_settings_get_schema_id        (IdeTweaksSettings  *self);
+const char        *ide_tweaks_settings_get_schema_id        (IdeTweaksSettings       *self);
 IDE_AVAILABLE_IN_ALL
-void               ide_tweaks_settings_set_schema_id        (IdeTweaksSettings  *self,
-                                                             const char         *schema_id);
+void               ide_tweaks_settings_set_schema_id        (IdeTweaksSettings       *self,
+                                                             const char              *schema_id);
 IDE_AVAILABLE_IN_ALL
-const char        *ide_tweaks_settings_get_schema_path      (IdeTweaksSettings  *self);
+const char        *ide_tweaks_settings_get_schema_path      (IdeTweaksSettings       *self);
 IDE_AVAILABLE_IN_ALL
-void               ide_tweaks_settings_set_schema_path      (IdeTweaksSettings  *self,
-                                                             const char         *schema_path);
+void               ide_tweaks_settings_set_schema_path      (IdeTweaksSettings       *self,
+                                                             const char              *schema_path);
 IDE_AVAILABLE_IN_ALL
-gboolean           ide_tweaks_settings_get_application_only (IdeTweaksSettings  *self);
+gboolean           ide_tweaks_settings_get_application_only (IdeTweaksSettings       *self);
 IDE_AVAILABLE_IN_ALL
-void               ide_tweaks_settings_set_application_only (IdeTweaksSettings  *self,
-                                                             gboolean            application_only);
+void               ide_tweaks_settings_set_application_only (IdeTweaksSettings       *self,
+                                                             gboolean                 application_only);
 IDE_AVAILABLE_IN_ALL
-GActionGroup      *ide_tweaks_settings_create_action_group  (IdeTweaksSettings  *self,
-                                                             IdeTweaks          *tweaks);
+GActionGroup      *ide_tweaks_settings_create_action_group  (IdeTweaksSettings       *self,
+                                                             IdeTweaks               *tweaks);
 IDE_AVAILABLE_IN_ALL
-void               ide_tweaks_settings_bind                 (IdeTweaksSettings  *self,
-                                                             const char         *key,
-                                                             gpointer            instance,
-                                                             const char         *property,
-                                                             GSettingsBindFlags  bind_flags);
+void               ide_tweaks_settings_bind                 (IdeTweaksSettings       *self,
+                                                             const char              *key,
+                                                             gpointer                 instance,
+                                                             const char              *property,
+                                                             GSettingsBindFlags       bind_flags);
+IDE_AVAILABLE_IN_ALL
+void               ide_tweaks_settings_bind_with_mapping    (IdeTweaksSettings       *self,
+                                                             const char              *key,
+                                                             gpointer                 instance,
+                                                             const char              *property,
+                                                             GSettingsBindFlags       bind_flags,
+                                                             GSettingsBindGetMapping  get_mapping,
+                                                             GSettingsBindSetMapping  set_mapping,
+                                                             gpointer                 user_data,
+                                                             GDestroyNotify           destroy);
+IDE_AVAILABLE_IN_ALL
+char              *ide_tweaks_settings_get_string           (IdeTweaksSettings       *self,
+                                                             const char              *key);
+IDE_AVAILABLE_IN_ALL
+void               ide_tweaks_settings_set_string           (IdeTweaksSettings       *self,
+                                                             const char              *key,
+                                                             const char              *value);
 
 G_END_DECLS


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