[Xfce4-commits] <garcon:master> Add workaround to fix empty <DefaultLayout> elements (bug #6882).

Jannis Pohlmann noreply at xfce.org
Sat Dec 4 15:02:02 CET 2010


Updating branch refs/heads/master
         to b66e39c727817d6ce6cc4de89d3caeee643008fc (commit)
       from b8d44bd58d20ec2c16dc9620db3cb9e8776c6bc8 (commit)

commit b66e39c727817d6ce6cc4de89d3caeee643008fc
Author: Jannis Pohlmann <jannis at xfce.org>
Date:   Sat Dec 4 15:00:18 2010 +0100

    Add workaround to fix empty <DefaultLayout> elements (bug #6882).
    
    For more information see my comment on the bug on
    
      http://bugzilla.xfce.org/show_bug.cgi?id=6882#c2

 NEWS                        |    1 +
 garcon/garcon-menu-merger.c |   33 +++++++++++++++++++++++++----
 tests/test-menu-parser.c    |   48 +++++++++++++++++++-----------------------
 3 files changed, 51 insertions(+), 31 deletions(-)

diff --git a/NEWS b/NEWS
index 38b9d37..8a636f7 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@
 - Add support for XDG_MENU_PREFIX; use applications.menu as a fallback
   (bug #5980).
 - Explicitly link against gobject, add other missing libs (bug #6405).
+- Add workaround to fix empty <DefaultLayout> elements (bug #6882).
 
 
 0.1.3
diff --git a/garcon/garcon-menu-merger.c b/garcon/garcon-menu-merger.c
index 81dfb8c..07bc8b0 100644
--- a/garcon/garcon-menu-merger.c
+++ b/garcon/garcon-menu-merger.c
@@ -332,6 +332,7 @@ garcon_menu_merger_run (GarconMenuMerger *merger,
   garcon_menu_merger_clean_up_elements (merger->priv->menu, GARCON_MENU_NODE_TYPE_ONLY_UNALLOCATED);
 
   garcon_menu_merger_prepend_default_layout (merger->priv->menu);
+  garcon_menu_merger_clean_up_elements (merger->priv->menu, GARCON_MENU_NODE_TYPE_DEFAULT_LAYOUT);
   garcon_menu_merger_clean_up_elements (merger->priv->menu, GARCON_MENU_NODE_TYPE_LAYOUT);
 
   g_list_foreach (context.file_stack, (GFunc) g_object_unref, NULL);
@@ -910,9 +911,10 @@ static void
 garcon_menu_merger_clean_up_elements (GNode             *node,
                                       GarconMenuNodeType type)
 {
-  GNode *child;
-  GNode *remaining_node = NULL;
-  GList *destroy_list = NULL;
+  GarconMenuNode *node_;
+  GNode          *child;
+  GNode          *remaining_node = NULL;
+  GList          *destroy_list = NULL;
 
   for (child = g_node_last_child (node); child != NULL; child = g_node_prev_sibling (child))
     {
@@ -937,7 +939,13 @@ garcon_menu_merger_clean_up_elements (GNode             *node,
         }
 
       if (type == GARCON_MENU_NODE_TYPE_LAYOUT
-          && garcon_menu_node_tree_get_node_type (child) != GARCON_MENU_NODE_TYPE_LAYOUT)
+          && garcon_menu_node_tree_get_node_type (child) != type)
+        {
+          continue;
+        }
+
+      if (type == GARCON_MENU_NODE_TYPE_DEFAULT_LAYOUT
+          && garcon_menu_node_tree_get_node_type (child) != type)
         {
           continue;
         }
@@ -951,12 +959,27 @@ garcon_menu_merger_clean_up_elements (GNode             *node,
   g_list_foreach (destroy_list, (GFunc) garcon_menu_node_tree_free, NULL);
   g_list_free (destroy_list);
 
-  if (type == GARCON_MENU_NODE_TYPE_LAYOUT
+  if (type == GARCON_MENU_NODE_TYPE_LAYOUT 
       && remaining_node != NULL
       && G_NODE_IS_LEAF (remaining_node))
     {
       garcon_menu_node_tree_free (remaining_node);
     }
+
+  if (type == GARCON_MENU_NODE_TYPE_DEFAULT_LAYOUT
+      && remaining_node != NULL
+      && G_NODE_IS_LEAF (remaining_node))
+    {
+      /* FIXME Fix empty <DefaultLayout> elements created due to a bug in
+       * alacarte. See http://bugzilla.xfce.org/show_bug.cgi?id=6882#c2
+       * for more information */
+      node_ = garcon_menu_node_create (GARCON_MENU_NODE_TYPE_MERGE, 
+                                       GUINT_TO_POINTER (GARCON_MENU_LAYOUT_MERGE_MENUS));
+      g_node_append_data (remaining_node, node_);
+      node_ = garcon_menu_node_create (GARCON_MENU_NODE_TYPE_MERGE, 
+                                       GUINT_TO_POINTER (GARCON_MENU_LAYOUT_MERGE_FILES));
+      g_node_append_data (remaining_node, node_);
+    }
 }
 
 
diff --git a/tests/test-menu-parser.c b/tests/test-menu-parser.c
index 792dc4b..ee4da65 100644
--- a/tests/test-menu-parser.c
+++ b/tests/test-menu-parser.c
@@ -53,6 +53,7 @@ node_name (GNode *node)
       case GARCON_MENU_NODE_TYPE_AND: return "And"; break;
       case GARCON_MENU_NODE_TYPE_NOT: return "Not"; break;
       case GARCON_MENU_NODE_TYPE_MOVE: return "Move"; break;
+      case GARCON_MENU_NODE_TYPE_DEFAULT_LAYOUT: return "DefaultLayout"; break;
       case GARCON_MENU_NODE_TYPE_LAYOUT: return "Layout"; break;
       default: return NULL; break;
     }
@@ -83,14 +84,15 @@ print_node (GNode *node,
 
 #define INDENT {for (i = 0; i < depth; ++i) g_print (" ");}
 
-  if (G_UNLIKELY (garcon_menu_node_tree_get_node_type (node) == GARCON_MENU_NODE_TYPE_MENU ||
-                  garcon_menu_node_tree_get_node_type (node) == GARCON_MENU_NODE_TYPE_INCLUDE ||
-                  garcon_menu_node_tree_get_node_type (node) == GARCON_MENU_NODE_TYPE_EXCLUDE ||
-                  garcon_menu_node_tree_get_node_type (node) == GARCON_MENU_NODE_TYPE_OR ||
-                  garcon_menu_node_tree_get_node_type (node) == GARCON_MENU_NODE_TYPE_AND ||
-                  garcon_menu_node_tree_get_node_type (node) == GARCON_MENU_NODE_TYPE_NOT ||
-                  garcon_menu_node_tree_get_node_type (node) == GARCON_MENU_NODE_TYPE_MOVE ||
-                  garcon_menu_node_tree_get_node_type (node) == GARCON_MENU_NODE_TYPE_LAYOUT))
+  if (garcon_menu_node_tree_get_node_type (node) == GARCON_MENU_NODE_TYPE_MENU ||
+      garcon_menu_node_tree_get_node_type (node) == GARCON_MENU_NODE_TYPE_INCLUDE ||
+      garcon_menu_node_tree_get_node_type (node) == GARCON_MENU_NODE_TYPE_EXCLUDE ||
+      garcon_menu_node_tree_get_node_type (node) == GARCON_MENU_NODE_TYPE_OR ||
+      garcon_menu_node_tree_get_node_type (node) == GARCON_MENU_NODE_TYPE_AND ||
+      garcon_menu_node_tree_get_node_type (node) == GARCON_MENU_NODE_TYPE_NOT ||
+      garcon_menu_node_tree_get_node_type (node) == GARCON_MENU_NODE_TYPE_MOVE ||
+      garcon_menu_node_tree_get_node_type (node) == GARCON_MENU_NODE_TYPE_DEFAULT_LAYOUT ||
+      garcon_menu_node_tree_get_node_type (node) == GARCON_MENU_NODE_TYPE_LAYOUT)
     {
       INDENT; g_print ("<%s>\n", node_name (node));
       print_child_nodes (node, depth);
@@ -206,27 +208,18 @@ print_tree (GarconMenuTreeProvider *provider)
 
 
 
-static const gchar ROOT_SPECS[][30] =
-{
-  "menus/applications.menu",
-  "menus/xfce-applications.menu",
-  "menus/gnome-applications.menu",
-  "menus/kde-applications.menu",
-};
-
-
-
 int
 main (int    argc,
       char **argv)
 {
   GarconMenuParser *parser;
   GarconMenuMerger *merger;
+  const gchar      *prefix;
   GError           *error = NULL;
   GFile            *file = NULL;
   gchar            *filename;
+  gchar            *relative_filename;
   gint              result = EXIT_SUCCESS;
-  gint              n;
 
   g_type_init ();
 
@@ -239,14 +232,15 @@ main (int    argc,
     file = g_file_new_for_path (argv[1]);
   else
     {
-      /* Search for a usable root menu file */
-      for (n = 0; n < G_N_ELEMENTS (ROOT_SPECS) && file == NULL; ++n)
+      prefix = g_getenv ("XDG_MENU_PREFIX");
+      relative_filename = g_strconcat ("menus", G_DIR_SEPARATOR_S,
+                                       prefix != NULL ? prefix : "", "applications.menu",
+                                       NULL);
+
+      /* Search for the menu file */
+      filename = garcon_config_lookup (relative_filename);
+      if (G_UNLIKELY (filename != NULL))
         {
-          /* Search for the root menu file */
-          filename = garcon_config_lookup (ROOT_SPECS[n]);
-          if (G_UNLIKELY (filename == NULL))
-            continue;
-
           /* Try to load the root menu from this file */
           file = g_file_new_for_path (filename);
           g_free (filename);
@@ -257,6 +251,8 @@ main (int    argc,
               file = NULL;
             }
         }
+
+      g_free (relative_filename);
     }
 
   parser = garcon_menu_parser_new (file);



More information about the Xfce4-commits mailing list