2 * Tizen Krate Setup-Wizard application
4 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 #include "krate-setup.h"
23 #define PASSPHRASE_STATE_UNDEFINED 0
24 #define PASSPHRASE_STATE_SETUP 1
25 #define PASSPHRASE_STATE_VERIFY 2
27 #define ARRAY_SIZE(_array_) \
28 (sizeof(_array_) / sizeof(_array_[0]))
32 struct security_lock_type {
37 struct security_lock_type security_lock_types[] = {
38 { "IDS_ST_BODY_PASSWORD", 0 },
41 char *security_group_text[] = {
42 "IDS_ST_MBODY_UNLOCK_METHOD",
45 static char *security_password_setup_data = NULL;
46 static char *security_password_verify_data = NULL;
48 static unsigned int security_passphrase_mode = PASSPHRASE_STATE_UNDEFINED;
49 static int security_lock_type_selected = 0;
51 static void create_password_setup_view(appdata_s *ad);
52 static void security_password_entry_changed_cb(void *data, Evas_Object *obj, void *event_info);
54 static char *security_multiline_text_get(void *data, Evas_Object *obj, const char *part)
56 char text[PATH_MAX] = "\0";
58 if (!strcmp(part, "elm.text.multiline")) {
59 snprintf(text, PATH_MAX, "Select a Krate unlock method and a timeout option.");
66 static char *security_group_text_get(void *data, Evas_Object *obj, const char *part)
68 char *text = (char *)__(data);
70 if (!strcmp(part, "elm.text")) {
78 static char *security_double_label_text_get(void *data, Evas_Object *obj, const char *part)
80 char text[PATH_MAX] = "\0";
81 int timeout = 10; /*[TBD] get value of timeout */
83 if (!strcmp(part, "elm.text"))
84 snprintf(text, PATH_MAX, "Security Timeout");
85 else if (!strcmp(part, "elm.text.sub"))
86 snprintf(text, PATH_MAX, "After %d minuates of inactivity", timeout);
92 static char *security_lock_type_text_get(void *data, Evas_Object *obj, const char *part)
94 struct security_lock_type *locktype = (struct security_lock_type *)data;
96 if (!strcmp(part, "elm.text")) {
97 return strdup(__(locktype->text));
103 static Evas_Object *security_lock_type_content_get(void *data, Evas_Object *obj, const char *part)
105 static Evas_Object *group = NULL;
106 struct security_lock_type *locktype = (struct security_lock_type *)data;
109 group = elm_radio_add(obj);
110 elm_radio_state_value_set(group, 0);
111 elm_radio_value_set(group, 0);
114 if (!strcmp(part, "elm.swallow.icon")) {
115 Evas_Object *radio = elm_radio_add(obj);
116 elm_radio_state_value_set(radio, locktype->index);
118 if (locktype->index == security_lock_type_selected) {
119 elm_radio_value_set(radio, locktype->index);
122 elm_radio_group_add(radio, group);
123 evas_object_propagate_events_set(radio, EINA_FALSE);
124 evas_object_repeat_events_set(radio, EINA_TRUE);
132 static void security_lock_type_select_cb(void *data, Evas_Object *obj, void *event_info)
134 struct security_lock_type *locktype = (struct security_lock_type *)data;
136 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
137 elm_radio_value_set(obj, locktype->index);
138 security_lock_type_selected = locktype->index;
141 static Eina_Bool security_view_pop_cb(void *data, Elm_Object_Item *it)
143 elm_win_indicator_opacity_set(ud.win, ELM_WIN_INDICATOR_BG_TRANSPARENT);
144 elm_object_signal_emit(ud.conform, "elm,state,indicator,overlap", "elm");
149 static Eina_Bool password_view_pop_cb(void *data, Elm_Object_Item *it)
151 if (security_passphrase_mode != PASSPHRASE_STATE_UNDEFINED) {
152 Evas_Object *entry = (Evas_Object *)evas_object_data_get(ud.nf, "setup_entry");
153 evas_object_smart_callback_add(entry, "changed", security_password_entry_changed_cb, NULL);
154 security_passphrase_mode--;
159 static void delete_object_data(void)
161 evas_object_data_del(ud.nf, "setup_entry");
162 evas_object_data_del(ud.nf, "setup_button");
163 evas_object_data_del(ud.nf, "verify_entry");
164 evas_object_data_del(ud.nf, "verify_button");
167 static void security_previous_view_cb(void *data, Evas_Object *obj, void *event_info)
169 elm_naviframe_item_pop(ud.nf);
172 static void security_password_setup_cb(void *data, Evas_Object *obj, void *event_info)
174 appdata_s *ad = (appdata_s *)data;
175 Evas_Object *entry, *entry_text;
177 if (security_passphrase_mode < PASSPHRASE_STATE_VERIFY) {
178 security_passphrase_mode++;
179 entry = (Evas_Object *)evas_object_data_get(ud.nf, "setup_entry");
180 evas_object_smart_callback_del(entry, "changed", security_password_entry_changed_cb);
181 create_password_setup_view(ad);
185 if (strcmp(security_password_setup_data, security_password_verify_data) != 0) {
186 entry = (Evas_Object *)evas_object_data_get(ud.nf, "verify_entry");
187 elm_entry_entry_set(entry, "");
188 elm_entry_input_panel_hide(entry);
190 Evas_Object *layout = (Evas_Object *)evas_object_data_get(ud.nf, "layout");
191 entry_text = _create_textblock(layout, __("IDS_ST_POP_PASSWORD_DO_NOT_MATCH"), ENTRY_INFO_STYLE_G);
192 elm_object_part_content_set(layout, "entry_info", entry_text);
193 dlog_print(DLOG_ERROR, LOG_TAG, "Password not matched");
196 delete_object_data();
198 ad->krate_password = security_password_setup_data;
200 if (_send_krate_create_request(ad) != 0) {
204 elm_win_indicator_opacity_set(ud.win, ELM_WIN_INDICATOR_BG_TRANSPARENT);
205 elm_object_signal_emit(ud.conform, "elm,state,indicator,overlap", "elm");
206 _create_setup_view(ad);
209 static void security_password_entry_unfocused_cb(void *data, Evas_Object *obj, void *event_info)
211 char **password = (char **)data;
212 *password = strdup(elm_entry_entry_get(obj));
215 static void security_password_entry_changed_cb(void *data, Evas_Object *obj, void *event_info)
217 Evas_Object *button = NULL;
218 const char *entry_data = NULL;
220 entry_data = elm_entry_entry_get(obj);
221 if (entry_data == NULL)
224 if (security_passphrase_mode < PASSPHRASE_STATE_VERIFY)
225 button = (Evas_Object *)evas_object_data_get(ud.nf, "setup_button");
227 button = (Evas_Object *)evas_object_data_get(ud.nf, "verify_button");
229 if (strlen(entry_data) > 1)
230 elm_object_disabled_set(button, EINA_FALSE);
232 elm_object_disabled_set(button, EINA_TRUE);
235 static void create_password_setup_view(appdata_s *ad)
239 Elm_Object_Item *item;
240 Evas_Object *layout, *left_button, *right_button;
241 Evas_Object *security_layout, *entry, *entry_title;
243 layout = _create_layout(ud.nf, ud.edj_path, "base_layout");
245 left_button = _create_button(layout, __("IDS_ST_SK_PREVIOUS"), security_previous_view_cb, NULL);
246 right_button = _create_button(layout, __("IDS_ST_BUTTON_NEXT"), security_password_setup_cb, ad);
247 elm_object_disabled_set(right_button, EINA_TRUE);
249 _create_two_button_layout(layout, left_button, right_button);
251 if (security_passphrase_mode == 1) {
252 entry_data = &security_password_setup_data;
253 title = "Setup Password";
254 evas_object_data_set(ud.nf, "setup_button", right_button);
256 entry_data = &security_password_verify_data;
257 title = "Verify Password";
258 evas_object_data_set(ud.nf, "verify_button", right_button);
261 security_layout = _create_layout(layout, ud.edj_path, "security_layout");
263 entry = _create_entry(security_layout);
264 entry_title = _create_textblock(security_layout, __("IDS_ST_BODY_ENTER_PASSWORD"), ENTRY_TITLE_STYLE_B);
265 elm_object_part_content_set(security_layout, "title", entry_title);
266 elm_object_part_content_set(security_layout, "entry", entry);
267 evas_object_smart_callback_add(entry, "unfocused", security_password_entry_unfocused_cb, entry_data);
268 evas_object_smart_callback_add(entry, "changed", security_password_entry_changed_cb, NULL);
270 elm_entry_input_panel_return_key_disabled_set(entry, EINA_TRUE);
271 elm_object_focus_set(entry, EINA_TRUE);
273 if (security_passphrase_mode < PASSPHRASE_STATE_VERIFY)
274 evas_object_data_set(ud.nf, "setup_entry", entry);
276 evas_object_data_set(ud.nf, "verify_entry", entry);
278 evas_object_data_set(ud.nf, "layout", security_layout);
280 elm_object_part_content_set(layout, "content_layout", security_layout);
282 item = elm_naviframe_item_push(ud.nf, title, NULL, NULL, layout, NULL);
283 elm_naviframe_item_title_enabled_set(item, EINA_TRUE, EINA_TRUE);
284 elm_naviframe_item_pop_cb_set(item, password_view_pop_cb, NULL);
287 void _create_security_view(appdata_s *ad)
290 Elm_Object_Item *item;
291 Elm_Genlist_Item_Class *itc;
292 Evas_Object *genlist, *layout, *left_button, *right_button;
294 elm_win_indicator_opacity_set(ud.win, ELM_WIN_INDICATOR_OPAQUE);
295 elm_object_signal_emit(ud.conform, "elm,state,indicator,nooverlap", "elm");
297 layout = _create_layout(ud.nf, ud.edj_path, "base_layout");
298 genlist = elm_genlist_add(layout);
299 elm_object_style_set(genlist, "solid/default");
300 elm_layout_content_set(layout, "content_layout", genlist);
301 elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
303 itc = _create_genlist_item_class("multiline", security_multiline_text_get, NULL);
304 _append_genlist_item(genlist, itc, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY, NULL);
306 itc = _create_genlist_item_class("group_index", security_group_text_get, NULL);
307 _append_genlist_item(genlist, itc, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY, security_group_text[0]);
309 itc = _create_genlist_item_class("one_icon", security_lock_type_text_get, security_lock_type_content_get);
310 for (index = 0; index < ARRAY_SIZE(security_lock_types); index++) {
311 item = elm_genlist_item_append(genlist,
313 &security_lock_types[index],
315 ELM_GENLIST_ITEM_NONE,
316 security_lock_type_select_cb,
317 &security_lock_types[index]);
320 /* Timeout list group*/
321 itc = _create_genlist_item_class("group_index", security_group_text_get, NULL);
322 _append_genlist_item(genlist, itc, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY, security_group_text[1]);
324 itc = _create_genlist_item_class("double_label", security_double_label_text_get, NULL);
325 item = _append_genlist_item(genlist, itc, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY, NULL);
326 elm_object_item_disabled_set(item, EINA_TRUE); /* [TBD] enable timeout options */
328 left_button = _create_button(layout, __("IDS_ST_SK_PREVIOUS"), security_previous_view_cb, NULL);
329 right_button = _create_button(layout, __("IDS_ST_BUTTON_NEXT"), security_password_setup_cb, ad);
330 _create_two_button_layout(layout, left_button, right_button);
332 item = elm_naviframe_item_push(ud.nf, "Krate Security", NULL, NULL, layout, NULL);
333 elm_naviframe_item_title_enabled_set(item, EINA_TRUE, EINA_TRUE);
334 elm_naviframe_item_pop_cb_set(item, security_view_pop_cb, NULL);