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