diff options
author | Ray Strode <rstrode@redhat.com> | 2012-03-21 16:52:57 -0400 |
---|---|---|
committer | Sergey V. Udaltsov <svu@gnome.org> | 2012-03-23 09:49:01 +0000 |
commit | c9d3c0e939c21230d6088aaf915d9b7d965d97d8 (patch) | |
tree | 4c503f1ffc4b3a8874bf60edb3652d54586980c6 /libgnomekbd | |
parent | a6ca20e027edf43df578c7cf1aa26eecb6512540 (diff) | |
download | libgnomekbd-c9d3c0e939c21230d6088aaf915d9b7d965d97d8.tar.gz |
config: make gkbd_keyboard_config_equals more forgiving
options should be able to appear in different orders,
or have different group names and still appear as equal.
This commit makes gkbd_keyboard_config_equals more
forgiving.
https://bugzilla.gnome.org/show_bug.cgi?id=670164
Diffstat (limited to 'libgnomekbd')
-rw-r--r-- | libgnomekbd/gkbd-keyboard-config.c | 59 |
1 files changed, 56 insertions, 3 deletions
diff --git a/libgnomekbd/gkbd-keyboard-config.c b/libgnomekbd/gkbd-keyboard-config.c index 397df24..5df372d 100644 --- a/libgnomekbd/gkbd-keyboard-config.c +++ b/libgnomekbd/gkbd-keyboard-config.c @@ -500,6 +500,54 @@ gkbd_keyboard_config_load_from_x_initial (GkbdKeyboardConfig * kbd_config, g_object_unref (G_OBJECT (data)); } +static gboolean +gkbd_keyboard_config_options_equals (GkbdKeyboardConfig * kbd_config1, + GkbdKeyboardConfig * kbd_config2) +{ + int num_options, num_options2; + + num_options = + (kbd_config1->options == + NULL) ? 0 : g_strv_length (kbd_config1->options); + num_options2 = + (kbd_config2->options == + NULL) ? 0 : g_strv_length (kbd_config2->options); + + if (num_options != num_options2) + return False; + + if (num_options != 0) { + int i; + char *group1, *option1; + + for (i = 0; i < num_options; i++) { + int j; + char *group2, *option2; + gboolean are_equal = FALSE; + + if (!gkbd_keyboard_config_split_items (kbd_config1->options[i], &group1, &option1)) + continue; + + g_free (group1); + + for (j = 0; j < num_options && !are_equal; j++) { + if (gkbd_keyboard_config_split_items (kbd_config2->options[j], &group2, &option2)) { + are_equal = strcmp (option1, option2) == 0; + g_free (group2); + g_free (option2); + } + } + + g_free (option1); + + if (!are_equal) + return False; + } + } + + return True; +} + gboolean gkbd_keyboard_config_equals (GkbdKeyboardConfig * kbd_config1, GkbdKeyboardConfig * kbd_config2) @@ -511,9 +559,14 @@ gkbd_keyboard_config_equals (GkbdKeyboardConfig * kbd_config1, (kbd_config2->model != NULL) && g_ascii_strcasecmp (kbd_config1->model, kbd_config2->model)) return False; - return g_strv_equal (kbd_config1->layouts_variants, - kbd_config2->layouts_variants) - && g_strv_equal (kbd_config1->options, kbd_config2->options); + if (!g_strv_equal (kbd_config1->layouts_variants, + kbd_config2->layouts_variants)) + return False; + + if (!gkbd_keyboard_config_options_equals (kbd_config1, kbd_config2)) + return False; + + return True; } void |