#include "ephoto.h" /*Callbacks*/ static void _ephoto_go_back(void *data, Evas_Object *obj, void *event_info); static void _ephoto_go_first(void *data, Evas_Object *obj, void *event_info); static void _ephoto_go_last(void *data, Evas_Object *obj, void *event_info); static void _ephoto_go_next(void *data, Evas_Object *obj, void *event_info); static void _ephoto_go_previous(void *data, Evas_Object *obj, void *event_info); static void _ephoto_go_slideshow(void *data, Evas_Object *obj, void *event_info); static void _ephoto_key_pressed(void *data, Evas *e, Evas_Object *obj, void *event_info); static void _ephoto_flow_browser_show_cb(void *data, Evas *e, Evas_Object *obj, void *event_info); static void _ephoto_flow_browser_del_cb(void *data, Evas *e, Evas_Object *obj, void *event_info); typedef struct _Ephoto_Flow_Browser Ephoto_Flow_Browser; struct _Ephoto_Flow_Browser { Evas_Object *flow_browser; Eina_List *iter; Evas_Object *image; Evas_Object *image2; Evas_Object *toolbar; const char *cur_image; }; static const char *toolbar_items[] = { "First", "Previous", "Next", "Last", "Slideshow" }; 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); } static void _ephoto_go_update(Ephoto_Flow_Browser *ef) { const char *file_type; char *buffer; int length; efreet_mime_init(); elm_layout_content_unset(ef->flow_browser, "ephoto.flow.swallow"); evas_object_hide(ef->image); evas_object_hide(ef->image2); file_type = efreet_mime_type_get(ef->cur_image); if (file_type && !strcmp(file_type, "image/jpeg")) { elm_photocam_file_set(ef->image, ef->cur_image); elm_layout_content_set(ef->flow_browser, "ephoto.flow.swallow", ef->image); evas_object_show(ef->image); } else { elm_image_file_set(ef->image2, ef->cur_image, NULL); elm_layout_content_set(ef->flow_browser, "ephoto.flow.swallow", ef->image2); evas_object_show(ef->image2); } elm_toolbar_item_unselect_all(ef->toolbar); efreet_mime_shutdown(); length = strlen(ef->cur_image) + strlen("Ephoto - ") + 1; buffer = alloca(length); snprintf(buffer, length, "Ephoto - %s", ef->cur_image); elm_win_title_set(em->win, buffer); } /*Create the flow browser*/ Evas_Object * ephoto_create_flow_browser(Evas_Object *parent) { Evas_Object *o; Ephoto_Flow_Browser *ef; ef = calloc(1, sizeof(Ephoto_Flow_Browser)); ef->flow_browser = elm_layout_add(parent); elm_layout_file_set(ef->flow_browser, PACKAGE_DATA_DIR "/themes/default/ephoto.edj", "ephoto/flow/layout"); // elm_win_resize_object_add(em->win, em->flow_browser); evas_object_size_hint_weight_set(ef->flow_browser, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(ef->flow_browser, EVAS_HINT_FILL, EVAS_HINT_FILL); ef->image = elm_photocam_add(ef->flow_browser); elm_photocam_zoom_mode_set(ef->image, ELM_PHOTOCAM_ZOOM_MODE_AUTO_FIT); evas_object_size_hint_weight_set(ef->image, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(ef->image, EVAS_HINT_FILL, EVAS_HINT_FILL); ef->image2 = elm_image_add(ef->flow_browser); elm_image_smooth_set(ef->image2, EINA_TRUE); evas_object_size_hint_weight_set(ef->image2, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(ef->image2, EVAS_HINT_FILL, EVAS_HINT_FILL); ef->toolbar = elm_toolbar_add(ef->flow_browser); elm_toolbar_icon_size_set(ef->toolbar, 24); elm_toolbar_homogenous_set(ef->toolbar, EINA_TRUE); evas_object_size_hint_weight_set(ef->toolbar, EVAS_HINT_EXPAND, 0.0); evas_object_size_hint_align_set(ef->toolbar, EVAS_HINT_FILL, 0.5); elm_layout_content_set(ef->flow_browser, "ephoto.flow.swallow", ef->toolbar); evas_object_show(ef->toolbar); o = elm_icon_add(ef->toolbar); elm_icon_file_set(o, PACKAGE_DATA_DIR "/images/go_back.png", NULL); elm_toolbar_item_add(ef->toolbar, o, "Go Back", _ephoto_go_back, ef); o = elm_icon_add(ef->toolbar); elm_icon_file_set(o, PACKAGE_DATA_DIR "/images/first.png", NULL); elm_toolbar_item_add(ef->toolbar, o, "First", _ephoto_go_first, ef); o = elm_icon_add(ef->toolbar); elm_icon_file_set(o, PACKAGE_DATA_DIR "/images/previous.png", NULL); elm_toolbar_item_add(ef->toolbar, o, "Previous", _ephoto_go_previous, ef); o = elm_icon_add(ef->toolbar); elm_icon_file_set(o, PACKAGE_DATA_DIR "/images/next.png", NULL); elm_toolbar_item_add(ef->toolbar, o, "Next", _ephoto_go_next, ef); o = elm_icon_add(ef->toolbar); elm_icon_file_set(o, PACKAGE_DATA_DIR "/images/last.png", NULL); elm_toolbar_item_add(ef->toolbar, o, "Last", _ephoto_go_last, ef); o = elm_icon_add(ef->toolbar); elm_icon_file_set(o, PACKAGE_DATA_DIR "/images/play_slideshow.png", NULL); elm_toolbar_item_add(ef->toolbar, o, "Slideshow", _ephoto_go_slideshow, ef); evas_object_event_callback_add(ef->flow_browser, EVAS_CALLBACK_SHOW, _ephoto_flow_browser_show_cb, ef); evas_object_event_callback_add(ef->flow_browser, EVAS_CALLBACK_DEL, _ephoto_flow_browser_del_cb, ef); evas_object_data_set(ef->flow_browser, "flow_browser", ef); return ef->flow_browser; } /*Show the flow browser*/ void ephoto_flow_browser_image_set(Evas_Object *obj, const char *current_image) { Ephoto_Flow_Browser *ef; const char *file_type; Elm_Toolbar_Item *o; int i; ef = evas_object_data_get(obj, "flow_browser"); if (current_image) { ef->cur_image = current_image; evas_object_event_callback_add(ef->flow_browser, EVAS_CALLBACK_KEY_UP, _ephoto_key_pressed, ef); ef->iter = eina_list_data_find_list(em->images, current_image); for (i = 0; i < (sizeof (toolbar_items) / sizeof (char*)); ++i) { o = elm_toolbar_item_find_by_label(ef->toolbar, toolbar_items[i]); elm_toolbar_item_disabled_set(o, !ef->iter ? EINA_TRUE : EINA_FALSE); } fprintf(stderr, "iter: %p\n", ef->iter); _ephoto_go_update(ef); } else { for (i = 0; i < (sizeof (toolbar_items) / sizeof (char*)); ++i) { o = elm_toolbar_item_find_by_label(ef->toolbar, toolbar_items[i]); elm_toolbar_item_disabled_set(o, EINA_TRUE); } } elm_layout_content_set(ef->flow_browser, "ephoto.toolbar.swallow", ef->toolbar); evas_object_show(ef->toolbar); evas_object_show(ef->flow_browser); evas_object_focus_set(ef->flow_browser, 1); } static void _ephoto_flow_browser_show_cb(void *data, Evas *e, Evas_Object *obj, void *event_info) { Ephoto_Flow_Browser *ef = data; ephoto_flow_browser_image_set(ef->flow_browser, NULL); } /*Delete the flow browser*/ static void _ephoto_flow_browser_del_cb(void *data, Evas *e, Evas_Object *obj, void *event_info) { Ephoto_Flow_Browser *ef = data; Eina_List *items; } /*A key has been pressed*/ static const struct { const char *name; void (*func)(void *data, Evas_Object *obj, void *event_info); } keys[] = { { "Left", _ephoto_go_previous }, { "Right", _ephoto_go_next }, { "space", _ephoto_go_next }, { "Escape", _ephoto_go_back }, { NULL, NULL } }; static void _ephoto_key_pressed(void *data, Evas *e, Evas_Object *obj, void *event_data) { Ephoto_Flow_Browser *ef = data; Evas_Event_Key_Up *eku; int i; eku = (Evas_Event_Key_Up *)event_data; for (i = 0; keys[i].name; ++i) if (!strcmp(eku->keyname, keys[i].name)) keys[i].func(ef, NULL, NULL); } /*Go back to the thumbnail viewer*/ static void _ephoto_go_back(void *data, Evas_Object *obj, void *event_info) { Ephoto_Flow_Browser *ef = data; evas_object_smart_callback_call(ef->flow_browser, "delete,request", NULL); /* elm_toolbar_item_unselect_all(ef->toolbar); */ /* em->thumb_browser = ephoto_create_thumb_browser(em->layout, ecore_file_dir_get(ef->cur_image)); */ /* elm_layout_content_set(em->layout, "ephoto.content.swallow", em->thumb_browser); */ } /*Go to the very first image in the list*/ static void _ephoto_go_first(void *data, Evas_Object *obj, void *event_info) { Ephoto_Flow_Browser *ef = data; ef->iter = em->images; ef->cur_image = eina_list_data_get(ef->iter); _ephoto_go_update(ef); } /*Go to the very last image in the list*/ static void _ephoto_go_last(void *data, Evas_Object *obj, void *event_info) { const char *file_type; Ephoto_Flow_Browser *ef = data; ef->iter = eina_list_last(em->images); ef->cur_image = eina_list_data_get(ef->iter); _ephoto_go_update(ef); } /*Go to the next image in the list*/ static void _ephoto_go_next(void *data, Evas_Object *obj, void *event_info) { const char *file_type; Ephoto_Flow_Browser *ef = data; ef->iter = eina_list_next(ef->iter); if (!ef->iter) ef->iter = em->images; ef->cur_image = eina_list_data_get(ef->iter); _ephoto_go_update(ef); } /*Go to the previous image in the list*/ static void _ephoto_go_previous(void *data, Evas_Object *obj, void *event_info) { const char *file_type; Ephoto_Flow_Browser *ef = data; ef->iter = eina_list_prev(ef->iter); if (!ef->iter) ef->iter = eina_list_last(em->images); ef->cur_image = eina_list_data_get(ef->iter); _ephoto_go_update(ef); } /*Go to the slideshow*/ static void _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); elm_toolbar_item_unselect_all(ef->toolbar); }