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>
27 #include "taskmanager.h"
28 #include "_util_log.h"
29 #include "_util_efl.h"
32 #include "_progressbar.h"
35 int _dead_cb(int pid, void *data)
39 struct appdata *ad = (struct appdata *)data;
40 retvm_if(ad == NULL, -1, "Invalid argument: appdata is NULL\n");
45 if (ad->update_timer) {
46 ecore_timer_del(ad->update_timer);
47 ad->update_timer = NULL;
50 ret = _subt_einalist_item(ad, pid);
51 _D("mode(%d) count(%d) pid(%d) \n", ad->mode, ad->endcnt, pid);
57 case MODE_DEL_HISTORY:
58 case MODE_DEL_ALL_HISTORY:
67 case MODE_END_ALL_INUSE:
68 case MODE_KILL_ALL_INUSE:
70 if (ad->endcnt <= 1) {
85 static void _back_cb(void *data, Evas_Object *obj, void *event_info)
87 struct appdata *ad = (struct appdata *)data;
89 _unset_notification_level(ad->win);
95 static void _drag_start_cb(void *data, Evas_Object *obj, void *event_info)
98 struct appdata *ad = (struct appdata *)data;
99 if (ad->update_timer) {
100 ecore_timer_del(ad->update_timer);
101 ad->update_timer = NULL;
105 static void _drag_stop_cb(void *data, Evas_Object *obj, void *event_info)
108 struct appdata *ad = (struct appdata *)data;
109 if (ad->update_timer) {
110 ecore_timer_del(ad->update_timer);
111 ad->update_timer = NULL;
113 ad->update_timer = ecore_timer_add(2.0, _update_list, ad);
117 static void _anim_start_cb(void *data, Evas_Object *obj, void *event_info)
120 struct appdata *ad = (struct appdata *)data;
121 if (ad->update_timer) {
122 ecore_timer_del(ad->update_timer);
123 ad->update_timer = NULL;
127 static void _anim_stop_cb(void *data, Evas_Object *obj, void *event_info)
130 struct appdata *ad = (struct appdata *)data;
131 if (ad->update_timer) {
132 ecore_timer_del(ad->update_timer);
133 ad->update_timer = NULL;
135 ad->update_timer = ecore_timer_add(2.0, _update_list, ad);
138 static void _moved_cb(void *data, Evas_Object *obj, void *event_info)
143 int _app_create(struct appdata *ad)
145 Evas_Object *ly, *bg, *nv, *bt, *gl;
147 retvm_if(ad == NULL, -1, "Invalid argument: appdata is NULL\n");
148 ad->ending = EINA_FALSE;
150 ly = _add_layout_main(ad->win, EINA_TRUE, EINA_FALSE);
151 retvm_if(ly == NULL, -1, "Failed to add layout main\n");
153 bg = _add_bg(ad->win, "group_list");
154 retvm_if(bg == NULL, -1, "Failed to add bg\n");
155 elm_object_part_content_set(ly, "elm.swallow.bg", bg);
157 nv = _add_naviframe(ly);
158 retvm_if(nv == NULL, -1, "Failed to add naviframe\n");
161 ly = _add_layout(ad->nv, EDJ_NAME, GRP_TM);
162 retvm_if(ly == NULL, -1, "Failed to add layout\n");
165 /* Load default content (running task) */
166 gl = _add_genlist(ly);
167 retvm_if(gl == NULL, -1, "Failed to add genlist\n");
168 elm_genlist_block_count_set(gl, 20);
169 evas_object_data_set(gl, "appdata", ad);
170 elm_object_part_content_set(ly, "list", gl);
171 evas_object_smart_callback_add(gl, "scroll,drag,start", _drag_start_cb, ad);
172 evas_object_smart_callback_add(gl, "scroll,drag,stop", _drag_stop_cb, ad);
173 evas_object_smart_callback_add(gl, "scroll,anim,start", _anim_start_cb, ad);
174 evas_object_smart_callback_add(gl, "scroll,anim,stop", _anim_stop_cb, ad);
177 bt = elm_button_add(nv);
178 retvm_if(bt == NULL, -1, "Failed to add button\n");
179 elm_object_style_set(bt, "naviframe/end_btn/default");
180 evas_object_smart_callback_add(bt, "clicked", _back_cb, ad);
182 elm_naviframe_item_push(nv,
183 _("IDS_TASKMGR_HEADER_TASK_SWITCHER"),
189 static void _get_win_geometry(struct appdata *ad)
194 ee = ecore_evas_ecore_evas_get(evas_object_evas_get(ad->win));
195 ecore_evas_screen_geometry_get(ee, 0, 0, &ad->root_w, &ad->root_h);
198 static void _vconf_noti_cb(keynode_t *node, void *data)
203 static void _set_vconf_noti(void *data)
205 vconf_notify_key_changed(VCONFKEY_IDLE_LOCK_STATE,
206 _vconf_noti_cb, NULL);
211 /* this func is to exit taskmanager after launching application */
212 static Eina_Bool __climsg_cb(void *data, int type, void *event)
217 struct appdata *ad = (struct appdata *)data;
218 Ecore_X_Event_Client_Message *ev = event;
221 _E("Invalid argument: event is NULL\n");
222 ecore_timer_add(0.3, _exit_cb, NULL);
223 return ECORE_CALLBACK_CANCEL;
226 pid_a = ev->data.l[1];
227 pid_d = ev->data.l[3];
229 a_deact = ecore_x_atom_get("_X_ILLUME_DEACTIVATE_WINDOW");
232 /* when pid_a == pid_d, this is useless data */
233 if (pid_a == pid_d) {
234 return ECORE_CALLBACK_RENEW;
237 if (ev->message_type == a_deact) {
238 _D("exit after 1.0 sec\n");
239 ad->exit_timer = ecore_timer_add(0.3, _exit_cb, ad);
240 return ECORE_CALLBACK_CANCEL;
242 _D("messagre is act\n");
246 return ECORE_CALLBACK_CANCEL;
250 static Eina_Bool _ask_kill_process(void *data)
252 struct appdata *ad = data;
254 _del_progressbar(ad);
257 /* why? check enum in taskmgr.h */
260 evas_object_del(ad->popup_ask);
261 ad->popup_ask = NULL;
263 ad->popup_ask = _add_popup_ask(ad->win,
264 "It might be an invalid process. Do you want to kill this proceess anyway?",
267 return ECORE_CALLBACK_CANCEL;
270 void _ok_response_cb(void *data, Evas_Object *obj, void *event_info)
272 struct appdata *ad = (struct appdata *)data;
274 retm_if(data == NULL, "Invalid argument: appdata is NULL\n");
276 evas_object_del(ad->popup_ask);
277 ad->popup_ask = NULL;
283 _del_popup_timer(ad);
284 ad->popup_timer = ecore_timer_add(7.0, _ask_kill_process, ad);
285 _show_progressbar(ad);
286 response_end_inuse(ad);
287 _restart_pthread(ad);
290 case MODE_END_ALL_INUSE:
291 _D("end all inuse\n");
292 _del_popup_timer(ad);
293 ad->popup_timer = ecore_timer_add(7.0, _ask_kill_process, ad);
294 _show_progressbar(ad);
295 response_end_all_inuse(ad);
298 case MODE_DEL_HISTORY:
300 _del_popup_timer(ad);
301 ad->popup_timer = ecore_timer_add(5.0, _ask_kill_process, ad);
302 response_del_history(ad);
305 case MODE_DEL_ALL_HISTORY:
306 _D("del all inuse\n");
307 _del_popup_timer(ad);
308 ad->popup_timer = ecore_timer_add(5.0, _ask_kill_process, ad);
309 response_del_all_history(ad);
312 case MODE_KILL_INUSE:
313 _D("kill all inuse\n");
314 response_kill_inuse(ad);
317 case MODE_KILL_ALL_INUSE:
318 _D("kill all inuse\n");
319 response_kill_all_inuse(ad);
323 printf("[Wanning] taskmanager: check mode [%d]\n",
329 void _cancel_response_cb(void *data, Evas_Object *obj, void *event_info)
331 struct appdata *ad = (struct appdata *)data;
333 retm_if(data == NULL, "Invalid argument: appdata is NULL\n");
335 evas_object_del(ad->popup_ask);
336 ad->popup_ask = NULL;
340 Eina_Bool _create_idler_cb(void *data)
342 Evas_Object *pu, *bt1, *bt2;
343 struct appdata *ad = (struct appdata *)data;
344 retvm_if(ad == NULL, ECORE_CALLBACK_CANCEL, "Invalid argument\n");
346 evas_object_show(ad->win);
353 _get_win_geometry(ad);
356 ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE, __climsg_cb, ad);
359 return ECORE_CALLBACK_CANCEL;