#include <Elementary.h>
#include "elm_priv.h"
-
-/**
- * @defgroup Thumb Thumb
- *
- * A thumb object is used for displaying the thumbnail of an image or video.
- * You must have compiled Elementary with Ethumb_Client support and the DBus
- * service must be present and auto-activated in order to have thumbnails to
- * be generated.
- *
- * Signals that you can add callbacks for are:
- *
- * "clicked" - This is called when a user has clicked the thumb without dragging
- * around.
- * "clicked,double" - This is called when a user has double-clicked the thumb.
- * "press" - This is called when a user has pressed down the thumb.
- * "generate,start" - The thumbnail generation started.
- * "generate,stop" - The generation process stopped.
- * "generate,error" - The generation failed.
- * "load,error" - The thumbnail image loading failed.
- */
+#include <assert.h>
typedef struct _Widget_Data Widget_Data;
const char *key;
struct
{
- int id;
const char *file;
const char *key;
#ifdef HAVE_ELEMENTARY_ETHUMB
const char *thumb_path;
const char *thumb_key;
- Ethumb_Exists *exists;
+ Ethumb_Client_Async *request;
Ethumb_Thumb_Format format;
#ifdef HAVE_ELEMENTARY_ETHUMB
static Eina_List *retry = NULL;
static int pending_request = 0;
-
-static void _thumb_exists(Ethumb_Client *client __UNUSED__, Ethumb_Exists *thread,
- Eina_Bool exists, void *data);
-
#endif
EAPI int ELM_ECORE_EVENT_ETHUMB_CONNECT = 0;
Widget_Data *wd = elm_widget_data_get(obj);
#ifdef HAVE_ELEMENTARY_ETHUMB
- if (wd->thumb.id >= 0)
- {
- ethumb_client_generate_cancel(_elm_ethumb_client, wd->thumb.id,
- NULL, NULL, NULL);
- wd->thumb.id = -1;
- }
- if (wd->thumb.exists)
+ if (wd->thumb.request)
{
- ethumb_client_thumb_exists_cancel(wd->thumb.exists, _thumb_exists, wd);
- wd->thumb.exists = NULL;
+ ethumb_client_thumb_async_cancel(_elm_ethumb_client, wd->thumb.request);
+ wd->thumb.request = NULL;
}
if (wd->thumb.retry)
{
evas_object_size_hint_min_set(wd->self, mw, mh);
eina_stringshare_replace(&(wd->thumb.file), thumb_path);
eina_stringshare_replace(&(wd->thumb.key), thumb_key);
+ edje_object_signal_emit(wd->frame, EDJE_SIGNAL_PULSE_STOP, "elm");
edje_object_signal_emit(wd->frame, EDJE_SIGNAL_GENERATE_STOP, "elm");
evas_object_smart_callback_call(wd->self, SIG_GENERATE_STOP, NULL);
}
elm_widget_sub_object_add(wd->self, wd->view);
}
- if (!edje_object_file_set(wd->view, thumb_path, "movie/thumb"))
+ if (!edje_object_file_set(wd->view, thumb_path, thumb_key))
{
wd->thumb.thumb_path = eina_stringshare_ref(thumb_path);
wd->thumb.thumb_key = eina_stringshare_ref(thumb_key);
}
static void
-_finished_thumb_cb(void *data, Ethumb_Client *c __UNUSED__, int id, const char *file, const char *key, const char *thumb_path, const char *thumb_key, Eina_Bool success)
+_elm_thumb_done(Ethumb_Client *client __UNUSED__, const char *thumb_path, const char *thumb_key, void *data)
{
Widget_Data *wd = data;
- EINA_SAFETY_ON_FALSE_RETURN(wd->thumb.id == id);
- wd->thumb.id = -1;
+ assert(wd->thumb.request);
pending_request--;
+ wd->thumb.request = NULL;
- edje_object_signal_emit(wd->frame, EDJE_SIGNAL_PULSE_STOP, "elm");
-
- if (success)
- {
- _finished_thumb(wd, thumb_path, thumb_key);
- return;
- }
-
- ERR("could not generate thumbnail for %s (key: %s)", file, key ? key : "");
- edje_object_signal_emit(wd->frame, EDJE_SIGNAL_GENERATE_ERROR, "elm");
- evas_object_smart_callback_call(wd->self, SIG_GENERATE_ERROR, NULL);
+ _finished_thumb(wd, thumb_path, thumb_key);
}
static void
-_thumb_exists(Ethumb_Client *client __UNUSED__, Ethumb_Exists *thread,
- Eina_Bool exists, void *data)
+_elm_thumb_error(Ethumb_Client *client __UNUSED__, void *data)
{
Widget_Data *wd = data;
- if (ethumb_client_thumb_exists_check(thread))
- return ;
-
- wd->thumb.exists = NULL;
-
- if (exists)
- {
- const char *thumb_path, *thumb_key;
-
- pending_request--;
+ assert(wd->thumb.request);
- wd->thumb.id = -1;
- ethumb_client_thumb_path_get(_elm_ethumb_client, &thumb_path,
- &thumb_key);
- _finished_thumb(wd, thumb_path, thumb_key);
- return;
- }
- else if ((wd->thumb.id = ethumb_client_generate
- (_elm_ethumb_client, _finished_thumb_cb, wd, NULL)) != -1)
- {
- edje_object_signal_emit(wd->frame, EDJE_SIGNAL_PULSE_START, "elm");
- edje_object_signal_emit(wd->frame, EDJE_SIGNAL_GENERATE_START, "elm");
- evas_object_smart_callback_call(wd->self, SIG_GENERATE_START, NULL);
- }
- else
- {
- pending_request--;
+ pending_request--;
+ wd->thumb.request = NULL;
- wd->thumb.id = -1;
- edje_object_signal_emit(wd->frame, EDJE_SIGNAL_GENERATE_ERROR, "elm");
- evas_object_smart_callback_call(wd->self, SIG_GENERATE_ERROR, NULL);
- }
+ ERR("could not generate thumbnail for %s (key: %s)", wd->thumb.file, wd->thumb.key ? wd->thumb.key : "");
+ edje_object_signal_emit(wd->frame, EDJE_SIGNAL_GENERATE_ERROR, "elm");
+ evas_object_smart_callback_call(wd->self, SIG_GENERATE_ERROR, NULL);
}
static void
_thumb_apply(Widget_Data *wd)
{
- if (wd->thumb.id > 0)
+ if (wd->thumb.request)
{
- ethumb_client_generate_cancel
- (_elm_ethumb_client, wd->thumb.id, NULL, NULL, NULL);
- wd->thumb.id = -1;
+ ethumb_client_thumb_async_cancel(_elm_ethumb_client, wd->thumb.request);
+ wd->thumb.request = NULL;
}
-
- if (wd->thumb.exists)
- {
- ethumb_client_thumb_exists_cancel(wd->thumb.exists, _thumb_exists, wd);
- wd->thumb.exists = NULL;
- }
-
if (wd->thumb.retry)
{
retry = eina_list_remove(retry, wd);
if (!wd->file) return;
+ edje_object_signal_emit(wd->frame, EDJE_SIGNAL_PULSE_START, "elm");
+ edje_object_signal_emit(wd->frame, EDJE_SIGNAL_GENERATE_START, "elm");
+ evas_object_smart_callback_call(wd->self, SIG_GENERATE_START, NULL);
+
pending_request++;
ethumb_client_file_set(_elm_ethumb_client, wd->file, wd->key);
- wd->thumb.exists = ethumb_client_thumb_exists(_elm_ethumb_client,
- _thumb_exists,
- wd);
+ wd->thumb.request = ethumb_client_thumb_async_get(_elm_ethumb_client,
+ _elm_thumb_done,
+ _elm_thumb_error,
+ wd);
}
static Eina_Bool
{
evas_object_show(wd->frame);
- if (elm_thumb_ethumb_client_connected())
+ if (elm_thumb_ethumb_client_connected_get())
{
_thumb_apply(wd);
return;
evas_object_hide(wd->frame);
- if (wd->thumb.id >= 0)
+ if (wd->thumb.request)
{
- ethumb_client_generate_cancel
- (_elm_ethumb_client, wd->thumb.id, NULL, NULL, NULL);
- wd->thumb.id = -1;
+ ethumb_client_thumb_async_cancel(_elm_ethumb_client, wd->thumb.request);
+ wd->thumb.request = NULL;
edje_object_signal_emit(wd->frame, EDJE_SIGNAL_GENERATE_STOP, "elm");
evas_object_smart_callback_call(wd->self, SIG_GENERATE_STOP, NULL);
}
- if (wd->thumb.exists)
- {
- ethumb_client_thumb_exists_cancel(wd->thumb.exists, _thumb_exists, wd);
- wd->thumb.exists = NULL;
- }
-
if (wd->thumb.retry)
{
retry = eina_list_remove(retry, wd);
return EINA_TRUE;
}
-/**
- * This must be called before any other function that handle with
- * elm_thumb objects or ethumb_client instances.
- *
- * @ingroup Thumb
- */
EAPI Eina_Bool
elm_need_ethumb(void)
{
#endif
}
-/**
- * Add a new thumb object to the parent.
- *
- * @param parent The parent object.
- * @return The new object or NULL if it cannot be created.
- *
- * @see elm_thumb_file_set()
- * @see elm_thumb_ethumb_client_get()
- *
- * @ingroup Thumb
- */
EAPI Evas_Object *
elm_thumb_add(Evas_Object *parent)
{
wd->file = NULL;
wd->key = NULL;
wd->eeh = NULL;
- wd->thumb.id = -1;
wd->on_hold = EINA_FALSE;
wd->is_video = EINA_FALSE;
wd->was_video = EINA_FALSE;
#ifdef HAVE_ELEMENTARY_ETHUMB
wd->thumb.thumb_path = NULL;
wd->thumb.thumb_key = NULL;
- wd->thumb.exists = NULL;
+ wd->thumb.request = NULL;
evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_DOWN,
_mouse_down_cb, wd);
evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_UP,
return obj;
}
-/**
- * Reload thumbnail if it was generated before.
- *
- * This is useful if the ethumb client configuration changed, like its
- * size, aspect or any other property one set in the handle returned
- * by elm_thumb_ethumb_client_get().
- *
- * @param obj The thumb object to reload
- *
- * @see elm_thumb_file_set()
- *
- * @ingroup Thumb
- */
EAPI void
elm_thumb_reload(Evas_Object *obj)
{
#endif
}
-/**
- * Set the file that will be used as thumbnail.
- *
- * The file can be an image or a video (in that case, acceptable extensions are:
- * avi, mp4, ogv, mov, mpg and wmv). To start the video animation, use the
- * function elm_thumb_animate().
- *
- * @param obj The thumb object.
- * @param file The path to file that will be used as thumb.
- * @param key The key used in case of an EET file.
- *
- * @see elm_thumb_file_get()
- * @see elm_thumb_reload()
- * @see elm_thumb_animate()
- *
- * @ingroup Thumb
- */
EAPI void
elm_thumb_file_set(Evas_Object *obj, const char *file, const char *key)
{
#ifdef HAVE_ELEMENTARY_ETHUMB
if (((file_replaced) || (key_replaced)) && (evas_object_visible_get(obj)))
_thumb_show(wd);
+#else
+ (void)key_replaced;
#endif
}
-/**
- * Get the image or video path and key used to generate the thumbnail.
- *
- * @param obj The thumb object.
- * @param file Pointer to filename.
- * @param key Pointer to key.
- *
- * @see elm_thumb_file_set()
- * @see elm_thumb_path_get()
- * @see elm_thumb_animate()
- *
- * @ingroup Thumb
- */
EAPI void
elm_thumb_file_get(const Evas_Object *obj, const char **file, const char **key)
{
*key = wd->key;
}
-/**
- * Get the path and key to the image or video generated by ethumb.
- *
- * One just need to make sure that the thumbnail was generated before getting
- * its path; otherwise, the path will be NULL. One way to do that is by asking
- * for the path when/after the "generate,stop" smart callback is called.
- *
- * @param obj The thumb object.
- * @param file Pointer to thumb path.
- * @param key Pointer to thumb key.
- *
- * @see elm_thumb_file_get()
- *
- * @ingroup Thumb
- */
EAPI void
elm_thumb_path_get(const Evas_Object *obj, const char **file, const char **key)
{
*key = wd->thumb.key;
}
-/**
- * Set the animation state for the thumb object. If its content is an animated
- * video, you may start/stop the animation or tell it to play continuously and
- * looping.
- *
- * @param obj The thumb object.
- * @param setting The animation setting.
- *
- * @see elm_thumb_file_set()
- *
- * @ingroup Thumb
- */
EAPI void
elm_thumb_animate_set(Evas_Object *obj, Elm_Thumb_Animation_Setting setting)
{
edje_object_signal_emit(wd->view, "animate_stop", "");
}
-/**
- * Get the animation state for the thumb object.
- *
- * @param obj The thumb object.
- * @return getting The animation setting or @c ELM_THUMB_ANIMATION_LAST,
- * on errors.
- *
- * @see elm_thumb_file_get()
- *
- * @ingroup Thumb
- */
EAPI Elm_Thumb_Animation_Setting
elm_thumb_animate_get(const Evas_Object *obj)
{
return wd->anim_setting;
}
-/**
- * Get the ethumb_client handle so custom configuration can be made.
- * This must be called before the objects are created to be sure no object is
- * visible and no generation started.
- *
- * @return Ethumb_Client instance or NULL.
- *
- * Example of usage:
- *
- * @code
- * #include <Elementary.h>
- * #ifndef ELM_LIB_QUICKLAUNCH
- * EAPI int
- * elm_main(int argc, char **argv)
- * {
- * Ethumb_Client *client;
- *
- * elm_need_ethumb();
- *
- * // ... your code
- *
- * client = elm_thumb_ethumb_client_get();
- * if (!client)
- * {
- * ERR("could not get ethumb_client");
- * return 1;
- * }
- * ethumb_client_size_set(client, 100, 100);
- * ethumb_client_crop_align_set(client, 0.5, 0.5);
- * // ... your code
- *
- * // Create elm_thumb objects here
- *
- * elm_run();
- * elm_shutdown();
- * return 0;
- * }
- * #endif
- * ELM_MAIN()
- * @endcode
- *
- * @ingroup Thumb
- */
EAPI void *
elm_thumb_ethumb_client_get(void)
{
return _elm_ethumb_client;
}
-/**
- * Get the ethumb_client connection state.
- *
- * @return EINA_TRUE if the client is connected to the server or
- * EINA_FALSE otherwise.
- */
EAPI Eina_Bool
-elm_thumb_ethumb_client_connected(void)
+elm_thumb_ethumb_client_connected_get(void)
{
return _elm_ethumb_connected;
}