Move theme hash from efreet_icon to efreet_cache
authorSebastian Dransfeld <sd@tango.flipp.net>
Wed, 9 Feb 2011 17:09:16 +0000 (17:09 +0000)
committerSebastian Dransfeld <sd@tango.flipp.net>
Wed, 9 Feb 2011 17:09:16 +0000 (17:09 +0000)
SVN revision: 56852

legacy/efreet/ChangeLog
legacy/efreet/src/lib/efreet_cache.c
legacy/efreet/src/lib/efreet_icon.c
legacy/efreet/src/lib/efreet_private.h

index aca24e9..ee857e8 100644 (file)
@@ -55,3 +55,7 @@
        * Do efreet_init before using efreet_*() functions
        * Move lock creation to own function for desktop cache
        * Set file owner to calling user
+
+2011-02-09  Sebastian Dransfeld
+
+       * Move theme hash from efreet_icon.c to efreet_cache.c
index 79cf11f..52f4e36 100644 (file)
@@ -47,6 +47,7 @@ static Eet_File            *icon_cache = NULL;
 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;
 
@@ -104,6 +105,7 @@ efreet_cache_init(void)
     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));
 
@@ -149,6 +151,7 @@ efreet_cache_shutdown(void)
     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);
 
@@ -649,8 +652,20 @@ efreet_cache_icon_fallback_find(const char *icon)
 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
@@ -659,6 +674,7 @@ efreet_cache_icon_theme_free(Efreet_Icon_Theme *theme)
     void *data;
 
     if (!theme) return;
+    if (theme == NON_EXISTING) return;
 
     eina_list_free(theme->paths);
     eina_list_free(theme->inherits);
@@ -668,23 +684,26 @@ efreet_cache_icon_theme_free(Efreet_Icon_Theme *theme)
     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;
 }
 
 /*
@@ -829,6 +848,7 @@ cache_update_cb(void *data __UNUSED__, Ecore_File_Monitor *em __UNUSED__,
     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;
@@ -856,31 +876,46 @@ cache_update_cb(void *data __UNUSED__, Ecore_File_Monitor *em __UNUSED__,
     {
         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
@@ -1040,11 +1075,15 @@ 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);
 }
index 81b0f67..52bf364 100644 (file)
@@ -39,8 +39,6 @@ static int _efreet_icon_log_dom = -1;
 #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;
@@ -97,7 +95,6 @@ efreet_icon_init(void)
     for (i = 0; default_exts[i]; i++)
         efreet_icon_extensions = eina_list_append(efreet_icon_extensions, eina_stringshare_add(default_exts[i]));
 
-    efreet_icon_themes = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_icon_theme_free));
     efreet_icon_changes_listen();
 
     efreet_extra_icon_dirs = NULL;
@@ -117,7 +114,6 @@ efreet_icon_shutdown(void)
     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);
@@ -225,25 +221,7 @@ efreet_icon_extensions_list_get(void)
 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();
 }
 
 /**
@@ -255,18 +233,9 @@ efreet_icon_theme_list_get(void)
 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);
 }
 
 /**
index 8f7c260..c21eef3 100644 (file)
@@ -94,7 +94,6 @@
 
 /* TODO: Move these to cache, make static and add accessor */
 extern Eina_Hash *efreet_desktop_cache;
-extern Eina_Hash *efreet_icon_themes;
 
 #define EFREET_DESKTOP_CACHE_MAJOR 1
 #define EFREET_DESKTOP_CACHE_MINOR 0
@@ -220,7 +219,7 @@ Efreet_Cache_Icon *efreet_cache_icon_find(Efreet_Icon_Theme *theme, const char *
 Efreet_Cache_Fallback_Icon *efreet_cache_icon_fallback_find(const char *icon);
 Efreet_Icon_Theme *efreet_cache_icon_theme_find(const char *theme);
 void efreet_cache_icon_theme_free(Efreet_Icon_Theme *theme);
-char **efreet_cache_icon_theme_name_list(int *num);
+Eina_List *efreet_cache_icon_theme_list(void);
 EAPI void efreet_cache_array_string_free(Efreet_Cache_Array_String *array);
 
 EAPI void efreet_hash_free(Eina_Hash *hash, Eina_Free_Cb free_cb);