summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile.am2
-rw-r--r--src/e.h5
-rw-r--r--src/menubuild.c406
-rw-r--r--src/menudb.c171
-rw-r--r--src/util.c35
-rw-r--r--src/view.c15
6 files changed, 459 insertions, 175 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 944508126..faa04424e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -21,7 +21,7 @@ ipc.c \
21keys.c \ 21keys.c \
22main.c \ 22main.c \
23menu.c \ 23menu.c \
24menudb.c \ 24menubuild.c \
25pack.c \ 25pack.c \
26resist.c \ 26resist.c \
27shelf.c \ 27shelf.c \
diff --git a/src/e.h b/src/e.h
index 336f347f9..8d7d5764f 100644
--- a/src/e.h
+++ b/src/e.h
@@ -774,6 +774,7 @@ void *e_memdup(void *data, int size);
774int e_glob_matches(char *str, char *glob); 774int e_glob_matches(char *str, char *glob);
775int e_file_can_exec(struct stat *st); 775int e_file_can_exec(struct stat *st);
776char *e_file_link(char *link); 776char *e_file_link(char *link);
777Evas_List e_file_list_dir(char *dir);
777 778
778void e_exec_set_args(int argc, char **argv); 779void e_exec_set_args(int argc, char **argv);
779void e_exec_restart(void); 780void e_exec_restart(void);
@@ -959,11 +960,9 @@ void e_menu_item_set_scale_icon(E_Menu_Item *mi, int scale);
959void e_menu_set_padding_icon(E_Menu *m, int pad); 960void e_menu_set_padding_icon(E_Menu *m, int pad);
960void e_menu_set_padding_state(E_Menu *m, int pad); 961void e_menu_set_padding_state(E_Menu *m, int pad);
961 962
962void e_build_menu_unbuild(E_Build_Menu *bm);
963E_Menu *e_build_menu_build_number(E_Build_Menu *bm, E_DB_File *db, int num);
964void e_build_menu_build(E_Build_Menu *bm);
965void e_build_menu_free(E_Build_Menu *bm); 963void e_build_menu_free(E_Build_Menu *bm);
966E_Build_Menu *e_build_menu_new_from_db(char *file); 964E_Build_Menu *e_build_menu_new_from_db(char *file);
965E_Build_Menu *e_build_menu_new_from_gnome_apps(char *dir);
967 966
968void e_fs_add_event_handler(void (*func) (EfsdEvent *ev)); 967void e_fs_add_event_handler(void (*func) (EfsdEvent *ev));
969void e_fs_init(void); 968void e_fs_init(void);
diff --git a/src/menubuild.c b/src/menubuild.c
new file mode 100644
index 000000000..a77254611
--- /dev/null
+++ b/src/menubuild.c
@@ -0,0 +1,406 @@
1#include "e.h"
2
3Evas_List build_menus = NULL;
4
5static void e_build_menu_cb_exec(E_Menu *m, E_Menu_Item *mi, void *data);
6
7static void e_build_menu_unbuild(E_Build_Menu *bm);
8
9static void e_build_menu_db_poll(int val, void *data);
10static E_Menu *e_build_menu_db_build_number(E_Build_Menu *bm, E_DB_File *db, int num);
11static void e_build_menu_db_build(E_Build_Menu *bm);
12
13static void e_build_menu_gnome_apps_poll(int val, void *data);
14static void e_build_menu_gnome_apps_build(E_Build_Menu *bm);
15
16static void
17e_build_menu_cb_exec(E_Menu *m, E_Menu_Item *mi, void *data)
18{
19 char *exe;
20
21 exe = data;
22 e_exec_run(exe);
23 return;
24 UN(m);
25 UN(mi);
26}
27
28static void
29e_build_menu_unbuild(E_Build_Menu *bm)
30{
31 Evas_List l;
32
33 bm->menu = NULL;
34 if (bm->menus)
35 {
36 for (l = bm->menus; l; l = l->next)
37 {
38 E_Menu *m;
39
40 m = l->data;
41 e_menu_hide(m);
42 e_menu_update_shows(m);
43 e_menu_update_hides(m);
44 e_menu_update_finish(m);
45 OBJ_DO_FREE(m);
46 }
47 bm->menus = evas_list_free(bm->menus);
48 }
49 if (bm->commands)
50 {
51 for (l = bm->commands; l; l = l->next)
52 {
53 IF_FREE(l->data);
54 }
55 bm->commands = evas_list_free(bm->commands);
56 }
57}
58
59
60/* BUILDING from DB's */
61
62
63static void
64e_build_menu_db_poll(int val, void *data)
65{
66 time_t mod;
67 E_Build_Menu *bm;
68
69 bm = data;
70 mod = e_file_modified_time(bm->file);
71 if (mod <= bm->mod_time)
72 {
73 e_add_event_timer(bm->file, 1.0, e_build_menu_db_poll, 0, data);
74 return;
75 }
76 bm->mod_time = mod;
77
78 e_build_menu_unbuild(bm);
79 e_build_menu_db_build(bm);
80 if (!bm->menu) bm->mod_time = 0;
81
82 e_add_event_timer(bm->file, 1.0, e_build_menu_db_poll, 0, data);
83 return;
84 UN(val);
85}
86
87static void
88e_build_menu_gnome_apps_poll(int val, void *data)
89{
90 time_t mod;
91 E_Build_Menu *bm;
92
93 bm = data;
94 mod = e_file_modified_time(bm->file);
95 if (mod <= bm->mod_time)
96 {
97 e_add_event_timer(bm->file, 1.0, e_build_menu_gnome_apps_poll, 0, data);
98 return;
99 }
100 bm->mod_time = mod;
101
102 e_build_menu_unbuild(bm);
103 e_build_menu_gnome_apps_build(bm);
104 if (!bm->menu) bm->mod_time = 0;
105
106 e_add_event_timer(bm->file, 1.0, e_build_menu_gnome_apps_poll, 0, data);
107 return;
108 UN(val);
109}
110
111static E_Menu *
112e_build_menu_db_build_number(E_Build_Menu *bm, E_DB_File *db, int num)
113{
114 E_Menu *menu;
115 char buf[4096];
116 int num2, i2;
117
118 sprintf(buf, "/menu/%i/count", num);
119 if (!e_db_int_get(db, buf, &num2)) return NULL;
120 menu = e_menu_new();
121 e_menu_set_padding_icon(menu, 2);
122 e_menu_set_padding_state(menu, 2);
123 for (i2 = 0; i2 < num2; i2++)
124 {
125 E_Menu_Item *menuitem;
126 char *text, *icon, *exe;
127 int ok, sub, sep;
128
129 sprintf(buf, "/menu/%i/%i/text", num, i2);
130 text = e_db_str_get(db, buf);
131 sprintf(buf, "/menu/%i/%i/icon", num, i2);
132 icon = e_db_str_get(db, buf);
133 sprintf(buf, "/menu/%i/%i/command", num, i2);
134 exe = e_db_str_get(db, buf);
135 sprintf(buf, "/menu/%i/%i/submenu", num, i2);
136 ok = e_db_int_get(db, buf, &sub);
137 sep = 0;
138 sprintf(buf, "/menu/%i/%i/separator", num, i2);
139 e_db_int_get(db, buf, &sep);
140 menuitem = e_menu_item_new(text);
141 e_menu_item_set_icon(menuitem, icon);
142 if ((icon) && (text)) e_menu_item_set_scale_icon(menuitem, 1);
143 IF_FREE(text);
144 IF_FREE(icon);
145 if (sep) e_menu_item_set_separator(menuitem, 1);
146 else
147 {
148 if (ok)
149 {
150 E_Menu *menu2;
151
152 menu2 = e_build_menu_db_build_number(bm, db, sub);
153 e_menu_item_set_submenu(menuitem, menu2);
154 }
155 }
156 if (exe)
157 {
158 e_menu_item_set_callback(menuitem, e_build_menu_cb_exec, exe);
159 bm->commands = evas_list_prepend(bm->commands, exe);
160 }
161 e_menu_add_item(menu, menuitem);
162 }
163 bm->menus = evas_list_prepend(bm->menus, menu);
164 return menu;
165}
166
167static void
168e_build_menu_db_build(E_Build_Menu *bm)
169{
170 E_DB_File *db;
171 int num;
172
173 e_db_flush();
174 db = e_db_open_read(bm->file);
175 if (!db) return;
176
177 if (!e_db_int_get(db, "/menu/count", &num)) goto error;
178 if (num > 0) bm->menu = e_build_menu_db_build_number(bm, db, 0);
179 error:
180 e_db_close(db);
181}
182
183
184/* BUILD from GNOME APPS directory structure */
185
186
187static E_Menu *
188e_build_menu_gnome_apps_build_dir(E_Build_Menu *bm, char *dir)
189{
190 E_Menu *menu = NULL;
191 Evas_List l, entries = NULL;
192
193 menu = e_menu_new();
194 e_menu_set_padding_icon(menu, 2);
195 e_menu_set_padding_state(menu, 2);
196 /* build the order of things to scan ...*/
197 {
198 FILE *f;
199 char buf[4096];
200 Evas_List dirlist = NULL;
201
202 /* read .order file */
203 sprintf(buf, "%s/.order", dir);
204 f = fopen(buf, "rb");
205 if (f)
206 {
207 while (fgets(buf, 4096, f))
208 {
209 int buf_len;
210
211 buf_len = strlen(buf);
212 if (buf_len > 0)
213 {
214 if (buf[buf_len - 1] == '\n')
215 buf[buf_len - 1] = 0;
216 entries = evas_list_append(entries, strdup(buf));
217 }
218 }
219 fclose(f);
220 }
221 /* read dir listing in alphabetical order and use that to suppliment */
222 dirlist = e_file_list_dir(dir);
223 for (l = dirlist; l; l = l->next)
224 {
225 char *s;
226
227 s = l->data;
228 /* if it isnt a "dot" file or dir */
229 if (s[0] != '.')
230 {
231 Evas_List ll;
232 int have_it;
233
234 have_it = 0;
235 for (ll = entries; ll; ll = ll->next)
236 {
237 if (!strcmp(ll->data, s))
238 {
239 have_it = 1;
240 break;
241 }
242 }
243 if (!have_it)
244 entries = evas_list_append(entries, strdup(s));
245 }
246 free(s);
247 }
248 if (dirlist) evas_list_free(dirlist);
249 }
250 /* now go thru list... */
251 for (l = entries; l; l = l->next)
252 {
253 char *s;
254 char buf[4096];
255 E_Menu_Item *menuitem;
256 char *icon, *name, *exe;
257 E_Menu *sub;
258 FILE *f;
259
260 f = NULL;
261 icon = NULL;
262 exe = NULL;
263 name = NULL;
264 sub = NULL;
265 s = l->data;
266 sprintf(buf, "%s/%s", dir, s);
267 /* if its a subdir... */
268 if (e_file_is_dir(buf))
269 {
270 sub = e_build_menu_gnome_apps_build_dir(bm, buf);
271 sprintf(buf, "%s/%s/.directory", dir, s);
272
273 f = fopen(buf, "rb");
274 }
275 /* regular file */
276 else
277 {
278 sprintf(buf, "%s/%s", dir, s);
279
280 f = fopen(buf, "rb");
281 }
282 if (f)
283 {
284 while (fgets(buf, 4096, f))
285 {
286 int buf_len;
287
288 buf_len = strlen(buf);
289 if (buf_len > 0)
290 {
291 if (buf[buf_len - 1] == '\n')
292 buf[buf_len - 1] = 0;
293 /* look for Name= */
294 if ((!name) &&
295 (((e_glob_matches(buf, "Name[en]=*")) ||
296 (e_glob_matches(buf, "Name=*")))))
297 {
298 char *eq;
299
300 eq = strchr(buf, '=');
301 if (eq)
302 name = strdup(eq + 1);
303 }
304 /* look for Icon= */
305 else if ((!icon) &&
306 ((e_glob_matches(buf, "Icon=*"))))
307 {
308 char *eq;
309
310 eq = strchr(buf, '=');
311 if (eq)
312 {
313 char buf2[4096];
314
315 sprintf(buf2, "/usr/share/pixmaps/%s", eq +1);
316 icon = strdup(buf2);
317 }
318 }
319 /* look for Icon= */
320 else if ((!exe) &&
321 ((e_glob_matches(buf, "Exec=*"))))
322 {
323 char *eq;
324
325 eq = strchr(buf, '=');
326 if (eq)
327 exe = strdup(eq + 1);
328 }
329 }
330 }
331 fclose(f);
332 }
333
334 if (!name) name = strdup(s);
335 menuitem = e_menu_item_new(name);
336 if (icon) e_menu_item_set_icon(menuitem, icon);
337 if ((icon) && (name)) e_menu_item_set_scale_icon(menuitem, 1);
338 if (exe)
339 {
340 e_menu_item_set_callback(menuitem, e_build_menu_cb_exec, exe);
341 bm->commands = evas_list_prepend(bm->commands, exe);
342 }
343 if (sub) e_menu_item_set_submenu(menuitem, sub);
344 e_menu_add_item(menu, menuitem);
345
346 IF_FREE(name);
347 IF_FREE(icon);
348 free(s);
349 }
350 if (entries) evas_list_free(entries);
351 bm->menus = evas_list_prepend(bm->menus, menu);
352 return menu;
353}
354
355static void
356e_build_menu_gnome_apps_build(E_Build_Menu *bm)
357{
358 E_Menu *menu;
359
360 menu = e_build_menu_gnome_apps_build_dir(bm, bm->file);
361 bm->menu = menu;
362}
363
364void
365e_build_menu_free(E_Build_Menu *bm)
366{
367 e_del_event_timer(bm->file);
368 e_build_menu_unbuild(bm);
369 IF_FREE(bm->file);
370 build_menus = evas_list_remove(build_menus, bm);
371 FREE(bm);
372}
373
374E_Build_Menu *
375e_build_menu_new_from_db(char *file)
376{
377 E_Build_Menu *bm;
378
379 if (!file) return NULL;
380 bm = NEW(E_Build_Menu, 1);
381 ZERO(bm, E_Build_Menu, 1);
382 OBJ_INIT(bm, e_build_menu_free);
383
384 bm->file = strdup(file);
385
386 build_menus = evas_list_prepend(build_menus, bm);
387 e_build_menu_db_poll(0, bm);
388 return bm;
389}
390
391E_Build_Menu *
392e_build_menu_new_from_gnome_apps(char *dir)
393{
394 E_Build_Menu *bm;
395
396 if (!dir) return NULL;
397 bm = NEW(E_Build_Menu, 1);
398 ZERO(bm, E_Build_Menu, 1);
399 OBJ_INIT(bm, e_build_menu_free);
400
401 bm->file = strdup(dir);
402
403 build_menus = evas_list_prepend(build_menus, bm);
404 e_build_menu_gnome_apps_poll(0, bm);
405 return bm;
406}
diff --git a/src/menudb.c b/src/menudb.c
deleted file mode 100644
index c59e8872d..000000000
--- a/src/menudb.c
+++ /dev/null
@@ -1,171 +0,0 @@
1#include "e.h"
2
3Evas_List build_menus = NULL;
4
5static void e_build_menu_poll(int val, void *data);
6
7static void
8e_build_menu_poll(int val, void *data)
9{
10 time_t mod;
11 E_Build_Menu *bm;
12
13 bm = data;
14 mod = e_file_modified_time(bm->file);
15 if (mod <= bm->mod_time)
16 {
17 e_add_event_timer(bm->file, 1.0, e_build_menu_poll, 0, data);
18 return;
19 }
20 bm->mod_time = mod;
21
22 e_build_menu_unbuild(bm);
23 e_build_menu_build(bm);
24 if (!bm->menu) bm->mod_time = 0;
25
26 e_add_event_timer(bm->file, 1.0, e_build_menu_poll, 0, data);
27 return;
28 UN(val);
29}
30
31static void
32e_build_menu_cb_exec(E_Menu *m, E_Menu_Item *mi, void *data)
33{
34 char *exe;
35
36 exe = data;
37 e_exec_run(exe);
38 return;
39 UN(m);
40 UN(mi);
41}
42
43void
44e_build_menu_unbuild(E_Build_Menu *bm)
45{
46 Evas_List l;
47
48 bm->menu = NULL;
49 if (bm->menus)
50 {
51 for (l = bm->menus; l; l = l->next)
52 {
53 E_Menu *m;
54
55 m = l->data;
56 e_menu_hide(m);
57 e_menu_update_shows(m);
58 e_menu_update_hides(m);
59 e_menu_update_finish(m);
60 OBJ_DO_FREE(m);
61 }
62 bm->menus = evas_list_free(bm->menus);
63 }
64 if (bm->commands)
65 {
66 for (l = bm->commands; l; l = l->next)
67 {
68 IF_FREE(l->data);
69 }
70 bm->commands = evas_list_free(bm->commands);
71 }
72}
73
74E_Menu *
75e_build_menu_build_number(E_Build_Menu *bm, E_DB_File *db, int num)
76{
77 E_Menu *menu;
78 char buf[4096];
79 int num2, i2;
80
81 sprintf(buf, "/menu/%i/count", num);
82 if (!e_db_int_get(db, buf, &num2)) return NULL;
83 menu = e_menu_new();
84 e_menu_set_padding_icon(menu, 2);
85 e_menu_set_padding_state(menu, 2);
86 for (i2 = 0; i2 < num2; i2++)
87 {
88 E_Menu_Item *menuitem;
89 char *text, *icon, *exe;
90 int ok, sub, sep;
91
92 sprintf(buf, "/menu/%i/%i/text", num, i2);
93 text = e_db_str_get(db, buf);
94 sprintf(buf, "/menu/%i/%i/icon", num, i2);
95 icon = e_db_str_get(db, buf);
96 sprintf(buf, "/menu/%i/%i/command", num, i2);
97 exe = e_db_str_get(db, buf);
98 sprintf(buf, "/menu/%i/%i/submenu", num, i2);
99 ok = e_db_int_get(db, buf, &sub);
100 sep = 0;
101 sprintf(buf, "/menu/%i/%i/separator", num, i2);
102 e_db_int_get(db, buf, &sep);
103 menuitem = e_menu_item_new(text);
104 e_menu_item_set_icon(menuitem, icon);
105 if ((icon) && (text)) e_menu_item_set_scale_icon(menuitem, 1);
106 IF_FREE(text);
107 IF_FREE(icon);
108 if (sep) e_menu_item_set_separator(menuitem, 1);
109 else
110 {
111 if (ok)
112 {
113 E_Menu *menu2;
114
115 menu2 = e_build_menu_build_number(bm, db, sub);
116 e_menu_item_set_submenu(menuitem, menu2);
117 }
118 }
119 if (exe)
120 {
121 e_menu_item_set_callback(menuitem, e_build_menu_cb_exec, exe);
122 bm->commands = evas_list_prepend(bm->commands, exe);
123 }
124 e_menu_add_item(menu, menuitem);
125 }
126 bm->menus = evas_list_prepend(bm->menus, menu);
127 return menu;
128}
129
130void
131e_build_menu_build(E_Build_Menu *bm)
132{
133 E_DB_File *db;
134 int num;
135
136 e_db_flush();
137 db = e_db_open_read(bm->file);
138 if (!db) return;
139
140 if (!e_db_int_get(db, "/menu/count", &num)) goto error;
141 if (num > 0) bm->menu = e_build_menu_build_number(bm, db, 0);
142 error:
143 e_db_close(db);
144}
145
146void
147e_build_menu_free(E_Build_Menu *bm)
148{
149 e_del_event_timer(bm->file);
150 e_build_menu_unbuild(bm);
151 IF_FREE(bm->file);
152 build_menus = evas_list_remove(build_menus, bm);
153 FREE(bm);
154}
155
156E_Build_Menu *
157e_build_menu_new_from_db(char *file)
158{
159 E_Build_Menu *bm;
160
161 if (!file) return NULL;
162 bm = NEW(E_Build_Menu, 1);
163 ZERO(bm, E_Build_Menu, 1);
164 OBJ_INIT(bm, e_build_menu_free);
165
166 bm->file = strdup(file);
167
168 build_menus = evas_list_prepend(build_menus, bm);
169 e_build_menu_poll(0, bm);
170 return bm;
171}
diff --git a/src/util.c b/src/util.c
index 0ccca47cb..21c3a3109 100644
--- a/src/util.c
+++ b/src/util.c
@@ -166,3 +166,38 @@ e_file_link(char *link)
166 buf[count] = 0; 166 buf[count] = 0;
167 return strdup(buf); 167 return strdup(buf);
168} 168}
169
170Evas_List
171e_file_list_dir(char *dir)
172{
173 DIR *dirp;
174 struct dirent *dp;
175 Evas_List list;
176
177 dirp = opendir(dir);
178 if (!dirp) return NULL;
179 list = NULL;
180 while ((dp = readdir(dirp)))
181 {
182 printf("%s\n", dp->d_name);
183 if ((strcmp(dp->d_name, ".")) &&
184 (strcmp(dp->d_name, "..")))
185 {
186 Evas_List l;
187
188 /* insertion sort */
189 for (l = list; l; l = l->next)
190 {
191 if (strcmp(l->data, dp->d_name) > 0)
192 {
193 list = evas_list_prepend_relative(list, strdup(dp->d_name), l->data);
194 break;
195 }
196 }
197 /* nowhwre to go? just append it */
198 if (!l) list = evas_list_append(list, strdup(dp->d_name));
199 }
200 }
201 closedir(dirp);
202 return list;
203}
diff --git a/src/view.c b/src/view.c
index 69ea42941..15cc4c0fc 100644
--- a/src/view.c
+++ b/src/view.c
@@ -90,6 +90,20 @@ e_bg_up_cb(void *_data, Evas _e, Evas_Object _o, int _b, int _x, int _y)
90 } 90 }
91 else if (_b == 3) 91 else if (_b == 3)
92 { 92 {
93 static E_Build_Menu *buildmenu = NULL;
94
95 if (!buildmenu)
96 {
97 buildmenu = e_build_menu_new_from_gnome_apps("/usr/share/gnome/apps");
98 }
99 if (buildmenu)
100 {
101 static E_Menu *menu = NULL;
102 menu = buildmenu->menu;
103 if (menu)
104 e_menu_show_at_mouse(menu, ev->rx, ev->ry, ev->time);
105 }
106/*
93 static E_Menu *menu = NULL; 107 static E_Menu *menu = NULL;
94 108
95 if (!menu) 109 if (!menu)
@@ -105,6 +119,7 @@ e_bg_up_cb(void *_data, Evas _e, Evas_Object _o, int _b, int _x, int _y)
105 } 119 }
106 if (menu) 120 if (menu)
107 e_menu_show_at_mouse(menu, ev->rx, ev->ry, ev->time); 121 e_menu_show_at_mouse(menu, ev->rx, ev->ry, ev->time);
122 */
108 } 123 }
109 } 124 }
110 if (ev->button == 1) 125 if (ev->button == 1)