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