tizen 2.3.1 release
[apps/home/settings.git] / setting-password / src / setting-password-simple.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
22 #include <setting-password.h>
23 #include <setting-common-data-slp-setting.h>
24 #include <setting-debug.h>
25 #include <dd-haptic.h>
26 #include <Ecore_IMF.h>
27 #include <Ecore_IMF_Evas.h>
28 #include <Ecore_X.h>
29 #include <Ecore.h>
30 #include <utilX.h>
31 #include <time.h>
32 #include <notification.h>
33
34 static int setting_password_simple_create(void *cb);
35 static int setting_password_simple_destroy(void *cb);
36 static int setting_password_simple_update(void *cb);
37 static int setting_password_simple_cleanup(void *cb);
38
39 setting_view setting_view_password_simple = {
40         .create = setting_password_simple_create,
41         .destroy = setting_password_simple_destroy,
42         .update = setting_password_simple_update,
43         .cleanup = setting_password_simple_cleanup,
44 };
45
46
47 #define SETTING_SP_TITLE_INDEX_START 0
48 #define SETTING_SP_TITLE_INDEX_MAX 3
49 const char *sp_titles[5] = { PW_ST_ENTER_PW,
50                              PW_ST_NEW_PW,
51                              PW_ST_ENTER_PW_AGAIN,
52                              PW_ST_ENTER_CUR_PW,
53                              NULL,
54                            };
55
56
57 extern struct _pw_item pw_its[];
58
59 /* ***************************************************
60  *
61  *basic func
62  *
63  ***************************************************/
64
65 static Eina_Bool setting_password_simple_click_softkey_cancel_cb(void *data, Elm_Object_Item *it)
66 {
67         SETTING_TRACE_BEGIN;
68         /* error check */
69         retvm_if(data == NULL, EINA_FALSE, "[Setting > Password] Data parameter is NULL");
70
71         SettingPasswordUG *ad = (SettingPasswordUG *) data;
72
73         if (ad->focus_timer) {
74                 ecore_timer_del(ad->focus_timer);
75                 ad->focus_timer = NULL;
76         }
77
78         if (ad->imf_handler) {
79                 ecore_event_handler_del(ad->imf_handler);
80                 ad->imf_handler = NULL;
81         }
82         if (ad->imf_context) {
83                 ecore_imf_context_del(ad->imf_context);
84                 ad->imf_context = NULL;
85         }
86
87         /* send result : Cancel */
88         app_control_h svc;
89         if (app_control_create(&svc) == 0) {
90                 app_control_add_extra_data(svc, "result", "Cancel");
91                 ug_send_result(ad->ug, svc);
92                 SETTING_TRACE("Send Result : %s\n", "Cancel");
93
94                 app_control_destroy(svc);
95         }
96         /* Send destroy request */
97         ug_destroy_me(ad->ug);
98
99         return EINA_TRUE;
100 }
101
102 static void setting_password_simple_add_description(Evas_Object *layout, char *desc)
103 {
104         ret_if(!layout || !desc);
105         elm_object_part_text_set(layout, "help.txt", _(desc));
106 }
107
108 static void _copy_chars_from_sp_entries(void *data, char *collection)
109 {
110         ret_if(data == NULL || collection == NULL);
111
112         SettingPasswordUG *ad = (SettingPasswordUG *) data;
113
114         if (ad->sp_entry1 == NULL || ad->sp_entry2 == NULL ||
115             ad->sp_entry3 == NULL || ad->sp_entry4 == NULL)
116                 return;
117
118         strncpy(collection, ad->sp_chars, 4);
119         memset(ad->sp_chars, 0x00, 5);
120 }
121
122 /* Verify simple password */
123 static int _handle_step1(void *data, char *collection)
124 {
125         SETTING_TRACE_BEGIN;
126         retv_if(data == NULL, SETTING_RETURN_FAIL);
127
128         SettingPasswordUG *ad = (SettingPasswordUG *) data;
129         int ret = 0;
130         int err = 0;
131
132         _copy_chars_from_sp_entries(ad, collection);
133
134         ret = setting_password_simple_check_simple_password(collection);
135         SETTING_TRACE("ret:%d", ret);
136         if (ret < 0) {
137                 SETTING_TRACE_ERROR("Invalid Password formatting")
138                 setting_password_simple_draw_next_simple_password(ad, 3);
139                 return SETTING_RETURN_FAIL;
140         }
141
142         unsigned int remain_attempt;
143         unsigned int valid_sec;
144         ret = setting_password_check_password(collection, &remain_attempt, &valid_sec);
145         SETTING_TRACE("ret:%d", ret);
146         if (ret != SETTING_RETURN_SUCCESS) {
147                 SETTING_TRACE_ERROR("Failed to invoke security_server_chk_pwd")
148                 setting_password_simple_draw_next_simple_password(ad, 3);
149                 ad->remain_attempt = remain_attempt;
150                 ad->valid_sec = valid_sec;
151                 return SETTING_PW_ERROR_DO_NOT_MATCH;
152         }
153
154         int value = 0;
155         ecore_imf_context_input_panel_hide(ad->imf_context);
156
157         if (0 == safeStrCmp(ad->view_type_string, "SETTING_PW_TYPE_SIMPLE_PASSWORD")) {
158                 setting_get_bool_slp_key(BOOL_SLP_SETTING_POWER_ON_LOCK, &value, &err);
159                 SETTING_TRACE_DEBUG("get VCONF POWER_ON_LOCK : %d", value);
160
161                 if (value == 0)
162                         ret = setting_set_bool_slp_key(BOOL_SLP_SETTING_POWER_ON_LOCK,
163                                                        SETTING_ON_OFF_BTN_ON, &err);
164                 else
165                         ret = setting_set_bool_slp_key(BOOL_SLP_SETTING_POWER_ON_LOCK,
166                                                        SETTING_ON_OFF_BTN_OFF, &err);
167
168                 /* reset VCONF */
169                 setting_set_int_slp_key(INT_SLP_SETTING_PHONE_LOCK_ATTEMPTS_LEFT,
170                                         PHONE_LOCK_ATTEMPS_MAX, &err);
171                 setting_retvm_if(err == SETTING_RETURN_FAIL, SETTING_RETURN_FAIL, "[Error] set value of vconf fail.");
172
173                 /* Correct Password. Send Bundle to caller for status change */
174         }
175
176         app_control_h svc;
177         if (app_control_create(&svc)) {
178                 setting_password_simple_draw_next_simple_password(ad, 3);
179                 return SETTING_RETURN_FAIL;
180         }
181
182         app_control_add_extra_data(svc, "result", ad->view_type_string);
183
184         if (0 == safeStrCmp(ad->view_type_string, "SETTING_PW_TYPE_ENTER_LOCK_TYPE"))
185                 app_control_add_extra_data(svc, "current", (char *)strdup(collection));
186
187         /* reset static variables */
188         memset(collection, 0x00, SETTING_PW_UG_NORMAL_PASSWORD_MIN_LENGTH + 1);
189
190         ug_send_result(ad->ug, svc);
191         SETTING_TRACE("Send Result : %s\n", ad->view_type_string);
192         app_control_destroy(svc);
193         /* Send destroy request */
194         ug_destroy_me(ad->ug);
195
196         return SETTING_RETURN_SUCCESS;
197 }
198
199 /* Set new simple password */
200 static int _handle_step2(void *data, int *step, char *collection1, char *collection2)
201 {
202         SETTING_TRACE_BEGIN;
203         retv_if(data == NULL, SETTING_RETURN_FAIL);
204
205         SettingPasswordUG *ad = (SettingPasswordUG *) data;
206         int ret = 0;
207         static int simple_sequence = 0;
208
209         if (*step == 0) {       /* Enter new password */
210                 _copy_chars_from_sp_entries(ad, collection1);
211
212                 ret = setting_password_simple_check_simple_password(collection1);
213                 if (ret < 0) {
214                         setting_password_simple_draw_next_simple_password(ad, 1);
215                         return SETTING_RETURN_FAIL;
216                 }
217
218                 (*step)++;
219                 setting_password_simple_draw_next_simple_password(ad, 2);
220         } else if (*step == 1) {        /* Enter password again */
221                 _copy_chars_from_sp_entries(ad, collection2);
222
223                 ret = setting_password_simple_check_simple_password(collection2);
224                 if (ret < 0) {
225                         setting_password_simple_draw_next_simple_password(ad, 2);
226                         return SETTING_RETURN_FAIL;
227                 }
228
229                 /* compare two input passwords : collection_step1, collection_step2 */
230                 if (safeStrNCmp(collection1, collection2, 4) == 0) {
231                         ecore_imf_context_input_panel_hide(ad->imf_context);
232                         ret = setting_password_set_password(ad->cur_pwd, collection1, ad);
233
234                         if (SETTING_RETURN_SUCCESS == ret) {
235                                 FREE(ad->step1_str);
236
237                                 app_control_h svc;
238                                 if (!app_control_create(&svc)) {
239                                         app_control_add_extra_data(svc, "result", ad->view_type_string);
240
241                                         /* reset static variables */
242                                         *step = 0;
243                                         /* reset static variables */
244                                         memset(collection1, 0x00, SETTING_PW_UG_NORMAL_PASSWORD_MIN_LENGTH + 1);
245                                         memset(collection2, 0x00, SETTING_PW_UG_NORMAL_PASSWORD_MIN_LENGTH + 1);
246
247                                         ug_send_result(ad->ug, svc);
248                                         SETTING_TRACE("Send Result : %s\n", ad->view_type_string);
249                                         app_control_destroy(svc);
250                                         /* Send destroy request */
251                                         ug_destroy_me(ad->ug);
252                                         return SETTING_RETURN_SUCCESS;
253                                 }
254                                 /* Display popup */
255                                 setting_password_ug_create_popup_notitle_nobtn(ad, _("IDS_ST_POP_NEW_PASSWD_SAVED"), TRUE);
256                         } else if (ret == SETTING_PW_ERROR_REUSED) {
257                                 setting_password_simple_draw_next_simple_password(ad, 1);
258                                 setting_password_simple_add_description(ad->simple_layout, PW_ERR_REUSED);
259                                 *step = 0;
260                                 /* reset static variables */
261                                 memset(collection1, 0x00, SETTING_PW_UG_NORMAL_PASSWORD_MIN_LENGTH + 1);
262                                 memset(collection2, 0x00, SETTING_PW_UG_NORMAL_PASSWORD_MIN_LENGTH + 1);
263                                 return SETTING_PW_ERROR_REUSED;
264                         } else {
265                                 setting_password_simple_draw_next_simple_password(ad, 1);
266                                 char temp[256] = {0,};
267                                 snprintf(temp, 256, "Unable to save password (%d)", ret);
268                                 setting_password_ug_create_popup_notitle_nobtn(ad, temp, FALSE);
269
270                                 *step = 0;
271                                 /* reset static variables */
272                                 memset(collection1, 0x00, SETTING_PW_UG_NORMAL_PASSWORD_MIN_LENGTH + 1);
273                                 memset(collection2, 0x00, SETTING_PW_UG_NORMAL_PASSWORD_MIN_LENGTH + 1);
274                                 return SETTING_PW_ERROR_UNKNOWN;
275                         }
276                 } else {
277                         setting_password_simple_draw_next_simple_password(ad, 2);
278                         return SETTING_ENTRY_NOT_MATCH_NEW_CONF_PW;
279                 }
280         }
281         return SETTING_RETURN_SUCCESS;
282 }
283
284 static int setting_password_simple_done_simple_password(void *data, int on_locking)
285 {
286         SETTING_TRACE_BEGIN;
287         retv_if(data == NULL, SETTING_RETURN_FAIL);
288
289         SettingPasswordUG *ad = (SettingPasswordUG *) data;
290
291         static int step = 0;
292
293         static char collection_step1[SETTING_PW_UG_NORMAL_PASSWORD_MIN_LENGTH + 1] = {0,};
294         static char collection_step2[SETTING_PW_UG_NORMAL_PASSWORD_MIN_LENGTH + 1] = {0,};
295
296         switch (ad->view_type) {
297                 case SETTING_PW_TYPE_SIMPLE_PASSWORD: {
298                                 SETTING_TRACE_DEBUG("case SIMPLE_PASSWORD");
299                                 return _handle_step1(ad, collection_step1);
300                         }
301                 case SETTING_PW_TYPE_SET_SIMPLE_PASSWORD: {
302                                 SETTING_TRACE_DEBUG("case SET_SIMPLE_PASSWORD");
303                                 return _handle_step2(ad, &step, collection_step1, collection_step2);
304                         }
305
306                 default:
307                         break;
308         }
309         return SETTING_RETURN_SUCCESS;
310 }
311
312 static Eina_Bool setting_password_simple_check_4entries(void *data)
313 {
314         SETTING_TRACE_BEGIN;
315         retv_if(data == NULL, EINA_FALSE);
316         SettingPasswordUG *ad = (SettingPasswordUG *) data;
317
318         int ret = 0;
319
320         ret = setting_password_simple_done_simple_password(ad, TRUE);
321
322         memset(ad->sp_chars, 0x00, 5);
323
324         if (ret == SETTING_RETURN_FAIL) {
325                 setting_password_simple_add_description(ad->simple_layout, PW_ST_INCORRECT_PW_TRY_AGAIN);
326         } else if (ret == SETTING_PW_ERROR_DO_NOT_MATCH) {
327                 if (0 == safeStrCmp(ad->view_type_string, "SETTING_PW_TYPE_ENTER_LOCK_TYPE")) {
328
329                         setting_password_simple_add_description(ad->simple_layout, PW_ERR_DESC);
330                         return EINA_FALSE;
331                 }
332                 /** @todo setting_password_ug_check_attemps_left */
333                 setting_int_slp_list item_attempts_left;
334                 setting_str_slp_list item_lock_timestamp;
335                 int attemps_left_max = 5;
336                 item_attempts_left = INT_SLP_SETTING_PHONE_LOCK_ATTEMPTS_LEFT;
337                 item_lock_timestamp = STR_SLP_SETTING_PHONE_LOCK_TIMESTAMP;
338                 attemps_left_max = PHONE_LOCK_ATTEMPS_MAX;
339
340                 int value = -1;
341                 int err = SETTING_RETURN_SUCCESS;
342                 setting_get_int_slp_key(item_attempts_left, &value, &err);
343                 retvm_if(err == SETTING_RETURN_FAIL, EINA_FALSE, "[Error] get value of vconf fail.");
344                 value--;
345                 if (value > 0 && value <= attemps_left_max) {
346                         setting_set_int_slp_key(item_attempts_left, value, &err);
347                         setting_retvm_if(err == SETTING_RETURN_FAIL, EINA_FALSE, "[Error] set value of vconf fail.");
348                         char speciliztion[MAX_SPECIALIZITION_LEN] = { 0, };
349                         char temp[MAX_SPECIALIZITION_LEN] = {0,};
350                         if (value > 1)
351                                 snprintf(temp, sizeof(temp), "%s. %s.", PW_ERR_DESC, ATTEMPTS_DESC);
352                         else
353                                 snprintf(temp, sizeof(temp), "%s. %s.", PW_ERR_DESC, ATTEMPT_DESC);
354                         snprintf(speciliztion, sizeof(speciliztion), temp, value);
355                         setting_password_simple_add_description(ad->simple_layout, speciliztion);
356                 } else if (value == 0) {
357                         /*  store the lock timestamp */
358                         elm_object_focus_set(ad->sp_entry1, EINA_FALSE);
359                         time_t cur_time = time(NULL);
360                         char cur_timestamp[LOCK_TIMESTAMP_LEN] = { 0, };
361                         int ret = snprintf(cur_timestamp, sizeof(cur_timestamp), "%ld", cur_time);
362                         retv_if(ret < 0, EINA_FALSE);
363                         setting_set_string_slp_key(item_lock_timestamp, cur_timestamp, &err);
364                         setting_retvm_if(err == SETTING_RETURN_FAIL, EINA_FALSE,
365                                          "[Error] set value of vconf fail.");
366
367                         setting_set_int_slp_key(item_attempts_left, value, &err);
368                         setting_retvm_if(err == SETTING_RETURN_FAIL, EINA_FALSE,
369                                          "[Error] set value of vconf fail.");
370
371                         ad->disable_item_type = ad->view_type;
372
373                         char temp[MAX_SPECIALIZITION_LEN] = {0,};
374                         snprintf(temp, sizeof(temp), PW_ERR_DELAY_DESC, PW_ERR_DELAY_TIME);
375                         setting_password_ug_create_popup_notitle_nobtn(ad, temp, TRUE);
376                 }
377         } else if (ret == SETTING_ENTRY_NOT_MATCH_NEW_CONF_PW) {
378                 setting_password_simple_add_description(ad->simple_layout, PW_ST_PW_DO_NOT_MATCH);
379         } else {
380                 /* if you have more cases, modify here. */
381         }
382
383         ad->simple_done_timer = NULL;
384         return EINA_FALSE;
385 }
386
387 Ecore_IMF_Context *__imf_context_create(void *data)
388 {
389         SETTING_TRACE_BEGIN;
390         retv_if(data == NULL, NULL);
391         SettingPasswordUG *ad = (SettingPasswordUG *) data;
392
393         Ecore_IMF_Context *imf_context = NULL;
394         const char *ctx_id = ecore_imf_context_default_id_get();
395
396         if (ctx_id) {
397                 imf_context = ecore_imf_context_add(ctx_id);
398
399                 if (ad->evas && imf_context) {
400                         ecore_imf_context_client_window_set(imf_context, (void *)ecore_evas_window_get(ecore_evas_ecore_evas_get(ad->evas)));
401                         ecore_imf_context_client_canvas_set(imf_context, ad->evas);
402                 }
403         }
404         return imf_context;
405 }
406
407 static Eina_Bool __imf_event_key_down_cb(void *data, int type, void *event)
408 {
409         SETTING_TRACE_BEGIN;
410         SettingPasswordUG *ad = (SettingPasswordUG *)data;
411         Ecore_Event_Key *ev = event;
412
413         char *commit_str = (char *)ev->key;
414         char *digit = (char *)ev->string;
415         SETTING_TRACE_DEBUG("ev->keyname is %s\n", commit_str); /*here you get the Input String from ISE */
416
417         if (!safeStrCmp(commit_str, "Return"))
418                 return EINA_TRUE;
419         else if (!safeStrCmp(commit_str, KEY_BACK))
420                 return EINA_TRUE;
421
422         if (!safeStrCmp(commit_str, "BackSpace")) {
423                 if (ad->sp_focused_num > 0)
424                         elm_entry_entry_set(ad->sp_entry[--ad->sp_focused_num], "");
425                 if (ad->sp_focused_num < 0)
426                         ad->sp_focused_num = 0;
427         } else {
428                 if (!digit)
429                         return EINA_TRUE;
430
431                 if (ad->sp_focused_num >= 4) {
432                         SETTING_TRACE_DEBUG("all entries are filled.");
433                         return EINA_TRUE;
434                 } else if (ad->sp_focused_num < 0) {
435                         ad->sp_focused_num = 0;
436                 }
437                 char key = digit[0];
438                 SETTING_TRACE_DEBUG("digit is %c", key);
439                 if (key >= '0' && key <= '9') {
440                         ad->sp_chars[ad->sp_focused_num] = key;
441                         elm_entry_entry_set(ad->sp_entry[ad->sp_focused_num], "<align=center>•</align>");
442                         ad->sp_focused_num++;
443                         if (ad->sp_focused_num == 4)
444                                 /*call done cb */
445                                 ad->simple_done_timer = ecore_timer_add(0.2, setting_password_simple_check_4entries, ad);
446                 }
447         }
448
449         return EINA_TRUE;
450 };
451
452 void __imf_show_for_simple_password(void *data)
453 {
454         SETTING_TRACE_BEGIN;
455         ret_if(data == NULL);
456         SettingPasswordUG *ad = (SettingPasswordUG *) data;
457
458         if (ad->imf_context) {
459                 ecore_imf_context_input_panel_show(ad->imf_context);
460         } else {
461                 Ecore_IMF_Context *imf_context = NULL;
462                 imf_context = __imf_context_create(ad);
463
464                 ad->imf_context = imf_context;
465
466                 ecore_imf_context_reset(imf_context);
467                 ecore_imf_context_input_panel_imdata_set(imf_context, (void *)"type=password", 13); /* for password read out with TTS */
468                 ecore_imf_context_input_panel_layout_set(imf_context, ECORE_IMF_INPUT_PANEL_LAYOUT_DATETIME);
469                 ecore_imf_context_focus_in(imf_context);
470                 ad->imf_handler = ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, __imf_event_key_down_cb, ad);
471                 if (!ad->imf_handler)
472                         SETTING_TRACE_DEBUG("handler is NULL");
473         }
474         SETTING_TRACE_END;
475 }
476
477 static void __enable_imf_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
478 {
479         SETTING_TRACE_BEGIN;
480         setting_retm_if(data == NULL, "Data parameter is NULL");
481         SettingPasswordUG *ad = (SettingPasswordUG *) data;
482
483         __imf_show_for_simple_password(ad);
484 }
485
486 static int setting_password_simple_create(void *cb)
487 {
488         SETTING_TRACE_BEGIN;
489         /* error check */
490         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
491
492         SettingPasswordUG *ad = (SettingPasswordUG *) cb;
493
494         ad->sp_focused_num = 0;
495
496         /* Create layout : layout/simple_password in setting-theme.edc */
497         ad->simple_layout = elm_layout_add(ad->win_main_layout);
498         elm_layout_file_set(ad->simple_layout, SETTING_THEME_EDJ_NAME, "layout/simple_password");
499
500         ad->sp_entry1  = elm_entry_add(ad->simple_layout);
501         elm_object_style_set(ad->sp_entry1 , "popup");
502         elm_entry_single_line_set(ad->sp_entry1 , EINA_TRUE);
503         elm_entry_editable_set(ad->sp_entry1 , EINA_FALSE);
504         ad->sp_entry[0] = ad->sp_entry1;
505         elm_object_part_content_set(ad->simple_layout, "entry1", ad->sp_entry1);
506
507         ad->sp_entry2  = elm_entry_add(ad->simple_layout);
508         elm_object_style_set(ad->sp_entry2 , "popup");
509         elm_entry_single_line_set(ad->sp_entry2 , EINA_TRUE);
510         elm_entry_editable_set(ad->sp_entry2 , EINA_FALSE);
511         ad->sp_entry[1] = ad->sp_entry2;
512         elm_object_part_content_set(ad->simple_layout, "entry2", ad->sp_entry2);
513
514         ad->sp_entry3  = elm_entry_add(ad->simple_layout);
515         elm_object_style_set(ad->sp_entry3 , "popup");
516         elm_entry_single_line_set(ad->sp_entry3 , EINA_TRUE);
517         elm_entry_editable_set(ad->sp_entry3 , EINA_FALSE);
518         ad->sp_entry[2] = ad->sp_entry3;
519         elm_object_part_content_set(ad->simple_layout, "entry3", ad->sp_entry3);
520
521         ad->sp_entry4  = elm_entry_add(ad->simple_layout);
522         elm_object_style_set(ad->sp_entry4 , "popup");
523         elm_entry_single_line_set(ad->sp_entry4 , EINA_TRUE);
524         elm_entry_editable_set(ad->sp_entry4 , EINA_FALSE);
525         ad->sp_entry[3] = ad->sp_entry4;
526         elm_object_part_content_set(ad->simple_layout, "entry4", ad->sp_entry4);
527
528         if (ad->view_type == SETTING_PW_TYPE_SIMPLE_PASSWORD)
529                 elm_object_part_text_set(ad->simple_layout, "title.txt", _(sp_titles[3]));
530         else
531                 elm_object_part_text_set(ad->simple_layout, "title.txt", _(sp_titles[1]));
532         /* End */
533
534         ad->ly_main = setting_create_layout_navi_bar(ad->win_main_layout, ad->win_get, "IDS_ST_BODY_SIMPLE_PASSWORD",
535                                                      _("IDS_COM_BODY_BACK"),
536                                                      NULL, NULL,
537                                                      (setting_call_back_func)setting_password_simple_click_softkey_cancel_cb,
538                                                      NULL, NULL,
539                                                      ad,
540                                                      ad->simple_layout,
541                                                      &(ad->navi_bar), NULL);
542         evas_object_event_callback_add(ad->sp_entry1, EVAS_CALLBACK_MOUSE_DOWN, __enable_imf_cb, ad);
543         evas_object_event_callback_add(ad->sp_entry2, EVAS_CALLBACK_MOUSE_DOWN, __enable_imf_cb, ad);
544         evas_object_event_callback_add(ad->sp_entry3, EVAS_CALLBACK_MOUSE_DOWN, __enable_imf_cb, ad);
545         evas_object_event_callback_add(ad->sp_entry4, EVAS_CALLBACK_MOUSE_DOWN, __enable_imf_cb, ad);
546
547         evas_object_show(ad->simple_layout);
548
549         __imf_show_for_simple_password(ad);
550
551         setting_view_password_simple.is_create = 1;
552
553         SETTING_TRACE_END;
554         return SETTING_RETURN_SUCCESS;
555 }
556
557 static int setting_password_simple_destroy(void *cb)
558 {
559         SETTING_TRACE_BEGIN;
560         /* error check */
561         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
562
563         SettingPasswordUG *ad = (SettingPasswordUG *) cb;
564
565         if (ad->imf_handler) {
566                 ecore_event_handler_del(ad->imf_handler);
567                 ad->imf_handler = NULL;
568         }
569         if (ad->imf_context) {
570                 ecore_imf_context_del(ad->imf_context);
571                 ad->imf_context = NULL;
572         }
573
574         if (ad->simple_done_timer) {
575                 ecore_timer_del(ad->simple_done_timer);
576                 ad->simple_done_timer = NULL;
577         }
578
579         if (ad->notify) {
580                 evas_object_del(ad->notify);
581                 ad->notify = NULL;
582         }
583
584         if (ad->ly_main != NULL) {
585                 evas_object_del(ad->ly_main);
586                 ad->ly_main = NULL;
587         }
588
589         setting_view_password_simple.is_create = 0;
590         SETTING_TRACE_END;
591         return SETTING_RETURN_SUCCESS;
592 }
593
594 static int setting_password_simple_update(void *cb)
595 {
596         SETTING_TRACE_BEGIN;
597         /* error check */
598         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
599
600         SettingPasswordUG *ad = (SettingPasswordUG *) cb;
601
602         if (ad->ly_main != NULL) {
603                 evas_object_show(ad->ly_main);
604         }
605         return SETTING_RETURN_SUCCESS;
606 }
607
608 static int setting_password_simple_cleanup(void *cb)
609 {
610         /* error check */
611         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
612
613         SettingPasswordUG *ad = (SettingPasswordUG *) cb;
614
615         if (ad->ly_main != NULL) {
616                 evas_object_hide(ad->ly_main);
617         }
618
619         return SETTING_RETURN_SUCCESS;
620 }
621
622 /* ***************************************************
623  *
624  *general func
625  *
626  ***************************************************/
627
628 int setting_password_simple_draw_next_simple_password(void *data, int title_index)
629 {
630         /* error check */
631         retvm_if(data == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER,
632                  "[Setting > Password] Data parameter is NULL");
633
634         SettingPasswordUG *ad = (SettingPasswordUG *) data;
635
636         elm_object_part_text_set(ad->simple_layout, "title.txt", _(sp_titles[title_index]));
637         elm_entry_entry_set(ad->sp_entry1, "");
638         elm_entry_entry_set(ad->sp_entry2, "");
639         elm_entry_entry_set(ad->sp_entry3, "");
640         elm_entry_entry_set(ad->sp_entry4, "");
641
642         memset(ad->sp_chars, 0x00, 5);
643         ad->sp_focused_num = 0;
644
645         return SETTING_RETURN_SUCCESS;
646 }
647
648 int setting_password_simple_check_simple_password(const char *collection)
649 {
650         retv_if(collection == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
651
652         int sp_len = safeStrLen(collection);
653         int index = 0;
654         char temp;
655
656         SETTING_TRACE_SECURE_DEBUG("collection length is %d", sp_len);
657
658         if (sp_len != 4)
659                 return SETTING_RETURN_FAIL;
660
661         /* check if digit. */
662         for (index = 0; index < sp_len; index++) {
663                 temp = (char)(collection[index]);
664                 if ((temp < '0') || (temp > '9'))
665                         return SETTING_RETURN_FAIL;
666                 else
667                         SETTING_TRACE_SECURE_DEBUG("temp %c", temp);
668         }
669
670         return SETTING_RETURN_SUCCESS;
671 }