diff --git a/data/themes/default/ephoto.edc b/data/themes/default/ephoto.edc index e0625f9..79bcd91 100644 --- a/data/themes/default/ephoto.edc +++ b/data/themes/default/ephoto.edc @@ -1,373 +1,530 @@ -collections { - group - { - name: "flow_image"; - image: "thumb_shadow.png" COMP; - parts - { - part - { - name: "event"; - type: RECT; - repeat_events: 1; - description - { - state: "default" 0.0; - color: 0 0 0 0; - } - } - part - { - name: "border-shadow"; - type: IMAGE; - mouse_events: 0; - description - { - state: "default" 0.0; - rel1 - { - to: "image"; - offset: -18 -18; - } - rel2 - { - to: "image"; - offset: 17 17; - } - image - { - normal: "thumb_shadow.png"; - border: 17 17 17 17; - middle: NONE; - } - } - } - part - { - name: "border"; - type: RECT; - mouse_events: 0; - description - { - state: "default" 0.0; - rel1 - { - to: "border-shadow"; - offset: 16 16; - } - rel2 - { - to: "border-shadow"; - offset: -15 -15; - } - } - } - part - { - name: "image"; - type: SWALLOW; - mouse_events: 0; - description - { - state: "default" 0.0; - aspect_preference: BOTH; - aspect: 1.0 1.0; - rel1.offset: 0 8; - rel2.offset: -1 -2; - } - } -// part -// { -// name: "text"; -// type: TEXT; -// effect: SOFT_SHADOW; -// mouse_events: 0; -// scale: 1; -// description -// { -// state: "default" 0.0; -// color: 0 0 0 255; -// color3: 0 0 0 0; -// align: 0.5 1.0; -// rel1 -// { -// relative: 0.0 1.0; -// offset: 20 -30; -// } -// rel2 -// { -// relative: 1.0 1.0; -// offset: -21 -15; -// } -// text -// { -// font: "Sans"; -// size: 10; -// min: 0 1; -// align: 0.5 0.0; -// text_class: "image"; -// } -// } -// } - } - } - group - { - name: "flow"; - parts - { - part - { - name: "offscreen_left"; - type: SWALLOW; - mouse_events: 1; - description - { - state: default 0.0; - fixed: 1 1; - visible: 0; - rel1.relative: 0.0 0.3; - rel1.offset: 0 0; - rel2.relative: 0.0 0.7; - rel2.offset: 0 0; - } - description - { - state: right 0.0; - visible: 1; - rel1.relative: 0.0 0.3; - rel1.offset: 0 0; - rel2.relative: 0.2 0.7; - rel2.offset: 0 0; - } - description - { - state: left 0.0; - visible: 0; - rel1.relative: 1.0 0.3; - rel1.offset: 0 0; - rel2.relative: 1.0 0.7; - rel2.offset: 0 0; - } - } - part - { - name: "left"; - type: SWALLOW; - mouse_events: 1; - description - { - state: default 0.0; - visible: 1; - rel1.relative: 0.0 0.3; - rel1.offset: 0 0; - rel2.relative: 0.2 0.7; - rel2.offset: 0 0; - } - description - { - state: right 0.0; - rel1.relative: 0.2 0.2; - rel1.offset: 0 0; - rel2.relative: 0.8 0.8; - rel2.offset: 0 0; - } - description - { - state: left 0.0; - rel1.relative: 0.0 0.3; - rel1.offset: 0 0; - rel2.relative: 0.0 0.7; - rel2.offset: 0 0; - } - description - { - state: full 0.0; - map.on: 1; - inherit: default 0.0; - visible: 0; - } - } - part - { - name: "right"; - type: SWALLOW; - mouse_events: 1; - description - { - state: default 0.0; - visible: 1; - rel1.relative: 0.8 0.3; - rel1.offset: 0 0; - rel2.relative: 1.0 0.7; - rel2.offset: 0 0; - } - description - { - state: right 0.0; - rel1.relative: 1.0 0.3; - rel1.offset: 0 0; - rel2.relative: 1.0 0.7; - rel2.offset: 0 0; - } - description - { - state: left 0.0; - rel1.relative: 0.2 0.2; - rel1.offset: 0 0; - rel2.relative: 0.8 0.8; - rel2.offset: 0 0; - } - description - { - state: full 0.0; - map.on: 1; - inherit: default 0.0; - visible: 0; - } - } - part - { - name: "center"; - type: SWALLOW; - mouse_events: 1; - description - { - state: default 0.0; - rel1.relative: 0.2 0.2; - rel1.offset: 0 0; - rel2.relative: 0.8 0.8; - rel2.offset: 0 0; - } - description - { - state: right 0.0; - rel1.relative: 0.8 0.3; - rel1.offset: 0 0; - rel2.relative: 1.0 0.7; - rel2.offset: 0 0; - } - description - { - state: left 0.0; - rel1.relative: 0.0 0.3; - rel1.offset: 0 0; - rel2.relative: 0.2 0.7; - rel2.offset: 0 0; - } - description - { - state: full 0.0; - rel1.relative: 0.0 0.0; - rel1.offset: 0 0; - rel2.relative: 1.0 1.0; - rel2.offset: -1 -1; - } - } - part - { - name: "offscreen_right"; - type: SWALLOW; - mouse_events: 1; - description - { - state: default 0.0; - fixed: 1 1; - visible: 0; - rel1.relative: 1.0 0.3; - rel1.offset: 0 0; - rel2.relative: 1.0 0.7; - rel2.offset: 0 0; - } - description - { - state: right 0.0; - visible: 0; - rel1.relative: 0.0 0.3; - rel1.offset: 0 0; - rel2.relative: 0.0 0.7; - rel2.offset: 0 0; - } - description - { - state: left 0.0; - visible: 1; - rel1.relative: 0.8 0.3; - rel1.offset: 0 0; - rel2.relative: 1.0 0.7; - rel2.offset: 0 0; - } - } - } - programs - { - program - { - name: "right"; - signal: "right"; - source: "ephoto"; - action: STATE_SET right 0.0; - transition: LINEAR 0.4; - target: "offscreen_right"; - target: "right"; - target: "center"; - target: "left"; - target: "offscreen_left"; - after: "done"; - } - program - { - name: "left"; - signal: "left"; - source: "ephoto"; - action: STATE_SET left 0.0; - transition: LINEAR 0.4; - target: "offscreen_left"; - target: "left"; - target: "center"; - target: "right"; - target: "offscreen_right"; - after: "done"; - } - program - { - name: "full"; - signal: "full"; - source: "ephoto"; - action: STATE_SET full 0.0; - transition: LINEAR 0.2; - target: "left"; - target: "right"; - target: "center"; - } - program - { - name: "full_reset"; - signal: "full_reset"; - source: "ephoto"; - action: STATE_SET default 0.0; - transition: LINEAR 0.2; - target: "left"; - target: "right"; - target: "center"; - } - program - { - name: "done"; - action: SIGNAL_EMIT "done" "ephoto"; - } - program - { - name: "reset"; - signal: "reset"; - source: "ephoto"; - action: STATE_SET default 0.0; - target: "offscreen_right"; - target: "right"; - target: "center"; - target: "left"; - target: "offscreen_left"; - } - } - } +externals { +external: "elm"; } + +collections { + images + { + image: "thumb_shadow.png" COMP; + } + group + { + name: "elm/layout/ephoto/orient"; + parts + { + part + { + name: "elm.swallow.content"; + type: SWALLOW; + description + { + state: "default" 0.0; + } + description + { + state: "rotate_0" 0.0; + inherit: "default" 0.0; + map + { + on: 1; + rotation.z : 0; + } + } + description + { + state: "rotate_90" 0.0; + inherit: "default" 0.0; + map + { + on: 1; + rotation.z : 90; + } + } + description + { + state: "rotate_180" 0.0; + inherit: "default" 0.0; + map + { + on: 1; + rotation.z : 180; + } + } + description + { + state: "rotate_270" 0.0; + inherit: "default" 0.0; + map + { + on: 1; + rotation.z : 270; + } + } + description + { + state: "flip_horiz" 0.0; + inherit: "default" 0.0; + map + { + on: 1; + rotation.y : 180; + } + } + description + { + state: "flip_vert" 0.0; + inherit: "default" 0.0; + map + { + on: 1; + rotation.x : 180; + } + } + description + { + state: "flip_horiz_90" 0.0; + inherit: "default" 0.0; + map + { + on: 1; + rotation + { + z: 90; + y: 180; + } + } + } + description + { + state: "flip_vert_90" 0.0; + inherit: "default" 0.0; + map + { + on: 1; + rotation + { + z: 90; + x: 180; + } + } + } + } + programs + { + program + { + signal: "state,rotate,0"; + source: "ephoto"; + action: STATE_SET "rotate_0" 0.0; + target: "elm.swallow.content"; + } + program + { + signal: "state,rotate,90"; + source: "ephoto"; + action: STATE_SET "rotate_90" 0.0; + target: "elm.swallow.content"; + } + program + { + signal: "state,rotate,180"; + source: "ephoto"; + action: STATE_SET "rotate_180" 0.0; + target: "elm.swallow.content"; + } + program + { + signal: "state,rotate,270"; + source: "ephoto"; + action: STATE_SET "rotate_270" 0.0; + target: "elm.swallow.content"; + } + program + { + signal: "state,flip,horiz"; + source: "ephoto"; + action: STATE_SET "flip_horiz" 0.0; + target: "elm.swallow.content"; + } + program + { + signal: "state,flip,vert"; + source: "ephoto"; + action: STATE_SET "flip_vert" 0.0; + target: "elm.swallow.content"; + } + program + { + signal: "state,flip,horiz,90"; + source: "ephoto"; + action: STATE_SET "flip_horiz_90" 0.0; + target: "elm.swallow.content"; + } + program + { + signal: "state,flip,vert,90"; + source: "ephoto"; + action: STATE_SET "flip_vert_90" 0.0; + target: "elm.swallow.content"; + } + } + } + } + group + { + name: "ephoto,thumb,grid"; + parts + { + part + { + name: "ephoto.swallow.content.thumb"; + type: SWALLOW; + mouse_events: 1; + description + { + state: "default" 0.0; + rel1.relative : 0.0 0.0; + rel1.offset : 0 0; + rel2.relative : 1.0 1.0; + rel2.offset : -1 -1; + } + } + } + } + group + { + name: "flow_image"; + parts + { + part + { + name: "event"; + type: RECT; + repeat_events: 1; + description + { + state: "default" 0.0; + color: 0 0 0 0; + } + } + part + { + name: "border-shadow"; + type: IMAGE; + mouse_events: 0; + description + { + state: "default" 0.0; + rel1 + { + to: "image"; + offset: -18 -18; + } + rel2 + { + to: "image"; + offset: 17 17; + } + image + { + normal: "thumb_shadow.png"; + border: 17 17 17 17; + middle: NONE; + } + } + } + part + { + name: "border"; + type: RECT; + mouse_events: 0; + description + { + state: "default" 0.0; + rel1 + { + to: "border-shadow"; + offset: 16 16; + } + rel2 + { + to: "border-shadow"; + offset: -15 -15; + } + } + } + part + { + name: "image"; + type: SWALLOW; + mouse_events: 0; + description + { + state: "default" 0.0; + aspect_preference: BOTH; + aspect: 1.0 1.0; + rel1.offset : 0 8; + rel2.offset : -1 -2; + } + } + } + } + group + { + name: "flow"; + parts + { + part + { + name: "offscreen_left"; + type: SWALLOW; + mouse_events: 1; + description + { + state: default 0.0; + fixed: 1 1; + visible: 0; + rel1.relative : 0.0 0.3; + rel1.offset : 0 0; + rel2.relative : 0.0 0.7; + rel2.offset : 0 0; + } + description + { + state: right 0.0; + visible: 1; + rel1.relative : 0.0 0.3; + rel1.offset : 0 0; + rel2.relative : 0.2 0.7; + rel2.offset : 0 0; + } + description + { + state: left 0.0; + visible: 0; + rel1.relative : 1.0 0.3; + rel1.offset : 0 0; + rel2.relative : 1.0 0.7; + rel2.offset : 0 0; + } + } + part + { + name: "left"; + type: SWALLOW; + mouse_events: 1; + description + { + state: default 0.0; + visible: 1; + rel1.relative : 0.0 0.3; + rel1.offset : 0 0; + rel2.relative : 0.2 0.7; + rel2.offset : 0 0; + } + description + { + state: right 0.0; + rel1.relative : 0.2 0.2; + rel1.offset : 0 0; + rel2.relative : 0.8 0.8; + rel2.offset : 0 0; + } + description + { + state: left 0.0; + rel1.relative : 0.0 0.3; + rel1.offset : 0 0; + rel2.relative : 0.0 0.7; + rel2.offset : 0 0; + } + description + { + state: full 0.0; + inherit: default 0.0; + visible: 0; + } + } + part + { + name: "offscreen_right"; + type: SWALLOW; + mouse_events: 1; + description + { + state: default 0.0; + fixed: 1 1; + visible: 0; + rel1.relative : 1.0 0.3; + rel1.offset : 0 0; + rel2.relative : 1.0 0.7; + rel2.offset : 0 0; + } + description + { + state: right 0.0; + visible: 0; + rel1.relative : 0.0 0.3; + rel1.offset : 0 0; + rel2.relative : 0.0 0.7; + rel2.offset : 0 0; + } + description + { + state: left 0.0; + visible: 1; + rel1.relative : 0.8 0.3; + rel1.offset : 0 0; + rel2.relative : 1.0 0.7; + rel2.offset : 0 0; + } + } + part + { + name: "right"; + type: SWALLOW; + mouse_events: 1; + description + { + state: default 0.0; + visible: 1; + rel1.relative : 0.8 0.3; + rel1.offset : 0 0; + rel2.relative : 1.0 0.7; + rel2.offset : 0 0; + } + description + { + state: right 0.0; + rel1.relative : 1.0 0.3; + rel1.offset : 0 0; + rel2.relative : 1.0 0.7; + rel2.offset : 0 0; + } + description + { + state: left 0.0; + rel1.relative : 0.2 0.2; + rel1.offset : 0 0; + rel2.relative : 0.8 0.8; + rel2.offset : 0 0; + } + description + { + state: full 0.0; + inherit: default 0.0; + visible: 0; + } + } + part + { + name: "center"; + type: SWALLOW; + mouse_events: 1; + description + { + state: default 0.0; + rel1.relative : 0.2 0.2; + rel1.offset : 0 0; + rel2.relative : 0.8 0.8; + rel2.offset : 0 0; + } + description + { + state: right 0.0; + rel1.relative : 0.8 0.3; + rel1.offset : 0 0; + rel2.relative : 1.0 0.7; + rel2.offset : 0 0; + } + description + { + state: left 0.0; + rel1.relative : 0.0 0.3; + rel1.offset : 0 0; + rel2.relative : 0.2 0.7; + rel2.offset : 0 0; + } + description + { + state: full 0.0; + rel1.relative : 0.0 0.0; + rel1.offset : 0 0; + rel2.relative : 1.0 1.0; + rel2.offset : -1 -1; + } + } + } + programs + { + program + { + name: "right"; + signal: "right"; + source: "ephoto"; + action: STATE_SET right 0.0; + transition: LINEAR 0.4; + target: "offscreen_right"; + target: "right"; + target: "center"; + target: "left"; + target: "offscreen_left"; + after: "done"; + } + program + { + name: "left"; + signal: "left"; + source: "ephoto"; + action: STATE_SET left 0.0; + transition: LINEAR 0.4; + target: "offscreen_left"; + target: "left"; + target: "center"; + target: "right"; + target: "offscreen_right"; + after: "done"; + } + program + { + name: "full"; + signal: "full"; + source: "ephoto"; + action: STATE_SET full 0.0; + transition: LINEAR 0.2; + target: "left"; + target: "right"; + target: "center"; + } + program + { + name: "full_reset"; + signal: "full_reset"; + source: "ephoto"; + action: STATE_SET default 0.0; + transition: LINEAR 0.2; + target: "left"; + target: "right"; + target: "center"; + } + program + { + name: "done"; + action: SIGNAL_EMIT "done" "ephoto"; + } + program + { + name: "reset"; + signal: "reset"; + source: "ephoto"; + action: STATE_SET default 0.0; + target: "offscreen_right"; + target: "right"; + target: "center"; + target: "left"; + target: "offscreen_left"; + } + } + } +} + diff --git a/data/themes/default/images/Makefile.am b/data/themes/default/images/Makefile.am index 9df1caa..a3b35fc 100644 --- a/data/themes/default/images/Makefile.am +++ b/data/themes/default/images/Makefile.am @@ -1,14 +1,5 @@ MAINTAINERCLEANFILES = Makefile.in EXTRA_DIST = \ -thumb_shadow.png \ -bt_sm_base1.png \ -bt_sm_shine.png \ -bt_sm_hilight.png \ -up-128.png \ -up-256.png \ -up-512.png \ -directory-128.png \ -directory-256.png \ -directory-512.png +thumb_shadow.png diff --git a/data/themes/default/images/bt_sm_base1.png b/data/themes/default/images/bt_sm_base1.png deleted file mode 100644 index c37e182..0000000 Binary files a/data/themes/default/images/bt_sm_base1.png and /dev/null differ diff --git a/data/themes/default/images/bt_sm_hilight.png b/data/themes/default/images/bt_sm_hilight.png deleted file mode 100644 index 63899ca..0000000 Binary files a/data/themes/default/images/bt_sm_hilight.png and /dev/null differ diff --git a/data/themes/default/images/bt_sm_shine.png b/data/themes/default/images/bt_sm_shine.png deleted file mode 100644 index 23bf311..0000000 Binary files a/data/themes/default/images/bt_sm_shine.png and /dev/null differ diff --git a/data/themes/default/images/directory-128.png b/data/themes/default/images/directory-128.png deleted file mode 100644 index b9af5f5..0000000 Binary files a/data/themes/default/images/directory-128.png and /dev/null differ diff --git a/data/themes/default/images/directory-256.png b/data/themes/default/images/directory-256.png deleted file mode 100644 index f47b9ae..0000000 Binary files a/data/themes/default/images/directory-256.png and /dev/null differ diff --git a/data/themes/default/images/directory-512.png b/data/themes/default/images/directory-512.png deleted file mode 100644 index 019fa9d..0000000 Binary files a/data/themes/default/images/directory-512.png and /dev/null differ diff --git a/data/themes/default/images/raise.png b/data/themes/default/images/raise.png deleted file mode 100644 index 61b2ce9..0000000 Binary files a/data/themes/default/images/raise.png and /dev/null differ diff --git a/data/themes/default/images/up-128.png b/data/themes/default/images/up-128.png deleted file mode 100644 index 9bcf119..0000000 Binary files a/data/themes/default/images/up-128.png and /dev/null differ diff --git a/data/themes/default/images/up-256.png b/data/themes/default/images/up-256.png deleted file mode 100644 index b6d4f5a..0000000 Binary files a/data/themes/default/images/up-256.png and /dev/null differ diff --git a/data/themes/default/images/up-512.png b/data/themes/default/images/up-512.png deleted file mode 100644 index d76c564..0000000 Binary files a/data/themes/default/images/up-512.png and /dev/null differ diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am index 721b736..26860e5 100644 --- a/src/bin/Makefile.am +++ b/src/bin/Makefile.am @@ -16,9 +16,12 @@ endif _sources = \ ephoto.c \ ephoto_main.c \ - ephoto_flow_browser.c \ - ephoto_slideshow.c \ - ephoto_thumb_browser.c + ephoto_config.c \ + ephoto_preferences.c \ + ephoto_thumb_browser.c \ + ephoto_single_browser.c \ + ephoto_flow_browser.c \ + ephoto_slideshow.c _libs = @ELEMENTARY_LIBS@ @EFREET_MIME_LIBS@ @EIO_LIBS@ @EXIF_LIBS@ diff --git a/src/bin/ephoto.c b/src/bin/ephoto.c index 24171f0..b0b5cdc 100644 --- a/src/bin/ephoto.c +++ b/src/bin/ephoto.c @@ -1,9 +1,16 @@ -#include "ephoto.h" - +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include #ifndef ELM_LIB_QUICKLAUNCH +#include "ephoto.h" + static void _ephoto_display_usage(void); +/* Global log domain pointer */ +int __log_domain = -1; + EAPI int elm_main(int argc, char **argv) { @@ -22,58 +29,67 @@ elm_main(int argc, char **argv) elm_need_ethumb(); elm_init(argc, argv); - elm_theme_extension_add(NULL, PACKAGE_DATA_DIR "/themes/default/ephoto.edj"); + elm_theme_extension_add(NULL, PACKAGE_DATA_DIR"/themes/default/ephoto.edj"); + + if (!efreet_mime_init()) + fprintf(stderr, "Could not init efreet_mime!\n"); client = elm_thumb_ethumb_client_get(); if (!client) { - printf("Ephoto could not get ethumb_client; Terminating...\n"); + ERR("could not get ethumb_client"); r = 1; - goto end; + goto end_log_domain; } ethumb_client_crop_align_set(client, 0.5, 0.5); ethumb_client_aspect_set(client, ETHUMB_THUMB_CROP); ethumb_client_orientation_set(client, ETHUMB_THUMB_ORIENT_ORIGINAL); + __log_domain = eina_log_domain_register("ephoto", EINA_COLOR_ORANGE); + if (!__log_domain) + { + EINA_LOG_ERR("Could not register log domain: Ephoto"); + r = 1; + goto end_log_domain; + } elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED); + DBG("Logging initialized"); if (argc > 2) { - printf("Too many arguments; Terminating...\n"); + printf("Too Many Arguments!\n"); _ephoto_display_usage(); r = 1; goto end; } - else if (argc == 2) + else if (argc < 2) { - if (!strncmp(argv[1], "--help", 6) || !strncmp(argv[1], "-h", 2)) + Evas_Object *win = ephoto_window_add(NULL); + if (!win) { - _ephoto_display_usage(); - r = 0; + r = 1; goto end; } - else - { - char *real = ecore_file_realpath(argv[1]); - if (!real) - { - printf("Invalid file or directory: '%s'; Terminating...\n", argv[1]); - r = 1; - goto end; - } - if (!ephoto_window_add(real)) - { - printf("Could not create the main window; Terminating...\n"); - goto end; - r = 1; - } - } + } + else if (!strncmp(argv[1], "--help", 6)) + { + _ephoto_display_usage(); + r = 0; + goto end; } else { - if (!ephoto_window_add(NULL)) + char *real = ecore_file_realpath(argv[1]); + if (!real) + { + printf("invalid file or directory: '%s'\n", argv[1]); + r = 1; + goto end; + } + Evas_Object *win = ephoto_window_add(real); + free(real); + if (!win) { - printf("Could not create the main window; Terminating...\n"); r = 1; goto end; } @@ -82,20 +98,25 @@ elm_main(int argc, char **argv) elm_run(); end: + eina_log_domain_unregister(__log_domain); + end_log_domain: + efreet_mime_shutdown(); elm_shutdown(); eio_shutdown(); - + return r; } +/*Display useage commands for ephoto*/ static void _ephoto_display_usage(void) { printf("Ephoto Usage: \n" - "ephoto --help | -h : This page\n" - "ephoto filename : Specifies a file to open\n" - "ephoto directory : Specifies a directory to open\n"); + "ephoto --help : This page\n" + "ephoto filename : Specifies a file to open\n" + "ephoto dirname : Specifies a directory to open\n"); } + #endif ELM_MAIN() diff --git a/src/bin/ephoto.h b/src/bin/ephoto.h index d06905c..b972c50 100644 --- a/src/bin/ephoto.h +++ b/src/bin/ephoto.h @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -15,101 +16,189 @@ #include #include #include -#include #include #include #include #include #include -/*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; +#define THEME_FILE PACKAGE_DATA_DIR"/themes/default/ephoto.edj" + +typedef struct _Ephoto_Config Ephoto_Config; +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; +typedef enum _Ephoto_Orient Ephoto_Orient; + +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); +void ephoto_directory_set(Ephoto *ephoto, const char *path); + +Ephoto_Orient ephoto_file_orient_get(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); + +Evas_Object *ephoto_single_browser_add(Ephoto *ephoto, Evas_Object *parent); +void ephoto_single_browser_entry_set(Evas_Object *obj, Ephoto_Entry *entry); +void ephoto_single_browser_path_pending_set(Evas_Object *obj, const char *path); + /* smart callbacks called: + * "back" - the user wants to go back to the previous screen. + * "slideshow" - the user wants to view a slideshow. + */ + +Evas_Object *ephoto_flow_browser_add(Ephoto *e, Evas_Object *parent); +void ephoto_flow_browser_entry_set(Evas_Object *obj __UNUSED__, Ephoto_Entry *entry); +/* smart callbacks called: + * "back" - the user wants to go back to the previous screen. + * "slideshow" - the user wants to view a slideshow. + */ + +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. + */ + +Evas_Object *ephoto_thumb_browser_add(Ephoto *ephoto, Evas_Object *parent); + +/* smart callbacks called: + * "selected" - an item in the thumb browser is selected. The selected Ephoto_Entry is passed as event_info argument. + */ -/*Ephoto States*/ enum _Ephoto_State { - EPHOTO_STATE_THUMB, - EPHOTO_STATE_FLOW, - EPHOTO_STATE_SLIDESHOW + EPHOTO_STATE_THUMB, + EPHOTO_STATE_FLOW, + EPHOTO_STATE_SINGLE, + EPHOTO_STATE_SLIDESHOW +}; + +enum _Ephoto_Orient /* matches with exif orientation tag */ +{ + EPHOTO_ORIENT_0 = 1, + EPHOTO_ORIENT_FLIP_HORIZ = 2, + EPHOTO_ORIENT_180 = 3, + EPHOTO_ORIENT_FLIP_VERT = 4, + EPHOTO_ORIENT_FLIP_VERT_90 = 5, + EPHOTO_ORIENT_90 = 6, + EPHOTO_ORIENT_FLIP_HORIZ_90 = 7, + EPHOTO_ORIENT_270 = 8 +}; + +/* TODO: split into window & global config, allow multi window + * + * This also requires single instance, as 2 instances changing the + * same configuration will lead to problems. + * + * Single instance is better done as DBus, using FDO standard methods. + */ +struct _Ephoto_Config +{ + int config_version; + const char *editor; + double slideshow_timeout; + const char *slideshow_transition; + + /* these should be per-window */ + int thumb_size; + int thumb_gen_size; + const char *directory; + }; -/*Ephoto Main Structure*/ struct _Ephoto { - /*Main Objects*/ Evas_Object *win; Evas_Object *bg; Evas_Object *pager; - /*Main Children*/ Evas_Object *thumb_browser; Evas_Object *flow_browser; + Evas_Object *single_browser; Evas_Object *slideshow; - /*Main Variables*/ - const char *directory; - Ecore_Job *change_dir; - Ecore_Timer *regen; - Eio_File *ls; Eina_List *entries; + Eina_List *thumbs; /* live thumbs that need to be regenerated on changes */ + + int thumb_gen_size; /* pending value for thumb_regen */ + struct { + Ecore_Timer *thumb_regen; + } timer; + struct { + Ecore_Job *change_dir; + } job; + + Eio_File *ls; + + Evas_Object *prefs_win; Ephoto_State state, prev_state; - Ethumb_Client *client; + + Ephoto_Config *config; }; -/*Ephoto Entry*/ struct _Ephoto_Entry { - /*These variables identify each thumbnail*/ const char *path; - const char *basename; + const char *basename; /* pointer inside path */ const char *label; + Ephoto *ephoto; 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); +Ephoto_Entry *ephoto_entry_new(Ephoto *ephoto, 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(Ephoto *ephoto); -/*Main Children*/ -Evas_Object *ephoto_flow_browser_add(void); -void ephoto_flow_browser_entry_set(Ephoto_Entry *entry); -void ephoto_flow_browser_del(void); +extern int __log_domain; +#define DBG(...) EINA_LOG_DOM_DBG(__log_domain, __VA_ARGS__) +#define INF(...) EINA_LOG_DOM_INFO(__log_domain, __VA_ARGS__) +#define ERR(...) EINA_LOG_DOM_ERR(__log_domain, __VA_ARGS__) -Evas_Object *ephoto_slideshow_add(void); -void ephoto_slideshow_entry_set(Ephoto_Entry *entry); -void ephoto_slideshow_del(void); +static inline Eina_Bool +_ephoto_eina_file_direct_info_image_useful(const Eina_File_Direct_Info *info) +{ + const char /* *type, */ *bname, *ext; -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); + bname = info->path + info->name_start; + if (bname[0] == '.') return EINA_FALSE; + if ((info->type != EINA_FILE_REG) && (info->type != EINA_FILE_UNKNOWN)) + return EINA_FALSE; + + ext = info->path + info->path_length - 1; + for (; ext > bname; ext--) if (*ext == '.') break; + if (*ext == '.') + { + ext++; + if ((strcasecmp(ext, "jpg") == 0) || + (strcasecmp(ext, "jpeg") == 0) || + (strcasecmp(ext, "png") == 0)) + return EINA_TRUE; + } + + return EINA_FALSE; + /* seems that this does not play nice with threads */ + //if (!(type = efreet_mime_type_get(info->path))) return EINA_FALSE; + //return strncmp(type, "image/", sizeof("image/") - 1) == 0; +} -/*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_config.c b/src/bin/ephoto_config.c new file mode 100644 index 0000000..602e2f3 --- /dev/null +++ b/src/bin/ephoto_config.c @@ -0,0 +1,158 @@ +#include "ephoto.h" + +#define CONFIG_VERSION 5 + +static int _ephoto_config_load(Ephoto *ephoto); +static Eina_Bool _ephoto_on_config_save(void *data); + +static Eet_Data_Descriptor *edd = NULL; +static Ecore_Timer *save_timer = NULL; + +Eina_Bool +ephoto_config_init(Ephoto *ephoto) +{ + Eet_Data_Descriptor_Class eddc; + + if (!eet_eina_stream_data_descriptor_class_set(&eddc, sizeof (eddc), "Ephoto_Config", sizeof(Ephoto_Config))) + { + ERR("Unable to create the config data descriptor!"); + return EINA_FALSE; + } + + if (!edd) edd = eet_data_descriptor_stream_new(&eddc); +#undef T +#undef D +#define T Ephoto_Config +#define D edd +#define C_VAL(edd, type, member, dtype) EET_DATA_DESCRIPTOR_ADD_BASIC(edd, type, #member, member, dtype) + C_VAL(D, T, config_version, EET_T_INT); + C_VAL(D, T, thumb_size, EET_T_INT); + C_VAL(D, T, thumb_gen_size, EET_T_INT); + C_VAL(D, T, directory, EET_T_STRING); + C_VAL(D, T, slideshow_timeout, EET_T_DOUBLE); + C_VAL(D, T, slideshow_transition, EET_T_STRING); + C_VAL(D, T, editor, EET_T_STRING); + + switch (_ephoto_config_load(ephoto)) + { + case 0: + /* Start a new config */ + ephoto->config->config_version = CONFIG_VERSION; + ephoto->config->thumb_size = 256; + ephoto->config->thumb_gen_size = 256; + ephoto->config->slideshow_timeout = 4.0; + ephoto->config->slideshow_transition = eina_stringshare_add("fade"); + ephoto->config->editor = eina_stringshare_add("gimp %s"); + break; + + case -1: + /* Incremental additions */ + if (ephoto->config->config_version < 2) + { + ephoto->config->slideshow_timeout = 4.0; + ephoto->config->slideshow_transition = eina_stringshare_add("fade"); + } + if (ephoto->config->config_version < 3) + ephoto->config->editor = eina_stringshare_add("gimp %s"); + + if (ephoto->config->config_version < 5) + ephoto->config->thumb_gen_size = 256; + + ephoto->config->config_version = CONFIG_VERSION; + break; + + default: + return EINA_TRUE; + } + + ephoto_config_save(ephoto, EINA_FALSE); + return EINA_TRUE; +} + +void +ephoto_config_save(Ephoto *ephoto, Eina_Bool instant) +{ + if (save_timer) + { + ecore_timer_del(save_timer); + save_timer = NULL; + } + + if (instant) + _ephoto_on_config_save(ephoto); + else + save_timer = ecore_timer_add(5.0, _ephoto_on_config_save, ephoto); +} + +void +ephoto_config_free(Ephoto *ephoto) +{ + free(ephoto->config); + ephoto->config = NULL; +} + +static int +_ephoto_config_load(Ephoto *ephoto) +{ + Eet_File *ef; + char buf[4096], buf2[4096]; + + snprintf(buf2, sizeof(buf2), "%s/.config/ephoto", getenv("HOME")); + ecore_file_mkpath(buf2); + snprintf(buf, sizeof(buf), "%s/ephoto.cfg", buf2); + + ef = eet_open(buf, EET_FILE_MODE_READ); + if (!ef) + { + ephoto_config_free(ephoto); + ephoto->config = calloc(1, sizeof(Ephoto_Config)); + return 0; + } + + ephoto->config = eet_data_read(ef, edd, "config"); + eet_close(ef); + + if (ephoto->config->config_version > CONFIG_VERSION) + { + ephoto_config_free(ephoto); + ephoto->config = calloc(1, sizeof(Ephoto_Config)); + return 0; + } + + if (ephoto->config->config_version < CONFIG_VERSION) + return -1; + + return 1; +} + +static Eina_Bool +_ephoto_on_config_save(void *data) +{ + Ephoto *ephoto = data; + Eet_File *ef; + char buf[4096], buf2[4096]; + + snprintf(buf, sizeof(buf), "%s/.config/ephoto/ephoto.cfg", getenv("HOME")); + snprintf(buf2, sizeof(buf2), "%s.tmp", buf); + + ef = eet_open(buf2, EET_FILE_MODE_WRITE); + if (!ef) goto save_end; + + eet_data_write(ef, edd, "config", ephoto->config, 1); + if (eet_close(ef)) goto save_end; + + if (!ecore_file_mv(buf2, buf)) goto save_end; + + INF("Config saved"); + +save_end: + ecore_file_unlink(buf2); + + if (save_timer) + { + ecore_timer_del(save_timer); + save_timer = NULL; + } + + return ECORE_CALLBACK_CANCEL; +} diff --git a/src/bin/ephoto_flow_browser.c b/src/bin/ephoto_flow_browser.c index 2519841..b0b1794 100644 --- a/src/bin/ephoto_flow_browser.c +++ b/src/bin/ephoto_flow_browser.c @@ -42,10 +42,11 @@ struct _Ephoto_Flow_Browser } action; }; +Ephoto *ephoto; Ephoto_Flow_Browser *efb; Evas_Object * -ephoto_flow_browser_add(void) +ephoto_flow_browser_add(Ephoto *e, Evas_Object *parent) { int i; @@ -60,7 +61,9 @@ ephoto_flow_browser_add(void) efb->key_down = EINA_FALSE; efb->mouse_wheel = EINA_FALSE; - efb->box = elm_box_add(ephoto->win); + ephoto = e; + + efb->box = elm_box_add(parent); elm_box_horizontal_set(efb->box, EINA_FALSE); elm_box_homogenous_set(efb->box, EINA_FALSE); evas_object_size_hint_weight_set @@ -181,6 +184,8 @@ ephoto_flow_browser_del(void) for (i = 0; i < 5; i++) evas_object_del(efb->images[i]); eina_list_free(efb->items); + if (efb->entry) + ephoto_entry_free_listener_del(efb->entry, _entry_free, NULL); evas_object_del(efb->layout); evas_object_del(efb->toolbar); evas_object_del(efb->box); @@ -188,7 +193,7 @@ ephoto_flow_browser_del(void) } void -ephoto_flow_browser_entry_set(Ephoto_Entry *entry) +ephoto_flow_browser_entry_set(Evas_Object *obj __UNUSED__, Ephoto_Entry *entry) { Eina_Bool same_file = EINA_FALSE; Eina_List *l; @@ -317,7 +322,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(efb->entry); + evas_object_smart_callback_call(efb->box, "back", efb->entry); } static void @@ -390,7 +395,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(efb->entry); + evas_object_smart_callback_call(efb->box, "slideshow", efb->entry); } static void diff --git a/src/bin/ephoto_main.c b/src/bin/ephoto_main.c index 6eb57d0..9694afd 100644 --- a/src/bin/ephoto_main.c +++ b/src/bin/ephoto_main.c @@ -1,25 +1,10 @@ #include "ephoto.h" -/*Ephoto Window Callbacks*/ -static void _ephoto_window_del(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNUSED__); - -/*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); - -/*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 { @@ -27,25 +12,182 @@ struct _Ephoto_Entry_Free_Listener const void *data; }; +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_single_browser_entry_set(ephoto->single_browser, NULL); + ephoto_slideshow_entry_set(ephoto->slideshow, NULL); + elm_pager_content_promote(ephoto->pager, ephoto->thumb_browser); + _ephoto_state_set(ephoto, EPHOTO_STATE_THUMB); + + if ((entry) && (entry->item)) elm_gengrid_item_bring_in(entry->item); +} + +static void +_ephoto_flow_browser_show(Ephoto *ephoto, Ephoto_Entry *entry) +{ + DBG("entry '%s'", entry->path); + ephoto_flow_browser_entry_set(ephoto->flow_browser, entry); + elm_pager_content_promote(ephoto->pager, ephoto->flow_browser); + _ephoto_state_set(ephoto, EPHOTO_STATE_FLOW); +} + +static void +_ephoto_single_browser_show(Ephoto *ephoto, Ephoto_Entry *entry) +{ + DBG("entry '%s'", entry->path); + ephoto_single_browser_entry_set(ephoto->single_browser, entry); + elm_pager_content_promote(ephoto->pager, ephoto->single_browser); + _ephoto_state_set(ephoto, EPHOTO_STATE_SINGLE); +} + +static void +_ephoto_slideshow_show(Ephoto *ephoto, Ephoto_Entry *entry) +{ + DBG("entry '%s'", entry->path); + ephoto_slideshow_entry_set(ephoto->slideshow, entry); + elm_pager_content_promote(ephoto->pager, ephoto->slideshow); + _ephoto_state_set(ephoto, EPHOTO_STATE_SLIDESHOW); +} + +static void +_ephoto_single_browser_back(void *data, Evas_Object *obj __UNUSED__, void *event_info) +{ + Ephoto *ephoto = data; + Ephoto_Entry *entry = event_info; + _ephoto_thumb_browser_show(ephoto, entry); +} + +static void +_ephoto_flow_browser_back(void *data, Evas_Object *obj __UNUSED__, void *event_info) +{ + Ephoto *ephoto = data; + Ephoto_Entry *entry = event_info; + _ephoto_thumb_browser_show(ephoto, entry); +} + +static void +_ephoto_slideshow_back(void *data, Evas_Object *obj __UNUSED__, void *event_info) +{ + Ephoto *ephoto = data; + Ephoto_Entry *entry = event_info; + switch (ephoto->prev_state) + { + case EPHOTO_STATE_SINGLE: + _ephoto_single_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); + } + elm_win_fullscreen_set(ephoto->win, EINA_FALSE); +} + +static void +_ephoto_thumb_browser_view(void *data, Evas_Object *obj __UNUSED__, void *event_info) +{ + Ephoto *ephoto = data; + Ephoto_Entry *entry = event_info; + _ephoto_single_browser_show(ephoto, entry); +} + +static void +_ephoto_thumb_browser_flow(void *data, Evas_Object *obj __UNUSED__, void *event_info) +{ + Ephoto *ephoto = data; + Ephoto_Entry *entry = event_info; + _ephoto_flow_browser_show(ephoto, entry); +} + +static void +_ephoto_thumb_browser_changed_directory(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) +{ + Ephoto *ephoto = data; + ephoto_single_browser_entry_set(ephoto->single_browser, NULL); + ephoto_slideshow_entry_set(ephoto->slideshow, NULL); +} + +static void +_ephoto_thumb_browser_slideshow(void *data, Evas_Object *obj __UNUSED__, 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 __UNUSED__, void *event_info) +{ + Ephoto *ephoto = data; + Ephoto_Entry *entry = event_info; + _ephoto_slideshow_show(ephoto, entry); +} + +static void +_ephoto_single_browser_slideshow(void *data, Evas_Object *obj __UNUSED__, void *event_info) +{ + Ephoto *ephoto = data; + Ephoto_Entry *entry = event_info; + _ephoto_slideshow_show(ephoto, entry); +} + +static void +_win_free(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__) +{ + Ephoto *ephoto = data; + if (ephoto->timer.thumb_regen) ecore_timer_del(ephoto->timer.thumb_regen); + free(ephoto); +} + Evas_Object * ephoto_window_add(const char *path) { + Ephoto *ephoto = calloc(1, sizeof(Ephoto)); + Ethumb_Client *client = elm_thumb_ethumb_client_get(); + char buf[PATH_MAX]; + EINA_SAFETY_ON_NULL_RETURN_VAL(ephoto, NULL); + 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; - evas_object_resize(ephoto->win, 600, 480); - ephoto_title_set("Ephoto"); - evas_object_smart_callback_add - (ephoto->win, "delete,request", _ephoto_window_del, NULL); - evas_object_show(ephoto->win); + { + free(ephoto); + return NULL; + } + + evas_object_event_callback_add + (ephoto->win, EVAS_CALLBACK_FREE, _win_free, ephoto); + + elm_win_autodel_set(ephoto->win, EINA_TRUE); + + if (!ephoto_config_init(ephoto)) + { + evas_object_del(ephoto->win); + return NULL; + } + + if ((ephoto->config->thumb_gen_size != 128) && + (ephoto->config->thumb_gen_size != 256) && + (ephoto->config->thumb_gen_size != 512)) + ephoto_thumb_size_set(ephoto, ephoto->config->thumb_size); + else if (client) + ethumb_client_size_set + (client, ephoto->config->thumb_gen_size, ephoto->config->thumb_gen_size); ephoto->bg = elm_bg_add(ephoto->win); evas_object_size_hint_weight_set @@ -55,7 +197,7 @@ ephoto_window_add(const char *path) evas_object_show(ephoto->bg); ephoto->pager = elm_pager_add(ephoto->win); - elm_object_style_set(ephoto->pager, "fade"); + elm_object_style_set(ephoto->pager, "fade_invisible"); evas_object_size_hint_weight_set (ephoto->pager, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_fill_set @@ -63,95 +205,303 @@ ephoto_window_add(const char *path) elm_win_resize_object_add(ephoto->win, ephoto->pager); evas_object_show(ephoto->pager); - ephoto->slideshow = ephoto_slideshow_add(); - elm_pager_content_push(ephoto->pager, ephoto->slideshow); - - ephoto->flow_browser = ephoto_flow_browser_add(); - elm_pager_content_push(ephoto->pager, ephoto->flow_browser); - - ephoto->thumb_browser = ephoto_thumb_browser_add(); + ephoto->thumb_browser = ephoto_thumb_browser_add(ephoto, ephoto->pager); + if (!ephoto->thumb_browser) + { + ERR("could not add thumb browser"); + evas_object_del(ephoto->win); + return NULL; + } elm_pager_content_push(ephoto->pager, 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, "flow", _ephoto_thumb_browser_flow, ephoto); + evas_object_smart_callback_add + (ephoto->thumb_browser, "changed,directory", + _ephoto_thumb_browser_changed_directory, ephoto); + evas_object_smart_callback_add + (ephoto->thumb_browser, "slideshow", + _ephoto_thumb_browser_slideshow, ephoto); - elm_pager_content_promote(ephoto->pager, ephoto->thumb_browser); - ephoto->state = EPHOTO_STATE_THUMB; + ephoto->flow_browser = ephoto_flow_browser_add(ephoto, ephoto->pager); + if (!ephoto->flow_browser) + { + ERR("could not add flow browser"); + evas_object_del(ephoto->win); + return NULL; + } + elm_pager_content_push(ephoto->pager, 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->single_browser = ephoto_single_browser_add(ephoto, ephoto->pager); + if (!ephoto->single_browser) + { + ERR("could not add single browser"); + evas_object_del(ephoto->win); + return NULL; + } + elm_pager_content_push(ephoto->pager, ephoto->single_browser); + evas_object_smart_callback_add + (ephoto->single_browser, "back", _ephoto_single_browser_back, ephoto); + evas_object_smart_callback_add + (ephoto->single_browser, "slideshow", + _ephoto_single_browser_slideshow, ephoto); + + ephoto->slideshow = ephoto_slideshow_add(ephoto, ephoto->pager); + if (!ephoto->slideshow) + { + ERR("could not add slideshow"); + evas_object_del(ephoto->win); + return NULL; + } + elm_pager_content_push(ephoto->pager, ephoto->slideshow); + evas_object_smart_callback_add + (ephoto->slideshow, "back", _ephoto_slideshow_back, ephoto); if ((!path) || (!ecore_file_exists(path))) { - char buf[PATH_MAX]; - - if (getcwd(buf, sizeof(buf))) - path = buf; - else - path = getenv("HOME"); + path = ephoto->config->directory; + if ((path) && (!ecore_file_exists(path))) path = NULL; + if (!path) + { + if (getcwd(buf, sizeof(buf))) + path = buf; + else + path = getenv("HOME"); + } } + if (ecore_file_is_dir(path)) - ephoto_populate(path); + { + ephoto_directory_set(ephoto, path); + _ephoto_thumb_browser_show(ephoto, NULL); + } else { char *dir = ecore_file_dir_get(path); - ephoto_populate(dir); + ephoto_directory_set(ephoto, dir); free(dir); + ephoto_single_browser_path_pending_set(ephoto->single_browser, path); + + elm_pager_content_promote(ephoto->pager, ephoto->single_browser); + ephoto->state = EPHOTO_STATE_SINGLE; } + + /* TODO restore size from last run as well? */ + evas_object_resize(ephoto->win, 900, 600); + evas_object_show(ephoto->win); + return ephoto->win; } void -ephoto_populate(const char *path) +ephoto_title_set(Ephoto *ephoto, const char *title) { - 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); + char buf[1024] = "Ephoto"; + + if (title) snprintf(buf, sizeof(buf), "%s - Ephoto", title); + elm_win_title_set(ephoto->win, buf); +} + +static void +_ephoto_populate_main(void *data, Eio_File *handler __UNUSED__, const Eina_File_Direct_Info *info) +{ + Ephoto *ephoto = data; + Ephoto_Entry *e; + Ephoto_Event_Entry_Create *ev; + + e = ephoto_entry_new(ephoto, 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 Eina_Bool +_ephoto_populate_filter(void *data __UNUSED__, Eio_File *handler __UNUSED__, const Eina_File_Direct_Info *info) +{ + const char *bname = info->path + info->name_start; + + if (bname[0] == '.') return EINA_FALSE; + + return _ephoto_eina_file_direct_info_image_useful(info); +} + +static void +_ephoto_populate_end(void *data, Eio_File *handler __UNUSED__) +{ + Ephoto *ephoto = data; + ephoto->ls = NULL; + + ecore_event_add(EPHOTO_EVENT_POPULATE_END, NULL, NULL, NULL); +} + +static void +_ephoto_populate_error(void *data, Eio_File *handler, int error) +{ + Ephoto *ephoto = data; + if (error) ERR("could not populate: %s", strerror(error)); + + /* XXX: Perhaps it would be better to _not_ emit POPULATE_END here */ + ecore_event_add(EPHOTO_EVENT_POPULATE_ERROR, NULL, NULL, NULL); + _ephoto_populate_end(ephoto, handler); +} + +static void +_ephoto_populate_entries(Ephoto *ephoto) +{ + /* Edje_External_Param param; */ + DBG("populate from '%s'", ephoto->config->directory); + + ephoto_entries_free(ephoto); + + ephoto->ls = eio_file_stat_ls(ephoto->config->directory, + _ephoto_populate_filter, + _ephoto_populate_main, + _ephoto_populate_end, + _ephoto_populate_error, + ephoto); + + ecore_event_add(EPHOTO_EVENT_POPULATE_START, NULL, NULL, NULL); +} + +static void +_ephoto_change_dir(void *data) +{ + Ephoto *ephoto = data; + ephoto->job.change_dir = NULL; + _ephoto_populate_entries(ephoto); } void -ephoto_title_set(const char *title) +ephoto_directory_set(Ephoto *ephoto, const char *path) { - elm_win_title_set(ephoto->win, title); + EINA_SAFETY_ON_NULL_RETURN(ephoto); + + ephoto_title_set(ephoto, path); + eina_stringshare_replace(&ephoto->config->directory, path); + if (ephoto->job.change_dir) ecore_job_del(ephoto->job.change_dir); + ephoto->job.change_dir = ecore_job_add(_ephoto_change_dir, ephoto); +} + +static Eina_Bool +_thumb_gen_size_changed_timer_cb(void *data) +{ + Ephoto *ephoto = data; + Ethumb_Client *client; + const Eina_List *l; + Evas_Object *o; + + if (ephoto->config->thumb_gen_size == ephoto->thumb_gen_size) goto end; + + INF("thumbnail generation size changed from %d to %d", + ephoto->config->thumb_gen_size, ephoto->thumb_gen_size); + + client = elm_thumb_ethumb_client_get(); + if (!client) + { + DBG("no client yet, try again later"); + return EINA_TRUE; + } + + ephoto->config->thumb_gen_size = ephoto->thumb_gen_size; + ethumb_client_size_set + (client, ephoto->thumb_gen_size, ephoto->thumb_gen_size); + + EINA_LIST_FOREACH(ephoto->thumbs, l, o) + { + Ethumb_Thumb_Format format; + format = (long)evas_object_data_get(o, "ephoto_format"); + ethumb_client_format_set(client, format); + elm_thumb_reload(o); + } + + end: + ephoto->timer.thumb_regen = NULL; + return EINA_FALSE; } void -ephoto_state_set(Ephoto_State state) +ephoto_thumb_size_set(Ephoto *ephoto, int size) { - ephoto->prev_state = ephoto->state; - ephoto->state = state; + if (ephoto->config->thumb_size != size) + { + INF("thumbnail display size changed from %d to %d", + ephoto->config->thumb_size, size); + ephoto->config->thumb_size = size; + ephoto_config_save(ephoto, EINA_FALSE); + } + + if (size <= 128) ephoto->thumb_gen_size = 128; + else if (size <= 256) ephoto->thumb_gen_size = 256; + else ephoto->thumb_gen_size = 512; + + if (ephoto->timer.thumb_regen) ecore_timer_del(ephoto->timer.thumb_regen); + ephoto->timer.thumb_regen = ecore_timer_add + (0.1, _thumb_gen_size_changed_timer_cb, ephoto); +} + +static void +_thumb_del(void *data, Evas *e __UNUSED__, Evas_Object *o, void *event_info __UNUSED__) +{ + Ephoto *ephoto = data; + ephoto->thumbs = eina_list_remove(ephoto->thumbs, o); +} + +Evas_Object * +ephoto_thumb_add(Ephoto *ephoto, Evas_Object *parent, const char *path) +{ + Evas_Object *o; + + EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL); + + o = elm_thumb_add(parent); + if (!o) return NULL; + + if (path) ephoto_thumb_path_set(o, path); + elm_object_style_set(o, "noframe"); + ephoto->thumbs = eina_list_append(ephoto->thumbs, o); + evas_object_event_callback_add(o, EVAS_CALLBACK_DEL, _thumb_del, ephoto); + return o; } void -ephoto_thumb_browser_show(Ephoto_Entry *entry) +ephoto_thumb_path_set(Evas_Object *o, const char *path) { - 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); -} + Ethumb_Thumb_Format format = ETHUMB_THUMB_FDO; + const char *ext = strrchr(path, '.'); + if (ext) + { + ext++; + if ((strcasecmp(ext, "jpg") == 0) || + (strcasecmp(ext, "jpeg") == 0)) + format = ETHUMB_THUMB_JPEG; /* faster! */ + } -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); + ethumb_client_format_set(elm_thumb_ethumb_client_get(), format); + evas_object_data_set(o, "ephoto_format", (void*)(long)format); + elm_thumb_file_set(o, path, NULL); } Ephoto_Entry * -ephoto_entry_new(const char *path, const char *label) +ephoto_entry_new(Ephoto *ephoto, const char *path, const char *label) { Ephoto_Entry *entry; - + EINA_SAFETY_ON_NULL_RETURN_VAL(path, NULL); entry = calloc(1, sizeof(Ephoto_Entry)); + EINA_SAFETY_ON_NULL_RETURN_VAL(entry, NULL); + entry->ephoto = ephoto; entry->path = eina_stringshare_add(path); entry->basename = ecore_file_file_get(entry->path); entry->label = eina_stringshare_add(label); - return entry; } @@ -165,6 +515,7 @@ ephoto_entry_free(Ephoto_Entry *entry) fl->cb((void *)fl->data, entry); free(fl); } + EINA_SAFETY_ON_NULL_RETURN(entry); eina_stringshare_del(entry->path); eina_stringshare_del(entry->label); free(entry); @@ -174,8 +525,10 @@ 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; - + EINA_SAFETY_ON_NULL_RETURN(entry); + EINA_SAFETY_ON_NULL_RETURN(cb); fl = malloc(sizeof(Ephoto_Entry_Free_Listener)); + EINA_SAFETY_ON_NULL_RETURN(fl); fl->cb = cb; fl->data = data; entry->free_listeners = eina_list_append(entry->free_listeners, fl); @@ -186,7 +539,8 @@ ephoto_entry_free_listener_del(Ephoto_Entry *entry, void (*cb)(void *data, const { Eina_List *l; Ephoto_Entry_Free_Listener *fl; - + EINA_SAFETY_ON_NULL_RETURN(entry); + EINA_SAFETY_ON_NULL_RETURN(cb); EINA_LIST_FOREACH(entry->free_listeners, l, fl) { if ((fl->cb == cb) && (fl->data == data)) @@ -199,88 +553,8 @@ ephoto_entry_free_listener_del(Ephoto_Entry *entry, void (*cb)(void *data, const } void -ephoto_entries_free(void) +ephoto_entries_free(Ephoto *ephoto) { 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 *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 -_ephoto_thumb_populate_filter(void *data __UNUSED__, Eio_File *handler __UNUSED__, const Eina_File_Direct_Info *info) -{ - const char *ext; - - ext = strrchr(info->path, '.'); - if (ext) - { - if ((!strncasecmp(ext, ".jpeg", 5)) || - (!strncasecmp(ext, ".jpg", 4)) || - (!strncasecmp(ext, ".png", 4)) || - (!strncasecmp(ext, ".gif", 4)) || - (!strncasecmp(ext, ".svg", 4))) - return EINA_TRUE; - } - return EINA_FALSE; -} - -static void -_ephoto_thumb_populate_main(void *data __UNUSED__, Eio_File *handler __UNUSED__, const Eina_File_Direct_Info *info) -{ - Ephoto_Entry *e; - Ephoto_Event_Entry_Create *ev; - - 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; - - ecore_event_add(EPHOTO_EVENT_POPULATE_END, NULL, NULL, NULL); -} - -static void -_ephoto_thumb_populate_error(void *data __UNUSED__, Eio_File *handler __UNUSED__, int error) -{ - 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_preferences.c b/src/bin/ephoto_preferences.c new file mode 100644 index 0000000..a36c2d1 --- /dev/null +++ b/src/bin/ephoto_preferences.c @@ -0,0 +1,189 @@ +#include "ephoto.h" + +#if 0 +static void _ephoto_preferences_pager_switch(void *data, Evas_Object *obj, void *event_info); +static void _ephoto_preferences_hide(void *data, Evas_Object *obj, void *event_info); +static void _ephoto_preferences_item_change(void *data, Evas_Object *obj, void *event_info); +static void _ephoto_preferences_slideshow_transition(void *data, Evas_Object *obj, void *event_info); + +static void +_ephoto_key_pressed(void *data, Evas *e, Evas_Object *obj, void *event_data) +{ + Evas_Event_Key_Down *eku; + eku = (Evas_Event_Key_Down *)event_data; + if (!strcmp(eku->key, "Escape")) + _ephoto_preferences_hide(data, NULL, NULL); +} + +void +ephoto_show_preferences(Ephoto *em) +{ + if (!em->prefs_win) + { + Evas_Object *o, *tb, *box, *pager, *pg1, *pg2, *pg3, *scr; + const Eina_List *transitions, *l; + const char *transition; + + em->prefs_win = o = elm_win_inwin_add(em->win); + elm_object_style_set(o, "minimal"); + + box = elm_box_add(em->prefs_win); + evas_object_show(box); + evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_win_inwin_content_set(o, box); + + tb = elm_toolbar_add(box); + elm_toolbar_homogenous_set(tb, EINA_FALSE); + evas_object_size_hint_align_set(tb, EVAS_HINT_FILL, 0.5); + + elm_box_pack_end(box, tb); + evas_object_show(tb); + + pager = elm_pager_add(box); + + pg1 = elm_box_add(pager); + evas_object_size_hint_weight_set(pg1, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_show(pg1); + elm_pager_content_push(pager, pg1); + evas_object_data_set(pg1, "pager", pager); + elm_toolbar_item_append(tb, NULL, "General", _ephoto_preferences_pager_switch, pg1); + + elm_box_pack_end(box, pager); + evas_object_show(pager); + + pg2 = elm_table_add(pager); + evas_object_size_hint_weight_set(pg2, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_show(pg2); + elm_pager_content_push(pager, pg2); + evas_object_data_set(pg2, "pager", pager); + elm_toolbar_item_append(tb, NULL, "Slideshow", _ephoto_preferences_pager_switch, pg2); + + o = elm_label_add(pg2); + elm_label_label_set(o, "Delay:"); + evas_object_show(o); + elm_table_pack(pg2, o, 0, 0, 1, 1); + + o = elm_spinner_add(pg2); + elm_spinner_label_format_set(o, "%1.1f seconds"); + elm_spinner_step_set(o, 0.1); + elm_spinner_min_max_set(o, 1.0, 10.0); + elm_spinner_value_set(o, em->config->slideshow_timeout); + evas_object_data_set(o, "config", "slideshow_timeout"); + evas_object_smart_callback_add(o, "delay,changed", + _ephoto_preferences_item_change, em); + evas_object_show(o); + elm_table_pack(pg2, o, 1, 0, 1, 1); + + o = elm_label_add(pg2); + elm_label_label_set(o, "Transition:"); + evas_object_show(o); + elm_table_pack(pg2, o, 0, 1, 1, 1); + + o = elm_hoversel_add(pg2); + elm_hoversel_hover_parent_set(o, em->win); + elm_hoversel_label_set(o, em->config->slideshow_transition); + transitions = elm_slideshow_transitions_get(em->slideshow); + EINA_LIST_FOREACH(transitions, l, transition) + { + elm_hoversel_item_add(o, transition, NULL, ELM_ICON_NONE, _ephoto_preferences_slideshow_transition, em); + } + evas_object_show(o); + elm_table_pack(pg2, o, 1, 1, 1, 1); + + pg3 = elm_box_add(pager); + evas_object_size_hint_weight_set(pg3, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_show(pg3); + elm_pager_content_push(pager, pg3); + evas_object_data_set(pg3, "pager", pager); + elm_toolbar_item_append(tb, NULL, "External Editor", _ephoto_preferences_pager_switch, pg3); + + o = elm_label_add(pg3); + elm_label_label_set(o, "Image editor:"); + elm_box_pack_end(pg3, o); + evas_object_show(o); + + scr = elm_scroller_add(pg3); + elm_box_pack_end(pg3, scr); + elm_scroller_bounce_set(scr, EINA_TRUE, EINA_FALSE); + evas_object_size_hint_weight_set(scr, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(scr, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_show(scr); + + o = elm_entry_add(pg3); + elm_entry_single_line_set(o, EINA_TRUE); + evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_entry_entry_set(o, em->config->editor); + evas_object_data_set(o, "config", "editor"); + evas_object_smart_callback_add(o, "changed", + _ephoto_preferences_item_change, em); + elm_scroller_content_set(scr, o); + evas_object_show(o); + + o = elm_button_add(box); + elm_button_label_set(o, "Close"); + evas_object_size_hint_align_set(o, 1.0, 0.5); + evas_object_smart_callback_add(o, "clicked", _ephoto_preferences_hide, em); + elm_box_pack_end(box, o); + evas_object_show(o); + + + evas_object_event_callback_add(em->prefs_win, EVAS_CALLBACK_KEY_DOWN, + _ephoto_key_pressed, em); + + elm_toolbar_item_selected_set(elm_toolbar_first_item_get(tb), + EINA_TRUE); + elm_pager_content_promote(pager, pg1); + } + + elm_win_inwin_activate(em->prefs_win); + evas_object_focus_set(em->prefs_win, EINA_TRUE); +} + +static void +_ephoto_preferences_pager_switch(void *data, Evas_Object *obj, void *event_info) +{ + Evas_Object *o = data; + Evas_Object *pager = evas_object_data_get(o, "pager"); + + elm_pager_content_promote(pager, o); +} + +static void +_ephoto_preferences_item_change(void *data, Evas_Object *obj, void *event_info) +{ + Ephoto *em = data; + const char *key = evas_object_data_get(obj, "config"); + + if (!strcmp(key, "slideshow_timeout")) + em->config->slideshow_timeout = elm_spinner_value_get(obj); + else if (!strcmp(key, "editor")) + eina_stringshare_replace( + &em->config->editor, + eina_stringshare_add(elm_entry_entry_get(obj))); + + ephoto_config_save(em, EINA_FALSE); +} + +static void +_ephoto_preferences_slideshow_transition(void *data, Evas_Object *obj, void *event_info) +{ + Ephoto *em = data; + Elm_Hoversel_Item *it = event_info; + const char *transition = elm_hoversel_item_label_get(it); + + elm_hoversel_label_set(obj, transition); + em->config->slideshow_transition = transition; + ephoto_config_save(em, EINA_FALSE); +} + +static void +_ephoto_preferences_hide(void *data, Evas_Object *obj, void *event_info) +{ + Ephoto *em = data; + + evas_object_hide(em->prefs_win); + evas_object_focus_set(em->thumb_browser, EINA_TRUE); +} + +#endif diff --git a/src/bin/ephoto_single_browser.c b/src/bin/ephoto_single_browser.c new file mode 100644 index 0000000..01080c3 --- /dev/null +++ b/src/bin/ephoto_single_browser.c @@ -0,0 +1,1025 @@ +#include "ephoto.h" + +#ifdef HAVE_LIBEXIF +#include +#endif + +/* ROTATION is disabled until we do it properly, and properly means + * elm_photocam and elm_image rotates their images internally. + * Rotating the scroller is not correct and was rejected by Raster and others. + */ +//#define ROTATION + +#define ZOOM_STEP 0.2 + +typedef struct _Ephoto_Single_Browser Ephoto_Single_Browser; +typedef struct _Ephoto_Viewer Ephoto_Viewer; + +struct _Ephoto_Single_Browser +{ + Ephoto *ephoto; + Evas_Object *layout; + Evas_Object *edje; + Evas_Object *orient_layout; + Evas_Object *orient_edje; + Evas_Object *viewer; + Evas_Object *toolbar; + struct { + Elm_Toolbar_Item *back; + Elm_Toolbar_Item *zoom_in; + Elm_Toolbar_Item *zoom_out; + Elm_Toolbar_Item *zoom_1; + Elm_Toolbar_Item *zoom_fit; + Elm_Toolbar_Item *go_first; + Elm_Toolbar_Item *go_prev; + Elm_Toolbar_Item *go_next; + Elm_Toolbar_Item *go_last; +#ifdef ROTATION + Elm_Toolbar_Item *rotate_counterclock; + Elm_Toolbar_Item *rotate_clock; + Elm_Toolbar_Item *flip_horiz; + Elm_Toolbar_Item *flip_vert; +#endif + Elm_Toolbar_Item *slideshow; + } action; + const char *pending_path; + Ephoto_Entry *entry; + Ephoto_Orient orient; + Eina_List *handlers; +}; + +struct _Ephoto_Viewer +{ + Evas_Object *photocam; + Evas_Object *scroller; + Evas_Object *image; + double zoom; + Eina_Bool fit:1; +}; + +static void _zoom_set(Ephoto_Single_Browser *sb, double zoom); +static void _zoom_in(Ephoto_Single_Browser *sb); +static void _zoom_out(Ephoto_Single_Browser *sb); + +static Eina_Bool +_path_is_jpeg(const char *path_stringshared) +{ + size_t len = eina_stringshare_strlen(path_stringshared); + const char *ext; + + if (len < sizeof(".jpg")) return EINA_FALSE; + ext = path_stringshared + len - (sizeof(".jpg") - 1); + if (strcasecmp(ext, ".jpg") == 0) return EINA_TRUE; + + if (len < sizeof(".jpeg")) return EINA_FALSE; + ext = path_stringshared + len - (sizeof(".jpeg") - 1); + if (strcasecmp(ext, ".jpeg") == 0) return EINA_TRUE; + + return EINA_FALSE; +} + +static void +_viewer_photocam_loaded(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__) +{ + elm_photocam_paused_set(obj, EINA_FALSE); +} + +static void +_viewer_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) +{ + Ephoto_Viewer *v = data; + free(v); +} + +static Evas_Object * +_viewer_add(Evas_Object *parent, const char *path) +{ + Ephoto_Viewer *v = calloc(1, sizeof(Ephoto_Viewer)); + Evas_Object *obj; + int err; + + EINA_SAFETY_ON_NULL_RETURN_VAL(v, NULL); + if (_path_is_jpeg(path)) + { + obj = v->photocam = elm_photocam_add(parent); + EINA_SAFETY_ON_NULL_GOTO(obj, error); + err = elm_photocam_file_set(obj, path); + if (err != EVAS_LOAD_ERROR_NONE) goto load_error; + elm_photocam_paused_set(obj, EINA_TRUE); + evas_object_smart_callback_add + (obj, "loaded", _viewer_photocam_loaded, v); + } + else + { + Evas_Coord w, h; + obj = v->scroller = elm_scroller_add(parent); + EINA_SAFETY_ON_NULL_GOTO(obj, error); + v->image = evas_object_image_filled_add(evas_object_evas_get(parent)); + evas_object_image_file_set(v->image, path, NULL); + err = evas_object_image_load_error_get(v->image); + if (err != EVAS_LOAD_ERROR_NONE) goto load_error; + evas_object_image_size_get(v->image, &w, &h); + evas_object_size_hint_align_set(v->image, 0.5, 0.5); + evas_object_size_hint_min_set(v->image, w, h); + evas_object_size_hint_max_set(v->image, w, h); + evas_object_resize(v->image, w, h); + evas_object_show(v->image); + elm_scroller_content_set(obj, v->image); + } + + evas_object_size_hint_weight_set(obj, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(obj, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_data_set(obj, "viewer", v); + evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL, _viewer_del, v); + return obj; + + load_error: + ERR("could not load image '%s': %s", path, evas_load_error_str(err)); + evas_object_del(obj); + error: + free(v); + return NULL; +} + +static void +_viewer_zoom_apply(Ephoto_Viewer *v, double zoom) +{ + v->zoom = zoom; + if (v->photocam) elm_photocam_zoom_set(v->photocam, 1.0 / zoom); + else + { + Evas_Coord w, h; + evas_object_image_size_get(v->image, &w, &h); + w *= zoom; + h *= zoom; + evas_object_size_hint_min_set(v->image, w, h); + evas_object_size_hint_max_set(v->image, w, h); + } +} + +static void +_viewer_zoom_fit_apply(Ephoto_Viewer *v) +{ + Evas_Coord cw, ch, iw, ih; + double zx, zy, zoom; + + if (v->photocam) + { + evas_object_geometry_get(v->photocam, NULL, NULL, &cw, &ch); + elm_photocam_image_size_get(v->photocam, &iw, &ih); + } + else + { + evas_object_geometry_get(v->scroller, NULL, NULL, &cw, &ch); + evas_object_image_size_get(v->image, &iw, &ih); + } + + if ((cw <= 0) || (ch <= 0)) return; /* object still not resized */ + EINA_SAFETY_ON_TRUE_RETURN(iw <= 0); + EINA_SAFETY_ON_TRUE_RETURN(ih <= 0); + + zx = (double)cw / (double)iw; + zy = (double)ch / (double)ih; + + zoom = (zx < zy) ? zx : zy; + _viewer_zoom_apply(v, zoom); +} + +static void +_viewer_resized(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) +{ + _viewer_zoom_fit_apply(data); +} + +static void +_viewer_zoom_set(Evas_Object *obj, double zoom) +{ + Ephoto_Viewer *v = evas_object_data_get(obj, "viewer"); + EINA_SAFETY_ON_NULL_RETURN(v); + _viewer_zoom_apply(v, zoom); + + if (v->fit) + { + if (v->photocam) + evas_object_event_callback_del_full + (v->photocam, EVAS_CALLBACK_RESIZE, _viewer_resized, v); + else + evas_object_event_callback_del_full + (v->scroller, EVAS_CALLBACK_RESIZE, _viewer_resized, v); + v->fit = EINA_FALSE; + } +} + +static double +_viewer_zoom_get(Evas_Object *obj) +{ + Ephoto_Viewer *v = evas_object_data_get(obj, "viewer"); + EINA_SAFETY_ON_NULL_RETURN_VAL(v, 0.0); + return v->zoom; +} + +static void +_viewer_zoom_fit(Evas_Object *obj) +{ + Ephoto_Viewer *v = evas_object_data_get(obj, "viewer"); + EINA_SAFETY_ON_NULL_RETURN(v); + + if (v->fit) return; + v->fit = EINA_TRUE; + + if (v->photocam) + evas_object_event_callback_add + (v->photocam, EVAS_CALLBACK_RESIZE, _viewer_resized, v); + else + evas_object_event_callback_add + (v->scroller, EVAS_CALLBACK_RESIZE, _viewer_resized, v); + + _viewer_zoom_fit_apply(v); +} + +static void +_orient_apply(Ephoto_Single_Browser *sb) +{ +#ifdef ROTATION + const char *sig; + switch (sb->orient) + { + case EPHOTO_ORIENT_0: + sig = "state,rotate,0"; + break; + case EPHOTO_ORIENT_90: + sig = "state,rotate,90"; + break; + case EPHOTO_ORIENT_180: + sig = "state,rotate,180"; + break; + case EPHOTO_ORIENT_270: + sig = "state,rotate,270"; + break; + case EPHOTO_ORIENT_FLIP_HORIZ: + sig = "state,flip,horiz"; + break; + case EPHOTO_ORIENT_FLIP_VERT: + sig = "state,flip,vert"; + break; + case EPHOTO_ORIENT_FLIP_HORIZ_90: + sig = "state,flip,horiz,90"; + break; + case EPHOTO_ORIENT_FLIP_VERT_90: + sig = "state,flip,vert,90"; + break; + default: + return; + } + DBG("orient: %d, signal '%s'", sb->orient, sig); + edje_object_signal_emit(sb->orient_edje, sig, "ephoto"); +#else + (void)sb; +#endif +} + +#ifdef ROTATION +static void +_rotate_counterclock(Ephoto_Single_Browser *sb) +{ + switch (sb->orient) + { + case EPHOTO_ORIENT_0: + sb->orient = EPHOTO_ORIENT_270; + break; + case EPHOTO_ORIENT_90: + sb->orient = EPHOTO_ORIENT_0; + break; + case EPHOTO_ORIENT_180: + sb->orient = EPHOTO_ORIENT_90; + break; + case EPHOTO_ORIENT_270: + sb->orient = EPHOTO_ORIENT_180; + break; + case EPHOTO_ORIENT_FLIP_HORIZ: + sb->orient = EPHOTO_ORIENT_FLIP_HORIZ_90; + break; + case EPHOTO_ORIENT_FLIP_VERT: + sb->orient = EPHOTO_ORIENT_FLIP_VERT_90; + break; + case EPHOTO_ORIENT_FLIP_HORIZ_90: + sb->orient = EPHOTO_ORIENT_FLIP_VERT; + break; + case EPHOTO_ORIENT_FLIP_VERT_90: + sb->orient = EPHOTO_ORIENT_FLIP_HORIZ; + break; + } + _orient_apply(sb); +} + +static void +_rotate_clock(Ephoto_Single_Browser *sb) +{ + switch (sb->orient) + { + case EPHOTO_ORIENT_0: + sb->orient = EPHOTO_ORIENT_90; + break; + case EPHOTO_ORIENT_90: + sb->orient = EPHOTO_ORIENT_180; + break; + case EPHOTO_ORIENT_180: + sb->orient = EPHOTO_ORIENT_270; + break; + case EPHOTO_ORIENT_270: + sb->orient = EPHOTO_ORIENT_0; + break; + case EPHOTO_ORIENT_FLIP_HORIZ: + sb->orient = EPHOTO_ORIENT_FLIP_VERT_90; + break; + case EPHOTO_ORIENT_FLIP_VERT: + sb->orient = EPHOTO_ORIENT_FLIP_HORIZ_90; + break; + case EPHOTO_ORIENT_FLIP_HORIZ_90: + sb->orient = EPHOTO_ORIENT_FLIP_HORIZ; + break; + case EPHOTO_ORIENT_FLIP_VERT_90: + sb->orient = EPHOTO_ORIENT_FLIP_VERT; + break; + } + _orient_apply(sb); +} + +static void +_flip_horiz(Ephoto_Single_Browser *sb) +{ + switch (sb->orient) + { + case EPHOTO_ORIENT_0: + sb->orient = EPHOTO_ORIENT_FLIP_HORIZ; + break; + case EPHOTO_ORIENT_90: + sb->orient = EPHOTO_ORIENT_FLIP_HORIZ_90; + break; + case EPHOTO_ORIENT_180: + sb->orient = EPHOTO_ORIENT_FLIP_VERT; + break; + case EPHOTO_ORIENT_270: + sb->orient = EPHOTO_ORIENT_FLIP_VERT_90; + break; + case EPHOTO_ORIENT_FLIP_HORIZ: + sb->orient = EPHOTO_ORIENT_0; + break; + case EPHOTO_ORIENT_FLIP_VERT: + sb->orient = EPHOTO_ORIENT_180; + break; + case EPHOTO_ORIENT_FLIP_HORIZ_90: + sb->orient = EPHOTO_ORIENT_90; + break; + case EPHOTO_ORIENT_FLIP_VERT_90: + sb->orient = EPHOTO_ORIENT_270; + break; + } + _orient_apply(sb); +} + +static void +_flip_vert(Ephoto_Single_Browser *sb) +{ + switch (sb->orient) + { + case EPHOTO_ORIENT_0: + sb->orient = EPHOTO_ORIENT_FLIP_VERT; + break; + case EPHOTO_ORIENT_90: + sb->orient = EPHOTO_ORIENT_FLIP_VERT_90; + break; + case EPHOTO_ORIENT_180: + sb->orient = EPHOTO_ORIENT_FLIP_HORIZ; + break; + case EPHOTO_ORIENT_270: + sb->orient = EPHOTO_ORIENT_FLIP_HORIZ_90; + break; + case EPHOTO_ORIENT_FLIP_HORIZ: + sb->orient = EPHOTO_ORIENT_180; + break; + case EPHOTO_ORIENT_FLIP_VERT: + sb->orient = EPHOTO_ORIENT_0; + break; + case EPHOTO_ORIENT_FLIP_HORIZ_90: + sb->orient = EPHOTO_ORIENT_270; + break; + case EPHOTO_ORIENT_FLIP_VERT_90: + sb->orient = EPHOTO_ORIENT_90; + break; + } + _orient_apply(sb); +} +#endif + +static void +_mouse_wheel(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info) +{ + Ephoto_Single_Browser *sb = data; + Evas_Event_Mouse_Wheel *ev = event_info; + if (!evas_key_modifier_is_set(ev->modifiers, "Control")) return; + + if (ev->z > 0) _zoom_in(sb); + else _zoom_out(sb); +} + +static Ephoto_Entry * +_first_entry_find(Ephoto_Single_Browser *sb) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(sb->ephoto, NULL); + + return eina_list_nth(sb->ephoto->entries, 0); +} + +static Ephoto_Entry * +_last_entry_find(Ephoto_Single_Browser *sb) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(sb->ephoto, NULL); + + return eina_list_data_get(eina_list_last(sb->ephoto->entries)); +} + +static void +_ephoto_single_browser_toolbar_eval(Ephoto_Single_Browser *sb) +{ + if (!sb->entry) + { + elm_toolbar_item_disabled_set(sb->action.go_first, EINA_TRUE); + elm_toolbar_item_disabled_set(sb->action.go_prev, EINA_TRUE); + elm_toolbar_item_disabled_set(sb->action.go_next, EINA_TRUE); + elm_toolbar_item_disabled_set(sb->action.go_last, EINA_TRUE); + elm_toolbar_item_disabled_set(sb->action.slideshow, EINA_TRUE); + } + else + { + Eina_Bool is_first = sb->entry == _first_entry_find(sb); + Eina_Bool is_last = sb->entry == _last_entry_find(sb); + + elm_toolbar_item_disabled_set(sb->action.go_first, is_first); + elm_toolbar_item_disabled_set(sb->action.go_prev, is_first); + elm_toolbar_item_disabled_set(sb->action.go_next, is_last); + elm_toolbar_item_disabled_set(sb->action.go_last, is_last); + elm_toolbar_item_disabled_set(sb->action.slideshow, EINA_FALSE); + } +} + +Ephoto_Orient +ephoto_file_orient_get(const char *path) +{ +#ifndef HAVE_LIBEXIF + return EPHOTO_ORIENT_0; +#else + Ephoto_Orient orient = EPHOTO_ORIENT_0; + ExifData *exif; + ExifEntry *entry; + ExifByteOrder bo; + + if (!_path_is_jpeg(path)) return orient; + + exif = exif_data_new_from_file(path); + if (!exif) goto end; + bo = exif_data_get_byte_order(exif); + entry = exif_data_get_entry(exif, EXIF_TAG_ORIENTATION); + if (!entry) goto end_entry; + + orient = exif_get_short(entry->data, bo); + DBG("orient=%d", orient); + if ((orient < 1) || (orient > 8)) + { + ERR("exif orient not supported: %d", orient); + orient = EPHOTO_ORIENT_0; + } + + end_entry: + exif_data_free(exif); + end: + return orient; +#endif +} + +static void +_ephoto_single_browser_recalc(Ephoto_Single_Browser *sb) +{ + if (sb->viewer) + { + evas_object_del(sb->viewer); + sb->viewer = NULL; + } + + if (sb->entry) + { + const char *bname = ecore_file_file_get(sb->entry->path); + sb->viewer = _viewer_add(sb->orient_layout, sb->entry->path); + elm_layout_content_set + (sb->orient_layout, "elm.swallow.content", sb->viewer); + evas_object_show(sb->viewer); + evas_object_event_callback_add + (sb->viewer, EVAS_CALLBACK_MOUSE_WHEEL, _mouse_wheel, sb); + edje_object_part_text_set(sb->edje, "elm.text.title", bname); + ephoto_title_set(sb->ephoto, bname); + sb->orient = ephoto_file_orient_get(sb->entry->path); + _orient_apply(sb); + } + + elm_object_focus(sb->layout); + + _ephoto_single_browser_toolbar_eval(sb); +} + +static void +_zoom_set(Ephoto_Single_Browser *sb, double zoom) +{ + DBG("zoom %f", zoom); + if (zoom <= 0.0) return; + _viewer_zoom_set(sb->viewer, zoom); +} + +static void +_zoom_fit(Ephoto_Single_Browser *sb) +{ + if (sb->viewer) _viewer_zoom_fit(sb->viewer); +} + +static void +_zoom_in(Ephoto_Single_Browser *sb) +{ + double change = (1.0 + ZOOM_STEP); + _viewer_zoom_set(sb->viewer, _viewer_zoom_get(sb->viewer) * change); +} + +static void +_zoom_out(Ephoto_Single_Browser *sb) +{ + double change = (1.0 - ZOOM_STEP); + _viewer_zoom_set(sb->viewer, _viewer_zoom_get(sb->viewer) * change); +} + +static void +_zoom_in_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__) +{ + Ephoto_Single_Browser *sb = data; + elm_toolbar_item_selected_set(sb->action.zoom_in, EINA_FALSE); + _zoom_in(sb); +} + +static void +_zoom_out_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__) +{ + Ephoto_Single_Browser *sb = data; + elm_toolbar_item_selected_set(sb->action.zoom_out, EINA_FALSE); + _zoom_out(sb); +} + +static void +_zoom_1_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__) +{ + Ephoto_Single_Browser *sb = data; + elm_toolbar_item_selected_set(sb->action.zoom_1, EINA_FALSE); + _zoom_set(sb, 1.0); +} + +static void +_zoom_fit_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__) +{ + Ephoto_Single_Browser *sb = data; + elm_toolbar_item_selected_set(sb->action.zoom_fit, EINA_FALSE); + _zoom_fit(sb); +} + +static int +_entry_cmp(const void *pa, const void *pb) +{ + const Ephoto_Entry *a = pa; + const char *path = pb; + + if (path == a->path) + return 0; + else + return strcoll(a->path, path); +} + +static void +_next_entry(Ephoto_Single_Browser *sb) +{ + Ephoto_Entry *entry = NULL; + Eina_List *node; + EINA_SAFETY_ON_NULL_RETURN(sb->entry); + + node = eina_list_search_sorted_list(sb->ephoto->entries, _entry_cmp, sb->entry->path); + if (!node) return; + while ((node = node->next)) + { + entry = node->data; + } + if (!entry) + entry = _first_entry_find(sb); + if (entry) + { + DBG("next is '%s'", entry->path); + ephoto_single_browser_entry_set(sb->layout, entry); + } +} + +static void +_prev_entry(Ephoto_Single_Browser *sb) +{ + Eina_List *node; + Ephoto_Entry *entry = NULL; + EINA_SAFETY_ON_NULL_RETURN(sb->entry); + + node = eina_list_search_sorted_list(sb->ephoto->entries, _entry_cmp, sb->entry->path); + if (!node) return; + while ((node = node->prev)) + { + entry = node->data; + } + if (!entry) + entry = _last_entry_find(sb); + if (entry) + { + DBG("prev is '%s'", entry->path); + ephoto_single_browser_entry_set(sb->layout, entry); + } +} + +static void +_first_entry(Ephoto_Single_Browser *sb) +{ + Ephoto_Entry *entry = _first_entry_find(sb); + if (!entry) return; + DBG("first is '%s'", entry->path); + ephoto_single_browser_entry_set(sb->layout, entry); +} + +static void +_last_entry(Ephoto_Single_Browser *sb) +{ + Ephoto_Entry *entry = _last_entry_find(sb); + if (!entry) return; + DBG("last is '%s'", entry->path); + ephoto_single_browser_entry_set(sb->layout, entry); +} + +static void +_go_first(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__) +{ + Ephoto_Single_Browser *sb = data; + elm_toolbar_item_selected_set(sb->action.go_first, EINA_FALSE); + _first_entry(sb); +} + +static void +_go_prev(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__) +{ + Ephoto_Single_Browser *sb = data; + elm_toolbar_item_selected_set(sb->action.go_prev, EINA_FALSE); + _prev_entry(sb); +} + +static void +_go_next(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__) +{ + Ephoto_Single_Browser *sb = data; + elm_toolbar_item_selected_set(sb->action.go_next, EINA_FALSE); + _next_entry(sb); +} + +static void +_go_last(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__) +{ + Ephoto_Single_Browser *sb = data; + elm_toolbar_item_selected_set(sb->action.go_last, EINA_FALSE); + _last_entry(sb); +} + +#ifdef ROTATION +static void +_go_rotate_counterclock(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__) +{ + Ephoto_Single_Browser *sb = data; + elm_toolbar_item_selected_set(sb->action.rotate_counterclock, EINA_FALSE); + _rotate_counterclock(sb); +} + +static void +_go_rotate_clock(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__) +{ + Ephoto_Single_Browser *sb = data; + elm_toolbar_item_selected_set(sb->action.rotate_clock, EINA_FALSE); + _rotate_clock(sb); +} + +static void +_go_flip_horiz(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__) +{ + Ephoto_Single_Browser *sb = data; + elm_toolbar_item_selected_set(sb->action.flip_horiz, EINA_FALSE); + _flip_horiz(sb); +} + +static void +_go_flip_vert(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__) +{ + Ephoto_Single_Browser *sb = data; + elm_toolbar_item_selected_set(sb->action.flip_vert, EINA_FALSE); + _flip_vert(sb); +} +#endif + +static void +_slideshow(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__) +{ + Ephoto_Single_Browser *sb = data; + elm_toolbar_item_selected_set(sb->action.slideshow, EINA_FALSE); + if (sb->entry) + evas_object_smart_callback_call(sb->layout, "slideshow", sb->entry); +} + +static void +_back(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__) +{ + Ephoto_Single_Browser *sb = data; + elm_toolbar_item_selected_set(sb->action.back, EINA_FALSE); + evas_object_smart_callback_call(sb->layout, "back", sb->entry); +} + +static void +_key_down(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info) +{ + Ephoto_Single_Browser *sb = data; + Evas_Event_Key_Down *ev = event_info; + Eina_Bool ctrl = evas_key_modifier_is_set(ev->modifiers, "Control"); + Eina_Bool shift = evas_key_modifier_is_set(ev->modifiers, "Shift"); + const char *k = ev->keyname; + + DBG("key pressed '%s'", k); + if (ctrl) + { + if ((!strcmp(k, "plus")) || (!strcmp(k, "equal"))) + _zoom_in(sb); + else if (!strcmp(k, "minus")) + _zoom_out(sb); + else if (!strcmp(k, "0")) + { + if (shift) _zoom_fit(sb); + else _zoom_set(sb, 1.0); + } + + return; + } + + if (!strcmp(k, "Escape")) + evas_object_smart_callback_call(sb->layout, "back", sb->entry); + else if (!strcmp(k, "Left") || !strcmp(k, "BackSpace")) + _prev_entry(sb); + else if (!strcmp(k, "Right") || !strcmp(k, "space")) + _next_entry(sb); + else if (!strcmp(k, "Home")) + _first_entry(sb); + else if (!strcmp(k, "End")) + _last_entry(sb); +#if ROTATION + else if (!strcmp(k, "bracketleft")) + { + if (!shift) _rotate_counterclock(sb); + else _flip_horiz(sb); + } + else if (!strcmp(k, "bracketright")) + { + if (!shift) _rotate_clock(sb); + else _flip_vert(sb); + } +#endif + else if (!strcmp(k, "F5")) + { + if (sb->entry) + evas_object_smart_callback_call(sb->layout, "slideshow", sb->entry); + } +} + +static void +_entry_free(void *data, const Ephoto_Entry *entry __UNUSED__) +{ + Ephoto_Single_Browser *sb = data; + sb->entry = NULL; +} + +static void +_layout_del(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__) +{ + Ephoto_Single_Browser *sb = data; + Ecore_Event_Handler *handler; + + EINA_LIST_FREE(sb->handlers, handler) + ecore_event_handler_del(handler); + if (sb->entry) + ephoto_entry_free_listener_del(sb->entry, _entry_free, sb); + if (sb->pending_path) + eina_stringshare_del(sb->pending_path); + free(sb); +} + +static Elm_Toolbar_Item * +_toolbar_item_add(Ephoto_Single_Browser *sb, const char *icon, const char *label, int priority, Evas_Smart_Cb cb) +{ + Elm_Toolbar_Item *item = elm_toolbar_item_append(sb->toolbar, icon, label, + cb, sb); + elm_toolbar_item_priority_set(item, priority); + return item; +} + +static Elm_Toolbar_Item * +_toolbar_item_separator_add(Ephoto_Single_Browser *sb) +{ + Elm_Toolbar_Item *it = elm_toolbar_item_append + (sb->toolbar, NULL, NULL, NULL, NULL); + elm_toolbar_item_separator_set(it, EINA_TRUE); + return it; +} + +static Eina_Bool +_ephoto_single_populate_end(void *data, int type __UNUSED__, void *event __UNUSED__) +{ + Ephoto_Single_Browser *sb = data; + + _ephoto_single_browser_toolbar_eval(sb); + + return ECORE_CALLBACK_PASS_ON; +} + +static Eina_Bool +_ephoto_single_entry_create(void *data, int type __UNUSED__, void *event __UNUSED__) +{ + Ephoto_Single_Browser *sb = data; + Ephoto_Event_Entry_Create *ev = event; + Ephoto_Entry *e; + + e = ev->entry; + if (!sb->entry && sb->pending_path && e->path == sb->pending_path) + { + DBG("Adding entry %p for path %s", e, sb->pending_path); + + eina_stringshare_del(sb->pending_path); + sb->pending_path = NULL; + ephoto_single_browser_entry_set(sb->ephoto->single_browser, e); + } + + return ECORE_CALLBACK_PASS_ON; +} + +Evas_Object * +ephoto_single_browser_add(Ephoto *ephoto, Evas_Object *parent) +{ + Evas_Object *layout = elm_layout_add(parent), *button; + Ephoto_Single_Browser *sb; + + EINA_SAFETY_ON_NULL_RETURN_VAL(layout, NULL); + + sb = calloc(1, sizeof(Ephoto_Single_Browser)); + EINA_SAFETY_ON_NULL_GOTO(sb, error); + sb->ephoto = ephoto; + sb->layout = layout; + sb->edje = elm_layout_edje_get(layout); + evas_object_event_callback_add(layout, EVAS_CALLBACK_DEL, _layout_del, sb); + evas_object_event_callback_add + (layout, EVAS_CALLBACK_KEY_DOWN, _key_down, sb); + evas_object_data_set(layout, "single_browser", sb); + + if (!elm_layout_theme_set + (layout, "layout", "application", "toolbar-content-back")) + { + ERR("could not load style 'toolbar-content-back' from theme"); + goto error; + } + + /*TODO This is hack. Better Idea?*/ + button = edje_object_part_external_object_get(sb->edje, "back"); + evas_object_del(button); + + sb->toolbar = edje_object_part_external_object_get + (sb->edje, "elm.external.toolbar"); + if (!sb->toolbar) + { + ERR("no toolbar in layout!"); + goto error; + } + elm_toolbar_homogenous_set(sb->toolbar, EINA_FALSE); + elm_toolbar_mode_shrink_set(sb->toolbar, ELM_TOOLBAR_SHRINK_MENU); + elm_toolbar_menu_parent_set(sb->toolbar, parent); + + sb->action.back = _toolbar_item_add + (sb, "edit-undo", "Back", 200, _back); + + _toolbar_item_separator_add(sb); + + sb->action.slideshow = _toolbar_item_add + (sb, "media-playback-start", "Slideshow", 150, _slideshow); + + sb->action.zoom_in = _toolbar_item_add + (sb, "zoom-in", "Zoom In", 100, _zoom_in_cb); + sb->action.zoom_out = _toolbar_item_add + (sb, "zoom-out", "Zoom Out", 80, _zoom_out_cb); + sb->action.zoom_1 = _toolbar_item_add + (sb, "zoom-original", "Zoom 1:1", 50, _zoom_1_cb); + sb->action.zoom_fit = _toolbar_item_add + (sb, "zoom-fit-best", "Zoom Fit", 40, _zoom_fit_cb); + + _toolbar_item_separator_add(sb); + + sb->action.go_first = _toolbar_item_add(sb, "go-first", "First", 50, _go_first); + sb->action.go_prev = _toolbar_item_add + (sb, "go-previous", "Previous", 100, _go_prev); + sb->action.go_next = _toolbar_item_add(sb, "go-next", "Next", 50, _go_next); + sb->action.go_last = _toolbar_item_add(sb, "go-last", "Last", 50, _go_last); + + _toolbar_item_separator_add(sb); + +#ifdef ROTATION + sb->action.rotate_counterclock = _toolbar_item_add + (sb, "object-rotate-left", "Rotate Left", 50, _go_rotate_counterclock); + sb->action.rotate_clock = _toolbar_item_add + (sb, "object-rotate-right", "Rotate Right", 30, _go_rotate_clock); + sb->action.flip_horiz = _toolbar_item_add + (sb, "object-flip-horizontal", "Flip Horiz.", 30, _go_flip_horiz); + sb->action.flip_vert = _toolbar_item_add + (sb, "object-flip-vertical", "Flip Vert.", 30, _go_flip_vert); + + elm_toolbar_item_tooltip_text_set + (sb->action.rotate_counterclock, + "Rotate object to the left (counter-clockwise)"); + elm_toolbar_item_tooltip_text_set + (sb->action.rotate_clock, "Rotate object to the right (clockwise)"); + + elm_toolbar_item_tooltip_text_set + (sb->action.flip_horiz, "Flip object horizontally"); + elm_toolbar_item_tooltip_text_set + (sb->action.flip_vert, "Flip object vertically"); +#endif + + sb->orient_layout = elm_layout_add(layout); + if (!elm_layout_theme_set + (sb->orient_layout, "layout", "ephoto", "orient")) + { + ERR("could not load style 'ephoto/orient' from theme"); + goto error; + } + sb->orient_edje = elm_layout_edje_get(sb->orient_layout); + elm_layout_content_set(sb->layout, "elm.swallow.content", sb->orient_layout); + elm_object_focus_custom_chain_append(sb->layout, sb->orient_layout, NULL); + + _ephoto_single_browser_toolbar_eval(sb); + + sb->handlers = eina_list_append + (sb->handlers, ecore_event_handler_add + (EPHOTO_EVENT_POPULATE_END, _ephoto_single_populate_end, sb)); + + sb->handlers = eina_list_append + (sb->handlers, ecore_event_handler_add + (EPHOTO_EVENT_ENTRY_CREATE, _ephoto_single_entry_create, sb)); + + return layout; + + error: + evas_object_del(layout); + return NULL; +} + +void +ephoto_single_browser_entry_set(Evas_Object *obj, Ephoto_Entry *entry) +{ + Ephoto_Single_Browser *sb = evas_object_data_get(obj, "single_browser"); + Eina_Bool same_file = EINA_FALSE; + EINA_SAFETY_ON_NULL_RETURN(sb); + + DBG("entry %p, was %p", entry, sb->entry); + + if (sb->entry) + { + ephoto_entry_free_listener_del(sb->entry, _entry_free, sb); + if (entry && entry->path == sb->entry->path) + same_file = EINA_TRUE; + } + + sb->entry = entry; + + if (entry) + ephoto_entry_free_listener_add(entry, _entry_free, sb); + + if (!sb->entry || same_file) + _ephoto_single_browser_toolbar_eval(sb); + else + { + _ephoto_single_browser_recalc(sb); + _zoom_fit(sb); + } +} + +void +ephoto_single_browser_path_pending_set(Evas_Object *obj, const char *path) +{ + Ephoto_Single_Browser *sb = evas_object_data_get(obj, "single_browser"); + EINA_SAFETY_ON_NULL_RETURN(sb); + + DBG("Setting pending path '%s'", path); + sb->pending_path = eina_stringshare_add(path); +} diff --git a/src/bin/ephoto_slideshow.c b/src/bin/ephoto_slideshow.c index fea7c3a..5041f4f 100644 --- a/src/bin/ephoto_slideshow.c +++ b/src/bin/ephoto_slideshow.c @@ -1,99 +1,192 @@ #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__); - typedef struct _Ephoto_Slideshow Ephoto_Slideshow; + struct _Ephoto_Slideshow { + Ephoto *ephoto; 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) +static void +_key_down(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info) { - ss = calloc(1, sizeof(Ephoto_Slideshow)); + Ephoto_Slideshow *ss = data; + Evas_Event_Key_Down *ev = event_info; + const char *k = ev->keyname; - 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) -{ - if (ss->entry) - ephoto_entry_free_listener_del(ss->entry, _entry_free, NULL); - free(ss); - evas_object_del(ss->slideshow); -} - -void -ephoto_slideshow_entry_set(Ephoto_Entry *entry) -{ - Ephoto_Entry *itr; - Eina_List *l; - - if (ss->entry) - ephoto_entry_free_listener_del(ss->entry, _entry_free, NULL); - ss->entry = entry; - - 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->entries, l, itr) + if (!strcmp(k, "Escape")) { + Evas_Object *win = ss->ephoto->win; Elm_Slideshow_Item *item; + Ephoto_Entry *entry; - item = elm_slideshow_item_add(ss->slideshow, &_ephoto_item_cls, itr); - if (itr == entry) - elm_slideshow_show(item); + 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 -_entry_free(void *data __UNUSED__, const Ephoto_Entry *entry __UNUSED__) +_mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__) { + Ephoto_Slideshow *ss = data; + evas_object_smart_callback_call(ss->slideshow, "back", ss->entry); +} + +static void +_entry_free(void *data, const Ephoto_Entry *entry __UNUSED__) +{ + Ephoto_Slideshow *ss = data; ss->entry = NULL; } -static -Evas_Object *_ephoto_slideshow_item_get(void *data, Evas_Object *obj) +static void +_slideshow_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) +{ + Ephoto_Slideshow *ss = data; + if (ss->entry) + ephoto_entry_free_listener_del(ss->entry, _entry_free, ss); + free(ss); +} + +Evas_Object * +ephoto_slideshow_add(Ephoto *ephoto, Evas_Object *parent) +{ + Evas_Object *slideshow = elm_slideshow_add(parent); + Ephoto_Slideshow *ss; + + EINA_SAFETY_ON_NULL_RETURN_VAL(slideshow, NULL); + + 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); + + 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); + + return ss->slideshow; + + error: + evas_object_del(slideshow); + return NULL; +} + +static void +_image_resized(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *image, void *event_info __UNUSED__) +{ + Evas_Map *map = evas_map_new(4); + Evas_Coord cx, cy, x, y, w, h; + int orient = (long)evas_object_data_get(image, "orient"); + + evas_object_geometry_get(image, &x, &y, &w, &h); + evas_map_util_points_populate_from_geometry(map, x, y, w, h, 0); + cx = x + w / 2; + cy = y + h / 2; + + switch (orient) + { + case EPHOTO_ORIENT_0: + break; + case EPHOTO_ORIENT_90: + evas_map_util_rotate(map, 90.0, cx, cy); + evas_object_map_enable_set(image, EINA_TRUE); + evas_object_map_set(image, map); + printf("rotated 90 around %d,%d (%dx%d)\n", cx, cy, w, h); + break; + case EPHOTO_ORIENT_180: + evas_map_util_rotate(map, 180.0, cx, cy); + evas_object_map_enable_set(image, EINA_TRUE); + evas_object_map_set(image, map); + printf("rotated 180 around %d,%d (%d,%d %dx%d)\n", cx, cy, x, y, w, h); + break; + case EPHOTO_ORIENT_270: + evas_map_util_rotate(map, 270.0, cx, cy); + evas_object_map_enable_set(image, EINA_TRUE); + evas_object_map_set(image, map); + printf("rotated 270 around %d,%d (%dx%d)\n", cx, cy, w, h); + break; + default: + ERR("unknown orient %d", orient); + } + + evas_map_free(map); +} + +static Evas_Object * +_slideshow_item_get(void *data, Evas_Object *obj) { Ephoto_Entry *entry = data; - + /* TODO use viewer from ephoto_single_browser.c */ + /* TODO consider using exif rotation, see ephoto_single_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"); + evas_object_data_set + (image, "orient", (void*)(long)ephoto_file_orient_get(entry->path)); + evas_object_event_callback_add + (image, EVAS_CALLBACK_RESIZE, _image_resized, NULL); + return image; } -static void -_ephoto_mouse_down(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__) +static const Elm_Slideshow_Item_Class _item_cls = {{_slideshow_item_get, NULL}}; + +void +ephoto_slideshow_entry_set(Evas_Object *obj, Ephoto_Entry *entry) { - elm_win_fullscreen_set(ephoto->win, EINA_FALSE); - if (ephoto->prev_state == EPHOTO_STATE_THUMB) - ephoto_thumb_browser_show(ss->entry); - else if (ephoto->prev_state == EPHOTO_STATE_FLOW) - ephoto_flow_browser_show(ss->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); + + if (ss->entry) + ephoto_entry_free_listener_del(ss->entry, _entry_free, ss); + + ss->entry = entry; + + if (entry) + ephoto_entry_free_listener_add(entry, _entry_free, ss); + + 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; + 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 95add25..c313915 100644 --- a/src/bin/ephoto_thumb_browser.c +++ b/src/bin/ephoto_thumb_browser.c @@ -1,375 +1,498 @@ #include "ephoto.h" #define ZOOM_MAX 512 -#define ZOOM_MED 256 #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__); -static void _ephoto_change_dir(void *data __UNUSED__, Evas_Object *o __UNUSED__, void *event_info); -static void _ephoto_zoom_in(void *data __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__); -static void _ephoto_zoom_out(void *data __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__); -static void _ephoto_show_flow(void *data __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__); -static void _ephoto_show_slideshow(void *data __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__); - -static const Elm_Gengrid_Item_Class _ephoto_thumbnail_class = { - "thumb", - { - _ephoto_thumbnail_label_get, - _ephoto_thumbnail_icon_get, - NULL, - _ephoto_thumbnail_del - } - }; +#define PARENT_DIR "Up" typedef struct _Ephoto_Thumb_Browser Ephoto_Thumb_Browser; + struct _Ephoto_Thumb_Browser { - Evas_Object *box; - Evas_Object *dir_entry; + Ephoto *ephoto; + Evas_Object *layout; + Evas_Object *edje; + Evas_Object *fsel; Evas_Object *grid; Evas_Object *toolbar; - Eina_List *handlers; + Evas_Object *overlay; + Eio_File *ls; Eina_List *todo_items; Eina_List *grid_items; - Eio_File *ls; - int thumb_size; + Eina_List *handlers; struct { + Elm_Toolbar_Item *flow; Elm_Toolbar_Item *zoom_in; Elm_Toolbar_Item *zoom_out; - Elm_Toolbar_Item *view_flow; + Elm_Toolbar_Item *view_single; Elm_Toolbar_Item *slideshow; } action; struct { - Ecore_Animator *todo_items; + Ecore_Animator *todo_items; } animator; + Eina_Bool layout_deleted : 1; }; -Ephoto_Thumb_Browser *etb; - -Evas_Object * -ephoto_thumb_browser_add(void) +static void +_todo_items_free(Ephoto_Thumb_Browser *tb) { - etb = calloc(1, sizeof(Ephoto_Thumb_Browser)); - etb->thumb_size = ZOOM_START; - - etb->box = elm_box_add(ephoto->win); - elm_box_horizontal_set(etb->box, EINA_FALSE); - elm_box_homogenous_set(etb->box, EINA_FALSE); - evas_object_size_hint_weight_set - (etb->box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - elm_win_resize_object_add(ephoto->win, etb->box); - evas_object_show(etb->box); - - etb->toolbar = elm_toolbar_add(etb->box); - elm_toolbar_homogenous_set(etb->toolbar, EINA_TRUE); - elm_toolbar_mode_shrink_set(etb->toolbar, ELM_TOOLBAR_SHRINK_MENU); - elm_toolbar_menu_parent_set(etb->toolbar, etb->box); - evas_object_size_hint_weight_set(etb->toolbar, 0.0, 0.0); - evas_object_size_hint_align_set(etb->toolbar, EVAS_HINT_FILL, 0.0); - - etb->action.zoom_in = elm_toolbar_item_append - (etb->toolbar, "add", "Zoom In", _ephoto_zoom_in, NULL); - elm_toolbar_item_priority_set(etb->action.zoom_in, 0); - etb->action.zoom_out = elm_toolbar_item_append - (etb->toolbar, "remove", "Zoom Out", _ephoto_zoom_out, NULL); - elm_toolbar_item_priority_set(etb->action.zoom_out, 1); - etb->action.view_flow = elm_toolbar_item_append - (etb->toolbar, "image", "View Flow", _ephoto_show_flow, NULL); - elm_toolbar_item_priority_set(etb->action.view_flow, 2); - etb->action.slideshow = elm_toolbar_item_append - (etb->toolbar, "media-playback-start", "Slideshow", _ephoto_show_slideshow, NULL); - elm_toolbar_item_priority_set(etb->action.slideshow, 3); - - elm_toolbar_icon_size_set(etb->toolbar, 32); - elm_box_pack_end(etb->box, etb->toolbar); - evas_object_show(etb->toolbar); - - etb->dir_entry = elm_fileselector_entry_add(etb->box); - elm_fileselector_entry_path_set(etb->dir_entry, ephoto->directory); - elm_fileselector_entry_button_label_set(etb->dir_entry, "Choose"); - elm_fileselector_entry_is_save_set(etb->dir_entry, EINA_FALSE); - elm_fileselector_entry_inwin_mode_set(etb->dir_entry, EINA_TRUE); - evas_object_size_hint_weight_set(etb->dir_entry, 0.0, 0.0); - evas_object_size_hint_align_set(etb->dir_entry, EVAS_HINT_FILL, 0.0); - evas_object_smart_callback_add - (etb->dir_entry, "file,chosen", _ephoto_change_dir, NULL); - elm_box_pack_end(etb->box, etb->dir_entry); - evas_object_show(etb->dir_entry); - - etb->grid = elm_gengrid_add(etb->box); - elm_gengrid_align_set(etb->grid, 0.5, 0.5); - elm_gengrid_bounce_set(etb->grid, EINA_FALSE, EINA_TRUE); - elm_gengrid_item_size_set(etb->grid, etb->thumb_size, etb->thumb_size); - evas_object_size_hint_align_set - (etb->grid, EVAS_HINT_FILL, EVAS_HINT_FILL); - evas_object_size_hint_weight_set - (etb->grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - elm_box_pack_end(etb->box, etb->grid); - 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); + eina_list_free(tb->todo_items); + tb->todo_items = NULL; } static void -_todo_items_free() +_grid_items_free(Ephoto_Thumb_Browser *tb) { - eina_list_free(etb->todo_items); - etb->todo_items = NULL; + eina_list_free(tb->grid_items); + tb->grid_items = NULL; +} + +static Ephoto_Entry * +_first_file_entry_find(Ephoto_Thumb_Browser *tb) +{ + return eina_list_nth(tb->ephoto->entries, 0); +} + +static char * +_ephoto_thumb_item_label_get(void *data, Evas_Object *obj __UNUSED__, const char *part __UNUSED__) +{ + Ephoto_Entry *e = data; + return strdup(e->label); +} + + +static Evas_Object * +_ephoto_thumb_file_icon_get(void *data, Evas_Object *obj, const char *part __UNUSED__) +{ + Ephoto_Entry *e = data; + return ephoto_thumb_add(e->ephoto, obj, e->path); } static void -_grid_items_free() +_ephoto_thumb_item_del(void *data __UNUSED__, Evas_Object *obj __UNUSED__) { - eina_list_free(etb->grid_items); - etb->grid_items = NULL; + /* FIXME: the entry is already freed when changing directories + * One solution is to take care of this cleaning when manually removing + * some grid items + Ephoto_Entry *e = data; + e->item = NULL; + */ } -static void -_entry_item_add(Ephoto_Entry *e) -{ - const Elm_Gengrid_Item_Class *ic = &_ephoto_thumbnail_class; +static const Elm_Gengrid_Item_Class _ephoto_thumb_file_class = { + "thumb", + { + _ephoto_thumb_item_label_get, + _ephoto_thumb_file_icon_get, + NULL, + _ephoto_thumb_item_del + } +}; - e->item = elm_gengrid_item_append(etb->grid, ic, e, NULL, NULL); - etb->grid_items = eina_list_append(etb->grid_items, e->item); +static void +_entry_item_add(Ephoto_Thumb_Browser *tb, Ephoto_Entry *e) +{ + const Elm_Gengrid_Item_Class *ic; + + ic = &_ephoto_thumb_file_class; + + e->item = elm_gengrid_item_append(tb->grid, ic, e, NULL, NULL); + tb->grid_items = eina_list_append(tb->grid_items, e->item); if (e->item) elm_gengrid_item_data_set(e->item, e); else - ephoto_entry_free(e); + { + ERR("could not add item to grid: path '%s'", e->path); + ephoto_entry_free(e); + return; + } } static Eina_Bool -_todo_items_process(void *data __UNUSED__) +_todo_items_process(void *data) { + Ephoto_Thumb_Browser *tb = data; + Edje_Message_Int msg; Ephoto_Entry *entry; - if ((etb->ls) && (eina_list_count(etb->todo_items) < TODO_ITEM_MIN_BATCH)) + if ((tb->ls) && (eina_list_count(tb->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); + tb->animator.todo_items = NULL; + + EINA_LIST_FREE(tb->todo_items, entry) + _entry_item_add(tb, entry); + + msg.val = eina_list_count(tb->ephoto->entries); + edje_object_message_send(tb->edje, EDJE_MESSAGE_INT, 1, &msg); + return EINA_FALSE; } -static Eina_Bool -_ephoto_thumb_populate_start(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__) +static void +_ephoto_thumb_selected(void *data, Evas_Object *o __UNUSED__, void *event_info) { - _todo_items_free(); - _grid_items_free(); - elm_gengrid_clear(etb->grid); - elm_fileselector_entry_path_set(etb->dir_entry, ephoto->directory); + Ephoto_Thumb_Browser *tb = data; + Elm_Gengrid_Item *it = event_info; + Ephoto_Entry *e = elm_gengrid_item_data_get(it); + + elm_gengrid_item_selected_set(it, EINA_FALSE); + + evas_object_smart_callback_call(tb->layout, "view", e); +} + +static void +_changed_dir(void *data, Evas_Object *o __UNUSED__, void *event_info) +{ + Ephoto_Thumb_Browser *tb = data; + const char *path = event_info; + if (!path) return; + ephoto_directory_set(tb->ephoto, path); +} + +static void +_changed_dir_text(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__) +{ + Ephoto_Thumb_Browser *tb = data; + const char *path = elm_fileselector_entry_path_get(tb->fsel); + if (ecore_file_is_dir(path)) + ephoto_directory_set(tb->ephoto, path); +} + +static void +_zoom_set(Ephoto_Thumb_Browser *tb, int zoom) +{ + if (zoom > ZOOM_MAX) zoom = ZOOM_MAX; + else if (zoom < ZOOM_MIN) zoom = ZOOM_MIN; + + ephoto_thumb_size_set(tb->ephoto, zoom); + elm_gengrid_item_size_set(tb->grid, zoom, zoom); + + elm_toolbar_item_disabled_set(tb->action.zoom_out, zoom == ZOOM_MIN); + elm_toolbar_item_disabled_set(tb->action.zoom_in, zoom == ZOOM_MAX); +} + +static void +_zoom_in(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__) +{ + Ephoto_Thumb_Browser *tb = data; + elm_toolbar_item_selected_set(tb->action.zoom_in, EINA_FALSE); + _zoom_set(tb, tb->ephoto->config->thumb_size + ZOOM_STEP); +} + +static void +_zoom_out(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__) +{ + Ephoto_Thumb_Browser *tb = data; + elm_toolbar_item_selected_set(tb->action.zoom_out, EINA_FALSE); + _zoom_set(tb, tb->ephoto->config->thumb_size - ZOOM_STEP); +} + +static void +_view_single(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__) +{ + Ephoto_Thumb_Browser *tb = data; + Elm_Gengrid_Item *it = elm_gengrid_selected_item_get(tb->grid); + Ephoto_Entry *entry; + + elm_toolbar_item_selected_set(tb->action.view_single, EINA_FALSE); + + if (it) entry = elm_gengrid_item_data_get(it); + else entry = _first_file_entry_find(tb); + + if (!entry) return; + evas_object_smart_callback_call(tb->layout, "view", entry); +} + +static void +_slideshow(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__) +{ + Ephoto_Thumb_Browser *tb = data; + Elm_Gengrid_Item *it = elm_gengrid_selected_item_get(tb->grid); + Ephoto_Entry *entry; + + elm_toolbar_item_selected_set(tb->action.slideshow, EINA_FALSE); + + if (it) entry = elm_gengrid_item_data_get(it); + else entry = _first_file_entry_find(tb); + + if (!entry) return; + evas_object_smart_callback_call(tb->layout, "slideshow", entry); +} + +static void +_flow(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__) +{ + Ephoto_Thumb_Browser *tb = data; + Elm_Gengrid_Item *it = elm_gengrid_selected_item_get(tb->grid); + Ephoto_Entry *entry; + + elm_toolbar_item_selected_set(tb->action.flow, EINA_FALSE); + + if (it) entry = elm_gengrid_item_data_get(it); + else entry = _first_file_entry_find(tb); + + if (!entry) return; + evas_object_smart_callback_call(tb->layout, "flow", entry); +} + +static void +_key_down(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info) +{ + Ephoto_Thumb_Browser *tb = data; + Evas_Event_Key_Down *ev = event_info; + Eina_Bool alt = evas_key_modifier_is_set(ev->modifiers, "Alt"); + const char *k = ev->keyname; + + if (alt) + { + if (!strcmp(k, "Up")) + { + if (strcmp(tb->ephoto->config->directory, "/") != 0) + { + char *parent = ecore_file_dir_get + (tb->ephoto->config->directory); + if (parent) + ephoto_directory_set(tb->ephoto, parent); + free(parent); + } + } + + return; + } + + 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 __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__) +{ + Ephoto_Thumb_Browser *tb = data; + Ecore_Event_Handler *handler; + + _todo_items_free(tb); + _grid_items_free(tb); + EINA_LIST_FREE(tb->handlers, handler) + ecore_event_handler_del(handler); + + if (tb->animator.todo_items) + { + ecore_animator_del(tb->animator.todo_items); + tb->animator.todo_items = NULL; + } + if (tb->ls) + { + tb->layout_deleted = EINA_TRUE; + eio_file_cancel(tb->ls); + return; + } + free(tb); +} + +static Elm_Toolbar_Item * +_toolbar_item_add(Ephoto_Thumb_Browser *tb, const char *icon, const char *label, int priority, Evas_Smart_Cb cb) +{ + Elm_Toolbar_Item *item = elm_toolbar_item_append(tb->toolbar, icon, label, + cb, tb); + elm_toolbar_item_priority_set(item, priority); + return item; +} + +static Eina_Bool +_ephoto_thumb_populate_start(void *data, int type __UNUSED__, void *event __UNUSED__) +{ + Ephoto_Thumb_Browser *tb = data; + + evas_object_smart_callback_call(tb->layout, "changed,directory", NULL); + + _todo_items_free(tb); + _grid_items_free(tb); + elm_gengrid_clear(tb->grid); + elm_fileselector_entry_path_set(tb->fsel, tb->ephoto->config->directory); + + edje_object_signal_emit(tb->edje, "populate,start", "ephoto"); return ECORE_CALLBACK_PASS_ON; } static Eina_Bool -_ephoto_thumb_populate_end(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__) +_ephoto_thumb_populate_end(void *data, int type __UNUSED__, void *event __UNUSED__) { - etb->ls = NULL; - + Ephoto_Thumb_Browser *tb = data; + + tb->ls = NULL; + if (tb->layout_deleted) + { + free(tb); + return ECORE_CALLBACK_PASS_ON; + } + + edje_object_signal_emit(tb->edje, "populate,stop", "ephoto"); + return ECORE_CALLBACK_PASS_ON; } static Eina_Bool -_ephoto_thumb_populate_error(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__) +_ephoto_thumb_populate_error(void *data, int type __UNUSED__, void *event __UNUSED__) { + Ephoto_Thumb_Browser *tb = data; + + edje_object_signal_emit(tb->edje, "populate,error", "ephoto"); + return ECORE_CALLBACK_PASS_ON; } static Eina_Bool -_ephoto_thumb_entry_create(void *data __UNUSED__, int type __UNUSED__, void *event) +_ephoto_thumb_entry_create(void *data, int type __UNUSED__, void *event) { + Ephoto_Thumb_Browser *tb = data; Ephoto_Event_Entry_Create *ev = event; Ephoto_Entry *e; e = ev->entry; - etb->todo_items = eina_list_append(etb->todo_items, e); + tb->todo_items = eina_list_append(tb->todo_items, e); - if (!etb->animator.todo_items) - etb->animator.todo_items = ecore_animator_add(_todo_items_process, NULL); + if (!tb->animator.todo_items) + tb->animator.todo_items = ecore_animator_add(_todo_items_process, tb); return ECORE_CALLBACK_PASS_ON; } -static Evas_Object * -_ephoto_thumbnail_icon_get(void *data, Evas_Object *obj __UNUSED__, const char *part __UNUSED__) +static void +_ephoto_up_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__) { - Ephoto_Entry *entry = data; - Evas_Object *o; - const char *ext = strrchr(entry->path, '.'); + Ephoto_Thumb_Browser *tb = data; + char *parent_dir; - if (!strncmp(part, "elm.swallow.icon.", sizeof("elm.swallow.icon.") - 1) != 0) - return NULL; + parent_dir = ecore_file_dir_get(tb->ephoto->config->directory); + if (!parent_dir) + return; + ephoto_directory_set(tb->ephoto, parent_dir); +} - if (ext) +Evas_Object * +ephoto_thumb_browser_add(Ephoto *ephoto, Evas_Object *parent) +{ + Evas_Object *layout = elm_layout_add(parent); + Ephoto_Thumb_Browser *tb; + + EINA_SAFETY_ON_NULL_RETURN_VAL(layout, NULL); + + tb = calloc(1, sizeof(Ephoto_Thumb_Browser)); + EINA_SAFETY_ON_NULL_GOTO(tb, error); + tb->ephoto = ephoto; + 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); + + if (!elm_layout_theme_set + (layout, "layout", "application", "toolbar-vbox")) { - if ((!strcasecmp(ext, "jpg")) || (!strcasecmp(ext, "jpeg"))) - ethumb_client_format_set(ephoto->client, ETHUMB_THUMB_JPEG); + ERR("could not load style 'toolbar-vbox' from theme"); + goto error; } - else - ethumb_client_format_set(ephoto->client, ETHUMB_THUMB_FDO); - ethumb_client_size_set(ephoto->client, etb->thumb_size, etb->thumb_size); + tb->toolbar = edje_object_part_external_object_get + (tb->edje, "elm.external.toolbar"); + if (!tb->toolbar) + { + ERR("no toolbar in layout!"); + goto error; + } + elm_toolbar_homogenous_set(tb->toolbar, EINA_FALSE); + elm_toolbar_mode_shrink_set(tb->toolbar, ELM_TOOLBAR_SHRINK_MENU); + elm_toolbar_menu_parent_set(tb->toolbar, parent); - o = elm_thumb_add(ephoto->win); - elm_object_style_set(o, "noframe"); - elm_thumb_file_set(o, entry->path, NULL); - evas_object_show(o); + tb->action.flow = _toolbar_item_add + (tb, "image", "Flow", 120, _flow); + tb->action.slideshow = _toolbar_item_add + (tb, "media-playback-start", "Slideshow", 100, _slideshow); + tb->action.zoom_in = _toolbar_item_add + (tb, "zoom-in", "Zoom In", 50, _zoom_in); + tb->action.zoom_out = _toolbar_item_add + (tb, "zoom-out", "Zoom Out", 50, _zoom_out); + tb->action.view_single = _toolbar_item_add + (tb, "image", "Single", 50, _view_single); - return o; -} - -static char * -_ephoto_thumbnail_label_get(void *data, Evas_Object *obj __UNUSED__, const char *part __UNUSED__) -{ - Ephoto_Entry *e = data; - - return strdup(e->label); -} - -static void -_ephoto_thumbnail_del(void *data __UNUSED__, Evas_Object *obj __UNUSED__) -{ - -} - -static void -_ephoto_change_dir(void *data __UNUSED__, Evas_Object *o __UNUSED__, void *event_info) -{ - const char *path = event_info; - - if (!path) return; - - ephoto_populate(path); -} - -static void -_ephoto_zoom_in(void *data __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__) -{ - elm_toolbar_item_selected_set(etb->action.zoom_in, EINA_FALSE); - etb->thumb_size += ZOOM_STEP; - if (etb->thumb_size >= ZOOM_MAX) - etb->thumb_size = ZOOM_MAX; - elm_gengrid_item_size_set(etb->grid, etb->thumb_size, etb->thumb_size); - elm_toolbar_item_disabled_set(etb->action.zoom_in, etb->thumb_size == ZOOM_MAX); - elm_toolbar_item_disabled_set(etb->action.zoom_out, etb->thumb_size == ZOOM_MIN); -} - -static void -_ephoto_zoom_out(void *data __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__) -{ - elm_toolbar_item_selected_set(etb->action.zoom_out, EINA_FALSE); - etb->thumb_size -= ZOOM_STEP; - if (etb->thumb_size <= ZOOM_MIN) - etb->thumb_size = ZOOM_MIN; - elm_gengrid_item_size_set(etb->grid, etb->thumb_size, etb->thumb_size); - elm_toolbar_item_disabled_set(etb->action.zoom_out, etb->thumb_size == ZOOM_MIN); - elm_toolbar_item_disabled_set(etb->action.zoom_in, etb->thumb_size == ZOOM_MAX); -} - -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); - - 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; - - 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); - - 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); + tb->fsel = elm_fileselector_entry_add(layout); + EINA_SAFETY_ON_NULL_GOTO(tb->fsel, error); + evas_object_size_hint_weight_set(tb->fsel, EVAS_HINT_EXPAND, 0.0); + evas_object_size_hint_align_set(tb->fsel, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_fileselector_entry_button_label_set(tb->fsel, "Choose..."); + elm_fileselector_entry_folder_only_set(tb->fsel, EINA_TRUE); + evas_object_smart_callback_add + (tb->fsel, "file,chosen", _changed_dir, tb); + evas_object_smart_callback_add + (tb->fsel, "activated", _changed_dir_text, tb); + + evas_object_show(tb->fsel); + elm_layout_box_append(layout, "elm.box.content", tb->fsel); + + tb->overlay = elm_layout_add(layout); + elm_layout_file_set + (tb->overlay, PACKAGE_DATA_DIR "/themes/default/ephoto.edj", + "ephoto,thumb,grid"); + evas_object_size_hint_weight_set + (tb->overlay, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set + (tb->overlay, EVAS_HINT_FILL, EVAS_HINT_FILL); + edje_object_signal_callback_add + (elm_layout_edje_get(tb->overlay), "ephoto.signal.up", "ephoto", + _ephoto_up_clicked, tb); + evas_object_show(tb->overlay); + elm_layout_box_append(tb->layout, "elm.box.content", tb->overlay); + + tb->grid = elm_gengrid_add(tb->overlay); + EINA_SAFETY_ON_NULL_GOTO(tb->grid, error); + elm_gengrid_align_set(tb->grid, 0.5, 0.5); + elm_gengrid_bounce_set(tb->grid, EINA_FALSE, EINA_TRUE); + evas_object_size_hint_align_set + (tb->grid, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_size_hint_weight_set + (tb->grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_smart_callback_add + (tb->grid, "selected", _ephoto_thumb_selected, tb); + _zoom_set(tb, tb->ephoto->config->thumb_size); + evas_object_show(tb->grid); + elm_layout_content_set + (tb->overlay, "ephoto.swallow.content.thumb", tb->grid); + + tb->handlers = eina_list_append + (tb->handlers, ecore_event_handler_add + (EPHOTO_EVENT_POPULATE_START, _ephoto_thumb_populate_start, tb)); + + tb->handlers = eina_list_append + (tb->handlers, ecore_event_handler_add + (EPHOTO_EVENT_POPULATE_END, _ephoto_thumb_populate_end, tb)); + + tb->handlers = eina_list_append + (tb->handlers, ecore_event_handler_add + (EPHOTO_EVENT_POPULATE_ERROR, _ephoto_thumb_populate_error, tb)); + + tb->handlers = eina_list_append + (tb->handlers, ecore_event_handler_add + (EPHOTO_EVENT_ENTRY_CREATE, _ephoto_thumb_entry_create, tb)); + + return layout; + + error: + evas_object_del(layout); + return NULL; }