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.
18 #include <appcore-common.h>
23 #include "taskmanager.h"
24 #include "_util_log.h"
25 #include "_util_efl.h"
28 #include "_progressbar.h"
32 int _dead_cb(int pid, void *data)
36 struct appdata *ad = (struct appdata *)data;
37 retvm_if(ad == NULL, -1, "Invalid argument: appdata is NULL\n");
40 if (ad->update_timer) {
41 ecore_timer_del(ad->update_timer);
42 ad->update_timer = NULL;
44 _subt_einalist_item(ad, pid);
46 _D("mode(%d) count(%d)\n", ad->mode, ad->endcnt);
50 case MODE_DEL_HISTORY:
51 case MODE_DEL_ALL_HISTORY:
60 case MODE_END_ALL_INUSE:
61 case MODE_KILL_ALL_INUSE:
63 if (ad->endcnt <= 1) {
77 static void _back_cb(void *data, Evas_Object *obj, void *event_info)
79 struct appdata *ad = (struct appdata *)data;
81 _unset_notification_level(ad->win);
87 static void _drag_start_cb(void *data, Evas_Object *obj, void *event_info)
90 struct appdata *ad = (struct appdata *)data;
91 if (ad->update_timer) {
92 ecore_timer_del(ad->update_timer);
93 ad->update_timer = NULL;
97 static void _drag_stop_cb(void *data, Evas_Object *obj, void *event_info)
100 struct appdata *ad = (struct appdata *)data;
101 if (ad->update_timer) {
102 ecore_timer_del(ad->update_timer);
103 ad->update_timer = NULL;
105 ad->update_timer = ecore_timer_add(2.0, _update_list, ad);
109 static void _anim_start_cb(void *data, Evas_Object *obj, void *event_info)
112 struct appdata *ad = (struct appdata *)data;
113 if (ad->update_timer) {
114 ecore_timer_del(ad->update_timer);
115 ad->update_timer = NULL;
119 static void _anim_stop_cb(void *data, Evas_Object *obj, void *event_info)
122 struct appdata *ad = (struct appdata *)data;
123 if (ad->update_timer) {
124 ecore_timer_del(ad->update_timer);
125 ad->update_timer = NULL;
127 ad->update_timer = ecore_timer_add(2.0, _update_list, ad);
130 static void _moved_cb(void *data, Evas_Object *obj, void *event_info)
135 int _app_create(struct appdata *ad)
137 Evas_Object *ly, *bg, *nv, *bt, *gl;
139 retvm_if(ad == NULL, -1, "Invalid argument: appdata is NULL\n");
140 ad->ending = EINA_FALSE;
142 ly = _add_layout_main(ad->win, EINA_TRUE, EINA_FALSE);
143 retvm_if(ly == NULL, -1, "Failed to add layout main\n");
145 bg = _add_bg(ad->win, "group_list");
146 retvm_if(bg == NULL, -1, "Failed to add bg\n");
147 elm_object_part_content_set(ly, "elm.swallow.bg", bg);
149 nv = _add_naviframe(ly);
150 retvm_if(nv == NULL, -1, "Failed to add naviframe\n");
151 evas_object_show(nv);
154 ly = _add_layout(ad->nv, EDJ_NAME, GRP_TM);
155 retvm_if(ly == NULL, -1, "Failed to add layout\n");
158 /* Load default content (running task) */
159 gl = _add_genlist(ly);
160 retvm_if(gl == NULL, -1, "Failed to add genlist\n");
161 elm_genlist_block_count_set(gl, 20);
162 evas_object_data_set(gl, "appdata", ad);
163 elm_object_part_content_set(ly, "list", gl);
164 evas_object_smart_callback_add(gl, "scroll,drag,start", _drag_start_cb, ad);
165 evas_object_smart_callback_add(gl, "scroll,drag,stop", _drag_stop_cb, ad);
166 evas_object_smart_callback_add(gl, "scroll,anim,start", _anim_start_cb, ad);
167 evas_object_smart_callback_add(gl, "scroll,anim,stop", _anim_stop_cb, ad);
168 // evas_object_smart_callback_add(gl, "edge,bottom", _moved_cb, ad);
169 evas_object_show(gl);
172 bt = elm_button_add(nv);
173 retvm_if(bt == NULL, -1, "Failed to add button\n");
174 elm_object_style_set(bt, "naviframe/end_btn/default");
175 evas_object_smart_callback_add(bt, "clicked", _back_cb, ad);
177 elm_naviframe_item_push(nv,
178 _("IDS_TASKMGR_HEADER_TASK_SWITCHER"),
184 static void _get_win_geometry(struct appdata *ad)
186 Ecore_X_Window focus_win;
187 Ecore_X_Window root_win;
189 focus_win = ecore_x_window_focus_get();
190 root_win = ecore_x_window_root_get(focus_win);
191 ecore_x_window_size_get(root_win, &ad->root_w, &ad->root_h);
194 static void _vconf_noti_cb(keynode_t *node, void *data)
199 static void _set_vconf_noti(void *data)
201 vconf_notify_key_changed(VCONFKEY_IDLE_LOCK_STATE,
202 _vconf_noti_cb, NULL);
205 /* this func is to exit taskmanager after launching application */
206 static Eina_Bool __climsg_cb(void *data, int type, void *event)
211 Ecore_X_Event_Client_Message *ev = event;
214 _E("Invalid argument: event is NULL\n");
215 ecore_timer_add(1.5, _exit_cb, NULL);
216 return ECORE_CALLBACK_CANCEL;
219 pid_a = ev->data.l[1];
220 pid_d = ev->data.l[3];
221 a_deact = ecore_x_atom_get("_X_ILLUME_DEACTIVATE_WINDOW");
223 /* when pid_a == pid_d, this is useless data */
224 if (pid_a == pid_d) {
225 return ECORE_CALLBACK_RENEW;
228 if (ev->message_type == a_deact) {
229 _D("exit after 1.0 sec\n");
230 ecore_timer_add(1.5, _exit_cb, NULL);
231 return ECORE_CALLBACK_CANCEL;
233 _D("messagre is act\n");
237 return ECORE_CALLBACK_CANCEL;
240 static Eina_Bool _ask_kill_process(void *data)
242 struct appdata *ad = data;
244 _del_progressbar(ad);
247 /* why? check enum in taskmgr.h */
250 case MODE_KILL_INUSE:
251 _D("kill all inuse\n");
252 response_kill_inuse(ad);
255 case MODE_KILL_ALL_INUSE:
256 _D("kill all inuse\n");
257 response_kill_all_inuse(ad);
262 evas_object_del(ad->popup_ask);
263 ad->popup_ask = NULL;
265 ad->popup_ask = _add_popup_ask(ad->win,
266 "It might be an invalid process. Do you want to kill this proceess anyway?",
269 return ECORE_CALLBACK_CANCEL;
272 void _ok_response_cb(void *data, Evas_Object *obj, void *event_info)
274 struct appdata *ad = (struct appdata *)data;
276 retm_if(data == NULL, "Invalid argument: appdata is NULL\n");
278 evas_object_del(ad->popup_ask);
279 ad->popup_ask = NULL;
285 _del_popup_timer(ad);
286 ad->popup_timer = ecore_timer_add(7.0, _ask_kill_process, ad);
287 _show_progressbar(ad);
288 response_end_inuse(ad);
289 _restart_pthread(ad);
292 case MODE_END_ALL_INUSE:
293 _D("end all inuse\n");
294 _del_popup_timer(ad);
295 ad->popup_timer = ecore_timer_add(7.0, _ask_kill_process, ad);
296 _show_progressbar(ad);
297 response_end_all_inuse(ad);
300 case MODE_DEL_HISTORY:
302 _del_popup_timer(ad);
303 ad->popup_timer = ecore_timer_add(5.0, _ask_kill_process, ad);
304 response_del_history(ad);
307 case MODE_DEL_ALL_HISTORY:
308 _D("del all inuse\n");
309 _del_popup_timer(ad);
310 ad->popup_timer = ecore_timer_add(5.0, _ask_kill_process, ad);
311 response_del_all_history(ad);
314 case MODE_KILL_INUSE:
315 _D("kill all inuse\n");
316 response_kill_inuse(ad);
319 case MODE_KILL_ALL_INUSE:
320 _D("kill all inuse\n");
321 response_kill_all_inuse(ad);
325 printf("[Wanning] taskmanager: check mode [%d]\n",
331 void _cancel_response_cb(void *data, Evas_Object *obj, void *event_info)
333 struct appdata *ad = (struct appdata *)data;
335 retm_if(data == NULL, "Invalid argument: appdata is NULL\n");
337 evas_object_del(ad->popup_ask);
338 ad->popup_ask = NULL;
342 Eina_Bool _create_idler_cb(void *data)
344 Evas_Object *pu, *bt1, *bt2;
345 struct appdata *ad = (struct appdata *)data;
346 retvm_if(ad == NULL, ECORE_CALLBACK_CANCEL, "Invalid argument\n");
348 evas_object_show(ad->win);
353 _get_win_geometry(ad);
355 ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE, __climsg_cb, NULL);
357 return ECORE_CALLBACK_CANCEL;