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[] = {
41 char* security_group_text[] = {
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_object_signal_emit(ud.conform, "elm,state,indicator,overlap", "elm");
148 static Eina_Bool password_view_pop_cb(void *data, Elm_Object_Item *it)
150 if (security_passphrase_mode != PASSPHRASE_STATE_UNDEFINED) {
151 Evas_Object *entry = (Evas_Object *)evas_object_data_get(ud.nf, "setup_entry");
152 evas_object_smart_callback_add(entry, "changed", security_password_entry_changed_cb, NULL);
153 security_passphrase_mode--;
158 static void delete_object_data(void)
160 evas_object_data_del(ud.nf, "setup_entry");
161 evas_object_data_del(ud.nf, "setup_button");
162 evas_object_data_del(ud.nf, "verify_entry");
163 evas_object_data_del(ud.nf, "verify_button");
166 static void security_previous_view_cb(void *data, Evas_Object *obj, void *event_info)
168 elm_naviframe_item_pop(ud.nf);
171 static void security_password_setup_cb(void *data, Evas_Object *obj, void *event_info)
173 appdata_s *ad = (appdata_s *)data;
175 if (security_passphrase_mode < PASSPHRASE_STATE_VERIFY) {
176 security_passphrase_mode++;
177 entry = (Evas_Object *)evas_object_data_get(ud.nf, "setup_entry");
178 evas_object_smart_callback_del(entry, "changed", security_password_entry_changed_cb);
179 create_password_setup_view(ad);
183 if (strcmp(security_password_setup_data, security_password_verify_data) != 0) {
184 entry = (Evas_Object *)evas_object_data_get(ud.nf, "verify_entry");
185 elm_entry_entry_set(entry, "");
186 elm_entry_input_panel_hide(entry);
188 Evas_Object *layout = (Evas_Object *)evas_object_data_get(ud.nf, "layout");
189 elm_object_part_text_set(layout, "entry_info", "Password do not matched.");
190 dlog_print(DLOG_ERROR, LOG_TAG, "Password not matched");
193 delete_object_data();
195 ad->krate_password = security_password_setup_data;
197 if (_send_krate_create_request(ad) != 0) {
201 elm_object_signal_emit(ud.conform, "elm,state,indicator,overlap", "elm");
202 _create_setup_view(ad);
205 static void security_password_entry_unfocused_cb(void *data, Evas_Object *obj, void *event_info)
207 char **password = (char **)data;
208 *password = strdup(elm_entry_entry_get(obj));
211 static void security_password_entry_changed_cb(void *data, Evas_Object *obj, void *event_info)
214 const char *entry_data = elm_entry_entry_get(obj);
216 if (entry_data == NULL)
219 if (security_passphrase_mode < PASSPHRASE_STATE_VERIFY)
220 button = (Evas_Object *)evas_object_data_get(ud.nf, "setup_button");
222 button = (Evas_Object *)evas_object_data_get(ud.nf, "verify_button");
224 if (strlen(entry_data) > 1)
225 elm_object_disabled_set(button, EINA_FALSE);
227 elm_object_disabled_set(button, EINA_TRUE);
230 static Evas_Object *security_password_setup_content_get(void *data, Evas_Object *obj, const char *part)
232 if (!strcmp(part, "elm.swallow.content")) {
233 Evas_Object *layout, *entry;
235 layout = _create_layout(obj, ud.edj_path, "security_layout");
237 entry = _create_entry(obj);
238 elm_object_part_text_set(layout, "title", "Enter password");
239 elm_object_part_content_set(layout, "entry", entry);
240 evas_object_smart_callback_add(entry, "unfocused", security_password_entry_unfocused_cb, data);
241 evas_object_smart_callback_add(entry, "changed", security_password_entry_changed_cb, NULL);
242 elm_entry_input_panel_return_key_disabled_set(entry, EINA_TRUE);
244 if (security_passphrase_mode < PASSPHRASE_STATE_VERIFY)
245 evas_object_data_set(ud.nf, "setup_entry", entry);
247 evas_object_data_set(ud.nf, "verify_entry", entry);
249 evas_object_data_set(ud.nf, "layout", layout);
257 static void create_password_setup_view(appdata_s *ad)
261 Elm_Object_Item *item;
262 Elm_Genlist_Item_Class *itc;
263 Evas_Object *genlist, *layout, *left_button, *right_button;
265 layout = _create_layout(ud.nf, ud.edj_path, "base_layout");
266 genlist = elm_genlist_add(layout);
267 elm_layout_content_set(layout, "content_layout", genlist);
268 elm_object_style_set(genlist, "solid/default");
269 elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
271 left_button = _create_button(layout, PREV_BUTTON, security_previous_view_cb, NULL);
272 right_button = _create_button(layout, NEXT_BUTTON, security_password_setup_cb, ad);
273 elm_object_disabled_set(right_button, EINA_TRUE);
275 _create_two_button_layout(layout, left_button, right_button);
277 if (security_passphrase_mode == 1) {
278 entry = &security_password_setup_data;
279 title = "Setup Password";
280 evas_object_data_set(ud.nf, "setup_button", right_button);
282 entry = &security_password_verify_data;
283 title = "Verify Password";
284 evas_object_data_set(ud.nf, "verify_button", right_button);
287 itc = _create_genlist_item_class("full", NULL, security_password_setup_content_get);
288 item = _append_genlist_item(genlist, itc, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY, (void **)entry);
290 item = elm_naviframe_item_push(ud.nf, title, NULL, NULL, layout, NULL);
291 elm_naviframe_item_title_enabled_set(item, EINA_TRUE, EINA_TRUE);
292 elm_naviframe_item_pop_cb_set(item, password_view_pop_cb, NULL);
295 void _create_security_view(appdata_s *ad)
298 Elm_Object_Item *item;
299 Elm_Genlist_Item_Class *itc;
300 Evas_Object *genlist, *layout, *left_button, *right_button;
302 elm_object_signal_emit(ud.conform, "elm,state,indicator,nooverlap", "elm");
304 layout = _create_layout(ud.nf, ud.edj_path, "base_layout");
305 genlist = elm_genlist_add(layout);
306 elm_object_style_set(genlist, "solid/default");
307 elm_layout_content_set(layout, "content_layout", genlist);
308 elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
310 itc = _create_genlist_item_class("multiline", security_multiline_text_get, NULL);
311 _append_genlist_item(genlist, itc, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY, NULL);
313 itc = _create_genlist_item_class("group_index", security_group_text_get, NULL);
314 _append_genlist_item(genlist, itc, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY, security_group_text[0]);
316 itc = _create_genlist_item_class("one_icon", security_lock_type_text_get, security_lock_type_content_get);
317 for (index = 0; index < ARRAY_SIZE(security_lock_types); index++) {
318 item = elm_genlist_item_append(genlist,
320 &security_lock_types[index],
322 ELM_GENLIST_ITEM_NONE,
323 security_lock_type_select_cb,
324 &security_lock_types[index]);
326 elm_object_item_disabled_set(item, EINA_TRUE);
330 /* Timeout list group*/
331 itc = _create_genlist_item_class("group_index", security_group_text_get, NULL);
332 _append_genlist_item(genlist, itc, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY, security_group_text[1]);
334 itc = _create_genlist_item_class("double_label", security_double_label_text_get, NULL);
335 item = _append_genlist_item(genlist, itc, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY, NULL);
336 elm_object_item_disabled_set(item, EINA_TRUE); /* [TBD] enable timeout options */
338 left_button = _create_button(layout, PREV_BUTTON, security_previous_view_cb, NULL);
339 right_button = _create_button(layout, NEXT_BUTTON, security_password_setup_cb, ad);
340 _create_two_button_layout(layout, left_button, right_button);
342 item = elm_naviframe_item_push(ud.nf, "Krate Security", NULL, NULL, layout, NULL);
343 elm_naviframe_item_title_enabled_set(item, EINA_TRUE, EINA_TRUE);
344 elm_naviframe_item_pop_cb_set(item, security_view_pop_cb, NULL);