- add e_thumb, rip code from efm into its own file, can thumbnail images and eaps...
authorcodewarrior <codewarrior>
Tue, 18 Oct 2005 23:03:36 +0000 (23:03 +0000)
committercodewarrior <codewarrior@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Tue, 18 Oct 2005 23:03:36 +0000 (23:03 +0000)
- remove all thumb code from efm and use e_thumb
- fixme: first time startup bug for efm is still there (if the thumbnailer hasnt been used, still debugging )

SVN revision: 17668

src/bin/Makefile.am
src/bin/e_fileman_smart.c
src/bin/e_includes.h
src/bin/e_thumb.c [new file with mode: 0644]
src/bin/e_thumb.h [new file with mode: 0644]

index a45987d..1f11d66 100644 (file)
@@ -95,7 +95,8 @@ e_widget_table.h \
 e_config_dialog.h \
 e_int_config_focus.h \
 e_icon_layout.h \
-e_int_border_locks.h
+e_int_border_locks.h \
+e_thumb.h
 
 enlightenment_src = \
 e_user.c \
@@ -173,6 +174,7 @@ e_config_dialog.c \
 e_int_config_focus.c \
 e_icon_layout.c \
 e_int_border_locks.c \
+e_thumb.c \
 $(ENLIGHTENMENTHEADERS)
 
 enlightenment_SOURCES = \
index b51c22c..8e02d5e 100644 (file)
 #include <grp.h>
 
 /* TODO:
- * - scrolling 
+ * - scrolling
  * 
  * - checking wether events belong to us (ecore events)
  *
  * - add ability to have icons on desktop (this works, but we need some fixes)
  *   files should go on ~/.e/e/desktop for example.
  *
- * - add eap support. load eaps and exec them on double click. this would
- *   allow us to embed E's control panel for example.
- *
  * - when we select multiple items, the right click menu on the icons needs
  *   to display some group related things and its actions need to work
  *   on the group.
@@ -199,8 +196,6 @@ struct _E_Fm_Smart_Data
    int visible_files;
    double position;
 
-   char *thumb_path;
-
    struct {
        unsigned char start : 1;
        int x, y;
@@ -293,11 +288,6 @@ static void                _e_fm_file_menu_delete(void *data, E_Menu *m, E_Menu_
 static void                _e_fm_file_menu_properties(void *data, E_Menu *m, E_Menu_Item *mi);
 static void                _e_fm_file_delete_yes_cb(void *data, E_Dialog *dia);
 static void                _e_fm_file_delete_no_cb(void *data, E_Dialog *dia);
-static char               *_e_fm_file_thumb_path_get(char *file);
-static Evas_Bool           _e_fm_file_thumb_exists(char *file);
-static Evas_Bool           _e_fm_file_thumb_create(char *file);
-static Evas_Object        *_e_fm_file_thumb_get(E_Fm_File *file);
-static char               *_e_fm_file_id(char *file);
 static void                _e_fm_fake_mouse_up_cb(void *data);
 static void                _e_fm_fake_mouse_up_later(Evas *evas, int button);
 static void                _e_fm_fake_mouse_up_all_later(Evas *evas);
@@ -323,7 +313,7 @@ static int                 _e_fm_drop_drop_cb(void *data, int type, void *event)
 static int                 _e_fm_thumbnailer_exit(void *data, int type, void *event);
 
 static Ecore_Event_Handler *_e_fm_mouse_up_handler = NULL;
-static char *thumb_path;
+
 static double _e_fm_grab_time = 0;
 static Evas_Smart *e_fm_smart = NULL;
 
@@ -541,16 +531,8 @@ _e_fm_smart_add(Evas_Object *object)
    sd->icon_info.x_space = 15;
    sd->icon_info.y_space = 15;
 
-   homedir = e_user_homedir_get();
-   if (homedir)
-     {
-       thumb_path = E_NEW(char, PATH_MAX);
-       snprintf(thumb_path, PATH_MAX, "%s/.e/e/fileman/thumbnails", homedir);
-       if (!ecore_file_exists(thumb_path))
-         ecore_file_mkpath(thumb_path);
-       free(homedir);
-     }
-
+   e_thumb_init();
+   
    sd->monitor = NULL;
    sd->file_offset = 0;
    sd->position = 0;
@@ -676,6 +658,8 @@ _e_fm_smart_del(Evas_Object *object)
 
    free(sd->dir);
    free(sd);
+   
+   e_thumb_shutdown();
 }
 
 static void
@@ -1383,15 +1367,20 @@ _e_fm_thumbnailer_exit(void *data, int type, void *event)
    Ecore_Event_Exe_Exit *ev;
    E_Fm_Smart_Data *sd;
    Evas_List *l;
-
+   char *fullname;
+   
    ev = event;
    sd = data;
 
+
+   D(("_e_fm_thumbnailer_exit: %s\n", "searching for thumbnail.."));
+   
    for (l = sd->pending_thumbs; l; l = l->next)
      {
        E_Fm_Thumb_Pending *pthumb;
        Evas_Object *thumb;
 
+       
        pthumb = l->data;
        if (pthumb->pid != ev->pid) continue;
 
@@ -1402,9 +1391,16 @@ _e_fm_thumbnailer_exit(void *data, int type, void *event)
             pthumb->file->icon_img = NULL;
          }
 
-       thumb = _e_fm_file_thumb_get(pthumb->file);
+       fullname = _e_fm_file_fullname(pthumb->file);
+       thumb = e_thumb_evas_object_get(fullname,
+                                       pthumb->file->sd->evas, 
+                                       pthumb->file->sd->icon_info.w, 
+                                       pthumb->file->sd->icon_info.h);
+       free(fullname);
+       
        if (thumb)
          {
+            D(("_e_fm_thumbnailer_exit: thumb found for%s\n",pthumb->file->attr->name));
             pthumb->file->icon_img = thumb;
             edje_object_part_swallow(pthumb->file->icon, "icon_swallow", pthumb->file->icon_img);
          }
@@ -1423,34 +1419,34 @@ _e_fm_file_thumb_generate_job(void *data)
    pid_t pid;
    E_Fm_File *file;
 
+   if (!data)
+     return;   
    file = data;
-   if (!file)
-     return;
 
    pthumb = E_NEW(E_Fm_Thumb_Pending, 1);
    pthumb->file = file;
 
    pid = fork();
-
+   
    if (pid == 0)
-     {
+    {
        /* child */
        char *fullname;
-
-       fullname = _e_fm_file_fullname(file);
+       
+       fullname = _e_fm_file_fullname(pthumb->file);
        if (fullname)
-         {
-            if (!_e_fm_file_thumb_exists(fullname))
-              _e_fm_file_thumb_create(fullname);
+        {
+            if (!e_thumb_exists(fullname))
+              e_thumb_create(fullname, pthumb->file->sd->icon_info.w, pthumb->file->sd->icon_info.h);
             free(fullname);
          }
        exit(0);
      }
    else if (pid > 0)
-     {
-       /* parent */
-       pthumb->pid = pid;
-       file->sd->pending_thumbs = evas_list_append(file->sd->pending_thumbs, pthumb);
+    {
+       /* parent */
+       pthumb->pid = pid;
+       pthumb->file->sd->pending_thumbs = evas_list_append(pthumb->file->sd->pending_thumbs, pthumb);
      }
 }
 
@@ -1469,12 +1465,12 @@ _e_fm_file_icon_get(E_Fm_File *file)
    if (fullname)
      {
        Evas_Object *o = NULL;
-       if (_e_fm_file_thumb_exists(fullname))
-         o = _e_fm_file_thumb_get(file);
+       if (e_thumb_exists(fullname))
+         o = e_thumb_evas_object_get(fullname, file->sd->evas, file->sd->icon_info.w, file->sd->icon_info.h);
        free(fullname);
        if (o) return o;
      }
-
+   
    ecore_job_add(_e_fm_file_thumb_generate_job, file);
    return _e_fm_file_icon_mime_get(file);
 }
@@ -2658,138 +2654,6 @@ _e_fm_grabbed_mouse_up_cb(void *data, int type, void *event)
    return 0;
 }
 
-static char *
-_e_fm_file_thumb_path_get(char *file)
-{
-   char *id;
-   char thumb[PATH_MAX];
-   id = _e_fm_file_id(file);
-   snprintf(thumb, sizeof(thumb), "%s/%s", thumb_path, id);
-   free(id);
-   return strdup(thumb);
-}
-
-static Evas_Bool
-_e_fm_file_thumb_exists(char *file)
-{
-   char *thumb;
-   Evas_Bool ret;
-
-   thumb = _e_fm_file_thumb_path_get(file);
-   ret = ecore_file_exists(thumb);
-   free(thumb);
-
-   return ret;
-}
-
-static Evas_Bool
-_e_fm_file_thumb_create(char *file)
-{
-   Eet_File *ef;
-   char *thumbpath;
-   Evas_Object *im;
-   const int *data;
-   int size;
-   Ecore_Evas *buf;
-   Evas *evasbuf;
-
-   thumbpath = _e_fm_file_thumb_path_get(file);
-
-   ef = eet_open(thumbpath, EET_FILE_MODE_WRITE);
-   if (!ef)
-     {
-       free(thumbpath);
-               return -1;
-     }
-   free(thumbpath);
-
-   // we need to remove the hardcode somehow.
-   //buf = ecore_evas_buffer_new(file->sd->icon_info.w,file->sd->icon_info.h);
-   buf = ecore_evas_buffer_new(48, 48);
-   evasbuf = ecore_evas_get(buf);
-   im = evas_object_image_add(evasbuf);
-   evas_object_image_file_set(im, file, NULL);
-   evas_object_image_fill_set(im, 0, 0, 48, 48);
-   evas_object_resize(im, 48, 48);
-   evas_object_show(im);
-   data = ecore_evas_buffer_pixels_get(buf);
-
-   if ((size = eet_data_image_write(ef, "/thumbnail/data", (void *)data, 48, 48, 1, 0, 70, 1)) < 0)
-     {
-       printf("BUG: Couldn't write thumb db\n");
-     }
-
-   eet_close(ef);
-
-   ecore_evas_free(buf);
-   return 1;
-}
-
-static Evas_Object *
-_e_fm_file_thumb_get(E_Fm_File *file)
-{
-   Eet_File *ef;
-   char *thumb, *fullname, *ext;
-   Evas_Object *im = NULL;
-   void *data;
-   unsigned int w, h;
-   int a, c, q, l;
-   
-
-   fullname = _e_fm_file_fullname(file);
-   
-   ext = strrchr(file->attr->name, '.');   
-   if(ext)
-    {
-       if(!strcasecmp(ext, ".eap"))
-       {
-          E_App *app;
-          
-          app = e_app_new(fullname, 0);
-          
-          if(!app)
-           { /* fallback icon */ }
-          
-          im = edje_object_add(file->sd->evas);
-          edje_object_file_set(im, fullname, "icon");
-          free(fullname);
-          e_object_unref(E_OBJECT(a));       
-          return im;       
-       }
-    }      
-   
-   if (!_e_fm_file_thumb_exists(fullname))
-     _e_fm_file_thumb_create(fullname);
-
-   thumb = _e_fm_file_thumb_path_get(fullname);
-
-   ef = eet_open(thumb, EET_FILE_MODE_READ);
-   if (!ef)
-     {
-       free(fullname);
-       free(thumb);
-               return NULL;
-     }
-   free(fullname);
-   free(thumb);
-
-   data = eet_data_image_read(ef, "/thumbnail/data", &w, &h, &a, &c, &q, &l);
-   if (data)
-    {
-       im = evas_object_image_add(file->sd->evas);
-       evas_object_image_alpha_set(im, 0);
-       evas_object_image_size_set(im, w, h);
-       evas_object_image_smooth_scale_set(im, 0);
-       evas_object_image_data_copy_set(im, data);
-       evas_object_image_data_update_add(im, 0, 0, w, h);
-       evas_object_image_fill_set(im, 0, 0, w, h);
-       evas_object_resize(im, w, h);
-       free(data);
-    }
-   eet_close(ef);
-   return im;
-}
-
 static E_Fm_File_Type
 _e_fm_file_type(E_Fm_File *file)
 {
@@ -2923,35 +2787,3 @@ _e_fm_file_fullname(E_Fm_File *file)
 
    return strdup(fullname);
 }
-
-static char *
-_e_fm_file_id(char *file)
-{
-   char                s[256];
-   const char         *chmap =
-     "0123456789abcdefghijklmnopqrstuvwxyz\80\81\82\83\84\85\86\87\88\8a\8b\8c\8d\8e\8f\90\91\92\93\9d-_";
-   int                 id[2];
-   struct stat         st;
-
-   if (stat(file, &st) < 0)
-     return NULL;
-   id[0] = (int)st.st_ino;
-   id[1] = (int)st.st_dev;
-
-   sprintf(s,
-          "%c%c%c%c%c%c"
-          "%c%c%c%c%c%c",
-          chmap[(id[0] >> 0) & 0x3f],
-          chmap[(id[0] >> 6) & 0x3f],
-          chmap[(id[0] >> 12) & 0x3f],
-          chmap[(id[0] >> 18) & 0x3f],
-          chmap[(id[0] >> 24) & 0x3f],
-          chmap[(id[0] >> 28) & 0x3f],
-          chmap[(id[1] >> 0) & 0x3f],
-          chmap[(id[1] >> 6) & 0x3f],
-          chmap[(id[1] >> 12) & 0x3f],
-          chmap[(id[1] >> 18) & 0x3f],
-          chmap[(id[1] >> 24) & 0x3f], chmap[(id[1] >> 28) & 0x3f]);
-
-   return strdup(s);
-}
index ee4cc0e..d978428 100644 (file)
@@ -77,3 +77,4 @@
 #include "e_int_config_focus.h"
 #include "e_icon_layout.h"
 #include "e_int_border_locks.h"
