4 * Copyright 2012 Samsung Electronics Co., Ltd
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
10 * http://www.tizenopensource.org/license
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.
22 #include "common_utils.h"
23 #include "common_generate_pin.h"
24 #include "connection_manager.h"
25 #include "wlan_manager.h"
26 #include "view_detail.h"
27 #include "viewer_list.h"
28 #include "viewer_manager.h"
29 #include "appcoreWrapper.h"
30 #include "i18nmanager.h"
32 #define LIST_ITEM_CONNECTED_AP_FONT_SIZE 28
34 static Evas_Object* viewer_list = NULL;
35 static Elm_Object_Item* first_item = NULL;
36 static Elm_Object_Item* last_item = NULL;
38 static Elm_Genlist_Item_Class *itc;
39 static Elm_Genlist_Item_Class *no_wifi_device_itc;
40 static Elm_Genlist_Item_Class *grouptitle_itc;
41 static Elm_Genlist_Item_Class *last_item_itc;
42 static Elm_Object_Item *grouptitle = NULL;
44 extern wifi_appdata *ug_app_state;
46 struct connecting_cancel_popup_data {
51 static struct connecting_cancel_popup_data *g_disconnect_popup = NULL;
53 static void _gl_listview_more_btn_cb(void *data, Evas_Object *obj, void *event_info)
55 __COMMON_FUNC_ENTER__;
57 elm_object_disabled_set(obj, EINA_TRUE);
59 wifi_device_info_t *device_info = (wifi_device_info_t *)data;
66 SECURE_DEBUG_LOG(UG_NAME_NORMAL, "ssid [%s]", device_info->ssid);
68 view_detail(device_info, ug_app_state->layout_main, obj);
73 char* ConvertRGBAtoHex(int r, int g, int b, int a)
78 string = g_try_malloc0(sizeof(char)*255);
80 hexcolor = (r << 24) + (g << 16) + (b << 8) + a;
81 g_snprintf(string, 255, "%08x", hexcolor);
87 static char* _gl_listview_text_get(void *data, Evas_Object *obj, const char *part)
91 char* convertedColor = NULL;
92 int ug_type = wifi_get_ug_type();
94 ug_genlist_data_t* gdata = (ug_genlist_data_t*) data;
95 retvm_if(NULL == gdata || NULL == gdata->device_info, NULL);
97 assertm_if(NULL == gdata->device_info->ssid, "NULL!!");
99 if (!strcmp("elm.text", part)) {
100 det = evas_textblock_text_utf8_to_markup(NULL,
101 gdata->device_info->ssid);
102 assertm_if(NULL == det, "NULL!!");
103 assertm_if(NULL == convertedColor, "NULL!!");
105 if (ug_type != UG_VIEW_OOBE && VIEWER_ITEM_RADIO_MODE_CONNECTED == gdata->radio_mode) {
106 convertedColor = ConvertRGBAtoHex(61, 185, 204, 255);
107 buf = g_strdup_printf("<color=#%s>%s</color>",
108 convertedColor, det);
111 g_free(convertedColor);
113 } else if (wifi_get_ug_type() == UG_VIEW_OOBE) {
114 buf = g_strdup_printf("<font_size=%d>%s</font_size>",
115 OOBE_BIG_FONT_SIZE, det);
119 } else if (!strcmp("elm.text.sub", part)
120 && gdata->device_info->ap_status_txt != NULL) {
121 det = g_strdup(gdata->device_info->ap_status_txt);
122 assertm_if(NULL == det, "NULL!!");
124 if (ug_type == UG_VIEW_OOBE)
125 buf = g_strdup_printf("<font_size=%d>%s</font_size>",
126 OOBE_SMALL_FONT_SIZE, det);
128 buf = g_strdup_printf("<font_size=%d>%s</font_size>",
129 SMALL_FONT_SIZE, det);
137 static Evas_Object *_gl_listview_content_get(void *data, Evas_Object *obj, const char *part)
139 ug_genlist_data_t *gdata = (ug_genlist_data_t *)data;
140 retvm_if(NULL == gdata, NULL);
142 Evas_Object *icon = NULL;
143 Evas_Object *btn = NULL;
145 if (gdata->device_info->ap_image_path == NULL) {
146 /* if there is no ap_image_path (NO AP Found situation) */
147 DEBUG_LOG(UG_NAME_ERR, "Fatal: Image path is NULL");
149 } else if (!strcmp("elm.swallow.icon", part)) {
150 icon = elm_image_add(obj);
151 retvm_if(NULL == icon, NULL);
154 char *temp_str = NULL;
155 temp_str = g_strdup_printf("%s.png", gdata->device_info->ap_image_path);
156 elm_image_file_set(icon, CUSTOM_EDITFIELD_PATH, temp_str);
159 if (wifi_get_ug_type() == UG_VIEW_OOBE) {
160 evas_object_color_set(icon, 0, 10, 10, 204);
161 evas_object_size_hint_min_set(icon, ELM_SCALE_SIZE(DEFAULT_OOBE_BUTTON_CIRCLE_WIDTH),
162 ELM_SCALE_SIZE(DEFAULT_OOBE_BUTTON_CIRCLE_HEIGHT));
164 evas_object_color_set(icon, 2, 61, 132, 204);
165 evas_object_size_hint_min_set(icon, ELM_SCALE_SIZE(DEFAULT_BUTTON_CIRCLE_SIZE),
166 ELM_SCALE_SIZE(DEFAULT_BUTTON_CIRCLE_SIZE));
168 } else if (!strcmp("elm.swallow.end", part)) {
169 if (VIEWER_ITEM_RADIO_MODE_CONNECTING == gdata->radio_mode ||
170 VIEWER_ITEM_RADIO_MODE_CONFIGURATION == gdata->radio_mode) {
172 icon = elm_progressbar_add(obj);
174 elm_object_style_set(icon, "process_medium");
175 evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, 0.5);
176 evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
177 elm_progressbar_pulse(icon, TRUE);
178 evas_object_propagate_events_set(icon, EINA_FALSE);
179 } else if (wifi_get_ug_type() != UG_VIEW_OOBE) {
180 btn = elm_button_add(obj);
181 elm_object_style_set(btn, "circle_custom");
182 icon = elm_image_add(btn);
183 elm_image_file_set(icon, CUSTOM_EDITFIELD_PATH, "wifi_icon_badge_info.png");
184 elm_image_resizable_set(icon, EINA_TRUE, EINA_TRUE);
185 elm_object_part_content_set(btn, "elm.swallow.content", icon);
186 evas_object_propagate_events_set(btn, EINA_FALSE);
187 evas_object_smart_callback_add(btn, "clicked", _gl_listview_more_btn_cb, gdata->device_info);
188 evas_object_show(btn);
196 static void _gl_listview_del(void *data, Evas_Object *obj)
201 ug_genlist_data_t *gdata = (ug_genlist_data_t *)data;
202 retm_if(NULL == gdata || NULL == gdata->device_info);
204 g_free(gdata->device_info->ap_image_path);
205 g_free(gdata->device_info->ap_status_txt);
206 g_free(gdata->device_info->ssid);
207 wifi_manager_ap_destroy(gdata->device_info->ap);
208 g_free(gdata->device_info);
212 static char *_gl_text_available_networks_get(void *data, Evas_Object *obj,
215 if (!strcmp("elm.text", part))
216 return g_strdup(sc(PACKAGE, I18N_TYPE_Available_networks));
221 static Evas_Object *_gl_content_scanning_icon_get(void *data, Evas_Object *obj,
224 Evas_Object *title_progressbar = NULL;
226 if (HEADER_MODE_SEARCHING == viewer_manager_header_mode_get()) {
227 title_progressbar = elm_progressbar_add(obj);
228 elm_object_style_set(title_progressbar, "process_small");
229 elm_progressbar_horizontal_set(title_progressbar, EINA_TRUE);
230 elm_progressbar_pulse(title_progressbar, EINA_TRUE);
233 return title_progressbar;
236 static char *_gl_hidden_network_text_get(void *data, Evas_Object *obj,
239 if (!strcmp("elm.text", part))
240 return g_strdup_printf("<font_size=%d>%s</font_size>",
241 BIG_FONT_SIZE, sc(PACKAGE, I18N_TYPE_Find_Hidden_Network));
246 static Evas_Object *_gl_hidden_network_content_get(void *data, Evas_Object *obj,
249 Evas_Object *icon = NULL;
251 if (!strcmp("elm.swallow.icon", part)) {
252 icon = elm_image_add(obj);
253 retvm_if(NULL == icon, NULL);
254 elm_image_file_set(icon, CUSTOM_EDITFIELD_PATH, "find_hidden_network.png");
255 evas_object_size_hint_min_set(icon, ELM_SCALE_SIZE(DEFAULT_OOBE_BUTTON_CIRCLE_WIDTH),
256 ELM_SCALE_SIZE(DEFAULT_OOBE_BUTTON_CIRCLE_HEIGHT));
262 Elm_Object_Item* viewer_list_get_first_item(void)
267 Elm_Object_Item* viewer_list_get_last_item(void)
272 #ifdef ACCESSIBLITY_FEATURE
273 static char *_access_info_cb(void *data, Evas_Object *obj)
275 char *strength = NULL;
278 ug_genlist_data_t *gdata = (ug_genlist_data_t *)data;
282 strength = common_utils_get_rssi_text(PACKAGE, gdata->device_info->rssi);
283 buf = g_strdup_printf("%s. %s. %s.", strength, gdata->device_info->ssid, gdata->device_info->ap_status_txt);
290 static void gl_lang_changed(void *data, Evas_Object *obj, void *event_info)
292 elm_genlist_realized_items_update(obj);
295 static void _gl_realized(void *data, Evas_Object *obj, void *event_info)
297 #ifdef ACCESSIBLITY_FEATURE
298 HEADER_MODES header_mode = viewer_manager_header_mode_get();
299 Elm_Object_Item *item = (Elm_Object_Item *)event_info;
301 if (header_mode == HEADER_MODE_ACTIVATING ||
302 header_mode == HEADER_MODE_DEACTIVATING ||
303 header_mode == HEADER_MODE_OFF) {
307 Elm_Object_Item *first_item = viewer_list_get_first_item();
308 Elm_Object_Item *last_item = viewer_list_get_last_item();
310 if (first_item == NULL || last_item == NULL)
313 int index = (int)elm_genlist_item_index_get(item);
314 int first_item_index = (int)elm_genlist_item_index_get(first_item);
315 int last_item_index = (int)elm_genlist_item_index_get(last_item);
318 if (first_item_index == -1) {
319 int group_index = (int)elm_genlist_item_index_get(grouptitle);
320 first_item_index = group_index + 1;
323 if (index >= first_item_index && index <= last_item_index &&
324 first_item_index < last_item_index) {
326 Evas_Object *ao = elm_object_item_access_object_get(item);
327 elm_access_info_cb_set(ao, ELM_ACCESS_INFO, _access_info_cb, elm_object_item_data_get(item));
328 g_snprintf(buf, sizeof(buf), "%s%s",
329 sc(PACKAGE, I18N_TYPE_Double_tap),
330 sc(PACKAGE, I18N_TYPE_Connect_to_device));
331 elm_access_info_set(ao, ELM_ACCESS_TYPE, buf);
332 elm_access_info_set(ao, ELM_ACCESS_STATE, sc(PACKAGE, I18N_TYPE_Wi_Fi_network_info));
335 Elm_Object_Item *first_item = viewer_list_get_first_item();
337 if (first_item == NULL)
340 int first_item_index = (int)elm_genlist_item_index_get(first_item);
342 if (first_item_index == -1) {
343 int group_index = (int)elm_genlist_item_index_get(grouptitle);
344 first_item_index = group_index + 1;
349 static void _info_popup_ok_cb(void *data, Evas_Object *obj, void *event_info)
351 pswd_popup_t *passpopup = (pswd_popup_t *)data;
353 if (passpopup != NULL && passpopup->info_popup != NULL) {
354 evas_object_del(passpopup->info_popup);
355 passpopup->info_popup = NULL;
359 static void __passwd_popup_cancel_cb(void *data, Evas_Object *obj,
362 __COMMON_FUNC_ENTER__;
364 if (ug_app_state->passpopup == NULL)
367 passwd_popup_free(ug_app_state->passpopup);
368 ug_app_state->passpopup = NULL;
373 __COMMON_FUNC_EXIT__;
376 static void __passwd_popup_ok_cb(void *data, Evas_Object *obj, void *event_info)
378 __COMMON_FUNC_ENTER__;
380 wifi_manager_ap_h ap = NULL;
381 int password_len = 0;
382 const char *password = NULL;
383 wifi_manager_security_type_e sec_type = WIFI_MANAGER_SECURITY_TYPE_NONE;
385 if (ug_app_state->passpopup == NULL)
388 ap = passwd_popup_get_ap(ug_app_state->passpopup);
389 password = passwd_popup_get_txt(ug_app_state->passpopup);
390 if (password != NULL)
391 password_len = strlen(password);
393 wifi_manager_ap_get_security_type(ap, &sec_type);
396 case WIFI_MANAGER_SECURITY_TYPE_WEP:
397 if (password_len != 5 && password_len != 13 &&
398 password_len != 26 && password_len != 10) {
399 common_utils_send_message_to_net_popup(
400 "Network connection popup",
401 "wrong password", "toast_popup", NULL);
403 if (ug_app_state->passpopup->entry) {
404 elm_object_focus_set(
405 ug_app_state->passpopup->entry,
412 case WIFI_MANAGER_SECURITY_TYPE_WPA_PSK:
413 case WIFI_MANAGER_SECURITY_TYPE_WPA2_PSK:
414 if (password_len < 8 || password_len > 64) {
415 common_utils_send_message_to_net_popup(
416 "Network connection popup",
417 "wrong password", "toast_popup", NULL);
419 if (ug_app_state->passpopup->entry) {
420 elm_object_focus_set(
421 ug_app_state->passpopup->entry,
429 ERROR_LOG(UG_NAME_NORMAL, "Wrong security mode: %d", sec_type);
430 passwd_popup_free(ug_app_state->passpopup);
431 ug_app_state->passpopup = NULL;
433 goto popup_ok_cb_exit;
436 bool favorite = FALSE;
437 if (wifi_manager_ap_is_favorite(ap, &favorite) == WIFI_MANAGER_ERROR_NONE
438 && favorite == TRUE) {
439 wlan_manager_forget(ap);
440 wifi_manager_ap_refresh(ap);
443 if (ug_app_state->is_hidden) {
444 wifi_manager_ap_h hidden_ap;
446 wifi_manager_ap_get_essid(ap, &ssid);
447 wlan_manager_ap_hidden_create(ssid, &hidden_ap);
449 wifi_manager_ap_set_security_type(hidden_ap, sec_type);
450 wlan_manager_connect_with_password(hidden_ap, password);
452 wlan_manager_connect_with_password(ap, password);
454 passwd_popup_free(ug_app_state->passpopup);
455 ug_app_state->passpopup = NULL;
462 g_free((gpointer)password);
464 __COMMON_FUNC_EXIT__;
467 static void __wps_pbc_popup_cancel_connecting(void *data, Evas_Object *obj,
470 __COMMON_FUNC_ENTER__;
472 if (ug_app_state->passpopup == NULL)
475 wifi_manager_ap_h ap = passwd_popup_get_ap(ug_app_state->passpopup);
477 int ret = wlan_manager_disconnect(ap);
478 if (ret != WLAN_MANAGER_ERR_NONE)
479 ERROR_LOG(UG_NAME_NORMAL, "Failed WPS PBC cancellation [%p]", ap);
481 passwd_popup_free(ug_app_state->passpopup);
482 ug_app_state->passpopup = NULL;
484 viewer_manager_header_mode_set(HEADER_MODE_ON);
485 ug_app_state->is_wifi_scan_indication_block = 0;
487 __COMMON_FUNC_EXIT__;
490 static void _wps_btn_cb(void* data, Evas_Object* obj, void* event_info)
492 __COMMON_FUNC_ENTER__;
494 if (!ug_app_state->passpopup)
497 ug_app_state->is_wifi_scan_indication_block = 1;
498 wifi_manager_ap_h ap = passwd_popup_get_ap(ug_app_state->passpopup);
499 int ret = wlan_manager_wps_connect(ap);
500 if (ret == WLAN_MANAGER_ERR_NONE) {
501 create_pbc_popup(ug_app_state->passpopup,
502 __wps_pbc_popup_cancel_connecting, NULL,
503 POPUP_WPS_BTN, NULL);
505 ERROR_LOG(UG_NAME_NORMAL, "wlan_manager_wps_connect failed");
506 passwd_popup_free(ug_app_state->passpopup);
507 ug_app_state->passpopup = NULL;
508 ug_app_state->is_wifi_scan_indication_block = 0;
511 __COMMON_FUNC_EXIT__;
514 static void _wps_cancel_cb(void* data, Evas_Object* obj, void* event_info)
516 __COMMON_FUNC_ENTER__;
518 ug_app_state->is_wifi_scan_indication_block = 0;
520 if (ug_app_state->passpopup == NULL)
523 current_popup_free(ug_app_state->passpopup, POPUP_WPS_OPTIONS);
525 __COMMON_FUNC_EXIT__;
528 static void _wps_pin_cb(void* data, Evas_Object* obj, void* event_info)
530 __COMMON_FUNC_ENTER__;
531 unsigned int rpin = 0;
532 char npin[9] = { '\0' };
534 int ret = WLAN_MANAGER_ERR_NONE;
535 wifi_manager_ap_h ap = NULL;
536 Evas_Object *info_popup = NULL;
538 if (!ug_app_state->passpopup)
541 ug_app_state->is_wifi_scan_indication_block = 1;
543 /* Generate WPS pin */
544 if (wps_generate_pin(&rpin) < 0) {
545 ERROR_LOG(UG_NAME_NORMAL, "Failed to generate WPS PIN");
546 __COMMON_FUNC_EXIT__;
551 g_snprintf(npin, sizeof(npin), "%08d", rpin);
553 pin_len = strlen(npin);
555 info_popup = common_utils_show_info_ok_popup(
556 ug_app_state->layout_main, PACKAGE,
557 sc(PACKAGE, I18N_TYPE_Invalid_pin),
559 ug_app_state->passpopup);
560 ug_app_state->passpopup->info_popup = info_popup;
562 __COMMON_FUNC_EXIT__;
566 ap = passwd_popup_get_ap(ug_app_state->passpopup);
568 ret = wlan_manager_wps_pin_connect(ap, npin);
569 if (ret == WLAN_MANAGER_ERR_NONE) {
570 INFO_LOG(UG_NAME_NORMAL, "wlan_manager_wps_pin_connect successful");
572 create_pbc_popup(ug_app_state->passpopup,
573 __wps_pbc_popup_cancel_connecting, NULL,
574 POPUP_WPS_PIN, npin);
576 ERROR_LOG(UG_NAME_NORMAL, "wlan_manager_wps_pin_connect failed");
577 passwd_popup_free(ug_app_state->passpopup);
578 ug_app_state->passpopup = NULL;
579 ug_app_state->is_wifi_scan_indication_block = 0;
582 __COMMON_FUNC_EXIT__;
585 static void __wps_options_popup_cb(void* data, Evas_Object* obj, void* event_info)
587 __COMMON_FUNC_ENTER__;
588 pswd_popup_create_req_data_t popup_info;
590 if (!ug_app_state->passpopup)
593 memset(&popup_info, 0, sizeof(pswd_popup_create_req_data_t));
595 popup_info.title = "IDS_WIFI_HEADER_SELECT_WPS_METHOD_ABB";
596 popup_info.ok_cb = NULL;
597 popup_info.cancel_cb = _wps_cancel_cb;
598 popup_info.show_wps_btn = EINA_FALSE;
599 popup_info.wps_btn_cb = _wps_btn_cb;
600 popup_info.wps_pin_cb = _wps_pin_cb;
601 popup_info.ap = passwd_popup_get_ap(ug_app_state->passpopup);
602 popup_info.cb_data = NULL;
603 create_wps_options_popup(ug_app_state->layout_main, ug_app_state->passpopup,
606 __COMMON_FUNC_EXIT__;
609 void viewer_list_wifi_reconnect(wifi_device_info_t *device_info)
611 pswd_popup_create_req_data_t popup_info;
612 wifi_manager_security_type_e sec_type = WIFI_MANAGER_SECURITY_TYPE_NONE;
613 wifi_device_info_t *device_info_temp = NULL;
614 struct ug_data *ugd = (struct ug_data *)ug_app_state->gadget;
616 if (device_info == NULL)
619 if (ug_app_state->passpopup != NULL || ug_app_state->eap_view != NULL) {
620 INFO_LOG(UG_NAME_ERR, "already launched popup");
624 wifi_manager_ap_get_security_type(device_info->ap, &sec_type);
627 case WIFI_MANAGER_SECURITY_TYPE_WEP:
628 case WIFI_MANAGER_SECURITY_TYPE_WPA_PSK:
629 case WIFI_MANAGER_SECURITY_TYPE_WPA2_PSK:
630 memset(&popup_info, 0, sizeof(pswd_popup_create_req_data_t));
632 device_info_temp = view_list_item_device_info_create(device_info->ap);
634 popup_info.title = device_info->ssid;
635 popup_info.sub_title = common_utils_get_ap_security_type_info_txt(PACKAGE,
638 popup_info.ok_cb = __passwd_popup_ok_cb;
639 popup_info.cancel_cb = __passwd_popup_cancel_cb;
640 popup_info.show_wps_btn = device_info->wps_mode;
641 popup_info.wps_btn_cb = __wps_options_popup_cb;
642 popup_info.ap = device_info->ap;
643 popup_info.cb_data = device_info_temp;
644 popup_info.sec_type = sec_type;
646 /* TODO: parameter with device_info */
647 /* TODO: finally parameter with wifi_manager_ap_h, WPA, EAP */
648 ug_app_state->passpopup = create_passwd_popup(
649 ug_app_state->conformant,
650 ug_app_state->parent_layout, PACKAGE, &popup_info);
652 if (ug_app_state->passpopup == NULL)
653 INFO_LOG(UG_NAME_ERR, "Fail to create password popup");
655 g_free(popup_info.sub_title);
657 case WIFI_MANAGER_SECURITY_TYPE_EAP:
658 ug_app_state->eap_view = create_eap_view(
659 ug_app_state->parent_layout, ugd->win_main,
660 ug_app_state->conformant,
661 PACKAGE, device_info,
662 viewer_manager_eap_view_deref);
665 ERROR_LOG(UG_NAME_NORMAL, "Unknown security type [%d]", sec_type);
671 void viewer_list_wifi_connect(wifi_device_info_t *device_info)
673 bool favorite = false;
674 pswd_popup_create_req_data_t popup_info;
675 wifi_manager_security_type_e sec_type = WIFI_MANAGER_SECURITY_TYPE_NONE;
676 wifi_device_info_t *dev_info_temp = NULL;
677 struct ug_data *ugd = (struct ug_data *)ug_app_state->gadget;
679 if (device_info == NULL)
682 wifi_manager_ap_is_favorite(device_info->ap, &favorite);
683 if (favorite == true) {
684 wlan_manager_connect(device_info->ap);
688 if (ug_app_state->passpopup != NULL || ug_app_state->eap_view != NULL) {
689 INFO_LOG(UG_NAME_ERR, "already launched popup");
693 wifi_manager_ap_get_security_type(device_info->ap, &sec_type);
696 case WIFI_MANAGER_SECURITY_TYPE_NONE:
697 if (ug_app_state->is_hidden) {
698 wifi_manager_ap_h ap;
700 wifi_manager_ap_get_essid(device_info->ap, &ssid);
701 wlan_manager_ap_hidden_create(ssid, &ap);
703 wifi_manager_ap_set_security_type(ap, WIFI_MANAGER_SECURITY_TYPE_NONE);
704 wlan_manager_connect(ap);
706 wlan_manager_connect(device_info->ap);
709 case WIFI_MANAGER_SECURITY_TYPE_WEP:
710 case WIFI_MANAGER_SECURITY_TYPE_WPA_PSK:
711 case WIFI_MANAGER_SECURITY_TYPE_WPA2_PSK:
712 memset(&popup_info, 0, sizeof(pswd_popup_create_req_data_t));
714 dev_info_temp = view_list_item_device_info_create(device_info->ap);
716 popup_info.title = device_info->ssid;
717 popup_info.sub_title = common_utils_get_ap_security_type_info_txt(PACKAGE,
720 popup_info.ok_cb = __passwd_popup_ok_cb;
721 popup_info.cancel_cb = __passwd_popup_cancel_cb;
722 popup_info.show_wps_btn = device_info->wps_mode;
723 popup_info.wps_btn_cb = __wps_options_popup_cb;
724 popup_info.ap = device_info->ap;
725 popup_info.cb_data = dev_info_temp;
726 popup_info.sec_type = sec_type;
728 /* TODO: parameter with device_info */
729 /* TODO: finally parameter with wifi_manager_ap_h, WPA, EAP */
730 ug_app_state->passpopup = create_passwd_popup(
731 ug_app_state->conformant,
732 ug_app_state->parent_layout, PACKAGE, &popup_info);
734 if (ug_app_state->passpopup == NULL)
735 INFO_LOG(UG_NAME_ERR, "Fail to create password popup");
737 g_free(popup_info.sub_title);
740 case WIFI_MANAGER_SECURITY_TYPE_EAP:
741 ug_app_state->eap_view = create_eap_view(
742 ug_app_state->parent_layout, ugd->win_main,
743 ug_app_state->conformant,
744 PACKAGE, device_info,
745 viewer_manager_eap_view_deref);
749 ERROR_LOG(UG_NAME_NORMAL, "Unknown security type[%d]", sec_type);
754 void viewer_list_clear_disconnect_popup(wifi_manager_ap_h ap)
756 if (!g_disconnect_popup)
759 if (ap && g_disconnect_popup->ap &&
760 wlan_manager_is_same_network(g_disconnect_popup->ap, ap) != TRUE)
763 if (g_disconnect_popup->popup)
764 evas_object_del(g_disconnect_popup->popup);
766 if (g_disconnect_popup->ap)
767 wifi_manager_ap_destroy(g_disconnect_popup->ap);
769 g_free(g_disconnect_popup);
770 g_disconnect_popup = NULL;
773 static void __viewer_list_disconnect_cancel_cb(void *data,
774 Evas_Object *obj, void *event_info)
776 struct connecting_cancel_popup_data *popup =
777 (struct connecting_cancel_popup_data *)data;
782 evas_object_del(popup->popup);
785 wifi_manager_ap_destroy(popup->ap);
788 g_disconnect_popup = NULL;
791 static gboolean __viewer_list_update_ap(gpointer data)
793 wifi_manager_ap_h ap = (wifi_manager_ap_h)data;
795 viewer_manager_update_item_favorite_status(ap);
796 wifi_manager_ap_destroy(ap);
801 static void __viewer_list_disconnect_ok_cb(void *data,
802 Evas_Object *obj, void *event_info)
805 struct connecting_cancel_popup_data *popup =
806 (struct connecting_cancel_popup_data *)data;
810 wlan_manager_disconnect(popup->ap);
811 wlan_manager_forget(popup->ap);
814 evas_object_del(popup->popup);
816 id = common_util_managed_idle_add(__viewer_list_update_ap, (gpointer)popup->ap);
818 viewer_manager_update_item_favorite_status(popup->ap);
819 wifi_manager_ap_destroy(popup->ap);
823 g_disconnect_popup = NULL;
826 static void __viewer_list_disconnect_popup(wifi_device_info_t *device_info,
827 Evas_Object *win_main)
829 popup_btn_info_t popup_data;
830 struct connecting_cancel_popup_data *popup = NULL;
832 memset(&popup_data, 0, sizeof(popup_data));
834 popup = g_try_new0(struct connecting_cancel_popup_data, 1);
838 g_disconnect_popup = popup;
839 wifi_manager_ap_clone(&popup->ap, device_info->ap);
841 popup_data.title_txt = "IDS_WIFI_OPT_FORGET_NETWORK";
842 popup_data.info_txt = "IDS_WIFI_POP_CURRENT_NETWORK_WILL_BE_DISCONNECTED";
843 popup_data.btn1_cb = __viewer_list_disconnect_cancel_cb;
844 popup_data.btn1_txt = "IDS_WIFI_SK_CANCEL";
845 popup_data.btn1_data = popup;
846 popup_data.btn2_cb = __viewer_list_disconnect_ok_cb;
847 popup_data.btn2_txt = "IDS_WIFI_SK_FORGET";
848 popup_data.btn2_data = popup;
850 popup->popup = common_utils_show_info_popup(win_main, &popup_data);
853 static void __viewer_list_item_clicked_cb(void *data, Evas_Object *obj,
856 __COMMON_FUNC_ENTER__;
858 assertm_if(NULL == event_info, "event_info is NULL!!");
859 assertm_if(NULL == obj, "obj is NULL!!");
861 Elm_Object_Item *it = (Elm_Object_Item *)event_info;
862 ug_genlist_data_t *gdata = NULL;
863 wifi_device_info_t *device_info = NULL;
865 gdata = (ug_genlist_data_t *)elm_object_item_data_get(it);
866 retm_if(NULL == gdata);
868 device_info = gdata->device_info;
869 retm_if(NULL == device_info || NULL == device_info->ssid);
871 int item_state = gdata->radio_mode;
872 int current_state = 0;
874 SECURE_INFO_LOG(UG_NAME_NORMAL, "ssid --- %s", device_info->ssid);
875 INFO_LOG(UG_NAME_NORMAL, "ap --- %p", device_info->ap);
876 INFO_LOG(UG_NAME_NORMAL, "current item_state state is --- %d", item_state);
878 if (ug_app_state->is_lbhome == EINA_TRUE &&
879 ug_app_state->app_control != NULL) {
880 INFO_LOG(UG_NAME_NORMAL, "exit with reply");
884 app_control_create(&reply);
885 wifi_manager_ap_get_bssid(device_info->ap, &bssid);
886 SECURE_INFO_LOG(UG_NAME_NORMAL, "bssid %s, ssid %s", bssid, device_info->ssid);
888 app_control_add_extra_data(reply, "bssid", bssid);
889 app_control_add_extra_data(reply, "ssid", device_info->ssid);
890 app_control_reply_to_launch_request(reply, ug_app_state->app_control,
891 APP_CONTROL_RESULT_SUCCEEDED);
892 app_control_destroy(reply);
898 switch (item_state) {
899 case VIEWER_ITEM_RADIO_MODE_OFF:
900 current_state = viewer_manager_header_mode_get();
902 INFO_LOG(UG_NAME_NORMAL, "Clicked AP information\n");
903 INFO_LOG(UG_NAME_NORMAL, "header mode [%d]", current_state);
905 switch (current_state) {
907 case HEADER_MODE_CONNECTED:
908 case HEADER_MODE_CONNECTING:
909 case HEADER_MODE_SEARCHING:
910 viewer_list_wifi_connect(device_info);
913 case HEADER_MODE_OFF:
914 case HEADER_MODE_ACTIVATING:
915 case HEADER_MODE_DEACTIVATING:
917 INFO_LOG(UG_NAME_NORMAL, "Ignore click");
922 case VIEWER_ITEM_RADIO_MODE_CONNECTING:
923 case VIEWER_ITEM_RADIO_MODE_CONFIGURATION:
924 __viewer_list_disconnect_popup(device_info, ug_app_state->layout_main);
926 case VIEWER_ITEM_RADIO_MODE_CONNECTED:
928 INFO_LOG(UG_NAME_NORMAL, "Ignore click");
932 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
934 __COMMON_FUNC_EXIT__;
937 static char *viewer_list_get_device_status_txt(wifi_device_info_t *wifi_device,
938 VIEWER_ITEM_RADIO_MODES mode)
940 char *status_txt = NULL;
941 int current_state = 0;
943 current_state = viewer_manager_header_mode_get();
944 /* The strings are currently hard coded. It will be replaced with string ids later */
945 if (VIEWER_ITEM_RADIO_MODE_CONNECTING == mode) {
946 status_txt = g_strdup(sc(PACKAGE, I18N_TYPE_Connecting));
947 } else if (VIEWER_ITEM_RADIO_MODE_CONFIGURATION == mode) {
948 status_txt = g_strdup(sc(PACKAGE, I18N_TYPE_Obtaining_IP_addr));
949 } else if (VIEWER_ITEM_RADIO_MODE_CONNECTED == mode) {
950 if (connection_manager_is_wifi_connection_used() ||
951 current_state == HEADER_MODE_CONNECTED) {
952 status_txt = g_strdup(sc(PACKAGE, I18N_TYPE_Connected));
954 } else if (VIEWER_ITEM_RADIO_MODE_OFF == mode) {
955 status_txt = common_utils_get_ap_security_type_info_txt(PACKAGE,
958 status_txt = g_strdup(sc(PACKAGE, I18N_TYPE_Unknown));
959 INFO_LOG(UG_NAME_NORMAL, "Invalid mode: %d", mode);
965 Evas_Object* viewer_list_create(Evas_Object *win)
967 __COMMON_FUNC_ENTER__;
969 assertm_if(NULL == win, "NULL!!");
970 assertm_if(NULL != viewer_list, "Err!!");
972 viewer_list = elm_genlist_add(win);
973 assertm_if(NULL == viewer_list, "NULL!!");
975 if (wifi_get_ug_type() == UG_VIEW_OOBE) {
976 elm_object_style_set(viewer_list, "solid/default");
977 elm_object_color_class_color_set(viewer_list, "bg", 255, 255, 255, 255);
980 // To use multiline textblock/entry/editfield in genlist, set height_for_width mode
981 // then the item's height is calculated while the item's width fits to genlist width.
982 elm_genlist_mode_set(viewer_list, ELM_LIST_COMPRESS);
983 //elm_genlist_realization_mode_set(viewer_list, EINA_TRUE);
985 evas_object_size_hint_weight_set(viewer_list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
986 evas_object_size_hint_align_set(viewer_list, EVAS_HINT_FILL, EVAS_HINT_FILL);
988 itc = elm_genlist_item_class_new();
989 itc->item_style = WIFI_GENLIST_2LINE_TOP_TEXT_ICON_STYLE;
990 itc->func.text_get = _gl_listview_text_get;
991 itc->func.content_get = _gl_listview_content_get;
992 itc->func.state_get = NULL;
993 itc->func.del = _gl_listview_del;
995 no_wifi_device_itc = elm_genlist_item_class_new();
996 no_wifi_device_itc->item_style = WIFI_GENLIST_1LINE_TEXT_STYLE;
997 no_wifi_device_itc->func.text_get = _gl_listview_text_get;
998 no_wifi_device_itc->func.content_get = NULL;
999 no_wifi_device_itc->func.state_get = NULL;
1000 no_wifi_device_itc->func.del = _gl_listview_del;
1002 if (wifi_get_ug_type() == UG_VIEW_OOBE) {
1003 last_item_itc = elm_genlist_item_class_new();
1004 last_item_itc->item_style = WIFI_GENLIST_1LINE_TEXT_ICON_STYLE;
1005 last_item_itc->func.text_get = _gl_hidden_network_text_get;
1006 last_item_itc->func.content_get = _gl_hidden_network_content_get;
1007 last_item_itc->func.del = NULL;
1010 first_item = last_item = NULL;
1012 evas_object_smart_callback_add(viewer_list, "realized",
1013 _gl_realized, NULL);
1014 evas_object_smart_callback_add(viewer_list, "language,changed",
1015 gl_lang_changed, NULL);
1017 __COMMON_FUNC_EXIT__;
1021 void viewer_list_title_item_del(void)
1023 if (grouptitle != NULL) {
1024 elm_object_item_del(grouptitle);
1029 void viewer_list_title_item_update(void)
1031 if (grouptitle != NULL)
1032 elm_genlist_item_update(grouptitle);
1035 void viewer_list_title_item_set(Elm_Object_Item *item_header)
1037 if (item_header == NULL)
1040 if (grouptitle != NULL) {
1041 elm_genlist_item_update(grouptitle);
1045 //memset(&grouptitle_itc, 0, sizeof(grouptitle_itc));
1046 grouptitle_itc = elm_genlist_item_class_new();
1047 if (wifi_get_ug_type() == UG_VIEW_OOBE) {
1048 grouptitle_itc->item_style = WIFI_GENLIST_FULL_STYLE;
1049 grouptitle_itc->func.text_get = NULL;
1050 grouptitle_itc->func.content_get = NULL;
1052 grouptitle_itc->item_style = WIFI_GENLIST_GROUP_INDEX_STYLE;
1053 grouptitle_itc->func.text_get = _gl_text_available_networks_get;
1054 grouptitle_itc->func.content_get = _gl_content_scanning_icon_get;
1057 grouptitle = elm_genlist_item_insert_after(viewer_list,
1058 grouptitle_itc, NULL, NULL, item_header,
1059 ELM_GENLIST_ITEM_NONE, NULL, NULL);
1061 assertm_if(NULL == grouptitle, "NULL!!");
1063 elm_genlist_item_select_mode_set(grouptitle,
1064 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1067 int viewer_list_item_radio_mode_set(Elm_Object_Item* item,
1068 VIEWER_ITEM_RADIO_MODES mode)
1070 __COMMON_FUNC_ENTER__;
1073 INFO_LOG(COMMON_NAME_ERR, "item is NULL");
1077 ug_genlist_data_t* gdata = (ug_genlist_data_t *) elm_object_item_data_get(item);
1078 if (NULL == gdata || NULL == gdata->device_info) {
1079 INFO_LOG(COMMON_NAME_ERR, "gdata or device_info is NULL");
1083 if (gdata->radio_mode == mode) {
1084 SECURE_INFO_LOG(UG_NAME_NORMAL, "[%s] is already in requested state", gdata->device_info->ssid);
1088 SECURE_INFO_LOG(UG_NAME_NORMAL, "[%s] AP Item State Transition from [%d] --> [%d]", gdata->device_info->ssid, gdata->radio_mode, mode);
1089 gdata->radio_mode = mode;
1090 if (gdata->device_info->ap_status_txt) {
1091 g_free(gdata->device_info->ap_status_txt);
1092 gdata->device_info->ap_status_txt = viewer_list_get_device_status_txt(gdata->device_info, mode);
1096 elm_genlist_item_update(item);
1098 __COMMON_FUNC_EXIT__;
1102 static wifi_manager_connection_state_e _convert_wifi_state_to_viewer_radio_mode(
1103 wifi_manager_connection_state_e state)
1106 case WIFI_MANAGER_CONNECTION_STATE_ASSOCIATION:
1107 return VIEWER_ITEM_RADIO_MODE_CONNECTING;
1108 case WIFI_MANAGER_CONNECTION_STATE_CONFIGURATION:
1109 return VIEWER_ITEM_RADIO_MODE_CONFIGURATION;
1110 case WIFI_MANAGER_CONNECTION_STATE_CONNECTED:
1111 return VIEWER_ITEM_RADIO_MODE_CONNECTED;
1113 return VIEWER_ITEM_RADIO_MODE_OFF;
1117 Elm_Object_Item *viewer_list_item_insert_after(wifi_device_info_t *wifi_device,
1118 Elm_Object_Item *after)
1120 Elm_Object_Item* ret = NULL;
1121 ug_genlist_data_t* gdata = NULL;
1122 wifi_device_info_t *no_wifi_device = NULL;
1123 retvm_if(NULL == viewer_list, NULL);
1125 if (_is_emulator()) {
1126 if (wifi_device != NULL) {
1127 wifi_device->ap_status_txt = viewer_list_get_device_status_txt(
1129 VIEWER_ITEM_RADIO_MODE_OFF);
1131 no_wifi_device = g_try_new0(wifi_device_info_t, 1);
1132 if (no_wifi_device == NULL)
1135 no_wifi_device->ssid = g_strdup(sc(PACKAGE, I18N_TYPE_No_Wi_Fi_AP_Found));
1136 wifi_device = no_wifi_device;
1139 wifi_manager_connection_state_e state = WIFI_MANAGER_CONNECTION_STATE_DISCONNECTED;
1140 VIEWER_ITEM_RADIO_MODES rad_mode = VIEWER_ITEM_RADIO_MODE_OFF;
1141 if (wifi_device != NULL && wifi_device->ap != NULL) {
1142 if (wifi_manager_ap_get_connection_state(wifi_device->ap, &state) ==
1143 WIFI_MANAGER_ERROR_NONE) {
1144 rad_mode = _convert_wifi_state_to_viewer_radio_mode(state);
1146 wifi_device->ap_status_txt = viewer_list_get_device_status_txt(
1150 if (ug_app_state->is_first_scan == true) {
1151 int scan_result = wlan_manager_scan();
1152 if (scan_result != WLAN_MANAGER_ERR_NONE) {
1153 viewer_manager_hide(VIEWER_WINSET_SEARCHING);
1154 viewer_manager_header_mode_set(viewer_manager_header_mode_get());
1156 ug_app_state->is_first_scan = false;
1159 no_wifi_device = g_try_new0(wifi_device_info_t, 1);
1160 if (no_wifi_device == NULL)
1163 no_wifi_device->ssid = g_strdup(sc(PACKAGE, I18N_TYPE_No_Wi_Fi_AP_Found));
1164 wifi_device = no_wifi_device;
1168 gdata = g_try_new0(ug_genlist_data_t, 1);
1169 if (gdata == NULL) {
1170 if (no_wifi_device) {
1171 g_free(no_wifi_device->ssid);
1172 g_free(no_wifi_device);
1177 gdata->device_info = wifi_device;
1178 gdata->radio_mode = VIEWER_ITEM_RADIO_MODE_OFF;
1181 /* If the after item is NULL then insert it as first item */
1185 if (no_wifi_device == NULL) {
1186 ret = elm_genlist_item_insert_after(
1187 viewer_list, /*obj*/
1191 after, /*after than*/
1192 ELM_GENLIST_ITEM_NONE, /*flags*/
1193 __viewer_list_item_clicked_cb,/*func*/
1196 ret = elm_genlist_item_insert_after(
1197 viewer_list, /*obj*/
1198 no_wifi_device_itc,/*itc*/
1201 after, /*after than*/
1202 ELM_GENLIST_ITEM_NONE, /*flags*/
1203 __viewer_list_item_clicked_cb,/*func*/
1208 assertm_if(NULL == ret, "NULL!!");
1211 /* SECURE_DEBUG_LOG(UG_NAME_NORMAL,
1212 "* item add complete item [%p] ssid:[%s] security[%d] size:[%d]",
1215 wifi_device->security_mode,
1216 viewer_list_item_size_get()); */
1218 if (after == grouptitle) {
1229 elm_genlist_item_update(ret);
1235 void viewer_list_item_del(Elm_Object_Item *it)
1240 if (it == first_item)
1241 first_item = elm_genlist_item_next_get(first_item);
1242 else if (it == last_item)
1243 last_item = elm_genlist_item_prev_get(last_item);
1244 elm_object_item_del(it);
1247 int viewer_list_item_size_get()
1250 Elm_Object_Item *it = first_item;
1254 if (it == last_item)
1256 it = elm_genlist_item_next_get(it);
1262 void viewer_list_item_clear(void)
1264 __COMMON_FUNC_ENTER__;
1266 Elm_Object_Item *it = first_item;
1267 Elm_Object_Item *nxt = NULL;
1270 nxt = elm_genlist_item_next_get(it);
1271 elm_object_item_del(it);
1272 if (it == last_item)
1277 first_item = last_item = NULL;
1279 __COMMON_FUNC_EXIT__;
1282 void viewer_list_item_enable_all(void)
1284 __COMMON_FUNC_ENTER__;
1286 Elm_Object_Item *it = first_item;
1289 elm_object_item_disabled_set(it, EINA_FALSE);
1291 if (it == last_item)
1294 it = elm_genlist_item_next_get(it);
1297 __COMMON_FUNC_EXIT__;
1300 void viewer_list_item_disable_all(void)
1302 __COMMON_FUNC_ENTER__;
1304 Elm_Object_Item *it = first_item;
1307 elm_object_item_disabled_set(it, EINA_TRUE);
1309 if (it == last_item)
1312 it = elm_genlist_item_next_get(it);
1315 __COMMON_FUNC_EXIT__;
1318 Elm_Object_Item* item_get_for_ap(wifi_manager_ap_h ap)
1320 __COMMON_FUNC_ENTER__;
1322 __COMMON_FUNC_EXIT__;
1327 wifi_manager_security_type_e sec_type = WIFI_MANAGER_SECURITY_TYPE_NONE;
1329 if (WIFI_MANAGER_ERROR_NONE != wifi_manager_ap_get_essid(ap, &essid)) {
1330 __COMMON_FUNC_EXIT__;
1332 } else if (WIFI_MANAGER_ERROR_NONE != wifi_manager_ap_get_security_type(ap, &sec_type)) {
1334 __COMMON_FUNC_EXIT__;
1338 Elm_Object_Item *it = first_item;
1340 ug_genlist_data_t* gdata = elm_object_item_data_get(it);
1341 wifi_device_info_t *device_info = NULL;
1342 if (gdata && (device_info = gdata->device_info)) {
1343 if (!g_strcmp0(device_info->ssid, essid) && device_info->security_mode == sec_type)
1346 if (it == last_item) {
1350 it = elm_genlist_item_next_get(it);
1354 __COMMON_FUNC_EXIT__;
1358 Elm_Object_Item* item_get_for_ssid(const char *ssid)
1360 Elm_Object_Item *it = first_item;
1362 ug_genlist_data_t* gdata = elm_object_item_data_get(it);
1363 wifi_device_info_t *device_info = NULL;
1364 if (gdata && (device_info = gdata->device_info)) {
1365 if (!g_strcmp0(device_info->ssid, ssid))
1368 if (it == last_item) {
1372 it = elm_genlist_item_next_get(it);
1378 static void _hidden_network_cb(void* data, Evas_Object* obj, void* event_info)
1380 __COMMON_FUNC_ENTER__;
1382 view_hidden_ap_popup_create(ug_app_state->parent_layout, PACKAGE);
1384 __COMMON_FUNC_EXIT__;
1387 void viewer_list_item_hidden_network_set(Elm_Object_Item *item)
1392 last_item = elm_genlist_item_append(viewer_list,
1393 last_item_itc, NULL, item,
1394 ELM_GENLIST_ITEM_NONE, _hidden_network_cb, NULL);
1396 elm_genlist_item_select_mode_set(last_item,
1397 ELM_OBJECT_SELECT_MODE_ALWAYS);
1399 elm_genlist_item_update(last_item);