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);
448 __COMMON_FUNC_EXIT__;
451 static void _wps_btn_cb(void* data, Evas_Object* obj, void* event_info)
453 __COMMON_FUNC_ENTER__;
455 if (!ug_app_state->passpopup) {
459 wifi_ap_h ap = passwd_popup_get_ap(ug_app_state->passpopup);
460 int ret = wlan_manager_wps_connect(ap);
461 if (ret == WLAN_MANAGER_ERR_NONE) {
462 create_pbc_popup(ug_app_state->passpopup,
463 __wps_pbc_popup_cancel_connecting, NULL,
464 POPUP_WPS_BTN, NULL);
466 ERROR_LOG(UG_NAME_NORMAL, "wlan_manager_wps_connect failed");
467 passwd_popup_free(ug_app_state->passpopup);
468 ug_app_state->passpopup = NULL;
471 __COMMON_FUNC_EXIT__;
474 static void _wps_cancel_cb(void* data, Evas_Object* obj, void* event_info)
476 __COMMON_FUNC_ENTER__;
478 if (ug_app_state->passpopup == NULL) {
482 current_popup_free(ug_app_state->passpopup, POPUP_WPS_OPTIONS);
484 __COMMON_FUNC_EXIT__;
487 static void _wps_pin_cb(void* data, Evas_Object* obj, void* event_info)
489 __COMMON_FUNC_ENTER__;
490 unsigned int rpin = 0;
491 char npin[9] = { '\0' };
493 int ret = WLAN_MANAGER_ERR_NONE;
495 Evas_Object *info_popup = NULL;
497 if (!ug_app_state->passpopup) {
501 /* Generate WPS pin */
502 rpin = wps_generate_pin();
504 g_snprintf(npin, sizeof(npin), "%08d", rpin);
506 pin_len = strlen(npin);
508 info_popup = common_utils_show_info_ok_popup(
509 ug_app_state->layout_main, PACKAGE,
510 sc(PACKAGE, I18N_TYPE_Invalid_pin),
512 ug_app_state->passpopup);
513 ug_app_state->passpopup->info_popup = info_popup;
515 __COMMON_FUNC_EXIT__;
519 ap = passwd_popup_get_ap(ug_app_state->passpopup);
521 ret = wlan_manager_wps_pin_connect(ap, npin);
522 if (ret == WLAN_MANAGER_ERR_NONE) {
523 INFO_LOG(UG_NAME_NORMAL, "wlan_manager_wps_pin_connect successful");
525 create_pbc_popup(ug_app_state->passpopup,
526 __wps_pbc_popup_cancel_connecting, NULL,
527 POPUP_WPS_PIN, npin);
529 ERROR_LOG(UG_NAME_NORMAL, "wlan_manager_wps_pin_connect failed");
530 passwd_popup_free(ug_app_state->passpopup);
531 ug_app_state->passpopup = NULL;
534 __COMMON_FUNC_EXIT__;
537 static void __wps_options_popup_cb(void* data, Evas_Object* obj, void* event_info)
539 __COMMON_FUNC_ENTER__;
540 pswd_popup_create_req_data_t popup_info;
542 if (!ug_app_state->passpopup) {
546 memset(&popup_info, 0, sizeof(pswd_popup_create_req_data_t));
548 popup_info.title = "IDS_WIFI_HEADER_SELECT_WPS_METHOD_ABB";
549 popup_info.ok_cb = NULL;
550 popup_info.cancel_cb = _wps_cancel_cb;
551 popup_info.show_wps_btn = EINA_FALSE;
552 popup_info.wps_btn_cb = _wps_btn_cb;
553 popup_info.wps_pin_cb = _wps_pin_cb;
554 popup_info.ap = passwd_popup_get_ap(ug_app_state->passpopup);
555 popup_info.cb_data = NULL;
556 create_wps_options_popup(ug_app_state->layout_main, ug_app_state->passpopup,
559 __COMMON_FUNC_EXIT__;
562 void viewer_list_wifi_reconnect(wifi_device_info_t *device_info)
564 pswd_popup_create_req_data_t popup_info;
565 wifi_security_type_e sec_type = WIFI_SECURITY_TYPE_NONE;
566 wifi_device_info_t *device_info_temp = NULL;
567 struct ug_data *ugd = (struct ug_data *)ug_app_state->gadget;
569 if (device_info == NULL)
572 if (ug_app_state->passpopup != NULL || ug_app_state->eap_view != NULL) {
573 INFO_LOG(UG_NAME_ERR, "already launched popup");
577 wifi_ap_get_security_type(device_info->ap, &sec_type);
580 case WIFI_SECURITY_TYPE_WEP:
581 case WIFI_SECURITY_TYPE_WPA_PSK:
582 case WIFI_SECURITY_TYPE_WPA2_PSK:
583 memset(&popup_info, 0, sizeof(pswd_popup_create_req_data_t));
585 device_info_temp = view_list_item_device_info_create(device_info->ap);
587 popup_info.title = device_info->ssid;
588 popup_info.ok_cb = __passwd_popup_ok_cb;
589 popup_info.cancel_cb = __passwd_popup_cancel_cb;
590 popup_info.show_wps_btn = device_info->wps_mode;
591 popup_info.wps_btn_cb = __wps_options_popup_cb;
592 popup_info.ap = device_info->ap;
593 popup_info.cb_data = device_info_temp;
594 popup_info.sec_type = sec_type;
596 /* TODO: parameter with device_info */
597 /* TODO: finally parameter with wifi_ap_h, WPA, EAP */
598 ug_app_state->passpopup = create_passwd_popup(
599 ug_app_state->conformant,
600 ug_app_state->layout_main, PACKAGE, &popup_info);
602 if (ug_app_state->passpopup == NULL) {
603 INFO_LOG(UG_NAME_ERR, "Fail to create password popup");
607 case WIFI_SECURITY_TYPE_EAP:
608 ug_app_state->eap_view = create_eap_view(
609 ug_app_state->layout_main, ugd->win_main,
610 ug_app_state->conformant,
611 PACKAGE, device_info,
612 viewer_manager_eap_view_deref);
615 ERROR_LOG(UG_NAME_NORMAL, "Unknown security type [%d]", sec_type);
621 void viewer_list_wifi_connect(wifi_device_info_t *device_info)
623 bool favorite = false;
624 pswd_popup_create_req_data_t popup_info;
625 wifi_security_type_e sec_type = WIFI_SECURITY_TYPE_NONE;
626 wifi_device_info_t *dev_info_temp = NULL;
627 struct ug_data *ugd = (struct ug_data *)ug_app_state->gadget;
629 if (device_info == NULL)
632 wifi_ap_is_favorite(device_info->ap, &favorite);
633 if (favorite == true) {
634 wlan_manager_connect(device_info->ap);
638 if (ug_app_state->passpopup != NULL || ug_app_state->eap_view != NULL) {
639 INFO_LOG(UG_NAME_ERR, "already launched popup");
643 wifi_ap_get_security_type(device_info->ap, &sec_type);
646 case WIFI_SECURITY_TYPE_NONE:
647 if(ug_app_state->is_hidden) {
650 wifi_ap_get_essid(device_info->ap, &ssid);
651 wifi_ap_hidden_create(ssid, &ap);
653 wifi_ap_set_security_type(ap, WIFI_SECURITY_TYPE_NONE);
654 wlan_manager_connect(ap);
656 wlan_manager_connect(device_info->ap);
659 case WIFI_SECURITY_TYPE_WEP:
660 case WIFI_SECURITY_TYPE_WPA_PSK:
661 case WIFI_SECURITY_TYPE_WPA2_PSK:
662 memset(&popup_info, 0, sizeof(pswd_popup_create_req_data_t));
664 dev_info_temp = view_list_item_device_info_create(device_info->ap);
666 popup_info.title = device_info->ssid;
667 popup_info.ok_cb = __passwd_popup_ok_cb;
668 popup_info.cancel_cb = __passwd_popup_cancel_cb;
669 popup_info.show_wps_btn = device_info->wps_mode;
670 popup_info.wps_btn_cb = __wps_options_popup_cb;
671 popup_info.ap = device_info->ap;
672 popup_info.cb_data = dev_info_temp;
673 popup_info.sec_type = sec_type;
675 /* TODO: parameter with device_info */
676 /* TODO: finally parameter with wifi_ap_h, WPA, EAP */
677 ug_app_state->passpopup = create_passwd_popup(
678 ug_app_state->conformant,
679 ug_app_state->layout_main, PACKAGE, &popup_info);
681 if (ug_app_state->passpopup == NULL) {
682 INFO_LOG(UG_NAME_ERR, "Fail to create password popup");
687 case WIFI_SECURITY_TYPE_EAP:
688 ug_app_state->eap_view = create_eap_view(
689 ug_app_state->layout_main, ugd->win_main,
690 ug_app_state->conformant,
691 PACKAGE, device_info,
692 viewer_manager_eap_view_deref);
696 ERROR_LOG(UG_NAME_NORMAL, "Unknown security type[%d]", sec_type);
701 void viewer_list_clear_disconnect_popup(wifi_ap_h ap)
703 if (!g_disconnect_popup)
706 if (ap && g_disconnect_popup->ap &&
707 wlan_manager_is_same_network(g_disconnect_popup->ap, ap) != TRUE)
710 if (g_disconnect_popup->popup)
711 evas_object_del(g_disconnect_popup->popup);
713 if (g_disconnect_popup->ap)
714 wifi_ap_destroy(g_disconnect_popup->ap);
716 g_free(g_disconnect_popup);
717 g_disconnect_popup = NULL;
720 static void __viewer_list_disconnect_cancel_cb(void *data,
721 Evas_Object *obj, void *event_info)
723 struct connecting_cancel_popup_data *popup =
724 (struct connecting_cancel_popup_data *)data;
729 evas_object_del(popup->popup);
732 wifi_ap_destroy(popup->ap);
735 g_disconnect_popup = NULL;
738 static gboolean __viewer_list_update_ap(gpointer data)
740 wifi_ap_h ap = (wifi_ap_h)data;
742 viewer_manager_update_item_favorite_status(ap);
748 static void __viewer_list_disconnect_ok_cb(void *data,
749 Evas_Object *obj, void *event_info)
752 struct connecting_cancel_popup_data *popup =
753 (struct connecting_cancel_popup_data *)data;
757 wlan_manager_disconnect(popup->ap);
758 wlan_manager_forget(popup->ap);
761 evas_object_del(popup->popup);
763 id = common_util_managed_idle_add(__viewer_list_update_ap, (gpointer)popup->ap);
765 viewer_manager_update_item_favorite_status(popup->ap);
766 wifi_ap_destroy(popup->ap);
770 g_disconnect_popup = NULL;
773 static void __viewer_list_disconnect_popup(wifi_device_info_t *device_info,
774 Evas_Object *win_main)
776 popup_btn_info_t popup_data;
777 struct connecting_cancel_popup_data *popup = NULL;
779 memset(&popup_data, 0, sizeof(popup_data));
781 popup = g_try_new0(struct connecting_cancel_popup_data, 1);
785 g_disconnect_popup = popup;
786 wifi_ap_clone(&popup->ap, device_info->ap);
788 popup_data.title_txt = "IDS_WIFI_OPT_FORGET_NETWORK";
789 popup_data.info_txt = "IDS_WIFI_POP_CURRENT_NETWORK_WILL_BE_DISCONNECTED";
790 popup_data.btn1_cb = __viewer_list_disconnect_cancel_cb;
791 popup_data.btn1_txt = "IDS_WIFI_SK_CANCEL";
792 popup_data.btn1_data = popup;
793 popup_data.btn2_cb = __viewer_list_disconnect_ok_cb;
794 popup_data.btn2_txt = "IDS_WIFI_SK_FORGET";
795 popup_data.btn2_data = popup;
797 popup->popup = common_utils_show_info_popup(win_main, &popup_data);
800 static void __viewer_list_item_clicked_cb(void *data, Evas_Object *obj,
803 __COMMON_FUNC_ENTER__;
805 assertm_if(NULL == event_info, "event_info is NULL!!");
806 assertm_if(NULL == obj, "obj is NULL!!");
808 Elm_Object_Item *it = (Elm_Object_Item *)event_info;
809 ug_genlist_data_t *gdata = NULL;
810 wifi_device_info_t *device_info = NULL;
812 gdata = (ug_genlist_data_t *)elm_object_item_data_get(it);
813 retm_if(NULL == gdata);
815 device_info = gdata->device_info;
816 retm_if(NULL == device_info || NULL == device_info->ssid);
818 int item_state = gdata->radio_mode;
819 int current_state = 0;
821 SECURE_INFO_LOG(UG_NAME_NORMAL, "ssid --- %s", device_info->ssid);
822 INFO_LOG(UG_NAME_NORMAL, "ap --- 0x%x", device_info->ap);
823 INFO_LOG(UG_NAME_NORMAL, "current item_state state is --- %d", item_state);
825 if (ug_app_state->is_lbhome == EINA_TRUE &&
826 ug_app_state->app_control != NULL) {
827 INFO_LOG(UG_NAME_NORMAL, "exit with reply");
831 app_control_create(&reply);
832 wifi_ap_get_bssid(device_info->ap, &bssid);
833 SECURE_INFO_LOG(UG_NAME_NORMAL, "bssid %s, ssid %s", bssid, device_info->ssid);
835 app_control_add_extra_data(reply, "bssid", bssid);
836 app_control_add_extra_data(reply, "ssid", device_info->ssid);
837 app_control_reply_to_launch_request(reply, ug_app_state->app_control,
838 APP_CONTROL_RESULT_SUCCEEDED);
839 app_control_destroy(reply);
845 switch (item_state) {
846 case VIEWER_ITEM_RADIO_MODE_OFF:
847 current_state = viewer_manager_header_mode_get();
849 INFO_LOG(UG_NAME_NORMAL, "Clicked AP information\n");
850 INFO_LOG(UG_NAME_NORMAL, "header mode [%d]", current_state);
852 switch (current_state) {
854 case HEADER_MODE_CONNECTED:
855 case HEADER_MODE_CONNECTING:
856 case HEADER_MODE_SEARCHING:
857 viewer_list_wifi_connect(device_info);
860 case HEADER_MODE_OFF:
861 case HEADER_MODE_ACTIVATING:
862 case HEADER_MODE_DEACTIVATING:
864 INFO_LOG(UG_NAME_NORMAL, "Ignore click");
869 case VIEWER_ITEM_RADIO_MODE_CONNECTING:
870 case VIEWER_ITEM_RADIO_MODE_CONFIGURATION:
871 __viewer_list_disconnect_popup(device_info, ug_app_state->layout_main);
873 case VIEWER_ITEM_RADIO_MODE_CONNECTED:
875 INFO_LOG(UG_NAME_NORMAL, "Ignore click");
879 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
881 __COMMON_FUNC_EXIT__;
884 static char *viewer_list_get_device_status_txt(wifi_device_info_t *wifi_device,
885 VIEWER_ITEM_RADIO_MODES mode)
887 char *status_txt = NULL;
888 int current_state = 0;
890 current_state = viewer_manager_header_mode_get();
891 /* The strings are currently hard coded. It will be replaced with string ids later */
892 if (VIEWER_ITEM_RADIO_MODE_CONNECTING == mode) {
893 status_txt = g_strdup(sc(PACKAGE, I18N_TYPE_Connecting));
894 } else if (VIEWER_ITEM_RADIO_MODE_CONFIGURATION == mode) {
895 status_txt = g_strdup(sc(PACKAGE, I18N_TYPE_Obtaining_IP_addr));
896 } else if (VIEWER_ITEM_RADIO_MODE_CONNECTED == mode) {
897 if (connection_manager_is_wifi_connection_used() ||
898 current_state == HEADER_MODE_CONNECTED ) {
899 status_txt = g_strdup(sc(PACKAGE, I18N_TYPE_Connected));
901 } else if (VIEWER_ITEM_RADIO_MODE_OFF == mode) {
902 status_txt = common_utils_get_ap_security_type_info_txt(PACKAGE,
905 status_txt = g_strdup(sc(PACKAGE, I18N_TYPE_Unknown));
906 INFO_LOG(UG_NAME_NORMAL, "Invalid mode: %d", mode);
912 Evas_Object* viewer_list_create(Evas_Object *win)
914 __COMMON_FUNC_ENTER__;
916 assertm_if(NULL == win, "NULL!!");
917 assertm_if(NULL != viewer_list, "Err!!");
919 viewer_list = elm_genlist_add(win);
920 assertm_if(NULL == viewer_list, "NULL!!");
922 // To use multiline textblock/entry/editfield in genlist, set height_for_width mode
923 // then the item's height is calculated while the item's width fits to genlist width.
924 elm_genlist_mode_set(viewer_list, ELM_LIST_COMPRESS);
925 //elm_genlist_realization_mode_set(viewer_list, EINA_TRUE);
927 evas_object_size_hint_weight_set(viewer_list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
928 evas_object_size_hint_align_set(viewer_list, EVAS_HINT_FILL, EVAS_HINT_FILL);
930 itc.item_style = WIFI_GENLIST_2LINE_TOP_TEXT_ICON_STYLE;
931 itc.func.text_get = _gl_listview_text_get;
932 itc.func.content_get = _gl_listview_content_get;
933 itc.func.state_get = NULL;
934 itc.func.del = _gl_listview_del;
936 no_wifi_device_itc.item_style = WIFI_GENLIST_1LINE_TEXT_STYLE;
937 no_wifi_device_itc.func.text_get = _gl_listview_text_get;
938 no_wifi_device_itc.func.content_get = NULL;
939 no_wifi_device_itc.func.state_get = NULL;
940 no_wifi_device_itc.func.del = _gl_listview_del;
942 first_item = last_item = NULL;
944 evas_object_smart_callback_add(viewer_list, "realized",
946 evas_object_smart_callback_add(viewer_list, "language,changed",
947 gl_lang_changed, NULL);
949 __COMMON_FUNC_EXIT__;
953 void viewer_list_title_item_del(void)
955 if (grouptitle != NULL) {
956 elm_object_item_del(grouptitle);
961 void viewer_list_title_item_update(void)
963 if (grouptitle != NULL)
964 elm_genlist_item_update(grouptitle);
967 void viewer_list_title_item_set(Elm_Object_Item *item_header)
969 if (item_header == NULL)
972 if (grouptitle != NULL) {
973 elm_genlist_item_update(grouptitle);
977 memset(&grouptitle_itc, 0, sizeof(grouptitle_itc));
978 grouptitle_itc.item_style = WIFI_GENLIST_GROUP_INDEX_STYLE;
979 grouptitle_itc.func.text_get = _gl_text_available_networks_get;
980 grouptitle_itc.func.content_get = _gl_content_scanning_icon_get;
982 grouptitle = elm_genlist_item_insert_after(viewer_list,
983 &grouptitle_itc, NULL, NULL, item_header,
984 ELM_GENLIST_ITEM_NONE, NULL, NULL);
986 assertm_if(NULL == grouptitle, "NULL!!");
988 elm_genlist_item_select_mode_set(grouptitle,
989 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
992 int viewer_list_item_radio_mode_set(Elm_Object_Item* item,
993 VIEWER_ITEM_RADIO_MODES mode)
995 __COMMON_FUNC_ENTER__;
998 INFO_LOG(COMMON_NAME_ERR, "item is NULL");
1002 ug_genlist_data_t* gdata = (ug_genlist_data_t *) elm_object_item_data_get(item);
1003 if (NULL == gdata || NULL == gdata->device_info) {
1004 INFO_LOG(COMMON_NAME_ERR, "gdata or device_info is NULL");
1008 if (gdata->radio_mode == mode) {
1009 SECURE_INFO_LOG(UG_NAME_NORMAL, "[%s] is already in requested state", gdata->device_info->ssid);
1013 SECURE_INFO_LOG(UG_NAME_NORMAL, "[%s] AP Item State Transition from [%d] --> [%d]", gdata->device_info->ssid, gdata->radio_mode, mode);
1014 gdata->radio_mode = mode;
1015 if (gdata->device_info->ap_status_txt) {
1016 g_free(gdata->device_info->ap_status_txt);
1017 gdata->device_info->ap_status_txt = viewer_list_get_device_status_txt(gdata->device_info, mode);
1021 elm_genlist_item_update(item);
1023 __COMMON_FUNC_EXIT__;
1027 static wifi_connection_state_e _convert_wifi_state_to_viewer_radio_mode(
1028 wifi_connection_state_e state)
1031 case WIFI_CONNECTION_STATE_ASSOCIATION:
1032 return VIEWER_ITEM_RADIO_MODE_CONNECTING;
1033 case WIFI_CONNECTION_STATE_CONFIGURATION:
1034 return VIEWER_ITEM_RADIO_MODE_CONFIGURATION;
1035 case WIFI_CONNECTION_STATE_CONNECTED:
1036 return VIEWER_ITEM_RADIO_MODE_CONNECTED;
1038 return VIEWER_ITEM_RADIO_MODE_OFF;
1042 Elm_Object_Item *viewer_list_item_insert_after(wifi_device_info_t *wifi_device,
1043 Elm_Object_Item *after)
1045 Elm_Object_Item* ret = NULL;
1046 ug_genlist_data_t* gdata = NULL;
1047 wifi_device_info_t *no_wifi_device = NULL;
1048 wifi_connection_state_e state = WIFI_CONNECTION_STATE_DISCONNECTED;
1049 VIEWER_ITEM_RADIO_MODES rad_mode = VIEWER_ITEM_RADIO_MODE_OFF;
1050 retvm_if(NULL == viewer_list, NULL);
1052 if (wifi_device != NULL) {
1053 if (wifi_ap_get_connection_state(wifi_device->ap, &state) ==
1055 rad_mode = _convert_wifi_state_to_viewer_radio_mode(state);
1057 wifi_device->ap_status_txt = viewer_list_get_device_status_txt(
1061 if (ug_app_state->is_first_scan == true) {
1062 int scan_result = wlan_manager_scan();
1063 if (scan_result != WLAN_MANAGER_ERR_NONE) {
1064 viewer_manager_hide(VIEWER_WINSET_SEARCHING);
1065 viewer_manager_header_mode_set(viewer_manager_header_mode_get());
1067 ug_app_state->is_first_scan = false;
1070 no_wifi_device = g_try_new0(wifi_device_info_t, 1);
1071 if (no_wifi_device == NULL)
1074 no_wifi_device->ssid = g_strdup(sc(PACKAGE, I18N_TYPE_No_Wi_Fi_AP_Found));
1076 wifi_device = no_wifi_device;
1079 gdata = g_try_new0(ug_genlist_data_t, 1);
1080 retvm_if(NULL == gdata, NULL);
1081 gdata->device_info = wifi_device;
1082 gdata->radio_mode = VIEWER_ITEM_RADIO_MODE_OFF;
1085 /* If the after item is NULL then insert it as first item */
1089 if (no_wifi_device == NULL) {
1090 ret = elm_genlist_item_insert_after(
1091 viewer_list, /*obj*/
1095 after, /*after than*/
1096 ELM_GENLIST_ITEM_NONE, /*flags*/
1097 __viewer_list_item_clicked_cb,/*func*/
1100 ret = elm_genlist_item_insert_after(
1101 viewer_list, /*obj*/
1102 &no_wifi_device_itc,/*itc*/
1105 after, /*after than*/
1106 ELM_GENLIST_ITEM_NONE, /*flags*/
1107 __viewer_list_item_clicked_cb,/*func*/
1112 assertm_if(NULL == ret, "NULL!!");
1115 /* SECURE_DEBUG_LOG(UG_NAME_NORMAL,
1116 "* item add complete item [0x%x] ssid:[%s] security[%d] size:[%d]",
1119 wifi_device->security_mode,
1120 viewer_list_item_size_get()); */
1122 if (after == grouptitle) {
1135 elm_genlist_item_update(ret);
1141 void viewer_list_item_del(Elm_Object_Item *it)
1147 if (it == first_item) {
1148 first_item = elm_genlist_item_next_get(first_item);
1149 } else if (it == last_item) {
1150 last_item = elm_genlist_item_prev_get(last_item);
1152 elm_object_item_del(it);
1155 int viewer_list_item_size_get()
1158 Elm_Object_Item *it = first_item;
1162 if (it == last_item) {
1165 it = elm_genlist_item_next_get(it);
1171 void viewer_list_item_clear(void)
1173 __COMMON_FUNC_ENTER__;
1175 Elm_Object_Item *it = first_item;
1176 Elm_Object_Item *nxt = NULL;
1179 nxt = elm_genlist_item_next_get(it);
1180 elm_object_item_del(it);
1181 if (it == last_item) {
1187 first_item = last_item = NULL;
1189 __COMMON_FUNC_EXIT__;
1192 void viewer_list_item_enable_all(void)
1194 __COMMON_FUNC_ENTER__;
1196 Elm_Object_Item *it = first_item;
1199 elm_object_item_disabled_set(it, EINA_FALSE);
1201 if (it == last_item) {
1205 it = elm_genlist_item_next_get(it);
1208 __COMMON_FUNC_EXIT__;
1211 void viewer_list_item_disable_all(void)
1213 __COMMON_FUNC_ENTER__;
1215 Elm_Object_Item *it = first_item;
1218 elm_object_item_disabled_set(it, EINA_TRUE);
1220 if (it == last_item) {
1224 it = elm_genlist_item_next_get(it);
1227 __COMMON_FUNC_EXIT__;
1230 Elm_Object_Item* item_get_for_ap(wifi_ap_h ap)
1232 __COMMON_FUNC_ENTER__;
1234 __COMMON_FUNC_EXIT__;
1239 wifi_security_type_e type = WIFI_SECURITY_TYPE_NONE;
1241 if (WIFI_ERROR_NONE != wifi_ap_get_essid(ap, &essid)) {
1242 __COMMON_FUNC_EXIT__;
1244 } else if (WIFI_ERROR_NONE != wifi_ap_get_security_type(ap, &type)) {
1245 __COMMON_FUNC_EXIT__;
1249 Elm_Object_Item *it = first_item;
1250 wlan_security_mode_type_t sec_mode = common_utils_get_sec_mode(type);
1252 ug_genlist_data_t* gdata = elm_object_item_data_get(it);
1253 wifi_device_info_t *device_info = NULL;
1254 if (gdata && (device_info = gdata->device_info)) {
1255 if (!g_strcmp0(device_info->ssid, essid) && device_info->security_mode == sec_mode) {
1259 if (it == last_item) {
1263 it = elm_genlist_item_next_get(it);
1267 __COMMON_FUNC_EXIT__;
1271 Elm_Object_Item* item_get_for_ssid(const char *ssid)
1273 Elm_Object_Item *it = first_item;
1275 ug_genlist_data_t* gdata = elm_object_item_data_get(it);
1276 wifi_device_info_t *device_info = NULL;
1277 if (gdata && (device_info = gdata->device_info)) {
1278 if (!g_strcmp0(device_info->ssid, ssid)) {
1282 if (it == last_item) {
1286 it = elm_genlist_item_next_get(it);