|
|
51ad59 |
From 5634fd61f17d28dfc05cd47cfbd2bd2f21e6d2b1 Mon Sep 17 00:00:00 2001
|
|
|
51ad59 |
From: Allison Lortie <desrt@desrt.ca>
|
|
|
51ad59 |
Date: Wed, 2 Aug 2017 11:06:03 +0100
|
|
|
51ad59 |
Subject: [PATCH 1/4] gsettings: cleanup default value lookup
|
|
|
51ad59 |
|
|
|
51ad59 |
There are a couple of different ways (and soon one more) to access the
|
|
|
51ad59 |
default value of a key. Clean up the various places that access this to
|
|
|
51ad59 |
avoid duplication.
|
|
|
51ad59 |
|
|
|
51ad59 |
https://bugzilla.gnome.org/show_bug.cgi?id=746592
|
|
|
51ad59 |
---
|
|
|
51ad59 |
gio/gsettings.c | 20 ++++----------------
|
|
|
51ad59 |
1 file changed, 4 insertions(+), 16 deletions(-)
|
|
|
51ad59 |
|
|
|
51ad59 |
diff --git a/gio/gsettings.c b/gio/gsettings.c
|
|
|
51ad59 |
index 10d394d69..5e5816d57 100644
|
|
|
51ad59 |
--- a/gio/gsettings.c
|
|
|
51ad59 |
+++ b/gio/gsettings.c
|
|
|
51ad59 |
@@ -1204,10 +1204,7 @@ g_settings_get_value (GSettings *settings,
|
|
|
51ad59 |
value = g_settings_read_from_backend (settings, &skey, FALSE, FALSE);
|
|
|
51ad59 |
|
|
|
51ad59 |
if (value == NULL)
|
|
|
51ad59 |
- value = g_settings_schema_key_get_translated_default (&skey);
|
|
|
51ad59 |
-
|
|
|
51ad59 |
- if (value == NULL)
|
|
|
51ad59 |
- value = g_variant_ref (skey.default_value);
|
|
|
51ad59 |
+ value = g_settings_schema_key_get_default_value (&skey);
|
|
|
51ad59 |
|
|
|
51ad59 |
g_settings_schema_key_clear (&skey);
|
|
|
51ad59 |
|
|
|
51ad59 |
@@ -1304,10 +1301,7 @@ g_settings_get_default_value (GSettings *settings,
|
|
|
51ad59 |
value = g_settings_read_from_backend (settings, &skey, FALSE, TRUE);
|
|
|
51ad59 |
|
|
|
51ad59 |
if (value == NULL)
|
|
|
51ad59 |
- value = g_settings_schema_key_get_translated_default (&skey);
|
|
|
51ad59 |
-
|
|
|
51ad59 |
- if (value == NULL)
|
|
|
51ad59 |
- value = g_variant_ref (skey.default_value);
|
|
|
51ad59 |
+ value = g_settings_schema_key_get_default_value (&skey);
|
|
|
51ad59 |
|
|
|
51ad59 |
g_settings_schema_key_clear (&skey);
|
|
|
51ad59 |
|
|
|
51ad59 |
@@ -1360,10 +1354,7 @@ g_settings_get_enum (GSettings *settings,
|
|
|
51ad59 |
value = g_settings_read_from_backend (settings, &skey, FALSE, FALSE);
|
|
|
51ad59 |
|
|
|
51ad59 |
if (value == NULL)
|
|
|
51ad59 |
- value = g_settings_schema_key_get_translated_default (&skey);
|
|
|
51ad59 |
-
|
|
|
51ad59 |
- if (value == NULL)
|
|
|
51ad59 |
- value = g_variant_ref (skey.default_value);
|
|
|
51ad59 |
+ value = g_settings_schema_key_get_default_value (&skey);
|
|
|
51ad59 |
|
|
|
51ad59 |
result = g_settings_schema_key_to_enum (&skey, value);
|
|
|
51ad59 |
g_settings_schema_key_clear (&skey);
|
|
|
51ad59 |
@@ -1473,10 +1464,7 @@ g_settings_get_flags (GSettings *settings,
|
|
|
51ad59 |
value = g_settings_read_from_backend (settings, &skey, FALSE, FALSE);
|
|
|
51ad59 |
|
|
|
51ad59 |
if (value == NULL)
|
|
|
51ad59 |
- value = g_settings_schema_key_get_translated_default (&skey);
|
|
|
51ad59 |
-
|
|
|
51ad59 |
- if (value == NULL)
|
|
|
51ad59 |
- value = g_variant_ref (skey.default_value);
|
|
|
51ad59 |
+ value = g_settings_schema_key_get_default_value (&skey);
|
|
|
51ad59 |
|
|
|
51ad59 |
result = g_settings_schema_key_to_flags (&skey, value);
|
|
|
51ad59 |
g_settings_schema_key_clear (&skey);
|
|
|
51ad59 |
--
|
|
|
51ad59 |
2.21.0
|
|
|
51ad59 |
|
|
|
51ad59 |
|
|
|
51ad59 |
From 89c6e8f4a0bcda4b58dbaea713e62be01cfc2087 Mon Sep 17 00:00:00 2001
|
|
|
51ad59 |
From: Allison Lortie <desrt@desrt.ca>
|
|
|
51ad59 |
Date: Wed, 2 Aug 2017 11:08:17 +0100
|
|
|
51ad59 |
Subject: [PATCH 2/4] gsettingsschema: Allow per-desktop overrides
|
|
|
51ad59 |
MIME-Version: 1.0
|
|
|
51ad59 |
Content-Type: text/plain; charset=UTF-8
|
|
|
51ad59 |
Content-Transfer-Encoding: 8bit
|
|
|
51ad59 |
|
|
|
51ad59 |
Recognise a new 'd' option in schema keys which gives a dictionary of
|
|
|
51ad59 |
per-desktop default values. This dictionary is searched for the items
|
|
|
51ad59 |
found in XDG_CURRENT_DESKTOP, in the order. If nothing matches (or if
|
|
|
51ad59 |
the option is missing) then the default value is used as before.
|
|
|
51ad59 |
|
|
|
51ad59 |
This feature was requested by Alberts Muktupāvels and this patch is
|
|
|
51ad59 |
based on an approach devised by them.
|
|
|
51ad59 |
|
|
|
51ad59 |
https://bugzilla.gnome.org/show_bug.cgi?id=746592
|
|
|
51ad59 |
---
|
|
|
51ad59 |
gio/gsettings.c | 21 +++++++++++++++++
|
|
|
51ad59 |
gio/gsettingsschema-internal.h | 2 ++
|
|
|
51ad59 |
gio/gsettingsschema.c | 41 ++++++++++++++++++++++++++++++++++
|
|
|
51ad59 |
3 files changed, 64 insertions(+)
|
|
|
51ad59 |
|
|
|
51ad59 |
diff --git a/gio/gsettings.c b/gio/gsettings.c
|
|
|
51ad59 |
index 5e5816d57..f1130c095 100644
|
|
|
51ad59 |
--- a/gio/gsettings.c
|
|
|
51ad59 |
+++ b/gio/gsettings.c
|
|
|
51ad59 |
@@ -1739,6 +1739,13 @@ g_settings_get_mapped (GSettings *settings,
|
|
|
51ad59 |
if (okay) goto okay;
|
|
|
51ad59 |
}
|
|
|
51ad59 |
|
|
|
51ad59 |
+ if ((value = g_settings_schema_key_get_per_desktop_default (&skey)))
|
|
|
51ad59 |
+ {
|
|
|
51ad59 |
+ okay = mapping (value, &result, user_data);
|
|
|
51ad59 |
+ g_variant_unref (value);
|
|
|
51ad59 |
+ if (okay) goto okay;
|
|
|
51ad59 |
+ }
|
|
|
51ad59 |
+
|
|
|
51ad59 |
if (mapping (skey.default_value, &result, user_data))
|
|
|
51ad59 |
goto okay;
|
|
|
51ad59 |
|
|
|
51ad59 |
@@ -2647,6 +2654,20 @@ g_settings_binding_key_changed (GSettings *settings,
|
|
|
51ad59 |
}
|
|
|
51ad59 |
}
|
|
|
51ad59 |
|
|
|
51ad59 |
+ if (variant == NULL)
|
|
|
51ad59 |
+ {
|
|
|
51ad59 |
+ variant = g_settings_schema_key_get_per_desktop_default (&binding->key);
|
|
|
51ad59 |
+ if (variant &&
|
|
|
51ad59 |
+ !binding->get_mapping (&value, variant, binding->user_data))
|
|
|
51ad59 |
+ {
|
|
|
51ad59 |
+ g_error ("Per-desktop default value for key '%s' in schema '%s' "
|
|
|
51ad59 |
+ "was rejected by the binding mapping function.",
|
|
|
51ad59 |
+ binding->key.name, g_settings_schema_get_id (binding->key.schema));
|
|
|
51ad59 |
+ g_variant_unref (variant);
|
|
|
51ad59 |
+ variant = NULL;
|
|
|
51ad59 |
+ }
|
|
|
51ad59 |
+ }
|
|
|
51ad59 |
+
|
|
|
51ad59 |
if (variant == NULL)
|
|
|
51ad59 |
{
|
|
|
51ad59 |
variant = g_variant_ref (binding->key.default_value);
|
|
|
51ad59 |
diff --git a/gio/gsettingsschema-internal.h b/gio/gsettingsschema-internal.h
|
|
|
51ad59 |
index f54de3b34..5f996b4bc 100644
|
|
|
51ad59 |
--- a/gio/gsettingsschema-internal.h
|
|
|
51ad59 |
+++ b/gio/gsettingsschema-internal.h
|
|
|
51ad59 |
@@ -37,6 +37,7 @@ struct _GSettingsSchemaKey
|
|
|
51ad59 |
const GVariantType *type;
|
|
|
51ad59 |
GVariant *minimum, *maximum;
|
|
|
51ad59 |
GVariant *default_value;
|
|
|
51ad59 |
+ GVariant *desktop_overrides;
|
|
|
51ad59 |
|
|
|
51ad59 |
gint ref_count;
|
|
|
51ad59 |
};
|
|
|
51ad59 |
@@ -58,6 +59,7 @@ gboolean g_settings_schema_key_type_check (GSettin
|
|
|
51ad59 |
GVariant * g_settings_schema_key_range_fixup (GSettingsSchemaKey *key,
|
|
|
51ad59 |
GVariant *value);
|
|
|
51ad59 |
GVariant * g_settings_schema_key_get_translated_default (GSettingsSchemaKey *key);
|
|
|
51ad59 |
+GVariant * g_settings_schema_key_get_per_desktop_default (GSettingsSchemaKey *key);
|
|
|
51ad59 |
|
|
|
51ad59 |
gint g_settings_schema_key_to_enum (GSettingsSchemaKey *key,
|
|
|
51ad59 |
GVariant *value);
|
|
|
51ad59 |
diff --git a/gio/gsettingsschema.c b/gio/gsettingsschema.c
|
|
|
51ad59 |
index f1274a369..17b7e3b01 100644
|
|
|
51ad59 |
--- a/gio/gsettingsschema.c
|
|
|
51ad59 |
+++ b/gio/gsettingsschema.c
|
|
|
51ad59 |
@@ -27,6 +27,7 @@
|
|
|
51ad59 |
#include <glibintl.h>
|
|
|
51ad59 |
#include <locale.h>
|
|
|
51ad59 |
#include <string.h>
|
|
|
51ad59 |
+#include <stdlib.h>
|
|
|
51ad59 |
|
|
|
51ad59 |
/**
|
|
|
51ad59 |
* SECTION:gsettingsschema
|
|
|
51ad59 |
@@ -1283,6 +1284,11 @@ g_settings_schema_key_init (GSettingsSchemaKey *key,
|
|
|
51ad59 |
endian_fixup (&key->maximum);
|
|
|
51ad59 |
break;
|
|
|
51ad59 |
|
|
|
51ad59 |
+ case 'd':
|
|
|
51ad59 |
+ g_variant_get (data, "@a{sv}", &key->desktop_overrides);
|
|
|
51ad59 |
+ endian_fixup (&key->desktop_overrides);
|
|
|
51ad59 |
+ break;
|
|
|
51ad59 |
+
|
|
|
51ad59 |
default:
|
|
|
51ad59 |
g_warning ("unknown schema extension '%c'", code);
|
|
|
51ad59 |
break;
|
|
|
51ad59 |
@@ -1303,6 +1309,9 @@ g_settings_schema_key_clear (GSettingsSchemaKey *key)
|
|
|
51ad59 |
if (key->maximum)
|
|
|
51ad59 |
g_variant_unref (key->maximum);
|
|
|
51ad59 |
|
|
|
51ad59 |
+ if (key->desktop_overrides)
|
|
|
51ad59 |
+ g_variant_unref (key->desktop_overrides);
|
|
|
51ad59 |
+
|
|
|
51ad59 |
g_variant_unref (key->default_value);
|
|
|
51ad59 |
|
|
|
51ad59 |
g_settings_schema_unref (key->schema);
|
|
|
51ad59 |
@@ -1410,6 +1419,35 @@ g_settings_schema_key_get_translated_default (GSettingsSchemaKey *key)
|
|
|
51ad59 |
return value;
|
|
|
51ad59 |
}
|
|
|
51ad59 |
|
|
|
51ad59 |
+GVariant *
|
|
|
51ad59 |
+g_settings_schema_key_get_per_desktop_default (GSettingsSchemaKey *key)
|
|
|
51ad59 |
+{
|
|
|
51ad59 |
+ static const gchar * const *current_desktops;
|
|
|
51ad59 |
+ GVariant *value = NULL;
|
|
|
51ad59 |
+ gint i;
|
|
|
51ad59 |
+
|
|
|
51ad59 |
+ if (!key->desktop_overrides)
|
|
|
51ad59 |
+ return NULL;
|
|
|
51ad59 |
+
|
|
|
51ad59 |
+ if (g_once_init_enter (¤t_desktops))
|
|
|
51ad59 |
+ {
|
|
|
51ad59 |
+ const gchar *xdg_current_desktop = g_getenv ("XDG_CURRENT_DESKTOP");
|
|
|
51ad59 |
+ gchar **tmp;
|
|
|
51ad59 |
+
|
|
|
51ad59 |
+ if (xdg_current_desktop != NULL && xdg_current_desktop[0] != '\0')
|
|
|
51ad59 |
+ tmp = g_strsplit (xdg_current_desktop, G_SEARCHPATH_SEPARATOR_S, -1);
|
|
|
51ad59 |
+ else
|
|
|
51ad59 |
+ tmp = g_new0 (gchar *, 0 + 1);
|
|
|
51ad59 |
+
|
|
|
51ad59 |
+ g_once_init_leave (¤t_desktops, (const gchar **) tmp);
|
|
|
51ad59 |
+ }
|
|
|
51ad59 |
+
|
|
|
51ad59 |
+ for (i = 0; value == NULL && current_desktops[i] != NULL; i++)
|
|
|
51ad59 |
+ value = g_variant_lookup_value (key->desktop_overrides, current_desktops[i], NULL);
|
|
|
51ad59 |
+
|
|
|
51ad59 |
+ return value;
|
|
|
51ad59 |
+}
|
|
|
51ad59 |
+
|
|
|
51ad59 |
gint
|
|
|
51ad59 |
g_settings_schema_key_to_enum (GSettingsSchemaKey *key,
|
|
|
51ad59 |
GVariant *value)
|
|
|
51ad59 |
@@ -1698,6 +1736,9 @@ g_settings_schema_key_get_default_value (GSettingsSchemaKey *key)
|
|
|
51ad59 |
|
|
|
51ad59 |
value = g_settings_schema_key_get_translated_default (key);
|
|
|
51ad59 |
|
|
|
51ad59 |
+ if (!value)
|
|
|
51ad59 |
+ value = g_settings_schema_key_get_per_desktop_default (key);
|
|
|
51ad59 |
+
|
|
|
51ad59 |
if (!value)
|
|
|
51ad59 |
value = g_variant_ref (key->default_value);
|
|
|
51ad59 |
|
|
|
51ad59 |
--
|
|
|
51ad59 |
2.21.0
|
|
|
51ad59 |
|
|
|
51ad59 |
|
|
|
51ad59 |
From 3710e830de015829c086c69181a8703645d577ec Mon Sep 17 00:00:00 2001
|
|
|
51ad59 |
From: Allison Lortie <desrt@desrt.ca>
|
|
|
51ad59 |
Date: Wed, 2 Aug 2017 11:10:18 +0100
|
|
|
51ad59 |
Subject: [PATCH 3/4] glib-compile-schemas: Handle per-desktop overrides
|
|
|
51ad59 |
|
|
|
51ad59 |
Add a new syntax to override files: if the group name has a ':' in it,
|
|
|
51ad59 |
it indicates that we want to override the default values of keys for
|
|
|
51ad59 |
only one desktop. For example:
|
|
|
51ad59 |
|
|
|
51ad59 |
[org.gnome.desktop.interface:Unity]
|
|
|
51ad59 |
font-name='Ubuntu 12'
|
|
|
51ad59 |
|
|
|
51ad59 |
Will override the settings, only if "Unity" is found in
|
|
|
51ad59 |
XDG_CURRENT_DESKTOP. Multiple per-desktop overrides can be specified
|
|
|
51ad59 |
for a given key: the one which comes first in XDG_CURRENT_DESKTOP will
|
|
|
51ad59 |
be used.
|
|
|
51ad59 |
|
|
|
51ad59 |
https://bugzilla.gnome.org/show_bug.cgi?id=746592
|
|
|
51ad59 |
---
|
|
|
51ad59 |
gio/glib-compile-schemas.c | 83 ++++++++++++++++++++++++++++++++++----
|
|
|
51ad59 |
1 file changed, 75 insertions(+), 8 deletions(-)
|
|
|
51ad59 |
|
|
|
51ad59 |
diff --git a/gio/glib-compile-schemas.c b/gio/glib-compile-schemas.c
|
|
|
51ad59 |
index 2dc8c7171..59fb68ee7 100644
|
|
|
51ad59 |
--- a/gio/glib-compile-schemas.c
|
|
|
51ad59 |
+++ b/gio/glib-compile-schemas.c
|
|
|
51ad59 |
@@ -179,6 +179,8 @@ typedef struct
|
|
|
51ad59 |
GString *unparsed_default_value;
|
|
|
51ad59 |
GVariant *default_value;
|
|
|
51ad59 |
|
|
|
51ad59 |
+ GVariantDict *desktop_overrides;
|
|
|
51ad59 |
+
|
|
|
51ad59 |
GString *strinfo;
|
|
|
51ad59 |
gboolean is_enum;
|
|
|
51ad59 |
gboolean is_flags;
|
|
|
51ad59 |
@@ -731,6 +733,11 @@ key_state_serialise (KeyState *state)
|
|
|
51ad59 |
g_variant_builder_add (&builder, "(y(**))", 'r',
|
|
|
51ad59 |
state->minimum, state->maximum);
|
|
|
51ad59 |
|
|
|
51ad59 |
+ /* per-desktop overrides */
|
|
|
51ad59 |
+ if (state->desktop_overrides)
|
|
|
51ad59 |
+ g_variant_builder_add (&builder, "(y@a{sv})", 'd',
|
|
|
51ad59 |
+ g_variant_dict_end (state->desktop_overrides));
|
|
|
51ad59 |
+
|
|
|
51ad59 |
state->serialised = g_variant_builder_end (&builder);
|
|
|
51ad59 |
}
|
|
|
51ad59 |
|
|
|
51ad59 |
@@ -768,6 +775,9 @@ key_state_free (gpointer data)
|
|
|
51ad59 |
if (state->serialised)
|
|
|
51ad59 |
g_variant_unref (state->serialised);
|
|
|
51ad59 |
|
|
|
51ad59 |
+ if (state->desktop_overrides)
|
|
|
51ad59 |
+ g_variant_dict_unref (state->desktop_overrides);
|
|
|
51ad59 |
+
|
|
|
51ad59 |
g_slice_free (KeyState, state);
|
|
|
51ad59 |
}
|
|
|
51ad59 |
|
|
|
51ad59 |
@@ -1878,6 +1888,8 @@ set_overrides (GHashTable *schema_table,
|
|
|
51ad59 |
gchar **groups;
|
|
|
51ad59 |
gint i;
|
|
|
51ad59 |
|
|
|
51ad59 |
+ g_debug ("Processing override file '%s'", filename);
|
|
|
51ad59 |
+
|
|
|
51ad59 |
key_file = g_key_file_new ();
|
|
|
51ad59 |
if (!g_key_file_load_from_file (key_file, filename, 0, &error))
|
|
|
51ad59 |
{
|
|
|
51ad59 |
@@ -1900,18 +1912,31 @@ set_overrides (GHashTable *schema_table,
|
|
|
51ad59 |
for (i = 0; groups[i]; i++)
|
|
|
51ad59 |
{
|
|
|
51ad59 |
const gchar *group = groups[i];
|
|
|
51ad59 |
+ const gchar *schema_name;
|
|
|
51ad59 |
+ const gchar *desktop_id;
|
|
|
51ad59 |
SchemaState *schema;
|
|
|
51ad59 |
+ gchar **pieces;
|
|
|
51ad59 |
gchar **keys;
|
|
|
51ad59 |
gint j;
|
|
|
51ad59 |
|
|
|
51ad59 |
- schema = g_hash_table_lookup (schema_table, group);
|
|
|
51ad59 |
+ pieces = g_strsplit (group, ":", 2);
|
|
|
51ad59 |
+ schema_name = pieces[0];
|
|
|
51ad59 |
+ desktop_id = pieces[1];
|
|
|
51ad59 |
+
|
|
|
51ad59 |
+ g_debug ("Processing group '%s' (schema '%s', %s)",
|
|
|
51ad59 |
+ group, schema_name, desktop_id ? desktop_id : "all desktops");
|
|
|
51ad59 |
+
|
|
|
51ad59 |
+ schema = g_hash_table_lookup (schema_table, schema_name);
|
|
|
51ad59 |
|
|
|
51ad59 |
if (schema == NULL)
|
|
|
51ad59 |
- /* Having the schema not be installed is expected to be a
|
|
|
51ad59 |
- * common case. Don't even emit an error message about
|
|
|
51ad59 |
- * that.
|
|
|
51ad59 |
- */
|
|
|
51ad59 |
- continue;
|
|
|
51ad59 |
+ {
|
|
|
51ad59 |
+ /* Having the schema not be installed is expected to be a
|
|
|
51ad59 |
+ * common case. Don't even emit an error message about
|
|
|
51ad59 |
+ * that.
|
|
|
51ad59 |
+ */
|
|
|
51ad59 |
+ g_strfreev (pieces);
|
|
|
51ad59 |
+ continue;
|
|
|
51ad59 |
+ }
|
|
|
51ad59 |
|
|
|
51ad59 |
keys = g_key_file_get_keys (key_file, group, NULL, NULL);
|
|
|
51ad59 |
g_assert (keys != NULL);
|
|
|
51ad59 |
@@ -1939,6 +1964,32 @@ set_overrides (GHashTable *schema_table,
|
|
|
51ad59 |
|
|
|
51ad59 |
fprintf (stderr, _(" and --strict was specified; exiting.\n"));
|
|
|
51ad59 |
g_key_file_free (key_file);
|
|
|
51ad59 |
+ g_strfreev (pieces);
|
|
|
51ad59 |
+ g_strfreev (groups);
|
|
|
51ad59 |
+ g_strfreev (keys);
|
|
|
51ad59 |
+
|
|
|
51ad59 |
+ return FALSE;
|
|
|
51ad59 |
+ }
|
|
|
51ad59 |
+
|
|
|
51ad59 |
+ if (desktop_id != NULL && state->l10n)
|
|
|
51ad59 |
+ {
|
|
|
51ad59 |
+ /* Let's avoid the n*m case of per-desktop localised
|
|
|
51ad59 |
+ * default values, and just forbid it.
|
|
|
51ad59 |
+ */
|
|
|
51ad59 |
+ fprintf (stderr,
|
|
|
51ad59 |
+ _("cannot provide per-desktop overrides for localised "
|
|
|
51ad59 |
+ "key '%s' in schema '%s' (override file '%s')"),
|
|
|
51ad59 |
+ key, group, filename);
|
|
|
51ad59 |
+
|
|
|
51ad59 |
+ if (!strict)
|
|
|
51ad59 |
+ {
|
|
|
51ad59 |
+ fprintf (stderr, _("; ignoring override for this key.\n"));
|
|
|
51ad59 |
+ continue;
|
|
|
51ad59 |
+ }
|
|
|
51ad59 |
+
|
|
|
51ad59 |
+ fprintf (stderr, _(" and --strict was specified; exiting.\n"));
|
|
|
51ad59 |
+ g_key_file_free (key_file);
|
|
|
51ad59 |
+ g_strfreev (pieces);
|
|
|
51ad59 |
g_strfreev (groups);
|
|
|
51ad59 |
g_strfreev (keys);
|
|
|
51ad59 |
|
|
|
51ad59 |
@@ -1969,6 +2020,7 @@ set_overrides (GHashTable *schema_table,
|
|
|
51ad59 |
|
|
|
51ad59 |
fprintf (stderr, _("--strict was specified; exiting.\n"));
|
|
|
51ad59 |
g_key_file_free (key_file);
|
|
|
51ad59 |
+ g_strfreev (pieces);
|
|
|
51ad59 |
g_strfreev (groups);
|
|
|
51ad59 |
g_strfreev (keys);
|
|
|
51ad59 |
|
|
|
51ad59 |
@@ -1997,6 +2049,7 @@ set_overrides (GHashTable *schema_table,
|
|
|
51ad59 |
|
|
|
51ad59 |
fprintf (stderr, _(" and --strict was specified; exiting.\n"));
|
|
|
51ad59 |
g_key_file_free (key_file);
|
|
|
51ad59 |
+ g_strfreev (pieces);
|
|
|
51ad59 |
g_strfreev (groups);
|
|
|
51ad59 |
g_strfreev (keys);
|
|
|
51ad59 |
|
|
|
51ad59 |
@@ -2025,6 +2078,7 @@ set_overrides (GHashTable *schema_table,
|
|
|
51ad59 |
|
|
|
51ad59 |
fprintf (stderr, _(" and --strict was specified; exiting.\n"));
|
|
|
51ad59 |
g_key_file_free (key_file);
|
|
|
51ad59 |
+ g_strfreev (pieces);
|
|
|
51ad59 |
g_strfreev (groups);
|
|
|
51ad59 |
g_strfreev (keys);
|
|
|
51ad59 |
|
|
|
51ad59 |
@@ -2032,11 +2086,24 @@ set_overrides (GHashTable *schema_table,
|
|
|
51ad59 |
}
|
|
|
51ad59 |
}
|
|
|
51ad59 |
|
|
|
51ad59 |
- g_variant_unref (state->default_value);
|
|
|
51ad59 |
- state->default_value = value;
|
|
|
51ad59 |
+ if (desktop_id != NULL)
|
|
|
51ad59 |
+ {
|
|
|
51ad59 |
+ if (state->desktop_overrides == NULL)
|
|
|
51ad59 |
+ state->desktop_overrides = g_variant_dict_new (NULL);
|
|
|
51ad59 |
+
|
|
|
51ad59 |
+ g_variant_dict_insert_value (state->desktop_overrides, desktop_id, value);
|
|
|
51ad59 |
+ g_variant_unref (value);
|
|
|
51ad59 |
+ }
|
|
|
51ad59 |
+ else
|
|
|
51ad59 |
+ {
|
|
|
51ad59 |
+ g_variant_unref (state->default_value);
|
|
|
51ad59 |
+ state->default_value = value;
|
|
|
51ad59 |
+ }
|
|
|
51ad59 |
+
|
|
|
51ad59 |
g_free (string);
|
|
|
51ad59 |
}
|
|
|
51ad59 |
|
|
|
51ad59 |
+ g_strfreev (pieces);
|
|
|
51ad59 |
g_strfreev (keys);
|
|
|
51ad59 |
}
|
|
|
51ad59 |
|
|
|
51ad59 |
--
|
|
|
51ad59 |
2.21.0
|
|
|
51ad59 |
|
|
|
51ad59 |
|
|
|
51ad59 |
From 2ca9218fb46f32fa02bed43c6e60243c8c5d656f Mon Sep 17 00:00:00 2001
|
|
|
51ad59 |
From: =?UTF-8?q?Alberts=20Muktup=C4=81vels?= <alberts.muktupavels@gmail.com>
|
|
|
51ad59 |
Date: Tue, 19 Jun 2018 23:39:24 +0300
|
|
|
51ad59 |
Subject: [PATCH 4/4] Add a test for per-desktop overrides
|
|
|
51ad59 |
|
|
|
51ad59 |
---
|
|
|
51ad59 |
gio/glib-compile-schemas.c | 1 +
|
|
|
51ad59 |
gio/tests/Makefile.am | 2 +
|
|
|
51ad59 |
gio/tests/gsettings.c | 106 ++++++++++++++++++-
|
|
|
51ad59 |
gio/tests/org.gtk.test.gschema.override.orig | 2 +
|
|
|
51ad59 |
gio/tests/org.gtk.test.gschema.xml.orig | 6 ++
|
|
|
51ad59 |
5 files changed, 116 insertions(+), 1 deletion(-)
|
|
|
51ad59 |
create mode 100644 gio/tests/org.gtk.test.gschema.override.orig
|
|
|
51ad59 |
|
|
|
51ad59 |
diff --git a/gio/glib-compile-schemas.c b/gio/glib-compile-schemas.c
|
|
|
51ad59 |
index 59fb68ee7..00dd64146 100644
|
|
|
51ad59 |
--- a/gio/glib-compile-schemas.c
|
|
|
51ad59 |
+++ b/gio/glib-compile-schemas.c
|
|
|
51ad59 |
@@ -2139,6 +2139,7 @@ main (int argc, char **argv)
|
|
|
51ad59 |
|
|
|
51ad59 |
/* These options are only for use in the gschema-compile tests */
|
|
|
51ad59 |
{ "schema-file", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_FILENAME_ARRAY, &schema_files, NULL, NULL },
|
|
|
51ad59 |
+ { "override-file", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_FILENAME_ARRAY, &override_files, NULL, NULL },
|
|
|
51ad59 |
{ NULL }
|
|
|
51ad59 |
};
|
|
|
51ad59 |
|
|
|
51ad59 |
diff --git a/gio/tests/Makefile.am b/gio/tests/Makefile.am
|
|
|
51ad59 |
index 49a19bf4a..b41317ad9 100644
|
|
|
51ad59 |
--- a/gio/tests/Makefile.am
|
|
|
51ad59 |
+++ b/gio/tests/Makefile.am
|
|
|
51ad59 |
@@ -367,12 +367,14 @@ test.mo: de.po
|
|
|
51ad59 |
EXTRA_DIST += de.po
|
|
|
51ad59 |
dist_uninstalled_test_data += \
|
|
|
51ad59 |
org.gtk.test.gschema.xml.orig \
|
|
|
51ad59 |
+ org.gtk.test.gschema.override.orig \
|
|
|
51ad59 |
org.gtk.schemasourcecheck.gschema.xml \
|
|
|
51ad59 |
testenum.h \
|
|
|
51ad59 |
enums.xml.template
|
|
|
51ad59 |
# Generated while running the testcase itself...
|
|
|
51ad59 |
CLEANFILES += \
|
|
|
51ad59 |
org.gtk.test.gschema.xml \
|
|
|
51ad59 |
+ org.gtk.test.gschema.override \
|
|
|
51ad59 |
org.gtk.test.enums.xml \
|
|
|
51ad59 |
gsettings.store \
|
|
|
51ad59 |
gschemas.compiled \
|
|
|
51ad59 |
diff --git a/gio/tests/gsettings.c b/gio/tests/gsettings.c
|
|
|
51ad59 |
index 2be4122fe..acdeead4c 100644
|
|
|
51ad59 |
--- a/gio/tests/gsettings.c
|
|
|
51ad59 |
+++ b/gio/tests/gsettings.c
|
|
|
51ad59 |
@@ -2192,6 +2192,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS
|
|
|
51ad59 |
"org.gtk.test.range.direct",
|
|
|
51ad59 |
"org.gtk.test.mapped",
|
|
|
51ad59 |
"org.gtk.test.descriptions",
|
|
|
51ad59 |
+ "org.gtk.test.per-desktop",
|
|
|
51ad59 |
NULL));
|
|
|
51ad59 |
}
|
|
|
51ad59 |
|
|
|
51ad59 |
@@ -2583,6 +2584,100 @@ test_default_value (void)
|
|
|
51ad59 |
g_object_unref (settings);
|
|
|
51ad59 |
}
|
|
|
51ad59 |
|
|
|
51ad59 |
+static gboolean
|
|
|
51ad59 |
+string_map_func (GVariant *value,
|
|
|
51ad59 |
+ gpointer *result,
|
|
|
51ad59 |
+ gpointer user_data)
|
|
|
51ad59 |
+{
|
|
|
51ad59 |
+ const gchar *str;
|
|
|
51ad59 |
+
|
|
|
51ad59 |
+ str = g_variant_get_string (value, NULL);
|
|
|
51ad59 |
+ *result = g_variant_new_string (str);
|
|
|
51ad59 |
+
|
|
|
51ad59 |
+ return TRUE;
|
|
|
51ad59 |
+}
|
|
|
51ad59 |
+
|
|
|
51ad59 |
+/* Test that per-desktop values from org.gtk.test.gschema.override
|
|
|
51ad59 |
+ * does not change default value if current desktop is not listed in
|
|
|
51ad59 |
+ * $XDG_CURRENT_DESKTOP.
|
|
|
51ad59 |
+ */
|
|
|
51ad59 |
+static void
|
|
|
51ad59 |
+test_per_desktop (void)
|
|
|
51ad59 |
+{
|
|
|
51ad59 |
+ GSettings *settings;
|
|
|
51ad59 |
+ TestObject *obj;
|
|
|
51ad59 |
+ gpointer p;
|
|
|
51ad59 |
+ gchar *str;
|
|
|
51ad59 |
+
|
|
|
51ad59 |
+ settings = g_settings_new ("org.gtk.test.per-desktop");
|
|
|
51ad59 |
+ obj = test_object_new ();
|
|
|
51ad59 |
+
|
|
|
51ad59 |
+ if (!g_test_subprocess ())
|
|
|
51ad59 |
+ {
|
|
|
51ad59 |
+ g_test_trap_subprocess ("/gsettings/per-desktop/subprocess", 0, 0);
|
|
|
51ad59 |
+ g_test_trap_assert_passed ();
|
|
|
51ad59 |
+ }
|
|
|
51ad59 |
+
|
|
|
51ad59 |
+ str = g_settings_get_string (settings, "desktop");
|
|
|
51ad59 |
+ g_assert_cmpstr (str, ==, "GNOME");
|
|
|
51ad59 |
+ g_free (str);
|
|
|
51ad59 |
+
|
|
|
51ad59 |
+ p = g_settings_get_mapped (settings, "desktop", string_map_func, NULL);
|
|
|
51ad59 |
+
|
|
|
51ad59 |
+ str = g_variant_dup_string (p, NULL);
|
|
|
51ad59 |
+ g_assert_cmpstr (str, ==, "GNOME");
|
|
|
51ad59 |
+ g_free (str);
|
|
|
51ad59 |
+
|
|
|
51ad59 |
+ g_variant_unref (p);
|
|
|
51ad59 |
+
|
|
|
51ad59 |
+ g_settings_bind (settings, "desktop", obj, "string", G_SETTINGS_BIND_DEFAULT);
|
|
|
51ad59 |
+
|
|
|
51ad59 |
+ g_object_get (obj, "string", &str, NULL);
|
|
|
51ad59 |
+ g_assert_cmpstr (str, ==, "GNOME");
|
|
|
51ad59 |
+ g_free (str);
|
|
|
51ad59 |
+
|
|
|
51ad59 |
+ g_object_unref (settings);
|
|
|
51ad59 |
+ g_object_unref (obj);
|
|
|
51ad59 |
+}
|
|
|
51ad59 |
+
|
|
|
51ad59 |
+/* Test that per-desktop values from org.gtk.test.gschema.override
|
|
|
51ad59 |
+ * are successfully loaded based on the value of $XDG_CURRENT_DESKTOP.
|
|
|
51ad59 |
+ */
|
|
|
51ad59 |
+static void
|
|
|
51ad59 |
+test_per_desktop_subprocess (void)
|
|
|
51ad59 |
+{
|
|
|
51ad59 |
+ GSettings *settings;
|
|
|
51ad59 |
+ TestObject *obj;
|
|
|
51ad59 |
+ gpointer p;
|
|
|
51ad59 |
+ gchar *str;
|
|
|
51ad59 |
+
|
|
|
51ad59 |
+ g_setenv ("XDG_CURRENT_DESKTOP", "GNOME-Classic:GNOME", TRUE);
|
|
|
51ad59 |
+
|
|
|
51ad59 |
+ settings = g_settings_new ("org.gtk.test.per-desktop");
|
|
|
51ad59 |
+ obj = test_object_new ();
|
|
|
51ad59 |
+
|
|
|
51ad59 |
+ str = g_settings_get_string (settings, "desktop");
|
|
|
51ad59 |
+ g_assert_cmpstr (str, ==, "GNOME Classic");
|
|
|
51ad59 |
+ g_free (str);
|
|
|
51ad59 |
+
|
|
|
51ad59 |
+ p = g_settings_get_mapped (settings, "desktop", string_map_func, NULL);
|
|
|
51ad59 |
+
|
|
|
51ad59 |
+ str = g_variant_dup_string (p, NULL);
|
|
|
51ad59 |
+ g_assert_cmpstr (str, ==, "GNOME Classic");
|
|
|
51ad59 |
+ g_free (str);
|
|
|
51ad59 |
+
|
|
|
51ad59 |
+ g_variant_unref (p);
|
|
|
51ad59 |
+
|
|
|
51ad59 |
+ g_settings_bind (settings, "desktop", obj, "string", G_SETTINGS_BIND_DEFAULT);
|
|
|
51ad59 |
+
|
|
|
51ad59 |
+ g_object_get (obj, "string", &str, NULL);
|
|
|
51ad59 |
+ g_assert_cmpstr (str, ==, "GNOME Classic");
|
|
|
51ad59 |
+ g_free (str);
|
|
|
51ad59 |
+
|
|
|
51ad59 |
+ g_object_unref (settings);
|
|
|
51ad59 |
+ g_object_unref (obj);
|
|
|
51ad59 |
+}
|
|
|
51ad59 |
+
|
|
|
51ad59 |
static void
|
|
|
51ad59 |
test_extended_schema (void)
|
|
|
51ad59 |
{
|
|
|
51ad59 |
@@ -2603,6 +2698,7 @@ int
|
|
|
51ad59 |
main (int argc, char *argv[])
|
|
|
51ad59 |
{
|
|
|
51ad59 |
gchar *schema_text;
|
|
|
51ad59 |
+ gchar *override_text;
|
|
|
51ad59 |
gchar *enums;
|
|
|
51ad59 |
gint result;
|
|
|
51ad59 |
|
|
|
51ad59 |
@@ -2625,6 +2721,7 @@ main (int argc, char *argv[])
|
|
|
51ad59 |
g_setenv ("XDG_DATA_DIRS", ".", TRUE);
|
|
|
51ad59 |
g_setenv ("XDG_DATA_HOME", ".", TRUE);
|
|
|
51ad59 |
g_setenv ("GSETTINGS_SCHEMA_DIR", ".", TRUE);
|
|
|
51ad59 |
+ g_setenv ("XDG_CURRENT_DESKTOP", "", TRUE);
|
|
|
51ad59 |
|
|
|
51ad59 |
if (!backend_set)
|
|
|
51ad59 |
g_setenv ("GSETTINGS_BACKEND", "memory", TRUE);
|
|
|
51ad59 |
@@ -2647,6 +2744,10 @@ main (int argc, char *argv[])
|
|
|
51ad59 |
g_assert (g_file_set_contents ("org.gtk.test.gschema.xml", schema_text, -1, NULL));
|
|
|
51ad59 |
g_free (schema_text);
|
|
|
51ad59 |
|
|
|
51ad59 |
+ g_assert (g_file_get_contents (SRCDIR "/org.gtk.test.gschema.override.orig", &override_text, NULL, NULL));
|
|
|
51ad59 |
+ g_assert (g_file_set_contents ("org.gtk.test.gschema.override", override_text, -1, NULL));
|
|
|
51ad59 |
+ g_free (override_text);
|
|
|
51ad59 |
+
|
|
|
51ad59 |
/* Meson build defines this, autotools build does not */
|
|
|
51ad59 |
#ifndef GLIB_COMPILE_SCHEMAS
|
|
|
51ad59 |
#define GLIB_COMPILE_SCHEMAS "../glib-compile-schemas"
|
|
|
51ad59 |
@@ -2655,7 +2756,8 @@ main (int argc, char *argv[])
|
|
|
51ad59 |
g_remove ("gschemas.compiled");
|
|
|
51ad59 |
g_assert (g_spawn_command_line_sync (GLIB_COMPILE_SCHEMAS " --targetdir=. "
|
|
|
51ad59 |
"--schema-file=org.gtk.test.enums.xml "
|
|
|
51ad59 |
- "--schema-file=org.gtk.test.gschema.xml",
|
|
|
51ad59 |
+ "--schema-file=org.gtk.test.gschema.xml "
|
|
|
51ad59 |
+ "--override-file=org.gtk.test.gschema.override",
|
|
|
51ad59 |
NULL, NULL, &result, NULL));
|
|
|
51ad59 |
g_assert (result == 0);
|
|
|
51ad59 |
|
|
|
51ad59 |
@@ -2736,6 +2838,8 @@ main (int argc, char *argv[])
|
|
|
51ad59 |
g_test_add_func ("/gsettings/read-descriptions", test_read_descriptions);
|
|
|
51ad59 |
g_test_add_func ("/gsettings/test-extended-schema", test_extended_schema);
|
|
|
51ad59 |
g_test_add_func ("/gsettings/default-value", test_default_value);
|
|
|
51ad59 |
+ g_test_add_func ("/gsettings/per-desktop", test_per_desktop);
|
|
|
51ad59 |
+ g_test_add_func ("/gsettings/per-desktop/subprocess", test_per_desktop_subprocess);
|
|
|
51ad59 |
|
|
|
51ad59 |
result = g_test_run ();
|
|
|
51ad59 |
|
|
|
51ad59 |
diff --git a/gio/tests/org.gtk.test.gschema.override.orig b/gio/tests/org.gtk.test.gschema.override.orig
|
|
|
51ad59 |
new file mode 100644
|
|
|
51ad59 |
index 000000000..6694baace
|
|
|
51ad59 |
--- /dev/null
|
|
|
51ad59 |
+++ b/gio/tests/org.gtk.test.gschema.override.orig
|
|
|
51ad59 |
@@ -0,0 +1,2 @@
|
|
|
51ad59 |
+[org.gtk.test.per-desktop:GNOME-Classic]
|
|
|
51ad59 |
+desktop = "GNOME Classic"
|
|
|
51ad59 |
diff --git a/gio/tests/org.gtk.test.gschema.xml.orig b/gio/tests/org.gtk.test.gschema.xml.orig
|
|
|
51ad59 |
index c07558335..fbcdce683 100644
|
|
|
51ad59 |
--- a/gio/tests/org.gtk.test.gschema.xml.orig
|
|
|
51ad59 |
+++ b/gio/tests/org.gtk.test.gschema.xml.orig
|
|
|
51ad59 |
@@ -209,4 +209,10 @@
|
|
|
51ad59 |
</key>
|
|
|
51ad59 |
</schema>
|
|
|
51ad59 |
|
|
|
51ad59 |
+ <schema id="org.gtk.test.per-desktop" path="/tests/per-desktop/">
|
|
|
51ad59 |
+ <key name="desktop" type="s">
|
|
|
51ad59 |
+ <default>"GNOME"</default>
|
|
|
51ad59 |
+ </key>
|
|
|
51ad59 |
+ </schema>
|
|
|
51ad59 |
+
|
|
|
51ad59 |
</schemalist>
|
|
|
51ad59 |
--
|
|
|
51ad59 |
2.21.0
|
|
|
51ad59 |
|