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