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