From 55404c713475a89e270877b1467dffc56b994ec5 Mon Sep 17 00:00:00 2001 From: Sebastian Dransfeld Date: Thu, 9 Dec 2010 08:56:56 +0000 Subject: [PATCH] enable icon theme cache SVN revision: 55398 --- .../efreet/src/bin/efreet_icon_cache_create.c | 71 ++++++++++++++++++- legacy/efreet/src/lib/efreet_cache.c | 46 ++++++++++++ legacy/efreet/src/lib/efreet_icon.c | 66 ++++++++++------- legacy/efreet/src/lib/efreet_private.h | 7 +- 4 files changed, 160 insertions(+), 30 deletions(-) diff --git a/legacy/efreet/src/bin/efreet_icon_cache_create.c b/legacy/efreet/src/bin/efreet_icon_cache_create.c index 0af073b202..3fa2f52c30 100644 --- a/legacy/efreet/src/bin/efreet_icon_cache_create.c +++ b/legacy/efreet/src/bin/efreet_icon_cache_create.c @@ -300,6 +300,73 @@ cache_scan(Efreet_Icon_Theme *theme, Eina_Hash *themes, Eina_Hash *icons, Eina_H return 1; } +static Efreet_Icon_Theme_Directory * +icon_theme_directory_new(Efreet_Ini *ini, const char *name) +{ + Efreet_Icon_Theme_Directory *dir; + int val; + const char *tmp; + + if (!ini) return NULL; + + dir = NEW(Efreet_Icon_Theme_Directory, 1); + if (!dir) return NULL; + dir->name = eina_stringshare_add(name); + + efreet_ini_section_set(ini, name); + + tmp = efreet_ini_string_get(ini, "Context"); + if (tmp) + { + if (!strcasecmp(tmp, "Actions")) + dir->context = EFREET_ICON_THEME_CONTEXT_ACTIONS; + + else if (!strcasecmp(tmp, "Devices")) + dir->context = EFREET_ICON_THEME_CONTEXT_DEVICES; + + else if (!strcasecmp(tmp, "FileSystems")) + dir->context = EFREET_ICON_THEME_CONTEXT_FILESYSTEMS; + + else if (!strcasecmp(tmp, "MimeTypes")) + dir->context = EFREET_ICON_THEME_CONTEXT_MIMETYPES; + } + + /* Threshold is fallback */ + dir->type = EFREET_ICON_SIZE_TYPE_THRESHOLD; + + tmp = efreet_ini_string_get(ini, "Type"); + if (tmp) + { + if (!strcasecmp(tmp, "Fixed")) + dir->type = EFREET_ICON_SIZE_TYPE_FIXED; + + else if (!strcasecmp(tmp, "Scalable")) + dir->type = EFREET_ICON_SIZE_TYPE_SCALABLE; + } + + dir->size.normal = efreet_ini_int_get(ini, "Size"); + + if (dir->type == EFREET_ICON_SIZE_TYPE_THRESHOLD) + { + val = efreet_ini_int_get(ini, "Threshold"); + if (val < 0) val = 2; + dir->size.max = dir->size.normal + val; + dir->size.min = dir->size.normal - val; + } + else if (dir->type == EFREET_ICON_SIZE_TYPE_SCALABLE) + { + val = efreet_ini_int_get(ini, "MinSize"); + if (val < 0) dir->size.min = dir->size.normal; + else dir->size.min = val; + + val = efreet_ini_int_get(ini, "MaxSize"); + if (val < 0) dir->size.max = dir->size.normal; + else dir->size.max = val; + } + + return dir; +} + static void icon_theme_index_read(Efreet_Icon_Theme *theme, const char *path) { @@ -376,7 +443,7 @@ icon_theme_index_read(Efreet_Icon_Theme *theme, const char *path) if (p) *p = '\0'; - dir = efreet_icon_theme_directory_new(ini, s); + dir = icon_theme_directory_new(ini, s); if (!dir) goto error; theme->directories = eina_list_append(theme->directories, dir); @@ -413,7 +480,7 @@ cache_theme_scan(const char *dir) if (!theme) { - theme = efreet_icon_theme_new(); + theme = NEW(Efreet_Icon_Theme, 1); theme->name.internal = eina_stringshare_add(name); eina_hash_direct_add(icon_themes, (void *)theme->name.internal, theme); diff --git a/legacy/efreet/src/lib/efreet_cache.c b/legacy/efreet/src/lib/efreet_cache.c index e5448d7f55..b7c16376d3 100644 --- a/legacy/efreet/src/lib/efreet_cache.c +++ b/legacy/efreet/src/lib/efreet_cache.c @@ -45,6 +45,7 @@ static Eet_Data_Descriptor *icon_element_edd = NULL; static Eet_Data_Descriptor *icon_edd = NULL; static Eet_File *icon_cache = NULL; +static Eet_File *icon_theme_cache = NULL; static const char *icon_theme_cache_file = NULL; @@ -150,6 +151,7 @@ efreet_cache_shutdown(void) theme_name = NULL; icon_cache = efreet_cache_close(icon_cache); + icon_theme_cache = efreet_cache_close(icon_theme_cache); #endif desktop_cache = efreet_cache_close(desktop_cache); @@ -627,6 +629,49 @@ efreet_cache_icon_fallback_find(const char *icon) return eina_hash_find(fallback_cache->icons, icon); } + +Efreet_Icon_Theme * +efreet_cache_icon_theme_find(const char *theme) +{ + if (!efreet_cache_check(&icon_theme_cache, efreet_icon_theme_cache_file(), EFREET_ICON_CACHE_MAJOR)) return NULL; + return eet_data_read(icon_theme_cache, efreet_icon_theme_edd(), theme); +} + +void +efreet_cache_icon_theme_free(Efreet_Icon_Theme *theme) +{ + void *data; + + if (!theme) return; + + eina_list_free(theme->paths); + eina_list_free(theme->inherits); + EINA_LIST_FREE(theme->directories, data) + free(data); + + free(theme); +} + +char ** +efreet_cache_icon_theme_name_list(int *num) +{ + char **keys; + int i; + + if (!efreet_cache_check(&icon_theme_cache, efreet_icon_theme_cache_file(), EFREET_ICON_CACHE_MAJOR)) return NULL; + keys = eet_list(icon_theme_cache, "*", num); + for (i = 0; i < *num; i++) + { + if (!strcmp(keys[i], EFREET_CACHE_VERSION) && (i < (*num + 1))) + { + memmove(&keys[i], &keys[i + 1], (*num - i - 1) * sizeof(char *)); + (*num)--; + break; + } + } + return keys; +} + #endif Efreet_Desktop * @@ -805,6 +850,7 @@ cache_update_cb(void *data __UNUSED__, Ecore_File_Monitor *em __UNUSED__, } icon_cache = efreet_cache_close(icon_cache); + icon_theme_cache = efreet_cache_close(icon_theme_cache); ev = NEW(Efreet_Event_Cache_Update, 1); if (!ev) return; diff --git a/legacy/efreet/src/lib/efreet_icon.c b/legacy/efreet/src/lib/efreet_icon.c index a0a31f2c8f..66009494ed 100644 --- a/legacy/efreet/src/lib/efreet_icon.c +++ b/legacy/efreet/src/lib/efreet_icon.c @@ -43,7 +43,6 @@ void *alloca (size_t); static int _efreet_icon_log_dom = -1; /* TODO: Scan efreet_extra_icon_dirs for themes */ -/* TODO: icon theme cache */ static const char *efreet_icon_deprecated_user_dir = NULL; static const char *efreet_icon_user_dir = NULL; @@ -65,10 +64,10 @@ struct Efreet_Icon_Cache }; static char *efreet_icon_remove_extension(const char *icon); -static Efreet_Icon_Theme *efreet_icon_find_theme_check(const char *theme_name); - #ifndef ICON_CACHE +static Efreet_Icon_Theme *efreet_icon_find_theme_check(const char *theme_name); + static const char *efreet_icon_find_fallback(Efreet_Icon_Theme *theme, const char *icon, unsigned int size); @@ -102,7 +101,6 @@ static void efreet_icon_populate(Efreet_Icon *icon, const char *file); #ifndef ICON_CACHE static Efreet_Icon_Theme *efreet_icon_theme_new(void); -#endif static void efreet_icon_theme_free(Efreet_Icon_Theme *theme); static void efreet_icon_theme_dir_scan_all(const char *theme_name); static void efreet_icon_theme_dir_scan(const char *dir, @@ -112,13 +110,10 @@ static void efreet_icon_theme_path_add(Efreet_Icon_Theme *theme, static void efreet_icon_theme_index_read(Efreet_Icon_Theme *theme, const char *path); -#ifndef ICON_CACHE static Efreet_Icon_Theme_Directory *efreet_icon_theme_directory_new(Efreet_Ini *ini, const char *name); -#endif static void efreet_icon_theme_directory_free(Efreet_Icon_Theme_Directory *dir); -#ifndef ICON_CACHE static void efreet_icon_theme_cache_check(Efreet_Icon_Theme *theme); static int efreet_icon_theme_cache_check_dir(Efreet_Icon_Theme *theme, const char *dir); @@ -166,16 +161,16 @@ efreet_icon_init(void) for (i = 0; default_exts[i]; i++) efreet_icon_extensions = eina_list_append(efreet_icon_extensions, eina_stringshare_add(default_exts[i])); - efreet_icon_themes = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_icon_theme_free)); - - efreet_extra_icon_dirs = NULL; #ifndef ICON_CACHE + efreet_icon_themes = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_icon_theme_free)); efreet_icon_cache = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_icon_cache_free)); -#endif - -#if ICON_CACHE +#else + efreet_icon_themes = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_icon_theme_free)); efreet_icon_changes_listen(); #endif + + efreet_extra_icon_dirs = NULL; + return 1; } @@ -289,6 +284,7 @@ EAPI Eina_List * efreet_icon_theme_list_get(void) { Eina_List *list = NULL; +#ifndef ICON_CACHE Eina_Iterator *it; Efreet_Icon_Theme *theme; @@ -307,6 +303,23 @@ efreet_icon_theme_list_get(void) list = eina_list_append(list, theme); } eina_iterator_free(it); +#else + char **keys; + int num, i; + + keys = efreet_cache_icon_theme_name_list(&num); + if (keys) + { + for (i = 0; i < num; i++) + { + Efreet_Icon_Theme *theme; + + theme = efreet_icon_theme_find(keys[i]); + list = eina_list_append(list, theme); + } + free(keys); + } +#endif return list; } @@ -327,8 +340,13 @@ efreet_icon_theme_find(const char *theme_name) theme = eina_hash_find(efreet_icon_themes, theme_name); if (!theme) { +#ifndef ICON_CACHE efreet_icon_theme_dir_scan_all(theme_name); theme = eina_hash_find(efreet_icon_themes, theme_name); +#else + theme = efreet_cache_icon_theme_find(theme_name); + if (theme) eina_hash_direct_add(efreet_icon_themes, theme->name.internal, theme); +#endif } return theme; @@ -370,6 +388,7 @@ efreet_icon_remove_extension(const char *icon) return tmp; } +#ifndef ICON_CACHE /** * @internal * @param theme_name: The icon theme to look for @@ -393,6 +412,7 @@ efreet_icon_find_theme_check(const char *theme_name) return theme; } +#endif /** * @param theme_name: The icon theme to look for @@ -407,7 +427,11 @@ efreet_icon_path_find(const char *theme_name, const char *icon, unsigned int siz const char *value = NULL; Efreet_Icon_Theme *theme; +#ifndef ICON_CACHE theme = efreet_icon_find_theme_check(theme_name); +#else + theme = efreet_icon_theme_find(theme_name); +#endif if (theme) { @@ -477,7 +501,11 @@ efreet_icon_list_find(const char *theme_name, Eina_List *icons, char *data; Efreet_Icon_Theme *theme; +#ifndef ICON_CACHE theme = efreet_icon_find_theme_check(theme_name); +#else + theme = efreet_icon_theme_find(theme_name); +#endif if (theme) { @@ -1232,6 +1260,7 @@ error: efreet_ini_free(ini); } +#ifndef ICON_CACHE /** * @internal * @return Returns a new Efreet_Icon_Theme on success or NULL on failure @@ -1239,11 +1268,7 @@ error: * * Needs EAPI because of helper binaries */ -#ifndef ICON_CACHE static Efreet_Icon_Theme * -#else -EAPI Efreet_Icon_Theme * -#endif efreet_icon_theme_new(void) { Efreet_Icon_Theme *theme; @@ -1295,7 +1320,6 @@ efreet_icon_theme_path_add(Efreet_Icon_Theme *theme, const char *path) theme->paths = eina_list_append(theme->paths, eina_stringshare_add(path)); } -#ifndef ICON_CACHE /** * @internal * @return Returns no value @@ -1371,7 +1395,6 @@ efreet_icon_theme_cache_check_dir(Efreet_Icon_Theme *theme, const char *dir) return 1; } -#endif /** * @internal @@ -1578,11 +1601,7 @@ error: * * Needs EAPI because of helper binaries */ -#ifndef ICON_CACHE static Efreet_Icon_Theme_Directory * -#else -EAPI Efreet_Icon_Theme_Directory * -#endif efreet_icon_theme_directory_new(Efreet_Ini *ini, const char *name) { Efreet_Icon_Theme_Directory *dir; @@ -1664,7 +1683,6 @@ efreet_icon_theme_directory_free(Efreet_Icon_Theme_Directory *dir) FREE(dir); } -#ifndef ICON_CACHE static void efreet_icon_cache_free(Efreet_Icon_Cache *value) { diff --git a/legacy/efreet/src/lib/efreet_private.h b/legacy/efreet/src/lib/efreet_private.h index b0533c3ba8..d35688ca2b 100644 --- a/legacy/efreet/src/lib/efreet_private.h +++ b/legacy/efreet/src/lib/efreet_private.h @@ -238,10 +238,9 @@ EAPI void efreet_cache_icon_free(Efreet_Cache_Icon *icon); EAPI void efreet_cache_icon_fallback_free(Efreet_Cache_Fallback_Icon *icon); Efreet_Cache_Icon *efreet_cache_icon_find(Efreet_Icon_Theme *theme, const char *icon); Efreet_Cache_Fallback_Icon *efreet_cache_icon_fallback_find(const char *icon); - -EAPI Efreet_Icon_Theme *efreet_icon_theme_new(void); -EAPI Efreet_Icon_Theme_Directory *efreet_icon_theme_directory_new(Efreet_Ini *ini, - const char *name); +Efreet_Icon_Theme *efreet_cache_icon_theme_find(const char *theme); +void efreet_cache_icon_theme_free(Efreet_Icon_Theme *theme); +char **efreet_cache_icon_theme_name_list(int *num); #endif EAPI void efreet_hash_free(Eina_Hash *hash, Eina_Free_Cb free_cb);