Implement OOBE view #6
[apps/native/ug-wifi-efl.git] / sources / libraries / Common / common_pswd_popup.c
1 /*
2  * Wi-Fi
3  *
4  * Copyright 2012 Samsung Electronics Co., Ltd
5  *
6  * Licensed under the Flora License, Version 1.1 (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
9  *
10  * http://www.tizenopensource.org/license
11  *
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.
17  *
18  */
19 #include <feedback.h>
20 #include <efl_extension.h>
21
22 #include "common.h"
23 #include "common_utils.h"
24 #include "common_pswd_popup.h"
25 #include "common_generate_pin.h"
26 #include "i18nmanager.h"
27 #include "ug_wifi.h"
28
29 #define EDJ_GRP_POPUP_PBC_BUTTON_LAYOUT "popup_pbc_button_layout"
30 #define EDJ_GRP_POPUP_WPS_PIN_LAYOUT "popup_wps_pin_layout"
31
32 #define MAX_PBC_TIMEOUT_SECS    120     // Time in seconds
33 #define PASSWORD_LENGTH         64
34
35 static Elm_Genlist_Item_Class g_wps_itc;
36 static Elm_Genlist_Item_Class g_check_box_itc;
37 static Elm_Genlist_Item_Class g_pswd_entry_itc;
38 static gboolean wps_options_click = FALSE;
39 static gboolean keypad_state = FALSE;
40
41 static void __popup_entry_changed_cb(void* data, Evas_Object* obj, void* event_info)
42 {
43         Evas_Object *btn_ok = NULL;
44         pswd_popup_t *pswd_popup_data = NULL;
45         char* entry_str = NULL;
46         unsigned short int passwd_length = 0;
47
48         if (!data)
49                 return;
50
51         pswd_popup_data = (pswd_popup_t *) data;
52         entry_str = passwd_popup_get_txt(pswd_popup_data);
53         if (entry_str != NULL)
54                 passwd_length = strlen(entry_str);
55
56         btn_ok = elm_object_part_content_get(pswd_popup_data->popup, "button2");
57
58         if (pswd_popup_data->sec_type == WIFI_MANAGER_SECURITY_TYPE_WEP) {
59                 if (passwd_length > 0) {
60                         elm_object_disabled_set(btn_ok, EINA_FALSE);
61                         elm_entry_input_panel_return_key_disabled_set(obj,
62                                         EINA_FALSE);
63                 } else {
64                         elm_object_disabled_set(btn_ok, EINA_TRUE);
65                         elm_entry_input_panel_return_key_disabled_set(obj,
66                                         EINA_TRUE);
67                 }
68         } else if (pswd_popup_data->sec_type == WIFI_MANAGER_SECURITY_TYPE_WPA2_PSK ||
69                         pswd_popup_data->sec_type == WIFI_MANAGER_SECURITY_TYPE_WPA_PSK) {
70                 if (passwd_length > 7) {
71                         elm_object_disabled_set(btn_ok, EINA_FALSE);
72                         elm_entry_input_panel_return_key_disabled_set(obj,
73                                         EINA_FALSE);
74                 } else {
75                         elm_object_disabled_set(btn_ok, EINA_TRUE);
76                         elm_entry_input_panel_return_key_disabled_set(obj,
77                                         EINA_TRUE);
78                 }
79         }
80
81         if (elm_object_part_content_get(obj, "elm.swallow.clear")) {
82                 if (elm_object_focus_get(obj)) {
83                         if (elm_entry_is_empty(obj)) {
84                                 elm_object_signal_emit(obj,
85                                                 "elm,state,clear,hidden", "");
86                         } else {
87                                 elm_object_signal_emit(obj,
88                                                 "elm,state,clear,visible", "");
89                         }
90                 }
91         }
92
93         if (entry_str)
94                 g_free(entry_str);
95 }
96
97 static void __popup_entry_maxlength_reached(void *data, Evas_Object *obj,
98                 void *event_info)
99 {
100         common_utils_send_message_to_net_popup("Password length",
101                         "Lengthy Password", "notification", NULL);
102 }
103
104 static void __common_pbc_popup_destroy(pbc_popup_t *pbc_popup_data)
105 {
106         __COMMON_FUNC_ENTER__;
107         if (!pbc_popup_data)
108                 return;
109
110         if (pbc_popup_data->checker == 0) {
111                 pbc_popup_data->checker = 1;
112
113                 if (pbc_popup_data->timer != NULL) {
114                         ecore_timer_del(pbc_popup_data->timer);
115                         pbc_popup_data->timer = NULL;
116                 }
117
118                 if (pbc_popup_data->pin != NULL) {
119                         g_free(pbc_popup_data->pin);
120                         pbc_popup_data->pin = NULL;
121                 }
122
123                 if (pbc_popup_data->popup != NULL) {
124                         evas_object_hide(pbc_popup_data->popup);
125                         evas_object_del(pbc_popup_data->popup);
126                         pbc_popup_data->popup = NULL;
127                 }
128                 g_free(pbc_popup_data);
129         }
130         __COMMON_FUNC_EXIT__;
131         return;
132 }
133
134 static Eina_Bool _fn_pb_timer_bar(void *data)
135 {
136         double val = 120.0;
137         time_t current_time;
138         int time_diff;
139         time(&current_time);
140
141         pswd_popup_t *pswd_popup_data = (pswd_popup_t *)data;
142         pbc_popup_t *pbc_popup_data = pswd_popup_data->pbc_popup_data;
143         if (!pbc_popup_data || pbc_popup_data->timer == NULL ||
144                         pbc_popup_data->progressbar == NULL) {
145                 return ECORE_CALLBACK_CANCEL;
146         }
147         time_diff = difftime(current_time, pswd_popup_data->start_time);
148         pbc_popup_data->value = (double)(time_diff/(double)MAX_PBC_TIMEOUT_SECS);
149         if (pbc_popup_data->value >= 1) {
150                 if (pbc_popup_data->checker == 0) {
151                         __COMMON_FUNC_ENTER__;
152
153                         Evas_Object *cancel_btn = elm_object_part_content_get(
154                                         pbc_popup_data->popup, "button1");
155                         evas_object_smart_callback_call(cancel_btn, "clicked", NULL);
156
157                         __COMMON_FUNC_EXIT__;
158                 }
159                 return ECORE_CALLBACK_CANCEL;
160         }
161         val = val - time_diff;
162         int remain_mins = (int)(val);
163         int remain_secs = 0;
164         remain_secs = remain_mins % 60;
165         remain_mins /= 60;
166
167         char *remaining_time_str = g_strdup_printf(
168                         "<font_size=40><align=center>%02d:%02d</align></font_size>",
169                         remain_mins, remain_secs);
170         elm_object_text_set(pbc_popup_data->timer_label, remaining_time_str);
171         /* INFO_LOG(UG_NAME_NORMAL, "pbc_popup_data->value = %lf;"
172                         "remain_mins = %d; remain_secs = %d; remaining_time_str = %s",
173                         pbc_popup_data->value, remain_mins, remain_secs, remaining_time_str); */
174         g_free(remaining_time_str);
175
176         elm_progressbar_value_set(pbc_popup_data->progressbar, pbc_popup_data->value);
177
178         return ECORE_CALLBACK_RENEW;
179 }
180
181 static Eina_Bool _enable_scan_updates_cb(void *data)
182 {
183         /* Lets enable the scan updates */
184         wlan_manager_enable_scan_result_update();
185
186         /* Reset the ecore timer handle */
187         common_util_manager_ecore_scan_update_timer_reset();
188
189         return ECORE_CALLBACK_CANCEL;
190 }
191
192 static void __pbc_popup_language_changed_cb(void *data, Evas_Object *obj, void *event_info)
193 {
194         __COMMON_FUNC_ENTER__;
195
196         pbc_popup_t *pbc_data = (pbc_popup_t *)data;
197         Evas_Object *layout = NULL;
198         char str[1024];
199
200         retm_if(pbc_data == NULL || pbc_data->popup == NULL);
201         layout = elm_object_content_get(pbc_data->popup);
202
203         if (pbc_data->wps_type == POPUP_WPS_BTN) {
204                 g_snprintf(str, 1024, sc(PACKAGE,
205                                 I18N_TYPE_Press_WPS_On_Your_Wi_Fi_Access_Point), 2);
206                 elm_object_domain_translatable_part_text_set(layout,
207                                 "elm.text.description", PACKAGE, str);
208         } else if (pbc_data->wps_type == POPUP_WPS_PIN) {
209                 g_snprintf(str, 1024, sc(PACKAGE,
210                                 I18N_TYPE_Enter_PIN_number_on_your_WIFI_access_point),
211                                 pbc_data->pin, 2);
212                 elm_object_domain_translatable_part_text_set(layout,
213                                 "elm.text.description", PACKAGE, str);
214         }
215         __COMMON_FUNC_EXIT__;
216 }
217
218 void create_pbc_popup(pswd_popup_t *pswd_popup_data, Evas_Smart_Cb cancel_cb,
219                 void *cancel_cb_data, popup_type_t type, char *pin)
220 {
221         if (!pswd_popup_data)
222                 return;
223
224         Evas_Object *popup = NULL;
225         Evas_Object *progressbar = NULL;
226         Evas_Object *timer_label = NULL;
227         Evas_Object *layout;
228         char buf[512] = "";
229
230         pbc_popup_t *pbc_popup_data = NULL;
231         pbc_popup_data = g_new0(pbc_popup_t, 1);
232
233         popup_btn_info_t popup_btn_data;
234         memset(&popup_btn_data, 0, sizeof(popup_btn_data));
235         popup_btn_data.btn1_txt = "IDS_WIFI_SK_CANCEL";
236         popup_btn_data.btn1_cb = cancel_cb;
237         popup_btn_data.btn1_data = cancel_cb_data;
238         popup = common_utils_show_info_popup(pswd_popup_data->win, &popup_btn_data);
239
240         if (type == POPUP_WPS_BTN) {
241                 elm_object_domain_translatable_part_text_set(popup, "title,text",
242                                 PACKAGE, "IDS_WIFI_BUTTON_WPS_BUTTON");
243         } else if (type == POPUP_WPS_PIN) {
244                 elm_object_domain_translatable_part_text_set(popup, "title,text",
245                                 PACKAGE, "IDS_WIFI_SK_WPS_PIN");
246         }
247
248         layout = elm_layout_add(popup);
249         if (layout == NULL) {
250                 g_free(pbc_popup_data);
251                 return;
252         }
253
254         if (type == POPUP_WPS_BTN) {
255                 elm_layout_file_set(layout, CUSTOM_EDITFIELD_PATH,
256                                 EDJ_GRP_POPUP_PBC_BUTTON_LAYOUT);
257                 g_snprintf(buf, sizeof(buf), sc(pswd_popup_data->str_pkg_name,
258                                 I18N_TYPE_Press_WPS_On_Your_Wi_Fi_Access_Point), 2);
259                 elm_object_domain_translatable_part_text_set(layout,
260                                 "elm.text.description", PACKAGE, buf);
261         } else if (type == POPUP_WPS_PIN) {
262                 elm_layout_file_set(layout, CUSTOM_EDITFIELD_PATH,
263                                 EDJ_GRP_POPUP_WPS_PIN_LAYOUT);
264                 g_snprintf(buf, sizeof(buf),
265                                 sc(pswd_popup_data->str_pkg_name,
266                                         I18N_TYPE_Enter_PIN_number_on_your_WIFI_access_point),
267                                         pin, 2);
268                 elm_object_domain_translatable_part_text_set(layout,
269                                 "elm.text.description", PACKAGE, buf);
270         }
271         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
272
273         progressbar = elm_progressbar_add(layout);
274         elm_progressbar_horizontal_set(progressbar, EINA_TRUE);
275         evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL, EVAS_HINT_FILL);
276         evas_object_size_hint_weight_set(progressbar, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
277         elm_progressbar_value_set(progressbar, 0.0);
278
279         timer_label = elm_label_add(layout);
280         elm_label_line_wrap_set(timer_label, ELM_WRAP_MIXED);
281         elm_object_text_set(timer_label, _("<font_size=40><align=center>02:00</align></font_size>"));
282         evas_object_size_hint_weight_set(timer_label, EVAS_HINT_EXPAND, 0.0);
283         evas_object_size_hint_align_set(timer_label, EVAS_HINT_FILL, EVAS_HINT_FILL);
284         evas_object_show(timer_label);
285
286         elm_object_part_content_set(layout, "slider", progressbar);
287         elm_object_part_content_set(layout, "timer_label", timer_label);
288
289         pbc_popup_data->checker = 0;
290         pbc_popup_data->value = 0.0;
291         pbc_popup_data->progressbar = progressbar;
292         pbc_popup_data->timer_label = timer_label;
293         pbc_popup_data->popup = popup;
294         pbc_popup_data->wps_type = type;
295         pbc_popup_data->pin = g_strdup(pin);
296         time(&(pswd_popup_data->start_time));
297         pbc_popup_data->timer = ecore_timer_add(1.0, _fn_pb_timer_bar, pswd_popup_data);
298         evas_object_show(progressbar);
299         evas_object_smart_callback_add(popup, "language,changed",
300                         __pbc_popup_language_changed_cb, pbc_popup_data);
301         evas_object_show(popup);
302         elm_object_content_set(popup, layout);
303         pswd_popup_data->pbc_popup_data = pbc_popup_data;
304
305         evas_object_hide(pswd_popup_data->popup);
306
307         return;
308 }
309
310 static char *_gl_wps_text_get(void *data, Evas_Object *obj, const char *part)
311 {
312         if (!strcmp("elm.text", part)) {
313                 char buf[1024];
314                 snprintf(buf, 1023, "%s", sc(PACKAGE, (int)data));
315                 return g_strdup(dgettext(PACKAGE, buf));
316         }
317         return NULL;
318 }
319
320 static void _gl_realized(void *data, Evas_Object *obj, void *event_info)
321 {
322         if (!event_info)
323                 return;
324
325         int index = (int)elm_object_item_data_get(event_info);
326
327         if (index == I18N_TYPE_WPS_PIN)
328                 elm_object_item_signal_emit(event_info, "elm,state,bottomline,hide", "");
329 }
330
331 void create_wps_options_popup(Evas_Object *win_main,
332                 pswd_popup_t *pswd_popup_data,
333                 pswd_popup_create_req_data_t *popup_info)
334 {
335         if (!win_main || !popup_info || !pswd_popup_data)
336                 return;
337
338         Evas_Object *popup = NULL;
339         Evas_Object *genlist = NULL;
340         static Elm_Genlist_Item_Class wps_itc;
341         char *txt = NULL;
342         popup = elm_popup_add(win_main);
343         if (!popup)
344                 return;
345
346         ecore_imf_input_panel_hide();
347
348         txt = evas_textblock_text_utf8_to_markup(NULL, popup_info->title);
349         elm_object_domain_translatable_part_text_set(popup,
350                         "title,text", PACKAGE, txt);
351         g_free(txt);
352         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
353
354         genlist = elm_genlist_add(popup);
355         evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND,
356                         EVAS_HINT_EXPAND);
357         evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
358         elm_scroller_content_min_limit(genlist, EINA_FALSE, EINA_TRUE);
359         evas_object_smart_callback_add(genlist, "realized", _gl_realized, NULL);
360
361         wps_itc.item_style = WIFI_GENLIST_1LINE_TEXT_STYLE;
362         wps_itc.func.text_get = _gl_wps_text_get;
363         wps_itc.func.content_get = NULL;
364         wps_itc.func.state_get = NULL;
365         wps_itc.func.del = NULL;
366
367         elm_genlist_item_append(genlist, &wps_itc,
368                         (void*)I18N_TYPE_WPS_Button, NULL,
369                         ELM_GENLIST_ITEM_NONE, popup_info->wps_btn_cb,
370                         popup_info->cb_data);
371         elm_genlist_item_append(genlist, &wps_itc,
372                         (void*)I18N_TYPE_WPS_PIN, NULL,
373                         ELM_GENLIST_ITEM_NONE, popup_info->wps_pin_cb,
374                         popup_info->cb_data);
375
376         evas_object_show(genlist);
377
378         eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK,
379                         popup_info->cancel_cb, popup_info->cb_data);
380         elm_object_content_set(popup, genlist);
381         evas_object_show(popup);
382         elm_object_focus_set(popup, EINA_TRUE);
383
384         pswd_popup_data->wps_options_popup = popup;
385
386         evas_object_hide(pswd_popup_data->popup);
387 }
388
389 static char *_passwd_popup_wps_item_text_get(void *data, Evas_Object *obj,
390                 const char *part)
391 {
392         if (!strcmp("elm.text", part)) {
393                 char buf[1024];
394                 snprintf(buf, 1023, "%s", sc(PACKAGE, I18N_TYPE_WPS));
395                 return strdup(buf);
396         }
397         return NULL;
398 }
399
400 static Evas_Object *_passwd_popup_wps_item_content_get(void *data,
401                 Evas_Object *obj, const char *part)
402 {
403         Evas_Object *icon = NULL;
404
405         if (!strcmp("elm.swallow.icon", part)) {
406                 /* image */
407                 icon = elm_image_add(obj);
408                 retvm_if(NULL == icon, NULL);
409
410                 elm_image_file_set(icon, CUSTOM_EDITFIELD_PATH, "wifi_icon_wps.png");
411                 evas_object_color_set(icon, 2, 61, 132, 153);
412
413                 evas_object_size_hint_min_set(icon, DEFAULT_BUTTON_CIRCLE_SIZE, DEFAULT_BUTTON_CIRCLE_SIZE);
414         }
415         return icon;
416 }
417
418 static void _entry_edit_mode_show_cb(void *data, Evas *e, Evas_Object *obj,
419                 void *event_info)
420 {
421         evas_object_event_callback_del(obj, EVAS_CALLBACK_SHOW,
422                         _entry_edit_mode_show_cb);
423
424         elm_object_focus_set(obj, EINA_TRUE);
425 }
426
427 static void __popup_entry_activated_cb(void *data, Evas_Object *obj, void *event_info)
428 {
429         if (!obj)
430                 return;
431
432         elm_object_focus_set(obj, EINA_FALSE);
433 }
434
435 static Evas_Object* _gl_pswd_entry_item_content_get(void *data,
436                 Evas_Object *obj, const char *part)
437 {
438         if (obj == NULL || data == NULL)
439                 return NULL;
440
441         int return_key_type;
442         Evas_Object *entry = NULL;
443         Evas_Object *editfield = NULL;
444
445         static Elm_Entry_Filter_Limit_Size limit_filter_data;
446         pswd_popup_t *pswd_popup_data = (pswd_popup_t *)data;
447
448         if (!g_strcmp0(part, "elm.swallow.content")) {
449                 editfield = elm_layout_add(obj);
450                 elm_layout_theme_set(editfield, "layout", "editfield", "singleline");
451                 evas_object_size_hint_align_set(editfield, EVAS_HINT_FILL, 0.0);
452                 evas_object_size_hint_weight_set(editfield, EVAS_HINT_EXPAND, 0.0);
453                 entry = elm_entry_add(editfield);
454                 elm_entry_single_line_set(entry, EINA_TRUE);
455                 elm_entry_scrollable_set(entry, EINA_TRUE);
456                 elm_entry_password_set(entry, EINA_TRUE);
457                 eext_entry_selection_back_event_allow_set(entry, EINA_TRUE);
458                 evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, 0.0);
459                 evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, 0.0);
460                 if (!g_strcmp0(pswd_popup_data->str_pkg_name, "wifi-qs")) {
461                         elm_entry_input_panel_imdata_set(entry,
462                                         "type=systempopup", 16);
463                 }
464                 elm_entry_cnp_mode_set(entry, ELM_CNP_MODE_PLAINTEXT);
465                 elm_entry_input_panel_layout_set(entry,
466                                 ELM_INPUT_PANEL_LAYOUT_PASSWORD);
467                 elm_object_domain_translatable_part_text_set(entry, "elm.guide",
468                         PACKAGE, "IDS_WIFI_HEADER_PASSWORD");
469                 elm_object_signal_emit(entry, "elm,action,hide,search_icon", "");
470
471                 limit_filter_data.max_char_count = PASSWORD_LENGTH;
472                 elm_entry_markup_filter_append(entry,
473                 elm_entry_filter_limit_size, &limit_filter_data);
474
475                 return_key_type = ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DONE;
476                 elm_entry_input_panel_return_key_type_set(entry, return_key_type);
477                 elm_entry_input_panel_return_key_disabled_set(entry, EINA_TRUE);
478                 evas_object_smart_callback_add(entry, "activated",
479                                 __popup_entry_activated_cb, data);
480                 evas_object_smart_callback_add(entry, "changed",
481                                 __popup_entry_changed_cb, data);
482                 evas_object_smart_callback_add(entry, "preedit,changed",
483                                 __popup_entry_changed_cb, data);
484                 evas_object_smart_callback_add(entry, "maxlength,reached",
485                                 __popup_entry_maxlength_reached, NULL);
486                 evas_object_event_callback_add(entry, EVAS_CALLBACK_SHOW,
487                                 _entry_edit_mode_show_cb, NULL);
488                 elm_object_part_content_set(editfield, "elm.swallow.content", entry);
489
490                 pswd_popup_data->entry = entry;
491
492                 elm_entry_input_panel_show(entry);
493                 return editfield;
494         }
495
496         return NULL;
497 }
498
499 static void _chk_changed_cb(void *data, Evas_Object *obj, void *ei)
500 {
501         if (obj == NULL)
502                 return;
503
504         Eina_Bool state = elm_check_state_get(obj);
505         pswd_popup_t *pswd_popup_data = (pswd_popup_t *)data;
506
507         if (state)
508                 elm_entry_password_set(pswd_popup_data->entry, EINA_FALSE);
509         else
510                 elm_entry_password_set(pswd_popup_data->entry, EINA_TRUE);
511
512         elm_entry_cursor_end_set((Evas_Object *)data);
513 }
514 static char *_gl_pswd_check_box_item_text_get(void *data, Evas_Object *obj,
515                 const char *part)
516 {
517         if (!strcmp("elm.text", part)) {
518                 char buf[1024];
519                 snprintf(buf, 1023, "%s", sc(PACKAGE, I18N_TYPE_Show_password));
520                 return strdup(buf);
521         }
522         return NULL;
523
524 }
525
526 static Evas_Object *_gl_pswd_check_box_item_content_get(void *data,
527                 Evas_Object *obj, const char *part)
528 {
529         Evas_Object *check = NULL;
530         pswd_popup_t *pswd_popup_data = (pswd_popup_t *)data;
531
532         if (!strcmp("elm.swallow.icon", part)) {
533                 check = elm_check_add(obj);
534                 if (common_util_get_ug_type() == UG_VIEW_OOBE)
535                         elm_object_style_set(check, "oobe-casual");
536
537                 evas_object_propagate_events_set(check, EINA_FALSE);
538
539                 evas_object_size_hint_align_set(check, EVAS_HINT_FILL, EVAS_HINT_FILL);
540                 evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
541                 evas_object_smart_callback_add(check, "changed",
542                                 _chk_changed_cb, pswd_popup_data);
543
544                 elm_object_focus_allow_set(check, EINA_FALSE);
545
546                 return check;
547         }
548         return NULL;
549 }
550
551 static void _gl_pswd_check_box_sel(void *data, Evas_Object *obj, void *ei)
552 {
553         __COMMON_FUNC_ENTER__;
554         Elm_Object_Item *item = NULL;
555
556         item = (Elm_Object_Item *)ei;
557         if (item == NULL)
558                 return;
559
560         pswd_popup_t *pswd_popup_data = (pswd_popup_t *)data;
561
562         Evas_Object *ck = elm_object_item_part_content_get(ei, "elm.icon.right");
563
564         elm_genlist_item_selected_set(item, EINA_FALSE);
565
566         Eina_Bool state = elm_check_state_get(ck);
567         elm_check_state_set(ck, !state);
568         if (pswd_popup_data)
569                 _chk_changed_cb(pswd_popup_data->entry, ck, NULL);
570 }
571
572 static void _passwd_popup_keypad_off_cb(void *data, Evas_Object *obj,
573                 void *event_info)
574 {
575         if (data == NULL)
576                 return;
577
578         pswd_popup_t *pop_info = (pswd_popup_t *)data;
579
580         keypad_state = FALSE;
581
582         if (wps_options_click == TRUE) {
583                 wps_options_click = FALSE;
584
585                 if (pop_info->wps_btn_cb != NULL)
586                         pop_info->wps_btn_cb(NULL, NULL, NULL);
587         }
588         INFO_LOG(UG_NAME_NORMAL, "Keypad is down");
589 }
590
591 static void _passwd_popup_keypad_on_cb(void *data, Evas_Object *obj,
592                 void *event_info)
593 {
594         if (data == NULL)
595                 return;
596
597         keypad_state = TRUE;
598         INFO_LOG(UG_NAME_NORMAL, "Keypad is up");
599 }
600
601 static void popup_animation_finish_cb(void *data, Evas_Object *obj, void *event_info)
602 {
603         __COMMON_FUNC_ENTER__;
604         Elm_Object_Item *item = (Elm_Object_Item *) data;
605         Evas_Object *entry = NULL;
606
607         entry = elm_object_item_part_content_get(item, "elm.icon.entry");
608         elm_entry_input_panel_show(entry);
609         elm_entry_input_panel_show_on_demand_set(entry, EINA_FALSE);
610         elm_object_focus_set(entry, EINA_TRUE);
611
612         __COMMON_FUNC_EXIT__;
613 }
614
615 static void _common_wps_options_popup_cb(void* data, Evas_Object* obj,
616                 void* event_info)
617 {
618         __COMMON_FUNC_ENTER__;
619
620         if (!event_info || !data)
621                 return;
622
623         pswd_popup_t *pop_info = (pswd_popup_t *) data;
624         Elm_Object_Item *item = event_info;
625         elm_genlist_item_selected_set(item, EINA_FALSE);
626
627         if (keypad_state == FALSE) {
628                 if (pop_info->wps_btn_cb != NULL)
629                         pop_info->wps_btn_cb(NULL, NULL, NULL);
630         } else {
631                 wps_options_click = TRUE;
632                 ecore_imf_input_panel_hide();
633         }
634
635         __COMMON_FUNC_EXIT__;
636 }
637
638 pswd_popup_t *create_passwd_popup(Evas_Object *conformant, Evas_Object *win_main,
639                 const char *pkg_name, pswd_popup_create_req_data_t *popup_info)
640 {
641         Evas_Object *passpopup = NULL;
642         Evas_Object *genlist = NULL;
643         Evas_Object *btn_ok = NULL;
644
645         __COMMON_FUNC_ENTER__;
646
647         if (!win_main || !popup_info || !pkg_name)
648                 return NULL;
649
650         pswd_popup_t *pswd_popup_data = g_new0(pswd_popup_t, 1);
651
652         if (popup_info->ap) {
653                 if (WIFI_MANAGER_ERROR_NONE !=
654                                 wifi_manager_ap_clone(&(pswd_popup_data->ap), popup_info->ap)) {
655                         g_free(pswd_popup_data);
656
657                         return NULL;
658                 }
659         } else {
660                 /* Hidden Wi-Fi network does not have handle */
661         }
662
663         wps_options_click = FALSE;
664         /* Lets disable the scan updates so that the UI is not refreshed un necessarily */
665         wlan_manager_disable_scan_result_update();
666
667         popup_btn_info_t popup_btn_data;
668         memset(&popup_btn_data, 0, sizeof(popup_btn_data));
669
670         popup_btn_data.title_txt = popup_info->title;
671         popup_btn_data.sub_title_txt = popup_info->sub_title;
672         popup_btn_data.btn1_cb = popup_info->cancel_cb;
673         popup_btn_data.btn1_data = popup_info->cb_data;
674         popup_btn_data.btn1_txt = "IDS_WIFI_SK_CANCEL";
675         popup_btn_data.btn2_cb = popup_info->ok_cb;
676         popup_btn_data.btn2_data = popup_info->cb_data;
677         popup_btn_data.btn2_txt = "IDS_WIFI_BODY_CONNECT";
678
679         passpopup = common_utils_show_info_popup(win_main, &popup_btn_data);
680
681         if (!passpopup) {
682                 ERROR_LOG(UG_NAME_ERR, "Could not initialize popup");
683                 g_free(pswd_popup_data);
684                 return NULL;
685         }
686
687         pswd_popup_data->win = win_main;
688         pswd_popup_data->conf = conformant;
689         pswd_popup_data->str_pkg_name = pkg_name;
690         pswd_popup_data->popup = passpopup;
691         pswd_popup_data->sec_type = popup_info->sec_type;
692         pswd_popup_data->curr_ap_name = g_strdup(popup_info->title);
693         pswd_popup_data->show_wps_btn = popup_info->show_wps_btn;
694         pswd_popup_data->wps_btn_cb = popup_info->wps_btn_cb;
695
696         /* Hide the Okay button until the password is entered */
697         btn_ok = elm_object_part_content_get(passpopup, "button2");
698         elm_object_disabled_set(btn_ok, TRUE);
699 #ifdef ACCESSIBLITY_FEATURE
700         Evas_Object *eo = NULL;
701         Evas_Object *ao = NULL;
702         eo = elm_layout_edje_get(passpopup);
703         const Evas_Object *po = edje_object_part_object_get(eo, "elm.text.title");
704         ao = elm_access_object_get(po);
705         elm_access_info_set(ao, ELM_ACCESS_INFO, popup_info->title);
706 #endif
707
708         genlist = elm_genlist_add(passpopup);
709         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
710         elm_scroller_content_min_limit(genlist, EINA_FALSE, EINA_TRUE);
711         evas_object_size_hint_weight_set(genlist,
712                         EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
713         evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
714
715         /* Entry genlist item */
716         g_pswd_entry_itc.item_style = WIFI_GENLIST_SWALLOW_CONTENT_STYLE;
717         g_pswd_entry_itc.func.text_get = NULL;
718         g_pswd_entry_itc.func.content_get = _gl_pswd_entry_item_content_get;
719         g_check_box_itc.func.state_get = NULL;
720         g_check_box_itc.func.del = NULL;
721
722         Elm_Object_Item * entry_item = elm_genlist_item_append(genlist,
723                         &g_pswd_entry_itc, pswd_popup_data,
724                         NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
725
726         /* Checkbox genlist item */
727         g_check_box_itc.item_style = WIFI_GENLIST_1LINE_TEXT_ICON_STYLE;
728         g_check_box_itc.func.text_get = _gl_pswd_check_box_item_text_get;
729         g_check_box_itc.func.content_get = _gl_pswd_check_box_item_content_get;
730         g_check_box_itc.func.state_get = NULL;
731         g_check_box_itc.func.del = NULL;
732
733         elm_genlist_item_append(genlist, &g_check_box_itc, pswd_popup_data,
734                         NULL, ELM_GENLIST_ITEM_NONE,
735                         _gl_pswd_check_box_sel, pswd_popup_data);
736
737         if (popup_info->show_wps_btn) {
738                 /* WPS options genlist item */
739                 g_wps_itc.item_style = WIFI_GENLIST_1LINE_TEXT_ICON_STYLE;
740                 g_wps_itc.func.text_get = _passwd_popup_wps_item_text_get;
741                 g_wps_itc.func.content_get = _passwd_popup_wps_item_content_get;
742                 g_wps_itc.func.state_get = NULL;
743                 g_wps_itc.func.del = NULL;
744
745                 pswd_popup_data->wps_options_item = elm_genlist_item_append(genlist,
746                                 &g_wps_itc, NULL, NULL, ELM_GENLIST_ITEM_NONE,
747                                 _common_wps_options_popup_cb, pswd_popup_data);
748         }
749
750         //elm_genlist_realization_mode_set(genlist, EINA_TRUE);
751         evas_object_show(genlist);
752
753         elm_object_content_set(passpopup, genlist);
754
755         evas_object_smart_callback_add(passpopup, "show,finished",
756                         popup_animation_finish_cb, entry_item);
757         evas_object_show(passpopup);
758
759         evas_object_smart_callback_add(pswd_popup_data->conf,
760                         "virtualkeypad,state,on", _passwd_popup_keypad_on_cb,
761                         pswd_popup_data);
762         evas_object_smart_callback_add(pswd_popup_data->conf,
763                         "virtualkeypad,state,off", _passwd_popup_keypad_off_cb,
764                         pswd_popup_data);
765
766         __COMMON_FUNC_EXIT__;
767         return pswd_popup_data;
768 }
769
770 char *passwd_popup_get_txt(pswd_popup_t *pswd_popup_data)
771 {
772         if (pswd_popup_data) {
773                 Evas_Object *entry = pswd_popup_data->entry;
774                 return elm_entry_markup_to_utf8(elm_entry_entry_get(entry));
775         }
776
777         return NULL;
778 }
779
780 wifi_manager_ap_h passwd_popup_get_ap(pswd_popup_t *pswd_popup_data)
781 {
782         if (pswd_popup_data)
783                 return pswd_popup_data->ap;
784
785         return NULL;
786 }
787
788 void current_popup_free(pswd_popup_t *pswd_popup_data, popup_type_t type)
789 {
790         if (pswd_popup_data == NULL)
791                 return;
792
793         int rotation = -1;
794         char buf[1024];
795         Evas_Object *curr_popup = NULL;
796
797         if (type == POPUP_WPS_OPTIONS) {
798                 if (pswd_popup_data->wps_options_popup) {
799                         evas_object_hide(pswd_popup_data->wps_options_popup);
800                         evas_object_del(pswd_popup_data->wps_options_popup);
801                         pswd_popup_data->wps_options_popup = NULL;
802                 }
803                 evas_object_show(pswd_popup_data->popup);
804                 curr_popup = pswd_popup_data->popup;
805         }
806
807         rotation = common_utils_get_rotate_angle(APPCORE_RM_UNKNOWN);
808         if (rotation != -1) {
809                 g_snprintf(buf, sizeof(buf), "elm,state,orient,%d", rotation);
810                 SECURE_INFO_LOG(UG_NAME_NORMAL, "Rotation signal - %s", buf);
811                 elm_layout_signal_emit(curr_popup, buf, "elm");
812         }
813 }
814
815 void passwd_popup_hide(pswd_popup_t *pswd_popup_data)
816 {
817         if (pswd_popup_data == NULL)
818                 return;
819
820         if (pswd_popup_data->popup != NULL)
821                 evas_object_hide(pswd_popup_data->popup);
822 }
823
824 void passwd_popup_show(pswd_popup_t *pswd_popup_data)
825 {
826         if (pswd_popup_data == NULL)
827                 return;
828
829         if (pswd_popup_data->popup != NULL)
830                 evas_object_show(pswd_popup_data->popup);
831 }
832
833 void passwd_popup_free(pswd_popup_t *pswd_popup_data)
834 {
835         __COMMON_FUNC_ENTER__;
836
837         if (pswd_popup_data == NULL)
838                 return;
839
840         if (pswd_popup_data->conf) {
841                 if (keypad_state == TRUE)
842                         keypad_state = FALSE;
843                 evas_object_smart_callback_del(pswd_popup_data->conf,
844                                 "virtualkeypad,state,on",
845                                 _passwd_popup_keypad_on_cb);
846                 evas_object_smart_callback_del(pswd_popup_data->conf,
847                                 "virtualkeypad,state,off",
848                                 _passwd_popup_keypad_off_cb);
849         }
850
851         if (pswd_popup_data->curr_ap_name != NULL) {
852                 g_free(pswd_popup_data->curr_ap_name);
853                 pswd_popup_data->curr_ap_name = NULL;
854         }
855
856         if (pswd_popup_data->info_popup != NULL) {
857                 evas_object_del(pswd_popup_data->info_popup);
858                 pswd_popup_data->info_popup = NULL;
859                 INFO_LOG(UG_NAME_NORMAL, "info popup deleted");
860         }
861
862         if (pswd_popup_data->pbc_popup_data) {
863                 __common_pbc_popup_destroy(pswd_popup_data->pbc_popup_data);
864                 pswd_popup_data->pbc_popup_data = NULL;
865                 INFO_LOG(UG_NAME_NORMAL, "wps pbc popup deleted");
866         }
867
868         if (pswd_popup_data->popup != NULL) {
869                 evas_object_del(pswd_popup_data->popup);
870                 pswd_popup_data->popup = NULL;
871                 INFO_LOG(UG_NAME_NORMAL, "password popup deleted");
872         }
873
874         if (pswd_popup_data->wps_options_popup != NULL) {
875                 evas_object_del(pswd_popup_data->wps_options_popup);
876                 pswd_popup_data->wps_options_popup = NULL;
877                 INFO_LOG(UG_NAME_NORMAL, "wps option popup deleted");
878         }
879
880         /* Hidden Wi-Fi network does not have handle */
881         if (pswd_popup_data->ap)
882                 wifi_manager_ap_destroy(pswd_popup_data->ap);
883
884         g_free(pswd_popup_data);
885
886         /* A delay is needed to get the smooth Input panel closing animation effect */
887         common_util_managed_ecore_scan_update_timer_add(0.1,
888                         _enable_scan_updates_cb, NULL);
889
890         __COMMON_FUNC_EXIT__;
891 }