From a2f674b21bd9c96bd1f06e3aec7dbcdc4ea9a11c Mon Sep 17 00:00:00 2001 From: Stephen okra Houston Date: Fri, 24 Jun 2016 16:43:55 -0500 Subject: [PATCH] Ephoto: Add the beginnings of a custom slideshow widget. --- data/themes/ephoto.edc | 27 ++++ src/bin/ephoto_slideshow.c | 286 +++++++++++++++++++++++++------------ 2 files changed, 219 insertions(+), 94 deletions(-) diff --git a/data/themes/ephoto.edc b/data/themes/ephoto.edc index a03af5e..cebe3c6 100644 --- a/data/themes/ephoto.edc +++ b/data/themes/ephoto.edc @@ -367,6 +367,33 @@ collections { } } } + group { name: "ephoto,slideshow,base"; + parts { + rect { "background"; + scale: 1; + description { + state: "default" 0.0; + color: 0 0 0 255; + } + } + rect { "slide_clip"; + scale: 1; + description { + state: "default" 0.0; + rel1.to: "background"; + rel2.to: "background"; + } + } + swallow { "ephoto.swallow.slideshow"; + scale: 1; + clip_to: "slide_clip"; + mouse_events: 1; + description { + state: "default" 0.0; + } + } + } + } group { name: "ephoto,image,cropper,base"; script { public message(Msg_Type:type, id, ...) { diff --git a/src/bin/ephoto_slideshow.c b/src/bin/ephoto_slideshow.c index c27ff09..0f78a73 100644 --- a/src/bin/ephoto_slideshow.c +++ b/src/bin/ephoto_slideshow.c @@ -5,6 +5,7 @@ typedef struct _Ephoto_Slideshow Ephoto_Slideshow; struct _Ephoto_Slideshow { Ephoto *ephoto; + Evas_Object *current_image; Evas_Object *slideshow; Evas_Object *event; Evas_Object *notify; @@ -15,17 +16,119 @@ struct _Ephoto_Slideshow Evas_Object *fullscreen_after; Ephoto_Entry *entry; Eina_Bool playing; + Ecore_Timer *timer; + int timeout; + int current; }; +static Evas_Object *_slideshow_item_get(Ephoto_Entry *entry, Evas_Object *parent); +static Eina_Bool _slideshow_transition(void *data); +static void _slideshow_play(Ephoto_Slideshow *ss); +static void _slideshow_pause(Ephoto_Slideshow *ss); static Evas_Object *_add_icon(Evas_Object *parent, const char *icon, const char *label, Evas_Object *before); +static void +_image_shown(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, + void *event_data EINA_UNUSED) +{ + Ephoto_Entry *entry = data; + + ephoto_title_set(entry->ephoto, entry->basename); +} + +static Evas_Object * +_slideshow_item_get(Ephoto_Entry *entry, Evas_Object *parent) +{ + const char *group = NULL; + const char *ext = strrchr(entry->path, '.'); + + if (ext) + { + ext++; + if ((strcasecmp(ext, "edj") == 0)) + { + if (edje_file_group_exists(entry->path, "e/desktop/background")) + group = "e/desktop/background"; + else + { + Eina_List *g = edje_file_collection_list(entry->path); + + group = eina_list_data_get(g); + edje_file_collection_list_free(g); + } + } + } + Evas_Object *image = elm_image_add(parent); + elm_image_file_set(image, entry->path, group); + elm_image_fill_outside_set(image, EINA_FALSE); + evas_object_size_hint_weight_set(image, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(image, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_data_set(image, "entry", entry); + evas_object_event_callback_add(image, EVAS_CALLBACK_SHOW, _image_shown, + entry); + + return image; +} + +static Eina_Bool +_slideshow_transition(void *data) +{ + Ephoto_Slideshow *ss = data; + + if (ss->playing == 0) + { + if (ss->timer) + ecore_timer_del(ss->timer); + ss->timer = NULL; + return EINA_FALSE; + } + if (ss->current_image) + { + elm_layout_content_unset(ss->slideshow, "ephoto.swallow.slideshow"); + evas_object_del(ss->current_image); + } + ss->current += 1; + if (!eina_list_nth(ss->entries, ss->current)) + ss->current = 0; + ss->current_image = _slideshow_item_get(eina_list_nth(ss->entries, ss->current), + ss->slideshow); + elm_layout_content_set(ss->slideshow, "ephoto.swallow.slideshow", ss->current_image); + evas_object_show(ss->current_image); + + return EINA_TRUE; +} + +static void +_slideshow_play(Ephoto_Slideshow *ss) +{ + if (!ss->current_image) + { + if (!eina_list_nth(ss->entries, ss->current)) + ss->current = 0; + ss->current_image = _slideshow_item_get(eina_list_nth(ss->entries, ss->current), + ss->slideshow); + elm_layout_content_set(ss->slideshow, "ephoto.swallow.slideshow", ss->current_image); + evas_object_show(ss->current_image); + } + if (ss->timer) + ecore_timer_del(ss->timer); + ss->timer = ecore_timer_add(ss->timeout, _slideshow_transition, ss); +} + +static void +_slideshow_pause(Ephoto_Slideshow *ss) +{ + if (ss->timer) + ss->timer = ecore_timer_del(ss->timer); + ss->timer = NULL; +} + static void _mouse_down(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) { Ephoto_Slideshow *ss = data; - Elm_Object_Item *slideshow_item; Ephoto_Entry *entry; elm_layout_content_unset(ss->ephoto->layout, "ephoto.swallow.controls"); @@ -33,9 +136,8 @@ _mouse_down(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, elm_layout_content_set(ss->ephoto->layout, "ephoto.swallow.controls", ss->ephoto->statusbar); - slideshow_item = elm_slideshow_item_current_get(ss->slideshow); - if (slideshow_item) - entry = elm_object_item_data_get(slideshow_item); + if (ss->current_image) + entry = evas_object_data_get(ss->current_image, "entry"); else entry = ss->entry; if (ss->event) @@ -44,7 +146,16 @@ _mouse_down(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, ss->event = NULL; } evas_object_smart_callback_call(ss->slideshow, "back", entry); - elm_slideshow_clear(ss->slideshow); + if (ss->current_image) + { + elm_layout_content_unset(ss->slideshow, "ephoto.swallow.slideshow"); + evas_object_del(ss->current_image); + } + ss->current_image = NULL; + if (ss->timer) + ecore_timer_del(ss->timer); + ss->timer = NULL; + ss->current = 0; ss->playing = 0; evas_object_freeze_events_set(ss->slideshow, EINA_TRUE); } @@ -72,7 +183,6 @@ static void _back(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) { Ephoto_Slideshow *ss = data; - Elm_Object_Item *slideshow_item; Ephoto_Entry *entry; elm_layout_content_unset(ss->ephoto->layout, "ephoto.swallow.controls"); @@ -80,9 +190,8 @@ _back(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) elm_layout_content_set(ss->ephoto->layout, "ephoto.swallow.controls", ss->ephoto->statusbar); - slideshow_item = elm_slideshow_item_current_get(ss->slideshow); - if (slideshow_item) - entry = elm_object_item_data_get(slideshow_item); + if (ss->current_image) + entry = evas_object_data_get(ss->current_image, "entry"); else entry = ss->entry; if (ss->event) @@ -91,7 +200,16 @@ _back(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) ss->event = NULL; } evas_object_smart_callback_call(ss->slideshow, "back", entry); - elm_slideshow_clear(ss->slideshow); + if (ss->current_image) + { + elm_layout_content_unset(ss->slideshow, "ephoto.swallow.controls"); + evas_object_del(ss->current_image); + } + ss->current_image = NULL; + if (ss->timer) + ecore_timer_del(ss->timer); + ss->timer = NULL; + ss->current = 0; ss->playing = 0; evas_object_freeze_events_set(ss->slideshow, EINA_TRUE); } @@ -99,13 +217,33 @@ _back(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) static void _first(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) { - elm_slideshow_item_show(elm_slideshow_item_nth_get(data, 0)); + Ephoto_Slideshow *ss = data; + + _slideshow_pause(ss); + if (ss->current_image) + { + elm_layout_content_unset(ss->slideshow, "ephoto.swallow.slideshow"); + evas_object_del(ss->current_image); + ss->current_image = NULL; + } + ss->current = 0; + _slideshow_play(ss); } static void _next(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) { - elm_slideshow_next(data); + Ephoto_Slideshow *ss = data; + + _slideshow_pause(ss); + if (ss->current_image) + { + elm_layout_content_unset(ss->slideshow, "ephoto.swallow.slideshow"); + evas_object_del(ss->current_image); + ss->current_image = NULL; + } + ss->current += 1; + _slideshow_play(ss); } static void @@ -117,7 +255,7 @@ _pause(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) if (ss->playing) { - elm_slideshow_timeout_set(ss->slideshow, 0.0); + _slideshow_pause(ss); ss->pause = _add_icon(ss->notify, "media-playback-start", _("Play"), ss->pause_after); @@ -126,8 +264,7 @@ _pause(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) } else { - elm_slideshow_timeout_set(ss->slideshow, - ss->ephoto->config->slideshow_timeout); + _slideshow_play(ss); ss->pause = _add_icon(ss->notify, "media-playback-pause", _("Pause"), ss->pause_after); @@ -140,15 +277,33 @@ static void _previous(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) { - elm_slideshow_previous(data); + Ephoto_Slideshow *ss = data; + + _slideshow_pause(ss); + if (ss->current_image) + { + elm_layout_content_unset(ss->slideshow, "ephoto.swallow.slideshow"); + evas_object_del(ss->current_image); + ss->current_image = NULL; + } + ss->current -= 1; + _slideshow_play(ss); } static void _last(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) { - unsigned int count = elm_slideshow_count_get(data); + Ephoto_Slideshow *ss = data; - elm_slideshow_item_show(elm_slideshow_item_nth_get(data, count - 1)); + _slideshow_pause(ss); + if (ss->current_image) + { + elm_layout_content_unset(ss->slideshow, "ephoto.swallow.slideshow"); + evas_object_del(ss->current_image); + ss->current_image = NULL; + } + ss->current = eina_list_count(ss->entries) - 1; + _slideshow_play(ss); } static void @@ -216,19 +371,19 @@ _key_down(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, } else if (!strcmp(k, "Home")) { - _first(ss->slideshow, NULL, NULL); + _first(ss, NULL, NULL); } else if (!strcmp(k, "End")) { - _last(ss->slideshow, NULL, NULL); + _last(ss, NULL, NULL); } else if (!strcmp(k, "Left")) { - _previous(ss->slideshow, NULL, NULL); + _previous(ss, NULL, NULL); } else if (!strcmp(k, "Right")) { - _next(ss->slideshow, NULL, NULL); + _next(ss, NULL, NULL); } } @@ -290,18 +445,18 @@ ephoto_slideshow_show_controls(Ephoto *ephoto) but = _add_icon(ss->notify, "window-close", _("Back"), NULL); evas_object_smart_callback_add(but, "clicked", _back, ss); but = _add_icon(ss->notify, "go-first", _("First"), NULL); - evas_object_smart_callback_add(but, "clicked", _first, ss->slideshow); + evas_object_smart_callback_add(but, "clicked", _first, ss); but = _add_icon(ss->notify, "go-previous", _("Previous"), NULL); - evas_object_smart_callback_add(but, "clicked", _previous, ss->slideshow); + evas_object_smart_callback_add(but, "clicked", _previous, ss); ss->pause = _add_icon(ss->notify, "media-playback-start", _("Play"), NULL); evas_object_smart_callback_add(ss->pause, "clicked", _pause, ss); ss->pause_after = _add_icon(ss->notify, "go-next", _("Next"), NULL); evas_object_smart_callback_add(ss->pause_after, "clicked", _next, - ss->slideshow); + ss); but = _add_icon(ss->notify, "go-last", _("Last"), NULL); - evas_object_smart_callback_add(but, "clicked", _last, ss->slideshow); + evas_object_smart_callback_add(but, "clicked", _last, ss); ss->fullscreen = _add_icon(ss->notify, "view-fullscreen", _("Fullscreen"), NULL); evas_object_smart_callback_add(ss->fullscreen, "clicked", _fullscreen, ss); @@ -315,7 +470,7 @@ ephoto_slideshow_show_controls(Ephoto *ephoto) Evas_Object * ephoto_slideshow_add(Ephoto *ephoto, Evas_Object *parent) { - Evas_Object *slideshow = elm_slideshow_add(parent); + Evas_Object *slideshow = elm_layout_add(parent); Ephoto_Slideshow *ss; EINA_SAFETY_ON_NULL_RETURN_VAL(slideshow, NULL); @@ -325,8 +480,12 @@ ephoto_slideshow_add(Ephoto *ephoto, Evas_Object *parent) ss->ephoto = ephoto; ss->slideshow = slideshow; ss->playing = 0; + ss->current = 0; + ss->current_image = NULL; ss->event = NULL; + elm_layout_file_set(slideshow, PACKAGE_DATA_DIR "/themes/ephoto.edj", + "ephoto,slideshow,base"); evas_object_event_callback_add(slideshow, EVAS_CALLBACK_DEL, _slideshow_del, ss); evas_object_event_callback_add(slideshow, EVAS_CALLBACK_MOUSE_DOWN, @@ -335,12 +494,9 @@ ephoto_slideshow_add(Ephoto *ephoto, Evas_Object *parent) _main_focused, ss); evas_object_data_set(slideshow, "slideshow", ss); elm_object_tree_focus_allow_set(slideshow, EINA_FALSE); - 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); - evas_object_freeze_events_set(ss->slideshow, EINA_TRUE); return ss->slideshow; @@ -350,50 +506,6 @@ ephoto_slideshow_add(Ephoto *ephoto, Evas_Object *parent) return NULL; } -static void -_image_shown(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, - void *event_data EINA_UNUSED) -{ - Ephoto_Entry *entry = data; - - ephoto_title_set(entry->ephoto, entry->basename); -} - -static Evas_Object * -_slideshow_item_get(void *data, Evas_Object *obj) -{ - Ephoto_Entry *entry = data; - - const char *group = NULL; - const char *ext = strrchr(entry->path, '.'); - - if (ext) - { - ext++; - if ((strcasecmp(ext, "edj") == 0)) - { - if (edje_file_group_exists(entry->path, "e/desktop/background")) - group = "e/desktop/background"; - else - { - Eina_List *g = edje_file_collection_list(entry->path); - - group = eina_list_data_get(g); - edje_file_collection_list_free(g); - } - } - } - Evas_Object *image = elm_image_add(obj); - elm_image_file_set(image, entry->path, group); - evas_object_event_callback_add(image, EVAS_CALLBACK_SHOW, _image_shown, - entry); - - return image; -} - -static const Elm_Slideshow_Item_Class _item_cls = - { {_slideshow_item_get, NULL} }; - void ephoto_slideshow_entries_set(Evas_Object *obj, Eina_List *entries) { @@ -407,25 +519,21 @@ void ephoto_slideshow_entry_set(Evas_Object *obj, Ephoto_Entry *entry) { Ephoto_Slideshow *ss = evas_object_data_get(obj, "slideshow"); - Ephoto_Entry *itr; - const Eina_List *l; + + if (!entry) + return; if (ss->entry) ephoto_entry_free_listener_del(ss->entry, _entry_free, ss); ss->entry = entry; + ss->current = eina_list_data_idx(ss->entries, ss->entry); if (entry) ephoto_entry_free_listener_add(entry, _entry_free, ss); - elm_slideshow_loop_set(ss->slideshow, EINA_TRUE); - elm_slideshow_transition_set(ss->slideshow, - ss->ephoto->config->slideshow_transition); - elm_slideshow_timeout_set(ss->slideshow, - ss->ephoto->config->slideshow_timeout); - elm_slideshow_clear(ss->slideshow); - if (!entry) - return; + ss->timeout = ss->ephoto->config->slideshow_timeout; + _slideshow_play(ss); evas_object_freeze_events_set(ss->slideshow, EINA_FALSE); @@ -458,16 +566,6 @@ ephoto_slideshow_entry_set(Evas_Object *obj, Ephoto_Entry *entry) _fullscreen, ss); } } - - EINA_LIST_FOREACH(ss->entries, l, itr) - { - Elm_Object_Item *slideshow_item; - - slideshow_item = elm_slideshow_item_add(ss->slideshow, - &_item_cls, itr); - if (itr == entry) - elm_slideshow_item_show(slideshow_item); - } if (ss->event) { evas_object_del(ss->event);