Enlightenment CVS committal

Author  : englebass
Project : e17
Module  : libs/efreet

Dir     : e17/libs/efreet/src/lib


Modified Files:
        Efreet_Mime.h efreet_icon.c efreet_icon.h efreet_mime.c 


Log Message:
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!

===================================================================
RCS file: /cvs/e/e17/libs/efreet/src/lib/Efreet_Mime.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- Efreet_Mime.h       17 Jul 2007 19:21:20 -0000      1.5
+++ Efreet_Mime.h       26 Jul 2007 11:30:10 -0000      1.6
@@ -35,7 +35,7 @@
 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);
 
 /**
===================================================================
RCS file: /cvs/e/e17/libs/efreet/src/lib/efreet_icon.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -3 -r1.25 -r1.26
--- efreet_icon.c       25 Jul 2007 17:00:56 -0000      1.25
+++ efreet_icon.c       26 Jul 2007 11:30:10 -0000      1.26
@@ -2,12 +2,10 @@
 #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;
-static Ecore_Hash *efreet_icon_themes = NULL; 
+static Ecore_Hash *efreet_icon_themes = NULL;
 Ecore_List *efreet_icon_extensions = NULL;
 static Ecore_List *efreet_extra_icon_dirs = NULL;
 
@@ -17,52 +15,36 @@
 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, 
-                                              const char *icon, 
-                                              const char *size);
-static Efreet_Icon *efreet_icon_list_find_fallback(Efreet_Icon_Theme *theme, 
-                                                    Ecore_List *cache_keys, 
-                                                    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, 
-                                                    const char *icon_name);
-
-static Efreet_Icon *efreet_icon_lookup_directory(
-                                            Efreet_Icon_Theme *theme,
-                                            Efreet_Icon_Theme_Directory *dir,
-                                            const char *icon_name);
+static char *efreet_icon_find_fallback(Efreet_Icon_Theme *theme,
+                                       const char *icon,
+                                       const char *size);
+static char *efreet_icon_list_find_fallback(Efreet_Icon_Theme *theme,
+                                            Ecore_List *icons,
+                                            const char *size);
+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 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,
                                                     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);
 
 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);
@@ -70,17 +52,17 @@
 static void efreet_icon_theme_dir_scan(const char *dir,
                                         const char *theme_name);
 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);
-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);
 
-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);
 static void efreet_icon_theme_directory_free(Efreet_Icon_Theme_Directory *dir);
 
 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);
 
 /**
@@ -88,7 +70,7 @@
  * @return Returns 1 on success or 0 on failure
  * @brief Initializes the icon system
  */
-int 
+int
 efreet_icon_init(void)
 {
     if (efreet_icon_init_count++ > 0)
@@ -113,7 +95,7 @@
             ecore_list_append(efreet_icon_extensions, strdup(default_exts[i]));
 
         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));
         efreet_extra_icon_dirs = ecore_list_new();
     }
@@ -207,8 +189,8 @@
 
 /**
  * @return Returns a list of Efreet_Icon structs for all the non-hidden icon
- * themes 
- * @brief Retrieves all of the non-hidden icon themes available on the system. 
+ * themes
+ * @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.
  */
 Ecore_List *
@@ -288,7 +270,7 @@
             if (!strcmp(ext, ext2))
             {
 #ifdef STRICT_SPEC
-                printf("[Efreet]: Requesting an icon with an extension: %s\n", 
+                printf("[Efreet]: Requesting an icon with an extension: %s\n",
                                                                         icon);
 #endif
                 *ext = '\0';
@@ -318,8 +300,8 @@
         theme->fake = 1;
         theme->name.internal = ecore_string_instance(theme_name);
         ecore_hash_set(efreet_icon_themes, (void *)theme->name.internal, 
theme);
-    }   
-    
+    }
+
     return theme;
 }
 
@@ -331,42 +313,31 @@
  * 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
-     * then just look for a non theme icon 
+     * then just look for a non theme 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;
 }
 
@@ -374,35 +345,24 @@
  * @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 
+ * @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.
+ * back. This is useful when searching for mimetype icons.
  */
