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.ok_cb = __passwd_popup_ok_cb;
636 popup_info.cancel_cb = __passwd_popup_cancel_cb;
637 popup_info.show_wps_btn = device_info->wps_mode;
638 popup_info.wps_btn_cb = __wps_options_popup_cb;
639 popup_info.ap = device_info->ap;
640 popup_info.cb_data = device_info_temp;
641 popup_info.sec_type = sec_type;
643 /* TODO: parameter with device_info */
644 /* TODO: finally parameter with wifi_manager_ap_h, WPA, EAP */
645 ug_app_state->passpopup = create_passwd_popup(
646 ug_app_state->conformant,
647 ug_app_state->parent_layout, PACKAGE, &popup_info);
649 if (ug_app_state->passpopup == NULL)
650 INFO_LOG(UG_NAME_ERR, "Fail to create password popup");
653 case WIFI_MANAGER_SECURITY_TYPE_EAP:
654 ug_app_state->eap_view = create_eap_view(
655 ug_app_state->parent_layout, ugd->win_main,
656 ug_app_state->conformant,
657 PACKAGE, device_info,
658 viewer_manager_eap_view_deref);
661 ERROR_LOG(UG_NAME_NORMAL, "Unknown security type [%d]", sec_type);
667 void viewer_list_wifi_connect(wifi_device_info_t *device_info)
669 bool favorite = false;
670 pswd_popup_create_req_data_t popup_info;
671 wifi_manager_security_type_e sec_type = WIFI_MANAGER_SECURITY_TYPE_NONE;
672 wifi_device_info_t *dev_info_temp = NULL;
673 struct ug_data *ugd = (struct ug_data *)ug_app_state->gadget;
675 if (device_info == NULL)
678 wifi_manager_ap_is_favorite(device_info->ap, &favorite);
679 if (favorite == true) {
680 wlan_manager_connect(device_info->ap);
684 if (ug_app_state->passpopup != NULL || ug_app_state->eap_view != NULL) {
685 INFO_LOG(UG_NAME_ERR, "already launched popup");
689 wifi_manager_ap_get_security_type(device_info->ap, &sec_type);
692 case WIFI_MANAGER_SECURITY_TYPE_NONE:
693 if (ug_app_state->is_hidden) {
694 wifi_manager_ap_h ap;
696 wifi_manager_ap_get_essid(device_info->ap, &ssid);
697 wlan_manager_ap_hidden_create(ssid, &ap);
699 wifi_manager_ap_set_security_type(ap, WIFI_MANAGER_SECURITY_TYPE_NONE);
700 wlan_manager_connect(ap);
702 wlan_manager_connect(device_info->ap);
705 case WIFI_MANAGER_SECURITY_TYPE_WEP:
706 case WIFI_MANAGER_SECURITY_TYPE_WPA_PSK:
707 case WIFI_MANAGER_SECURITY_TYPE_WPA2_PSK:
708 memset(&popup_info, 0, sizeof(pswd_popup_create_req_data_t));
710 dev_info_temp = view_list_item_device_info_create(device_info->ap);
712 popup_info.title = device_info->ssid;
713 popup_info.ok_cb = __passwd_popup_ok_cb;
714 popup_info.cancel_cb = __passwd_popup_cancel_cb;
715 popup_info.show_wps_btn = device_info->wps_mode;
716 popup_info.wps_btn_cb = __wps_options_popup_cb;
717 popup_info.ap = device_info->ap;
718 popup_info.cb_data = dev_info_temp;
719 popup_info.sec_type = sec_type;
721 /* TODO: parameter with device_info */
722 /* TODO: finally parameter with wifi_manager_ap_h, WPA, EAP */
723 ug_app_state->passpopup = create_passwd_popup(
724 ug_app_state->conformant,
725 ug_app_state->parent_layout, PACKAGE, &popup_info);
727 if (ug_app_state->passpopup == NULL)
728 INFO_LOG(UG_NAME_ERR, "Fail to create password popup");
732 case WIFI_MANAGER_SECURITY_TYPE_EAP:
733 ug_app_state->eap_view = create_eap_view(
734 ug_app_state->parent_layout, ugd->win_main,
735 ug_app_state->conformant,
736 PACKAGE, device_info,
737 viewer_manager_eap_view_deref);
741 ERROR_LOG(UG_NAME_NORMAL, "Unknown security type[%d]", sec_type);
746 void viewer_list_clear_disconnect_popup(wifi_manager_ap_h ap)
748 if (!g_disconnect_popup)
751 if (ap && g_disconnect_popup->ap &&
752 wlan_manager_is_same_network(g_disconnect_popup->ap, ap) != TRUE)
755 if (g_disconnect_popup->popup)
756 evas_object_del(g_disconnect_popup->popup);
758 if (g_disconnect_popup->ap)
759 wifi_manager_ap_destroy(g_disconnect_popup->ap);
761 g_free(g_disconnect_popup);
762 g_disconnect_popup = NULL;
765 static void __viewer_list_disconnect_cancel_cb(void *data,
766 Evas_Object *obj, void *event_info)
768 struct connecting_cancel_popup_data *popup =
769 (struct connecting_cancel_popup_data *)data;
774 evas_object_del(popup->popup);
777 wifi_manager_ap_destroy(popup->ap);
780 g_disconnect_popup = NULL;
783 static gboolean __viewer_list_update_ap(gpointer data)
785 wifi_manager_ap_h ap = (wifi_manager_ap_h)data;
787 viewer_manager_update_item_favorite_status(ap);
788 wifi_manager_ap_destroy(ap);
793 static void __viewer_list_disconnect_ok_cb(void *data,
794 Evas_Object *obj, void *event_info)
797 struct connecting_cancel_popup_data *popup =
798 (struct connecting_cancel_popup_data *)data;
802 wlan_manager_disconnect(popup->ap);
803 wlan_manager_forget(popup->ap);
806 evas_object_del(popup->popup);
808 id = common_util_managed_idle_add(__viewer_list_update_ap, (gpointer)popup->ap);
810 viewer_manager_update_item_favorite_status(popup->ap);
811 wifi_manager_ap_destroy(popup->ap);
815 g_disconnect_popup = NULL;
818 static void __viewer_list_disconnect_popup(wifi_device_info_t *device_info,
819 Evas_Object *win_main)
821 popup_btn_info_t popup_data;
822 struct connecting_cancel_popup_data *popup = NULL;
824 memset(&popup_data, 0, sizeof(popup_data));
826 popup = g_try_new0(struct connecting_cancel_popup_data, 1);
830 g_disconnect_popup = popup;
831 wifi_manager_ap_clone(&popup->ap, device_info->ap);
833 popup_data.title_txt = "IDS_WIFI_OPT_FORGET_NETWORK";
834 popup_data.info_txt = "IDS_WIFI_POP_CURRENT_NETWORK_WILL_BE_DISCONNECTED";
835 popup_data.btn1_cb = __viewer_list_disconnect_cancel_cb;
836 popup_data.btn1_txt = "IDS_WIFI_SK_CANCEL";
837 popup_data.btn1_data = popup;
838 popup_data.btn2_cb = __viewer_list_disconnect_ok_cb;
839 popup_data.btn2_txt = "IDS_WIFI_SK_FORGET";
840 popup_data.btn2_data = popup;
842 popup->popup = common_utils_show_info_popup(win_main, &popup_data);
845 static void __viewer_list_item_clicked_cb(void *data, Evas_Object *obj,
848 __COMMON_FUNC_ENTER__;
850 assertm_if(NULL == event_info, "event_info is NULL!!");
851 assertm_if(NULL == obj, "obj is NULL!!");
853 Elm_Object_Item *it = (Elm_Object_Item *)event_info;
854 ug_genlist_data_t *gdata = NULL;
855 wifi_device_info_t *device_info = NULL;
857 gdata = (ug_genlist_data_t *)elm_object_item_data_get(it);
858 retm_if(NULL == gdata);
860 device_info = gdata->device_info;
861 retm_if(NULL == device_info || NULL == device_info->ssid);
863 int item_state = gdata->radio_mode;
864 int current_state = 0;
866 SECURE_INFO_LOG(UG_NAME_NORMAL, "ssid --- %s", device_info->ssid);
867 INFO_LOG(UG_NAME_NORMAL, "ap --- %p", device_info->ap);
868 INFO_LOG(UG_NAME_NORMAL, "current item_state state is --- %d", item_state);
870 if (ug_app_state->is_lbhome == EINA_TRUE &&
871 ug_app_state->app_control != NULL) {
872 INFO_LOG(UG_NAME_NORMAL, "exit with reply");
876 app_control_create(&reply);
877 wifi_manager_ap_get_bssid(device_info->ap, &bssid);
878 SECURE_INFO_LOG(UG_NAME_NORMAL, "bssid %s, ssid %s", bssid, device_info->ssid);
880 app_control_add_extra_data(reply, "bssid", bssid);
881 app_control_add_extra_data(reply, "ssid", device_info->ssid);
882 app_control_reply_to_launch_request(reply, ug_app_state->app_control,
883 APP_CONTROL_RESULT_SUCCEEDED);
884 app_control_destroy(reply);
890 switch (item_state) {
891 case VIEWER_ITEM_RADIO_MODE_OFF:
892 current_state = viewer_manager_header_mode_get();
894 INFO_LOG(UG_NAME_NORMAL, "Clicked AP information\n");
895 INFO_LOG(UG_NAME_NORMAL, "header mode [%d]", current_state);
897 switch (current_state) {
899 case HEADER_MODE_CONNECTED:
900 case HEADER_MODE_CONNECTING:
901 case HEADER_MODE_SEARCHING:
902 viewer_list_wifi_connect(device_info);
905 case HEADER_MODE_OFF:
906 case HEADER_MODE_ACTIVATING:
907 case HEADER_MODE_DEACTIVATING:
909 INFO_LOG(UG_NAME_NORMAL, "Ignore click");
914 case VIEWER_ITEM_RADIO_MODE_CONNECTING:
915 case VIEWER_ITEM_RADIO_MODE_CONFIGURATION:
916 __viewer_list_disconnect_popup(device_info, ug_app_state->layout_main);
918 case VIEWER_ITEM_RADIO_MODE_CONNECTED:
920 INFO_LOG(UG_NAME_NORMAL, "Ignore click");
924 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
926 __COMMON_FUNC_EXIT__;
929 static char *viewer_list_get_device_status_txt(wifi_device_info_t *wifi_device,
930 VIEWER_ITEM_RADIO_MODES mode)
932 char *status_txt = NULL;
933 int current_state = 0;
935 current_state = viewer_manager_header_mode_get();
936 /* The strings are currently hard coded. It will be replaced with string ids later */
937 if (VIEWER_ITEM_RADIO_MODE_CONNECTING == mode) {
938 status_txt = g_strdup(sc(PACKAGE, I18N_TYPE_Connecting));
939 } else if (VIEWER_ITEM_RADIO_MODE_CONFIGURATION == mode) {
940 status_txt = g_strdup(sc(PACKAGE, I18N_TYPE_Obtaining_IP_addr));
941 } else if (VIEWER_ITEM_RADIO_MODE_CONNECTED == mode) {
942 if (connection_manager_is_wifi_connection_used() ||
943 current_state == HEADER_MODE_CONNECTED) {
944 status_txt = g_strdup(sc(PACKAGE, I18N_TYPE_Connected));
946 } else if (VIEWER_ITEM_RADIO_MODE_OFF == mode) {
947 status_txt = common_utils_get_ap_security_type_info_txt(PACKAGE,
950 status_txt = g_strdup(sc(PACKAGE, I18N_TYPE_Unknown));
951 INFO_LOG(UG_NAME_NORMAL, "Invalid mode: %d", mode);
957 Evas_Object* viewer_list_create(Evas_Object *win)
959 __COMMON_FUNC_ENTER__;
961 assertm_if(NULL == win, "NULL!!");
962 assertm_if(NULL != viewer_list, "Err!!");
964 viewer_list = elm_genlist_add(win);
965 assertm_if(NULL == viewer_list, "NULL!!");
967 if (wifi_get_ug_type() == UG_VIEW_OOBE) {
968 elm_object_style_set(viewer_list, "solid/default");
969 elm_object_color_class_color_set(viewer_list, "bg", 255, 255, 255, 255);
972 // To use multiline textblock/entry/editfield in genlist, set height_for_width mode
973 // then the item's height is calculated while the item's width fits to genlist width.
974 elm_genlist_mode_set(viewer_list, ELM_LIST_COMPRESS);
975 //elm_genlist_realization_mode_set(viewer_list, EINA_TRUE);
977 evas_object_size_hint_weight_set(viewer_list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
978 evas_object_size_hint_align_set(viewer_list, EVAS_HINT_FILL, EVAS_HINT_FILL);
980 itc = elm_genlist_item_class_new();
981 itc->item_style = WIFI_GENLIST_2LINE_TOP_TEXT_ICON_STYLE;
982 itc->func.text_get = _gl_listview_text_get;
983 itc->func.content_get = _gl_listview_content_get;
984 itc->func.state_get = NULL;
985 itc->func.del = _gl_listview_del;
987 no_wifi_device_itc = elm_genlist_item_class_new();
988 no_wifi_device_itc->item_style = WIFI_GENLIST_1LINE_TEXT_STYLE;
989 no_wifi_device_itc->func.text_get = _gl_listview_text_get;
990 no_wifi_device_itc->func.content_get = NULL;
991 no_wifi_device_itc->func.state_get = NULL;
992 no_wifi_device_itc->func.del = _gl_listview_del;
994 if (wifi_get_ug_type() == UG_VIEW_OOBE) {
995 last_item_itc = elm_genlist_item_class_new();
996 last_item_itc->item_style = WIFI_GENLIST_1LINE_TEXT_ICON_STYLE;
997 last_item_itc->func.text_get = _gl_hidden_network_text_get;
998 last_item_itc->func.content_get = _gl_hidden_network_content_get;
999 last_item_itc->func.del = NULL;
1002 first_item = last_item = NULL;
1004 evas_object_smart_callback_add(viewer_list, "realized",
1005 _gl_realized, NULL);
1006 evas_object_smart_callback_add(viewer_list, "language,changed",
1007 gl_lang_changed, NULL);
1009 __COMMON_FUNC_EXIT__;
1013 void viewer_list_title_item_del(void)
1015 if (grouptitle != NULL) {
1016 elm_object_item_del(grouptitle);
1021 void viewer_list_title_item_update(void)
1023 if (grouptitle != NULL)
1024 elm_genlist_item_update(grouptitle);
1027 void viewer_list_title_item_set(Elm_Object_Item *item_header)
1029 if (item_header == NULL)
1032 if (grouptitle != NULL) {
1033 elm_genlist_item_update(grouptitle);
1037 //memset(&grouptitle_itc, 0, sizeof(grouptitle_itc));
1038 grouptitle_itc = elm_genlist_item_class_new();
1039 if (wifi_get_ug_type() == UG_VIEW_OOBE) {
1040 grouptitle_itc->item_style = WIFI_GENLIST_FULL_STYLE;
1041 grouptitle_itc->func.text_get = NULL;
1042 grouptitle_itc->func.content_get = NULL;
1044 grouptitle_itc->item_style = WIFI_GENLIST_GROUP_INDEX_STYLE;
1045 grouptitle_itc->func.text_get = _gl_text_available_networks_get;
1046 grouptitle_itc->func.content_get = _gl_content_scanning_icon_get;
1049 grouptitle = elm_genlist_item_insert_after(viewer_list,
1050 grouptitle_itc, NULL, NULL, item_header,
1051 ELM_GENLIST_ITEM_NONE, NULL, NULL);
1053 assertm_if(NULL == grouptitle, "NULL!!");
1055 elm_genlist_item_select_mode_set(grouptitle,
1056 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1059 int viewer_list_item_radio_mode_set(Elm_Object_Item* item,
1060 VIEWER_ITEM_RADIO_MODES mode)
1062 __COMMON_FUNC_ENTER__;
1065 INFO_LOG(COMMON_NAME_ERR, "item is NULL");
1069 ug_genlist_data_t* gdata = (ug_genlist_data_t *) elm_object_item_data_get(item);
1070 if (NULL == gdata || NULL == gdata->device_info) {
1071 INFO_LOG(COMMON_NAME_ERR, "gdata or device_info is NULL");
1075 if (gdata->radio_mode == mode) {
1076 SECURE_INFO_LOG(UG_NAME_NORMAL, "[%s] is already in requested state", gdata->device_info->ssid);
1080 SECURE_INFO_LOG(UG_NAME_NORMAL, "[%s] AP Item State Transition from [%d] --> [%d]", gdata->device_info->ssid, gdata->radio_mode, mode);
1081 gdata->radio_mode = mode;
1082 if (gdata->device_info->ap_status_txt) {
1083 g_free(gdata->device_info->ap_status_txt);
1084 gdata->device_info->ap_status_txt = viewer_list_get_device_status_txt(gdata->device_info, mode);
1088 elm_genlist_item_update(item);
1090 __COMMON_FUNC_EXIT__;
1094 static wifi_manager_connection_state_e _convert_wifi_state_to_viewer_radio_mode(
1095 wifi_manager_connection_state_e state)
1098 case WIFI_MANAGER_CONNECTION_STATE_ASSOCIATION:
1099 return VIEWER_ITEM_RADIO_MODE_CONNECTING;
1100 case WIFI_MANAGER_CONNECTION_STATE_CONFIGURATION:
1101 return VIEWER_ITEM_RADIO_MODE_CONFIGURATION;
1102 case WIFI_MANAGER_CONNECTION_STATE_CONNECTED:
1103 return VIEWER_ITEM_RADIO_MODE_CONNECTED;
1105 return VIEWER_ITEM_RADIO_MODE_OFF;
1109 Elm_Object_Item *viewer_list_item_insert_after(wifi_device_info_t *wifi_device,
1110 Elm_Object_Item *after)
1112 Elm_Object_Item* ret = NULL;
1113 ug_genlist_data_t* gdata = NULL;
1114 wifi_device_info_t *no_wifi_device = NULL;
1115 retvm_if(NULL == viewer_list, NULL);
1117 if (_is_emulator()) {
1118 if (wifi_device != NULL) {
1119 wifi_device->ap_status_txt = viewer_list_get_device_status_txt(
1121 VIEWER_ITEM_RADIO_MODE_OFF);
1123 no_wifi_device = g_try_new0(wifi_device_info_t, 1);
1124 if (no_wifi_device == NULL)
1127 no_wifi_device->ssid = g_strdup(sc(PACKAGE, I18N_TYPE_No_Wi_Fi_AP_Found));
1128 wifi_device = no_wifi_device;
1131 wifi_manager_connection_state_e state = WIFI_MANAGER_CONNECTION_STATE_DISCONNECTED;
1132 VIEWER_ITEM_RADIO_MODES rad_mode = VIEWER_ITEM_RADIO_MODE_OFF;
1133 if (wifi_device != NULL && wifi_device->ap != NULL) {
1134 if (wifi_manager_ap_get_connection_state(wifi_device->ap, &state) ==
1135 WIFI_MANAGER_ERROR_NONE) {
1136 rad_mode = _convert_wifi_state_to_viewer_radio_mode(state);
1138 wifi_device->ap_status_txt = viewer_list_get_device_status_txt(
1142 if (ug_app_state->is_first_scan == true) {
1143 int scan_result = wlan_manager_scan();
1144 if (scan_result != WLAN_MANAGER_ERR_NONE) {
1145 viewer_manager_hide(VIEWER_WINSET_SEARCHING);
1146 viewer_manager_header_mode_set(viewer_manager_header_mode_get());
1148 ug_app_state->is_first_scan = false;
1151 no_wifi_device = g_try_new0(wifi_device_info_t, 1);
1152 if (no_wifi_device == NULL)
1155 no_wifi_device->ssid = g_strdup(sc(PACKAGE, I18N_TYPE_No_Wi_Fi_AP_Found));
1156 wifi_device = no_wifi_device;
1160 gdata = g_try_new0(ug_genlist_data_t, 1);
1161 if (gdata == NULL) {
1162 if (no_wifi_device) {
1163 g_free(no_wifi_device->ssid);
1164 g_free(no_wifi_device);
1169 gdata->device_info = wifi_device;
1170 gdata->radio_mode = VIEWER_ITEM_RADIO_MODE_OFF;
1173 /* If the after item is NULL then insert it as first item */
1177 if (no_wifi_device == NULL) {
1178 ret = elm_genlist_item_insert_after(
1179 viewer_list, /*obj*/
1183 after, /*after than*/
1184 ELM_GENLIST_ITEM_NONE, /*flags*/
1185 __viewer_list_item_clicked_cb,/*func*/
1188 ret = elm_genlist_item_insert_after(
1189 viewer_list, /*obj*/
1190 no_wifi_device_itc,/*itc*/
1193 after, /*after than*/
1194 ELM_GENLIST_ITEM_NONE, /*flags*/
1195 __viewer_list_item_clicked_cb,/*func*/
1200 assertm_if(NULL == ret, "NULL!!");
1203 /* SECURE_DEBUG_LOG(UG_NAME_NORMAL,
1204 "* item add complete item [%p] ssid:[%s] security[%d] size:[%d]",
1207 wifi_device->security_mode,
1208 viewer_list_item_size_get()); */
1210 if (after == grouptitle) {
1221 elm_genlist_item_update(ret);
1227 void viewer_list_item_del(Elm_Object_Item *it)
1232 if (it == first_item)
1233 first_item = elm_genlist_item_next_get(first_item);
1234 else if (it == last_item)
1235 last_item = elm_genlist_item_prev_get(last_item);
1236 elm_object_item_del(it);
1239 int viewer_list_item_size_get()
1242 Elm_Object_Item *it = first_item;
1246 if (it == last_item)
1248 it = elm_genlist_item_next_get(it);
1254 void viewer_list_item_clear(void)
1256 __COMMON_FUNC_ENTER__;
1258 Elm_Object_Item *it = first_item;
1259 Elm_Object_Item *nxt = NULL;
1262 nxt = elm_genlist_item_next_get(it);
1263 elm_object_item_del(it);
1264 if (it == last_item)
1269 first_item = last_item = NULL;
1271 __COMMON_FUNC_EXIT__;
1274 void viewer_list_item_enable_all(void)
1276 __COMMON_FUNC_ENTER__;
1278 Elm_Object_Item *it = first_item;
1281 elm_object_item_disabled_set(it, EINA_FALSE);
1283 if (it == last_item)
1286 it = elm_genlist_item_next_get(it);
1289 __COMMON_FUNC_EXIT__;
1292 void viewer_list_item_disable_all(void)
1294 __COMMON_FUNC_ENTER__;
1296 Elm_Object_Item *it = first_item;
1299 elm_object_item_disabled_set(it, EINA_TRUE);
1301 if (it == last_item)
1304 it = elm_genlist_item_next_get(it);
1307 __COMMON_FUNC_EXIT__;
1310 Elm_Object_Item* item_get_for_ap(wifi_manager_ap_h ap)
1312 __COMMON_FUNC_ENTER__;
1314 __COMMON_FUNC_EXIT__;
1319 wifi_manager_security_type_e sec_type = WIFI_MANAGER_SECURITY_TYPE_NONE;
1321 if (WIFI_MANAGER_ERROR_NONE != wifi_manager_ap_get_essid(ap, &essid)) {
1322 __COMMON_FUNC_EXIT__;
1324 } else if (WIFI_MANAGER_ERROR_NONE != wifi_manager_ap_get_security_type(ap, &sec_type)) {
1326 __COMMON_FUNC_EXIT__;
1330 Elm_Object_Item *it = first_item;
1332 ug_genlist_data_t* gdata = elm_object_item_data_get(it);
1333 wifi_device_info_t *device_info = NULL;
1334 if (gdata && (device_info = gdata->device_info)) {
1335 if (!g_strcmp0(device_info->ssid, essid) && device_info->security_mode == sec_type)
1338 if (it == last_item) {
1342 it = elm_genlist_item_next_get(it);
1346 __COMMON_FUNC_EXIT__;
1350 Elm_Object_Item* item_get_for_ssid(const char *ssid)
1352 Elm_Object_Item *it = first_item;
1354 ug_genlist_data_t* gdata = elm_object_item_data_get(it);
1355 wifi_device_info_t *device_info = NULL;
1356 if (gdata && (device_info = gdata->device_info)) {
1357 if (!g_strcmp0(device_info->ssid, ssid))
1360 if (it == last_item) {
1364 it = elm_genlist_item_next_get(it);
1370 static void _hidden_network_cb(void* data, Evas_Object* obj, void* event_info)
1372 __COMMON_FUNC_ENTER__;
1374 view_hidden_ap_popup_create(ug_app_state->parent_layout, PACKAGE);
1376 __COMMON_FUNC_EXIT__;
1379 void viewer_list_item_hidden_network_set(Elm_Object_Item *item)
1384 last_item = elm_genlist_item_append(viewer_list,
1385 last_item_itc, NULL, item,
1386 ELM_GENLIST_ITEM_NONE, _hidden_network_cb, NULL);
1388 elm_genlist_item_select_mode_set(last_item,
1389 ELM_OBJECT_SELECT_MODE_ALWAYS);
1391 elm_genlist_item_update(last_item);