Patch : XDG menu-spec 0.8 support for desktop-file-utils



Hi all, 

I've worked on fixing desktop-file-utils and its gnome-vfs module to get
it compliant with XDG menu spec 0.8.

So far, desktop-file-utils passes the menu-spec test suite (I think some
tests will need to be added because I'm sure some special cases are not
handled by desktop-file-utils..) and gnome-vfs module allows gnome-panel
and nautilus to access XDG menus.

However, gnome-vfs module doesn't support the optional part of the spec
(Layout/DefaultLayout) and after some discussions with Mark McLoughlin
(gnome-panel maintainer), I'm not sure how to integrate this support in
the clean way, between VFS module, gnome-panel and nautilus (for editing
menu).

Morever, since my patches is fairly large and I'm not 100% confident
with my patch, I won't push this code for XDG menu support in GNOME for
MandrakeLinux 10.0 (which should have been used as testbed, since we
will also have KDE with XDG menu support).

So, I was hoping to get a review of this patch, to get in committed in
desktop-file-utils (Havoc, I don't know if you granted me write access
on CVS ?) so it is not lost and start serious discussion to get it right
and working as soon as GNOME 2.7 will open.

-- 
Frederic Crozat <fcrozat mandrakesoft com>
Mandrakesoft
? .menu-entries.c.swp
? .menu-parser.c.swp
? .menu-process.c.swp
? fix-before-clean.patch
? validate-menu-spec.patch
? xdg-0.8.patch
Index: Makefile.am
===================================================================
RCS file: /cvs/menus/desktop-file-utils/src/Makefile.am,v
retrieving revision 1.15
diff -u -r1.15 Makefile.am
--- Makefile.am	31 May 2003 17:51:57 -0000	1.15
+++ Makefile.am	9 Jan 2004 16:52:33 -0000
@@ -72,6 +72,7 @@
 	vfolder-query.h
 
 dfu_test_SOURCES=				\
+	dfu-test.h				\
 	dfu-test.c
 
 desktop_file_validate_LDADD=$(DESKTOP_FILE_UTILS_LIBS)
@@ -80,6 +81,7 @@
 dfu_test_LDADD=$(DESKTOP_FILE_UTILS_LIBS) libmenu_sources.la
 
 EXTRA_DIST =			\
+	$(dfu_test_SOURCES)	\
 	menu-modules.conf
 
 if HAVE_GNOME_VFS
Index: gen-compat-tree.c
===================================================================
RCS file: /cvs/menus/desktop-file-utils/src/gen-compat-tree.c,v
retrieving revision 1.13
diff -u -r1.13 gen-compat-tree.c
--- gen-compat-tree.c	17 Oct 2003 03:39:27 -0000	1.13
+++ gen-compat-tree.c	9 Jan 2004 16:52:34 -0000
@@ -16,6 +16,7 @@
 #include "vfolder-query.h"
 #include "menu-process.h"
 #include "menu-tree-cache.h"
+#include "menu-util.h"
 
 #include <libintl.h>
 #include <stdlib.h>
@@ -266,9 +267,20 @@
       ++i;
     }
 
-  if (i == 0)
-    {
-      g_printerr (_("Must specify one menu file to parse\n"));
+  if (i == 0) 
+    { 
+	    if ( do_print_test_results) {
+		    XdgPathInfo xdg;
+		    char * menufile;
+
+		    init_xdg_paths (&xdg);
+		    menufile = g_build_filename (xdg.first_system_config,
+                                           "menus", "applications.menu", NULL);
+		    process_one_file (menufile);
+		    g_free (menufile);
+	    } else {
+	      g_printerr (_("Must specify one menu file to parse\n"));
+	    }
 
       return 1;
     }
Index: menu-entries.c
===================================================================
RCS file: /cvs/menus/desktop-file-utils/src/menu-entries.c,v
retrieving revision 1.16
diff -u -r1.16 menu-entries.c
--- menu-entries.c	6 Jun 2003 16:22:55 -0000	1.16
+++ menu-entries.c	9 Jan 2004 16:52:34 -0000
@@ -66,6 +66,7 @@
 
 static CachedDir*  cached_dir_load          (EntryCache  *cache,
                                              const char  *canonical_path,
+                                             gboolean	  is_legacy,
                                              GError     **err);
 static void        cached_dir_mark_used     (CachedDir   *dir);
 static void        cached_dir_mark_unused   (CachedDir   *dir);
@@ -76,6 +77,7 @@
                                              const char  *name);
 static int         cached_dir_count_entries (CachedDir   *dir);
 static EntryCache* cached_dir_get_cache     (CachedDir   *dir);
