devilhorns pushed a commit to branch master. http://git.enlightenment.org/apps/express.git/commit/?id=331f331bcbbe3faaaf2d6f0357be00fd577a8ada
commit 331f331bcbbe3faaaf2d6f0357be00fd577a8ada Author: Chris Michael <cp.mich...@samsung.com> Date: Mon Aug 3 13:37:21 2015 -0400 express: Add support for media thumbnails Signed-off-by: Chris Michael <cp.mich...@samsung.com> --- src/bin/media.c | 208 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 202 insertions(+), 6 deletions(-) diff --git a/src/bin/media.c b/src/bin/media.c index dc38458..6b811ae 100644 --- a/src/bin/media.c +++ b/src/bin/media.c @@ -18,6 +18,7 @@ struct _Media Ecore_Con_Url *url; Ecore_Event_Handler *_prog_hdlr, *_compl_hdlr; + Ethumb_Client_Async *et_req; const char *src, *ext, *realf; @@ -43,8 +44,13 @@ struct _Media static Evas_Smart *_smart = NULL; static Evas_Smart_Class _parent_sc = EVAS_SMART_CLASS_INIT_NULL; +static Ethumb_Client *et_client = NULL; +static Eina_Bool et_connected = EINA_FALSE; +static Eina_List *et_queue = NULL; static void _smart_calculate(Evas_Object *obj); +static void _thumb_type_init(Evas_Object *obj); +static void _ethumb_init(void); static void _media_cb_img_preloaded(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event EINA_UNUSED) @@ -187,6 +193,192 @@ _img_type_calc(Media *sd, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h evas_object_resize(sd->o_img, w, h); } +static void +_thumb_type_calc(Media *sd, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h) +{ + if (!sd) return; + if ((w <= 0) || (h <= 0) || (sd->iw <= 0) || (sd->ih <= 0)) + { + w = 1; + h = 1; + } + else + { + int iw = 1, ih = 1; + + iw = w; + ih = (sd->ih * w) / sd->iw; + if (ih > h) + { + ih = h; + iw = (sd->iw * h) / sd->ih; + if (iw > w) iw = w; + } + if ((iw > sd->iw) || (ih > sd->ih)) + { + iw = sd->iw; + ih = sd->ih; + } + + x += ((w - iw) / 2); + y += ((h - ih) / 2); + w = iw; + h = ih; + } + + evas_object_move(sd->o_img, x, y); + evas_object_resize(sd->o_img, w, h); +} + +static void +_thumb_cb_preloaded(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event EINA_UNUSED) +{ + Media *sd; + Evas_Coord ox, oy, ow, oh; + + if (!(sd = evas_object_smart_data_get(data))) return; + evas_object_geometry_get(data, &ox, &oy, &ow, &oh); + _thumb_type_calc(sd, ox, oy, ow, oh); + evas_object_show(sd->o_img); + evas_object_show(sd->o_clip); +} + +static void +_ethumb_cb_done(Ethumb_Client *ec EINA_UNUSED, const char *file, const char *key, void *data) +{ + Media *sd; + + if (!(sd = evas_object_smart_data_get(data))) return; + sd->et_req = NULL; + evas_object_event_callback_add(sd->o_img, EVAS_CALLBACK_IMAGE_PRELOADED, + _thumb_cb_preloaded, data); + evas_object_image_file_set(sd->o_img, file, key); + evas_object_image_size_get(sd->o_img, &sd->iw, &sd->ih); + evas_object_image_preload(sd->o_img, EINA_FALSE); +} + +static void +_ethumb_cb_error(Ethumb_Client *ec EINA_UNUSED, void *data) +{ + Media *sd; + + if (!(sd = evas_object_smart_data_get(data))) return; + sd->et_req = NULL; +} + +static void +_ethumb_disconnect(void *data EINA_UNUSED, Ethumb_Client *ec) +{ + if (ec != et_client) return; + ethumb_client_disconnect(et_client); + et_connected = EINA_FALSE; + et_client = NULL; + if (et_queue) _ethumb_init(); +} + +static void +_ethumb_connect(void *data EINA_UNUSED, Ethumb_Client *ec, Eina_Bool ok) +{ + if (ok) + { + Evas_Object *o; + + et_connected = EINA_TRUE; + + ethumb_client_on_server_die_callback_set(ec, _ethumb_disconnect, + NULL, NULL); + + EINA_LIST_FREE(et_queue, o) + _thumb_type_init(o); + } + else + et_client = NULL; +} + +static void +_ethumb_init(void) +{ + if (et_client) return; + ethumb_client_init(); + et_client = ethumb_client_connect(_ethumb_connect, NULL, NULL); +} + +static void +_thumb_type_theme_init(Evas_Object *obj) +{ + Media *sd; + + if (!(sd = evas_object_smart_data_get(obj))) return; + + if ((sd->realf) && (sd->realf[0] != '/')) + { + static const char *icon_theme = NULL; + const char *f; + + if (!icon_theme) + { + Efreet_Icon_Theme *theme; + + theme = efreet_icon_theme_find(getenv("E_ICON_THEME")); + if (!theme) + { + const char **itr; + static const char *themes[] = + { + "Human", "oxygen", "gnome", "hicolor", NULL + }; + + for (itr = themes; *itr; itr++) + { + theme = efreet_icon_theme_find(*itr); + if (theme) break; + } + } + + if (theme) + icon_theme = eina_stringshare_add(theme->name.internal); + } + f = efreet_icon_path_find(icon_theme, sd->realf, sd->iw); + ethumb_client_file_set(et_client, f, NULL); + } + else + ethumb_client_file_set(et_client, sd->realf, NULL); + + sd->et_req = + ethumb_client_thumb_async_get(et_client, _ethumb_cb_done, + _ethumb_cb_error, obj); + sd->queued = EINA_FALSE; +} + +static void +_thumb_type_init(Evas_Object *obj) +{ + Media *sd; + + if (!(sd = evas_object_smart_data_get(obj))) return; + + sd->type = MEDIA_TYPE_THUMB; + + _ethumb_init(); + + sd->o_img = evas_object_image_filled_add(evas_object_evas_get(obj)); + evas_object_image_load_orientation_set(sd->o_img, EINA_TRUE); + evas_object_smart_member_add(sd->o_img, obj); + evas_object_clip_set(sd->o_img, sd->o_clip); + evas_object_raise(sd->o_event); + + sd->iw = sd->ih = 64; + + if (!et_connected) + { + et_queue = eina_list_append(et_queue, obj); + sd->queued = EINA_TRUE; + return; + } + + _thumb_type_theme_init(obj); +} + static void _media_cb_mouse_down(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event) { @@ -349,6 +541,12 @@ _smart_del(Evas_Object *obj) if (sd->o_busy) evas_object_del(sd->o_busy); if (sd->o_event) evas_object_del(sd->o_event); + if (sd->anim) ecore_timer_del(sd->anim); + if ((et_client) && (sd->et_req)) + ethumb_client_thumb_async_cancel(et_client, sd->et_req); + if (sd->queued) et_queue = eina_list_remove(et_queue, obj); + sd->et_req = NULL; + _parent_sc.del(obj); } @@ -393,9 +591,9 @@ _smart_calculate(Evas_Object *obj) /* case MEDIA_TYPE_MOV: */ /* _mov_type_calc(sd, ox, oy, ow, oh); */ /* break; */ - /* case MEDIA_TYPE_THUMB: */ - /* _thumb_type_calc(sd, ox, oy, ow, oh); */ - /* break; */ + case MEDIA_TYPE_THUMB: + _thumb_type_calc(sd, ox, oy, ow, oh); + break; case MEDIA_TYPE_UNKNOWN: return; default: @@ -582,9 +780,7 @@ _media_add(Evas_Object *parent, const char *src, int mode, Media_Type type) #endif if ((mode & MEDIA_SIZE_MASK) == MEDIA_THUMB) - { - /* TODO: type thumb init */ - } + _thumb_type_init(obj); else { switch (type) --