Enlightenment CVS committal

Author  : dj2
Project : e17
Module  : libs/ewl

Dir     : e17/libs/ewl/src/lib


Modified Files:
        ewl_icon_theme.c ewl_icon_theme.h ewl_misc.c 


Log Message:
- add caching to ewl_icon_theme.
- this fixes the memory leaks introduced by ecore_desktop switching from
  const char * to char *s

===================================================================
RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_icon_theme.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- ewl_icon_theme.c    6 Sep 2006 15:35:01 -0000       1.3
+++ ewl_icon_theme.c    24 Sep 2006 21:17:27 -0000      1.4
@@ -5,6 +5,40 @@
 
 static int ewl_icon_theme_is_edje = 0;
 
+static Ecore_Hash *ewl_icon_theme_cache = NULL;
+static void ewl_icon_theme_cb_free(void *data);
+
+/**
+ * @return Returns TRUE on success or FALSE on failure
+ * @brief Initializes the icon theme system
+ */
+int
+ewl_icon_theme_init(void)
+{
+       DENTER_FUNCTION(DLEVEL_STABLE);
+
+       ewl_icon_theme_cache = ecore_hash_new(ecore_str_hash, 
ecore_str_compare);
+       ecore_hash_set_free_key(ewl_icon_theme_cache, ewl_icon_theme_cb_free);
+       ecore_hash_set_free_value(ewl_icon_theme_cache, ewl_icon_theme_cb_free);
+
+       DRETURN_INT(TRUE, DLEVEL_STABLE);
+}
+
+/**
+ * @return Returns no value.
+ * @brief Shuts down the icon theme system
+ */
+void
+ewl_icon_theme_shutdown(void)
+{
+       DENTER_FUNCTION(DLEVEL_STABLE);
+
+       if (ewl_icon_theme_cache) ecore_hash_destroy(ewl_icon_theme_cache);
+       ewl_icon_theme_cache = NULL;
+
+       DLEAVE_FUNCTION(DLEVEL_STABLE);
+}
+
 /**
  * @return Returns no value
  * @brief Called when the icon theme is changed so we can clean up any
@@ -24,7 +58,11 @@
        else
                ewl_icon_theme_is_edje = 0;
 
-       /* XXX Need to clear out any caches we have here */
+       /* destroy the cache and re-create it */
+       ecore_hash_destroy(ewl_icon_theme_cache);
+       ewl_icon_theme_cache = ecore_hash_new(ecore_str_hash, 
ecore_str_compare);
+       ecore_hash_set_free_key(ewl_icon_theme_cache, ewl_icon_theme_cb_free);
+       ecore_hash_set_free_value(ewl_icon_theme_cache, ewl_icon_theme_cb_free);
 
        DLEAVE_FUNCTION(DLEVEL_STABLE);
 }
@@ -41,6 +79,7 @@
 {
        const char *ret;
        const char *icon_size;
+       char key[256];
 
        DENTER_FUNCTION(DLEVEL_STABLE);
        DCHECK_PARAM_PTR_RET("icon", icon, NULL);
@@ -51,19 +90,34 @@
 
        /* if our theme is an edje just return the .edj file */
        if (ewl_icon_theme_is_edje)
-               DRETURN_PTR(ewl_config.theme.icon.theme, DLEVEL_STABLE);;
-
-       /* XXX Should store a hash of these here so we don't have to keep
-        * looking it up. Just reset the hash on theme change */
+               DRETURN_PTR(ewl_config.theme.icon.theme, DLEVEL_STABLE);
 
        if (!size)
                icon_size = ewl_config.theme.icon.size;
        else
                icon_size = size;
 
-       ret = ecore_desktop_icon_find(icon, icon_size, 
+       snprintf(key, sizeof(key), "[EMAIL PROTECTED]", icon, size);
+       ret = ecore_hash_get(ewl_icon_theme_cache, key);
+       if (!ret)
+       {
+               ret = ecore_desktop_icon_find(icon, icon_size, 
                                        ewl_config.theme.icon.theme);
 
+               ecore_hash_set(ewl_icon_theme_cache, strdup(key), (void *)ret);
+       }
+
        DRETURN_PTR(ret, DLEVEL_STABLE);
 }
+
+static void
+ewl_icon_theme_cb_free(void *data)
+{
+       DENTER_FUNCTION(DLEVEL_STABLE);
+
+       IF_FREE(data);
+
+       DLEAVE_FUNCTION(DLEVEL_STABLE);
+}
+
 
===================================================================
RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_icon_theme.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- ewl_icon_theme.h    6 Sep 2006 15:16:11 -0000       1.3
+++ ewl_icon_theme.h    24 Sep 2006 21:17:27 -0000      1.4
@@ -8,6 +8,9 @@
  * @{
  */
 
+int             ewl_icon_theme_init(void);
+void            ewl_icon_theme_shutdown(void);
+
 void            ewl_icon_theme_theme_change(void);
 
 const char     *ewl_icon_theme_icon_path_get(const char *icon, 
===================================================================
RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_misc.c,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -3 -r1.65 -r1.66
--- ewl_misc.c  14 Sep 2006 05:35:38 -0000      1.65
+++ ewl_misc.c  24 Sep 2006 21:17:27 -0000      1.66
@@ -222,6 +222,12 @@
                DRETURN_INT(--ewl_init_count, DLEVEL_STABLE);
        }
 
+       if (!ewl_icon_theme_init()) {
+               DERROR("Could not init icon theme system.\n");
+               ewl_shutdown();
+               DRETURN_INT(--ewl_init_count, DLEVEL_STABLE);
+       }
+
        if (!(ewl_embed_list = ecore_list_new())) {
                DERROR("Could not allocate embed list, out of memory?\n");
                ewl_shutdown();
@@ -287,6 +293,7 @@
         */
        ewl_embed_shutdown();
        ewl_callbacks_shutdown();
+       ewl_icon_theme_shutdown();
        ewl_theme_shutdown();
        ewl_engines_shutdown();
        ewl_config_shutdown();



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to