+static gboolean    cached_dir_is_legacy     (CachedDir   *dir);
 
 static Entry*
 entry_new (EntryType   type,
@@ -148,7 +150,7 @@
     return entry->relative_path;
 }
 
-static gboolean
+gboolean
 entry_has_category (Entry      *entry,
                     EntryCache *cache,
                     const char *category)
@@ -264,7 +266,7 @@
 
   basename = g_path_get_dirname (path);
   
-  dir = cached_dir_load (cache, dirname, NULL);
+  dir = cached_dir_load (cache, dirname, 0, NULL);
 
   if (dir != NULL)
     retval = cached_dir_find_entry (dir, basename);
@@ -301,7 +303,7 @@
       return NULL;
     }
 
-  cd = cached_dir_load (cache, canonical, err);
+  cd = cached_dir_load (cache, canonical, flags & ENTRY_LOAD_LEGACY, err);
   if (cd == NULL)
     {
       g_free (canonical);
@@ -376,7 +378,7 @@
     }
 
   n_categories_total = n_categories_to_copy;
-  if (ed->flags & ENTRY_LOAD_LEGACY)
+  if (ed->flags & ENTRY_LOAD_LEGACY && n_categories_total > 0)
     n_categories_total += 1;
   
   if (n_categories_total > 0)
