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.
21 #include "view-main.h"
22 #include "common_pswd_popup.h"
23 #include "common_generate_pin.h"
24 #include "common_utils.h"
25 #include "view-alerts.h"
26 #include "i18nmanager.h"
27 #include "common_eap_connect.h"
28 #define VCONF_SORT_BY "file/private/wifi/sort_by"
30 #define QS_POPUP_CONNECTION_STATE "qs_popup_connection_state"
31 #define WIFI_DEVPKR_EDJ "/usr/apps/wifi-efl-ug/res/edje/wifi-qs/wifi-syspopup-custom.edj"
32 #define WIFI_SYSPOPUP_EMPTY_GRP "devpkr_no_wifi_networks"
34 struct connecting_cancel_popup_data {
39 static struct connecting_cancel_popup_data *g_disconnect_popup = NULL;
41 extern wifi_object* devpkr_app_state;
43 static Evas_Object* list = NULL;
44 static Elm_Genlist_Item_Class itc;
45 static int profiles_list_size = 0;
46 static Elm_Genlist_Item_Class grouptitle_itc;
47 static Elm_Object_Item *grouptitle = NULL;
49 static GList *wifi_device_list = NULL;
51 int view_main_get_profile_count(void)
53 return profiles_list_size;
56 static ITEM_CONNECTION_MODES view_main_state_get(void)
58 ITEM_CONNECTION_MODES state;
60 state = (ITEM_CONNECTION_MODES)evas_object_data_get(
61 list, QS_POPUP_CONNECTION_STATE);
66 static void view_main_state_set(ITEM_CONNECTION_MODES state)
68 evas_object_data_set(list, QS_POPUP_CONNECTION_STATE, (const void *)state);
71 static void __popup_ok_cb(void *data, Evas_Object *obj, void *event_info)
73 __COMMON_FUNC_ENTER__;
77 const char* password = NULL;
78 wifi_security_type_e sec_type = WIFI_SECURITY_TYPE_NONE;
80 if (devpkr_app_state->passpopup == NULL) {
84 ap = passwd_popup_get_ap(devpkr_app_state->passpopup);
85 password = passwd_popup_get_txt(devpkr_app_state->passpopup);
87 password_len = strlen(password);
89 wifi_ap_get_security_type(ap, &sec_type);
92 case WIFI_SECURITY_TYPE_WEP:
93 if (password_len != 5 && password_len != 13 &&
94 password_len != 26 && password_len != 10) {
95 common_utils_send_message_to_net_popup(
96 "Network connection popup",
97 "wrong password", "toast_popup", NULL);
99 if (devpkr_app_state->passpopup->entry) {
100 elm_object_focus_set(
101 devpkr_app_state->passpopup->entry,
108 case WIFI_SECURITY_TYPE_WPA_PSK:
109 case WIFI_SECURITY_TYPE_WPA2_PSK:
110 if (password_len < 8 || password_len > 64) {
111 common_utils_send_message_to_net_popup(
112 "Network connection popup",
113 "wrong password", "toast_popup", NULL);
115 if (devpkr_app_state->passpopup->entry) {
116 elm_object_focus_set(
117 devpkr_app_state->passpopup->entry,
125 ERROR_LOG(SP_NAME_ERR, "Wrong security mode: %d", sec_type);
126 passwd_popup_free(devpkr_app_state->passpopup);
130 wlan_manager_connect_with_password(ap, password);
132 passwd_popup_free(devpkr_app_state->passpopup);
133 devpkr_app_state->passpopup = NULL;
136 g_free((gpointer)password);
138 __COMMON_FUNC_EXIT__;
141 static void __popup_cancel_cb(void *data, Evas_Object *obj, void *event_info)
143 __COMMON_FUNC_ENTER__;
145 if (devpkr_app_state->passpopup == NULL) {
149 passwd_popup_free(devpkr_app_state->passpopup);
150 devpkr_app_state->passpopup = NULL;
152 elm_object_focus_set(devpkr_app_state->popup , EINA_TRUE);
154 __COMMON_FUNC_EXIT__;
157 static void __wps_pbc_popup_cancel_connecting(void *data, Evas_Object *obj,
160 if (devpkr_app_state->passpopup == NULL) {
164 wifi_ap_h ap = passwd_popup_get_ap(devpkr_app_state->passpopup);
166 int ret = wlan_manager_disconnect(ap);
167 if (ret != WLAN_MANAGER_ERR_NONE) {
168 ERROR_LOG(SP_NAME_ERR, "Failed WPS PBC cancellation [0x%x]", ap);
171 passwd_popup_free(devpkr_app_state->passpopup);
172 devpkr_app_state->passpopup = NULL;
175 static void _wps_btn_cb(void* data, Evas_Object* obj, void* event_info)
177 __COMMON_FUNC_ENTER__;
179 if (!devpkr_app_state->passpopup) {
183 wifi_ap_h ap = passwd_popup_get_ap(devpkr_app_state->passpopup);
184 int ret = wlan_manager_wps_connect(ap);
185 if (ret == WLAN_MANAGER_ERR_NONE) {
186 create_pbc_popup(devpkr_app_state->passpopup,
187 __wps_pbc_popup_cancel_connecting, NULL,
188 POPUP_WPS_BTN, NULL);
190 ERROR_LOG(SP_NAME_ERR, "wlan_manager_wps_connect failed");
193 passwd_popup_free(devpkr_app_state->passpopup);
194 devpkr_app_state->passpopup = NULL;
197 __COMMON_FUNC_EXIT__;
200 static void _wps_cancel_cb(void* data, Evas_Object* obj, void* event_info)
202 __COMMON_FUNC_ENTER__;
204 if (devpkr_app_state->passpopup == NULL) {
208 current_popup_free(devpkr_app_state->passpopup, POPUP_WPS_OPTIONS);
210 __COMMON_FUNC_EXIT__;
213 static void _wps_pin_cb(void* data, Evas_Object* obj, void* event_info)
215 __COMMON_FUNC_ENTER__;
217 unsigned int rpin = 0;
218 char npin[9] = { '\0' };
220 int ret = WLAN_MANAGER_ERR_NONE;
223 if (!devpkr_app_state->passpopup) {
227 /* Generate WPS pin */
228 rpin = wps_generate_pin();
230 g_snprintf(npin, sizeof(npin), "%08d", rpin);
232 pin_len = strlen(npin);
234 view_alerts_popup_show(sc(PACKAGE, I18N_TYPE_Invalid_pin));
236 __COMMON_FUNC_EXIT__;
240 ap = passwd_popup_get_ap(devpkr_app_state->passpopup);
242 ret = wlan_manager_wps_pin_connect(ap, npin);
243 if (ret == WLAN_MANAGER_ERR_NONE) {
244 INFO_LOG(UG_NAME_NORMAL, "wlan_manager_wps_pin_connect successful");
246 create_pbc_popup(devpkr_app_state->passpopup,
247 __wps_pbc_popup_cancel_connecting, NULL,
248 POPUP_WPS_PIN, npin);
250 ERROR_LOG(UG_NAME_NORMAL, "wlan_manager_wps_pin_connect failed");
252 passwd_popup_free(devpkr_app_state->passpopup);
253 devpkr_app_state->passpopup = NULL;
256 __COMMON_FUNC_EXIT__;
259 static void __popup_wps_options_cb(void* data, Evas_Object* obj, void* event_info)
261 __COMMON_FUNC_ENTER__;
262 pswd_popup_create_req_data_t popup_info;
264 if (!devpkr_app_state->passpopup) {
268 memset(&popup_info, 0, sizeof(pswd_popup_create_req_data_t));
270 popup_info.title = g_strdup(sc(PACKAGE, I18N_TYPE_Select_WPS_Method));
271 popup_info.ok_cb = NULL;
272 popup_info.cancel_cb = _wps_cancel_cb;
273 popup_info.show_wps_btn = EINA_FALSE;
274 popup_info.wps_btn_cb = _wps_btn_cb;
275 popup_info.wps_pin_cb = _wps_pin_cb;
276 popup_info.ap = passwd_popup_get_ap(devpkr_app_state->passpopup);
277 popup_info.cb_data = NULL;
278 create_wps_options_popup(devpkr_app_state->layout_main,
279 devpkr_app_state->passpopup, &popup_info);
281 __COMMON_FUNC_EXIT__;
284 void view_main_eap_view_deref(void)
286 devpkr_app_state->eap_popup = NULL;
289 void view_main_wifi_reconnect(devpkr_gl_data_t *gdata)
291 wifi_device_info_t *device_info;
292 pswd_popup_create_req_data_t popup_info;
293 wifi_security_type_e sec_type = WIFI_SECURITY_TYPE_NONE;
295 retm_if(NULL == gdata);
297 device_info = gdata->dev_info;
298 retm_if(NULL == device_info);
300 if (devpkr_app_state->passpopup != NULL ||
301 devpkr_app_state->eap_popup != NULL) {
302 INFO_LOG(SP_NAME_ERR, "already launched popup");
306 wifi_ap_get_security_type(device_info->ap, &sec_type);
309 case WIFI_SECURITY_TYPE_WEP:
310 case WIFI_SECURITY_TYPE_WPA_PSK:
311 case WIFI_SECURITY_TYPE_WPA2_PSK:
312 memset(&popup_info, 0, sizeof(pswd_popup_create_req_data_t));
314 popup_info.title = gdata->dev_info->ssid;
315 popup_info.ok_cb = __popup_ok_cb;
316 popup_info.cancel_cb = __popup_cancel_cb;
317 popup_info.show_wps_btn = gdata->dev_info->wps_mode;
318 popup_info.wps_btn_cb = __popup_wps_options_cb;
319 popup_info.ap = gdata->dev_info->ap;
320 popup_info.cb_data = NULL;
321 popup_info.sec_type = sec_type;
323 devpkr_app_state->passpopup = create_passwd_popup(
324 devpkr_app_state->conformant,
325 devpkr_app_state->layout_main, PACKAGE,
327 if (devpkr_app_state->passpopup == NULL) {
328 ERROR_LOG(SP_NAME_NORMAL, "Password popup creation failed");
332 case WIFI_SECURITY_TYPE_EAP:
333 devpkr_app_state->eap_popup = create_eap_view(
334 devpkr_app_state->layout_main,
335 devpkr_app_state->win_main,
336 devpkr_app_state->conformant,
337 PACKAGE, gdata->dev_info, view_main_eap_view_deref);
341 ERROR_LOG(SP_NAME_NORMAL, "Unknown security type [%d]", sec_type);
346 void view_main_wifi_connect(devpkr_gl_data_t *gdata)
348 bool favorite = false;
349 wifi_device_info_t *device_info;
350 pswd_popup_create_req_data_t popup_info;
351 wifi_security_type_e sec_type = WIFI_SECURITY_TYPE_NONE;
353 retm_if(NULL == gdata);
355 device_info = gdata->dev_info;
356 retm_if(NULL == device_info);
358 wifi_ap_is_favorite(device_info->ap, &favorite);
360 if (favorite == true) {
361 wlan_manager_connect(device_info->ap);
365 if (devpkr_app_state->passpopup != NULL ||
366 devpkr_app_state->eap_popup != NULL) {
367 INFO_LOG(SP_NAME_ERR, "already launched popup");
371 wifi_ap_get_security_type(device_info->ap, &sec_type);
374 case WIFI_SECURITY_TYPE_NONE:
375 wlan_manager_connect(device_info->ap);
378 case WIFI_SECURITY_TYPE_WEP:
379 case WIFI_SECURITY_TYPE_WPA_PSK:
380 case WIFI_SECURITY_TYPE_WPA2_PSK:
381 memset(&popup_info, 0, sizeof(pswd_popup_create_req_data_t));
383 popup_info.title = gdata->dev_info->ssid;
384 popup_info.ok_cb = __popup_ok_cb;
385 popup_info.cancel_cb = __popup_cancel_cb;
386 popup_info.show_wps_btn = gdata->dev_info->wps_mode;
387 popup_info.wps_btn_cb = __popup_wps_options_cb;
388 popup_info.ap = gdata->dev_info->ap;
389 popup_info.cb_data = NULL;
390 popup_info.sec_type = sec_type;
392 devpkr_app_state->passpopup = create_passwd_popup(
393 devpkr_app_state->conformant,
394 devpkr_app_state->layout_main, PACKAGE,
396 if (devpkr_app_state->passpopup == NULL) {
397 ERROR_LOG(SP_NAME_NORMAL, "Password popup creation failed");
401 case WIFI_SECURITY_TYPE_EAP:
402 devpkr_app_state->eap_popup = create_eap_view(
403 devpkr_app_state->layout_main,
404 devpkr_app_state->win_main,
405 devpkr_app_state->conformant,
406 PACKAGE, gdata->dev_info, view_main_eap_view_deref);
410 ERROR_LOG(SP_NAME_NORMAL, "Unknown security type [%d]", sec_type);
415 Elm_Object_Item *view_main_item_get_for_ap(wifi_ap_h ap)
417 __COMMON_FUNC_ENTER__;
419 __COMMON_FUNC_EXIT__;
424 wifi_security_type_e type = WIFI_SECURITY_TYPE_NONE;
426 if (WIFI_ERROR_NONE != wifi_ap_get_essid(ap, &essid)) {
427 __COMMON_FUNC_EXIT__;
429 } else if (WIFI_ERROR_NONE != wifi_ap_get_security_type(ap, &type)) {
430 __COMMON_FUNC_EXIT__;
434 Elm_Object_Item *it = elm_genlist_first_item_get(list);
435 wlan_security_mode_type_t sec_mode = common_utils_get_sec_mode(type);
437 devpkr_gl_data_t* gdata = elm_object_item_data_get(it);
438 wifi_device_info_t *device_info = NULL;
439 if (gdata && (device_info = gdata->dev_info)) {
440 if (!g_strcmp0(device_info->ssid, essid) && device_info->security_mode == sec_mode) {
445 it = elm_genlist_item_next_get(it);
449 __COMMON_FUNC_EXIT__;
454 /* Unused function */
455 Elm_Object_Item *__view_main_get_item_in_mode(ITEM_CONNECTION_MODES mode)
457 Elm_Object_Item* it = NULL;
458 it = elm_genlist_first_item_get(list);
459 __COMMON_FUNC_ENTER__;
461 devpkr_gl_data_t *gdata = (devpkr_gl_data_t *)elm_object_item_data_get(it);
462 if (gdata && gdata->connection_mode == mode) {
463 SECURE_INFO_LOG( SP_NAME_NORMAL, "Found Item [%s] in mode[%d]", gdata->dev_info->ssid, mode);
464 __COMMON_FUNC_EXIT__;
467 it = elm_genlist_item_next_get(it);
470 __COMMON_FUNC_EXIT__;
475 void view_main_clear_disconnect_popup(wifi_ap_h ap)
477 if (!g_disconnect_popup)
480 if (ap && g_disconnect_popup->ap &&
481 wlan_manager_is_same_network(g_disconnect_popup->ap, ap) != TRUE)
484 if (g_disconnect_popup->popup)
485 evas_object_del(g_disconnect_popup->popup);
487 if (g_disconnect_popup->ap)
488 wifi_ap_destroy(g_disconnect_popup->ap);
490 g_free(g_disconnect_popup);
491 g_disconnect_popup = NULL;
494 static void __view_main_disconnect_cancel_cb(void *data,
495 Evas_Object *obj, void *event_info)
497 struct connecting_cancel_popup_data *popup =
498 (struct connecting_cancel_popup_data *)data;
503 evas_object_del(popup->popup);
506 wifi_ap_destroy(popup->ap);
509 g_disconnect_popup = NULL;
512 static gboolean __view_main_update_ap(gpointer data)
514 wifi_ap_h ap = (wifi_ap_h)data;
521 static void __view_main_disconnect_ok_cb(void *data,
522 Evas_Object *obj, void *event_info)
525 struct connecting_cancel_popup_data *popup =
526 (struct connecting_cancel_popup_data *)data;
530 wlan_manager_disconnect(popup->ap);
531 wlan_manager_forget(popup->ap);
534 evas_object_del(popup->popup);
536 id = common_util_managed_idle_add(__view_main_update_ap, (gpointer)popup->ap);
538 wifi_ap_destroy(popup->ap);
542 g_disconnect_popup = NULL;
545 static void __view_main_disconnect_popup(wifi_device_info_t *device_info,
546 Evas_Object *win_main)
548 popup_btn_info_t popup_data;
549 struct connecting_cancel_popup_data *popup = NULL;
551 memset(&popup_data, 0, sizeof(popup_data));
553 popup = g_try_new0(struct connecting_cancel_popup_data, 1);
557 g_disconnect_popup = popup;
558 wifi_ap_clone(&popup->ap, device_info->ap);
560 popup_data.title_txt = "IDS_WIFI_OPT_FORGET_NETWORK";
561 popup_data.info_txt = "IDS_WIFI_POP_CURRENT_NETWORK_WILL_BE_DISCONNECTED";
562 popup_data.btn1_cb = __view_main_disconnect_cancel_cb;
563 popup_data.btn1_txt = "IDS_WIFI_SK_CANCEL";
564 popup_data.btn1_data = popup;
565 popup_data.btn2_cb = __view_main_disconnect_ok_cb;
566 popup_data.btn2_txt = "IDS_WIFI_SK_FORGET";
567 popup_data.btn2_data = popup;
569 popup->popup = common_utils_show_info_popup(win_main, &popup_data);
572 static void __gl_sel(void *data, Evas_Object *obj, void *event_info)
574 __COMMON_FUNC_ENTER__;
576 assertm_if(NULL == obj, "obj is NULL!!");
577 assertm_if(NULL == event_info, "event_info is NULL!!");
579 Elm_Object_Item *item = (Elm_Object_Item *)event_info;
580 devpkr_gl_data_t *gdata = (devpkr_gl_data_t *)elm_object_item_data_get(item);
581 if (!gdata || !gdata->dev_info) {
582 __COMMON_FUNC_EXIT__;
586 switch (gdata->connection_mode) {
587 case ITEM_CONNECTION_MODE_OFF:
588 view_main_wifi_connect(gdata);
591 case ITEM_CONNECTION_MODE_CONNECTING:
592 case ITEM_CONNECTION_MODE_CONFIGURATION:
593 __view_main_disconnect_popup(gdata->dev_info, devpkr_app_state->layout_main);
600 elm_genlist_item_selected_set(item, EINA_FALSE);
602 __COMMON_FUNC_EXIT__;
605 static char *_gl_text_get(void *data, Evas_Object *obj, const char *part)
610 assertm_if(NULL == data, "data param is NULL!!");
611 assertm_if(NULL == obj, "obj param is NULL!!");
612 assertm_if(NULL == part, "part param is NULL!!");
614 devpkr_gl_data_t *gdata = (devpkr_gl_data_t *) data;
615 retvm_if(NULL == gdata, NULL);
617 if (!strcmp("elm.text", part)) {
618 txt = evas_textblock_text_utf8_to_markup(NULL, gdata->dev_info->ssid);
621 ERROR_LOG(SP_NAME_NORMAL, "ssid name is NULL!!");
624 } else if (!strcmp("elm.text.sub", part)) {
625 if (ITEM_CONNECTION_MODE_CONNECTING == gdata->connection_mode) {
626 ret = g_strdup(sc(PACKAGE, I18N_TYPE_Connecting));
627 } else if (ITEM_CONNECTION_MODE_CONFIGURATION == gdata->connection_mode) {
628 ret = g_strdup(sc(PACKAGE, I18N_TYPE_Obtaining_IP_addr));
630 ret = g_strdup(gdata->dev_info->ap_status_txt);
634 ERROR_LOG(SP_NAME_NORMAL, "ap_status_txt is NULL!!");
641 static Evas_Object *_gl_content_get(void *data, Evas_Object *obj, const char *part)
647 devpkr_gl_data_t *gdata = (devpkr_gl_data_t *) data;
649 Evas_Object* icon = NULL;
650 Evas_Object *ic = NULL;
652 if (!strcmp("elm.swallow.icon", part)) {
653 char *temp_str = NULL;
654 ic = elm_layout_add(obj);
656 icon = elm_image_add(ic);
657 retvm_if(NULL == icon, NULL);
659 elm_layout_theme_set(ic, "layout", "list/B/type.3", "default");
661 temp_str = g_strdup_printf("%s.png", gdata->dev_info->ap_image_path);
662 elm_image_file_set(icon, CUSTOM_EDITFIELD_PATH, temp_str);
665 evas_object_color_set(icon, 2, 61, 132, 204);
667 evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, EVAS_HINT_FILL);
668 evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
669 elm_layout_content_set(ic, "elm.swallow.content", icon);
670 } else if (!strcmp("elm.swallow.end", part)) {
671 if (gdata->connection_mode == ITEM_CONNECTION_MODE_CONNECTING ||
672 gdata->connection_mode == ITEM_CONNECTION_MODE_CONFIGURATION) {
673 ic = elm_layout_add(obj);
674 elm_layout_theme_set(ic, "layout", "list/C/type.2", "default");
676 icon = elm_progressbar_add(obj);
677 elm_object_style_set(icon, "process_medium");
678 evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, 0.5);
679 evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
680 elm_progressbar_pulse(icon, TRUE);
682 elm_layout_content_set(ic, "elm.swallow.content", icon);
689 static void _gl_list_del(void* data, Evas_Object* obj)
695 devpkr_gl_data_t* gdata = (devpkr_gl_data_t *) data;
697 if (gdata->dev_info) {
698 SECURE_DEBUG_LOG(UG_NAME_NORMAL, "del target ssid: [%s]", gdata->dev_info->ssid);
699 g_free(gdata->dev_info->ap_image_path);
700 g_free(gdata->dev_info->ap_status_txt);
701 g_free(gdata->dev_info->ssid);
702 wifi_ap_destroy(gdata->dev_info->ap);
703 g_free(gdata->dev_info);
711 static Evas_Object *_create_genlist(Evas_Object* parent)
713 __COMMON_FUNC_ENTER__;
714 assertm_if(NULL == parent, "parent is NULL!!");
716 list = elm_genlist_add(parent);
717 assertm_if(NULL == list, "list allocation fail!!");
718 elm_genlist_mode_set(list, ELM_LIST_COMPRESS);
719 elm_genlist_homogeneous_set(list, EINA_TRUE);
721 evas_object_size_hint_weight_set(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
722 evas_object_size_hint_align_set(list, EVAS_HINT_FILL, EVAS_HINT_FILL);
724 itc.item_style = WIFI_GENLIST_2LINE_TOP_TEXT_ICON_STYLE;
725 itc.func.text_get = _gl_text_get;
726 itc.func.content_get = _gl_content_get;
727 itc.func.state_get = NULL;
728 itc.func.del = _gl_list_del;
730 __COMMON_FUNC_EXIT__;
735 static void view_main_scan_ui_clear(void)
737 __COMMON_FUNC_ENTER__;
742 elm_genlist_clear(list);
744 __COMMON_FUNC_EXIT__;
747 void view_main_item_state_set(wifi_ap_h ap, ITEM_CONNECTION_MODES state)
749 __COMMON_FUNC_ENTER__;
751 char *item_ssid = NULL;
752 wifi_security_type_e sec_type;
753 wlan_security_mode_type_t item_sec_mode;
754 Elm_Object_Item* it = NULL;
756 it = elm_genlist_first_item_get(list);
759 (WIFI_ERROR_NONE != wifi_ap_get_essid(ap, &item_ssid)) ||
760 (WIFI_ERROR_NONE != wifi_ap_get_security_type(ap, &sec_type))) {
761 ERROR_LOG(SP_NAME_NORMAL, "Invalid params");
762 __COMMON_FUNC_EXIT__;
765 item_sec_mode = common_utils_get_sec_mode(sec_type);
766 SECURE_INFO_LOG(SP_NAME_NORMAL, "item state set for AP[%s] with sec mode[%d]", item_ssid, item_sec_mode);
768 devpkr_gl_data_t *gdata = (devpkr_gl_data_t *)elm_object_item_data_get(it);
770 SECURE_INFO_LOG(SP_NAME_NORMAL, "gdata AP[%s] with sec mode[%d]",
771 gdata->dev_info->ssid, gdata->dev_info->security_mode);
774 if (gdata && gdata->dev_info->security_mode == item_sec_mode &&
775 !g_strcmp0(gdata->dev_info->ssid, item_ssid)) {
776 if (gdata->connection_mode != state) {
777 gdata->connection_mode = state;
778 INFO_LOG(SP_NAME_NORMAL, "State transition from [%d] --> [%d]", view_main_state_get(), state);
779 view_main_state_set(state);
781 elm_genlist_item_update(it);
786 it = elm_genlist_item_next_get(it);
789 __COMMON_FUNC_EXIT__;
793 static wifi_device_info_t *view_main_item_device_info_create(wifi_ap_h ap)
795 wifi_device_info_t *wifi_device = g_try_new0(wifi_device_info_t, 1);
796 wifi_security_type_e sec_type;
798 if (WIFI_ERROR_NONE != wifi_ap_clone(&(wifi_device->ap), ap)) {
801 } else if (WIFI_ERROR_NONE != wifi_ap_get_essid(ap, &(wifi_device->ssid))) {
804 } else if (WIFI_ERROR_NONE != wifi_ap_get_rssi(ap, &(wifi_device->rssi))) {
805 g_free(wifi_device->ssid);
808 } else if (WIFI_ERROR_NONE != wifi_ap_get_security_type(ap, &sec_type)) {
809 g_free(wifi_device->ssid);
812 } else if (WIFI_ERROR_NONE != wifi_ap_is_wps_supported(ap, &(wifi_device->wps_mode))) {
813 g_free(wifi_device->ssid);
818 wifi_device->security_mode = common_utils_get_sec_mode(sec_type);
819 wifi_device->ap_status_txt = common_utils_get_ap_security_type_info_txt(PACKAGE,
821 common_utils_get_device_icon(wifi_device, &wifi_device->ap_image_path);
826 static bool view_main_wifi_insert_found_ap(wifi_device_info_t *wifi_device)
828 devpkr_gl_data_t *gdata = g_try_new0(devpkr_gl_data_t, 1);
829 wifi_connection_state_e state;
831 assertm_if(NULL == list, "list is NULL");
836 gdata->dev_info = wifi_device;
837 if (gdata->dev_info == NULL) {
842 wifi_ap_get_connection_state(wifi_device->ap, &state);
844 if (WIFI_CONNECTION_STATE_ASSOCIATION == state ||
845 WIFI_CONNECTION_STATE_CONFIGURATION == state) {
846 gdata->connection_mode = ITEM_CONNECTION_MODE_CONNECTING;
847 gdata->it = elm_genlist_item_append(list, &itc, gdata,
848 NULL, ELM_GENLIST_ITEM_NONE, __gl_sel,
850 view_main_state_set(ITEM_CONNECTION_MODE_CONNECTING);
855 gdata->connection_mode = ITEM_CONNECTION_MODE_OFF;
857 gdata->it = elm_genlist_item_append(list, &itc, gdata, NULL,
858 ELM_GENLIST_ITEM_NONE, __gl_sel, NULL);
863 static gint compare(gconstpointer a, gconstpointer b)
865 bool favorite1 = false, favorite2 = false;
866 wifi_connection_state_e state1 = 0, state2 = 0;
868 wifi_device_info_t *wifi_device1 = (wifi_device_info_t*)a;
869 wifi_device_info_t *wifi_device2 = (wifi_device_info_t*)b;
871 wifi_ap_get_connection_state(wifi_device1->ap, &state1);
872 wifi_ap_get_connection_state(wifi_device2->ap, &state2);
874 if (state1 != state2) {
875 if (state1 == WIFI_CONNECTION_STATE_CONNECTED)
877 if (state2 == WIFI_CONNECTION_STATE_CONNECTED)
880 if (state1 == WIFI_CONNECTION_STATE_CONFIGURATION)
882 if (state2 == WIFI_CONNECTION_STATE_CONFIGURATION)
885 if (state1 == WIFI_CONNECTION_STATE_ASSOCIATION)
887 if (state2 == WIFI_CONNECTION_STATE_ASSOCIATION)
891 wifi_ap_is_favorite(wifi_device1->ap, &favorite1);
892 wifi_ap_is_favorite(wifi_device2->ap, &favorite2);
894 if (favorite1 != favorite2) {
895 if (favorite1 == true)
897 if (favorite2 == true)
900 if (devpkr_app_state->sort_type == I18N_TYPE_Signal_Strength) {
901 /*Sort in descending order of signal strength*/
902 return wifi_device2->rssi - wifi_device1->rssi;
904 return strcasecmp((const char *)wifi_device1->ssid,
905 (const char *)wifi_device2->ssid);
908 static bool view_main_wifi_found_ap_cb(wifi_ap_h ap, void* user_data)
910 int *profile_size = (int *)user_data;
911 wifi_device_info_t *wifi_device = NULL;
913 wifi_device = view_main_item_device_info_create(ap);
914 if (wifi_device == NULL)
917 wifi_device_list = g_list_insert_sorted(wifi_device_list, wifi_device, compare);
923 static Evas_Object *_gl_content_title_get(void *data, Evas_Object *obj, const char *part)
925 Evas_Object *title_progressbar = NULL;
927 if (FALSE == wifi_devpkr_get_scan_status())
930 title_progressbar = elm_progressbar_add(obj);
931 elm_object_style_set(title_progressbar, "process_small");
932 elm_progressbar_horizontal_set(title_progressbar, EINA_TRUE);
933 elm_progressbar_pulse(title_progressbar, EINA_TRUE);
935 return title_progressbar;
938 static char* _gl_text_title_get(void *data, Evas_Object *obj,const char *part)
940 if (!strcmp("elm.text", part)) {
941 return (char*) g_strdup(sc(PACKAGE, I18N_TYPE_Available_networks));
947 static void view_main_add_group_title(void)
949 grouptitle_itc.item_style = WIFI_GENLIST_GROUP_INDEX_STYLE;
950 grouptitle_itc.func.text_get = _gl_text_title_get;
951 grouptitle_itc.func.content_get = _gl_content_title_get;
953 grouptitle = elm_genlist_item_append(list,
957 ELM_GENLIST_ITEM_NONE,
960 assertm_if(NULL == grouptitle, "NULL!!");
962 elm_genlist_item_select_mode_set(grouptitle,
963 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
966 void view_main_update_group_title(gboolean is_bg_scan)
968 Evas_Object *box = NULL;
969 Evas_Object *main_list = NULL;
973 Elm_Object_Item *it = elm_genlist_first_item_get(list);
976 elm_object_item_disabled_set(it, EINA_TRUE);
977 it = elm_genlist_item_next_get(it);
981 if(grouptitle != NULL)
982 elm_genlist_item_update(grouptitle);
984 box = elm_object_content_get(devpkr_app_state->popup);
986 main_list = _create_genlist(box);
987 view_main_add_group_title();
989 elm_box_pack_start(box, main_list);
991 evas_object_show(main_list);
992 evas_object_show(box);
994 wifi_devpkr_redraw();
996 evas_object_show(devpkr_app_state->popup);
1002 static void view_main_create_empty_layout(void)
1004 __COMMON_FUNC_ENTER__;
1006 Evas_Object *box = NULL;
1007 Evas_Object *layout = NULL;
1008 Evas_Object *prev_box = NULL;
1010 prev_box = elm_object_content_get(devpkr_app_state->popup);
1011 if (prev_box != NULL) {
1012 evas_object_del(prev_box);
1017 box = elm_box_add(devpkr_app_state->popup);
1018 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1019 evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
1021 layout = elm_layout_add(devpkr_app_state->popup);
1022 elm_layout_file_set(layout, WIFI_DEVPKR_EDJ, WIFI_SYSPOPUP_EMPTY_GRP);
1023 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1024 evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
1026 elm_object_domain_translatable_part_text_set(layout, "text", PACKAGE,
1027 sc(PACKAGE, I18N_TYPE_No_Wi_Fi_AP_Found));
1029 elm_box_pack_end(box, layout);
1030 evas_object_show(layout);
1031 evas_object_show(box);
1032 elm_object_content_set(devpkr_app_state->popup, box);
1034 __COMMON_FUNC_EXIT__;
1037 void view_main_create_main_list(void)
1039 __COMMON_FUNC_ENTER__;
1041 Evas_Object *box = NULL;
1042 Evas_Object *main_list = NULL;
1043 Evas_Object *prev_box = NULL;
1045 prev_box = elm_object_content_get(devpkr_app_state->popup);
1046 if (prev_box != NULL) {
1047 evas_object_del(prev_box);
1052 box = elm_box_add(devpkr_app_state->popup);
1053 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1054 evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
1056 main_list = _create_genlist(box);
1057 view_main_add_group_title();
1059 elm_box_pack_end(box, main_list);
1060 evas_object_show(main_list);
1061 evas_object_show(box);
1062 elm_object_content_set(devpkr_app_state->popup, box);
1064 __COMMON_FUNC_EXIT__;
1067 void view_main_refresh_ap_info(Elm_Object_Item *item)
1073 devpkr_gl_data_t *gdata = elm_object_item_data_get(item);
1077 wifi_device_info_t *wifi_device = gdata->dev_info;
1082 wifi_ap_refresh(wifi_device->ap);
1085 static gboolean __view_main_scroll_to_top(void *data)
1088 elm_genlist_item_bring_in((Elm_Object_Item *)data,
1089 ELM_GENLIST_ITEM_SCROLLTO_TOP);
1094 Elm_Object_Item *view_main_move_item_to_top(Elm_Object_Item *old_item)
1096 __COMMON_FUNC_ENTER__;
1098 Elm_Object_Item *title_item = elm_genlist_first_item_get(list);
1099 Elm_Object_Item *first_item = elm_genlist_item_next_get(title_item);
1100 devpkr_gl_data_t *old_it_gdata = NULL, *first_it_gdata = NULL;
1102 if (!old_item || !first_item) {
1103 __COMMON_FUNC_EXIT__;
1107 old_it_gdata = elm_object_item_data_get(old_item);
1108 if (!old_it_gdata || !old_it_gdata->dev_info) {
1109 __COMMON_FUNC_EXIT__;
1113 if (old_item != first_item) {
1114 first_it_gdata = elm_object_item_data_get(first_item);
1115 elm_object_item_data_set(first_item, old_it_gdata);
1116 elm_object_item_data_set(old_item, first_it_gdata);
1118 elm_genlist_item_update(first_item);
1119 elm_genlist_item_update(old_item);
1122 common_util_managed_idle_add(__view_main_scroll_to_top, title_item);
1124 __COMMON_FUNC_EXIT__;
1128 gboolean view_main_show(void *data)
1130 __COMMON_FUNC_ENTER__;
1133 wifi_device_info_t *wifi_device = NULL;
1134 GList* list_of_device = NULL;
1136 int state = wlan_manager_state_get();
1137 if (WLAN_MANAGER_ERROR == state || WLAN_MANAGER_OFF == state) {
1138 INFO_LOG(SP_NAME_NORMAL, "Wi-Fi state is OFF");
1139 view_main_create_empty_layout();
1141 } else if (WLAN_MANAGER_CONNECTED == state) {
1142 __COMMON_FUNC_EXIT__;
1146 wifi_devpkr_enable_scan_btn();
1148 /* If previous profile list exists then just clear the genlist */
1149 if (profiles_list_size) {
1150 view_main_scan_ui_clear();
1151 view_main_add_group_title();
1153 view_main_create_main_list();
1156 view_main_state_set(ITEM_CONNECTION_MODE_OFF);
1158 profiles_list_size = 0;
1160 devpkr_app_state->sort_type = I18N_TYPE_Alphabetical;
1161 if (common_util_get_system_registry(VCONF_SORT_BY) == 1)
1162 devpkr_app_state->sort_type = I18N_TYPE_Signal_Strength;
1164 wifi_foreach_found_aps(view_main_wifi_found_ap_cb, &profiles_list_size);
1165 INFO_LOG(SP_NAME_NORMAL, "profiles list count [%d]\n", profiles_list_size);
1167 list_of_device = wifi_device_list;
1168 for (i = 0; i < profiles_list_size && list_of_device != NULL; i++) {
1169 wifi_device = (wifi_device_info_t*)list_of_device->data;
1171 view_main_wifi_insert_found_ap(wifi_device);
1173 list_of_device = list_of_device->next;
1176 if (wifi_device_list != NULL) {
1177 g_list_free(wifi_device_list);
1178 wifi_device_list = NULL;
1181 if (profiles_list_size <= 0)
1182 view_main_create_empty_layout();
1184 evas_object_show(list);
1187 wifi_devpkr_redraw();
1189 if (devpkr_app_state->passpopup == NULL &&
1190 devpkr_app_state->eap_popup == NULL)
1191 evas_object_show(devpkr_app_state->popup);
1192 evas_object_show(devpkr_app_state->win_main);
1194 __COMMON_FUNC_EXIT__;