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