Enlightenment CVS committal Author : rephorm Project : e17 Module : libs/efreet
Dir : e17/libs/efreet/src/lib Modified Files: efreet_desktop.c efreet_desktop.h Log Message: add a function to get desktop commands immediately when no remote uri's are passed in =================================================================== RCS file: /cvs/e/e17/libs/efreet/src/lib/efreet_desktop.c,v retrieving revision 1.18 retrieving revision 1.19 diff -u -3 -r1.18 -r1.19 --- efreet_desktop.c 17 Jun 2007 08:29:20 -0000 1.18 +++ efreet_desktop.c 18 Jun 2007 04:26:50 -0000 1.19 @@ -68,7 +68,7 @@ int *len, const char *src); static char *efreet_string_append_char(char *dest, int *size, int *len, char c); -static void efreet_desktop_command_build(Efreet_Desktop_Command *command); +static Ecore_List *efreet_desktop_command_build(Efreet_Desktop_Command *command); static void efreet_desktop_command_free(Efreet_Desktop_Command *command); static char *efreet_desktop_command_append_quoted(char *dest, int *size, int *len, char *src); @@ -99,6 +99,8 @@ char *exec, int remaining); static void efreet_desktop_type_info_free(Efreet_Desktop_Type_Info *info); +static int efreet_desktop_command_flags_get(Efreet_Desktop *desktop); +static void efreet_desktop_command_execs_process(Efreet_Desktop_Command *command, Ecore_List *execs); /** * @internal @@ -1045,6 +1047,58 @@ return efreet_desktop_command_progress_get(desktop, files, func, NULL, data); } +/** + * @param desktop: the desktop entry + * @param files an ecore list of local files, as absolute paths, local paths, or file:// uris (or NULL to get exec string with no files appended) + * @return Returns an ecore list of exec strings + * @brief Get the command to use to execute a desktop entry + * + * The returned list and each of its elements must be freed. + */ +Ecore_List * +efreet_desktop_command_local_get(Efreet_Desktop *desktop, Ecore_List *files) +{ + Efreet_Desktop_Command *command; + char *file; + Ecore_List *execs; + + if (!desktop || !desktop->exec) return NULL; + + command = NEW(Efreet_Desktop_Command, 1); + if (!command) return 0; + + command->files = ecore_list_new(); + command->desktop = desktop; + + ecore_list_set_free_cb(command->files, + ECORE_FREE_CB(efreet_desktop_command_file_free)); + + command->flags = efreet_desktop_command_flags_get(desktop); + /* get the required info for each file passed in */ + if (files) + { + ecore_list_goto_first(files); + while ((file = ecore_list_next(files))) + { + Efreet_Desktop_Command_File *dcf; + + dcf = efreet_desktop_command_file_process(command, file); + if (!dcf) continue; + if (dcf->pending) + { + efreet_desktop_command_file_free(dcf); + continue; + } + ecore_list_append(command->files, dcf); + } + } + + execs = efreet_desktop_command_build(command); + efreet_desktop_command_free(command); + + return execs; +} + /** * @param desktop: the desktop entry @@ -1063,7 +1117,6 @@ Efreet_Desktop_Progress_Cb cb_progress, void *data) { - char *p; Efreet_Desktop_Command *command; char *file; @@ -1081,6 +1134,46 @@ ecore_list_set_free_cb(command->files, ECORE_FREE_CB(efreet_desktop_command_file_free)); + command->flags = efreet_desktop_command_flags_get(desktop); + /* get the required info for each file passed in */ + if (files) + { + ecore_list_goto_first(files); + while ((file = ecore_list_next(files))) + { + Efreet_Desktop_Command_File *dcf; + + dcf = efreet_desktop_command_file_process(command, file); + if (!dcf) continue; + ecore_list_append(command->files, dcf); + command->num_pending += dcf->pending; + } + } + + if (command->num_pending == 0) + { + Ecore_List *execs; + execs = efreet_desktop_command_build(command); + efreet_desktop_command_execs_process(command, execs); + ecore_list_destroy(execs); + efreet_desktop_command_free(command); + } + + return 1; +} + +/** + * @internal + * + * @brief Determine which file related field codes are present in the Exec string of a .desktop + * @params desktop and Efreet Desktop + * @return a bitmask of file field codes present in exec string + */ +static int +efreet_desktop_command_flags_get(Efreet_Desktop *desktop) +{ + int flags = 0; + const char *p; /* first, determine which fields are present in the Exec string */ p = strchr(desktop->exec, '%'); while (p) @@ -1090,19 +1183,19 @@ { case 'f': case 'F': - command->flags |= EFREET_DESKTOP_EXEC_FLAG_FULLPATH; + flags |= EFREET_DESKTOP_EXEC_FLAG_FULLPATH; break; case 'u': case 'U': - command->flags |= EFREET_DESKTOP_EXEC_FLAG_URI; + flags |= EFREET_DESKTOP_EXEC_FLAG_URI; break; case 'd': case 'D': - command->flags |= EFREET_DESKTOP_EXEC_FLAG_DIR; + flags |= EFREET_DESKTOP_EXEC_FLAG_DIR; break; case 'n': case 'N': - command->flags |= EFREET_DESKTOP_EXEC_FLAG_FILE; + flags |= EFREET_DESKTOP_EXEC_FLAG_FILE; break; case '%': p++; @@ -1113,25 +1206,28 @@ p = strchr(p, '%'); } + return flags; +} - /* get the required info for each file passed in */ - if (files) - { - ecore_list_goto_first(files); - while ((file = ecore_list_next(files))) - { - Efreet_Desktop_Command_File *dcf; - dcf = efreet_desktop_command_file_process(command, file); - if (!dcf) continue; - ecore_list_append(command->files, dcf); - command->num_pending += dcf->pending; - } +/** + * @internal + * + * @brief Call the command callback for each exec in the list + * @param command + * @param execs + */ +static void +efreet_desktop_command_execs_process(Efreet_Desktop_Command *command, Ecore_List *execs) +{ + char *exec; + int num; + num = ecore_list_nodes(execs); + ecore_list_goto_first(execs); + while ((exec = ecore_list_next(execs))) + { + command->cb_command(command->data, command->desktop, exec, --num); } - - if (command->num_pending == 0) efreet_desktop_command_build(command); - - return 1; } @@ -1141,14 +1237,13 @@ * efreet_desktop_command_get is called for each exec string created. * * @param command: the command to build - * @return Nothing is returned + * @return a list of executable strings */ -static void +static Ecore_List * efreet_desktop_command_build(Efreet_Desktop_Command *command) { Efreet_Desktop_Command_File *file = NULL; int first = 1; - int num = 0; Ecore_List *execs; char *exec; @@ -1243,21 +1338,13 @@ exec[len++] = '\0'; ecore_list_append(execs, exec); - num++; /* If no file was added, then the Exec field doesn't contain any file * fields (fFuUdDnN). We only want to run the app once in this case. */ if (!file_added) break; } - ecore_list_goto_first(execs); - while ((exec = ecore_list_next(execs))) - { - command->cb_command(command->data, command->desktop, exec, --num); - } - - efreet_desktop_command_free(command); - ecore_list_destroy(execs); + return execs; } static void @@ -1459,7 +1546,6 @@ snprintf(buf, PATH_MAX, "/tmp/%d-%d-%s", getpid(), efreet_desktop_command_file_id++, base); - printf("nonlocal fullpath: %s\n", buf); f->fullpath = strdup(buf); f->pending = 1; @@ -1580,7 +1666,13 @@ f->command->num_pending--; if (f->command->num_pending <= 0) - efreet_desktop_command_build(f->command); + { + Ecore_List *execs; + execs = efreet_desktop_command_build(f->command); + efreet_desktop_command_execs_process(f->command, execs); + ecore_list_destroy(execs); + efreet_desktop_command_free(f->command); + } } static int =================================================================== RCS file: /cvs/e/e17/libs/efreet/src/lib/efreet_desktop.h,v retrieving revision 1.10 retrieving revision 1.11 diff -u -3 -r1.10 -r1.11 --- efreet_desktop.h 17 Jun 2007 08:29:20 -0000 1.10 +++ efreet_desktop.h 18 Jun 2007 04:26:50 -0000 1.11 @@ -121,6 +121,8 @@ Ecore_List *files, Efreet_Desktop_Command_Cb func, void *data); +Ecore_List * efreet_desktop_command_local_get(Efreet_Desktop *desktop, + Ecore_List *files); unsigned int efreet_desktop_category_count_get(Efreet_Desktop *desktop); void efreet_desktop_category_add(Efreet_Desktop *desktop, ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs