diff --git a/src/bin/e_fileman_icon.c b/src/bin/e_fileman_icon.c index 8fb6a60be..fb9308711 100644 --- a/src/bin/e_fileman_icon.c +++ b/src/bin/e_fileman_icon.c @@ -42,7 +42,7 @@ static void _e_fm_icon_smart_clip_unset (Evas_Object *obj); /* Create icons */ static void _e_fm_icon_icon_mime_get(E_Smart_Data *sd); -static void _e_fm_icon_thumb_job_generate(void *data); +static void _e_fm_icon_thumb_generate(void); static int _e_fm_icon_thumb_cb_exe_exit(void *data, int type, void *event); /* local subsystem globals */ @@ -50,7 +50,6 @@ static Evas_Smart *e_smart = NULL; static pid_t pid = -1; static Evas_List *thumb_files = NULL; -static Ecore_Job *thumb_job = NULL; static Evas_List *event_handlers = NULL; @@ -345,8 +344,7 @@ _e_fm_icon_smart_show(Evas_Object *obj) else { thumb_files = evas_list_append(thumb_files, sd); - if (thumb_job) ecore_job_del(thumb_job); - thumb_job = ecore_job_add(_e_fm_icon_thumb_job_generate, NULL); + if (pid == -1) _e_fm_icon_thumb_generate(); _e_fm_icon_icon_mime_get(sd); } } @@ -460,67 +458,46 @@ _e_fm_icon_icon_mime_get(E_Smart_Data *sd) } static void -_e_fm_icon_thumb_job_generate(void *data) +_e_fm_icon_thumb_generate(void) { - if ((!thumb_files) || (pid != -1))return; + E_Smart_Data *sd; + + if ((!thumb_files) || (pid != -1)) return; pid = fork(); - thumb_job = NULL; - if (pid == 0) - { - /* child */ - Evas_List *l; - for (l = thumb_files; l; l = l->next) - { - E_Smart_Data *sd; - sd = l->data; - if(!e_thumb_exists(sd->file->path)) - e_thumb_create(sd->file->path, sd->w, sd->h); - } + { + sd = thumb_files->data; + if (!e_thumb_exists(sd->file->path)) + e_thumb_create(sd->file->path, 48, 48); // thumbnail size exit(0); - } + } } static int _e_fm_icon_thumb_cb_exe_exit(void *data, int type, void *event) { Ecore_Event_Exe_Exit *ev; - Evas_List *l; + E_Smart_Data *sd; ev = event; if (ev->pid != pid) return 1; - for (l = thumb_files; l;) + if (!thumb_files) return 1; + + sd = thumb_files->data; + thumb_files = evas_list_remove_list(thumb_files, thumb_files); + + if (ecore_file_exists(sd->thumb_path)) { - E_Smart_Data *sd; - - sd = l->data; - if (ecore_file_exists(sd->thumb_path)) - { - Evas_List *tmp; - if (sd->image_object) evas_object_del(sd->image_object); - sd->image_object = NULL; - sd->image_object = e_thumb_evas_object_get(sd->file->path, - sd->evas, - sd->w, sd->h); - edje_object_part_swallow(sd->icon_object, "icon_swallow", - sd->image_object); - tmp = l; - l = l->next; - thumb_files = evas_list_remove_list(thumb_files, tmp); - } - else - { - l = l->next; - } + if (sd->image_object) evas_object_del(sd->image_object); + sd->image_object = e_thumb_evas_object_get(sd->file->path, + sd->evas, + sd->w, sd->h); + edje_object_part_swallow(sd->icon_object, "icon_swallow", + sd->image_object); } pid = -1; - if (thumb_files) - { - if (thumb_job) ecore_job_del(thumb_job); - thumb_job = ecore_job_add(_e_fm_icon_thumb_job_generate, NULL); - } - + _e_fm_icon_thumb_generate(); return 1; } diff --git a/src/bin/e_icon.c b/src/bin/e_icon.c index 079243134..437358942 100644 --- a/src/bin/e_icon.c +++ b/src/bin/e_icon.c @@ -52,6 +52,17 @@ e_icon_file_set(Evas_Object *obj, const char *file) _e_icon_smart_reconfigure(sd); } +void +e_icon_file_key_set(Evas_Object *obj, const char *file, const char *key) +{ + E_Smart_Data *sd; + + sd = evas_object_smart_data_get(obj); + /* smart code here */ + evas_object_image_file_set(sd->obj, file, key); + _e_icon_smart_reconfigure(sd); +} + const char * e_icon_file_get(Evas_Object *obj) { diff --git a/src/bin/e_icon.h b/src/bin/e_icon.h index 64f592450..71f0fb749 100644 --- a/src/bin/e_icon.h +++ b/src/bin/e_icon.h @@ -8,6 +8,7 @@ EAPI Evas_Object *e_icon_add (Evas *evas); EAPI void e_icon_file_set (Evas_Object *obj, const char *file); +EAPI void e_icon_file_key_set (Evas_Object *obj, const char *file, const char *key); EAPI const char *e_icon_file_get (Evas_Object *obj); EAPI void e_icon_smooth_scale_set (Evas_Object *obj, int smooth); EAPI int e_icon_smooth_scale_get (Evas_Object *obj); diff --git a/src/bin/e_thumb.c b/src/bin/e_thumb.c index 0f9cd765e..d71f2fcf0 100644 --- a/src/bin/e_thumb.c +++ b/src/bin/e_thumb.c @@ -78,19 +78,24 @@ e_thumb_create(char *file, Evas_Coord w, Evas_Coord h) char *thumbpath; Evas_Object *im; const int *data; - int size; + int size, iw, ih, ww, hh; Ecore_Evas *buf; Evas *evasbuf; + int alpha; thumbpath = e_thumb_file_get(file); - if(!thumbpath) { free(thumbpath); return -1; } + if (!thumbpath) + { + free(thumbpath); + return -1; + } ef = eet_open(thumbpath, EET_FILE_MODE_WRITE); if (!ef) - { - free(thumbpath); - return -1; - } + { + free(thumbpath); + return -1; + } free(thumbpath); @@ -98,20 +103,32 @@ e_thumb_create(char *file, Evas_Coord w, Evas_Coord 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); + iw = 0; ih = 0; + evas_object_image_size_get(im, &iw, &ih); + alpha = evas_object_image_alpha_get(im); + ww = w; + hh = (w * ih) / iw; + if (hh > h) + { + hh = h; + ww = (h * iw) / ih; + } + ecore_evas_resize(buf, ww, hh); + evas_object_image_fill_set(im, 0, 0, ww, hh); + evas_object_resize(im, ww, hh); 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) + eet_write(ef, "/thumbnail/orig_path", file, strlen(file), 1); + if ((size = eet_data_image_write(ef, "/thumbnail/data", + (void *)data, ww, hh, alpha, + 0, 91, 1)) <= 0) { - printf("e_thumb: BUG: Couldn't write thumb db\n"); eet_close(ef); return -1; } - + evas_object_del(im); eet_close(ef); - ecore_evas_free(buf); return 1; } @@ -159,47 +176,32 @@ e_thumb_evas_object_get(char *file, Evas *evas, Evas_Coord width, Evas_Coord hei /* 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; - } - } - + { + if (!e_thumb_create(file, width, height)) + { + DEF_THUMB_RETURN; + } + } + thumb = e_thumb_file_get(file); - if(!thumb) - { - DEF_THUMB_RETURN; - } + if (!thumb) + { + DEF_THUMB_RETURN; + } ef = eet_open(thumb, EET_FILE_MODE_READ); if (!ef) - { - free(thumb); - DEF_THUMB_RETURN; - } + { + eet_close(ef); + free(thumb); + DEF_THUMB_RETURN; + } + + im = e_icon_add(evas); + e_icon_file_key_set(im, thumb, "/thumbnail/data"); + e_icon_fill_inside_set(im, 1); 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, 1); - 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; } @@ -207,10 +209,13 @@ e_thumb_evas_object_get(char *file, Evas *evas, Evas_Coord width, Evas_Coord hei static char * _e_thumb_file_id(char *file) { - char s[256]; + char s[256], *sp; const char *chmap = - "0123456789abcdefghijklmnopqrstuvwxyz€‚ƒ„…†‡ˆŠ‹ŒŽ‘’“-_"; - int id[2]; + "0123456789abcdef" + "ghijklmnopqrstuv" + "wxyz`~!@#$%^&*()" + "[];',.{}<>?-=_+|"; + unsigned int id[6], i; struct stat st; if (stat(file, &st) < 0) @@ -218,21 +223,28 @@ _e_thumb_file_id(char *file) id[0] = (int)st.st_ino; id[1] = (int)st.st_dev; + id[2] = (int)(st.st_size & 0xffffffff); + id[3] = (int)((st.st_size >> 32) & 0xffffffff); + id[4] = (int)(st.st_mtime & 0xffffffff); + id[5] = (int)((st.st_mtime >> 32) & 0xffffffff); - 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]); - + sp = s; + for (i = 0; i < 6; i++) + { + unsigned int t, tt; + int j; + + t = id[i]; + j = 32; + while (j > 0) + { + tt = t & ((1 << 6) - 1); + *sp = chmap[tt]; + t >>= 6; + j -= 6; + sp++; + } + } + *sp = 0; return strdup(s); }