From 7fe641df375fadbbf2da5734e3bd14ee9971e88a Mon Sep 17 00:00:00 2001 From: Carsten Haitzler Date: Sat, 3 Feb 2001 17:17:07 +0000 Subject: [PATCH] oooooh - look at this - the desktop left click menu is......... CONFIGURABLE yes - it generates it from a..... DATABASE - there's a script that builds the menu - it's a default set - but easily editable in the script (an example of how to build a menu db - but... eventually we'd need a gui.) This only builds a menu from a db file - it also monitors it for changes and updates the menu to match any changes that happen. I need to write later a fs menu builder that builds a menu from the filing system. SVN revision: 4164 --- data/config/behavior/default/apps_menu.db | Bin 0 -> 20480 bytes data/scripts/build_app_menu_db.sh | 109 ++++++++++++++ src/border.c | 2 +- src/config.c | 7 +- src/desktops.c | 116 ++------------- src/e.h | 20 +++ src/menu.c | 2 +- src/menudb.c | 167 ++++++++++++++++++++++ 8 files changed, 316 insertions(+), 107 deletions(-) create mode 100644 data/config/behavior/default/apps_menu.db create mode 100755 data/scripts/build_app_menu_db.sh diff --git a/data/config/behavior/default/apps_menu.db b/data/config/behavior/default/apps_menu.db new file mode 100644 index 0000000000000000000000000000000000000000..5ff5a8fd279d095f6b0b0c3c3a665e4784bb7b8e GIT binary patch literal 20480 zcmeI3U1%It6vua)`a$>JbE41(h3Zn;Qf=exCQV`j6>BY}#Wc-_5JaP!%_O_T-C1{L zNdlo26<=&=wSG_#AF73xRv+w(w${>0s9G=vs;v!JK`KRsT8UBx(L1yAaqlD>ZP2vf z8CWKJ=G-&q{_f1e|J;*EBsfwFZ;aevf31#0=DFr7akf8E@mVfDwtakirdyn@{c%(A zL^+A7s^*aulh-~W%76$E0U|&IhyW2F0z`la5CI}U1c<=(O~BUo-myHwAu{hW{(uvB z21oH29>jgP8;jV3-Pnp7u^Ah13EqheZ^lWu1n1yOI0+}l==lnPJ3;T|J#Xe!9>=4_{ zo@dW6iy7<*_9$y%YgrxB*dq34?8n%}n3pY`i2xBG0z`la5CI}U1c(3;2os2!RxujU za(cd`)oKYXZRB#Pd~eh&^&0V-j<{y_Wb>MtDOtV7U_M@xiRX>M=rsOn7)u|rq8(yX z{6R5H@^>y|^Okqdq_|_r{wlT*T{q7pWtP-z<8+y2`<%RVE0getOTIx?b_nO@>#U4k z%70kC6k(2>aoel*(r7@MaN#A_ONN`IX84*R($XEr!$mG_4~eoIpm#9 z8-ilVEQ+N_6?LtU72^t~)}J?WdQGZOcv82_dkT3ulrtt2$4RiOMY-kFnKx*rUPu*F zmLZ-EvBxVvBy+VCp~Tbf>i;ubvz%u6u}*06{FOXbNz0Zq{bdWxA#XR2mJZ3)u_=DF z+RV$FPWS5OfMpbv1$IX%k%ISkouwCpXE3mb+?`~?zP8c(o$&Vi?eCucAIIZ(6c6AY z+<`CP2$oRC6t)ZPzYG^+HOBA?Ou_{?4`Xl&j=&+<18=}KupkAG!6sM_jZg@{wCkaxA7rv@^1bJ-^d@}NnXQm=L>n1|G_S?@7V-9!#-vou!C$LdzEcr z1FWBQu{O4bt!672XTQgO6%~MQW2a-EQysutLOK%xB0vO)01+SpM1TnV4+%si&0RZH zb9*L99@JLU+(9* z65lI5_?ILMb_}=lz%^O3jO) zq?dHk^L`@j9)Isx8F`=E`~RQehj>`%|GoGMzKC0K82dyAKnK>~BD@V3;05>s#^E>| zhW)S?UV`l~3?=A?9_WBpxE~r|87zis_?e#jhh{g+F(+BpDyHj219B5a39i!rysF+}RqWYBjPkDs*$j$fu5a*SV zj~xAf5zpdj(f|JzzKlC@3l6#a{~NFg>qQU1e9`;=6MPM4VN_HB-iCd!3wFQ=3_=>Y5ttnTxoiJlYUc3U zD1v{Yn4=C0r7|G*MhG@RONM+wk-CR%1GgdVe*gdg literal 0 HcmV?d00001 diff --git a/data/scripts/build_app_menu_db.sh b/data/scripts/build_app_menu_db.sh new file mode 100755 index 000000000..61856bca1 --- /dev/null +++ b/data/scripts/build_app_menu_db.sh @@ -0,0 +1,109 @@ +#!/bin/sh + +# this is the databse to create +DB="./apps_menu.db" + +# shell function calls that setup, cleanup and build menus in a menus database +setup () +{ + NUM=0 + ENTRYNUM=0 + MENUNUM=0 + rm -f $DB +} + +finish () +{ + edb_ed $DB add "/menu/count" int $MENUNUM +} + +menu () +{ + ENTRYNUM=0 + MENUNUM=$1; + M1=$[ $MENUNUM + 1 ]; + if [ $M1 -gt $NUM ]; then + NUM=$M1; + fi +} + +end_menu () +{ + edb_ed $DB add "/menu/"$MENUNUM"/count" int $ENTRYNUM +} + +entry () +{ + if [ $1 = "text" ]; then + edb_ed $DB add "/menu/"$MENUNUM"/"$ENTRYNUM"/text" str "$2" + if [ "$3" = "sub" ]; then + edb_ed $DB add "/menu/"$MENUNUM"/"$ENTRYNUM"/submenu" int $4 + else + edb_ed $DB add "/menu/"$MENUNUM"/"$ENTRYNUM"/command" str "$3" + fi + + + else if [ $1 = "icon" ]; then + edb_ed $DB add "/menu/"$MENUNUM"/"$ENTRYNUM"/icon" str "$2" + if [ "$3" = "sub" ]; then + edb_ed $DB add "/menu/"$MENUNUM"/"$ENTRYNUM"/submenu" int $4 + else + edb_ed $DB add "/menu/"$MENUNUM"/"$ENTRYNUM"/command" str "$3" + fi + + + else if [ $1 = "both" ]; then + edb_ed $DB add "/menu/"$MENUNUM"/"$ENTRYNUM"/text" str "$2" + edb_ed $DB add "/menu/"$MENUNUM"/"$ENTRYNUM"/icon" str "$3" + if [ "$4" = "sub" ]; then + edb_ed $DB add "/menu/"$MENUNUM"/"$ENTRYNUM"/submenu" int $5 + else + edb_ed $DB add "/menu/"$MENUNUM"/"$ENTRYNUM"/command" str "$4" + fi + + + else if [ $1 = "separator" ]; then + edb_ed $DB add "/menu/"$MENUNUM"/"$ENTRYNUM"/separator" int 1 + + + fi; fi; fi; fi + ENTRYNUM=$[ $ENTRYNUM + 1 ]; +} + + + + +############################################################################### +## +## Menus are defined here +## +## IF you want to edit anything - edit this - it's REALLY simple. + +setup + +menu 0 +entry both 'Eterm' '/usr/share/pixmaps/gnome-eterm.png' 'Eterm' +entry both 'Netscape' '/usr/share/pixmaps/netscape.png' 'netscape' +entry both 'TkRat' '/usr/share/pixmaps/gnome-ccdesktop.png' 'tkrat' +entry both 'X Chat' '/usr/share/pixmaps/gnome-irc.png' 'xchat' +entry both 'XMMS' '/usr/share/pixmaps/mc/gnome-audio.png' 'xmms' +entry both 'The GIMP' '/usr/share/pixmaps/gimp.png' 'gimp' +entry separator +entry both 'XTerm' '/usr/share/pixmaps/gnome-term.png' 'xterm' +entry both 'XMag' '/usr/share/pixmaps/gnome-applets.png' 'xmag' +entry separator +entry text 'Network' 'sub' 1 +entry text 'System' 'sub' 2 +end_menu + +menu 1 +entry text 'Ethernet On' 'sudo -S /sbin/ifup eth0' +entry text 'Ethernet Off' 'sudo -S /sbin/ifdown eth0' +end_menu + +menu 2 +entry text 'Shut Down' 'sudo -S /sbin/shutdown -h now' +entry text 'Reboot' 'sudo -S /sbin/shutdown -r now' +end_menu + +finish diff --git a/src/border.c b/src/border.c index 1e6256baf..400256f5b 100644 --- a/src/border.c +++ b/src/border.c @@ -75,7 +75,7 @@ e_idle(void *data) evas_render(b->evas.b); } } - e_db_runtime_flush(); + e_db_flush(); return; UN(data); } diff --git a/src/config.c b/src/config.c index b251ee11a..82cd904fa 100644 --- a/src/config.c +++ b/src/config.c @@ -16,7 +16,8 @@ static char cfg_grabs_db[4096] = ""; static char cfg_settings_db[4096] = ""; static char cfg_actions_db[4096] = ""; static char cfg_borders_db[4096] = ""; -static char cfg_menus_db[4096] = ""; +static char cfg_apps_menu_db[4096] = ""; +static char cfg_menus_dir[4096] = ""; static char cfg_user_dir[4096] = ""; static char cfg_images_dir[4096] = ""; static char cfg_fonts_dir[4096] = ""; @@ -45,9 +46,11 @@ e_config_get(char *type) PACKAGE_DATA_DIR"/data/config/behavior/default/settings.db"); E_CONF("actions", cfg_actions_db, PACKAGE_DATA_DIR"/data/config/behavior/default/actions.db"); + E_CONF("apps_menu", cfg_apps_menu_db, + PACKAGE_DATA_DIR"/data/config/behavior/default/apps_menu.db"); E_CONF("borders", cfg_borders_db, PACKAGE_DATA_DIR"/data/config/appearance/default/borders/"); - E_CONF("menus", cfg_menus_db, + E_CONF("menus", cfg_menus_dir, PACKAGE_DATA_DIR"/data/config/appearance/default/menus/"); E_CONF("images", cfg_images_dir, PACKAGE_DATA_DIR"/data/images/"); diff --git a/src/desktops.c b/src/desktops.c index 0319b2d15..a54a76550 100644 --- a/src/desktops.c +++ b/src/desktops.c @@ -26,7 +26,7 @@ e_idle(void *data) desk = l->data; e_desktops_update(desk); } - e_db_runtime_flush(); + e_db_flush(); return; UN(data); } @@ -132,112 +132,22 @@ e_mouse_down(Eevent * ev) evas_event_button_down(evas, x, y, e->button); if (e->button == 1) { - int count; static E_Menu *menu = NULL; - char buf[4096]; + static E_Build_Menu *buildmenu = NULL; - if (!menu) + if (!buildmenu) { - menu = e_menu_new(); - menu->pad.icon = 2; - menu->pad.state = 2; - for (count = 1; count <= 16; count++) - { - int count2; - E_Menu *menu2; - E_Menu_Item *menuitem; - char *icons[] = - { - "cd.png", - "drawer_closed.png", - "drawer_cube_closed.png", - "drawer_cube_open.png", - "drawer_cube_open_socks.png", - "drawer_image_closed.png", - "drawer_image_open.png", - "drawer_image_open_socks.png", - "drawer_light_closed.png", - "drawer_light_open.png", - "drawer_light_open_socks.png", - "drawer_open.png", - "drawer_open_socks.png", - "drawer_palette_closed.png", - "drawer_palette_open.png", - "drawer_palette_open_socks.png", - "drawer_style_closed.png", - "drawer_style_open.png", - "drawer_style_open_socks.png", - "drawer_text_closed.png", - "drawer_text_open.png", - "drawer_text_open_socks.png", - "palette.png", - "quake3.png", - "trash_closed.png", - "trash_full_closed.png", - "trash_full_open.png", - "trash_open.png", - "watch.png" - }; - - sprintf(buf, "Menu item %i", count); - menuitem = e_menu_item_new(buf); - sprintf(buf, "/home/raster/icons/%s", icons[rand() % 29]); - menuitem->icon = strdup(buf); - menuitem->scale_icon = 1; - menuitem->radio = rand() & 0x1; - menuitem->check = rand() & 0x1; - menuitem->on = rand() & 0x1; - if (count < 10) - { - menu2 = e_menu_new(); - menu2->pad.icon = 2; - menu2->pad.state = 2; - menuitem->submenu = menu2; - } - e_menu_add_item(menu, menuitem); - if (count < 10) - { - for (count2 = 1; count2 <= 14; count2++) - { - E_Menu_Item *menuitem2; - E_Menu *menu3; - int count3; - - sprintf(buf, "Submenu item %i", count2); - if (!(rand()%3)) menuitem2 = e_menu_item_new(buf); - else menuitem2 = e_menu_item_new(""); - menu3 = e_menu_new(); - menu3->pad.icon = 2; - menu3->pad.state = 2; - menuitem2->submenu = menu3; - sprintf(buf, "/home/raster/icons/%s", icons[rand() % 29]); - if (!(rand()%3)) menuitem2->icon = strdup(buf); - menuitem2->scale_icon = 1; - menuitem2->radio = rand() & 0x1; - menuitem2->check = rand() & 0x1; - menuitem2->on = rand() & 0x1; - if (!(rand()%3)) menuitem2->separator = 1; - e_menu_add_item(menu2, menuitem2); - for (count3 = 1; count3 <= 12; count3++) - { - E_Menu_Item *menuitem3; - - sprintf(buf, "Submenu item %i", count3); - menuitem3 = e_menu_item_new(NULL); - sprintf(buf, "/home/raster/icons/%s", icons[rand() % 29]); - menuitem3->icon = strdup(buf); - menuitem3->scale_icon = 1; - menuitem3->radio = rand() & 0x1; - menuitem3->check = rand() & 0x1; - menuitem3->on = rand() & 0x1; - if (!(rand()%3)) menuitem3->separator = 1; - e_menu_add_item(menu3, menuitem3); - } - } - } - } + char *apps_menu_db; + + apps_menu_db = e_config_get("apps_menu"); + if (apps_menu_db) buildmenu = e_build_menu_new_from_db(apps_menu_db); + } + if (buildmenu) + { + menu = buildmenu->menu; + if (menu) + e_menu_show_at_mouse(menu, e->rx, e->ry, e->time); } - e_menu_show_at_mouse(menu, e->rx, e->ry, e->time); } if (e->button == 3) e_exec_restart(); diff --git a/src/e.h b/src/e.h index 7008ed4b2..088db4b58 100644 --- a/src/e.h +++ b/src/e.h @@ -132,6 +132,7 @@ typedef struct _E_Active_Action_Timer E_Active_Action_Timer; typedef struct _E_View E_View; typedef struct _E_Menu E_Menu; typedef struct _E_Menu_Item E_Menu_Item; +typedef struct _E_Build_Menu E_Build_Menu; struct _E_Object { @@ -382,6 +383,19 @@ struct _E_Menu_Item void *func_select_data; }; +struct _E_Build_Menu +{ + OBJ_PROPERTIES; + + char *file; + time_t mod_time; + + E_Menu *menu; + + Evas_List menus; + Evas_List commands; +}; + void e_action_add_proto(char *action, void (*func_start) (void *o, E_Action *a, void *data, int x, int y, int rx, int ry), void (*func_stop) (void *o, E_Action *a, void *data, int x, int y, int rx, int ry), @@ -513,3 +527,9 @@ void e_menu_update_finish(E_Menu *m); void e_menu_update_shows(E_Menu *m); void e_menu_update_hides(E_Menu *m); void e_menu_update(E_Menu *m); + +void e_build_menu_unbuild(E_Build_Menu *bm); +E_Menu *e_build_menu_build_number(E_Build_Menu *bm, E_DB_File *db, int num); +void e_build_menu_build(E_Build_Menu *bm); +void e_build_menu_free(E_Build_Menu *bm); +E_Build_Menu *e_build_menu_new_from_db(char *file); diff --git a/src/menu.c b/src/menu.c index 9d9ecafc2..40d7a0c9b 100644 --- a/src/menu.c +++ b/src/menu.c @@ -171,7 +171,7 @@ e_idle(void *data) if (m->first_expose) evas_render(m->evas); } - e_db_runtime_flush(); + e_db_flush(); return; UN(data); } diff --git a/src/menudb.c b/src/menudb.c index 1c816a6a0..a6c758f6b 100644 --- a/src/menudb.c +++ b/src/menudb.c @@ -1 +1,168 @@ #include "e.h" + +Evas_List build_menus = NULL; + +static void e_build_menu_poll(int val, void *data); + +static void +e_build_menu_poll(int val, void *data) +{ + time_t mod; + E_Build_Menu *bm; + + bm = data; + mod = e_file_modified_time(bm->file); + if (mod <= bm->mod_time) + { + e_add_event_timer(bm->file, 1.0, e_build_menu_poll, 0, data); + return; + } + bm->mod_time = mod; + + e_build_menu_unbuild(bm); + e_build_menu_build(bm); + if (!bm->menu) bm->mod_time = 0; + + e_add_event_timer(bm->file, 1.0, e_build_menu_poll, 0, data); + UN(val); +} + +static void +e_build_menu_cb_exec(E_Menu *m, E_Menu_Item *mi, void *data) +{ + char *exe; + + exe = data; + e_exec_run(exe); + UN(m); + UN(mi); +} + +void +e_build_menu_unbuild(E_Build_Menu *bm) +{ + Evas_List l; + + bm->menu = NULL; + if (bm->menus) + { + for (l = bm->menus; l; l = l->next) + { + E_Menu *m; + + m = l->data; + e_menu_hide(m); + e_menu_update_shows(m); + e_menu_update_hides(m); + e_menu_update_finish(m); + OBJ_DO_FREE(m); + } + bm->menus = evas_list_free(bm->menus); + } + if (bm->commands) + { + for (l = bm->commands; l; l = l->next) + { + IF_FREE(l->data); + } + bm->commands = evas_list_free(bm->commands); + } +} + +E_Menu * +e_build_menu_build_number(E_Build_Menu *bm, E_DB_File *db, int num) +{ + E_Menu *menu; + char buf[4096]; + int num2, i2; + + sprintf(buf, "/menu/%i/count", num); + if (!e_db_int_get(db, buf, &num2)) return NULL; + menu = e_menu_new(); + menu->pad.icon = 2; + menu->pad.state = 2; + for (i2 = 0; i2 < num2; i2++) + { + E_Menu_Item *menuitem; + char *text, *icon, *exe; + int ok, sub, sep; + + sprintf(buf, "/menu/%i/%i/text", num, i2); + text = e_db_str_get(db, buf); + sprintf(buf, "/menu/%i/%i/icon", num, i2); + icon = e_db_str_get(db, buf); + sprintf(buf, "/menu/%i/%i/command", num, i2); + exe = e_db_str_get(db, buf); + sprintf(buf, "/menu/%i/%i/submenu", num, i2); + ok = e_db_int_get(db, buf, &sub); + sep = 0; + sprintf(buf, "/menu/%i/%i/separator", num, i2); + e_db_int_get(db, buf, &sep); + menuitem = e_menu_item_new(text); + menuitem->icon = icon; + if ((icon) && (text)) menuitem->scale_icon = 1; + if (sep) + menuitem->separator = 1; + else + { + if (ok) + { + E_Menu *menu2; + + menu2 = e_build_menu_build_number(bm, db, sub); + menuitem->submenu = menu2; + } + } + if (exe) + { + e_menu_item_set_callback(menuitem, e_build_menu_cb_exec, exe); + bm->commands = evas_list_prepend(bm->commands, exe); + } + e_menu_add_item(menu, menuitem); + } + bm->menus = evas_list_prepend(bm->menus, menu); + return menu; +} + +void +e_build_menu_build(E_Build_Menu *bm) +{ + E_DB_File *db; + int num; + + e_db_flush(); + db = e_db_open_read(bm->file); + if (!db) return; + + if (!e_db_int_get(db, "/menu/count", &num)) goto error; + if (num > 0) bm->menu = e_build_menu_build_number(bm, db, 0); + error: + e_db_close(db); +} + +void +e_build_menu_free(E_Build_Menu *bm) +{ + e_del_event_timer(bm->file); + e_build_menu_unbuild(bm); + IF_FREE(bm->file); + build_menus = evas_list_remove(build_menus, bm); + FREE(bm); +} + +E_Build_Menu * +e_build_menu_new_from_db(char *file) +{ + E_Build_Menu *bm; + + if (!file) return NULL; + bm = NEW(E_Build_Menu, 1); + ZERO(bm, E_Build_Menu, 1); + OBJ_INIT(bm, e_build_menu_free); + + bm->file = strdup(file); + + build_menus = evas_list_prepend(build_menus, bm); + e_build_menu_poll(0, bm); + return bm; +}