3 //#define USE_ICON_CACHE
5 typedef struct _E_Smart_Data E_Smart_Data;
6 typedef struct _Cache_Item Cache_Item;
7 typedef struct _Cache Cache;
11 Evas_Coord x, y, w, h;
13 Evas_Object *eventarea;
16 int frame, frame_count;
18 unsigned char fill_inside : 1;
19 unsigned char scale_up : 1;
20 unsigned char preload : 1;
21 unsigned char loading : 1;
31 unsigned int timestamp;
33 Evas_Object *icon, *obj;
45 Eina_List *load_queue;
48 /* local subsystem functions */
49 static void _e_icon_smart_reconfigure(E_Smart_Data *sd);
50 static void _e_icon_smart_init(void);
51 static void _e_icon_smart_add(Evas_Object *obj);
52 static void _e_icon_smart_del(Evas_Object *obj);
53 static void _e_icon_smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y);
54 static void _e_icon_smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h);
55 static void _e_icon_smart_show(Evas_Object *obj);
56 static void _e_icon_smart_hide(Evas_Object *obj);
57 static void _e_icon_smart_color_set(Evas_Object *obj, int r, int g, int b, int a);
58 static void _e_icon_smart_clip_set(Evas_Object *obj, Evas_Object *clip);
59 static void _e_icon_smart_clip_unset(Evas_Object *obj);
60 static void _e_icon_obj_prepare(Evas_Object *obj, E_Smart_Data *sd);
61 static void _e_icon_preloaded(void *data, Evas *e, Evas_Object *obj, void *event_info);
64 static Eina_Bool _e_icon_cache_find(Evas_Object *o, const char *file);
65 static void _e_icon_cache_icon_loaded(Cache_Item *ci);
66 static void _e_icon_cache_icon_try_next(Cache_Item *ci);
67 static void _e_icon_cache_item_free(void *data);
68 static void _e_icon_obj_del(void *data, Evas *e, Evas_Object *obj, void *event_info);
71 /* local subsystem globals */
72 static Evas_Smart *_e_smart = NULL;
75 static Cache *_cache = NULL;
76 static E_Config_DD *cache_edd = NULL;
77 static E_Config_DD *cache_item_edd = NULL;
92 #define D cache_item_edd
93 D = E_CONFIG_DD_NEW("Cache_Item", T);
94 E_CONFIG_VAL(D, T, timestamp, UINT);
99 D = E_CONFIG_DD_NEW("Cache", T);
100 E_CONFIG_HASH(D, T, hash, cache_item_edd);
104 e_user_dir_concat_static(buf, "icon_cache.eet");
106 ef = eet_open(buf, EET_FILE_MODE_READ_WRITE);
107 if (!ef) return 1; /* not critical */
109 _cache = eet_data_read(ef, cache_edd, "idx");
111 _cache = E_NEW(Cache, 1);
114 _cache->hash = eina_hash_string_superfast_new(_e_icon_cache_item_free);
118 _cache->file = strdup(buf);
126 e_icon_shutdown(void)
128 #ifdef USE_ICON_CACHE
131 E_FREE(_cache->file);
134 eet_close(_cache->ef);
136 if (_cache->load_queue)
137 eina_list_free(_cache->load_queue);
139 eina_hash_free(_cache->hash);
143 E_CONFIG_DD_FREE(cache_item_edd);
144 E_CONFIG_DD_FREE(cache_edd);
150 /* externally accessible functions */
152 e_icon_add(Evas *evas)
154 _e_icon_smart_init();
155 return evas_object_smart_add(evas, _e_smart);
159 _e_icon_obj_prepare(Evas_Object *obj, E_Smart_Data *sd)
161 if (!sd->obj) return;
167 pclip = evas_object_clip_get(sd->obj);
168 evas_object_del(sd->obj);
169 #ifdef USE_ICON_CACHE
171 eina_stringshare_replace(&sd->file, NULL);
173 sd->obj = evas_object_image_add(evas_object_evas_get(obj));
174 evas_object_image_scale_hint_set(sd->obj, EVAS_IMAGE_SCALE_HINT_STATIC);
175 evas_object_smart_member_add(sd->obj, obj);
176 evas_object_event_callback_add(sd->obj, EVAS_CALLBACK_IMAGE_PRELOADED,
177 _e_icon_preloaded, obj);
178 evas_object_clip_set(sd->obj, pclip);
183 _frame_anim(void *data)
185 E_Smart_Data *sd = data;
190 fr = (sd->frame % (sd->frame_count)) + 1;
191 evas_object_image_animated_frame_set(sd->obj, fr);
192 t = evas_object_image_animated_frame_duration_get(sd->obj, fr, 0);
193 sd->timer = ecore_timer_add(t, _frame_anim, sd);
198 _handle_anim(E_Smart_Data *sd)
202 if (sd->timer) ecore_timer_del(sd->timer);
206 if (!evas_object_image_animated_get(sd->obj)) return 0;
207 // FIXME: hack around jiyouns BUG!!!!!!!!
211 snprintf(buf, sizeof(buf), "%ld", (long)sd);
212 evas_object_image_file_get(sd->obj, &file, NULL);
213 evas_object_image_file_set(sd->obj, file, buf);
215 sd->frame_count = evas_object_image_animated_frame_count_get(sd->obj);
216 if (sd->frame_count < 2) return 0;
217 evas_object_show(sd->obj);
218 t = evas_object_image_animated_frame_duration_get(sd->obj, sd->frame, 0);
219 sd->timer = ecore_timer_add(t, _frame_anim, sd);
224 e_icon_file_set(Evas_Object *obj, const char *file)
229 if (!file) return EINA_FALSE;
230 if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERR(0);
231 if (!(sd = evas_object_smart_data_get(obj)))
235 if ((len > 4) && (!strcasecmp(file + len - 4, ".edj")))
236 return e_icon_file_edje_set(obj, file, "icon");
238 /* smart code here */
239 _e_icon_obj_prepare(obj, sd);
240 /* FIXME: 64x64 - unhappy about this. use icon size */
244 eina_stringshare_del(sd->fdo);
248 if (sd->timer) ecore_timer_del(sd->timer);
252 sd->edje = EINA_FALSE;
255 evas_object_image_load_size_set(sd->obj, sd->size, sd->size);
256 if (sd->preload) evas_object_hide(sd->obj);
258 #ifdef USE_ICON_CACHE
259 if (_e_icon_cache_find(obj, file))
261 _e_icon_smart_reconfigure(sd);
266 evas_object_image_file_set(sd->obj, file, NULL);
267 if (evas_object_image_load_error_get(sd->obj) != EVAS_LOAD_ERROR_NONE)
270 if (!_handle_anim(sd))
275 evas_object_image_preload(sd->obj, EINA_FALSE);
277 else if (evas_object_visible_get(obj))
279 evas_object_show(sd->obj);
280 #ifdef USE_ICON_CACHE
281 _e_icon_cache_icon_loaded(sd->ci);
285 #ifdef USE_ICON_CACHE
288 evas_object_event_callback_del_full(sd->obj, EVAS_CALLBACK_DEL,
289 _e_icon_obj_del, obj);
290 _cache->load_queue = eina_list_remove(_cache->load_queue, sd->ci);
291 eina_stringshare_del(sd->ci->id);
297 _e_icon_smart_reconfigure(sd);
302 e_icon_file_key_set(Evas_Object *obj, const char *file, const char *key)
306 if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERR(0);
307 if (!(sd = evas_object_smart_data_get(obj)))
310 /* smart code here */
314 eina_stringshare_del(sd->fdo);
318 if (sd->timer) ecore_timer_del(sd->timer);
322 sd->edje = EINA_FALSE;
324 _e_icon_obj_prepare(obj, sd);
326 evas_object_image_load_size_set(sd->obj, sd->size, sd->size);
327 if (sd->preload) evas_object_hide(sd->obj);
328 evas_object_image_file_set(sd->obj, file, key);
329 if (evas_object_image_load_error_get(sd->obj) != EVAS_LOAD_ERROR_NONE)
331 if (!_handle_anim(sd))
336 evas_object_image_preload(sd->obj, 0);
338 else if (evas_object_visible_get(obj))
339 evas_object_show(sd->obj);
341 _e_icon_smart_reconfigure(sd);
346 e_icon_edje_object_set(Evas_Object *obj, Evas_Object *edje)
350 if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERR();
351 if (!(sd = evas_object_smart_data_get(obj))) return;
353 /* smart code here */
354 if (sd->obj) evas_object_del(sd->obj);
358 eina_stringshare_del(sd->fdo);
362 if (sd->timer) ecore_timer_del(sd->timer);
366 sd->edje = EINA_TRUE;
369 if (evas_object_visible_get(obj)) evas_object_show(sd->obj);
370 evas_object_smart_member_add(sd->obj, obj);
371 _e_icon_smart_reconfigure(sd);
375 e_icon_file_edje_set(Evas_Object *obj, const char *file, const char *part)
379 if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERR(0);
380 if (!(sd = evas_object_smart_data_get(obj)))
383 /* smart code here */
384 if (sd->obj) evas_object_del(sd->obj);
388 eina_stringshare_del(sd->fdo);
392 if (sd->timer) ecore_timer_del(sd->timer);
396 sd->edje = EINA_TRUE;
398 sd->obj = edje_object_add(evas_object_evas_get(obj));
399 edje_object_file_set(sd->obj, file, part);
400 if (edje_object_load_error_get(sd->obj) != EDJE_LOAD_ERROR_NONE)
402 if (evas_object_visible_get(obj)) evas_object_show(sd->obj);
403 evas_object_smart_member_add(sd->obj, obj);
404 _e_icon_smart_reconfigure(sd);
409 e_icon_fdo_icon_set(Evas_Object *obj, const char *icon)
415 if (!icon) return EINA_TRUE;
416 if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERR(0);
417 if (icon[0] == '/') return e_icon_file_set(obj, icon);
419 if (!(sd = evas_object_smart_data_get(obj)))
422 if (sd->timer) ecore_timer_del(sd->timer);
426 sd->edje = EINA_FALSE;
428 eina_stringshare_replace(&sd->fdo, icon);
429 if (!sd->fdo) return EINA_FALSE;
431 path = efreet_icon_path_find(e_config->icon_theme, sd->fdo, sd->size);
432 if (!path) return EINA_TRUE;
435 if ((len > 4) && (!strcasecmp(icon + len - 4, ".edj")))
436 return e_icon_file_edje_set(obj, path, "icon");
438 /* smart code here */
439 _e_icon_obj_prepare(obj, sd);
442 evas_object_image_load_size_set(sd->obj, sd->size, sd->size);
443 if (sd->preload) evas_object_hide(sd->obj);
444 evas_object_image_file_set(sd->obj, path, NULL);
445 if (evas_object_image_load_error_get(sd->obj) != EVAS_LOAD_ERROR_NONE)
450 evas_object_image_preload(sd->obj, 0);
452 else if (evas_object_visible_get(obj))
453 evas_object_show(sd->obj);
454 _e_icon_smart_reconfigure(sd);
459 e_icon_object_set(Evas_Object *obj, Evas_Object *o)
464 if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERR();
465 if (!(sd = evas_object_smart_data_get(obj))) return;
466 str = evas_object_type_get(o);
467 if ((!str) || strcmp(str, "image"))
468 CRI(EINA_COLOR_RED"******************\ntrying to set an image object of type '%s'! this is not what you want!\n******************\n"EINA_COLOR_RESET, str);
470 if (sd->timer) ecore_timer_del(sd->timer);
474 sd->edje = EINA_FALSE;
476 /* smart code here */
477 if (sd->obj) evas_object_del(sd->obj);
480 evas_object_smart_member_add(sd->obj, obj);
481 if (evas_object_visible_get(obj)) evas_object_show(sd->obj);
482 _e_icon_smart_reconfigure(sd);
486 e_icon_file_get(const Evas_Object *obj)
491 if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERR(NULL);
492 if (!(sd = evas_object_smart_data_get(obj))) return NULL;
493 #ifdef USE_ICON_CACHE
494 if (sd->file) return sd->file;
498 edje_object_file_get(sd->obj, &file, NULL);
501 evas_object_image_file_get(sd->obj, &file, NULL);
506 e_icon_smooth_scale_set(Evas_Object *obj, Eina_Bool smooth)
510 if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERRNR();
511 if (!(sd = evas_object_smart_data_get(obj))) return;
512 if (sd->edje) return;
513 evas_object_image_smooth_scale_set(sd->obj, smooth);
517 e_icon_smooth_scale_get(const Evas_Object *obj)
521 if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERR(0);
522 if (!(sd = evas_object_smart_data_get(obj))) return EINA_FALSE;
525 return evas_object_image_smooth_scale_get(sd->obj);
529 e_icon_alpha_set(Evas_Object *obj, Eina_Bool alpha)
533 if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERRNR();
534 if (!(sd = evas_object_smart_data_get(obj))) return;
535 if (sd->edje) return;
536 evas_object_image_alpha_set(sd->obj, alpha);
540 e_icon_alpha_get(const Evas_Object *obj)
544 if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERR(0);
545 if (!(sd = evas_object_smart_data_get(obj))) return EINA_FALSE;
546 if (sd->edje) return EINA_FALSE;
547 return evas_object_image_alpha_get(sd->obj);
551 e_icon_preload_set(Evas_Object *obj, Eina_Bool preload)
555 if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERRNR();
556 if (!(sd = evas_object_smart_data_get(obj))) return;
557 sd->preload = preload;
561 e_icon_preload_get(const Evas_Object *obj)
565 if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERR(0);
566 if (!(sd = evas_object_smart_data_get(obj))) return EINA_FALSE;
571 e_icon_size_get(const Evas_Object *obj, int *w, int *h)
575 if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERRNR();
576 if (!(sd = evas_object_smart_data_get(obj)))
583 edje_object_size_min_calc(sd->obj, w, h);
585 evas_object_image_size_get(sd->obj, w, h);
589 e_icon_fill_inside_get(const Evas_Object *obj)
593 if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERR(0);
594 if (!(sd = evas_object_smart_data_get(obj))) return EINA_FALSE;
595 return sd->fill_inside;
599 e_icon_fill_inside_set(Evas_Object *obj, Eina_Bool fill_inside)
603 if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERRNR();
604 if (!(sd = evas_object_smart_data_get(obj))) return;
605 fill_inside = !!fill_inside;
606 if (sd->fill_inside == fill_inside) return;
607 sd->fill_inside = fill_inside;
608 _e_icon_smart_reconfigure(sd);
612 e_icon_scale_up_get(const Evas_Object *obj)
616 if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERR(0);
617 if (!(sd = evas_object_smart_data_get(obj))) return EINA_FALSE;
622 e_icon_scale_up_set(Evas_Object *obj, Eina_Bool scale_up)
626 if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERRNR();
627 if (!(sd = evas_object_smart_data_get(obj))) return;
628 scale_up = !!scale_up;
629 if (sd->scale_up == scale_up) return;
630 sd->scale_up = scale_up;
631 _e_icon_smart_reconfigure(sd);
635 e_icon_data_set(Evas_Object *obj, void *data, int w, int h)
639 if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERRNR();
640 if (!(sd = evas_object_smart_data_get(obj))) return;
641 if (sd->edje) return;
642 evas_object_image_size_set(sd->obj, w, h);
643 evas_object_image_data_copy_set(sd->obj, data);
647 e_icon_data_get(const Evas_Object *obj, int *w, int *h)
651 if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERR(NULL);
652 if (!(sd = evas_object_smart_data_get(obj))) return NULL;
653 if (sd->edje) return NULL;
654 evas_object_image_size_get(sd->obj, w, h);
655 return evas_object_image_data_get(sd->obj, 0);
659 e_icon_scale_size_set(Evas_Object *obj, int size)
663 if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERRNR();
664 if (!(sd = evas_object_smart_data_get(obj))) return;
666 if (sd->edje) return;
667 evas_object_image_load_size_set(sd->obj, sd->size, sd->size);
671 e_icon_scale_size_get(const Evas_Object *obj)
675 if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERR(0);
676 if (!(sd = evas_object_smart_data_get(obj))) return 0;
681 e_icon_selected_set(const Evas_Object *obj, Eina_Bool selected)
685 if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERRNR();
686 if (!(sd = evas_object_smart_data_get(obj))) return;
687 if (!sd->edje) return;
689 edje_object_signal_emit(sd->obj, "e,state,selected", "e");
691 edje_object_signal_emit(sd->obj, "e,state,unselected", "e");
694 /* local subsystem globals */
696 _e_icon_smart_reconfigure(E_Smart_Data *sd)
699 Evas_Coord x, y, w, h;
701 if (!sd->obj) return;
708 evas_object_move(sd->obj, x, y);
709 evas_object_resize(sd->obj, w, h);
710 evas_object_move(sd->eventarea, x, y);
711 evas_object_resize(sd->eventarea, w, h);
717 evas_object_image_size_get(sd->obj, &iw, &ih);
724 h = ((double)ih * w) / (double)iw;
728 w = ((double)iw * h) / (double)ih;
734 h = ((double)ih * w) / (double)iw;
738 w = ((double)iw * h) / (double)ih;
743 if ((w > iw) || (h > ih))
749 x = sd->x + ((sd->w - w) / 2);
750 y = sd->y + ((sd->h - h) / 2);
751 evas_object_move(sd->obj, x, y);
752 evas_object_image_fill_set(sd->obj, 0, 0, w, h);
753 evas_object_resize(sd->obj, w, h);
754 evas_object_move(sd->eventarea, x, y);
755 evas_object_resize(sd->eventarea, w, h);
760 _e_icon_smart_init(void)
762 if (_e_smart) return;
764 static Evas_Smart_Class sc = EVAS_SMART_CLASS_INIT_NAME_VERSION("e_icon");
767 sc.add = _e_icon_smart_add;
768 sc.del = _e_icon_smart_del;
769 sc.move = _e_icon_smart_move;
770 sc.resize = _e_icon_smart_resize;
771 sc.show = _e_icon_smart_show;
772 sc.hide = _e_icon_smart_hide;
773 sc.color_set = _e_icon_smart_color_set;
774 sc.clip_set = _e_icon_smart_clip_set;
775 sc.clip_unset = _e_icon_smart_clip_unset;
777 _e_smart = evas_smart_class_new(&sc);
782 _e_icon_preloaded(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
786 if (!(sd = evas_object_smart_data_get(data))) return;
788 evas_object_smart_callback_call(data, "preloaded", NULL);
789 evas_object_show(sd->obj);
792 #ifdef USE_ICON_CACHE
793 _e_icon_cache_icon_loaded(sd->ci);
798 _e_icon_smart_add(Evas_Object *obj)
802 if (!(sd = calloc(1, sizeof(E_Smart_Data)))) return;
803 sd->eventarea = evas_object_rectangle_add(evas_object_evas_get(obj));
804 evas_object_color_set(sd->eventarea, 0, 0, 0, 0);
805 evas_object_smart_member_add(sd->eventarea, obj);
807 sd->obj = evas_object_image_add(evas_object_evas_get(obj));
808 evas_object_event_callback_add(sd->obj, EVAS_CALLBACK_IMAGE_PRELOADED,
809 _e_icon_preloaded, obj);
817 evas_object_smart_member_add(sd->obj, obj);
818 evas_object_smart_data_set(obj, sd);
822 _e_icon_smart_del(Evas_Object *obj)
826 if (!(sd = evas_object_smart_data_get(obj))) return;
827 evas_object_del(sd->obj);
828 evas_object_del(sd->eventarea);
829 if (sd->fdo) eina_stringshare_del(sd->fdo);
830 #ifdef USE_ICON_CACHE
831 if (sd->file) eina_stringshare_del(sd->file);
833 if (sd->timer) ecore_timer_del(sd->timer);
834 evas_object_smart_data_set(obj, NULL);
835 memset(sd, 0, sizeof(*sd));
840 _e_icon_smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
844 if (!(sd = evas_object_smart_data_get(obj))) return;
845 if ((sd->x == x) && (sd->y == y)) return;
848 _e_icon_smart_reconfigure(sd);
852 _e_icon_smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
856 if (!(sd = evas_object_smart_data_get(obj))) return;
857 if ((sd->w == w) && (sd->h == h)) return;
864 sd->size = MAX(w, h);
865 path = efreet_icon_path_find(e_config->icon_theme, sd->fdo, sd->size);
868 /* smart code here */
869 evas_object_image_load_size_set(sd->obj, sd->size, sd->size);
870 evas_object_image_file_set(sd->obj, path, NULL);
874 evas_object_image_preload(sd->obj, 0);
878 _e_icon_smart_reconfigure(sd);
882 _e_icon_smart_show(Evas_Object *obj)
886 if (!(sd = evas_object_smart_data_get(obj))) return;
887 if (!((sd->preload) && (sd->loading)))
889 evas_object_show(sd->obj);
890 #ifdef USE_ICON_CACHE
892 _e_icon_cache_icon_loaded(sd->ci);
896 evas_object_show(sd->eventarea);
900 _e_icon_smart_hide(Evas_Object *obj)
904 if (!(sd = evas_object_smart_data_get(obj))) return;
905 evas_object_hide(sd->obj);
906 evas_object_hide(sd->eventarea);
910 _e_icon_smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
914 if (!(sd = evas_object_smart_data_get(obj))) return;
915 evas_object_color_set(sd->obj, r, g, b, a);
919 _e_icon_smart_clip_set(Evas_Object *obj, Evas_Object *clip)
923 if (!(sd = evas_object_smart_data_get(obj))) return;
924 evas_object_clip_set(sd->obj, clip);
925 evas_object_clip_set(sd->eventarea, clip);
929 _e_icon_smart_clip_unset(Evas_Object *obj)
933 if (!(sd = evas_object_smart_data_get(obj))) return;
934 evas_object_clip_unset(sd->obj);
935 evas_object_clip_unset(sd->eventarea);
938 #ifdef USE_ICON_CACHE
941 _e_icon_cache_item_free(void *data)
943 Cache_Item *ci = data;
944 eina_stringshare_del(ci->id);
949 _e_icon_cache_save(void *data)
951 if (_cache->load_queue)
956 /* EINA_LIST_FOREACH(_cache->load_queue, l, ci)
957 * printf(" : %s\n", ci->id); */
959 return ECORE_CALLBACK_RENEW;
962 eet_sync(_cache->ef);
963 eet_close(_cache->ef);
966 _cache->timer = NULL;
968 return ECORE_CALLBACK_CANCEL;
972 _e_icon_cache_find(Evas_Object *obj, const char *file)
980 if (!_cache) return EINA_FALSE;
982 if (!(sd = evas_object_smart_data_get(obj)))
985 snprintf(buf, sizeof(buf), "%d:%s", sd->size, file);
987 if ((ci = eina_hash_find(_cache->hash, buf)))
989 unsigned int w, h, alpha;
994 _cache->ef = eet_open(_cache->file, EET_FILE_MODE_READ_WRITE);
996 if (_cache->ef && (data = eet_data_image_read(_cache->ef, buf,
1000 evas_object_image_size_set(sd->obj, w, h);
1001 evas_object_image_alpha_set(sd->obj, alpha);
1002 evas_object_image_data_copy_set(sd->obj, data);
1003 evas_object_smart_callback_call(obj, "preloaded", NULL);
1004 evas_object_show(sd->obj);
1009 if ((_cache->ef) && !(_cache->timer))
1010 _cache->timer = ecore_timer_add(3.0, _e_icon_cache_save, NULL);
1015 eina_hash_del_by_key(_cache->hash, ci->id);
1019 id = eina_stringshare_add(buf);
1021 /* not found in cache, check load queue */
1022 EINA_LIST_FOREACH(_cache->load_queue, l, ci)
1024 if (ci->id != id) continue;
1025 ci->objs = eina_list_append(ci->objs, obj);
1027 evas_object_event_callback_add(sd->obj, EVAS_CALLBACK_DEL,
1028 _e_icon_obj_del, obj);
1029 eina_stringshare_del(id);
1033 ci = E_NEW(Cache_Item, 1);
1038 sd->file = eina_stringshare_add(file);
1040 evas_object_event_callback_add(sd->obj, EVAS_CALLBACK_DEL, _e_icon_obj_del, obj);
1042 _cache->load_queue = eina_list_append(_cache->load_queue, ci);
1048 _e_icon_cache_icon_try_next(Cache_Item *ci)
1055 /* no more e_icon wait for this object to bet loaded */
1056 _cache->load_queue = eina_list_remove(_cache->load_queue, ci);
1057 _e_icon_cache_item_free(ci);
1061 obj = eina_list_data_get(ci->objs);
1062 ci->objs = eina_list_remove_list(ci->objs, ci->objs);
1067 if (!(sd = evas_object_smart_data_get(obj)))
1070 evas_object_image_file_set(sd->obj, sd->file, NULL);
1071 if (evas_object_image_load_error_get(sd->obj) != EVAS_LOAD_ERROR_NONE)
1074 sd->ci->icon = sd->obj;
1076 evas_object_image_preload(sd->obj, EINA_FALSE);
1080 evas_object_event_callback_del_full(sd->obj, EVAS_CALLBACK_DEL,
1081 _e_icon_obj_del, obj);
1082 _e_icon_cache_icon_try_next(ci);
1086 _e_icon_obj_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1090 if (!(sd = evas_object_smart_data_get(data))) return;
1091 if (!sd->ci) return;
1093 /* check if the deleted object is the one that is used for
1094 preloading. when other objs wait for this image data start
1095 preloading again with the next. */
1097 if (sd->ci->icon == obj)
1099 _e_icon_cache_icon_try_next(sd->ci);
1104 sd->ci->objs = eina_list_remove(sd->ci->objs, data);
1110 _e_icon_cache_icon_loaded(Cache_Item *ci)
1117 if (!_cache) return;
1119 if (!ci || !ci->id) return;
1120 _cache->load_queue = eina_list_remove(_cache->load_queue, ci);
1122 data = evas_object_image_data_get(ci->icon, EINA_FALSE);
1123 evas_object_image_size_get(ci->icon, &w, &h);
1124 alpha = evas_object_image_alpha_get(ci->icon);
1126 evas_object_event_callback_del_full(ci->icon, EVAS_CALLBACK_DEL,
1127 _e_icon_obj_del, ci->obj);
1128 evas_object_smart_callback_call(ci->obj, "preloaded", NULL);
1130 DBG("icon loaded %p, %s\n", data, ci->id);
1132 sd = evas_object_smart_data_get(ci->obj);
1135 /* pass loaded data to other e_icon wating for this */
1136 EINA_LIST_FREE(ci->objs, obj)
1138 sd = evas_object_smart_data_get(obj);
1140 evas_object_event_callback_del_full(sd->obj, EVAS_CALLBACK_DEL,
1141 _e_icon_obj_del, obj);
1142 if (!data) continue;
1144 evas_object_image_size_set(sd->obj, w, h);
1145 evas_object_image_alpha_set(sd->obj, alpha);
1146 evas_object_image_data_copy_set(sd->obj, data);
1147 evas_object_show(sd->obj);
1148 evas_object_smart_callback_call(obj, "preloaded", NULL);
1154 _cache->ef = eet_open(_cache->file, EET_FILE_MODE_READ_WRITE);
1155 if (_cache->ef && eet_data_image_write(_cache->ef, ci->id, data,
1156 w, h, alpha, 1, 100, 0))
1158 eina_hash_add(_cache->hash, ci->id, ci);
1159 eet_data_write(_cache->ef, cache_edd, "idx", _cache, 1);
1162 _cache->timer = ecore_timer_add(3.0, _e_icon_cache_save, NULL);
1164 eina_stringshare_replace(&ci->id, NULL);
1169 DBG("couldnt write cache %p !!!\n", _cache->ef);
1170 _e_icon_cache_item_free(ci);