Fix N_SE-2274:Icon size are different
[apps/home/taskmanager.git] / src / _genlist.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  * 
4  * Licensed under the Flora License, Version 1.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  * 
8  *     http://www.tizenopensource.org/license
9  * 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17
18
19
20 #include <stdio.h>
21 #include <unistd.h>
22 #include <appcore-efl.h>
23 #include <vconf.h>
24 #include <utilX.h>
25 #include <aul.h>
26 #include <Ecore_X.h>
27 #include <Eina.h>
28 #include <unistd.h>
29 #include <time.h>
30 #include <sys/time.h>
31 #include <pthread.h>
32
33 #include "taskmanager.h"
34 #include "_genlist.h"
35 #include "_util_log.h"
36 #include "_util_efl.h"
37 #include "_logic.h"
38 #include "_cpu.h"
39 #include "_eina.h"
40 #include "_info.h"
41 #include "_progressbar.h"
42
43 pthread_t pt;
44 pthread_cond_t  pc;
45 pthread_mutex_t pm;
46 pthread_mutex_t mutex_for_graph_update = PTHREAD_MUTEX_INITIALIZER;
47 static Elm_Object_Item *g_egi;
48
49 /* group list:gl, data list:dl, button list:bl, no list: nl */
50 static Elm_Genlist_Item_Class itc_gl;
51 static Elm_Genlist_Item_Class itc_hl;
52 static Elm_Genlist_Item_Class itc_dl;
53 static Elm_Genlist_Item_Class itc_bl;
54 static Elm_Genlist_Item_Class itc_nl;
55 static Elm_Genlist_Item_Class itc_separator4;
56 static Elm_Genlist_Item_Class itc_separator2;
57
58 static char *button_text[TS_MAX] = {
59         "IDS_TASKMGR_BUTTON_CLOSE_ALL_APPLICATIONS",
60         "IDS_TASKMGR_BUTTON_CLEAR_HISTORY_ABB"
61 };
62
63 static void end_all_inuse_cb(void *data, Evas_Object *obj, void *event_info);
64 static void delete_all_history_cb(void *data, Evas_Object *obj,
65                                   void *event_info);
66 void (*func_del[TS_MAX]) (void *data, Evas_Object *obj, void *event_info) = {
67 &end_all_inuse_cb, &delete_all_history_cb};
68
69 static void end_inuse_cb(void *data, Evas_Object *obj, void *event_info);
70 static void delete_history_cb(void *data, Evas_Object *obj, void *event_info);
71 void (*func_end[TS_MAX]) (void *data, Evas_Object *obj, void *event_info) = {
72 &end_inuse_cb, &delete_history_cb};
73
74 static char *group_name[TS_MAX] = {
75         "IDS_TASKMGR_HEADER_RUNNING",
76         "IDS_TASKMGR_MBODY_RECENTLY_USED"
77 };
78
79 static char *nolist_text[TS_MAX] = {
80         "IDS_TASKMGR_MBODY_NO_APPS_OPEN",
81         "IDS_TASKMGR_MBODY_NO_RECENTLY_USED_APPS"
82 };
83
84 void taskmanager_free_info(struct _task_info *info);
85 Eina_Bool _update_list(void *data);
86
87 static void clear_genlist(void *data)
88 {
89         ret_if(data == NULL);
90
91         struct appdata *ad = data;
92
93         if (ad->gl) {
94                 elm_genlist_clear(ad->gl);
95         }
96 }
97
98 void clear_task_manager_list(void *data)
99 {
100         ret_if(data == NULL);
101
102         struct appdata *ad = data;
103         _free_einalist_all(ad);
104         clear_genlist(ad);
105 }
106
107 static void app_genlist_item_update(void *data)
108 {
109         ret_if(data == NULL);
110
111         struct appdata *ad = (struct appdata *)data;
112
113         Elm_Object_Item *it_r;
114         Eina_List *realized_item_list, *l_r;
115         unsigned int cnt = 0;
116
117         realized_item_list = elm_genlist_realized_items_get(ad->gl);
118         cnt = eina_list_count(realized_item_list);
119         if (cnt > 0) {
120                 EINA_LIST_FOREACH(realized_item_list, l_r, it_r) {
121                         if (it_r != NULL) {
122                                 elm_genlist_item_update(it_r);
123                         }
124                 }
125         }
126 }
127
128 Eina_Bool alert_app_info(void *data)
129 {
130         retv_if(data == NULL, -1);
131
132         struct appdata *ad = (struct appdata *)data;
133
134         app_genlist_item_update(ad);
135         return ECORE_CALLBACK_CANCEL;
136 }
137
138 static void end_all_inuse_cb(void *data, Evas_Object *obj, void *event_info)
139 {
140         ret_if(data == NULL);
141
142         struct appdata *ad = data;
143         char buf[_BUF_MAX] = { 0, };
144
145         ad->mode = MODE_END_ALL_INUSE;
146         snprintf(buf, sizeof(buf), T_("IDS_TASKMGR_POP_CLOSE_ALL_APPS_Q_THIS_MAY_CAUSE_DATA_TO_BE_LOST"));
147         if (ad->popup_ask) {
148                 evas_object_del(ad->popup_ask);
149                 ad->popup_ask = NULL;
150         }
151         ad->popup_ask = _add_popup_ask(ad->win, buf, ad);
152 }
153
154 static void
155 delete_all_history_cb(void *data, Evas_Object *obj, void *event_info)
156 {
157 _D("func\n");
158         ret_if(data == NULL);
159
160         struct appdata *ad = data;
161         char buf[_BUF_MAX] = { 0, };
162
163 //      refresh_app_info(ad);
164
165         ad->mode = MODE_DEL_ALL_HISTORY;
166         snprintf(buf, sizeof(buf), T_("IDS_TASKMGR_POP_CLEAR_ALL_APP_HISTORY_Q"));
167         if (ad->popup_ask) {
168                 evas_object_del(ad->popup_ask);
169                 ad->popup_ask = NULL;
170         }
171         ad->popup_ask = _add_popup_ask(ad->win, buf, ad);
172 }
173
174 static void end_inuse_cb(void *data, Evas_Object *obj, void *event_info)
175 {
176         ret_if(data == NULL);
177
178         struct _task_info *info_ev = (struct _task_info *)data;
179         struct appdata *ad = info_ev->ad;
180         char buf[_BUF_MAX] = { 0, };
181
182         ad->mode = MODE_END_INUSE;
183         snprintf(buf, _BUF_MAX, T_("IDS_TASKMGR_POP_CLOSE_PS_APP_Q_THIS_MAY_CAUSE_DATA_TO_BE_LOST"), info_ev->app_name);
184         if (ad->popup_ask) {
185                 evas_object_del(ad->popup_ask);
186                 ad->popup_ask = NULL;
187         }
188         ad->popup_ask = _add_popup_ask(ad->win, buf, ad);
189         g_egi = (void *)info_ev->it;
190 //      evas_object_data_set(ad->popup_ask, "selected_egi", (void *)info_ev->it);
191 }
192
193 static void delete_history_cb(void *data, Evas_Object *obj, void *event_info)
194 {
195         ret_if(data == NULL);
196
197         struct _task_info *info_ev = (struct _task_info *)data;
198         struct appdata *ad = info_ev->ad;
199         char buf[_BUF_MAX] = { 0, };
200
201         ad->mode = MODE_DEL_HISTORY;
202
203         snprintf(buf, _BUF_MAX, T_("IDS_TASKMGR_POP_CLEAR_PS_HISTORY_Q"), info_ev->app_name);
204         if (ad->popup_ask) {
205                 evas_object_del(ad->popup_ask);
206                 ad->popup_ask = NULL;
207         }
208         ad->popup_ask = _add_popup_ask(ad->win, buf, ad);
209         g_egi = (void *)info_ev->it;
210 //      evas_object_data_set(ad->popup_ask, "selected_egi", (void *)info_ev->it);
211 }
212
213 static void nl_sel(void *data, Evas_Object *obj, void *event_info)
214 {
215 _D("func\n");
216         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
217         elm_genlist_item_selected_set(item, EINA_FALSE);
218         return;
219 }
220
221 static char *nl_text_get(void *data, Evas_Object *obj, const char *part)
222 {
223         char buf[_BUF_MAX] = { 0, };
224
225         if (!strcmp(part, "elm.text")) {
226                 snprintf(buf, sizeof(buf), "%s", T_(nolist_text[(int)data]));
227
228                 return strdup(buf);
229         }
230         return NULL;
231 }
232
233 static void _gl_sel_app(void *data, Evas_Object *obj, void *event_info)
234 {
235 _D("func\n");
236         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
237         struct appdata *ad = (struct appdata *)data;
238         struct _task_info *info;
239         /* parameter to block double click */
240         static int selected = 0;
241         Elm_Object_Item *it = (Elm_Object_Item *) event_info;
242
243         elm_genlist_item_selected_set(it, EINA_FALSE);
244
245         retm_if(ad == NULL, "Invalid argument: appdata is NULL\n");
246
247         _fini_pthread();
248         if (ad->update_timer) {
249                 ecore_timer_del(ad->update_timer);
250                 ad->update_timer = NULL;
251         }
252
253         if (selected == 1)
254                 return;
255         selected = 1;
256
257         if (item == NULL) {
258                 _E("[Error] Cannot find genlist item\n");
259                 selected = 0;
260                 return;
261         }
262
263         info = (struct _task_info *)elm_object_item_data_get(item);
264         if (info == NULL) {
265                 _E("[Error] Cannot get item data: info\n");
266                 selected = 0;
267                 return;
268         }
269
270         if (info->pid) {
271                 /* when application is alive */
272                 aul_resume_pid(info->pid);
273                 selected = 0;
274         } else {
275                 /* when application is dead */
276                 if (info->pkg_name == NULL) {
277                         util_show_popup_with_message(info->ad->win,
278                                         3.0,
279                                         T_("IDS_TASKMGR_POP_UNABLE_TO_OPEN_APPLICATION"));
280                         selected = 0;
281
282                 } else {
283                         _unset_notification_level(info->ad->win);
284
285                         if (!strcmp(info->pkg_name, "org.tizen.phone")) {
286                                 /* exception : Because dialer doesn't need bundle
287                                  * since being unifyed dialer, voice call and video call
288                                  */
289                                 aul_launch_app(info->pkg_name, NULL);
290                                 selected = 0;
291                         } else {
292                                 aul_launch_app(info->pkg_name, info->b);
293                                 selected = 0;
294                         }
295                 }
296         }
297 }
298
299 static Evas_Object *_gl_content_get_app(void *data, Evas_Object *obj,
300                                      const char *part)
301 {
302         struct _task_info *info = (struct _task_info *)data;
303         char buf[_BUF_MAX] = { 0, };
304
305         Evas_Object *icon = NULL;
306         Evas_Object *btn = NULL;
307
308         Evas_Object *rt, *icon_ly = NULL;
309
310         retvm_if(data == NULL, NULL, "Invalid argument: task info is NULL\n");
311
312         if (!strcmp(part, "elm.icon.1")) {
313                 snprintf(buf, sizeof(buf), "%s", info->icn_path);
314                 retvm_if(buf == NULL, NULL, "%s icon is NULL\n", info->app_name);
315                 if (!ecore_file_exists(buf) || strlen(buf) < 4)
316                         snprintf((char *)buf, (size_t) sizeof(buf),
317                                  (const char *)IMAGEDIR "/icon_taskmgr.png");
318
319                 if (!strncmp(&buf[strlen(buf) - 3], "edj", 3)) {
320                         icon_ly = _add_layout(obj, buf, "icon");
321
322                 } else {
323                         icon_ly = elm_icon_add(obj);
324                         elm_icon_file_set(icon_ly, buf, NULL);
325                 }
326
327                 icon = _add_layout(obj, EDJ_NAME, "icon");
328                 retvm_if(icon == NULL, NULL, "Cannot add layout: icon\n");
329
330                 rt = evas_object_rectangle_add(evas_object_evas_get(obj));
331                 retvm_if(rt == NULL, NULL, "Failed to add rectangle\n");
332
333                 evas_object_color_set(rt, 0, 0, 0, 0);
334                 evas_object_size_hint_min_set(rt, 50, 50);
335 //              evas_object_size_hint_min_set(rt, (int)(50.0 * scale),
336 //                                            (int)(50.0 * scale));
337 //              evas_object_size_hint_max_set(rt, (int)(50.0 * scale),
338 //                                            (int)(50.0 * scale));
339                 elm_object_part_content_set(icon, "icon_ly", rt);
340
341                 elm_object_part_content_set(icon, "icon", icon_ly);
342
343                 return icon;
344
345         } else if (!strcmp(part, "elm.icon.2")) {
346                 btn = elm_button_add(obj);
347                 elm_object_text_set(btn, S_("IDS_COM_BODY_END"));
348                 elm_object_style_set(btn, "default");
349
350                 evas_object_smart_callback_add(btn, "clicked",
351                                                func_end[info->category], info);
352                 elm_object_focus_set(btn, EINA_FALSE);
353
354 //              evas_object_size_hint_min_set(btn, (int)(90.0 * scale),
355 //                                            (int)(47.0 * scale));
356 //              evas_object_size_hint_max_set(btn, (int)(90.0 * scale),
357 //                                            (int)(47.0 * scale));
358
359                 evas_object_propagate_events_set(btn, EINA_FALSE);
360
361                 return btn;
362         }
363
364         return NULL;
365 }
366
367 static char *_gl_text_get_app(void *data, Evas_Object *obj, const char *part)
368 {
369         struct _task_info *info = (struct _task_info *)data;
370         char buf[_BUF_MAX] = { 0, };
371         Evas_Object *eo;
372
373         retvm_if(data == NULL, NULL, "Invalid argument: task info is NULL\n");
374         retvm_if(part == NULL, NULL, "Invalid argument: part is NULL\n");
375
376         if (!strcmp(part, "elm.text.1")) {
377                 snprintf(buf, _BUF_MAX, "%s", info->app_name);
378                 return strdup(buf);
379
380         } else if (!strcmp(part, "elm.text.2")) {
381                 if (info->category == TS_INUSE) {
382                         snprintf(buf, _BUF_MAX, "CPU: %.1f%%", info->cpu);
383                         return strdup(buf);
384
385                 } else {
386                         if (info->it) {
387                                 elm_object_signal_emit(info->it, "prog.hide.mem","taskmanager");
388                         }
389                         return NULL;
390                 }
391         }
392         return NULL;
393 }
394
395 static void _bl_sel(void *data, Evas_Object *obj, void *event_info)
396 {
397 _D("func\n");
398         int mode = (int)data;
399         struct appdata *ad;
400         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
401
402         elm_genlist_item_selected_set(item, EINA_FALSE);
403 }
404
405 static char *_bl_text_get(void *data, Evas_Object *obj, const char *part)
406 {
407         if (!strcmp(part, "elm.text")) {
408                 return strdup(T_(button_text[(int)data]));
409
410         }
411         return NULL;
412 }
413
414 static Evas_Object *_bl_content_get(void *data, Evas_Object *obj,
415                                 const char *part)
416 {
417         Evas_Object *btn = NULL;
418         struct appdata *ad = evas_object_data_get(obj, "appdata");
419
420         if (!strcmp(part, "elm.icon")) {
421
422                 btn = elm_button_add(obj);
423                 elm_object_style_set(btn, "default");
424
425                 elm_object_text_set(btn, T_(button_text[(int)data]));
426                 evas_object_smart_callback_add(btn, "clicked",
427                                                func_del[(int)data], ad);
428                 elm_object_focus_set(btn, EINA_FALSE);
429
430                 evas_object_size_hint_min_set(btn, 0, 50);
431                 evas_object_size_hint_max_set(btn, 0, 50);
432 //              evas_object_size_hint_min_set(btn, 0, (int)(47.0 * scale));
433 //              evas_object_size_hint_max_set(btn, 0, (int)(47.0 * scale));
434
435                 evas_object_propagate_events_set(btn, EINA_FALSE);
436
437                 return btn;
438
439         }
440         return NULL;
441 }
442
443 static char *_gl_text_get_title(void *data, Evas_Object *obj, const char *part)
444 {
445         char buf[_BUF_MAX];
446
447         if (!strcmp(part, "elm.text")) {
448                 snprintf(buf, sizeof(buf), "%s (%d)",
449                                 T_(group_name[(int)data]), _get_grp_cnt((int)data));
450                 return strdup(buf);
451         }
452         return NULL;
453 }
454
455 static char *_gl_text_get_his(void *data, Evas_Object *obj, const char *part)
456 {
457         struct _task_info *info = (struct _task_info *)data;
458         char buf[_BUF_MAX] = { 0, };
459         Evas_Object *eo;
460
461         if (!strcmp(part, "elm.text")) {
462                 snprintf(buf, _BUF_MAX, "%s", info->app_name);
463                 return strdup(buf);
464         }
465         return NULL;
466 }
467
468 static Evas_Object *_gl_content_get_his(void *data, Evas_Object *obj,
469                                      const char *part)
470 {
471         struct _task_info *info = (struct _task_info *)data;
472         char buf[_BUF_MAX] = { 0, };
473
474         Evas_Object *icon = NULL;
475         Evas_Object *btn = NULL;
476
477         Evas_Object *rt, *icon_ly = NULL;
478         retvm_if(data == NULL, NULL, "Invalid argument: task info is NULL\n");
479
480         if (!strcmp(part, "elm.icon.1")) {
481                 snprintf(buf, sizeof(buf), "%s", info->icn_path);
482                 retvm_if(buf == NULL, NULL, "%s icon is NULL\n", info->app_name);
483                 if (!ecore_file_exists(buf) || strlen(buf) < 4)
484                         snprintf((char *)buf, (size_t) sizeof(buf),
485                                  (const char *)IMAGEDIR "/icon_taskmgr.png");
486
487                 if (!strncmp(&buf[strlen(buf) - 3], "edj", 3)) {
488                         icon_ly = _add_layout(obj, buf, "icon");
489
490                 } else {
491                         icon_ly = elm_icon_add(obj);
492                         elm_icon_file_set(icon_ly, buf, NULL);
493                 }
494
495                 icon = _add_layout(obj, EDJ_NAME, "icon");
496                 retvm_if (icon == NULL, NULL, "Cannot add layout: icon\n");
497
498                 rt = evas_object_rectangle_add(evas_object_evas_get(obj));
499                 retvm_if (rt == NULL, NULL, "Failed to add rectangle\n");
500
501                 evas_object_color_set(rt, 0, 0, 0, 0);
502                 evas_object_size_hint_min_set(rt, 50, 50);
503 //              evas_object_size_hint_min_set(rt, (int)(50.0 * scale),
504 //                                            (int)(50.0 * scale));
505 //              evas_object_size_hint_max_set(rt, (int)(50.0 * scale),
506 //                                            (int)(50.0 * scale));
507                 elm_object_part_content_set(icon, "icon_ly", rt);
508
509                 elm_object_part_content_set(icon, "icon", icon_ly);
510
511                 return icon;
512
513         } else if (!strcmp(part, "elm.icon.2")) {
514                 btn = elm_button_add(obj);
515                 elm_object_text_set(btn, S_("IDS_COM_OPT_DELETE"));
516                 elm_object_style_set(btn, "default");
517
518                 evas_object_smart_callback_add(btn, "clicked",
519                                                func_end[info->category], info);
520                 elm_object_focus_set(btn, EINA_FALSE);
521
522         //      evas_object_size_hint_min_set(btn, (int)(90.0 * scale),
523         //                                    (int)(47.0 * scale));
524         //      evas_object_size_hint_max_set(btn, (int)(90.0 * scale),
525         //                                    (int)(47.0 * scale));
526
527                 evas_object_propagate_events_set(btn, EINA_FALSE);
528
529                 return btn;
530         }
531
532         return NULL;
533
534 }
535
536 void _set_itc(void)
537 {
538         itc_gl.item_style = "grouptitle";
539         itc_gl.func.text_get = _gl_text_get_title;
540
541         itc_dl.item_style = "2text.2icon.7";
542         itc_dl.func.text_get = _gl_text_get_app;
543         itc_dl.func.content_get = _gl_content_get_app;
544
545         itc_hl.item_style = "1text.2icon.4";
546         itc_hl.func.text_get = _gl_text_get_his;
547         itc_hl.func.content_get = _gl_content_get_his;
548
549         itc_separator4.item_style = "dialogue/seperator.4";
550         itc_separator2.item_style = "dialogue/seperator.2";
551
552         itc_bl.item_style = "dialogue/bg/1icon";
553 //      itc_bl.item_style = "1icon";
554         itc_bl.func.content_get = _bl_content_get;
555
556         itc_nl.item_style = "1text";
557         itc_nl.func.text_get = nl_text_get;
558
559 }
560
561 int check_genlist(struct appdata *ad)
562 {
563         Elm_Object_Item *egi;
564         struct _task_info *info;
565         int i = 1;
566
567         egi = elm_genlist_first_item_get(ad->gl);
568         while(egi) {
569                 info = (struct _task_info *)elm_object_item_data_get(egi);
570                 if(info) {
571                         _D("%s info[0x%x]\n", (int)info < 3 ? "-" : info->app_name, info);
572                 } else {
573                         _D("group\n");
574                 }
575                 egi = elm_genlist_item_next_get(egi);
576         }
577
578         return 0;
579 }
580
581 int _set_genlist_from_eina(struct appdata *ad)
582 {
583 _D("func\n");
584         Eina_List *l;
585         Elm_Object_Item *git, *item;
586         struct _task_info *info;
587         int i;
588
589         retvm_if(ad == NULL, -1, "Invalid argument: appdata is NULL\n");
590         retvm_if(ad->gl == NULL, -1, "Invalid argument:genlist is NULL\n");
591
592         for (i = 0; i < TS_MAX; i++) {
593                 git = elm_genlist_item_append(ad->gl, &itc_gl,
594                                                  (void *)i, NULL,
595                                                  ELM_GENLIST_ITEM_NONE,
596                                               NULL, NULL);
597                 retvm_if(git == NULL, -1, "Failed append item\n");
598                 elm_genlist_item_select_mode_set(git, EINA_TRUE);
599
600                 if (eina_list_count(ad->applist[i]) > 0) {
601
602                         item = elm_genlist_item_append(ad->gl, &itc_separator4,
603                                                 NULL, git,
604                                                 ELM_GENLIST_ITEM_NONE,
605                                                 NULL, NULL);
606                         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
607
608
609                         item = elm_genlist_item_append(ad->gl, &itc_bl,
610                                                 (void *)i, git,
611                                                 ELM_GENLIST_ITEM_NONE,
612                                                 _bl_sel, (void *)i);
613
614                         item = elm_genlist_item_append(ad->gl, &itc_separator2,
615                                                 NULL, git,
616                                                 ELM_GENLIST_ITEM_NONE,
617                                                 NULL, NULL);
618                         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
619
620                         ad->applist[i] = eina_list_nth_list(ad->applist[i], 0);
621                         EINA_LIST_FOREACH(ad->applist[i], l, info) {
622                                 if (info != NULL) {
623                                         info->it = elm_genlist_item_append(ad->gl,
624                                                                     (i == TS_INUSE) ? &itc_dl : &itc_hl,
625                                                                     (void *)info, git,
626                                                                     ELM_GENLIST_ITEM_NONE,
627                                                                     _gl_sel_app, ad);
628                                 }
629                         }
630                 } else {
631                         item = elm_genlist_item_append(ad->gl, &itc_nl,
632                                                 (void *)i, git,
633                                                 ELM_GENLIST_ITEM_NONE,
634                                                 nl_sel, NULL);
635                         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
636                 }
637         }
638         return 0;
639 }
640
641 Eina_Bool _update_list(void *data)
642 {
643 _D("func\n");
644         struct appdata *ad = data;
645         Eina_List *l, *l_next;
646         struct _task_info *info;
647
648         pthread_mutex_lock(&mutex_for_graph_update);
649
650         if(ad->applist[TS_INUSE] == NULL) {
651                 _D("inuse is NULL\n");
652                 return ECORE_CALLBACK_CANCEL;
653         }
654         ad->applist[TS_INUSE] = eina_list_nth_list(ad->applist[TS_INUSE], 0);
655         _D("%d\n", eina_list_count(ad->applist[TS_INUSE]));
656
657         EINA_LIST_FOREACH_SAFE(ad->applist[TS_INUSE], l, l_next, info) {
658                 elm_genlist_item_update(info->it);
659
660         }
661         pthread_mutex_unlock(&mutex_for_graph_update);
662         return ECORE_CALLBACK_RENEW;
663 }
664
665 void *_update_pthread_cb(void *data)
666 {
667 _D("func\n");
668         struct appdata *ad = data;
669         long tick;
670         int ncpu;
671         Eina_List *l, *l_next;
672         struct _task_info *info;
673
674         while(1) {
675
676                 if (ad->ending == EINA_FALSE) {
677                         if(ad->applist[TS_INUSE] == NULL) {
678                                 _D("in use list is NULL\n");
679                                 return ECORE_CALLBACK_CANCEL;
680                         }
681
682                         _get_sysconf(&ncpu, &tick);
683
684                         ad->applist[TS_INUSE] = eina_list_nth_list(ad->applist[TS_INUSE], 0);
685                         if (eina_list_count(ad->applist[TS_INUSE]) < 1) {
686                                 _D("list count is 0\n");
687                                 return NULL;
688                         }
689
690                         EINA_LIST_FOREACH_SAFE(ad->applist[TS_INUSE], l, l_next, info) {
691                                 if (info) {
692                                         info->cpu = _get_cpu_ratio(info, ncpu, tick);
693                                         _D("%d / %lf\n", info->pid, info->cpu);
694                                 }
695
696                         }
697                         sleep(2);
698                 }
699         }
700
701         return NULL;
702
703 }
704
705 void _set_genlist(struct appdata *ad)
706 {
707 _D("func\n");
708         retm_if(ad == NULL, "Invalid argument: appdata is NULL\n");
709         int ret = AUL_R_ERROR;
710
711         _init_grp_cnt();
712
713         while (ret != AUL_R_OK)
714                 ret = aul_app_get_running_app_info(runapp_info_get, ad);
715
716         taskmanager_get_history_app_info(ad);
717         _set_genlist_from_eina(ad);
718
719 }
720
721 void _init_pthread(void)
722 {
723         pthread_mutex_init(&pm, NULL);
724         pthread_cond_init(&pc, NULL);
725 }
726
727 void _fini_pthread(void)
728 {
729 _D("func\n");
730         if (pt) {
731                 pthread_cancel(pt);
732         }
733 }
734
735 void refresh_app_info(struct appdata *ad)
736 {
737 _D("func\n");
738         retm_if(ad == NULL, "Invalid argument: appdata is NULL\n");
739
740         _free_einalist_all(ad);
741         clear_genlist(ad);
742
743         _set_genlist(ad);
744
745         alert_app_info(ad);
746
747 }
748
749 void _del_popup_timer(struct appdata *ad)
750 {
751         if (ad->popup_timer) {
752                 ecore_timer_del(ad->popup_timer);
753                 ad->popup_timer = NULL;
754         }
755 }
756
757 void taskmanager_free_info(struct _task_info *info)
758 {
759         if (info) {
760                 if (info->app_name) {
761                         free(info->app_name);
762                         info->app_name = NULL;
763                 }
764                 if (info->pkg_name) {
765                         free(info->pkg_name);
766                         info->pkg_name = NULL;
767                 }
768                 if (info->icn_path) {
769                         free(info->icn_path);
770                         info->icn_path = NULL;
771                 }
772
773                 free(info);
774         }
775 }
776
777 void _restart_pthread(struct appdata *ad)
778 {
779 _D("func\n");
780         pthread_cancel(pt);
781         if (eina_list_count(ad->applist[TS_INUSE]) > 0) {
782
783                 pthread_create(&pt, NULL, _update_pthread_cb, ad);
784                 pthread_detach(pt);
785                 if (ad->update_timer) {
786                         ecore_timer_del(ad->update_timer);
787                         ad->update_timer = NULL;
788                 }
789                 ad->update_timer = ecore_timer_add(2.0, _update_list, ad);
790         }
791 }
792 int response_end_inuse(struct appdata *ad)
793 {
794 _D("func\n");
795         Eina_List *l, *l_next;
796         struct _task_info *info;
797         Elm_Object_Item *egi;
798
799         retvm_if(ad == NULL, -1, "Invalid argument: appdata is NULL\n");
800
801         ad->ending = EINA_TRUE;
802 //      egi = evas_object_data_get(ad->popup_ask, "selected_egi");
803
804         EINA_LIST_FOREACH_SAFE(ad->applist[TS_INUSE], l, l_next, info) {
805                 if (info->it == g_egi) {
806                         if (info->pid > 0) {
807                                 if (aul_terminate_pid(info->pid) < 0) {
808                                         kill(info->pid, SIGKILL);
809                                 }
810 //                              ad->applist[TS_INUSE] =
811 //                                      eina_list_remove_list(ad->applist[TS_INUSE], l);
812                         }
813                         break;
814                 }
815         }
816         ad->ending = EINA_FALSE;
817
818         return 0;
819 }
820
821 Eina_Bool _refresh_idler_cb(void *data)
822 {
823 _D("func\n");
824         struct appdata *ad = (struct appdata *)data;
825         retvm_if(data == NULL, ECORE_CALLBACK_CANCEL, "Invalid argument: appdata is NULL\n:");
826
827         _del_popup_timer(ad);
828         _del_progressbar(ad);
829         refresh_app_info(ad);
830         return ECORE_CALLBACK_CANCEL;
831 }
832
833 int response_end_all_inuse(struct appdata *ad)
834 {
835         Eina_List *l;
836         struct _task_info *info;
837
838         retvm_if(ad == NULL, -1, "Invalid argument: appdata is NULL\n");
839
840         ad->ending = EINA_TRUE;
841
842         if(ad->update_timer) {
843                 ecore_timer_del(ad->update_timer);
844                 ad->update_timer = NULL;
845         }
846
847         ad->endcnt = eina_list_count(ad->applist[TS_INUSE]);
848         _D("set end count (%d)\n", ad->endcnt);
849
850         EINA_LIST_FOREACH(ad->applist[TS_INUSE], l, info) {
851                 if (info != NULL) {
852                         if (info->pid > 0) {
853                                 if (aul_terminate_pid(info->pid) < 0) {
854                                         kill(info->pid, SIGKILL);
855                                 }
856                                 _D("terminated\n");
857 //                              ad->applist[TS_INUSE] =
858 //                                      eina_list_remove_list(ad->applist[TS_INUSE], l);
859                         }
860                 }
861         }
862         ad->ending = EINA_FALSE;
863         return 0;
864 }
865
866 int response_del_history(struct appdata *ad)
867 {
868         Eina_List *l, *l_next;
869         struct _task_info *info;
870         Elm_Object_Item *egi;
871
872         retvm_if(ad == NULL, -1, "Invalid argument: appdata is NULL\n");
873
874         _show_progressbar(ad);
875 //      egi = evas_object_data_get(ad->popup_ask, "selected_egi");
876         EINA_LIST_FOREACH_SAFE(ad->applist[TS_HISTORY], l, l_next, info) {
877                 if (info->it == g_egi) {
878
879                         if (rua_init() == -1) {
880                                 break;
881                         }
882                         rua_delete_history_with_pkgname(info->pkg_name);
883                         rua_fini();
884
885                         ad->applist[TS_HISTORY] =
886                             eina_list_remove_list(ad->applist[TS_HISTORY], l);
887
888                         if (info->b) {
889                                 bundle_free(info->b);
890                         }
891
892                         elm_object_item_del(info->it);
893                         taskmanager_free_info(info);
894                         break;
895                 }
896         }
897         alert_app_info(ad);
898         refresh_app_info(ad);
899         _del_popup_timer(ad);
900         _del_progressbar(ad);
901
902         ad->mode = MODE_NONE;
903         return 0;
904 }
905
906 int response_del_all_history(struct appdata *ad)
907 {
908         Eina_List *l;
909         struct _task_info *info;
910
911         retvm_if(ad == NULL, -1, "Invalid argument: appdata is NULL\n");
912
913         if(ad->update_timer) {
914                 _D("update timer is deleted\n");
915                 ecore_timer_del(ad->update_timer);
916                 ad->update_timer = NULL;
917         }
918
919
920         _show_progressbar(ad);
921
922         if (rua_init() == -1) {
923                 return -1;
924         }
925
926         EINA_LIST_FOREACH(ad->applist[TS_HISTORY], l, info) {
927                 if (info != NULL) {
928                         rua_delete_history_with_pkgname(info->pkg_name);
929                 }
930         }
931
932         if (eina_list_count(ad->applist[TS_INUSE]) == 0) {
933                 rua_clear_history();
934         }
935
936         rua_fini();
937         refresh_app_info(ad);
938         _del_popup_timer(ad);
939         _del_progressbar(ad);
940
941         ad->mode = MODE_NONE;
942         return 0;
943 }
944
945 int response_kill_inuse(struct appdata *ad)
946 {
947         Eina_List *l, *l_next;
948         struct _task_info *info;
949         Elm_Object_Item *egi;
950
951         retvm_if(ad == NULL, -1, "Invalid argument: appdata is NULL\n");
952
953         _show_progressbar(ad);
954 //      egi = evas_object_data_get(ad->popup_ask, "selected_egi");
955
956         EINA_LIST_FOREACH_SAFE(ad->applist[TS_INUSE], l, l_next, info) {
957                 if (info->it == g_egi) {
958                         if (info->pid > 0) {
959                                 kill(info->pid, SIGKILL);
960                         }
961
962                         ad->applist[TS_INUSE] =
963                             eina_list_remove_list(ad->applist[TS_INUSE], l);
964                         taskmanager_free_info(info);
965                         break;
966                 }
967         }
968         refresh_app_info(ad);
969         _del_progressbar(ad);
970
971         return 0;
972 }
973
974 int response_kill_all_inuse(struct appdata *ad)
975 {
976         Eina_List *l;
977         struct _task_info *info;
978
979         retvm_if(ad == NULL, -1, "Invalid argument: appdata is NULL\n");
980
981         _show_progressbar(ad);
982
983         EINA_LIST_FOREACH(ad->applist[TS_INUSE], l, info) {
984                 if (info != NULL) {
985                         if (info->pid > 0) {
986                                 kill(info->pid, SIGKILL);
987                         }
988                 }
989         }
990         refresh_app_info(ad);
991         _del_progressbar(ad);
992
993         return 0;
994 }
995