From a8094c93299235213264cdbff2ced9403614b553 Mon Sep 17 00:00:00 2001 From: jlzapata Date: Tue, 14 Feb 2006 02:32:14 +0000 Subject: [PATCH] efm: - actions working, for test cases it only has: "edit with gimp", "play with xmms" and "enqueue on xmms". test it :) SVN revision: 20448 --- src/bin/e_fileman_file.c | 2 + src/bin/e_fileman_mime.c | 103 ++++++++++++++++++++++++++++++++++++-- src/bin/e_fileman_mime.h | 13 ++--- src/bin/e_fileman_smart.c | 15 ++++-- 4 files changed, 119 insertions(+), 14 deletions(-) diff --git a/src/bin/e_fileman_file.c b/src/bin/e_fileman_file.c index c22782aea..499f3bf7f 100644 --- a/src/bin/e_fileman_file.c +++ b/src/bin/e_fileman_file.c @@ -398,6 +398,8 @@ e_fm_file_assoc_exec(E_Fm_File *file) return 1; } + +/* FIXME get rid of this */ EAPI int e_fm_file_exec_with(E_Fm_File *file, char* exec_with) { diff --git a/src/bin/e_fileman_mime.c b/src/bin/e_fileman_mime.c index 1a01437d3..1580229fb 100644 --- a/src/bin/e_fileman_mime.c +++ b/src/bin/e_fileman_mime.c @@ -70,6 +70,7 @@ static char * _e_fm_mime_suffix_get(char *filename); static void _e_fm_mime_action_append(E_Fm_Mime_Entry *entry, char *action_name); +static char *_e_fm_mime_action_tokenizer(Evas_List *files, E_Fm_Mime_Action *action); static int init_count = 0; static Evas_List *entries = NULL; @@ -313,16 +314,112 @@ e_fm_mime_set(E_Fm_File *file) file->mime = (E_Fm_Mime_Entry*)entries->data; } -/* will call the command of an @action for the list of @files */ -void +E_Fm_Mime_Action * +e_fm_mime_action_get_by_label(char *label) +{ + Evas_List *l; + E_Fm_Mime_Action *action = NULL; + + for(l = actions; l; l = l->next) + { + action = (E_Fm_Mime_Action*)l->data; + if(!strcmp(label,action->label)) + break; + } + return action; +} + +/* will call the command of an @action for the list of E_Fm_Files @files */ +int e_fm_mime_action_call(Evas_List *files, E_Fm_Mime_Action *action) { - printf("executing\n"); + Ecore_Exe *exe; + char *command; + + /* FIXME: use the e app execution mechanisms where possible so we can + * collect error output + */ + command = _e_fm_mime_action_tokenizer(files,action); + printf("going to execute %s\n", command); + exe = ecore_exe_run(command, NULL); + + if (!exe) + { + e_error_dialog_show(_("Run Error"), + _("Enlightenment was unable to fork a child process:\n" + "\n" + "%s\n" + "\n"), + command); + return 0; + } + return 1; } /* subsystem functions */ /***********************/ +static char* +_e_fm_mime_action_tokenizer(Evas_List *files, E_Fm_Mime_Action *action) +{ + char *buf; + char *c; + int i, bsize,trans; + Evas_List *l; + + buf = calloc(PATH_MAX,sizeof(char)); + bsize = PATH_MAX; + i = 0; + trans = 0; + for(c = action->cmd; *c; c++) + { + if( i > bsize - 1) + { + bsize += PATH_MAX; + buf = realloc(buf,bsize); + } + if(trans) + { + char *astr = NULL; + if(*c == 'f') + { + int i = 2; + char *f = NULL; + + astr = calloc(PATH_MAX,sizeof(char)); + for(l = files; l; l = l->next) + { + E_Fm_File *file; + + file = (E_Fm_File *)l->data; + sprintf(astr,"%s %s",astr,file->path); + astr = realloc(astr,PATH_MAX*i); + i++; + } + } + if(!astr) + continue; + if(bsize < i + strlen(astr)) + { + bsize += strlen(astr) + 1; + buf = realloc(buf,bsize); + } + buf[i-1] = '\0'; + sprintf(buf, "%s%s", buf, astr); + i += strlen(astr) - 1; + trans = 0; + free(astr); + continue; + } + if(*c == '%') + trans = 1; + else + buf[i] = *c; + i++; + } + return buf; +} + static void _e_fm_mime_action_append(E_Fm_Mime_Entry *entry, char *action_name) diff --git a/src/bin/e_fileman_mime.h b/src/bin/e_fileman_mime.h index f97c67fe2..532b472d9 100644 --- a/src/bin/e_fileman_mime.h +++ b/src/bin/e_fileman_mime.h @@ -32,12 +32,13 @@ struct _E_Fm_Mime_Action int multiple; /* support for multiple files at once */ }; -EAPI int e_fm_mime_init(void); -EAPI void e_fm_mime_shutdwon(void); -EAPI void e_fm_mime_set(E_Fm_File *file); -EAPI void e_fm_mime_action_call(Evas_List *files, E_Fm_Mime_Action *action); -EAPI E_Fm_Mime_Entry *e_fm_mime_common(E_Fm_Mime_Entry *e1, E_Fm_Mime_Entry *e2); -EAPI E_Fm_Mime_Entry *e_fm_mime_list(Evas_List *mis); +EAPI int e_fm_mime_init(void); +EAPI void e_fm_mime_shutdwon(void); +EAPI void e_fm_mime_set(E_Fm_File *file); +EAPI int e_fm_mime_action_call(Evas_List *files, E_Fm_Mime_Action *action); +EAPI E_Fm_Mime_Entry *e_fm_mime_common(E_Fm_Mime_Entry *e1, E_Fm_Mime_Entry *e2); +EAPI E_Fm_Mime_Entry *e_fm_mime_list(Evas_List *mis); +EAPI E_Fm_Mime_Action *e_fm_mime_action_get_by_label(char *label); #endif diff --git a/src/bin/e_fileman_smart.c b/src/bin/e_fileman_smart.c index 64eeba954..d5f6a6b07 100644 --- a/src/bin/e_fileman_smart.c +++ b/src/bin/e_fileman_smart.c @@ -3893,22 +3893,27 @@ _e_fm_menu_context_display(E_Fm_Smart_Data *sd, Evas_Coord dx, Evas_Coord dy, un ; } +/* callback when a mime action is clicked on the actions menu */ static void _e_fm_menu_actions(void *data, E_Menu *m, E_Menu_Item *mi) { E_Fm_Smart_Data *sd; E_Fm_Mime_Action *action; Evas_List *l; + Evas_List *files = NULL; sd = data; /* search for the action clicked */ - for(l = sd->selection.mime; l; l = l->next) + action = e_fm_mime_action_get_by_label(mi->label); + /* get the list of files selected */ + for(l = sd->selection.icons; l; l = l->next) { - action = (E_Fm_Mime_Action*)l->data; - if(!strcmp(action->label,mi->label)) - break; + E_Fm_Icon *icon; + + icon = (E_Fm_Icon *)l->data; + files = evas_list_append(files,icon->file); } /* execute the action on the files */ - + e_fm_mime_action_call(files,action); }