-Efreet_Icon *
-efreet_icon_list_find(const char *theme_name, Ecore_List *icons, 
+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),"[EMAIL PROTECTED]", icon, 
size); 
-        ecore_list_append(share_keys, strdup(cache_key));
-    }
 #ifdef SLOPPY_SPEC
     {
         Ecore_List *tmps = NULL;
@@ -412,18 +372,18 @@
         ecore_list_first_goto(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
-     * 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);
         while ((icon = ecore_list_next(icons)))
@@ -432,14 +392,6 @@
                 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;
 }
@@ -451,33 +403,40 @@
  * @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;
+
+    path = efreet_icon_path_find(theme, icon, size);
+    if (path)
+    {
+        Efreet_Icon *icon;
 
-    ico = efreet_icon_find(theme, icon, size);
+        icon = efreet_icon_new(path);
+        free(path);
+        return icon;
+    }
 
-    return (ico ? ico->path : NULL);
+    return NULL;
 }
 
 /**
  * @internal
  * @param theme: The theme to search in
- * @param cache_key: The cache key to use  ([EMAIL PROTECTED] 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, 
-                                          const char *icon, const char *size)
+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)
     {
         ecore_list_first_goto(theme->inherits);
@@ -488,8 +447,7 @@
             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,49 +459,42 @@
 
         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;
 }
 
 /**
  * @internal
  * @param theme: The theme to search in
- * @param cache_key: The cache key to use  ([EMAIL PROTECTED] 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;
 
     /* limit recursion in finding themes and inherited themes to 256 levels */
     if (recurse > 256) return NULL;
     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 */
     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 @@
 /**
  * @internal
  * @param theme: The theme to search in
- * @param cache_keys: The cache keys to use  ([EMAIL PROTECTED] 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, 
-                                          Ecore_List *icons, const char *size)
+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,14 +526,14 @@
             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;
         }
     }
-    
+
     /* if this isn't the hicolor theme, and we have no other fallbacks
-     * check hicolor 
+     * check hicolor
      */
     else if (strcmp(theme->name.internal, "hicolor"))
     {
@@ -591,50 +541,39 @@
 
         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);
     }
-    
+
     return value;
 }
 
 /**
  * @internal
  * @param theme: The theme to search in
- * @param cache_keys: The cache keys to use  ([EMAIL PROTECTED] 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;
 
     /* limit recursion in finding themes and inherited themes to 256 levels */
     if (recurse > 256) return NULL;
     recurse++;
-   
+
     ecore_list_first_goto(icons);
     while ((icon = ecore_list_next(icons)))
     {
@@ -644,7 +583,7 @@
 
     /* 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,20 +594,20 @@
  * @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 *
-efreet_icon_lookup_icon(Efreet_Icon_Theme *theme, const char *icon_name, 
+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;
 
-    if (!theme || (theme->paths.count == 0) || !icon_name || !size) 
+    if (!theme || (theme->paths.count == 0) || !icon_name || !size)
         return NULL;
 
     real_size = atoi(size);
@@ -692,29 +631,16 @@
         distance = efreet_icon_directory_size_distance(dir, real_size);
         if (distance >= minimal_size) continue;
 
-        tmp = efreet_icon_lookup_directory(theme, dir, 
+        tmp = efreet_icon_lookup_directory(theme, dir,
                                            icon_name);
-        if (tmp) 
+        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), "[EMAIL PROTECTED]", 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 @@
  * 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;
 }
 
 /**
@@ -758,7 +688,7 @@
  * @brief Checks if the size matches for the given directory or not
  */
 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)
 {
     if (dir->type == EFREET_ICON_SIZE_TYPE_FIXED)
@@ -817,10 +747,10 @@
  * @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 @@
  * @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 @@
 
         if (ecore_file_exists(path))
         {
-            icon = efreet_icon_new(path);
+            icon = strdup(path);
             if (icon) break;
         }
     }
@@ -892,7 +822,7 @@
 
         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,160 +843,31 @@
  * @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);
 
