elementary: use new Ethumb facility.

SVN revision: 65782
This commit is contained in:
Cedric BAIL 2011-12-01 15:37:56 +00:00
parent e9f0867326
commit 13c14120f2
2 changed files with 56 additions and 156 deletions

View File

@ -17,19 +17,17 @@ struct _Widget_Data
#ifdef HAVE_ELEMENTARY_ETHUMB
struct {
int id;
struct {
const char *path;
const char *key;
} file, thumb;
Ethumb_Exists *exists;
Ecore_Event_Handler *eeh;
Ethumb_Thumb_Format format;
Ethumb_Client_Async *request;
Eina_Bool retry : 1;
} thumb;
#endif
@ -59,8 +57,6 @@ struct _Widget_Data
#ifdef HAVE_ELEMENTARY_ETHUMB
static Eina_List *_elm_icon_retry = NULL;
static int _icon_pending_request = 0;
static void _icon_thumb_exists(Ethumb_Client *client __UNUSED__, Ethumb_Exists *thread, Eina_Bool exists, void *data);
#endif
static const char *widtype = NULL;
@ -108,17 +104,10 @@ _icon_size_min_get(Evas_Object *icon)
static void
_icon_thumb_stop(Widget_Data *wd, void *ethumbd)
{
if (wd->thumb.id >= 0)
if (wd->thumb.request)
{
ethumb_client_generate_cancel(ethumbd, wd->thumb.id, NULL, NULL, NULL);
wd->thumb.id = -1;
_icon_pending_request--;
}
if (wd->thumb.exists)
{
ethumb_client_thumb_exists_cancel(wd->thumb.exists);
wd->thumb.exists = NULL;
ethumb_client_thumb_async_cancel(ethumbd, wd->thumb.request);
wd->thumb.request = NULL;
_icon_pending_request--;
}
@ -225,68 +214,34 @@ _icon_thumb_finish(Widget_Data *wd, Ethumb_Client *ethumbd)
}
static void
_icon_thumb_cb(void *data,
Ethumb_Client *ethumbd,
int id,
const char *file __UNUSED__,
const char *key __UNUSED__,
const char *thumb_path,
const char *thumb_key,
Eina_Bool success)
_icon_thumb_done(Ethumb_Client *client, 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);
_icon_pending_request--;
wd->thumb.request = NULL;
if (success)
{
eina_stringshare_replace(&wd->thumb.thumb.path, thumb_path);
eina_stringshare_replace(&wd->thumb.thumb.key, thumb_key);
wd->thumb.format = ethumb_client_format_get(ethumbd);
eina_stringshare_replace(&wd->thumb.thumb.path, thumb_path);
eina_stringshare_replace(&wd->thumb.thumb.key, thumb_key);
wd->thumb.format = ethumb_client_format_get(client);
_icon_thumb_finish(wd, ethumbd);
}
else
{
ERR("could not generate thumbnail for %s (key: %s)", file, key);
_icon_thumb_cleanup(ethumbd);
}
_icon_thumb_finish(wd, client);
}
static void
_icon_thumb_exists(Ethumb_Client *client __UNUSED__, Ethumb_Exists *thread, Eina_Bool exists, void *data)
_icon_thumb_error(Ethumb_Client *client, void *data)
{
Widget_Data *wd = data;
Ethumb_Client *ethumbd;
if (ethumb_client_thumb_exists_check(thread))
return ;
assert(wd->thumb.request);
wd->thumb.exists = NULL;
_icon_pending_request--;
wd->thumb.request = NULL;
ethumbd = elm_thumb_ethumb_client_get();
if (exists)
{
const char *thumb_path, *thumb_key;
_icon_pending_request--;
ethumb_client_thumb_path_get(ethumbd, &thumb_path, &thumb_key);
eina_stringshare_replace(&wd->thumb.thumb.path, thumb_path);
eina_stringshare_replace(&wd->thumb.thumb.key, thumb_key);
wd->thumb.format = ethumb_client_format_get(ethumbd);
_icon_thumb_finish(wd, ethumbd);
}
else if ((wd->thumb.id = ethumb_client_generate(ethumbd, _icon_thumb_cb, wd, NULL)) == -1)
{
ERR("Generate was unable to start !");
/* Failed to generate thumbnail */
_icon_pending_request--;
}
ERR("could not generate thumbnail for %s (key: %s)", wd->thumb.file.path, wd->thumb.file.key);
_icon_thumb_cleanup(client);
}
static void
@ -303,7 +258,7 @@ _icon_thumb_apply(Widget_Data *wd)
_icon_pending_request++;
if (!ethumb_client_file_set(ethumbd, wd->thumb.file.path, wd->thumb.file.key)) return ;
ethumb_client_size_set(ethumbd, _icon_size_min_get(wd->img), _icon_size_min_get(wd->img));
wd->thumb.exists = ethumb_client_thumb_exists(ethumbd, _icon_thumb_exists, wd);
wd->thumb.request = ethumb_client_thumb_async_get(ethumbd, _icon_thumb_done, _icon_thumb_error, wd);
}
static Eina_Bool
@ -663,7 +618,7 @@ elm_icon_add(Evas_Object *parent)
evas_object_smart_callbacks_descriptions_set(obj, _signals);
#ifdef HAVE_ELEMENTARY_ETHUMB
wd->thumb.id = -1;
wd->thumb.request = NULL;
#endif
wd->smooth = EINA_TRUE;

View File

@ -12,13 +12,12 @@ struct _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;
@ -67,10 +66,6 @@ Eina_Bool _elm_ethumb_connected = EINA_FALSE;
#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;
@ -81,16 +76,10 @@ _del_hook(Evas_Object *obj)
Widget_Data *wd = elm_widget_data_get(obj);
#ifdef HAVE_ELEMENTARY_ETHUMB
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;
}
if (wd->thumb.exists)
{
ethumb_client_thumb_exists_cancel(wd->thumb.exists);
wd->thumb.exists = NULL;
ethumb_client_thumb_async_cancel(_elm_ethumb_client, wd->thumb.request);
wd->thumb.request = NULL;
}
if (wd->thumb.retry)
{
@ -350,85 +339,44 @@ err:
}
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;
}
_finished_thumb(wd, thumb_path, thumb_key);
}
static void
_elm_thumb_error(Ethumb_Client *client __UNUSED__, void *data)
{
Widget_Data *wd = data;
assert(wd->thumb.request);
pending_request--;
wd->thumb.request = NULL;
ERR("could not generate thumbnail for %s (key: %s)", wd->thumb.file, wd->thumb.key ? wd->thumb.key : "");
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);
}
static void
_thumb_exists(Ethumb_Client *client __UNUSED__, Ethumb_Exists *thread,
Eina_Bool exists, 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--;
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--;
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);
}
}
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);
wd->thumb.exists = NULL;
}
if (wd->thumb.retry)
{
retry = eina_list_remove(retry, wd);
@ -437,11 +385,16 @@ _thumb_apply(Widget_Data *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
@ -480,22 +433,15 @@ _thumb_hide_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void
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);
wd->thumb.exists = NULL;
}
if (wd->thumb.retry)
{
retry = eina_list_remove(retry, wd);
@ -604,7 +550,6 @@ 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;
@ -612,7 +557,7 @@ elm_thumb_add(Evas_Object *parent)
#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,