1Upstream-Status: Pending
2
3Index: openbox-xdgmenu-0.3/openbox-xdgmenu.c
4===================================================================
5--- openbox-xdgmenu-0.3.orig/openbox-xdgmenu.c
6+++ openbox-xdgmenu-0.3/openbox-xdgmenu.c
7@@ -32,7 +32,7 @@
8 #include <string.h>
9 #include <glib.h>
10 #include <glib/gprintf.h>
11-#include <gnome-menus/gmenu-tree.h>
12+#include <gnome-menus-3.0/gmenu-tree.h>
13
14 /*=============================================================================
15  * Declarations
16@@ -42,7 +42,6 @@ static void process_directory(GMenuTreeD
17 static void process_entry(GMenuTreeEntry *entry);
18 static void process_separator(GMenuTreeSeparator *entry);
19
20-gboolean option_show_amount_of_entries = 0;
21 gboolean option_do_not_use_categories = 0;
22
23 /*=============================================================================
24@@ -61,11 +60,6 @@ int main (int argc, char **argv)
25           g_free (xdgfile);
26           return 0;
27         }
28-        else if ((strcmp (argv[i], "--show-amount") == 0) ||
29-        (strcmp (argv[i], "-a") == 0))
30-        {
31-            option_show_amount_of_entries = 1;
32-        }
33         else if ((strcmp (argv[i], "--plain") == 0) ||
34         (strcmp (argv[i], "-p") == 0))
35         {
36@@ -93,16 +87,15 @@ int main (int argc, char **argv)
37         return 1;
38     }
39
40-    FILE * file;
41-    if (!(file = fopen(xdgfile, "r")))
42+    GMenuTree *menuTree = gmenu_tree_new (xdgfile,  GMENU_TREE_FLAGS_NONE );
43+
44+    GError *error = NULL;
45+    if (!gmenu_tree_load_sync(menuTree, &error))
46     {
47-        g_printf ("Could not read file \"%s\".\n", xdgfile);
48-        g_free (xdgfile);
49-        return 2;
50+        g_printerr ("Failed to load tree: %s\n", error->message);
51+        g_clear_error (&error);
52+        return 3;
53     }
54-    fclose(file);
55-
56-    GMenuTree *menuTree = gmenu_tree_lookup (xdgfile,  GMENU_TREE_FLAGS_NONE );
57
58     GMenuTreeDirectory *rootDirectory = gmenu_tree_get_root_directory(menuTree);
59
60@@ -129,11 +122,10 @@ void show_help()
61     g_printf ("  openbox-xdgmenu [options] <Xdg menu file>\n");
62     g_printf ("\n");
63     g_printf ("Options:\n");
64-    g_printf ("  -a: Show the amount of items in each category next to its name.\n");
65     g_printf ("  -p: Do not use categories.\n");
66     g_printf ("\n");
67     g_printf ("For example:\n");
68-    g_printf ("  openbox-xdgmenu \"/etc/xdg/menus/applications.menu\"\n\n");
69+    g_printf ("  openbox-xdgmenu \"gnome-applications.menu\"\n\n");
70 }
71
72 /*=============================================================================
73@@ -141,72 +133,61 @@ void show_help()
74  */
75 void process_directory(GMenuTreeDirectory *directory, gboolean isRoot)
76 {
77-    int hasSeparator = 0;
78+    GMenuTreeSeparator *separator = NULL;
79     int hasMenu = 0;
80     GMenuTreeItemType entryType;
81-    GSList *entryList = gmenu_tree_directory_get_contents (directory);
82-    GSList *l;
83-
84-    if (option_do_not_use_categories == 00 && isRoot == 0 &&
85-    g_slist_length(entryList) > 0)
86+    GMenuTreeIter *iter = gmenu_tree_directory_iter (directory);
87+    GMenuTreeItemType next_type;
88+
89+    while ((next_type = gmenu_tree_iter_next (iter)) != GMENU_TREE_ITEM_INVALID)
90     {
91-        hasMenu = 1;
92-
93-        if (option_show_amount_of_entries == 1)
94+        if (option_do_not_use_categories == 00 && isRoot == 0 && hasMenu == 0)
95         {
96+            hasMenu = 1;
97+
98             g_printf(
99-              "<menu id=\"xdg-menu-%s\" label=\"%s (%d)\">\n",
100-              g_strjoinv("&amp;", g_strsplit(gmenu_tree_directory_get_name(directory),"&",0)),
101-              g_strjoinv("&amp;", g_strsplit(gmenu_tree_directory_get_name(directory),"&",0)),
102-              g_slist_length(entryList));
103+                  "<menu id=\"xdg-menu-%s\" label=\"%s\">\n",
104+                  g_strjoinv("&amp;", g_strsplit(gmenu_tree_directory_get_name(directory),"&",0)),
105+                  g_strjoinv("&amp;", g_strsplit(gmenu_tree_directory_get_name(directory),"&",0)));
106         }
107-        else
108-        {
109-            g_printf(
110-              "<menu id=\"xdg-menu-%s\" label=\"%s\">\n",
111-              g_strjoinv("&amp;", g_strsplit(gmenu_tree_directory_get_name(directory),"&",0)),
112-              g_strjoinv("&amp;", g_strsplit(gmenu_tree_directory_get_name(directory),"&",0)));
113-        }
114-    }
115
116-    for (l = entryList; l; l = l->next)
117-    {
118-        GMenuTreeItem *item = l->data;
119-
120-        entryType = gmenu_tree_item_get_type (GMENU_TREE_ITEM(item));
121-
122-        switch (entryType)
123+        switch (next_type)
124         {
125+            case GMENU_TREE_ITEM_INVALID:
126+                break;
127             case GMENU_TREE_ITEM_DIRECTORY:
128-                if (hasSeparator)
129+                if (separator != NULL)
130                 {
131-                    process_separator(GMENU_TREE_SEPARATOR(item));
132-                    hasSeparator = 0;
133+                    process_separator(separator);
134+                    gmenu_tree_item_unref (separator);
135+                    separator = NULL;
136                 }
137-                process_directory(GMENU_TREE_DIRECTORY(item), 0);
138+                process_directory(gmenu_tree_iter_get_directory(iter), 0);
139                 break;
140             case GMENU_TREE_ITEM_ENTRY:
141-                if (hasSeparator)
142+                if (separator != NULL)
143                 {
144-                    process_separator(GMENU_TREE_SEPARATOR(item));
145-                    hasSeparator = 0;
146+                    process_separator(separator);
147+                    gmenu_tree_item_unref (separator);
148+                    separator = NULL;
149                 }
150-                process_entry(GMENU_TREE_ENTRY(item));
151+                process_entry(gmenu_tree_iter_get_entry(iter));
152                 break;
153             case GMENU_TREE_ITEM_SEPARATOR:
154-                hasSeparator = 1;
155+                separator = gmenu_tree_iter_get_separator(iter);
156                 break;
157         }
158-
159-        gmenu_tree_item_unref (item);
160     }
161
162     if (hasMenu == 1)
163     {
164         g_printf("</menu>\n");
165     }
166+
167+    if (separator != NULL)
168+        gmenu_tree_item_unref (separator);
169
170-    g_slist_free (entryList);
171+    gmenu_tree_iter_unref (iter);
172 }
173
174 /*=============================================================================
175@@ -214,8 +195,9 @@ void process_directory(GMenuTreeDirector
176  */
177 void process_entry(GMenuTreeEntry *entry)
178 {
179-    char *name = g_strdup (gmenu_tree_entry_get_name(entry));
180-    char *exec = g_strdup (gmenu_tree_entry_get_exec(entry));
181+    GDesktopAppInfo *appinfo = gmenu_tree_entry_get_app_info (entry);
182+    char *name = g_strdup (g_app_info_get_name(G_APP_INFO(appinfo)));
183+    char *exec = g_strdup (g_app_info_get_executable(G_APP_INFO(appinfo)));
184     int i;
185
186     for (i = 0; i < strlen(exec) - 1; i++) {
187