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