@@ -472,6 +474,7 @@
   while (tmp != NULL)
     {
       Entry *src;
+      char *path;
 
       src = tmp->data;
 
@@ -486,7 +489,13 @@
       strcpy (child_path_start,
               src->relative_path);
 
-      if (!(* func) (ed, src, parent_path,
+      if (cached_dir_is_legacy(cd)) {	      
+         path = child_path_start;
+      } else {
+         path = parent_path;
+      }
+
+      if (!(* func) (ed, src, path,
                      data1, data2))
         return FALSE;
 
@@ -1200,6 +1209,7 @@
   GSList *subdirs;
   guint have_read_entries : 1;
   guint use_count : 27;
+  guint is_legacy : 1;
 };
 
 struct EntryCache
@@ -1229,6 +1239,7 @@
 
   dir->cache = cache;
   dir->name = g_strdup (name);
+  dir->is_legacy = 0;
 
   menu_verbose ("New cached dir \"%s\"\n", name);
   
@@ -1289,6 +1300,11 @@
   g_free (dir);
 }
 
+static gboolean
+cached_dir_is_legacy (CachedDir *cd) {
+  return cd->is_legacy;
+}
+
 static void
 ensure_root_dir (EntryCache *cache)
 {
@@ -1443,6 +1459,7 @@
 static CachedDir*
 cached_dir_load (EntryCache *cache,
                  const char *canonical_path,
+                 gboolean    is_legacy,
                  GError    **err)
 {
   CachedDir *retval;
@@ -1455,6 +1472,8 @@
                               canonical_path);
   g_assert (retval != NULL);
 
+  retval->is_legacy = retval->is_legacy || is_legacy;
+
   cached_dir_scan_recursive (retval, canonical_path);
   
   return retval;
@@ -1826,6 +1845,7 @@
 
   menu_verbose ("Reading entries for %s (full path %s)\n",
                 dir ? dir->name : "(not created yet)", dirname);
+  menu_verbose( "basename %s\n", basename);
   
   dp = opendir (dirname);
   if (dp == NULL)
@@ -1840,6 +1860,7 @@
       g_assert (parent != NULL);
       
       dir = cached_dir_new (parent->cache, basename);
+      dir->is_legacy = parent->is_legacy;
       dir->parent = parent;
       parent->subdirs = g_slist_prepend (parent->subdirs,
                                          dir);
Index: menu-entries.h
===================================================================
RCS file: /cvs/menus/desktop-file-utils/src/menu-entries.h,v
retrieving revision 1.7
diff -u -r1.7 menu-entries.h
--- menu-entries.h	29 May 2003 23:09:18 -0000	1.7
+++ menu-entries.h	9 Jan 2004 16:52:34 -0000
@@ -121,6 +121,10 @@
 const char* entry_get_absolute_path (Entry      *entry);
 const char* entry_get_relative_path (Entry      *entry);
 const char* entry_get_name          (Entry      *entry);
+gboolean entry_has_category 	    (Entry      *entry,
+		                     EntryCache *cache,
+				     const char *category);
+
 
 EntrySet* entry_set_new          (void);
 void      entry_set_ref          (EntrySet *set);
Index: menu-layout.h
===================================================================
RCS file: /cvs/menus/desktop-file-utils/src/menu-layout.h,v
retrieving revision 1.20
diff -u -r1.20 menu-layout.h
--- menu-layout.h	23 Oct 2003 23:41:41 -0000	1.20
+++ menu-layout.h	9 Jan 2004 16:52:34 -0000
@@ -61,7 +61,12 @@
   MENU_NODE_OLD,
   MENU_NODE_NEW,
   MENU_NODE_DELETED,
-  MENU_NODE_NOT_DELETED
+  MENU_NODE_NOT_DELETED,
+  MENU_NODE_LAYOUT,
+  MENU_NODE_DEFAULT_LAYOUT,
+  MENU_NODE_MENUNAME,
+  MENU_NODE_SEPARATOR,
+  MENU_NODE_MERGE
 } MenuNodeType;
 
 MenuNode*    menu_node_new          (MenuNodeType type);
Index: menu-method.c
===================================================================
RCS file: /cvs/menus/desktop-file-utils/src/menu-method.c,v
retrieving revision 1.17
diff -u -r1.17 menu-method.c
--- menu-method.c	17 Jul 2003 21:54:00 -0000	1.17
+++ menu-method.c	9 Jan 2004 16:52:34 -0000
@@ -886,6 +886,8 @@
 	if (retval != GNOME_VFS_OK)
 		return retval;
 
+	g_return_val_if_fail (menu_path != NULL, GNOME_VFS_ERROR_NOT_FOUND);
+
 	tmp_error = NULL;
         tree = menu_method_get_tree (method, menu_file, &tmp_error);
         if (tree == NULL) {
@@ -903,11 +905,11 @@
 	res = desktop_entry_tree_resolve_path (tree, menu_path, &node,
 					       real_path_p, NULL);
 	if (res == PATH_RESOLUTION_NOT_FOUND) {		
-                desktop_entry_tree_unref (tree);
-                g_free (menu_path);
-
 		menu_verbose ("Failed to resolve path %s in desktop entry tree\n",
 			      menu_path);
+
+                desktop_entry_tree_unref (tree);
+                g_free (menu_path);
 		
                 return GNOME_VFS_ERROR_NOT_FOUND;
         }
Index: menu-modules.conf
===================================================================
RCS file: /cvs/menus/desktop-file-utils/src/menu-modules.conf,v
retrieving revision 1.2
diff -u -r1.2 menu-modules.conf
--- menu-modules.conf	20 May 2003 22:47:00 -0000	1.2
+++ menu-modules.conf	9 Jan 2004 16:52:34 -0000
@@ -7,4 +7,3 @@
 #
 
 menu-test:  libmenu.so
-
Index: menu-parser.c
===================================================================
RCS file: /cvs/menus/desktop-file-utils/src/menu-parser.c,v
retrieving revision 1.12
diff -u -r1.12 menu-parser.c
--- menu-parser.c	23 Oct 2003 23:41:41 -0000	1.12
+++ menu-parser.c	9 Jan 2004 16:52:34 -0000
@@ -338,6 +338,10 @@
         {
           push_node (parser, MENU_NODE_APP_DIR);
         }
+      else if (ELEMENT_IS ("LegacyDir"))
+        {
+          push_node (parser, MENU_NODE_LEGACY_DIR);
+        }
       else if (ELEMENT_IS ("DefaultAppDirs"))
         {
           push_node (parser, MENU_NODE_DEFAULT_APP_DIRS);
@@ -403,6 +407,14 @@
         {
           push_node (parser, MENU_NODE_NOT_DELETED);
         }
+      else if (ELEMENT_IS ("Layout"))
+        {
+          push_node (parser, MENU_NODE_LAYOUT);
+        }
+      else if (ELEMENT_IS ("DefaultLayout"))
+        {
+          push_node (parser, MENU_NODE_DEFAULT_LAYOUT);
+        }
       else
         {
           set_error (error, context, G_MARKUP_ERROR,
@@ -491,6 +503,55 @@
 }
 
 static void
+start_layout_child_element (MenuParser          *parser,
+                          GMarkupParseContext *context,
+                          const gchar         *element_name,
+                          const gchar        **attribute_names,
+                          const gchar        **attribute_values,
+                          GError             **error)
+{
+  if (ELEMENT_IS ("Merge"))
+    {
+	const char *type;
+	
+	push_node (parser, MENU_NODE_MERGE);
+	if (!locate_attributes (context, element_name,
+			        attribute_names, attribute_values,
+			        error, "type", &type,
+			        NULL))
+	    return;
+		    
+    }
+  else {
+  if (!check_no_attributes (context, element_name,
+                            attribute_names, attribute_values,
+                            error))
+    return;
+
+  if (ELEMENT_IS ("Filename"))
+    {
+      push_node (parser, MENU_NODE_FILENAME); 
+    }
+  else if (ELEMENT_IS ("Menuname"))
+    {
+      push_node (parser, MENU_NODE_MENUNAME); 
+    }
+  else if (ELEMENT_IS ("Separator"))
+    {
+      push_node (parser, MENU_NODE_SEPARATOR); 
+    }
+  else
+    {
+      set_error (error, context, G_MARKUP_ERROR,
+                 G_MARKUP_ERROR_UNKNOWN_ELEMENT,
+                 _("Element <%s> may not appear below <%s>\n"),
+                 element_name, "Move");
+    }
+  }
+}
+
+
+static void
 start_element_handler (GMarkupParseContext *context,
                        const gchar         *element_name,
                        const gchar        **attribute_names,
@@ -544,6 +605,13 @@
                                 attribute_names, attribute_values,
                                 error);
     }
+  else if (menu_node_get_type (parser->stack_top) == MENU_NODE_LAYOUT ||
+           menu_node_get_type (parser->stack_top) == MENU_NODE_DEFAULT_LAYOUT)
+    {
+      start_layout_child_element (parser, context, element_name,
+                                  attribute_names, attribute_values,
+                                  error);
+    }
   else
     {
       set_error (error, context, G_MARKUP_ERROR,
@@ -723,6 +791,7 @@
     case MENU_NODE_LEGACY_DIR:
     case MENU_NODE_OLD:
     case MENU_NODE_NEW:
+    case MENU_NODE_MENUNAME:
       if (menu_node_get_content (parser->stack_top) == NULL)
         {
           set_error (error, context, G_MARKUP_ERROR,
@@ -750,6 +819,10 @@
     case MENU_NODE_KDE_LEGACY_DIRS:
     case MENU_NODE_DELETED:
     case MENU_NODE_NOT_DELETED:
+    case MENU_NODE_LAYOUT:
+    case MENU_NODE_DEFAULT_LAYOUT:
+    case MENU_NODE_SEPARATOR:
+    case MENU_NODE_MERGE:
       break;
 
     case MENU_NODE_MOVE:
@@ -805,6 +878,7 @@
     case MENU_NODE_LEGACY_DIR:
     case MENU_NODE_OLD:
     case MENU_NODE_NEW:
+    case MENU_NODE_MENUNAME:
       g_assert (menu_node_get_content (parser->stack_top) == NULL);
       
       menu_node_set_content (parser->stack_top, text);
@@ -828,6 +902,10 @@
     case MENU_NODE_MOVE:
     case MENU_NODE_DELETED:
     case MENU_NODE_NOT_DELETED:
+    case MENU_NODE_LAYOUT:
+    case MENU_NODE_DEFAULT_LAYOUT:
+    case MENU_NODE_SEPARATOR:
+    case MENU_NODE_MERGE:
       if (!all_whitespace (text, text_len))
         {
           set_error (error, context, G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE,
Index: menu-process.c
===================================================================
RCS file: /cvs/menus/desktop-file-utils/src/menu-process.c,v
retrieving revision 1.35
diff -u -r1.35 menu-process.c
--- menu-process.c	24 Oct 2003 00:13:51 -0000	1.35
+++ menu-process.c	9 Jan 2004 16:52:34 -0000
@@ -266,6 +266,7 @@
                             "applnk",
                             NULL);
       menu_node_set_content (n, f);
+      menu_node_legacy_dir_set_prefix (n, "kde");
       menu_node_insert_before (node, n);
 
       menu_verbose ("Adding <LegacyDir>%s</LegacyDir> in <KDELegacyDirs/>\n",
@@ -389,13 +390,157 @@
 }
 
 static void
+resolve_legacy_dir (MenuCache  *menu_cache,
+                    EntryCache *entry_cache,
+                    MenuNode   *node)
+{
+      MenuNode *menu, *to_merge;
+      MenuNode *n, *fake_root, *fake_menu, *tmp_node;
+      EntryDirectoryList *directories;
+      EntrySet *set;
+      GSList *entries;
+
+      to_merge = menu_node_new (MENU_NODE_ROOT);
+
+      menu = menu_node_new (MENU_NODE_MENU);
+      menu_node_append_child (to_merge, menu);
+
+      n = menu_node_new (MENU_NODE_APP_DIR);
+      menu_node_set_content (n, menu_node_get_content (node));
+      menu_node_append_child (menu, n);
+      menu_node_unref (n);
+      
+      n = menu_node_new (MENU_NODE_DIRECTORY_DIR);
+      menu_node_set_content (n, menu_node_get_content (node));
+      menu_node_append_child (menu, n);
+      menu_node_unref (n);
+
+      n = menu_node_new (MENU_NODE_INCLUDE);
+      menu_node_append_child (menu, n);
+
+      set = entry_set_new ();
+      fake_root = menu_node_new (MENU_NODE_ROOT);
+      menu_node_root_set_entry_cache (fake_root, entry_cache);
+      fake_menu =  menu_node_new (MENU_NODE_MENU);
+      menu_node_append_child (fake_root, fake_menu);
+
+      tmp_node = menu_node_new (MENU_NODE_LEGACY_DIR);
+      menu_node_set_content (tmp_node, menu_node_get_content (node));
+      menu_node_append_child (fake_menu, tmp_node);
+      menu_node_unref (tmp_node);
+
+      directories = menu_node_menu_get_app_entries (fake_menu);
+
+      entry_directory_list_get_all_desktops (directories, set);
+
+      entries = entry_set_list_entries (set);
+
+      while (entries != NULL)
+        {
+          Entry *e = entries->data;
+	  gint abs_path_len, start_path_len, rel_path_len;
+
+
+	  if (entry_has_category (e, entry_cache, "Legacy")) {
+		  entries = entries->next;
+		  continue;
+	  }
+
+	  abs_path_len = strlen (entry_get_absolute_path (e));
+	  start_path_len = strlen (menu_node_get_content(node)) 
+		  + 1 - g_str_has_suffix (menu_node_get_content (node), "/");
+	  rel_path_len = strlen (entry_get_relative_path (e));
+
+	  if (abs_path_len <= (start_path_len + rel_path_len + 1)) { /* file in current dir */
+	    MenuNode *f = menu_node_new (MENU_NODE_FILENAME);
+
+	    menu_node_set_content (f, entry_get_relative_path (e));
+
+	    menu_node_append_child (n, f);
+	    menu_node_unref (f);
+	  } else {
+		MenuNode *subdir, *include, *f, *top_dir;
+		char *path, *dir_path;
+		char **path_elements;
+		int i;
+
+		path = g_strndup (entry_get_absolute_path (e) + start_path_len,  
+				abs_path_len - start_path_len - 1 - rel_path_len);
+		dir_path = g_build_filename (menu_node_get_content (node), path, NULL);
+
+		path_elements = g_strsplit (path, "/", 0);
+		top_dir = menu;
+		subdir = NULL;
+		i = 0;
+
+		while (path_elements[i] != NULL) {
+  			subdir = menu_node_new (MENU_NODE_MENU);
+			menu_node_append_child (top_dir, subdir);
+
+			f = menu_node_new (MENU_NODE_NAME);
+			menu_node_set_content (f, path_elements[i]);
+			menu_node_append_child (subdir, f);
+			menu_node_unref (f);
+			/*menu_node_unref (top_dir);*/ /* FIXME*/ 
+			top_dir = subdir;
+			i++;
+		} 
+
+		g_strfreev (path_elements);
+
+		f = menu_node_new (MENU_NODE_APP_DIR);
+		menu_node_set_content (f, dir_path);
+		menu_node_append_child (subdir, f);
+		menu_node_unref (f);
+
+		f = menu_node_new (MENU_NODE_DIRECTORY_DIR);
+		menu_node_set_content (f, dir_path);
+		menu_node_append_child (subdir, f);
+		menu_node_unref (f);
+
+		include = menu_node_new (MENU_NODE_INCLUDE);
+	        menu_node_append_child (subdir, include);
+		
+		f = menu_node_new (MENU_NODE_FILENAME);
+
+		menu_node_set_content (f, g_strdup (entry_get_relative_path (e)));
+		menu_node_append_child (include, f);
+
+		g_free (path);
+		g_free (dir_path);
+
+		menu_node_unref (f);
+		menu_node_unref (include);
+		menu_node_unref (subdir);
+        	menu_node_strip_duplicate_children (to_merge);
+	  }
+
+          entries = entries->next;
+        }
+
+      menu_node_unref (n);
+
+
+      merge_resolved_copy_of_children (menu_cache, entry_cache,
+                                       node, to_merge);
+
+      menu_node_unref (menu);
+
+      menu_node_unref (to_merge);
+
+      menu_node_unref (fake_menu);
+      menu_node_unref (fake_root);
+}
+
+
+static void
 menu_node_resolve_files_recursive (MenuCache  *menu_cache,
                                    EntryCache *entry_cache,
                                    MenuNode   *node)
 {
   MenuNode *child;
 
-  menu_verbose ("Resolving files in node %p\n", node);
+  menu_verbose ("Resolving files in node %p %s\n", node, menu_node_get_content(node));
       
   switch (menu_node_get_type (node))
     {
@@ -417,7 +562,10 @@
     case MENU_NODE_DEFAULT_MERGE_DIRS:
       resolve_default_merge_dirs (menu_cache, entry_cache, node);
       break;
-      
+    case MENU_NODE_LEGACY_DIR:
+      resolve_legacy_dir (menu_cache, entry_cache, node);
+      /* FIXME break; */
+
     case MENU_NODE_PASSTHROUGH:
       /* Just get rid of this, we don't need the memory usage */
       menu_node_unlink (node);
@@ -1060,7 +1208,14 @@
       ++i;
     }
 
-  if (iter == NULL && prev != NULL && split[i] != NULL)
+  if (iter == NULL && prev != NULL && split[i] != NULL) {
+    if (strcmp (split[i], ".directory") == 0) {
+        menu_verbose ("Return directory entry for entry named \"%s\"\n",
+                      split[i]);
+        entry = prev->dir_entry;
+        iter = prev;
+    }
+  else 
     {
       /* The last element was not a dir; see if it's one
        * of the entries.
@@ -1090,6 +1245,7 @@
           tmp = tmp->next;
         }
     }
+  }
 
   g_strfreev (split);
 
@@ -1351,8 +1507,9 @@
              void                        *user_data)
 {
   GSList *tmp;
-  char *p;
+  char *p, tmpchar;
   DesktopEntryForeachInfo info;
+  TreeNode *node;
 
   p = path_for_node (dir);
 
@@ -1361,7 +1518,15 @@
   
   info.is_dir = TRUE;
   info.depth = depth;
-  info.menu_id = dir->name; /* FIXME ! */
+  info.menu_id = g_strdelimit (g_strdup(dir->name), "/", '-');
+  /* FIXME.. I'm not sure of that code */
+  if ((node = tree_node_find_subdir (tree->root, p) != NULL) 
+		  && (menu_node_legacy_dir_get_prefix (node) != NULL)) {
+	  tmpchar = info.menu_id;
+	  info.menu_id = g_strconcat (menu_node_legacy_dir_get_prefix (node), 
+			  "-", tmpchar, NULL);
+	  g_free (tmpchar);
+  }
   info.menu_basename = dir->name;
   info.menu_fullpath = p;
   info.filesystem_path_to_entry = dir->dir_entry ? entry_get_absolute_path (dir->dir_entry) : NULL;
@@ -1373,18 +1538,21 @@
       g_free (p);
       return FALSE;
     }
+  g_free (info.menu_id);
   g_free (p);
   
   tmp = dir->entries;
   while (tmp != NULL)
     {
       Entry *e = tmp->data;
+      char *root_path;
 
       p = path_for_entry (dir, e);
 
       info.is_dir = FALSE;
       info.depth = depth + 1;
-      info.menu_id = entry_get_relative_path (e); /* FIXME */
+      root_path = g_strndup (entry_get_absolute_path (e), strlen (entry_get_absolute_path (e)) - strlen (entry_get_relative_path (e)) - 1);
+      info.menu_id = g_strdelimit (g_strdup (entry_get_relative_path (e)), "/", '-');
       info.menu_basename = entry_get_name (e);
       info.menu_fullpath = p;
       info.filesystem_path_to_entry = entry_get_absolute_path (e);
@@ -1399,6 +1567,7 @@
           g_free (p);
           return FALSE;
         }
+      g_free (info.menu_id);
       g_free (p);
 
       tmp = tmp->next;
@@ -2040,7 +2209,7 @@
           
           g_print ("%s\t%s\t%s\n",
                    s,
-                   info->menu_basename,
+                   info->menu_id,
                    info->filesystem_path_to_entry);
 
           g_free (s);
Index: menu-process.h
===================================================================
RCS file: /cvs/menus/desktop-file-utils/src/menu-process.h,v
retrieving revision 1.18
diff -u -r1.18 menu-process.h
--- menu-process.h	23 Oct 2003 18:59:24 -0000	1.18
+++ menu-process.h	9 Jan 2004 16:52:34 -0000
@@ -39,7 +39,7 @@
 {
   gboolean is_dir;
   int depth;
-  const char *menu_id;
+  char *menu_id;
   const char *menu_basename;
   const char *menu_fullpath;
   const char *menu_fullpath_localized;


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