changing type of calling exit_cb function to timer.
[apps/core/preloaded/taskmanager.git] / src / taskmanager.c
1 /*
2  * org.tizen.taskmgr
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Flora License, Version 1.0 (the License);
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://floralicense.org/license/
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an AS IS BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18
19
20
21 #include <stdio.h>
22 #include <unistd.h>
23 #include <appcore-efl.h>
24 #include <Elementary.h>
25 #include <Ecore_X.h>
26 #include <utilX.h>
27 #include <vconf.h>
28 #include <aul.h>
29 #include <sysman.h>
30
31 #include "taskmanager.h"
32 #include "_util_log.h"
33 #include "_util_efl.h"
34 #include "_logic.h"
35 #include "_genlist.h"
36
37 struct text_part {
38         char *part;
39         char *msgid;
40 };
41
42 enum {
43         IDLELOCK_OFF = 0x0,
44         IDLELOCK_ON,
45         IDLELOCK_MAX,
46 };
47
48 static struct text_part main_txt[] = {
49 };
50
51 static void update_ts(Evas_Object *eo, struct text_part *tp, int size)
52 {
53         int i;
54
55         if (eo == NULL || tp == NULL || size < 0)
56                 return;
57
58         for (i = 0; i < size; i++) {
59                 if (tp[i].part && tp[i].msgid)
60                         edje_object_part_text_set(eo,
61                                                   tp[i].part, _(tp[i].msgid));
62         }
63 }
64
65 static int _lang_changed(void *data)
66 {
67         struct appdata *ad = data;
68
69         if (ad->ly == NULL)
70                 return 0;
71
72         update_ts(elm_layout_edje_get(ad->ly),
73                   main_txt, sizeof(main_txt) / sizeof(main_txt[0]));
74
75         return 0;
76 }
77
78 int _get_vconf_idlelock(void)
79 {
80         int ret = -1;
81         int lock = IDLELOCK_OFF;
82
83         ret = vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &lock);
84         retvm_if(ret < 0, -1, "Failed to get vconf %s\n",
85                  VCONFKEY_IDLE_LOCK_STATE);
86         _D("idlelock vconf:%d\n", lock);
87
88         return lock == VCONFKEY_IDLE_LOCK ? IDLELOCK_ON : IDLELOCK_OFF;
89 }
90
91 Eina_Bool _exit_cb(void *data)
92 {
93         int lock = IDLELOCK_ON;
94         lock = _get_vconf_idlelock();
95
96         _D("lock(%d)\n", lock);
97         if(lock == IDLELOCK_OFF){
98                 _D("normal case\n");
99                 elm_exit();
100         }
101         else{
102                 _D("IDLELOCK is set, taskmnager doesn't exit\n");
103                 return ECORE_CALLBACK_CANCEL;
104         }
105         return ECORE_CALLBACK_CANCEL;
106 }
107
108 void _key_grab(struct appdata *ad)
109 {
110         int ret = 0;
111         Ecore_X_Window xwin;    /* key grab */
112         Ecore_X_Display *disp;  /* key grab */
113
114         /* Key Grab */
115         disp = ecore_x_display_get();
116         xwin = elm_win_xwindow_get(ad->win);
117
118         ret = utilx_grab_key(disp, xwin, KEY_SELECT, SHARED_GRAB);
119         retm_if(ret < 0, "Failed to grab home key\n");
120 }
121
122 int _set_launch_effect(Evas_Object *win)
123 {
124         Ecore_X_Window xwin = 0;
125         static Ecore_X_Atom ATOM_WM_WINDOW_ROLE = 0;
126         static Ecore_X_Atom ATOM_NET_WM_NAME = 0;
127         retvm_if(win == NULL, -1, "[Error] Invalid argument: win is NULL\n");
128
129         ATOM_WM_WINDOW_ROLE = ecore_x_atom_get("WM_WINDOW_ROLE");
130         if (!ATOM_WM_WINDOW_ROLE) {
131                 fprintf(stderr,
132                         "[App] %s(%d) XInternAtom(WM_WINDOW_ROLE) failed.\n",
133                         __func__, __LINE__);
134         }
135
136         ATOM_NET_WM_NAME = ecore_x_atom_get("_NET_WM_NAME");
137         if (!ATOM_NET_WM_NAME) {
138                 fprintf(stderr,
139                         "[App] %s(%d) XInternAtom(ATOM_NET_WM_NAME) failed.\n",
140                         __func__, __LINE__);
141         }
142
143         xwin = elm_win_xwindow_get(win);
144         ecore_x_window_prop_string_set(xwin, ATOM_WM_WINDOW_ROLE,
145                                        "TASK_MANAGER");
146         ecore_x_window_prop_string_set(xwin, ATOM_NET_WM_NAME, "TASK_MANAGER");
147
148         ecore_x_icccm_name_class_set(xwin, "TASK_MANAGER", "TASK_MANAGER");
149         return 0;
150 }
151
152 int _unset_notification_level(Evas_Object *win)
153 {
154         Ecore_X_Window xwin;
155
156         xwin = elm_win_xwindow_get(win);
157         ecore_x_netwm_window_type_set(xwin, ECORE_X_WINDOW_TYPE_NORMAL);
158         return 0;
159 }
160
161
162 int _set_notification_level(Evas_Object *win, Utilx_Notification_Level level)
163 {
164         Ecore_X_Window xwin = 0;
165
166         xwin = elm_win_xwindow_get(win);
167         ecore_x_netwm_window_type_set(xwin, ECORE_X_WINDOW_TYPE_NOTIFICATION);
168         utilx_set_system_notification_level(ecore_x_display_get(), xwin, level);
169         return 0;
170 }
171
172 int app_create(void *data)
173 {
174         Evas_Object *win;
175         struct appdata *ad = data;
176         int r;
177
178         win = _add_window(PACKAGE);
179         retv_if(win == NULL, -1);
180         elm_win_indicator_mode_set(win, ELM_WIN_INDICATOR_SHOW);
181         ad->win = win;
182
183         _set_launch_effect(win);
184 //      _set_notification_level(win, UTILX_NOTIFICATION_LEVEL_NORMAL);
185
186         /* init internationalization */
187         r = appcore_set_i18n(PACKAGE, LOCALEDIR);
188         retvm_if(r < 0, -1, "Failed to set i18n\n");
189         _lang_changed(ad);
190
191
192         elm_theme_extension_add(NULL, EDJ_THEME);
193
194         _app_create(ad);
195         _set_itc();
196         _set_genlist(ad);
197
198         /* set dead signal listener */
199         aul_listen_app_dead_signal(_dead_cb, ad);
200
201         appcore_set_event_callback(APPCORE_EVENT_LANG_CHANGE,
202                         _lang_changed, ad);
203
204         ecore_idler_add(_create_idler_cb, ad);
205
206         return 0;
207 }
208
209 static int app_terminate(void *data)
210 {
211         return 0;
212 }
213
214 static int app_pause(void *data)
215 {
216         return 0;
217 }
218
219 static int app_resume(void *data)
220 {
221 _D("func\n");
222         struct appdata *ad = data;
223
224         refresh_app_info(ad);
225         if (ad->killall_timer) {
226                 ecore_timer_del(ad->killall_timer);
227                 ad->killall_timer = NULL;
228         }
229         if (ad->exit_timer) {
230                 ecore_timer_del(ad->exit_timer);
231                 ad->exit_timer = NULL;
232         }
233
234         return 0;
235 }
236
237 static int app_reset(bundle *b, void *data)
238 {
239         struct appdata *ad = data;
240
241         /* appcore measure time example */
242         printf("from AUL to %s(): %d msec\n", __func__,
243                         appcore_measure_time_from("APP_START_TIME"));
244         printf("from create to %s(): %d msec\n", __func__,
245                         appcore_measure_time());
246
247         if (ad->win)
248                 elm_win_activate(ad->win);
249         return 0;
250 }
251
252 int main(int argc, char *argv[])
253 {
254         sysconf_set_mempolicy(OOM_IGNORE);
255
256         struct appdata ad;
257         struct appcore_ops ops = {
258                 .create = app_create,
259                 .terminate = app_terminate,
260                 .pause = app_pause,
261                 .resume = app_resume,
262                 .reset = app_reset,
263         };
264
265         /* appcore measure time example */
266         _D("from AUL to %s(): %d msec\n", __func__,
267                appcore_measure_time_from("APP_START_TIME"));
268
269         memset(&ad, 0x0, sizeof(struct appdata));
270         ops.data = &ad;
271
272         return appcore_efl_main(PACKAGE, &argc, &argv, &ops);
273 }