2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "view_pwd_popup.h"
21 #include "settings_provider.h"
22 #include "settingviewmgr.h"
24 #define PWD_DATA_ID "change_passcode_data"
25 #define CTXPOPUP_WIDTH 688
26 #define CTXPOPUP_HEIGHT 411
29 #define BOX_HPADDING 10
30 #define BOX_VPADDING 0
32 #define MSGID_PWD_TITLE "Change passcode"
33 #define MSGID_UPTEXT "Enter your old passcode"
34 #define MSGID_DOWNTEXT "Default passcode is 0000"
35 #define MSGID_INVALID_PWD "Failed passcode attempt"
36 #define MSGID_NEW_PWD "Enter your new passcode"
37 #define MSGID_REENTER_PWD "Re-enter your new passcode"
38 #define MSGID_DIFFER_PWD "Not same passcode. Enter again"
39 #define MSGID_CANCEL "Cancel"
40 #define PWD_SYMBOL "*"
41 #define PWD_RANGE "0123456789"
43 #define SIG_CLICKED "clicked"
44 #define SIG_DISMISSED "dismissed"
54 struct SPasscodePopupView {
58 Evas_Object *cancel_btn;
59 Evas_Object *ctxpopup;
65 char entered_pwd[PWD_SIZE];
66 char reentered_pwd[PWD_SIZE];
73 struct settingview_data *view;
76 //static void _hide(Evas_Object *base);
81 * @param[in]: data : the user data of change passcode view.
85 static void _free_pwd_data(SPasscodePopupView *data)
91 evas_object_del(data->bg);
94 evas_object_del(data->base);
97 evas_object_del(data->ctxpopup);
100 eina_array_free(data->array);
104 * Create background of change passcode view.
106 * @param[in]: win : the window this view created on.
108 * @return: the created background of type evas object.
110 static Evas_Object *_add_pwd_bg(Evas_Object *win)
117 bg = utils_add_base(win);
119 _ERR("elm layout add failed.");
123 elm_layout_file_set(bg, EDJ_FILE, GRP_PWD_BG);
129 * Create the base layout of change passcode view.
131 * @param[in]: ctxpopup : the ctxpopup which contains change passcode view.
133 * @return: the created base layout of change passcode view.
135 static Evas_Object *_add_pwd_base(Evas_Object *ctxpopup)
142 base = utils_add_base(ctxpopup);
144 _ERR("elm layout add failed.");
148 elm_layout_file_set(base, EDJ_FILE, GRP_PWD_VIEW);
150 elm_object_part_text_set(base, PART_TITLE,
151 utils_get_translation_str(MSGID_PWD_TITLE));
152 elm_object_part_text_set(base, PART_UPTEXT,
153 utils_get_translation_str(MSGID_UPTEXT));
154 elm_object_part_text_set(base, PART_DOWNTEXT,
155 utils_get_translation_str(MSGID_DOWNTEXT));
161 * Evas_Smart_Cb type callback for handling click event.
163 * @param[in]: priv : the user data.
164 * @param[in]: obj : the corresponding object which the click event occurred.
165 * @param[in]: ev : event info.
169 static void _cancelbtn_clicked_cb(void *priv, Evas_Object *obj, void *ev)
171 SPasscodePopupView *data;
176 data = (SPasscodePopupView *) priv;
178 data->mgr->ViewPop();
182 * Create cancel button of change passcode view.
184 * @param[in]: data : the user data of change passcode view.
186 * @return: the created cancel button or null if error occurred.
188 static Evas_Object *_add_pwd_cancel_btn(SPasscodePopupView *data)
192 if (!data || !data->base)
195 btn = utils_add_btn(data->base, PWD_BASIC_BTN,
196 utils_get_translation_str((const char *) MSGID_CANCEL), EINA_TRUE);
198 _ERR("utils add button failed.");
202 evas_object_smart_callback_add(btn, SIG_CLICKED,
203 _cancelbtn_clicked_cb, data);
205 elm_object_part_content_set(data->base, SWALLOW_CANCEL_BTN, btn);
207 elm_object_focus_allow_set(btn, EINA_TRUE);
213 * Set the move directions of focus between entries and cancel button.
215 * @param[in]: array : eina array containing entries.
216 * @param[in]: cancel_btn : the cancel button.
220 static void _set_entry_directions(Eina_Array *array, Evas_Object *cancel_btn)
226 if (!array || !cancel_btn)
229 for (i = ENTRY_0; i < ENTRY_3; i++) {
230 en = (Evas_Object *) eina_array_data_get(array, i);
234 elm_object_focus_next_object_set(en,
235 (Evas_Object *) eina_array_data_get(array, i + 1),
237 elm_object_focus_next_object_set(en, en, ELM_FOCUS_LEFT);
238 elm_object_focus_next_object_set(en, en, ELM_FOCUS_RIGHT);
239 elm_object_focus_next_object_set(en, en, ELM_FOCUS_UP);
240 elm_object_focus_next_object_set(en, cancel_btn,
244 lasten = (Evas_Object *) eina_array_data_get(array, ENTRY_3);
245 elm_object_focus_next_object_set(lasten, lasten, ELM_FOCUS_UP);
246 elm_object_focus_next_object_set(lasten, cancel_btn, ELM_FOCUS_DOWN);
247 elm_object_focus_next_object_set(lasten, lasten, ELM_FOCUS_LEFT);
248 elm_object_focus_next_object_set(lasten, lasten, ELM_FOCUS_RIGHT);
250 elm_object_focus_next_object_set(cancel_btn, cancel_btn,
252 elm_object_focus_next_object_set(cancel_btn, cancel_btn,
254 elm_object_focus_next_object_set(cancel_btn,
255 (Evas_Object *) eina_array_data_get(array, ENTRY_0), ELM_FOCUS_UP);
256 elm_object_focus_next_object_set(cancel_btn, cancel_btn,
263 * @param[in]: vdata : view data.
265 * @return: the passcode.
267 static char *_get_pwd(struct settingview_data *vdata)
269 struct settingitem *item;
274 item = viewdata_get_parentitem(vdata);
276 _ERR("get parent item failed.");
280 return provider_get_list_value(item);
284 * Check if the input passcode is right.
286 * @param[in]: data : the user data of change passcode view.
288 * @return: 0 - wrong passcode, 1 - right passcode.
290 static int _check_pwd(SPasscodePopupView *data)
294 if (!data || !data->view)
297 pwd = _get_pwd(data->view);
299 _ERR("get passcode failed.");
303 if (strncmp(data->pwd, pwd, strlen(pwd))) {
316 * @param[in]: pwd : the passcode.
320 static void _clear_pwd(char *pwd)
337 * This function clears displayed passcode in entries when user
338 * inputs wrong passcode.
340 * @param[in]: data : the user data of change passcode view.
344 static void _reset_pwd(SPasscodePopupView *data)
346 Evas_Object *btn, *first;
350 if (!data || !data->array || !data->base)
355 first = (Evas_Object *) eina_array_data_get(array, ENTRY_0);
359 elm_object_focus_set(first, EINA_TRUE);
360 elm_object_focus_next_object_set(data->cancel_btn, first, ELM_FOCUS_UP);
362 for (i = ENTRY_0; i < ENTRY_MAX; i++) {
363 btn = (Evas_Object *)eina_array_data_get(array, i);
367 elm_object_text_set(btn, "");
372 * Set passcode to system.
374 * @param[in]: data : the user data of change passcode view.
376 * @return: 0 - Success, -1 - Fail.
378 static int _set_pwd(SPasscodePopupView *data)
381 struct settingitem *item;
383 if (!data || !data->view)
386 item = viewdata_get_parentitem(data->view);
388 _ERR("get parent item failed.");
392 ret = provider_set_list_value(item, data->pwd);
394 _ERR("set passcode failed.");
402 * Check if the reentered passcode is right.
404 * @param[in]: data : the user data of change passcode view.
406 * @return: 0 - Success, -1 - Fail.
408 static int _check_reentered_pwd(SPasscodePopupView *data)
413 if (strncmp(data->entered_pwd, data->reentered_pwd,
421 * Update text of change passcode view.
423 * @param[in]: data : the user data of change passcode view.
424 * @param[in]: part : edje part of text.
425 * @param[in]: msgid : the message id of text.
429 static void _update_pwd_ui(SPasscodePopupView *data,
430 const char *part, const char *msgid)
434 if (!data || !data->base || !msgid || !part)
439 text = utils_get_translation_str(msgid);
440 elm_object_part_text_set(data->base, part, text);
444 * Evas_Object_Event_Cb type callback for handling key press event.
446 * @param[in]: priv : the user data.
447 * @param[in]: e : the evas canvas.
448 * @param[in]: obj : the corresponding object which the key press event occurred.
449 * @param[in]: ei : event info.
453 static void _entry_keypress_cb(void *priv, Evas *e,
454 Evas_Object *obj, void *ei)
456 Evas_Event_Key_Down *event;
458 Evas_Object *next_entry;
459 SPasscodePopupView *data;
463 if (!priv || !ei || !obj)
466 data = (SPasscodePopupView *) priv;
471 event = (Evas_Event_Key_Down *) ei;
472 keyname = event->keyname;
477 for (i = ENTRY_0; i < ENTRY_MAX; i++) {
478 if (obj == eina_array_data_get(array, i)) {
484 if (!strncmp(keyname, KEY_BACK, strlen(keyname)) || !strncmp(keyname, KEY_BACK_REMOTE, strlen(keyname))) {
485 data->mgr->ViewPop();
486 } else if (!strncmp(keyname, KEY_DOWN, strlen(keyname))) {
487 elm_object_focus_set(data->cancel_btn, EINA_TRUE);
488 } else if (!strncmp(keyname, KEY_0, strlen(keyname)) ||
489 !strncmp(keyname, KEY_1, strlen(keyname)) ||
490 !strncmp(keyname, KEY_2, strlen(keyname)) ||
491 !strncmp(keyname, KEY_3, strlen(keyname)) ||
492 !strncmp(keyname, KEY_4, strlen(keyname)) ||
493 !strncmp(keyname, KEY_5, strlen(keyname)) ||
494 !strncmp(keyname, KEY_6, strlen(keyname)) ||
495 !strncmp(keyname, KEY_7, strlen(keyname)) ||
496 !strncmp(keyname, KEY_8, strlen(keyname)) ||
497 !strncmp(keyname, KEY_9, strlen(keyname))) {
498 elm_entry_entry_set(obj, PWD_SYMBOL);
500 data->pwd[entry_idx] = keyname[0];
502 if (data->new_flag && !data->renew_flag)
503 data->entered_pwd[entry_idx] = keyname[0];
505 if (data->renew_flag)
506 data->reentered_pwd[entry_idx] = keyname[0];
508 if (entry_idx < ENTRY_3) {
509 elm_object_focus_next(obj, ELM_FOCUS_NEXT);
510 next_entry = elm_object_focus_next_object_get(obj,
513 _ERR("next entry is null.");
517 elm_object_focus_next_object_set(data->cancel_btn,
518 next_entry, ELM_FOCUS_UP);
520 if (!data->new_flag) {
521 if (_check_pwd(data)) {
522 _update_pwd_ui(data, PART_UPTEXT,
527 _update_pwd_ui(data, PART_UPTEXT,
530 } else if (!data->renew_flag) {
531 _update_pwd_ui(data, PART_UPTEXT,
534 data->renew_flag = 1;
536 if (_check_reentered_pwd(data)) {
537 if (_set_pwd(data) != 0) {
538 _ERR("set passcode failed.");
543 data->renew_flag = 0;
545 data->mgr->ViewPop();
547 _update_pwd_ui(data, PART_UPTEXT,
550 data->renew_flag = 0;
561 * @param[in]: parent : object the entry will be created on.
563 * @return: the created entry or null if error occurred.
565 static Evas_Object *_add_entry(Evas_Object *parent)
568 Elm_Entry_Filter_Limit_Size length = {
571 Elm_Entry_Filter_Accept_Set type = {
578 entry = utils_add_entry(parent);
580 _ERR("utils add entry failed.");
584 elm_entry_markup_filter_append(entry,
585 elm_entry_filter_limit_size, &length);
586 elm_entry_markup_filter_append(entry,
587 elm_entry_filter_accept_set, &type);
589 elm_object_style_set(entry, STYLE_PWD_ENTRY);
591 elm_entry_text_style_user_push(entry, STYLE_ENTRY_TEXT);
592 elm_object_part_content_set(parent, SWALLOW_ENTRY, entry);
598 * Create entries for inputting passcode.
600 * @param[in]: data : the user data of change passcode view.
602 * @return: 0 - Success, -1 - Fail.
604 static int _add_pwd_entry(SPasscodePopupView *data)
609 Evas_Object *entry_base;
612 if (!data || !data->base) {
613 _ERR("invalid arguments.");
617 box = utils_add_box(data->base);
619 _ERR("add box failed.");
623 elm_box_horizontal_set(box, EINA_TRUE);
624 elm_box_padding_set(box, BOX_HPADDING, BOX_VPADDING);
626 array = eina_array_new(1);
628 _ERR("new eina array failed.");
629 evas_object_del(box);
633 for (i = ENTRY_0; i < ENTRY_MAX; i++) {
634 entry_base = utils_add_base(data->base);
636 _ERR("entry base created failed.");
637 evas_object_del(box);
638 eina_array_free(array);
642 elm_layout_file_set(entry_base, EDJ_FILE, GRP_PWD_ENTRY);
644 entry = _add_entry(entry_base);
646 _ERR("add entry failed.");
647 evas_object_del(box);
648 evas_object_del(entry_base);
649 eina_array_free(array);
653 eina_array_push(array, entry);
654 elm_box_pack_end(box, entry_base);
656 evas_object_event_callback_add(entry, EVAS_CALLBACK_KEY_DOWN,
657 _entry_keypress_cb, data);
660 elm_object_part_content_set(data->base, SWALLOW_CONTENT_AREA, box);
662 elm_object_focus_allow_set(
663 (Evas_Object *) eina_array_data_get(array, ENTRY_0), EINA_TRUE);
664 elm_object_focus_set(
665 (Evas_Object *)eina_array_data_get(array, ENTRY_0), EINA_TRUE);
667 _set_entry_directions(array, data->cancel_btn);
676 * Evas_Smart_Cb type callback for handling ctxpopup dismissed event.
678 * @param[in]: priv : the user data.
679 * @param[in]: obj : the corresponding object which the dismissed event occurred.
680 * @param[in]: ev : event info.
684 void CPasscodePopupView::sm_CbCtxpopupDismissed(void *priv, Evas_Object *obj, void *ev)
686 CPasscodePopupView *root = (CPasscodePopupView*)priv;
688 root->m_OnCtxpopupDismissed(obj, ev);
692 void CPasscodePopupView::m_OnCtxpopupDismissed(Evas_Object *obj, void *ev)
697 if (!m->base || !m->mgr)
707 Evas_Object* CPasscodePopupView::Base(void)
716 * Create all the UI components of change passcode view.
718 * @param[in]: mgr : view manager of settings views.
719 * @param[in]: view : data of view.
720 * @prev[in]: prev : the user data.
722 * @return: the base layout of change passcode view or null
725 bool CPasscodePopupView::Create(struct settingview_data *view, void *prev)
730 CSettingMgr *mgr = CSettingMgr::GetInstance();
733 Evas_Object *base, *bg;
735 Evas_Object *cancel_btn;
736 Evas_Object *ctxpopup;
744 m = new SPasscodePopupView;
746 _ERR("calloc _change_passcode_data failed.");
754 bg = _add_pwd_bg(win);
756 _ERR("add change passcode background failed.");
760 ctxpopup = utils_add_ctxpopup(win, (char *) CHANGE_PWD_CTXPOPUP_STYLE);
762 _ERR("add ctxpopup failed.");
766 m->ctxpopup = ctxpopup;
768 base = _add_pwd_base(m->ctxpopup);
770 _ERR("add change passcode base layout failed.");
776 elm_object_content_set(ctxpopup, base);
781 xpos = (width - CTXPOPUP_WIDTH) / 2;
782 ypos = (height - CTXPOPUP_HEIGHT) / 2;
783 evas_object_move(m->ctxpopup, xpos * ELM_SCALE, ypos * ELM_SCALE);
785 cancel_btn = _add_pwd_cancel_btn(m);
787 _ERR("add change passcode cancel button failed.");
791 m->cancel_btn = cancel_btn;
793 ret = _add_pwd_entry(m);
795 _ERR("add change passcode input buttons failed.");
803 evas_object_smart_callback_add(m->ctxpopup,
804 SIG_DISMISSED, sm_CbCtxpopupDismissed, this);
806 evas_object_data_set(base, PWD_DATA_ID, m);
818 * Show the change passcode view.
820 * @param[in]: base : the base layout of change passcode view.
824 void CPasscodePopupView::Show(void)
828 evas_object_show(m->ctxpopup);
832 * Destroy the change passcode view.
834 * @param[in]: base : the base layout of change passcode view.
838 void CPasscodePopupView::Destroy(void)
848 * Hide the change passcode view.
850 * @param[in]: base : the base layout of change passcode view.
854 void CPasscodePopupView::Hide(void)
858 evas_object_hide(m->bg);
859 evas_object_hide(m->ctxpopup);
865 * view class of change passcode view.
867 static struct setting_class _vclass = {
868 VCLASS_TITLE_CHANGE_PASSCODE,
884 * Return view class of change passcode view.
888 * @return: the view class of change passcode view.
890 struct setting_class *view_passcode_popup_get_vclass(void)