From 7b68d53abc4d30ed11f21092ac6a90ec6f93708e Mon Sep 17 00:00:00 2001 From: Sebastian Dransfeld Date: Mon, 22 Nov 2010 20:51:34 +0000 Subject: [PATCH] fix fallback icon searching SVN revision: 54831 --- legacy/efreet/src/lib/efreet_cache.c | 4 +- legacy/efreet/src/lib/efreet_icon.c | 91 +++++++++++++++++++++++++- legacy/efreet/src/lib/efreet_private.h | 2 +- 3 files changed, 93 insertions(+), 4 deletions(-) diff --git a/legacy/efreet/src/lib/efreet_cache.c b/legacy/efreet/src/lib/efreet_cache.c index 71a0ba0d9d..ec331a30b9 100644 --- a/legacy/efreet/src/lib/efreet_cache.c +++ b/legacy/efreet/src/lib/efreet_cache.c @@ -275,7 +275,7 @@ efreet_cache_icon_find(Efreet_Icon_Theme *theme, const char *icon) return NULL; } -const char * +Efreet_Cache_Icon * efreet_cache_icon_fallback_find(const char *icon) { if (!icon_fallback_cache) @@ -285,7 +285,7 @@ efreet_cache_icon_fallback_find(const char *icon) path = efreet_icon_cache_file("_fallback"); icon_fallback_cache = eet_open(path, EET_FILE_MODE_READ); if (icon_fallback_cache) - icon_cache_close(); + icon_cache_timer_update(); } if (icon_fallback_cache) return eet_data_read(icon_fallback_cache, cache_icon_fallback_edd, icon); diff --git a/legacy/efreet/src/lib/efreet_icon.c b/legacy/efreet/src/lib/efreet_icon.c index 4f2224f975..e046d5ae85 100644 --- a/legacy/efreet/src/lib/efreet_icon.c +++ b/legacy/efreet/src/lib/efreet_icon.c @@ -100,6 +100,8 @@ static int efreet_cache_icon_size_match(Efreet_Cache_Icon_Element *elem, unsigne static double efreet_cache_icon_size_distance(Efreet_Cache_Icon_Element *elem, unsigned int size); static const char *efreet_cache_icon_lookup_path(Efreet_Cache_Icon_Element *elem); static const char *efreet_cache_icon_lookup_path_path(Efreet_Cache_Icon_Element *elem, const char *path); +static const char *efreet_cache_icon_fallback_lookup_path(Efreet_Cache_Icon *icon); +static const char *efreet_cache_icon_fallback_lookup_path_path(Efreet_Cache_Icon *icon, const char *path); #endif /** @@ -409,7 +411,11 @@ efreet_icon_path_find(const char *theme_name, const char *icon, unsigned int siz */ if (!value || (value == NON_EXISTING)) #ifdef ICON_CACHE - value = efreet_cache_icon_fallback_find(icon); + { + cache = efreet_cache_icon_fallback_find(icon); + value = efreet_cache_icon_fallback_lookup_path(cache); + efreet_cache_icon_free(cache); + } #else value = efreet_icon_fallback_icon(icon); #endif @@ -1823,4 +1829,87 @@ efreet_cache_icon_lookup_path_path(Efreet_Cache_Icon_Element *elem, const char * } return NULL; } + +static const char * +efreet_cache_icon_fallback_lookup_path(Efreet_Cache_Icon *icon) +{ + const char *path; + Eina_List *xdg_dirs, *l; + const char *dir; + char buf[PATH_MAX]; + + if (!icon) return NULL; + + if (eina_list_count(icon->icons) == 1) + { + const char *pp, *ext; + + path = eina_list_data_get(icon->icons); + pp = strrchr(path, '.'); + + EINA_LIST_FOREACH(efreet_icon_extensions, l, ext) + if (!strcmp(pp, ext)) + return path; + return NULL; + } + + path = efreet_cache_icon_fallback_lookup_path_path(icon, efreet_icon_deprecated_user_dir_get()); + if (path) return path; + path = efreet_cache_icon_fallback_lookup_path_path(icon, efreet_icon_user_dir_get()); + if (path) return path; +#if 0 + EINA_LIST_FOREACH(efreet_extra_icon_dirs, l, dir) + { + path = efreet_cache_icon_lookup_path_path(elem, dir); + if (path) return path; + } +#endif + + xdg_dirs = efreet_data_dirs_get(); + + EINA_LIST_FOREACH(xdg_dirs, l, dir) + { + snprintf(buf, sizeof(buf), "%s/icons", dir); + path = efreet_cache_icon_fallback_lookup_path_path(icon, buf); + if (path) return path; + } + +#ifndef STRICT_SPEC + EINA_LIST_FOREACH(xdg_dirs, l, dir) + { + snprintf(buf, sizeof(buf), "%s/pixmaps", dir); + path = efreet_cache_icon_fallback_lookup_path_path(icon, buf); + if (path) return path; + } +#endif + + path = efreet_cache_icon_fallback_lookup_path_path(icon, "/usr/share/pixmaps"); + if (path) return path; + + return NULL; +} + +static const char * +efreet_cache_icon_fallback_lookup_path_path(Efreet_Cache_Icon *icon, const char *path) +{ + Eina_List *l, *ll; + const char *ext, *p, *pp; + int len; + + len = strlen(path); + + EINA_LIST_FOREACH(icon->icons, l, p) + { + + if (strncmp(path, p, len)) continue; + pp = strrchr(p, '.'); + if (!pp) continue; + + EINA_LIST_FOREACH(efreet_icon_extensions, ll, ext) + if (!strcmp(pp, ext)) + return p; + } + return NULL; +} + #endif diff --git a/legacy/efreet/src/lib/efreet_private.h b/legacy/efreet/src/lib/efreet_private.h index c490b80282..676142dcee 100644 --- a/legacy/efreet/src/lib/efreet_private.h +++ b/legacy/efreet/src/lib/efreet_private.h @@ -216,7 +216,7 @@ EAPI Eet_Data_Descriptor *efreet_icon_edd_init(void); EAPI Eet_Data_Descriptor *efreet_icon_fallback_edd_init(void); EAPI void efreet_cache_icon_free(Efreet_Cache_Icon *icon); Efreet_Cache_Icon *efreet_cache_icon_find(Efreet_Icon_Theme *theme, const char *icon); -const char *efreet_cache_icon_fallback_find(const char *icon); +Efreet_Cache_Icon *efreet_cache_icon_fallback_find(const char *icon); #endif #define NON_EXISTING (void *)-1