Fixed memory leak
[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                 g_free(pbc_popup_data);
252                 return;
253         }
254
255         if (type == POPUP_WPS_BTN) {
256                 elm_layout_file_set(layout, CUSTOM_EDITFIELD_PATH,
257                                 EDJ_GRP_POPUP_PBC_BUTTON_LAYOUT);
258                 g_snprintf(buf, sizeof(buf), sc(pswd_popup_data->str_pkg_name,
259                                 I18N_TYPE_Press_WPS_On_Your_Wi_Fi_Access_Point), 2);
260                 elm_object_domain_translatable_part_text_set(layout,
261                                 "elm.text.description", PACKAGE, buf);
262         } else if (type == POPUP_WPS_PIN) {
263                 elm_layout_file_set(layout, CUSTOM_EDITFIELD_PATH,
264                                 EDJ_GRP_POPUP_WPS_PIN_LAYOUT);
265                 g_snprintf(buf, sizeof(buf),
266                                 sc(pswd_popup_data->str_pkg_name,
267                                         I18N_TYPE_Enter_PIN_number_on_your_WIFI_access_point),
268                                         pin, 2);
269                 elm_object_domain_translatable_part_text_set(layout,
270                                 "elm.text.description", PACKAGE, buf);
271         }
272         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
273
274         progressbar = elm_progressbar_add(layout);
275         elm_progressbar_horizontal_set(progressbar, EINA_TRUE);
276         evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL, EVAS_HINT_FILL);
277         evas_object_size_hint_weight_set(progressbar, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
278         elm_progressbar_value_set(progressbar, 0.0);
279
280         timer_label = elm_label_add(layout);
281         elm_label_line_wrap_set(timer_label, ELM_WRAP_MIXED);
282         elm_object_text_set(timer_label, _("<font_size=40><align=center>02:00</align></font_size>"));
283         evas_object_size_hint_weight_set(timer_label, EVAS_HINT_EXPAND, 0.0);
284         evas_object_size_hint_align_set(timer_label, EVAS_HINT_FILL, EVAS_HINT_FILL);
285         evas_object_show(timer_label);
286
287         elm_object_part_content_set(layout, "slider", progressbar);
288         elm_object_part_content_set(layout, "timer_label", timer_label);
289
290         pbc_popup_data->checker = 0;
291         pbc_popup_data->value = 0.0;
292         pbc_popup_data->progressbar = progressbar;
293         pbc_popup_data->timer_label = timer_label;
294         pbc_popup_data->popup = popup;
295         pbc_popup_data->wps_type = type;
296         pbc_popup_data->pin = g_strdup(pin);
297         time(&(pswd_popup_data->start_time));
298         pbc_popup_data->timer = ecore_timer_add(1.0, _fn_pb_timer_bar, pswd_popup_data);
299         evas_object_show(progressbar);
300         evas_object_smart_callback_add(popup, "language,changed",
301                         __pbc_popup_language_changed_cb, pbc_popup_data);
302         evas_object_show(popup);
303         elm_object_content_set(popup, layout);
304         pswd_popup_data->pbc_popup_data = pbc_popup_data;
305
306         evas_object_hide(pswd_popup_data->popup);
307
308         return;
309 }
310
311 static char *_gl_wps_text_get(void *data, Evas_Object *obj, const char *part)
312 {
313         if (!strcmp("elm.text", part)) {
314                 char buf[1024];
315                 snprintf(buf, 1023, "%s", sc(PACKAGE, (int)data));
316                 return g_strdup(dgettext(PACKAGE, buf));
317         }
318         return NULL;
319 }
320
321 static void _gl_realized(void *data, Evas_Object *obj, void *event_info)
322 {
323         if (!event_info)
324                 return;
325
326         int index = (int)elm_object_item_data_get(event_info);
327
328         if (index == I18N_TYPE_WPS_PIN) {
329                 elm_object_item_signal_emit(event_info, "elm,state,bottomline,hide", "");
330         }
331 }
332
333 void create_wps_options_popup(Evas_Object *win_main,
334                 pswd_popup_t *pswd_popup_data,
335                 pswd_popup_create_req_data_t *popup_info)
336 {
337         if (!win_main || !popup_info || !pswd_popup_data) {
338                 return;
339         }
340
341         Evas_Object *popup = NULL;
342         Evas_Object *genlist = NULL;
343         static Elm_Genlist_Item_Class wps_itc;
344         char *txt = NULL;
345         popup = elm_popup_add(win_main);
346         if (!popup)
347                 return;
348
349         ecore_imf_input_panel_hide();
350
351         txt = evas_textblock_text_utf8_to_markup(NULL, popup_info->title);
352         elm_object_domain_translatable_part_text_set(popup,
353                         "title,text", PACKAGE, txt);
354         g_free(txt);
355         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
356
357         genlist = elm_genlist_add(popup);
358         evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND,
359                         EVAS_HINT_EXPAND);
360         evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
361         elm_scroller_content_min_limit(genlist, EINA_FALSE, EINA_TRUE);
362         evas_object_smart_callback_add(genlist, "realized", _gl_realized, NULL);
363
364         wps_itc.item_style = WIFI_GENLIST_1LINE_TEXT_STYLE;
365         wps_itc.func.text_get = _gl_wps_text_get;
366         wps_itc.func.content_get = NULL;
367         wps_itc.func.state_get = NULL;
368         wps_itc.func.del = NULL;
369
370         elm_genlist_item_append(genlist, &wps_itc,
371                         (void*)I18N_TYPE_WPS_Button, NULL,
372                         ELM_GENLIST_ITEM_NONE, popup_info->wps_btn_cb,
373                         popup_info->cb_data);
374         elm_genlist_item_append(genlist, &wps_itc,
375                         (void*)I18N_TYPE_WPS_PIN, NULL,
376                         ELM_GENLIST_ITEM_NONE, popup_info->wps_pin_cb,
377                         popup_info->cb_data);
378
379         evas_object_show(genlist);
380
381         eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK,
382                         popup_info->cancel_cb, popup_info->cb_data);
383         elm_object_content_set(popup, genlist);
384         evas_object_show(popup);
385         elm_object_focus_set(popup, EINA_TRUE);
386
387         pswd_popup_data->wps_options_popup = popup;
388
389         evas_object_hide(pswd_popup_data->popup);
390 }
391
392 static char *_passwd_popup_wps_item_text_get(void *data, Evas_Object *obj,
393                 const char *part)
394 {
395         if (!strcmp("elm.text", part)) {
396                 char buf[1024];
397                 snprintf(buf, 1023, "%s", sc(PACKAGE, I18N_TYPE_WPS));
398                 return strdup(buf);
399         }
400         return NULL;
401 }
402
403 static Evas_Object *_passwd_popup_wps_item_content_get(void *data,
404                 Evas_Object *obj, const char *part)
405 {
406         Evas_Object *icon = NULL;
407
408         if (!strcmp("elm.swallow.icon", part)) {
409                 /* image */
410                 icon = elm_image_add(obj);
411                 retvm_if(NULL == icon, NULL);
412
413                 elm_image_file_set(icon, CUSTOM_EDITFIELD_PATH, "wifi_icon_wps.png");
414                 evas_object_color_set(icon, 2, 61, 132, 153);
415
416                 evas_object_size_hint_min_set(icon, DEFAULT_BUTTON_CIRCLE_SIZE, DEFAULT_BUTTON_CIRCLE_SIZE);
417         }
418         return icon;
419 }
420
421 static void _entry_edit_mode_show_cb(void *data, Evas *e, Evas_Object *obj,
422                 void *event_info)
423 {
424         evas_object_event_callback_del(obj, EVAS_CALLBACK_SHOW,
425                         _entry_edit_mode_show_cb);
426
427         elm_object_focus_set(obj, EINA_TRUE);
428 }
429
430 static void __popup_entry_activated_cb(void *data, Evas_Object *obj, void *event_info)
431 {
432         if (!obj)
433                 return;
434
435         elm_object_focus_set(obj, EINA_FALSE);
436 }
437
438 static Evas_Object* _gl_pswd_entry_item_content_get(void *data,
439                 Evas_Object *obj, const char *part)
440 {
441         if (obj == NULL || data == NULL) {
442                 return NULL;
443         }
444
445         int return_key_type;
446         Evas_Object *entry = NULL;
447         Evas_Object *editfield = NULL;
448
449         static Elm_Entry_Filter_Limit_Size limit_filter_data;
450         pswd_popup_t *pswd_popup_data = (pswd_popup_t *)data;
451
452         if (!g_strcmp0(part, "elm.swallow.content")) {
453                 editfield = elm_layout_add(obj);
454                 elm_layout_theme_set(editfield, "layout", "editfield", "singleline");
455                 evas_object_size_hint_align_set(editfield, EVAS_HINT_FILL, 0.0);
456                 evas_object_size_hint_weight_set(editfield, EVAS_HINT_EXPAND, 0.0);
457                 entry = elm_entry_add(editfield);
458                 elm_entry_single_line_set(entry, EINA_TRUE);
459                 elm_entry_scrollable_set(entry, EINA_TRUE);
460                 elm_entry_password_set(entry, EINA_TRUE);
461                 eext_entry_selection_back_event_allow_set(entry, EINA_TRUE);
462                 evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, 0.0);
463                 evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, 0.0);
464                 if (!g_strcmp0(pswd_popup_data->str_pkg_name, "wifi-qs")) {
465                         elm_entry_input_panel_imdata_set(entry,
466                                         "type=systempopup", 16);
467                 }
468                 elm_entry_cnp_mode_set(entry, ELM_CNP_MODE_PLAINTEXT);
469                 elm_entry_input_panel_layout_set(entry,
470                                 ELM_INPUT_PANEL_LAYOUT_PASSWORD);
471                 elm_object_domain_translatable_part_text_set(entry, "elm.guide",
472                         PACKAGE, "IDS_WIFI_HEADER_PASSWORD");
473                 elm_object_signal_emit(entry, "elm,action,hide,search_icon", "");
474
475                 limit_filter_data.max_char_count = PASSWORD_LENGTH;
476                 elm_entry_markup_filter_append(entry,
477                 elm_entry_filter_limit_size, &limit_filter_data);
478
479                 return_key_type = ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DONE;
480                 elm_entry_input_panel_return_key_type_set(entry, return_key_type);
481                 elm_entry_input_panel_return_key_disabled_set(entry, EINA_TRUE);
482                 evas_object_smart_callback_add(entry, "activated",
483                                 __popup_entry_activated_cb, data);
484                 evas_object_smart_callback_add(entry, "changed",
485                                 __popup_entry_changed_cb, data);
486                 evas_object_smart_callback_add(entry, "preedit,changed",
487                                 __popup_entry_changed_cb, data);
488                 evas_object_smart_callback_add(entry, "maxlength,reached",
489                                 __popup_entry_maxlength_reached, NULL);
490                 evas_object_event_callback_add(entry, EVAS_CALLBACK_SHOW,
491                                 _entry_edit_mode_show_cb, NULL);
492                 elm_object_part_content_set(editfield, "elm.swallow.content", entry);
493
494                 pswd_popup_data->entry = entry;
495
496                 elm_entry_input_panel_show(entry);
497                 return editfield;
498         }
499
500         return NULL;
501 }
502
503 static void _chk_changed_cb(void *data, Evas_Object *obj, void *ei)
504 {
505         if (obj == NULL) {
506                 return;
507         }
508
509         Eina_Bool state = elm_check_state_get(obj);
510         pswd_popup_t *pswd_popup_data = (pswd_popup_t *)data;
511
512         if (state) {
513                 elm_entry_password_set(pswd_popup_data->entry, EINA_FALSE);
514         } else {
515                 elm_entry_password_set(pswd_popup_data->entry, EINA_TRUE);
516         }
517         elm_entry_cursor_end_set((Evas_Object *)data);
518 }
519 static char *_gl_pswd_check_box_item_text_get(void *data, Evas_Object *obj,
520                 const char *part)
521 {
522         if (!strcmp("elm.text", part)) {
523                 char buf[1024];
524                 snprintf(buf, 1023, "%s", sc(PACKAGE, I18N_TYPE_Show_password));
525                 return strdup(buf);
526         }
527         return NULL;
528
529 }
530
531 static Evas_Object *_gl_pswd_check_box_item_content_get(void *data,
532                 Evas_Object *obj, const char *part)
533 {
534         Evas_Object *check = NULL;
535         pswd_popup_t *pswd_popup_data = (pswd_popup_t *)data;
536
537         if (!strcmp("elm.swallow.end", part)) {
538                 check = elm_check_add(obj);
539                 evas_object_propagate_events_set(check, EINA_FALSE);
540
541                 evas_object_size_hint_align_set(check, EVAS_HINT_FILL, EVAS_HINT_FILL);
542                 evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
543                 evas_object_smart_callback_add(check, "changed",
544                                 _chk_changed_cb, pswd_popup_data);
545
546                 elm_object_focus_allow_set(check, EINA_FALSE);
547
548                 return check;
549         }
550         return NULL;
551 }
552
553 static void _gl_pswd_check_box_sel(void *data, Evas_Object *obj, void *ei)
554 {
555         __COMMON_FUNC_ENTER__;
556         Elm_Object_Item *item = NULL;
557
558         item = (Elm_Object_Item *)ei;
559         if (item == NULL) {
560                 return;
561         }
562
563         pswd_popup_t *pswd_popup_data = (pswd_popup_t *)data;
564
565         Evas_Object *ck = elm_object_item_part_content_get(ei, "elm.icon.right");
566
567         elm_genlist_item_selected_set(item, EINA_FALSE);
568
569         Eina_Bool state = elm_check_state_get(ck);
570         elm_check_state_set(ck, !state);
571         if (pswd_popup_data) {
572                 _chk_changed_cb(pswd_popup_data->entry, ck, NULL);
573         }
574 }
575
576 static void _passwd_popup_keypad_off_cb(void *data, Evas_Object *obj,
577                 void *event_info)
578 {
579         if (data == NULL) {
580                 return;
581         }
582
583         pswd_popup_t *pop_info = (pswd_popup_t *)data;
584
585         keypad_state = FALSE;
586
587         if (wps_options_click == TRUE) {
588                 wps_options_click = FALSE;
589
590                 if (pop_info->wps_btn_cb != NULL) {
591                         pop_info->wps_btn_cb(NULL, NULL, NULL);
592                 }
593         }
594         INFO_LOG(UG_NAME_NORMAL,"Keypad is down");
595 }
596
597 static void _passwd_popup_keypad_on_cb(void *data, Evas_Object *obj,
598                 void *event_info)
599 {
600         if (data == NULL) {
601                 return;
602         }
603
604         keypad_state = TRUE;
605         INFO_LOG(UG_NAME_NORMAL,"Keypad is up");
606 }
607
608 static void popup_animation_finish_cb(void *data, Evas_Object *obj, void *event_info)
609 {
610         __COMMON_FUNC_ENTER__;
611         Elm_Object_Item *item = (Elm_Object_Item *) data;
612         Evas_Object *entry = NULL;
613
614         entry = elm_object_item_part_content_get(item, "elm.icon.entry");
615         elm_entry_input_panel_show(entry);
616         elm_entry_input_panel_show_on_demand_set(entry, EINA_FALSE);
617         elm_object_focus_set(entry, EINA_TRUE);
618
619         __COMMON_FUNC_EXIT__;
620 }
621
622 static void _common_wps_options_popup_cb(void* data, Evas_Object* obj,
623                 void* event_info)
624 {
625         __COMMON_FUNC_ENTER__;
626
627         if (!event_info || !data) {
628                 return;
629         }
630
631         pswd_popup_t *pop_info = (pswd_popup_t *) data;
632         Elm_Object_Item *item = event_info;
633         elm_genlist_item_selected_set(item, EINA_FALSE);
634
635         if (keypad_state == FALSE) {
636                 if (pop_info->wps_btn_cb != NULL)
637                         pop_info->wps_btn_cb(NULL, NULL, NULL);
638         } else {
639                 wps_options_click = TRUE;
640                 ecore_imf_input_panel_hide();
641         }
642
643         __COMMON_FUNC_EXIT__;
644 }
645
646 pswd_popup_t *create_passwd_popup(Evas_Object *conformant,Evas_Object *win_main,
647                 const char *pkg_name, pswd_popup_create_req_data_t *popup_info)
648 {
649         Evas_Object *passpopup = NULL;
650         Evas_Object *genlist = NULL;
651         Evas_Object *btn_ok = NULL;
652
653         __COMMON_FUNC_ENTER__;
654
655         if (!win_main || !popup_info || !pkg_name) {
656                 return NULL;
657         }
658
659         pswd_popup_t *pswd_popup_data = g_new0(pswd_popup_t, 1);
660
661         if (popup_info->ap) {
662                 if (WIFI_ERROR_NONE !=
663                                 wifi_ap_clone(&(pswd_popup_data->ap), popup_info->ap)) {
664                         g_free(pswd_popup_data);
665
666                         return NULL;
667                 }
668         } else {
669                 /* Hidden Wi-Fi network does not have handle */
670         }
671
672         wps_options_click = FALSE;
673         /* Lets disable the scan updates so that the UI is not refreshed un necessarily */
674         wlan_manager_disable_scan_result_update();
675
676         popup_btn_info_t popup_btn_data;
677         memset(&popup_btn_data, 0, sizeof(popup_btn_data));
678
679         popup_btn_data.title_txt = popup_info->title;
680         popup_btn_data.btn1_cb = popup_info->cancel_cb;
681         popup_btn_data.btn1_data = popup_info->cb_data;
682         popup_btn_data.btn1_txt = "IDS_WIFI_SK_CANCEL";
683         popup_btn_data.btn2_cb = popup_info->ok_cb;
684         popup_btn_data.btn2_data = popup_info->cb_data;
685         popup_btn_data.btn2_txt = "IDS_WIFI_BODY_CONNECT";
686
687         passpopup = common_utils_show_info_popup(win_main, &popup_btn_data);
688
689         if (!passpopup) {
690                 ERROR_LOG(UG_NAME_ERR, "Could not initialize popup");
691                 g_free(pswd_popup_data);
692                 return NULL;
693         }
694
695         pswd_popup_data->win = win_main;
696         pswd_popup_data->conf = conformant;
697         pswd_popup_data->str_pkg_name = pkg_name;
698         pswd_popup_data->popup = passpopup;
699         pswd_popup_data->sec_type = popup_info->sec_type;
700         pswd_popup_data->curr_ap_name = g_strdup(popup_info->title);
701         pswd_popup_data->show_wps_btn = popup_info->show_wps_btn;
702         pswd_popup_data->wps_btn_cb = popup_info->wps_btn_cb;
703
704         /* Hide the Okay button until the password is entered */
705         btn_ok = elm_object_part_content_get(passpopup, "button2");
706         elm_object_disabled_set(btn_ok, TRUE);
707 #ifdef ACCESSIBLITY_FEATURE
708         Evas_Object *eo = NULL;
709         Evas_Object *ao = NULL;
710         eo = elm_layout_edje_get(passpopup);
711         const Evas_Object *po = edje_object_part_object_get(eo, "elm.text.title");
712         ao = elm_access_object_get(po);
713         elm_access_info_set(ao, ELM_ACCESS_INFO, popup_info->title);
714 #endif
715
716         genlist = elm_genlist_add(passpopup);
717         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
718         elm_scroller_content_min_limit(genlist, EINA_FALSE, EINA_TRUE);
719         evas_object_size_hint_weight_set(genlist,
720                         EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
721         evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
722
723         /* Entry genlist item */
724         g_pswd_entry_itc.item_style = WIFI_GENLIST_SWALLOW_CONTENT_STYLE;
725         g_pswd_entry_itc.func.text_get = NULL;
726         g_pswd_entry_itc.func.content_get = _gl_pswd_entry_item_content_get;
727         g_check_box_itc.func.state_get = NULL;
728         g_check_box_itc.func.del = NULL;
729
730         Elm_Object_Item * entry_item = elm_genlist_item_append(genlist,
731                         &g_pswd_entry_itc, pswd_popup_data,
732                         NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
733
734         /* Checkbox genlist item */
735         g_check_box_itc.item_style = WIFI_GENLIST_1LINE_TEXT_ICON_STYLE;
736         g_check_box_itc.func.text_get = _gl_pswd_check_box_item_text_get;
737         g_check_box_itc.func.content_get = _gl_pswd_check_box_item_content_get;
738         g_check_box_itc.func.state_get = NULL;
739         g_check_box_itc.func.del = NULL;
740
741         elm_genlist_item_append(genlist, &g_check_box_itc, pswd_popup_data,
742                         NULL, ELM_GENLIST_ITEM_NONE,
743                         _gl_pswd_check_box_sel, pswd_popup_data);
744
745         if (popup_info->show_wps_btn) {
746                 /* WPS options genlist item */
747                 g_wps_itc.item_style = WIFI_GENLIST_1LINE_TEXT_ICON_STYLE;
748                 g_wps_itc.func.text_get = _passwd_popup_wps_item_text_get;
749                 g_wps_itc.func.content_get = _passwd_popup_wps_item_content_get;
750                 g_wps_itc.func.state_get = NULL;
751                 g_wps_itc.func.del = NULL;
752
753                 pswd_popup_data->wps_options_item = elm_genlist_item_append(genlist,
754                                 &g_wps_itc, NULL, NULL, ELM_GENLIST_ITEM_NONE,
755                                 _common_wps_options_popup_cb, pswd_popup_data);
756         }
757
758         //elm_genlist_realization_mode_set(genlist, EINA_TRUE);
759         evas_object_show(genlist);
760
761         elm_object_content_set(passpopup, genlist);
762
763         evas_object_smart_callback_add(passpopup, "show,finished",
764                         popup_animation_finish_cb, entry_item);
765         evas_object_show(passpopup);
766
767         evas_object_smart_callback_add(pswd_popup_data->conf,
768                         "virtualkeypad,state,on", _passwd_popup_keypad_on_cb,
769                         pswd_popup_data);
770         evas_object_smart_callback_add(pswd_popup_data->conf,
771                         "virtualkeypad,state,off", _passwd_popup_keypad_off_cb,
772                         pswd_popup_data);
773
774         __COMMON_FUNC_EXIT__;
775         return pswd_popup_data;
776 }
777
778 char *passwd_popup_get_txt(pswd_popup_t *pswd_popup_data)
779 {
780         if (pswd_popup_data) {
781                 Evas_Object *entry = pswd_popup_data->entry;
782                 return elm_entry_markup_to_utf8(elm_entry_entry_get(entry));
783         }
784
785         return NULL;
786 }
787
788 wifi_ap_h passwd_popup_get_ap(pswd_popup_t *pswd_popup_data)
789 {
790         if (pswd_popup_data) {
791                 return pswd_popup_data->ap;
792         }
793
794         return NULL;
795 }
796
797 void current_popup_free(pswd_popup_t *pswd_popup_data, popup_type_t type)
798 {
799         if (pswd_popup_data == NULL) {
800                 return;
801         }
802
803         int rotation = -1;
804         char buf[1024];
805         Evas_Object *curr_popup = NULL;
806
807         if (type == POPUP_WPS_OPTIONS) {
808                 if (pswd_popup_data->wps_options_popup) {
809                         evas_object_hide(pswd_popup_data->wps_options_popup);
810                         evas_object_del(pswd_popup_data->wps_options_popup);
811                         pswd_popup_data->wps_options_popup = NULL;
812                 }
813                 evas_object_show(pswd_popup_data->popup);
814                 curr_popup = pswd_popup_data->popup;
815         }
816
817         rotation = common_utils_get_rotate_angle(APPCORE_RM_UNKNOWN);
818         if (rotation != -1) {
819                 g_snprintf(buf, sizeof(buf), "elm,state,orient,%d", rotation);
820                 SECURE_INFO_LOG(UG_NAME_NORMAL, "Rotation signal - %s", buf);
821                 elm_layout_signal_emit(curr_popup, buf, "elm");
822         }
823 }
824
825 void passwd_popup_hide(pswd_popup_t *pswd_popup_data)
826 {
827         if (pswd_popup_data == NULL) {
828                 return;
829         }
830
831         if (pswd_popup_data->popup != NULL) {
832                 evas_object_hide(pswd_popup_data->popup);
833         }
834 }
835
836 void passwd_popup_show(pswd_popup_t *pswd_popup_data)
837 {
838         if (pswd_popup_data == NULL) {
839                 return;
840         }
841
842         if (pswd_popup_data->popup != NULL) {
843                 evas_object_show(pswd_popup_data->popup);
844         }
845 }
846
847 void passwd_popup_free(pswd_popup_t *pswd_popup_data)
848 {
849         __COMMON_FUNC_ENTER__;
850
851         if (pswd_popup_data == NULL) {
852                 return;
853         }
854
855         if (pswd_popup_data->conf) {
856                 if (keypad_state == TRUE)
857                         keypad_state = FALSE;
858                 evas_object_smart_callback_del(pswd_popup_data->conf,
859                                 "virtualkeypad,state,on",
860                                 _passwd_popup_keypad_on_cb);
861                 evas_object_smart_callback_del(pswd_popup_data->conf,
862                                 "virtualkeypad,state,off",
863                                 _passwd_popup_keypad_off_cb);
864         }
865
866         if (pswd_popup_data->curr_ap_name != NULL) {
867                 g_free(pswd_popup_data->curr_ap_name);
868                 pswd_popup_data->curr_ap_name = NULL;
869         }
870
871         if (pswd_popup_data->info_popup != NULL) {
872                 evas_object_del(pswd_popup_data->info_popup);
873                 pswd_popup_data->info_popup = NULL;
874                 INFO_LOG(UG_NAME_NORMAL, "info popup deleted");
875         }
876
877         if (pswd_popup_data->pbc_popup_data) {
878                 __common_pbc_popup_destroy(pswd_popup_data->pbc_popup_data);
879                 pswd_popup_data->pbc_popup_data = NULL;
880                 INFO_LOG(UG_NAME_NORMAL, "wps pbc popup deleted");
881         }
882
883         if (pswd_popup_data->popup != NULL) {
884                 evas_object_del(pswd_popup_data->popup);
885                 pswd_popup_data->popup = NULL;
886                 INFO_LOG(UG_NAME_NORMAL, "password popup deleted");
887         }
888
889         if (pswd_popup_data->wps_options_popup != NULL) {
890                 evas_object_del(pswd_popup_data->wps_options_popup);
891                 pswd_popup_data->wps_options_popup = NULL;
892                 INFO_LOG(UG_NAME_NORMAL, "wps option popup deleted");
893         }
894
895         /* Hidden Wi-Fi network does not have handle */
896         if (pswd_popup_data->ap)
897                 wifi_ap_destroy(pswd_popup_data->ap);
898
899         g_free(pswd_popup_data);
900
901         /* A delay is needed to get the smooth Input panel closing animation effect */
902         common_util_managed_ecore_scan_update_timer_add(0.1,
903                         _enable_scan_updates_cb, NULL);
904
905         __COMMON_FUNC_EXIT__;
906 }