gnome-menus r899 - in trunk: . libmenu



Author: vuntz
Date: Mon May 19 00:26:27 2008
New Revision: 899
URL: http://svn.gnome.org/viewvc/gnome-menus?rev=899&view=rev

Log:
2008-05-19  Vincent Untz  <vuntz gnome org>

	Complete XDG_MENU_PREFIX support: <MergeFile type="parent"> wasn't
	working with it.

	* libmenu/gmenu-tree.c: (load_parent_merge_file_from_basename): new
	from code from load_parent_merge_file, with an extra comment :-)
	(load_parent_merge_file): if the menu file is applications.menu, handle
	XDG_MENU_PREFIX so that we load the right parent file.


Modified:
   trunk/ChangeLog
   trunk/libmenu/gmenu-tree.c

Modified: trunk/libmenu/gmenu-tree.c
==============================================================================
--- trunk/libmenu/gmenu-tree.c	(original)
+++ trunk/libmenu/gmenu-tree.c	Mon May 19 00:26:27 2008
@@ -1786,34 +1786,18 @@
 }
 
 static gboolean
-load_parent_merge_file (GMenuTree      *tree,
-			GHashTable     *loaded_menu_files,
-			MenuLayoutNode *layout)
+load_parent_merge_file_from_basename (GMenuTree      *tree,
+                                      GHashTable     *loaded_menu_files,
+			              MenuLayoutNode *layout,
+                                      const char     *menu_file,
+                                      const char     *canonical_basedir)
 {
-  MenuLayoutNode     *root;
-  const char         *basedir;
-  const char         *menu_name;
-  char               *canonical_basedir;
-  char               *menu_file;
   gboolean            found_basedir;
   const char * const *system_config_dirs;
   int                 i;
 
-  root = menu_layout_node_get_root (layout);
-
-  basedir   = menu_layout_node_root_get_basedir (root);
-  menu_name = menu_layout_node_root_get_name (root);
-
-  canonical_basedir = menu_canonicalize_file_name (basedir, FALSE);
-  if (canonical_basedir == NULL)
-    {
-      menu_verbose ("Menu basedir '%s' no longer exists, not merging parent\n",
-		    basedir);
-      return FALSE;
-    }
-
-  menu_file = g_strconcat (menu_name, ".menu", NULL);
-
+  /* We're not interested in menu files that are in directories which are not a
+   * parent of the base directory of this menu file */
   found_basedir = compare_basedir_to_config_dir (canonical_basedir,
 						 g_get_user_config_dir ());
 
@@ -1829,6 +1813,9 @@
 	}
       else
 	{
+	  g_print ("Looking for parent menu file '%s' in '%s'\n",
+			menu_file, system_config_dirs[i]);
+
 	  menu_verbose ("Looking for parent menu file '%s' in '%s'\n",
 			menu_file, system_config_dirs[i]);
 
@@ -1845,10 +1832,60 @@
       ++i;
     }
 
+  return system_config_dirs[i] != NULL;
+}
+
+static gboolean
+load_parent_merge_file (GMenuTree      *tree,
+			GHashTable     *loaded_menu_files,
+			MenuLayoutNode *layout)
+{
+  MenuLayoutNode     *root;
+  const char         *basedir;
+  const char         *menu_name;
+  char               *canonical_basedir;
+  char               *menu_file;
+  gboolean            found;
+
+  root = menu_layout_node_get_root (layout);
+
+  basedir   = menu_layout_node_root_get_basedir (root);
+  menu_name = menu_layout_node_root_get_name (root);
+
+  canonical_basedir = menu_canonicalize_file_name (basedir, FALSE);
+  if (canonical_basedir == NULL)
+    {
+      menu_verbose ("Menu basedir '%s' no longer exists, not merging parent\n",
+		    basedir);
+      return FALSE;
+    }
+
+  menu_file = g_strconcat (menu_name, ".menu", NULL);
+
+  if (strcmp (menu_file, "applications.menu") == 0 &&
+      g_getenv ("XDG_MENU_PREFIX"))
+    {
+      char *prefixed_basename;
+      prefixed_basename = g_strdup_printf ("%s%s",
+                                           g_getenv ("XDG_MENU_PREFIX"),
+                                           tree->basename);
+      found = load_parent_merge_file_from_basename (tree, loaded_menu_files,
+                                                    layout, prefixed_basename,
+                                                    canonical_basedir);
+      g_free (prefixed_basename);
+    }
+
+  if (!found)
+    {
+      found = load_parent_merge_file_from_basename (tree, loaded_menu_files,
+                                                    layout, menu_file,
+                                                    canonical_basedir);
+    }
+
   g_free (menu_file);
   g_free (canonical_basedir);
 
-  return system_config_dirs[i] != NULL;
+  return found;
 }
 
 static void



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