tizen 2.3 release
[apps/home/settings.git] / src / personal_mode_util / setting_personal_mode.c
1 /*
2  * setting_personal_mode
3  *
4  *
5  *
6  */
7 #include <setting-debug.h>
8 #include <setting-common-draw-widget.h>
9 #include <setting-common-general-func.h>
10 #include <stdio.h>
11 #include <Elementary.h>
12 #include <efl_assist.h>
13 #include <vconf.h>
14 #include <app.h>
15 #include <Ecore_X.h>
16 #include <ode.h>
17 #include <notification.h>
18 #include <ui-gadget.h>
19
20 #define EXPORT_PUBLIC __attribute__ ((visibility ("default")))
21
22 typedef struct _personal_mode_data {
23         ui_gadget_h ug;
24         Evas *evas;
25         Evas_Object *win;
26         Evas_Object *ly_main;
27
28         Evas_Object *popup;
29         Evas_Object *check;
30 } personal_mode_data;
31
32 static void personal_mode_terminate(void *data)
33 {
34         SETTING_TRACE_BEGIN;
35
36         ret_if(data == NULL);
37         personal_mode_data *ad = (personal_mode_data *) data;
38
39         if(ad->popup)
40         {
41                 evas_object_del(ad->popup);
42                 ad->popup = NULL;
43         }
44
45         if(ad->ly_main)
46         {
47                 evas_object_del(ad->ly_main);
48                 ad->ly_main = NULL;
49         }
50
51         if(ad->win)
52         {
53                 evas_object_del(ad->win);
54                 ad->win = NULL;
55         }
56         
57         elm_exit();
58 }
59
60 static void __del_cb(void *data, Evas_Object *obj, void *event)
61 {
62         elm_exit();
63 }
64
65 void personal_mode_unmount(void *data)
66 {
67         SETTING_TRACE_BEGIN;
68         ret_if(data == NULL);
69         personal_mode_data *ad = (personal_mode_data *) data;
70
71         // unmount
72         if(ode_init() != 0)
73         {
74                 SETTING_TRACE("change #1. init failed");
75                 setting_create_simple_popup(ad, ad->win, NULL, "Fail to change unlock method");
76                 return;
77         }
78         if(pse_unmount() != 0)
79         {
80                 SETTING_TRACE("change #2. unmount failed");
81                 setting_create_simple_popup(ad, ad->win, NULL, "Fail to change unlock method");
82                 ode_deinit();
83                 return;
84         }
85         ode_deinit();
86
87         vconf_set_bool(VCONFKEY_SETAPPL_PERSONAL_MODE_STATUS_BOOL, 0);
88         notification_delete_all_by_type("org.tizen.setting.personal", NOTIFICATION_VARIABLE_TYPE_NONE);
89         // 1 line notification on the notification bar.
90         notification_status_message_post(_("IDS_ST_TPOP_PERSONAL_MODE_DISABLED_ABB"));
91 }
92
93 static Evas_Object* personal_mode_create_window(const char *name, bool transparent)
94 {
95         SETTING_TRACE_BEGIN;
96
97         Evas_Object *eo;
98         int w, h;
99
100         eo = elm_win_add(NULL, name, ELM_WIN_BASIC);
101         if(eo)
102         {
103                 elm_win_title_set(eo, name);
104                 elm_win_conformant_set(eo, EINA_TRUE);
105
106                 if(transparent)
107                 {
108                         SETTING_TRACE_DEBUG("set transparent");
109
110                         elm_win_alpha_set(eo, EINA_TRUE);
111
112                         unsigned int opaqueVal = 1;
113                         Ecore_X_Atom opaqueAtom = ecore_x_atom_get("_E_ILLUME_WINDOW_REGION_OPAQUE");
114                         Ecore_X_Window xwin = elm_win_xwindow_get(eo);
115                         ecore_x_window_prop_card32_set(xwin, opaqueAtom, &opaqueVal, 1);
116                 }
117
118                 evas_object_smart_callback_add(eo, "delete,request", __del_cb, NULL);
119                 ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
120                 evas_object_resize(eo, w, h);
121
122                 elm_win_indicator_mode_set(eo, ELM_WIN_INDICATOR_SHOW);
123                 elm_win_indicator_opacity_set(eo, ELM_WIN_INDICATOR_OPAQUE);
124
125                 if(elm_win_wm_rotation_supported_get(eo))
126                 {
127                         const int rots[4] = {0, 90, 180, 270};
128                         elm_win_wm_rotation_available_rotations_set(eo, (const int*)&rots, 4);
129                 }
130                 SETTING_TRACE_DEBUG("win layer : %d", elm_win_layer_get(eo));
131         }
132         return eo;
133 }
134
135 static Evas_Object* personal_mode_create_layout(Evas_Object *win)
136 {
137         SETTING_TRACE_BEGIN;
138         Evas_Object *eo = elm_layout_add(win);
139         if(eo)
140         {
141                 evas_object_size_hint_weight_set(eo, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
142                 elm_layout_theme_set(eo, "layout", "application", "default");
143                 evas_object_show(eo);
144
145                 Evas_Object *conform = elm_conformant_add(win);
146                 evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
147                 evas_object_size_hint_align_set(conform, EVAS_HINT_FILL, EVAS_HINT_FILL);
148                 elm_win_resize_object_add(win, conform);
149                 elm_object_content_set(conform, eo);
150                 evas_object_show(conform);
151         }
152         return eo;
153 }
154
155 void personal_mode_destroy_ug_cb(ui_gadget_h ug, void *priv)
156 {
157         personal_mode_data *ad = (personal_mode_data *) priv;
158         if (!ad)
159                 return;         /*  do nothing if ad is NULL */
160
161         //elm_win_lower(ad->win);
162
163         if (ug) {
164                 setting_ug_destroy(ug);
165                 ad->ug = NULL;
166         }
167 }
168
169 void personal_mode_end_ug_cb(ui_gadget_h ug, void *priv)
170 {
171         if(!ug)
172                 return;
173         personal_mode_data *ad = (personal_mode_data *) priv;
174         if (!ad)
175                 return;         /*  do nothing if ad is NULL */
176         personal_mode_terminate(ad);
177 }
178
179 void personal_mode_layout_ug_cb(ui_gadget_h ug, enum ug_mode mode,
180                                       void *priv)
181 {
182         Evas_Object *base;
183
184         base = (Evas_Object *) ug_get_layout(ug);
185         if (!base)
186                 return;
187
188         switch (mode) {
189         case UG_MODE_FULLVIEW:
190                 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
191                                                  EVAS_HINT_EXPAND);
192                 ug_disable_effect(ug);
193                 evas_object_show(base);
194                 break;
195         default:
196                 break;
197         }
198 }
199
200 static void personal_mode_popup_cb(void *data, Evas_Object *obj, void *event)
201 {
202         SETTING_TRACE_BEGIN;
203         personal_mode_data *ad = data;
204
205         char *btn_str = elm_entry_markup_to_utf8(elm_object_text_get(obj));
206         if(!strcmp(btn_str, _("IDS_COM_SK_OK")))
207         {
208                 if(ad->check)
209                 {
210                         int status = elm_check_state_get(ad->check);
211                         vconf_set_bool("db/setting/personal_off_popup_do_not_show_flag", status);       
212                 }
213                 personal_mode_unmount(ad);
214         }
215
216         personal_mode_terminate(ad);
217 }
218
219 static bool personal_mode_create(void *data)
220 {
221         SETTING_TRACE_BEGIN;
222         
223         return true;
224 }
225
226 static void personal_mode_service(app_control_h service, void *data)
227 {
228         SETTING_TRACE_BEGIN;
229
230         personal_mode_data *ad = (personal_mode_data *)data;
231
232         int     curStatus = 0;
233         int     popupOption = 0;
234         char    *viewtype = NULL;
235
236         // get current personal mode
237         vconf_get_bool(VCONFKEY_SETAPPL_PERSONAL_MODE_STATUS_BOOL, &curStatus);
238
239         // get <do not show again> option
240         vconf_get_bool("db/setting/personal_off_popup_do_not_show_flag", &popupOption);
241
242         // check viewtype as "unlock_method"
243         app_control_get_extra_data(service, "viewtype", &viewtype);
244
245         // try to OFF  
246         if(curStatus && !safeStrCmp(viewtype, "unlock_method"))
247         {
248                 if(popupOption)
249                 {
250                         // just unmount and exist
251                         personal_mode_unmount(ad);
252                         personal_mode_terminate(ad);
253                 }
254                 else
255                 {
256                         // create transparent window and popup
257                         ad->win = personal_mode_create_window("personal_mode", 1);
258                         UG_INIT_EFL(ad->win, UG_OPT_INDICATOR_ENABLE);
259                         ad->evas = evas_object_evas_get(ad->win);
260
261                         ad->ly_main = personal_mode_create_layout(ad->win);
262                         evas_object_show(ad->win);
263                         elm_win_activate(ad->win);
264
265                         ad->popup = setting_create_popup_with_label_check(ad, ad->win, NULL,
266                                                                                 _("IDS_ST_POP_ANY_PERSONAL_CONTENT_WILL_NOT_BE_ACCESSIBLE_IN_NORMAL_MODE"),
267                                                                                 _("IDS_ST_BODY_DO_NOT_SHOW_AGAIN"), &(ad->check), personal_mode_popup_cb, 
268                                                                                 0, 2, "IDS_COM_SK_CANCEL", "IDS_COM_SK_OK");
269                         evas_object_show(ad->popup);
270                 }
271         }
272         else
273         {
274                 // create normal window and create ug with service
275                 ad->win = personal_mode_create_window("personal_mode", 1);
276
277                 UG_INIT_EFL(ad->win, UG_OPT_INDICATOR_ENABLE);
278                 ad->evas = evas_object_evas_get(ad->win);
279
280                 ad->ly_main = personal_mode_create_layout(ad->win);
281                 evas_object_show(ad->win);
282                 elm_win_activate(ad->win);
283
284                 // ug_create
285                 struct ug_cbs *cbs = (struct ug_cbs *)calloc(1, sizeof(struct ug_cbs));
286                 if(!cbs)
287                 {
288                         personal_mode_terminate(ad);
289                         return;
290                 }
291                 cbs->layout_cb = personal_mode_layout_ug_cb;
292                 cbs->result_cb = NULL;
293                 cbs->destroy_cb = personal_mode_destroy_ug_cb;
294                 cbs->end_cb = personal_mode_end_ug_cb;
295                 cbs->priv = (void *)ad;
296
297                 ad->ug = setting_ug_create(NULL, "setting-personalpage-efl", UG_MODE_FULLVIEW, service, cbs);
298         }
299         FREE(viewtype);
300
301         SETTING_TRACE_END;
302 }
303
304 static void personal_mode_pause(void *data)
305 {
306         SETTING_TRACE_BEGIN;
307 }
308
309 /**
310 * The function is called when Setting begins run in forground from background
311 */
312 static void personal_mode_resume(void *data)
313 {
314         SETTING_TRACE_BEGIN;
315 }
316
317 EXPORT_PUBLIC
318 int main(int argc, char* argv[])
319 {
320         SETTING_TRACE_BEGIN;
321         personal_mode_data ad;
322
323         elm_init(argc, argv);
324
325         app_event_callback_s ops = {0,};
326         ops.create = personal_mode_create;
327         ops.terminate = personal_mode_terminate;
328         ops.pause = personal_mode_pause;
329         ops.resume = personal_mode_resume;
330         ops.app_control = personal_mode_service;
331
332         memset(&ad, 0x00, sizeof(personal_mode_data));
333         
334         int ret = app_efl_main(&argc, &argv, &ops, &ad);
335         retvm_if(ret == -1, -1, "App returns -1");
336
337         SETTING_TRACE_END;
338         return 0;
339 }
340