Update changed code
[profile/ivi/taskmanager.git] / src / taskmanager.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 <stdio.h>
21 #include <unistd.h>
22 #include <appcore-efl.h>
23 #include <Elementary.h>
24 #include <Ecore_X.h>
25 #include <utilX.h>
26 #include <vconf.h>
27 #include <aul.h>
28 #include <sysman.h>
29
30 #include "taskmanager.h"
31 #include "_util_log.h"
32 #include "_util_efl.h"
33 #include "_logic.h"
34 #include "_genlist.h"
35
36 struct text_part {
37         char *part;
38         char *msgid;
39 };
40
41 static struct text_part main_txt[] = {
42 };
43
44 static void update_ts(Evas_Object *eo, struct text_part *tp, int size)
45 {
46         int i;
47
48         if (eo == NULL || tp == NULL || size < 0)
49                 return;
50
51         for (i = 0; i < size; i++) {
52                 if (tp[i].part && tp[i].msgid)
53                         edje_object_part_text_set(eo,
54                                                   tp[i].part, _(tp[i].msgid));
55         }
56 }
57
58 static int _lang_changed(void *data)
59 {
60         struct appdata *ad = data;
61
62         if (ad->ly == NULL)
63                 return 0;
64
65         update_ts(elm_layout_edje_get(ad->ly),
66                   main_txt, sizeof(main_txt) / sizeof(main_txt[0]));
67
68         return 0;
69 }
70
71 static int rotate(enum appcore_rm m, void *data)
72 {
73         struct appdata *ad = data;
74         int r;
75
76         if (ad == NULL || ad->win == NULL)
77                 return 0;
78
79         switch (m) {
80         case APPCORE_RM_PORTRAIT_NORMAL:
81                 r = 0;
82                 break;
83         case APPCORE_RM_PORTRAIT_REVERSE:
84                 r = 180;
85                 break;
86         case APPCORE_RM_LANDSCAPE_NORMAL:
87                 r = 270;
88                 break;
89         case APPCORE_RM_LANDSCAPE_REVERSE:
90                 r = 90;
91                 break;
92         default:
93                 r = -1;
94                 break;
95         }
96
97         if (r >= 0)
98                 elm_win_rotation_with_resize_set(ad->win, r);
99
100         return 0;
101 }
102
103 Eina_Bool _exit_cb(void *data)
104 {
105         struct appdata *ad = (struct appdata *)data;
106
107         ad->exit_timer = NULL;
108         elm_exit();
109         return ECORE_CALLBACK_CANCEL;
110 }
111
112 void _key_grab(struct appdata *ad)
113 {
114         int ret = 0;
115         Ecore_X_Window xwin;    /* key grab */
116         Ecore_X_Display *disp;  /* key grab */
117
118         /* Key Grab */
119         disp = ecore_x_display_get();
120         xwin = elm_win_xwindow_get(ad->win);
121
122         ret = utilx_grab_key(disp, xwin, KEY_SELECT, SHARED_GRAB);
123         retm_if(ret < 0, "Failed to grab home key\n");
124 }
125
126 int _set_launch_effect(Evas_Object *win)
127 {
128         Ecore_X_Window xwin = 0;
129         static Ecore_X_Atom ATOM_WM_WINDOW_ROLE = 0;
130         static Ecore_X_Atom ATOM_NET_WM_NAME = 0;
131         retvm_if(win == NULL, -1, "[Error] Invalid argument: win is NULL\n");
132
133         ATOM_WM_WINDOW_ROLE = ecore_x_atom_get("WM_WINDOW_ROLE");
134         if (!ATOM_WM_WINDOW_ROLE) {
135                 fprintf(stderr,
136                         "[App] %s(%d) XInternAtom(WM_WINDOW_ROLE) failed.\n",
137                         __func__, __LINE__);
138         }
139
140         ATOM_NET_WM_NAME = ecore_x_atom_get("_NET_WM_NAME");
141         if (!ATOM_NET_WM_NAME) {
142                 fprintf(stderr,
143                         "[App] %s(%d) XInternAtom(ATOM_NET_WM_NAME) failed.\n",
144                         __func__, __LINE__);
145         }
146
147         xwin = elm_win_xwindow_get(win);
148         ecore_x_window_prop_string_set(xwin, ATOM_WM_WINDOW_ROLE,
149                                        "TASK_MANAGER");
150         ecore_x_window_prop_string_set(xwin, ATOM_NET_WM_NAME, "TASK_MANAGER");
151
152         ecore_x_icccm_name_class_set(xwin, "TASK_MANAGER", "TASK_MANAGER");
153         return 0;
154 }
155
156 int _unset_notification_level(Evas_Object *win)
157 {
158         Ecore_X_Window xwin;
159
160         xwin = elm_win_xwindow_get(win);
161         ecore_x_netwm_window_type_set(xwin, ECORE_X_WINDOW_TYPE_NORMAL);
162         return 0;
163 }
164
165
166 int _set_notification_level(Evas_Object *win, Utilx_Notification_Level level)
167 {
168         Ecore_X_Window xwin = 0;
169
170         xwin = elm_win_xwindow_get(win);
171         ecore_x_netwm_window_type_set(xwin, ECORE_X_WINDOW_TYPE_NOTIFICATION);
172         utilx_set_system_notification_level(ecore_x_display_get(), xwin, level);
173         return 0;
174 }
175
176 int app_create(void *data)
177 {
178         Evas_Object *win;
179         struct appdata *ad = data;
180         int r;
181
182         win = _add_window(PACKAGE);
183         retv_if(win == NULL, -1);
184         elm_win_indicator_mode_set(win, ELM_WIN_INDICATOR_SHOW);
185         ad->win = win;
186
187         _set_launch_effect(win);
188 //      _set_notification_level(win, UTILX_NOTIFICATION_LEVEL_NORMAL);
189
190         elm_theme_extension_add(NULL, EDJ_THEME);
191
192         _app_create(ad);
193         _set_itc();
194         _set_genlist(ad);
195
196         /* set dead signal listener */
197         aul_listen_app_dead_signal(_dead_cb, ad);
198
199         /* init internationalization */
200         r = appcore_set_i18n(PACKAGE, LOCALEDIR);
201         retvm_if(r < 0, -1, "Failed to set i18n\n");
202         _lang_changed(ad);
203
204         appcore_set_event_callback(APPCORE_EVENT_LANG_CHANGE,
205                         _lang_changed, ad);
206
207         _restart_pthread(ad);
208         ecore_idler_add(_create_idler_cb, ad);
209
210         return 0;
211 }
212
213 static int app_terminate(void *data)
214 {
215 _D("func\n");
216         struct appdata *ad = data;
217 //      sleep(1);
218 //      ecore_timer_add(0.2, _exit_cb, NULL);
219
220         return 0;
221 }
222
223 static int app_pause(void *data)
224 {
225 _D("func\n");
226         _fini_pthread();
227         return 0;
228 }
229
230 static int app_resume(void *data)
231 {
232 _D("func\n");
233         struct appdata *ad = data;
234
235         if (ad->exit_timer) {
236                 ecore_timer_del(ad->exit_timer);
237                 ad->exit_timer = NULL;
238         }
239
240         return 0;
241 }
242
243 static int app_reset(bundle *b, void *data)
244 {
245         struct appdata *ad = data;
246
247         /* appcore measure time example */
248         printf("from AUL to %s(): %d msec\n", __func__,
249                         appcore_measure_time_from("APP_START_TIME"));
250         printf("from create to %s(): %d msec\n", __func__,
251                         appcore_measure_time());
252
253         if (ad->win)
254                 elm_win_activate(ad->win);
255         return 0;
256 }
257
258 int main(int argc, char *argv[])
259 {
260         sysconf_set_mempolicy(OOM_IGNORE);
261
262         struct appdata ad;
263         struct appcore_ops ops = {
264                 .create = app_create,
265                 .terminate = app_terminate,
266                 .pause = app_pause,
267                 .resume = app_resume,
268                 .reset = app_reset,
269         };
270
271         /* appcore measure time example */
272         _D("from AUL to %s(): %d msec\n", __func__,
273                appcore_measure_time_from("APP_START_TIME"));
274
275         memset(&ad, 0x0, sizeof(struct appdata));
276         ops.data = &ad;
277
278         return appcore_efl_main(PACKAGE, &argc, &argv, &ops);
279 }