Enlightenment CVS committal

Author  : onefang
Project : e17
Module  : libs/ecore

Dir     : e17/libs/ecore/src/lib/ecore_desktop


Modified Files:
        Ecore_Desktop.h ecore_desktop.c ecore_desktop_icon.c 
        ecore_desktop_menu.c ecore_desktop_paths.c 


Log Message:
*Icon theme support functions.

*Minor API change that no one was using anyway.

===================================================================
RCS file: /cvs/e/e17/libs/ecore/src/lib/ecore_desktop/Ecore_Desktop.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -3 -r1.13 -r1.14
--- Ecore_Desktop.h     19 Aug 2006 06:26:00 -0000      1.13
+++ Ecore_Desktop.h     20 Aug 2006 03:45:53 -0000      1.14
@@ -54,6 +54,22 @@
 };
 typedef struct _Ecore_Desktop Ecore_Desktop;
 
+struct _Ecore_Desktop_Icon_Theme
+{
+   Ecore_Hash         *data, *group;
+   Ecore_List         *Directories;
+   char               *path;
+   char               *name;
+   char               *comment;
+   char               *example;
+   char               *example_path;
+   char               *inherits;
+   char               *directories;
+   int                 hidden;
+};
+typedef struct _Ecore_Desktop_Icon_Theme Ecore_Desktop_Icon_Theme;
+
+
 enum _Ecore_Desktop_Tree_Element_Type
 {
    ECORE_DESKTOP_TREE_ELEMENT_TYPE_NULL = 0,
@@ -88,13 +104,13 @@
    /* Function Prototypes */
    EAPI int            ecore_desktop_paths_init(void);
    char               *ecore_desktop_paths_file_find(Ecore_List * paths,
-                                                  const char *file, const int 
sub,
+                                                  const char *file, int sub,
                                                   int (*func) (void
                                                                *data,
                                                                const char
                                                                *path),
                                                   void *data);
-   char               *ecore_desktop_paths_recursive_search(const char *path, 
const char *file,
+   char               *ecore_desktop_paths_recursive_search(const char *path, 
const char *file, int sub,
                                                            int (*dir_func)
                                                            (void *data,
                                                             const char *path),
@@ -114,12 +130,17 @@
    Ecore_Desktop      *ecore_desktop_get(const char *file, const char *lang);
    void                ecore_desktop_destroy(Ecore_Desktop * desktop);
 
+
+   EAPI int            ecore_desktop_icon_init(void);
+   EAPI int            ecore_desktop_icon_shutdown(void);
    const char         *ecore_desktop_icon_find(const char *icon, 
                                               const char *icon_size,
                                               const char *icon_theme);
 
 
    Ecore_Hash         *ecore_desktop_icon_theme_list(void);
+   Ecore_Desktop_Icon_Theme      *ecore_desktop_icon_theme_get(const char 
*file, const char *lang);
+   void                
ecore_desktop_icon_theme_destroy(Ecore_Desktop_Icon_Theme *icon_theme);
 
 
    Ecore_Desktop_Tree *ecore_desktop_menu_get(char *file);
===================================================================
RCS file: /cvs/e/e17/libs/ecore/src/lib/ecore_desktop/ecore_desktop.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -3 -r1.10 -r1.11
--- ecore_desktop.c     18 Aug 2006 21:52:33 -0000      1.10
+++ ecore_desktop.c     20 Aug 2006 03:45:53 -0000      1.11
@@ -17,6 +17,8 @@
 static Ecore_Hash  *ini_file_cache;
 static Ecore_Hash  *desktop_cache;
 
+void _ecore_desktop_destroy(Ecore_Desktop * desktop);
+
 
 /**
  * @defgroup Ecore_Desktop_Main_Group .desktop file Functions
@@ -145,7 +147,7 @@
  * as returned by ecore_desktop_ini_get().  Some of the data in the
  * .desktop file is decoded into specific members of the returned 
  * structure.
- * 
+ *
  * Use ecore_desktop_destroy() to free this structure.
  *
  * @param   file Full path to the .desktop file.
@@ -370,10 +372,12 @@
          {
             ecore_hash_set_free_key(desktop_cache, free);
             ecore_hash_set_free_value(desktop_cache,
-                                      (Ecore_Free_Cb) ecore_desktop_destroy);
+                                      (Ecore_Free_Cb) _ecore_desktop_destroy);
          }
      }
 
+   if (!ecore_desktop_icon_init()) return --init_count;
+
    return init_count;   
 }
 
@@ -390,6 +394,8 @@
 {
    if (--init_count != 0) return init_count;
 
+   ecore_desktop_icon_shutdown();
+
    if (ini_file_cache)
      {
        ecore_hash_destroy(ini_file_cache);
@@ -417,6 +423,13 @@
  */
 void
 ecore_desktop_destroy(Ecore_Desktop * desktop)
+{
+  /* This is just a dummy, because these structures are cached. */
+  /* Later versions of the cache may reference count, then this will be 
useful. */
+}
+
+void
+_ecore_desktop_destroy(Ecore_Desktop * desktop)
 {
    if (desktop->eap_name)
       free(desktop->eap_name);
===================================================================
RCS file: /cvs/e/e17/libs/ecore/src/lib/ecore_desktop/ecore_desktop_icon.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -3 -r1.10 -r1.11
--- ecore_desktop_icon.c        19 Aug 2006 06:26:00 -0000      1.10
+++ ecore_desktop_icon.c        20 Aug 2006 03:45:53 -0000      1.11
@@ -10,9 +10,13 @@
                                              const char *icon_theme);
 
 static int _ecore_desktop_icon_theme_list_add(void *data, const char *path);
+void _ecore_desktop_icon_theme_destroy(Ecore_Desktop_Icon_Theme * icon_theme);
 
 
 static const char  *ext[] = { ".png", ".svgz", ".svg", ".xpm", "", NULL };
+static int          init_count = 0;
+static Ecore_Hash  *icon_theme_cache;
+static int          loaded = 0;
 
 
 /**
@@ -142,7 +146,7 @@
    printf("SEARCHING FOR %s\n", icn);
 #endif
    theme_path =
-      ecore_desktop_paths_file_find(ecore_desktop_paths_icons, icn, 1,
+      ecore_desktop_paths_file_find(ecore_desktop_paths_icons, icn, 2,
                                          NULL, NULL);
    if (theme_path)
      {
@@ -380,39 +384,184 @@
 Ecore_Hash *
 ecore_desktop_icon_theme_list(void)
 {
-   Ecore_Hash *result = NULL;
-
-   result = ecore_hash_new(ecore_str_hash, ecore_str_compare);
-   if (result)
-      {
-        ecore_hash_set_free_key(result, free);
-        ecore_hash_set_free_value(result, free);
-         ecore_desktop_paths_file_find(ecore_desktop_paths_icons, 
"index.theme", 1, _ecore_desktop_icon_theme_list_add, result);
-      }
-
-   return result;
+   if (!loaded)
+      ecore_desktop_paths_file_find(ecore_desktop_paths_icons, "index.theme", 
2, _ecore_desktop_icon_theme_list_add, NULL);
+   loaded = 1;
+   return icon_theme_cache;
 }
 
 
 static int 
 _ecore_desktop_icon_theme_list_add(void *data, const char *path)
 {
-   Ecore_Hash *result;
-
-   result = data;
-   if (result)
-      {
-         char *key, *dir;
-
-         dir = ecore_file_get_dir(path);
-        if (dir)
-           {
-              key = (char *) ecore_file_get_file(dir);
-              if (ecore_hash_get(result, key) == NULL)  /* Only the first one 
found for each name is important. */
-                  ecore_hash_set(result, strdup(key), strdup(path));
-              free(dir);
-           }
-      }
+   char                icn[PATH_MAX];
 
+   snprintf(icn, PATH_MAX, "%sindex.theme", path);
+   if (ecore_desktop_icon_theme_get(icn, NULL))
+      return 1;  /* Should stop it from recursing this directory, but let it 
continue searching the next. */
    return 0;
+}
+
+
+/**
+ * Setup what ever needs to be setup to support ecore_desktop_icon.
+ *
+ * There are internal structures that are needed for ecore_desktop_icon
+ * functions to operate, this sets them up.
+ *
+ * @ingroup Ecore_Desktop_Icon_Group
+ */
+EAPI int
+ecore_desktop_icon_init()
+{
+   if (++init_count != 1) return init_count;
+
+   if (!icon_theme_cache)
+     {
+       icon_theme_cache = ecore_hash_new(ecore_str_hash, ecore_str_compare);
+       if (icon_theme_cache)
+         {
+            ecore_hash_set_free_key(icon_theme_cache, free);
+            ecore_hash_set_free_value(icon_theme_cache,
+                                      (Ecore_Free_Cb) 
_ecore_desktop_icon_theme_destroy);
+         }
+     }
+
+   return init_count;   
+}
+
+/**
+ * Tear down what ever needs to be torn down to support ecore_desktop_ycon.
+ *
+ * There are internal structures that are needed for ecore_desktop_icon
+ * functions to operate, this tears them down.
+ *
+ * @ingroup Ecore_Desktop_Icon_Group
+ */
+EAPI int
+ecore_desktop_icon_shutdown()
+{
+   if (--init_count != 0) return init_count;
+
+   if (icon_theme_cache)
+     {
+       ecore_hash_destroy(icon_theme_cache);
+       icon_theme_cache = NULL;
+     }
+
+   return init_count;   
+}
+
+
+/**
+ * Get the contents of an index.theme file.
+ *
+ * Everything that is in the index.theme file is returned in the
+ * data member of the Ecore_Desktop_Icon_Theme structure, it's an Ecore_Hash 
+ * as returned by ecore_desktop_ini_get().  Some of the data in the
+ * index.theme file is decoded into specific members of the returned 
+ * structure.
+ *
+ * Use ecore_desktop_icon_theme_destroy() to free this structure.
+ * 
+ * @param   icon_theme Name of the icon theme, or full path to the index.theme 
file.
+ * @param   lang Language to use, or NULL for default.
+ * @return  An Ecore_Desktop_Icon_Theme containing the files contents.
+ * @ingroup Ecore_Desktop_Icon_Group
+ */
+Ecore_Desktop_Icon_Theme      *
+ecore_desktop_icon_theme_get(const char *icon_theme, const char *lang)
+{
+   Ecore_Desktop_Icon_Theme      *result;
+
+   result = (Ecore_Desktop_Icon_Theme *) ecore_hash_get(icon_theme_cache, 
(char *) icon_theme);
+   if (!result)
+     {
+        char  icn[PATH_MAX], *theme_path;
+
+        if (icon_theme[0] == '/')
+          {
+              char *dir;
+
+             theme_path = strdup(icon_theme);
+              dir = ecore_file_get_dir(theme_path);
+             if (dir)
+                icon_theme = (char *) ecore_file_get_file(dir);
+#ifdef DEBUG
+              printf("LOADING THEME %s  -   %s\n", icon_theme, theme_path);
+#endif
+          }
+       else
+          {
+              snprintf(icn, PATH_MAX, "%s/index.theme", icon_theme);
+#ifdef DEBUG
+              printf("SEARCHING FOR %s\n", icn);
+#endif
+              theme_path = 
ecore_desktop_paths_file_find(ecore_desktop_paths_icons, icn, 2, NULL, NULL);
+          }
+        if (theme_path)
+          {
+             result = calloc(1, sizeof(Ecore_Desktop_Icon_Theme));
+             if (result)
+               {
+                  result->data = ecore_desktop_ini_get(theme_path);
+                  if (result->data)
+                    {
+                       result->group =
+                          (Ecore_Hash *) ecore_hash_get(result->data,
+                                                  "Icon Theme");
+                       if (result->group)
+                         {
+                            char               *value;
+
+                            result->path = theme_path;
+                            result->name = (char 
*)ecore_hash_get(result->group, "Name");
+                            result->comment = (char 
*)ecore_hash_get(result->group, "Comment");
+                            result->inherits = (char 
*)ecore_hash_get(result->group, "Inherits");
+                            result->directories = (char 
*)ecore_hash_get(result->group, "Directories");
+                            value = (char *)ecore_hash_get(result->group, 
"Example");
+                            if (!value)
+                               value = "exec";
+                            result->example = strdup(value);
+
+                            ecore_hash_set(icon_theme_cache, 
strdup(icon_theme), result);
+                         }
+                    }
+
+                  if (!result->path)
+                    {
+                       free(theme_path);
+                       free(result);
+                       result = NULL;
+                    }
+               }
+          }
+     }
+
+   return result;
+}
+
+
+/**
+ * Free whatever resources are used by an Ecore_Desktop_Icon_Theme.
+ *
+ * There are internal resources used by each Ecore_Desktop_Icon_Theme
+ * This releases those resources.
+ *
+ * @param  icon_theme  An Ecore_Desktop_Icon_Theme.
+ * @ingroup Ecore_Desktop_Icon_Group
+ */
+void
+ecore_desktop_icon_theme_destroy(Ecore_Desktop_Icon_Theme * icon_theme)
+{
+  /* This is just a dummy, because these structures are cached. */
+  /* Later versions of the cache may reference count, then this will be 
useful. */
+}
+
+void
+_ecore_desktop_icon_theme_destroy(Ecore_Desktop_Icon_Theme * icon_theme)
+{
+   if (icon_theme->path) free(icon_theme->path);
+   if (icon_theme->example) free(icon_theme->example);
+   free(icon_theme);
 }
