3 typedef struct _E_Thumb E_Thumb;
12 unsigned char queued : 1;
13 unsigned char busy : 1;
14 unsigned char done : 1;
17 /* local subsystem functions */
18 static void _e_thumb_gen_begin(int objid, const char *file, const char *key, int w, int h);
19 static void _e_thumb_gen_end(int objid);
20 static void _e_thumb_del_hook(void *data, Evas *e, Evas_Object *obj, void *event_info);
21 static void _e_thumb_hash_add(int objid, Evas_Object *obj);
22 static void _e_thumb_hash_del(int objid);
23 static Evas_Object *_e_thumb_hash_find(int objid);
24 static void _e_thumb_thumbnailers_kill(void);
25 static void _e_thumb_thumbnailers_kill_cancel(void);
26 static Eina_Bool _e_thumb_cb_kill(void *data);
27 static Eina_Bool _e_thumb_cb_exe_event_del(void *data, int type, void *event);
29 /* local subsystem globals */
30 static Eina_List *_thumbnailers = NULL;
31 static Eina_List *_thumbnailers_exe = NULL;
32 static Eina_List *_thumb_queue = NULL;
33 static int _objid = 0;
34 static Eina_Hash *_thumbs = NULL;
35 static int _pending = 0;
36 static int _num_thumbnailers = 1;
37 static Ecore_Event_Handler *_exe_del_handler = NULL;
38 static Ecore_Timer *_kill_timer = NULL;
40 /* externally accessible functions */
44 _exe_del_handler = ecore_event_handler_add(ECORE_EXE_EVENT_DEL,
45 _e_thumb_cb_exe_event_del,
47 _thumbs = eina_hash_string_superfast_new(NULL);
52 e_thumb_shutdown(void)
54 _e_thumb_thumbnailers_kill_cancel();
55 _e_thumb_cb_kill(NULL);
56 if (_exe_del_handler) ecore_event_handler_del(_exe_del_handler);
57 _exe_del_handler = NULL;
58 _thumbnailers = eina_list_free(_thumbnailers);
59 E_FREE_LIST(_thumbnailers_exe, ecore_exe_free);
60 _thumb_queue = eina_list_free(_thumb_queue);
62 eina_hash_free(_thumbs);
69 _thumb_preloaded(void *data, Evas_Object *obj __UNUSED__, void *event __UNUSED__)
71 evas_object_smart_callback_call(data, "e_thumb_gen", NULL);
75 e_thumb_icon_add(Evas *evas)
80 obj = e_icon_add(evas);
81 evas_object_smart_callback_add(obj, "preloaded", _thumb_preloaded, obj);
83 eth = E_NEW(E_Thumb, 1);
87 evas_object_data_set(obj, "e_thumbdata", eth);
88 evas_object_event_callback_add(obj, EVAS_CALLBACK_FREE,
89 _e_thumb_del_hook, NULL);
90 _e_thumb_hash_add(eth->objid, obj);
95 e_thumb_icon_file_set(Evas_Object *obj, const char *file, const char *key)
99 eth = evas_object_data_get(obj, "e_thumbdata");
101 if (eth->file) eina_stringshare_del(eth->file);
103 if (eth->key) eina_stringshare_del(eth->key);
105 if (eth->sort_id) free(eth->sort_id);
107 if (file) eth->file = eina_stringshare_add(file);
108 if (key) eth->key = eina_stringshare_add(key);
112 e_thumb_icon_size_set(Evas_Object *obj, int w, int h)
116 eth = evas_object_data_get(obj, "e_thumbdata");
118 if ((w < 1) || (h <1)) return;
124 e_thumb_icon_begin(Evas_Object *obj)
129 eth = evas_object_data_get(obj, "e_thumbdata");
131 if (eth->queued) return;
132 if (eth->busy) return;
133 if (eth->done) return;
134 if (!eth->file) return;
137 while ((int) eina_list_count(_thumbnailers_exe) < _num_thumbnailers)
141 snprintf(buf, sizeof(buf), "%s/enlightenment/utils/enlightenment_thumb --nice=%d", e_prefix_lib_get(),
142 e_config->thumb_nice);
143 exe = ecore_exe_run(buf, NULL);
144 _thumbnailers_exe = eina_list_append(_thumbnailers_exe, exe);
146 _thumb_queue = eina_list_append(_thumb_queue, eth);
150 EINA_LIST_FREE(_thumb_queue, eth2)
155 if (_pending == 1) _e_thumb_thumbnailers_kill_cancel();
156 _e_thumb_gen_begin(eth2->objid, eth2->file, eth2->key, eth2->w, eth2->h);
160 if (_pending == 1) _e_thumb_thumbnailers_kill_cancel();
161 _e_thumb_gen_begin(eth->objid, eth->file, eth->key, eth->w, eth->h);
165 e_thumb_icon_end(Evas_Object *obj)
169 eth = evas_object_data_get(obj, "e_thumbdata");
173 _thumb_queue = eina_list_remove(_thumb_queue, eth);
178 _e_thumb_gen_end(eth->objid);
181 if (_pending == 0) _e_thumb_thumbnailers_kill();
186 e_thumb_icon_rethumb(Evas_Object *obj)
189 eth = evas_object_data_get(obj, "e_thumbdata");
192 if (eth->done) eth->done = 0;
193 else e_thumb_icon_end(obj);
195 e_thumb_icon_begin(obj);
198 #define A(v) (((v) >> 24) & 0xff)
199 #define R(v) (((v) >> 16) & 0xff)
200 #define G(v) (((v) >> 8 ) & 0xff)
201 #define B(v) (((v) ) & 0xff)
202 #define PIX(p, x, y) p[((y) << 2) + (x)]
203 #define PIX2(p, x, y) p[((y) << 1) + (x)]
206 _e_thumb_key_load(E_Thumb *eth, const char *icon)
211 ef = eet_open(icon, EET_FILE_MODE_READ);
213 eth->sort_id = eet_read(ef, "/thumbnail/sort_id", &size);
216 if (size > 0) eth->sort_id[size - 1] = 0;
227 e_thumb_sort_id_get(Evas_Object *obj)
230 eth = evas_object_data_get(obj, "e_thumbdata");
232 if (!eth->sort_id) return "";
237 e_thumb_client_data(Ecore_Ipc_Event_Client_Data *e)
244 if (!eina_list_data_find(_thumbnailers, e->client))
245 _thumbnailers = eina_list_prepend(_thumbnailers, e->client);
250 if ((icon) && (e->size > 1) && (icon[e->size - 1] == 0))
252 obj = _e_thumb_hash_find(objid);
255 eth = evas_object_data_get(obj, "e_thumbdata");
261 if (_pending == 0) _e_thumb_thumbnailers_kill();
262 if (ecore_file_exists(icon))
264 e_icon_preload_set(obj, 1);
265 e_icon_file_key_set(obj, icon, "/thumbnail/data");
266 _e_thumb_key_load(eth, icon);
269 evas_object_smart_callback_call(obj, "e_thumb_gen", NULL);
277 EINA_LIST_FREE(_thumb_queue, eth)
282 if (_pending == 1) _e_thumb_thumbnailers_kill_cancel();
283 _e_thumb_gen_begin(eth->objid, eth->file, eth->key, eth->w, eth->h);
289 e_thumb_client_del(Ecore_Ipc_Event_Client_Del *e)
291 if (!eina_list_data_find(_thumbnailers, e->client)) return;
292 _thumbnailers = eina_list_remove(_thumbnailers, e->client);
293 if ((!_thumbs) && (!_thumbnailers)) _objid = 0;
296 /* local subsystem functions */
298 _e_thumb_gen_begin(int objid, const char *file, const char *key, int w, int h)
302 Ecore_Ipc_Client *cli;
307 if (key) l2 = strlen(key);
308 buf = alloca(l1 + 1 + l2 + 1);
310 if (key) strcpy(buf + l1 + 1, key);
311 else buf[l1 + 1] = 0;
312 cli = eina_list_data_get(_thumbnailers);
314 _thumbnailers = eina_list_remove_list(_thumbnailers, _thumbnailers);
315 _thumbnailers = eina_list_append(_thumbnailers, cli);
316 ecore_ipc_client_send(cli, E_IPC_DOMAIN_THUMB, 1, objid, w, h, buf, l1 + 1 + l2 + 1);
320 _e_thumb_gen_end(int objid)
323 Ecore_Ipc_Client *cli;
325 /* send thumb cancel */
326 EINA_LIST_FOREACH(_thumbnailers, l, cli)
328 ecore_ipc_client_send(cli, E_IPC_DOMAIN_THUMB, 2, objid, 0, 0, NULL, 0);
333 _e_thumb_del_hook(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
337 eth = evas_object_data_get(obj, "e_thumbdata");
339 evas_object_data_del(obj, "e_thumbdata");
340 _e_thumb_hash_del(eth->objid);
343 _e_thumb_gen_end(eth->objid);
346 if (_pending == 0) _e_thumb_thumbnailers_kill();
349 _thumb_queue = eina_list_remove(_thumb_queue, eth);
350 if (eth->file) eina_stringshare_del(eth->file);
351 if (eth->key) eina_stringshare_del(eth->key);
352 if (eth->sort_id) free(eth->sort_id);
357 _e_thumb_hash_add(int objid, Evas_Object *obj)
361 snprintf(buf, sizeof(buf), "%i", objid);
362 eina_hash_add(_thumbs, buf, obj);
366 _e_thumb_hash_del(int objid)
370 snprintf(buf, sizeof(buf), "%i", objid);
371 eina_hash_del(_thumbs, buf, NULL);
372 if ((!_thumbs) && (!_thumbnailers)) _objid = 0;
376 _e_thumb_hash_find(int objid)
380 snprintf(buf, sizeof(buf), "%i", objid);
381 return eina_hash_find(_thumbs, buf);
385 _e_thumb_thumbnailers_kill(void)
387 if (_kill_timer) ecore_timer_del(_kill_timer);
388 _kill_timer = ecore_timer_add(1.0, _e_thumb_cb_kill, NULL);
392 _e_thumb_thumbnailers_kill_cancel(void)
394 if (_kill_timer) ecore_timer_del(_kill_timer);
399 _e_thumb_cb_kill(void *data __UNUSED__)
404 EINA_LIST_FOREACH(_thumbnailers_exe, l, exe)
405 ecore_exe_terminate(exe);
407 return ECORE_CALLBACK_DONE;
411 _e_thumb_cb_exe_event_del(void *data __UNUSED__, int type __UNUSED__, void *event)
413 Ecore_Exe_Event_Del *ev;
418 EINA_LIST_FOREACH(_thumbnailers_exe, l, exe)
422 _thumbnailers_exe = eina_list_remove_list(_thumbnailers_exe, l);
426 if ((!_thumbnailers_exe) && (_thumb_queue))
428 while ((int) eina_list_count(_thumbnailers_exe) < _num_thumbnailers)
433 snprintf(buf, sizeof(buf), "%s/enlightenment/utils/enlightenment_thumb --nice=%d", e_prefix_lib_get(),
434 e_config->thumb_nice);
435 exe = ecore_exe_run(buf, NULL);
436 _thumbnailers_exe = eina_list_append(_thumbnailers_exe, exe);
439 return ECORE_CALLBACK_PASS_ON;