2010-07-01 11:49:22 -07:00
|
|
|
#include "ephoto.h"
|
|
|
|
|
2010-09-29 10:34:35 -07:00
|
|
|
#define SLIDER_MAX 300
|
|
|
|
#define SLIDER_MIN 80
|
2010-10-03 02:50:00 -07:00
|
|
|
|
2010-10-08 11:51:19 -07:00
|
|
|
#define PARENT_DIR "Up"
|
2010-10-03 02:50:00 -07:00
|
|
|
|
2010-09-13 09:40:33 -07:00
|
|
|
typedef struct _Ephoto_Thumb_Data Ephoto_Thumb_Data;
|
|
|
|
typedef struct _Ephoto_Thumb_Browser Ephoto_Thumb_Browser;
|
|
|
|
|
|
|
|
struct _Ephoto_Thumb_Data
|
|
|
|
{
|
2010-10-08 11:51:19 -07:00
|
|
|
const char *thumb_path;
|
|
|
|
const char *file;
|
|
|
|
const char *basename;
|
|
|
|
Eina_Bool is_directory;
|
2010-09-13 09:40:33 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _Ephoto_Thumb_Browser
|
|
|
|
{
|
|
|
|
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;
|
2010-10-03 02:50:00 -07:00
|
|
|
Elm_Toolbar_Item *view_large;
|
2010-09-13 09:40:33 -07:00
|
|
|
Eio_File *list;
|
|
|
|
};
|
|
|
|
|
2010-09-13 15:24:59 -07:00
|
|
|
#define THUMB_RATIO (256 / 192)
|
2010-09-13 09:40:33 -07:00
|
|
|
|
2010-07-01 11:49:22 -07:00
|
|
|
/*Callbacks*/
|
|
|
|
static void _ephoto_slider_changed(void *data, Evas_Object *obj, void *event_info);
|
2010-10-08 11:51:19 -07:00
|
|
|
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);
|
2010-07-14 16:23:54 -07:00
|
|
|
static void _ephoto_thumb_clicked_job(void *data);
|
|
|
|
static void _ephoto_thumb_clicked(void *data, Evas_Object *obj, void *event_info);
|
2010-10-03 02:50:00 -07:00
|
|
|
static void _ephoto_thumb_selected(void *data, Evas_Object *obj, void *event_info);
|
2010-07-05 14:07:53 -07:00
|
|
|
static void _ephoto_view_large(void *data, Evas_Object *obj, void *event_info);
|
2010-10-03 02:50:00 -07:00
|
|
|
static void _ephoto_change_directory_window(void *data, Evas_Object *obj, void *event_info);
|
2010-07-27 19:06:03 -07:00
|
|
|
static void _ephoto_view_slideshow(void *data, Evas_Object *obj, void *event_info);
|
2010-09-19 08:30:36 -07:00
|
|
|
static void _ephoto_preferences(void *data, Evas_Object *obj, void *event_info);
|
2010-09-13 09:40:33 -07:00
|
|
|
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);
|
2010-09-29 10:34:35 -07:00
|
|
|
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);
|
2010-10-03 02:50:00 -07:00
|
|
|
static void _ephoto_thumbnail_add(Ephoto_Thumb_Browser *tb, const char *path, Eina_Bool is_dir);
|
|
|
|
static void _ephoto_change_directory(Ephoto_Thumb_Browser *tb, const char *directory);
|
|
|
|
static void _ephoto_populate_images(Ephoto_Thumb_Browser *tb);
|
2010-09-29 10:34:35 -07:00
|
|
|
|
|
|
|
/*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 },
|
2010-10-03 02:50:00 -07:00
|
|
|
{ "d", "Control", _ephoto_change_directory_window},
|
2010-09-29 10:34:35 -07:00
|
|
|
{ "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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-03 02:50:00 -07:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2010-07-01 11:49:22 -07:00
|
|
|
/*Create the thumbnail browser object*/
|
2010-09-13 09:40:33 -07:00
|
|
|
Evas_Object *
|
2010-09-19 08:30:36 -07:00
|
|
|
ephoto_create_thumb_browser(Evas_Object *parent)
|
2010-07-01 11:49:22 -07:00
|
|
|
{
|
|
|
|
Evas_Object *o;
|
2010-09-13 09:40:33 -07:00
|
|
|
Ephoto_Thumb_Browser *tb;
|
|
|
|
|
|
|
|
tb = calloc(1, sizeof(Ephoto_Thumb_Browser));
|
2010-07-01 11:49:22 -07:00
|
|
|
|
|
|
|
elm_theme_extension_add(NULL, PACKAGE_DATA_DIR "/themes/default/ephoto.edj");
|
|
|
|
|
2010-09-13 09:40:33 -07:00
|
|
|
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);
|
2010-07-01 11:49:22 -07:00
|
|
|
|
2010-09-13 09:40:33 -07:00
|
|
|
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);
|
2010-09-19 08:30:36 -07:00
|
|
|
elm_label_label_set(tb->dir_label, em->config->directory);
|
2010-09-13 09:40:33 -07:00
|
|
|
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);
|
2010-09-29 10:34:35 -07:00
|
|
|
elm_slider_min_max_set(tb->thumb_slider, SLIDER_MIN, SLIDER_MAX);
|
2010-09-13 15:24:59 -07:00
|
|
|
elm_slider_value_set(tb->thumb_slider, em->config->thumb_size);
|
2010-09-13 09:40:33 -07:00
|
|
|
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);
|
2010-09-13 15:27:00 -07:00
|
|
|
elm_gengrid_bounce_set(tb->thumb_browser, EINA_TRUE, EINA_FALSE);
|
2010-09-13 15:24:59 -07:00
|
|
|
elm_gengrid_item_size_set(tb->thumb_browser, em->config->thumb_size, em->config->thumb_size / THUMB_RATIO);
|
2010-09-13 09:40:33 -07:00
|
|
|
elm_gengrid_horizontal_set(tb->thumb_browser, EINA_TRUE);
|
|
|
|
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);
|
|
|
|
evas_object_size_hint_fill_set(tb->thumb_browser, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
|
|
|
|
|
|
|
elm_object_style_set(tb->thumb_browser, "ephoto");
|
2010-10-03 02:50:00 -07:00
|
|
|
evas_object_smart_callback_add(tb->thumb_browser, "selected", _ephoto_thumb_selected, tb);
|
2010-09-13 09:40:33 -07:00
|
|
|
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);
|
2010-08-25 17:40:31 -07:00
|
|
|
elm_icon_file_set(o, PACKAGE_DATA_DIR "/images/change_directory.png", NULL);
|
2010-10-03 02:50:00 -07:00
|
|
|
elm_toolbar_item_add(tb->toolbar, o, "Change Directory", _ephoto_change_directory_window, tb);
|
2010-08-25 17:40:31 -07:00
|
|
|
|
2010-09-13 09:40:33 -07:00
|
|
|
o = elm_icon_add(tb->toolbar);
|
2010-08-25 17:40:31 -07:00
|
|
|
elm_icon_file_set(o, PACKAGE_DATA_DIR "/images/filter.png", NULL);
|
2010-09-13 09:40:33 -07:00
|
|
|
elm_toolbar_item_add(tb->toolbar, o, "Filter", NULL, NULL);
|
2010-08-25 17:40:31 -07:00
|
|
|
|
2010-09-13 09:40:33 -07:00
|
|
|
o = elm_icon_add(tb->toolbar);
|
2010-08-25 17:40:31 -07:00
|
|
|
elm_icon_file_set(o, PACKAGE_DATA_DIR "/images/view_presentation.png", NULL);
|
2010-10-03 02:50:00 -07:00
|
|
|
tb->view_large = elm_toolbar_item_add(tb->toolbar, o, "View Large", _ephoto_view_large, tb);
|
2010-08-25 17:40:31 -07:00
|
|
|
|
2010-09-13 09:40:33 -07:00
|
|
|
o = elm_icon_add(tb->toolbar);
|
2010-08-25 17:40:31 -07:00
|
|
|
elm_icon_file_set(o, PACKAGE_DATA_DIR "/images/play_slideshow.png", NULL);
|
2010-09-13 09:40:33 -07:00
|
|
|
elm_toolbar_item_add(tb->toolbar, o, "Play Slideshow", _ephoto_view_slideshow, tb);
|
|
|
|
|
2010-09-19 08:30:36 -07:00
|
|
|
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);
|
|
|
|
|
2010-09-13 09:40:33 -07:00
|
|
|
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);
|
2010-09-29 10:34:35 -07:00
|
|
|
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);
|
2010-10-03 02:50:00 -07:00
|
|
|
|
|
|
|
ephoto_populate_thumbnails(tb->layout);
|
|
|
|
_ephoto_set_title(em->config->directory);
|
|
|
|
|
2010-09-13 09:40:33 -07:00
|
|
|
return tb->layout;
|
2010-07-01 11:49:22 -07:00
|
|
|
}
|
|
|
|
|
2010-10-02 17:13:02 -07:00
|
|
|
|
2010-07-01 11:49:22 -07:00
|
|
|
/*Show the thumbnail browser*/
|
2010-09-13 09:40:33 -07:00
|
|
|
static void
|
|
|
|
_ephoto_show_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
|
|
|
|
|
2010-07-01 11:49:22 -07:00
|
|
|
{
|
2010-09-19 08:30:36 -07:00
|
|
|
/* Ephoto_Thumb_Browser *tb = evas_object_data_get(obj, "thumb_browser"); */
|
2010-09-07 06:12:08 -07:00
|
|
|
|
2010-09-13 09:40:33 -07:00
|
|
|
/* 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); */
|
2010-10-03 02:50:00 -07:00
|
|
|
_ephoto_set_title(em->config->directory);
|
2010-07-01 11:49:22 -07:00
|
|
|
}
|
|
|
|
|
2010-07-02 04:17:59 -07:00
|
|
|
/* Use ecore thread facility to avoid lock completly */
|
2010-07-01 11:49:22 -07:00
|
|
|
|
2010-10-03 02:50:00 -07:00
|
|
|
/* Check directory type from another thread */
|
|
|
|
static Eina_Bool
|
|
|
|
_ephoto_populate_filter_directory(void *data, const char *file)
|
|
|
|
{
|
|
|
|
const char *type;
|
|
|
|
|
|
|
|
if (!(type = efreet_mime_type_get(file)))
|
|
|
|
return EINA_FALSE;
|
|
|
|
if (!strncmp(type, "inode/directory", 15))
|
|
|
|
return EINA_TRUE;
|
|
|
|
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-07-22 09:15:16 -07:00
|
|
|
/* Check image type from another thread */
|
|
|
|
static Eina_Bool
|
2010-10-03 02:50:00 -07:00
|
|
|
_ephoto_populate_filter_image(void *data, const char *file)
|
2010-07-02 04:17:59 -07:00
|
|
|
{
|
2010-10-08 11:51:19 -07:00
|
|
|
const char *type, *basename;
|
2010-07-02 04:17:59 -07:00
|
|
|
|
2010-10-08 11:51:19 -07:00
|
|
|
/* TODO: eio_file_ls_direct() and get more useful parameter than file */
|
|
|
|
basename = ecore_file_file_get(file);
|
|
|
|
if ((!basename) || (basename[0] == '.'))
|
|
|
|
return EINA_FALSE;
|
2010-07-02 04:17:59 -07:00
|
|
|
|
2010-10-08 11:51:19 -07:00
|
|
|
/* TODO: speed up case for jpg/jpeg/png */
|
|
|
|
if (!(type = efreet_mime_type_get(file)))
|
|
|
|
return EINA_FALSE;
|
|
|
|
if (!strncmp(type, "image", 5))
|
|
|
|
return EINA_TRUE;
|
|
|
|
|
|
|
|
return EINA_FALSE;
|
2010-07-01 11:49:22 -07:00
|
|
|
}
|
|
|
|
|
2010-10-03 02:50:00 -07:00
|
|
|
/*Done populating directories*/
|
|
|
|
static void
|
|
|
|
_ephoto_populate_end_directory(void *data)
|
|
|
|
{
|
|
|
|
Ephoto_Thumb_Browser *tb = (Ephoto_Thumb_Browser *)data;
|
|
|
|
_ephoto_populate_images(tb);
|
|
|
|
}
|
|
|
|
|
2010-07-05 14:07:53 -07:00
|
|
|
/*Done populating images*/
|
2010-07-01 11:49:22 -07:00
|
|
|
static void
|
2010-10-03 02:50:00 -07:00
|
|
|
_ephoto_populate_end_image(void *data)
|
2010-07-01 11:49:22 -07:00
|
|
|
{
|
2010-09-13 09:40:33 -07:00
|
|
|
Ephoto_Thumb_Browser *tb = (Ephoto_Thumb_Browser *)data;
|
2010-07-01 11:49:22 -07:00
|
|
|
|
2010-09-13 09:40:33 -07:00
|
|
|
tb->list = NULL;
|
2010-10-02 17:13:02 -07:00
|
|
|
|
|
|
|
if (em->config->sort_images)
|
|
|
|
{
|
|
|
|
Eina_List *l;
|
|
|
|
const char *file;
|
|
|
|
em->images = eina_list_sort(em->images,
|
|
|
|
eina_list_count(em->images),
|
|
|
|
EINA_COMPARE_CB(strcoll));
|
|
|
|
EINA_LIST_FOREACH(em->images, l, file)
|
2010-10-03 02:50:00 -07:00
|
|
|
{
|
|
|
|
_ephoto_thumbnail_add(tb, file, EINA_FALSE);
|
|
|
|
}
|
2010-10-02 17:13:02 -07:00
|
|
|
}
|
2010-07-01 11:49:22 -07:00
|
|
|
}
|
|
|
|
|
2010-09-07 06:12:08 -07:00
|
|
|
static void
|
2010-10-03 02:50:00 -07:00
|
|
|
_ephoto_populate_error(int error, void *data)
|
2010-09-07 06:12:08 -07:00
|
|
|
{
|
2010-09-13 09:40:33 -07:00
|
|
|
Ephoto_Thumb_Browser *tb = (Ephoto_Thumb_Browser*)data;
|
2010-09-07 06:12:08 -07:00
|
|
|
/* We don't handle error case in ephoto */
|
2010-09-13 09:40:33 -07:00
|
|
|
tb->list = NULL;
|
2010-09-07 06:12:08 -07:00
|
|
|
}
|
|
|
|
|
2010-07-22 09:15:16 -07:00
|
|
|
/* Build the interface component after detection from main thread */
|
2010-07-02 04:17:59 -07:00
|
|
|
static void
|
2010-10-03 02:50:00 -07:00
|
|
|
_ephoto_populate_main_directory(void *data, const char *file)
|
2010-07-01 11:49:22 -07:00
|
|
|
{
|
2010-10-03 02:50:00 -07:00
|
|
|
Ephoto_Thumb_Browser *tb = (Ephoto_Thumb_Browser*)data;
|
|
|
|
_ephoto_thumbnail_add(tb, file, EINA_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Build the interface component after detection from main thread */
|
|
|
|
static void
|
|
|
|
_ephoto_populate_main_image(void *data, const char *file)
|
|
|
|
{
|
|
|
|
Ephoto_Thumb_Browser *tb = (Ephoto_Thumb_Browser*)data;
|
|
|
|
const char *type;
|
2010-07-01 11:49:22 -07:00
|
|
|
|
2010-07-22 09:15:16 -07:00
|
|
|
file = eina_stringshare_ref(file);
|
|
|
|
|
2010-10-03 02:50:00 -07:00
|
|
|
em->images = eina_list_append(em->images, file);
|
2010-10-02 17:13:02 -07:00
|
|
|
if (em->config->sort_images) return;
|
2010-10-03 02:50:00 -07:00
|
|
|
|
|
|
|
if (!(type = efreet_mime_type_get(file)))
|
|
|
|
return;
|
|
|
|
if (!strncmp(type, "image", 5))
|
|
|
|
{
|
|
|
|
em->images = eina_list_append(em->images, file);
|
|
|
|
|
|
|
|
_ephoto_thumbnail_add(tb, file, EINA_FALSE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_ephoto_thumbnail_add(tb, file, EINA_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-02 04:17:59 -07:00
|
|
|
}
|
|
|
|
|
2010-10-03 02:50:00 -07:00
|
|
|
/*Create a thread to populate images*/
|
|
|
|
static void
|
|
|
|
_ephoto_populate_images(Ephoto_Thumb_Browser *tb)
|
|
|
|
{
|
|
|
|
tb->list = eio_file_ls(em->config->directory,
|
|
|
|
_ephoto_populate_filter_image,
|
|
|
|
_ephoto_populate_main_image,
|
|
|
|
_ephoto_populate_end_image,
|
|
|
|
_ephoto_populate_error,
|
|
|
|
tb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Start a thread to list images and directories in a directory without locking the interface */
|
2010-07-02 04:17:59 -07:00
|
|
|
void
|
2010-09-13 09:40:33 -07:00
|
|
|
ephoto_populate_thumbnails(Evas_Object *obj)
|
2010-07-02 04:17:59 -07:00
|
|
|
{
|
2010-09-13 09:40:33 -07:00
|
|
|
Ephoto_Thumb_Browser *tb = evas_object_data_get(obj, "thumb_browser");
|
|
|
|
|
2010-10-03 02:50:00 -07:00
|
|
|
_ephoto_thumbnail_add(tb, PARENT_DIR, EINA_TRUE);
|
2010-09-19 08:30:36 -07:00
|
|
|
tb->list = eio_file_ls(em->config->directory,
|
2010-10-03 02:50:00 -07:00
|
|
|
_ephoto_populate_filter_directory,
|
|
|
|
_ephoto_populate_main_directory,
|
|
|
|
_ephoto_populate_end_directory,
|
2010-09-07 06:12:08 -07:00
|
|
|
_ephoto_populate_error,
|
2010-09-13 09:40:33 -07:00
|
|
|
tb);
|
2010-07-02 04:17:59 -07:00
|
|
|
}
|
|
|
|
|
2010-09-29 10:34:35 -07:00
|
|
|
/*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);
|
|
|
|
}
|
2010-07-02 04:17:59 -07:00
|
|
|
/*Change the thumbnail size*/
|
|
|
|
static void
|
|
|
|
_ephoto_slider_changed(void *data, Evas_Object *obj, void *event)
|
|
|
|
{
|
2010-09-13 15:24:59 -07:00
|
|
|
int val;
|
2010-09-13 09:40:33 -07:00
|
|
|
Ephoto_Thumb_Browser *tb = data;
|
2010-07-01 11:49:22 -07:00
|
|
|
|
2010-09-13 09:40:33 -07:00
|
|
|
val = elm_slider_value_get(tb->thumb_slider);
|
2010-09-13 15:24:59 -07:00
|
|
|
elm_gengrid_item_size_set(tb->thumb_browser, val, val / THUMB_RATIO);
|
|
|
|
|
|
|
|
em->config->thumb_size = val;
|
2010-09-14 00:02:04 -07:00
|
|
|
ephoto_config_save(em, EINA_FALSE);
|
2010-07-01 11:49:22 -07:00
|
|
|
}
|
|
|
|
|
2010-10-03 02:50:00 -07:00
|
|
|
/* Called when adding a directory or a file to elm_gengrid */
|
|
|
|
static void
|
|
|
|
_ephoto_thumbnail_add(Ephoto_Thumb_Browser *tb, const char *path, Eina_Bool is_dir)
|
2010-07-01 11:49:22 -07:00
|
|
|
{
|
2010-10-03 02:50:00 -07:00
|
|
|
Ephoto_Thumb_Data *etd;
|
2010-07-07 21:25:28 -07:00
|
|
|
|
2010-10-03 02:50:00 -07:00
|
|
|
etd = calloc(1, sizeof(*etd));
|
|
|
|
etd->thumb_path = eina_stringshare_add(path);
|
|
|
|
etd->file = eina_stringshare_add(path);
|
2010-10-08 11:51:19 -07:00
|
|
|
etd->basename = ecore_file_file_get(etd->file);
|
|
|
|
etd->is_directory = is_dir;
|
2010-10-03 02:50:00 -07:00
|
|
|
elm_gengrid_item_append(tb->thumb_browser, &tb->eg, etd, NULL, NULL);
|
2010-07-01 11:49:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*Get the label for the icon in the grid*/
|
|
|
|
static char *
|
2010-10-08 11:51:19 -07:00
|
|
|
_ephoto_get_label(void *data, Evas_Object *obj, const char *part)
|
2010-07-01 11:49:22 -07:00
|
|
|
{
|
2010-10-08 11:51:19 -07:00
|
|
|
Ephoto_Thumb_Data *etd = data;
|
|
|
|
return strdup(etd->basename);
|
2010-07-01 11:49:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*Get the image for the icon in the grid*/
|
|
|
|
static Evas_Object *
|
2010-10-08 11:51:19 -07:00
|
|
|
_ephoto_get_icon(void *data, Evas_Object *obj, const char *part)
|
2010-07-01 11:49:22 -07:00
|
|
|
{
|
2010-10-08 11:51:19 -07:00
|
|
|
Ephoto_Thumb_Data *etd = data;
|
|
|
|
Evas_Object *thumb, *o;
|
|
|
|
|
|
|
|
if (strcmp(part, "elm.swallow.icon") != 0) return NULL;
|
|
|
|
|
|
|
|
thumb = elm_layout_add(obj);
|
|
|
|
if (etd->is_directory)
|
|
|
|
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 (etd->is_directory)
|
|
|
|
{
|
|
|
|
o = ephoto_directory_thumb_add(thumb, etd->thumb_path);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
o = elm_thumb_add(thumb);
|
|
|
|
elm_thumb_file_set(o, etd->thumb_path, NULL);
|
|
|
|
}
|
|
|
|
evas_object_show(o);
|
|
|
|
elm_layout_content_set(thumb, "ephoto.swallow.content", o);
|
|
|
|
|
|
|
|
return thumb;
|
2010-07-01 11:49:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*Get the state of the icon in the grid!*/
|
|
|
|
static Eina_Bool
|
2010-10-08 11:51:19 -07:00
|
|
|
_ephoto_get_state(void *data, Evas_Object *obj, const char *part)
|
2010-07-01 11:49:22 -07:00
|
|
|
{
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*Delete the grid*/
|
|
|
|
static void
|
2010-10-08 11:51:19 -07:00
|
|
|
_ephoto_grid_del(void *data, Evas_Object *obj)
|
2010-07-01 11:49:22 -07:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-07-14 16:23:54 -07:00
|
|
|
/*Thumb clicked job*/
|
|
|
|
static void
|
|
|
|
_ephoto_thumb_clicked_job(void *data)
|
2010-07-05 15:58:16 -07:00
|
|
|
{
|
|
|
|
const Eina_List *selected;
|
2010-10-03 02:50:00 -07:00
|
|
|
char *parent_dir;
|
2010-07-07 21:25:28 -07:00
|
|
|
Ephoto_Thumb_Data *etd;
|
2010-07-05 15:58:16 -07:00
|
|
|
Evas_Object *o;
|
2010-09-13 09:40:33 -07:00
|
|
|
Ephoto_Thumb_Browser *tb = data;
|
2010-07-05 15:58:16 -07:00
|
|
|
|
2010-09-13 09:40:33 -07:00
|
|
|
selected = elm_gengrid_selected_items_get(tb->thumb_browser);
|
2010-07-14 16:23:54 -07:00
|
|
|
o = eina_list_data_get(selected);
|
|
|
|
etd = (Ephoto_Thumb_Data *)elm_gengrid_item_data_get((Elm_Gengrid_Item *)o);
|
2010-10-08 11:51:19 -07:00
|
|
|
if (etd->is_directory)
|
2010-10-03 02:50:00 -07:00
|
|
|
{
|
|
|
|
if (!strcmp(etd->file, PARENT_DIR))
|
|
|
|
{
|
|
|
|
parent_dir = ecore_file_dir_get(em->config->directory);
|
|
|
|
_ephoto_change_directory(tb, parent_dir);
|
|
|
|
free(parent_dir);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
_ephoto_change_directory(tb, etd->file);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
evas_object_smart_callback_call(tb->layout, "selected", (char *)etd->file);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Change the current directory showed in thumb browser. */
|
|
|
|
static void
|
|
|
|
_ephoto_change_directory(Ephoto_Thumb_Browser *tb, const char *directory)
|
|
|
|
{
|
|
|
|
const Eina_List *l, *iter;
|
|
|
|
Elm_Gengrid_Item *item;
|
|
|
|
Ephoto_Thumb_Data *etd;
|
|
|
|
|
|
|
|
if ((directory) && (eina_stringshare_replace(&em->config->directory, directory)))
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
elm_gengrid_clear(tb->thumb_browser);
|
|
|
|
eina_list_free(em->images);
|
|
|
|
em->images = NULL;
|
|
|
|
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;
|
2010-10-08 11:51:19 -07:00
|
|
|
Ephoto_Thumb_Data *etd = elm_gengrid_item_data_get(event_info);
|
|
|
|
if (etd->is_directory)
|
2010-10-03 02:50:00 -07:00
|
|
|
elm_toolbar_item_disabled_set(tb->view_large, EINA_TRUE);
|
|
|
|
else
|
|
|
|
elm_toolbar_item_disabled_set(tb->view_large, EINA_FALSE);
|
2010-09-29 10:09:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*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);
|
2010-07-05 15:58:16 -07:00
|
|
|
}
|
|
|
|
|
2010-07-27 19:06:03 -07:00
|
|
|
/*File Selector is shown*/
|
2010-07-07 19:37:45 -07:00
|
|
|
static void
|
|
|
|
_ephoto_fileselector_shown(void *data, Evas *e, Evas_Object *obj, void *event_info)
|
|
|
|
{
|
2010-09-19 08:30:36 -07:00
|
|
|
elm_fileselector_path_set(obj, em->config->directory);
|
2010-07-07 19:37:45 -07:00
|
|
|
evas_render(em->e);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*Directory has been chosen*/
|
|
|
|
static void
|
|
|
|
_ephoto_directory_chosen(void *data, Evas_Object *obj, void *event_info)
|
|
|
|
{
|
2010-09-13 09:40:33 -07:00
|
|
|
Ephoto_Thumb_Browser *tb = data;
|
2010-07-07 19:37:45 -07:00
|
|
|
|
2010-10-03 02:50:00 -07:00
|
|
|
_ephoto_change_directory(tb, elm_fileselector_selected_get(obj));
|
2010-09-13 09:40:33 -07:00
|
|
|
evas_object_del(tb->fsel_win);
|
|
|
|
elm_toolbar_item_unselect_all(tb->toolbar);
|
2010-07-07 19:37:45 -07:00
|
|
|
}
|
|
|
|
|
2010-07-05 14:07:53 -07:00
|
|
|
/*Show the flow browser*/
|
|
|
|
static void
|
|
|
|
_ephoto_view_large(void *data, Evas_Object *obj, void *event_info)
|
|
|
|
{
|
2010-07-05 15:58:16 -07:00
|
|
|
const Eina_List *selected;
|
|
|
|
Evas_Object *o;
|
2010-07-07 21:25:28 -07:00
|
|
|
Ephoto_Thumb_Data *etd;
|
2010-09-13 09:40:33 -07:00
|
|
|
Ephoto_Thumb_Browser *tb = data;
|
2010-07-05 15:58:16 -07:00
|
|
|
|
2010-09-13 09:40:33 -07:00
|
|
|
selected = elm_gengrid_selected_items_get(tb->thumb_browser);
|
|
|
|
|
|
|
|
/* em->flow_browser = ephoto_create_flow_browser(em->layout); */
|
2010-07-05 15:58:16 -07:00
|
|
|
|
|
|
|
if (eina_list_data_get(selected))
|
|
|
|
{
|
|
|
|
o = eina_list_data_get(selected);
|
2010-07-07 21:25:28 -07:00
|
|
|
etd = (Ephoto_Thumb_Data *)elm_gengrid_item_data_get((Elm_Gengrid_Item *)o);
|
2010-09-13 09:40:33 -07:00
|
|
|
/* _ephoto_thumb_clicked_job(etd->file); */
|
2010-09-18 13:18:43 -07:00
|
|
|
evas_object_smart_callback_call(tb->layout, "selected", (char *)etd->file);
|
2010-09-13 09:40:33 -07:00
|
|
|
|
2010-07-05 15:58:16 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-13 09:40:33 -07:00
|
|
|
/* _ephoto_thumb_clicked_job( eina_list_data_get(em->images)); */
|
|
|
|
evas_object_smart_callback_call(tb->layout, "selected", eina_list_data_get(em->images));
|
|
|
|
|
2010-07-05 15:58:16 -07:00
|
|
|
}
|
2010-09-13 09:40:33 -07:00
|
|
|
|
|
|
|
elm_toolbar_item_unselect_all(tb->toolbar);
|
2010-07-05 14:07:53 -07:00
|
|
|
}
|
2010-07-07 19:37:45 -07:00
|
|
|
|
|
|
|
/*Change directory*/
|
|
|
|
static void
|
2010-10-03 02:50:00 -07:00
|
|
|
_ephoto_change_directory_window(void *data, Evas_Object *obj, void *event_info)
|
2010-07-07 19:37:45 -07:00
|
|
|
{
|
2010-09-13 09:40:33 -07:00
|
|
|
Evas_Object *fsel;
|
|
|
|
Ephoto_Thumb_Browser *tb = data;
|
2010-07-07 19:37:45 -07:00
|
|
|
|
2010-09-13 09:40:33 -07:00
|
|
|
tb->fsel_win = elm_win_inwin_add(em->win);
|
2010-07-07 19:37:45 -07:00
|
|
|
|
2010-09-13 09:40:33 -07:00
|
|
|
fsel = elm_fileselector_add(tb->fsel_win);
|
2010-07-07 19:37:45 -07:00
|
|
|
elm_fileselector_folder_only_set(fsel, EINA_TRUE);
|
|
|
|
elm_fileselector_buttons_ok_cancel_set(fsel, EINA_TRUE);
|
2010-09-19 08:30:36 -07:00
|
|
|
elm_fileselector_path_set(fsel, em->config->directory);
|
2010-09-13 09:40:33 -07:00
|
|
|
evas_object_event_callback_add(fsel, EVAS_CALLBACK_SHOW,
|
|
|
|
_ephoto_fileselector_shown, tb);
|
2010-07-07 19:37:45 -07:00
|
|
|
evas_object_smart_callback_add(fsel, "done",
|
2010-09-13 09:40:33 -07:00
|
|
|
_ephoto_directory_chosen, tb);
|
2010-07-07 19:37:45 -07:00
|
|
|
|
2010-09-13 09:40:33 -07:00
|
|
|
elm_win_inwin_content_set(tb->fsel_win, fsel);
|
|
|
|
elm_win_inwin_activate(tb->fsel_win);
|
2010-07-07 19:37:45 -07:00
|
|
|
|
|
|
|
evas_object_show(fsel);
|
2010-09-13 09:40:33 -07:00
|
|
|
evas_object_show(tb->fsel_win);
|
2010-07-07 19:37:45 -07:00
|
|
|
}
|
|
|
|
|
2010-07-27 19:06:03 -07:00
|
|
|
/*Show slideshow*/
|
|
|
|
static void
|
|
|
|
_ephoto_view_slideshow(void *data, Evas_Object *obj, void *event_info)
|
2010-09-13 09:40:33 -07:00
|
|
|
{
|
|
|
|
Ephoto_Thumb_Browser *tb = data;
|
|
|
|
/* FIXME */
|
|
|
|
//ephoto_hide_thumb_browser();
|
2010-07-27 19:06:03 -07:00
|
|
|
ephoto_show_slideshow(0, NULL);
|
2010-09-13 09:40:33 -07:00
|
|
|
elm_toolbar_item_unselect_all(tb->toolbar);
|
|
|
|
}
|
|
|
|
|
2010-09-19 08:30:36 -07:00
|
|
|
/* 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);
|
|
|
|
}
|
|
|
|
|
2010-09-13 09:40:33 -07:00
|
|
|
/*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;
|
2010-09-18 13:18:43 -07:00
|
|
|
const Eina_List *l, *iter;
|
2010-09-13 09:40:33 -07:00
|
|
|
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);
|
|
|
|
}
|
2010-09-29 10:09:42 -07:00
|
|
|
em->thumb_browser = NULL;
|
2010-07-27 19:06:03 -07:00
|
|
|
}
|