[gnome-control-center] keyboard: make sure to retrieve the correct type from variants
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] keyboard: make sure to retrieve the correct type from variants
- Date: Fri, 29 Jul 2016 17:33:09 +0000 (UTC)
commit 00f1b53abb2e7a80fdf37cbfb66a8c033747f4d4
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Fri Jul 29 14:23:27 2016 -0300
keyboard: make sure to retrieve the correct type from variants
When comparing the keyboard shortcut's default and current
values, we double-check what kind of variant the default
value is, but don't check that for the user value.
This ends up throwing lots of variant-related warnings, as
the user value may not be a plain string.
Fix that by checking the variant types both for the user and
the default value of the shortcut's settings.
https://bugzilla.gnome.org/show_bug.cgi?id=769310
panels/keyboard/cc-keyboard-item.c | 23 +++++++++++++++--------
1 files changed, 15 insertions(+), 8 deletions(-)
---
diff --git a/panels/keyboard/cc-keyboard-item.c b/panels/keyboard/cc-keyboard-item.c
index a70eb3e..619474c 100644
--- a/panels/keyboard/cc-keyboard-item.c
+++ b/panels/keyboard/cc-keyboard-item.c
@@ -60,6 +60,17 @@ static void cc_keyboard_item_finalize (GObject *object);
G_DEFINE_TYPE (CcKeyboardItem, cc_keyboard_item, G_TYPE_OBJECT)
+static const gchar *
+get_binding_from_variant (GVariant *variant)
+{
+ if (g_variant_is_of_type (variant, G_VARIANT_TYPE_STRING))
+ return g_variant_get_string (variant, NULL);
+ else if (g_variant_is_of_type (variant, G_VARIANT_TYPE_STRING_ARRAY))
+ return g_variant_get_strv (variant, NULL)[0];
+ else
+ return "";
+}
+
static gboolean
binding_from_string (const char *str,
guint *accelerator_key,
@@ -574,18 +585,14 @@ cc_keyboard_item_is_value_default (CcKeyboardItem *self)
if (user_value)
{
GVariant *default_value;
- const gchar *default_binding;
+ const gchar *default_binding, *user_binding;
default_value = g_settings_get_default_value (self->settings, self->key);
- if (g_variant_is_of_type (default_value, G_VARIANT_TYPE_STRING))
- default_binding = g_variant_get_string (default_value, NULL);
- else if (g_variant_is_of_type (default_value, G_VARIANT_TYPE_STRING_ARRAY))
- default_binding = g_variant_get_strv (default_value, NULL)[0];
- else
- default_binding = "";
+ default_binding = get_binding_from_variant (default_value);
+ user_binding = get_binding_from_variant (user_value);
- is_value_default = (g_strcmp0 (default_binding, g_variant_get_string (user_value, NULL)) == 0);
+ is_value_default = (g_strcmp0 (default_binding, user_binding) == 0);
g_clear_pointer (&default_value, g_variant_unref);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]