Initialize Tizen 2.3
[apps/home/settings.git] / setting-security / src / setting-security-main.c
1 /*
2  * setting
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Flora License, Version 1.1 (the License);
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://floralicense.org/license/
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an AS IS BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #include <setting-common-data-type.h>
19 #include <setting-common-data-slp-setting.h>
20 #include <setting-common-draw-widget.h>
21 #include <setting-common-view.h>
22
23 #include <setting-security-main.h>
24 #include <setting-debug.h>
25 #include <app.h>
26
27 static int setting_security_main_create(void *cb);
28 static int setting_security_main_destroy(void *cb);
29 static int setting_security_main_update(void *cb);
30 static int setting_security_main_cleanup(void *cb);
31
32 setting_view setting_view_security_main = {
33         .create = setting_security_main_create,
34         .destroy = setting_security_main_destroy,
35         .update = setting_security_main_update,
36         .cleanup = setting_security_main_cleanup,
37 };
38
39 static void setting_security_main_click_softkey_back_cb(void *data,
40                                                         Evas_Object *obj,
41                                                         void *event_info);
42 #if DISABLED_CODE
43 static void setting_security_main_chk_btn_cb(void *data, Evas_Object *obj,
44                                                 void *event_info);
45 #endif
46 static void setting_security_main_mouse_up_Gendial_list_cb(void *data,
47                                                         Evas_Object *obj,
48                                                         void *event_info);
49 #if DISABLED_CODE
50 static void setting_security_main_update_view(void *data, char *keyStr);
51 static void setting_security_main_create_timer(void *data);
52 static Eina_Bool setting_security_main_timer_update_cb(void *data);
53 #endif
54
55 static void setting_security_main_check_vconf_value(void *data);
56
57
58 /* ***************************************************
59  **
60  **basic func
61  **
62  ****************************************************/
63
64 char *get_pa_screen_lock_type_str()
65 {
66         int lock_type = 0;
67
68         vconf_get_int(VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT, &lock_type);
69
70         switch(lock_type)
71         {
72                 case SETTING_SCREEN_LOCK_TYPE_SWIPE:
73                         return setting_gettext("IDS_ST_MBODY_SWIPE");
74                 case SETTING_SCREEN_LOCK_TYPE_OTHER:
75                         return vconf_get_str(VCONFKEY_SETAPPL_3RD_LOCK_PKG_NAME_STR);
76                 default:
77                         return NULL;
78         }
79 }
80
81 static int setting_security_main_create(void *cb)
82 {
83         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
84         SETTING_TRACE_BEGIN;
85         SettingSecurityUG *ad = (SettingSecurityUG *) cb;
86
87         Evas_Object *scroller;
88
89         int ret = 0;
90         int value = 0;
91         int err = 0;
92
93         gboolean b_status = FALSE;
94         int tapi_ret;
95
96         /* add basic layout */
97         char setBtnStr[MAX_DISPLAY_NAME_LEN_ON_UI];
98         snprintf(setBtnStr, sizeof(setBtnStr), "%s",
99                  (char *)dgettext("sys_string", "IDS_COM_BODY_BACK"));
100         ad->ly_main =
101             setting_create_layout_navi_bar_genlist(ad->win_main_layout,
102                                                    ad->win_get,
103                                                    _("IDS_ST_BODY_SECURITY"),
104                                                    setBtnStr, NULL,
105                                                    setting_security_main_click_softkey_back_cb,
106                                                    NULL, ad, &scroller,
107                                                    &ad->navi_bar);
108
109         Elm_Object_Item *item = NULL;
110
111         //item_data->sub_desc = (char *)g_strdup(sub_desc);
112         /* Screen lock type */
113         ad->data_screen_lock_type = setting_create_Gendial_field_def(scroller, &(ad->itc_2text_2),
114                                                                 setting_security_main_mouse_up_Gendial_list_cb,ad,
115                                                                 SWALLOW_Type_INVALID,
116                                                                 NULL, NULL,
117                                                                 0, Keystr_ScreenLockType, get_pa_screen_lock_type_str(ad), NULL);
118         if(ad->data_screen_lock_type)
119                 ad->data_screen_lock_type->userdata = ad;
120
121         /* SIM settings */
122         if(ad->handle && !isEmulBin())
123         {
124                 /* check status of sim and tapi */
125                 ret = setting_get_int_slp_key(INT_SLP_SETTING_SIM_SLOT, &value, &err);
126                 tapi_ret = tel_check_modem_power_status(ad->handle, &b_status);
127
128                 if ((tapi_ret == TAPI_API_SUCCESS) && (b_status == TAPI_PHONE_POWER_STATUS_ON) && (value == VCONFKEY_TELEPHONY_SIM_INSERTED))
129                 {
130                         /* separator */
131                         item = elm_genlist_item_append(scroller, &(ad->itc_seperator), NULL, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
132                         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
133
134                         setting_create_Gendial_field_def(scroller, &(ad->itc_1text),
135                                                                 setting_security_main_mouse_up_Gendial_list_cb,ad,
136                                                                 SWALLOW_Type_INVALID,
137                                                                 NULL, NULL,
138                                                                 0,"IDS_ST_BODY_SIM_CARD_SETTINGS", NULL, NULL);
139                 }
140         }
141
142         /* update info */
143
144         setting_view_security_main.is_create = 1;
145
146         g_ad = (SettingSecurityUG *) malloc(sizeof(SettingSecurityUG) *1);
147         retv_if(!g_ad, -1);
148         memcpy(g_ad, ad, sizeof(SettingSecurityUG));
149
150         SETTING_TRACE_END;
151         return SETTING_RETURN_SUCCESS;
152 }
153
154 static int setting_security_main_destroy(void *cb)
155 {
156         SETTING_TRACE_BEGIN;
157         /* error check */
158         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
159
160         SettingSecurityUG *ad = (SettingSecurityUG *) cb;
161
162         if (ad->update_view_timer) {
163                 ecore_timer_del(ad->update_view_timer);
164                 ad->update_view_timer = NULL;
165         }
166
167         if (ad->ly_main != NULL) {
168                 evas_object_del(ad->ly_main);
169
170                 FREE(g_ad);
171         }
172         if(ad->input_pwd)
173                 FREE(ad->input_pwd);
174
175         setting_view_security_main.is_create = 0;
176
177         return SETTING_RETURN_SUCCESS;
178 }
179
180 static int setting_security_main_update(void *cb)
181 {
182         SETTING_TRACE_BEGIN;
183         /* error check */
184         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
185
186         SettingSecurityUG *ad = (SettingSecurityUG *) cb;
187         evas_object_show(ad->ly_main);
188
189         if (ad->data_screen_lock_type ) {
190                 G_FREE(ad->data_screen_lock_type->sub_desc);
191                 ad->data_screen_lock_type->sub_desc = (char *)g_strdup(get_pa_screen_lock_type_str(ad));
192                 elm_genlist_item_update(ad->data_screen_lock_type->item);
193         }
194
195         return SETTING_RETURN_SUCCESS;
196 }
197
198 static int setting_security_main_cleanup(void *cb)
199 {
200         SETTING_TRACE_BEGIN;
201         /* error check */
202         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
203
204         return SETTING_RETURN_SUCCESS;
205 }
206
207 /* ***************************************************
208  **
209  **call back func
210  **
211  ****************************************************/
212 static void
213 setting_security_main_click_softkey_back_cb(void *data, Evas_Object *obj,
214                                             void *event_info)
215 {
216         SETTING_TRACE_BEGIN;
217         /* error check */
218         retm_if(data == NULL, "[Setting > Security] Data parameter is NULL");
219
220         SettingSecurityUG *ad = (SettingSecurityUG *) data;
221
222         /* Send destroy request */
223         ug_destroy_me(ad->ug);
224 }
225
226 int _handle_sim_exception(void *data, int sim_status)
227 {
228         retv_if(data == NULL, SETTING_RETURN_FAIL);
229
230         SettingSecurityUG *ad = (SettingSecurityUG *) data;
231
232         switch (sim_status) {
233                 case VCONFKEY_TELEPHONY_SIM_INSERTED:
234                         break;
235
236                 case VCONFKEY_TELEPHONY_SIM_NOT_PRESENT:
237
238                         setting_create_simple_popup(NULL, ad->win_get,
239                                                     NULL, _("IDS_ST_SECURITY_BODY_NOIMSI"));
240                         SETTING_TRACE_DEBUG
241                             ("%s*** [ERR] INCORRECTED SIM. sim_slot_type=%d ***%s",
242                              SETTING_FONT_RED, sim_status, SETTING_FONT_BLACK);
243                         return SETTING_RETURN_FAIL;
244
245                         break;
246
247                 case VCONFKEY_TELEPHONY_SIM_CARD_ERROR:
248                 case VCONFKEY_TELEPHONY_SIM_UNKNOWN:
249
250                         setting_create_simple_popup(NULL, ad->win_get,
251                                                     NULL, _("IDS_COM_BODY_INVALID_SIM_CARD"));
252                         SETTING_TRACE_DEBUG
253                             ("%s*** [ERR] INCORRECTED SIM. sim_slot_type=%d ***%s",
254                              SETTING_FONT_RED, sim_status, SETTING_FONT_BLACK);
255                         return SETTING_RETURN_FAIL;
256
257                         break;
258                 default:
259                         break;
260         }
261         return SETTING_RETURN_SUCCESS;
262 }
263
264 static void
265 setting_security_main_mouse_up_Gendial_list_cb(void *data, Evas_Object *obj,
266                                                void *event_info)
267 {
268         SETTING_TRACE_BEGIN;
269         /* error check */
270         setting_retm_if(data == NULL, "Data parameter is NULL");
271
272         retm_if(event_info == NULL, "Invalid argument: event info is NULL");
273         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
274         elm_genlist_item_selected_set(item, 0);
275         Setting_GenGroupItem_Data *list_item =
276             (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
277
278         SettingSecurityUG *ad = (SettingSecurityUG *) data;
279
280         SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
281
282         if(!safeStrCmp("IDS_ST_BODY_SIM_CARD_SETTINGS", list_item->keyStr)) {
283                 setting_view_change(&setting_view_security_main, &setting_view_security_sim_settings, ad);      
284         }
285         else if(!safeStrCmp(Keystr_ScreenLockType, list_item->keyStr)) {
286                 setting_view_change(&setting_view_security_main, &setting_view_security_locktype, ad);
287         }
288 }