Fix genlist style
[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_assist.h>
21 #include <efl_extension.h>
22
23 #include "common.h"
24 #include "common_pswd_popup.h"
25 #include "common_generate_pin.h"
26 #include "i18nmanager.h"
27 #include "ug_wifi.h"
28
29 #define EDJ_GRP_POPUP_PBC_BUTTON_LAYOUT "popup_pbc_button_layout"
30 #define EDJ_GRP_POPUP_WPS_PIN_LAYOUT "popup_wps_pin_layout"
31
32 #define MAX_PBC_TIMEOUT_SECS    120     // Time in seconds
33 #define PASSWORD_LENGTH         64
34
35 static Elm_Genlist_Item_Class g_wps_itc;
36 static Elm_Genlist_Item_Class g_check_box_itc;
37 static Elm_Genlist_Item_Class g_pswd_entry_itc;
38 static gboolean wps_options_click = FALSE;
39 static gboolean keypad_state = FALSE;
40
41 static void __popup_entry_changed_cb(void* data, Evas_Object* obj, void* event_info)
42 {
43         Evas_Object *btn_ok = NULL;
44         pswd_popup_t *pswd_popup_data = NULL;
45         char* entry_str = NULL;
46         unsigned short int passwd_length = 0;
47
48         if (!data) {
49                 return;
50         }
51
52         pswd_popup_data = (pswd_popup_t *) data;
53         entry_str = passwd_popup_get_txt(pswd_popup_data);
54         if (entry_str != NULL)
55                 passwd_length = strlen(entry_str);
56
57         btn_ok = elm_object_part_content_get(pswd_popup_data->popup, "button2");
58
59         if (pswd_popup_data->sec_type == WIFI_SECURITY_TYPE_WEP) {
60                 if (passwd_length > 0) {
61                         elm_object_disabled_set(btn_ok, EINA_FALSE);
62                         elm_entry_input_panel_return_key_disabled_set(obj,
63                                         EINA_FALSE);
64                 } else {
65                         elm_object_disabled_set(btn_ok, EINA_TRUE);
66                         elm_entry_input_panel_return_key_disabled_set(obj,
67                                         EINA_TRUE);
68                 }
69         } else if (pswd_popup_data->sec_type == WIFI_SECURITY_TYPE_WPA2_PSK ||
70                         pswd_popup_data->sec_type == WIFI_SECURITY_TYPE_WPA_PSK) {
71                 if (passwd_length > 7) {
72                         elm_object_disabled_set(btn_ok, EINA_FALSE);
73                         elm_entry_input_panel_return_key_disabled_set(obj,
74                                         EINA_FALSE);
75                 } else {
76                         elm_object_disabled_set(btn_ok, EINA_TRUE);
77                         elm_entry_input_panel_return_key_disabled_set(obj,
78                                         EINA_TRUE);
79                 }
80         }
81
82         if (elm_object_part_content_get(obj, "elm.swallow.clear")) {
83                 if (elm_object_focus_get(obj)) {
84                         if (elm_entry_is_empty(obj)) {
85                                 elm_object_signal_emit(obj,
86                                                 "elm,state,clear,hidden", "");
87                         } else {
88                                 elm_object_signal_emit(obj,
89                                                 "elm,state,clear,visible", "");
90                         }
91                 }
92         }
93
94         if (entry_str)
95                 g_free(entry_str);
96 }
97
98 static void __popup_entry_maxlength_reached(void *data, Evas_Object *obj,
99                 void *event_info)
100 {
101         common_utils_send_message_to_net_popup("Password length",
102                         "Lengthy Password", "notification", NULL);
103 }
104
105 static void __common_pbc_popup_destroy(pbc_popup_t *pbc_popup_data)
106 {
107         __COMMON_FUNC_ENTER__;
108         if (!pbc_popup_data) {
109                 return;
110         }
111
112         if (pbc_popup_data->checker == 0) {
113                 pbc_popup_data->checker = 1;
114
115                 if (pbc_popup_data->timer != NULL) {
116                         ecore_timer_del(pbc_popup_data->timer);
117                         pbc_popup_data->timer = NULL;
118                 }
119
120                 if (pbc_popup_data->pin != NULL) {
121                         g_free(pbc_popup_data->pin);
122                         pbc_popup_data->pin = NULL;
123                 }
124
125                 if (pbc_popup_data->popup != NULL) {
126                         evas_object_hide(pbc_popup_data->popup);
127                         evas_object_del(pbc_popup_data->popup);
128                         pbc_popup_data->popup = NULL;
129                 }
130                 g_free(pbc_popup_data);
131         }
132         __COMMON_FUNC_EXIT__;
133         return;
134 }
135
136 static Eina_Bool _fn_pb_timer_bar(void *data)
137 {
138         double val = 120.0;
139         time_t current_time;
140         int time_diff;
141         time(&current_time);
142
143         pswd_popup_t *pswd_popup_data = (pswd_popup_t *)data;
144         pbc_popup_t *pbc_popup_data = pswd_popup_data->pbc_popup_data;
145         if (!pbc_popup_data || pbc_popup_data->timer == NULL ||
146                         pbc_popup_data->progressbar == NULL) {
147                 return ECORE_CALLBACK_CANCEL;
148         }
149         time_diff = difftime(current_time, pswd_popup_data->start_time);
150         pbc_popup_data->value = (double)(time_diff/(double)MAX_PBC_TIMEOUT_SECS);
151         if (pbc_popup_data->value >= 1) {
152                 if (pbc_popup_data->checker == 0) {
153                         __COMMON_FUNC_ENTER__;
154
155                         Evas_Object *cancel_btn = elm_object_part_content_get(
156                                         pbc_popup_data->popup, "button1");
157                         evas_object_smart_callback_call(cancel_btn, "clicked", NULL);
158
159                         __COMMON_FUNC_EXIT__;
160                 }
161                 return ECORE_CALLBACK_CANCEL;
162         }
163         val = val - time_diff;
164         int remain_mins = (int)(val);
165         int remain_secs = 0;
166         remain_secs = remain_mins % 60;
167         remain_mins /= 60;
168
169         char *remaining_time_str = g_strdup_printf(
170                         "<font_size=40><align=center>%02d:%02d</align></font_size>",
171                         remain_mins, remain_secs);
172         elm_object_text_set(pbc_popup_data->timer_label, remaining_time_str);
173         /* INFO_LOG(UG_NAME_NORMAL, "pbc_popup_data->value = %lf;"
174                         "remain_mins = %d; remain_secs = %d; remaining_time_str = %s",
175                         pbc_popup_data->value, remain_mins, remain_secs, remaining_time_str); */
176         g_free(remaining_time_str);
177
178         elm_progressbar_value_set(pbc_popup_data->progressbar, pbc_popup_data->value);
179
180         return ECORE_CALLBACK_RENEW;
181 }
182
183 static Eina_Bool _enable_scan_updates_cb(void *data)
184 {
185         /* Lets enable the scan updates */
186         wlan_manager_enable_scan_result_update();
187
188         /* Reset the ecore timer handle */
189         common_util_manager_ecore_scan_update_timer_reset();
190
191         return ECORE_CALLBACK_CANCEL;
192 }
193
194 static void __pbc_popup_language_changed_cb(void *data, Evas_Object *obj, void *event_info)
195 {
196         __COMMON_FUNC_ENTER__;
197
198         pbc_popup_t *pbc_data = (pbc_popup_t *)data;
199         Evas_Object *layout = NULL;
200         char str[1024];
201
202         retm_if(pbc_data == NULL || pbc_data->popup == NULL);
203         layout = elm_object_content_get(pbc_data->popup);
204
205         if (pbc_data->wps_type == POPUP_WPS_BTN) {
206                 g_snprintf(str, 1024, sc(PACKAGE,
207                                 I18N_TYPE_Press_WPS_On_Your_Wi_Fi_Access_Point), 2);
208                 elm_object_domain_translatable_part_text_set(layout,
209                                 "elm.text.description", PACKAGE, str);
210         } else if (pbc_data->wps_type == POPUP_WPS_PIN) {
211                 g_snprintf(str, 1024, sc(PACKAGE,
212                                 I18N_TYPE_Enter_PIN_number_on_your_WIFI_access_point),
213                                 pbc_data->pin, 2);
214                 elm_object_domain_translatable_part_text_set(layout,
215                                 "elm.text.description", PACKAGE, str);
216         }
217         __COMMON_FUNC_EXIT__;
218 }
219
220 void create_pbc_popup(pswd_popup_t *pswd_popup_data, Evas_Smart_Cb cancel_cb,
221                 void *cancel_cb_data, popup_type_t type, char *pin)
222 {
223         if (!pswd_popup_data) {
224                 return;
225         }
226         Evas_Object *popup = NULL;
227         Evas_Object *progressbar = NULL;
228         Evas_Object *timer_label = NULL;
229         Evas_Object *layout;
230         char buf[512] = "";
231
232         pbc_popup_t *pbc_popup_data = NULL;
233         pbc_popup_data = g_new0(pbc_popup_t, 1);
234
235         popup_btn_info_t popup_btn_data;
236         memset(&popup_btn_data, 0, sizeof(popup_btn_data));
237         popup_btn_data.btn1_txt = "IDS_WIFI_SK_CANCEL";
238         popup_btn_data.btn1_cb = cancel_cb;
239         popup_btn_data.btn1_data = cancel_cb_data;
240         popup = common_utils_show_info_popup(pswd_popup_data->win, &popup_btn_data);
241
242         if (type == POPUP_WPS_BTN) {
243                 elm_object_domain_translatable_part_text_set(popup, "title,text",
244                                 PACKAGE, "IDS_WIFI_BUTTON_WPS_BUTTON");
245         } else if (type == POPUP_WPS_PIN) {
246                 elm_object_domain_translatable_part_text_set(popup, "title,text",
247                                 PACKAGE, "IDS_WIFI_SK_WPS_PIN" );
248         }
249
250         layout = elm_layout_add(popup);
251         if (layout == NULL) {
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.icon.entry")) {
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         if (state) {
511                 elm_entry_password_set((Evas_Object *)data, EINA_FALSE);
512         } else {
513                 elm_entry_password_set((Evas_Object *)data, EINA_TRUE);
514         }
515 }
516 static char *_gl_pswd_check_box_item_text_get(void *data, Evas_Object *obj,
517                 const char *part)
518 {
519         if (!strcmp("elm.text", part)) {
520                 char buf[1024];
521                 snprintf(buf, 1023, "%s", sc(PACKAGE, I18N_TYPE_Show_password));
522                 return strdup(buf);
523         }
524         return NULL;
525
526 }
527
528 static Evas_Object *_gl_pswd_check_box_item_content_get(void *data,
529                 Evas_Object *obj, const char *part)
530 {
531         Evas_Object *check = NULL;
532         pswd_popup_t *pswd_popup_data = (pswd_popup_t *)data;
533
534         if (!strcmp("elm.swallow.end", part)) {
535                 check = elm_check_add(obj);
536                 evas_object_propagate_events_set(check, EINA_FALSE);
537
538                 evas_object_size_hint_align_set(check, EVAS_HINT_FILL, EVAS_HINT_FILL);
539                 evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
540                 evas_object_smart_callback_add(check, "changed",
541                                 _chk_changed_cb, pswd_popup_data->entry);
542
543                 elm_object_focus_allow_set(check, EINA_FALSE);
544
545                 return check;
546         }
547         return NULL;
548 }
549
550 static void _gl_pswd_check_box_sel(void *data, Evas_Object *obj, void *ei)
551 {
552         __COMMON_FUNC_ENTER__;
553         Elm_Object_Item *item = NULL;
554
555         item = (Elm_Object_Item *)ei;
556         if (item == NULL) {
557                 return;
558         }
559
560         pswd_popup_t *pswd_popup_data = (pswd_popup_t *)data;
561
562         Evas_Object *ck = elm_object_item_part_content_get(ei, "elm.icon.right");
563
564         elm_genlist_item_selected_set(item, EINA_FALSE);
565
566         Eina_Bool state = elm_check_state_get(ck);
567         elm_check_state_set(ck, !state);
568         if (pswd_popup_data) {
569                 _chk_changed_cb(pswd_popup_data->entry, ck, NULL);
570         }
571 }
572
573 static void _passwd_popup_keypad_off_cb(void *data, Evas_Object *obj,
574                 void *event_info)
575 {
576         if (data == NULL) {
577                 return;
578         }
579
580         pswd_popup_t *pop_info = (pswd_popup_t *)data;
581
582         keypad_state = FALSE;
583
584         if (wps_options_click == TRUE) {
585                 wps_options_click = FALSE;
586
587                 if (pop_info->wps_btn_cb != NULL) {
588                         pop_info->wps_btn_cb(NULL, NULL, NULL);
589                 }
590         }
591         INFO_LOG(UG_NAME_NORMAL,"Keypad is down");
592 }
593
594 static void _passwd_popup_keypad_on_cb(void *data, Evas_Object *obj,
595                 void *event_info)
596 {
597         if (data == NULL) {
598                 return;
599         }
600
601         keypad_state = TRUE;
602         INFO_LOG(UG_NAME_NORMAL,"Keypad is up");
603 }
604
605 static void popup_animation_finish_cb(void *data, Evas_Object *obj, void *event_info)
606 {
607         __COMMON_FUNC_ENTER__;
608         Elm_Object_Item *item = (Elm_Object_Item *) data;
609         Evas_Object *entry = NULL;
610
611         entry = elm_object_item_part_content_get(item, "elm.icon.entry");
612         elm_entry_input_panel_show(entry);
613         elm_entry_input_panel_show_on_demand_set(entry, EINA_FALSE);
614         elm_object_focus_set(entry, EINA_TRUE);
615
616         __COMMON_FUNC_EXIT__;
617 }
618
619 static void _common_wps_options_popup_cb(void* data, Evas_Object* obj,
620                 void* event_info)
621 {
622         __COMMON_FUNC_ENTER__;
623
624         if (!event_info || !data) {
625                 return;
626         }
627
628         pswd_popup_t *pop_info = (pswd_popup_t *) data;
629         Elm_Object_Item *item = event_info;
630         elm_genlist_item_selected_set(item, EINA_FALSE);
631
632         if (keypad_state == FALSE) {
633                 if (pop_info->wps_btn_cb != NULL)
634                         pop_info->wps_btn_cb(NULL, NULL, NULL);
635         } else {
636                 wps_options_click = TRUE;
637                 ecore_imf_input_panel_hide();
638         }
639
640         __COMMON_FUNC_EXIT__;
641 }
642
643 pswd_popup_t *create_passwd_popup(Evas_Object *conformant,Evas_Object *win_main,
644                 const char *pkg_name, pswd_popup_create_req_data_t *popup_info)
645 {
646         Evas_Object *passpopup = NULL;
647         Evas_Object *genlist = NULL;
648         Evas_Object *btn_ok = NULL;
649
650         __COMMON_FUNC_ENTER__;
651
652         if (!win_main || !popup_info || !pkg_name) {
653                 return NULL;
654         }
655
656         pswd_popup_t *pswd_popup_data = g_new0(pswd_popup_t, 1);
657
658         if (popup_info->ap) {
659                 if (WIFI_ERROR_NONE !=
660                                 wifi_ap_clone(&(pswd_popup_data->ap), popup_info->ap)) {
661                         g_free(pswd_popup_data);
662
663                         return NULL;
664                 }
665         } else {
666                 /* Hidden Wi-Fi network does not have handle */
667         }
668
669         wps_options_click = FALSE;
670         /* Lets disable the scan updates so that the UI is not refreshed un necessarily */
671         wlan_manager_disable_scan_result_update();
672
673         popup_btn_info_t popup_btn_data;
674         memset(&popup_btn_data, 0, sizeof(popup_btn_data));
675
676         popup_btn_data.title_txt = popup_info->title;
677         popup_btn_data.btn1_cb = popup_info->cancel_cb;
678         popup_btn_data.btn1_data = popup_info->cb_data;
679         popup_btn_data.btn1_txt = "IDS_WIFI_SK_CANCEL";
680         popup_btn_data.btn2_cb = popup_info->ok_cb;
681         popup_btn_data.btn2_data = popup_info->cb_data;
682         popup_btn_data.btn2_txt = "IDS_WIFI_BODY_CONNECT";
683
684         passpopup = common_utils_show_info_popup(win_main, &popup_btn_data);
685
686         if (!passpopup) {
687                 ERROR_LOG(UG_NAME_ERR, "Could not initialize popup");
688                 return NULL;
689         }
690
691         pswd_popup_data->win = win_main;
692         pswd_popup_data->conf = conformant;
693         pswd_popup_data->str_pkg_name = pkg_name;
694         pswd_popup_data->popup = passpopup;
695         pswd_popup_data->sec_type = popup_info->sec_type;
696         pswd_popup_data->curr_ap_name = g_strdup(popup_info->title);
697         pswd_popup_data->show_wps_btn = popup_info->show_wps_btn;
698         pswd_popup_data->wps_btn_cb = popup_info->wps_btn_cb;
699
700         /* Hide the Okay button until the password is entered */
701         btn_ok = elm_object_part_content_get(passpopup, "button2");
702         elm_object_disabled_set(btn_ok, TRUE);
703 #ifdef ACCESSIBLITY_FEATURE
704         Evas_Object *eo = NULL;
705         Evas_Object *ao = NULL;
706         eo = elm_layout_edje_get(passpopup);
707         const Evas_Object *po = edje_object_part_object_get(eo, "elm.text.title");
708         ao = elm_access_object_get(po);
709         elm_access_info_set(ao, ELM_ACCESS_INFO, popup_info->title);
710 #endif
711
712         genlist = elm_genlist_add(passpopup);
713         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
714         elm_scroller_content_min_limit(genlist, EINA_FALSE, EINA_TRUE);
715         evas_object_size_hint_weight_set(genlist,
716                         EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
717         evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
718
719         /* Entry genlist item */
720         g_pswd_entry_itc.item_style = "entry";
721         g_pswd_entry_itc.func.text_get = NULL;
722         g_pswd_entry_itc.func.content_get = _gl_pswd_entry_item_content_get;
723         g_check_box_itc.func.state_get = NULL;
724         g_check_box_itc.func.del = NULL;
725
726         Elm_Object_Item * entry_item = elm_genlist_item_append(genlist,
727                         &g_pswd_entry_itc, pswd_popup_data,
728                         NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
729
730         /* Checkbox genlist item */
731         g_check_box_itc.item_style = WIFI_GENLIST_1LINE_TEXT_ICON_STYLE;
732         g_check_box_itc.func.text_get = _gl_pswd_check_box_item_text_get;
733         g_check_box_itc.func.content_get = _gl_pswd_check_box_item_content_get;
734         g_check_box_itc.func.state_get = NULL;
735         g_check_box_itc.func.del = NULL;
736
737         elm_genlist_item_append(genlist, &g_check_box_itc, pswd_popup_data,
738                         NULL, ELM_GENLIST_ITEM_NONE,
739                         _gl_pswd_check_box_sel, pswd_popup_data);
740
741         if (popup_info->show_wps_btn) {
742                 /* WPS options genlist item */
743                 g_wps_itc.item_style = WIFI_GENLIST_1LINE_TEXT_ICON_STYLE;
744                 g_wps_itc.func.text_get = _passwd_popup_wps_item_text_get;
745                 g_wps_itc.func.content_get = _passwd_popup_wps_item_content_get;
746                 g_wps_itc.func.state_get = NULL;
747                 g_wps_itc.func.del = NULL;
748
749                 pswd_popup_data->wps_options_item = elm_genlist_item_append(genlist,
750                                 &g_wps_itc, NULL, NULL, ELM_GENLIST_ITEM_NONE,
751                                 _common_wps_options_popup_cb, pswd_popup_data);
752         }
753
754         evas_object_show(genlist);
755
756         elm_object_content_set(passpopup, genlist);
757
758         evas_object_smart_callback_add(passpopup, "show,finished",
759                         popup_animation_finish_cb, entry_item);
760         evas_object_show(passpopup);
761
762         evas_object_smart_callback_add(pswd_popup_data->conf,
763                         "virtualkeypad,state,on", _passwd_popup_keypad_on_cb,
764                         pswd_popup_data);
765         evas_object_smart_callback_add(pswd_popup_data->conf,
766                         "virtualkeypad,state,off", _passwd_popup_keypad_off_cb,
767                         pswd_popup_data);
768
769         __COMMON_FUNC_EXIT__;
770         return pswd_popup_data;
771 }
772
773 char *passwd_popup_get_txt(pswd_popup_t *pswd_popup_data)
774 {
775         if (pswd_popup_data) {
776                 Evas_Object *entry = pswd_popup_data->entry;
777                 return elm_entry_markup_to_utf8(elm_entry_entry_get(entry));
778         }
779
780         return NULL;
781 }
782
783 wifi_ap_h passwd_popup_get_ap(pswd_popup_t *pswd_popup_data)
784 {
785         if (pswd_popup_data) {
786                 return pswd_popup_data->ap;
787         }
788
789         return NULL;
790 }
791
792 void current_popup_free(pswd_popup_t *pswd_popup_data, popup_type_t type)
793 {
794         if (pswd_popup_data == NULL) {
795                 return;
796         }
797
798         int rotation = -1;
799         char buf[1024];
800         Evas_Object *curr_popup = NULL;
801
802         if (type == POPUP_WPS_OPTIONS) {
803                 if (pswd_popup_data->wps_options_popup) {
804                         evas_object_hide(pswd_popup_data->wps_options_popup);
805                         evas_object_del(pswd_popup_data->wps_options_popup);
806                         pswd_popup_data->wps_options_popup = NULL;
807                 }
808                 evas_object_show(pswd_popup_data->popup);
809                 curr_popup = pswd_popup_data->popup;
810         }
811
812         rotation = common_utils_get_rotate_angle(APPCORE_RM_UNKNOWN);
813         if (rotation != -1) {
814                 g_snprintf(buf, sizeof(buf), "elm,state,orient,%d", rotation);
815                 SECURE_INFO_LOG(UG_NAME_NORMAL, "Rotation signal - %s", buf);
816                 elm_layout_signal_emit(curr_popup, buf, "elm");
817         }
818 }
819
820 void passwd_popup_hide(pswd_popup_t *pswd_popup_data)
821 {
822         if (pswd_popup_data == NULL) {
823                 return;
824         }
825
826         if (pswd_popup_data->popup != NULL) {
827                 evas_object_hide(pswd_popup_data->popup);
828         }
829 }
830
831 void passwd_popup_show(pswd_popup_t *pswd_popup_data)
832 {
833         if (pswd_popup_data == NULL) {
834                 return;
835         }
836
837         if (pswd_popup_data->popup != NULL) {
838                 evas_object_show(pswd_popup_data->popup);
839         }
840 }
841
842 void passwd_popup_free(pswd_popup_t *pswd_popup_data)
843 {
844         __COMMON_FUNC_ENTER__;
845
846         if (pswd_popup_data == NULL) {
847                 return;
848         }
849
850         if (pswd_popup_data->conf) {
851                 if (keypad_state == TRUE)
852                         keypad_state = FALSE;
853                 evas_object_smart_callback_del(pswd_popup_data->conf,
854                                 "virtualkeypad,state,on",
855                                 _passwd_popup_keypad_on_cb);
856                 evas_object_smart_callback_del(pswd_popup_data->conf,
857                                 "virtualkeypad,state,off",
858                                 _passwd_popup_keypad_off_cb);
859         }
860
861         if (pswd_popup_data->curr_ap_name != NULL) {
862                 g_free(pswd_popup_data->curr_ap_name);
863                 pswd_popup_data->curr_ap_name = NULL;
864         }
865
866         if (pswd_popup_data->info_popup != NULL) {
867                 evas_object_del(pswd_popup_data->info_popup);
868                 pswd_popup_data->info_popup = NULL;
869                 INFO_LOG(UG_NAME_NORMAL, "info popup deleted");
870         }
871
872         if (pswd_popup_data->pbc_popup_data) {
873                 __common_pbc_popup_destroy(pswd_popup_data->pbc_popup_data);
874                 pswd_popup_data->pbc_popup_data = NULL;
875                 INFO_LOG(UG_NAME_NORMAL, "wps pbc popup deleted");
876         }
877
878         if (pswd_popup_data->popup != NULL) {
879                 evas_object_del(pswd_popup_data->popup);
880                 pswd_popup_data->popup = NULL;
881                 INFO_LOG(UG_NAME_NORMAL, "password popup deleted");
882         }
883
884         if (pswd_popup_data->wps_options_popup != NULL) {
885                 evas_object_del(pswd_popup_data->wps_options_popup);
886                 pswd_popup_data->wps_options_popup = NULL;
887                 INFO_LOG(UG_NAME_NORMAL, "wps option popup deleted");
888         }
889
890         /* Hidden Wi-Fi network does not have handle */
891         if (pswd_popup_data->ap)
892                 wifi_ap_destroy(pswd_popup_data->ap);
893
894         g_free(pswd_popup_data);
895
896         /* A delay is needed to get the smooth Input panel closing animation effect */
897         common_util_managed_ecore_scan_update_timer_add(0.1,
898                         _enable_scan_updates_cb, NULL);
899
900         __COMMON_FUNC_EXIT__;
901 }