diff options
author | Rui Matos <tiagomatos@gmail.com> | 2013-01-21 17:31:34 +0100 |
---|---|---|
committer | Rui Matos <tiagomatos@gmail.com> | 2013-03-16 17:35:15 +0100 |
commit | 6c9ae8128e7cc7f09f0c86dd0596430a07618453 (patch) | |
tree | 00ffc4c80e6a2595ac2c1865c613f0c47eb7b373 | |
parent | 42e9bd70b7b8919cd9cefbafc0eac8bb38f84c5e (diff) | |
download | gnome-desktop-6c9ae8128e7cc7f09f0c86dd0596430a07618453.tar.gz |
gnome-xkb-info: Handle duplicated layouts
When merging entries from another .xml file (i.e. when
show-all-sources is active) there might be layout entries which were
already added before. In that case we don't want to create new entries
and replace the old ones because layout variants which were already
added depend on the existence of the old main layout.
https://bugzilla.gnome.org/show_bug.cgi?id=692219
https://bugzilla.gnome.org/show_bug.cgi?id=694149
-rw-r--r-- | libgnome-desktop/gnome-xkb-info.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/libgnome-desktop/gnome-xkb-info.c b/libgnome-desktop/gnome-xkb-info.c index b86b6161..28dc3de3 100644 --- a/libgnome-desktop/gnome-xkb-info.c +++ b/libgnome-desktop/gnome-xkb-info.c @@ -281,6 +281,8 @@ parse_start_element (GMarkupParseContext *context, } else if (strcmp (element_name, "variant") == 0) { + Layout *layout; + if (priv->current_parser_variant) { g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, @@ -295,9 +297,20 @@ parse_start_element (GMarkupParseContext *context, return; } + if (!priv->current_parser_layout->xkb_name) + { + g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, + "'variant' elements must be inside named 'layout' elements"); + return; + } + + layout = g_hash_table_lookup (priv->layouts_table, priv->current_parser_layout->xkb_name); + if (!layout) + layout = priv->current_parser_layout; + priv->current_parser_variant = g_slice_new0 (Layout); priv->current_parser_variant->is_variant = TRUE; - priv->current_parser_variant->main_layout = priv->current_parser_layout; + priv->current_parser_variant->main_layout = layout; } else if (strcmp (element_name, "group") == 0) { @@ -381,6 +394,12 @@ parse_end_element (GMarkupParseContext *context, priv->current_parser_layout->id = g_strdup (priv->current_parser_layout->xkb_name); + if (g_hash_table_contains (priv->layouts_table, priv->current_parser_layout->id)) + { + g_clear_pointer (&priv->current_parser_layout, free_layout); + return; + } + if (priv->current_parser_layout->short_desc) maybe_replace (priv->layouts_by_short_desc, priv->current_parser_layout->short_desc, priv->current_parser_layout); |