tizen 2.3 release
[apps/home/settings.git] / setting-security / src / setting-security-confirm-encryption.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-security-confirm-encryption.h>
26 #include <setting-debug.h>
27
28 static int setting_security_confirm_encryption_create(void *cb);
29 static int setting_security_confirm_encryption_destroy(void *cb);
30 static int setting_security_confirm_encryption_update(void *cb);
31 static int setting_security_confirm_encryption_cleanup(void *cb);
32
33 setting_view setting_view_security_confirm_encryption = {
34         .create = setting_security_confirm_encryption_create,
35         .destroy = setting_security_confirm_encryption_destroy,
36         .update = setting_security_confirm_encryption_update,
37         .cleanup = setting_security_confirm_encryption_cleanup,
38 };
39
40 /* ***************************************************
41  **
42  **basic func
43  **
44  ****************************************************/
45
46 static void __confirm_enc_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
47 {
48         SETTING_TRACE_BEGIN;
49         ret_if(data == NULL);
50
51         SettingSecurityUG *ad = data;
52
53         Evas_Object *fast_encryption = elm_object_part_content_get(ad->enc_scroller, "fast.check");
54         if(fast_encryption)
55         {
56                 int ret = 0;
57                 int status = -1;
58                 status = elm_check_state_get(fast_encryption);
59                 SETTING_TRACE_DEBUG("fast encryption check button status is %d", status);
60                 ret = vconf_set_bool(VCONFKEY_ODE_FAST_ENCRYPTION, status);
61                 if(ret != 0)
62                         SETTING_TRACE_DEBUG("vconf_set_bool(%s) failed", VCONFKEY_ODE_FAST_ENCRYPTION);
63         }
64
65         /* To do : View change, Encrypting... or Decrypting... */
66         //setting_view_change(&setting_view_security_confirm_encryption, &setting_view_security_enc_processing, ad);
67         // Call setting-encrypting-efl.
68         app_control_h svc;
69         if(app_control_create(&svc) == APP_CONTROL_ERROR_NONE)
70         {
71                 app_control_set_app_id(svc, "org.tizen.setting.encrypting");
72                 app_control_set_operation(svc, APP_CONTROL_OPERATION_DEFAULT);
73                 //service_set_window(svc, elm_win_xwindow_get(ad->win_get));
74                 app_control_add_extra_data(svc, "caller", "device");
75                 app_control_add_extra_data(svc, "input_pwd", ad->input_pwd);
76                 if(ad->cur_enc_mode == 0)
77                 {
78                         app_control_add_extra_data(svc, "cur_mode", "unencrypted");
79                 }
80                 else if(ad->cur_enc_mode == 1)
81                 {
82                         app_control_add_extra_data(svc, "cur_mode", "encrypted");
83                 }
84                 app_control_send_launch_request(svc, NULL, NULL);
85                 app_control_destroy(svc);
86         }
87         // End.
88 }
89
90 static void __confirm_check_btn_cb(void *data, Evas_Object *obj, void *event_info)
91 {
92         SETTING_TRACE_BEGIN;
93 }
94
95 void __add_confirm_content(void *data)
96 {
97         SETTING_TRACE_BEGIN;
98         ret_if(data == NULL);
99
100         SettingSecurityUG *ad = (SettingSecurityUG *) data;
101
102         if(ad->enc_scroller == NULL)
103         {
104                 SETTING_TRACE_DEBUG("There is no layout object");
105                 return;
106         }
107
108         Evas_Object *check_btn = NULL;
109         char temp[2048] = {0,};
110
111         if(ad->cur_enc_mode == 0)
112         {
113                 SETTING_TRACE_DEBUG("Encrypt");
114                 snprintf(temp, 2048, "%s", _(CONFIRM_ENCRYPTION_GUIDE_01));
115                 elm_object_part_text_set(ad->enc_scroller, "description", temp);
116
117                 // add check.
118                 check_btn = elm_check_add(ad->enc_scroller);
119                 if(check_btn)
120                 {
121                         elm_check_state_set(check_btn, 0);
122                         evas_object_smart_callback_add(check_btn, "changed", __confirm_check_btn_cb, ad);
123                         elm_object_part_content_set(ad->enc_scroller, "fast.check", check_btn);
124                 }
125                 // add fast encryption description.
126                 memset(temp, 0x00, 2048);
127                 snprintf(temp, 2048, "%s : %s", _(CONFIRM_ENCRYPTION_GUIDE_02), _(CONFIRM_ENCRYPTION_GUIDE_03));
128                 elm_object_part_text_set(ad->enc_scroller, "fast.text", temp);
129         }
130         else if(ad->cur_enc_mode == 1)
131         {
132                 SETTING_TRACE_DEBUG("Decrypt");
133                 snprintf(temp, 2048, "%s", _(DEVICE_DECRYPTION_GUIDE_01));
134                 elm_object_part_text_set(ad->enc_scroller, "description", temp);
135         }
136
137         //SETTING_TRACE_DEBUG("guide : %s", temp);
138 }
139
140 static int setting_security_confirm_encryption_create(void *cb)
141 {
142         SETTING_TRACE_BEGIN;
143         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
144
145         SettingSecurityUG *ad = (SettingSecurityUG *) cb;
146
147         Evas_Object *inner_layout = NULL;
148         inner_layout = elm_layout_add(ad->win_get);
149         if(!inner_layout)
150                 return SETTING_RETURN_FAIL;
151
152         elm_layout_file_set(inner_layout, SETTING_THEME_EDJ_NAME, "encryption_confirm_layout");
153
154         ad->enc_scroller = inner_layout;
155         __add_confirm_content(ad);
156
157         if(ad->cur_enc_mode == 0)
158         {
159                 setting_push_layout_navi_bar(Keystr_ConfirmEncryption,
160                                                                                         "IDS_COM_BODY_BACK", "IDS_ST_HEADER_ENCRYPT_DEVICE", NULL,
161                                                                                         (setting_call_back_func)setting_security_confirm_encryption_click_softkey_back_cb,
162                                                                                         __confirm_enc_btn_clicked_cb, NULL,
163                                                                                         ad, inner_layout,
164                                                                                         ad->navi_bar, NULL);
165         }
166         else if(ad->cur_enc_mode == 1)
167         {
168                 setting_push_layout_navi_bar(Keystr_ConfirmDecryption,
169                                                                                         "IDS_COM_BODY_BACK", "IDS_ST_BODY_DECRYPT_DEVICE", NULL,
170                                                                                         (setting_call_back_func)setting_security_confirm_encryption_click_softkey_back_cb,
171                                                                                         __confirm_enc_btn_clicked_cb, NULL,
172                                                                                         ad, inner_layout,
173                                                                                         ad->navi_bar, NULL);
174         }
175
176         evas_object_show(inner_layout);
177
178         setting_view_security_confirm_encryption.is_create = 1;
179
180         return SETTING_RETURN_SUCCESS;
181
182 }
183
184 static int setting_security_confirm_encryption_destroy(void *cb)
185 {
186         /* error check */
187         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
188
189         SettingSecurityUG *ad = (SettingSecurityUG *) cb;
190
191         elm_naviframe_item_pop(ad->navi_bar);
192
193         setting_view_security_confirm_encryption.is_create = 0;
194
195         return SETTING_RETURN_SUCCESS;
196 }
197
198 static int setting_security_confirm_encryption_update(void *cb)
199 {
200         /* error check */
201         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
202
203         return SETTING_RETURN_SUCCESS;
204 }
205
206 static int setting_security_confirm_encryption_cleanup(void *cb)
207 {
208         /* error check */
209         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
210
211         return setting_security_confirm_encryption_destroy(cb);
212
213         //return SETTING_RETURN_SUCCESS;
214 }
215
216 /* ***************************************************
217  **
218  **call back func
219  **
220  ****************************************************/
221 static Eina_Bool
222 setting_security_confirm_encryption_click_softkey_back_cb(void *data, Elm_Object_Item *it)
223 {
224         /* error check */
225         retvm_if(data == NULL, EINA_FALSE, "[Setting > Security] Data parameter is NULL");
226
227         SettingSecurityUG *ad = (SettingSecurityUG *) data;
228
229         setting_view_change(&setting_view_security_confirm_encryption, &setting_view_security_encryption, ad);
230         return EINA_TRUE;
231 }