[gnome-builder/wip/settings: 3/3] settings: allow pinning settings to global gsettings
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/settings: 3/3] settings: allow pinning settings to global gsettings
- Date: Sun, 3 May 2015 20:30:25 +0000 (UTC)
commit 7ee7403a063fb42d9ff3efd281ce9a92e18c6ad0
Author: Christian Hergert <christian hergert me>
Date: Sun May 3 13:29:26 2015 -0700
settings: allow pinning settings to global gsettings
So that we can use the same helper object when configuring project as well
as global preferences, we need to allow ourselves to ignore the project
settings.
By setting IdeSettings:is-global, we'll ignore the gsettings at the
project relative path.
libide/ide-settings.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++--
libide/ide-settings.h | 39 ++++++++++++++++++---------------
2 files changed, 74 insertions(+), 21 deletions(-)
---
diff --git a/libide/ide-settings.c b/libide/ide-settings.c
index 538a6e9..2f7399a 100644
--- a/libide/ide-settings.c
+++ b/libide/ide-settings.c
@@ -48,6 +48,8 @@ struct _IdeSettings
GSettings *global_settings;
GSettings *project_settings;
+
+ guint is_global : 1;
};
G_DEFINE_TYPE (IdeSettings, ide_settings, IDE_TYPE_OBJECT)
@@ -56,6 +58,7 @@ enum {
PROP_0,
PROP_RELATIVE_PATH,
PROP_SCHEMA_ID,
+ PROP_IS_GLOBAL,
LAST_PROP
};
@@ -118,7 +121,8 @@ ide_settings__project_settings_changed (IdeSettings *self,
g_assert (key != NULL);
g_assert (G_IS_SETTINGS (project_settings));
- g_signal_emit (self, gSignals [CHANGED], g_quark_from_string (key), key);
+ if (self->is_global == FALSE)
+ g_signal_emit (self, gSignals [CHANGED], g_quark_from_string (key), key);
}
static void
@@ -206,6 +210,10 @@ ide_settings_get_property (GObject *object,
g_value_set_string (value, ide_settings_get_relative_path (self));
break;
+ case PROP_IS_GLOBAL:
+ g_value_set_boolean (value, ide_settings_get_is_global (self));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -229,6 +237,10 @@ ide_settings_set_property (GObject *object,
ide_settings_set_relative_path (self, g_value_get_object (value));
break;
+ case PROP_IS_GLOBAL:
+ ide_settings_set_is_global (self, g_value_get_boolean (value));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -314,18 +326,34 @@ GVariant *
ide_settings_get_value (IdeSettings *self,
const gchar *key)
{
- GVariant *ret;
+ GVariant *ret = NULL;
g_return_val_if_fail (IDE_IS_SETTINGS (self), NULL);
g_return_val_if_fail (key != NULL, NULL);
- ret = g_settings_get_user_value (self->project_settings, key);
+ if (self->is_global == FALSE)
+ ret = g_settings_get_user_value (self->project_settings, key);
+
if (ret == NULL)
ret = g_settings_get_value (self->global_settings, key);
return ret;
}
+void
+ide_settings_set_value (IdeSettings *self,
+ const gchar *key,
+ GVariant *value)
+{
+ g_return_if_fail (IDE_IS_SETTINGS (self));
+ g_return_if_fail (key != NULL);
+
+ if (self->is_global)
+ g_settings_set_value (self->global_settings, key, value);
+ else
+ g_settings_set_value (self->project_settings, key, value);
+}
+
GVariant *
ide_settings_get_user_value (IdeSettings *self,
const gchar *key)
@@ -395,3 +423,25 @@ DEFINE_SETTER (guint, uint, new_uint32)
DEFINE_SETTER (double, double, new_double)
DEFINE_SETTER (const gchar *, string, new_string)
+gboolean
+ide_settings_get_is_global (IdeSettings *self)
+{
+ g_return_val_if_fail (IDE_IS_SETTINGS (self), FALSE);
+
+ return self->is_global;
+}
+
+void
+ide_settings_set_is_global (IdeSettings *self,
+ gboolean is_global)
+{
+ g_return_if_fail (IDE_IS_SETTINGS (self));
+
+ is_global = !!is_global;
+
+ if (is_global != self->is_global)
+ {
+ self->is_global = is_global;
+ g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_IS_GLOBAL]);
+ }
+}
diff --git a/libide/ide-settings.h b/libide/ide-settings.h
index 6d411c1..7f747d9 100644
--- a/libide/ide-settings.h
+++ b/libide/ide-settings.h
@@ -27,24 +27,27 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (IdeSettings, ide_settings, IDE, SETTINGS, IdeObject)
-const gchar *ide_settings_get_relative_path (IdeSettings *self);
-const gchar *ide_settings_get_schema_id (IdeSettings *self);
-GVariant *ide_settings_get_value (IdeSettings *self,
- const gchar *key);
-GVariant *ide_settings_get_default_value (IdeSettings *self,
- const gchar *key);
-GVariant *ide_settings_get_user_value (IdeSettings *self,
- const gchar *key);
-guint ide_settings_get_uint (IdeSettings *self,
- const gchar *key);
-gint ide_settings_get_int (IdeSettings *self,
- const gchar *key);
-gboolean ide_settings_get_gboolean (IdeSettings *self,
- const gchar *key);
-gchar *ide_settings_get_string (IdeSettings *self,
- const gchar *key);
-gdouble ide_settings_get_double (IdeSettings *self,
- const gchar *key);
+const gchar *ide_settings_get_relative_path (IdeSettings *self);
+const gchar *ide_settings_get_schema_id (IdeSettings *self);
+GVariant *ide_settings_get_value (IdeSettings *self,
+ const gchar *key);
+GVariant *ide_settings_get_default_value (IdeSettings *self,
+ const gchar *key);
+GVariant *ide_settings_get_user_value (IdeSettings *self,
+ const gchar *key);
+guint ide_settings_get_uint (IdeSettings *self,
+ const gchar *key);
+gint ide_settings_get_int (IdeSettings *self,
+ const gchar *key);
+gboolean ide_settings_get_gboolean (IdeSettings *self,
+ const gchar *key);
+gchar *ide_settings_get_string (IdeSettings *self,
+ const gchar *key);
+gdouble ide_settings_get_double (IdeSettings *self,
+ const gchar *key);
+gboolean ide_settings_get_is_global (IdeSettings *self);
+void ide_settings_set_is_global (IdeSettings *self,
+ gboolean is_global);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]