static Eet_File *fallback_cache = NULL;
static Eet_File *icon_theme_cache = NULL;
+static Eina_Hash *themes = NULL;
static Eina_Hash *icons = NULL;
static Eina_Hash *fallbacks = NULL;
EFREET_EVENT_ICON_CACHE_UPDATE = ecore_event_type_new();
EFREET_EVENT_DESKTOP_CACHE_UPDATE = ecore_event_type_new();
+ themes = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_icon_theme_free));
icons = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_icon_free));
fallbacks = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_icon_fallback_free));
icon_cache = efreet_cache_close(icon_cache);
icon_theme_cache = efreet_cache_close(icon_theme_cache);
+ IF_FREE_HASH(themes);
IF_FREE_HASH(icons);
IF_FREE_HASH(fallbacks);
Efreet_Icon_Theme *
efreet_cache_icon_theme_find(const char *theme)
{
+ Efreet_Cache_Icon_Theme *cache;
+
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(EINA_FALSE), theme);
+
+ cache = eina_hash_find(themes, theme);
+ if (cache == NON_EXISTING) return NULL;
+ if (cache) return &(cache->theme);
+
+ cache = eet_data_read(icon_theme_cache, efreet_icon_theme_edd(EINA_FALSE), theme);
+ if (cache)
+ eina_hash_add(themes, theme, cache);
+ else
+ eina_hash_add(themes, theme, NON_EXISTING);
+ return &(cache->theme);
}
void
void *data;
if (!theme) return;
+ if (theme == NON_EXISTING) return;
eina_list_free(theme->paths);
eina_list_free(theme->inherits);
free(theme);
}
-char **
-efreet_cache_icon_theme_name_list(int *num)
+Eina_List *
+efreet_cache_icon_theme_list(void)
{
+ Eina_List *ret = NULL;
char **keys;
- int i;
+ int i, num;
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++)
+ keys = eet_list(icon_theme_cache, "*", &num);
+ for (i = 0; i < num; i++)
{
- if (!strncmp(keys[i], "__efreet", 8) && (i < (*num + 1)))
- {
- memmove(&keys[i], &keys[i + 1], (*num - i - 1) * sizeof(char *));
- (*num)--;
- }
+ Efreet_Icon_Theme *theme;
+ if (!strncmp(keys[i], "__efreet", 8)) continue;
+ /* TODO: This could be done more efficient by checking the theme hash
+ * directly. */
+ theme = efreet_cache_icon_theme_find(keys[i]);
+ if (theme) ret = eina_list_append(ret, theme);
}
- return keys;
+ free(keys);
+ return ret;
}
/*
const char *file;
Efreet_Event_Cache_Update *ev = NULL;
Efreet_Old_Cache *d = NULL;
+ Eina_List *l = NULL;
if (event != ECORE_FILE_EVENT_CREATED_FILE &&
event != ECORE_FILE_EVENT_MODIFIED) return;
{
ev = NEW(Efreet_Event_Cache_Update, 1);
if (!ev) goto error;
+
+ IF_RELEASE(theme_name);
+
+ /* Save all old caches */
d = NEW(Efreet_Old_Cache, 1);
if (!d) goto error;
+ d->hash = themes;
+ d->ef = icon_theme_cache;
+ l = eina_list_append(l, d);
- IF_RELEASE(theme_name);
+ d = NEW(Efreet_Old_Cache, 1);
+ if (!d) goto error;
+ d->hash = icons;
+ d->ef = icon_cache;
+ l = eina_list_append(l, d);
- eina_hash_free(icons);
+ d = NEW(Efreet_Old_Cache, 1);
+ if (!d) goto error;
+ d->hash = fallbacks;
+ d->ef = fallback_cache;
+ l = eina_list_append(l, d);
+
+ /* Create new empty caches */
+ themes = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_icon_theme_free));
icons = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_icon_free));
- eina_hash_free(fallbacks);
fallbacks = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_icon_fallback_free));
- icon_cache = efreet_cache_close(icon_cache);
- fallback_cache = efreet_cache_close(fallback_cache);
-
- d->hash = efreet_icon_themes;
- d->ef = icon_theme_cache;
-
- efreet_icon_themes = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_icon_theme_free));
icon_theme_cache = NULL;
+ icon_cache = NULL;
+ fallback_cache = NULL;
- ecore_event_add(EFREET_EVENT_ICON_CACHE_UPDATE, ev, icon_cache_update_free, d);
+ /* Send event */
+ ecore_event_add(EFREET_EVENT_ICON_CACHE_UPDATE, ev, icon_cache_update_free, l);
}
return;
error:
IF_FREE(ev);
IF_FREE(d);
+ EINA_LIST_FREE(l, d)
+ free(d);
}
static void
icon_cache_update_free(void *data, void *ev)
{
Efreet_Old_Cache *d;
+ Eina_List *l;
- d = data;
- if (d->hash)
- eina_hash_free(d->hash);
- efreet_cache_close(d->ef);
- free(d);
+ l = data;
+ EINA_LIST_FREE(l, d)
+ {
+ if (d->hash)
+ eina_hash_free(d->hash);
+ efreet_cache_close(d->ef);
+ free(d);
+ }
free(ev);
}
#include "Efreet.h"
#include "efreet_private.h"
-Eina_Hash *efreet_icon_themes = NULL;
-
static const char *efreet_icon_deprecated_user_dir = NULL;
static const char *efreet_icon_user_dir = NULL;
static Eina_List *efreet_icon_extensions = NULL;
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_cache_icon_theme_free));
efreet_icon_changes_listen();
efreet_extra_icon_dirs = NULL;
IF_RELEASE(efreet_icon_deprecated_user_dir);
IF_FREE_LIST(efreet_icon_extensions, eina_stringshare_del);
- IF_FREE_HASH(efreet_icon_themes);
efreet_extra_icon_dirs = eina_list_free(efreet_extra_icon_dirs);
eina_log_domain_unregister(_efreet_icon_log_dom);
EAPI Eina_List *
efreet_icon_theme_list_get(void)
{
- Eina_List *list = NULL;
- 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]);
- if (theme)
- list = eina_list_append(list, theme);
- }
- free(keys);
- }
-
- return list;
+ return efreet_cache_icon_theme_list();
}
/**
EAPI Efreet_Icon_Theme *
efreet_icon_theme_find(const char *theme_name)
{
- Efreet_Icon_Theme *theme;
-
if (!theme_name) return NULL;
- theme = eina_hash_find(efreet_icon_themes, theme_name);
- if (!theme)
- {
- theme = efreet_cache_icon_theme_find(theme_name);
- if (theme) eina_hash_direct_add(efreet_icon_themes, theme->name.internal, theme);
- }
-
- return theme;
+ return efreet_cache_icon_theme_find(theme_name);
}
/**