fix bugs of ode app
[platform/core/security/ode.git] / tools / apps / ode / src / ode-app-common.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
19 #include "ode-app.h"
20 #include "ode-password.h"
21
22 char *confirm_button_text[] = {
23         "IDS_ST_BUTTON_BACK",
24         "IDS_ST_BUTTON_ENCRYPT_ABB2",
25         "IDS_ST_BUTTON_DECRYPT_DEVICE"
26 };
27
28 void set_icon(appdata_s *ad, int type, char *part)
29 {
30         Evas_Object *icon_check = NULL, *icon_bar = NULL;
31         int ret;
32         if (ad->encryption_layout == NULL || ad->icon_check_path == NULL || ad->icon_bar_path == NULL) {
33                 dlog_print(DLOG_ERROR, LOG_TAG, "invalid parameter");
34                 return;
35         }
36         if (type == ICON_CHECK) {
37                 icon_check = elm_image_add(ad->encryption_layout);
38                 if (icon_check == NULL) {
39                         dlog_print(DLOG_ERROR, LOG_TAG, "elm_image_add failed");
40                         return;
41                 }
42                 if (elm_image_file_set(icon_check, ad->icon_check_path, NULL) == EINA_FALSE) {
43                         dlog_print(DLOG_ERROR, LOG_TAG, "elm_image_file_set failed");
44                         return;
45                 }
46                 evas_object_color_set(icon_check, 153, 153, 153, 255);
47                 evas_object_size_hint_align_set(icon_check, EVAS_HINT_FILL, EVAS_HINT_FILL);
48                 evas_object_size_hint_weight_set(icon_check, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
49
50                 ret = elm_layout_content_set(ad->encryption_layout, part, icon_check);
51                 if (!ret) {
52                         dlog_print(DLOG_ERROR, LOG_TAG, "elm_layout_content_set failed");
53                         return;
54                 }
55                 evas_object_show(icon_check);
56         } else if (type == ICON_BAR) {
57                 icon_bar = elm_image_add(ad->encryption_layout);
58                 if (icon_bar == NULL) {
59                         dlog_print(DLOG_ERROR, LOG_TAG, "elm_image_add failed");
60                         return;
61                 }
62                 elm_image_file_set(icon_bar, ad->icon_bar_path, NULL);
63                 evas_object_color_set(icon_bar, 0, 0, 0, 255);
64                 evas_object_size_hint_align_set(icon_bar, EVAS_HINT_FILL, EVAS_HINT_FILL);
65                 evas_object_size_hint_weight_set(icon_bar, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
66
67                 ret = elm_layout_content_set(ad->encryption_layout, part, icon_bar);
68                 if (!ret) {
69                         dlog_print(DLOG_ERROR, LOG_TAG, "elm_layout_content_set failed");
70                         return;
71                 }
72                 evas_object_show(icon_bar);
73         }
74 }
75
76 void _prev_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
77 {
78         appdata_s *ad = (appdata_s *)data;
79         elm_naviframe_item_pop(ad->navi_bar);
80 }
81
82 void set_next_btn(Evas_Object *layout, const char* edj_path, const char *btn_text, Evas_Smart_Cb callback, const void* data)
83 {
84         Evas_Object *btn_layout;
85         Evas_Object *next_btn;
86         appdata_s *ad = (appdata_s *)data;
87         dlog_print(DLOG_DEBUG, LOG_TAG, "set_next_btn start");
88         btn_layout = ode_create_layout(layout, edj_path, "next_button_layout");
89
90         next_btn = ode_create_button(btn_layout, btn_text, "bottom");
91         elm_object_part_content_set(btn_layout, "next_button", next_btn);
92         ad->device_info.next_button = next_btn;
93
94         evas_object_smart_callback_add(next_btn, "clicked", callback, data);
95         elm_object_part_content_set(layout, "bottom_layout", btn_layout);
96         return;
97 }
98
99 void set_two_btn(Evas_Object *layout, appdata_s *ad, Evas_Smart_Cb callback, const void* data)
100 {
101         Evas_Object *btn_layout;
102         Evas_Object *prev_btn, *next_btn;
103
104         btn_layout = ode_create_layout(layout, ad->edj_path, "two_button_layout");
105
106         prev_btn = ode_create_button(layout, __("IDS_ST_BUTTON_BACK"), "bottom");
107         elm_object_part_content_set(btn_layout, "prev_button", prev_btn);
108         evas_object_smart_callback_add(prev_btn, "clicked", _prev_btn_clicked_cb, data);
109
110         next_btn = ode_create_button(layout, __("IDS_ST_BUTTON_NEXT"), "bottom");
111         ad->device_info.next_button = next_btn;
112         elm_object_part_content_set(btn_layout, "next_button", next_btn);
113
114         evas_object_smart_callback_add(next_btn, "clicked", callback, data);
115
116         elm_object_part_content_set(layout, "bottom_layout", btn_layout);
117         return;
118 }
119
120 void _back_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
121 {
122         ui_app_exit();
123 }
124
125 static Eina_Bool _pop_cb(void *data, Elm_Object_Item *it)
126 {
127         ui_app_exit();
128         return EINA_FALSE;
129 }
130
131 void sw_back_btn_set(Evas_Object *obj, const char *title_label, Evas_Object *content)
132 {
133         Evas_Object *back_btn = NULL;
134
135         back_btn = elm_button_add(obj);
136         elm_object_style_set(back_btn, "naviframe/back_btn/default");
137         evas_object_smart_callback_add(back_btn, "clicked", _back_btn_clicked_cb, obj);
138
139         Elm_Object_Item *nf_it = elm_naviframe_item_push(obj, title_label, back_btn, NULL, content, NULL);
140         elm_naviframe_item_pop_cb_set(nf_it, _pop_cb, NULL);
141 }
142
143 void set_change_pw_btn(Evas_Object *layout, const char *edj_path, const char *btn_text, Evas_Smart_Cb callback, const void* data)
144 {
145         Evas_Object *btn_layout;
146
147         btn_layout = ode_create_layout(layout, edj_path, "one_button_layout");
148
149         btn_layout = ode_create_button(btn_layout, btn_text, "default");
150         elm_object_part_content_set(btn_layout, "button_base", btn_layout);
151         evas_object_smart_callback_add(btn_layout, "clicked", callback, data);
152
153         elm_object_part_content_set(layout, "change_pw_btn_base", btn_layout);
154         return;
155 }
156
157 void set_confirm_two_btn(Evas_Object *layout, const char *edj_path, int text_idx, Evas_Smart_Cb callback, const void* data)
158 {
159         Evas_Object *btn_layout;
160         Evas_Object *prev_btn, *next_btn;
161
162         btn_layout = ode_create_layout(layout, edj_path, "two_button_layout");
163
164         prev_btn = ode_create_button(layout, __(confirm_button_text[0]), "bottom");
165         elm_object_part_content_set(btn_layout, "prev_button", prev_btn);
166         evas_object_smart_callback_add(prev_btn, "clicked", _prev_btn_clicked_cb, data);
167
168         next_btn = ode_create_button(layout, __(confirm_button_text[text_idx]), "bottom");
169         elm_object_part_content_set(btn_layout, "next_button", next_btn);
170
171         evas_object_smart_callback_add(next_btn, "clicked", callback, data);
172         elm_object_part_content_set(layout, "bottom_layout", btn_layout);
173         return;
174 }