e9cbe2944352162f090749f27a7b5737d0c98beb
[apps/core/preloaded/taskmanager.git] / src / _logic.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
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
7  *
8  *     http://www.tizenopensource.org/license
9  *
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.
15  */
16
17
18
19
20 #include <appcore-common.h>
21 #include <aul.h>
22 #include <Ecore_X.h>
23 #include <vconf.h>
24
25 #include "taskmanager.h"
26 #include "_util_log.h"
27 #include "_util_efl.h"
28 #include "_genlist.h"
29 #include "_eina.h"
30 #include "_progressbar.h"
31 #include "_info.h"
32
33 int _dead_cb(int pid, void *data)
34 {
35 _D("func\n");
36         /* redraw list */
37         struct appdata *ad = (struct appdata *)data;
38         retvm_if(ad == NULL, -1, "Invalid argument: appdata is NULL\n");
39
40         int ret = -1;
41
42         _fini_pthread();
43         if (ad->update_timer) {
44                 ecore_timer_del(ad->update_timer);
45                 ad->update_timer = NULL;
46         }
47
48         ret = _subt_einalist_item(ad, pid);
49         _D("mode(%d) count(%d) pid(%d) \n", ad->mode, ad->endcnt, pid);
50
51         if (ret != -1) {
52                 switch (ad->mode) {
53                 default:
54                 case MODE_END_INUSE:
55                 case MODE_DEL_HISTORY:
56                 case MODE_DEL_ALL_HISTORY:
57                 case MODE_KILL_INUSE:
58                         _D("aa\n");
59                         _del_popup_timer(ad);
60                         _del_progressbar(ad);
61                         refresh_app_info(ad);
62                         _restart_pthread(ad);
63                         break;
64
65                 case MODE_END_ALL_INUSE:
66                 case MODE_KILL_ALL_INUSE:
67                         _D("bb\n");
68                         if (ad->endcnt <= 1) {
69                                 _D("count set 0\n");
70                                 _del_popup_timer(ad);
71                                 _del_progressbar(ad);
72                                 refresh_app_info(ad);
73                                 _restart_pthread(ad);
74
75                         } else {
76                                 ad->endcnt--;
77                         }
78                         break;
79                 }
80         }
81
82         return ret;
83 }
84
85 static void _back_cb(void *data, Evas_Object *obj, void *event_info)
86 {
87         struct appdata *ad = (struct appdata *)data;
88         /*
89         _unset_notification_level(ad->win);
90         */
91         elm_exit();
92
93 }
94
95 static void _drag_start_cb(void *data, Evas_Object *obj, void *event_info)
96 {
97         _D("func\n");
98         struct appdata *ad = (struct appdata *)data;
99         if (ad->update_timer) {
100                 ecore_timer_del(ad->update_timer);
101                 ad->update_timer = NULL;
102         }
103 }
104
105 static void _drag_stop_cb(void *data, Evas_Object *obj, void *event_info)
106 {
107         _D("func\n");
108         struct appdata *ad = (struct appdata *)data;
109         if (ad->update_timer) {
110                 ecore_timer_del(ad->update_timer);
111                 ad->update_timer = NULL;
112         }
113         ad->update_timer = ecore_timer_add(2.0, _update_list, ad);
114 }
115
116
117 static void _anim_start_cb(void *data, Evas_Object *obj, void *event_info)
118 {
119         _D("func\n");
120         struct appdata *ad = (struct appdata *)data;
121         if (ad->update_timer) {
122                 ecore_timer_del(ad->update_timer);
123                 ad->update_timer = NULL;
124         }
125 }
126
127 static void _anim_stop_cb(void *data, Evas_Object *obj, void *event_info)
128 {
129         _D("func\n");
130         struct appdata *ad = (struct appdata *)data;
131         if (ad->update_timer) {
132                 ecore_timer_del(ad->update_timer);
133                 ad->update_timer = NULL;
134         }
135         ad->update_timer = ecore_timer_add(2.0, _update_list, ad);
136 }
137
138 static void _moved_cb(void *data, Evas_Object *obj, void *event_info)
139 {
140         _D("func\n");
141 }
142
143 int _app_create(struct appdata *ad)
144 {
145         Evas_Object *ly, *bg, *nv, *bt, *gl;
146
147         retvm_if(ad == NULL, -1, "Invalid argument: appdata is NULL\n");
148         ad->ending = EINA_FALSE;
149
150         ly = _add_layout_main(ad->win, EINA_TRUE, EINA_FALSE);
151         retvm_if(ly == NULL, -1, "Failed to add layout main\n");
152
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);
156
157         nv = _add_naviframe(ly);
158         retvm_if(nv == NULL, -1, "Failed to add naviframe\n");
159         ad->nv = nv;
160
161         ly = _add_layout(ad->nv, EDJ_NAME, GRP_TM);
162         retvm_if(ly == NULL, -1, "Failed to add layout\n");
163         ad->ly = ly;
164
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);
175         ad->gl = gl;
176
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);
181
182         elm_naviframe_item_push(nv,
183                         T_("IDS_TASKMGR_HEADER_TASK_SWITCHER"),
184                         bt, NULL, ly, NULL);
185
186         return 0;
187 }
188
189 static void _get_win_geometry(struct appdata *ad)
190 {
191         Ecore_X_Window focus_win;
192         Ecore_X_Window root_win;
193
194         focus_win = ecore_x_window_focus_get();
195         root_win = ecore_x_window_root_get(focus_win);
196         ecore_x_window_size_get(root_win, &ad->root_w, &ad->root_h);
197 }
198
199 /* this func is to exit taskmanager after launching application */
200 static Eina_Bool __climsg_cb(void *data, int type, void *event)
201 {
202         static Atom a_deact;
203         pid_t pid_a, pid_d;
204
205         struct appdata *ad = (struct appdata *)data;
206         Ecore_X_Event_Client_Message *ev = event;
207
208         if(ev == NULL) {
209                 _E("Invalid argument: event is NULL\n");
210                 _exit_cb(ad);
211                 return ECORE_CALLBACK_CANCEL;
212         }
213
214         pid_a = ev->data.l[1];
215         pid_d = ev->data.l[3];
216         a_deact = ecore_x_atom_get("_X_ILLUME_DEACTIVATE_WINDOW");
217
218         /* when pid_a == pid_d, this is useless data */
219         if (pid_a == pid_d) {
220                 return ECORE_CALLBACK_RENEW;
221         }
222
223         if (ev->message_type == a_deact) {
224                 _exit_cb(ad);
225                 return ECORE_CALLBACK_CANCEL;
226         } else {
227                 _D("messagre is act\n");
228
229         }
230
231         return ECORE_CALLBACK_CANCEL;
232 }
233
234 void _ok_response_cb(void *data, Evas_Object *obj, void *event_info)
235 {
236         struct appdata *ad = (struct appdata *)data;
237
238         retm_if(data == NULL, "Invalid argument: appdata is NULL\n");
239         if (ad->popup_ask) {
240                 evas_object_del(ad->popup_ask);
241                 ad->popup_ask = NULL;
242         }
243
244         switch (ad->mode) {
245                 case MODE_END_INUSE:
246                         _D("end inuse\n");
247                         _del_popup_timer(ad);
248                         _show_progressbar(ad);
249                         response_end_inuse(ad);
250                         _restart_pthread(ad);
251                         break;
252
253                 case MODE_END_ALL_INUSE:
254                         _D("end all inuse\n");
255                         _del_popup_timer(ad);
256                         _show_progressbar(ad);
257                         response_end_all_inuse(ad);
258                         break;
259
260                 case MODE_DEL_HISTORY:
261                         _D("del inuse\n");
262                         _del_popup_timer(ad);
263                         response_del_history(ad);
264                         break;
265
266                 case MODE_DEL_ALL_HISTORY:
267                         _D("del all inuse\n");
268                         _del_popup_timer(ad);
269                         response_del_all_history(ad);
270                         break;
271
272                 case MODE_KILL_INUSE:
273                         _D("kill all inuse\n");
274                         response_kill_inuse(ad);
275                         break;
276
277                 case MODE_KILL_ALL_INUSE:
278                         _D("kill all inuse\n");
279                         response_kill_all_inuse(ad);
280                         break;
281
282                 default:
283                         printf("[Wanning] taskmanager: check mode [%d]\n",
284                                         ad->mode);
285                         break;
286         }
287 }
288
289 void _cancel_response_cb(void *data, Evas_Object *obj, void *event_info)
290 {
291         struct appdata *ad = (struct appdata *)data;
292
293         retm_if(data == NULL, "Invalid argument: appdata is NULL\n");
294         if (ad->popup_ask) {
295                 evas_object_del(ad->popup_ask);
296                 ad->popup_ask = NULL;
297         }
298 }
299
300 Eina_Bool _create_idler_cb(void *data)
301 {
302         Evas_Object *pu, *bt1, *bt2;
303         struct appdata *ad = (struct appdata *)data;
304         retvm_if(ad == NULL, ECORE_CALLBACK_CANCEL, "Invalid argument\n");
305
306         evas_object_show(ad->win);
307
308         _key_grab(ad);
309
310         _init_pthread();
311         _get_win_geometry(ad);
312         ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE, __climsg_cb, ad);
313
314         return ECORE_CALLBACK_CANCEL;
315 }
316
317
318