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