===================================================================
RCS file: /cvs/e/e17/libs/ecore/src/lib/ecore_desktop/ecore_desktop_menu.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -3 -r1.8 -r1.9
--- ecore_desktop_menu.c        18 Aug 2006 21:52:33 -0000      1.8
+++ ecore_desktop_menu.c        20 Aug 2006 03:45:53 -0000      1.9
@@ -949,7 +949,7 @@
           sprintf(dir, "%s/%s", unxml_data->path, app_dir);
        our_data.path = dir;
        our_data.length = strlen(dir);
-       ecore_desktop_paths_recursive_search(dir, NULL, NULL,
+       ecore_desktop_paths_recursive_search(dir, NULL, -1, NULL,
                                             _ecore_desktop_menu_check_app,
                                             &our_data);
      }
@@ -1031,7 +1031,7 @@
                sprintf(merge_path, "%s", &string[10]);
             else
                sprintf(merge_path, "%s%s", unxml_data->path, &string[10]);
-            ecore_desktop_paths_recursive_search(merge_path, NULL, NULL,
+            ecore_desktop_paths_recursive_search(merge_path, NULL, -1, NULL,
                                                  
_ecore_desktop_menu_check_menu,
                                                  merge);
             result = 1;
@@ -1071,7 +1071,7 @@
 #ifdef DEBUG
             printf("<LEGACYDIR> - %s - %s\n", legacy_data.prefix, merge_path);
 #endif
-            ecore_desktop_paths_recursive_search(merge_path, NULL,
+            ecore_desktop_paths_recursive_search(merge_path, NULL, -1,
                                                  
_ecore_desktop_menu_legacy_menu_dir,
                                                  
_ecore_desktop_menu_legacy_menu,
                                                  &legacy_data);
@@ -1306,7 +1306,7 @@
                                 if (merge)
                                   {
                                      ecore_desktop_paths_recursive_search
-                                        (merge_path, NULL, NULL,
+                                        (merge_path, NULL, -1, NULL,
                                          _ecore_desktop_menu_check_directory,
                                          merge);
                                      ecore_desktop_tree_merge(tree, i + 1,
===================================================================
RCS file: /cvs/e/e17/libs/ecore/src/lib/ecore_desktop/ecore_desktop_paths.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -3 -r1.9 -r1.10
--- ecore_desktop_paths.c       18 Aug 2006 21:52:33 -0000      1.9
+++ ecore_desktop_paths.c       20 Aug 2006 03:45:53 -0000      1.10
@@ -254,12 +254,12 @@
  *
  * @param   type The type of directories to search.
  * @param   file The file to search for.
- * @param   sub Should we search sub directories.
+ * @param   sub Levels of sub directories to search, -1 = all, 0 = none.
  * @param   func A function to call for each file found.
  * @param   data A pointer to pass on to func.
  */
 char               *
-ecore_desktop_paths_file_find(Ecore_List * paths, const char *file, const int 
sub,
+ecore_desktop_paths_file_find(Ecore_List * paths, const char *file, int sub,
                                    int (*func) (void *data, const char *path),
                                    void *data)
 {
@@ -282,9 +282,9 @@
                     if (func(data, temp))
                        break;
               }
-            else if (sub)
+            else if (sub != 0)
                path =
-                  ecore_desktop_paths_recursive_search(this_path, file, NULL,
+                  ecore_desktop_paths_recursive_search(this_path, file, sub, 
NULL,
                                                        func, data);
             if (path && (!func))
                break;
@@ -539,7 +539,7 @@
 }
 
 char               *
-ecore_desktop_paths_recursive_search(const char *path, const char *file,
+ecore_desktop_paths_recursive_search(const char *path, const char *file, int 
sub,
                                     int (*dir_func) (void *data,
                                                      const char *path),
                                     int (*func) (void *data, const char *path),
@@ -548,6 +548,10 @@
    char               *fpath = NULL;
    DIR                *dir = NULL;
 
+
+   if ((sub != 0) && (sub != -1))
+         sub -= 1;
+
    dir = opendir(path);
 
    if (dir != NULL)
@@ -571,11 +575,12 @@
                            if (dir_func)
                               if (dir_func(data, info_text))
                                  break;
-                           fpath =
-                              ecore_desktop_paths_recursive_search(info_text,
-                                                                   file,
-                                                                   dir_func,
-                                                                   func, data);
+                           if (sub != 0)
+                              fpath =
+                                 
ecore_desktop_paths_recursive_search(info_text,
+                                                                      file, 
sub,
+                                                                      dir_func,
+                                                                      func, 
data);
                         }
                    }
                  else



-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to