From d408b3f0552e485f31267052adfc0321e0d9b779 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Fri, 13 Oct 2006 23:25:43 +0000 Subject: [PATCH] Some optimizations and tweaking. SVN revision: 26576 --- .../src/lib/ecore_desktop/Ecore_Desktop.h | 1 + .../lib/ecore_desktop/ecore_desktop_icon.c | 137 +++++++++++------- 2 files changed, 83 insertions(+), 55 deletions(-) diff --git a/legacy/ecore/src/lib/ecore_desktop/Ecore_Desktop.h b/legacy/ecore/src/lib/ecore_desktop/Ecore_Desktop.h index 1776d0a8d0..3f7d1a7388 100644 --- a/legacy/ecore/src/lib/ecore_desktop/Ecore_Desktop.h +++ b/legacy/ecore/src/lib/ecore_desktop/Ecore_Desktop.h @@ -83,6 +83,7 @@ struct _Ecore_Desktop_Icon_Theme char *inherits; char *directories; int hidden; + unsigned char hicolor:1; /* Actually calling this st_mtime causes compile issues, must be some strange macros at work. */ time_t mtime; /* For checking if the cache is valid. */ }; diff --git a/legacy/ecore/src/lib/ecore_desktop/ecore_desktop_icon.c b/legacy/ecore/src/lib/ecore_desktop/ecore_desktop_icon.c index 7dcf313255..41a708d090 100644 --- a/legacy/ecore/src/lib/ecore_desktop/ecore_desktop_icon.c +++ b/legacy/ecore/src/lib/ecore_desktop/ecore_desktop_icon.c @@ -164,6 +164,8 @@ _ecore_desktop_icon_find0(const char *icon, const char *icon_size, char *found = NULL; int wanted_size; int minimal_size = INT_MAX; + int has_ext = 0; + int has_icon_ext = 0; int i; char *closest = NULL; Ecore_Desktop_Icon_Theme_Directory *directory; @@ -171,6 +173,22 @@ _ecore_desktop_icon_find0(const char *icon, const char *icon_size, if ((icon == NULL) || (icon[0] == '\0')) return NULL; + /* Check the file extension, if any. */ + found = strrchr(icon, '.'); + if (found != NULL) + { + has_ext = 1; + for (i = 0; ext[i] != NULL; i++) + { + if (strcmp(found, ext[i]) == 0) + { + has_icon_ext = 1; + break; + } + } + found = NULL; + } + #ifdef DEBUG fprintf(stderr, "\tTrying To Find Icon %s (%s) in theme %s\n", icon, icon_size, icon_theme); @@ -186,8 +204,8 @@ _ecore_desktop_icon_find0(const char *icon, const char *icon_size, if (!theme->Directories) goto done; wanted_size = atoi(icon_size); - /* Loop through the themes directories. */ + /* Loop through the themes directories. */ ecore_list_goto_first(theme->Directories); while ((directory = ecore_list_next(theme->Directories)) != NULL) { @@ -221,44 +239,48 @@ _ecore_desktop_icon_find0(const char *icon, const char *icon_size, break; } - /* Look for icon with all extensions. */ - for (i = 0; ext[i] != NULL; i++) + /* Do we need to check this directory? */ + if ((match) || (result_size < minimal_size)) { - /* Check if there will be an extension. */ - if ((ext[i][0] == '\0') && (strrchr(icon, '.') == NULL)) - continue; - snprintf(path, PATH_MAX, "%s/%s/%s%s", - icon_theme, directory->path, icon, ext[i]); + /* Look for icon with all extensions. */ + for (i = 0; ext[i] != NULL; i++) + { + /* Check if there will be an extension to check. */ + if ((ext[i][0] == '\0') && (!has_ext)) + continue; + if ((ext[i][0] != '\0') && (has_icon_ext)) + continue; + snprintf(path, PATH_MAX, "%s/%s/%s%s", icon_theme, directory->path, icon, ext[i]); #ifdef DEBUG - printf("FDO icon = %s\n", path); + printf("FDO icon = %s\n", path); #endif - found = ecore_desktop_paths_file_find(ecore_desktop_paths_icons, path, - 0, NULL, NULL); - if (found) - { - if (ecore_file_is_dir(found)) - { - free(found); - found = NULL; - } - else if (match) /* If there is a match in sizes, return the icon. */ - goto done; - else if (result_size < minimal_size) /* While we are here, figure out our next fallback strategy. */ - { - minimal_size = result_size; - if (closest) free(closest); - closest = found; - found = NULL; - } - else - { - free(found); - found = NULL; - } - } - } - } - } /* while ((directory = ecore_list_next(directory_paths)) != NULL) */ + found = ecore_desktop_paths_file_find(ecore_desktop_paths_icons, path, 0, NULL, NULL); + if (found) + { + if (ecore_file_is_dir(found)) + { + free(found); + found = NULL; + } + else if (match) /* If there is a match in sizes, return the icon. */ + goto done; + else if (result_size < minimal_size) /* While we are here, figure out our next fallback strategy. */ + { + minimal_size = result_size; + if (closest) free(closest); + closest = found; + found = NULL; + } + else + { + free(found); + found = NULL; + } + } + } /* for (i = 0; ext[i] != NULL; i++) */ + } /* if ((match) || (result_size < minimal_size)) */ + } /* if (directory->size) */ + } /* while ((directory = ecore_list_next(directory_paths)) != NULL) */ if (!found) { @@ -271,37 +293,39 @@ _ecore_desktop_icon_find0(const char *icon, const char *icon_size, } /* Fall back strategy #2, Try again with the parent themes. */ - if ((theme->Inherits) && (strcmp(icon_theme, "hicolor") != 0)) + if (!theme->hicolor) { - char *inherits; - - ecore_list_goto_first(theme->Inherits); - while ((inherits = ecore_list_next(theme->Inherits)) != NULL) + if (theme->Inherits) { - found = _ecore_desktop_icon_find0(icon, icon_size, inherits); - if (found) goto done; - } - } + char *inherits; - /* Fall back strategy #3, Try the default hicolor theme. */ - if ((!(theme->Inherits)) && (strcmp(icon_theme, "hicolor") != 0)) - { - found = _ecore_desktop_icon_find0(icon, icon_size, "hicolor"); - if (found) goto done; + ecore_list_goto_first(theme->Inherits); + while ((inherits = ecore_list_next(theme->Inherits)) != NULL) + { + found = _ecore_desktop_icon_find0(icon, icon_size, inherits); + if (found) goto done; + } + } + else /* Fall back strategy #3, Try the default hicolor theme. */ + { + found = _ecore_desktop_icon_find0(icon, icon_size, "hicolor"); + if (found) goto done; + } } /* Fall back strategy #4, Just search in the base of the icon directories. */ for (i = 0; ext[i] != NULL; i++) { - /* Check if there will be an extension. */ - if ((ext[i][0] == '\0') && (strrchr(icon, '.') == NULL)) - continue; + /* Check if there will be an extension to check. */ + if ((ext[i][0] == '\0') && (!has_ext)) + continue; + if ((ext[i][0] != '\0') && (has_icon_ext)) + continue; snprintf(path, PATH_MAX, "%s%s", icon, ext[i]); #ifdef DEBUG printf("FDO icon = %s\n", path); #endif - found = ecore_desktop_paths_file_find(ecore_desktop_paths_icons, - path, 0, NULL, NULL); + found = ecore_desktop_paths_file_find(ecore_desktop_paths_icons, path, 0, NULL, NULL); if (found) { if (ecore_file_is_dir(found)) @@ -456,6 +480,9 @@ ecore_desktop_icon_theme_get(const char *icon_theme, const char *lang) result->group = ecore_hash_get(result->data, "Icon Theme"); if (!result->group) goto error; + if ((strcmp(icon_theme, "hicolor") == 0)) + result->hicolor = 1; + /* According to the spec, name and comment are required, but we can fake those easily enough. */ value = ecore_hash_get(result->group, "Name"); if (!value) value = (char *) icon_theme;