Commit 00f1b53a authored by Georges Basile Stavracas Neto's avatar Georges Basile Stavracas Neto Committed by Bastien Nocera
Browse files

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
parent 3aa7cf69
......@@ -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);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment