2 * Copyright 2012 Samsung Electronics Co., Ltd
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
8 * http://www.tizenopensource.org/license
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.
20 #include <appcore-common.h>
25 #include "taskmanager.h"
26 #include "_util_log.h"
27 #include "_util_efl.h"
30 #include "_progressbar.h"
33 int _dead_cb(int pid, void *data)
37 struct appdata *ad = (struct appdata *)data;
38 retvm_if(ad == NULL, -1, "Invalid argument: appdata is NULL\n");
43 if (ad->update_timer) {
44 ecore_timer_del(ad->update_timer);
45 ad->update_timer = NULL;
48 ret = _subt_einalist_item(ad, pid);
49 _D("mode(%d) count(%d) pid(%d) \n", ad->mode, ad->endcnt, pid);
55 case MODE_DEL_HISTORY:
56 case MODE_DEL_ALL_HISTORY:
65 case MODE_END_ALL_INUSE:
66 case MODE_KILL_ALL_INUSE:
68 if (ad->endcnt <= 1) {
83 static void _back_cb(void *data, Evas_Object *obj, void *event_info)
85 struct appdata *ad = (struct appdata *)data;
87 _unset_notification_level(ad->win);
93 static void _drag_start_cb(void *data, Evas_Object *obj, void *event_info)
96 struct appdata *ad = (struct appdata *)data;
97 if (ad->update_timer) {
98 ecore_timer_del(ad->update_timer);
99 ad->update_timer = NULL;
103 static void _drag_stop_cb(void *data, Evas_Object *obj, void *event_info)
106 struct appdata *ad = (struct appdata *)data;
107 if (ad->update_timer) {
108 ecore_timer_del(ad->update_timer);
109 ad->update_timer = NULL;
111 ad->update_timer = ecore_timer_add(2.0, _update_list, ad);
115 static void _anim_start_cb(void *data, Evas_Object *obj, void *event_info)
118 struct appdata *ad = (struct appdata *)data;
119 if (ad->update_timer) {
120 ecore_timer_del(ad->update_timer);
121 ad->update_timer = NULL;
125 static void _anim_stop_cb(void *data, Evas_Object *obj, void *event_info)
128 struct appdata *ad = (struct appdata *)data;
129 if (ad->update_timer) {
130 ecore_timer_del(ad->update_timer);
131 ad->update_timer = NULL;
133 ad->update_timer = ecore_timer_add(2.0, _update_list, ad);
136 static void _moved_cb(void *data, Evas_Object *obj, void *event_info)
141 int _app_create(struct appdata *ad)
143 Evas_Object *ly, *bg, *nv, *bt, *gl;
145 retvm_if(ad == NULL, -1, "Invalid argument: appdata is NULL\n");
146 ad->ending = EINA_FALSE;
148 ly = _add_layout_main(ad->win, EINA_TRUE, EINA_FALSE);
149 retvm_if(ly == NULL, -1, "Failed to add layout main\n");
151 bg = _add_bg(ad->win, "group_list");
152 retvm_if(bg == NULL, -1, "Failed to add bg\n");
153 elm_object_part_content_set(ly, "elm.swallow.bg", bg);
155 nv = _add_naviframe(ly);
156 retvm_if(nv == NULL, -1, "Failed to add naviframe\n");
159 ly = _add_layout(ad->nv, EDJ_NAME, GRP_TM);
160 retvm_if(ly == NULL, -1, "Failed to add layout\n");
163 /* Load default content (running task) */
164 gl = _add_genlist(ly);
165 retvm_if(gl == NULL, -1, "Failed to add genlist\n");
166 elm_genlist_block_count_set(gl, 20);
167 evas_object_data_set(gl, "appdata", ad);
168 elm_object_part_content_set(ly, "list", gl);
169 evas_object_smart_callback_add(gl, "scroll,drag,start", _drag_start_cb, ad);
170 evas_object_smart_callback_add(gl, "scroll,drag,stop", _drag_stop_cb, ad);
171 evas_object_smart_callback_add(gl, "scroll,anim,start", _anim_start_cb, ad);
172 evas_object_smart_callback_add(gl, "scroll,anim,stop", _anim_stop_cb, ad);
175 bt = elm_button_add(nv);
176 retvm_if(bt == NULL, -1, "Failed to add button\n");
177 elm_object_style_set(bt, "naviframe/end_btn/default");
178 evas_object_smart_callback_add(bt, "clicked", _back_cb, ad);
180 elm_naviframe_item_push(nv,
181 _("IDS_TASKMGR_HEADER_TASK_SWITCHER"),
187 static void _get_win_geometry(struct appdata *ad)
192 ee = ecore_evas_ecore_evas_get(evas_object_evas_get(ad->win));
193 ecore_evas_screen_geometry_get(ee, 0, 0, &ad->root_w, &ad->root_h);
196 static void _vconf_noti_cb(keynode_t *node, void *data)
201 static void _set_vconf_noti(void *data)
203 vconf_notify_key_changed(VCONFKEY_IDLE_LOCK_STATE,
204 _vconf_noti_cb, NULL);
209 /* this func is to exit taskmanager after launching application */
210 static Eina_Bool __climsg_cb(void *data, int type, void *event)
215 struct appdata *ad = (struct appdata *)data;
216 Ecore_X_Event_Client_Message *ev = event;
219 _E("Invalid argument: event is NULL\n");
220 ecore_timer_add(0.3, _exit_cb, NULL);
221 return ECORE_CALLBACK_CANCEL;
224 pid_a = ev->data.l[1];
225 pid_d = ev->data.l[3];
226 a_deact = ecore_x_atom_get("_X_ILLUME_DEACTIVATE_WINDOW");
228 /* when pid_a == pid_d, this is useless data */
229 if (pid_a == pid_d) {
230 return ECORE_CALLBACK_RENEW;
233 if (ev->message_type == a_deact) {
234 _D("exit after 1.0 sec\n");
235 ad->exit_timer = ecore_timer_add(0.3, _exit_cb, ad);
236 return ECORE_CALLBACK_CANCEL;
238 _D("messagre is act\n");
242 return ECORE_CALLBACK_CANCEL;
246 static Eina_Bool _ask_kill_process(void *data)
248 struct appdata *ad = data;
250 _del_progressbar(ad);
253 /* why? check enum in taskmgr.h */
256 evas_object_del(ad->popup_ask);
257 ad->popup_ask = NULL;
259 ad->popup_ask = _add_popup_ask(ad->win,
260 "It might be an invalid process. Do you want to kill this proceess anyway?",
263 return ECORE_CALLBACK_CANCEL;
266 void _ok_response_cb(void *data, Evas_Object *obj, void *event_info)
268 struct appdata *ad = (struct appdata *)data;
270 retm_if(data == NULL, "Invalid argument: appdata is NULL\n");
272 evas_object_del(ad->popup_ask);
273 ad->popup_ask = NULL;
279 _del_popup_timer(ad);
280 ad->popup_timer = ecore_timer_add(7.0, _ask_kill_process, ad);
281 _show_progressbar(ad);
282 response_end_inuse(ad);
283 _restart_pthread(ad);
286 case MODE_END_ALL_INUSE:
287 _D("end all inuse\n");
288 _del_popup_timer(ad);
289 ad->popup_timer = ecore_timer_add(7.0, _ask_kill_process, ad);
290 _show_progressbar(ad);
291 response_end_all_inuse(ad);
294 case MODE_DEL_HISTORY:
296 _del_popup_timer(ad);
297 ad->popup_timer = ecore_timer_add(5.0, _ask_kill_process, ad);
298 response_del_history(ad);
301 case MODE_DEL_ALL_HISTORY:
302 _D("del all inuse\n");
303 _del_popup_timer(ad);
304 ad->popup_timer = ecore_timer_add(5.0, _ask_kill_process, ad);
305 response_del_all_history(ad);
308 case MODE_KILL_INUSE:
309 _D("kill all inuse\n");
310 response_kill_inuse(ad);
313 case MODE_KILL_ALL_INUSE:
314 _D("kill all inuse\n");
315 response_kill_all_inuse(ad);
319 printf("[Wanning] taskmanager: check mode [%d]\n",
325 void _cancel_response_cb(void *data, Evas_Object *obj, void *event_info)
327 struct appdata *ad = (struct appdata *)data;
329 retm_if(data == NULL, "Invalid argument: appdata is NULL\n");
331 evas_object_del(ad->popup_ask);
332 ad->popup_ask = NULL;
336 Eina_Bool _create_idler_cb(void *data)
338 Evas_Object *pu, *bt1, *bt2;
339 struct appdata *ad = (struct appdata *)data;
340 retvm_if(ad == NULL, ECORE_CALLBACK_CANCEL, "Invalid argument\n");
342 evas_object_show(ad->win);
349 _get_win_geometry(ad);
352 ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE, __climsg_cb, ad);
355 return ECORE_CALLBACK_CANCEL;