forked from enlightenment/efl
Remove the icon cache.
This means that users of efreet_icon_list_find, efreet_icon_path_find and efreet_icon_find must clean up after themselves! SVN revision: 30986
This commit is contained in:
parent
4142475b16
commit
3b116f3a2b
|
@ -1,12 +1,13 @@
|
|||
#include <Efreet.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "comp.h"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int i = 0, k;
|
||||
const char *path;
|
||||
char *path;
|
||||
|
||||
efreet_init();
|
||||
|
||||
|
@ -16,6 +17,7 @@ main(int argc, char **argv)
|
|||
{
|
||||
path = efreet_icon_path_find(THEME, icons[i], SIZE);
|
||||
// printf("%s: %s\n", icons[i], (path ? path : "NOT FOUND"));
|
||||
if (path) free(path);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#define PATH_MAX 4096
|
||||
#endif
|
||||
|
||||
#define SIZE "16x16"
|
||||
#define SIZE "128x128"
|
||||
#define THEME "Tango"
|
||||
|
||||
static void ef_icon_theme_themes_find(const char *search_dir,
|
||||
|
@ -450,8 +450,7 @@ ef_cb_efreet_icon_match(void)
|
|||
|
||||
for (i = 0; icons[i] != NULL; i++)
|
||||
{
|
||||
const char *path;
|
||||
char *t, *s;
|
||||
char *path, *s;
|
||||
|
||||
path = efreet_icon_path_find(THEME, icons[i], SIZE);
|
||||
|
||||
|
@ -465,10 +464,9 @@ ef_cb_efreet_icon_match(void)
|
|||
continue;
|
||||
}
|
||||
|
||||
t = strdup(path);
|
||||
s = strrchr(t, '.');
|
||||
s = strrchr(path, '.');
|
||||
if (s) *s = '\0';
|
||||
s = strrchr(t, '/');
|
||||
s = strrchr(path, '/');
|
||||
if (s) s++;
|
||||
|
||||
if (s && strcmp(s, icons[i]))
|
||||
|
@ -476,7 +474,7 @@ ef_cb_efreet_icon_match(void)
|
|||
printf("Name mismatch name (%s) vs ef (%s)\n", icons[i], s);
|
||||
ret = 0;
|
||||
}
|
||||
free(t);
|
||||
free(path);
|
||||
}
|
||||
ecore_hash_destroy(icon_hash);
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ const char *efreet_mime_globs_type_get(const char *file);
|
|||
const char *efreet_mime_special_type_get(const char *file);
|
||||
const char *efreet_mime_fallback_type_get(const char *file);
|
||||
|
||||
const char *efreet_mime_type_icon_get(const char *mime, const char *theme,
|
||||
char *efreet_mime_type_icon_get(const char *mime, const char *theme,
|
||||
const char *size);
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
#include "Efreet.h"
|
||||
#include "efreet_private.h"
|
||||
|
||||
#define NO_MATCH_KEY ((char *)0xdeadbeef)
|
||||
|
||||
static char *efreet_icon_deprecated_user_dir = NULL;
|
||||
static char *efreet_icon_user_dir = NULL;
|
||||
static Ecore_Hash *efreet_icon_dirs_cached = NULL;
|
||||
|
@ -17,31 +15,23 @@ static char *efreet_icon_remove_extension(const char *icon);
|
|||
static Efreet_Icon_Theme *efreet_icon_find_theme_check(const char *theme_name);
|
||||
|
||||
|
||||
static Efreet_Icon *efreet_icon_find_fallback(Efreet_Icon_Theme *theme,
|
||||
const char *cache_key,
|
||||
static char *efreet_icon_find_fallback(Efreet_Icon_Theme *theme,
|
||||
const char *icon,
|
||||
const char *size);
|
||||
static Efreet_Icon *efreet_icon_list_find_fallback(Efreet_Icon_Theme *theme,
|
||||
Ecore_List *cache_keys,
|
||||
static char *efreet_icon_list_find_fallback(Efreet_Icon_Theme *theme,
|
||||
Ecore_List *icons,
|
||||
const char *size);
|
||||
static Efreet_Icon *efreet_icon_find_helper(Efreet_Icon_Theme *theme,
|
||||
const char *cache_key,
|
||||
const char *icon,
|
||||
const char *size);
|
||||
static Efreet_Icon *efreet_icon_list_find_helper(Efreet_Icon_Theme *theme,
|
||||
Ecore_List *cache_keys,
|
||||
Ecore_List *icons,
|
||||
const char *size);
|
||||
static Efreet_Icon *efreet_icon_lookup_icon(Efreet_Icon_Theme *theme,
|
||||
const char *icon_name,
|
||||
const char *size);
|
||||
static Efreet_Icon *efreet_icon_fallback_icon(const char *icon_name);
|
||||
static Efreet_Icon *efreet_icon_fallback_dir_scan(const char *dir,
|
||||
static char *efreet_icon_find_helper(Efreet_Icon_Theme *theme,
|
||||
const char *icon, const char *size);
|
||||
static char *efreet_icon_list_find_helper(Efreet_Icon_Theme *theme,
|
||||
Ecore_List *icons, const char *size);
|
||||
static char *efreet_icon_lookup_icon(Efreet_Icon_Theme *theme,
|
||||
const char *icon_name, const char *size);
|
||||
static char *efreet_icon_fallback_icon(const char *icon_name);
|
||||
static char *efreet_icon_fallback_dir_scan(const char *dir,
|
||||
const char *icon_name);
|
||||
|
||||
static Efreet_Icon *efreet_icon_lookup_directory(
|
||||
Efreet_Icon_Theme *theme,
|
||||
static char *efreet_icon_lookup_directory(Efreet_Icon_Theme *theme,
|
||||
Efreet_Icon_Theme_Directory *dir,
|
||||
const char *icon_name);
|
||||
static int efreet_icon_directory_size_distance(Efreet_Icon_Theme_Directory *dir,
|
||||
|
@ -50,19 +40,11 @@ static int efreet_icon_directory_size_match(Efreet_Icon_Theme_Directory *dir,
|
|||
unsigned int size);
|
||||
|
||||
static Efreet_Icon *efreet_icon_new(const char *path);
|
||||
static void efreet_icon_free(Efreet_Icon *icon);
|
||||
static void efreet_icon_point_free(Efreet_Icon_Point *point);
|
||||
static void efreet_icon_populate(Efreet_Icon *icon, const char *file);
|
||||
|
||||
static Efreet_Icon *efreet_icon_cache_check(Efreet_Icon_Theme *theme,
|
||||
const char *name,
|
||||
unsigned int size);
|
||||
static void *efreet_icon_cache_get(Efreet_Icon_Theme *theme, const char *key);
|
||||
static void efreet_icon_cache_set(Efreet_Icon_Theme *theme,
|
||||
const char *key, void *value);
|
||||
static void efreet_icon_directory_cache(Efreet_Icon_Theme *theme,
|
||||
Efreet_Icon_Theme_Directory *dir,
|
||||
const char *path);
|
||||
static char *efreet_icon_lookup_directory_helper(Efreet_Icon_Theme_Directory *dir,
|
||||
const char *path, const char *icon_name);
|
||||
|
||||
static Efreet_Icon_Theme *efreet_icon_theme_new(void);
|
||||
static void efreet_icon_theme_free(Efreet_Icon_Theme *theme);
|
||||
|
@ -331,30 +313,24 @@ efreet_icon_find_theme_check(const char *theme_name)
|
|||
* if the icon is not found
|
||||
* @brief Retrieves all of the information about the given icon.
|
||||
*/
|
||||
Efreet_Icon *
|
||||
efreet_icon_find(const char *theme_name, const char *icon, const char *size)
|
||||
char *
|
||||
efreet_icon_path_find(const char *theme_name, const char *icon, const char *size)
|
||||
{
|
||||
const char *share_key;
|
||||
char cache_key[PATH_MAX];
|
||||
Efreet_Icon *value = NULL;
|
||||
char *value = NULL;
|
||||
Efreet_Icon_Theme *theme;
|
||||
const char *key_list[] = { icon, "@", size, NULL };
|
||||
|
||||
theme = efreet_icon_find_theme_check(theme_name);
|
||||
|
||||
efreet_array_cat(cache_key, sizeof(cache_key), key_list);
|
||||
|
||||
share_key = ecore_string_instance(cache_key);
|
||||
#ifdef SLOPPY_SPEC
|
||||
{
|
||||
char *tmp;
|
||||
|
||||
tmp = efreet_icon_remove_extension(icon);
|
||||
value = efreet_icon_find_helper(theme, share_key, tmp, size);
|
||||
value = efreet_icon_find_helper(theme, tmp, size);
|
||||
FREE(tmp);
|
||||
}
|
||||
#else
|
||||
value = efreet_icon_find_helper(theme, share_key, icon, size);
|
||||
value = efreet_icon_find_helper(theme, icon, size);
|
||||
#endif
|
||||
|
||||
/* we didn't find the icon in the theme or in the inherited directories
|
||||
|
@ -362,11 +338,6 @@ efreet_icon_find(const char *theme_name, const char *icon, const char *size)
|
|||
*/
|
||||
if (!value) value = efreet_icon_fallback_icon(icon);
|
||||
|
||||
efreet_icon_cache_set(theme, share_key, value);
|
||||
|
||||
if (value == (void *)NO_MATCH_KEY)
|
||||
value = NULL;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -374,35 +345,24 @@ efreet_icon_find(const char *theme_name, const char *icon, const char *size)
|
|||
* @param theme_name: The icon theme to look for
|
||||
* @param icon: List of icons to look for
|
||||
* @param size; The icon size to look for
|
||||
* @return Returns the Efreet_Icon structure representing first found icon or
|
||||
* @return Returns the path representing first found icon or
|
||||
* NULL if none of the icons are found
|
||||
* @brief Retrieves all of the information about the first found icon in
|
||||
* the list.
|
||||
* @note This function will search the given theme for all icons before falling
|
||||
* back. This is useful when searching for mimetype icons.
|
||||
*/
|
||||
Efreet_Icon *
|
||||
char *
|
||||
efreet_icon_list_find(const char *theme_name, Ecore_List *icons,
|
||||
const char *size)
|
||||
{
|
||||
Ecore_List *share_keys;
|
||||
char cache_key[PATH_MAX];
|
||||
const char *icon = NULL;
|
||||
const char *share_key = NULL;
|
||||
Efreet_Icon *value = NULL;
|
||||
char *value = NULL;
|
||||
Efreet_Icon_Theme *theme;
|
||||
|
||||
theme = efreet_icon_find_theme_check(theme_name);
|
||||
|
||||
share_keys = ecore_list_new();
|
||||
ecore_list_free_cb_set(share_keys,free);
|
||||
ecore_list_first_goto(icons);
|
||||
|
||||
while ((icon = ecore_list_next(icons)))
|
||||
{
|
||||
snprintf(cache_key, sizeof(cache_key),"%s@%s", icon, size);
|
||||
ecore_list_append(share_keys, strdup(cache_key));
|
||||
}
|
||||
#ifdef SLOPPY_SPEC
|
||||
{
|
||||
Ecore_List *tmps = NULL;
|
||||
|
@ -413,11 +373,11 @@ efreet_icon_list_find(const char *theme_name, Ecore_List *icons,
|
|||
while ((icon = ecore_list_next(icons)))
|
||||
ecore_list_append(tmps, efreet_icon_remove_extension(icon));
|
||||
|
||||
value = efreet_icon_list_find_helper(theme, share_keys, tmps, size);
|
||||
value = efreet_icon_list_find_helper(theme, tmps, size);
|
||||
ecore_list_destroy(tmps);
|
||||
}
|
||||
#else
|
||||
value = efreet_icon_list_find_helper(theme, share_keys, icons, size);
|
||||
value = efreet_icon_list_find_helper(theme, icons, size);
|
||||
#endif
|
||||
|
||||
/* we didn't find the icons in the theme or in the inherited directories
|
||||
|
@ -433,14 +393,6 @@ efreet_icon_list_find(const char *theme_name, Ecore_List *icons,
|
|||
}
|
||||
}
|
||||
|
||||
ecore_list_first_goto(share_keys);
|
||||
while ((share_key = ecore_list_next(share_keys)))
|
||||
efreet_icon_cache_set(theme, ecore_string_instance(share_key), value);
|
||||
ecore_list_destroy(share_keys);
|
||||
|
||||
if (value == (void *)NO_MATCH_KEY)
|
||||
value = NULL;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -451,32 +403,39 @@ efreet_icon_list_find(const char *theme_name, Ecore_List *icons,
|
|||
* @return Returns the path to the given icon or NULL if none found
|
||||
* @brief Retrives the path to the given icon.
|
||||
*/
|
||||
const char *
|
||||
efreet_icon_path_find(const char *theme, const char *icon, const char *size)
|
||||
Efreet_Icon *
|
||||
efreet_icon_find(const char *theme, const char *icon, const char *size)
|
||||
{
|
||||
Efreet_Icon *ico;
|
||||
char *path;
|
||||
|
||||
ico = efreet_icon_find(theme, icon, size);
|
||||
path = efreet_icon_path_find(theme, icon, size);
|
||||
if (path)
|
||||
{
|
||||
Efreet_Icon *icon;
|
||||
|
||||
return (ico ? ico->path : NULL);
|
||||
icon = efreet_icon_new(path);
|
||||
free(path);
|
||||
return icon;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @param theme: The theme to search in
|
||||
* @param cache_key: The cache key to use (icon\@sizexsize ecore_string)
|
||||
* @param icon: The icon to search for
|
||||
* @param size: The size to search for
|
||||
* @return Returns the icon matching the given information or NULL if no
|
||||
* icon found
|
||||
* @brief Scans inheriting themes for the given icon
|
||||
*/
|
||||
static Efreet_Icon *
|
||||
efreet_icon_find_fallback(Efreet_Icon_Theme *theme, const char *cache_key,
|
||||
static char *
|
||||
efreet_icon_find_fallback(Efreet_Icon_Theme *theme,
|
||||
const char *icon, const char *size)
|
||||
{
|
||||
char *parent = NULL;
|
||||
Efreet_Icon *value = NULL;
|
||||
char *value = NULL;
|
||||
|
||||
if (theme->inherits)
|
||||
{
|
||||
|
@ -488,8 +447,7 @@ efreet_icon_find_fallback(Efreet_Icon_Theme *theme, const char *cache_key,
|
|||
parent_theme = efreet_icon_theme_find(parent);
|
||||
if ((!parent_theme) || (parent_theme == theme)) continue;
|
||||
|
||||
value = efreet_icon_find_helper(parent_theme, cache_key,
|
||||
icon, size);
|
||||
value = efreet_icon_find_helper(parent_theme, icon, size);
|
||||
if (value) break;
|
||||
}
|
||||
}
|
||||
|
@ -501,8 +459,7 @@ efreet_icon_find_fallback(Efreet_Icon_Theme *theme, const char *cache_key,
|
|||
|
||||
parent_theme = efreet_icon_theme_find("hicolor");
|
||||
if (parent_theme)
|
||||
value = efreet_icon_find_helper(parent_theme, cache_key,
|
||||
icon, size);
|
||||
value = efreet_icon_find_helper(parent_theme, icon, size);
|
||||
}
|
||||
|
||||
return value;
|
||||
|
@ -511,27 +468,21 @@ efreet_icon_find_fallback(Efreet_Icon_Theme *theme, const char *cache_key,
|
|||
/**
|
||||
* @internal
|
||||
* @param theme: The theme to search in
|
||||
* @param cache_key: The cache key to use (icon\@sizexsize ecore_string)
|
||||
* @param icon: The icon to search for
|
||||
* @param size: The size to search for
|
||||
* @return Returns the icon matching the given information or NULL if no
|
||||
* icon found
|
||||
* @brief Scans the theme and any inheriting themes for the given icon
|
||||
*/
|
||||
static Efreet_Icon *
|
||||
efreet_icon_find_helper(Efreet_Icon_Theme *theme, const char *cache_key,
|
||||
const char *icon,
|
||||
const char *size)
|
||||
static char *
|
||||
efreet_icon_find_helper(Efreet_Icon_Theme *theme,
|
||||
const char *icon, const char *size)
|
||||
{
|
||||
Efreet_Icon *value;
|
||||
char *value;
|
||||
static int recurse = 0;
|
||||
|
||||
efreet_icon_theme_cache_check(theme);
|
||||
|
||||
/* see if this is in the cache already */
|
||||
value = efreet_icon_cache_get(theme, cache_key);
|
||||
if (value) return value;
|
||||
|
||||
/* go no further if this theme is fake */
|
||||
if (theme->fake || !theme->valid) return NULL;
|
||||
|
||||
|
@ -543,7 +494,7 @@ efreet_icon_find_helper(Efreet_Icon_Theme *theme, const char *cache_key,
|
|||
|
||||
/* we didin't find the image check the inherited themes */
|
||||
if (!value)
|
||||
value = efreet_icon_find_fallback(theme, cache_key, icon, size);
|
||||
value = efreet_icon_find_fallback(theme, icon, size);
|
||||
|
||||
recurse--;
|
||||
return value;
|
||||
|
@ -552,19 +503,18 @@ efreet_icon_find_helper(Efreet_Icon_Theme *theme, const char *cache_key,
|
|||
/**
|
||||
* @internal
|
||||
* @param theme: The theme to search in
|
||||
* @param cache_keys: The cache keys to use (icon\@sizexsize ecore_string)
|
||||
* @param icons: The icons to search for
|
||||
* @param size: The size to search for
|
||||
* @return Returns the icon matching the given information or NULL if no
|
||||
* icon found
|
||||
* @brief Scans inheriting themes for the given icons
|
||||
*/
|
||||
static Efreet_Icon *
|
||||
efreet_icon_list_find_fallback(Efreet_Icon_Theme *theme, Ecore_List *cache_keys,
|
||||
static char *
|
||||
efreet_icon_list_find_fallback(Efreet_Icon_Theme *theme,
|
||||
Ecore_List *icons, const char *size)
|
||||
{
|
||||
char *parent = NULL;
|
||||
Efreet_Icon *value = NULL;
|
||||
char *value = NULL;
|
||||
|
||||
if (theme->inherits)
|
||||
{
|
||||
|
@ -576,7 +526,7 @@ efreet_icon_list_find_fallback(Efreet_Icon_Theme *theme, Ecore_List *cache_keys,
|
|||
parent_theme = efreet_icon_theme_find(parent);
|
||||
if ((!parent_theme) || (parent_theme == theme)) continue;
|
||||
|
||||
value = efreet_icon_list_find_helper(parent_theme, cache_keys,
|
||||
value = efreet_icon_list_find_helper(parent_theme,
|
||||
icons, size);
|
||||
if (value) break;
|
||||
}
|
||||
|
@ -591,7 +541,7 @@ efreet_icon_list_find_fallback(Efreet_Icon_Theme *theme, Ecore_List *cache_keys,
|
|||
|
||||
parent_theme = efreet_icon_theme_find("hicolor");
|
||||
if (parent_theme)
|
||||
value = efreet_icon_list_find_helper(parent_theme, cache_keys,
|
||||
value = efreet_icon_list_find_helper(parent_theme,
|
||||
icons, size);
|
||||
}
|
||||
|
||||
|
@ -601,33 +551,22 @@ efreet_icon_list_find_fallback(Efreet_Icon_Theme *theme, Ecore_List *cache_keys,
|
|||
/**
|
||||
* @internal
|
||||
* @param theme: The theme to search in
|
||||
* @param cache_keys: The cache keys to use (icon\@sizexsize ecore_string)
|
||||
* @param icons: The icons to search for
|
||||
* @param size: The size to search for
|
||||
* @return Returns the icon matching the given information or NULL if no
|
||||
* icon found
|
||||
* @brief Scans the theme and any inheriting themes for the given icons
|
||||
*/
|
||||
static Efreet_Icon *
|
||||
efreet_icon_list_find_helper(Efreet_Icon_Theme *theme, Ecore_List *cache_keys,
|
||||
Ecore_List *icons,
|
||||
const char *size)
|
||||
static char *
|
||||
efreet_icon_list_find_helper(Efreet_Icon_Theme *theme,
|
||||
Ecore_List *icons, const char *size)
|
||||
{
|
||||
Efreet_Icon *value = NULL;
|
||||
char *value = NULL;
|
||||
const char *icon = NULL;
|
||||
const char *cache_key = NULL;
|
||||
static int recurse = 0;
|
||||
|
||||
efreet_icon_theme_cache_check(theme);
|
||||
|
||||
/* see if this is in the cache already */
|
||||
ecore_list_first_goto(cache_keys);
|
||||
while ((cache_key = ecore_list_next(cache_keys)))
|
||||
{
|
||||
if ((value = efreet_icon_cache_get(theme, cache_key)))
|
||||
return value;
|
||||
}
|
||||
|
||||
/* go no further if this theme is fake */
|
||||
if (theme->fake || !theme->valid) return NULL;
|
||||
|
||||
|
@ -644,7 +583,7 @@ efreet_icon_list_find_helper(Efreet_Icon_Theme *theme, Ecore_List *cache_keys,
|
|||
|
||||
/* we didn't find the image check the inherited themes */
|
||||
if (!value)
|
||||
value = efreet_icon_list_find_fallback(theme, cache_keys, icons, size);
|
||||
value = efreet_icon_list_find_fallback(theme, icons, size);
|
||||
|
||||
recurse--;
|
||||
return value;
|
||||
|
@ -655,15 +594,15 @@ efreet_icon_list_find_helper(Efreet_Icon_Theme *theme, Ecore_List *cache_keys,
|
|||
* @param theme: The icon theme to look in
|
||||
* @param icon_name: The icon name to look for
|
||||
* @param size: The icon size to look for
|
||||
* @return Returns the Efreet_Icon for the theme/icon/size combo or NULL if
|
||||
* @return Returns the path for the theme/icon/size combo or NULL if
|
||||
* none found
|
||||
* @brief Looks for the @a icon in the @a theme for the @a size given.
|
||||
*/
|
||||
static Efreet_Icon *
|
||||
static char *
|
||||
efreet_icon_lookup_icon(Efreet_Icon_Theme *theme, const char *icon_name,
|
||||
const char *size)
|
||||
{
|
||||
Efreet_Icon *icon = NULL, *tmp = NULL;
|
||||
char *icon = NULL, *tmp = NULL;
|
||||
Efreet_Icon_Theme_Directory *dir;
|
||||
int minimal_size = INT_MAX;
|
||||
unsigned int real_size;
|
||||
|
@ -696,25 +635,12 @@ efreet_icon_lookup_icon(Efreet_Icon_Theme *theme, const char *icon_name,
|
|||
icon_name);
|
||||
if (tmp)
|
||||
{
|
||||
FREE(icon);
|
||||
icon = tmp;
|
||||
minimal_size = distance;
|
||||
}
|
||||
}
|
||||
|
||||
if (icon)
|
||||
{
|
||||
char cache_key[PATH_MAX];
|
||||
const char *key;
|
||||
|
||||
snprintf(cache_key, sizeof(cache_key), "%s@%dx%d", icon_name, real_size, real_size);
|
||||
key = ecore_string_instance(cache_key);
|
||||
|
||||
if (!efreet_icon_cache_get(theme, key))
|
||||
efreet_icon_cache_set(theme, key, icon);
|
||||
else
|
||||
ecore_string_release(cache_key);
|
||||
}
|
||||
|
||||
return icon;
|
||||
}
|
||||
|
||||
|
@ -729,24 +655,28 @@ efreet_icon_lookup_icon(Efreet_Icon_Theme *theme, const char *icon_name,
|
|||
* none found
|
||||
* @brief Tries to find the file closest matching the given icon
|
||||
*/
|
||||
static Efreet_Icon *
|
||||
static char *
|
||||
efreet_icon_lookup_directory(Efreet_Icon_Theme *theme,
|
||||
Efreet_Icon_Theme_Directory *dir,
|
||||
const char *icon_name)
|
||||
{
|
||||
if (theme->paths.count == 1)
|
||||
efreet_icon_directory_cache(theme, dir, theme->paths.path);
|
||||
return efreet_icon_lookup_directory_helper(dir, theme->paths.path, icon_name);
|
||||
|
||||
else
|
||||
{
|
||||
char *icon;
|
||||
const char *path;
|
||||
|
||||
ecore_list_first_goto(theme->paths.path);
|
||||
while ((path = ecore_list_next(theme->paths.path)))
|
||||
efreet_icon_directory_cache(theme, dir, path);
|
||||
{
|
||||
icon = efreet_icon_lookup_directory_helper(dir, path, icon_name);
|
||||
if (icon) return icon;
|
||||
}
|
||||
}
|
||||
|
||||
return efreet_icon_cache_check(theme, icon_name, dir->size.normal);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -817,10 +747,10 @@ efreet_icon_directory_size_distance(Efreet_Icon_Theme_Directory *dir,
|
|||
* @return Returns the Efreet_Icon for the given name or NULL if none found
|
||||
* @brief Looks for the un-themed icon in the base directories
|
||||
*/
|
||||
static Efreet_Icon *
|
||||
static char *
|
||||
efreet_icon_fallback_icon(const char *icon_name)
|
||||
{
|
||||
Efreet_Icon *icon;
|
||||
char *icon;
|
||||
|
||||
if (!icon_name) return NULL;
|
||||
|
||||
|
@ -863,10 +793,10 @@ efreet_icon_fallback_icon(const char *icon_name)
|
|||
* @brief Scans the given @a dir for the given @a icon_name returning the
|
||||
* Efreet_icon if found, NULL otherwise.
|
||||
*/
|
||||
static Efreet_Icon *
|
||||
static char *
|
||||
efreet_icon_fallback_dir_scan(const char *dir, const char *icon_name)
|
||||
{
|
||||
Efreet_Icon *icon = NULL;
|
||||
char *icon = NULL;
|
||||
char path[PATH_MAX], *ext;
|
||||
|
||||
if (!dir || !icon_name) return NULL;
|
||||
|
@ -879,7 +809,7 @@ efreet_icon_fallback_dir_scan(const char *dir, const char *icon_name)
|
|||
|
||||
if (ecore_file_exists(path))
|
||||
{
|
||||
icon = efreet_icon_new(path);
|
||||
icon = strdup(path);
|
||||
if (icon) break;
|
||||
}
|
||||
}
|
||||
|
@ -892,7 +822,7 @@ efreet_icon_fallback_dir_scan(const char *dir, const char *icon_name)
|
|||
|
||||
if (ecore_file_exists(path))
|
||||
{
|
||||
icon = efreet_icon_new(path);
|
||||
icon = strdup(path);
|
||||
#ifdef STRICT_SPEC
|
||||
if (icon)
|
||||
printf("[Efreet]: Found an icon that already has an extension: %s\n", path);
|
||||
|
@ -913,158 +843,29 @@ efreet_icon_fallback_dir_scan(const char *dir, const char *icon_name)
|
|||
* @brief Caches the icons in the given theme directory path at the given
|
||||
* size
|
||||
*/
|
||||
static void
|
||||
efreet_icon_directory_cache(Efreet_Icon_Theme *theme,
|
||||
Efreet_Icon_Theme_Directory *dir, const char *path)
|
||||
static char *
|
||||
efreet_icon_lookup_directory_helper(Efreet_Icon_Theme_Directory *dir,
|
||||
const char *path, const char *icon_name)
|
||||
{
|
||||
char file_path[PATH_MAX], size_str[10];
|
||||
const char *dir_key, *path_strs[] = { path, "/", dir->name, NULL };
|
||||
DIR *dirp;
|
||||
struct dirent *file;
|
||||
char *icon = NULL;
|
||||
char file_path[PATH_MAX];
|
||||
const char *ext, *path_strs[] = { path, "/", dir->name, "/", icon_name, NULL, NULL };
|
||||
|
||||
/* make sure the cache exists, create if needed */
|
||||
if (!efreet_icon_dirs_cached)
|
||||
ecore_list_first_goto(efreet_icon_extensions);
|
||||
while ((ext = ecore_list_next(efreet_icon_extensions)))
|
||||
{
|
||||
efreet_icon_dirs_cached = ecore_hash_new(NULL, NULL);
|
||||
ecore_hash_free_key_cb_set(efreet_icon_dirs_cached,
|
||||
ECORE_FREE_CB(ecore_string_release));
|
||||
}
|
||||
|
||||
path_strs[5] = ext;
|
||||
efreet_array_cat(file_path, sizeof(file_path), path_strs);
|
||||
|
||||
/* if we've already cached this directory don't do it again */
|
||||
dir_key = ecore_string_instance(file_path);
|
||||
if (ecore_hash_get(efreet_icon_dirs_cached, dir_key)) return;
|
||||
|
||||
ecore_hash_set(efreet_icon_dirs_cached, (void *)dir_key, (void *)1);
|
||||
|
||||
snprintf(size_str, sizeof(size_str), "%d", dir->size.normal);
|
||||
dirp = opendir(file_path);
|
||||
if (dirp)
|
||||
if (ecore_file_exists(file_path))
|
||||
{
|
||||
while ((file = readdir(dirp)))
|
||||
{
|
||||
char key_str[PATH_MAX], *ext, *name;
|
||||
const char *key, *name_strs[] = {NULL, "@", size_str, "x", size_str, NULL};
|
||||
Efreet_Icon *value;
|
||||
|
||||
name = strdup(file->d_name);
|
||||
name_strs[0] = name;
|
||||
|
||||
/* Drop the extension to cache icon name */
|
||||
ext = strrchr(name, '.');
|
||||
if (!ext)
|
||||
{
|
||||
FREE(name);
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* we need to skip .icon files as their used for
|
||||
* informational purposes only */
|
||||
if (!strcmp(ext, ".icon"))
|
||||
{
|
||||
FREE(name);
|
||||
continue;
|
||||
}
|
||||
*ext = '\0';
|
||||
}
|
||||
|
||||
efreet_array_cat(key_str, sizeof(key_str), name_strs);
|
||||
key = ecore_string_instance(key_str);
|
||||
FREE(name);
|
||||
|
||||
/* Check for an existing cached icon */
|
||||
value = ecore_hash_get(theme->icon_cache, key);
|
||||
if (value == (void *)NO_MATCH_KEY) value = NULL;
|
||||
|
||||
if (!value)
|
||||
{
|
||||
const char *icon_path[] = { path, "/", dir->name, "/", file->d_name, NULL };
|
||||
|
||||
/* No icon present, build a full path and generate icon */
|
||||
efreet_array_cat(file_path, sizeof(file_path), icon_path);
|
||||
value = efreet_icon_new(file_path);
|
||||
|
||||
/* Add icon to cache */
|
||||
if (value)
|
||||
{
|
||||
value->ref_count++;
|
||||
ecore_hash_set(theme->icon_cache, (void *)key, value);
|
||||
icon = strdup(file_path);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
closedir(dirp);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param theme: The theme to work with
|
||||
* @param name: The icon name to look for
|
||||
* @param size: The icon size to look for
|
||||
* @return Returns the icon in the @a themes cache for @a name and @a size
|
||||
* or NULL if none found
|
||||
* @brief Looks up the @a name'd icon at @a size in the @a themes cache
|
||||
*/
|
||||
static Efreet_Icon *
|
||||
efreet_icon_cache_check(Efreet_Icon_Theme *theme, const char *name, unsigned int size)
|
||||
{
|
||||
Efreet_Icon *icon = NULL;
|
||||
char size_ext[PATH_MAX];
|
||||
|
||||
snprintf(size_ext, sizeof(size_ext), "%dx%d", size, size);
|
||||
{
|
||||
char icon_path[PATH_MAX];
|
||||
const char *share_key[] = { name, "@", size_ext, NULL };
|
||||
const char *cache_key;
|
||||
|
||||
efreet_array_cat(icon_path, sizeof(icon_path), share_key);
|
||||
cache_key = ecore_string_instance(icon_path);
|
||||
icon = efreet_icon_cache_get(theme, cache_key);
|
||||
}
|
||||
|
||||
return icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @param theme: The theme to get the icon from
|
||||
* @param key: The key to lookup in the cache. The key must be an
|
||||
* ecore_string.
|
||||
* @return Returns the icon for the given key or NULL if none found.
|
||||
* @brief Retrives the icon for the given @a key or NULL if no icon for that key.
|
||||
*/
|
||||
static void *
|
||||
efreet_icon_cache_get(Efreet_Icon_Theme *theme, const char *key)
|
||||
{
|
||||
return ecore_hash_get(theme->icon_cache, key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param theme: The theme to work with
|
||||
* @param key: The key to cache, this key must be an ecore_string
|
||||
* @param value: The value to hash for the given key
|
||||
* @return Returns no value
|
||||
* @brief Adds the given @a value into the @a themes hash for @a key
|
||||
*/
|
||||
static void
|
||||
efreet_icon_cache_set(Efreet_Icon_Theme *theme, const char *key, void *value)
|
||||
{
|
||||
/* add back to the cache */
|
||||
/* XXX this is a bit inefficient as I'll end up adding back to the cache
|
||||
* even if I found the item in the cache. Not a big deal at the moment
|
||||
* tho. */
|
||||
if (!value)
|
||||
ecore_hash_set(theme->icon_cache, (void *)key, NO_MATCH_KEY);
|
||||
else
|
||||
{
|
||||
if (value != NO_MATCH_KEY) ((Efreet_Icon *)value)->ref_count++;
|
||||
|
||||
ecore_hash_set(theme->icon_cache, (void *)key, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @return Returns a new Efreet_Icon struct on success or NULL on failure
|
||||
|
@ -1109,15 +910,14 @@ efreet_icon_new(const char *path)
|
|||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @param icon: The Efreet_Icon to cleanup
|
||||
* @return Returns no value.
|
||||
* @brief Free's the given icon and all its internal data.
|
||||
*/
|
||||
static void
|
||||
void
|
||||
efreet_icon_free(Efreet_Icon *icon)
|
||||
{
|
||||
if (!icon || (icon == (void *)NO_MATCH_KEY)) return;
|
||||
if (!icon) return;
|
||||
|
||||
icon->ref_count --;
|
||||
if (icon->ref_count > 0) return;
|
||||
|
@ -1284,8 +1084,6 @@ efreet_icon_theme_free(Efreet_Icon_Theme *theme)
|
|||
IF_FREE_LIST(theme->inherits);
|
||||
IF_FREE_LIST(theme->directories);
|
||||
|
||||
IF_FREE_HASH(theme->icon_cache);
|
||||
|
||||
FREE(theme);
|
||||
}
|
||||
|
||||
|
@ -1359,19 +1157,6 @@ efreet_icon_theme_cache_check(Efreet_Icon_Theme *theme)
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* When the cache is invalided it will delete the cache. Make sure we
|
||||
* have a cache before we finish */
|
||||
if (!theme->icon_cache)
|
||||
{
|
||||
theme->icon_cache = ecore_hash_new(NULL, NULL);
|
||||
ecore_hash_free_key_cb_set(theme->icon_cache,
|
||||
ECORE_FREE_CB(ecore_string_release));
|
||||
ecore_hash_free_value_cb_set(theme->icon_cache,
|
||||
ECORE_FREE_CB(efreet_icon_free));
|
||||
}
|
||||
|
||||
theme->last_cache_check = new_check;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1392,7 +1177,6 @@ efreet_icon_theme_cache_check_dir(Efreet_Icon_Theme *theme, const char *dir)
|
|||
{
|
||||
if (efreet_icon_dirs_cached)
|
||||
ecore_hash_remove(efreet_icon_dirs_cached, dir);
|
||||
IF_FREE_HASH(theme->icon_cache);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -79,7 +79,6 @@ struct Efreet_Icon_Theme
|
|||
Ecore_List *directories; /**< List of subdirectories for this theme */
|
||||
|
||||
double last_cache_check; /**< Last time the cache was checked */
|
||||
Ecore_Hash *icon_cache; /**< Cache of the icon data */
|
||||
|
||||
unsigned char hidden:1; /**< Should this theme be hidden from users */
|
||||
unsigned char valid:1; /**< Have we seen an index for this theme */
|
||||
|
@ -167,11 +166,12 @@ Ecore_List *efreet_icon_theme_list_get(void);
|
|||
Efreet_Icon_Theme *efreet_icon_theme_find(const char *theme_name);
|
||||
Efreet_Icon *efreet_icon_find(const char *theme_name, const char *icon,
|
||||
const char *size);
|
||||
Efreet_Icon *efreet_icon_list_find(const char *theme_name,
|
||||
char *efreet_icon_list_find(const char *theme_name,
|
||||
Ecore_List *icons,
|
||||
const char *size);
|
||||
const char *efreet_icon_path_find(const char *theme, const char *icon,
|
||||
char *efreet_icon_path_find(const char *theme, const char *icon,
|
||||
const char *size);
|
||||
void efreet_icon_free(Efreet_Icon *icon);
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
|
|
@ -132,6 +132,7 @@ efreet_mime_shutdown(void)
|
|||
IF_FREE_LIST(globs);
|
||||
IF_FREE_LIST(magics);
|
||||
IF_FREE_HASH(monitors);
|
||||
IF_FREE_HASH(wild);
|
||||
|
||||
efreet_shutdown();
|
||||
ecore_file_shutdown();
|
||||
|
@ -177,10 +178,10 @@ efreet_mime_type_get(const char *file)
|
|||
* @return Returns mime type icon path as a string
|
||||
* @brief Retreive the mime type icon for a file
|
||||
*/
|
||||
const char *
|
||||
char *
|
||||
efreet_mime_type_icon_get(const char *mime, const char *theme, const char *size)
|
||||
{
|
||||
Efreet_Icon *icon = NULL;
|
||||
char *icon = NULL;
|
||||
Ecore_List *icons = NULL;
|
||||
const char *env = NULL;
|
||||
char *p = NULL, *pp = NULL, *ppp = NULL;
|
||||
|
@ -236,10 +237,7 @@ efreet_mime_type_icon_get(const char *mime, const char *theme, const char *size)
|
|||
|
||||
ecore_list_destroy(icons);
|
||||
|
||||
if (icon)
|
||||
return icon->path;
|
||||
|
||||
return NULL;
|
||||
return icon;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue