ephoto/src/bin/ephoto_single_browser.c

1576 lines
49 KiB
C
Raw Normal View History

#include "ephoto.h"
#define ZOOM_STEP 0.2
static Ecore_Timer *_1s_hold = NULL;
typedef struct _Ephoto_Single_Browser Ephoto_Single_Browser;
typedef struct _Ephoto_Viewer Ephoto_Viewer;
struct _Ephoto_Single_Browser
{
Ephoto *ephoto;
Evas_Object *main;
Evas_Object *bar;
Evas_Object *table;
Evas_Object *viewer;
Evas_Object *infolabel;
2015-01-06 11:34:18 -08:00
Evas_Object *nolabel;
Evas_Object *botbox;
const char *pending_path;
Ephoto_Entry *entry;
Ephoto_Orient orient;
Eina_List *handlers;
Eina_Bool cropping:1;
};
struct _Ephoto_Viewer
{
Evas_Object *scroller;
Evas_Object *table;
Evas_Object *image;
double zoom;
Eina_Bool fit:1;
Eina_Bool cropping:1;
Eina_Bool zoom_first:1;
};
static void _zoom_set(Ephoto_Single_Browser *sb, double zoom);
static void _zoom_in(Ephoto_Single_Browser *sb);
static void _zoom_out(Ephoto_Single_Browser *sb);
static void _apply_crop(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED);
static void _cancel_crop(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED);
static void
_viewer_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
Ephoto_Viewer *v = data;
free(v);
}
static Evas_Object *
_image_create_icon(void *data, Evas_Object *parent, Evas_Coord *xoff, Evas_Coord *yoff)
{
Evas_Object *ic;
Evas_Object *io = data;
const char *f, *g;
Evas_Coord x, y, w, h, xm, ym;
elm_image_file_get(io, &f, &g);
ic = elm_image_add(parent);
elm_image_file_set(ic, f, g);
evas_object_geometry_get(io, &x, &y, &w, &h);
evas_object_move(ic, x, y);
evas_object_resize(ic, 60, 60);
evas_object_show(ic);
evas_pointer_canvas_xy_get(evas_object_evas_get(io), &xm, &ym);
if (xoff) *xoff = xm-30;
if (yoff) *yoff = ym-30;
return ic;
}
static Eina_Bool
_1s_hold_time(void *data)
{
const char *f;
char dd[PATH_MAX];
Evas_Object *io = data;
elm_image_file_get(io, &f, NULL);
snprintf(dd, sizeof(dd), "file://%s", f);
elm_drag_start(io, ELM_SEL_FORMAT_IMAGE, dd, ELM_XDND_ACTION_COPY,
_image_create_icon, io,
NULL, NULL, NULL, NULL, NULL, NULL);
_1s_hold = NULL;
return ECORE_CALLBACK_CANCEL;
}
static void
_image_mouse_down_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
Evas_Object *io = data;
_1s_hold = ecore_timer_add(0.5, _1s_hold_time, io);
}
static void
_image_mouse_up_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
ecore_timer_del(_1s_hold);
}
static Evas_Object *
_viewer_add(Evas_Object *parent, const char *path)
{
Ephoto_Single_Browser *sb = evas_object_data_get(parent, "single_browser");
Ephoto_Viewer *v = calloc(1, sizeof(Ephoto_Viewer));
Evas_Object *obj;
int err;
EINA_SAFETY_ON_NULL_RETURN_VAL(v, NULL);
v->zoom_first = EINA_TRUE;
Evas_Coord w, h;
const char *group = NULL;
const char *ext = strrchr(path, '.');
if (ext)
{
ext++;
if ((strcasecmp(ext, "edj") == 0))
{
if (edje_file_group_exists(path, "e/desktop/background"))
group = "e/desktop/background";
else
{
Eina_List *g = edje_file_collection_list(path);
group = eina_list_data_get(g);
edje_file_collection_list_free(g);
}
}
}
obj = v->scroller = elm_scroller_add(parent);
EINA_SAFETY_ON_NULL_GOTO(obj, error);
evas_object_size_hint_weight_set(obj, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(obj, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_data_set(obj, "viewer", v);
evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL, _viewer_del, v);
evas_object_show(obj);
v->table = elm_table_add(v->scroller);
evas_object_size_hint_weight_set(v->table, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(v->table, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_object_content_set(v->scroller, v->table);
evas_object_show(v->table);
v->cropping = sb->cropping;
if (v->cropping)
v->image = ephoto_cropper_add(v->table, path, group);
else
{
v->image = elm_image_add(v->table);
elm_image_preload_disabled_set(v->image, EINA_TRUE);
elm_image_file_set(v->image, path, group);
err = evas_object_image_load_error_get(elm_image_object_get(v->image));
if (err != EVAS_LOAD_ERROR_NONE) goto load_error;
evas_object_image_size_get(elm_image_object_get(v->image), &w, &h);
elm_drop_target_add(v->image, ELM_SEL_FORMAT_IMAGE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
evas_object_size_hint_min_set(v->image, w, h);
evas_object_size_hint_max_set(v->image, w, h);
evas_object_event_callback_add(v->image, EVAS_CALLBACK_MOUSE_DOWN, _image_mouse_down_cb, v->image);
evas_object_event_callback_add(v->image, EVAS_CALLBACK_MOUSE_UP, _image_mouse_up_cb, v->image);
}
elm_table_pack(v->table, v->image, 0, 0, 1, 1);
evas_object_show(v->image);
return obj;
load_error:
ERR("could not load image '%s': %s", path, evas_load_error_str(err));
error:
2015-01-06 11:34:18 -08:00
evas_object_event_callback_del(obj, EVAS_CALLBACK_DEL, _viewer_del);
evas_object_data_del(obj, "viewer");
free(v);
return NULL;
}
static void
_viewer_zoom_apply(Ephoto_Viewer *v, double zoom)
{
v->zoom = zoom;
Evas_Coord w, h;
Evas_Object *image;
if (v->cropping)
image = evas_object_data_get(v->image, "image");
else
image = v->image;
evas_object_image_size_get(elm_image_object_get(image), &w, &h);
w *= zoom;
h *= zoom;
evas_object_size_hint_min_set(v->image, w, h);
evas_object_size_hint_max_set(v->image, w, h);
}
static void
_viewer_zoom_fit_apply(Ephoto_Viewer *v)
{
Evas_Coord cw, ch, iw, ih;
Evas_Object *image;
double zx, zy, zoom;
if (v->cropping)
image = evas_object_data_get(v->image, "image");
else
image = v->image;
evas_object_geometry_get(v->scroller, NULL, NULL, &cw, &ch);
evas_object_image_size_get(elm_image_object_get(image), &iw, &ih);
if ((cw <= 0) || (ch <= 0)) return; /* object still not resized */
EINA_SAFETY_ON_TRUE_RETURN(iw <= 0);
EINA_SAFETY_ON_TRUE_RETURN(ih <= 0);
zx = (double)cw/(double)iw;
zy = (double)ch/(double)ih;
zoom = (zx < zy) ? zx : zy;
_viewer_zoom_apply(v, zoom);
}
static void
_viewer_resized(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
Ephoto_Viewer *v = data;
if (v->zoom_first)
{
Evas_Coord cw, ch, iw, ih;
Evas_Object *image;
if (v->cropping)
image = evas_object_data_get(v->image, "image");
else
image = v->image;
evas_object_geometry_get(v->scroller, NULL, NULL, &cw, &ch);
evas_object_image_size_get(elm_image_object_get(image), &iw, &ih);
if ((cw <= 0) || (ch <= 0)) return; /* object still not resized */
EINA_SAFETY_ON_TRUE_RETURN(iw <= 0);
EINA_SAFETY_ON_TRUE_RETURN(ih <= 0);
if (iw < cw && ih < ch)
_viewer_zoom_apply(v, 1);
else
_viewer_zoom_fit_apply(v);
}
else
_viewer_zoom_fit_apply(v);
}
static void
_viewer_zoom_set(Evas_Object *obj, double zoom)
{
Ephoto_Viewer *v = evas_object_data_get(obj, "viewer");
EINA_SAFETY_ON_NULL_RETURN(v);
_viewer_zoom_apply(v, zoom);
if (v->fit)
{
evas_object_event_callback_del_full
(v->scroller, EVAS_CALLBACK_RESIZE, _viewer_resized, v);
v->fit = EINA_FALSE;
}
}
static double
_viewer_zoom_get(Evas_Object *obj)
{
Ephoto_Viewer *v = evas_object_data_get(obj, "viewer");
EINA_SAFETY_ON_NULL_RETURN_VAL(v, 0.0);
return v->zoom;
}
static void
_viewer_zoom_fit(Evas_Object *obj)
{
Ephoto_Viewer *v = evas_object_data_get(obj, "viewer");
EINA_SAFETY_ON_NULL_RETURN(v);
if (v->fit) return;
v->fit = EINA_TRUE;
evas_object_event_callback_add
(v->scroller, EVAS_CALLBACK_RESIZE, _viewer_resized, v);
_viewer_zoom_fit_apply(v);
}
static void
_orient_apply(Ephoto_Single_Browser *sb)
{
Ephoto_Viewer *v = evas_object_data_get(sb->viewer, "viewer");
int w, h;
EINA_SAFETY_ON_NULL_RETURN(v);
switch (sb->orient)
{
case EPHOTO_ORIENT_0:
elm_image_orient_set(v->image, ELM_IMAGE_ORIENT_NONE);
break;
case EPHOTO_ORIENT_90:
elm_image_orient_set(v->image, ELM_IMAGE_ROTATE_90);
break;
case EPHOTO_ORIENT_180:
elm_image_orient_set(v->image, ELM_IMAGE_ROTATE_180);
break;
case EPHOTO_ORIENT_270:
elm_image_orient_set(v->image, ELM_IMAGE_ROTATE_270);
break;
case EPHOTO_ORIENT_FLIP_HORIZ:
elm_image_orient_set(v->image, ELM_IMAGE_FLIP_HORIZONTAL);
break;
case EPHOTO_ORIENT_FLIP_VERT:
elm_image_orient_set(v->image, ELM_IMAGE_FLIP_VERTICAL);
break;
case EPHOTO_ORIENT_FLIP_HORIZ_90:
elm_image_orient_set(v->image, ELM_IMAGE_FLIP_TRANSPOSE);
break;
case EPHOTO_ORIENT_FLIP_VERT_90:
elm_image_orient_set(v->image, ELM_IMAGE_FLIP_TRANSVERSE);
break;
default:
return;
}
2014-11-23 19:40:11 -08:00
elm_table_unpack(v->table, v->image);
elm_object_content_unset(v->scroller);
elm_image_object_size_get(v->image, &w, &h);
evas_object_size_hint_min_set(v->image, w, h);
evas_object_size_hint_max_set(v->image, w, h);
elm_table_pack(v->table, v->image, 0, 0, 1, 1);
2014-11-23 19:40:11 -08:00
elm_object_content_set(v->scroller, v->table);
if (v->fit)
_viewer_zoom_fit_apply(v);
else
_viewer_zoom_set(sb->viewer, _viewer_zoom_get(sb->viewer));
DBG("orient: %d", sb->orient);
}
static void
_rotate_counterclock(Ephoto_Single_Browser *sb)
{
switch (sb->orient)
{
case EPHOTO_ORIENT_0:
sb->orient = EPHOTO_ORIENT_270;
break;
case EPHOTO_ORIENT_90:
sb->orient = EPHOTO_ORIENT_0;
break;
case EPHOTO_ORIENT_180:
sb->orient = EPHOTO_ORIENT_90;
break;
case EPHOTO_ORIENT_270:
sb->orient = EPHOTO_ORIENT_180;
break;
case EPHOTO_ORIENT_FLIP_HORIZ:
sb->orient = EPHOTO_ORIENT_FLIP_VERT_90;
break;
case EPHOTO_ORIENT_FLIP_VERT_90:
sb->orient = EPHOTO_ORIENT_FLIP_VERT;
break;
case EPHOTO_ORIENT_FLIP_VERT:
sb->orient = EPHOTO_ORIENT_FLIP_HORIZ_90;
break;
case EPHOTO_ORIENT_FLIP_HORIZ_90:
sb->orient = EPHOTO_ORIENT_FLIP_HORIZ;
break;
default:
sb->orient = EPHOTO_ORIENT_0;
break;
}
_orient_apply(sb);
}
static void
_rotate_clock(Ephoto_Single_Browser *sb)
{
switch (sb->orient)
{
case EPHOTO_ORIENT_0:
sb->orient = EPHOTO_ORIENT_90;
break;
case EPHOTO_ORIENT_90:
sb->orient = EPHOTO_ORIENT_180;
break;
case EPHOTO_ORIENT_180:
sb->orient = EPHOTO_ORIENT_270;
break;
case EPHOTO_ORIENT_270:
sb->orient = EPHOTO_ORIENT_0;
break;
case EPHOTO_ORIENT_FLIP_HORIZ:
sb->orient = EPHOTO_ORIENT_FLIP_HORIZ_90;
break;
case EPHOTO_ORIENT_FLIP_VERT_90:
sb->orient = EPHOTO_ORIENT_FLIP_HORIZ;
break;
case EPHOTO_ORIENT_FLIP_VERT:
sb->orient = EPHOTO_ORIENT_FLIP_VERT_90;
break;
case EPHOTO_ORIENT_FLIP_HORIZ_90:
sb->orient = EPHOTO_ORIENT_FLIP_VERT;
break;
default:
sb->orient = EPHOTO_ORIENT_0;
break;
}
_orient_apply(sb);
}
static void
_flip_horiz(Ephoto_Single_Browser *sb)
{
switch (sb->orient)
{
case EPHOTO_ORIENT_0:
sb->orient = EPHOTO_ORIENT_FLIP_HORIZ;
break;
case EPHOTO_ORIENT_90:
sb->orient = EPHOTO_ORIENT_FLIP_VERT_90;
break;
case EPHOTO_ORIENT_180:
sb->orient = EPHOTO_ORIENT_FLIP_VERT;
break;
case EPHOTO_ORIENT_270:
sb->orient = EPHOTO_ORIENT_FLIP_HORIZ_90;
break;
case EPHOTO_ORIENT_FLIP_HORIZ:
sb->orient = EPHOTO_ORIENT_0;
break;
case EPHOTO_ORIENT_FLIP_VERT_90:
sb->orient = EPHOTO_ORIENT_90;
break;
case EPHOTO_ORIENT_FLIP_VERT:
sb->orient = EPHOTO_ORIENT_180;
break;
case EPHOTO_ORIENT_FLIP_HORIZ_90:
sb->orient = EPHOTO_ORIENT_270;
break;
default:
sb->orient = EPHOTO_ORIENT_0;
break;
}
_orient_apply(sb);
}
static void
_flip_vert(Ephoto_Single_Browser *sb)
{
switch (sb->orient)
{
case EPHOTO_ORIENT_0:
sb->orient = EPHOTO_ORIENT_FLIP_VERT;
break;
case EPHOTO_ORIENT_90:
sb->orient = EPHOTO_ORIENT_FLIP_HORIZ_90;
break;
case EPHOTO_ORIENT_180:
sb->orient = EPHOTO_ORIENT_FLIP_HORIZ;
break;
case EPHOTO_ORIENT_270:
sb->orient = EPHOTO_ORIENT_FLIP_VERT_90;
break;
case EPHOTO_ORIENT_FLIP_HORIZ:
sb->orient = EPHOTO_ORIENT_180;
break;
case EPHOTO_ORIENT_FLIP_VERT_90:
sb->orient = EPHOTO_ORIENT_270;
break;
case EPHOTO_ORIENT_FLIP_VERT:
sb->orient = EPHOTO_ORIENT_0;
break;
case EPHOTO_ORIENT_FLIP_HORIZ_90:
sb->orient = EPHOTO_ORIENT_90;
break;
default:
sb->orient = EPHOTO_ORIENT_0;
break;
}
_orient_apply(sb);
}
static void
_mouse_wheel(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
{
Ephoto_Single_Browser *sb = data;
Evas_Event_Mouse_Wheel *ev = event_info;
if (!evas_key_modifier_is_set(ev->modifiers, "Control")) return;
2015-02-20 17:22:43 -08:00
if (ev->z > 0) _zoom_out(sb);
else _zoom_in(sb);
}
static Ephoto_Entry *
_first_entry_find(Ephoto_Single_Browser *sb)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(sb->ephoto, NULL);
return eina_list_nth(sb->ephoto->entries, 0);
}
static Ephoto_Entry *
_last_entry_find(Ephoto_Single_Browser *sb)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(sb->ephoto, NULL);
return eina_list_last_data_get(sb->ephoto->entries);
}
static const char *
_ephoto_get_file_size(const char *path)
{
char isize[PATH_MAX];
Eina_File *f = eina_file_open(path, EINA_FALSE);
size_t size = eina_file_size_get(f);
eina_file_close(f);
double dsize = (double)size;
if (dsize < 1024.0) snprintf(isize, sizeof(isize), "%'.0f bytes", dsize);
else
{
dsize /= 1024.0;
if (dsize < 1024) snprintf(isize, sizeof(isize), "%'.0f KB", dsize);
else
{
dsize /= 1024.0;
if (dsize < 1024) snprintf(isize, sizeof(isize), "%'.1f MB", dsize);
else
{
dsize /= 1024.0;
if (dsize < 1024) snprintf(isize, sizeof(isize), "%'.1f GB", dsize);
else
{
dsize /= 1024.0;
snprintf(isize, sizeof(isize), "%'.1f TB", dsize);
}
}
}
}
return strdup(isize);
}
static void
_ephoto_single_browser_recalc(Ephoto_Single_Browser *sb)
{
if (sb->viewer)
{
evas_object_del(sb->viewer);
sb->viewer = NULL;
evas_object_del(sb->botbox);
sb->botbox = NULL;
evas_object_del(sb->infolabel);
sb->infolabel = NULL;
}
2015-01-06 11:34:18 -08:00
if (sb->nolabel)
{
evas_object_del(sb->nolabel);
sb->nolabel = NULL;
}
if (sb->entry)
{
const char *bname = ecore_file_file_get(sb->entry->path);
elm_table_clear(sb->table, EINA_FALSE);
sb->viewer = _viewer_add(sb->main, sb->entry->path);
2015-01-06 11:34:18 -08:00
if (sb->viewer)
{
char image_info[PATH_MAX];
Evas_Coord w, h;
Ephoto_Viewer *v = evas_object_data_get(sb->viewer, "viewer");
elm_table_pack(sb->table, sb->viewer, 0, 1, 4, 1);
2015-01-06 11:34:18 -08:00
evas_object_show(sb->viewer);
evas_object_event_callback_add
(sb->viewer, EVAS_CALLBACK_MOUSE_WHEEL, _mouse_wheel, sb);
if (sb->cropping)
{
Evas_Object *ic, *button;
sb->botbox = elm_box_add(sb->table);
elm_box_homogeneous_set(sb->botbox, EINA_TRUE);
elm_box_horizontal_set(sb->botbox, EINA_TRUE);
evas_object_size_hint_weight_set(sb->botbox, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(sb->botbox, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_table_pack(sb->table, sb->botbox, 0, 2, 4, 1);
evas_object_show(sb->botbox);
ic = elm_icon_add(sb->botbox);
evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
elm_icon_standard_set(ic, "document-save");
button = elm_button_add(sb->botbox);
elm_object_text_set(button, "Apply");
elm_object_part_content_set(button, "icon", ic);
evas_object_smart_callback_add(button, "clicked", _apply_crop, sb);
elm_box_pack_end(sb->botbox, button);
evas_object_show(button);
ic = elm_icon_add(sb->botbox);
evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
elm_icon_standard_set(ic, "window-close");
button = elm_button_add(sb->botbox);
elm_object_text_set(button, "Cancel");
elm_object_part_content_set(button, "icon", ic);
evas_object_smart_callback_add(button, "clicked", _cancel_crop, sb);
elm_box_pack_end(sb->botbox, button);
evas_object_show(button);
}
else
{
evas_object_image_size_get(elm_image_object_get(v->image), &w, &h);
snprintf(image_info, PATH_MAX,
"<b>Type:</b> %s <b>Resolution:</b> %dx%d <b>File Size: </b>%s",
efreet_mime_type_get(sb->entry->path), w, h,
_ephoto_get_file_size(sb->entry->path));
sb->botbox = evas_object_rectangle_add(evas_object_evas_get(sb->table));
evas_object_color_set(sb->botbox, 0, 0, 0, 0);
evas_object_size_hint_min_set(sb->botbox, 0, sb->ephoto->bottom_bar_size);
evas_object_size_hint_weight_set(sb->botbox, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_fill_set(sb->botbox, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_table_pack(sb->table, sb->botbox, 0, 2, 4, 1);
evas_object_show(sb->botbox);
sb->infolabel = elm_label_add(sb->table);
elm_label_line_wrap_set(sb->infolabel, ELM_WRAP_NONE);
elm_object_text_set(sb->infolabel, image_info);
evas_object_size_hint_weight_set(sb->infolabel, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
evas_object_size_hint_align_set(sb->infolabel, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_table_pack(sb->table, sb->infolabel, 0, 2, 4, 1);
evas_object_show(sb->infolabel);
ephoto_title_set(sb->ephoto, bname);
}
2015-01-06 11:34:18 -08:00
}
else
{
sb->nolabel = elm_label_add(sb->table);
elm_label_line_wrap_set(sb->nolabel, ELM_WRAP_WORD);
elm_object_text_set(sb->nolabel, "This image does not exist or is corrupted");
evas_object_size_hint_weight_set(sb->nolabel, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(sb->nolabel, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_table_pack(sb->table, sb->nolabel, 0, 1, 4, 1);
2015-01-06 11:34:18 -08:00
evas_object_show(sb->nolabel);
ephoto_title_set(sb->ephoto, "Bad Image");
}
}
elm_object_focus_set(sb->main, EINA_TRUE);
}
static void
_zoom_set(Ephoto_Single_Browser *sb, double zoom)
{
DBG("zoom %f", zoom);
if (zoom <= 0.0) return;
_viewer_zoom_set(sb->viewer, zoom);
}
static void
_zoom_fit(Ephoto_Single_Browser *sb)
{
if (sb->viewer) _viewer_zoom_fit(sb->viewer);
}
static void
_zoom_in(Ephoto_Single_Browser *sb)
{
double change = (1.0+ZOOM_STEP);
_viewer_zoom_set(sb->viewer, _viewer_zoom_get(sb->viewer) * change);
}
static void
_zoom_out(Ephoto_Single_Browser *sb)
{
double change = (1.0-ZOOM_STEP);
_viewer_zoom_set(sb->viewer, _viewer_zoom_get(sb->viewer) * change);
}
static void
_zoom_in_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
Ephoto_Single_Browser *sb = data;
Ephoto_Viewer *v = evas_object_data_get(sb->viewer, "viewer");
v->zoom_first = EINA_FALSE;
_zoom_in(sb);
}
static void
_zoom_out_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
Ephoto_Single_Browser *sb = data;
Ephoto_Viewer *v = evas_object_data_get(sb->viewer, "viewer");
v->zoom_first = EINA_FALSE;
_zoom_out(sb);
}
static void
_zoom_1_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
Ephoto_Single_Browser *sb = data;
Ephoto_Viewer *v = evas_object_data_get(sb->viewer, "viewer");
v->zoom_first = EINA_FALSE;
_zoom_set(sb, 1.0);
}
static void
_zoom_fit_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
Ephoto_Single_Browser *sb = data;
Ephoto_Viewer *v = evas_object_data_get(sb->viewer, "viewer");
Eina_Bool first_click;
if (v->zoom_first)
first_click = EINA_TRUE;
else
first_click = EINA_FALSE;
v->zoom_first = EINA_FALSE;
if (first_click)
v->fit = EINA_FALSE;
_zoom_fit(sb);
}
static void
_next_entry(Ephoto_Single_Browser *sb)
{
Ephoto_Entry *entry = NULL;
Eina_List *node;
EINA_SAFETY_ON_NULL_RETURN(sb->entry);
node = eina_list_data_find_list(sb->ephoto->entries, sb->entry);
if (!node) return;
if ((node = node->next))
entry = node->data;
if (!entry)
entry = _first_entry_find(sb);
if (entry)
{
DBG("next is '%s'", entry->path);
ephoto_single_browser_entry_set(sb->main, entry);
}
}
static void
_prev_entry(Ephoto_Single_Browser *sb)
{
Eina_List *node;
Ephoto_Entry *entry = NULL;
EINA_SAFETY_ON_NULL_RETURN(sb->entry);
node = eina_list_data_find_list(sb->ephoto->entries, sb->entry);
if (!node) return;
if ((node = node->prev))
entry = node->data;
if (!entry)
entry = _last_entry_find(sb);
if (entry)
{
DBG("prev is '%s'", entry->path);
ephoto_single_browser_entry_set(sb->main, entry);
}
}
static void
_first_entry(Ephoto_Single_Browser *sb)
{
Ephoto_Entry *entry = _first_entry_find(sb);
if (!entry) return;
DBG("first is '%s'", entry->path);
ephoto_single_browser_entry_set(sb->main, entry);
}
static void
_last_entry(Ephoto_Single_Browser *sb)
{
Ephoto_Entry *entry = _last_entry_find(sb);
if (!entry) return;
DBG("last is '%s'", entry->path);
ephoto_single_browser_entry_set(sb->main, entry);
}
static void
_reset_yes(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
Evas_Object *win = data;
Ephoto_Single_Browser *sb = evas_object_data_get(win, "single_browser");
sb->cropping = EINA_FALSE;
ephoto_single_browser_entry_set(sb->main, sb->entry);
evas_object_del(win);
}
static void
_reset_no(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
Evas_Object *win = data;
evas_object_del(win);
}
static void
_reset_image(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
Ephoto_Single_Browser *sb = data;
Evas_Object *win, *box, *label, *hbox, *ic, *button;
win = elm_win_inwin_add(sb->ephoto->win);
elm_object_style_set(win, "minimal");
evas_object_show(win);
box = elm_box_add(win);
elm_box_horizontal_set(box, EINA_FALSE);
evas_object_size_hint_weight_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
label = elm_label_add(box);
elm_object_text_set(label, "Are you sure you want to reset your changes?");
evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_box_pack_end(box, label);
evas_object_show(label);
hbox = elm_box_add(win);
elm_box_horizontal_set(hbox, EINA_TRUE);
evas_object_size_hint_weight_set(hbox, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_size_hint_align_set(hbox, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_box_pack_end(box, hbox);
evas_object_show(hbox);
ic = elm_icon_add(hbox);
evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
elm_icon_standard_set(ic, "stock_save");
button = elm_button_add(hbox);
elm_object_text_set(button, "Yes");
elm_object_part_content_set(button, "icon", ic);
evas_object_smart_callback_add(button, "clicked", _reset_yes, win);
elm_box_pack_end(hbox, button);
evas_object_show(button);
ic = elm_icon_add(hbox);
evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
elm_icon_standard_set(ic, "stock_close");
button = elm_button_add(hbox);
elm_object_text_set(button, "No");
elm_object_part_content_set(button, "icon", ic);
evas_object_smart_callback_add(button, "clicked", _reset_no, win);
elm_box_pack_end(hbox, button);
evas_object_show(button);
evas_object_data_set(win, "single_browser", sb);
elm_win_inwin_content_set(win, box);
evas_object_show(box);
}
static void
_failed_save(Ephoto_Single_Browser *sb)
{
Evas_Object *win, *box, *label, *ic, *button;
win = elm_win_inwin_add(sb->ephoto->win);
elm_object_style_set(win, "minimal");
evas_object_show(win);
box = elm_box_add(win);
elm_box_horizontal_set(box, EINA_FALSE);
evas_object_size_hint_weight_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
label = elm_label_add(box);
elm_object_text_set(label, "Error: Image could not be saved here!");
evas_object_size_hint_weight_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_box_pack_end(box, label);
evas_object_show(label);
ic = elm_icon_add(box);
evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
elm_icon_standard_set(ic, "stock_close");
button = elm_button_add(box);
elm_object_text_set(button, "OK");
elm_object_part_content_set(button, "icon", ic);
evas_object_smart_callback_add(button, "clicked", _reset_no, win);
elm_box_pack_end(box, button);
evas_object_show(button);
evas_object_data_set(win, "single_browser", sb);
elm_win_inwin_content_set(win, box);
evas_object_show(box);
}
static void
_save_yes(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
Evas_Object *win = data;
Ephoto_Single_Browser *sb = evas_object_data_get(win, "single_browser");
Ephoto_Viewer *v = evas_object_data_get(sb->viewer, "viewer");
Eina_Bool success;
if (ecore_file_exists(sb->entry->path))
{
success = ecore_file_unlink(sb->entry->path);
if (!success)
{
_failed_save(sb);
ephoto_single_browser_entry_set(sb->main, sb->entry);
evas_object_del(win);
return;
}
}
success = evas_object_image_save(elm_image_object_get(v->image), sb->entry->path, NULL, NULL);
if (!success)
_failed_save(sb);
ephoto_single_browser_entry_set(sb->main, sb->entry);
evas_object_del(win);
}
static void
_save_no(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
Evas_Object *win = data;
evas_object_del(win);
}
static void
_save_image(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)