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 <Efreet.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include "comp.h"
|
#include "comp.h"
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int i = 0, k;
|
int i = 0, k;
|
||||||
const char *path;
|
char *path;
|
||||||
|
|
||||||
efreet_init();
|
efreet_init();
|
||||||
|
|
||||||
|
@ -16,6 +17,7 @@ main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
path = efreet_icon_path_find(THEME, icons[i], SIZE);
|
path = efreet_icon_path_find(THEME, icons[i], SIZE);
|
||||||
// printf("%s: %s\n", icons[i], (path ? path : "NOT FOUND"));
|
// printf("%s: %s\n", icons[i], (path ? path : "NOT FOUND"));
|
||||||
|
if (path) free(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#define PATH_MAX 4096
|
#define PATH_MAX 4096
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SIZE "16x16"
|
#define SIZE "128x128"
|
||||||
#define THEME "Tango"
|
#define THEME "Tango"
|
||||||
|
|
||||||
static void ef_icon_theme_themes_find(const char *search_dir,
|
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++)
|
for (i = 0; icons[i] != NULL; i++)
|
||||||
{
|
{
|
||||||
const char *path;
|
char *path, *s;
|
||||||
char *t, *s;
|
|
||||||
|
|
||||||
path = efreet_icon_path_find(THEME, icons[i], SIZE);
|
path = efreet_icon_path_find(THEME, icons[i], SIZE);
|
||||||
|
|
||||||
|
@ -465,10 +464,9 @@ ef_cb_efreet_icon_match(void)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
t = strdup(path);
|
s = strrchr(path, '.');
|
||||||
s = strrchr(t, '.');
|
|
||||||
if (s) *s = '\0';
|
if (s) *s = '\0';
|
||||||
s = strrchr(t, '/');
|
s = strrchr(path, '/');
|
||||||
if (s) s++;
|
if (s) s++;
|
||||||
|
|
||||||
if (s && strcmp(s, icons[i]))
|
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);
|
printf("Name mismatch name (%s) vs ef (%s)\n", icons[i], s);
|
||||||
ret = 0;
|
ret = 0;
|
||||||
}
|
}
|
||||||
free(t);
|
free(path);
|
||||||
}
|
}
|
||||||
ecore_hash_destroy(icon_hash);
|
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_special_type_get(const char *file);
|
||||||
const char *efreet_mime_fallback_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);
|
const char *size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2,12 +2,10 @@
|
||||||
#include "Efreet.h"
|
#include "Efreet.h"
|
||||||
#include "efreet_private.h"
|
#include "efreet_private.h"
|
||||||
|
|
||||||
#define NO_MATCH_KEY ((char *)0xdeadbeef)
|
|
||||||
|
|
||||||
static char *efreet_icon_deprecated_user_dir = NULL;
|
static char *efreet_icon_deprecated_user_dir = NULL;
|
||||||
static char *efreet_icon_user_dir = NULL;
|
static char *efreet_icon_user_dir = NULL;
|
||||||
static Ecore_Hash *efreet_icon_dirs_cached = NULL;
|
static Ecore_Hash *efreet_icon_dirs_cached = NULL;
|
||||||
static Ecore_Hash *efreet_icon_themes = NULL;
|
static Ecore_Hash *efreet_icon_themes = NULL;
|
||||||
Ecore_List *efreet_icon_extensions = NULL;
|
Ecore_List *efreet_icon_extensions = NULL;
|
||||||
static Ecore_List *efreet_extra_icon_dirs = NULL;
|
static Ecore_List *efreet_extra_icon_dirs = NULL;
|
||||||
|
|
||||||
|
@ -17,52 +15,36 @@ 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_Theme *efreet_icon_find_theme_check(const char *theme_name);
|
||||||
|
|
||||||
|
|
||||||
static Efreet_Icon *efreet_icon_find_fallback(Efreet_Icon_Theme *theme,
|
static char *efreet_icon_find_fallback(Efreet_Icon_Theme *theme,
|
||||||
const char *cache_key,
|
const char *icon,
|
||||||
const char *icon,
|
const char *size);
|
||||||
const char *size);
|
static char *efreet_icon_list_find_fallback(Efreet_Icon_Theme *theme,
|
||||||
static Efreet_Icon *efreet_icon_list_find_fallback(Efreet_Icon_Theme *theme,
|
Ecore_List *icons,
|
||||||
Ecore_List *cache_keys,
|
const char *size);
|
||||||
Ecore_List *icons,
|
static char *efreet_icon_find_helper(Efreet_Icon_Theme *theme,
|
||||||
const char *size);
|
const char *icon, const char *size);
|
||||||
static Efreet_Icon *efreet_icon_find_helper(Efreet_Icon_Theme *theme,
|
static char *efreet_icon_list_find_helper(Efreet_Icon_Theme *theme,
|
||||||
const char *cache_key,
|
Ecore_List *icons, const char *size);
|
||||||
const char *icon,
|
static char *efreet_icon_lookup_icon(Efreet_Icon_Theme *theme,
|
||||||
const char *size);
|
const char *icon_name, const char *size);
|
||||||
static Efreet_Icon *efreet_icon_list_find_helper(Efreet_Icon_Theme *theme,
|
static char *efreet_icon_fallback_icon(const char *icon_name);
|
||||||
Ecore_List *cache_keys,
|
static char *efreet_icon_fallback_dir_scan(const char *dir,
|
||||||
Ecore_List *icons,
|
const char *icon_name);
|
||||||
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,
|
|
||||||
const char *icon_name);
|
|
||||||
|
|
||||||
static Efreet_Icon *efreet_icon_lookup_directory(
|
static char *efreet_icon_lookup_directory(Efreet_Icon_Theme *theme,
|
||||||
Efreet_Icon_Theme *theme,
|
Efreet_Icon_Theme_Directory *dir,
|
||||||
Efreet_Icon_Theme_Directory *dir,
|
const char *icon_name);
|
||||||
const char *icon_name);
|
|
||||||
static int efreet_icon_directory_size_distance(Efreet_Icon_Theme_Directory *dir,
|
static int efreet_icon_directory_size_distance(Efreet_Icon_Theme_Directory *dir,
|
||||||
unsigned int size);
|
unsigned int size);
|
||||||
static int efreet_icon_directory_size_match(Efreet_Icon_Theme_Directory *dir,
|
static int efreet_icon_directory_size_match(Efreet_Icon_Theme_Directory *dir,
|
||||||
unsigned int size);
|
unsigned int size);
|
||||||
|
|
||||||
static Efreet_Icon *efreet_icon_new(const char *path);
|
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_point_free(Efreet_Icon_Point *point);
|
||||||
static void efreet_icon_populate(Efreet_Icon *icon, const char *file);
|
static void efreet_icon_populate(Efreet_Icon *icon, const char *file);
|
||||||
|
|
||||||
static Efreet_Icon *efreet_icon_cache_check(Efreet_Icon_Theme *theme,
|
static char *efreet_icon_lookup_directory_helper(Efreet_Icon_Theme_Directory *dir,
|
||||||
const char *name,
|
const char *path, const char *icon_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 Efreet_Icon_Theme *efreet_icon_theme_new(void);
|
static Efreet_Icon_Theme *efreet_icon_theme_new(void);
|
||||||
static void efreet_icon_theme_free(Efreet_Icon_Theme *theme);
|
static void efreet_icon_theme_free(Efreet_Icon_Theme *theme);
|
||||||
|
@ -70,17 +52,17 @@ static void efreet_icon_theme_dir_scan_all(const char *theme_name);
|
||||||
static void efreet_icon_theme_dir_scan(const char *dir,
|
static void efreet_icon_theme_dir_scan(const char *dir,
|
||||||
const char *theme_name);
|
const char *theme_name);
|
||||||
static void efreet_icon_theme_dir_validity_check(void);
|
static void efreet_icon_theme_dir_validity_check(void);
|
||||||
static void efreet_icon_theme_path_add(Efreet_Icon_Theme *theme,
|
static void efreet_icon_theme_path_add(Efreet_Icon_Theme *theme,
|
||||||
const char *path);
|
const char *path);
|
||||||
static void efreet_icon_theme_index_read(Efreet_Icon_Theme *theme,
|
static void efreet_icon_theme_index_read(Efreet_Icon_Theme *theme,
|
||||||
const char *path);
|
const char *path);
|
||||||
|
|
||||||
static Efreet_Icon_Theme_Directory *efreet_icon_theme_directory_new(Efreet_Ini *ini,
|
static Efreet_Icon_Theme_Directory *efreet_icon_theme_directory_new(Efreet_Ini *ini,
|
||||||
const char *name);
|
const char *name);
|
||||||
static void efreet_icon_theme_directory_free(Efreet_Icon_Theme_Directory *dir);
|
static void efreet_icon_theme_directory_free(Efreet_Icon_Theme_Directory *dir);
|
||||||
|
|
||||||
static void efreet_icon_theme_cache_check(Efreet_Icon_Theme *theme);
|
static void efreet_icon_theme_cache_check(Efreet_Icon_Theme *theme);
|
||||||
static int efreet_icon_theme_cache_check_dir(Efreet_Icon_Theme *theme,
|
static int efreet_icon_theme_cache_check_dir(Efreet_Icon_Theme *theme,
|
||||||
const char *dir);
|
const char *dir);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -88,7 +70,7 @@ static int efreet_icon_theme_cache_check_dir(Efreet_Icon_Theme *theme,
|
||||||
* @return Returns 1 on success or 0 on failure
|
* @return Returns 1 on success or 0 on failure
|
||||||
* @brief Initializes the icon system
|
* @brief Initializes the icon system
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
efreet_icon_init(void)
|
efreet_icon_init(void)
|
||||||
{
|
{
|
||||||
if (efreet_icon_init_count++ > 0)
|
if (efreet_icon_init_count++ > 0)
|
||||||
|
@ -113,7 +95,7 @@ efreet_icon_init(void)
|
||||||
ecore_list_append(efreet_icon_extensions, strdup(default_exts[i]));
|
ecore_list_append(efreet_icon_extensions, strdup(default_exts[i]));
|
||||||
|
|
||||||
efreet_icon_themes = ecore_hash_new(NULL, NULL);
|
efreet_icon_themes = ecore_hash_new(NULL, NULL);
|
||||||
ecore_hash_free_value_cb_set(efreet_icon_themes,
|
ecore_hash_free_value_cb_set(efreet_icon_themes,
|
||||||
ECORE_FREE_CB(efreet_icon_theme_free));
|
ECORE_FREE_CB(efreet_icon_theme_free));
|
||||||
efreet_extra_icon_dirs = ecore_list_new();
|
efreet_extra_icon_dirs = ecore_list_new();
|
||||||
}
|
}
|
||||||
|
@ -207,8 +189,8 @@ efreet_icon_extra_list_get(void)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Returns a list of Efreet_Icon structs for all the non-hidden icon
|
* @return Returns a list of Efreet_Icon structs for all the non-hidden icon
|
||||||
* themes
|
* themes
|
||||||
* @brief Retrieves all of the non-hidden icon themes available on the system.
|
* @brief Retrieves all of the non-hidden icon themes available on the system.
|
||||||
* The returned list must be freed. Do not free the list data.
|
* The returned list must be freed. Do not free the list data.
|
||||||
*/
|
*/
|
||||||
Ecore_List *
|
Ecore_List *
|
||||||
|
@ -288,7 +270,7 @@ efreet_icon_remove_extension(const char *icon)
|
||||||
if (!strcmp(ext, ext2))
|
if (!strcmp(ext, ext2))
|
||||||
{
|
{
|
||||||
#ifdef STRICT_SPEC
|
#ifdef STRICT_SPEC
|
||||||
printf("[Efreet]: Requesting an icon with an extension: %s\n",
|
printf("[Efreet]: Requesting an icon with an extension: %s\n",
|
||||||
icon);
|
icon);
|
||||||
#endif
|
#endif
|
||||||
*ext = '\0';
|
*ext = '\0';
|
||||||
|
@ -318,8 +300,8 @@ efreet_icon_find_theme_check(const char *theme_name)
|
||||||
theme->fake = 1;
|
theme->fake = 1;
|
||||||
theme->name.internal = ecore_string_instance(theme_name);
|
theme->name.internal = ecore_string_instance(theme_name);
|
||||||
ecore_hash_set(efreet_icon_themes, (void *)theme->name.internal, theme);
|
ecore_hash_set(efreet_icon_themes, (void *)theme->name.internal, theme);
|
||||||
}
|
}
|
||||||
|
|
||||||
return theme;
|
return theme;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -331,42 +313,31 @@ efreet_icon_find_theme_check(const char *theme_name)
|
||||||
* if the icon is not found
|
* if the icon is not found
|
||||||
* @brief Retrieves all of the information about the given icon.
|
* @brief Retrieves all of the information about the given icon.
|
||||||
*/
|
*/
|
||||||
Efreet_Icon *
|
char *
|
||||||
efreet_icon_find(const char *theme_name, const char *icon, const char *size)
|
efreet_icon_path_find(const char *theme_name, const char *icon, const char *size)
|
||||||
{
|
{
|
||||||
const char *share_key;
|
char *value = NULL;
|
||||||
char cache_key[PATH_MAX];
|
|
||||||
Efreet_Icon *value = NULL;
|
|
||||||
Efreet_Icon_Theme *theme;
|
Efreet_Icon_Theme *theme;
|
||||||
const char *key_list[] = { icon, "@", size, NULL };
|
|
||||||
|
|
||||||
theme = efreet_icon_find_theme_check(theme_name);
|
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
|
#ifdef SLOPPY_SPEC
|
||||||
{
|
{
|
||||||
char *tmp;
|
char *tmp;
|
||||||
|
|
||||||
tmp = efreet_icon_remove_extension(icon);
|
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);
|
FREE(tmp);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
value = efreet_icon_find_helper(theme, share_key, icon, size);
|
value = efreet_icon_find_helper(theme, icon, size);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* we didn't find the icon in the theme or in the inherited directories
|
/* we didn't find the icon in the theme or in the inherited directories
|
||||||
* then just look for a non theme icon
|
* then just look for a non theme icon
|
||||||
*/
|
*/
|
||||||
if (!value) value = efreet_icon_fallback_icon(icon);
|
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;
|
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 theme_name: The icon theme to look for
|
||||||
* @param icon: List of icons to look for
|
* @param icon: List of icons to look for
|
||||||
* @param size; The icon size 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
|
* NULL if none of the icons are found
|
||||||
* @brief Retrieves all of the information about the first found icon in
|
* @brief Retrieves all of the information about the first found icon in
|
||||||
* the list.
|
* the list.
|
||||||
* @note This function will search the given theme for all icons before falling
|
* @note This function will search the given theme for all icons before falling
|
||||||
* back. This is useful when searching for mimetype icons.
|
* back. This is useful when searching for mimetype icons.
|
||||||
*/
|
*/
|
||||||
Efreet_Icon *
|
char *
|
||||||
efreet_icon_list_find(const char *theme_name, Ecore_List *icons,
|
efreet_icon_list_find(const char *theme_name, Ecore_List *icons,
|
||||||
const char *size)
|
const char *size)
|
||||||
{
|
{
|
||||||
Ecore_List *share_keys;
|
|
||||||
char cache_key[PATH_MAX];
|
|
||||||
const char *icon = NULL;
|
const char *icon = NULL;
|
||||||
const char *share_key = NULL;
|
char *value = NULL;
|
||||||
Efreet_Icon *value = NULL;
|
|
||||||
Efreet_Icon_Theme *theme;
|
Efreet_Icon_Theme *theme;
|
||||||
|
|
||||||
theme = efreet_icon_find_theme_check(theme_name);
|
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);
|
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
|
#ifdef SLOPPY_SPEC
|
||||||
{
|
{
|
||||||
Ecore_List *tmps = NULL;
|
Ecore_List *tmps = NULL;
|
||||||
|
@ -412,18 +372,18 @@ efreet_icon_list_find(const char *theme_name, Ecore_List *icons,
|
||||||
ecore_list_first_goto(icons);
|
ecore_list_first_goto(icons);
|
||||||
while ((icon = ecore_list_next(icons)))
|
while ((icon = ecore_list_next(icons)))
|
||||||
ecore_list_append(tmps, efreet_icon_remove_extension(icon));
|
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);
|
ecore_list_destroy(tmps);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
value = efreet_icon_list_find_helper(theme, share_keys, icons, size);
|
value = efreet_icon_list_find_helper(theme, icons, size);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* we didn't find the icons in the theme or in the inherited directories
|
/* we didn't find the icons in the theme or in the inherited directories
|
||||||
* then just look for a non theme icon
|
* then just look for a non theme icon
|
||||||
*/
|
*/
|
||||||
if(!value)
|
if (!value)
|
||||||
{
|
{
|
||||||
ecore_list_first_goto(icons);
|
ecore_list_first_goto(icons);
|
||||||
while ((icon = ecore_list_next(icons)))
|
while ((icon = ecore_list_next(icons)))
|
||||||
|
@ -432,14 +392,6 @@ efreet_icon_list_find(const char *theme_name, Ecore_List *icons,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
return value;
|
||||||
}
|
}
|
||||||
|
@ -451,33 +403,40 @@ efreet_icon_list_find(const char *theme_name, Ecore_List *icons,
|
||||||
* @return Returns the path to the given icon or NULL if none found
|
* @return Returns the path to the given icon or NULL if none found
|
||||||
* @brief Retrives the path to the given icon.
|
* @brief Retrives the path to the given icon.
|
||||||
*/
|
*/
|
||||||
const char *
|
Efreet_Icon *
|
||||||
efreet_icon_path_find(const char *theme, const char *icon, const char *size)
|
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
|
* @internal
|
||||||
* @param theme: The theme to search in
|
* @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 icon: The icon to search for
|
||||||
* @param size: The size to search for
|
* @param size: The size to search for
|
||||||
* @return Returns the icon matching the given information or NULL if no
|
* @return Returns the icon matching the given information or NULL if no
|
||||||
* icon found
|
* icon found
|
||||||
* @brief Scans inheriting themes for the given icon
|
* @brief Scans inheriting themes for the given icon
|
||||||
*/
|
*/
|
||||||
static Efreet_Icon *
|
static char *
|
||||||
efreet_icon_find_fallback(Efreet_Icon_Theme *theme, const char *cache_key,
|
efreet_icon_find_fallback(Efreet_Icon_Theme *theme,
|
||||||
const char *icon, const char *size)
|
const char *icon, const char *size)
|
||||||
{
|
{
|
||||||
char *parent = NULL;
|
char *parent = NULL;
|
||||||
Efreet_Icon *value = NULL;
|
char *value = NULL;
|
||||||
|
|
||||||
if (theme->inherits)
|
if (theme->inherits)
|
||||||
{
|
{
|
||||||
ecore_list_first_goto(theme->inherits);
|
ecore_list_first_goto(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);
|
parent_theme = efreet_icon_theme_find(parent);
|
||||||
if ((!parent_theme) || (parent_theme == theme)) continue;
|
if ((!parent_theme) || (parent_theme == theme)) continue;
|
||||||
|
|
||||||
value = efreet_icon_find_helper(parent_theme, cache_key,
|
value = efreet_icon_find_helper(parent_theme, icon, size);
|
||||||
icon, size);
|
|
||||||
if (value) break;
|
if (value) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -501,49 +459,42 @@ efreet_icon_find_fallback(Efreet_Icon_Theme *theme, const char *cache_key,
|
||||||
|
|
||||||
parent_theme = efreet_icon_theme_find("hicolor");
|
parent_theme = efreet_icon_theme_find("hicolor");
|
||||||
if (parent_theme)
|
if (parent_theme)
|
||||||
value = efreet_icon_find_helper(parent_theme, cache_key,
|
value = efreet_icon_find_helper(parent_theme, icon, size);
|
||||||
icon, size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
* @param theme: The theme to search in
|
* @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 icon: The icon to search for
|
||||||
* @param size: The size to search for
|
* @param size: The size to search for
|
||||||
* @return Returns the icon matching the given information or NULL if no
|
* @return Returns the icon matching the given information or NULL if no
|
||||||
* icon found
|
* icon found
|
||||||
* @brief Scans the theme and any inheriting themes for the given icon
|
* @brief Scans the theme and any inheriting themes for the given icon
|
||||||
*/
|
*/
|
||||||
static Efreet_Icon *
|
static char *
|
||||||
efreet_icon_find_helper(Efreet_Icon_Theme *theme, const char *cache_key,
|
efreet_icon_find_helper(Efreet_Icon_Theme *theme,
|
||||||
const char *icon,
|
const char *icon, const char *size)
|
||||||
const char *size)
|
|
||||||
{
|
{
|
||||||
Efreet_Icon *value;
|
char *value;
|
||||||
static int recurse = 0;
|
static int recurse = 0;
|
||||||
|
|
||||||
efreet_icon_theme_cache_check(theme);
|
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 */
|
/* go no further if this theme is fake */
|
||||||
if (theme->fake || !theme->valid) return NULL;
|
if (theme->fake || !theme->valid) return NULL;
|
||||||
|
|
||||||
/* limit recursion in finding themes and inherited themes to 256 levels */
|
/* limit recursion in finding themes and inherited themes to 256 levels */
|
||||||
if (recurse > 256) return NULL;
|
if (recurse > 256) return NULL;
|
||||||
recurse++;
|
recurse++;
|
||||||
|
|
||||||
value = efreet_icon_lookup_icon(theme, icon, size);
|
value = efreet_icon_lookup_icon(theme, icon, size);
|
||||||
|
|
||||||
/* we didin't find the image check the inherited themes */
|
/* we didin't find the image check the inherited themes */
|
||||||
if (!value)
|
if (!value)
|
||||||
value = efreet_icon_find_fallback(theme, cache_key, icon, size);
|
value = efreet_icon_find_fallback(theme, icon, size);
|
||||||
|
|
||||||
recurse--;
|
recurse--;
|
||||||
return value;
|
return value;
|
||||||
|
@ -552,19 +503,18 @@ efreet_icon_find_helper(Efreet_Icon_Theme *theme, const char *cache_key,
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
* @param theme: The theme to search in
|
* @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 icons: The icons to search for
|
||||||
* @param size: The size to search for
|
* @param size: The size to search for
|
||||||
* @return Returns the icon matching the given information or NULL if no
|
* @return Returns the icon matching the given information or NULL if no
|
||||||
* icon found
|
* icon found
|
||||||
* @brief Scans inheriting themes for the given icons
|
* @brief Scans inheriting themes for the given icons
|
||||||
*/
|
*/
|
||||||
static Efreet_Icon *
|
static char *
|
||||||
efreet_icon_list_find_fallback(Efreet_Icon_Theme *theme, Ecore_List *cache_keys,
|
efreet_icon_list_find_fallback(Efreet_Icon_Theme *theme,
|
||||||
Ecore_List *icons, const char *size)
|
Ecore_List *icons, const char *size)
|
||||||
{
|
{
|
||||||
char *parent = NULL;
|
char *parent = NULL;
|
||||||
Efreet_Icon *value = NULL;
|
char *value = NULL;
|
||||||
|
|
||||||
if (theme->inherits)
|
if (theme->inherits)
|
||||||
{
|
{
|
||||||
|
@ -576,14 +526,14 @@ efreet_icon_list_find_fallback(Efreet_Icon_Theme *theme, Ecore_List *cache_keys,
|
||||||
parent_theme = efreet_icon_theme_find(parent);
|
parent_theme = efreet_icon_theme_find(parent);
|
||||||
if ((!parent_theme) || (parent_theme == theme)) continue;
|
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);
|
icons, size);
|
||||||
if (value) break;
|
if (value) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if this isn't the hicolor theme, and we have no other fallbacks
|
/* if this isn't the hicolor theme, and we have no other fallbacks
|
||||||
* check hicolor
|
* check hicolor
|
||||||
*/
|
*/
|
||||||
else if (strcmp(theme->name.internal, "hicolor"))
|
else if (strcmp(theme->name.internal, "hicolor"))
|
||||||
{
|
{
|
||||||
|
@ -591,50 +541,39 @@ efreet_icon_list_find_fallback(Efreet_Icon_Theme *theme, Ecore_List *cache_keys,
|
||||||
|
|
||||||
parent_theme = efreet_icon_theme_find("hicolor");
|
parent_theme = efreet_icon_theme_find("hicolor");
|
||||||
if (parent_theme)
|
if (parent_theme)
|
||||||
value = efreet_icon_list_find_helper(parent_theme, cache_keys,
|
value = efreet_icon_list_find_helper(parent_theme,
|
||||||
icons, size);
|
icons, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
* @param theme: The theme to search in
|
* @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 icons: The icons to search for
|
||||||
* @param size: The size to search for
|
* @param size: The size to search for
|
||||||
* @return Returns the icon matching the given information or NULL if no
|
* @return Returns the icon matching the given information or NULL if no
|
||||||
* icon found
|
* icon found
|
||||||
* @brief Scans the theme and any inheriting themes for the given icons
|
* @brief Scans the theme and any inheriting themes for the given icons
|
||||||
*/
|
*/
|
||||||
static Efreet_Icon *
|
static char *
|
||||||
efreet_icon_list_find_helper(Efreet_Icon_Theme *theme, Ecore_List *cache_keys,
|
efreet_icon_list_find_helper(Efreet_Icon_Theme *theme,
|
||||||
Ecore_List *icons,
|
Ecore_List *icons, const char *size)
|
||||||
const char *size)
|
|
||||||
{
|
{
|
||||||
Efreet_Icon *value = NULL;
|
char *value = NULL;
|
||||||
const char *icon = NULL;
|
const char *icon = NULL;
|
||||||
const char *cache_key = NULL;
|
|
||||||
static int recurse = 0;
|
static int recurse = 0;
|
||||||
|
|
||||||
efreet_icon_theme_cache_check(theme);
|
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 */
|
/* go no further if this theme is fake */
|
||||||
if (theme->fake || !theme->valid) return NULL;
|
if (theme->fake || !theme->valid) return NULL;
|
||||||
|
|
||||||
/* limit recursion in finding themes and inherited themes to 256 levels */
|
/* limit recursion in finding themes and inherited themes to 256 levels */
|
||||||
if (recurse > 256) return NULL;
|
if (recurse > 256) return NULL;
|
||||||
recurse++;
|
recurse++;
|
||||||
|
|
||||||
ecore_list_first_goto(icons);
|
ecore_list_first_goto(icons);
|
||||||
while ((icon = ecore_list_next(icons)))
|
while ((icon = ecore_list_next(icons)))
|
||||||
{
|
{
|
||||||
|
@ -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 */
|
/* we didn't find the image check the inherited themes */
|
||||||
if (!value)
|
if (!value)
|
||||||
value = efreet_icon_list_find_fallback(theme, cache_keys, icons, size);
|
value = efreet_icon_list_find_fallback(theme, icons, size);
|
||||||
|
|
||||||
recurse--;
|
recurse--;
|
||||||
return value;
|
return value;
|
||||||
|
@ -655,20 +594,20 @@ efreet_icon_list_find_helper(Efreet_Icon_Theme *theme, Ecore_List *cache_keys,
|
||||||
* @param theme: The icon theme to look in
|
* @param theme: The icon theme to look in
|
||||||
* @param icon_name: The icon name to look for
|
* @param icon_name: The icon name to look for
|
||||||
* @param size: The icon size 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
|
* none found
|
||||||
* @brief Looks for the @a icon in the @a theme for the @a size given.
|
* @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,
|
efreet_icon_lookup_icon(Efreet_Icon_Theme *theme, const char *icon_name,
|
||||||
const char *size)
|
const char *size)
|
||||||
{
|
{
|
||||||
Efreet_Icon *icon = NULL, *tmp = NULL;
|
char *icon = NULL, *tmp = NULL;
|
||||||
Efreet_Icon_Theme_Directory *dir;
|
Efreet_Icon_Theme_Directory *dir;
|
||||||
int minimal_size = INT_MAX;
|
int minimal_size = INT_MAX;
|
||||||
unsigned int real_size;
|
unsigned int real_size;
|
||||||
|
|
||||||
if (!theme || (theme->paths.count == 0) || !icon_name || !size)
|
if (!theme || (theme->paths.count == 0) || !icon_name || !size)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
real_size = atoi(size);
|
real_size = atoi(size);
|
||||||
|
@ -692,29 +631,16 @@ efreet_icon_lookup_icon(Efreet_Icon_Theme *theme, const char *icon_name,
|
||||||
distance = efreet_icon_directory_size_distance(dir, real_size);
|
distance = efreet_icon_directory_size_distance(dir, real_size);
|
||||||
if (distance >= minimal_size) continue;
|
if (distance >= minimal_size) continue;
|
||||||
|
|
||||||
tmp = efreet_icon_lookup_directory(theme, dir,
|
tmp = efreet_icon_lookup_directory(theme, dir,
|
||||||
icon_name);
|
icon_name);
|
||||||
if (tmp)
|
if (tmp)
|
||||||
{
|
{
|
||||||
|
FREE(icon);
|
||||||
icon = tmp;
|
icon = tmp;
|
||||||
minimal_size = distance;
|
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;
|
return icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -729,24 +655,28 @@ efreet_icon_lookup_icon(Efreet_Icon_Theme *theme, const char *icon_name,
|
||||||
* none found
|
* none found
|
||||||
* @brief Tries to find the file closest matching the given icon
|
* @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_lookup_directory(Efreet_Icon_Theme *theme,
|
||||||
Efreet_Icon_Theme_Directory *dir,
|
Efreet_Icon_Theme_Directory *dir,
|
||||||
const char *icon_name)
|
const char *icon_name)
|
||||||
{
|
{
|
||||||
if (theme->paths.count == 1)
|
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
|
else
|
||||||
{
|
{
|
||||||
|
char *icon;
|
||||||
const char *path;
|
const char *path;
|
||||||
|
|
||||||
ecore_list_first_goto(theme->paths.path);
|
ecore_list_first_goto(theme->paths.path);
|
||||||
while ((path = ecore_list_next(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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -758,7 +688,7 @@ efreet_icon_lookup_directory(Efreet_Icon_Theme *theme,
|
||||||
* @brief Checks if the size matches for the given directory or not
|
* @brief Checks if the size matches for the given directory or not
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
efreet_icon_directory_size_match(Efreet_Icon_Theme_Directory *dir,
|
efreet_icon_directory_size_match(Efreet_Icon_Theme_Directory *dir,
|
||||||
unsigned int size)
|
unsigned int size)
|
||||||
{
|
{
|
||||||
if (dir->type == EFREET_ICON_SIZE_TYPE_FIXED)
|
if (dir->type == EFREET_ICON_SIZE_TYPE_FIXED)
|
||||||
|
@ -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
|
* @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
|
* @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_fallback_icon(const char *icon_name)
|
||||||
{
|
{
|
||||||
Efreet_Icon *icon;
|
char *icon;
|
||||||
|
|
||||||
if (!icon_name) return NULL;
|
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
|
* @brief Scans the given @a dir for the given @a icon_name returning the
|
||||||
* Efreet_icon if found, NULL otherwise.
|
* 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_fallback_dir_scan(const char *dir, const char *icon_name)
|
||||||
{
|
{
|
||||||
Efreet_Icon *icon = NULL;
|
char *icon = NULL;
|
||||||
char path[PATH_MAX], *ext;
|
char path[PATH_MAX], *ext;
|
||||||
|
|
||||||
if (!dir || !icon_name) return NULL;
|
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))
|
if (ecore_file_exists(path))
|
||||||
{
|
{
|
||||||
icon = efreet_icon_new(path);
|
icon = strdup(path);
|
||||||
if (icon) break;
|
if (icon) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -892,7 +822,7 @@ efreet_icon_fallback_dir_scan(const char *dir, const char *icon_name)
|
||||||
|
|
||||||
if (ecore_file_exists(path))
|
if (ecore_file_exists(path))
|
||||||
{
|
{
|
||||||
icon = efreet_icon_new(path);
|
icon = strdup(path);
|
||||||
#ifdef STRICT_SPEC
|
#ifdef STRICT_SPEC
|
||||||
if (icon)
|
if (icon)
|
||||||
printf("[Efreet]: Found an icon that already has an extension: %s\n", path);
|
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
|
* @brief Caches the icons in the given theme directory path at the given
|
||||||
* size
|
* size
|
||||||
*/
|
*/
|
||||||
static void
|
static char *
|
||||||
efreet_icon_directory_cache(Efreet_Icon_Theme *theme,
|
efreet_icon_lookup_directory_helper(Efreet_Icon_Theme_Directory *dir,
|
||||||
Efreet_Icon_Theme_Directory *dir, const char *path)
|
const char *path, const char *icon_name)
|
||||||
{
|
{
|
||||||
char file_path[PATH_MAX], size_str[10];
|
char *icon = NULL;
|
||||||
const char *dir_key, *path_strs[] = { path, "/", dir->name, NULL };
|
char file_path[PATH_MAX];
|
||||||
DIR *dirp;
|
const char *ext, *path_strs[] = { path, "/", dir->name, "/", icon_name, NULL, NULL };
|
||||||
struct dirent *file;
|
|
||||||
|
|
||||||
/* make sure the cache exists, create if needed */
|
ecore_list_first_goto(efreet_icon_extensions);
|
||||||
if (!efreet_icon_dirs_cached)
|
while ((ext = ecore_list_next(efreet_icon_extensions)))
|
||||||
{
|
{
|
||||||
efreet_icon_dirs_cached = ecore_hash_new(NULL, NULL);
|
path_strs[5] = ext;
|
||||||
ecore_hash_free_key_cb_set(efreet_icon_dirs_cached,
|
efreet_array_cat(file_path, sizeof(file_path), path_strs);
|
||||||
ECORE_FREE_CB(ecore_string_release));
|
|
||||||
}
|
|
||||||
|
|
||||||
efreet_array_cat(file_path, sizeof(file_path), path_strs);
|
if (ecore_file_exists(file_path))
|
||||||
|
|
||||||
/* 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)
|
|
||||||
{
|
|
||||||
while ((file = readdir(dirp)))
|
|
||||||
{
|
{
|
||||||
char key_str[PATH_MAX], *ext, *name;
|
icon = strdup(file_path);
|
||||||
const char *key, *name_strs[] = {NULL, "@", size_str, "x", size_str, NULL};
|
break;
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
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;
|
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
|
* @internal
|
||||||
* @return Returns a new Efreet_Icon struct on success or NULL on failure
|
* @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
|
* @param icon: The Efreet_Icon to cleanup
|
||||||
* @return Returns no value.
|
* @return Returns no value.
|
||||||
* @brief Free's the given icon and all its internal data.
|
* @brief Free's the given icon and all its internal data.
|
||||||
*/
|
*/
|
||||||
static void
|
void
|
||||||
efreet_icon_free(Efreet_Icon *icon)
|
efreet_icon_free(Efreet_Icon *icon)
|
||||||
{
|
{
|
||||||
if (!icon || (icon == (void *)NO_MATCH_KEY)) return;
|
if (!icon) return;
|
||||||
|
|
||||||
icon->ref_count --;
|
icon->ref_count --;
|
||||||
if (icon->ref_count > 0) return;
|
if (icon->ref_count > 0) return;
|
||||||
|
@ -1209,7 +1009,7 @@ efreet_icon_populate(Efreet_Icon *icon, const char *file)
|
||||||
char *t, *s, *p;
|
char *t, *s, *p;
|
||||||
|
|
||||||
icon->attach_points = ecore_list_new();
|
icon->attach_points = ecore_list_new();
|
||||||
ecore_list_free_cb_set(icon->attach_points,
|
ecore_list_free_cb_set(icon->attach_points,
|
||||||
ECORE_FREE_CB(efreet_icon_point_free));
|
ECORE_FREE_CB(efreet_icon_point_free));
|
||||||
|
|
||||||
t = strdup(tmp);
|
t = strdup(tmp);
|
||||||
|
@ -1284,8 +1084,6 @@ efreet_icon_theme_free(Efreet_Icon_Theme *theme)
|
||||||
IF_FREE_LIST(theme->inherits);
|
IF_FREE_LIST(theme->inherits);
|
||||||
IF_FREE_LIST(theme->directories);
|
IF_FREE_LIST(theme->directories);
|
||||||
|
|
||||||
IF_FREE_HASH(theme->icon_cache);
|
|
||||||
|
|
||||||
FREE(theme);
|
FREE(theme);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1338,7 +1136,7 @@ efreet_icon_theme_cache_check(Efreet_Icon_Theme *theme)
|
||||||
double new_check;
|
double new_check;
|
||||||
|
|
||||||
new_check = ecore_time_get();
|
new_check = ecore_time_get();
|
||||||
|
|
||||||
/* we're within 5 seconds of the last time we checked the cache */
|
/* we're within 5 seconds of the last time we checked the cache */
|
||||||
if ((new_check - 5) <= theme->last_cache_check) return;
|
if ((new_check - 5) <= theme->last_cache_check) return;
|
||||||
|
|
||||||
|
@ -1359,19 +1157,6 @@ efreet_icon_theme_cache_check(Efreet_Icon_Theme *theme)
|
||||||
break;
|
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)
|
if (efreet_icon_dirs_cached)
|
||||||
ecore_hash_remove(efreet_icon_dirs_cached, dir);
|
ecore_hash_remove(efreet_icon_dirs_cached, dir);
|
||||||
IF_FREE_HASH(theme->icon_cache);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1460,7 +1244,7 @@ efreet_icon_theme_dir_scan(const char *search_dir, const char *theme_name)
|
||||||
* given name */
|
* given name */
|
||||||
snprintf(path, sizeof(path), "%s/%s", search_dir, dir->d_name);
|
snprintf(path, sizeof(path), "%s/%s", search_dir, dir->d_name);
|
||||||
if (((theme_name != NULL) && (strcmp(theme_name, dir->d_name)))
|
if (((theme_name != NULL) && (strcmp(theme_name, dir->d_name)))
|
||||||
|| !ecore_file_is_dir(path))
|
|| !ecore_file_is_dir(path))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
key = ecore_string_instance(dir->d_name);
|
key = ecore_string_instance(dir->d_name);
|
||||||
|
@ -1470,7 +1254,7 @@ efreet_icon_theme_dir_scan(const char *search_dir, const char *theme_name)
|
||||||
{
|
{
|
||||||
theme = efreet_icon_theme_new();
|
theme = efreet_icon_theme_new();
|
||||||
theme->name.internal = key;
|
theme->name.internal = key;
|
||||||
ecore_hash_set(efreet_icon_themes,
|
ecore_hash_set(efreet_icon_themes,
|
||||||
(void *)theme->name.internal, theme);
|
(void *)theme->name.internal, theme);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1497,7 +1281,7 @@ efreet_icon_theme_dir_scan(const char *search_dir, const char *theme_name)
|
||||||
if (theme_name)
|
if (theme_name)
|
||||||
{
|
{
|
||||||
Efreet_Icon_Theme *theme;
|
Efreet_Icon_Theme *theme;
|
||||||
|
|
||||||
theme = ecore_hash_get(efreet_icon_themes, theme_name);
|
theme = ecore_hash_get(efreet_icon_themes, theme_name);
|
||||||
if (theme && !theme->valid && !theme->fake)
|
if (theme && !theme->valid && !theme->fake)
|
||||||
{
|
{
|
||||||
|
@ -1536,7 +1320,7 @@ efreet_icon_theme_index_read(Efreet_Icon_Theme *theme, const char *path)
|
||||||
tmp = efreet_ini_localestring_get(ini, "Comment");
|
tmp = efreet_ini_localestring_get(ini, "Comment");
|
||||||
if (tmp) theme->comment = strdup(tmp);
|
if (tmp) theme->comment = strdup(tmp);
|
||||||
|
|
||||||
tmp = efreet_ini_string_get(ini, "Example");
|
tmp = efreet_ini_string_get(ini, "Example");
|
||||||
if (tmp) theme->example_icon = strdup(tmp);
|
if (tmp) theme->example_icon = strdup(tmp);
|
||||||
|
|
||||||
theme->hidden = efreet_ini_boolean_get(ini, "Hidden");
|
theme->hidden = efreet_ini_boolean_get(ini, "Hidden");
|
||||||
|
@ -1578,7 +1362,7 @@ efreet_icon_theme_index_read(Efreet_Icon_Theme *theme, const char *path)
|
||||||
int last = 0;
|
int last = 0;
|
||||||
|
|
||||||
theme->directories = ecore_list_new();
|
theme->directories = ecore_list_new();
|
||||||
ecore_list_free_cb_set(theme->directories,
|
ecore_list_free_cb_set(theme->directories,
|
||||||
ECORE_FREE_CB(efreet_icon_theme_directory_free));
|
ECORE_FREE_CB(efreet_icon_theme_directory_free));
|
||||||
|
|
||||||
t = strdup(tmp);
|
t = strdup(tmp);
|
||||||
|
@ -1592,7 +1376,7 @@ efreet_icon_theme_index_read(Efreet_Icon_Theme *theme, const char *path)
|
||||||
if (!p) last = 1;
|
if (!p) last = 1;
|
||||||
else *p = '\0';
|
else *p = '\0';
|
||||||
|
|
||||||
ecore_list_append(theme->directories,
|
ecore_list_append(theme->directories,
|
||||||
efreet_icon_theme_directory_new(ini, s));
|
efreet_icon_theme_directory_new(ini, s));
|
||||||
|
|
||||||
if (!last) s = ++p;
|
if (!last) s = ++p;
|
||||||
|
@ -1669,11 +1453,11 @@ efreet_icon_theme_directory_new(Efreet_Ini *ini, const char *name)
|
||||||
|
|
||||||
else if (!strcasecmp(tmp, "FileSystems"))
|
else if (!strcasecmp(tmp, "FileSystems"))
|
||||||
dir->context = EFREET_ICON_THEME_CONTEXT_FILESYSTEMS;
|
dir->context = EFREET_ICON_THEME_CONTEXT_FILESYSTEMS;
|
||||||
|
|
||||||
else if (!strcasecmp(tmp, "MimeTypes"))
|
else if (!strcasecmp(tmp, "MimeTypes"))
|
||||||
dir->context = EFREET_ICON_THEME_CONTEXT_MIMETYPES;
|
dir->context = EFREET_ICON_THEME_CONTEXT_MIMETYPES;
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp = efreet_ini_string_get(ini, "Type");
|
tmp = efreet_ini_string_get(ini, "Type");
|
||||||
if (tmp)
|
if (tmp)
|
||||||
{
|
{
|
||||||
|
|
|
@ -79,7 +79,6 @@ struct Efreet_Icon_Theme
|
||||||
Ecore_List *directories; /**< List of subdirectories for this theme */
|
Ecore_List *directories; /**< List of subdirectories for this theme */
|
||||||
|
|
||||||
double last_cache_check; /**< Last time the cache was checked */
|
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 hidden:1; /**< Should this theme be hidden from users */
|
||||||
unsigned char valid:1; /**< Have we seen an index for this theme */
|
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_Theme *efreet_icon_theme_find(const char *theme_name);
|
||||||
Efreet_Icon *efreet_icon_find(const char *theme_name, const char *icon,
|
Efreet_Icon *efreet_icon_find(const char *theme_name, const char *icon,
|
||||||
const char *size);
|
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,
|
Ecore_List *icons,
|
||||||
const char *size);
|
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);
|
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(globs);
|
||||||
IF_FREE_LIST(magics);
|
IF_FREE_LIST(magics);
|
||||||
IF_FREE_HASH(monitors);
|
IF_FREE_HASH(monitors);
|
||||||
|
IF_FREE_HASH(wild);
|
||||||
|
|
||||||
efreet_shutdown();
|
efreet_shutdown();
|
||||||
ecore_file_shutdown();
|
ecore_file_shutdown();
|
||||||
|
@ -177,10 +178,10 @@ efreet_mime_type_get(const char *file)
|
||||||
* @return Returns mime type icon path as a string
|
* @return Returns mime type icon path as a string
|
||||||
* @brief Retreive the mime type icon for a file
|
* @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_mime_type_icon_get(const char *mime, const char *theme, const char *size)
|
||||||
{
|
{
|
||||||
Efreet_Icon *icon = NULL;
|
char *icon = NULL;
|
||||||
Ecore_List *icons = NULL;
|
Ecore_List *icons = NULL;
|
||||||
const char *env = NULL;
|
const char *env = NULL;
|
||||||
char *p = NULL, *pp = NULL, *ppp = 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);
|
ecore_list_destroy(icons);
|
||||||
|
|
||||||
if (icon)
|
return icon;
|
||||||
return icon->path;
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue