Enlightenment CVS committal Author : onefang Project : e17 Module : apps/e_utils
Dir : e17/apps/e_utils/src/bin/e17genmenu/src/bin Modified Files: fdo_paths.c fdo_paths.h global.c icons.c icons.h main.c Log Message: Icon search strategy according to fdo specs is half done. This half works fine. The other half is fallbacks that I will add next. What a monstrosity this is. Optimization comes later. =================================================================== RCS file: /cvsroot/enlightenment/e17/apps/e_utils/src/bin/e17genmenu/src/bin/fdo_paths.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -3 -r1.6 -r1.7 --- fdo_paths.c 3 Feb 2006 00:15:12 -0000 1.6 +++ fdo_paths.c 3 Feb 2006 05:50:37 -0000 1.7 @@ -25,9 +25,9 @@ int done; }; +static Fdo_Path_List *_fdo_paths_list_new(char *buffer); static Fdo_Path_List *_fdo_paths_list_add(Fdo_Path_List * list, char *element); static int _fdo_paths_list_exist(Fdo_Path_List * list, char *element); -static Fdo_Path_List *_fdo_paths_paths_to_list(char *paths); static void _fdo_paths_list_del(Fdo_Path_List * list); static Fdo_Path_List *_fdo_paths_get(char *before, char *env_home, char *env, @@ -152,6 +152,48 @@ return path; } +/** Split a list of paths into a path list. + * + * The list of paths can use any one of ;:, to seperate the paths. + * You can also escape the :;, with \. + * + * FIXME: The concept here is still buggy, but it should do for now. + * + * @param paths A list of paths. + */ +Fdo_Path_List * +fdo_paths_paths_to_list(char *paths) +{ + Fdo_Path_List *list = NULL; + + list = _fdo_paths_list_new(paths); + if ((list) && (list->buffer)) + { + char *start, *end; + int finished = 0; + + end = list->buffer; + while (!finished) + { + start = end; + do /* FIXME: There is probably a better way to do this. */ + { + while ((*end != ';') && (*end != ':') && (*end != ',') && (*end != '\0')) + end++; + } + while ((end != list->buffer) && (*(end - 1) == '\\') && (*end != '\0')); /* Ignore any escaped ;:, */ + /* FIXME: We still need to unescape it now. */ + if (*end == '\0') + finished = 1; + *end = '\0'; + if (!_fdo_paths_list_exist(list, start)) + list = _fdo_paths_list_add(list, start); + end++; + } + } + return list; +} + /* We need - config file full of paths menus=pathlist @@ -253,34 +295,6 @@ } static Fdo_Path_List * -_fdo_paths_paths_to_list(char *paths) -{ - Fdo_Path_List *list = NULL; - - list = _fdo_paths_list_new(paths); - if ((list) && (list->buffer)) - { - char *start, *end; - int finished = 0; - - end = list->buffer; - while (!finished) - { - start = end; - while ((*end != ':') && (*end != '\0')) - end++; - if (*end == '\0') - finished = 1; - *end = '\0'; - if (!_fdo_paths_list_exist(list, start)) - list = _fdo_paths_list_add(list, start); - end++; - } - } - return list; -} - -static Fdo_Path_List * _fdo_paths_get(char *before, char *env_home, char *env, char *env_home_default, char *env_default, char *type, char *gnome_extra, char *kde) { @@ -294,9 +308,9 @@ /* Don't sort them, as they are in preferred order from each source. */ /* Merge the results, there are probably some duplicates. */ - types = _fdo_paths_paths_to_list(type); - gnome_extras = _fdo_paths_paths_to_list(gnome_extra); - kdes = _fdo_paths_paths_to_list(kde); + types = fdo_paths_paths_to_list(type); + gnome_extras = fdo_paths_paths_to_list(gnome_extra); + kdes = fdo_paths_paths_to_list(kde); home = get_home(); if (home) @@ -320,7 +334,7 @@ { Fdo_Path_List *befores; - befores = _fdo_paths_paths_to_list(before); + befores = fdo_paths_paths_to_list(before); if (befores) { for (i = 0; i < befores->size; i++) @@ -340,7 +354,7 @@ value = getenv(env_home); if ((value == NULL) || (value[0] == '\0')) value = env_home_default; - env_list = _fdo_paths_paths_to_list(value); + env_list = fdo_paths_paths_to_list(value); if (env_list) { for (i = 0; i < env_list->size; i++) @@ -364,7 +378,7 @@ value = getenv(env); if ((value == NULL) || (value[0] == '\0')) value = env_default; - env_list = _fdo_paths_paths_to_list(value); + env_list = fdo_paths_paths_to_list(value); if (env_list) { for (i = 0; i < env_list->size; i++) @@ -574,7 +588,7 @@ read = ecore_exe_event_data_get(ev->exe, ECORE_EXE_PIPE_READ); value = read->lines[0].line; - config_list = _fdo_paths_paths_to_list(value); + config_list = fdo_paths_paths_to_list(value); if (config_list) { int i, j; =================================================================== RCS file: /cvsroot/enlightenment/e17/apps/e_utils/src/bin/e17genmenu/src/bin/fdo_paths.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- fdo_paths.h 1 Feb 2006 19:37:59 -0000 1.2 +++ fdo_paths.h 3 Feb 2006 05:50:38 -0000 1.3 @@ -32,6 +32,7 @@ void fdo_paths_init(); char *fdo_paths_search_for_file(Fdo_Paths_Type type, char *file, int (*func) (const void *data, char *path), const void *data); + Fdo_Path_List *fdo_paths_paths_to_list(char *paths); void fdo_paths_shutdown(); # ifdef __cplusplus =================================================================== RCS file: /cvsroot/enlightenment/e17/apps/e_utils/src/bin/e17genmenu/src/bin/global.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -3 -r1.5 -r1.6 --- global.c 1 Feb 2006 19:03:22 -0000 1.5 +++ global.c 3 Feb 2006 05:50:38 -0000 1.6 @@ -139,7 +139,7 @@ return strdup(c); } } - return NULL; + return "crystalsvg"; } int =================================================================== RCS file: /cvsroot/enlightenment/e17/apps/e_utils/src/bin/e17genmenu/src/bin/icons.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -3 -r1.4 -r1.5 --- icons.c 1 Feb 2006 09:41:25 -0000 1.4 +++ icons.c 3 Feb 2006 05:50:38 -0000 1.5 @@ -1,6 +1,10 @@ +#include <stdlib.h> + #include "global.h" #include "config.h" +#include "fdo_paths.h" #include "icons.h" +#include "parse.h" char * set_icon(char *token) @@ -129,3 +133,171 @@ return DEFAULTICON; } + + +char * +find_fdo_icon(char *icon) +{ + char icn[MAX_PATH], path[MAX_PATH]; + char *dir, *icon_size, *icon_theme, *theme_path; + + if (icon == NULL) + return DEFAULTICON; + +#ifdef DEBUG + fprintf(stderr, "\tTrying To Find Icon %s\n", icon); +#endif + + /* Check For Unsupported Extension */ + if ((!strcmp(icon + strlen(icon) - 4, ".svg")) + || (!strcmp(icon + strlen(icon) - 4, ".ico")) + || (!strcmp(icon + strlen(icon) - 4, ".xpm"))) + return DEFAULTICON; + + /* Check If Dir Supplied In Desktop File */ + dir = ecore_file_get_dir(icon); + if (!strcmp(dir, icon) == 0) + { + snprintf(path, MAX_PATH, "%s", icon); + /* Check Supplied Dir For Icon */ + if (ecore_file_exists(path)) + return strdup(icon); + } + + /* Get Icon Options */ + icon_size = get_icon_size(); + icon_theme = get_icon_theme(); + + snprintf(icn, MAX_PATH, "%s/index.theme", icon_theme); + printf("SEARCHING FOR %s\n", icn); + theme_path = fdo_paths_search_for_file(FDO_PATHS_TYPE_ICON, icn, NULL, NULL); + if (theme_path) + { + Ecore_Hash *theme; + + printf("Path to %s is %s\n", icn, theme_path); + theme = parse_ini_file(theme_path); + if (theme) + { + Ecore_Hash *icon_group; + + icon_group = (Ecore_Hash *) ecore_hash_get(theme, "Icon Theme"); + if (icon_group) + { + char *directories, *inherits; + + directories = (char *) ecore_hash_get(icon_group, "Directories"); + inherits = (char *) ecore_hash_get(icon_group, "Inherits"); + if ((directories) && (inherits)) + { + Fdo_Path_List *directory_paths; + + printf("Inherits %s Directories %s\n", inherits, directories); + directory_paths = fdo_paths_paths_to_list(directories); + if (directory_paths) + { + int wanted_size; + char i; + + wanted_size = atoi(icon_size); + for (i = 0; i < directory_paths->size; i++) + { + Ecore_Hash *sub_group; + + printf("FDO icon path = %s\n", directory_paths->list[i]); + sub_group = (Ecore_Hash *) ecore_hash_get(theme, directory_paths->list[i]); + if (sub_group) + { + char *size, *type, *minsize, *maxsize, *threshold; + + size = (char *) ecore_hash_get(sub_group, "Size"); + type = (char *) ecore_hash_get(sub_group, "Type"); + minsize = (char *) ecore_hash_get(sub_group, "MinSize"); + maxsize = (char *) ecore_hash_get(sub_group, "MaxSize"); + threshold = (char *) ecore_hash_get(sub_group, "Threshold"); + if (size) + { + int match = 0; + int this_size; + + this_size = atoi(size); + if (!type) + type = "Threshold"; + switch (type[0]) + { + case 'F' : /* Fixed. */ + { + match = (wanted_size == this_size); + break; + } + case 'S' : /* Scaled. */ + { + int min_size, max_size; + + if (!minsize) + minsize = size; + if (!maxsize) + maxsize = size; + min_size = atoi(minsize); + max_size = atoi(maxsize); + match = ((min_size <= wanted_size) && (wanted_size <= max_size)); + break; + } + default : /* Threshold. */ + { + int thresh_size; + + if (!threshold) + threshold = "2"; + thresh_size = atoi(threshold); + match = ( ((this_size - thresh_size) <= wanted_size) && (wanted_size <= (this_size + thresh_size)) ); + break; + } + } + if (match) + { + char *found; + + /* First try a .png file. */ + snprintf(path, MAX_PATH, "%s/%s/%s.png", icon_theme, directory_paths->list[i], icon); + printf("FDO icon = %s\n", path); + found = fdo_paths_search_for_file(FDO_PATHS_TYPE_ICON, path, NULL, NULL); + if (found) + return found; + else + { /* Then a .svg file. */ + snprintf(path, MAX_PATH, "%s/%s/%s.svg", icon_theme, directory_paths->list[i], icon); + printf("FDO icon = %s\n", path); + found = fdo_paths_search_for_file(FDO_PATHS_TYPE_ICON, path, NULL, NULL); + if (found) + return found; + else + { /* Then a .xpm file. */ + snprintf(path, MAX_PATH, "%s/%s/%s.xpm", icon_theme, directory_paths->list[i], icon); + printf("FDO icon = %s\n", path); + found = fdo_paths_search_for_file(FDO_PATHS_TYPE_ICON, path, NULL, NULL); + if (found) + return found; + else + { /* Finally, try without an extension, in case one was given. */ + snprintf(path, MAX_PATH, "%s/%s/%s", icon_theme, directory_paths->list[i], icon); + printf("FDO icon = %s\n", path); + found = fdo_paths_search_for_file(FDO_PATHS_TYPE_ICON, path, NULL, NULL); + if (found) + return found; + } + } + } + } + } + } + } + } + } + } + } + free(theme_path); + } + + return DEFAULTICON; +} =================================================================== RCS file: /cvsroot/enlightenment/e17/apps/e_utils/src/bin/e17genmenu/src/bin/icons.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- icons.h 31 Jan 2006 22:04:17 -0000 1.2 +++ icons.h 3 Feb 2006 05:50:38 -0000 1.3 @@ -28,5 +28,6 @@ /* Function Prototypes */ char *set_icon(char *token); char *find_icon(char *icon); +char *find_fdo_icon(char *icon); #endif =================================================================== RCS file: /cvsroot/enlightenment/e17/apps/e_utils/src/bin/e17genmenu/src/bin/main.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -3 -r1.7 -r1.8 --- main.c 3 Feb 2006 01:25:52 -0000 1.7 +++ main.c 3 Feb 2006 05:50:38 -0000 1.8 @@ -2,6 +2,7 @@ #include "config.h" #include "menus.h" #include "parse.h" +#include "icons.h" #include "sort.h" #include "fdo_paths.h" @@ -84,6 +85,18 @@ free(path); } } + path = find_fdo_icon("tux"); + if (path) + { + printf("Path to tux is %s\n", path); + free(path); + } + path = find_fdo_icon("blah"); + if (path) + { + printf("Path to blah is %s\n", path); + free(path); + } fdo_paths_shutdown(); ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642 _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs