4 * Copyright 2012 Samsung Electronics Co., Ltd
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
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_Object_Item* grouptitle = NULL;
43 extern wifi_appdata *ug_app_state;
45 struct connecting_cancel_popup_data {
50 static struct connecting_cancel_popup_data *g_disconnect_popup = NULL;
52 static void _gl_listview_more_btn_cb(void *data, Evas_Object *obj, void *event_info)
54 __COMMON_FUNC_ENTER__;
56 elm_object_disabled_set(obj, EINA_TRUE);
58 wifi_device_info_t *device_info = (wifi_device_info_t *)data;
65 SECURE_DEBUG_LOG(UG_NAME_NORMAL, "ssid [%s]", device_info->ssid);
67 view_detail(device_info, ug_app_state->layout_main, obj);
72 char* ConvertRGBAtoHex(int r, int g, int b, int a)
77 string = g_try_malloc0(sizeof(char )* 255);
79 hexcolor = (r << 24) + (g << 16) + (b << 8) + a;
80 sprintf(string, "%08x", hexcolor);
86 static char* _gl_listview_text_get(void *data, Evas_Object *obj, const char *part)
91 ug_genlist_data_t* gdata = (ug_genlist_data_t*) data;
92 retvm_if(NULL == gdata || NULL == gdata->device_info, NULL);
94 assertm_if(NULL == gdata->device_info->ssid, "NULL!!");
96 if (!strcmp("elm.text", part)) {
97 det = evas_textblock_text_utf8_to_markup(NULL,
98 gdata->device_info->ssid);
99 assertm_if(NULL == det, "NULL!!");
100 if (VIEWER_ITEM_RADIO_MODE_CONNECTED == gdata->radio_mode) {
101 buf = g_strdup_printf("<color=#%s>%s</color>",
102 ConvertRGBAtoHex(2, 61, 132, 255), det);
107 } else if (!strcmp("elm.text.sub", part)
108 && gdata->device_info->ap_status_txt != NULL) {
109 det = g_strdup(gdata->device_info->ap_status_txt);
111 assertm_if(NULL == det, "NULL!!");
116 static Evas_Object *_gl_listview_content_get(void *data, Evas_Object *obj, const char *part)
118 ug_genlist_data_t *gdata = (ug_genlist_data_t *)data;
119 retvm_if(NULL == gdata, NULL);
121 Evas_Object *icon = NULL;
122 Evas_Object *btn = NULL;
124 if (gdata->device_info->ap_image_path == NULL) {
125 /* if there is no ap_image_path (NO AP Found situation) */
126 DEBUG_LOG(UG_NAME_ERR, "Fatal: Image path is NULL");
128 } else if (!strcmp("elm.swallow.icon", part)) {
129 icon = elm_image_add(obj);
130 retvm_if(NULL == icon, NULL);
133 char *temp_str = NULL;
134 temp_str = g_strdup_printf("%s.png", gdata->device_info->ap_image_path);
135 elm_image_file_set(icon, CUSTOM_EDITFIELD_PATH, temp_str);
138 evas_object_color_set(icon, 2, 61, 132, 204);
139 evas_object_size_hint_min_set(icon, ELM_SCALE_SIZE(DEFAULT_BUTTON_CIRCLE_SIZE), ELM_SCALE_SIZE(DEFAULT_BUTTON_CIRCLE_SIZE));
141 } else if (!strcmp("elm.swallow.end", part)) {
142 if (VIEWER_ITEM_RADIO_MODE_CONNECTING == gdata->radio_mode ||
143 VIEWER_ITEM_RADIO_MODE_CONFIGURATION == gdata->radio_mode) {
145 icon = elm_progressbar_add(obj);
147 elm_object_style_set(icon, "process_medium");
148 evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, 0.5);
149 evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
150 elm_progressbar_pulse(icon, TRUE);
151 evas_object_propagate_events_set(icon, EINA_FALSE);
154 btn = elm_button_add(obj);
155 elm_object_style_set(btn, "circle_custom");
156 icon = elm_image_add(btn);
157 elm_image_file_set(icon, CUSTOM_EDITFIELD_PATH, "wifi_icon_badge_info.png");
158 elm_image_resizable_set(icon, EINA_TRUE, EINA_TRUE);
159 elm_object_part_content_set(btn, "elm.swallow.content", icon);
160 evas_object_propagate_events_set(btn, EINA_FALSE);
161 evas_object_smart_callback_add(btn, "clicked", _gl_listview_more_btn_cb,gdata->device_info);
162 evas_object_show(btn);
170 static void _gl_listview_del(void *data, Evas_Object *obj)
175 ug_genlist_data_t *gdata = (ug_genlist_data_t *)data;
176 retm_if(NULL == gdata || NULL == gdata->device_info);
178 g_free(gdata->device_info->ap_image_path);
179 g_free(gdata->device_info->ap_status_txt);
180 g_free(gdata->device_info->ssid);
181 wifi_ap_destroy(gdata->device_info->ap);
182 g_free(gdata->device_info);
186 static char *_gl_text_available_networks_get(void *data, Evas_Object *obj,
189 if (!strcmp("elm.text", part))
190 return g_strdup(sc(PACKAGE, I18N_TYPE_Available_networks));
195 static Evas_Object *_gl_content_scanning_icon_get(void *data, Evas_Object *obj,
198 Evas_Object *title_progressbar = NULL;
200 if (HEADER_MODE_SEARCHING == viewer_manager_header_mode_get()) {
201 title_progressbar = elm_progressbar_add(obj);
202 elm_object_style_set(title_progressbar, "process_small");
203 elm_progressbar_horizontal_set(title_progressbar, EINA_TRUE);
204 elm_progressbar_pulse(title_progressbar, EINA_TRUE);
207 return title_progressbar;
210 Elm_Object_Item* viewer_list_get_first_item(void)
215 Elm_Object_Item* viewer_list_get_last_item(void)
220 #ifdef ACCESSIBLITY_FEATURE
221 static char *_access_info_cb(void *data, Evas_Object *obj)
223 char *strength = NULL;
226 ug_genlist_data_t *gdata = (ug_genlist_data_t *)data;
231 strength = common_utils_get_rssi_text(PACKAGE, gdata->device_info->rssi);
232 buf = g_strdup_printf("%s. %s. %s.", strength, gdata->device_info->ssid, gdata->device_info->ap_status_txt);
239 static void gl_lang_changed(void *data, Evas_Object *obj, void *event_info)
241 elm_genlist_realized_items_update(obj);
244 static void _gl_realized(void *data, Evas_Object *obj, void *event_info)
246 #ifdef ACCESSIBLITY_FEATURE
247 HEADER_MODES header_mode = viewer_manager_header_mode_get();
248 Elm_Object_Item *item = (Elm_Object_Item *)event_info;
250 if (header_mode == HEADER_MODE_ACTIVATING ||
251 header_mode == HEADER_MODE_DEACTIVATING ||
252 header_mode == HEADER_MODE_OFF) {
256 Elm_Object_Item *first_item = viewer_list_get_first_item();
257 Elm_Object_Item *last_item = viewer_list_get_last_item();
259 if (first_item == NULL || last_item == NULL) {
263 int index = (int)elm_genlist_item_index_get(item);
264 int first_item_index = (int)elm_genlist_item_index_get(first_item);
265 int last_item_index = (int)elm_genlist_item_index_get(last_item);
268 if (first_item_index == -1) {
269 int group_index = (int)elm_genlist_item_index_get(grouptitle);
270 first_item_index = group_index + 1;
273 if (index >= first_item_index && index <= last_item_index &&
274 first_item_index < last_item_index) {
276 Evas_Object *ao = elm_object_item_access_object_get(item);
277 elm_access_info_cb_set(ao, ELM_ACCESS_INFO, _access_info_cb, elm_object_item_data_get(item));
278 g_snprintf(buf, sizeof(buf), "%s%s",
279 sc(PACKAGE, I18N_TYPE_Double_tap),
280 sc(PACKAGE, I18N_TYPE_Connect_to_device));
281 elm_access_info_set(ao, ELM_ACCESS_TYPE, buf);
282 elm_access_info_set(ao, ELM_ACCESS_STATE, sc(PACKAGE, I18N_TYPE_Wi_Fi_network_info));
285 if (ug_app_state->ug_type == UG_VIEW_SETUP_WIZARD &&
286 first_item_index == index) {
287 viewer_manager_setup_wizard_btns_color_set(TRUE);
290 Elm_Object_Item *item = (Elm_Object_Item *)event_info;
291 Elm_Object_Item *first_item = viewer_list_get_first_item();
293 if (first_item == NULL) {
297 int index = (int)elm_genlist_item_index_get(item);
298 int first_item_index = (int)elm_genlist_item_index_get(first_item);
300 if (first_item_index == -1) {
301 int group_index = (int)elm_genlist_item_index_get(grouptitle);
302 first_item_index = group_index + 1;
305 if (ug_app_state->ug_type == UG_VIEW_SETUP_WIZARD &&
306 first_item_index == index) {
307 viewer_manager_setup_wizard_btns_color_set(TRUE);
312 static void _info_popup_ok_cb(void *data, Evas_Object *obj, void *event_info)
314 pswd_popup_t *passpopup = (pswd_popup_t *)data;
316 if (passpopup != NULL && passpopup->info_popup != NULL) {
317 evas_object_del(passpopup->info_popup);
318 passpopup->info_popup = NULL;
322 static void __passwd_popup_cancel_cb(void *data, Evas_Object *obj,
325 __COMMON_FUNC_ENTER__;
327 if (ug_app_state->passpopup == NULL) {
331 passwd_popup_free(ug_app_state->passpopup);
332 ug_app_state->passpopup = NULL;
338 __COMMON_FUNC_EXIT__;
341 static void __passwd_popup_ok_cb(void *data, Evas_Object *obj, void *event_info)
343 __COMMON_FUNC_ENTER__;
346 int password_len = 0;
347 const char *password = NULL;
348 wifi_security_type_e sec_type = WIFI_SECURITY_TYPE_NONE;
350 if (ug_app_state->passpopup == NULL) {
354 ap = passwd_popup_get_ap(ug_app_state->passpopup);
355 password = passwd_popup_get_txt(ug_app_state->passpopup);
356 if (password != NULL)
357 password_len = strlen(password);
359 wifi_ap_get_security_type(ap, &sec_type);
362 case WIFI_SECURITY_TYPE_WEP:
363 if (password_len != 5 && password_len != 13 &&
364 password_len != 26 && password_len != 10) {
365 common_utils_send_message_to_net_popup(
366 "Network connection popup",
367 "wrong password", "toast_popup", NULL);
369 if (ug_app_state->passpopup->entry) {
370 elm_object_focus_set(
371 ug_app_state->passpopup->entry,
378 case WIFI_SECURITY_TYPE_WPA_PSK:
379 case WIFI_SECURITY_TYPE_WPA2_PSK:
380 if (password_len < 8 || password_len > 64) {
381 common_utils_send_message_to_net_popup(
382 "Network connection popup",
383 "wrong password", "toast_popup", NULL);
385 if (ug_app_state->passpopup->entry) {
386 elm_object_focus_set(
387 ug_app_state->passpopup->entry,
395 ERROR_LOG(UG_NAME_NORMAL, "Wrong security mode: %d", sec_type);
396 passwd_popup_free(ug_app_state->passpopup);
397 ug_app_state->passpopup = NULL;
399 goto popup_ok_cb_exit;
402 bool favorite = FALSE;
403 if(wifi_ap_is_favorite(ap, &favorite) == WIFI_ERROR_NONE
404 && favorite == TRUE) {
405 wlan_manager_forget(ap);
409 if (ug_app_state->is_hidden) {
412 wifi_ap_get_essid(ap, &ssid);
413 wifi_ap_hidden_create(ssid, &hidden_ap);
415 wifi_ap_set_security_type(hidden_ap, sec_type);
416 wlan_manager_connect_with_password(hidden_ap, password);
418 wlan_manager_connect_with_password(ap, password);
420 passwd_popup_free(ug_app_state->passpopup);
421 ug_app_state->passpopup = NULL;
429 g_free((gpointer)password);
431 __COMMON_FUNC_EXIT__;
434 static void __wps_pbc_popup_cancel_connecting(void *data, Evas_Object *obj,
437 __COMMON_FUNC_ENTER__;
439 if (ug_app_state->passpopup == NULL) {
443 wifi_ap_h ap = passwd_popup_get_ap(ug_app_state->passpopup);
445 int ret = wlan_manager_disconnect(ap);
446 if (ret != WLAN_MANAGER_ERR_NONE) {
447 ERROR_LOG(UG_NAME_NORMAL, "Failed WPS PBC cancellation [0x%x]", ap);
450 passwd_popup_free(ug_app_state->passpopup);
451 ug_app_state->passpopup = NULL;
453 viewer_manager_header_mode_set(HEADER_MODE_ON);
455 __COMMON_FUNC_EXIT__;
458 static void _wps_btn_cb(void* data, Evas_Object* obj, void* event_info)
460 __COMMON_FUNC_ENTER__;
462 if (!ug_app_state->passpopup) {
466 wifi_ap_h ap = passwd_popup_get_ap(ug_app_state->passpopup);
467 int ret = wlan_manager_wps_connect(ap);
468 if (ret == WLAN_MANAGER_ERR_NONE) {
469 create_pbc_popup(ug_app_state->passpopup,
470 __wps_pbc_popup_cancel_connecting, NULL,
471 POPUP_WPS_BTN, NULL);
473 ERROR_LOG(UG_NAME_NORMAL, "wlan_manager_wps_connect failed");
474 passwd_popup_free(ug_app_state->passpopup);
475 ug_app_state->passpopup = NULL;
478 __COMMON_FUNC_EXIT__;
481 static void _wps_cancel_cb(void* data, Evas_Object* obj, void* event_info)
483 __COMMON_FUNC_ENTER__;
485 if (ug_app_state->passpopup == NULL) {
489 current_popup_free(ug_app_state->passpopup, POPUP_WPS_OPTIONS);
491 __COMMON_FUNC_EXIT__;
494 static void _wps_pin_cb(void* data, Evas_Object* obj, void* event_info)
496 __COMMON_FUNC_ENTER__;
497 unsigned int rpin = 0;
498 char npin[9] = { '\0' };
500 int ret = WLAN_MANAGER_ERR_NONE;
502 Evas_Object *info_popup = NULL;
504 if (!ug_app_state->passpopup) {
508 /* Generate WPS pin */
509 rpin = wps_generate_pin();
511 g_snprintf(npin, sizeof(npin), "%08d", rpin);
513 pin_len = strlen(npin);
515 info_popup = common_utils_show_info_ok_popup(
516 ug_app_state->layout_main, PACKAGE,
517 sc(PACKAGE, I18N_TYPE_Invalid_pin),
519 ug_app_state->passpopup);
520 ug_app_state->passpopup->info_popup = info_popup;
522 __COMMON_FUNC_EXIT__;
526 ap = passwd_popup_get_ap(ug_app_state->passpopup);
528 ret = wlan_manager_wps_pin_connect(ap, npin);
529 if (ret == WLAN_MANAGER_ERR_NONE) {
530 INFO_LOG(UG_NAME_NORMAL, "wlan_manager_wps_pin_connect successful");
532 create_pbc_popup(ug_app_state->passpopup,
533 __wps_pbc_popup_cancel_connecting, NULL,
534 POPUP_WPS_PIN, npin);
536 ERROR_LOG(UG_NAME_NORMAL, "wlan_manager_wps_pin_connect failed");
537 passwd_popup_free(ug_app_state->passpopup);
538 ug_app_state->passpopup = NULL;
541 __COMMON_FUNC_EXIT__;
544 static void __wps_options_popup_cb(void* data, Evas_Object* obj, void* event_info)
546 __COMMON_FUNC_ENTER__;
547 pswd_popup_create_req_data_t popup_info;
549 if (!ug_app_state->passpopup) {
553 memset(&popup_info, 0, sizeof(pswd_popup_create_req_data_t));
555 popup_info.title = "IDS_WIFI_HEADER_SELECT_WPS_METHOD_ABB";
556 popup_info.ok_cb = NULL;
557 popup_info.cancel_cb = _wps_cancel_cb;
558 popup_info.show_wps_btn = EINA_FALSE;
559 popup_info.wps_btn_cb = _wps_btn_cb;
560 popup_info.wps_pin_cb = _wps_pin_cb;
561 popup_info.ap = passwd_popup_get_ap(ug_app_state->passpopup);
562 popup_info.cb_data = NULL;
563 create_wps_options_popup(ug_app_state->layout_main, ug_app_state->passpopup,
566 __COMMON_FUNC_EXIT__;
569 void viewer_list_wifi_reconnect(wifi_device_info_t *device_info)
571 pswd_popup_create_req_data_t popup_info;
572 wifi_security_type_e sec_type = WIFI_SECURITY_TYPE_NONE;
573 wifi_device_info_t *device_info_temp = NULL;
574 struct ug_data *ugd = (struct ug_data *)ug_app_state->gadget;
576 if (device_info == NULL)
579 if (ug_app_state->passpopup != NULL || ug_app_state->eap_view != NULL) {
580 INFO_LOG(UG_NAME_ERR, "already launched popup");
584 wifi_ap_get_security_type(device_info->ap, &sec_type);
587 case WIFI_SECURITY_TYPE_WEP:
588 case WIFI_SECURITY_TYPE_WPA_PSK:
589 case WIFI_SECURITY_TYPE_WPA2_PSK:
590 memset(&popup_info, 0, sizeof(pswd_popup_create_req_data_t));
592 device_info_temp = view_list_item_device_info_create(device_info->ap);
594 popup_info.title = device_info->ssid;
595 popup_info.ok_cb = __passwd_popup_ok_cb;
596 popup_info.cancel_cb = __passwd_popup_cancel_cb;
597 popup_info.show_wps_btn = device_info->wps_mode;
598 popup_info.wps_btn_cb = __wps_options_popup_cb;
599 popup_info.ap = device_info->ap;
600 popup_info.cb_data = device_info_temp;
601 popup_info.sec_type = sec_type;
603 /* TODO: parameter with device_info */
604 /* TODO: finally parameter with wifi_ap_h, WPA, EAP */
605 ug_app_state->passpopup = create_passwd_popup(
606 ug_app_state->conformant,
607 ug_app_state->layout_main, PACKAGE, &popup_info);
609 if (ug_app_state->passpopup == NULL) {
610 INFO_LOG(UG_NAME_ERR, "Fail to create password popup");
614 case WIFI_SECURITY_TYPE_EAP:
615 ug_app_state->eap_view = create_eap_view(
616 ug_app_state->layout_main, ugd->win_main,
617 ug_app_state->conformant,
618 PACKAGE, device_info,
619 viewer_manager_eap_view_deref);
622 ERROR_LOG(UG_NAME_NORMAL, "Unknown security type [%d]", sec_type);
628 void viewer_list_wifi_connect(wifi_device_info_t *device_info)
630 bool favorite = false;
631 pswd_popup_create_req_data_t popup_info;
632 wifi_security_type_e sec_type = WIFI_SECURITY_TYPE_NONE;
633 wifi_device_info_t *dev_info_temp = NULL;
634 struct ug_data *ugd = (struct ug_data *)ug_app_state->gadget;
636 if (device_info == NULL)
639 wifi_ap_is_favorite(device_info->ap, &favorite);
640 if (favorite == true) {
641 wlan_manager_connect(device_info->ap);
645 if (ug_app_state->passpopup != NULL || ug_app_state->eap_view != NULL) {
646 INFO_LOG(UG_NAME_ERR, "already launched popup");
650 wifi_ap_get_security_type(device_info->ap, &sec_type);
653 case WIFI_SECURITY_TYPE_NONE:
654 if(ug_app_state->is_hidden) {
657 wifi_ap_get_essid(device_info->ap, &ssid);
658 wifi_ap_hidden_create(ssid, &ap);
660 wifi_ap_set_security_type(ap, WIFI_SECURITY_TYPE_NONE);
661 wlan_manager_connect(ap);
663 wlan_manager_connect(device_info->ap);
666 case WIFI_SECURITY_TYPE_WEP:
667 case WIFI_SECURITY_TYPE_WPA_PSK:
668 case WIFI_SECURITY_TYPE_WPA2_PSK:
669 memset(&popup_info, 0, sizeof(pswd_popup_create_req_data_t));
671 dev_info_temp = view_list_item_device_info_create(device_info->ap);
673 popup_info.title = device_info->ssid;
674 popup_info.ok_cb = __passwd_popup_ok_cb;
675 popup_info.cancel_cb = __passwd_popup_cancel_cb;
676 popup_info.show_wps_btn = device_info->wps_mode;
677 popup_info.wps_btn_cb = __wps_options_popup_cb;
678 popup_info.ap = device_info->ap;
679 popup_info.cb_data = dev_info_temp;
680 popup_info.sec_type = sec_type;
682 /* TODO: parameter with device_info */
683 /* TODO: finally parameter with wifi_ap_h, WPA, EAP */
684 ug_app_state->passpopup = create_passwd_popup(
685 ug_app_state->conformant,
686 ug_app_state->layout_main, PACKAGE, &popup_info);
688 if (ug_app_state->passpopup == NULL) {
689 INFO_LOG(UG_NAME_ERR, "Fail to create password popup");
694 case WIFI_SECURITY_TYPE_EAP:
695 ug_app_state->eap_view = create_eap_view(
696 ug_app_state->layout_main, ugd->win_main,
697 ug_app_state->conformant,
698 PACKAGE, device_info,
699 viewer_manager_eap_view_deref);
703 ERROR_LOG(UG_NAME_NORMAL, "Unknown security type[%d]", sec_type);
708 void viewer_list_clear_disconnect_popup(wifi_ap_h ap)
710 if (!g_disconnect_popup)
713 if (ap && g_disconnect_popup->ap &&
714 wlan_manager_is_same_network(g_disconnect_popup->ap, ap) != TRUE)
717 if (g_disconnect_popup->popup)
718 evas_object_del(g_disconnect_popup->popup);
720 if (g_disconnect_popup->ap)
721 wifi_ap_destroy(g_disconnect_popup->ap);
723 g_free(g_disconnect_popup);
724 g_disconnect_popup = NULL;
727 static void __viewer_list_disconnect_cancel_cb(void *data,
728 Evas_Object *obj, void *event_info)
730 struct connecting_cancel_popup_data *popup =
731 (struct connecting_cancel_popup_data *)data;
736 evas_object_del(popup->popup);
739 wifi_ap_destroy(popup->ap);
742 g_disconnect_popup = NULL;
745 static gboolean __viewer_list_update_ap(gpointer data)
747 wifi_ap_h ap = (wifi_ap_h)data;
749 viewer_manager_update_item_favorite_status(ap);
755 static void __viewer_list_disconnect_ok_cb(void *data,
756 Evas_Object *obj, void *event_info)
759 struct connecting_cancel_popup_data *popup =
760 (struct connecting_cancel_popup_data *)data;
764 wlan_manager_disconnect(popup->ap);
765 wlan_manager_forget(popup->ap);
768 evas_object_del(popup->popup);
770 id = common_util_managed_idle_add(__viewer_list_update_ap, (gpointer)popup->ap);
772 viewer_manager_update_item_favorite_status(popup->ap);
773 wifi_ap_destroy(popup->ap);
777 g_disconnect_popup = NULL;
780 static void __viewer_list_disconnect_popup(wifi_device_info_t *device_info,
781 Evas_Object *win_main)
783 popup_btn_info_t popup_data;
784 struct connecting_cancel_popup_data *popup = NULL;
786 memset(&popup_data, 0, sizeof(popup_data));
788 popup = g_try_new0(struct connecting_cancel_popup_data, 1);
792 g_disconnect_popup = popup;
793 wifi_ap_clone(&popup->ap, device_info->ap);
795 popup_data.title_txt = "IDS_WIFI_OPT_FORGET_NETWORK";
796 popup_data.info_txt = "IDS_WIFI_POP_CURRENT_NETWORK_WILL_BE_DISCONNECTED";
797 popup_data.btn1_cb = __viewer_list_disconnect_cancel_cb;
798 popup_data.btn1_txt = "IDS_WIFI_SK_CANCEL";
799 popup_data.btn1_data = popup;
800 popup_data.btn2_cb = __viewer_list_disconnect_ok_cb;
801 popup_data.btn2_txt = "IDS_WIFI_SK_FORGET";
802 popup_data.btn2_data = popup;
804 popup->popup = common_utils_show_info_popup(win_main, &popup_data);
807 static void __viewer_list_item_clicked_cb(void *data, Evas_Object *obj,
810 __COMMON_FUNC_ENTER__;
812 assertm_if(NULL == event_info, "event_info is NULL!!");
813 assertm_if(NULL == obj, "obj is NULL!!");
815 Elm_Object_Item *it = (Elm_Object_Item *)event_info;
816 ug_genlist_data_t *gdata = NULL;
817 wifi_device_info_t *device_info = NULL;
819 gdata = (ug_genlist_data_t *)elm_object_item_data_get(it);
820 retm_if(NULL == gdata);
822 device_info = gdata->device_info;
823 retm_if(NULL == device_info || NULL == device_info->ssid);
825 int item_state = gdata->radio_mode;
826 int current_state = 0;
828 SECURE_INFO_LOG(UG_NAME_NORMAL, "ssid --- %s", device_info->ssid);
829 INFO_LOG(UG_NAME_NORMAL, "ap --- 0x%x", device_info->ap);
830 INFO_LOG(UG_NAME_NORMAL, "current item_state state is --- %d", item_state);
832 if (ug_app_state->is_lbhome == EINA_TRUE &&
833 ug_app_state->app_control != NULL) {
834 INFO_LOG(UG_NAME_NORMAL, "exit with reply");
838 app_control_create(&reply);
839 wifi_ap_get_bssid(device_info->ap, &bssid);
840 SECURE_INFO_LOG(UG_NAME_NORMAL, "bssid %s, ssid %s", bssid, device_info->ssid);
842 app_control_add_extra_data(reply, "bssid", bssid);
843 app_control_add_extra_data(reply, "ssid", device_info->ssid);
844 app_control_reply_to_launch_request(reply, ug_app_state->app_control,
845 APP_CONTROL_RESULT_SUCCEEDED);
846 app_control_destroy(reply);
852 switch (item_state) {
853 case VIEWER_ITEM_RADIO_MODE_OFF:
854 current_state = viewer_manager_header_mode_get();
856 INFO_LOG(UG_NAME_NORMAL, "Clicked AP information\n");
857 INFO_LOG(UG_NAME_NORMAL, "header mode [%d]", current_state);
859 switch (current_state) {
861 case HEADER_MODE_CONNECTED:
862 case HEADER_MODE_CONNECTING:
863 case HEADER_MODE_SEARCHING:
864 viewer_list_wifi_connect(device_info);
867 case HEADER_MODE_OFF:
868 case HEADER_MODE_ACTIVATING:
869 case HEADER_MODE_DEACTIVATING:
871 INFO_LOG(UG_NAME_NORMAL, "Ignore click");
876 case VIEWER_ITEM_RADIO_MODE_CONNECTING:
877 case VIEWER_ITEM_RADIO_MODE_CONFIGURATION:
878 __viewer_list_disconnect_popup(device_info, ug_app_state->layout_main);
880 case VIEWER_ITEM_RADIO_MODE_CONNECTED:
882 INFO_LOG(UG_NAME_NORMAL, "Ignore click");
886 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
888 __COMMON_FUNC_EXIT__;
891 static char *viewer_list_get_device_status_txt(wifi_device_info_t *wifi_device,
892 VIEWER_ITEM_RADIO_MODES mode)
894 char *status_txt = NULL;
895 int current_state = 0;
897 current_state = viewer_manager_header_mode_get();
898 /* The strings are currently hard coded. It will be replaced with string ids later */
899 if (VIEWER_ITEM_RADIO_MODE_CONNECTING == mode) {
900 status_txt = g_strdup(sc(PACKAGE, I18N_TYPE_Connecting));
901 } else if (VIEWER_ITEM_RADIO_MODE_CONFIGURATION == mode) {
902 status_txt = g_strdup(sc(PACKAGE, I18N_TYPE_Obtaining_IP_addr));
903 } else if (VIEWER_ITEM_RADIO_MODE_CONNECTED == mode) {
904 if (connection_manager_is_wifi_connection_used() ||
905 current_state == HEADER_MODE_CONNECTED ) {
906 status_txt = g_strdup(sc(PACKAGE, I18N_TYPE_Connected));
908 } else if (VIEWER_ITEM_RADIO_MODE_OFF == mode) {
909 status_txt = common_utils_get_ap_security_type_info_txt(PACKAGE,
912 status_txt = g_strdup(sc(PACKAGE, I18N_TYPE_Unknown));
913 INFO_LOG(UG_NAME_NORMAL, "Invalid mode: %d", mode);
919 Evas_Object* viewer_list_create(Evas_Object *win)
921 __COMMON_FUNC_ENTER__;
923 assertm_if(NULL == win, "NULL!!");
924 assertm_if(NULL != viewer_list, "Err!!");
926 viewer_list = elm_genlist_add(win);
927 assertm_if(NULL == viewer_list, "NULL!!");
929 // To use multiline textblock/entry/editfield in genlist, set height_for_width mode
930 // then the item's height is calculated while the item's width fits to genlist width.
931 elm_genlist_mode_set(viewer_list, ELM_LIST_COMPRESS);
932 elm_genlist_homogeneous_set(viewer_list, EINA_TRUE);
934 evas_object_size_hint_weight_set(viewer_list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
935 evas_object_size_hint_align_set(viewer_list, EVAS_HINT_FILL, EVAS_HINT_FILL);
937 itc.item_style = WIFI_GENLIST_2LINE_TOP_TEXT_ICON_STYLE;
938 itc.func.text_get = _gl_listview_text_get;
939 itc.func.content_get = _gl_listview_content_get;
940 itc.func.state_get = NULL;
941 itc.func.del = _gl_listview_del;
943 no_wifi_device_itc.item_style = WIFI_GENLIST_1LINE_TEXT_STYLE;
944 no_wifi_device_itc.func.text_get = _gl_listview_text_get;
945 no_wifi_device_itc.func.content_get = NULL;
946 no_wifi_device_itc.func.state_get = NULL;
947 no_wifi_device_itc.func.del = _gl_listview_del;
949 first_item = last_item = NULL;
951 evas_object_smart_callback_add(viewer_list, "realized",
953 evas_object_smart_callback_add(viewer_list, "language,changed",
954 gl_lang_changed, NULL);
956 __COMMON_FUNC_EXIT__;
960 void viewer_list_title_item_del(void)
962 if (grouptitle != NULL) {
963 elm_object_item_del(grouptitle);
968 void viewer_list_title_item_update(void)
970 if (grouptitle != NULL)
971 elm_genlist_item_update(grouptitle);
974 void viewer_list_title_item_set(Elm_Object_Item *item_header)
976 if (item_header == NULL)
979 if (grouptitle != NULL) {
980 elm_genlist_item_update(grouptitle);
984 memset(&grouptitle_itc, 0, sizeof(grouptitle_itc));
985 grouptitle_itc.item_style = WIFI_GENLIST_GROUP_INDEX_STYLE;
986 grouptitle_itc.func.text_get = _gl_text_available_networks_get;
987 grouptitle_itc.func.content_get = _gl_content_scanning_icon_get;
989 grouptitle = elm_genlist_item_insert_after(viewer_list,
990 &grouptitle_itc, NULL, NULL, item_header,
991 ELM_GENLIST_ITEM_NONE, NULL, NULL);
993 assertm_if(NULL == grouptitle, "NULL!!");
995 elm_genlist_item_select_mode_set(grouptitle,
996 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
999 int viewer_list_item_radio_mode_set(Elm_Object_Item* item,
1000 VIEWER_ITEM_RADIO_MODES mode)
1002 __COMMON_FUNC_ENTER__;
1005 INFO_LOG(COMMON_NAME_ERR, "item is NULL");
1009 ug_genlist_data_t* gdata = (ug_genlist_data_t *) elm_object_item_data_get(item);
1010 if (NULL == gdata || NULL == gdata->device_info) {
1011 INFO_LOG(COMMON_NAME_ERR, "gdata or device_info is NULL");
1015 if (gdata->radio_mode == mode) {
1016 SECURE_INFO_LOG(UG_NAME_NORMAL, "[%s] is already in requested state", gdata->device_info->ssid);
1020 SECURE_INFO_LOG(UG_NAME_NORMAL, "[%s] AP Item State Transition from [%d] --> [%d]", gdata->device_info->ssid, gdata->radio_mode, mode);
1021 gdata->radio_mode = mode;
1022 if (gdata->device_info->ap_status_txt) {
1023 g_free(gdata->device_info->ap_status_txt);
1024 gdata->device_info->ap_status_txt = viewer_list_get_device_status_txt(gdata->device_info, mode);
1028 elm_genlist_item_update(item);
1030 __COMMON_FUNC_EXIT__;
1034 static wifi_connection_state_e _convert_wifi_state_to_viewer_radio_mode(
1035 wifi_connection_state_e state)
1038 case WIFI_CONNECTION_STATE_ASSOCIATION:
1039 return VIEWER_ITEM_RADIO_MODE_CONNECTING;
1040 case WIFI_CONNECTION_STATE_CONFIGURATION:
1041 return VIEWER_ITEM_RADIO_MODE_CONFIGURATION;
1042 case WIFI_CONNECTION_STATE_CONNECTED:
1043 return VIEWER_ITEM_RADIO_MODE_CONNECTED;
1045 return VIEWER_ITEM_RADIO_MODE_OFF;
1049 Elm_Object_Item *viewer_list_item_insert_after(wifi_device_info_t *wifi_device,
1050 Elm_Object_Item *after)
1052 Elm_Object_Item* ret = NULL;
1053 ug_genlist_data_t* gdata = NULL;
1054 wifi_device_info_t *no_wifi_device = NULL;
1055 wifi_connection_state_e state = WIFI_CONNECTION_STATE_DISCONNECTED;
1056 VIEWER_ITEM_RADIO_MODES rad_mode = VIEWER_ITEM_RADIO_MODE_OFF;
1057 retvm_if(NULL == viewer_list, NULL);
1059 if (wifi_device != NULL) {
1060 if (wifi_ap_get_connection_state(wifi_device->ap, &state) ==
1062 rad_mode = _convert_wifi_state_to_viewer_radio_mode(state);
1064 wifi_device->ap_status_txt = viewer_list_get_device_status_txt(
1068 if (ug_app_state->is_first_scan == true) {
1069 int scan_result = wlan_manager_scan();
1070 if (scan_result != WLAN_MANAGER_ERR_NONE) {
1071 viewer_manager_hide(VIEWER_WINSET_SEARCHING);
1072 viewer_manager_header_mode_set(viewer_manager_header_mode_get());
1074 ug_app_state->is_first_scan = false;
1077 no_wifi_device = g_try_new0(wifi_device_info_t, 1);
1078 if (no_wifi_device == NULL)
1081 no_wifi_device->ssid = g_strdup(sc(PACKAGE, I18N_TYPE_No_Wi_Fi_AP_Found));
1083 wifi_device = no_wifi_device;
1086 gdata = g_try_new0(ug_genlist_data_t, 1);
1087 retvm_if(NULL == gdata, NULL);
1088 gdata->device_info = wifi_device;
1089 gdata->radio_mode = VIEWER_ITEM_RADIO_MODE_OFF;
1092 /* If the after item is NULL then insert it as first item */
1096 if (no_wifi_device == NULL) {
1097 ret = elm_genlist_item_insert_after(
1098 viewer_list, /*obj*/
1102 after, /*after than*/
1103 ELM_GENLIST_ITEM_NONE, /*flags*/
1104 __viewer_list_item_clicked_cb,/*func*/
1107 ret = elm_genlist_item_insert_after(
1108 viewer_list, /*obj*/
1109 &no_wifi_device_itc,/*itc*/
1112 after, /*after than*/
1113 ELM_GENLIST_ITEM_NONE, /*flags*/
1114 __viewer_list_item_clicked_cb,/*func*/
1119 assertm_if(NULL == ret, "NULL!!");
1122 /* SECURE_DEBUG_LOG(UG_NAME_NORMAL,
1123 "* item add complete item [0x%x] ssid:[%s] security[%d] size:[%d]",
1126 wifi_device->security_mode,
1127 viewer_list_item_size_get()); */
1129 if (after == grouptitle) {
1142 elm_genlist_item_update(ret);
1148 void viewer_list_item_del(Elm_Object_Item *it)
1154 if (it == first_item) {
1155 first_item = elm_genlist_item_next_get(first_item);
1156 } else if (it == last_item) {
1157 last_item = elm_genlist_item_prev_get(last_item);
1159 elm_object_item_del(it);
1162 int viewer_list_item_size_get()
1165 Elm_Object_Item *it = first_item;
1169 if (it == last_item) {
1172 it = elm_genlist_item_next_get(it);
1178 void viewer_list_item_clear(void)
1180 __COMMON_FUNC_ENTER__;
1182 Elm_Object_Item *it = first_item;
1183 Elm_Object_Item *nxt = NULL;
1186 nxt = elm_genlist_item_next_get(it);
1187 elm_object_item_del(it);
1188 if (it == last_item) {
1194 first_item = last_item = NULL;
1196 __COMMON_FUNC_EXIT__;
1199 void viewer_list_item_enable_all(void)
1201 __COMMON_FUNC_ENTER__;
1203 Elm_Object_Item *it = first_item;
1206 elm_object_item_disabled_set(it, EINA_FALSE);
1208 if (it == last_item) {
1212 it = elm_genlist_item_next_get(it);
1215 __COMMON_FUNC_EXIT__;
1218 void viewer_list_item_disable_all(void)
1220 __COMMON_FUNC_ENTER__;
1222 Elm_Object_Item *it = first_item;
1225 elm_object_item_disabled_set(it, EINA_TRUE);
1227 if (it == last_item) {
1231 it = elm_genlist_item_next_get(it);
1234 __COMMON_FUNC_EXIT__;
1237 Elm_Object_Item* item_get_for_ap(wifi_ap_h ap)
1239 __COMMON_FUNC_ENTER__;
1241 __COMMON_FUNC_EXIT__;
1246 wifi_security_type_e type = WIFI_SECURITY_TYPE_NONE;
1248 if (WIFI_ERROR_NONE != wifi_ap_get_essid(ap, &essid)) {
1249 __COMMON_FUNC_EXIT__;
1251 } else if (WIFI_ERROR_NONE != wifi_ap_get_security_type(ap, &type)) {
1252 __COMMON_FUNC_EXIT__;
1256 Elm_Object_Item *it = first_item;
1257 wlan_security_mode_type_t sec_mode = common_utils_get_sec_mode(type);
1259 ug_genlist_data_t* gdata = elm_object_item_data_get(it);
1260 wifi_device_info_t *device_info = NULL;
1261 if (gdata && (device_info = gdata->device_info)) {
1262 if (!g_strcmp0(device_info->ssid, essid) && device_info->security_mode == sec_mode) {
1266 if (it == last_item) {
1270 it = elm_genlist_item_next_get(it);
1274 __COMMON_FUNC_EXIT__;
1278 Elm_Object_Item* item_get_for_ssid(const char *ssid)
1280 Elm_Object_Item *it = first_item;
1282 ug_genlist_data_t* gdata = elm_object_item_data_get(it);
1283 wifi_device_info_t *device_info = NULL;
1284 if (gdata && (device_info = gdata->device_info)) {
1285 if (!g_strcmp0(device_info->ssid, ssid)) {
1289 if (it == last_item) {
1293 it = elm_genlist_item_next_get(it);