Remove SMACK rule file(.rule) according three domain model
[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.1 (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 enum {
49         LCD_OFF = 0x0,
50         LCD_ON,
51         LCD_MAX,
52 };
53
54 static struct text_part main_txt[] = {
55 };
56
57 static void update_ts(Evas_Object *eo, struct text_part *tp, int size)
58 {
59         int i;
60
61         if (eo == NULL || tp == NULL || size < 0)
62                 return;
63
64         for (i = 0; i < size; i++) {
65                 if (tp[i].part && tp[i].msgid)
66                         edje_object_part_text_set(eo,
67                                                   tp[i].part, _(tp[i].msgid));
68         }
69 }
70
71 static int _lang_changed(void *data)
72 {
73         struct appdata *ad = data;
74
75         if (ad->ly == NULL)
76                 return 0;
77
78         update_ts(elm_layout_edje_get(ad->ly),
79                   main_txt, sizeof(main_txt) / sizeof(main_txt[0]));
80
81         return 0;
82 }
83
84 int _get_vconf_idlelock(void)
85 {
86         int ret = -1;
87         int lock = IDLELOCK_OFF;
88
89         ret = vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &lock);
90         retvm_if(ret < 0, -1, "Failed to get vconf\n");
91         _D("idlelock vconf:%d\n", lock);
92
93         return lock == VCONFKEY_IDLE_LOCK ? IDLELOCK_ON : IDLELOCK_OFF;
94 }
95
96 int _get_vconf_lcdstate(void)
97 {
98         int ret = -1;
99         int lcd = 0;
100
101         ret = vconf_get_int(VCONFKEY_PM_STATE, &lcd);
102         retvm_if(ret < 0, -1, "Failed to get vconf\n");
103         _D("lcd vconf:%d\n", lcd);
104
105         return lcd == VCONFKEY_PM_STATE_LCDOFF ? LCD_OFF : LCD_ON;
106 }
107
108 Eina_Bool _exit_cb(void *data)
109 {
110         int lock = IDLELOCK_ON;
111         lock = _get_vconf_idlelock();
112
113         _D("lock(%d)\n", lock);
114         if(lock == IDLELOCK_OFF){
115                 _D("normal case\n");
116                 elm_exit();
117         }
118         else{
119                 _D("IDLELOCK is set, taskmnager doesn't exit\n");
120                 return ECORE_CALLBACK_CANCEL;
121         }
122         return ECORE_CALLBACK_CANCEL;
123 }
124
125 void _key_grab(struct appdata *ad)
126 {
127         int ret = 0;
128         Ecore_X_Window xwin;    /* key grab */
129         Ecore_X_Display *disp;  /* key grab */
130
131         /* Key Grab */
132         disp = ecore_x_display_get();
133         xwin = elm_win_xwindow_get(ad->win);
134
135         ret = utilx_grab_key(disp, xwin, KEY_SELECT, SHARED_GRAB);
136         retm_if(ret < 0, "Failed to grab home key\n");
137 }
138
139 int _set_launch_effect(Evas_Object *win)
140 {
141         Ecore_X_Window xwin = 0;
142         static Ecore_X_Atom ATOM_WM_WINDOW_ROLE = 0;
143         static Ecore_X_Atom ATOM_NET_WM_NAME = 0;
144         retvm_if(win == NULL, -1, "[Error] Invalid argument: win is NULL\n");
145
146         ATOM_WM_WINDOW_ROLE = ecore_x_atom_get("WM_WINDOW_ROLE");
147         if (!ATOM_WM_WINDOW_ROLE) {
148                 fprintf(stderr,
149                         "[App] %s(%d) XInternAtom(WM_WINDOW_ROLE) failed.\n",
150                         __func__, __LINE__);
151         }
152
153         ATOM_NET_WM_NAME = ecore_x_atom_get("_NET_WM_NAME");
154         if (!ATOM_NET_WM_NAME) {
155                 fprintf(stderr,
156                         "[App] %s(%d) XInternAtom(ATOM_NET_WM_NAME) failed.\n",
157                         __func__, __LINE__);
158         }
159
160         xwin = elm_win_xwindow_get(win);
161         ecore_x_window_prop_string_set(xwin, ATOM_WM_WINDOW_ROLE,
162                                        "TASK_MANAGER");
163         ecore_x_window_prop_string_set(xwin, ATOM_NET_WM_NAME, "TASK_MANAGER");
164
165         ecore_x_icccm_name_class_set(xwin, "TASK_MANAGER", "TASK_MANAGER");
166         return 0;
167 }
168
169 int _unset_notification_level(Evas_Object *win)
170 {
171         Ecore_X_Window xwin;
172
173         xwin = elm_win_xwindow_get(win);
174         ecore_x_netwm_window_type_set(xwin, ECORE_X_WINDOW_TYPE_NORMAL);
175         return 0;
176 }
177
178
179 int _set_notification_level(Evas_Object *win, Utilx_Notification_Level level)
180 {
181         Ecore_X_Window xwin = 0;
182
183         xwin = elm_win_xwindow_get(win);
184         ecore_x_netwm_window_type_set(xwin, ECORE_X_WINDOW_TYPE_NOTIFICATION);
185         utilx_set_system_notification_level(ecore_x_display_get(), xwin, level);
186         return 0;
187 }
188
189 void _check_show_state(void)
190 {
191         int lcd = LCD_OFF, idlelock = IDLELOCK_OFF;
192         lcd = _get_vconf_lcdstate();
193         idlelock = _get_vconf_idlelock();
194         if(lcd == LCD_OFF || idlelock == IDLELOCK_ON)
195         {
196                 elm_exit();
197         }
198 }
199
200 int app_create(void *data)
201 {
202         Evas_Object *win;
203         struct appdata *ad = data;
204         int r;
205
206         win = _add_window(PACKAGE);
207         retv_if(win == NULL, -1);
208         elm_win_indicator_mode_set(win, ELM_WIN_INDICATOR_SHOW);
209         ad->win = win;
210
211         _set_launch_effect(win);
212 //      _set_notification_level(win, UTILX_NOTIFICATION_LEVEL_NORMAL);
213
214         /* init internationalization */
215         r = appcore_set_i18n(PACKAGE, LOCALEDIR);
216         retvm_if(r < 0, -1, "Failed to set i18n\n");
217         _lang_changed(ad);
218
219
220         elm_theme_extension_add(NULL, EDJ_THEME);
221
222         _app_create(ad);
223         _set_itc();
224         _set_genlist(ad);
225
226         /* set dead signal listener */
227         aul_listen_app_dead_signal(_dead_cb, ad);
228
229         appcore_set_event_callback(APPCORE_EVENT_LANG_CHANGE,
230                         _lang_changed, ad);
231
232         ecore_idler_add(_create_idler_cb, ad);
233
234         return 0;
235 }
236
237 static int app_terminate(void *data)
238 {
239         return 0;
240 }
241
242 static int app_pause(void *data)
243 {
244         return 0;
245 }
246
247 static int app_resume(void *data)
248 {
249 _D("func\n");
250         struct appdata *ad = data;
251
252         refresh_app_info(ad);
253         if (ad->killall_timer) {
254                 ecore_timer_del(ad->killall_timer);
255                 ad->killall_timer = NULL;
256         }
257         if (ad->exit_timer) {
258                 ecore_timer_del(ad->exit_timer);
259                 ad->exit_timer = NULL;
260         }
261
262         return 0;
263 }
264
265 static int app_reset(bundle *b, void *data)
266 {
267         struct appdata *ad = data;
268
269         /* appcore measure time example */
270         printf("from AUL to %s(): %d msec\n", __func__,
271                         appcore_measure_time_from("APP_START_TIME"));
272         printf("from create to %s(): %d msec\n", __func__,
273                         appcore_measure_time());
274
275         if (ad->win)
276                 elm_win_activate(ad->win);
277         return 0;
278 }
279
280 int main(int argc, char *argv[])
281 {
282         sysconf_set_mempolicy(OOM_IGNORE);
283
284         struct appdata ad;
285         struct appcore_ops ops = {
286                 .create = app_create,
287                 .terminate = app_terminate,
288                 .pause = app_pause,
289                 .resume = app_resume,
290                 .reset = app_reset,
291         };
292
293         /* appcore measure time example */
294         _D("from AUL to %s(): %d msec\n", __func__,
295                appcore_measure_time_from("APP_START_TIME"));
296
297         memset(&ad, 0x0, sizeof(struct appdata));
298         ops.data = &ad;
299
300         return appcore_efl_main(PACKAGE, &argc, &argv, &ops);
301 }