From 0407e51787d60549dbaa2e343dd393cf66796013 Mon Sep 17 00:00:00 2001 From: Carsten Haitzler Date: Thu, 2 Dec 2004 04:24:54 +0000 Subject: [PATCH] new eapp file format.. now to do the file layout arrangement we discussed... btw - u'll need to update eet for this... SVN revision: 12330 --- src/bin/Makefile.am | 8 +- src/bin/e_apps.c | 132 ++++++++++++++++----- src/bin/e_eapp_main.c | 246 ++++++++++++++++++++++++++++++++++++++++ src/bin/e_main.c | 7 +- src/bin/e_remote_main.c | 192 +++++++++++++++++++++---------- 5 files changed, 495 insertions(+), 90 deletions(-) create mode 100644 src/bin/e_eapp_main.c diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am index 33a5ad7c0..762daea83 100644 --- a/src/bin/Makefile.am +++ b/src/bin/Makefile.am @@ -6,7 +6,7 @@ INCLUDES = -I$(includedir) \ @e_cflags@ \ @EDJE_DEF@ -bin_PROGRAMS = enlightenment enlightenment_remote +bin_PROGRAMS = enlightenment enlightenment_remote enlightenment_eapp enlightenment_SOURCES = \ e.h \ @@ -67,3 +67,9 @@ e.h \ e_remote_main.c enlightenment_remote_LDFLAGS = @e_libs@ @dlopen_libs@ + +enlightenment_eapp_SOURCES = \ +e.h \ +e_eapp_main.c + +enlightenment_eapp_LDFLAGS = @e_libs@ @dlopen_libs@ diff --git a/src/bin/e_apps.c b/src/bin/e_apps.c index 529e24dc9..e45d38de7 100644 --- a/src/bin/e_apps.c +++ b/src/bin/e_apps.c @@ -2,7 +2,7 @@ /* TODO List: * - * * if a application .eet file is added in a different location in a monitored app tree but has the same filename as an existing one somewhere else, the existing one gets a changed callback, not an dded callback for the new one + * * if a application .eapp file is added in a different location in a monitored app tree but has the same filename as an existing one somewhere else, the existing one gets a changed callback, not an dded callback for the new one * * track app execution state, visibility state etc. and call callbacks * * calls to execute an app or query its runing/starting state etc. */ @@ -80,7 +80,7 @@ e_app_new(char *path, int scan_subdirs) char buf[4096]; a->path = strdup(path); - snprintf(buf, sizeof(buf), "%s/.directory.eet", path); + snprintf(buf, sizeof(buf), "%s/.directory.eapp", path); a->directory_mod_time = e_file_mod_time(buf); if (e_file_exists(buf)) _e_app_fields_fill(a, buf); @@ -92,7 +92,7 @@ e_app_new(char *path, int scan_subdirs) { char *p; - /* check if file ends in .eet */ + /* check if file ends in .eapp */ p = strrchr(path, '.'); if (!p) { @@ -100,7 +100,7 @@ e_app_new(char *path, int scan_subdirs) return NULL; } p++; - if (strcasecmp(p, "eet")) + if (strcasecmp(p, "eapp")) { free(a); return NULL; @@ -283,45 +283,119 @@ _e_app_free(E_App *a) static void _e_app_fields_fill(E_App *a, char *path) { + Eet_File *ef; char buf[4096]; - char *str; + char *str, *v; char *lang; + int size; /* get our current language */ lang = getenv("LANG"); /* if its "C" its the default - so drop it */ if ((lang) && (!strcmp(lang, "C"))) lang = NULL; - /* get fields (language local preferred) */ - if (lang) + ef = eet_open(a->path, EET_FILE_MODE_READ); + if (!ef) return; + if (lang) snprintf(buf, sizeof(buf), "app/info/name[%s]", lang); + v = eet_read(ef, buf, &size); + if (v) { - snprintf(buf, sizeof(buf), "app/name[%s]", lang); - a->name = edje_file_data_get(path, buf); + str = malloc(size + 1); + memcpy(str, v, size); + str[size] = 0; + a->name = str; + free(v); } - if (!a->name) a->name = edje_file_data_get(path, "app/name"); - if (lang) + else { - snprintf(buf, sizeof(buf), "app/generic[%s]", lang); - a->generic = edje_file_data_get(path, buf); + v = eet_read(ef, "app/info/name", &size); + if (v) + { + str = malloc(size + 1); + memcpy(str, v, size); + str[size] = 0; + a->name = str; + free(v); + } } - if (!a->generic) a->generic = edje_file_data_get(path, "app/generic"); - if (lang) + if (lang) snprintf(buf, sizeof(buf), "app/info/generic[%s]", lang); + v = eet_read(ef, buf, &size); + if (v) { - snprintf(buf, sizeof(buf), "app/comment[%s]", lang); - a->comment = edje_file_data_get(path, buf); + str = malloc(size + 1); + memcpy(str, v, size); + str[size] = 0; + a->generic = str; + free(v); } - if (!a->comment) a->comment = edje_file_data_get(path, "app/comment"); - - a->exe = edje_file_data_get(path, "app/exe"); - a->win_name = edje_file_data_get(path, "app/window/name"); - a->win_class = edje_file_data_get(path, "app/window/class"); - - str = edje_file_data_get(path, "app/startup_notify"); - if (str) + else { - a->startup_notify = atoi(str); - free(str); + v = eet_read(ef, "app/info/generic", &size); + if (v) + { + str = malloc(size + 1); + memcpy(str, v, size); + str[size] = 0; + a->generic = str; + free(v); + } } + if (lang) snprintf(buf, sizeof(buf), "app/info/comment[%s]", lang); + v = eet_read(ef, buf, &size); + if (v) + { + str = malloc(size + 1); + memcpy(str, v, size); + str[size] = 0; + a->comment = str; + free(v); + } + else + { + v = eet_read(ef, "app/info/comment", &size); + if (v) + { + str = malloc(size + 1); + memcpy(str, v, size); + str[size] = 0; + a->comment = str; + free(v); + } + } + v = eet_read(ef, "app/info/exe", &size); + if (v) + { + str = malloc(size + 1); + memcpy(str, v, size); + str[size] = 0; + a->exe = str; + free(v); + } + v = eet_read(ef, "app/window/name", &size); + if (v) + { + str = malloc(size + 1); + memcpy(str, v, size); + str[size] = 0; + a->win_name = str; + free(v); + } + v = eet_read(ef, "app/window/class", &size); + if (v) + { + str = malloc(size + 1); + memcpy(str, v, size); + str[size] = 0; + a->win_class = str; + free(v); + } + v = eet_read(ef, "app/info/startup_notify", &size); + if (v) + { + a->startup_notify = *v; + free(v); + } + eet_close(ef); } static void @@ -567,7 +641,7 @@ _e_app_check_each(Evas_Hash *hash, const char *key, void *data, void *fdata) mod_time = e_file_mod_time(a->path); snprintf(buf, sizeof(buf), "%s/.order", a->path); order_mod_time = e_file_mod_time(buf); - snprintf(buf, sizeof(buf), "%s/.directory.eet", a->path); + snprintf(buf, sizeof(buf), "%s/.directory.eapp", a->path); directory_mod_time = e_file_mod_time(buf); if ((mod_time != a->mod_time) || (order_mod_time != a->order_mod_time) || @@ -594,7 +668,7 @@ _e_app_check_each(Evas_Hash *hash, const char *key, void *data, void *fdata) } if (directory_mod_time != a->directory_mod_time) { - snprintf(buf, sizeof(buf), "%s/.directory.eet", a->path); + snprintf(buf, sizeof(buf), "%s/.directory.eapp", a->path); _e_app_fields_empty(a); _e_app_fields_fill(a, buf); ch = calloc(1, sizeof(E_App_Change_Info)); diff --git a/src/bin/e_eapp_main.c b/src/bin/e_eapp_main.c new file mode 100644 index 000000000..9426014f3 --- /dev/null +++ b/src/bin/e_eapp_main.c @@ -0,0 +1,246 @@ +#include "e.h" + +/* FIXME: handle LANG!!!! */ + +static void _e_help(void); + +/* externally accessible functions */ +int +main(int argc, char **argv) +{ + int i; + Eet_File *ef; + char buf[4096]; + + char *lang = NULL; + int del_name = 0; + int del_generic = 0; + int del_comment = 0; + int del_exe = 0; + int del_win_name = 0; + int del_win_class = 0; + int del_startup_notify = 0; + char *file = NULL; + char *set_name = NULL; + char *set_generic = NULL; + char *set_comment = NULL; + char *set_exe = NULL; + char *set_win_name = NULL; + char *set_win_class = NULL; + int set_startup_notify = -1; + + /* handle some command-line parameters */ + for (i = 1; i < argc; i++) + { + if ((!strcmp(argv[i], "-lang")) && (i < (argc - 1))) + { + i++; + lang = argv[i]; + } + else if ((!strcmp(argv[i], "-set-name")) && (i < (argc - 1))) + { + i++; + set_name = argv[i]; + } + else if ((!strcmp(argv[i], "-set-generic")) && (i < (argc - 1))) + { + i++; + set_generic = argv[i]; + } + else if ((!strcmp(argv[i], "-set-comment")) && (i < (argc - 1))) + { + i++; + set_comment = argv[i]; + } + else if ((!strcmp(argv[i], "-set-exe")) && (i < (argc - 1))) + { + i++; + set_exe = argv[i]; + } + else if ((!strcmp(argv[i], "-set-win-name")) && (i < (argc - 1))) + { + i++; + set_win_name = argv[i]; + } + else if ((!strcmp(argv[i], "-set-win-class")) && (i < (argc - 1))) + { + i++; + set_win_class = argv[i]; + } + else if ((!strcmp(argv[i], "-set-win-class")) && (i < (argc - 1))) + { + i++; + set_win_class = argv[i]; + } + else if ((!strcmp(argv[i], "-set-startup-notify")) && (i < (argc - 1))) + { + i++; + set_startup_notify = atoi(argv[i]); + } + else if ((!strcmp(argv[i], "-del-all"))) + { + del_name = 1; + del_generic = 1; + del_comment = 1; + del_exe = 1; + del_win_name = 1; + del_win_class = 1; + } + else if ((!strcmp(argv[i], "-del-name"))) + { + del_name = 1; + } + else if ((!strcmp(argv[i], "-del-generic"))) + { + del_generic = 1; + } + else if ((!strcmp(argv[i], "-del-comment"))) + { + del_comment = 1; + } + else if ((!strcmp(argv[i], "-del-exe"))) + { + del_exe = 1; + } + else if ((!strcmp(argv[i], "-del-win-name"))) + { + del_win_name = 1; + } + else if ((!strcmp(argv[i], "-del-win-class"))) + { + del_win_class = 1; + } + else if ((!strcmp(argv[i], "-del-startup-notify"))) + { + del_startup_notify = 1; + } + else if ((!strcmp(argv[i], "-h")) || + (!strcmp(argv[i], "-help")) || + (!strcmp(argv[i], "--h")) || + (!strcmp(argv[i], "--help"))) + { + _e_help(); + exit(0); + } + else + file = argv[i]; + } + if (!file) + { + printf("ERROR: no file specified!\n"); + _e_help(); + exit(0); + } + eet_init(); + ef = eet_open(file, EET_FILE_MODE_RW); + if (!ef) + { + printf("ERROR: cannot open file %s for READ/WRITE\n", file); + return -1; + } + if (set_name) + { + if (lang) snprintf(buf, sizeof(buf), "app/info/name[%s]", lang); + else snprintf(buf, sizeof(buf), "app/info/name"); + eet_write(ef, buf, set_name, strlen(set_name), 0); + } + if (set_generic) + { + if (lang) snprintf(buf, sizeof(buf), "app/info/generic[%s]", lang); + else snprintf(buf, sizeof(buf), "app/info/generic"); + eet_write(ef, buf, set_generic, strlen(set_generic), 0); + } + if (set_comment) + { + if (lang) snprintf(buf, sizeof(buf), "app/info/comment[%s]", lang); + else snprintf(buf, sizeof(buf), "app/info/comment"); + eet_write(ef, buf, set_comment, strlen(set_comment), 0); + } + if (set_exe) + eet_write(ef, "app/info/exe", set_exe, strlen(set_exe), 0); + if (set_win_name) + eet_write(ef, "app/window/name", set_win_name, strlen(set_win_name), 0); + if (set_win_class) + eet_write(ef, "app/window/class", set_win_class, strlen(set_win_class), 0); + if (set_startup_notify >= 0) + { + unsigned char tmp[1]; + + tmp[0] = set_startup_notify; + if (set_startup_notify) + eet_write(ef, "app/info/startup_notify", tmp, 1, 0); + else + eet_write(ef, "app/info/startup_notify", tmp, 1, 0); + } + if (del_name) + { + char **matches = NULL; + int match_num = 0; + + matches = eet_list(ef, "app/info/name*", &match_num); + if (matches) + { + for (i = 0; i < match_num; i++) eet_delete(ef, matches[i]); + free(matches); + } + } + if (del_generic) + { + char **matches = NULL; + int match_num = 0; + + matches = eet_list(ef, "app/info/generic*", &match_num); + if (matches) + { + for (i = 0; i < match_num; i++) eet_delete(ef, matches[i]); + free(matches); + } + } + if (del_comment) + { + char **matches = NULL; + int match_num = 0; + + matches = eet_list(ef, "app/info/comment*", &match_num); + if (matches) + { + for (i = 0; i < match_num; i++) eet_delete(ef, matches[i]); + free(matches); + } + } + if (del_exe) + eet_delete(ef, "app/info/exe"); + if (del_win_name) + eet_delete(ef, "app/window/name"); + if (del_win_class) + eet_delete(ef, "app/window/class"); + if (del_startup_notify) + eet_delete(ef, "app/info/startup_notify"); + + eet_close(ef); + eet_shutdown(); + /* just return 0 to keep the compiler quiet */ + return 0; +} + +static void +_e_help(void) +{ + printf("OPTIONS:\n" + " -lang LANG Set the language properties to modify\n" + " -set-name NAME Set the application name\n" + " -set-generic GENERIC Set the application generic name\n" + " -set-comment COMMENT Set the application comment\n" + " -set-exe EXE Set the application execute line\n" + " -set-win-name WIN_NAME Set the application window name\n" + " -set-win-class WIN_CLASS Set the application window class\n" + " -set-startup-notify [1/0] Set the application startup notify flag to on/off\n" + " -del-name Delete the application name\n" + " -del-generic Delete the application generic name\n" + " -del-comment Delete the application comment\n" + " -del-exe Delete the application execute line\n" + " -del-win-name Delete the application window name\n" + " -del-win-class Delete the application window class\n" + " -del-startup-notify Delete the application startup notify flag\n" + ); +} diff --git a/src/bin/e_main.c b/src/bin/e_main.c index 76ebc1494..051ea38ea 100644 --- a/src/bin/e_main.c +++ b/src/bin/e_main.c @@ -63,8 +63,11 @@ main(int argc, char **argv) { if ((!strcmp(argv[i], "-display")) && (i < (argc - 1))) { + char buf[1024]; i++; - display_name = argv[i]; + + snprintf(buf, sizeof(buf), "DISPLAY=%s", argv[i]); + putenv(buf); } } @@ -94,7 +97,7 @@ main(int argc, char **argv) _e_main_idle_enterer_before = ecore_idle_enterer_add(_e_main_cb_idler_before, NULL); /* init x */ - if (!ecore_x_init(display_name)) + if (!ecore_x_init(NULL)) { e_error_message_show("Enlightenment cannot initialize its X connection.\n" "Have you set your DISPLAY variable?"); diff --git a/src/bin/e_remote_main.c b/src/bin/e_remote_main.c index 85d68c8ce..f35a71dd8 100644 --- a/src/bin/e_remote_main.c +++ b/src/bin/e_remote_main.c @@ -1,5 +1,18 @@ #include "e.h" +typedef struct _E_IPC_Opt_Handler E_IPC_Opt_Handler; + +struct _E_IPC_Opt_Handler +{ + char *option; + char *desc; + int num_params; + int replies; + int type; + int simple_request_id; + void (*func) (char **params); +}; + /* local subsystem functions */ static int _e_cb_signal_exit(void *data, int ev_type, void *ev); static int _e_ipc_init(void); @@ -9,12 +22,32 @@ static int _e_ipc_cb_server_add(void *data, int type, void *event); static int _e_ipc_cb_server_del(void *data, int type, void *event); static int _e_ipc_cb_server_data(void *data, int type, void *event); +static void _e_help(void); + /* local subsystem globals */ static Ecore_Ipc_Server *_e_ipc_server = NULL; static const char *display_name = NULL; static int reply_count = 0; static int reply_expect = 0; +#define SIMPLE_REQ 0 +#define SIMPLE_STR_REQ 1 +#define FULL_FUNC 2 + +#define REQ(opt, desc, ipc, rep) {opt, desc, 0, rep, SIMPLE_REQ, ipc, NULL} +#define STR(opt, desc, ipc, rep) {opt, desc, 1, rep, SIMPLE_STR_REQ, ipc, NULL} +#define FNC(opt, desc, param, fn, rep) {opt, desc, param, rep, SIMPLE_FUNC, 0, fn} + +E_IPC_Opt_Handler handlers[] = +{ + STR("-module-load", "Load module OPT1 into memory", E_IPC_OP_MODULE_LOAD, 0), + STR("-module-unload", "Unload (and disable) module OPT1 from memory", E_IPC_OP_MODULE_UNLOAD, 0), + STR("-module-enable", "Enable module OPT1 if not enabled", E_IPC_OP_MODULE_ENABLE, 0), + STR("-module-disable", "Disable module OPT1 if not disabled", E_IPC_OP_MODULE_DISABLE, 0), + REQ("-module-list", "List all loaded modules and their states", E_IPC_OP_MODULE_LIST, 1), + STR("-bg-set", "Set the background edje file to be OPT1", E_IPC_OP_BG_SET, 0) +}; + /* externally accessible functions */ int main(int argc, char **argv) @@ -30,6 +63,14 @@ main(int argc, char **argv) i++; display_name = argv[i]; } + else if ((!strcmp(argv[i], "-h")) || + (!strcmp(argv[i], "-help")) || + (!strcmp(argv[i], "--h")) || + (!strcmp(argv[i], "--help"))) + { + _e_help(); + exit(0); + } } /* basic ecore init */ @@ -121,73 +162,63 @@ _e_ipc_cb_server_add(void *data, int type, void *event) int argc; char **argv; int i; + int process_count = 0; e = event; ecore_app_args_get(&argc, &argv); for (i = 1; i < argc; i++) { char *v; + int j; + + for (j = 0; j < (sizeof(handlers) / sizeof(E_IPC_Opt_Handler)); j++) + { + E_IPC_Opt_Handler *handler; - if ((!strcmp(argv[i], "-load-module")) && (i < (argc - 1))) - { - i++; - v = argv[i]; - ecore_ipc_server_send(_e_ipc_server, - E_IPC_DOMAIN_REQUEST, - E_IPC_OP_MODULE_LOAD, - 0/*ref*/, 0/*ref_to*/, 0/*response*/, - v, strlen(v)); + handler = &handlers[j]; + if (!strcmp(handler->option, argv[i])) + { + if (i >= (argc - handler->num_params)) + { + printf("ERROR: option %s expects %i parameters\n", + handler->option, handler->num_params); + exit(-1); + } + else + { + switch (handler->type) + { + case SIMPLE_REQ: + ecore_ipc_server_send(_e_ipc_server, + E_IPC_DOMAIN_REQUEST, + handler->simple_request_id, + 0/*ref*/, 0/*ref_to*/, 0/*response*/, + NULL, 0); + break; + case SIMPLE_STR_REQ: + v = argv[i + 1]; + ecore_ipc_server_send(_e_ipc_server, + E_IPC_DOMAIN_REQUEST, + handler->simple_request_id, + 0/*ref*/, 0/*ref_to*/, 0/*response*/, + v, strlen(v)); + break; + case FULL_FUNC: + handler->func(argv + i + 1); + break; + default: + break; + } + process_count++; + reply_expect += handler->replies; + i += handler->num_params; + break; + } + } } - else if ((!strcmp(argv[i], "-unload-module")) && (i < (argc - 1))) - { - i++; - v = argv[i]; - ecore_ipc_server_send(_e_ipc_server, - E_IPC_DOMAIN_REQUEST, - E_IPC_OP_MODULE_UNLOAD, - 0/*ref*/, 0/*ref_to*/, 0/*response*/, - v, strlen(v)); - } - else if ((!strcmp(argv[i], "-enable-module")) && (i < (argc - 1))) - { - i++; - v = argv[i]; - ecore_ipc_server_send(_e_ipc_server, - E_IPC_DOMAIN_REQUEST, - E_IPC_OP_MODULE_ENABLE, - 0/*ref*/, 0/*ref_to*/, 0/*response*/, - v, strlen(v)); - } - else if ((!strcmp(argv[i], "-disable-module")) && (i < (argc - 1))) - { - i++; - v = argv[i]; - ecore_ipc_server_send(_e_ipc_server, - E_IPC_DOMAIN_REQUEST, - E_IPC_OP_MODULE_DISABLE, - 0/*ref*/, 0/*ref_to*/, 0/*response*/, - v, strlen(v)); - } - else if ((!strcmp(argv[i], "-list-modules"))) - { - reply_expect++; - ecore_ipc_server_send(_e_ipc_server, - E_IPC_DOMAIN_REQUEST, - E_IPC_OP_MODULE_LIST, - 0/*ref*/, 0/*ref_to*/, 0/*response*/, - NULL, 0); - } - else if ((!strcmp(argv[i], "-bg-set")) && (i < (argc - 1))) - { - i++; - v = argv[i]; - ecore_ipc_server_send(_e_ipc_server, - E_IPC_DOMAIN_REQUEST, - E_IPC_OP_BG_SET, - 0/*ref*/, 0/*ref_to*/, 0/*response*/, - v, strlen(v)); - } } + if (process_count <= 0) + _e_help(); if (reply_count >= reply_expect) ecore_main_loop_quit(); return 1; } @@ -207,6 +238,8 @@ _e_ipc_cb_server_data(void *data, int type, void *event) Ecore_Ipc_Event_Server_Data *e; e = event; + /* FIXME: should make this function/callback based in a table like the */ + /* option handlers... */ printf("REPLY: BEGIN\n"); switch (e->minor) { @@ -247,3 +280,46 @@ _e_ipc_cb_server_data(void *data, int type, void *event) if (reply_count >= reply_expect) ecore_main_loop_quit(); return 1; } + +static void +_e_help(void) +{ + int j, k, l; + E_IPC_Opt_Handler *handler; + char buf[128]; + int parsize = 0, opsize = 0; + + printf("OPTIONS:\n"); + for (j = 0; j < (sizeof(handlers) / sizeof(E_IPC_Opt_Handler)); j++) + { + handler = &handlers[j]; + if (strlen(handler->option) > parsize) parsize = strlen(handler->option); + l = 0; + for (k = 0; k < handler->num_params; k++) + { + snprintf(buf, sizeof(buf), " OPT%i", k + 1); + l += strlen(buf); + } + if (l > opsize) opsize = l; + } + for (j = 0; j < (sizeof(handlers) / sizeof(E_IPC_Opt_Handler)); j++) + { + handler = &handlers[j]; + printf(" %s", handler->option); + l = parsize - strlen(handler->option); + for (k = 0; k < l; k++) printf(" "); + l = 0; + for (k = 0; k < handler->num_params; k++) + { + snprintf(buf, sizeof(buf), " OPT%i", k + 1); + printf("%s", buf); + l += strlen(buf); + } + while (l < opsize) + { + printf(" "); + l++; + } + printf(" - %s\n", handler->desc); + } +}