2009-08-16 19:11:33 -07:00
|
|
|
#include "Evry.h"
|
|
|
|
|
2009-08-19 05:07:37 -07:00
|
|
|
typedef struct _Image_View Image_View;
|
|
|
|
|
|
|
|
|
|
|
|
struct _Image_View
|
|
|
|
{
|
|
|
|
Evry_View view;
|
|
|
|
Evas *evas;
|
|
|
|
|
|
|
|
const Evry_State *state;
|
|
|
|
|
|
|
|
Evas_Object *o_main;
|
|
|
|
|
|
|
|
Eina_List *items;
|
|
|
|
Evas_Object *o_thumb[4];
|
|
|
|
};
|
|
|
|
|
2009-08-16 19:11:33 -07:00
|
|
|
|
2009-08-17 16:54:16 -07:00
|
|
|
static Evry_View *view = NULL;
|
2009-08-19 05:07:37 -07:00
|
|
|
static const char *view_types = NULL;
|
2009-08-16 19:11:33 -07:00
|
|
|
|
|
|
|
static int
|
|
|
|
_check_item(const Evry_Item *it)
|
|
|
|
{
|
2009-08-18 07:29:30 -07:00
|
|
|
if ((!it || !it->uri || !it->mime) ||
|
|
|
|
(it->plugin->type_out != view_types))
|
|
|
|
return 0;
|
2009-08-16 19:11:33 -07:00
|
|
|
|
2009-08-17 17:47:09 -07:00
|
|
|
if (!strncmp(it->mime, "image/", 6))
|
2009-08-16 19:11:33 -07:00
|
|
|
return 1;
|
2009-08-18 07:29:30 -07:00
|
|
|
|
2009-08-16 19:11:33 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cb_preview_thumb_gen(void *data, Evas_Object *obj, void *event_info)
|
|
|
|
{
|
|
|
|
Evas_Coord w, h;
|
2009-08-19 05:07:37 -07:00
|
|
|
Image_View *v = data;
|
|
|
|
|
|
|
|
e_icon_size_get(v->o_thumb[1], &w, &h);
|
|
|
|
edje_extern_object_min_size_set(v->o_thumb[1], w, h);
|
|
|
|
edje_object_part_swallow(v->o_main, "e.swallow.icon2", v->o_thumb[1]);
|
|
|
|
evas_object_show(v->o_thumb[1]);
|
2009-08-16 19:11:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-08-19 05:07:37 -07:00
|
|
|
_show_item(Image_View *v, const Evry_Item *it, int dir)
|
2009-08-16 19:11:33 -07:00
|
|
|
{
|
2009-08-17 16:54:16 -07:00
|
|
|
int w, h;
|
2009-08-16 19:11:33 -07:00
|
|
|
|
2009-08-19 05:07:37 -07:00
|
|
|
if (v->o_thumb[1 + dir])
|
2009-08-16 19:11:33 -07:00
|
|
|
{
|
2009-08-19 05:07:37 -07:00
|
|
|
e_thumb_icon_end(v->o_thumb[1+dir]);
|
|
|
|
edje_object_part_unswallow(v->o_main, v->o_thumb[1+dir]);
|
|
|
|
evas_object_hide(v->o_thumb[1+dir]);
|
|
|
|
evas_object_del(v->o_thumb[1+dir]);
|
2009-08-16 19:11:33 -07:00
|
|
|
}
|
|
|
|
|
2009-08-19 05:07:37 -07:00
|
|
|
if (dir && v->o_thumb[1])
|
2009-08-16 19:11:33 -07:00
|
|
|
{
|
2009-08-19 05:07:37 -07:00
|
|
|
edje_object_part_unswallow(v->o_main, v->o_thumb[1]);
|
2009-08-16 19:11:33 -07:00
|
|
|
|
|
|
|
if (dir > 0)
|
|
|
|
{
|
2009-08-19 05:07:37 -07:00
|
|
|
v->o_thumb[2] = v->o_thumb[1];
|
|
|
|
edje_object_part_swallow(v->o_main, "e.swallow.icon1", v->o_thumb[2]);
|
2009-08-16 19:11:33 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-08-19 05:07:37 -07:00
|
|
|
v->o_thumb[0] = v->o_thumb[1];
|
|
|
|
edje_object_part_swallow(v->o_main, "e.swallow.icon3", v->o_thumb[0]);
|
2009-08-16 19:11:33 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-19 05:07:37 -07:00
|
|
|
v->o_thumb[1] = e_thumb_icon_add(v->evas);
|
|
|
|
e_thumb_icon_file_set(v->o_thumb[1], it->uri, NULL);
|
|
|
|
evas_object_smart_callback_add(v->o_thumb[1], "e_thumb_gen", _cb_preview_thumb_gen, v);
|
|
|
|
edje_object_part_geometry_get(v->o_main, "e.swallow.icon2", NULL, NULL, &w, &h);
|
|
|
|
e_thumb_icon_size_set(v->o_thumb[1], w, h);
|
|
|
|
e_thumb_icon_begin(v->o_thumb[1]);
|
2009-08-16 19:11:33 -07:00
|
|
|
|
|
|
|
if (dir)
|
|
|
|
{
|
|
|
|
if (dir > 0)
|
2009-08-19 05:07:37 -07:00
|
|
|
edje_object_signal_emit(v->o_main, "e,signal,slide_left", "e");
|
2009-08-16 19:11:33 -07:00
|
|
|
else
|
2009-08-19 05:07:37 -07:00
|
|
|
edje_object_signal_emit(v->o_main, "e,signal,slide_right", "e");
|
2009-08-16 19:11:33 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-08-19 05:07:37 -07:00
|
|
|
_cb_key_down(const Evry_View *view, const Ecore_Event_Key *ev)
|
2009-08-16 19:11:33 -07:00
|
|
|
{
|
2009-08-19 05:07:37 -07:00
|
|
|
Image_View *v = (Image_View *) view;
|
|
|
|
|
2009-08-17 17:47:09 -07:00
|
|
|
Eina_List *l;
|
|
|
|
Evry_Item *it = NULL, *cur_item;
|
2009-08-16 19:11:33 -07:00
|
|
|
|
2009-08-19 05:07:37 -07:00
|
|
|
cur_item = v->state->sel_item;
|
2009-08-17 16:54:16 -07:00
|
|
|
|
|
|
|
if (!strcmp(ev->key, "Down"))
|
2009-08-16 19:11:33 -07:00
|
|
|
{
|
2009-08-19 05:07:37 -07:00
|
|
|
if (!v->items) return 1;
|
2009-08-17 17:47:09 -07:00
|
|
|
|
2009-08-19 05:07:37 -07:00
|
|
|
l = eina_list_data_find_list(v->items, cur_item);
|
2009-08-16 19:11:33 -07:00
|
|
|
|
|
|
|
if (l && l->next)
|
2009-08-17 17:47:09 -07:00
|
|
|
it = l->next->data;
|
|
|
|
else
|
2009-08-19 05:07:37 -07:00
|
|
|
it = v->items->data;
|
2009-08-17 17:47:09 -07:00
|
|
|
|
|
|
|
if (it && (it != cur_item))
|
2009-08-16 19:11:33 -07:00
|
|
|
{
|
2009-08-19 05:07:37 -07:00
|
|
|
_show_item(v, it, 1);
|
|
|
|
evry_item_select(v->state, it);
|
2009-08-16 19:11:33 -07:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2009-08-17 16:54:16 -07:00
|
|
|
else if (!strcmp(ev->key, "Up"))
|
2009-08-16 19:11:33 -07:00
|
|
|
{
|
2009-08-19 05:07:37 -07:00
|
|
|
if (!v->items) return 1;
|
2009-08-17 17:47:09 -07:00
|
|
|
|
2009-08-19 05:07:37 -07:00
|
|
|
l = eina_list_data_find_list(v->items, cur_item);
|
2009-08-17 17:47:09 -07:00
|
|
|
|
|
|
|
if (l && l->prev)
|
|
|
|
it = l->prev->data;
|
|
|
|
else
|
2009-08-19 05:07:37 -07:00
|
|
|
it = eina_list_last(v->items)->data;
|
2009-08-17 17:47:09 -07:00
|
|
|
|
|
|
|
if (it && (it != cur_item))
|
2009-08-16 19:11:33 -07:00
|
|
|
{
|
2009-08-19 05:07:37 -07:00
|
|
|
_show_item(v, it, -1);
|
|
|
|
evry_item_select(v->state, it);
|
2009-08-16 19:11:33 -07:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-08-19 05:07:37 -07:00
|
|
|
_view_clear(const Evry_View *view)
|
2009-08-17 16:54:16 -07:00
|
|
|
{
|
2009-08-19 05:07:37 -07:00
|
|
|
Image_View *v = (Image_View *) view;
|
2009-08-17 16:54:16 -07:00
|
|
|
|
2009-08-19 05:07:37 -07:00
|
|
|
if (v->o_thumb[0]) evas_object_del(v->o_thumb[0]);
|
|
|
|
v->o_thumb[0] = NULL;
|
|
|
|
if (v->o_thumb[1]) evas_object_del(v->o_thumb[1]);
|
|
|
|
v->o_thumb[1] = NULL;
|
|
|
|
if (v->o_thumb[2]) evas_object_del(v->o_thumb[2]);
|
|
|
|
v->o_thumb[2] = NULL;
|
|
|
|
if (v->items) eina_list_free(v->items);
|
|
|
|
v->items = NULL;
|
2009-08-16 19:11:33 -07:00
|
|
|
}
|
|
|
|
|
2009-08-19 05:07:37 -07:00
|
|
|
static Eina_List *
|
|
|
|
_get_list(const Evry_State *s)
|
2009-08-16 19:11:33 -07:00
|
|
|
{
|
2009-08-19 05:07:37 -07:00
|
|
|
Eina_List *l, *items = NULL;
|
|
|
|
Evry_Item *it;
|
2009-08-17 17:47:09 -07:00
|
|
|
|
2009-08-17 16:54:16 -07:00
|
|
|
EINA_LIST_FOREACH(s->plugin->items, l, it)
|
2009-08-19 05:07:37 -07:00
|
|
|
if (_check_item(it))
|
|
|
|
items = eina_list_append(items, it);
|
2009-08-17 16:54:16 -07:00
|
|
|
|
2009-08-19 05:07:37 -07:00
|
|
|
return items;
|
2009-08-16 19:11:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-08-19 05:07:37 -07:00
|
|
|
_view_update(const Evry_View *view)
|
2009-08-16 19:11:33 -07:00
|
|
|
{
|
2009-08-19 05:07:37 -07:00
|
|
|
Image_View *v = (Image_View *) view;
|
2009-08-17 16:54:16 -07:00
|
|
|
Evry_Item *it;
|
|
|
|
|
2009-08-19 05:07:37 -07:00
|
|
|
v->items = _get_list(v->state);
|
|
|
|
if (!v->items) return 0;
|
2009-08-17 16:54:16 -07:00
|
|
|
|
2009-08-19 05:07:37 -07:00
|
|
|
it = eina_list_data_find(v->items, v->state->sel_item);
|
|
|
|
if (!it)
|
|
|
|
{
|
|
|
|
it = v->items->data;
|
|
|
|
evry_item_select(v->state, it);
|
|
|
|
}
|
|
|
|
|
|
|
|
_show_item(v, it, 0);
|
|
|
|
|
2009-08-16 19:11:33 -07:00
|
|
|
return 1;
|
|
|
|
}
|
2009-08-17 16:54:16 -07:00
|
|
|
|
|
|
|
static Evas_Object *
|
2009-08-19 05:07:37 -07:00
|
|
|
_view_object(const Evry_View *view)
|
|
|
|
{
|
|
|
|
return ((Image_View*) view)->o_main;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Evry_View *
|
|
|
|
_view_create(const Evry_View *view, const Evry_State *s, const Evas_Object *swallow)
|
2009-08-17 16:54:16 -07:00
|
|
|
{
|
2009-08-19 05:07:37 -07:00
|
|
|
Image_View *v;
|
2009-08-17 16:54:16 -07:00
|
|
|
int w, h, x, y;
|
|
|
|
|
2009-08-19 05:07:37 -07:00
|
|
|
if (!_get_list(s))
|
|
|
|
return NULL;
|
2009-08-17 16:54:16 -07:00
|
|
|
|
2009-08-19 05:07:37 -07:00
|
|
|
v = E_NEW(Image_View, 1);
|
|
|
|
v->view = *view;
|
|
|
|
v->state = s;
|
|
|
|
v->evas = evas_object_evas_get(swallow);
|
|
|
|
v->o_main = edje_object_add(v->evas);
|
|
|
|
e_theme_edje_object_set(v->o_main, "base/theme/everything",
|
2009-08-17 16:54:16 -07:00
|
|
|
"e/widgets/everything/preview");
|
|
|
|
|
|
|
|
edje_object_part_geometry_get(swallow, "e.swallow.list", &x, &y, &w, &h);
|
2009-08-19 05:07:37 -07:00
|
|
|
edje_extern_object_min_size_set(v->o_main, w * 3, 100);
|
|
|
|
evas_object_resize(v->o_main, w * 3, h);
|
2009-08-17 16:54:16 -07:00
|
|
|
|
2009-08-19 05:07:37 -07:00
|
|
|
return &v->view;
|
|
|
|
}
|
2009-08-17 16:54:16 -07:00
|
|
|
|
2009-08-19 05:07:37 -07:00
|
|
|
static void
|
|
|
|
_view_destroy(const Evry_View *view)
|
|
|
|
{
|
|
|
|
Image_View *v = (Image_View *) view;
|
2009-08-17 16:54:16 -07:00
|
|
|
|
2009-08-19 05:07:37 -07:00
|
|
|
_view_clear(view);
|
|
|
|
evas_object_del(v->o_main);
|
2009-08-17 16:54:16 -07:00
|
|
|
|
2009-08-19 05:07:37 -07:00
|
|
|
E_FREE(v);
|
2009-08-17 16:54:16 -07:00
|
|
|
}
|
|
|
|
|
2009-08-16 19:11:33 -07:00
|
|
|
static Eina_Bool
|
|
|
|
_init(void)
|
|
|
|
{
|
2009-08-17 16:54:16 -07:00
|
|
|
view = E_NEW(Evry_View, 1);
|
2009-08-19 05:07:37 -07:00
|
|
|
view->id = view;
|
|
|
|
view->name = "Image Viewer";
|
|
|
|
view->create = &_view_create;
|
|
|
|
view->destroy = &_view_destroy;
|
|
|
|
view->object = &_view_object;
|
|
|
|
view->update = &_view_update;
|
|
|
|
view->clear = &_view_clear;
|
2009-08-17 16:54:16 -07:00
|
|
|
view->cb_key_down = &_cb_key_down;
|
|
|
|
evry_view_register(view, 2);
|
2009-08-16 19:11:33 -07:00
|
|
|
|
2009-08-17 20:15:36 -07:00
|
|
|
view_types = eina_stringshare_add("FILE");
|
|
|
|
|
2009-08-16 19:11:33 -07:00
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_shutdown(void)
|
|
|
|
{
|
2009-08-17 20:15:36 -07:00
|
|
|
eina_stringshare_del(view_types);
|
2009-08-17 16:54:16 -07:00
|
|
|
evry_view_unregister(view);
|
|
|
|
E_FREE(view);
|
2009-08-16 19:11:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EINA_MODULE_INIT(_init);
|
|
|
|
EINA_MODULE_SHUTDOWN(_shutdown);
|