elementary: fix race condition in elm_thumb.
[framework/uifw/elementary.git] / src / lib / elm_thumb.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3
4 /**
5  * @defgroup Thumb Thumb
6  *
7  * A thumb object is used for displaying the thumbnail of an image or video.
8  * You must have compiled Elementary with Ethumb_Client support and the DBus
9  * service must be present and auto-activated in order to have thumbnails to
10  * be generated.
11  *
12  * Signals that you can add callbacks for are:
13  *
14  * "clicked" - This is called when a user has clicked the thumb without dragging
15  *             around.
16  * "clicked,double" - This is called when a user has double-clicked the thumb.
17  * "press" - This is called when a user has pressed down the thumb.
18  * "generate,start" - The thumbnail generation started.
19  * "generate,stop" - The generation process stopped.
20  * "generate,error" - The generation failed.
21  * "load,error" - The thumbnail image loading failed.
22  */
23
24 typedef struct _Widget_Data Widget_Data;
25
26 struct _Widget_Data
27 {
28    Evas_Object *self;
29    Evas_Object *frame;
30    Evas_Object *view;
31    const char *file;
32    const char *key;
33    struct
34      {
35         int id;
36         const char *file;
37         const char *key;
38 #ifdef HAVE_ELEMENTARY_ETHUMB
39         Ethumb_Exists *exists;
40 #endif
41      } thumb;
42    Ecore_Event_Handler *eeh;
43    Elm_Thumb_Animation_Setting anim_setting;
44    Eina_Bool on_hold : 1;
45    Eina_Bool is_video : 1;
46    Eina_Bool was_video : 1;
47    Eina_Bool edit : 1;
48 };
49
50 static const char *widtype = NULL;
51
52 static const char SIG_CLICKED[] = "clicked";
53 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
54 static const char SIG_GENERATE_ERROR[] = "generate,error";
55 static const char SIG_GENERATE_START[] = "generate,start";
56 static const char SIG_GENERATE_STOP[] = "generate,stop";
57 static const char SIG_LOAD_ERROR[] = "load,error";
58 static const char SIG_PRESS[] = "press";
59
60 static const Evas_Smart_Cb_Description _signals[] =
61 {
62      {SIG_CLICKED, ""},
63      {SIG_CLICKED_DOUBLE, ""},
64      {SIG_GENERATE_ERROR, ""},
65      {SIG_GENERATE_START, ""},
66      {SIG_GENERATE_STOP, ""},
67      {SIG_LOAD_ERROR, ""},
68      {SIG_PRESS, ""},
69      {NULL, NULL}
70 };
71
72 #define EDJE_SIGNAL_GENERATE_START "elm,thumb,generate,start"
73 #define EDJE_SIGNAL_GENERATE_STOP "elm,thumb,generate,stop"
74 #define EDJE_SIGNAL_GENERATE_ERROR "elm,thumb,generate,error"
75 #define EDJE_SIGNAL_LOAD_ERROR "elm,thumb,load,error"
76 #define EDJE_SIGNAL_PULSE_START "elm,state,pulse,start"
77 #define EDJE_SIGNAL_PULSE_STOP "elm,state,pulse,stop"
78
79 struct _Ethumb_Client *_elm_ethumb_client = NULL;
80 Eina_Bool _elm_ethumb_connected = EINA_FALSE;
81
82 EAPI int ELM_ECORE_EVENT_ETHUMB_CONNECT = 0;
83
84 static void
85 _del_hook(Evas_Object *obj)
86 {
87    Widget_Data *wd = elm_widget_data_get(obj);
88
89 #ifdef HAVE_ELEMENTARY_ETHUMB
90    if (wd->thumb.id >= 0)
91      {
92         ethumb_client_generate_cancel(_elm_ethumb_client, wd->thumb.id,
93                                       NULL, NULL, NULL);
94         wd->thumb.id = -1;
95      }
96    if (wd->thumb.exists)
97      {
98         ethumb_client_thumb_exists_cancel(wd->thumb.exists);
99         wd->thumb.exists = NULL;
100      }
101 #endif
102
103    eina_stringshare_del(wd->file);
104    eina_stringshare_del(wd->key);
105    if (wd->eeh) ecore_event_handler_del(wd->eeh);
106    free(wd);
107 }
108
109 static void
110 _theme_hook(Evas_Object *obj)
111 {
112    Widget_Data *wd = elm_widget_data_get(obj);
113    _elm_theme_object_set(obj, wd->frame, "thumb", "base",
114                          elm_widget_style_get(obj));
115 }
116
117 #ifdef HAVE_ELEMENTARY_ETHUMB
118 static void
119 _mouse_down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
120 {
121    Widget_Data *wd = data;
122    Evas_Event_Mouse_Down *ev = event_info;
123
124    if (ev->button != 1)
125      return;
126    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
127      wd->on_hold = EINA_TRUE;
128    else
129      wd->on_hold = EINA_FALSE;
130    if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
131      evas_object_smart_callback_call(wd->self, SIG_CLICKED_DOUBLE, NULL);
132    else
133      evas_object_smart_callback_call(wd->self, SIG_PRESS, NULL);
134 }
135
136 static void
137 _mouse_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
138 {
139    Widget_Data *wd = data;
140    Evas_Event_Mouse_Up *ev = event_info;
141
142    if (ev->button != 1)
143      return;
144    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
145      wd->on_hold = EINA_TRUE;
146    else
147      wd->on_hold = EINA_FALSE;
148    if (!wd->on_hold)
149      evas_object_smart_callback_call(wd->self, SIG_CLICKED, NULL);
150    wd->on_hold = EINA_FALSE;
151 }
152
153 static void
154 _finished_thumb(Widget_Data *wd, const char *thumb_path, const char *thumb_key)
155 {
156    Eina_Bool new_view = EINA_FALSE;
157    int r;
158    Evas_Coord mw, mh;
159    Evas *evas;
160
161    evas = evas_object_evas_get(wd->self);
162    if ((wd->view) && (wd->is_video ^ wd->was_video))
163      {
164         evas_object_del(wd->view);
165         wd->view = NULL;
166      }
167    wd->was_video = wd->is_video;
168
169    if ((wd->is_video) &&
170        (ethumb_client_format_get(_elm_ethumb_client) == ETHUMB_THUMB_EET))
171      {
172         if (!wd->view)
173           {
174              wd->view = edje_object_add(evas);
175              if (!wd->view)
176                {
177                   ERR("could not create edje object");
178                   goto err;
179                }
180              new_view = EINA_TRUE;
181           }
182
183         if (!edje_object_file_set(wd->view, thumb_path, "movie/thumb"))
184           {
185              ERR("could not set file=%s key=%s for %s", thumb_path, thumb_key,
186                  wd->file);
187              goto view_err;
188           }
189      }
190    else
191      {
192         if (!wd->view)
193           {
194              wd->view = evas_object_image_filled_add(evas);
195              if (!wd->view)
196                {
197                   ERR("could not create image object");
198                   goto err;
199                }
200              new_view = EINA_TRUE;
201           }
202
203         evas_object_image_file_set(wd->view, thumb_path, thumb_key);
204         r = evas_object_image_load_error_get(wd->view);
205         if (r != EVAS_LOAD_ERROR_NONE)
206           {
207              ERR("%s: %s", thumb_path, evas_load_error_str(r));
208              goto view_err;
209           }
210      }
211
212    if (new_view) elm_widget_sub_object_add(wd->self, wd->view);
213    edje_object_part_swallow(wd->frame, "elm.swallow.content", wd->view);
214    edje_object_size_min_get(wd->frame, &mw, &mh);
215    edje_object_size_min_restricted_calc(wd->frame, &mw, &mh, mw, mh);
216    evas_object_size_hint_min_set(wd->self, mw, mh);
217    eina_stringshare_replace(&(wd->thumb.file), thumb_path);
218    eina_stringshare_replace(&(wd->thumb.key), thumb_key);
219    edje_object_signal_emit(wd->frame, EDJE_SIGNAL_GENERATE_STOP, "elm");
220    evas_object_smart_callback_call(wd->self, SIG_GENERATE_STOP, NULL);
221    return;
222
223 view_err:
224    evas_object_del(wd->view);
225    wd->view = NULL;
226 err:
227    edje_object_signal_emit(wd->frame, EDJE_SIGNAL_LOAD_ERROR, "elm");
228    evas_object_smart_callback_call(wd->self, SIG_LOAD_ERROR, NULL);
229 }
230
231 static void
232 _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)
233 {
234    Widget_Data *wd = data;
235
236    EINA_SAFETY_ON_FALSE_RETURN(wd->thumb.id == id);
237    wd->thumb.id = -1;
238
239    edje_object_signal_emit(wd->frame, EDJE_SIGNAL_PULSE_STOP, "elm");
240
241    if (success)
242      {
243         _finished_thumb(wd, thumb_path, thumb_key);
244         return;
245      }
246
247    ERR("could not generate thumbnail for %s (key: %s)", file, key ? key : "");
248    edje_object_signal_emit(wd->frame, EDJE_SIGNAL_GENERATE_ERROR, "elm");
249    evas_object_smart_callback_call(wd->self, SIG_GENERATE_ERROR, NULL);
250 }
251
252 static void
253 _thumb_exists(Ethumb_Client *client __UNUSED__, Ethumb_Exists *thread,
254               Eina_Bool exists, void *data)
255 {
256    Widget_Data *wd = data;
257
258    if (ethumb_client_thumb_exists_check(thread))
259      return ;
260
261    wd->thumb.exists = NULL;
262
263    if (exists)
264      {
265         const char *thumb_path, *thumb_key;
266
267         wd->thumb.id = -1;
268         ethumb_client_thumb_path_get(_elm_ethumb_client, &thumb_path,
269                                      &thumb_key);
270         _finished_thumb(wd, thumb_path, thumb_key);
271         return;
272      }
273    else if ((wd->thumb.id = ethumb_client_generate
274              (_elm_ethumb_client, _finished_thumb_cb, wd, NULL)) != -1)
275      {
276         edje_object_signal_emit(wd->frame, EDJE_SIGNAL_PULSE_START, "elm");
277         edje_object_signal_emit(wd->frame, EDJE_SIGNAL_GENERATE_START, "elm");
278         evas_object_smart_callback_call(wd->self, SIG_GENERATE_START, NULL);
279      }
280    else
281      {
282         wd->thumb.id = -1;
283         edje_object_signal_emit(wd->frame, EDJE_SIGNAL_GENERATE_ERROR, "elm");
284         evas_object_smart_callback_call(wd->self, SIG_GENERATE_ERROR, NULL);
285      }
286
287 }
288
289 static void
290 _thumb_apply(Widget_Data *wd)
291 {
292    if (wd->thumb.id > 0)
293      {
294         ethumb_client_generate_cancel
295            (_elm_ethumb_client, wd->thumb.id, NULL, NULL, NULL);
296         wd->thumb.id = -1;
297      }
298
299    if (wd->thumb.exists)
300      {
301         ethumb_client_thumb_exists_cancel(wd->thumb.exists);
302         wd->thumb.exists = NULL;
303      }
304
305    if (!wd->file) return;
306
307    ethumb_client_file_set(_elm_ethumb_client, wd->file, wd->key);
308    wd->thumb.exists = ethumb_client_thumb_exists(_elm_ethumb_client,
309                                                  _thumb_exists,
310                                                  wd);
311 }
312
313 static Eina_Bool
314 _thumb_apply_cb(void *data, int type __UNUSED__, void *ev __UNUSED__)
315 {
316    _thumb_apply(data);
317    return ECORE_CALLBACK_RENEW;
318 }
319
320 static void
321 _thumb_show(Widget_Data *wd)
322 {
323    evas_object_show(wd->frame);
324
325    if (elm_thumb_ethumb_client_connected())
326      {
327         _thumb_apply(wd);
328         return;
329      }
330
331    if (!wd->eeh)
332      wd->eeh = ecore_event_handler_add(ELM_ECORE_EVENT_ETHUMB_CONNECT,
333                                        _thumb_apply_cb, wd);
334 }
335
336 static void
337 _thumb_show_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
338 {
339    _thumb_show(data);
340 }
341
342 static void
343 _thumb_hide_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
344 {
345    Widget_Data *wd = data;
346
347    evas_object_hide(wd->frame);
348
349    if (wd->thumb.id >= 0)
350      {
351         ethumb_client_generate_cancel
352            (_elm_ethumb_client, wd->thumb.id, NULL, NULL, NULL);
353         wd->thumb.id = -1;
354
355         edje_object_signal_emit(wd->frame, EDJE_SIGNAL_GENERATE_STOP, "elm");
356         evas_object_smart_callback_call(wd->self, SIG_GENERATE_STOP, NULL);
357      }
358
359    if (wd->thumb.exists)
360      {
361         ethumb_client_thumb_exists_cancel(wd->thumb.exists);
362         wd->thumb.exists = NULL;
363      }
364
365    if (wd->eeh)
366      {
367         ecore_event_handler_del(wd->eeh);
368         wd->eeh = NULL;
369      }
370 }
371
372 #endif
373
374 #ifdef ELM_ETHUMB
375 static int _elm_need_ethumb = 0;
376
377 static void _on_die_cb(void *, Ethumb_Client *);
378
379 static void
380 _connect_cb(void *data __UNUSED__, Ethumb_Client *c, Eina_Bool success)
381 {
382    if (success)
383      {
384         ethumb_client_on_server_die_callback_set(c, _on_die_cb, NULL, NULL);
385         _elm_ethumb_connected = EINA_TRUE;
386         ecore_event_add(ELM_ECORE_EVENT_ETHUMB_CONNECT, NULL, NULL, NULL);
387      }
388    else
389      _elm_ethumb_client = NULL;
390 }
391
392 static void
393 _on_die_cb(void *data __UNUSED__, Ethumb_Client *c __UNUSED__)
394 {
395    ethumb_client_disconnect(_elm_ethumb_client);
396    _elm_ethumb_client = NULL;
397    _elm_ethumb_connected = EINA_FALSE;
398    _elm_ethumb_client = ethumb_client_connect(_connect_cb, NULL, NULL);
399 }
400 #endif
401
402 void
403 _elm_unneed_ethumb(void)
404 {
405 #ifdef ELM_ETHUMB
406    if (--_elm_need_ethumb) return;
407
408    ethumb_client_disconnect(_elm_ethumb_client);
409    _elm_ethumb_client = NULL;
410    ethumb_client_shutdown();
411    ELM_ECORE_EVENT_ETHUMB_CONNECT = 0;
412 #endif
413 }
414
415 static Eina_Bool
416 _elm_thumb_dropcb(void *data __UNUSED__, Evas_Object *o, Elm_Selection_Data *drop)
417 {
418    if ((!o) || (!drop) || (!drop->data)) return EINA_FALSE;
419    elm_thumb_file_set(o, drop->data, NULL);
420    return EINA_TRUE;
421 }
422
423 /**
424  * This must be called before any other function that handle with
425  * elm_thumb objects or ethumb_client instances.
426  *
427  * @ingroup Thumb
428  */
429 EAPI Eina_Bool
430 elm_need_ethumb(void)
431 {
432 #ifdef ELM_ETHUMB
433    if (_elm_need_ethumb++) return EINA_TRUE;
434    ELM_ECORE_EVENT_ETHUMB_CONNECT = ecore_event_type_new();
435    ethumb_client_init();
436    _elm_ethumb_client = ethumb_client_connect(_connect_cb, NULL, NULL);
437    return EINA_TRUE;
438 #else
439    return EINA_FALSE;
440 #endif
441 }
442
443 /**
444  * Add a new thumb object to the parent.
445  *
446  * @param parent The parent object.
447  * @return The new object or NULL if it cannot be created.
448  *
449  * @see elm_thumb_file_set()
450  * @see elm_thumb_ethumb_client_get()
451  *
452  * @ingroup Thumb
453  */
454 EAPI Evas_Object *
455 elm_thumb_add(Evas_Object *parent)
456 {
457    Evas *e;
458    Widget_Data *wd;
459    Evas_Object *obj;
460    Evas_Coord minw, minh;
461
462    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
463
464    ELM_SET_WIDTYPE(widtype, "thumb");
465    elm_widget_type_set(obj, "thumb");
466    elm_widget_sub_object_add(parent, obj);
467    elm_widget_data_set(obj, wd);
468    elm_widget_del_hook_set(obj, _del_hook);
469    elm_widget_theme_hook_set(obj, _theme_hook);
470    elm_widget_can_focus_set(obj, EINA_FALSE);
471
472    wd->frame = edje_object_add(e);
473    _elm_theme_object_set(obj, wd->frame, "thumb", "base", "default");
474    elm_widget_resize_object_set(obj, wd->frame);
475
476    edje_object_size_min_calc(obj, &minw, &minh);
477    evas_object_size_hint_min_set(obj, minw, minh);
478
479    wd->self = obj;
480    wd->view = NULL;
481    wd->file = NULL;
482    wd->key = NULL;
483    wd->eeh = NULL;
484    wd->thumb.id = -1;
485    wd->on_hold = EINA_FALSE;
486    wd->is_video = EINA_FALSE;
487    wd->was_video = EINA_FALSE;
488
489 #ifdef HAVE_ELEMENTARY_ETHUMB
490    wd->thumb.exists = NULL;
491    evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_DOWN,
492                                   _mouse_down_cb, wd);
493    evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_UP,
494                                   _mouse_up_cb, wd);
495    evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW,
496                                   _thumb_show_cb, wd);
497    evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE,
498                                   _thumb_hide_cb, wd);
499 #endif
500
501    // TODO: convert Elementary to subclassing of Evas_Smart_Class
502    // TODO: and save some bytes, making descriptions per-class and not instance!
503    evas_object_smart_callbacks_descriptions_set(obj, _signals);
504    return obj;
505 }
506
507 /**
508  * Reload thumbnail if it was generated before.
509  *
510  * This is useful if the ethumb client configuration changed, like its
511  * size, aspect or any other property one set in the handle returned
512  * by elm_thumb_ethumb_client_get().
513  *
514  * @param obj The thumb object to reload
515  *
516  * @see elm_thumb_file_set()
517  *
518  * @ingroup Thumb
519  */
520 EAPI void
521 elm_thumb_reload(Evas_Object *obj)
522 {
523    ELM_CHECK_WIDTYPE(obj, widtype);
524    Widget_Data *wd = elm_widget_data_get(obj);
525
526    eina_stringshare_replace(&(wd->thumb.file), NULL);
527    eina_stringshare_replace(&(wd->thumb.key), NULL);
528
529 #ifdef HAVE_ELEMENTARY_ETHUMB
530    if (evas_object_visible_get(obj))
531      _thumb_show(wd);
532 #endif
533 }
534
535 /**
536  * Set the file that will be used as thumbnail.
537  *
538  * The file can be an image or a video (in that case, acceptable extensions are:
539  * avi, mp4, ogv, mov, mpg and wmv). To start the video animation, use the
540  * function elm_thumb_animate().
541  *
542  * @param obj The thumb object.
543  * @param file The path to file that will be used as thumb.
544  * @param key The key used in case of an EET file.
545  *
546  * @see elm_thumb_file_get()
547  * @see elm_thumb_reload()
548  * @see elm_thumb_animate()
549  *
550  * @ingroup Thumb
551  */
552 EAPI void
553 elm_thumb_file_set(Evas_Object *obj, const char *file, const char *key)
554 {
555    ELM_CHECK_WIDTYPE(obj, widtype);
556    Eina_Bool file_replaced, key_replaced;
557    Widget_Data *wd = elm_widget_data_get(obj);
558
559    file_replaced = eina_stringshare_replace(&(wd->file), file);
560    key_replaced = eina_stringshare_replace(&(wd->key), key);
561
562    if (file_replaced)
563      {
564         int prefix_size;
565         const char **ext, *ptr;
566         static const char *extensions[] =
567           {
568              ".avi", ".mp4", ".ogv", ".mov", ".mpg", ".wmv", NULL
569           };
570
571         prefix_size = eina_stringshare_strlen(wd->file) - 4;
572         if (prefix_size >= 0)
573           {
574              ptr = wd->file + prefix_size;
575              wd->is_video = EINA_FALSE;
576              for (ext = extensions; *ext; ext++)
577                if (!strcasecmp(ptr, *ext))
578                  {
579                     wd->is_video = EINA_TRUE;
580                     break;
581                  }
582           }
583      }
584
585    eina_stringshare_replace(&(wd->thumb.file), NULL);
586    eina_stringshare_replace(&(wd->thumb.key), NULL);
587
588 #ifdef HAVE_ELEMENTARY_ETHUMB
589    if (((file_replaced) || (key_replaced)) && (evas_object_visible_get(obj)))
590      _thumb_show(wd);
591 #endif
592 }
593
594 /**
595  * Get the image or video path and key used to generate the thumbnail.
596  *
597  * @param obj The thumb object.
598  * @param file Pointer to filename.
599  * @param key Pointer to key.
600  *
601  * @see elm_thumb_file_set()
602  * @see elm_thumb_path_get()
603  * @see elm_thumb_animate()
604  *
605  * @ingroup Thumb
606  */
607 EAPI void
608 elm_thumb_file_get(const Evas_Object *obj, const char **file, const char **key)
609 {
610    ELM_CHECK_WIDTYPE(obj, widtype);
611    Widget_Data *wd = elm_widget_data_get(obj);
612
613    if (file)
614      *file = wd->file;
615    if (key)
616      *key = wd->key;
617 }
618
619 /**
620  * Get the path and key to the image or video generated by ethumb.
621  *
622  * One just need to make sure that the thumbnail was generated before getting
623  * its path; otherwise, the path will be NULL. One way to do that is by asking
624  * for the path when/after the "generate,stop" smart callback is called.
625  *
626  * @param obj The thumb object.
627  * @param file Pointer to thumb path.
628  * @param key Pointer to thumb key.
629  *
630  * @see elm_thumb_file_get()
631  *
632  * @ingroup Thumb
633  */
634 EAPI void
635 elm_thumb_path_get(const Evas_Object *obj, const char **file, const char **key)
636 {
637    ELM_CHECK_WIDTYPE(obj, widtype);
638    Widget_Data *wd = elm_widget_data_get(obj);
639
640    if (file)
641      *file = wd->thumb.file;
642    if (key)
643      *key = wd->thumb.key;
644 }
645
646 /**
647  * Set the animation state for the thumb object. If its content is an animated
648  * video, you may start/stop the animation or tell it to play continuously and
649  * looping.
650  *
651  * @param obj The thumb object.
652  * @param setting The animation setting.
653  *
654  * @see elm_thumb_file_set()
655  *
656  * @ingroup Thumb
657  */
658 EAPI void
659 elm_thumb_animate_set(Evas_Object *obj, Elm_Thumb_Animation_Setting setting)
660 {
661    ELM_CHECK_WIDTYPE(obj, widtype);
662    Widget_Data *wd = elm_widget_data_get(obj);
663
664    EINA_SAFETY_ON_TRUE_RETURN(setting >= ELM_THUMB_ANIMATION_LAST);
665
666    wd->anim_setting = setting;
667    if (setting == ELM_THUMB_ANIMATION_LOOP)
668      edje_object_signal_emit(wd->view, "animate_loop", "");
669    else if (setting == ELM_THUMB_ANIMATION_START)
670      edje_object_signal_emit(wd->view, "animate", "");
671    else if (setting == ELM_THUMB_ANIMATION_STOP)
672      edje_object_signal_emit(wd->view, "animate_stop", "");
673 }
674
675 /**
676  * Get the animation state for the thumb object.
677  *
678  * @param obj The thumb object.
679  * @return getting The animation setting or @c ELM_THUMB_ANIMATION_LAST,
680  * on errors.
681  *
682  * @see elm_thumb_file_get()
683  *
684  * @ingroup Thumb
685  */
686 EAPI Elm_Thumb_Animation_Setting
687 elm_thumb_animate_get(const Evas_Object *obj)
688 {
689    ELM_CHECK_WIDTYPE(obj, widtype) ELM_THUMB_ANIMATION_LAST;
690    Widget_Data *wd = elm_widget_data_get(obj);
691
692    return wd->anim_setting;
693 }
694
695 /**
696  * Get the ethumb_client handle so custom configuration can be made.
697  * This must be called before the objects are created to be sure no object is
698  * visible and no generation started.
699  *
700  * @return Ethumb_Client instance or NULL.
701  *
702  * Example of usage:
703  *
704  * @code
705  * #include <Elementary.h>
706  * #ifndef ELM_LIB_QUICKLAUNCH
707  * EAPI int
708  * elm_main(int argc, char **argv)
709  * {
710  *    Ethumb_Client *client;
711  *
712  *    elm_need_ethumb();
713  *
714  *    // ... your code
715  *
716  *    client = elm_thumb_ethumb_client_get();
717  *    if (!client)
718  *      {
719  *         ERR("could not get ethumb_client");
720  *         return 1;
721  *      }
722  *    ethumb_client_size_set(client, 100, 100);
723  *    ethumb_client_crop_align_set(client, 0.5, 0.5);
724  *    // ... your code
725  *
726  *    // Create elm_thumb objects here
727  *
728  *    elm_run();
729  *    elm_shutdown();
730  *    return 0;
731  * }
732  * #endif
733  * ELM_MAIN()
734  * @endcode
735  *
736  * @ingroup Thumb
737  */
738 EAPI void *
739 elm_thumb_ethumb_client_get(void)
740 {
741    return _elm_ethumb_client;
742 }
743
744 /**
745  * Get the ethumb_client connection state.
746  *
747  * @return EINA_TRUE if the client is connected to the server or
748  *         EINA_FALSE otherwise.
749  */
750 EAPI Eina_Bool
751 elm_thumb_ethumb_client_connected(void)
752 {
753    return _elm_ethumb_connected;
754 }
755
756 EAPI Eina_Bool
757 elm_thumb_editable_set(Evas_Object *obj, Eina_Bool edit)
758 {
759    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
760    Widget_Data *wd = elm_widget_data_get(obj);
761
762    if (!wd) return EINA_FALSE;
763    edit = !!edit;
764    if (wd->edit == edit) return EINA_TRUE;
765
766    wd->edit = edit;
767    if (wd->edit)
768      elm_drop_target_add(obj, ELM_SEL_FORMAT_IMAGE,
769                          _elm_thumb_dropcb, obj);
770    else
771      elm_drop_target_del(obj);
772
773    return EINA_TRUE;
774 }
775
776 EAPI Eina_Bool
777 elm_thumb_editable_get(const Evas_Object *obj)
778 {
779    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
780    Widget_Data *wd = elm_widget_data_get(obj);
781
782    if (!wd) return EINA_FALSE;
783    return wd->edit;
784 }
785
786 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-2f0^-2{2(0W1st0 :*/