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