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)
90 int r = 0, g = 0, b = 0, a = 0;
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!!");
101 if (VIEWER_ITEM_RADIO_MODE_CONNECTED == gdata->radio_mode) {
102 edje_color_class_get("T024S",&r, &g, &b, &a,
103 NULL, NULL, NULL, NULL,
104 NULL, NULL, NULL, NULL);
105 buf = g_strdup_printf("<color=#%s>%s</color>",
106 ConvertRGBAtoHex(r, g, b, a), det);
111 } else if (!strcmp("elm.text.sub", part)
112 && gdata->device_info->ap_status_txt != NULL) {
113 det = g_strdup(gdata->device_info->ap_status_txt);
115 assertm_if(NULL == det, "NULL!!");
120 static Evas_Object *_gl_listview_content_get(void *data, Evas_Object *obj, const char *part)
122 ug_genlist_data_t *gdata = (ug_genlist_data_t *)data;
123 retvm_if(NULL == gdata, NULL);
125 Evas_Object *icon = NULL;
126 Evas_Object *btn = NULL;
127 Evas_Object *ic = 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 ic = elm_layout_add(obj);
135 elm_layout_theme_set(ic, "layout", "list/B/type.3", "default");
137 icon = elm_image_add(ic);
138 retvm_if(NULL == icon, NULL);
141 char *temp_str = NULL;
142 temp_str = g_strdup_printf("%s.png", gdata->device_info->ap_image_path);
143 elm_image_file_set(icon, CUSTOM_EDITFIELD_PATH, temp_str);
146 evas_object_color_set(icon, 2, 61, 132, 204);
148 evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, EVAS_HINT_FILL);
149 evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
150 elm_layout_content_set(ic, "elm.swallow.content", icon);
152 } else if (!strcmp("elm.swallow.end", part)) {
153 if (VIEWER_ITEM_RADIO_MODE_CONNECTING == gdata->radio_mode ||
154 VIEWER_ITEM_RADIO_MODE_CONFIGURATION == gdata->radio_mode) {
155 ic = elm_layout_add(obj);
156 elm_layout_theme_set(ic, "layout", "list/C/type.2", "default");
158 icon = elm_progressbar_add(ic);
160 elm_object_style_set(icon, "process_medium");
161 evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, 0.5);
162 evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
163 elm_progressbar_pulse(icon, TRUE);
164 elm_layout_content_set(ic, "elm.swallow.content", icon);
165 evas_object_propagate_events_set(icon, EINA_FALSE);
168 btn = elm_button_add(obj);
169 elm_object_style_set(btn, "circle_custom");
170 icon = elm_image_add(btn);
171 elm_image_file_set(icon, CUSTOM_EDITFIELD_PATH, "wifi_icon_badge_info.png");
172 elm_image_resizable_set(icon, EINA_TRUE, EINA_TRUE);
173 elm_object_part_content_set(btn, "elm.swallow.content", icon);
174 evas_object_propagate_events_set(btn, EINA_FALSE);
175 evas_object_smart_callback_add(btn, "clicked", _gl_listview_more_btn_cb,gdata->device_info);
176 evas_object_show(btn);
184 static void _gl_listview_del(void *data, Evas_Object *obj)
189 ug_genlist_data_t *gdata = (ug_genlist_data_t *)data;
190 retm_if(NULL == gdata || NULL == gdata->device_info);
192 g_free(gdata->device_info->ap_image_path);
193 g_free(gdata->device_info->ap_status_txt);
194 g_free(gdata->device_info->ssid);
195 wifi_ap_destroy(gdata->device_info->ap);
196 g_free(gdata->device_info);
200 static char *_gl_text_available_networks_get(void *data, Evas_Object *obj,
203 if (!strcmp("elm.text", part))
204 return g_strdup(sc(PACKAGE, I18N_TYPE_Available_networks));
209 static Evas_Object *_gl_content_scanning_icon_get(void *data, Evas_Object *obj,
212 Evas_Object *title_progressbar = NULL;
214 if (HEADER_MODE_SEARCHING == viewer_manager_header_mode_get()) {
215 title_progressbar = elm_progressbar_add(obj);
216 elm_object_style_set(title_progressbar, "process_small");
217 elm_progressbar_horizontal_set(title_progressbar, EINA_TRUE);
218 elm_progressbar_pulse(title_progressbar, EINA_TRUE);
221 return title_progressbar;
224 Elm_Object_Item* viewer_list_get_first_item(void)
229 Elm_Object_Item* viewer_list_get_last_item(void)
234 #ifdef ACCESSIBLITY_FEATURE
235 static char *_access_info_cb(void *data, Evas_Object *obj)
237 char *strength = NULL;
240 ug_genlist_data_t *gdata = (ug_genlist_data_t *)data;
245 strength = common_utils_get_rssi_text(PACKAGE, gdata->device_info->rssi);
246 buf = g_strdup_printf("%s. %s. %s.", strength, gdata->device_info->ssid, gdata->device_info->ap_status_txt);
253 static void gl_lang_changed(void *data, Evas_Object *obj, void *event_info)
255 elm_genlist_realized_items_update(obj);
258 static void _gl_realized(void *data, Evas_Object *obj, void *event_info)
260 #ifdef ACCESSIBLITY_FEATURE
261 HEADER_MODES header_mode = viewer_manager_header_mode_get();
262 Elm_Object_Item *item = (Elm_Object_Item *)event_info;
264 if (header_mode == HEADER_MODE_ACTIVATING ||
265 header_mode == HEADER_MODE_DEACTIVATING ||
266 header_mode == HEADER_MODE_OFF) {
270 Elm_Object_Item *first_item = viewer_list_get_first_item();
271 Elm_Object_Item *last_item = viewer_list_get_last_item();
273 if (first_item == NULL || last_item == NULL) {
277 int index = (int)elm_genlist_item_index_get(item);
278 int first_item_index = (int)elm_genlist_item_index_get(first_item);
279 int last_item_index = (int)elm_genlist_item_index_get(last_item);
282 if (first_item_index == -1) {
283 int group_index = (int)elm_genlist_item_index_get(grouptitle);
284 first_item_index = group_index + 1;
287 if (index >= first_item_index && index <= last_item_index &&
288 first_item_index < last_item_index) {
290 Evas_Object *ao = elm_object_item_access_object_get(item);
291 elm_access_info_cb_set(ao, ELM_ACCESS_INFO, _access_info_cb, elm_object_item_data_get(item));
292 g_snprintf(buf, sizeof(buf), "%s%s",
293 sc(PACKAGE, I18N_TYPE_Double_tap),
294 sc(PACKAGE, I18N_TYPE_Connect_to_device));
295 elm_access_info_set(ao, ELM_ACCESS_TYPE, buf);
296 elm_access_info_set(ao, ELM_ACCESS_STATE, sc(PACKAGE, I18N_TYPE_Wi_Fi_network_info));
299 if (ug_app_state->ug_type == UG_VIEW_SETUP_WIZARD &&
300 first_item_index == index) {
301 viewer_manager_setup_wizard_btns_color_set(TRUE);
304 Elm_Object_Item *item = (Elm_Object_Item *)event_info;
305 Elm_Object_Item *first_item = viewer_list_get_first_item();
307 if (first_item == NULL) {
311 int index = (int)elm_genlist_item_index_get(item);
312 int first_item_index = (int)elm_genlist_item_index_get(first_item);
314 if (first_item_index == -1) {
315 int group_index = (int)elm_genlist_item_index_get(grouptitle);
316 first_item_index = group_index + 1;
319 if (ug_app_state->ug_type == UG_VIEW_SETUP_WIZARD &&
320 first_item_index == index) {
321 viewer_manager_setup_wizard_btns_color_set(TRUE);
326 static void _info_popup_ok_cb(void *data, Evas_Object *obj, void *event_info)
328 pswd_popup_t *passpopup = (pswd_popup_t *)data;
330 if (passpopup != NULL && passpopup->info_popup != NULL) {
331 evas_object_del(passpopup->info_popup);
332 passpopup->info_popup = NULL;
336 static void __passwd_popup_cancel_cb(void *data, Evas_Object *obj,
339 __COMMON_FUNC_ENTER__;
341 if (ug_app_state->passpopup == NULL) {
345 passwd_popup_free(ug_app_state->passpopup);
346 ug_app_state->passpopup = NULL;
352 __COMMON_FUNC_EXIT__;
355 static void __passwd_popup_ok_cb(void *data, Evas_Object *obj, void *event_info)
357 __COMMON_FUNC_ENTER__;
360 int password_len = 0;
361 const char *password = NULL;
362 wifi_security_type_e sec_type = WIFI_SECURITY_TYPE_NONE;
364 if (ug_app_state->passpopup == NULL) {
368 ap = passwd_popup_get_ap(ug_app_state->passpopup);
369 password = passwd_popup_get_txt(ug_app_state->passpopup);
370 if (password != NULL)
371 password_len = strlen(password);
373 wifi_ap_get_security_type(ap, &sec_type);
376 case WIFI_SECURITY_TYPE_WEP:
377 if (password_len != 5 && password_len != 13 &&
378 password_len != 26 && password_len != 10) {
379 common_utils_send_message_to_net_popup(
380 "Network connection popup",
381 "wrong password", "toast_popup", NULL);
383 if (ug_app_state->passpopup->entry) {
384 elm_object_focus_set(
385 ug_app_state->passpopup->entry,
392 case WIFI_SECURITY_TYPE_WPA_PSK:
393 case WIFI_SECURITY_TYPE_WPA2_PSK:
394 if (password_len < 8 || password_len > 64) {
395 common_utils_send_message_to_net_popup(
396 "Network connection popup",
397 "wrong password", "toast_popup", NULL);
399 if (ug_app_state->passpopup->entry) {
400 elm_object_focus_set(
401 ug_app_state->passpopup->entry,
409 ERROR_LOG(UG_NAME_NORMAL, "Wrong security mode: %d", sec_type);
410 passwd_popup_free(ug_app_state->passpopup);
411 ug_app_state->passpopup = NULL;
413 goto popup_ok_cb_exit;
416 bool favorite = FALSE;
417 if(wifi_ap_is_favorite(ap, &favorite) == WIFI_ERROR_NONE
418 && favorite == TRUE) {
419 wlan_manager_forget(ap);
423 if (ug_app_state->is_hidden) {
426 wifi_ap_get_essid(ap, &ssid);
427 wifi_ap_hidden_create(ssid, &hidden_ap);
429 wifi_ap_set_security_type(hidden_ap, sec_type);
430 wlan_manager_connect_with_password(hidden_ap, password);
432 wlan_manager_connect_with_password(ap, password);
434 passwd_popup_free(ug_app_state->passpopup);
435 ug_app_state->passpopup = NULL;
443 g_free((gpointer)password);
445 __COMMON_FUNC_EXIT__;
448 static void __wps_pbc_popup_cancel_connecting(void *data, Evas_Object *obj,
451 __COMMON_FUNC_ENTER__;
453 if (ug_app_state->passpopup == NULL) {
457 wifi_ap_h ap = passwd_popup_get_ap(ug_app_state->passpopup);
459 int ret = wlan_manager_disconnect(ap);
460 if (ret != WLAN_MANAGER_ERR_NONE) {
461 ERROR_LOG(UG_NAME_NORMAL, "Failed WPS PBC cancellation [0x%x]", ap);
464 passwd_popup_free(ug_app_state->passpopup);
465 ug_app_state->passpopup = NULL;
467 viewer_manager_header_mode_set(HEADER_MODE_ON);
469 __COMMON_FUNC_EXIT__;
472 static void _wps_btn_cb(void* data, Evas_Object* obj, void* event_info)
474 __COMMON_FUNC_ENTER__;
476 if (!ug_app_state->passpopup) {
480 wifi_ap_h ap = passwd_popup_get_ap(ug_app_state->passpopup);
481 int ret = wlan_manager_wps_connect(ap);
482 if (ret == WLAN_MANAGER_ERR_NONE) {
483 create_pbc_popup(ug_app_state->passpopup,
484 __wps_pbc_popup_cancel_connecting, NULL,
485 POPUP_WPS_BTN, NULL);
487 ERROR_LOG(UG_NAME_NORMAL, "wlan_manager_wps_connect failed");
488 passwd_popup_free(ug_app_state->passpopup);
489 ug_app_state->passpopup = NULL;
492 __COMMON_FUNC_EXIT__;
495 static void _wps_cancel_cb(void* data, Evas_Object* obj, void* event_info)
497 __COMMON_FUNC_ENTER__;
499 if (ug_app_state->passpopup == NULL) {
503 current_popup_free(ug_app_state->passpopup, POPUP_WPS_OPTIONS);
505 __COMMON_FUNC_EXIT__;
508 static void _wps_pin_cb(void* data, Evas_Object* obj, void* event_info)
510 __COMMON_FUNC_ENTER__;
511 unsigned int rpin = 0;
512 char npin[9] = { '\0' };
514 int ret = WLAN_MANAGER_ERR_NONE;
516 Evas_Object *info_popup = NULL;
518 if (!ug_app_state->passpopup) {
522 /* Generate WPS pin */
523 rpin = wps_generate_pin();
525 g_snprintf(npin, sizeof(npin), "%08d", rpin);
527 pin_len = strlen(npin);
529 info_popup = common_utils_show_info_ok_popup(
530 ug_app_state->layout_main, PACKAGE,
531 sc(PACKAGE, I18N_TYPE_Invalid_pin),
533 ug_app_state->passpopup);
534 ug_app_state->passpopup->info_popup = info_popup;
536 __COMMON_FUNC_EXIT__;
540 ap = passwd_popup_get_ap(ug_app_state->passpopup);
542 ret = wlan_manager_wps_pin_connect(ap, npin);
543 if (ret == WLAN_MANAGER_ERR_NONE) {
544 INFO_LOG(UG_NAME_NORMAL, "wlan_manager_wps_pin_connect successful");
546 create_pbc_popup(ug_app_state->passpopup,
547 __wps_pbc_popup_cancel_connecting, NULL,
548 POPUP_WPS_PIN, npin);
550 ERROR_LOG(UG_NAME_NORMAL, "wlan_manager_wps_pin_connect failed");
551 passwd_popup_free(ug_app_state->passpopup);
552 ug_app_state->passpopup = NULL;
555 __COMMON_FUNC_EXIT__;
558 static void __wps_options_popup_cb(void* data, Evas_Object* obj, void* event_info)
560 __COMMON_FUNC_ENTER__;
561 pswd_popup_create_req_data_t popup_info;
563 if (!ug_app_state->passpopup) {
567 memset(&popup_info, 0, sizeof(pswd_popup_create_req_data_t));
569 popup_info.title = "IDS_WIFI_HEADER_SELECT_WPS_METHOD_ABB";
570 popup_info.ok_cb = NULL;
571 popup_info.cancel_cb = _wps_cancel_cb;
572 popup_info.show_wps_btn = EINA_FALSE;
573 popup_info.wps_btn_cb = _wps_btn_cb;
574 popup_info.wps_pin_cb = _wps_pin_cb;
575 popup_info.ap = passwd_popup_get_ap(ug_app_state->passpopup);
576 popup_info.cb_data = NULL;
577 create_wps_options_popup(ug_app_state->layout_main, ug_app_state->passpopup,
580 __COMMON_FUNC_EXIT__;
583 void viewer_list_wifi_reconnect(wifi_device_info_t *device_info)
585 pswd_popup_create_req_data_t popup_info;
586 wifi_security_type_e sec_type = WIFI_SECURITY_TYPE_NONE;
587 wifi_device_info_t *device_info_temp = NULL;
588 struct ug_data *ugd = (struct ug_data *)ug_app_state->gadget;
590 if (device_info == NULL)
593 if (ug_app_state->passpopup != NULL || ug_app_state->eap_view != NULL) {
594 INFO_LOG(UG_NAME_ERR, "already launched popup");
598 wifi_ap_get_security_type(device_info->ap, &sec_type);
601 case WIFI_SECURITY_TYPE_WEP:
602 case WIFI_SECURITY_TYPE_WPA_PSK:
603 case WIFI_SECURITY_TYPE_WPA2_PSK:
604 memset(&popup_info, 0, sizeof(pswd_popup_create_req_data_t));
606 device_info_temp = view_list_item_device_info_create(device_info->ap);
608 popup_info.title = device_info->ssid;
609 popup_info.ok_cb = __passwd_popup_ok_cb;
610 popup_info.cancel_cb = __passwd_popup_cancel_cb;
611 popup_info.show_wps_btn = device_info->wps_mode;
612 popup_info.wps_btn_cb = __wps_options_popup_cb;
613 popup_info.ap = device_info->ap;
614 popup_info.cb_data = device_info_temp;
615 popup_info.sec_type = sec_type;
617 /* TODO: parameter with device_info */
618 /* TODO: finally parameter with wifi_ap_h, WPA, EAP */
619 ug_app_state->passpopup = create_passwd_popup(
620 ug_app_state->conformant,
621 ug_app_state->layout_main, PACKAGE, &popup_info);
623 if (ug_app_state->passpopup == NULL) {
624 INFO_LOG(UG_NAME_ERR, "Fail to create password popup");
628 case WIFI_SECURITY_TYPE_EAP:
629 ug_app_state->eap_view = create_eap_view(
630 ug_app_state->layout_main, ugd->win_main,
631 ug_app_state->conformant,
632 PACKAGE, device_info,
633 viewer_manager_eap_view_deref);
636 ERROR_LOG(UG_NAME_NORMAL, "Unknown security type [%d]", sec_type);
642 void viewer_list_wifi_connect(wifi_device_info_t *device_info)
644 bool favorite = false;
645 pswd_popup_create_req_data_t popup_info;
646 wifi_security_type_e sec_type = WIFI_SECURITY_TYPE_NONE;
647 wifi_device_info_t *dev_info_temp = NULL;
648 struct ug_data *ugd = (struct ug_data *)ug_app_state->gadget;
650 if (device_info == NULL)
653 wifi_ap_is_favorite(device_info->ap, &favorite);
654 if (favorite == true) {
655 wlan_manager_connect(device_info->ap);
659 if (ug_app_state->passpopup != NULL || ug_app_state->eap_view != NULL) {
660 INFO_LOG(UG_NAME_ERR, "already launched popup");
664 wifi_ap_get_security_type(device_info->ap, &sec_type);
667 case WIFI_SECURITY_TYPE_NONE:
668 if(ug_app_state->is_hidden) {
671 wifi_ap_get_essid(device_info->ap, &ssid);
672 wifi_ap_hidden_create(ssid, &ap);
674 wifi_ap_set_security_type(ap, WIFI_SECURITY_TYPE_NONE);
675 wlan_manager_connect(ap);
677 wlan_manager_connect(device_info->ap);
680 case WIFI_SECURITY_TYPE_WEP:
681 case WIFI_SECURITY_TYPE_WPA_PSK:
682 case WIFI_SECURITY_TYPE_WPA2_PSK:
683 memset(&popup_info, 0, sizeof(pswd_popup_create_req_data_t));
685 dev_info_temp = view_list_item_device_info_create(device_info->ap);
687 popup_info.title = device_info->ssid;
688 popup_info.ok_cb = __passwd_popup_ok_cb;
689 popup_info.cancel_cb = __passwd_popup_cancel_cb;
690 popup_info.show_wps_btn = device_info->wps_mode;
691 popup_info.wps_btn_cb = __wps_options_popup_cb;
692 popup_info.ap = device_info->ap;
693 popup_info.cb_data = dev_info_temp;
694 popup_info.sec_type = sec_type;
696 /* TODO: parameter with device_info */
697 /* TODO: finally parameter with wifi_ap_h, WPA, EAP */
698 ug_app_state->passpopup = create_passwd_popup(
699 ug_app_state->conformant,
700 ug_app_state->layout_main, PACKAGE, &popup_info);
702 if (ug_app_state->passpopup == NULL) {
703 INFO_LOG(UG_NAME_ERR, "Fail to create password popup");
708 case WIFI_SECURITY_TYPE_EAP:
709 ug_app_state->eap_view = create_eap_view(
710 ug_app_state->layout_main, ugd->win_main,
711 ug_app_state->conformant,
712 PACKAGE, device_info,
713 viewer_manager_eap_view_deref);
717 ERROR_LOG(UG_NAME_NORMAL, "Unknown security type[%d]", sec_type);
722 void viewer_list_clear_disconnect_popup(wifi_ap_h ap)
724 if (!g_disconnect_popup)
727 if (ap && g_disconnect_popup->ap &&
728 wlan_manager_is_same_network(g_disconnect_popup->ap, ap) != TRUE)
731 if (g_disconnect_popup->popup)
732 evas_object_del(g_disconnect_popup->popup);
734 if (g_disconnect_popup->ap)
735 wifi_ap_destroy(g_disconnect_popup->ap);
737 g_free(g_disconnect_popup);
738 g_disconnect_popup = NULL;
741 static void __viewer_list_disconnect_cancel_cb(void *data,
742 Evas_Object *obj, void *event_info)
744 struct connecting_cancel_popup_data *popup =
745 (struct connecting_cancel_popup_data *)data;
750 evas_object_del(popup->popup);
753 wifi_ap_destroy(popup->ap);
756 g_disconnect_popup = NULL;
759 static gboolean __viewer_list_update_ap(gpointer data)
761 wifi_ap_h ap = (wifi_ap_h)data;
763 viewer_manager_update_item_favorite_status(ap);
769 static void __viewer_list_disconnect_ok_cb(void *data,
770 Evas_Object *obj, void *event_info)
773 struct connecting_cancel_popup_data *popup =
774 (struct connecting_cancel_popup_data *)data;
778 wlan_manager_disconnect(popup->ap);
779 wlan_manager_forget(popup->ap);
782 evas_object_del(popup->popup);
784 id = common_util_managed_idle_add(__viewer_list_update_ap, (gpointer)popup->ap);
786 viewer_manager_update_item_favorite_status(popup->ap);
787 wifi_ap_destroy(popup->ap);
791 g_disconnect_popup = NULL;
794 static void __viewer_list_disconnect_popup(wifi_device_info_t *device_info,
795 Evas_Object *win_main)
797 popup_btn_info_t popup_data;
798 struct connecting_cancel_popup_data *popup = NULL;
800 memset(&popup_data, 0, sizeof(popup_data));
802 popup = g_try_new0(struct connecting_cancel_popup_data, 1);
806 g_disconnect_popup = popup;
807 wifi_ap_clone(&popup->ap, device_info->ap);
809 popup_data.title_txt = "IDS_WIFI_OPT_FORGET_NETWORK";
810 popup_data.info_txt = "IDS_WIFI_POP_CURRENT_NETWORK_WILL_BE_DISCONNECTED";
811 popup_data.btn1_cb = __viewer_list_disconnect_cancel_cb;
812 popup_data.btn1_txt = "IDS_WIFI_SK_CANCEL";
813 popup_data.btn1_data = popup;
814 popup_data.btn2_cb = __viewer_list_disconnect_ok_cb;
815 popup_data.btn2_txt = "IDS_WIFI_SK_FORGET";
816 popup_data.btn2_data = popup;
818 popup->popup = common_utils_show_info_popup(win_main, &popup_data);
821 static void __viewer_list_item_clicked_cb(void *data, Evas_Object *obj,
824 __COMMON_FUNC_ENTER__;
826 assertm_if(NULL == event_info, "event_info is NULL!!");
827 assertm_if(NULL == obj, "obj is NULL!!");
829 Elm_Object_Item *it = (Elm_Object_Item *)event_info;
830 ug_genlist_data_t *gdata = NULL;
831 wifi_device_info_t *device_info = NULL;
833 gdata = (ug_genlist_data_t *)elm_object_item_data_get(it);
834 retm_if(NULL == gdata);
836 device_info = gdata->device_info;
837 retm_if(NULL == device_info || NULL == device_info->ssid);
839 int item_state = gdata->radio_mode;
840 int current_state = 0;
842 SECURE_INFO_LOG(UG_NAME_NORMAL, "ssid --- %s", device_info->ssid);
843 INFO_LOG(UG_NAME_NORMAL, "ap --- 0x%x", device_info->ap);
844 INFO_LOG(UG_NAME_NORMAL, "current item_state state is --- %d", item_state);
846 if (ug_app_state->is_lbhome == EINA_TRUE &&
847 ug_app_state->app_control != NULL) {
848 INFO_LOG(UG_NAME_NORMAL, "exit with reply");
852 app_control_create(&reply);
853 wifi_ap_get_bssid(device_info->ap, &bssid);
854 SECURE_INFO_LOG(UG_NAME_NORMAL, "bssid %s, ssid %s", bssid, device_info->ssid);
856 app_control_add_extra_data(reply, "bssid", bssid);
857 app_control_add_extra_data(reply, "ssid", device_info->ssid);
858 app_control_reply_to_launch_request(reply, ug_app_state->app_control,
859 APP_CONTROL_RESULT_SUCCEEDED);
860 app_control_destroy(reply);
866 switch (item_state) {
867 case VIEWER_ITEM_RADIO_MODE_OFF:
868 current_state = viewer_manager_header_mode_get();
870 INFO_LOG(UG_NAME_NORMAL, "Clicked AP information\n");
871 INFO_LOG(UG_NAME_NORMAL, "header mode [%d]", current_state);
873 switch (current_state) {
875 case HEADER_MODE_CONNECTED:
876 case HEADER_MODE_CONNECTING:
877 case HEADER_MODE_SEARCHING:
878 viewer_list_wifi_connect(device_info);
881 case HEADER_MODE_OFF:
882 case HEADER_MODE_ACTIVATING:
883 case HEADER_MODE_DEACTIVATING:
885 INFO_LOG(UG_NAME_NORMAL, "Ignore click");
890 case VIEWER_ITEM_RADIO_MODE_CONNECTING:
891 case VIEWER_ITEM_RADIO_MODE_CONFIGURATION:
892 __viewer_list_disconnect_popup(device_info, ug_app_state->layout_main);
894 case VIEWER_ITEM_RADIO_MODE_CONNECTED:
896 INFO_LOG(UG_NAME_NORMAL, "Ignore click");
900 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
902 __COMMON_FUNC_EXIT__;
905 static char *viewer_list_get_device_status_txt(wifi_device_info_t *wifi_device,
906 VIEWER_ITEM_RADIO_MODES mode)
908 char *status_txt = NULL;
909 int current_state = 0;
911 current_state = viewer_manager_header_mode_get();
912 /* The strings are currently hard coded. It will be replaced with string ids later */
913 if (VIEWER_ITEM_RADIO_MODE_CONNECTING == mode) {
914 status_txt = g_strdup(sc(PACKAGE, I18N_TYPE_Connecting));
915 } else if (VIEWER_ITEM_RADIO_MODE_CONFIGURATION == mode) {
916 status_txt = g_strdup(sc(PACKAGE, I18N_TYPE_Obtaining_IP_addr));
917 } else if (VIEWER_ITEM_RADIO_MODE_CONNECTED == mode) {
918 if (connection_manager_is_wifi_connection_used() ||
919 current_state == HEADER_MODE_CONNECTED ) {
920 status_txt = g_strdup(sc(PACKAGE, I18N_TYPE_Connected));
922 } else if (VIEWER_ITEM_RADIO_MODE_OFF == mode) {
923 status_txt = common_utils_get_ap_security_type_info_txt(PACKAGE,
926 status_txt = g_strdup(sc(PACKAGE, I18N_TYPE_Unknown));
927 INFO_LOG(UG_NAME_NORMAL, "Invalid mode: %d", mode);
933 Evas_Object* viewer_list_create(Evas_Object *win)
935 __COMMON_FUNC_ENTER__;
937 assertm_if(NULL == win, "NULL!!");
938 assertm_if(NULL != viewer_list, "Err!!");
940 viewer_list = elm_genlist_add(win);
941 assertm_if(NULL == viewer_list, "NULL!!");
943 // To use multiline textblock/entry/editfield in genlist, set height_for_width mode
944 // then the item's height is calculated while the item's width fits to genlist width.
945 elm_genlist_mode_set(viewer_list, ELM_LIST_COMPRESS);
946 elm_genlist_homogeneous_set(viewer_list, EINA_TRUE);
948 evas_object_size_hint_weight_set(viewer_list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
949 evas_object_size_hint_align_set(viewer_list, EVAS_HINT_FILL, EVAS_HINT_FILL);
951 itc.item_style = WIFI_GENLIST_2LINE_TOP_TEXT_ICON_STYLE;
952 itc.func.text_get = _gl_listview_text_get;
953 itc.func.content_get = _gl_listview_content_get;
954 itc.func.state_get = NULL;
955 itc.func.del = _gl_listview_del;
957 no_wifi_device_itc.item_style = WIFI_GENLIST_1LINE_TEXT_STYLE;
958 no_wifi_device_itc.func.text_get = _gl_listview_text_get;
959 no_wifi_device_itc.func.content_get = NULL;
960 no_wifi_device_itc.func.state_get = NULL;
961 no_wifi_device_itc.func.del = _gl_listview_del;
963 first_item = last_item = NULL;
965 evas_object_smart_callback_add(viewer_list, "realized",
967 evas_object_smart_callback_add(viewer_list, "language,changed",
968 gl_lang_changed, NULL);
970 __COMMON_FUNC_EXIT__;
974 void viewer_list_title_item_del(void)
976 if (grouptitle != NULL) {
977 elm_object_item_del(grouptitle);
982 void viewer_list_title_item_update(void)
984 if (grouptitle != NULL)
985 elm_genlist_item_update(grouptitle);
988 void viewer_list_title_item_set(Elm_Object_Item *item_header)
990 if (item_header == NULL)
993 if (grouptitle != NULL) {
994 elm_genlist_item_update(grouptitle);
998 memset(&grouptitle_itc, 0, sizeof(grouptitle_itc));
999 grouptitle_itc.item_style = WIFI_GENLIST_GROUP_INDEX_STYLE;
1000 grouptitle_itc.func.text_get = _gl_text_available_networks_get;
1001 grouptitle_itc.func.content_get = _gl_content_scanning_icon_get;
1003 grouptitle = elm_genlist_item_insert_after(viewer_list,
1004 &grouptitle_itc, NULL, NULL, item_header,
1005 ELM_GENLIST_ITEM_NONE, NULL, NULL);
1007 assertm_if(NULL == grouptitle, "NULL!!");
1009 elm_genlist_item_select_mode_set(grouptitle,
1010 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1013 int viewer_list_item_radio_mode_set(Elm_Object_Item* item,
1014 VIEWER_ITEM_RADIO_MODES mode)
1016 __COMMON_FUNC_ENTER__;
1019 INFO_LOG(COMMON_NAME_ERR, "item is NULL");
1023 ug_genlist_data_t* gdata = (ug_genlist_data_t *) elm_object_item_data_get(item);
1024 if (NULL == gdata || NULL == gdata->device_info) {
1025 INFO_LOG(COMMON_NAME_ERR, "gdata or device_info is NULL");
1029 if (gdata->radio_mode == mode) {
1030 SECURE_INFO_LOG(UG_NAME_NORMAL, "[%s] is already in requested state", gdata->device_info->ssid);
1034 SECURE_INFO_LOG(UG_NAME_NORMAL, "[%s] AP Item State Transition from [%d] --> [%d]", gdata->device_info->ssid, gdata->radio_mode, mode);
1035 gdata->radio_mode = mode;
1036 if (gdata->device_info->ap_status_txt) {
1037 g_free(gdata->device_info->ap_status_txt);
1038 gdata->device_info->ap_status_txt = viewer_list_get_device_status_txt(gdata->device_info, mode);
1042 elm_genlist_item_update(item);
1044 __COMMON_FUNC_EXIT__;
1048 static wifi_connection_state_e _convert_wifi_state_to_viewer_radio_mode(
1049 wifi_connection_state_e state)
1052 case WIFI_CONNECTION_STATE_ASSOCIATION:
1053 return VIEWER_ITEM_RADIO_MODE_CONNECTING;
1054 case WIFI_CONNECTION_STATE_CONFIGURATION:
1055 return VIEWER_ITEM_RADIO_MODE_CONFIGURATION;
1056 case WIFI_CONNECTION_STATE_CONNECTED:
1057 return VIEWER_ITEM_RADIO_MODE_CONNECTED;
1059 return VIEWER_ITEM_RADIO_MODE_OFF;
1063 Elm_Object_Item *viewer_list_item_insert_after(wifi_device_info_t *wifi_device,
1064 Elm_Object_Item *after)
1066 Elm_Object_Item* ret = NULL;
1067 ug_genlist_data_t* gdata = NULL;
1068 wifi_device_info_t *no_wifi_device = NULL;
1069 wifi_connection_state_e state = WIFI_CONNECTION_STATE_DISCONNECTED;
1070 VIEWER_ITEM_RADIO_MODES rad_mode = VIEWER_ITEM_RADIO_MODE_OFF;
1071 retvm_if(NULL == viewer_list, NULL);
1073 if (wifi_device != NULL) {
1074 if (wifi_ap_get_connection_state(wifi_device->ap, &state) ==
1076 rad_mode = _convert_wifi_state_to_viewer_radio_mode(state);
1078 wifi_device->ap_status_txt = viewer_list_get_device_status_txt(
1082 if (ug_app_state->is_first_scan == true) {
1083 int scan_result = wlan_manager_scan();
1084 if (scan_result != WLAN_MANAGER_ERR_NONE) {
1085 viewer_manager_hide(VIEWER_WINSET_SEARCHING);
1086 viewer_manager_header_mode_set(viewer_manager_header_mode_get());
1088 ug_app_state->is_first_scan = false;
1091 no_wifi_device = g_try_new0(wifi_device_info_t, 1);
1092 if (no_wifi_device == NULL)
1095 no_wifi_device->ssid = g_strdup(sc(PACKAGE, I18N_TYPE_No_Wi_Fi_AP_Found));
1097 wifi_device = no_wifi_device;
1100 gdata = g_try_new0(ug_genlist_data_t, 1);
1101 retvm_if(NULL == gdata, NULL);
1102 gdata->device_info = wifi_device;
1103 gdata->radio_mode = VIEWER_ITEM_RADIO_MODE_OFF;
1106 /* If the after item is NULL then insert it as first item */
1110 if (no_wifi_device == NULL) {
1111 ret = elm_genlist_item_insert_after(
1112 viewer_list, /*obj*/
1116 after, /*after than*/
1117 ELM_GENLIST_ITEM_NONE, /*flags*/
1118 __viewer_list_item_clicked_cb,/*func*/
1121 ret = elm_genlist_item_insert_after(
1122 viewer_list, /*obj*/
1123 &no_wifi_device_itc,/*itc*/
1126 after, /*after than*/
1127 ELM_GENLIST_ITEM_NONE, /*flags*/
1128 __viewer_list_item_clicked_cb,/*func*/
1133 assertm_if(NULL == ret, "NULL!!");
1136 /* SECURE_DEBUG_LOG(UG_NAME_NORMAL,
1137 "* item add complete item [0x%x] ssid:[%s] security[%d] size:[%d]",
1140 wifi_device->security_mode,
1141 viewer_list_item_size_get()); */
1143 if (after == grouptitle) {
1156 elm_genlist_item_update(ret);
1162 void viewer_list_item_del(Elm_Object_Item *it)
1168 if (it == first_item) {
1169 first_item = elm_genlist_item_next_get(first_item);
1170 } else if (it == last_item) {
1171 last_item = elm_genlist_item_prev_get(last_item);
1173 elm_object_item_del(it);
1176 int viewer_list_item_size_get()
1179 Elm_Object_Item *it = first_item;
1183 if (it == last_item) {
1186 it = elm_genlist_item_next_get(it);
1192 void viewer_list_item_clear(void)
1194 __COMMON_FUNC_ENTER__;
1196 Elm_Object_Item *it = first_item;
1197 Elm_Object_Item *nxt = NULL;
1200 nxt = elm_genlist_item_next_get(it);
1201 elm_object_item_del(it);
1202 if (it == last_item) {
1208 first_item = last_item = NULL;
1210 __COMMON_FUNC_EXIT__;
1213 void viewer_list_item_enable_all(void)
1215 __COMMON_FUNC_ENTER__;
1217 Elm_Object_Item *it = first_item;
1220 elm_object_item_disabled_set(it, EINA_FALSE);
1222 if (it == last_item) {
1226 it = elm_genlist_item_next_get(it);
1229 __COMMON_FUNC_EXIT__;
1232 void viewer_list_item_disable_all(void)
1234 __COMMON_FUNC_ENTER__;
1236 Elm_Object_Item *it = first_item;
1239 elm_object_item_disabled_set(it, EINA_TRUE);
1241 if (it == last_item) {
1245 it = elm_genlist_item_next_get(it);
1248 __COMMON_FUNC_EXIT__;
1251 Elm_Object_Item* item_get_for_ap(wifi_ap_h ap)
1253 __COMMON_FUNC_ENTER__;
1255 __COMMON_FUNC_EXIT__;
1260 wifi_security_type_e type = WIFI_SECURITY_TYPE_NONE;
1262 if (WIFI_ERROR_NONE != wifi_ap_get_essid(ap, &essid)) {
1263 __COMMON_FUNC_EXIT__;
1265 } else if (WIFI_ERROR_NONE != wifi_ap_get_security_type(ap, &type)) {
1266 __COMMON_FUNC_EXIT__;
1270 Elm_Object_Item *it = first_item;
1271 wlan_security_mode_type_t sec_mode = common_utils_get_sec_mode(type);
1273 ug_genlist_data_t* gdata = elm_object_item_data_get(it);
1274 wifi_device_info_t *device_info = NULL;
1275 if (gdata && (device_info = gdata->device_info)) {
1276 if (!g_strcmp0(device_info->ssid, essid) && device_info->security_mode == sec_mode) {
1280 if (it == last_item) {
1284 it = elm_genlist_item_next_get(it);
1288 __COMMON_FUNC_EXIT__;
1292 Elm_Object_Item* item_get_for_ssid(const char *ssid)
1294 Elm_Object_Item *it = first_item;
1296 ug_genlist_data_t* gdata = elm_object_item_data_get(it);
1297 wifi_device_info_t *device_info = NULL;
1298 if (gdata && (device_info = gdata->device_info)) {
1299 if (!g_strcmp0(device_info->ssid, ssid)) {
1303 if (it == last_item) {
1307 it = elm_genlist_item_next_get(it);