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 g_snprintf(string, sizeof(string), "%08x", hexcolor);
86 static char* _gl_listview_text_get(void *data, Evas_Object *obj, const char *part)
90 char* convertedColor = NULL;
92 ug_genlist_data_t* gdata = (ug_genlist_data_t*) data;
93 retvm_if(NULL == gdata || NULL == gdata->device_info, NULL);
95 assertm_if(NULL == gdata->device_info->ssid, "NULL!!");
97 if (!strcmp("elm.text", part)) {
98 det = evas_textblock_text_utf8_to_markup(NULL,
99 gdata->device_info->ssid);
100 assertm_if(NULL == det, "NULL!!");
102 convertedColor = ConvertRGBAtoHex(61, 185, 204, 255);
103 assertm_if(NULL == convertedColor, "NULL!!");
104 if (VIEWER_ITEM_RADIO_MODE_CONNECTED == gdata->radio_mode) {
105 buf = g_strdup_printf("<color=#%s>%s</color>",
106 convertedColor, det);
109 g_free(convertedColor);
112 } else if (!strcmp("elm.text.sub", part)
113 && gdata->device_info->ap_status_txt != NULL) {
114 det = g_strdup(gdata->device_info->ap_status_txt);
116 assertm_if(NULL == det, "NULL!!");
121 static Evas_Object *_gl_listview_content_get(void *data, Evas_Object *obj, const char *part)
123 ug_genlist_data_t *gdata = (ug_genlist_data_t *)data;
124 retvm_if(NULL == gdata, NULL);
126 Evas_Object *icon = NULL;
127 Evas_Object *btn = NULL;
129 if (gdata->device_info->ap_image_path == NULL) {
130 /* if there is no ap_image_path (NO AP Found situation) */
131 DEBUG_LOG(UG_NAME_ERR, "Fatal: Image path is NULL");
133 } else if (!strcmp("elm.swallow.icon", part)) {
134 icon = elm_image_add(obj);
135 retvm_if(NULL == icon, NULL);
138 char *temp_str = NULL;
139 temp_str = g_strdup_printf("%s.png", gdata->device_info->ap_image_path);
140 elm_image_file_set(icon, CUSTOM_EDITFIELD_PATH, temp_str);
143 evas_object_color_set(icon, 2, 61, 132, 204);
144 evas_object_size_hint_min_set(icon, ELM_SCALE_SIZE(DEFAULT_BUTTON_CIRCLE_SIZE), ELM_SCALE_SIZE(DEFAULT_BUTTON_CIRCLE_SIZE));
146 } else if (!strcmp("elm.swallow.end", part)) {
147 if (VIEWER_ITEM_RADIO_MODE_CONNECTING == gdata->radio_mode ||
148 VIEWER_ITEM_RADIO_MODE_CONFIGURATION == gdata->radio_mode) {
150 icon = elm_progressbar_add(obj);
152 elm_object_style_set(icon, "process_medium");
153 evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, 0.5);
154 evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
155 elm_progressbar_pulse(icon, TRUE);
156 evas_object_propagate_events_set(icon, EINA_FALSE);
159 btn = elm_button_add(obj);
160 elm_object_style_set(btn, "circle_custom");
161 icon = elm_image_add(btn);
162 elm_image_file_set(icon, CUSTOM_EDITFIELD_PATH, "wifi_icon_badge_info.png");
163 elm_image_resizable_set(icon, EINA_TRUE, EINA_TRUE);
164 elm_object_part_content_set(btn, "elm.swallow.content", icon);
165 evas_object_propagate_events_set(btn, EINA_FALSE);
166 evas_object_smart_callback_add(btn, "clicked", _gl_listview_more_btn_cb,gdata->device_info);
167 evas_object_show(btn);
175 static void _gl_listview_del(void *data, Evas_Object *obj)
180 ug_genlist_data_t *gdata = (ug_genlist_data_t *)data;
181 retm_if(NULL == gdata || NULL == gdata->device_info);
183 g_free(gdata->device_info->ap_image_path);
184 g_free(gdata->device_info->ap_status_txt);
185 g_free(gdata->device_info->ssid);
186 wifi_ap_destroy(gdata->device_info->ap);
187 g_free(gdata->device_info);
191 static char *_gl_text_available_networks_get(void *data, Evas_Object *obj,
194 if (!strcmp("elm.text", part))
195 return g_strdup(sc(PACKAGE, I18N_TYPE_Available_networks));
200 static Evas_Object *_gl_content_scanning_icon_get(void *data, Evas_Object *obj,
203 Evas_Object *title_progressbar = NULL;
205 if (HEADER_MODE_SEARCHING == viewer_manager_header_mode_get()) {
206 title_progressbar = elm_progressbar_add(obj);
207 elm_object_style_set(title_progressbar, "process_small");
208 elm_progressbar_horizontal_set(title_progressbar, EINA_TRUE);
209 elm_progressbar_pulse(title_progressbar, EINA_TRUE);
212 return title_progressbar;
215 Elm_Object_Item* viewer_list_get_first_item(void)
220 Elm_Object_Item* viewer_list_get_last_item(void)
225 #ifdef ACCESSIBLITY_FEATURE
226 static char *_access_info_cb(void *data, Evas_Object *obj)
228 char *strength = NULL;
231 ug_genlist_data_t *gdata = (ug_genlist_data_t *)data;
236 strength = common_utils_get_rssi_text(PACKAGE, gdata->device_info->rssi);
237 buf = g_strdup_printf("%s. %s. %s.", strength, gdata->device_info->ssid, gdata->device_info->ap_status_txt);
244 static void gl_lang_changed(void *data, Evas_Object *obj, void *event_info)
246 elm_genlist_realized_items_update(obj);
249 static void _gl_realized(void *data, Evas_Object *obj, void *event_info)
251 #ifdef ACCESSIBLITY_FEATURE
252 HEADER_MODES header_mode = viewer_manager_header_mode_get();
253 Elm_Object_Item *item = (Elm_Object_Item *)event_info;
255 if (header_mode == HEADER_MODE_ACTIVATING ||
256 header_mode == HEADER_MODE_DEACTIVATING ||
257 header_mode == HEADER_MODE_OFF) {
261 Elm_Object_Item *first_item = viewer_list_get_first_item();
262 Elm_Object_Item *last_item = viewer_list_get_last_item();
264 if (first_item == NULL || last_item == NULL) {
268 int index = (int)elm_genlist_item_index_get(item);
269 int first_item_index = (int)elm_genlist_item_index_get(first_item);
270 int last_item_index = (int)elm_genlist_item_index_get(last_item);
273 if (first_item_index == -1) {
274 int group_index = (int)elm_genlist_item_index_get(grouptitle);
275 first_item_index = group_index + 1;
278 if (index >= first_item_index && index <= last_item_index &&
279 first_item_index < last_item_index) {
281 Evas_Object *ao = elm_object_item_access_object_get(item);
282 elm_access_info_cb_set(ao, ELM_ACCESS_INFO, _access_info_cb, elm_object_item_data_get(item));
283 g_snprintf(buf, sizeof(buf), "%s%s",
284 sc(PACKAGE, I18N_TYPE_Double_tap),
285 sc(PACKAGE, I18N_TYPE_Connect_to_device));
286 elm_access_info_set(ao, ELM_ACCESS_TYPE, buf);
287 elm_access_info_set(ao, ELM_ACCESS_STATE, sc(PACKAGE, I18N_TYPE_Wi_Fi_network_info));
290 Elm_Object_Item *first_item = viewer_list_get_first_item();
292 if (first_item == NULL) {
296 int first_item_index = (int)elm_genlist_item_index_get(first_item);
298 if (first_item_index == -1) {
299 int group_index = (int)elm_genlist_item_index_get(grouptitle);
300 first_item_index = group_index + 1;
305 static void _info_popup_ok_cb(void *data, Evas_Object *obj, void *event_info)
307 pswd_popup_t *passpopup = (pswd_popup_t *)data;
309 if (passpopup != NULL && passpopup->info_popup != NULL) {
310 evas_object_del(passpopup->info_popup);
311 passpopup->info_popup = NULL;
315 static void __passwd_popup_cancel_cb(void *data, Evas_Object *obj,
318 __COMMON_FUNC_ENTER__;
320 if (ug_app_state->passpopup == NULL) {
324 passwd_popup_free(ug_app_state->passpopup);
325 ug_app_state->passpopup = NULL;
331 __COMMON_FUNC_EXIT__;
334 static void __passwd_popup_ok_cb(void *data, Evas_Object *obj, void *event_info)
336 __COMMON_FUNC_ENTER__;
339 int password_len = 0;
340 const char *password = NULL;
341 wifi_security_type_e sec_type = WIFI_SECURITY_TYPE_NONE;
343 if (ug_app_state->passpopup == NULL) {
347 ap = passwd_popup_get_ap(ug_app_state->passpopup);
348 password = passwd_popup_get_txt(ug_app_state->passpopup);
349 if (password != NULL)
350 password_len = strlen(password);
352 wifi_ap_get_security_type(ap, &sec_type);
355 case WIFI_SECURITY_TYPE_WEP:
356 if (password_len != 5 && password_len != 13 &&
357 password_len != 26 && password_len != 10) {
358 common_utils_send_message_to_net_popup(
359 "Network connection popup",
360 "wrong password", "toast_popup", NULL);
362 if (ug_app_state->passpopup->entry) {
363 elm_object_focus_set(
364 ug_app_state->passpopup->entry,
371 case WIFI_SECURITY_TYPE_WPA_PSK:
372 case WIFI_SECURITY_TYPE_WPA2_PSK:
373 if (password_len < 8 || password_len > 64) {
374 common_utils_send_message_to_net_popup(
375 "Network connection popup",
376 "wrong password", "toast_popup", NULL);
378 if (ug_app_state->passpopup->entry) {
379 elm_object_focus_set(
380 ug_app_state->passpopup->entry,
388 ERROR_LOG(UG_NAME_NORMAL, "Wrong security mode: %d", sec_type);
389 passwd_popup_free(ug_app_state->passpopup);
390 ug_app_state->passpopup = NULL;
392 goto popup_ok_cb_exit;
395 bool favorite = FALSE;
396 if(wifi_ap_is_favorite(ap, &favorite) == WIFI_ERROR_NONE
397 && favorite == TRUE) {
398 wlan_manager_forget(ap);
402 if (ug_app_state->is_hidden) {
405 wifi_ap_get_essid(ap, &ssid);
406 wifi_ap_hidden_create(ssid, &hidden_ap);
408 wifi_ap_set_security_type(hidden_ap, sec_type);
409 wlan_manager_connect_with_password(hidden_ap, password);
411 wlan_manager_connect_with_password(ap, password);
413 passwd_popup_free(ug_app_state->passpopup);
414 ug_app_state->passpopup = NULL;
422 g_free((gpointer)password);
424 __COMMON_FUNC_EXIT__;
427 static void __wps_pbc_popup_cancel_connecting(void *data, Evas_Object *obj,
430 __COMMON_FUNC_ENTER__;
432 if (ug_app_state->passpopup == NULL) {
436 wifi_ap_h ap = passwd_popup_get_ap(ug_app_state->passpopup);
438 int ret = wlan_manager_disconnect(ap);
439 if (ret != WLAN_MANAGER_ERR_NONE) {
440 ERROR_LOG(UG_NAME_NORMAL, "Failed WPS PBC cancellation [0x%x]", ap);
443 passwd_popup_free(ug_app_state->passpopup);
444 ug_app_state->passpopup = NULL;
446 viewer_manager_header_mode_set(HEADER_MODE_ON);
447 ug_app_state->is_wifi_scan_indication_block = 0;
449 __COMMON_FUNC_EXIT__;
452 static void _wps_btn_cb(void* data, Evas_Object* obj, void* event_info)
454 __COMMON_FUNC_ENTER__;
456 if (!ug_app_state->passpopup) {
460 ug_app_state->is_wifi_scan_indication_block = 1;
461 wifi_ap_h ap = passwd_popup_get_ap(ug_app_state->passpopup);
462 int ret = wlan_manager_wps_connect(ap);
463 if (ret == WLAN_MANAGER_ERR_NONE) {
464 create_pbc_popup(ug_app_state->passpopup,
465 __wps_pbc_popup_cancel_connecting, NULL,
466 POPUP_WPS_BTN, NULL);
468 ERROR_LOG(UG_NAME_NORMAL, "wlan_manager_wps_connect failed");
469 passwd_popup_free(ug_app_state->passpopup);
470 ug_app_state->passpopup = NULL;
471 ug_app_state->is_wifi_scan_indication_block = 0;
474 __COMMON_FUNC_EXIT__;
477 static void _wps_cancel_cb(void* data, Evas_Object* obj, void* event_info)
479 __COMMON_FUNC_ENTER__;
481 ug_app_state->is_wifi_scan_indication_block = 0;
483 if (ug_app_state->passpopup == NULL) {
487 current_popup_free(ug_app_state->passpopup, POPUP_WPS_OPTIONS);
489 __COMMON_FUNC_EXIT__;
492 static void _wps_pin_cb(void* data, Evas_Object* obj, void* event_info)
494 __COMMON_FUNC_ENTER__;
495 unsigned int rpin = 0;
496 char npin[9] = { '\0' };
498 int ret = WLAN_MANAGER_ERR_NONE;
500 Evas_Object *info_popup = NULL;
502 if (!ug_app_state->passpopup) {
506 ug_app_state->is_wifi_scan_indication_block = 1;
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;
539 ug_app_state->is_wifi_scan_indication_block = 0;
542 __COMMON_FUNC_EXIT__;
545 static void __wps_options_popup_cb(void* data, Evas_Object* obj, void* event_info)
547 __COMMON_FUNC_ENTER__;
548 pswd_popup_create_req_data_t popup_info;
550 if (!ug_app_state->passpopup) {
554 memset(&popup_info, 0, sizeof(pswd_popup_create_req_data_t));
556 popup_info.title = "IDS_WIFI_HEADER_SELECT_WPS_METHOD_ABB";
557 popup_info.ok_cb = NULL;
558 popup_info.cancel_cb = _wps_cancel_cb;
559 popup_info.show_wps_btn = EINA_FALSE;
560 popup_info.wps_btn_cb = _wps_btn_cb;
561 popup_info.wps_pin_cb = _wps_pin_cb;
562 popup_info.ap = passwd_popup_get_ap(ug_app_state->passpopup);
563 popup_info.cb_data = NULL;
564 create_wps_options_popup(ug_app_state->layout_main, ug_app_state->passpopup,
567 __COMMON_FUNC_EXIT__;
570 void viewer_list_wifi_reconnect(wifi_device_info_t *device_info)
572 pswd_popup_create_req_data_t popup_info;
573 wifi_security_type_e sec_type = WIFI_SECURITY_TYPE_NONE;
574 wifi_device_info_t *device_info_temp = NULL;
575 struct ug_data *ugd = (struct ug_data *)ug_app_state->gadget;
577 if (device_info == NULL)
580 if (ug_app_state->passpopup != NULL || ug_app_state->eap_view != NULL) {
581 INFO_LOG(UG_NAME_ERR, "already launched popup");
585 wifi_ap_get_security_type(device_info->ap, &sec_type);
588 case WIFI_SECURITY_TYPE_WEP:
589 case WIFI_SECURITY_TYPE_WPA_PSK:
590 case WIFI_SECURITY_TYPE_WPA2_PSK:
591 memset(&popup_info, 0, sizeof(pswd_popup_create_req_data_t));
593 device_info_temp = view_list_item_device_info_create(device_info->ap);
595 popup_info.title = device_info->ssid;
596 popup_info.ok_cb = __passwd_popup_ok_cb;
597 popup_info.cancel_cb = __passwd_popup_cancel_cb;
598 popup_info.show_wps_btn = device_info->wps_mode;
599 popup_info.wps_btn_cb = __wps_options_popup_cb;
600 popup_info.ap = device_info->ap;
601 popup_info.cb_data = device_info_temp;
602 popup_info.sec_type = sec_type;
604 /* TODO: parameter with device_info */
605 /* TODO: finally parameter with wifi_ap_h, WPA, EAP */
606 ug_app_state->passpopup = create_passwd_popup(
607 ug_app_state->conformant,
608 ug_app_state->layout_main, PACKAGE, &popup_info);
610 if (ug_app_state->passpopup == NULL) {
611 INFO_LOG(UG_NAME_ERR, "Fail to create password popup");
615 case WIFI_SECURITY_TYPE_EAP:
616 ug_app_state->eap_view = create_eap_view(
617 ug_app_state->layout_main, ugd->win_main,
618 ug_app_state->conformant,
619 PACKAGE, device_info,
620 viewer_manager_eap_view_deref);
623 ERROR_LOG(UG_NAME_NORMAL, "Unknown security type [%d]", sec_type);
629 void viewer_list_wifi_connect(wifi_device_info_t *device_info)
631 bool favorite = false;
632 pswd_popup_create_req_data_t popup_info;
633 wifi_security_type_e sec_type = WIFI_SECURITY_TYPE_NONE;
634 wifi_device_info_t *dev_info_temp = NULL;
635 struct ug_data *ugd = (struct ug_data *)ug_app_state->gadget;
637 if (device_info == NULL)
640 wifi_ap_is_favorite(device_info->ap, &favorite);
641 if (favorite == true) {
642 wlan_manager_connect(device_info->ap);
646 if (ug_app_state->passpopup != NULL || ug_app_state->eap_view != NULL) {
647 INFO_LOG(UG_NAME_ERR, "already launched popup");
651 wifi_ap_get_security_type(device_info->ap, &sec_type);
654 case WIFI_SECURITY_TYPE_NONE:
655 if(ug_app_state->is_hidden) {
658 wifi_ap_get_essid(device_info->ap, &ssid);
659 wifi_ap_hidden_create(ssid, &ap);
661 wifi_ap_set_security_type(ap, WIFI_SECURITY_TYPE_NONE);
662 wlan_manager_connect(ap);
664 wlan_manager_connect(device_info->ap);
667 case WIFI_SECURITY_TYPE_WEP:
668 case WIFI_SECURITY_TYPE_WPA_PSK:
669 case WIFI_SECURITY_TYPE_WPA2_PSK:
670 memset(&popup_info, 0, sizeof(pswd_popup_create_req_data_t));
672 dev_info_temp = view_list_item_device_info_create(device_info->ap);
674 popup_info.title = device_info->ssid;
675 popup_info.ok_cb = __passwd_popup_ok_cb;
676 popup_info.cancel_cb = __passwd_popup_cancel_cb;
677 popup_info.show_wps_btn = device_info->wps_mode;
678 popup_info.wps_btn_cb = __wps_options_popup_cb;
679 popup_info.ap = device_info->ap;
680 popup_info.cb_data = dev_info_temp;
681 popup_info.sec_type = sec_type;
683 /* TODO: parameter with device_info */
684 /* TODO: finally parameter with wifi_ap_h, WPA, EAP */
685 ug_app_state->passpopup = create_passwd_popup(
686 ug_app_state->conformant,
687 ug_app_state->layout_main, PACKAGE, &popup_info);
689 if (ug_app_state->passpopup == NULL) {
690 INFO_LOG(UG_NAME_ERR, "Fail to create password popup");
695 case WIFI_SECURITY_TYPE_EAP:
696 ug_app_state->eap_view = create_eap_view(
697 ug_app_state->layout_main, ugd->win_main,
698 ug_app_state->conformant,
699 PACKAGE, device_info,
700 viewer_manager_eap_view_deref);
704 ERROR_LOG(UG_NAME_NORMAL, "Unknown security type[%d]", sec_type);
709 void viewer_list_clear_disconnect_popup(wifi_ap_h ap)
711 if (!g_disconnect_popup)
714 if (ap && g_disconnect_popup->ap &&
715 wlan_manager_is_same_network(g_disconnect_popup->ap, ap) != TRUE)
718 if (g_disconnect_popup->popup)
719 evas_object_del(g_disconnect_popup->popup);
721 if (g_disconnect_popup->ap)
722 wifi_ap_destroy(g_disconnect_popup->ap);
724 g_free(g_disconnect_popup);
725 g_disconnect_popup = NULL;
728 static void __viewer_list_disconnect_cancel_cb(void *data,
729 Evas_Object *obj, void *event_info)
731 struct connecting_cancel_popup_data *popup =
732 (struct connecting_cancel_popup_data *)data;
737 evas_object_del(popup->popup);
740 wifi_ap_destroy(popup->ap);
743 g_disconnect_popup = NULL;
746 static gboolean __viewer_list_update_ap(gpointer data)
748 wifi_ap_h ap = (wifi_ap_h)data;
750 viewer_manager_update_item_favorite_status(ap);
756 static void __viewer_list_disconnect_ok_cb(void *data,
757 Evas_Object *obj, void *event_info)
760 struct connecting_cancel_popup_data *popup =
761 (struct connecting_cancel_popup_data *)data;
765 wlan_manager_disconnect(popup->ap);
766 wlan_manager_forget(popup->ap);
769 evas_object_del(popup->popup);
771 id = common_util_managed_idle_add(__viewer_list_update_ap, (gpointer)popup->ap);
773 viewer_manager_update_item_favorite_status(popup->ap);
774 wifi_ap_destroy(popup->ap);
778 g_disconnect_popup = NULL;
781 static void __viewer_list_disconnect_popup(wifi_device_info_t *device_info,
782 Evas_Object *win_main)
784 popup_btn_info_t popup_data;
785 struct connecting_cancel_popup_data *popup = NULL;
787 memset(&popup_data, 0, sizeof(popup_data));
789 popup = g_try_new0(struct connecting_cancel_popup_data, 1);
793 g_disconnect_popup = popup;
794 wifi_ap_clone(&popup->ap, device_info->ap);
796 popup_data.title_txt = "IDS_WIFI_OPT_FORGET_NETWORK";
797 popup_data.info_txt = "IDS_WIFI_POP_CURRENT_NETWORK_WILL_BE_DISCONNECTED";
798 popup_data.btn1_cb = __viewer_list_disconnect_cancel_cb;
799 popup_data.btn1_txt = "IDS_WIFI_SK_CANCEL";
800 popup_data.btn1_data = popup;
801 popup_data.btn2_cb = __viewer_list_disconnect_ok_cb;
802 popup_data.btn2_txt = "IDS_WIFI_SK_FORGET";
803 popup_data.btn2_data = popup;
805 popup->popup = common_utils_show_info_popup(win_main, &popup_data);
808 static void __viewer_list_item_clicked_cb(void *data, Evas_Object *obj,
811 __COMMON_FUNC_ENTER__;
813 assertm_if(NULL == event_info, "event_info is NULL!!");
814 assertm_if(NULL == obj, "obj is NULL!!");
816 Elm_Object_Item *it = (Elm_Object_Item *)event_info;
817 ug_genlist_data_t *gdata = NULL;
818 wifi_device_info_t *device_info = NULL;
820 gdata = (ug_genlist_data_t *)elm_object_item_data_get(it);
821 retm_if(NULL == gdata);
823 device_info = gdata->device_info;
824 retm_if(NULL == device_info || NULL == device_info->ssid);
826 int item_state = gdata->radio_mode;
827 int current_state = 0;
829 SECURE_INFO_LOG(UG_NAME_NORMAL, "ssid --- %s", device_info->ssid);
830 INFO_LOG(UG_NAME_NORMAL, "ap --- 0x%x", device_info->ap);
831 INFO_LOG(UG_NAME_NORMAL, "current item_state state is --- %d", item_state);
833 if (ug_app_state->is_lbhome == EINA_TRUE &&
834 ug_app_state->app_control != NULL) {
835 INFO_LOG(UG_NAME_NORMAL, "exit with reply");
839 app_control_create(&reply);
840 wifi_ap_get_bssid(device_info->ap, &bssid);
841 SECURE_INFO_LOG(UG_NAME_NORMAL, "bssid %s, ssid %s", bssid, device_info->ssid);
843 app_control_add_extra_data(reply, "bssid", bssid);
844 app_control_add_extra_data(reply, "ssid", device_info->ssid);
845 app_control_reply_to_launch_request(reply, ug_app_state->app_control,
846 APP_CONTROL_RESULT_SUCCEEDED);
847 app_control_destroy(reply);
853 switch (item_state) {
854 case VIEWER_ITEM_RADIO_MODE_OFF:
855 current_state = viewer_manager_header_mode_get();
857 INFO_LOG(UG_NAME_NORMAL, "Clicked AP information\n");
858 INFO_LOG(UG_NAME_NORMAL, "header mode [%d]", current_state);
860 switch (current_state) {
862 case HEADER_MODE_CONNECTED:
863 case HEADER_MODE_CONNECTING:
864 case HEADER_MODE_SEARCHING:
865 viewer_list_wifi_connect(device_info);
868 case HEADER_MODE_OFF:
869 case HEADER_MODE_ACTIVATING:
870 case HEADER_MODE_DEACTIVATING:
872 INFO_LOG(UG_NAME_NORMAL, "Ignore click");
877 case VIEWER_ITEM_RADIO_MODE_CONNECTING:
878 case VIEWER_ITEM_RADIO_MODE_CONFIGURATION:
879 __viewer_list_disconnect_popup(device_info, ug_app_state->layout_main);
881 case VIEWER_ITEM_RADIO_MODE_CONNECTED:
883 INFO_LOG(UG_NAME_NORMAL, "Ignore click");
887 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
889 __COMMON_FUNC_EXIT__;
892 static char *viewer_list_get_device_status_txt(wifi_device_info_t *wifi_device,
893 VIEWER_ITEM_RADIO_MODES mode)
895 char *status_txt = NULL;
896 int current_state = 0;
898 current_state = viewer_manager_header_mode_get();
899 /* The strings are currently hard coded. It will be replaced with string ids later */
900 if (VIEWER_ITEM_RADIO_MODE_CONNECTING == mode) {
901 status_txt = g_strdup(sc(PACKAGE, I18N_TYPE_Connecting));
902 } else if (VIEWER_ITEM_RADIO_MODE_CONFIGURATION == mode) {
903 status_txt = g_strdup(sc(PACKAGE, I18N_TYPE_Obtaining_IP_addr));
904 } else if (VIEWER_ITEM_RADIO_MODE_CONNECTED == mode) {
905 if (connection_manager_is_wifi_connection_used() ||
906 current_state == HEADER_MODE_CONNECTED ) {
907 status_txt = g_strdup(sc(PACKAGE, I18N_TYPE_Connected));
909 } else if (VIEWER_ITEM_RADIO_MODE_OFF == mode) {
910 status_txt = common_utils_get_ap_security_type_info_txt(PACKAGE,
913 status_txt = g_strdup(sc(PACKAGE, I18N_TYPE_Unknown));
914 INFO_LOG(UG_NAME_NORMAL, "Invalid mode: %d", mode);
920 Evas_Object* viewer_list_create(Evas_Object *win)
922 __COMMON_FUNC_ENTER__;
924 assertm_if(NULL == win, "NULL!!");
925 assertm_if(NULL != viewer_list, "Err!!");
927 viewer_list = elm_genlist_add(win);
928 assertm_if(NULL == viewer_list, "NULL!!");
930 // To use multiline textblock/entry/editfield in genlist, set height_for_width mode
931 // then the item's height is calculated while the item's width fits to genlist width.
932 elm_genlist_mode_set(viewer_list, ELM_LIST_COMPRESS);
933 //elm_genlist_realization_mode_set(viewer_list, EINA_TRUE);
935 evas_object_size_hint_weight_set(viewer_list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
936 evas_object_size_hint_align_set(viewer_list, EVAS_HINT_FILL, EVAS_HINT_FILL);
938 itc = elm_genlist_item_class_new();
939 itc->item_style = WIFI_GENLIST_2LINE_TOP_TEXT_ICON_STYLE;
940 itc->func.text_get = _gl_listview_text_get;
941 itc->func.content_get = _gl_listview_content_get;
942 itc->func.state_get = NULL;
943 itc->func.del = _gl_listview_del;
945 no_wifi_device_itc = elm_genlist_item_class_new();
946 no_wifi_device_itc->item_style = WIFI_GENLIST_1LINE_TEXT_STYLE;
947 no_wifi_device_itc->func.text_get = _gl_listview_text_get;
948 no_wifi_device_itc->func.content_get = NULL;
949 no_wifi_device_itc->func.state_get = NULL;
950 no_wifi_device_itc->func.del = _gl_listview_del;
952 first_item = last_item = NULL;
954 evas_object_smart_callback_add(viewer_list, "realized",
956 evas_object_smart_callback_add(viewer_list, "language,changed",
957 gl_lang_changed, NULL);
959 __COMMON_FUNC_EXIT__;
963 void viewer_list_title_item_del(void)
965 if (grouptitle != NULL) {
966 elm_object_item_del(grouptitle);
971 void viewer_list_title_item_update(void)
973 if (grouptitle != NULL)
974 elm_genlist_item_update(grouptitle);
977 void viewer_list_title_item_set(Elm_Object_Item *item_header)
979 if (item_header == NULL)
982 if (grouptitle != NULL) {
983 elm_genlist_item_update(grouptitle);
987 //memset(&grouptitle_itc, 0, sizeof(grouptitle_itc));
988 grouptitle_itc = elm_genlist_item_class_new();
989 grouptitle_itc->item_style = WIFI_GENLIST_GROUP_INDEX_STYLE;
990 grouptitle_itc->func.text_get = _gl_text_available_networks_get;
991 grouptitle_itc->func.content_get = _gl_content_scanning_icon_get;
993 grouptitle = elm_genlist_item_insert_after(viewer_list,
994 grouptitle_itc, NULL, NULL, item_header,
995 ELM_GENLIST_ITEM_NONE, NULL, NULL);
997 assertm_if(NULL == grouptitle, "NULL!!");
999 elm_genlist_item_select_mode_set(grouptitle,
1000 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1003 int viewer_list_item_radio_mode_set(Elm_Object_Item* item,
1004 VIEWER_ITEM_RADIO_MODES mode)
1006 __COMMON_FUNC_ENTER__;
1009 INFO_LOG(COMMON_NAME_ERR, "item is NULL");
1013 ug_genlist_data_t* gdata = (ug_genlist_data_t *) elm_object_item_data_get(item);
1014 if (NULL == gdata || NULL == gdata->device_info) {
1015 INFO_LOG(COMMON_NAME_ERR, "gdata or device_info is NULL");
1019 if (gdata->radio_mode == mode) {
1020 SECURE_INFO_LOG(UG_NAME_NORMAL, "[%s] is already in requested state", gdata->device_info->ssid);
1024 SECURE_INFO_LOG(UG_NAME_NORMAL, "[%s] AP Item State Transition from [%d] --> [%d]", gdata->device_info->ssid, gdata->radio_mode, mode);
1025 gdata->radio_mode = mode;
1026 if (gdata->device_info->ap_status_txt) {
1027 g_free(gdata->device_info->ap_status_txt);
1028 gdata->device_info->ap_status_txt = viewer_list_get_device_status_txt(gdata->device_info, mode);
1032 elm_genlist_item_update(item);
1034 __COMMON_FUNC_EXIT__;
1038 #ifndef TIZEN_EMULATOR
1039 static wifi_connection_state_e _convert_wifi_state_to_viewer_radio_mode(
1040 wifi_connection_state_e state)
1043 case WIFI_CONNECTION_STATE_ASSOCIATION:
1044 return VIEWER_ITEM_RADIO_MODE_CONNECTING;
1045 case WIFI_CONNECTION_STATE_CONFIGURATION:
1046 return VIEWER_ITEM_RADIO_MODE_CONFIGURATION;
1047 case WIFI_CONNECTION_STATE_CONNECTED:
1048 return VIEWER_ITEM_RADIO_MODE_CONNECTED;
1050 return VIEWER_ITEM_RADIO_MODE_OFF;
1055 Elm_Object_Item *viewer_list_item_insert_after(wifi_device_info_t *wifi_device,
1056 Elm_Object_Item *after)
1058 Elm_Object_Item* ret = NULL;
1059 ug_genlist_data_t* gdata = NULL;
1060 wifi_device_info_t *no_wifi_device = NULL;
1061 retvm_if(NULL == viewer_list, NULL);
1063 #ifdef TIZEN_EMULATOR
1064 if (wifi_device != NULL) {
1065 wifi_device->ap_status_txt = viewer_list_get_device_status_txt(
1067 VIEWER_ITEM_RADIO_MODE_OFF);
1069 no_wifi_device = g_try_new0(wifi_device_info_t, 1);
1070 if (no_wifi_device == NULL)
1073 no_wifi_device->ssid = g_strdup(sc(PACKAGE, I18N_TYPE_No_Wi_Fi_AP_Found));
1074 wifi_device = no_wifi_device;
1077 wifi_connection_state_e state = WIFI_CONNECTION_STATE_DISCONNECTED;
1078 VIEWER_ITEM_RADIO_MODES rad_mode = VIEWER_ITEM_RADIO_MODE_OFF;
1079 if (wifi_device != NULL && wifi_device->ap != NULL) {
1080 if (wifi_ap_get_connection_state(wifi_device->ap, &state) ==
1082 rad_mode = _convert_wifi_state_to_viewer_radio_mode(state);
1084 wifi_device->ap_status_txt = viewer_list_get_device_status_txt(
1088 if (ug_app_state->is_first_scan == true) {
1089 int scan_result = wlan_manager_scan();
1090 if (scan_result != WLAN_MANAGER_ERR_NONE) {
1091 viewer_manager_hide(VIEWER_WINSET_SEARCHING);
1092 viewer_manager_header_mode_set(viewer_manager_header_mode_get());
1094 ug_app_state->is_first_scan = false;
1097 no_wifi_device = g_try_new0(wifi_device_info_t, 1);
1098 if (no_wifi_device == NULL)
1101 no_wifi_device->ssid = g_strdup(sc(PACKAGE, I18N_TYPE_No_Wi_Fi_AP_Found));
1102 wifi_device = no_wifi_device;
1106 gdata = g_try_new0(ug_genlist_data_t, 1);
1107 retvm_if(NULL == gdata, NULL);
1108 gdata->device_info = wifi_device;
1109 gdata->radio_mode = VIEWER_ITEM_RADIO_MODE_OFF;
1112 /* If the after item is NULL then insert it as first item */
1116 if (no_wifi_device == NULL) {
1117 ret = elm_genlist_item_insert_after(
1118 viewer_list, /*obj*/
1122 after, /*after than*/
1123 ELM_GENLIST_ITEM_NONE, /*flags*/
1124 __viewer_list_item_clicked_cb,/*func*/
1127 ret = elm_genlist_item_insert_after(
1128 viewer_list, /*obj*/
1129 no_wifi_device_itc,/*itc*/
1132 after, /*after than*/
1133 ELM_GENLIST_ITEM_NONE, /*flags*/
1134 __viewer_list_item_clicked_cb,/*func*/
1139 assertm_if(NULL == ret, "NULL!!");
1142 /* SECURE_DEBUG_LOG(UG_NAME_NORMAL,
1143 "* item add complete item [0x%x] ssid:[%s] security[%d] size:[%d]",
1146 wifi_device->security_mode,
1147 viewer_list_item_size_get()); */
1149 if (after == grouptitle) {
1162 elm_genlist_item_update(ret);
1168 void viewer_list_item_del(Elm_Object_Item *it)
1174 if (it == first_item) {
1175 first_item = elm_genlist_item_next_get(first_item);
1176 } else if (it == last_item) {
1177 last_item = elm_genlist_item_prev_get(last_item);
1179 elm_object_item_del(it);
1182 int viewer_list_item_size_get()
1185 Elm_Object_Item *it = first_item;
1189 if (it == last_item) {
1192 it = elm_genlist_item_next_get(it);
1198 void viewer_list_item_clear(void)
1200 __COMMON_FUNC_ENTER__;
1202 Elm_Object_Item *it = first_item;
1203 Elm_Object_Item *nxt = NULL;
1206 nxt = elm_genlist_item_next_get(it);
1207 elm_object_item_del(it);
1208 if (it == last_item) {
1214 first_item = last_item = NULL;
1216 __COMMON_FUNC_EXIT__;
1219 void viewer_list_item_enable_all(void)
1221 __COMMON_FUNC_ENTER__;
1223 Elm_Object_Item *it = first_item;
1226 elm_object_item_disabled_set(it, EINA_FALSE);
1228 if (it == last_item) {
1232 it = elm_genlist_item_next_get(it);
1235 __COMMON_FUNC_EXIT__;
1238 void viewer_list_item_disable_all(void)
1240 __COMMON_FUNC_ENTER__;
1242 Elm_Object_Item *it = first_item;
1245 elm_object_item_disabled_set(it, EINA_TRUE);
1247 if (it == last_item) {
1251 it = elm_genlist_item_next_get(it);
1254 __COMMON_FUNC_EXIT__;
1257 Elm_Object_Item* item_get_for_ap(wifi_ap_h ap)
1259 __COMMON_FUNC_ENTER__;
1261 __COMMON_FUNC_EXIT__;
1266 wifi_security_type_e type = WIFI_SECURITY_TYPE_NONE;
1268 if (WIFI_ERROR_NONE != wifi_ap_get_essid(ap, &essid)) {
1269 __COMMON_FUNC_EXIT__;
1271 } else if (WIFI_ERROR_NONE != wifi_ap_get_security_type(ap, &type)) {
1272 __COMMON_FUNC_EXIT__;
1276 Elm_Object_Item *it = first_item;
1277 wlan_security_mode_type_t sec_mode = common_utils_get_sec_mode(type);
1279 ug_genlist_data_t* gdata = elm_object_item_data_get(it);
1280 wifi_device_info_t *device_info = NULL;
1281 if (gdata && (device_info = gdata->device_info)) {
1282 if (!g_strcmp0(device_info->ssid, essid) && device_info->security_mode == sec_mode) {
1286 if (it == last_item) {
1290 it = elm_genlist_item_next_get(it);
1294 __COMMON_FUNC_EXIT__;
1298 Elm_Object_Item* item_get_for_ssid(const char *ssid)
1300 Elm_Object_Item *it = first_item;
1302 ug_genlist_data_t* gdata = elm_object_item_data_get(it);
1303 wifi_device_info_t *device_info = NULL;
1304 if (gdata && (device_info = gdata->device_info)) {
1305 if (!g_strcmp0(device_info->ssid, ssid)) {
1309 if (it == last_item) {
1313 it = elm_genlist_item_next_get(it);