From b66db644f15406e8c98d7cb37e840ff92d232219 Mon Sep 17 00:00:00 2001 From: codewarrior Date: Sat, 22 Oct 2005 17:02:37 +0000 Subject: [PATCH] - modularize e_fm_file thumb determination scheme - add thumb functions for: * e17 themes (thanks Chady) * e17 bg files * eap * jpg/png - add scrolling support (must be calculated, currently is absolute) SVN revision: 17776 --- src/bin/e_fileman.c | 49 +++++++++++-- src/bin/e_fileman_file.c | 115 +++++++++++++++++++++++++++-- src/bin/e_fileman_file.h | 23 +++--- src/bin/e_fileman_icon.c | 2 +- src/bin/e_fileman_smart.c | 4 ++ src/bin/e_thumb.c | 180 ++++++++++++++++++++++++++++++++++++++++------ 6 files changed, 334 insertions(+), 39 deletions(-) diff --git a/src/bin/e_fileman.c b/src/bin/e_fileman.c index 0e004a0..ee61997 100644 --- a/src/bin/e_fileman.c +++ b/src/bin/e_fileman.c @@ -19,8 +19,9 @@ #endif static void _e_fileman_vscrollbar_drag_cb(Evas_Object *object, double value, void *data); -static void _e_fileman_reconf_cb(void *data, int type, void *event); -static void _e_fileman_dir_change_cb(void *data, int type, void *event); +static int _e_fileman_reconf_cb(void *data, int type, void *event); +static int _e_fileman_dir_change_cb(void *data, int type, void *event); +static int _e_fileman_mouse_wheel_cb(void *data, int type, void *event); static void _e_fileman_resize_cb(E_Win *win); static void _e_fileman_delete_cb(E_Win *win); static void _e_fileman_vscrollbar_show_cb(void *data, Evas_Object *obj, void *ev); @@ -100,6 +101,11 @@ e_fileman_new(E_Container *con) _e_fileman_dir_change_cb, fileman)); + fileman->event_handlers = evas_list_append(fileman->event_handlers, + ecore_event_handler_add(ECORE_X_EVENT_MOUSE_WHEEL, + _e_fileman_mouse_wheel_cb, + fileman)); + evas_event_thaw(fileman->evas); D(("e_fileman_new: ok\n")); @@ -194,7 +200,7 @@ _e_fileman_vscrollbar_drag_cb(Evas_Object *object, double value, void *data) e_fm_scroll_vertical(fileman->smart, value); } -static void +static int _e_fileman_reconf_cb(void *data, int type, void *event) { E_Event_Fm_Reconfigure *ev; @@ -222,10 +228,11 @@ _e_fileman_reconf_cb(void *data, int type, void *event) D(("e_fileman_reconf_cb: hide (%p)\n", fileman)); edje_object_part_unswallow(fileman->main, fileman->vscrollbar); evas_object_hide(fileman->vscrollbar); - } + } + return 1; } -static void +static int _e_fileman_dir_change_cb(void *data, int type, void *event) { E_Event_Fm_Directory_Change *ev; @@ -239,6 +246,38 @@ _e_fileman_dir_change_cb(void *data, int type, void *event) D(("_e_fileman_dir_change_cb:\n")); e_scrollbar_value_set(fileman->vscrollbar, 0.0); + return 1; +} + +static int +_e_fileman_mouse_wheel_cb(void *data, int type, void *event) +{ + Ecore_X_Event_Mouse_Wheel *ev; + E_Fileman *fileman; + double pos; + + ev = event; + fileman = data; + + pos = e_scrollbar_value_get(fileman->vscrollbar); + + if(ev->z < 0) + { + pos -= 0.05; + if(pos < 0.0) + pos = 0.0; + } + + if(ev->z > 0) + { + pos += 0.05; + if(pos > 1.0) + pos = 1.0; + } + + e_scrollbar_value_set(fileman->vscrollbar, pos); + e_fm_scroll_vertical(fileman->smart, pos); + return 1; } static void diff --git a/src/bin/e_fileman_file.c b/src/bin/e_fileman_file.c index 9a6daf0..b36c993 100644 --- a/src/bin/e_fileman_file.c +++ b/src/bin/e_fileman_file.c @@ -53,6 +53,12 @@ e_fm_file_new(const char *filename) if (file->name[0] == '.') file->type |= E_FM_FILE_TYPE_HIDDEN; + file->preview_funcs = E_NEW(E_Fm_File_Preview_Function, 4); + file->preview_funcs[0] = e_fm_file_is_image; + file->preview_funcs[1] = e_fm_file_is_etheme; + file->preview_funcs[2] = e_fm_file_is_ebg; + file->preview_funcs[3] = e_fm_file_is_eap; + D(("e_fm_file_new: %s\n", filename)); return file; @@ -131,6 +137,22 @@ e_fm_file_copy(E_Fm_File *file, const char *name) } int +e_fm_file_can_preview(E_Fm_File *file) +{ + int i; + + D(("e_fm_file_can_preview: (%s) (%p)\n", file->name, file)); + for (i = 0; i < sizeof(file->preview_funcs); i++) + { + E_Fm_File_Preview_Function func; + func = file->preview_funcs[i]; + if(func(file)) + return 1; + } + return 0; +} + +int e_fm_file_is_image(E_Fm_File *file) { /* We need to check if it is a filetype supported by evas. @@ -138,15 +160,99 @@ e_fm_file_is_image(E_Fm_File *file) * canvas. */ char *ext; + + if ((file->type != E_FM_FILE_TYPE_FILE) && (file->type != E_FM_FILE_TYPE_SYMLINK)) return 0; + + ext = strrchr(file->name, '.'); + if (!ext) return 0; - if ((file->type != E_FM_FILE_TYPE_FILE) && (file->type != E_FM_FILE_TYPE_SYMLINK)) return 0; + D(("e_fm_file_is_image: (%p)\n", file)); + return (!strcasecmp(ext, ".jpg")) || (!strcasecmp(ext, ".png")) + || (!strcasecmp(ext, ".jpeg")); +} +int +e_fm_file_is_etheme(E_Fm_File *file) +{ + int val; + char *ext; + Evas_List *groups, *l; + + if ((file->type != E_FM_FILE_TYPE_FILE) && (file->type != E_FM_FILE_TYPE_SYMLINK)) return 0; + ext = strrchr(file->name, '.'); if (!ext) return 0; - D(("e_fm_file_is_image: (%p)\n", file)); - return (!strcasecmp(ext, ".jpg")) || (!strcasecmp(ext, ".png")) - || (!strcasecmp(ext, ".jpeg")) || (!strcasecmp(ext, ".eap")); + if(strcasecmp(ext, ".edj")) + return 0; + + val = 0; + groups = edje_file_collection_list(file->path); + if(!groups) + return 0; + + for (l = groups; l; l = l->next) + if(!strcmp(l->data, "widgets/border/default/border")) + { + val = 1; + break; + } + edje_file_collection_list_free(groups); + return val; +} + +int +e_fm_file_is_ebg(E_Fm_File *file) +{ + int val; + char *ext; + Evas_List *groups, *l; + + if ((file->type != E_FM_FILE_TYPE_FILE) && (file->type != E_FM_FILE_TYPE_SYMLINK)) return 0; + + ext = strrchr(file->name, '.'); + if (!ext) return 0; + + if(strcasecmp(ext, ".edj")) + return 0; + + val = 0; + groups = edje_file_collection_list(file->path); + if(!groups) + return 0; + + for (l = groups; l; l = l->next) + if(!strcmp(l->data, "desktop/background")) + { + val = 1; + break; + } + edje_file_collection_list_free(groups); + return val; +} + +int +e_fm_file_is_eap(E_Fm_File *file) +{ + char *ext; + E_App *app; + + if ((file->type != E_FM_FILE_TYPE_FILE) && (file->type != E_FM_FILE_TYPE_SYMLINK)) return 0; + + ext = strrchr(file->name, '.'); + if (!ext) return 0; + + if(strcasecmp(ext, ".eap")) + return 0; + + app = e_app_new(file->path, 0); + if(!app) + { + e_object_unref(E_OBJECT(app)); + return 0; + } + e_object_unref(E_OBJECT(app)); + return 1; } int @@ -226,6 +332,7 @@ static void _e_fm_file_free(E_Fm_File *file) { D(("_e_fm_file_free: (%p) (%s)\n", file, file->name)); + free(file->preview_funcs); if (file->path) free(file->path); if (file->name) free(file->name); free(file); diff --git a/src/bin/e_fileman_file.h b/src/bin/e_fileman_file.h index 9450b39..2bae0f0 100644 --- a/src/bin/e_fileman_file.h +++ b/src/bin/e_fileman_file.h @@ -5,6 +5,7 @@ typedef struct _E_Fm_File E_Fm_File; typedef struct _E_Fm_File_Attributes E_Fm_File_Attributes; +typedef int(*E_Fm_File_Preview_Function) (E_Fm_File*); #define E_FM_FILE_TYPE_FILE (1 << 8) #define E_FM_FILE_TYPE_DIRECTORY (1 << 9) @@ -48,16 +49,22 @@ struct _E_Fm_File time_t atime; /* time of last access */ time_t mtime; /* time of last modification */ time_t ctime; /* time of last status change */ + + E_Fm_File_Preview_Function *preview_funcs; }; -EAPI E_Fm_File *e_fm_file_new (const char *filename); -EAPI int e_fm_file_rename (E_Fm_File *file, const char *name); -EAPI int e_fm_file_delete (E_Fm_File *file); -EAPI int e_fm_file_copy (E_Fm_File *file, const char *name); -EAPI int e_fm_file_is_image (E_Fm_File *file); -EAPI int e_fm_file_exec (E_Fm_File *file); -EAPI int e_fm_file_assoc_set (E_Fm_File *file, const char *assoc); -EAPI int e_fm_file_assoc_exec (E_Fm_File *file); +EAPI E_Fm_File *e_fm_file_new (const char *filename); +EAPI int e_fm_file_rename (E_Fm_File *file, const char *name); +EAPI int e_fm_file_delete (E_Fm_File *file); +EAPI int e_fm_file_copy (E_Fm_File *file, const char *name); +EAPI int e_fm_file_can_preview (E_Fm_File *file); +EAPI int e_fm_file_is_image (E_Fm_File *file); +EAPI int e_fm_file_is_etheme (E_Fm_File *file); +EAPI int e_fm_file_is_ebg (E_Fm_File *file); +EAPI int e_fm_file_is_eap (E_Fm_File *file); +EAPI int e_fm_file_exec (E_Fm_File *file); +EAPI int e_fm_file_assoc_set (E_Fm_File *file, const char *assoc); +EAPI int e_fm_file_assoc_exec (E_Fm_File *file); #endif #endif diff --git a/src/bin/e_fileman_icon.c b/src/bin/e_fileman_icon.c index 998a429..91e009b 100644 --- a/src/bin/e_fileman_icon.c +++ b/src/bin/e_fileman_icon.c @@ -333,7 +333,7 @@ _e_fm_icon_smart_show(Evas_Object *obj) "fileman/icon"); evas_object_smart_member_add(sd->icon_object, obj); - if (e_fm_file_is_image(sd->file)) + if (e_fm_file_can_preview(sd->file)) { sd->thumb_path = e_thumb_file_get(sd->file->path); if (e_thumb_exists(sd->file->path)) diff --git a/src/bin/e_fileman_smart.c b/src/bin/e_fileman_smart.c index 3119b28..3dbce7b 100644 --- a/src/bin/e_fileman_smart.c +++ b/src/bin/e_fileman_smart.c @@ -903,6 +903,7 @@ _e_fm_file_delete_yes_cb(void *data, E_Dialog *dia) static void _e_fm_icon_prop_fill_data(E_Fm_Icon_CFData *cfdata) { + /*- BASIC -*/ if((cfdata->icon->file->mode & (S_IWUSR|S_IWGRP|S_IWOTH))) cfdata->protect = 0; else @@ -915,6 +916,9 @@ _e_fm_icon_prop_fill_data(E_Fm_Icon_CFData *cfdata) cfdata->readwrite = 1; else if(!(cfdata->icon->file->mode & (S_IRGRP|S_IROTH|S_IWGRP|S_IWOTH))) cfdata->readwrite = 2; + + /*- ADVANCED -*/ +// if((cfdata->icon->file->mode & } static void * diff --git a/src/bin/e_thumb.c b/src/bin/e_thumb.c index 540d634..c868dad 100644 --- a/src/bin/e_thumb.c +++ b/src/bin/e_thumb.c @@ -84,6 +84,151 @@ e_thumb_exists(char *file) return 0; } +int * +_e_thumb_image_create(char *file, Evas_Coord w, Evas_Coord h, int *ww, int *hh, int *alpha, Evas_Object **im, Ecore_Evas **buf) +{ + Evas *evasbuf; + int size, iw, ih; + + *buf = ecore_evas_buffer_new(1, 1); + evasbuf = ecore_evas_get(*buf); + *im = evas_object_image_add(evasbuf); + evas_object_image_file_set(*im, file, NULL); + iw = 0; ih = 0; + evas_object_image_size_get(*im, &iw, &ih); + *alpha = evas_object_image_alpha_get(im); + if ((iw > 0) && (ih > 0)) + { + *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_move(*im, 0, 0); + evas_object_show(*im); + + return ecore_evas_buffer_pixels_get(*buf); + } + return NULL; +} + +/* thumbnail an e17 background and return pixel data */ +int * +_e_thumb_ebg_create(char *file, Evas_Coord w, Evas_Coord h, int *ww, int *hh, int *alpha, Evas_Object **im, Ecore_Evas **buf) +{ + Evas *evasbuf; + Evas_Object *wallpaper; + int *pixels; + + *ww = 640; + *hh = 480; + *alpha = 0; + + w = 640; + h = 480; + + *buf = ecore_evas_buffer_new(w, h); + evasbuf = ecore_evas_get(*buf); + + wallpaper = edje_object_add(evasbuf); + + + edje_object_file_set(wallpaper, file, "desktop/background"); + + /* wallpaper */ + evas_object_move(wallpaper, 0, 0); + evas_object_resize(wallpaper, w, h); + + evas_object_show(wallpaper); + + pixels = ecore_evas_buffer_pixels_get(*buf); + + evas_object_del(wallpaper); + return pixels; +} + +/* thumbnail an e17 theme and return pixel data */ +int * +_e_thumb_etheme_create(char *file, Evas_Coord w, Evas_Coord h, int *ww, int *hh, int *alpha, Evas_Object **im, Ecore_Evas **buf) +{ + Evas *evasbuf; + Evas_Object *wallpaper, *window, *clock, *start, **pager; + int *pixels; + + *ww = 640; + *hh = 480; + *alpha = 0; + + w = 640; + h = 480; + + *buf = ecore_evas_buffer_new(w, h); + evasbuf = ecore_evas_get(*buf); + + wallpaper = edje_object_add(evasbuf); + window = edje_object_add(evasbuf); + clock = edje_object_add(evasbuf); + start = edje_object_add(evasbuf); + pager = E_NEW(Evas_Object*, 3); + pager[0] = edje_object_add(evasbuf); + pager[1] = edje_object_add(evasbuf); + pager[2] = edje_object_add(evasbuf); + + edje_object_file_set(wallpaper, file, "desktop/background"); + edje_object_file_set(window, file, "widgets/border/default/border"); + edje_object_file_set(clock, file, "modules/clock/main"); + edje_object_file_set(clock, file, "modules/clock/main"); + edje_object_file_set(start, file, "modules/start/main"); + edje_object_file_set(pager[0], file, "modules/pager/main"); + edje_object_file_set(pager[1], file, "modules/pager/desk"); + edje_object_file_set(pager[2], file, "modules/pager/window"); + edje_object_part_text_set(window, "title_text", file); + edje_object_part_swallow(pager[0], "items", pager[1]); + edje_object_part_swallow(pager[1], "items", pager[2]); + + /* wallpaper */ + evas_object_move(wallpaper, 0, 0); + evas_object_resize(wallpaper, w, h); + /* main window */ + evas_object_move(window, (w * 0.1), (h * 0.05)); + evas_object_resize(window, w * 0.8, h * 0.75); + /* clock */ + evas_object_move(clock, (w * 0.9), (h * 0.9)); + evas_object_resize(clock, w * 0.1, h * 0.1); + /* start */ + evas_object_move(start, (w * 0.9), (h * 0.9)); + evas_object_resize(start, w * 0.1, h * 0.1); + /* pager */ + evas_object_move(pager[0], (w * 0.3), (h * 0.9)); + evas_object_resize(pager[0], w * 0.1, h * 0.1); + + evas_object_show(wallpaper); + evas_object_show(window); + evas_object_show(clock); + evas_object_show(start); + evas_object_show(pager[0]); + evas_object_show(pager[1]); + evas_object_show(pager[2]); + + pixels = ecore_evas_buffer_pixels_get(*buf); + + evas_object_del(wallpaper); + evas_object_del(window); + evas_object_del(clock); + evas_object_del(start); + evas_object_del(pager[0]); + evas_object_del(pager[1]); + evas_object_del(pager[2]); + free(pager); + + return pixels; +} + /* create and save a thumb to disk */ int e_thumb_create(char *file, Evas_Coord w, Evas_Coord h) @@ -111,14 +256,20 @@ e_thumb_create(char *file, Evas_Coord w, Evas_Coord h) return -1; } - buf = ecore_evas_buffer_new(1, 1); - evasbuf = ecore_evas_get(buf); - im = evas_object_image_add(evasbuf); - evas_object_image_file_set(im, file, NULL); - iw = 0; ih = 0; - evas_object_image_size_get(im, &iw, &ih); - alpha = evas_object_image_alpha_get(im); - if ((iw > 0) && (ih > 0)) + if(ext) + { + if(!strcasecmp(ext, ".edj")) + { + /* for now, this function does both the bg and theme previews */ + data = _e_thumb_etheme_create(file, w, h, &ww, &hh, &alpha, &im, &buf); + } + else + data = _e_thumb_image_create(file, w, h, &ww, &hh, &alpha, &im, &buf); + } + else + data = _e_thumb_image_create(file, w, h, &ww, &hh, &alpha, &im, &buf); + + if (data) { ef = eet_open(thumbpath, EET_FILE_MODE_WRITE); if (!ef) @@ -129,19 +280,6 @@ e_thumb_create(char *file, Evas_Coord w, Evas_Coord h) return -1; } free(thumbpath); - - 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); eet_write(ef, "/thumbnail/orig_path", file, strlen(file), 1); if ((size = eet_data_image_write(ef, "/thumbnail/data", -- 2.7.4