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");
41 if (ad->update_timer) {
42 ecore_timer_del(ad->update_timer);
43 ad->update_timer = NULL;
45 _subt_einalist_item(ad, pid);
47 _D("mode(%d) count(%d)\n", ad->mode, ad->endcnt);
51 case MODE_DEL_HISTORY:
52 case MODE_DEL_ALL_HISTORY:
61 case MODE_END_ALL_INUSE:
62 case MODE_KILL_ALL_INUSE:
64 if (ad->endcnt <= 1) {
78 static void _back_cb(void *data, Evas_Object *obj, void *event_info)
80 struct appdata *ad = (struct appdata *)data;
82 _unset_notification_level(ad->win);
88 static void _drag_start_cb(void *data, Evas_Object *obj, void *event_info)
91 struct appdata *ad = (struct appdata *)data;
92 if (ad->update_timer) {
93 ecore_timer_del(ad->update_timer);
94 ad->update_timer = NULL;
98 static void _drag_stop_cb(void *data, Evas_Object *obj, void *event_info)
101 struct appdata *ad = (struct appdata *)data;
102 if (ad->update_timer) {
103 ecore_timer_del(ad->update_timer);
104 ad->update_timer = NULL;
106 ad->update_timer = ecore_timer_add(2.0, _update_list, ad);
110 static void _anim_start_cb(void *data, Evas_Object *obj, void *event_info)
113 struct appdata *ad = (struct appdata *)data;
114 if (ad->update_timer) {
115 ecore_timer_del(ad->update_timer);
116 ad->update_timer = NULL;
120 static void _anim_stop_cb(void *data, Evas_Object *obj, void *event_info)
123 struct appdata *ad = (struct appdata *)data;
124 if (ad->update_timer) {
125 ecore_timer_del(ad->update_timer);
126 ad->update_timer = NULL;
128 ad->update_timer = ecore_timer_add(2.0, _update_list, ad);
131 static void _moved_cb(void *data, Evas_Object *obj, void *event_info)
136 int _app_create(struct appdata *ad)
138 Evas_Object *ly, *bg, *nv, *bt, *gl;
140 retvm_if(ad == NULL, -1, "Invalid argument: appdata is NULL\n");
141 ad->ending = EINA_FALSE;
143 ly = _add_layout_main(ad->win, EINA_TRUE, EINA_FALSE);
144 retvm_if(ly == NULL, -1, "Failed to add layout main\n");
146 bg = _add_bg(ad->win, "group_list");
147 retvm_if(bg == NULL, -1, "Failed to add bg\n");
148 elm_object_part_content_set(ly, "elm.swallow.bg", bg);
150 nv = _add_naviframe(ly);
151 retvm_if(nv == NULL, -1, "Failed to add naviframe\n");
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);
171 bt = elm_button_add(nv);
172 retvm_if(bt == NULL, -1, "Failed to add button\n");
173 elm_object_style_set(bt, "naviframe/end_btn/default");
174 evas_object_smart_callback_add(bt, "clicked", _back_cb, ad);
176 elm_naviframe_item_push(nv,
177 _("IDS_TASKMGR_HEADER_TASK_SWITCHER"),
183 static void _get_win_geometry(struct appdata *ad)
185 Ecore_X_Window focus_win;
186 Ecore_X_Window root_win;
188 focus_win = ecore_x_window_focus_get();
189 root_win = ecore_x_window_root_get(focus_win);
190 ecore_x_window_size_get(root_win, &ad->root_w, &ad->root_h);
193 static void _vconf_noti_cb(keynode_t *node, void *data)
198 static void _set_vconf_noti(void *data)
200 vconf_notify_key_changed(VCONFKEY_IDLE_LOCK_STATE,
201 _vconf_noti_cb, NULL);
204 /* this func is to exit taskmanager after launching application */
205 static Eina_Bool __climsg_cb(void *data, int type, void *event)
210 struct appdata *ad = (struct appdata *)data;
211 Ecore_X_Event_Client_Message *ev = event;
214 _E("Invalid argument: event is NULL\n");
215 ecore_timer_add(0.3, _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 ad->exit_timer = ecore_timer_add(0.3, _exit_cb, ad);
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 evas_object_del(ad->popup_ask);
251 ad->popup_ask = NULL;
253 ad->popup_ask = _add_popup_ask(ad->win,
254 "It might be an invalid process. Do you want to kill this proceess anyway?",
257 return ECORE_CALLBACK_CANCEL;
260 void _ok_response_cb(void *data, Evas_Object *obj, void *event_info)
262 struct appdata *ad = (struct appdata *)data;
264 retm_if(data == NULL, "Invalid argument: appdata is NULL\n");
266 evas_object_del(ad->popup_ask);
267 ad->popup_ask = NULL;
273 _del_popup_timer(ad);
274 ad->popup_timer = ecore_timer_add(7.0, _ask_kill_process, ad);
275 _show_progressbar(ad);
276 response_end_inuse(ad);
277 _restart_pthread(ad);
280 case MODE_END_ALL_INUSE:
281 _D("end all inuse\n");
282 _del_popup_timer(ad);
283 ad->popup_timer = ecore_timer_add(7.0, _ask_kill_process, ad);
284 _show_progressbar(ad);
285 response_end_all_inuse(ad);
288 case MODE_DEL_HISTORY:
290 _del_popup_timer(ad);
291 ad->popup_timer = ecore_timer_add(5.0, _ask_kill_process, ad);
292 response_del_history(ad);
295 case MODE_DEL_ALL_HISTORY:
296 _D("del all inuse\n");
297 _del_popup_timer(ad);
298 ad->popup_timer = ecore_timer_add(5.0, _ask_kill_process, ad);
299 response_del_all_history(ad);
302 case MODE_KILL_INUSE:
303 _D("kill all inuse\n");
304 response_kill_inuse(ad);
307 case MODE_KILL_ALL_INUSE:
308 _D("kill all inuse\n");
309 response_kill_all_inuse(ad);
313 printf("[Wanning] taskmanager: check mode [%d]\n",
319 void _cancel_response_cb(void *data, Evas_Object *obj, void *event_info)
321 struct appdata *ad = (struct appdata *)data;
323 retm_if(data == NULL, "Invalid argument: appdata is NULL\n");
325 evas_object_del(ad->popup_ask);
326 ad->popup_ask = NULL;
330 Eina_Bool _create_idler_cb(void *data)
332 Evas_Object *pu, *bt1, *bt2;
333 struct appdata *ad = (struct appdata *)data;
334 retvm_if(ad == NULL, ECORE_CALLBACK_CANCEL, "Invalid argument\n");
336 evas_object_show(ad->win);
341 _get_win_geometry(ad);
343 ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE, __climsg_cb, ad);
345 return ECORE_CALLBACK_CANCEL;