From 770baf199ed10ed0df59570e91120d3aedbc1593 Mon Sep 17 00:00:00 2001 From: Gustavo Sverzut Barbieri Date: Tue, 12 Oct 2010 03:40:14 +0000 Subject: [PATCH] slideshow is back. toolbars still missing, will return them back tomorrow. SVN revision: 53281 --- src/bin/ephoto.h | 39 ++---- src/bin/ephoto_flow_browser.c | 17 ++- src/bin/ephoto_main.c | 75 ++++++++++- src/bin/ephoto_slideshow.c | 228 +++++++++++++++------------------ src/bin/ephoto_thumb_browser.c | 32 +++++ 5 files changed, 232 insertions(+), 159 deletions(-) diff --git a/src/bin/ephoto.h b/src/bin/ephoto.h index cac0973..87973e1 100644 --- a/src/bin/ephoto.h +++ b/src/bin/ephoto.h @@ -31,52 +31,39 @@ typedef struct _Ephoto_Entry Ephoto_Entry; typedef enum _Ephoto_State Ephoto_State; typedef enum _Ephoto_Orient Ephoto_Orient; -/*Main Functions*/ Evas_Object *ephoto_window_add(const char *path); void ephoto_title_set(Ephoto *ephoto, const char *title); void ephoto_thumb_size_set(Ephoto *ephoto, int size); Evas_Object *ephoto_thumb_add(Ephoto *ephoto, Evas_Object *parent, const char *path); void ephoto_thumb_path_set(Evas_Object *o, const char *path); +Eina_Bool ephoto_config_init(Ephoto *em); +void ephoto_config_save(Ephoto *em, Eina_Bool instant); +void ephoto_config_free(Ephoto *em); -/* Configuration */ -Eina_Bool ephoto_config_init(Ephoto *em); -void ephoto_config_save(Ephoto *em, Eina_Bool instant); -void ephoto_config_free(Ephoto *em); - -/* Preferences */ -void ephoto_show_preferences(Ephoto *em); - -/*Ephoto Flow Browser*/ Evas_Object *ephoto_flow_browser_add(Ephoto *ephoto, Evas_Object *parent); -void ephoto_flow_browser_path_set(Evas_Object *obj, const char *image); -void ephoto_flow_browser_entry_set(Evas_Object *obj, Ephoto_Entry *entry); - +void ephoto_flow_browser_path_set(Evas_Object *obj, const char *image); +void ephoto_flow_browser_entry_set(Evas_Object *obj, Ephoto_Entry *entry); /* smart callbacks called: - * "back" - the user requested to delete the flow browser, typically called when go_back button is pressed or Escape key is typed. + * "back" - the user want to go back to the previous screen. */ +Evas_Object *ephoto_slideshow_add(Ephoto *ephoto, Evas_Object *parent); +void ephoto_slideshow_entry_set(Evas_Object *obj, Ephoto_Entry *entry); + /* smart callbacks called: + * "back" - the user want to go back to the previous screen. + */ -/*Ephoto Slideshow*/ -void ephoto_create_slideshow(void); -void ephoto_show_slideshow(int view, const char *current_image); -void ephoto_hide_slideshow(void); -void ephoto_delete_slideshow(void); - -/* Ephoto Directory Thumb */ Evas_Object *ephoto_directory_thumb_add(Evas_Object *parent, Ephoto_Entry *e); -/*Ephoto Thumb Browser*/ Evas_Object *ephoto_thumb_browser_add(Ephoto *ephoto, Evas_Object *parent); void ephoto_thumb_browser_directory_set(Evas_Object *obj, const char *path); void ephoto_thumb_browser_path_pending_set(Evas_Object *obj, const char *path, void (*cb)(void *data, Ephoto_Entry *entry), const void *data); /* smart callbacks called: - * "selected" - an item in the thumb browser is selected. The selected file is passed as event_info argument. - * "directory,changed" - the user selected a new directory. The selected directory is passed as event_info argument. + * "selected" - an item in the thumb browser is selected. The selected Ephoto_Entry is passed as event_info argument. */ -/* Enum for the state machine */ enum _Ephoto_State { EPHOTO_STATE_THUMB, @@ -135,7 +122,7 @@ struct _Ephoto } timer; Evas_Object *prefs_win; - Ephoto_State state; + Ephoto_State state, prev_state; Ephoto_Config *config; }; diff --git a/src/bin/ephoto_flow_browser.c b/src/bin/ephoto_flow_browser.c index d4049ec..839e00d 100644 --- a/src/bin/ephoto_flow_browser.c +++ b/src/bin/ephoto_flow_browser.c @@ -199,7 +199,7 @@ _mouse_wheel(void *data, Evas *e, Evas_Object *o, void *event_info) } static Ephoto_Entry * -_find_first_entry(Ephoto_Flow_Browser *fb) +_first_entry_find(Ephoto_Flow_Browser *fb) { const Eina_List *l; Ephoto_Entry *entry; @@ -211,7 +211,7 @@ _find_first_entry(Ephoto_Flow_Browser *fb) } static Ephoto_Entry * -_find_last_entry(Ephoto_Flow_Browser *fb) +_last_entry_find(Ephoto_Flow_Browser *fb) { const Eina_List *l; Ephoto_Entry *entry; @@ -235,12 +235,12 @@ _ephoto_flow_browser_toolbar_eval(Ephoto_Flow_Browser *fb) { edje_object_signal_emit(fb->edje, "slideshow,enable", "ephoto"); - if (fb->entry == _find_first_entry(fb)) + if (fb->entry == _first_entry_find(fb)) edje_object_signal_emit(fb->edje, "prev,disable", "ephoto"); else edje_object_signal_emit(fb->edje, "prev,enable", "ephoto"); - if (fb->entry == _find_last_entry(fb)) + if (fb->entry == _last_entry_find(fb)) edje_object_signal_emit(fb->edje, "next,disable", "ephoto"); else edje_object_signal_emit(fb->edje, "next,enable", "ephoto"); @@ -392,7 +392,7 @@ _prev_entry(Ephoto_Flow_Browser *fb) static void _first_entry(Ephoto_Flow_Browser *fb) { - Ephoto_Entry *entry = _find_first_entry(fb); + Ephoto_Entry *entry = _first_entry_find(fb); if (!entry) return; DBG("first is '%s'", entry->path); ephoto_flow_browser_entry_set(fb->layout, entry); @@ -401,7 +401,7 @@ _first_entry(Ephoto_Flow_Browser *fb) static void _last_entry(Ephoto_Flow_Browser *fb) { - Ephoto_Entry *entry = _find_last_entry(fb); + Ephoto_Entry *entry = _last_entry_find(fb); if (!entry) return; DBG("last is '%s'", entry->path); ephoto_flow_browser_entry_set(fb->layout, entry); @@ -460,6 +460,11 @@ _key_down(void *data, Evas *e, Evas_Object *o, void *event_info) _rotate_counterclock(fb); else if (!strcmp(k, "bracketright")) _rotate_clock(fb); + else if (!strcmp(k, "F5")) + { + if (fb->entry) + evas_object_smart_callback_call(fb->layout, "slideshow", fb->entry); + } } static void diff --git a/src/bin/ephoto_main.c b/src/bin/ephoto_main.c index 1fc2847..d6ce00e 100644 --- a/src/bin/ephoto_main.c +++ b/src/bin/ephoto_main.c @@ -1,15 +1,23 @@ #include "ephoto.h" +static void +_ephoto_state_set(Ephoto *ephoto, Ephoto_State state) +{ + ephoto->prev_state = ephoto->state; + ephoto->state = state; +} + static void _ephoto_thumb_browser_show(Ephoto *ephoto, Ephoto_Entry *entry) { DBG("entry '%s'", entry ? entry->path : ""); ephoto_flow_browser_path_set(ephoto->flow_browser, NULL); + ephoto_slideshow_entry_set(ephoto->slideshow, NULL); elm_object_focus(ephoto->thumb_browser); evas_object_focus_set(ephoto->thumb_browser, EINA_TRUE); // TODO while elm_layout is broken WRT focus edje_object_signal_emit(ephoto->edje, "thumb_browser,show", "ephoto"); - ephoto->state = EPHOTO_STATE_THUMB; + _ephoto_state_set(ephoto, EPHOTO_STATE_THUMB); if ((entry) && (entry->item)) elm_gengrid_item_bring_in(entry->item); } @@ -22,7 +30,18 @@ _ephoto_flow_browser_show(Ephoto *ephoto, Ephoto_Entry *entry) elm_object_focus(ephoto->flow_browser); evas_object_focus_set(ephoto->flow_browser, EINA_TRUE); // TODO while elm_layout is broken WRT focus edje_object_signal_emit(ephoto->edje, "flow_browser,show", "ephoto"); - ephoto->state = EPHOTO_STATE_FLOW; + _ephoto_state_set(ephoto, EPHOTO_STATE_FLOW); +} + +static void +_ephoto_slideshow_show(Ephoto *ephoto, Ephoto_Entry *entry) +{ + DBG("entry '%s'", entry->path); + ephoto_slideshow_entry_set(ephoto->slideshow, entry); + elm_object_focus(ephoto->slideshow); + evas_object_focus_set(ephoto->slideshow, EINA_TRUE); // TODO while elm_layout is broken WRT focus + edje_object_signal_emit(ephoto->edje, "slideshow,show", "ephoto"); + _ephoto_state_set(ephoto, EPHOTO_STATE_SLIDESHOW); } static void @@ -33,6 +52,24 @@ _ephoto_flow_browser_back(void *data, Evas_Object *obj, void *event_info) _ephoto_thumb_browser_show(ephoto, entry); } +static void +_ephoto_slideshow_back(void *data, Evas_Object *obj, void *event_info) +{ + Ephoto *ephoto = data; + Ephoto_Entry *entry = event_info; + switch (ephoto->prev_state) + { + case EPHOTO_STATE_FLOW: + _ephoto_flow_browser_show(ephoto, entry); + break; + case EPHOTO_STATE_THUMB: + _ephoto_thumb_browser_show(ephoto, entry); + break; + default: + ERR("unhandled previous state %d", ephoto->prev_state); + } +} + static void _ephoto_thumb_browser_view(void *data, Evas_Object *obj, void *event_info) { @@ -41,6 +78,22 @@ _ephoto_thumb_browser_view(void *data, Evas_Object *obj, void *event_info) _ephoto_flow_browser_show(ephoto, entry); } +static void +_ephoto_thumb_browser_slideshow(void *data, Evas_Object *obj, void *event_info) +{ + Ephoto *ephoto = data; + Ephoto_Entry *entry = event_info; + _ephoto_slideshow_show(ephoto, entry); +} + +static void +_ephoto_flow_browser_slideshow(void *data, Evas_Object *obj, void *event_info) +{ + Ephoto *ephoto = data; + Ephoto_Entry *entry = event_info; + _ephoto_slideshow_show(ephoto, entry); +} + static void _pending_path_found(void *data, Ephoto_Entry *entry) { @@ -131,6 +184,9 @@ ephoto_window_add(const char *path) (ephoto->layout, "ephoto.swallow.thumb_browser", ephoto->thumb_browser); evas_object_smart_callback_add (ephoto->thumb_browser, "view", _ephoto_thumb_browser_view, ephoto); + evas_object_smart_callback_add + (ephoto->thumb_browser, "slideshow", + _ephoto_thumb_browser_slideshow, ephoto); ephoto->flow_browser = ephoto_flow_browser_add(ephoto, ephoto->layout); if (!ephoto->flow_browser) @@ -143,6 +199,21 @@ ephoto_window_add(const char *path) (ephoto->layout, "ephoto.swallow.flow_browser", ephoto->flow_browser); evas_object_smart_callback_add (ephoto->flow_browser, "back", _ephoto_flow_browser_back, ephoto); + evas_object_smart_callback_add + (ephoto->flow_browser, "slideshow", + _ephoto_flow_browser_slideshow, ephoto); + + ephoto->slideshow = ephoto_slideshow_add(ephoto, ephoto->layout); + if (!ephoto->slideshow) + { + ERR("could not add flow browser"); + evas_object_del(ephoto->win); + return NULL; + } + elm_layout_content_set + (ephoto->layout, "ephoto.swallow.slideshow", ephoto->slideshow); + evas_object_smart_callback_add + (ephoto->slideshow, "back", _ephoto_slideshow_back, ephoto); edje_object_size_min_get(ephoto->edje, &mw, &mh); edje_object_size_min_restricted_calc(ephoto->edje, &mw, &mh, mw, mh); diff --git a/src/bin/ephoto_slideshow.c b/src/bin/ephoto_slideshow.c index 21aff0b..64167d7 100644 --- a/src/bin/ephoto_slideshow.c +++ b/src/bin/ephoto_slideshow.c @@ -1,151 +1,129 @@ #include "ephoto.h" -#if 0 -static Evas_Object *_ephoto_get_image(void *data, Evas_Object *obj); -static void _ephoto_end_slideshow(void *data, Evas *e, Evas_Object *obj, void *event_info); -static void _ephoto_switch_fullscreen(); +typedef struct _Ephoto_Slideshow Ephoto_Slideshow; -static Elm_Slideshow_Item_Class itc; -static int return_view; -static const char *cur_image; - -/*Key is pressed*/ -static void -_ephoto_key_pressed(void *data, Evas *e, Evas_Object *obj, void *event_data) +struct _Ephoto_Slideshow { - Evas_Event_Key_Down *eku = (Evas_Event_Key_Down *)event_data; - if ((!strcmp(eku->key, "F5")) || (!strcmp(eku->key, "Escape"))) - ephoto_hide_slideshow(); - if ((!strcmp(eku->key, "F11"))) - _ephoto_switch_fullscreen(); + Ephoto *ephoto; + Evas_Object *slideshow; + Ephoto_Entry *entry; +}; + +static void +_key_down(void *data, Evas *e, Evas_Object *o, void *event_info) +{ + Ephoto_Slideshow *ss = data; + Evas_Event_Key_Down *ev = event_info; + const char *k = ev->keyname; + + if (!strcmp(k, "Escape")) + { + Evas_Object *win = ss->ephoto->win; + Elm_Slideshow_Item *item; + Ephoto_Entry *entry; + + if (elm_win_fullscreen_get(win)) + elm_win_fullscreen_set(win, EINA_FALSE); + + item = elm_slideshow_item_current_get(ss->slideshow); + if (item) entry = elm_slideshow_item_data_get(item); + else entry = ss->entry; + evas_object_smart_callback_call(ss->slideshow, "back", entry); + } + else if (!strcmp(k, "F11")) + { + Evas_Object *win = ss->ephoto->win; + elm_win_fullscreen_set(win, !elm_win_fullscreen_get(win)); + } } static void -_ephoto_switch_fullscreen(void) +_mouse_down(void *data, Evas *e, Evas_Object *o, void *event_info) { - elm_win_fullscreen_set(em->win, !elm_win_fullscreen_get(em->win)); + Ephoto_Slideshow *ss = data; + evas_object_smart_callback_call(ss->slideshow, "back", ss->entry); } -/*Create the slideshow*/ -void -ephoto_create_slideshow(void) +static void +_slideshow_del(void *data, Evas *e, Evas_Object *obj, void *event_info) { - em->slideshow = elm_slideshow_add(em->win); - elm_slideshow_loop_set(em->slideshow, EINA_TRUE); - elm_slideshow_layout_set(em->slideshow, "fullscreen"); - evas_object_size_hint_weight_set(em->slideshow, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(em->slideshow, EVAS_HINT_FILL, EVAS_HINT_FILL); - evas_object_event_callback_add(em->slideshow, EVAS_CALLBACK_MOUSE_DOWN, - _ephoto_end_slideshow, NULL); - evas_object_event_callback_add(em->slideshow, EVAS_CALLBACK_KEY_DOWN, - _ephoto_key_pressed, NULL); - em->slideshow_notify = elm_notify_add(em->win); - Evas_Object *label = elm_label_add(em->win); - elm_label_label_set(label, "Press F11 to turn off fullscreen"); - elm_notify_content_set(em->slideshow_notify, label); - elm_notify_orient_set(em->slideshow_notify, ELM_NOTIFY_ORIENT_TOP); - elm_notify_timeout_set(em->slideshow_notify, 2); + Ephoto_Slideshow *ss = data; + free(ss); } -/*Start and show the slideshow*/ -void -ephoto_show_slideshow(int view, const char *current_image) +Evas_Object * +ephoto_slideshow_add(Ephoto *ephoto, Evas_Object *parent) { - Eina_List *l = NULL, *iter = NULL; - Elm_Slideshow_Item *cur_item = NULL, *item; - const char *image; - int x, y, w, h; + Evas_Object *slideshow = elm_slideshow_add(parent); + Ephoto_Slideshow *ss; - elm_slideshow_transition_set(em->slideshow, em->config->slideshow_transition); - elm_slideshow_timeout_set(em->slideshow, em->config->slideshow_timeout); - elm_win_fullscreen_set(em->win, EINA_TRUE); + EINA_SAFETY_ON_NULL_RETURN_VAL(slideshow, NULL); - return_view = view; - cur_image = current_image; + ss = calloc(1, sizeof(Ephoto_Slideshow)); + EINA_SAFETY_ON_NULL_GOTO(ss, error); + ss->ephoto = ephoto; + ss->slideshow = slideshow; + evas_object_event_callback_add + (slideshow, EVAS_CALLBACK_DEL, _slideshow_del, ss); + evas_object_event_callback_add + (slideshow, EVAS_CALLBACK_KEY_DOWN, _key_down, ss); + evas_object_event_callback_add + (slideshow, EVAS_CALLBACK_MOUSE_DOWN, _mouse_down, ss); + evas_object_data_set(slideshow, "slideshow", ss); - evas_object_geometry_get(em->win, &x, &y, &w, &h); - evas_object_resize(em->slideshow, w, h); - evas_object_move(em->slideshow, 0, 0); + elm_slideshow_loop_set(slideshow, EINA_TRUE); + elm_slideshow_layout_set(slideshow, "fullscreen"); + 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); - itc.func.get = _ephoto_get_image; - itc.func.del = NULL; + return ss->slideshow; - elm_slideshow_clear(em->slideshow); - /* TODO: - l = em->images; - EINA_LIST_FOREACH(l, iter, image) - { - item = elm_slideshow_item_add(em->slideshow, &itc, image); - if ((current_image) && (!strcmp(image, current_image))) - cur_item = item; - } - */ - if (cur_item) - elm_slideshow_show(cur_item); - - evas_object_show(em->slideshow); - evas_object_focus_set(em->slideshow, EINA_TRUE); - elm_win_resize_object_add(em->win, em->slideshow); - - evas_object_show(em->slideshow_notify); + error: + evas_object_del(slideshow); + return NULL; } -/*Hide the slideshow object*/ -void -ephoto_hide_slideshow(void) -{ - elm_win_fullscreen_set(em->win, EINA_FALSE); - evas_object_hide(em->slideshow); - elm_slideshow_clear(em->slideshow); - if (return_view == 0) - evas_object_focus_set(em->thumb_browser, 1); - else if (return_view == 1) - evas_object_focus_set(em->flow_browser, 1); - - // FIXME - /* - if (return_view == 0) - ephoto_show_thumb_browser(); - else*/ - //ephoto_show_flow_browser(cur_image); -} - -/*Delete the slideshow object*/ -void -ephoto_delete_slideshow(void) -{ - evas_object_del(em->slideshow); -} - -/*Get the image for the slideshow*/ static Evas_Object * -_ephoto_get_image(void *data, Evas_Object *obj) +_slideshow_item_get(void *data, Evas_Object *obj) { - char *file; - Evas_Object *image; - char *buffer; - int length; - - file = data; - - image = elm_photo_add(obj); - elm_photo_file_set(image, file); - elm_photo_fill_inside_set(image, EINA_TRUE); - elm_object_style_set(image, "shadow"); - - length = strlen(file) + strlen("Ephoto - ") + 1; - buffer = alloca(length); - snprintf(buffer, length, "Ephoto - %s", file); - elm_win_title_set(em->win, buffer); - - return image; + Ephoto_Entry *entry = data; + /* TODO use viewer from ephoto_flow_browser.c */ + /* TODO consider using exif rotation, see ephoto_flow_browser.c */ + Evas_Object *image = elm_photo_add(obj); + elm_photo_file_set(image, entry->path); + elm_photo_fill_inside_set(image, EINA_TRUE); + elm_object_style_set(image, "shadow"); + return image; } -/*End the slideshow*/ -static void -_ephoto_end_slideshow(void *data, Evas *e, Evas_Object *obj, void *event_info) -{ - ephoto_hide_slideshow(); -} +static const Elm_Slideshow_Item_Class _item_cls = {{_slideshow_item_get, NULL}}; -#endif +void +ephoto_slideshow_entry_set(Evas_Object *obj, Ephoto_Entry *entry) +{ + Ephoto_Slideshow *ss = evas_object_data_get(obj, "slideshow"); + Ephoto_Config *conf; + Ephoto_Entry *itr; + const Eina_List *l; + EINA_SAFETY_ON_NULL_RETURN(ss); + + conf = ss->ephoto->config; + + DBG("entry %p, was %p", entry, ss->entry); + ss->entry = entry; + elm_slideshow_loop_set(ss->slideshow, EINA_TRUE); /* move to config? */ + elm_slideshow_transition_set(ss->slideshow, conf->slideshow_transition); + elm_slideshow_timeout_set(ss->slideshow, conf->slideshow_timeout); + elm_slideshow_clear(ss->slideshow); + if (!entry) return; + + elm_win_fullscreen_set(ss->ephoto->win, EINA_TRUE); + EINA_LIST_FOREACH(ss->ephoto->entries, l, itr) + { + Elm_Slideshow_Item *item; + if (itr->is_dir) continue; + item = elm_slideshow_item_add(ss->slideshow, &_item_cls, itr); + if (itr == entry) elm_slideshow_show(item); + } +} diff --git a/src/bin/ephoto_thumb_browser.c b/src/bin/ephoto_thumb_browser.c index 6c63d0a..ee647b6 100644 --- a/src/bin/ephoto_thumb_browser.c +++ b/src/bin/ephoto_thumb_browser.c @@ -25,6 +25,16 @@ struct _Ephoto_Thumb_Browser } job; }; +static Ephoto_Entry * +_first_file_entry_find(Ephoto_Thumb_Browser *tb) +{ + const Eina_List *l; + Ephoto_Entry *entry; + EINA_LIST_FOREACH(tb->ephoto->entries, l, entry) + if (!entry->is_dir) return entry; + return NULL; +} + static char * _ephoto_thumb_item_label_get(void *data, Evas_Object *obj, const char *part) { @@ -349,6 +359,26 @@ _zoom_out(void *data, Evas_Object *o, const char *emission, const char *source) _zoom_set(tb, tb->ephoto->config->thumb_size - ZOOM_STEP); } +static void +_key_down(void *data, Evas *e, Evas_Object *o, void *event_info) +{ + Ephoto_Thumb_Browser *tb = data; + Evas_Event_Key_Down *ev = event_info; + const char *k = ev->keyname; + + if (!strcmp(k, "F5")) + { + Elm_Gengrid_Item *it = elm_gengrid_selected_item_get(tb->grid); + Ephoto_Entry *entry; + if (it) entry = elm_gengrid_item_data_get(it); + else entry = _first_file_entry_find(tb); + + if (entry) + evas_object_smart_callback_call(tb->layout, "slideshow", entry); + } +} + + static void _layout_del(void *data, Evas *e, Evas_Object *o, void *event_info) { @@ -374,6 +404,8 @@ ephoto_thumb_browser_add(Ephoto *ephoto, Evas_Object *parent) tb->layout = layout; tb->edje = elm_layout_edje_get(layout); evas_object_event_callback_add(layout, EVAS_CALLBACK_DEL, _layout_del, tb); + evas_object_event_callback_add + (layout, EVAS_CALLBACK_KEY_DOWN, _key_down, tb); evas_object_data_set(layout, "thumb_browser", tb); edje_object_signal_callback_add (tb->edje, "location,changed", "ephoto", _changed_dir, tb);