+#include "e_thumb.h"
diff --git a/src/bin/e_thumb.c b/src/bin/e_thumb.c
new file mode 100644 (file)
index 0000000..648db0f
--- /dev/null
@@ -0,0 +1,232 @@
+/*
+* vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
+*/
+
+#include "e.h"
+
+static char       *_e_thumb_file_id(char *file);
+
+static char       *thumb_path = NULL;
+
+int
+e_thumb_init(void)
+{
+   char *homedir;
+   char  path[PATH_MAX];
+   
+   homedir = e_user_homedir_get();
+   if (homedir)
+    {
+       snprintf(path, sizeof(path), "%s/.e/e/fileman/thumbnails", homedir);
+       if (!ecore_file_exists(path))
+        ecore_file_mkpath(path);
+       thumb_path = strdup(path);
+       free(homedir);
+    }
+   else return 0;
+   
+   return 1;
+}
+
+int
+e_thumb_shutdown(void)
+{
+   free(thumb_path);
+   return 1;
+}
+
+char *
+e_thumb_dir_get(void)
+{
+   return strdup(thumb_path);
+}
+
+char *
+e_thumb_file_get(char *file)
+{
+   char *id;
+   char thumb[PATH_MAX];
+   
+   id = _e_thumb_file_id(file);   
+   if(!thumb) { free(id); return NULL; }
+   snprintf(thumb, sizeof(thumb), "%s/%s", thumb_path, id);
+   free(id);
+   return strdup(thumb);   
+}
+
+int
+e_thumb_exists(char *file)
+{
+   char *thumb;
+   int ret;
+   
+   thumb = e_thumb_file_get(file);
+   ret = ecore_file_exists(thumb);
+   free(thumb);
+   
+   return ret;     
+}
+
+int
+e_thumb_create(char *file, Evas_Coord w, Evas_Coord h)
+{
+   Eet_File *ef;
+   char *thumbpath;
+   Evas_Object *im;
+   const int *data;
+   int size;
+   Ecore_Evas *buf;
+   Evas *evasbuf;
+   
+   thumbpath = e_thumb_file_get(file);
+   if(!thumbpath) { free(thumbpath); return -1; }
+   
+   ef = eet_open(thumbpath, EET_FILE_MODE_WRITE);
+   if (!ef)
+    {
+       free(thumbpath);
+       return -1;
+    }
+   
+   free(thumbpath);
+   
+   buf = ecore_evas_buffer_new(w, h);
+   evasbuf = ecore_evas_get(buf);
+   im = evas_object_image_add(evasbuf);
+   evas_object_image_file_set(im, file, NULL);
+   evas_object_image_fill_set(im, 0, 0, w, h);
+   evas_object_resize(im, w, h);
+   evas_object_show(im);
+   data = ecore_evas_buffer_pixels_get(buf);
+   
+   if ((size = eet_data_image_write(ef, "/thumbnail/data", (void *)data, w, h, 1, 0, 70, 1)) < 0)
+    {
+       printf("e_thumb: BUG: Couldn't write thumb db\n");
+       eet_close(ef);
+       return -1;
+    }
+   
+   eet_close(ef);
+   
+   ecore_evas_free(buf);
+   return 1;
+}
+
+Evas_Object *
+e_thumb_evas_object_get(char *file, Evas *evas, Evas_Coord width, Evas_Coord height)
+{
+   Eet_File *ef;
+   char *thumb, *ext;
+   Evas_Object *im = NULL;
+   void *data;
+   unsigned int w, h;
+   int a, c, q, l;
+   
+#define DEF_THUMB_RETURN im = evas_object_rectangle_add(evas); \
+              evas_object_color_set(im, 255, 255, 255, 255); \
+              evas_object_resize(im, width, height); \
+              return im 
+   
+   /* eap thumbnailer */
+   ext = strrchr(file, '.');
+   if(ext)
+    {
+       if(!strcasecmp(ext, ".eap"))
+       {
+          E_App *app;
+          
+          app = e_app_new(file, 0);
+          
+          if(!app)          
+           { 
+              DEF_THUMB_RETURN;
+           }
+          else
+           {
+              im = edje_object_add(evas);
+              edje_object_file_set(im, file, "icon");
+              e_object_unref(E_OBJECT(app));          
+              return im;
+           }
+       }
+    }
+     
+   /* saved thumb */
+   /* TODO: add ability to fetch thumbs from freedesktop dirs */
+   if (!e_thumb_exists(file))
+    {
+       if(!e_thumb_create(file, width, height))
+       {
+          DEF_THUMB_RETURN;
+       }
+    }
+      
+   thumb = e_thumb_file_get(file);
+   if(!thumb)
+    {
+       DEF_THUMB_RETURN;
+    }
+   
+   ef = eet_open(thumb, EET_FILE_MODE_READ);
+   if (!ef)
+    {
+       free(thumb);
+       DEF_THUMB_RETURN;
+    }
+   
+   free(thumb);
+   
+   data = eet_data_image_read(ef, "/thumbnail/data", &w, &h, &a, &c, &q, &l);
+   if (data)
+    {
+       im = evas_object_image_add(evas);
+       evas_object_image_alpha_set(im, 0);
+       evas_object_image_size_set(im, w, h);
+       evas_object_image_smooth_scale_set(im, 0);
+       evas_object_image_data_copy_set(im, data);
+       evas_object_image_data_update_add(im, 0, 0, w, h);
+       evas_object_image_fill_set(im, 0, 0, w, h);
+       evas_object_resize(im, w, h);
+       free(data);
+    }
+   else
+    {
+       DEF_THUMB_RETURN;
+    }
+   
+   eet_close(ef);
+   return im;
+}
+
+static char *
+_e_thumb_file_id(char *file)
+{
+   char                s[256];
+   const char         *chmap =
+     "0123456789abcdefghijklmnopqrstuvwxyz\80\81\82\83\84\85\86\87\88\8a\8b\8c\8d\8e\8f\90\91\92\93\9d-_";
+   int                 id[2];
+   struct stat         st;
+
+   if (stat(file, &st) < 0)
+     return NULL;
+   
+   id[0] = (int)st.st_ino;
+   id[1] = (int)st.st_dev;
+
+   sprintf(s,
+          "%c%c%c%c%c%c"
+          "%c%c%c%c%c%c",
+          chmap[(id[0] >> 0) & 0x3f],
+          chmap[(id[0] >> 6) & 0x3f],
+          chmap[(id[0] >> 12) & 0x3f],
+          chmap[(id[0] >> 18) & 0x3f],
+          chmap[(id[0] >> 24) & 0x3f],
+          chmap[(id[0] >> 28) & 0x3f],
+          chmap[(id[1] >> 0) & 0x3f],
+          chmap[(id[1] >> 6) & 0x3f],
+          chmap[(id[1] >> 12) & 0x3f],
+          chmap[(id[1] >> 18) & 0x3f],
+          chmap[(id[1] >> 24) & 0x3f], chmap[(id[1] >> 28) & 0x3f]);
+
+   return strdup(s);
+}
diff --git a/src/bin/e_thumb.h b/src/bin/e_thumb.h
new file mode 100644 (file)
index 0000000..b466ce1
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
+ */
+#ifdef E_TYPEDEFS
+
+#else
+#ifndef E_THUMB_H
+#define E_THUMB_H
+
+
+EAPI int                   e_thumb_init(void);
+EAPI int                   e_thumb_shutdown(void);
+EAPI char                 *e_thumb_dir_get(void);
+EAPI char                 *e_thumb_file_get(char *file);
+EAPI int                   e_thumb_exists(char *file);
+EAPI int                   e_thumb_create(char *file, Evas_Coord w, Evas_Coord h);
+EAPI Evas_Object          *e_thumb_evas_object_get(char *file, Evas *evas, Evas_Coord width, Evas_Coord height);
+
+#endif
+#endif