tizen 2.3 release
[apps/home/b2-clocksetting.git] / src / setting-privacy.c
1 /*
2  * Copyright (c) 2010 Samsung Electronics, Inc.
3  * All rights reserved.
4  *
5  * This software is a confidential and proprietary information
6  * of Samsung Electronics, Inc. ("Confidential Information").  You
7  * shall not disclose such Confidential Information and shall use
8  * it only in accordance with the terms of the license agreement
9  * you entered into with Samsung Electronics.
10  */
11 /*
12  * setting-privacy.c
13  *
14  *  Created on: Jan 7, 2014
15  *      Author: Sunyeop Hwang
16  */
17
18
19 #include "setting-privacy.h"
20 #include "setting_data_vconf.h"
21 #include "util.h"
22
23 static void _privacy_lock_cb(void *data, Evas_Object *obj, void *event_info);
24 static void _privacy_see_pattern_cb(void *data, Evas_Object *obj, void *event_info);
25 static void _privacy_help_cb(void *data, Evas_Object *obj, void *event_info);
26 static void _privacy_pattern_enable_cb(void *data, Evas_Object *obj, void *event_info);
27 static void _privacy_pattern_disable_cb(void *data, Evas_Object *obj, void *event_info);
28 static void _create_privacy_pattern_list(void *data);
29
30 static struct _privacy_menu_item privacy_menu_list[] = {
31         { "IDS_LCKSCN_BODY_PRIVACY_LOCK_ABB",   _privacy_lock_cb },
32         { "IDS_ST_MBODY_HELP",                  _privacy_help_cb }
33 };
34
35
36 static struct _privacy_menu_item privacy_pattern_menu_list[] = {
37         { "IDS_LCKSCN_HEADER_PIN",      _privacy_pattern_enable_cb },
38         { "IDS_LCKSCN_BODY_NONE",       _privacy_pattern_disable_cb }
39 };
40
41 static char *lock_type_str[] = {
42                 "IDS_LCKSCN_BODY_NONE",
43                 "IDS_LCKSCN_HEADER_PIN"
44 };
45
46 static Evas_Object *g_privacy_genlist = NULL;
47
48 int _get_lock_type_value()
49 {
50         int value = 0;
51         if (vconf_get_int("db/setting/lock_type", &value) != 0) {
52                 ERR("error get vconf value!!");
53         }
54         return value;
55 }
56
57 int _set_lock_type_value(int value)
58 {
59         if (vconf_set_int("db/setting/lock_type", value) != 0) {
60                 ERR("error set vconf value!!");
61                 return FALSE;
62         }
63         return TRUE;
64 }
65
66 int _get_see_pattern_value()
67 {
68         int value = 0;
69         if (vconf_get_bool("db/setting/see_pattern", &value) != 0) {
70                 ERR("error get vconf value!!");
71         }
72         return value;
73 }
74
75 int _set_see_pattern_value(int value)
76 {
77         if (vconf_set_bool("db/setting/see_pattern", value) != 0) {
78                 ERR("error set vconf value!!");
79                 return FALSE;
80         }
81         return TRUE;
82 }
83
84 static void _privacy_lock_setting_cb(app_control_h service, app_control_h reply, app_control_result_e result, void *data)
85 {
86         appdata *ad = data;
87         if (!ad) {
88                 ERR("appdata is null");
89                 return;
90         }
91
92         if (result == APP_CONTROL_RESULT_SUCCEEDED) {
93                 _set_lock_type_value(1);
94                 elm_naviframe_item_pop(ad->nf);
95
96                 if (g_privacy_genlist) {
97                         elm_genlist_realized_items_update(g_privacy_genlist);
98                 }
99         }
100 }
101
102 static void _privacy_lock_verify_cb(app_control_h service, app_control_h reply, app_control_result_e result, void *data)
103 {
104         appdata *ad = data;
105         if (!ad) {
106                 ERR("appdata is null");
107                 return;
108         }
109
110         if (result == APP_CONTROL_RESULT_SUCCEEDED) {
111                 _create_privacy_pattern_list(ad);
112         }
113 }
114
115 static void _gl_privacy_del(void *data, Evas_Object *obj)
116 {
117         Privacy_Item_Data *id = data;
118         if (id)
119                 free(id);
120 }
121
122 char *_gl_privacy_pattern_title_get(void *data, Evas_Object *obj, const char *part)
123 {
124         char buf[1024];
125         Item_Data *id = data;
126         int index = id->index;
127         char * device_info = NULL;
128
129         if (!strcmp(part, "elm.text")) {
130                 snprintf(buf, sizeof(buf)-1, "%s", _(privacy_pattern_menu_list[index].name));
131         }
132
133         return strdup(buf);
134 }
135
136 static void _privacy_pattern_enable_cb(void *data, Evas_Object *obj, void *event_info)
137 {
138         elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
139
140         appdata *ad = data;
141         if (!ad) {
142                 ERR("appdata is null");
143                 return;
144         }
145
146         app_control_h service;
147         app_control_create(&service);
148         app_control_set_app_id(service, "org.tizen.w-lockscreen-setting");
149
150         app_control_add_extra_data(service, "type", "setting");
151         app_control_send_launch_request(service, _privacy_lock_setting_cb, ad);
152         app_control_destroy(service);
153 }
154
155 static void _privacy_pattern_disable_cb(void *data, Evas_Object *obj, void *event_info)
156 {
157         elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
158
159         appdata *ad = data;
160         if (!ad) {
161                 ERR("appdata is null");
162                 return;
163         }
164
165         _set_lock_type_value(0);
166         elm_naviframe_item_pop(ad->nf);
167
168         if (g_privacy_genlist) {
169                 elm_genlist_realized_items_update(g_privacy_genlist);
170         }
171 }
172
173 static void _create_privacy_pattern_list(void *data)
174 {
175         appdata *ad = data;
176
177         if (!ad) {
178                 ERR("appdata is null!!");
179                 return;
180         }
181
182         Evas_Object *genlist = NULL;
183         Evas_Object *layout = NULL;
184         Elm_Object_Item *nf_it = NULL;
185         struct _privacy_menu_item *menu_list = NULL;
186         int idx = 0;
187
188         Elm_Genlist_Item_Class *itc = elm_genlist_item_class_new();
189         itc->item_style = "1text";
190         itc->func.text_get = _gl_privacy_pattern_title_get;
191         itc->func.del = _gl_privacy_del;
192
193         layout = elm_layout_add(ad->nf);
194         elm_layout_file_set(layout, EDJE_PATH, "setting/genlist/layout");
195         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
196
197         genlist = elm_genlist_add(layout);
198         elm_genlist_block_count_set(genlist, 14);
199
200         menu_list = privacy_pattern_menu_list;
201
202         for (idx = 0; idx < sizeof(privacy_pattern_menu_list) / sizeof(struct _privacy_menu_item); idx++) {
203                 Privacy_Item_Data *id = calloc(sizeof(Privacy_Item_Data), 1);
204                 id->index = idx;
205                 id->item = elm_genlist_item_append(
206                                 genlist,                // genlist object
207                                 itc,                    // item class
208                                 id,                     // data
209                                 NULL,
210                                 ELM_GENLIST_ITEM_NONE,
211                                 menu_list[idx].func,    // call back
212                                 ad);
213         }
214
215         elm_genlist_item_class_free(itc);
216
217         elm_object_part_content_set(layout, "elm.genlist", genlist);
218
219         nf_it = elm_naviframe_item_push(ad->nf, NULL, NULL, NULL, layout, NULL);
220         elm_naviframe_item_title_enabled_set(nf_it, EINA_FALSE, EINA_FALSE);
221 }
222
223 char *_gl_privacy_title_get(void *data, Evas_Object *obj, const char *part)
224 {
225         char buf[1024];
226         Item_Data *id = data;
227         int index = id->index;
228         char * device_info = NULL;
229
230         if (!strcmp(part, "elm.text.1") || !strcmp(part, "elm.text")) {
231                 snprintf(buf, sizeof(buf)-1, "%s", _(privacy_menu_list[index].name));
232         } else if (!strcmp(part, "elm.text.2")) {
233                 snprintf(buf, sizeof(buf)-1, "%s", _(lock_type_str[_get_lock_type_value()]));
234         }
235
236         return strdup(buf);
237 }
238
239 Evas_Object *_gl_privacy_content_get(void *data, Evas_Object *obj, const char *part)
240 {
241         Evas_Object *check = NULL;
242
243         Privacy_Item_Data *id = data;
244
245         if (!strcmp(part, "elm.icon")) {
246                 check = elm_check_add(obj);
247                 elm_check_state_set(check, (_get_see_pattern_value()) ? EINA_TRUE : EINA_FALSE);
248                 //evas_object_smart_callback_add(check, "changed", _see_pattern_chk_changed_cb, (void *)1);
249                 evas_object_size_hint_align_set(check, EVAS_HINT_FILL, EVAS_HINT_FILL);
250                 evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
251
252                 id->check = check;
253         }
254         return check;
255 }
256
257 static void _privacy_lock_cb(void *data, Evas_Object *obj, void *event_info)
258 {
259         elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
260
261         appdata *ad = data;
262         if (!ad) {
263                 ERR("appdata is null");
264                 return;
265         }
266
267         if (!_get_lock_type_value()) {
268                 _create_privacy_pattern_list(ad);
269         } else {
270                 app_control_h service;
271                 app_control_create(&service);
272                 app_control_set_app_id(service, "org.tizen.w-lockscreen-setting");
273
274                 app_control_add_extra_data(service, "type", "verify");
275                 app_control_send_launch_request(service, _privacy_lock_verify_cb, ad);
276                 app_control_destroy(service);
277         }
278 }
279
280 void _create_help_popup(void *data)
281 {
282         Evas_Object *popup = NULL;
283         Evas_Object *btn = NULL;
284         Evas_Object *scroller = NULL;
285         Evas_Object *label = NULL;
286
287         appdata *ad = (appdata *) data;
288         if( ad == NULL )
289                 return;
290
291         popup = elm_popup_add(ad->nf);
292         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
293         elm_object_translatable_part_text_set(popup, "title,text", "IDS_ST_MBODY_HELP");
294
295         ad->popup = popup;
296
297         scroller = elm_scroller_add(popup);
298         evas_object_size_hint_weight_set(scroller, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
299         elm_scroller_bounce_set(scroller, EINA_FALSE, EINA_TRUE);
300         elm_scroller_policy_set(scroller, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
301         elm_object_style_set(scroller, "effect");
302         elm_object_content_set(popup, scroller);
303         evas_object_show(scroller);
304
305         label = elm_label_add(scroller);
306         elm_object_style_set(label, "popup/default");
307         elm_label_line_wrap_set(label, ELM_WRAP_MIXED);
308         elm_object_translatable_text_set(label, "IDS_LCKSCN_BODY_THE_PRIVACY_LOCK_OPTION_WILL_BE_SHOWN_WHEN_BLUETOOTH_IS_DISCONNECTED");
309
310         evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0.0);
311         evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
312         elm_object_content_set(scroller, label);
313         evas_object_show(label);
314
315         ea_object_event_callback_add(popup, EA_CALLBACK_BACK, setting_popup_back_cb, ad);
316
317         evas_object_show(popup);
318 }
319
320 static void _privacy_help_cb(void *data, Evas_Object *obj, void *event_info)
321 {
322         elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
323
324         appdata *ad = data;
325         if( ad == NULL )
326         {
327                 DBG("%s", "_privcay_help_cb - ad is null");
328                 return;
329         }
330
331         _create_help_popup(ad);
332 }
333
334 Evas_Object *create_privacy_list(void *data)
335 {
336         appdata *ad = data;
337
338         if (!ad) {
339                 ERR("appdata is null!!");
340                 return NULL;
341         }
342
343         Evas_Object *genlist = NULL;
344         Evas_Object *layout = NULL;
345         struct _privacy_menu_item *menu_list = NULL;
346         int idx = 0;
347
348         Elm_Genlist_Item_Class *itc = NULL;
349
350         Elm_Genlist_Item_Class *itc_2text = elm_genlist_item_class_new();
351         itc_2text->item_style = "2text";
352         itc_2text->func.text_get = _gl_privacy_title_get;
353         itc_2text->func.del = _gl_privacy_del;
354
355         Elm_Genlist_Item_Class *itc_1text = elm_genlist_item_class_new();
356         itc_1text->item_style = "1text";
357         itc_1text->func.text_get = _gl_privacy_title_get;
358         itc_1text->func.del = _gl_privacy_del;
359
360         layout = elm_layout_add(ad->nf);
361         elm_layout_file_set(layout, EDJE_PATH, "setting/genlist/layout");
362         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
363
364         genlist = elm_genlist_add(layout);
365         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
366         //elm_genlist_block_count_set(genlist, 14);
367
368         menu_list = privacy_menu_list;
369
370         for (idx = 0; idx < sizeof(privacy_menu_list) / sizeof(struct _privacy_menu_item); idx++) {
371                 if (idx == 0) {
372                         itc = itc_2text;
373                 } else {
374                         itc = itc_1text;
375                 }
376
377                 Privacy_Item_Data *id = calloc(sizeof(Privacy_Item_Data), 1);
378                 id->index = idx;
379                 id->item = elm_genlist_item_append(
380                                 genlist,                // genlist object
381                                 itc,                    // item class
382                                 id,                     // data
383                                 NULL,
384                                 ELM_GENLIST_ITEM_NONE,
385                                 menu_list[idx].func,    // call back
386                                 ad);
387         }
388
389         elm_genlist_item_class_free(itc_2text);
390         elm_genlist_item_class_free(itc_1text);
391         itc = NULL;
392
393         g_privacy_genlist = genlist;
394
395         elm_object_part_content_set(layout, "elm.genlist", genlist);
396
397         return layout;
398 }
399
400 Eina_Bool clear_privacy_cb(void *data, Elm_Object_Item *it)
401 {
402         g_privacy_genlist = NULL;
403
404         return EINA_TRUE;
405 }
406