tizen 2.3 release
[apps/home/settings.git] / setting-personalpage / src / setting-personalpage-unlock.c
1 /*
2  * setting
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
5  *
6  * Contact: MyoungJune Park <mj2004.park@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 #include <setting-common-data-type.h>
22 #include <setting-common-data-slp-setting.h>
23 #include <setting-common-draw-widget.h>
24
25 #include <setting-personalpage-unlock.h>
26 #include <setting-debug.h>
27
28
29 static int setting_personalpage_unlock_create(void *cb);
30 static int setting_personalpage_unlock_destroy(void *cb);
31 static int setting_personalpage_unlock_update(void *cb);
32 static int setting_personalpage_unlock_cleanup(void *cb);
33
34 setting_view setting_view_personalpage_unlock = {
35         .create = setting_personalpage_unlock_create,
36         .destroy = setting_personalpage_unlock_destroy,
37         .update = setting_personalpage_unlock_update,
38         .cleanup = setting_personalpage_unlock_cleanup,
39 };
40
41 /* ***************************************************
42  **
43  **basic func
44  **
45  ****************************************************/
46
47 static void setting_personalpage_unlock_mouse_up_Gendial_list_cb(void *data, Evas_Object *obj, void *event_info)
48 {
49         SETTING_TRACE_BEGIN;
50         /* error check */
51         setting_retm_if(data == NULL, "Data parameter is NULL");
52
53         retm_if(event_info == NULL, "Invalid argument: event info is NULL");
54         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
55         elm_genlist_item_selected_set(item, 0);
56         Setting_GenGroupItem_Data *list_item =
57             (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
58
59         SettingPersonalpageUG *ad = (SettingPersonalpageUG *) data;
60
61         SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
62
63         if (!safeStrCmp("IDS_ST_BODY_SIMPLE_PASSWORD", list_item->keyStr))
64         {
65                 // launch password ug for setting key.
66                 setting_personalpage_create_password_sg(ad, SETTING_PERSONAL_PW_CALLER_UNLOCK_PIN);
67         }
68         else if (!safeStrCmp("IDS_COM_BODY_AUTH_PASSWORD", list_item->keyStr))
69         {
70                 // launch password ug for setting key.
71                 setting_personalpage_create_password_sg(ad, SETTING_PERSONAL_PW_CALLER_UNLOCK_PASSWORD);
72         }
73 }
74
75 static void setting_personalpage_unlock_click_radio_cb(void *data, Evas_Object *obj, void *event_info)
76 {
77         SETTING_TRACE_BEGIN;
78         ret_if(!data);
79         Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *)data;
80         SettingPersonalpageUG *ad = (SettingPersonalpageUG *) list_item->userdata;
81
82         int selected = elm_radio_value_get(obj);
83
84         if(selected == 1)
85         {
86                 setting_personalpage_create_password_sg(ad, SETTING_PERSONAL_PW_CALLER_UNLOCK_PIN);
87         }
88         else if(selected == 2)
89         {
90                 setting_personalpage_create_password_sg(ad, SETTING_PERSONAL_PW_CALLER_UNLOCK_PASSWORD);
91         }
92
93         //retreive radio.
94         int current = -1;
95         vconf_get_int(VCONFKEY_SETAPPL_PERSONAL_MODE_UNLOCK_METHOD_INT, &current);
96         elm_radio_value_set(obj, current);
97 }
98
99 void __init_popup_resp_cb(void *data, Evas_Object *obj, void *event_info)
100 {
101         SETTING_TRACE_BEGIN;
102         ret_if(!data);
103
104         SettingPersonalpageUG *ad = (SettingPersonalpageUG *)data;
105
106         int response_type = btn_type(obj);
107
108         if(response_type == POPUP_RESPONSE_CANCEL)
109         {
110                 SETTING_TRACE("CANCEL");
111                 // if cancel, ug_destroy me
112                 ug_destroy_me(ad->ug);
113         }
114         else if(response_type == POPUP_RESPONSE_OK)
115         {
116                 // if ok, do nothing
117                 SETTING_TRACE("OK");
118         }
119
120         if(ad->init_popup)
121         {
122                 evas_object_del(ad->init_popup);
123                 ad->init_popup = NULL;
124         }
125 }
126
127 static int setting_personalpage_unlock_create(void *cb)
128 {
129         SETTING_TRACE_BEGIN;
130         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
131
132         SettingPersonalpageUG *ad = (SettingPersonalpageUG *) cb;
133
134         Elm_Object_Item *item = NULL;
135         Evas_Object *genlist = NULL;
136
137         /* add basic layout */
138         char setBtnStr[MAX_DISPLAY_NAME_LEN_ON_UI];
139         snprintf(setBtnStr, sizeof(setBtnStr), "%s",
140                  (char *)dgettext("sys_string", "IDS_COM_BODY_BACK"));
141
142         if(ad->viewtype == PERSONAL_VIEW_UNLOCK_METHOD)
143         {
144                 ad->ly_main = setting_create_layout_navi_bar_genlist(ad->win_main_layout, ad->win_get, "IDS_ST_MBODY_UNLOCK_METHOD",
145                                                                                         setBtnStr, NULL,
146                                                                                         (setting_call_back_func)setting_personalpage_unlock_click_softkey_back_cb,
147                                                                                         NULL,
148                                                                                         ad,
149                                                                                         &genlist,
150                                                                                         &(ad->navi_bar));
151         }
152         else
153         {
154                 setting_push_layout_navi_bar_genlist(ad->win_main_layout, ad->win_get, "IDS_ST_MBODY_UNLOCK_METHOD",
155                                                                                         setBtnStr, NULL,
156                                                                                         (setting_call_back_func)setting_personalpage_unlock_click_softkey_back_cb,
157                                                                                         NULL,
158                                                                                         ad,
159                                                                                         &genlist,
160                                                                                         ad->navi_bar);
161         }
162
163         item = elm_genlist_item_append(genlist,
164                                                                 &itc_seperator, NULL, NULL,
165                                                                 ELM_GENLIST_ITEM_NONE, NULL, NULL);
166         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
167
168         Evas_Object *radio = elm_radio_add(genlist);
169         elm_radio_state_value_set(radio, -1);
170         ad->rd_option = radio;
171
172         // item 1
173         ad->data_unlock_pin = setting_create_Gendial_field_1radio(genlist,
174                                                 &(itc_1text_1icon_3),
175                                                 setting_personalpage_unlock_mouse_up_Gendial_list_cb,   /*add to sel_cb */
176                                                 ad,     /* sel data */
177                                                 SWALLOW_Type_1RADIO_1BTN,
178                                                 radio, 1,
179                                                 "IDS_ST_BODY_SIMPLE_PASSWORD",
180                                                 setting_personalpage_unlock_click_radio_cb);
181         if(ad->data_unlock_pin)
182         {
183                 ad->data_unlock_pin->userdata = ad;
184                 ad->data_unlock_pin->group_style = SETTING_GROUP_STYLE_TOP;
185         };
186         // item 2
187         ad->data_unlock_password = setting_create_Gendial_field_1radio(genlist,
188                                                 &(itc_1text_1icon_3),
189                                                 setting_personalpage_unlock_mouse_up_Gendial_list_cb,   /*add to sel_cb */
190                                                 ad,     /* sel data */
191                                                 SWALLOW_Type_1RADIO_1BTN,
192                                                 radio, 2,
193                                                 "IDS_COM_BODY_AUTH_PASSWORD",
194                                                 setting_personalpage_unlock_click_radio_cb);
195         if(ad->data_unlock_password)
196         {
197                 ad->data_unlock_password->userdata = ad;
198                 ad->data_unlock_password->group_style = SETTING_GROUP_STYLE_BOTTOM;
199         }
200
201         int unlock_method = -1;
202         vconf_get_int(VCONFKEY_SETAPPL_PERSONAL_MODE_UNLOCK_METHOD_INT, &unlock_method);
203         if(unlock_method > 0)
204         {
205                 elm_radio_value_set(radio, unlock_method);
206         }
207         else if(ad->viewtype == PERSONAL_VIEW_UNLOCK_METHOD)
208         {
209                 // add popup
210                 ad->init_popup = setting_create_popup_with_btn(ad, ad->navi_bar,
211                                                                         _("IDS_ST_HEADER_PERSONAL_MODE"),
212                                                                         _("IDS_ST_POP_TO_USE_PERSONAL_MODE_YOU_MUST_REGISTER_AN_UNLOCK_METHOD"),
213                                                                         __init_popup_resp_cb, 0,
214                                                                         2,
215                                                                         "IDS_COM_SK_OK", "IDS_COM_SK_CANCEL");
216         }
217
218
219         setting_view_personalpage_unlock.is_create = 1;
220
221         return SETTING_RETURN_SUCCESS;
222
223 }
224
225 static int setting_personalpage_unlock_destroy(void *cb)
226 {
227         SETTING_TRACE_BEGIN;
228         /* error check */
229         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
230
231         SettingPersonalpageUG *ad = (SettingPersonalpageUG *) cb;
232
233         if(ad->viewtype == PERSONAL_VIEW_UNLOCK_METHOD)
234         {
235                 if(ad->init_popup)
236                 {
237                         evas_object_del(ad->init_popup);
238                         ad->init_popup = NULL;
239                 }
240
241                 if (ad->ly_main != NULL)
242                 {
243                         evas_object_del(ad->ly_main);
244                         ad->ly_main = NULL;
245                 }
246         }
247         else
248         {
249                 elm_naviframe_item_pop(ad->navi_bar);
250         }
251         setting_view_personalpage_unlock.is_create = 0;
252
253         return SETTING_RETURN_SUCCESS;
254 }
255
256 static int setting_personalpage_unlock_update(void *cb)
257 {
258         SETTING_TRACE_BEGIN;
259         /* error check */
260
261         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
262         //SettingPersonalpageUG *ad = (SettingPersonalpageUG *) cb;
263
264         return SETTING_RETURN_SUCCESS;
265 }
266
267 static int setting_personalpage_unlock_cleanup(void *cb)
268 {
269         SETTING_TRACE_BEGIN;
270         /* error check */
271         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
272         SettingPersonalpageUG *ad = (SettingPersonalpageUG *) cb;
273
274         if (ad->viewtype == PERSONAL_VIEW_UNLOCK_METHOD)
275         {
276                 return SETTING_RETURN_SUCCESS;
277         }
278         else
279         {
280                 return setting_personalpage_unlock_destroy(ad);
281         }
282 }
283
284 /* ***************************************************
285  **
286  **call back func
287  **
288  ****************************************************/
289
290 static Eina_Bool
291 setting_personalpage_unlock_click_softkey_back_cb(void *data, Elm_Object_Item *it)
292 {
293         /* error check */
294         retvm_if(data == NULL, EINA_TRUE, "[Setting > Security] Data parameter is NULL");
295
296         SettingPersonalpageUG *ad = (SettingPersonalpageUG *) data;
297
298
299         if (ad->viewtype == PERSONAL_VIEW_UNLOCK_METHOD)
300         {
301                 ug_destroy_me(ad->ug);
302                 return EINA_FALSE;
303         }
304         else
305         {
306                 setting_view_change(&setting_view_personalpage_unlock, &setting_view_personalpage_main, ad);
307                 return EINA_TRUE;
308         }
309 }
310