d6318efe18c92d384ce317477fdc5e53903736b7
[framework/uifw/elementary.git] / src / lib / elm_icon.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3 #include "els_icon.h"
4
5 #ifdef ELM_EFREET
6 #define NON_EXISTING (void *)-1
7 static const char *icon_theme = NULL;
8 #endif
9
10 typedef struct _Widget_Data Widget_Data;
11
12 struct _Widget_Data
13 {
14    Evas_Object *img;
15    const char *stdicon;
16    Elm_Icon_Lookup_Order lookup_order;
17
18 #ifdef HAVE_ELEMENTARY_ETHUMB
19    struct {
20       int id;
21
22       struct {
23          const char *path;
24          const char *key;
25       } file, thumb;
26
27       Ethumb_Exists *exists;
28
29       Ecore_Event_Handler *eeh;
30
31       Ethumb_Thumb_Format format;
32
33       Eina_Bool retry : 1;
34    } thumb;
35 #endif
36
37 #ifdef ELM_EFREET
38    struct {
39         int requested_size;
40         Eina_Bool use : 1;
41    } freedesktop;
42 #endif
43    int in_eval;
44    Eina_Bool scale_up : 1;
45    Eina_Bool scale_down : 1;
46    Eina_Bool smooth : 1;
47    Eina_Bool fill_outside : 1;
48    Eina_Bool no_scale : 1;
49
50    /* for animation feature */
51    Ecore_Timer *timer;
52    int frame_count;
53    int cur_frame;
54    double duration;
55    Eina_Bool anim : 1;
56    Eina_Bool play : 1;
57 };
58
59 #ifdef HAVE_ELEMENTARY_ETHUMB
60 static Eina_List *_elm_icon_retry = NULL;
61 static int _icon_pending_request = 0;
62
63 static void _icon_thumb_exists(Ethumb_Client *client __UNUSED__, Ethumb_Exists *thread, Eina_Bool exists, void *data);
64 #endif
65
66 static const char *widtype = NULL;
67 static void _del_hook(Evas_Object *obj);
68 static void _theme_hook(Evas_Object *obj);
69 static void _sizing_eval(Evas_Object *obj);
70 static void _mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info);
71
72 static Eina_Bool _icon_standard_set(Widget_Data *wd, Evas_Object *obj, const char *name);
73 static Eina_Bool _icon_freedesktop_set(Widget_Data *wd, Evas_Object *obj, const char *name, int size);
74
75 static const char SIG_CLICKED[] = "clicked";
76
77 static const Evas_Smart_Cb_Description _signals[] = {
78    {SIG_CLICKED, ""},
79    {NULL, NULL}
80 };
81
82
83 //FIXME: move this code to ecore
84 #ifdef _WIN32
85 static Eina_Bool
86 _path_is_absolute(const char *path)
87 {
88    //TODO: Check if this works with all absolute paths in windows
89    return ((isalpha (*path)) && (*(path + 1) == ':') && ((*(path + 2) == '\\') || (*(path + 2) == '/')));
90 }
91 #else
92 static Eina_Bool
93 _path_is_absolute(const char *path)
94 {
95    return  (*path == '/');
96 }
97 #endif
98
99 static inline int
100 _icon_size_min_get(Evas_Object *icon)
101 {
102    int size;
103    _els_smart_icon_size_get(icon, &size, NULL);
104    return (size < 16) ? 16 : size;
105 }
106
107 #ifdef HAVE_ELEMENTARY_ETHUMB
108 static void
109 _icon_thumb_stop(Widget_Data *wd, void *ethumbd)
110 {
111    if (wd->thumb.id >= 0)
112      {
113         ethumb_client_generate_cancel(ethumbd, wd->thumb.id, NULL, NULL, NULL);
114         wd->thumb.id = -1;
115         _icon_pending_request--;
116      }
117
118    if (wd->thumb.exists)
119      {
120         ethumb_client_thumb_exists_cancel(wd->thumb.exists);
121         wd->thumb.exists = NULL;
122         _icon_pending_request--;
123      }
124
125    if (wd->thumb.retry)
126      {
127         _elm_icon_retry = eina_list_remove(_elm_icon_retry, wd);
128         wd->thumb.retry = EINA_FALSE;
129      }
130 }
131
132 static Eina_Bool
133 _icon_thumb_display(Widget_Data *wd)
134 {
135    Eina_Bool ret = EINA_FALSE;
136
137    if (wd->thumb.format == ETHUMB_THUMB_EET)
138      {
139         static const char *extensions[] = {
140           ".avi", ".mp4", ".ogv", ".mov", ".mpg", ".wmv", NULL
141         };
142         const char **ext, *ptr;
143         int prefix_size;
144         Eina_Bool video = EINA_FALSE;
145
146         prefix_size = eina_stringshare_strlen(wd->thumb.file.path) - 4;
147         if (prefix_size >= 0)
148           {
149              ptr = wd->thumb.file.path + prefix_size;
150              for (ext = extensions; *ext; ++ext)
151                if (!strcasecmp(ptr, *ext))
152                  {
153                     video = EINA_TRUE;
154                     break;
155                  }
156           }
157
158         if (video)
159           ret = _els_smart_icon_file_edje_set(wd->img, wd->thumb.thumb.path, wd->thumb.thumb.key);
160      }
161
162    if (!ret)
163      ret = _els_smart_icon_file_key_set(wd->img, wd->thumb.thumb.path, wd->thumb.thumb.key);
164
165    return ret;
166 }
167
168 static Eina_Bool
169 _icon_thumb_retry(Widget_Data *wd)
170 {
171    return _icon_thumb_display(wd);
172 }
173
174 static void
175 _icon_thumb_cleanup(Ethumb_Client *ethumbd)
176 {
177    Eina_List *l, *ll;
178    Widget_Data *wd;
179
180    EINA_LIST_FOREACH_SAFE(_elm_icon_retry, l, ll, wd)
181      if (_icon_thumb_retry(wd))
182        {
183           _elm_icon_retry = eina_list_remove_list(_elm_icon_retry, l);
184           wd->thumb.retry = EINA_FALSE;
185        }
186
187    if (_icon_pending_request == 0)
188      EINA_LIST_FREE(_elm_icon_retry, wd)
189        _icon_thumb_stop(wd, ethumbd);
190 }
191
192 static void
193 _icon_thumb_finish(Widget_Data *wd, Ethumb_Client *ethumbd)
194 {
195    const char *file = NULL, *group = NULL;
196    Eina_Bool ret;
197
198    _els_smart_icon_file_get(wd->img, &file, &group);
199    file = eina_stringshare_ref(file);
200    group = eina_stringshare_ref(group);
201
202    ret = _icon_thumb_display(wd);
203
204    if (!ret && file)
205      {
206         const char *p;
207
208         if (!wd->thumb.retry)
209           {
210              _elm_icon_retry = eina_list_append(_elm_icon_retry, wd);
211              wd->thumb.retry = EINA_TRUE;
212           }
213
214         /* Back to previous image */
215         if (((p = strrchr(file, '.'))) && (!strcasecmp(p, ".edj")))
216           _els_smart_icon_file_edje_set(wd->img, file, group);
217         else
218           _els_smart_icon_file_key_set(wd->img, file, group);
219      }
220
221    _icon_thumb_cleanup(ethumbd);
222
223    eina_stringshare_del(file);
224    eina_stringshare_del(group);
225 }
226
227 static void
228 _icon_thumb_cb(void *data,
229                Ethumb_Client *ethumbd,
230                int id,
231                const char *file __UNUSED__,
232                const char *key __UNUSED__,
233                const char *thumb_path,
234                const char *thumb_key,
235                Eina_Bool success)
236 {
237    Widget_Data *wd = data;
238
239    EINA_SAFETY_ON_FALSE_RETURN(wd->thumb.id == id);
240    wd->thumb.id = -1;
241
242    _icon_pending_request--;
243
244    if (success)
245      {
246         eina_stringshare_replace(&wd->thumb.thumb.path, thumb_path);
247         eina_stringshare_replace(&wd->thumb.thumb.key, thumb_key);
248         wd->thumb.format = ethumb_client_format_get(ethumbd);
249
250         _icon_thumb_finish(wd, ethumbd);
251      }
252    else
253      {
254         ERR("could not generate thumbnail for %s (key: %s)", file, key);
255         _icon_thumb_cleanup(ethumbd);
256      }
257 }
258
259 static void
260 _icon_thumb_exists(Ethumb_Client *client __UNUSED__, Ethumb_Exists *thread, Eina_Bool exists, void *data)
261 {
262    Widget_Data *wd = data;
263    Ethumb_Client *ethumbd;
264
265    if (ethumb_client_thumb_exists_check(thread))
266      return ;
267
268    wd->thumb.exists = NULL;
269
270    ethumbd = elm_thumb_ethumb_client_get();
271
272    if (exists)
273      {
274         const char *thumb_path, *thumb_key;
275
276         _icon_pending_request--;
277         ethumb_client_thumb_path_get(ethumbd, &thumb_path, &thumb_key);
278         eina_stringshare_replace(&wd->thumb.thumb.path, thumb_path);
279         eina_stringshare_replace(&wd->thumb.thumb.key, thumb_key);
280         wd->thumb.format = ethumb_client_format_get(ethumbd);
281
282         _icon_thumb_finish(wd, ethumbd);
283      }
284    else if ((wd->thumb.id = ethumb_client_generate(ethumbd, _icon_thumb_cb, wd, NULL)) == -1)
285      {
286         ERR("Generate was unable to start !");
287         /* Failed to generate thumbnail */
288         _icon_pending_request--;
289      }
290 }
291
292 static void
293 _icon_thumb_apply(Widget_Data *wd)
294 {
295    Ethumb_Client *ethumbd;
296
297    ethumbd = elm_thumb_ethumb_client_get();
298
299    _icon_thumb_stop(wd, ethumbd);
300
301    if (!wd->thumb.file.path) return ;
302
303    _icon_pending_request++;
304    if (!ethumb_client_file_set(ethumbd, wd->thumb.file.path, wd->thumb.file.key)) return ;
305    ethumb_client_size_set(ethumbd, _icon_size_min_get(wd->img), _icon_size_min_get(wd->img));
306    wd->thumb.exists = ethumb_client_thumb_exists(ethumbd, _icon_thumb_exists, wd);
307 }
308
309 static Eina_Bool
310 _icon_thumb_apply_cb(void *data, int type __UNUSED__, void *ev __UNUSED__)
311 {
312    Widget_Data *wd = data;
313
314    _icon_thumb_apply(wd);
315    return ECORE_CALLBACK_RENEW;
316 }
317 #endif
318
319 static void
320 _del_hook(Evas_Object *obj)
321 {
322    Widget_Data *wd = elm_widget_data_get(obj);
323 #ifdef HAVE_ELEMENTARY_ETHUMB
324    Ethumb_Client *ethumbd;
325 #endif
326
327    if (!wd) return;
328    if (wd->stdicon) eina_stringshare_del(wd->stdicon);
329
330 #ifdef HAVE_ELEMENTARY_ETHUMB
331    ethumbd = elm_thumb_ethumb_client_get();
332    _icon_thumb_stop(wd, ethumbd);
333
334    eina_stringshare_del(wd->thumb.file.path);
335    eina_stringshare_del(wd->thumb.file.key);
336    eina_stringshare_del(wd->thumb.thumb.path);
337    eina_stringshare_del(wd->thumb.thumb.key);
338
339    if (wd->thumb.eeh)
340      ecore_event_handler_del(wd->thumb.eeh);
341 #endif
342
343    if (wd->timer)
344      ecore_timer_del(wd->timer);
345    free(wd);
346 }
347
348 static void
349 _theme_hook(Evas_Object *obj)
350 {
351    Widget_Data *wd = elm_widget_data_get(obj);
352    if (!wd) return;
353    if (wd->stdicon)
354      _elm_theme_object_icon_set(obj, wd->img, wd->stdicon, elm_widget_style_get(obj));
355    _sizing_eval(obj);
356 }
357
358 static void
359 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
360 {
361    Widget_Data *wd = elm_widget_data_get(obj);
362    if (!wd) return;
363    Evas_Object *icon_edje;
364    icon_edje = _els_smart_icon_edje_get(wd->img);
365    if (!icon_edje) return;
366    edje_object_signal_emit(icon_edje, emission, source);
367 }
368
369 static void
370 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
371 {
372    Widget_Data *wd = elm_widget_data_get(obj);
373    if (!wd) return;
374    Evas_Object *icon_edje;
375    icon_edje = _els_smart_icon_edje_get(wd->img);
376    if (!icon_edje) return;
377    edje_object_signal_callback_add(icon_edje, emission, source, func_cb, data);
378 }
379
380 static void
381 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
382 {
383    Widget_Data *wd = elm_widget_data_get(obj);
384    if (!wd) return;
385    Evas_Object *icon_edje;
386    icon_edje = _els_smart_icon_edje_get(wd->img);
387    if (!icon_edje) return;
388    edje_object_signal_callback_del_full(icon_edje, emission, source, func_cb,
389                                         data);
390 }
391
392 static void
393 _sizing_eval(Evas_Object *obj)
394 {
395    Widget_Data *wd = elm_widget_data_get(obj);
396    if (!wd) return;
397    Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
398    int w, h;
399
400    wd->in_eval++;
401    _els_smart_icon_size_get(wd->img, &w, &h);
402 #ifdef ELM_EFREET
403    if (wd->freedesktop.use && wd->stdicon)
404      {
405         int size;
406         /* This icon has been set to a freedesktop icon, and the requested
407            appears to have a different size than the requested size, so try to
408            request another, higher resolution, icon.
409 FIXME: Find a better heuristic to determine if there should be
410 an icon with a different resolution. */
411         size = ((w / 16) + 1) * 16;
412         _icon_freedesktop_set(wd, obj, wd->stdicon, size);
413      }
414 #endif
415    _els_smart_icon_scale_up_set(wd->img, wd->scale_up);
416    _els_smart_icon_scale_down_set(wd->img, wd->scale_down);
417    _els_smart_icon_smooth_scale_set(wd->img, wd->smooth);
418    _els_smart_icon_fill_inside_set(wd->img, !(wd->fill_outside));
419    if (wd->no_scale) _els_smart_icon_scale_set(wd->img, 1.0);
420    else
421      {
422         _els_smart_icon_scale_set(wd->img, elm_widget_scale_get(obj) *
423                                   _elm_config->scale);
424         _els_smart_icon_size_get(wd->img, &w, &h);
425      }
426    if (!wd->scale_down)
427      {
428         minw = w;
429         minh = h;
430      }
431    if (!wd->scale_up)
432      {
433         maxw = w;
434         maxh = h;
435      }
436    evas_object_size_hint_min_set(obj, minw, minh);
437    evas_object_size_hint_max_set(obj, maxw, maxh);
438    wd->in_eval--;
439 }
440
441 static void
442 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
443 {
444    Evas_Event_Mouse_Up *ev = event_info;
445    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
446    evas_object_smart_callback_call(data, SIG_CLICKED, event_info);
447 }
448
449 static Eina_Bool
450 _elm_icon_animate_cb(void *data)
451 {
452    Widget_Data  *wd = data;
453    Evas_Object  *img_obj;
454
455    if (!wd) return ECORE_CALLBACK_CANCEL;
456    if (!wd->anim) return ECORE_CALLBACK_CANCEL;
457
458    img_obj = _els_smart_icon_object_get(wd->img);
459    wd->cur_frame++;
460    if (wd->cur_frame > wd->frame_count)
461      wd->cur_frame = wd->cur_frame % wd->frame_count;
462    evas_object_image_animated_frame_set(img_obj, wd->cur_frame);
463
464    wd->duration = evas_object_image_animated_frame_duration_get(img_obj, wd->cur_frame, 0);
465
466    if (wd->duration > 0)
467      ecore_timer_interval_set(wd->timer, wd->duration);
468    return ECORE_CALLBACK_RENEW;
469 }
470
471 static Eina_Bool
472 _icon_standard_set(Widget_Data *wd, Evas_Object *obj, const char *name)
473 {
474    if (_elm_theme_object_icon_set(obj, wd->img, name, "default"))
475      {
476 #ifdef ELM_EFREET
477         /* TODO: elm_unneed_efreet() */
478         wd->freedesktop.use = EINA_FALSE;
479 #endif
480         return EINA_TRUE;
481      }
482    return EINA_FALSE;
483 }
484
485 static Eina_Bool
486 #ifdef ELM_EFREET
487 _icon_file_set(Widget_Data *wd, Evas_Object *obj, const char *path)
488 #else
489 _icon_file_set(Widget_Data *wd __UNUSED__, Evas_Object *obj, const char *path)
490 #endif
491 {
492    if (elm_icon_file_set(obj, path, NULL))
493      {
494 #ifdef ELM_EFREET
495         /* TODO: elm_unneed_efreet() */
496         wd->freedesktop.use = EINA_FALSE;
497 #endif
498         return EINA_TRUE;
499      }
500    return EINA_FALSE;
501 }
502
503 static Eina_Bool
504 #ifdef ELM_EFREET
505 _icon_freedesktop_set(Widget_Data *wd, Evas_Object *obj, const char *name, int size)
506 #else
507 _icon_freedesktop_set(Widget_Data *wd __UNUSED__, Evas_Object *obj __UNUSED__, const char *name __UNUSED__, int size __UNUSED__)
508 #endif
509 {
510 #ifdef ELM_EFREET
511    const char *path;
512
513    elm_need_efreet();
514    if (icon_theme == NON_EXISTING) return EINA_FALSE;
515    if (!icon_theme)
516      {
517         Efreet_Icon_Theme *theme;
518         /* TODO: Listen for EFREET_EVENT_ICON_CACHE_UPDATE */
519         theme = efreet_icon_theme_find(getenv("E_ICON_THEME"));
520         if (!theme)
521           {
522              const char **itr;
523              static const char *themes[] = {
524                   "gnome", "Human", "oxygen", "hicolor", NULL
525              };
526              for (itr = themes; *itr; itr++)
527                {
528                   theme = efreet_icon_theme_find(*itr);
529                   if (theme) break;
530                }
531           }
532
533         if (!theme)
534           {
535              icon_theme = NON_EXISTING;
536              return EINA_FALSE;
537           }
538         else
539           icon_theme = eina_stringshare_add(theme->name.internal);
540      }
541    path = efreet_icon_path_find(icon_theme, name, size);
542    wd->freedesktop.use = !!path;
543    if (wd->freedesktop.use)
544      {
545         wd->freedesktop.requested_size = size;
546         elm_icon_file_set(obj, path, NULL);
547         return EINA_TRUE;
548      }
549 #endif
550    return EINA_FALSE;
551 }
552
553 static Eina_Bool
554 _elm_icon_standard_set(Widget_Data *wd, Evas_Object *obj, const char *name, Eina_Bool *fdo)
555 {
556    char *tmp;
557    Eina_Bool ret;
558
559    /* try locating the icon using the specified lookup order */
560    switch (wd->lookup_order)
561      {
562       case ELM_ICON_LOOKUP_FDO:
563          ret = _icon_freedesktop_set(wd, obj, name, _icon_size_min_get(wd->img));
564          if (ret && fdo) *fdo = EINA_TRUE;
565          break;
566       case ELM_ICON_LOOKUP_THEME:
567          ret = _icon_standard_set(wd, obj, name);
568          break;
569       case ELM_ICON_LOOKUP_THEME_FDO:
570          ret = _icon_standard_set(wd, obj, name);
571          if (!ret)
572            {
573               ret = _icon_freedesktop_set(wd, obj, name, _icon_size_min_get(wd->img));
574               if (ret && fdo) *fdo = EINA_TRUE;
575            }
576          break;
577       case ELM_ICON_LOOKUP_FDO_THEME:
578       default:
579          ret = _icon_freedesktop_set(wd, obj, name, _icon_size_min_get(wd->img));
580          if (!ret)
581            ret = _icon_standard_set(wd, obj, name);
582          else if (fdo)
583            *fdo = EINA_TRUE;
584          break;
585      }
586
587    if (ret)
588      {
589         eina_stringshare_replace(&wd->stdicon, name);
590         if (!wd->in_eval) _sizing_eval(obj);
591         return EINA_TRUE;
592      }
593
594    if (_path_is_absolute(name))
595      return _icon_file_set(wd, obj, name);
596
597    /* if that fails, see if icon name is in the format size/name. if so,
598       try locating a fallback without the size specification */
599    if (!(tmp = strchr(name, '/'))) return EINA_FALSE;
600    ++tmp;
601    if (*tmp) return elm_icon_standard_set(obj, tmp);
602    /* give up */
603    return EINA_FALSE;
604 }
605
606 static void
607 _elm_icon_standard_resize(void *data,
608                           Evas *e __UNUSED__,
609                           Evas_Object *obj,
610                           void *event_info __UNUSED__)
611 {
612    Widget_Data *wd = data;
613    const char *refup = eina_stringshare_ref(wd->stdicon);
614    Eina_Bool fdo = EINA_FALSE;
615
616    if (!_elm_icon_standard_set(wd, obj, wd->stdicon, &fdo) || (!fdo))
617      evas_object_event_callback_del_full(obj, EVAS_CALLBACK_RESIZE,
618                                          _elm_icon_standard_resize, wd);
619    eina_stringshare_del(refup);
620 }
621
622 #ifdef HAVE_ELEMENTARY_ETHUMB
623 static void
624 _elm_icon_thumb_resize(void *data,
625                        Evas *e __UNUSED__,
626                        Evas_Object *obj,
627                        void *event_info __UNUSED__)
628 {
629    Widget_Data *wd = data;
630
631    if (wd->thumb.file.path)
632      elm_icon_thumb_set(obj, wd->thumb.file.path, wd->thumb.file.key);
633 }
634 #endif
635
636 EAPI Evas_Object *
637 elm_icon_add(Evas_Object *parent)
638 {
639    Evas_Object *obj;
640    Evas *e;
641    Widget_Data *wd;
642
643    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
644
645    ELM_SET_WIDTYPE(widtype, "icon");
646    elm_widget_type_set(obj, "icon");
647    elm_widget_can_focus_set(obj, EINA_FALSE);
648    elm_widget_sub_object_add(parent, obj);
649    elm_widget_data_set(obj, wd);
650    elm_widget_del_hook_set(obj, _del_hook);
651    elm_widget_theme_hook_set(obj, _theme_hook);
652    elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
653    elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
654    elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
655
656    wd->lookup_order = ELM_ICON_LOOKUP_THEME_FDO;
657    wd->img = _els_smart_icon_add(e);
658    evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_UP,
659                                   _mouse_up, obj);
660    evas_object_repeat_events_set(wd->img, EINA_TRUE);
661    elm_widget_resize_object_set(obj, wd->img);
662
663    evas_object_smart_callbacks_descriptions_set(obj, _signals);
664
665 #ifdef HAVE_ELEMENTARY_ETHUMB
666    wd->thumb.id = -1;
667 #endif
668
669    wd->smooth = EINA_TRUE;
670    wd->scale_up = EINA_TRUE;
671    wd->scale_down = EINA_TRUE;
672
673    _sizing_eval(obj);
674    return obj;
675 }
676
677 EAPI Eina_Bool
678 elm_icon_memfile_set(Evas_Object *obj, const void *img, size_t size, const char *format, const char *key)
679 {
680    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
681    Widget_Data *wd = elm_widget_data_get(obj);
682    Eina_Bool ret;
683
684    if (!wd) return EINA_FALSE;
685    EINA_SAFETY_ON_NULL_RETURN_VAL(img, EINA_FALSE);
686    EINA_SAFETY_ON_TRUE_RETURN_VAL(!size, EINA_FALSE);
687    eina_stringshare_del(wd->stdicon);
688    wd->stdicon = NULL;
689    ret = _els_smart_icon_memfile_set(wd->img, img, size, format, key);
690    if (!wd->in_eval) _sizing_eval(obj);
691    return ret;
692 }
693
694 EAPI Eina_Bool
695 elm_icon_file_set(Evas_Object *obj, const char *file, const char *group)
696 {
697    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
698    Widget_Data *wd = elm_widget_data_get(obj);
699    Eina_Bool ret;
700    const char *tmp_file;
701    const char *tmp_group;
702
703    if (!wd) return EINA_FALSE;
704    EINA_SAFETY_ON_NULL_RETURN_VAL(file, EINA_FALSE);
705
706    _els_smart_icon_file_get(wd->img, &tmp_file, &tmp_group);
707    if ((tmp_file == file || (file && tmp_file && !strcmp(tmp_file, file)))
708        && (group == tmp_group || (group && tmp_group && !strcmp(group, tmp_group))))
709      return EINA_TRUE;
710
711 #ifdef ELM_EFREET
712    if (!wd->freedesktop.use)
713      {
714         if (wd->stdicon) eina_stringshare_del(wd->stdicon);
715         wd->stdicon = NULL;
716      }
717 #endif
718    if (eina_str_has_extension(file, ".edj"))
719      ret = _els_smart_icon_file_edje_set(wd->img, file, group);
720    else
721      ret = _els_smart_icon_file_key_set(wd->img, file, group);
722    if (!wd->in_eval) _sizing_eval(obj);
723    return ret;
724 }
725
726 EAPI void
727 elm_icon_file_get(const Evas_Object *obj, const char **file, const char **group)
728 {
729    ELM_CHECK_WIDTYPE(obj, widtype);
730    Widget_Data *wd = elm_widget_data_get(obj);
731    if (!wd) return;
732    _els_smart_icon_file_get(wd->img, file, group);
733 }
734
735 EAPI void
736 elm_icon_thumb_set(Evas_Object *obj, const char *file, const char *group)
737 {
738    ELM_CHECK_WIDTYPE(obj, widtype);
739    Widget_Data *wd = elm_widget_data_get(obj);
740    if (!wd) return;
741
742 #ifdef HAVE_ELEMENTARY_ETHUMB
743    evas_object_event_callback_del_full(obj, EVAS_CALLBACK_RESIZE,
744                                        _elm_icon_standard_resize, wd);
745    evas_object_event_callback_del_full(obj, EVAS_CALLBACK_RESIZE,
746                                        _elm_icon_thumb_resize, wd);
747
748    evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE,
749                                   _elm_icon_thumb_resize, wd);
750
751    eina_stringshare_replace(&wd->thumb.file.path, file);
752    eina_stringshare_replace(&wd->thumb.file.key, group);
753
754    if (elm_thumb_ethumb_client_connected())
755      {
756         _icon_thumb_apply(wd);
757         return ;
758      }
759
760    if (!wd->thumb.eeh)
761      {
762         wd->thumb.eeh = ecore_event_handler_add(ELM_ECORE_EVENT_ETHUMB_CONNECT, _icon_thumb_apply_cb, wd);
763      }
764 #else
765    (void) obj;
766    (void) file;
767    (void) group;
768 #endif
769 }
770
771
772 EAPI Eina_Bool
773 elm_icon_animated_available_get(const Evas_Object *obj)
774 {
775    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
776    Evas_Object *img_obj ;
777    Widget_Data *wd = elm_widget_data_get(obj);
778    if (!wd) return EINA_FALSE;
779
780    img_obj = _els_smart_icon_object_get(wd->img);
781
782    return evas_object_image_animated_get(img_obj);
783 }
784
785 EAPI void
786 elm_icon_animated_set(Evas_Object *obj, Eina_Bool anim)
787 {
788    ELM_CHECK_WIDTYPE(obj, widtype);
789    Evas_Object *img_obj ;
790    Widget_Data *wd = elm_widget_data_get(obj);
791    if (!wd) return;
792    if (wd->anim == anim) return;
793
794    img_obj = _els_smart_icon_object_get(wd->img);
795    if (!evas_object_image_animated_get(img_obj)) return;
796    if (anim)
797      {
798         wd->frame_count = evas_object_image_animated_frame_count_get(img_obj);
799         wd->cur_frame = 1;
800         wd->duration = evas_object_image_animated_frame_duration_get(img_obj, wd->cur_frame, 0);
801         evas_object_image_animated_frame_set(img_obj, wd->cur_frame);
802      }
803    else
804      {
805         wd->frame_count = -1;
806         wd->cur_frame = -1;
807         wd->duration = -1;
808      }
809    wd->anim = anim;
810    return;
811 }
812
813 EAPI Eina_Bool
814 elm_icon_animated_get(const Evas_Object *obj)
815 {
816    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
817    Widget_Data *wd = elm_widget_data_get(obj);
818    if (!wd) return EINA_FALSE;
819    return wd->anim;
820 }
821
822 EAPI void
823 elm_icon_animated_play_set(Evas_Object *obj, Eina_Bool play)
824 {
825    ELM_CHECK_WIDTYPE(obj, widtype);
826    Widget_Data *wd = elm_widget_data_get(obj);
827    if (!wd) return;
828    if (!wd->anim) return;
829    if (wd->play == play) return;
830
831    if (play)
832      {
833         wd->timer = ecore_timer_add(wd->duration, _elm_icon_animate_cb, wd);
834      }
835    else
836      {
837         if (wd->timer)
838           {
839              ecore_timer_del(wd->timer);
840              wd->timer = NULL;
841           }
842      }
843    wd->play = play;
844
845 }
846
847 EAPI Eina_Bool
848 elm_icon_animated_play_get(const Evas_Object *obj)
849 {
850    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
851    Widget_Data *wd = elm_widget_data_get(obj);
852    if (!wd) return EINA_FALSE;
853    return wd->play;
854 }
855
856 EAPI Eina_Bool
857 elm_icon_standard_set(Evas_Object *obj, const char *name)
858 {
859    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
860    Widget_Data *wd = elm_widget_data_get(obj);
861    Eina_Bool fdo = EINA_FALSE;
862    Eina_Bool ret;
863
864    if ((!wd) || (!name)) return EINA_FALSE;
865
866    evas_object_event_callback_del_full(obj, EVAS_CALLBACK_RESIZE,
867                                        _elm_icon_standard_resize, wd);
868
869    ret = _elm_icon_standard_set(wd, obj, name, &fdo);
870
871    if (fdo)
872      evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE,
873                                     _elm_icon_standard_resize, wd);
874
875    return ret;
876 }
877
878 EAPI const char *
879 elm_icon_standard_get(const Evas_Object *obj)
880 {
881    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
882    Widget_Data *wd = elm_widget_data_get(obj);
883    if (!wd) return NULL;
884    return wd->stdicon;
885 }
886
887 EAPI void
888 elm_icon_order_lookup_set(Evas_Object *obj, Elm_Icon_Lookup_Order order)
889 {
890    ELM_CHECK_WIDTYPE(obj, widtype);
891    Widget_Data *wd = elm_widget_data_get(obj);
892    if (wd) wd->lookup_order = order;
893 }
894
895 EAPI Elm_Icon_Lookup_Order
896 elm_icon_order_lookup_get(const Evas_Object *obj)
897 {
898    ELM_CHECK_WIDTYPE(obj, widtype) ELM_ICON_LOOKUP_THEME_FDO;
899    Widget_Data *wd = elm_widget_data_get(obj);
900    if (!wd) return ELM_ICON_LOOKUP_THEME_FDO;
901    return wd->lookup_order;
902 }
903
904 EAPI void
905 elm_icon_smooth_set(Evas_Object *obj, Eina_Bool smooth)
906 {
907    ELM_CHECK_WIDTYPE(obj, widtype);
908    Widget_Data *wd = elm_widget_data_get(obj);
909
910    if (!wd) return;
911    wd->smooth = smooth;
912    if (!wd->in_eval) _sizing_eval(obj);
913 }
914
915 EAPI Eina_Bool
916 elm_icon_smooth_get(const Evas_Object *obj)
917 {
918    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
919    Widget_Data *wd = elm_widget_data_get(obj);
920
921    if (!wd) return EINA_FALSE;
922    return wd->smooth;
923 }
924
925 EAPI void
926 elm_icon_no_scale_set(Evas_Object *obj, Eina_Bool no_scale)
927 {
928    ELM_CHECK_WIDTYPE(obj, widtype);
929    Widget_Data *wd = elm_widget_data_get(obj);
930
931    if (!wd) return;
932    wd->no_scale = no_scale;
933    if (!wd->in_eval) _sizing_eval(obj);
934 }
935
936 EAPI Eina_Bool
937 elm_icon_no_scale_get(const Evas_Object *obj)
938 {
939    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
940    Widget_Data *wd = elm_widget_data_get(obj);
941    if (!wd) return EINA_FALSE;
942    return wd->no_scale;
943 }
944
945 EAPI void
946 elm_icon_scale_set(Evas_Object *obj, Eina_Bool scale_up, Eina_Bool scale_down)
947 {
948    ELM_CHECK_WIDTYPE(obj, widtype);
949    Widget_Data *wd = elm_widget_data_get(obj);
950
951    if (!wd) return;
952    wd->scale_up = scale_up;
953    wd->scale_down = scale_down;
954    if (!wd->in_eval) _sizing_eval(obj);
955 }
956
957 EAPI void
958 elm_icon_scale_get(const Evas_Object *obj, Eina_Bool *scale_up, Eina_Bool *scale_down)
959 {
960    ELM_CHECK_WIDTYPE(obj, widtype);
961    Widget_Data *wd = elm_widget_data_get(obj);
962    if (!wd) return;
963    if (scale_up) *scale_up = wd->scale_up;
964    if (scale_down) *scale_down = wd->scale_down;
965 }
966
967 EAPI void
968 elm_icon_fill_outside_set(Evas_Object *obj, Eina_Bool fill_outside)
969 {
970    ELM_CHECK_WIDTYPE(obj, widtype);
971    Widget_Data *wd = elm_widget_data_get(obj);
972
973    if (!wd) return;
974    wd->fill_outside = fill_outside;
975    if (!wd->in_eval) _sizing_eval(obj);
976 }
977
978 EAPI void
979 elm_icon_size_get(const Evas_Object *obj, int *w, int *h)
980 {
981    ELM_CHECK_WIDTYPE(obj, widtype);
982    Widget_Data *wd = elm_widget_data_get(obj);
983
984    if (!wd) return;
985    _els_smart_icon_size_get(wd->img, w, h);
986 }
987
988 EAPI Eina_Bool
989 elm_icon_fill_outside_get(const Evas_Object *obj)
990 {
991    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
992    Widget_Data *wd = elm_widget_data_get(obj);
993
994    if (!wd) return EINA_FALSE;
995    return wd->fill_outside;
996 }
997
998 EAPI void
999 elm_icon_prescale_set(Evas_Object *obj, int size)
1000 {
1001    ELM_CHECK_WIDTYPE(obj, widtype);
1002    Widget_Data *wd = elm_widget_data_get(obj);
1003
1004    if (!wd) return;
1005    _els_smart_icon_scale_size_set(wd->img, size);
1006 }
1007
1008 EAPI int
1009 elm_icon_prescale_get(const Evas_Object *obj)
1010 {
1011    ELM_CHECK_WIDTYPE(obj, widtype) 0;
1012    Widget_Data *wd = elm_widget_data_get(obj);
1013
1014    if (!wd) return 0;
1015    return _els_smart_icon_scale_size_get(wd->img);
1016 }
1017
1018 EAPI Evas_Object *
1019 elm_icon_object_get(Evas_Object *obj)
1020 {
1021    ELM_CHECK_WIDTYPE(obj, widtype) 0;
1022    Widget_Data *wd = elm_widget_data_get(obj);
1023
1024    if (!wd) return NULL;
1025    return _els_smart_icon_object_get(wd->img);
1026 }
1027
1028 EAPI void
1029 elm_icon_preload_set(Evas_Object *obj, Eina_Bool disable)
1030 {
1031    ELM_CHECK_WIDTYPE(obj, widtype);
1032    Widget_Data *wd = elm_widget_data_get(obj);
1033
1034    if (!wd) return;
1035    _els_smart_icon_preload_set(wd->img, disable);
1036 }