-    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)
-    {
-        while ((file = readdir(dirp)))
+        if (ecore_file_exists(file_path))
         {
-            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
  * @brief Creates a new Efreet_Icon struct
  */
@@ -1109,15 +910,14 @@
 }
 
 /**
- * @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;
@@ -1209,7 +1009,7 @@
         char *t, *s, *p;
 
         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));
 
         t = strdup(tmp);
@@ -1284,8 +1084,6 @@
     IF_FREE_LIST(theme->inherits);
     IF_FREE_LIST(theme->directories);
 
-    IF_FREE_HASH(theme->icon_cache);
-
     FREE(theme);
 }
 
@@ -1338,7 +1136,7 @@
     double new_check;
 
     new_check = ecore_time_get();
- 
+
     /* we're within 5 seconds of the last time we checked the cache */
     if ((new_check - 5) <= theme->last_cache_check) return;
 
@@ -1359,19 +1157,6 @@
                 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 @@
     {
         if (efreet_icon_dirs_cached)
             ecore_hash_remove(efreet_icon_dirs_cached, dir);
-        IF_FREE_HASH(theme->icon_cache);
         return 0;
     }
 
@@ -1460,7 +1244,7 @@
          * given name */
         snprintf(path, sizeof(path), "%s/%s", search_dir, dir->d_name);
         if (((theme_name != NULL) && (strcmp(theme_name, dir->d_name)))
-                || !ecore_file_is_dir(path)) 
+                || !ecore_file_is_dir(path))
             continue;
 
         key = ecore_string_instance(dir->d_name);
@@ -1470,7 +1254,7 @@
         {
             theme = efreet_icon_theme_new();
             theme->name.internal = key;
-            ecore_hash_set(efreet_icon_themes, 
+            ecore_hash_set(efreet_icon_themes,
                         (void *)theme->name.internal, theme);
         }
         else
@@ -1497,7 +1281,7 @@
     if (theme_name)
     {
         Efreet_Icon_Theme *theme;
-    
+
         theme = ecore_hash_get(efreet_icon_themes, theme_name);
         if (theme && !theme->valid && !theme->fake)
         {
@@ -1536,7 +1320,7 @@
     tmp = efreet_ini_localestring_get(ini, "Comment");
     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);
 
     theme->hidden = efreet_ini_boolean_get(ini, "Hidden");
@@ -1578,7 +1362,7 @@
         int last = 0;
 
         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));
 
         t = strdup(tmp);
@@ -1592,7 +1376,7 @@
             if (!p) last = 1;
             else *p = '\0';
 
-            ecore_list_append(theme->directories, 
+            ecore_list_append(theme->directories,
                             efreet_icon_theme_directory_new(ini, s));
 
             if (!last) s = ++p;
@@ -1669,11 +1453,11 @@
 
         else if (!strcasecmp(tmp, "FileSystems"))
             dir->context = EFREET_ICON_THEME_CONTEXT_FILESYSTEMS;
-        
+
         else if (!strcasecmp(tmp, "MimeTypes"))
             dir->context = EFREET_ICON_THEME_CONTEXT_MIMETYPES;
     }
- 
+
     tmp = efreet_ini_string_get(ini, "Type");
     if (tmp)
     {
===================================================================
RCS file: /cvs/e/e17/libs/efreet/src/lib/efreet_icon.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -3 -r1.4 -r1.5
--- efreet_icon.h       17 Jul 2007 19:21:20 -0000      1.4
+++ efreet_icon.h       26 Jul 2007 11:30:10 -0000      1.5
@@ -79,7 +79,6 @@
     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 @@
 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);
 
 /** 
  * @}
===================================================================
RCS file: /cvs/e/e17/libs/efreet/src/lib/efreet_mime.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -3 -r1.23 -r1.24
--- efreet_mime.c       25 Jul 2007 17:00:56 -0000      1.23
+++ efreet_mime.c       26 Jul 2007 11:30:10 -0000      1.24
@@ -132,6 +132,7 @@
     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 @@
  * @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 @@
       
     ecore_list_destroy(icons);
     
-    if (icon)
-        return icon->path;
-    
-    return NULL;
+    return icon;
 }
 
 /**



-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to