[gnome-desktop/gnome-3-6] gnome-xkb-info: Handle duplicated layouts



commit 6c9ae8128e7cc7f09f0c86dd0596430a07618453
Author: Rui Matos <tiagomatos gmail com>
Date:   Mon Jan 21 17:31:34 2013 +0100

    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

 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 b86b616..28dc3de 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);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]