ab5a976a70efb7d005188839ad9de11865911ccf
[platform/core/security/ode.git] / tools / apps / ode / src / password / confirm-popup.c
1 /*
2  *
3  * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 #include <ode/external-encryption.h>
19 #include "ode-password.h"
20
21 #define PASSWORD_TITLE_STYLE_B "DEFAULT='font=Tizen:style=Regular font_size=38 color=#000000 wrap=mixed align=center'"
22 #define PASSWORD_CONTENT_STYLE_B "DEFAULT='font=Tizen:style=Regular font_size=32 color=#000000 wrap=mixed'"
23 #define EDJ_PATH "/usr/apps/" PACKAGE "/res/" PACKAGE ".edj"
24
25 static Evas_Object *confirm_entry = NULL;
26
27 static void key_event_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
28 {
29         Evas_Event_Key_Down *ev = (Evas_Event_Key_Down *)event_info;
30         popup_data_s *popup_data = (popup_data_s *)data;
31
32         if (!strcmp(ev->keyname, "XF86Back")) {
33                 evas_object_del(popup_data->popup);
34                 if (popup_data->mode == INSERT_SD_CARD)
35                         create_insert_sdcard_popup(popup_data);
36         }
37         return;
38 }
39
40 static void confirm_password_popup_cancel_cb(void *data, Evas_Object *obj, void *event_info)
41 {
42         popup_data_s *popup_data = (popup_data_s *)data;
43
44         evas_object_del(popup_data->popup);
45         if (popup_data->mode == INSERT_SD_CARD)
46                 create_insert_sdcard_popup(popup_data);
47         return;
48 }
49
50 static void confirm_password_popup_confirm_cb(void *data, Evas_Object *obj, void *event_info)
51 {
52         int ret = 0;
53         bool result = 0;
54         popup_data_s *popup_data = (popup_data_s *)data;
55
56         ret = ode_external_encryption_verify_password(elm_entry_entry_get(confirm_entry), &result);
57         if (ret != ODE_ERROR_NONE) {
58                 dlog_print(DLOG_ERROR, LOG_TAG, "failed to verify password");
59                 return;
60         }
61
62         if (!result) {
63                 /* error */
64                 dlog_print(DLOG_ERROR, LOG_TAG, "password not matched");
65                 return;
66         }
67
68         if (popup_data->mode == CHANGE_PASSWORD) {
69                 snprintf(popup_data->entry_data_old, PATH_MAX, "%s", elm_entry_entry_get(confirm_entry));
70                 evas_object_del(popup_data->popup);
71                 create_password_message_popup(popup_data);
72         } else {
73                 if (popup_data->entry_data)
74                         snprintf(popup_data->entry_data, PATH_MAX, "%s", elm_entry_entry_get(confirm_entry));
75                 evas_object_del(popup_data->popup);
76                 password_result_callback(popup_data, "success");
77         }
78
79         return;
80 }
81
82 void create_confirm_password_popup(popup_data_s *data)
83 {
84         Evas_Object *layout = NULL, *textblock = NULL;
85         Evas_Object *cancel_button = NULL, *next_button = NULL;
86
87         if (data->mode == INSERT_SD_CARD)
88                 data->popup = ode_create_popup(data->parent, __("IDS_ST_HEADER_USE_ENCRYPTED_SD_CARD"), NULL);
89         else
90                 data->popup = ode_create_popup(data->parent, __("IDS_ST_BODY_PASSWORD"), NULL);
91
92         layout = ode_create_layout(data->popup, EDJ_PATH, "entry_popup");
93         elm_object_part_content_set(data->popup, "elm.swallow.content", layout);
94
95         textblock = ode_create_textblock(layout, __("IDS_LCKSCN_NPBODY_ENTER_PASSWORD"), PASSWORD_TITLE_STYLE_B);
96         elm_object_part_content_set(layout, "title", textblock);
97
98         confirm_entry = ode_create_entry(layout);
99         elm_object_part_content_set(layout, "entry", confirm_entry);
100
101         cancel_button = ode_create_popup_button(data->popup, __("IDS_ST_BUTTON_CANCEL"),
102                                                         confirm_password_popup_cancel_cb, data);
103         next_button = ode_create_popup_button(data->popup, __("IDS_ST_BUTTON_DONE"),
104                                                         confirm_password_popup_confirm_cb, data);
105         elm_object_part_content_set(data->popup, "button1", cancel_button);
106         elm_object_part_content_set(data->popup, "button2", next_button);
107
108         evas_object_event_callback_add(data->popup, EVAS_CALLBACK_KEY_DOWN, key_event_cb, data);
109         evas_object_show(data->popup);
110         return;
111 }