From 9652a108bf1cdfaff6183e0141aacb47eb2ace8e Mon Sep 17 00:00:00 2001 From: Gustavo Sverzut Barbieri Date: Sun, 10 Oct 2010 01:13:53 +0000 Subject: [PATCH] ouch, refactor part 2 -- less is more, so get nothing ;-) okay, still yet another partial code, it's far from ready, don't even checkout until you're ready to code. preferences, flow_browser, slideshow are temporarily gone. still no toolbar in main window, layout redone using EXTERNAL... when it go back, it will be in the same form as eve/enjoy. SVN revision: 53238 --- data/themes/default/ephoto.edc | 116 ++++-- src/bin/ephoto.c | 44 ++- src/bin/ephoto.h | 92 +++-- src/bin/ephoto_config.c | 226 +++++------ src/bin/ephoto_directory_thumb.c | 2 +- src/bin/ephoto_flow_browser.c | 29 +- src/bin/ephoto_main.c | 239 ++++++++---- src/bin/ephoto_preferences.c | 3 + src/bin/ephoto_slideshow.c | 2 + src/bin/ephoto_thumb_browser.c | 621 ++++--------------------------- 10 files changed, 533 insertions(+), 841 deletions(-) diff --git a/data/themes/default/ephoto.edc b/data/themes/default/ephoto.edc index cb50f3d..4a87669 100644 --- a/data/themes/default/ephoto.edc +++ b/data/themes/default/ephoto.edc @@ -3,6 +3,10 @@ fonts font: "Vera.ttf" "default"; } +externals { + external: "elm"; +} + collections { images @@ -719,64 +723,94 @@ collections } } - group - { - name: "ephoto/main/layout"; + group { name: "ephoto/main/layout"; + data.item: "initial_size" "480 800"; parts { - part { - name: "ephoto.content.swallow"; + part { name: "ephoto.swallow.content"; type: SWALLOW; - description { - state: "default" 0.0; + description { state: "default" 0.0; } } } } - group - { - name: "ephoto/browser/layout"; + + group { name: "ephoto/browser/layout"; parts { - part { - name: "bg"; - type: RECT; + part { name: "ephoto.location"; + type: EXTERNAL; + source: "elm/scrolled_entry"; description { state: "default" 0.0; - color: 10 10 10 0; + rel2 { + relative: 0.0 0.0; + offset: -3 64; + to_x: "ephoto.fileselector"; + } + params { + bool: "editable" 1; + bool: "single line" 1; + } } } - part { - name: "ephoto.thumb.swallow"; + + part { name: "ephoto.fileselector"; + type: EXTERNAL; + source: "elm/fileselector_button"; + description { + state: "default" 0.0; + align: 1.0 0.0; + rel1 { relative: 1.0 0.0; + offset: -100 3; + } + rel2 { relative: 1.0 0.0; + offset: -4 58; + } + params { + string: "icon" "folder"; + bool: "folder only" 1; + bool: "inwin mode" 1; + } + } + } + + programs { + program { + signal: "activated"; + source: "ephoto.location"; + action: PARAM_COPY "ephoto.location" "text" "ephoto.fileselector" "path"; + after: "announce-location"; + } + + program { + signal: "file,chosen"; + source: "ephoto.fileselector"; + action: PARAM_COPY "ephoto.fileselector" "path" "ephoto.location" "text"; + after: "announce-location"; + } + + program { name: "announce-location"; + action: SIGNAL_EMIT "location,changed" "ephoto"; + } + + program { + signal: "location,set"; + source: "ephoto"; + action: PARAM_COPY "ephoto.location" "text" "ephoto.fileselector" "path"; + } + } + + part { name: "ephoto.thumb.swallow"; type: SWALLOW; description { state: "default" 0.0; - rel1.to: "ephoto.location.swallow"; - rel1.relative: 0 1; - rel2.to: "ephoto.toolbar.swallow"; - rel2.relative: 1 0; + rel1 { to: "ephoto.location"; + relative: 0.0 1.0; + } } } - part { - name: "ephoto.location.swallow"; - type: SWALLOW; - description { - state: "default" 0.0; - rel2.relative: 1 0; - rel2.offset: 0 64; - - } - } - part { - name: "ephoto.toolbar.swallow"; - type: SWALLOW; - description { - color: 0 255 0 255; - state: "default" 0.0; - rel1.relative: 0 1; - rel1.offset: 0 -63; - } - } - } + } } + group { name: "ephoto/flow/layout"; diff --git a/src/bin/ephoto.c b/src/bin/ephoto.c index 97c1a38..0a92516 100644 --- a/src/bin/ephoto.c +++ b/src/bin/ephoto.c @@ -38,6 +38,7 @@ main(int argc, char **argv) goto end_log_domain; } + elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED); DBG("Logging initialized"); if (argc > 2) @@ -49,7 +50,12 @@ main(int argc, char **argv) } else if (argc < 2) { - ephoto_create_main_window(NULL, NULL); + Evas_Object *win = ephoto_window_add(NULL); + if (!win) + { + r = 1; + goto end; + } } else if (!strncmp(argv[1], "--help", 6)) { @@ -57,30 +63,22 @@ main(int argc, char **argv) r = 0; goto end; } - else if (ecore_file_is_dir(argv[1])) - { - char *real = ecore_file_realpath(argv[1]); - ephoto_create_main_window(real, NULL); - free(real); - } - else if (ecore_file_exists(argv[1])) - { - char *directory, *real; - const char *image; - - image = eina_stringshare_add(argv[1]); - directory = ecore_file_dir_get(argv[1]); - real = ecore_file_realpath(directory); - ephoto_create_main_window(real, image); - free(directory); - free(real); - } else { - printf("Incorrect Argument!\n"); - _ephoto_display_usage(); - r = 1; - goto end; + 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) + { + r = 1; + goto end; + } } elm_run(); diff --git a/src/bin/ephoto.h b/src/bin/ephoto.h index 101dcf4..b6821cc 100644 --- a/src/bin/ephoto.h +++ b/src/bin/ephoto.h @@ -22,6 +22,8 @@ #include #include "config.h" +#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; @@ -30,9 +32,9 @@ typedef enum _Ephoto_State Ephoto_State; typedef enum _Ephoto_Orient Ephoto_Orient; /*Main Functions*/ -void ephoto_create_main_window(const char *directory, const char *image); -void ephoto_thumb_size_set(int size); -Evas_Object *ephoto_thumb_add(Evas_Object *parent, const char *path); +Evas_Object *ephoto_window_add(const char *path); +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); @@ -45,10 +47,10 @@ void ephoto_config_free(Ephoto *em); void ephoto_show_preferences(Ephoto *em); /*Ephoto Flow Browser*/ -Evas_Object *ephoto_create_flow_browser(Evas_Object *parent); +Evas_Object *ephoto_flow_browser_add(Ephoto *ephoto, Evas_Object *parent); void ephoto_flow_browser_image_set(Evas_Object *obj, const char *current_image); /* smart callbacks called: - * "delete,request" - the user requested to delete the flow browser, typically called when go_back button is pressed or Escape key is typed. + * "back" - the user requested to delete the flow browser, typically called when go_back button is pressed or Escape key is typed. */ @@ -62,7 +64,9 @@ void ephoto_delete_slideshow(void); Evas_Object *ephoto_directory_thumb_add(Evas_Object *parent, Ephoto_Entry *e); /*Ephoto Thumb Browser*/ -Evas_Object *ephoto_thumb_browser_add(Evas_Object *parent); +Evas_Object *ephoto_thumb_browser_add(Ephoto *ephoto, Evas_Object *parent); +void ephoto_thumb_browser_directory_set(Evas_Object *obj, const char *path); + /* smart callbacks called: * "selected" - an item in the thumb browser is selected. The selected file is passed as event_info argument. * "directory,changed" - the user selected a new directory. The selected directory is passed as event_info argument. @@ -71,55 +75,64 @@ Evas_Object *ephoto_thumb_browser_add(Evas_Object *parent); /* Enum for the state machine */ enum _Ephoto_State { - EPHOTO_STATE_THUMB, - EPHOTO_STATE_FLOW, - EPHOTO_STATE_SLIDESHOW + EPHOTO_STATE_THUMB, + EPHOTO_STATE_FLOW, + EPHOTO_STATE_SLIDESHOW }; enum _Ephoto_Orient { - EPHOTO_ORIENT_0, - EPHOTO_ORIENT_90, - EPHOTO_ORIENT_180, - EPHOTO_ORIENT_270 + EPHOTO_ORIENT_0, + EPHOTO_ORIENT_90, + EPHOTO_ORIENT_180, + EPHOTO_ORIENT_270 }; +/* 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; + int config_version; - int thumb_size; - int thumb_gen_size; + int thumb_size; + int thumb_gen_size; - int remember_directory; - const char *directory; + int remember_directory; + const char *directory; - double slideshow_timeout; - const char *slideshow_transition; + double slideshow_timeout; + const char *slideshow_transition; - const char *editor; + const char *editor; }; -/*Ephoto Main Structure*/ struct _Ephoto { - Evas *e; - Evas_Object *win; - Evas_Object *bg; - Evas_Object *layout; - Evas_Object *flow_browser; - Evas_Object *slideshow; - Evas_Object *slideshow_notify; - Evas_Object *thumb_browser; - Eina_List *entries; + Evas_Object *win; + Evas_Object *bg; + Evas_Object *layout; - Evas_Object *prefs_win; - Ephoto_State state; + Evas_Object *thumb_browser; + Evas_Object *flow_browser; + Evas_Object *slideshow; - Ephoto_Config *config; + Eina_List *entries; + Eina_List *thumbs; /* live thumbs that need to be regenerated on changes */ - Eet_Data_Descriptor *config_edd; - Ecore_Timer *config_save; + int thumb_gen_size; /* pending value for thumb_regen */ + struct { + Ecore_Timer *thumb_regen; + } timer; + + Evas_Object *prefs_win; + Ephoto_State state; + + Ephoto_Config *config; }; struct _Ephoto_Entry @@ -127,6 +140,7 @@ struct _Ephoto_Entry const char *path; const char *basename; /* pointer inside path */ const char *label; + Ephoto *ephoto; Elm_Gengrid_Item *item; Eina_List *dir_files; /* if dir, here contain files with preview */ Eina_Bool dir_files_checked : 1; @@ -134,11 +148,9 @@ struct _Ephoto_Entry Eina_Bool is_up : 1; }; -Ephoto_Entry *ephoto_entry_new(const char *path, const char *label); +Ephoto_Entry *ephoto_entry_new(Ephoto *ephoto, const char *path, const char *label); void ephoto_entry_free(Ephoto_Entry *entry); -void ephoto_entries_free(Ephoto *em); - -extern Ephoto *em; +void ephoto_entries_free(Ephoto *ephoto); extern int __log_domain; #define DBG(...) EINA_LOG_DOM_DBG(__log_domain, __VA_ARGS__) diff --git a/src/bin/ephoto_config.c b/src/bin/ephoto_config.c index 0af85b9..2b76b5d 100644 --- a/src/bin/ephoto_config.c +++ b/src/bin/ephoto_config.c @@ -2,160 +2,160 @@ #define CONFIG_VERSION 5 -static int _ephoto_config_load(Ephoto *em); +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 *em) +ephoto_config_init(Ephoto *ephoto) { - Eet_Data_Descriptor_Class eddc; + 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 (!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; + } - em->config_edd = eet_data_descriptor_stream_new(&eddc); + if (!edd) edd = eet_data_descriptor_stream_new(&eddc); #undef T #undef D -#define T Ephoto_Config -#define D em->config_edd +#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, remember_directory, 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); + 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, remember_directory, 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(em)) - { - case 0: - /* Start a new config */ - em->config->config_version = CONFIG_VERSION; - em->config->thumb_size = 256; - em->config->thumb_gen_size = 256; - em->config->remember_directory = 1; - em->config->slideshow_timeout = 4.0; - em->config->slideshow_transition = - eina_stringshare_add("fade"); - em->config->editor = - eina_stringshare_add("gimp %s"); - break; - case -1: - if (em->config->config_version < 2) - { - em->config->remember_directory = 1; - em->config->slideshow_timeout = 4.0; - em->config->slideshow_transition = - eina_stringshare_add("fade"); - } - if (em->config->config_version < 3) - em->config->editor = - eina_stringshare_add("gimp %s"); + 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->remember_directory = 1; + ephoto->config->slideshow_timeout = 4.0; + ephoto->config->slideshow_transition = eina_stringshare_add("fade"); + ephoto->config->editor = eina_stringshare_add("gimp %s"); + break; - if (em->config->config_version < 5) - em->config->thumb_gen_size = 256; + case -1: + /* Incremental additions */ + if (ephoto->config->config_version < 2) + { + ephoto->config->remember_directory = 1; + 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"); - /* Incremental additions */ - em->config->config_version = CONFIG_VERSION; - break; - default: - return EINA_TRUE; - } - ephoto_config_save(em, EINA_FALSE); - return EINA_TRUE; + 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 *em, Eina_Bool instant) +ephoto_config_save(Ephoto *ephoto, Eina_Bool instant) { - if (em->config_save) - { - ecore_timer_del(em->config_save); - em->config_save = NULL; - } + if (save_timer) + { + ecore_timer_del(save_timer); + save_timer = NULL; + } - if (instant) - _ephoto_on_config_save(em); - else - em->config_save = ecore_timer_add(5, _ephoto_on_config_save, em); + 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 *em) +ephoto_config_free(Ephoto *ephoto) { - free(em->config); - em->config = NULL; + free(ephoto->config); + ephoto->config = NULL; } static int -_ephoto_config_load(Ephoto *em) +_ephoto_config_load(Ephoto *ephoto) { - Eet_File *ef; - char buf[4096], buf2[4096]; + 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); + 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(em); - em->config = calloc(1, sizeof(Ephoto_Config)); - return 0; - } + ef = eet_open(buf, EET_FILE_MODE_READ); + if (!ef) + { + ephoto_config_free(ephoto); + ephoto->config = calloc(1, sizeof(Ephoto_Config)); + return 0; + } - em->config = eet_data_read(ef, em->config_edd, "config"); - eet_close(ef); + ephoto->config = eet_data_read(ef, edd, "config"); + eet_close(ef); - if (em->config->config_version > CONFIG_VERSION) - { - ephoto_config_free(em); - em->config = calloc(1, sizeof(Ephoto_Config)); - return 0; - } + if (ephoto->config->config_version > CONFIG_VERSION) + { + ephoto_config_free(ephoto); + ephoto->config = calloc(1, sizeof(Ephoto_Config)); + return 0; + } - if (em->config->config_version < CONFIG_VERSION) - return -1; + if (ephoto->config->config_version < CONFIG_VERSION) + return -1; - return 1; + return 1; } static Eina_Bool _ephoto_on_config_save(void *data) { - Ephoto *em = data; - Eet_File *ef; - char buf[4096], buf2[4096]; - int ret; + 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); + 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) - { - eet_data_write(ef, em->config_edd, "config", em->config, 1); + ef = eet_open(buf2, EET_FILE_MODE_WRITE); + if (!ef) goto save_end; - if (eet_close(ef)) - goto save_end; + eet_data_write(ef, edd, "config", ephoto->config, 1); + if (eet_close(ef)) goto save_end; - ret = ecore_file_mv(buf2, buf); - if (!ret) - goto save_end; + if (!ecore_file_mv(buf2, buf)) goto save_end; - DBG("Config saved"); - ecore_file_unlink(buf2); - } + INF("Config saved"); save_end: - if (em->config_save) - ecore_timer_del(em->config_save); - em->config_save = NULL; - return ECORE_CALLBACK_CANCEL; + 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_directory_thumb.c b/src/bin/ephoto_directory_thumb.c index 7527928..8d3e6ea 100644 --- a/src/bin/ephoto_directory_thumb.c +++ b/src/bin/ephoto_directory_thumb.c @@ -104,7 +104,7 @@ ephoto_directory_thumb_add(Evas_Object *parent, Ephoto_Entry *entry) EINA_SAFETY_ON_NULL_RETURN_VAL(_pending_dirs, NULL); } - obj = ephoto_thumb_add(parent, NULL); + obj = ephoto_thumb_add(entry->ephoto, parent, NULL); EINA_SAFETY_ON_NULL_RETURN_VAL(obj, NULL); if (!dt) diff --git a/src/bin/ephoto_flow_browser.c b/src/bin/ephoto_flow_browser.c index fa1a480..83b0823 100644 --- a/src/bin/ephoto_flow_browser.c +++ b/src/bin/ephoto_flow_browser.c @@ -4,6 +4,31 @@ #include #endif +Evas_Object * +ephoto_flow_browser_add(Ephoto *ephoto, Evas_Object *parent) +{ + Evas_Object *layout = elm_layout_add(parent); + EINA_SAFETY_ON_NULL_RETURN_VAL(layout, NULL); + + if (!elm_layout_file_set(layout, THEME_FILE, "ephoto/flow/layout")) + { + evas_object_del(layout); + return NULL; + } + + /* TODO */ + + return layout; +} + +void +ephoto_flow_browser_image_set(Evas_Object *obj, const char *path) +{ + /* TODO */ +} + + +#if 0 /*Callbacks*/ static void _ephoto_go_back(void *data, Evas_Object *obj, void *event_info); @@ -418,7 +443,7 @@ _ephoto_go_slideshow(void *data, Evas_Object *obj, void *event_info) Ephoto_Flow_Browser *ef = data; // FIXME //ephoto_hide_flow_browser(); - ephoto_show_slideshow(1, ef->cur_image); + // TODO ephoto_show_slideshow(1, ef->cur_image); elm_toolbar_item_unselect_all(ef->toolbar); } @@ -528,3 +553,5 @@ _ephoto_zoom_regular_size(void *data, Evas_Object *obj, void *event) Ephoto_Flow_Browser *ef = data; elm_photocam_zoom_mode_set(ef->image, ELM_PHOTOCAM_ZOOM_MODE_AUTO_FIT); } + +#endif diff --git a/src/bin/ephoto_main.c b/src/bin/ephoto_main.c index 799d4d6..1579e53 100644 --- a/src/bin/ephoto_main.c +++ b/src/bin/ephoto_main.c @@ -1,49 +1,140 @@ #include "ephoto.h" -/*Ephoto Main Global*/ -Ephoto *em; - -static Eina_List *_thumbs = NULL; -static Ecore_Timer *_thumb_gen_size_changed_timer = NULL; - -/*Inline Callbacks*/ -static void _ephoto_delete_main_window(void *data, Evas_Object *obj, void *event_info); -static void _ephoto_flow_browser_delete_cb(void *data, Evas_Object *obj, void *event_info); -static void _ephoto_thumb_browser_selected_cb(void *data, Evas_Object *obj, void *event_info); - -/* Objects Callbacks */ -static void -_ephoto_flow_browser_delete_cb(void *data, Evas_Object *obj, void *event_info) +static void +_ephoto_flow_browser_delete(void *data, Evas_Object *obj, void *event_info) { - em->thumb_browser = ephoto_thumb_browser_add(em->layout); - elm_layout_content_set(em->layout, "ephoto.content.swallow", em->thumb_browser); - evas_object_smart_callback_add(em->thumb_browser, - "selected", - _ephoto_thumb_browser_selected_cb, - NULL); - em->state = EPHOTO_STATE_THUMB; - em->flow_browser = NULL; + Ephoto *ephoto = data; + ephoto->flow_browser = NULL; + elm_layout_content_set + (ephoto->layout, "ephoto.swallow.content", ephoto->thumb_browser); + ephoto->state = EPHOTO_STATE_THUMB; } -static void -_ephoto_thumb_browser_selected_cb(void *data, Evas_Object *obj, void *event_info) +static void +_ephoto_flow_browser_show(Ephoto *ephoto, Ephoto_Entry *entry) { - const char *file = event_info; + /* remove thumb browser without deleting it */ + elm_layout_content_unset(ephoto->layout, "ephoto.swallow.content"); - em->flow_browser = ephoto_create_flow_browser(em->layout); - ephoto_flow_browser_image_set(em->flow_browser, file); - elm_layout_content_set(em->layout, "ephoto.content.swallow", em->flow_browser); - evas_object_smart_callback_add(em->flow_browser, - "delete,request", - _ephoto_flow_browser_delete_cb, - NULL); - em->state = EPHOTO_STATE_FLOW; + ephoto->flow_browser = ephoto_flow_browser_add(ephoto, ephoto->layout); + ephoto_flow_browser_image_set(ephoto->flow_browser, entry->path); + elm_layout_content_set + (ephoto->layout, "ephoto.swallow.content", ephoto->flow_browser); + + evas_object_smart_callback_add + (ephoto->flow_browser, "back", _ephoto_flow_browser_delete, ephoto); + ephoto->state = EPHOTO_STATE_FLOW; } -/*Create the main ephoto window*/ -void -ephoto_create_main_window(const char *directory, const char *image) +static void +_ephoto_thumb_browser_view(void *data, Evas_Object *obj, void *event_info) { + Ephoto *ephoto = data; + Ephoto_Entry *entry = event_info; + _ephoto_flow_browser_show(ephoto, entry); +} + +static void +_win_del(void *data, Evas *e, Evas_Object *o, void *event_info) +{ + 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(); + Evas_Object *ed; + Evas_Coord mw, mh, iw, ih; + const char *s; + EINA_SAFETY_ON_NULL_RETURN_VAL(ephoto, NULL); + + ephoto->win = elm_win_add(NULL, "ephoto", ELM_WIN_BASIC); + if (!ephoto->win) + { + free(ephoto); + return NULL; + } + + evas_object_event_callback_add + (ephoto->win, EVAS_CALLBACK_DEL, _win_del, ephoto); + + elm_win_autodel_set(ephoto->win, EINA_TRUE); + evas_object_show(ephoto->win); + + 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 + (ephoto->bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_fill_set(ephoto->bg, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_win_resize_object_add(ephoto->win, ephoto->bg); + evas_object_show(ephoto->bg); + + ephoto->layout = elm_layout_add(ephoto->win); + if (!elm_layout_file_set(ephoto->layout, THEME_FILE, "ephoto/main/layout")) + { + ERR("could not load group 'ephoto/main/layout' from file %s", + THEME_FILE); + evas_object_del(ephoto->win); + return NULL; + } + evas_object_size_hint_weight_set + (ephoto->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_fill_set + (ephoto->layout, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_win_resize_object_add(ephoto->win, ephoto->layout); + evas_object_show(ephoto->layout); + + ephoto->thumb_browser = ephoto_thumb_browser_add(ephoto, ephoto->layout); + if (!ephoto->thumb_browser) + { + ERR("could not add thumb browser"); + evas_object_del(ephoto->win); + return NULL; + } + elm_layout_content_set + (ephoto->layout, "ephoto.swallow.content", ephoto->thumb_browser); + + ed = elm_layout_edje_get(ephoto->layout); + edje_object_size_min_get(ed, &mw, &mh); + edje_object_size_min_restricted_calc(ed, &mw, &mh, mw, mh); + if (mw < 1) mw = 320; + if (mh < 1) mh = 240; + + s = edje_object_data_get(ed, "initial_size"); + if ((!s) || (sscanf(s, "%d %d", &iw, &ih) != 2)) iw = ih = 0; + if (iw < mw) iw = mw; + if (ih < mh) ih = mh; + evas_object_resize(ephoto->win, iw, ih); + + if (!path) + ephoto_thumb_browser_directory_set + (ephoto->thumb_browser, ephoto->config->directory); + else if (ecore_file_is_dir(path)) + ephoto_thumb_browser_directory_set(ephoto->thumb_browser, path); + else + ERR("loading file to be done"); + + return ephoto->win; +} + +#if 0 char current_directory[PATH_MAX]; Ethumb_Client *client = elm_thumb_ethumb_client_get(); @@ -83,13 +174,6 @@ ephoto_create_main_window(const char *directory, const char *image) /* Add the main layout to the window */ em->layout = elm_layout_add(em->win); - elm_layout_file_set(em->layout, - PACKAGE_DATA_DIR "/themes/default/ephoto.edj", - "ephoto/main/layout"); - elm_win_resize_object_add(em->win, em->layout); - evas_object_size_hint_weight_set(em->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_size_hint_fill_set(em->layout, EVAS_HINT_FILL, EVAS_HINT_FILL); - evas_object_show(em->layout); /* Prepare the slideshow beforehand, in order @@ -162,25 +246,33 @@ _ephoto_delete_main_window(void *data, Evas_Object *obj, void *event_info) free(em); elm_exit(); } +#endif static Eina_Bool _thumb_gen_size_changed_timer_cb(void *data) { - const int gen_size = (long)data; + Ephoto *ephoto = data; Ethumb_Client *client; const Eina_List *l; Evas_Object *o; - if (em->config->thumb_gen_size == gen_size) goto end; + if (ephoto->config->thumb_gen_size == ephoto->thumb_gen_size) goto end; INF("thumbnail generation size changed from %d to %d", - em->config->thumb_gen_size, gen_size); + ephoto->config->thumb_gen_size, ephoto->thumb_gen_size); client = elm_thumb_ethumb_client_get(); - em->config->thumb_gen_size = gen_size; - ethumb_client_size_set(client, gen_size, gen_size); + if (!client) + { + DBG("no client yet, try again later"); + return EINA_TRUE; + } - EINA_LIST_FOREACH(_thumbs, l, o) + 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"); @@ -189,45 +281,39 @@ _thumb_gen_size_changed_timer_cb(void *data) } end: - _thumb_gen_size_changed_timer = NULL; + ephoto->timer.thumb_regen = NULL; return EINA_FALSE; } void -ephoto_thumb_size_set(int size) +ephoto_thumb_size_set(Ephoto *ephoto, int size) { - int gen_size; - - if (em->config->thumb_size != size) + if (ephoto->config->thumb_size != size) { INF("thumbnail display size changed from %d to %d", - em->config->thumb_size, size); - em->config->thumb_size = size; - ephoto_config_save(em, EINA_FALSE); + ephoto->config->thumb_size, size); + ephoto->config->thumb_size = size; + ephoto_config_save(ephoto, EINA_FALSE); } - if (size <= 128) gen_size = 128; - else if (size <= 256) gen_size = 256; - else gen_size = 512; + if (size <= 128) ephoto->thumb_gen_size = 128; + else if (size <= 256) ephoto->thumb_gen_size = 256; + else ephoto->thumb_gen_size = 512; - if (_thumb_gen_size_changed_timer) - { - ecore_timer_del(_thumb_gen_size_changed_timer); - _thumb_gen_size_changed_timer = NULL; - } - - _thumb_gen_size_changed_timer = ecore_timer_add - (0.1, _thumb_gen_size_changed_timer_cb, (void*)(long)gen_size); + 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, Evas_Object *o, void *event_info) { - _thumbs = eina_list_remove(_thumbs, o); + Ephoto *ephoto = data; + ephoto->thumbs = eina_list_remove(ephoto->thumbs, o); } Evas_Object * -ephoto_thumb_add(Evas_Object *parent, const char *path) +ephoto_thumb_add(Ephoto *ephoto, Evas_Object *parent, const char *path) { Evas_Object *o; @@ -238,8 +324,8 @@ ephoto_thumb_add(Evas_Object *parent, const char *path) if (path) ephoto_thumb_path_set(o, path); elm_object_style_set(o, "noframe"); - _thumbs = eina_list_append(_thumbs, o); - evas_object_event_callback_add(o, EVAS_CALLBACK_DEL, _thumb_del, NULL); + ephoto->thumbs = eina_list_append(ephoto->thumbs, o); + evas_object_event_callback_add(o, EVAS_CALLBACK_DEL, _thumb_del, ephoto); return o; } @@ -262,12 +348,13 @@ ephoto_thumb_path_set(Evas_Object *o, const char *path) } 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); @@ -286,8 +373,8 @@ ephoto_entry_free(Ephoto_Entry *entry) } void -ephoto_entries_free(Ephoto *em) +ephoto_entries_free(Ephoto *ephoto) { - Ephoto_Entry *e; - EINA_LIST_FREE(em->entries, e) ephoto_entry_free(e); + Ephoto_Entry *entry; + EINA_LIST_FREE(ephoto->entries, entry) ephoto_entry_free(entry); } diff --git a/src/bin/ephoto_preferences.c b/src/bin/ephoto_preferences.c index f459f93..d2af2a6 100644 --- a/src/bin/ephoto_preferences.c +++ b/src/bin/ephoto_preferences.c @@ -1,5 +1,6 @@ #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); @@ -194,3 +195,5 @@ _ephoto_preferences_hide(void *data, Evas_Object *obj, void *event_info) evas_object_hide(em->prefs_win); evas_object_focus_set(em->thumb_browser, EINA_TRUE); } + +#endif diff --git a/src/bin/ephoto_slideshow.c b/src/bin/ephoto_slideshow.c index 2280fa8..21aff0b 100644 --- a/src/bin/ephoto_slideshow.c +++ b/src/bin/ephoto_slideshow.c @@ -1,5 +1,6 @@ #include "ephoto.h" +#if 0 static Evas_Object *_ephoto_get_image(void *data, Evas_Object *obj); static void _ephoto_end_slideshow(void *data, Evas *e, Evas_Object *obj, void *event_info); static void _ephoto_switch_fullscreen(); @@ -147,3 +148,4 @@ _ephoto_end_slideshow(void *data, Evas *e, Evas_Object *obj, void *event_info) ephoto_hide_slideshow(); } +#endif diff --git a/src/bin/ephoto_thumb_browser.c b/src/bin/ephoto_thumb_browser.c index d8b22bd..83e7fe3 100644 --- a/src/bin/ephoto_thumb_browser.c +++ b/src/bin/ephoto_thumb_browser.c @@ -4,16 +4,19 @@ #define SLIDER_MIN 128 #define PARENT_DIR "Up" -#define THEME_FILE PACKAGE_DATA_DIR"/themes/default/ephoto.edj" typedef struct _Ephoto_Thumb_Browser Ephoto_Thumb_Browser; struct _Ephoto_Thumb_Browser { + Ephoto *ephoto; Evas_Object *layout; Evas_Object *edje; Evas_Object *grid; Eio_File *ls; + struct { + Ecore_Job *change_dir; + } job; }; static char * @@ -40,7 +43,7 @@ _ephoto_thumb_dir_icon_get(void *data, Evas_Object *obj, const char *part) f = eina_list_nth(e->dir_files, n); if (f) - return ephoto_thumb_add(obj, f); + return ephoto_thumb_add(e->ephoto, obj, f); if (e->dir_files_checked) return NULL; @@ -70,7 +73,7 @@ static Evas_Object * _ephoto_thumb_file_icon_get(void *data, Evas_Object *obj, const char *part) { Ephoto_Entry *e = data; - return ephoto_thumb_add(obj, e->path); + return ephoto_thumb_add(e->ephoto, obj, e->path); } static void @@ -118,7 +121,7 @@ _ephoto_populate_main(void *data, const Eina_File_Direct_Info *info) Edje_Message_Int msg; Ephoto_Entry *e; - e = ephoto_entry_new(info->path, info->path + info->name_start); + e = ephoto_entry_new(tb->ephoto, info->path, info->path + info->name_start); if (info->dirent->d_type == DT_DIR) e->is_dir = EINA_TRUE; else if (info->dirent->d_type == DT_REG) e->is_dir = EINA_FALSE; else e->is_dir = !_ephoto_eina_file_direct_info_image_useful(info); @@ -138,9 +141,9 @@ _ephoto_populate_main(void *data, const Eina_File_Direct_Info *info) return; } - em->entries = eina_list_append(em->entries, e); + tb->ephoto->entries = eina_list_append(tb->ephoto->entries, e); - msg.val = eina_list_count(em->entries); + msg.val = eina_list_count(tb->ephoto->entries); edje_object_message_send(tb->edje, EDJE_MESSAGE_INT, 1, &msg); DBG("populate add '%s'", e->path); } @@ -182,27 +185,34 @@ _ephoto_populate_error(int error, void *data) static void _ephoto_populate_entries(Ephoto_Thumb_Browser *tb) { - Ephoto_Entry *e; + Edje_External_Param param; char *parent_dir; - DBG("populate from '%s'", em->config->directory); + DBG("populate from '%s'", tb->ephoto->config->directory); elm_gengrid_clear(tb->grid); - ephoto_entries_free(em); + ephoto_entries_free(tb->ephoto); - parent_dir = ecore_file_dir_get(em->config->directory); + parent_dir = ecore_file_dir_get(tb->ephoto->config->directory); if (parent_dir) { - e = ephoto_entry_new(parent_dir, PARENT_DIR); + Ephoto_Entry *e = ephoto_entry_new(tb->ephoto, parent_dir, PARENT_DIR); free(parent_dir); EINA_SAFETY_ON_NULL_RETURN(e); e->is_up = EINA_TRUE; + e->is_dir = EINA_TRUE; e->item = elm_gengrid_item_append (tb->grid, &_ephoto_thumb_up_class, e, NULL, NULL); - /* does not go into em->entries as it is always the first - no sort! */ + /* does not go into entries as it is always the first - no sort! */ } + param.name = "text"; + param.type = EDJE_EXTERNAL_PARAM_TYPE_STRING; + param.s = tb->ephoto->config->directory; + edje_object_part_external_param_set(tb->edje, "ephoto.location", ¶m); + edje_object_signal_emit(tb->edje, "location,set", "ephoto"); + edje_object_signal_emit(tb->edje, "populate,start", "ephoto"); - tb->ls = eio_file_direct_ls(em->config->directory, + tb->ls = eio_file_direct_ls(tb->ephoto->config->directory, _ephoto_populate_filter, _ephoto_populate_main, _ephoto_populate_end, @@ -210,16 +220,53 @@ _ephoto_populate_entries(Ephoto_Thumb_Browser *tb) tb); } +static void +_ephoto_thumb_change_dir(void *data) +{ + Ephoto_Thumb_Browser *tb = data; + tb->job.change_dir = NULL; + _ephoto_populate_entries(tb); +} + +static void +_ephoto_thumb_selected(void *data, Evas_Object *o, void *event_info) +{ + Ephoto_Thumb_Browser *tb = data; + Elm_Gengrid_Item *it = event_info; + Ephoto_Entry *e = elm_gengrid_item_data_get(it); + + if (e->is_dir) + ephoto_thumb_browser_directory_set(tb->layout, e->path); + else + evas_object_smart_callback_call(tb->layout, "view", e); +} + +static void +_changed_dir(void *data, Evas_Object *o, const char *emission, const char *source) +{ + Ephoto_Thumb_Browser *tb = data; + Edje_External_Param p; + + p.name = "text"; + p.type = EDJE_EXTERNAL_PARAM_TYPE_STRING; + p.s = NULL; + if (!edje_object_part_external_param_get(tb->edje, "ephoto.location", &p)) + return; + + ephoto_thumb_browser_directory_set(tb->layout, p.s); +} + static void _layout_del(void *data, Evas *e, Evas_Object *o, void *event_info) { Ephoto_Thumb_Browser *tb = data; if (tb->ls) eio_file_cancel(tb->ls); + if (tb->job.change_dir) ecore_job_del(tb->job.change_dir); free(tb); } Evas_Object * -ephoto_thumb_browser_add(Evas_Object *parent) +ephoto_thumb_browser_add(Ephoto *ephoto, Evas_Object *parent) { Evas_Object *layout = elm_layout_add(parent); Ephoto_Thumb_Browser *tb; @@ -228,8 +275,13 @@ ephoto_thumb_browser_add(Evas_Object *parent) 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_data_set(layout, "thumb_browser", tb); + edje_object_signal_callback_add + (tb->edje, "location,changed", "ephoto", _changed_dir, tb); if (!elm_layout_file_set(layout, THEME_FILE, "ephoto/browser/layout")) { @@ -245,21 +297,16 @@ ephoto_thumb_browser_add(Evas_Object *parent) elm_gengrid_align_set(tb->grid, 0.5, 0.5); elm_gengrid_bounce_set(tb->grid, EINA_FALSE, EINA_TRUE); elm_gengrid_item_size_set - (tb->grid, em->config->thumb_size, em->config->thumb_size); + (tb->grid, tb->ephoto->config->thumb_size, tb->ephoto->config->thumb_size); 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); - evas_object_smart_callback_add - (tb->grid, "clicked", _ephoto_thumb_clicked, tb); - */ - elm_layout_content_set(tb->layout, "ephoto.thumb.swallow", tb->grid); - _ephoto_populate_entries(tb); + elm_layout_content_set(tb->layout, "ephoto.thumb.swallow", tb->grid); return layout; @@ -268,531 +315,13 @@ ephoto_thumb_browser_add(Evas_Object *parent) return NULL; } -#if 0 - - - - - -typedef struct _Ephoto_Thumb_Browser Ephoto_Thumb_Browser; - -struct _Ephoto_Thumb_Browser +void +ephoto_thumb_browser_directory_set(Evas_Object *obj, const char *path) { - Evas_Object *layout; - Evas_Object *thumb_browser; - Evas_Object *dir_label; - Evas_Object *toolbar; - Evas_Object *thumb_slider; - Evas_Object *thbox; - Evas_Object *fsel_win; - Elm_Gengrid_Item_Class eg; - Elm_Toolbar_Item *view_large; - Eio_File *list; -}; + Ephoto_Thumb_Browser *tb = evas_object_data_get(obj, "thumb_browser"); + EINA_SAFETY_ON_NULL_RETURN(tb); -#define THUMB_RATIO (256 / 192) - -/*Callbacks*/ -static void _ephoto_slider_changed(void *data, Evas_Object *obj, void *event_info); -static char *_ephoto_get_label(void *data, Evas_Object *obj, const char *part); -static Evas_Object *_ephoto_get_icon(void *data, Evas_Object *obj, const char *part); -static Eina_Bool _ephoto_get_state(void *data, Evas_Object *obj, const char *part); -static void _ephoto_grid_del(void *data, Evas_Object *obj); -static void _ephoto_thumb_clicked_job(void *data); -static void _ephoto_thumb_clicked(void *data, Evas_Object *obj, void *event_info); -static void _ephoto_thumb_selected(void *data, Evas_Object *obj, void *event_info); -static void _ephoto_view_large(void *data, Evas_Object *obj, void *event_info); -static void _ephoto_change_directory_window(void *data, Evas_Object *obj, void *event_info); -static void _ephoto_view_slideshow(void *data, Evas_Object *obj, void *event_info); -static void _ephoto_preferences(void *data, Evas_Object *obj, void *event_info); -static void _ephoto_del_cb(void *data, Evas *e, Evas_Object *obj, void *event_info); -static void _ephoto_show_cb(void *data, Evas *e, Evas_Object *obj, void *event_info); -static void _ephoto_zoom_in(void *data, Evas_Object *obj, void *event_info); -static void _ephoto_zoom_out(void *data, Evas_Object *obj, void *event_info); -static void _ephoto_zoom_regular_size(void *data, Evas_Object *obj, void *event_info); -static void _ephoto_change_directory(Ephoto_Thumb_Browser *tb, const char *directory); -static void _ephoto_populate_images(Ephoto_Thumb_Browser *tb); - -/*A key has been pressed*/ -static const struct -{ - const char *name; - const char *modifiers; - void (*func)(void *data, Evas_Object *obj, void *event_info); -} keys[] = { - { "F5", NULL, _ephoto_view_slideshow }, - { "d", "Control", _ephoto_change_directory_window}, - { "p", "Control", _ephoto_preferences}, - { "plus", "Control", _ephoto_zoom_in}, - { "minus", "Control", _ephoto_zoom_out}, - { "0", "Control", _ephoto_zoom_regular_size}, - { NULL, NULL, NULL } -}; - -static void -_ephoto_key_pressed(void *data, Evas *e, Evas_Object *obj, void *event_data) -{ - Evas_Event_Key_Down *eku; - int i; - - eku = (Evas_Event_Key_Down *)event_data; - DBG("Key name: %s", eku->key); - for (i = 0; keys[i].name; ++i) - if ((!strcmp(eku->key, keys[i].name)) && - ((keys[i].modifiers == NULL) || (evas_key_modifier_is_set(eku->modifiers, keys[i].modifiers)))) - keys[i].func(data, obj, NULL); + eina_stringshare_replace(&tb->ephoto->config->directory, path); + if (tb->job.change_dir) ecore_job_del(tb->job.change_dir); + tb->job.change_dir = ecore_job_add(_ephoto_thumb_change_dir, tb); } - -static void -_ephoto_mouse_wheel(void *data, Evas *e, Evas_Object *obj, void *event_data) -{ - Evas_Event_Mouse_Wheel *emw = (Evas_Event_Mouse_Wheel *) event_data; - if (evas_key_modifier_is_set(emw->modifiers, "Control")) - { - if (emw->z < 0) - _ephoto_zoom_in(data, NULL, NULL); - else - _ephoto_zoom_out(data, NULL, NULL); - } -} - -static void -_ephoto_set_title(const char *file) -{ - char *buffer; - int length; - - length = strlen(file) + strlen("Ephoto - ") + 1; - buffer = alloca(length); - snprintf(buffer, length, "Ephoto - %s", file); - elm_win_title_set(em->win, buffer); -} - -/*Create the thumbnail browser object*/ -Evas_Object * -ephoto_create_thumb_browser(Evas_Object *parent) -{ - Evas_Object *o; - Ephoto_Thumb_Browser *tb; - - tb = calloc(1, sizeof(Ephoto_Thumb_Browser)); - - tb->layout = elm_layout_add(parent); - elm_layout_file_set(tb->layout, - PACKAGE_DATA_DIR "/themes/default/ephoto.edj", - "ephoto/browser/layout"); - - evas_object_size_hint_weight_set(tb->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_size_hint_fill_set(tb->layout, EVAS_HINT_FILL, EVAS_HINT_FILL); - evas_object_show(tb->layout); - - tb->thbox = elm_box_add(tb->layout); - elm_box_horizontal_set(tb->thbox, EINA_TRUE); - evas_object_size_hint_weight_set(tb->thbox, EVAS_HINT_EXPAND, EVAS_HINT_FILL); - evas_object_size_hint_fill_set(tb->thbox, EVAS_HINT_FILL, EVAS_HINT_FILL); - elm_layout_content_set(tb->layout, "ephoto.location.swallow", tb->thbox); - - tb->dir_label = elm_label_add(tb->thbox); - elm_label_label_set(tb->dir_label, em->config->directory); - evas_object_size_hint_weight_set(tb->dir_label, EVAS_HINT_EXPAND, 0.0); - evas_object_size_hint_align_set(tb->dir_label, 0.01, 0.5); - elm_box_pack_end(tb->thbox, tb->dir_label); - - tb->thumb_slider = elm_slider_add(tb->thbox); - elm_slider_label_set(tb->thumb_slider, "Thumb Size:"); - elm_slider_span_size_set(tb->thumb_slider, 100); - elm_slider_min_max_set(tb->thumb_slider, SLIDER_MIN, SLIDER_MAX); - elm_slider_value_set(tb->thumb_slider, em->config->thumb_size); - elm_box_pack_end(tb->thbox, tb->thumb_slider); - evas_object_smart_callback_add(tb->thumb_slider, "changed", - _ephoto_slider_changed, tb); - evas_object_show(tb->thumb_slider); - evas_object_show(tb->dir_label); - - tb->thumb_browser = elm_gengrid_add(tb->layout); - elm_gengrid_align_set(tb->thumb_browser, 0.5, 0.5); - elm_gengrid_bounce_set(tb->thumb_browser, EINA_TRUE, EINA_FALSE); - elm_gengrid_item_size_set(tb->thumb_browser, em->config->thumb_size, em->config->thumb_size / THUMB_RATIO); - evas_object_size_hint_align_set(tb->thumb_browser, EVAS_HINT_FILL, EVAS_HINT_FILL); - evas_object_size_hint_weight_set(tb->thumb_browser, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - - elm_object_style_set(tb->thumb_browser, "ephoto"); - evas_object_smart_callback_add(tb->thumb_browser, "selected", _ephoto_thumb_selected, tb); - evas_object_smart_callback_add(tb->thumb_browser, "clicked", _ephoto_thumb_clicked, tb); - elm_layout_content_set(tb->layout, "ephoto.thumb.swallow", tb->thumb_browser); - - tb->toolbar = elm_toolbar_add(tb->layout); - elm_toolbar_icon_size_set(tb->toolbar, 24); - elm_toolbar_homogenous_set(tb->toolbar, EINA_TRUE); - elm_toolbar_scrollable_set(tb->toolbar, EINA_FALSE); - - evas_object_size_hint_weight_set(tb->toolbar, EVAS_HINT_EXPAND, 0.0); - evas_object_size_hint_align_set(tb->toolbar, EVAS_HINT_FILL, 0.5); - - elm_layout_content_set(tb->layout, "ephoto.toolbar.swallow", tb->toolbar); - - o = elm_icon_add(tb->toolbar); - elm_icon_file_set(o, PACKAGE_DATA_DIR "/images/change_directory.png", NULL); - elm_toolbar_item_add(tb->toolbar, o, "Change Directory", _ephoto_change_directory_window, tb); - - o = elm_icon_add(tb->toolbar); - elm_icon_file_set(o, PACKAGE_DATA_DIR "/images/filter.png", NULL); - elm_toolbar_item_add(tb->toolbar, o, "Filter", NULL, NULL); - - o = elm_icon_add(tb->toolbar); - elm_icon_file_set(o, PACKAGE_DATA_DIR "/images/view_presentation.png", NULL); - tb->view_large = elm_toolbar_item_add(tb->toolbar, o, "View Large", _ephoto_view_large, tb); - - o = elm_icon_add(tb->toolbar); - elm_icon_file_set(o, PACKAGE_DATA_DIR "/images/play_slideshow.png", NULL); - elm_toolbar_item_add(tb->toolbar, o, "Play Slideshow", _ephoto_view_slideshow, tb); - - o = elm_icon_add(tb->toolbar); - elm_icon_file_set(o, PACKAGE_DATA_DIR "/images/preferences.png", NULL); - elm_toolbar_item_add(tb->toolbar, o, "Preferences", _ephoto_preferences, tb); - - tb->eg.item_style = "ephoto"; - tb->eg.func.label_get = _ephoto_get_label; - tb->eg.func.icon_get = _ephoto_get_icon; - tb->eg.func.state_get = _ephoto_get_state; - tb->eg.func.del = _ephoto_grid_del; - - evas_object_data_set(tb->layout, "thumb_browser", tb); - evas_object_event_callback_add(tb->layout, EVAS_CALLBACK_DEL, _ephoto_del_cb, tb); - evas_object_event_callback_add(tb->layout, EVAS_CALLBACK_SHOW, _ephoto_show_cb, tb); - evas_object_event_callback_add(tb->layout, EVAS_CALLBACK_KEY_DOWN, - _ephoto_key_pressed, tb); - evas_object_event_callback_add(tb->layout, EVAS_CALLBACK_MOUSE_WHEEL, - _ephoto_mouse_wheel, tb); - evas_object_focus_set(tb->layout, 1); - - ephoto_populate_thumbnails(tb->layout); - _ephoto_set_title(em->config->directory); - - return tb->layout; -} - - -/*Show the thumbnail browser*/ -static void -_ephoto_show_cb(void *data, Evas *e, Evas_Object *obj, void *event_info) - -{ - /* Ephoto_Thumb_Browser *tb = evas_object_data_get(obj, "thumb_browser"); */ - - /* evas_object_show(tb->toolbar); */ - /* evas_object_show(tb->thumb_browser); */ - /* evas_object_show(tb->dir_label); */ - /* evas_object_show(tb->thumb_slider); */ - /* evas_object_show(tb->thbox); */ - _ephoto_set_title(em->config->directory); -} - -/* Use ecore thread facility to avoid lock completly */ - -/*Zoom out the thumbnail size*/ -static void -_ephoto_zoom_out(void *data, Evas_Object *obj, void *event) -{ - int val; - Ephoto_Thumb_Browser *tb = data; - - val = elm_slider_value_get(tb->thumb_slider); - val -= (SLIDER_MAX + SLIDER_MIN) / 10; - if (val > SLIDER_MAX) - val = SLIDER_MAX; - elm_slider_value_set(tb->thumb_slider, val); - _ephoto_slider_changed(data, obj, event); -} - -/*Zoom in the thumbnail size*/ -static void -_ephoto_zoom_in(void *data, Evas_Object *obj, void *event) -{ - int val; - Ephoto_Thumb_Browser *tb = data; - - val = elm_slider_value_get(tb->thumb_slider); - val += (SLIDER_MAX + SLIDER_MIN) / 10; - if (val > SLIDER_MAX) - val = SLIDER_MAX; - elm_slider_value_set(tb->thumb_slider, val); - _ephoto_slider_changed(data, obj, event); - -} - -/*Zoom half the thumbnail size*/ -static void -_ephoto_zoom_regular_size(void *data, Evas_Object *obj, void *event) -{ - int val; - Ephoto_Thumb_Browser *tb = data; - - val = (SLIDER_MAX + SLIDER_MIN) / 2; - elm_slider_value_set(tb->thumb_slider, val); - _ephoto_slider_changed(data, obj, event); -} -/*Change the thumbnail size*/ -static void -_ephoto_slider_changed(void *data, Evas_Object *obj, void *event) -{ - Ephoto_Thumb_Browser *tb = data; - int val = elm_slider_value_get(tb->thumb_slider); - elm_gengrid_item_size_set(tb->thumb_browser, val, val / THUMB_RATIO); - - ephoto_thumb_size_set(val); -} - -/* Called when adding a directory or a file to elm_gengrid */ -/* -static Ephoto_Thumb_Data * -_ephoto_thumbnail_add(Ephoto_Thumb_Browser *tb, const char *path) -{ - Ephoto_Thumb_Data *etd = calloc(1, sizeof(*etd)); - etd->file = eina_stringshare_add(path); - etd->thumb_path = eina_stringshare_ref(etd->file); - etd->basename = ecore_file_file_get(etd->file); - elm_gengrid_item_append(tb->thumb_browser, &tb->eg, etd, NULL, NULL); - return etd; -} -*/ - -/*Get the label for the icon in the grid*/ -static char * -_ephoto_get_label(void *data, Evas_Object *obj, const char *part) -{ - Ephoto_Entry *e = data; - return strdup(e->basename); -} - -static Evas_Object * -_ephoto_directory_up_add(Evas_Object *parent_obj) -{ - Evas_Object *obj = edje_object_add(evas_object_evas_get(parent_obj)); - edje_object_file_set(obj, PACKAGE_DATA_DIR "/themes/default/ephoto.edj", - "/ephoto/directory/up"); - return obj; -} - -/*Get the image for the icon in the grid*/ -static Evas_Object * -_ephoto_get_icon(void *data, Evas_Object *obj, const char *part) -{ - Ephoto_Entry *e = data; - Evas_Object *thumb, *o; - - if (strcmp(part, "elm.swallow.icon") != 0) return NULL; - - thumb = elm_layout_add(obj); - if (e->is_dir) - elm_layout_file_set(thumb, PACKAGE_DATA_DIR "/themes/default/ephoto.edj", - "/ephoto/thumb/no_border"); - else - elm_layout_file_set(thumb, PACKAGE_DATA_DIR "/themes/default/ephoto.edj", - "/ephoto/thumb"); - evas_object_size_hint_weight_set(thumb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_show(thumb); - - if (e->is_dir) - { - if (e->is_up) - o = _ephoto_directory_up_add(thumb); - else - o = ephoto_directory_thumb_add(thumb, e->path); - } - else - o = ephoto_thumb_add(thumb, e->path); - - elm_layout_content_set(thumb, "ephoto.swallow.content", o); - - return thumb; -} - -/*Delete the grid*/ -static void -_ephoto_grid_del(void *data, Evas_Object *obj) -{ - Ephoto_Entry *e = data; - e->item = NULL; -} - -/*Thumb clicked job*/ -static void -_ephoto_thumb_clicked_job(void *data) -{ - const Eina_List *selected; - char *parent_dir; - Ephoto_Entry *e; - Ephoto_Thumb_Browser *tb = data; - - selected = elm_gengrid_selected_items_get(tb->thumb_browser); - e = elm_gengrid_item_data_get(eina_list_data_get(selected)); - if (e->is_dir) - { - if (e->is_up) - { - parent_dir = ecore_file_dir_get(em->config->directory); - _ephoto_change_directory(tb, parent_dir); - free(parent_dir); - } - else - _ephoto_change_directory(tb, e->path); - } - else - evas_object_smart_callback_call(tb->layout, "selected", (void*)e->path); -} - -/* Change the current directory showed in thumb browser. */ -static void -_ephoto_change_directory(Ephoto_Thumb_Browser *tb, const char *directory) -{ - Elm_Gengrid_Item *item; - - if ((directory) && (eina_stringshare_replace(&em->config->directory, directory))) - { - elm_gengrid_clear(tb->thumb_browser); - ephoto_entries_free(em); - ephoto_populate_thumbnails(tb->layout); - elm_label_label_set(tb->dir_label, em->config->directory); - _ephoto_set_title(em->config->directory); - } - - evas_object_smart_callback_call(tb->layout, "directory,changed", (char *) em->config->directory); -} - -/*Called when an item is selected in gengrid*/ -static void -_ephoto_thumb_selected(void *data, Evas_Object *obj, void *event_info) -{ - Ephoto_Thumb_Browser *tb = data; - Ephoto_Thumb_Data *etd = elm_gengrid_item_data_get(event_info); - if (etd->is_directory) - elm_toolbar_item_disabled_set(tb->view_large, EINA_TRUE); - else - elm_toolbar_item_disabled_set(tb->view_large, EINA_FALSE); -} - -/*Check to see if the thumbnail was double clicked*/ -static void -_ephoto_thumb_clicked(void *data, Evas_Object *obj, void *event_info) -{ - ecore_job_add(_ephoto_thumb_clicked_job, data); -} - -/*File Selector is shown*/ -static void -_ephoto_fileselector_shown(void *data, Evas *e, Evas_Object *obj, void *event_info) -{ - elm_fileselector_path_set(obj, em->config->directory); - evas_render(em->e); -} - -/*Directory has been chosen*/ -static void -_ephoto_directory_chosen(void *data, Evas_Object *obj, void *event_info) -{ - Ephoto_Thumb_Browser *tb = data; - - _ephoto_change_directory(tb, elm_fileselector_selected_get(obj)); - evas_object_del(tb->fsel_win); - elm_toolbar_item_unselect_all(tb->toolbar); -} - -/*Show the flow browser*/ -static void -_ephoto_view_large(void *data, Evas_Object *obj, void *event_info) -{ - const Eina_List *selected; - Evas_Object *o; - Ephoto_Thumb_Data *etd; - Ephoto_Thumb_Browser *tb = data; - - selected = elm_gengrid_selected_items_get(tb->thumb_browser); - - /* em->flow_browser = ephoto_create_flow_browser(em->layout); */ - - if (eina_list_data_get(selected)) - { - o = eina_list_data_get(selected); - etd = (Ephoto_Thumb_Data *)elm_gengrid_item_data_get((Elm_Gengrid_Item *)o); - /* _ephoto_thumb_clicked_job(etd->file); */ - evas_object_smart_callback_call(tb->layout, "selected", (char *)etd->file); - - } - else - { - /* _ephoto_thumb_clicked_job( eina_list_data_get(em->images)); */ - // TODO: evas_object_smart_callback_call(tb->layout, "selected", eina_list_data_get(em->images)); - - } - - elm_toolbar_item_unselect_all(tb->toolbar); -} - -/*Change directory*/ -static void -_ephoto_change_directory_window(void *data, Evas_Object *obj, void *event_info) -{ - Evas_Object *fsel; - Ephoto_Thumb_Browser *tb = data; - - tb->fsel_win = elm_win_inwin_add(em->win); - - fsel = elm_fileselector_add(tb->fsel_win); - elm_fileselector_folder_only_set(fsel, EINA_TRUE); - elm_fileselector_buttons_ok_cancel_set(fsel, EINA_TRUE); - elm_fileselector_path_set(fsel, em->config->directory); - evas_object_event_callback_add(fsel, EVAS_CALLBACK_SHOW, - _ephoto_fileselector_shown, tb); - evas_object_smart_callback_add(fsel, "done", - _ephoto_directory_chosen, tb); - - elm_win_inwin_content_set(tb->fsel_win, fsel); - elm_win_inwin_activate(tb->fsel_win); - - evas_object_show(fsel); - evas_object_show(tb->fsel_win); -} - -/*Show slideshow*/ -static void -_ephoto_view_slideshow(void *data, Evas_Object *obj, void *event_info) -{ - Ephoto_Thumb_Browser *tb = data; - /* FIXME */ - //ephoto_hide_thumb_browser(); - ephoto_show_slideshow(0, NULL); - elm_toolbar_item_unselect_all(tb->toolbar); -} - -/* Show the preferences window */ -static void -_ephoto_preferences(void *data, Evas_Object *obj, void *event_info) -{ - Ephoto_Thumb_Browser *tb = data; - - ephoto_show_preferences(em); - elm_toolbar_item_unselect_all(tb->toolbar); -} - -/*Destroy the thumbnail browser object itself*/ -static void -_ephoto_del_cb(void *data, Evas *e, Evas_Object *obj, void *event_info) -{ - Ephoto_Thumb_Browser *tb = data; - const Eina_List *l, *iter; - Elm_Gengrid_Item *item; - Ephoto_Thumb_Data *etd; - - l = elm_gengrid_items_get(tb->thumb_browser); - EINA_LIST_FOREACH(l, iter, item) - { - etd = (Ephoto_Thumb_Data *)elm_gengrid_item_data_get(item); - eina_stringshare_del(etd->thumb_path); - eina_stringshare_del(etd->file); - free(etd); - } - em->thumb_browser = NULL; -} - -#endif