From 362047fe2459b637a422e4aa7e7db5a06024c296 Mon Sep 17 00:00:00 2001 From: titan Date: Tue, 22 Feb 2011 01:55:08 +0000 Subject: [PATCH] Speed up the ephoto thumb browser by a lot... Thanks k-s for some old cold that helped :) SVN revision: 57227 --- src/bin/ephoto.c | 37 +++---- src/bin/ephoto.h | 81 +++++++++----- src/bin/ephoto_flow_browser.c | 153 ++++++++++++------------- src/bin/ephoto_main.c | 197 ++++++++++++++++++++++++++++----- src/bin/ephoto_slideshow.c | 78 ++++++++----- src/bin/ephoto_thumb_browser.c | 195 ++++++++++++++++++++++++++------ 6 files changed, 534 insertions(+), 207 deletions(-) diff --git a/src/bin/ephoto.c b/src/bin/ephoto.c index a7898c8..24171f0 100644 --- a/src/bin/ephoto.c +++ b/src/bin/ephoto.c @@ -3,7 +3,6 @@ #ifndef ELM_LIB_QUICKLAUNCH static void _ephoto_display_usage(void); -Ephoto *ephoto; EAPI int elm_main(int argc, char **argv) @@ -25,9 +24,6 @@ elm_main(int argc, char **argv) elm_theme_extension_add(NULL, PACKAGE_DATA_DIR "/themes/default/ephoto.edj"); - if (!efreet_mime_init()) - printf("Ephoto could not init efreet_mime!\n"); - client = elm_thumb_ethumb_client_get(); if (!client) { @@ -41,9 +37,6 @@ elm_main(int argc, char **argv) elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED); - ephoto = calloc(1, sizeof(Ephoto)); - ephoto->client = client; - if (argc > 2) { printf("Too many arguments; Terminating...\n"); @@ -51,7 +44,7 @@ elm_main(int argc, char **argv) r = 1; goto end; } - if (argc == 2) + else if (argc == 2) { if (!strncmp(argv[1], "--help", 6) || !strncmp(argv[1], "-h", 2)) { @@ -59,7 +52,7 @@ elm_main(int argc, char **argv) r = 0; goto end; } - else if (argc == 2) + else { char *real = ecore_file_realpath(argv[1]); if (!real) @@ -68,27 +61,27 @@ elm_main(int argc, char **argv) r = 1; goto end; } - if (ecore_file_is_dir(real)) - ephoto->directory = eina_stringshare_add(real); - else if (ecore_file_exists(real)) - ephoto->file = eina_stringshare_add(real); - free(real); + if (!ephoto_window_add(real)) + { + printf("Could not create the main window; Terminating...\n"); + goto end; + r = 1; + } } } - - if (!ephoto_window_add()) + else { - printf("Could not create the main window; Terminating...\n"); - r = 1; - goto end; + if (!ephoto_window_add(NULL)) + { + printf("Could not create the main window; Terminating...\n"); + r = 1; + goto end; + } } elm_run(); end: - if (ephoto) - free(ephoto); - efreet_mime_shutdown(); elm_shutdown(); eio_shutdown(); diff --git a/src/bin/ephoto.h b/src/bin/ephoto.h index 54e8395..d06905c 100644 --- a/src/bin/ephoto.h +++ b/src/bin/ephoto.h @@ -24,30 +24,10 @@ /*Ephoto Typedefs*/ typedef struct _Ephoto Ephoto; +typedef struct _Ephoto_Entry Ephoto_Entry; +typedef struct _Ephoto_Event_Entry_Create Ephoto_Event_Entry_Create; typedef enum _Ephoto_State Ephoto_State; -/*Main Functions*/ -Evas_Object *ephoto_window_add(void); -void ephoto_populate(void); -void ephoto_title_set(const char *title); -void ephoto_thumb_size_set(int size); -void ephoto_directory_set(const char *path); - -/*Main Children*/ -Evas_Object *ephoto_flow_browser_add(void); -void ephoto_flow_browser_image_set(void); -void ephoto_flow_browser_del(void); -void ephoto_flow_browser_show(void); - -Evas_Object *ephoto_slideshow_add(void); -void ephoto_slideshow_del(void); -void ephoto_slideshow_show(void); - -Evas_Object *ephoto_thumb_browser_add(void); -void ephoto_thumb_browser_thumb_append(Eina_List *node); -void ephoto_thumb_browser_del(void); -void ephoto_thumb_browser_show(void); - /*Ephoto States*/ enum _Ephoto_State { @@ -71,14 +51,65 @@ struct _Ephoto /*Main Variables*/ const char *directory; - const char *file; + Ecore_Job *change_dir; + Ecore_Timer *regen; Eio_File *ls; - Eina_List *images; - Eina_List *current_index; + Eina_List *entries; Ephoto_State state, prev_state; Ethumb_Client *client; }; +/*Ephoto Entry*/ +struct _Ephoto_Entry +{ + /*These variables identify each thumbnail*/ + const char *path; + const char *basename; + const char *label; + Elm_Gengrid_Item *item; + Eina_List *free_listeners; +}; + +/*Ephoto Entry Event*/ +struct _Ephoto_Event_Entry_Create +{ + Ephoto_Entry *entry; +}; + +/*Main Functions*/ +Evas_Object *ephoto_window_add(const char *path); +void ephoto_populate(const char *path); +void ephoto_title_set(const char *title); +void ephoto_state_set(Ephoto_State state); +void ephoto_flow_browser_show(Ephoto_Entry *entry); +void ephoto_slideshow_show(Ephoto_Entry *entry); +void ephoto_thumb_browser_show(Ephoto_Entry *entry); +Ephoto_Entry *ephoto_entry_new(const char *path, const char *label); +void ephoto_entry_free(Ephoto_Entry *entry); +void ephoto_entry_free_listener_add(Ephoto_Entry *entry, void (*cb)(void *data, const Ephoto_Entry *entry), const void *data); +void ephoto_entry_free_listener_del(Ephoto_Entry *entry, void (*cb)(void *data, const Ephoto_Entry *entry), const void *data); +void ephoto_entries_free(void); + +/*Main Children*/ +Evas_Object *ephoto_flow_browser_add(void); +void ephoto_flow_browser_entry_set(Ephoto_Entry *entry); +void ephoto_flow_browser_del(void); + +Evas_Object *ephoto_slideshow_add(void); +void ephoto_slideshow_entry_set(Ephoto_Entry *entry); +void ephoto_slideshow_del(void); + +Evas_Object *ephoto_thumb_browser_add(void); +void ephoto_thumb_browser_entry_set(Ephoto_Entry *entry); +void ephoto_thumb_browser_thumb_append(Eina_List *node); +void ephoto_thumb_browser_del(void); + +/*Ephoto Events*/ +extern int EPHOTO_EVENT_ENTRY_CREATE; +extern int EPHOTO_EVENT_POPULATE_START; +extern int EPHOTO_EVENT_POPULATE_END; +extern int EPHOTO_EVENT_POPULATE_ERROR; + extern Ephoto *ephoto; #endif diff --git a/src/bin/ephoto_flow_browser.c b/src/bin/ephoto_flow_browser.c index d1516b0..2519841 100644 --- a/src/bin/ephoto_flow_browser.c +++ b/src/bin/ephoto_flow_browser.c @@ -1,5 +1,6 @@ #include "ephoto.h" +static void _entry_free(void *data __UNUSED__, const Ephoto_Entry *entry __UNUSED__); static Evas_Object *_ephoto_add_image_edje(const char *swallow); static Evas_Object *_ephoto_add_image(Evas_Object *swallow); static void _ephoto_flow_done(void *data __UNUSED__, Evas_Object *o __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__); @@ -22,12 +23,15 @@ struct _Ephoto_Flow_Browser { Eina_Bool key_down; Eina_Bool mouse_wheel; + Eina_List *current_index; + Eina_List *items; Evas_Object *box; Evas_Object *layout; Evas_Object *images[5]; Evas_Object *img_edje[5]; Evas_Object *toolbar; Ephoto_Flow_State efs; + Ephoto_Entry *entry; char *swallows[5]; int flow_direct; struct { @@ -121,21 +125,28 @@ ephoto_flow_browser_add(void) void ephoto_flow_browser_image_set(void) { - Eina_List *prevv, *prev, *next, *nextt; + Eina_List *prevv, *prev, *next, *nextt; + Ephoto_Entry *pp, *p, *n, *nn, *c; int i; - prev = eina_list_prev(ephoto->current_index); + prev = eina_list_prev(efb->current_index); if (!eina_list_data_get(prev)) - prev = eina_list_last(ephoto->images); + prev = eina_list_last(efb->items); prevv = eina_list_prev(prev); if (!eina_list_data_get(prevv)) - prevv = eina_list_last(ephoto->images); - next = eina_list_next(ephoto->current_index); + prevv = eina_list_last(efb->items); + next = eina_list_next(efb->current_index); if (!eina_list_data_get(next)) - next = eina_list_nth_list(ephoto->images, 0); + next = eina_list_nth_list(efb->items, 0); nextt = eina_list_next(next); if (!eina_list_data_get(nextt)) - nextt = eina_list_nth_list(ephoto->images, 0); + nextt = eina_list_nth_list(efb->items, 0); + + pp = eina_list_data_get(prevv); + p = eina_list_data_get(prev); + c = eina_list_data_get(efb->current_index); + n = eina_list_data_get(next); + nn = eina_list_data_get(nextt); for (i = 0; i < 5; i++) { @@ -143,19 +154,19 @@ ephoto_flow_browser_image_set(void) elm_layout_content_unset(efb->img_edje[i], "image"); } - elm_thumb_file_set(efb->images[0], eina_list_data_get(prevv), NULL); + elm_thumb_file_set(efb->images[0], pp->path, NULL); elm_layout_content_set(efb->img_edje[0], "image", efb->images[0]); elm_layout_content_set(efb->layout, "offscreen_left", efb->img_edje[0]); - elm_thumb_file_set(efb->images[1], eina_list_data_get(prev), NULL); + elm_thumb_file_set(efb->images[1], p->path, NULL); elm_layout_content_set(efb->img_edje[1], "image", efb->images[1]); elm_layout_content_set(efb->layout, "left", efb->img_edje[1]); - elm_thumb_file_set(efb->images[2], eina_list_data_get(ephoto->current_index), NULL); + elm_thumb_file_set(efb->images[2], c->path, NULL); elm_layout_content_set(efb->img_edje[2], "image", efb->images[2]); elm_layout_content_set(efb->layout, "center", efb->img_edje[2]); - elm_thumb_file_set(efb->images[3], eina_list_data_get(next), NULL); + elm_thumb_file_set(efb->images[3], n->path, NULL); elm_layout_content_set(efb->img_edje[3], "image", efb->images[3]); elm_layout_content_set(efb->layout, "right", efb->img_edje[3]); - elm_thumb_file_set(efb->images[4], eina_list_data_get(nextt), NULL); + elm_thumb_file_set(efb->images[4], nn->path, NULL); elm_layout_content_set(efb->img_edje[4], "image", efb->images[4]); elm_layout_content_set(efb->layout, "offscreen_right", efb->img_edje[4]); @@ -169,6 +180,7 @@ ephoto_flow_browser_del(void) for (i = 0; i < 5; i++) evas_object_del(efb->images[i]); + eina_list_free(efb->items); evas_object_del(efb->layout); evas_object_del(efb->toolbar); evas_object_del(efb->box); @@ -176,10 +188,11 @@ ephoto_flow_browser_del(void) } void -ephoto_flow_browser_show(void) +ephoto_flow_browser_entry_set(Ephoto_Entry *entry) { - ephoto->prev_state = ephoto->state; - ephoto->state = EPHOTO_STATE_FLOW; + Eina_Bool same_file = EINA_FALSE; + Eina_List *l; + Ephoto_Entry *itr; elm_object_focus(efb->layout); if (!evas_object_key_grab(efb->box, "Escape", 0, 0, 1)) @@ -192,8 +205,45 @@ ephoto_flow_browser_show(void) printf("Couldn't grab BackSpace key\n"); if (!evas_object_key_grab(efb->box, "space", 0, 0, 1)) printf("Couldn't grab space key\n"); + + if (efb->entry) + { + ephoto_entry_free_listener_del(efb->entry, _entry_free, NULL); + if (entry && entry->path == efb->entry->path) + same_file = EINA_TRUE; + } + + efb->entry = entry; + + if (entry) + ephoto_entry_free_listener_add(entry, _entry_free, NULL); + if (!efb->entry || same_file) + { + elm_toolbar_item_disabled_set(efb->action.go_prev, EINA_TRUE); + elm_toolbar_item_disabled_set(efb->action.go_next, EINA_TRUE); + elm_toolbar_item_disabled_set(efb->action.slideshow, EINA_TRUE); + return; + } + else + { + elm_toolbar_item_disabled_set(efb->action.go_prev, EINA_FALSE); + elm_toolbar_item_disabled_set(efb->action.go_next, EINA_FALSE); + elm_toolbar_item_disabled_set(efb->action.slideshow, EINA_FALSE); + } + eina_list_free(efb->items); + efb->items = NULL; + EINA_LIST_FOREACH(ephoto->entries, l, itr) + { + efb->items = eina_list_append(efb->items, itr); + if (itr == entry) efb->current_index = eina_list_last(efb->items); + } ephoto_flow_browser_image_set(); - elm_pager_content_promote(ephoto->pager, ephoto->flow_browser); +} + +static void +_entry_free(void *data __UNUSED__, const Ephoto_Entry *entry __UNUSED__) +{ + efb->entry = NULL; } static Evas_Object * @@ -227,66 +277,25 @@ static void _ephoto_flow_done(void *data __UNUSED__, Evas_Object *o __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__) { Evas_Object *edje; - Eina_List *prevv, *prev, *next, *nextt; - int i; - - prev = eina_list_prev(ephoto->current_index); - if (!eina_list_data_get(prev)) - prev = eina_list_last(ephoto->images); - prevv = eina_list_prev(prev); - if (!eina_list_data_get(prevv)) - prevv = eina_list_last(ephoto->images); - next = eina_list_next(ephoto->current_index); - if (!eina_list_data_get(next)) - next = eina_list_nth_list(ephoto->images, 0); - nextt = eina_list_next(next); - if (!eina_list_data_get(nextt)) - nextt = eina_list_nth_list(ephoto->images, 0); edje = elm_layout_edje_get(efb->layout); edje_object_freeze(edje); - for (i = 0; i < 5; i++) - { - elm_layout_content_unset(efb->layout, efb->swallows[i]); - elm_layout_content_unset(efb->img_edje[i], "image"); - } if (efb->flow_direct == 0) { - elm_thumb_file_set(efb->images[4], eina_list_data_get(nextt), NULL); - elm_layout_content_set(efb->img_edje[4], "image", efb->images[4]); - elm_layout_content_set(efb->layout, "offscreen_right", efb->img_edje[4]); - elm_thumb_file_set(efb->images[3], eina_list_data_get(next), NULL); - elm_layout_content_set(efb->img_edje[3], "image", efb->images[3]); - elm_layout_content_set(efb->layout, "right", efb->img_edje[3]); - elm_thumb_file_set(efb->images[2], eina_list_data_get(ephoto->current_index), NULL); - elm_layout_content_set(efb->img_edje[2], "image", efb->images[2]); - elm_layout_content_set(efb->layout, "center", efb->img_edje[2]); - elm_thumb_file_set(efb->images[1], eina_list_data_get(prev), NULL); - elm_layout_content_set(efb->img_edje[1], "image", efb->images[1]); - elm_layout_content_set(efb->layout, "left", efb->img_edje[1]); - elm_thumb_file_set(efb->images[0], eina_list_data_get(prevv), NULL); - elm_layout_content_set(efb->img_edje[0], "image", efb->images[0]); - elm_layout_content_set(efb->layout, "offscreen_left", efb->img_edje[0]); + efb->current_index = eina_list_prev(efb->current_index); + if (!eina_list_data_get(efb->current_index)) + efb->current_index = eina_list_last(efb->items); + ephoto_flow_browser_image_set(); } else { - elm_thumb_file_set(efb->images[0], eina_list_data_get(prevv), NULL); - elm_layout_content_set(efb->img_edje[0], "image", efb->images[0]); - elm_layout_content_set(efb->layout, "offscreen_left", efb->img_edje[0]); - elm_thumb_file_set(efb->images[1], eina_list_data_get(prev), NULL); - elm_layout_content_set(efb->img_edje[1], "image", efb->images[1]); - elm_layout_content_set(efb->layout, "left", efb->img_edje[1]); - elm_thumb_file_set(efb->images[2], eina_list_data_get(ephoto->current_index), NULL); - elm_layout_content_set(efb->img_edje[2], "image", efb->images[2]); - elm_layout_content_set(efb->layout, "center", efb->img_edje[2]); - elm_thumb_file_set(efb->images[3], eina_list_data_get(next), NULL); - elm_layout_content_set(efb->img_edje[3], "image", efb->images[3]); - elm_layout_content_set(efb->layout, "right", efb->img_edje[3]); - elm_thumb_file_set(efb->images[4], eina_list_data_get(nextt), NULL); - elm_layout_content_set(efb->img_edje[4], "image", efb->images[4]); - elm_layout_content_set(efb->layout, "offscreen_right", efb->img_edje[4]); + efb->current_index = eina_list_next(efb->current_index); + if (!eina_list_data_get(efb->current_index)) + efb->current_index = eina_list_nth_list(efb->items, 0); + ephoto_flow_browser_image_set(); } + edje_object_signal_emit(edje, "reset", "ephoto"); edje_object_thaw(edje); @@ -308,7 +317,7 @@ _ephoto_flow_back(void *data __UNUSED__, Evas_Object *o __UNUSED__, void *event_ evas_object_key_ungrab(efb->box, "space", 0, 0); elm_object_unfocus(efb->layout); - ephoto_thumb_browser_show(); + ephoto_thumb_browser_show(efb->entry); } static void @@ -318,10 +327,6 @@ _ephoto_flow_prev(void *data __UNUSED__, Evas_Object *o __UNUSED__, void *event_ elm_toolbar_item_selected_set(efb->action.go_prev, EINA_FALSE); - ephoto->current_index = eina_list_prev(ephoto->current_index); - if (!eina_list_data_get(ephoto->current_index)) - ephoto->current_index = eina_list_last(ephoto->images); - elm_toolbar_item_disabled_set(efb->action.go_prev, EINA_TRUE); elm_toolbar_item_disabled_set(efb->action.go_next, EINA_TRUE); efb->mouse_wheel = EINA_TRUE; @@ -345,10 +350,6 @@ _ephoto_flow_next(void *data __UNUSED__, Evas_Object *o __UNUSED__, void *event_ elm_toolbar_item_selected_set(efb->action.go_next, EINA_FALSE); - ephoto->current_index = eina_list_next(ephoto->current_index); - if (!ephoto->current_index) - ephoto->current_index = eina_list_nth_list(ephoto->images, 0); - elm_toolbar_item_disabled_set(efb->action.go_prev, EINA_TRUE); elm_toolbar_item_disabled_set(efb->action.go_next, EINA_TRUE); efb->mouse_wheel = EINA_TRUE; @@ -389,7 +390,7 @@ _ephoto_show_slideshow(void *data __UNUSED__, Evas_Object *o __UNUSED__, void *e { elm_toolbar_item_selected_set(efb->action.slideshow, EINA_FALSE); - ephoto_slideshow_show(); + ephoto_slideshow_show(efb->entry); } static void diff --git a/src/bin/ephoto_main.c b/src/bin/ephoto_main.c index b612318..6eb57d0 100644 --- a/src/bin/ephoto_main.c +++ b/src/bin/ephoto_main.c @@ -1,15 +1,43 @@ #include "ephoto.h" +/*Ephoto Window Callbacks*/ static void _ephoto_window_del(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNUSED__); -static void _ephoto_thumb_populate(void); + +/*Ephoto Thumb Population Callbacks*/ +static void _ephoto_thumb_populate(void *data __UNUSED__); static Eina_Bool _ephoto_thumb_populate_filter(void *data __UNUSED__, Eio_File *handler __UNUSED__, const Eina_File_Direct_Info *info); static void _ephoto_thumb_populate_main(void *data __UNUSED__, Eio_File *handler __UNUSED__, const Eina_File_Direct_Info *info); static void _ephoto_thumb_populate_end(void *data __UNUSED__, Eio_File *handler __UNUSED__); static void _ephoto_thumb_populate_error(void *data __UNUSED__, Eio_File *handler __UNUSED__, int error); -Evas_Object * -ephoto_window_add(void) +/*Main Ephoto Structure*/ +Ephoto *ephoto; + +/*Ephoto Events*/ +int EPHOTO_EVENT_ENTRY_CREATE = 0; +int EPHOTO_EVENT_POPULATE_START = 0; +int EPHOTO_EVENT_POPULATE_END = 0; +int EPHOTO_EVENT_POPULATE_ERROR = 0; + +/*Ephoto Entry Listener*/ +typedef struct _Ephoto_Entry_Free_Listener Ephoto_Entry_Free_Listener; +struct _Ephoto_Entry_Free_Listener { + void (*cb)(void *data, const Ephoto_Entry *dead); + const void *data; +}; + +Evas_Object * +ephoto_window_add(const char *path) +{ + EPHOTO_EVENT_ENTRY_CREATE = ecore_event_type_new(); + EPHOTO_EVENT_POPULATE_START = ecore_event_type_new(); + EPHOTO_EVENT_POPULATE_END = ecore_event_type_new(); + EPHOTO_EVENT_POPULATE_ERROR = ecore_event_type_new(); + + ephoto = calloc(1, sizeof(Ephoto)); + ephoto->client = elm_thumb_ethumb_client_get(); + ephoto->win = elm_win_add(NULL, "ephoto", ELM_WIN_BASIC); if (!ephoto->win) return NULL; @@ -35,15 +63,6 @@ ephoto_window_add(void) elm_win_resize_object_add(ephoto->win, ephoto->pager); evas_object_show(ephoto->pager); - if (!ephoto->directory && !ephoto->file) - { - char buf[PATH_MAX], *cwd; - cwd = getcwd(buf, PATH_MAX); - ephoto->directory = eina_stringshare_add(cwd); - } - else if (ephoto->file) - ephoto->directory = eina_stringshare_add(ecore_file_dir_get(ephoto->file)); - ephoto->slideshow = ephoto_slideshow_add(); elm_pager_content_push(ephoto->pager, ephoto->slideshow); @@ -56,16 +75,32 @@ ephoto_window_add(void) elm_pager_content_promote(ephoto->pager, ephoto->thumb_browser); ephoto->state = EPHOTO_STATE_THUMB; - ephoto->current_index = ephoto->images; - _ephoto_thumb_populate(); + if ((!path) || (!ecore_file_exists(path))) + { + char buf[PATH_MAX]; + if (getcwd(buf, sizeof(buf))) + path = buf; + else + path = getenv("HOME"); + } + if (ecore_file_is_dir(path)) + ephoto_populate(path); + else + { + char *dir = ecore_file_dir_get(path); + ephoto_populate(dir); + free(dir); + } return ephoto->win; } void -ephoto_populate() +ephoto_populate(const char *path) { - _ephoto_thumb_populate(); + eina_stringshare_replace(&ephoto->directory, path); + if (ephoto->change_dir) ecore_job_del(ephoto->change_dir); + ephoto->change_dir = ecore_job_add(_ephoto_thumb_populate, NULL); } void @@ -74,23 +109,129 @@ ephoto_title_set(const char *title) elm_win_title_set(ephoto->win, title); } +void +ephoto_state_set(Ephoto_State state) +{ + ephoto->prev_state = ephoto->state; + ephoto->state = state; +} + +void +ephoto_thumb_browser_show(Ephoto_Entry *entry) +{ + ephoto_state_set(EPHOTO_STATE_THUMB); + ephoto_flow_browser_entry_set(NULL); + ephoto_slideshow_entry_set(NULL); + elm_pager_content_promote(ephoto->pager, ephoto->thumb_browser); + ephoto_thumb_browser_entry_set(entry); +} + +void +ephoto_flow_browser_show(Ephoto_Entry *entry) +{ + ephoto_state_set(EPHOTO_STATE_FLOW); + elm_pager_content_promote(ephoto->pager, ephoto->flow_browser); + ephoto_flow_browser_entry_set(entry); +} + +void +ephoto_slideshow_show(Ephoto_Entry *entry) +{ + ephoto_state_set(EPHOTO_STATE_SLIDESHOW); + elm_pager_content_promote(ephoto->pager, ephoto->slideshow); + ephoto_slideshow_entry_set(entry); +} + +Ephoto_Entry * +ephoto_entry_new(const char *path, const char *label) +{ + Ephoto_Entry *entry; + + entry = calloc(1, sizeof(Ephoto_Entry)); + entry->path = eina_stringshare_add(path); + entry->basename = ecore_file_file_get(entry->path); + entry->label = eina_stringshare_add(label); + + return entry; +} + +void +ephoto_entry_free(Ephoto_Entry *entry) +{ + Ephoto_Entry_Free_Listener *fl; + + EINA_LIST_FREE(entry->free_listeners, fl) + { + fl->cb((void *)fl->data, entry); + free(fl); + } + eina_stringshare_del(entry->path); + eina_stringshare_del(entry->label); + free(entry); +} + +void +ephoto_entry_free_listener_add(Ephoto_Entry *entry, void (*cb)(void *data, const Ephoto_Entry *entry), const void *data) +{ + Ephoto_Entry_Free_Listener *fl; + + fl = malloc(sizeof(Ephoto_Entry_Free_Listener)); + fl->cb = cb; + fl->data = data; + entry->free_listeners = eina_list_append(entry->free_listeners, fl); +} + +void +ephoto_entry_free_listener_del(Ephoto_Entry *entry, void (*cb)(void *data, const Ephoto_Entry *entry), const void *data) +{ + Eina_List *l; + Ephoto_Entry_Free_Listener *fl; + + EINA_LIST_FOREACH(entry->free_listeners, l, fl) + { + if ((fl->cb == cb) && (fl->data == data)) + { + entry->free_listeners = eina_list_remove_list + (entry->free_listeners, l); + break; + } + } +} + +void +ephoto_entries_free(void) +{ + Ephoto_Entry *entry; + + EINA_LIST_FREE(ephoto->entries, entry) ephoto_entry_free(entry); +} + static void _ephoto_window_del(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNUSED__) { ephoto_thumb_browser_del(); ephoto_flow_browser_del(); + ephoto_slideshow_del(); evas_object_del(ephoto->win); + if (ephoto->regen) + ecore_timer_del(ephoto->regen); + if (ephoto->directory) + eina_stringshare_del(ephoto->directory); + free(ephoto); } static void -_ephoto_thumb_populate(void) +_ephoto_thumb_populate(void *data __UNUSED__) { + ephoto->change_dir = NULL; + ephoto_entries_free(); ephoto->ls = eio_file_stat_ls(ephoto->directory, _ephoto_thumb_populate_filter, _ephoto_thumb_populate_main, _ephoto_thumb_populate_end, _ephoto_thumb_populate_error, NULL); + ecore_event_add(EPHOTO_EVENT_POPULATE_START, NULL, NULL, NULL); } static Eina_Bool @@ -114,22 +255,24 @@ _ephoto_thumb_populate_filter(void *data __UNUSED__, Eio_File *handler __UNUSED_ static void _ephoto_thumb_populate_main(void *data __UNUSED__, Eio_File *handler __UNUSED__, const Eina_File_Direct_Info *info) { - Eina_List *node; - ephoto->images = eina_list_append(ephoto->images, info->path); - node = eina_list_nth_list - (ephoto->images, (eina_list_count(ephoto->images)-1)); + Ephoto_Entry *e; + Ephoto_Event_Entry_Create *ev; - ephoto_thumb_browser_thumb_append(node); - if (ephoto->file && !strcmp(ephoto->file, info->path)) - ephoto->current_index = node; + e = ephoto_entry_new(info->path, info->path + info->name_start); + ephoto->entries = eina_list_append(ephoto->entries, e); + + ev = calloc(1, sizeof(Ephoto_Event_Entry_Create)); + ev->entry = e; + + ecore_event_add(EPHOTO_EVENT_ENTRY_CREATE, ev, NULL, NULL); } static void _ephoto_thumb_populate_end(void *data __UNUSED__, Eio_File *handler __UNUSED__) { ephoto->ls = NULL; - if (!ephoto->current_index) - ephoto->current_index = eina_list_nth_list(ephoto->images, 0); + + ecore_event_add(EPHOTO_EVENT_POPULATE_END, NULL, NULL, NULL); } static void @@ -137,5 +280,7 @@ _ephoto_thumb_populate_error(void *data __UNUSED__, Eio_File *handler __UNUSED__ { if (error) printf("Error while populating images: %s\n", strerror(error)); + ecore_event_add(EPHOTO_EVENT_POPULATE_ERROR, NULL, NULL, NULL); + _ephoto_thumb_populate_end(NULL, NULL); } diff --git a/src/bin/ephoto_slideshow.c b/src/bin/ephoto_slideshow.c index cddbe41..fea7c3a 100644 --- a/src/bin/ephoto_slideshow.c +++ b/src/bin/ephoto_slideshow.c @@ -1,63 +1,87 @@ #include "ephoto.h" +static void _entry_free(void *data __UNUSED__, const Ephoto_Entry *entry __UNUSED__); static Evas_Object *_ephoto_slideshow_item_get(void *data, Evas_Object *obj); static void _ephoto_mouse_down(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__); -static Evas_Object *slideshow; +typedef struct _Ephoto_Slideshow Ephoto_Slideshow; +struct _Ephoto_Slideshow +{ + Evas_Object *slideshow; + Ephoto_Entry *entry; +}; +static Ephoto_Slideshow *ss; + static const Elm_Slideshow_Item_Class _ephoto_item_cls = {{_ephoto_slideshow_item_get, NULL}}; Evas_Object * ephoto_slideshow_add(void) { - slideshow = elm_slideshow_add(ephoto->win); - elm_slideshow_layout_set(slideshow, "fullscreen"); - elm_slideshow_loop_set(slideshow, EINA_TRUE); - elm_slideshow_transition_set(slideshow, "fade"); - elm_slideshow_timeout_set(slideshow, 3); - evas_object_size_hint_weight_set - (slideshow, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(slideshow, EVAS_HINT_FILL, EVAS_HINT_FILL); - evas_object_event_callback_add - (slideshow, EVAS_CALLBACK_MOUSE_DOWN, _ephoto_mouse_down, NULL); + ss = calloc(1, sizeof(Ephoto_Slideshow)); - return slideshow; + ss->slideshow = elm_slideshow_add(ephoto->win); + elm_slideshow_layout_set(ss->slideshow, "fullscreen"); + elm_slideshow_loop_set(ss->slideshow, EINA_TRUE); + elm_slideshow_transition_set(ss->slideshow, "fade"); + elm_slideshow_timeout_set(ss->slideshow, 5); + evas_object_size_hint_weight_set + (ss->slideshow, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(ss->slideshow, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_event_callback_add + (ss->slideshow, EVAS_CALLBACK_MOUSE_DOWN, _ephoto_mouse_down, NULL); + + return ss->slideshow; } void ephoto_slideshow_del(void) { - evas_object_del(slideshow); + if (ss->entry) + ephoto_entry_free_listener_del(ss->entry, _entry_free, NULL); + free(ss); + evas_object_del(ss->slideshow); } void -ephoto_slideshow_show(void) +ephoto_slideshow_entry_set(Ephoto_Entry *entry) { - Eina_List *l; - const char *image; + Ephoto_Entry *itr; + Eina_List *l; - ephoto->prev_state = ephoto->state; - ephoto->state = EPHOTO_STATE_SLIDESHOW; - elm_pager_content_promote(ephoto->pager, ephoto->slideshow); + if (ss->entry) + ephoto_entry_free_listener_del(ss->entry, _entry_free, NULL); + ss->entry = entry; - elm_slideshow_clear(slideshow); + if (entry) + ephoto_entry_free_listener_add(entry, _entry_free, NULL); + + elm_slideshow_clear(ss->slideshow); + if (!entry) + return; elm_win_fullscreen_set(ephoto->win, EINA_TRUE); - EINA_LIST_FOREACH(ephoto->images, l, image) + EINA_LIST_FOREACH(ephoto->entries, l, itr) { Elm_Slideshow_Item *item; - item = elm_slideshow_item_add(slideshow, &_ephoto_item_cls, image); - if (l == ephoto->current_index) + item = elm_slideshow_item_add(ss->slideshow, &_ephoto_item_cls, itr); + if (itr == entry) elm_slideshow_show(item); } } +static void +_entry_free(void *data __UNUSED__, const Ephoto_Entry *entry __UNUSED__) +{ + ss->entry = NULL; +} + static Evas_Object *_ephoto_slideshow_item_get(void *data, Evas_Object *obj) { - const char *file = data; + Ephoto_Entry *entry = data; Evas_Object *image = elm_photo_add(obj); - elm_photo_file_set(image, file); + elm_photo_file_set(image, entry->path); elm_photo_fill_inside_set(image, EINA_TRUE); elm_object_style_set(image, "shadow"); @@ -69,7 +93,7 @@ _ephoto_mouse_down(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *o __U { elm_win_fullscreen_set(ephoto->win, EINA_FALSE); if (ephoto->prev_state == EPHOTO_STATE_THUMB) - ephoto_thumb_browser_show(); + ephoto_thumb_browser_show(ss->entry); else if (ephoto->prev_state == EPHOTO_STATE_FLOW) - ephoto_flow_browser_show(); + ephoto_flow_browser_show(ss->entry); } diff --git a/src/bin/ephoto_thumb_browser.c b/src/bin/ephoto_thumb_browser.c index fa9ab4c..95add25 100644 --- a/src/bin/ephoto_thumb_browser.c +++ b/src/bin/ephoto_thumb_browser.c @@ -5,7 +5,16 @@ #define ZOOM_MIN 128 #define ZOOM_START 192 #define ZOOM_STEP 32 +#define TODO_ITEM_MIN_BATCH 16 +static void _todo_items_free(void); +static void _grid_items_free(void); +static void _entry_item_add(Ephoto_Entry *e); +static Eina_Bool _todo_items_process(void *data __UNUSED__); +static Eina_Bool _ephoto_thumb_entry_create(void *data __UNUSED__, int type __UNUSED__, void *event); +static Eina_Bool _ephoto_thumb_populate_error(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__); +static Eina_Bool _ephoto_thumb_populate_end(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__); +static Eina_Bool _ephoto_thumb_populate_start(void *data, int type __UNUSED__, void *event __UNUSED__); static Evas_Object *_ephoto_thumbnail_icon_get(void *data, Evas_Object *obj __UNUSED__, const char *part __UNUSED__); static char *_ephoto_thumbnail_label_get(void *data, Evas_Object *obj __UNUSED__, const char *part __UNUSED__); static void _ephoto_thumbnail_del(void *data __UNUSED__, Evas_Object *obj __UNUSED__); @@ -32,6 +41,10 @@ struct _Ephoto_Thumb_Browser Evas_Object *dir_entry; Evas_Object *grid; Evas_Object *toolbar; + Eina_List *handlers; + Eina_List *todo_items; + Eina_List *grid_items; + Eio_File *ls; int thumb_size; struct { Elm_Toolbar_Item *zoom_in; @@ -39,6 +52,9 @@ struct _Ephoto_Thumb_Browser Elm_Toolbar_Item *view_flow; Elm_Toolbar_Item *slideshow; } action; + struct { + Ecore_Animator *todo_items; + } animator; }; Ephoto_Thumb_Browser *etb; @@ -105,43 +121,147 @@ ephoto_thumb_browser_add(void) evas_object_smart_callback_add(etb->grid, "clicked", _ephoto_show_flow, NULL); evas_object_show(etb->grid); + etb->handlers = eina_list_append + (etb->handlers, ecore_event_handler_add + (EPHOTO_EVENT_POPULATE_START, _ephoto_thumb_populate_start, NULL)); + + + etb->handlers = eina_list_append + (etb->handlers, ecore_event_handler_add + (EPHOTO_EVENT_POPULATE_END, _ephoto_thumb_populate_end, NULL)); + + etb->handlers = eina_list_append + (etb->handlers, ecore_event_handler_add + (EPHOTO_EVENT_POPULATE_ERROR, _ephoto_thumb_populate_error, NULL)); + + etb->handlers = eina_list_append + (etb->handlers, ecore_event_handler_add + (EPHOTO_EVENT_ENTRY_CREATE, _ephoto_thumb_entry_create, NULL)); + return etb->box; } +void +ephoto_thumb_browser_entry_set(Ephoto_Entry *entry) +{ + if ((entry) && (entry->item)) + elm_gengrid_item_bring_in(entry->item); +} + void ephoto_thumb_browser_del(void) { + Ecore_Event_Handler *handler; + evas_object_del(etb->box); + _todo_items_free(); + _grid_items_free(); + EINA_LIST_FREE(etb->handlers, handler) + ecore_event_handler_del(handler); + if (etb->animator.todo_items) + { + ecore_animator_del(etb->animator.todo_items); + etb->animator.todo_items = NULL; + } + if (etb->ls) + { + eio_file_cancel(etb->ls); + return; + } free(etb); } -void -ephoto_thumb_browser_show(void) +static void +_todo_items_free() { - ephoto->prev_state = ephoto->state; - ephoto->state = EPHOTO_STATE_THUMB; - - elm_pager_content_promote(ephoto->pager, ephoto->thumb_browser); - elm_object_focus(etb->grid); + eina_list_free(etb->todo_items); + etb->todo_items = NULL; } -void -ephoto_thumb_browser_thumb_append(Eina_List *node) +static void +_grid_items_free() { - Elm_Gengrid_Item *egi; - const Elm_Gengrid_Item_Class *egic; + eina_list_free(etb->grid_items); + etb->grid_items = NULL; +} - egic = &_ephoto_thumbnail_class; - egi = elm_gengrid_item_append(etb->grid, egic, node, NULL, NULL); - elm_gengrid_item_data_set(egi, node); +static void +_entry_item_add(Ephoto_Entry *e) +{ + const Elm_Gengrid_Item_Class *ic = &_ephoto_thumbnail_class; + + e->item = elm_gengrid_item_append(etb->grid, ic, e, NULL, NULL); + etb->grid_items = eina_list_append(etb->grid_items, e->item); + + if (e->item) + elm_gengrid_item_data_set(e->item, e); + else + ephoto_entry_free(e); +} + +static Eina_Bool +_todo_items_process(void *data __UNUSED__) +{ + Ephoto_Entry *entry; + + if ((etb->ls) && (eina_list_count(etb->todo_items) < TODO_ITEM_MIN_BATCH)) + return EINA_TRUE; + etb->animator.todo_items = NULL; + + EINA_LIST_FREE(etb->todo_items, entry) + _entry_item_add(entry); + return EINA_FALSE; +} + +static Eina_Bool +_ephoto_thumb_populate_start(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__) +{ + _todo_items_free(); + _grid_items_free(); + elm_gengrid_clear(etb->grid); + elm_fileselector_entry_path_set(etb->dir_entry, ephoto->directory); + + return ECORE_CALLBACK_PASS_ON; +} + +static Eina_Bool +_ephoto_thumb_populate_end(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__) +{ + etb->ls = NULL; + + return ECORE_CALLBACK_PASS_ON; +} + +static Eina_Bool +_ephoto_thumb_populate_error(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__) +{ + return ECORE_CALLBACK_PASS_ON; +} + +static Eina_Bool +_ephoto_thumb_entry_create(void *data __UNUSED__, int type __UNUSED__, void *event) +{ + Ephoto_Event_Entry_Create *ev = event; + Ephoto_Entry *e; + + e = ev->entry; + etb->todo_items = eina_list_append(etb->todo_items, e); + + if (!etb->animator.todo_items) + etb->animator.todo_items = ecore_animator_add(_todo_items_process, NULL); + + return ECORE_CALLBACK_PASS_ON; } static Evas_Object * _ephoto_thumbnail_icon_get(void *data, Evas_Object *obj __UNUSED__, const char *part __UNUSED__) { - Eina_List *node = data; + Ephoto_Entry *entry = data; Evas_Object *o; - const char *ext = strrchr(eina_list_data_get(node), '.'); + const char *ext = strrchr(entry->path, '.'); + + if (!strncmp(part, "elm.swallow.icon.", sizeof("elm.swallow.icon.") - 1) != 0) + return NULL; if (ext) { @@ -155,7 +275,7 @@ _ephoto_thumbnail_icon_get(void *data, Evas_Object *obj __UNUSED__, const char * o = elm_thumb_add(ephoto->win); elm_object_style_set(o, "noframe"); - elm_thumb_file_set(o, eina_list_data_get(node), NULL); + elm_thumb_file_set(o, entry->path, NULL); evas_object_show(o); return o; @@ -164,12 +284,9 @@ _ephoto_thumbnail_icon_get(void *data, Evas_Object *obj __UNUSED__, const char * static char * _ephoto_thumbnail_label_get(void *data, Evas_Object *obj __UNUSED__, const char *part __UNUSED__) { - Eina_List *node = data; - const char *f; + Ephoto_Entry *e = data; - f = ecore_file_file_get(eina_list_data_get(node)); - - return strdup(f); + return strdup(e->label); } static void @@ -185,12 +302,7 @@ _ephoto_change_dir(void *data __UNUSED__, Evas_Object *o __UNUSED__, void *event if (!path) return; - elm_gengrid_clear(etb->grid); - ephoto->images = eina_list_free(ephoto->images); - ephoto->current_index = NULL; - eina_stringshare_del(ephoto->directory); - ephoto->directory = eina_stringshare_add(path); - ephoto_populate(); + ephoto_populate(path); } static void @@ -221,6 +333,7 @@ static void _ephoto_show_flow(void *data __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__) { Elm_Gengrid_Item *egi; + Ephoto_Entry *entry; elm_toolbar_item_selected_set(etb->action.view_flow, EINA_FALSE); @@ -228,15 +341,35 @@ _ephoto_show_flow(void *data __UNUSED__, Evas_Object *o __UNUSED__, void *event_ egi = elm_gengrid_selected_item_get(etb->grid); if (egi) - ephoto->current_index = elm_gengrid_item_data_get(egi); + entry = elm_gengrid_item_data_get(egi); + else + entry = eina_list_data_get + (eina_list_nth_list(ephoto->entries, 0)); + if (!entry) + return; - ephoto_flow_browser_show(); + printf("%s\n", entry->path); + ephoto_flow_browser_show(entry); } static void _ephoto_show_slideshow(void *data __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__) { + Elm_Gengrid_Item *egi; + Ephoto_Entry *entry; + elm_toolbar_item_selected_set(etb->action.slideshow, EINA_FALSE); - ephoto_slideshow_show(); + elm_object_unfocus(etb->grid); + + egi = elm_gengrid_selected_item_get(etb->grid); + if (egi) + entry = elm_gengrid_item_data_get(egi); + else + entry = eina_list_data_get + (eina_list_nth_list(ephoto->entries, 0)); + if (!entry) + return; + + ephoto_slideshow_show(entry); }