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)
189 Ecore_X_Window focus_win;
190 Ecore_X_Window root_win;
192 focus_win = ecore_x_window_focus_get();
193 root_win = ecore_x_window_root_get(focus_win);
194 ecore_x_window_size_get(root_win, &ad->root_w, &ad->root_h);
197 static void _vconf_noti_cb(keynode_t *node, void *data)
202 static void _set_vconf_noti(void *data)
204 vconf_notify_key_changed(VCONFKEY_IDLE_LOCK_STATE,
205 _vconf_noti_cb, NULL);
208 /* this func is to exit taskmanager after launching application */
209 static Eina_Bool __climsg_cb(void *data, int type, void *event)
214 struct appdata *ad = (struct appdata *)data;
215 Ecore_X_Event_Client_Message *ev = event;
218 _E("Invalid argument: event is NULL\n");
219 ecore_timer_add(0.3, _exit_cb, NULL);
220 return ECORE_CALLBACK_CANCEL;
223 pid_a = ev->data.l[1];
224 pid_d = ev->data.l[3];
225 a_deact = ecore_x_atom_get("_X_ILLUME_DEACTIVATE_WINDOW");
227 /* when pid_a == pid_d, this is useless data */
228 if (pid_a == pid_d) {
229 return ECORE_CALLBACK_RENEW;
232 if (ev->message_type == a_deact) {
233 _D("exit after 1.0 sec\n");
234 ad->exit_timer = ecore_timer_add(0.3, _exit_cb, ad);
235 return ECORE_CALLBACK_CANCEL;
237 _D("messagre is act\n");
241 return ECORE_CALLBACK_CANCEL;
244 static Eina_Bool _ask_kill_process(void *data)
246 struct appdata *ad = data;
248 _del_progressbar(ad);
251 /* why? check enum in taskmgr.h */
254 evas_object_del(ad->popup_ask);
255 ad->popup_ask = NULL;
257 ad->popup_ask = _add_popup_ask(ad->win,
258 "It might be an invalid process. Do you want to kill this proceess anyway?",
261 return ECORE_CALLBACK_CANCEL;
264 void _ok_response_cb(void *data, Evas_Object *obj, void *event_info)
266 struct appdata *ad = (struct appdata *)data;
268 retm_if(data == NULL, "Invalid argument: appdata is NULL\n");
270 evas_object_del(ad->popup_ask);
271 ad->popup_ask = NULL;
277 _del_popup_timer(ad);
278 ad->popup_timer = ecore_timer_add(7.0, _ask_kill_process, ad);
279 _show_progressbar(ad);
280 response_end_inuse(ad);
281 _restart_pthread(ad);
284 case MODE_END_ALL_INUSE:
285 _D("end all inuse\n");
286 _del_popup_timer(ad);
287 ad->popup_timer = ecore_timer_add(7.0, _ask_kill_process, ad);
288 _show_progressbar(ad);
289 response_end_all_inuse(ad);
292 case MODE_DEL_HISTORY:
294 _del_popup_timer(ad);
295 ad->popup_timer = ecore_timer_add(5.0, _ask_kill_process, ad);
296 response_del_history(ad);
299 case MODE_DEL_ALL_HISTORY:
300 _D("del all inuse\n");
301 _del_popup_timer(ad);
302 ad->popup_timer = ecore_timer_add(5.0, _ask_kill_process, ad);
303 response_del_all_history(ad);
306 case MODE_KILL_INUSE:
307 _D("kill all inuse\n");
308 response_kill_inuse(ad);
311 case MODE_KILL_ALL_INUSE:
312 _D("kill all inuse\n");
313 response_kill_all_inuse(ad);
317 printf("[Wanning] taskmanager: check mode [%d]\n",
323 void _cancel_response_cb(void *data, Evas_Object *obj, void *event_info)
325 struct appdata *ad = (struct appdata *)data;
327 retm_if(data == NULL, "Invalid argument: appdata is NULL\n");
329 evas_object_del(ad->popup_ask);
330 ad->popup_ask = NULL;
334 Eina_Bool _create_idler_cb(void *data)
336 Evas_Object *pu, *bt1, *bt2;
337 struct appdata *ad = (struct appdata *)data;
338 retvm_if(ad == NULL, ECORE_CALLBACK_CANCEL, "Invalid argument\n");
340 evas_object_show(ad->win);
345 _get_win_geometry(ad);
347 ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE, __climsg_cb, ad);
349 return ECORE_CALLBACK_CANCEL;