ae0cec62f975c9dccfc679f463072f83b88513c1
[apps/native/ug-wifi-efl.git] / sources / ui-gadget / viewers-layout / wifi_viewer_list.c
1 /*
2  * Wi-Fi
3  *
4  * Copyright 2012 Samsung Electronics Co., Ltd
5  *
6  * Licensed under the Flora License, Version 1.1 (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
9  *
10  * http://www.tizenopensource.org/license
11  *
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.
17  *
18  */
19
20 #include "common.h"
21 #include "ug_wifi.h"
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"
31
32 #define LIST_ITEM_CONNECTED_AP_FONT_SIZE                28
33
34 static Evas_Object* viewer_list = NULL;
35 static Elm_Object_Item* first_item = NULL;
36 static Elm_Object_Item* last_item = NULL;
37
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_Genlist_Item_Class *last_item_itc;
42 static Elm_Object_Item *grouptitle = NULL;
43
44 extern wifi_appdata *ug_app_state;
45
46 struct connecting_cancel_popup_data {
47         Evas_Object *popup;
48         wifi_manager_ap_h ap;
49 };
50
51 static struct connecting_cancel_popup_data *g_disconnect_popup = NULL;
52
53 static void _gl_listview_more_btn_cb(void *data, Evas_Object *obj, void *event_info)
54 {
55         __COMMON_FUNC_ENTER__;
56
57         elm_object_disabled_set(obj, EINA_TRUE);
58
59         wifi_device_info_t *device_info = (wifi_device_info_t *)data;
60
61         if (data == NULL) {
62                 __COMMON_FUNC_EXIT__;
63                 return;
64         }
65
66         SECURE_DEBUG_LOG(UG_NAME_NORMAL, "ssid [%s]", device_info->ssid);
67
68         view_detail(device_info, ug_app_state->layout_main, obj);
69
70         __COMMON_FUNC_EXIT__;
71 }
72
73 char* ConvertRGBAtoHex(int r, int g, int b, int a)
74 {
75         int hexcolor = 0;
76         char* string = NULL;
77
78         string = g_try_malloc0(sizeof(char)*255);
79         if (string != NULL) {
80                 hexcolor = (r << 24) + (g << 16) + (b << 8) + a;
81                 g_snprintf(string, 255, "%08x", hexcolor);
82         }
83
84         return string;
85 }
86
87 static char* _gl_listview_text_get(void *data, Evas_Object *obj, const char *part)
88 {
89         char* det = NULL;
90         char* buf = NULL;
91         char* convertedColor = NULL;
92         int ug_type = wifi_get_ug_type();
93
94         ug_genlist_data_t* gdata = (ug_genlist_data_t*) data;
95         retvm_if(NULL == gdata || NULL == gdata->device_info, NULL);
96
97         assertm_if(NULL == gdata->device_info->ssid, "NULL!!");
98
99         if (!strcmp("elm.text", part)) {
100                 det = evas_textblock_text_utf8_to_markup(NULL,
101                                 gdata->device_info->ssid);
102                 assertm_if(NULL == det, "NULL!!");
103                 assertm_if(NULL == convertedColor, "NULL!!");
104
105                 if (ug_type != UG_VIEW_OOBE && VIEWER_ITEM_RADIO_MODE_CONNECTED == gdata->radio_mode) {
106                         convertedColor = ConvertRGBAtoHex(61, 185, 204, 255);
107                         buf = g_strdup_printf("<color=#%s>%s</color>",
108                                         convertedColor, det);
109
110                         g_free(det);
111                         g_free(convertedColor);
112                         return buf;
113                 } else if (wifi_get_ug_type() == UG_VIEW_OOBE) {
114                         buf = g_strdup_printf("<font_size=%d>%s</font_size>",
115                                         OOBE_BIG_FONT_SIZE, det);
116                         g_free(det);
117                         return buf;
118                 }
119         } else if (!strcmp("elm.text.sub", part)
120                         && gdata->device_info->ap_status_txt != NULL) {
121                 det = g_strdup(gdata->device_info->ap_status_txt);
122                 assertm_if(NULL == det, "NULL!!");
123
124                 if (ug_type == UG_VIEW_OOBE)
125                         buf = g_strdup_printf("<font_size=%d>%s</font_size>",
126                                         OOBE_SMALL_FONT_SIZE, det);
127                 else
128                         buf = g_strdup_printf("<font_size=%d>%s</font_size>",
129                                         SMALL_FONT_SIZE, det);
130                 g_free(det);
131                 return buf;
132         }
133
134         return det;
135 }
136
137 static Evas_Object *_gl_listview_content_get(void *data, Evas_Object *obj, const char *part)
138 {
139         ug_genlist_data_t *gdata = (ug_genlist_data_t *)data;
140         retvm_if(NULL == gdata, NULL);
141
142         Evas_Object *icon = NULL;
143         Evas_Object *btn = NULL;
144
145         if (gdata->device_info->ap_image_path == NULL) {
146                 /* if there is no ap_image_path (NO AP Found situation) */
147                 DEBUG_LOG(UG_NAME_ERR, "Fatal: Image path is NULL");
148
149         } else if (!strcmp("elm.swallow.icon", part)) {
150                 icon = elm_image_add(obj);
151                 retvm_if(NULL == icon, NULL);
152
153                 /* for strength */
154                 char *temp_str = NULL;
155                 temp_str = g_strdup_printf("%s.png", gdata->device_info->ap_image_path);
156                 elm_image_file_set(icon, CUSTOM_EDITFIELD_PATH, temp_str);
157                 g_free(temp_str);
158
159                 if (wifi_get_ug_type() == UG_VIEW_OOBE) {
160                         evas_object_color_set(icon, 0, 10, 10, 204);
161                         evas_object_size_hint_min_set(icon, ELM_SCALE_SIZE(DEFAULT_OOBE_BUTTON_CIRCLE_WIDTH),
162                                         ELM_SCALE_SIZE(DEFAULT_OOBE_BUTTON_CIRCLE_HEIGHT));
163                 } else {
164                         evas_object_color_set(icon, 2, 61, 132, 204);
165                         evas_object_size_hint_min_set(icon, ELM_SCALE_SIZE(DEFAULT_BUTTON_CIRCLE_SIZE),
166                                         ELM_SCALE_SIZE(DEFAULT_BUTTON_CIRCLE_SIZE));
167                 }
168         } else if (!strcmp("elm.swallow.end", part)) {
169                 if (VIEWER_ITEM_RADIO_MODE_CONNECTING == gdata->radio_mode ||
170                                 VIEWER_ITEM_RADIO_MODE_CONFIGURATION == gdata->radio_mode) {
171
172                         icon = elm_progressbar_add(obj);
173
174                         elm_object_style_set(icon, "process_medium");
175                         evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, 0.5);
176                         evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
177                         elm_progressbar_pulse(icon, TRUE);
178                         evas_object_propagate_events_set(icon, EINA_FALSE);
179                 } else if (wifi_get_ug_type() != UG_VIEW_OOBE) {
180                         btn = elm_button_add(obj);
181                         elm_object_style_set(btn, "circle_custom");
182                         icon = elm_image_add(btn);
183                         elm_image_file_set(icon, CUSTOM_EDITFIELD_PATH, "wifi_icon_badge_info.png");
184                         elm_image_resizable_set(icon, EINA_TRUE, EINA_TRUE);
185                         elm_object_part_content_set(btn, "elm.swallow.content", icon);
186                         evas_object_propagate_events_set(btn, EINA_FALSE);
187                         evas_object_smart_callback_add(btn, "clicked", _gl_listview_more_btn_cb, gdata->device_info);
188                         evas_object_show(btn);
189
190                         return btn;
191                 }
192         }
193         return icon;
194 }
195
196 static void _gl_listview_del(void *data, Evas_Object *obj)
197 {
198         if (data == NULL)
199                 return;
200
201         ug_genlist_data_t *gdata = (ug_genlist_data_t *)data;
202         retm_if(NULL == gdata || NULL == gdata->device_info);
203
204         g_free(gdata->device_info->ap_image_path);
205         g_free(gdata->device_info->ap_status_txt);
206         g_free(gdata->device_info->ssid);
207         wifi_manager_ap_destroy(gdata->device_info->ap);
208         g_free(gdata->device_info);
209         g_free(gdata);
210 }
211
212 static char *_gl_text_available_networks_get(void *data, Evas_Object *obj,
213                 const char *part)
214 {
215         if (!strcmp("elm.text", part))
216                 return g_strdup(sc(PACKAGE, I18N_TYPE_Available_networks));
217
218         return NULL;
219 }
220
221 static Evas_Object *_gl_content_scanning_icon_get(void *data, Evas_Object *obj,
222                 const char *part)
223 {
224         Evas_Object *title_progressbar = NULL;
225
226         if (HEADER_MODE_SEARCHING == viewer_manager_header_mode_get()) {
227                 title_progressbar  = elm_progressbar_add(obj);
228                 elm_object_style_set(title_progressbar, "process_small");
229                 elm_progressbar_horizontal_set(title_progressbar, EINA_TRUE);
230                 elm_progressbar_pulse(title_progressbar, EINA_TRUE);
231         }
232
233         return title_progressbar;
234 }
235
236 static char *_gl_hidden_network_text_get(void *data, Evas_Object *obj,
237                 const char *part)
238 {
239         if (!strcmp("elm.text", part))
240                 return g_strdup_printf("<font_size=%d>%s</font_size>",
241                                 BIG_FONT_SIZE, sc(PACKAGE, I18N_TYPE_Find_Hidden_Network));
242
243         return NULL;
244 }
245
246 static Evas_Object *_gl_hidden_network_content_get(void *data, Evas_Object *obj,
247                 const char *part)
248 {
249         Evas_Object *icon = NULL;
250
251         if (!strcmp("elm.swallow.icon", part)) {
252                 icon = elm_image_add(obj);
253                 retvm_if(NULL == icon, NULL);
254                 elm_image_file_set(icon, CUSTOM_EDITFIELD_PATH, "find_hidden_network.png");
255                 evas_object_size_hint_min_set(icon, ELM_SCALE_SIZE(DEFAULT_OOBE_BUTTON_CIRCLE_WIDTH),
256                                 ELM_SCALE_SIZE(DEFAULT_OOBE_BUTTON_CIRCLE_HEIGHT));
257         }
258
259         return icon;
260 }
261
262 Elm_Object_Item* viewer_list_get_first_item(void)
263 {
264         return first_item;
265 }
266
267 Elm_Object_Item* viewer_list_get_last_item(void)
268 {
269         return last_item;
270 }
271
272 #ifdef ACCESSIBLITY_FEATURE
273 static char *_access_info_cb(void *data, Evas_Object *obj)
274 {
275         char *strength = NULL;
276         char *buf = NULL;
277
278         ug_genlist_data_t *gdata = (ug_genlist_data_t *)data;
279         if (!gdata)
280                 return NULL;
281
282         strength = common_utils_get_rssi_text(PACKAGE, gdata->device_info->rssi);
283         buf = g_strdup_printf("%s. %s. %s.", strength, gdata->device_info->ssid, gdata->device_info->ap_status_txt);
284
285         g_free(strength);
286         return buf;
287 }
288 #endif
289
290 static void gl_lang_changed(void *data, Evas_Object *obj, void *event_info)
291 {
292         elm_genlist_realized_items_update(obj);
293 }
294
295 static void _gl_realized(void *data, Evas_Object *obj, void *event_info)
296 {
297 #ifdef ACCESSIBLITY_FEATURE
298         HEADER_MODES header_mode = viewer_manager_header_mode_get();
299         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
300
301         if (header_mode == HEADER_MODE_ACTIVATING ||
302                 header_mode == HEADER_MODE_DEACTIVATING ||
303                 header_mode == HEADER_MODE_OFF) {
304                 return ;
305         }
306
307         Elm_Object_Item *first_item = viewer_list_get_first_item();
308         Elm_Object_Item *last_item = viewer_list_get_last_item();
309
310         if (first_item == NULL || last_item == NULL)
311                 return;
312
313         int index = (int)elm_genlist_item_index_get(item);
314         int first_item_index = (int)elm_genlist_item_index_get(first_item);
315         int last_item_index = (int)elm_genlist_item_index_get(last_item);
316         char buf[100] = "";
317
318         if (first_item_index == -1) {
319                 int group_index = (int)elm_genlist_item_index_get(grouptitle);
320                 first_item_index = group_index + 1;
321         }
322
323         if (index >= first_item_index && index <= last_item_index &&
324                         first_item_index < last_item_index) {
325
326                 Evas_Object *ao = elm_object_item_access_object_get(item);
327                 elm_access_info_cb_set(ao, ELM_ACCESS_INFO, _access_info_cb, elm_object_item_data_get(item));
328                 g_snprintf(buf, sizeof(buf), "%s%s",
329                                                 sc(PACKAGE, I18N_TYPE_Double_tap),
330                                                 sc(PACKAGE, I18N_TYPE_Connect_to_device));
331                 elm_access_info_set(ao, ELM_ACCESS_TYPE, buf);
332                 elm_access_info_set(ao, ELM_ACCESS_STATE, sc(PACKAGE, I18N_TYPE_Wi_Fi_network_info));
333         }
334 #else
335         Elm_Object_Item *first_item = viewer_list_get_first_item();
336
337         if (first_item == NULL)
338                 return;
339
340         int first_item_index = (int)elm_genlist_item_index_get(first_item);
341
342         if (first_item_index == -1) {
343                 int group_index = (int)elm_genlist_item_index_get(grouptitle);
344                 first_item_index = group_index + 1;
345         }
346 #endif
347 }
348
349 static void _info_popup_ok_cb(void *data, Evas_Object *obj, void *event_info)
350 {
351         pswd_popup_t *passpopup = (pswd_popup_t *)data;
352
353         if (passpopup != NULL && passpopup->info_popup != NULL) {
354                 evas_object_del(passpopup->info_popup);
355                 passpopup->info_popup = NULL;
356         }
357 }
358
359 static void __passwd_popup_cancel_cb(void *data,  Evas_Object *obj,
360                 void *event_info)
361 {
362         __COMMON_FUNC_ENTER__;
363
364         if (ug_app_state->passpopup == NULL)
365                 return;
366
367         passwd_popup_free(ug_app_state->passpopup);
368         ug_app_state->passpopup = NULL;
369
370         if (data)
371                 g_free(data);
372
373         __COMMON_FUNC_EXIT__;
374 }
375
376 static void __passwd_popup_ok_cb(void *data, Evas_Object *obj, void *event_info)
377 {
378         __COMMON_FUNC_ENTER__;
379
380         wifi_manager_ap_h ap = NULL;
381         int password_len = 0;
382         const char *password = NULL;
383         wifi_manager_security_type_e sec_type = WIFI_MANAGER_SECURITY_TYPE_NONE;
384
385         if (ug_app_state->passpopup == NULL)
386                 return;
387
388         ap = passwd_popup_get_ap(ug_app_state->passpopup);
389         password = passwd_popup_get_txt(ug_app_state->passpopup);
390         if (password != NULL)
391                 password_len = strlen(password);
392
393         wifi_manager_ap_get_security_type(ap, &sec_type);
394
395         switch (sec_type) {
396         case WIFI_MANAGER_SECURITY_TYPE_WEP:
397                 if (password_len != 5 && password_len != 13 &&
398                                 password_len != 26 && password_len != 10) {
399                         common_utils_send_message_to_net_popup(
400                                         "Network connection popup",
401                                         "wrong password", "toast_popup", NULL);
402
403                         if (ug_app_state->passpopup->entry) {
404                                 elm_object_focus_set(
405                                                 ug_app_state->passpopup->entry,
406                                                 EINA_TRUE);
407                         }
408                         goto failure;
409                 }
410                 break;
411
412         case WIFI_MANAGER_SECURITY_TYPE_WPA_PSK:
413         case WIFI_MANAGER_SECURITY_TYPE_WPA2_PSK:
414                 if (password_len < 8 || password_len > 64) {
415                         common_utils_send_message_to_net_popup(
416                                         "Network connection popup",
417                                         "wrong password", "toast_popup", NULL);
418
419                         if (ug_app_state->passpopup->entry) {
420                                 elm_object_focus_set(
421                                                 ug_app_state->passpopup->entry,
422                                                 EINA_TRUE);
423                         }
424                         goto failure;
425                 }
426                 break;
427
428         default:
429                 ERROR_LOG(UG_NAME_NORMAL, "Wrong security mode: %d", sec_type);
430                 passwd_popup_free(ug_app_state->passpopup);
431                 ug_app_state->passpopup = NULL;
432
433                 goto popup_ok_cb_exit;
434         }
435
436         bool favorite = FALSE;
437         if (wifi_manager_ap_is_favorite(ap, &favorite) == WIFI_MANAGER_ERROR_NONE
438                 && favorite == TRUE) {
439                 wlan_manager_forget(ap);
440                 wifi_manager_ap_refresh(ap);
441         }
442
443         if (ug_app_state->is_hidden) {
444                 wifi_manager_ap_h hidden_ap;
445                 char *ssid;
446                 wifi_manager_ap_get_essid(ap, &ssid);
447                 wlan_manager_ap_hidden_create(ssid, &hidden_ap);
448                 g_free(ssid);
449                 wifi_manager_ap_set_security_type(hidden_ap, sec_type);
450                 wlan_manager_connect_with_password(hidden_ap, password);
451         } else
452                 wlan_manager_connect_with_password(ap, password);
453
454         passwd_popup_free(ug_app_state->passpopup);
455         ug_app_state->passpopup = NULL;
456
457 popup_ok_cb_exit:
458         if (data)
459                 g_free(data);
460
461 failure:
462         g_free((gpointer)password);
463
464         __COMMON_FUNC_EXIT__;
465 }
466
467 static void __wps_pbc_popup_cancel_connecting(void *data, Evas_Object *obj,
468                 void *event_info)
469 {
470         __COMMON_FUNC_ENTER__;
471
472         if (ug_app_state->passpopup == NULL)
473                 return;
474
475         wifi_manager_ap_h ap = passwd_popup_get_ap(ug_app_state->passpopup);
476
477         int ret = wlan_manager_disconnect(ap);
478         if (ret != WLAN_MANAGER_ERR_NONE)
479                 ERROR_LOG(UG_NAME_NORMAL, "Failed WPS PBC cancellation [%p]", ap);
480
481         passwd_popup_free(ug_app_state->passpopup);
482         ug_app_state->passpopup = NULL;
483
484         viewer_manager_header_mode_set(HEADER_MODE_ON);
485         ug_app_state->is_wifi_scan_indication_block = 0;
486
487         __COMMON_FUNC_EXIT__;
488 }
489
490 static void _wps_btn_cb(void* data, Evas_Object* obj, void* event_info)
491 {
492         __COMMON_FUNC_ENTER__;
493
494         if (!ug_app_state->passpopup)
495                 return;
496
497         ug_app_state->is_wifi_scan_indication_block = 1;
498         wifi_manager_ap_h ap = passwd_popup_get_ap(ug_app_state->passpopup);
499         int ret = wlan_manager_wps_connect(ap);
500         if (ret == WLAN_MANAGER_ERR_NONE) {
501                 create_pbc_popup(ug_app_state->passpopup,
502                                 __wps_pbc_popup_cancel_connecting, NULL,
503                                 POPUP_WPS_BTN, NULL);
504         } else {
505                 ERROR_LOG(UG_NAME_NORMAL, "wlan_manager_wps_connect failed");
506                 passwd_popup_free(ug_app_state->passpopup);
507                 ug_app_state->passpopup = NULL;
508                 ug_app_state->is_wifi_scan_indication_block = 0;
509         }
510
511         __COMMON_FUNC_EXIT__;
512 }
513
514 static void _wps_cancel_cb(void* data, Evas_Object* obj, void* event_info)
515 {
516         __COMMON_FUNC_ENTER__;
517
518         ug_app_state->is_wifi_scan_indication_block = 0;
519
520         if (ug_app_state->passpopup == NULL)
521                 return;
522
523         current_popup_free(ug_app_state->passpopup, POPUP_WPS_OPTIONS);
524
525         __COMMON_FUNC_EXIT__;
526 }
527
528 static void _wps_pin_cb(void* data, Evas_Object* obj, void* event_info)
529 {
530         __COMMON_FUNC_ENTER__;
531         unsigned int rpin = 0;
532         char npin[9] = { '\0' };
533         int pin_len = 0;
534         int ret = WLAN_MANAGER_ERR_NONE;
535         wifi_manager_ap_h ap = NULL;
536         Evas_Object *info_popup = NULL;
537
538         if (!ug_app_state->passpopup)
539                 return;
540
541         ug_app_state->is_wifi_scan_indication_block = 1;
542
543         /* Generate WPS pin */
544         if (wps_generate_pin(&rpin) < 0) {
545                 ERROR_LOG(UG_NAME_NORMAL, "Failed to generate WPS PIN");
546                 __COMMON_FUNC_EXIT__;
547                 return;
548         }
549
550         if (rpin > 0)
551                 g_snprintf(npin, sizeof(npin), "%08d", rpin);
552
553         pin_len = strlen(npin);
554         if (pin_len != 8) {
555                 info_popup = common_utils_show_info_ok_popup(
556                                 ug_app_state->layout_main, PACKAGE,
557                                 sc(PACKAGE, I18N_TYPE_Invalid_pin),
558                                 _info_popup_ok_cb,
559                                 ug_app_state->passpopup);
560                 ug_app_state->passpopup->info_popup = info_popup;
561
562                 __COMMON_FUNC_EXIT__;
563                 return;
564         }
565
566         ap = passwd_popup_get_ap(ug_app_state->passpopup);
567
568         ret = wlan_manager_wps_pin_connect(ap, npin);
569         if (ret == WLAN_MANAGER_ERR_NONE) {
570                 INFO_LOG(UG_NAME_NORMAL, "wlan_manager_wps_pin_connect successful");
571
572                 create_pbc_popup(ug_app_state->passpopup,
573                                 __wps_pbc_popup_cancel_connecting, NULL,
574                                 POPUP_WPS_PIN, npin);
575         } else {
576                 ERROR_LOG(UG_NAME_NORMAL, "wlan_manager_wps_pin_connect failed");
577                 passwd_popup_free(ug_app_state->passpopup);
578                 ug_app_state->passpopup = NULL;
579                 ug_app_state->is_wifi_scan_indication_block = 0;
580         }
581
582         __COMMON_FUNC_EXIT__;
583 }
584
585 static void __wps_options_popup_cb(void* data, Evas_Object* obj, void* event_info)
586 {
587         __COMMON_FUNC_ENTER__;
588         pswd_popup_create_req_data_t popup_info;
589
590         if (!ug_app_state->passpopup)
591                 return;
592
593         memset(&popup_info, 0, sizeof(pswd_popup_create_req_data_t));
594
595         popup_info.title = "IDS_WIFI_HEADER_SELECT_WPS_METHOD_ABB";
596         popup_info.ok_cb = NULL;
597         popup_info.cancel_cb = _wps_cancel_cb;
598         popup_info.show_wps_btn = EINA_FALSE;
599         popup_info.wps_btn_cb = _wps_btn_cb;
600         popup_info.wps_pin_cb = _wps_pin_cb;
601         popup_info.ap = passwd_popup_get_ap(ug_app_state->passpopup);
602         popup_info.cb_data = NULL;
603         create_wps_options_popup(ug_app_state->layout_main, ug_app_state->passpopup,
604                         &popup_info);
605
606         __COMMON_FUNC_EXIT__;
607 }
608
609 void viewer_list_wifi_reconnect(wifi_device_info_t *device_info)
610 {
611         pswd_popup_create_req_data_t popup_info;
612         wifi_manager_security_type_e sec_type = WIFI_MANAGER_SECURITY_TYPE_NONE;
613         wifi_device_info_t *device_info_temp = NULL;
614         struct ug_data *ugd = (struct ug_data *)ug_app_state->gadget;
615
616         if (device_info == NULL)
617                 return;
618
619         if (ug_app_state->passpopup != NULL || ug_app_state->eap_view != NULL) {
620                 INFO_LOG(UG_NAME_ERR, "already launched popup");
621                 return;
622         }
623
624         wifi_manager_ap_get_security_type(device_info->ap, &sec_type);
625
626         switch (sec_type) {
627         case WIFI_MANAGER_SECURITY_TYPE_WEP:
628         case WIFI_MANAGER_SECURITY_TYPE_WPA_PSK:
629         case WIFI_MANAGER_SECURITY_TYPE_WPA2_PSK:
630                 memset(&popup_info, 0, sizeof(pswd_popup_create_req_data_t));
631
632                 device_info_temp = view_list_item_device_info_create(device_info->ap);
633
634                 popup_info.title = device_info->ssid;
635                 popup_info.ok_cb = __passwd_popup_ok_cb;
636                 popup_info.cancel_cb = __passwd_popup_cancel_cb;
637                 popup_info.show_wps_btn = device_info->wps_mode;
638                 popup_info.wps_btn_cb = __wps_options_popup_cb;
639                 popup_info.ap = device_info->ap;
640                 popup_info.cb_data = device_info_temp;
641                 popup_info.sec_type = sec_type;
642
643                 /* TODO: parameter with device_info */
644                 /* TODO: finally parameter with wifi_manager_ap_h, WPA, EAP */
645                 ug_app_state->passpopup = create_passwd_popup(
646                                 ug_app_state->conformant,
647                                 ug_app_state->parent_layout, PACKAGE, &popup_info);
648
649                 if (ug_app_state->passpopup == NULL)
650                         INFO_LOG(UG_NAME_ERR, "Fail to create password popup");
651
652                 break;
653         case WIFI_MANAGER_SECURITY_TYPE_EAP:
654                 ug_app_state->eap_view = create_eap_view(
655                                 ug_app_state->parent_layout, ugd->win_main,
656                                 ug_app_state->conformant,
657                                 PACKAGE, device_info,
658                                 viewer_manager_eap_view_deref);
659                 break;
660         default:
661                 ERROR_LOG(UG_NAME_NORMAL, "Unknown security type [%d]", sec_type);
662                 return;
663         }
664
665 }
666
667 void viewer_list_wifi_connect(wifi_device_info_t *device_info)
668 {
669         bool favorite = false;
670         pswd_popup_create_req_data_t popup_info;
671         wifi_manager_security_type_e sec_type = WIFI_MANAGER_SECURITY_TYPE_NONE;
672         wifi_device_info_t *dev_info_temp = NULL;
673         struct ug_data *ugd = (struct ug_data *)ug_app_state->gadget;
674
675         if (device_info == NULL)
676                 return;
677
678         wifi_manager_ap_is_favorite(device_info->ap, &favorite);
679         if (favorite == true) {
680                 wlan_manager_connect(device_info->ap);
681                 return;
682         }
683
684         if (ug_app_state->passpopup != NULL || ug_app_state->eap_view != NULL) {
685                 INFO_LOG(UG_NAME_ERR, "already launched popup");
686                 return;
687         }
688
689         wifi_manager_ap_get_security_type(device_info->ap, &sec_type);
690
691         switch (sec_type) {
692         case WIFI_MANAGER_SECURITY_TYPE_NONE:
693                 if (ug_app_state->is_hidden) {
694                         wifi_manager_ap_h ap;
695                         char *ssid;
696                         wifi_manager_ap_get_essid(device_info->ap, &ssid);
697                         wlan_manager_ap_hidden_create(ssid, &ap);
698                         g_free(ssid);
699                         wifi_manager_ap_set_security_type(ap, WIFI_MANAGER_SECURITY_TYPE_NONE);
700                         wlan_manager_connect(ap);
701                 } else
702                         wlan_manager_connect(device_info->ap);
703                 break;
704
705         case WIFI_MANAGER_SECURITY_TYPE_WEP:
706         case WIFI_MANAGER_SECURITY_TYPE_WPA_PSK:
707         case WIFI_MANAGER_SECURITY_TYPE_WPA2_PSK:
708                 memset(&popup_info, 0, sizeof(pswd_popup_create_req_data_t));
709
710                 dev_info_temp = view_list_item_device_info_create(device_info->ap);
711
712                 popup_info.title = device_info->ssid;
713                 popup_info.ok_cb = __passwd_popup_ok_cb;
714                 popup_info.cancel_cb = __passwd_popup_cancel_cb;
715                 popup_info.show_wps_btn = device_info->wps_mode;
716                 popup_info.wps_btn_cb = __wps_options_popup_cb;
717                 popup_info.ap = device_info->ap;
718                 popup_info.cb_data = dev_info_temp;
719                 popup_info.sec_type = sec_type;
720
721                 /* TODO: parameter with device_info */
722                 /* TODO: finally parameter with wifi_manager_ap_h, WPA, EAP */
723                 ug_app_state->passpopup = create_passwd_popup(
724                                 ug_app_state->conformant,
725                                 ug_app_state->parent_layout, PACKAGE, &popup_info);
726
727                 if (ug_app_state->passpopup == NULL)
728                         INFO_LOG(UG_NAME_ERR, "Fail to create password popup");
729
730                 break;
731
732         case WIFI_MANAGER_SECURITY_TYPE_EAP:
733                 ug_app_state->eap_view = create_eap_view(
734                                 ug_app_state->parent_layout, ugd->win_main,
735                                 ug_app_state->conformant,
736                                 PACKAGE, device_info,
737                                 viewer_manager_eap_view_deref);
738                 break;
739
740         default:
741                 ERROR_LOG(UG_NAME_NORMAL, "Unknown security type[%d]", sec_type);
742                 break;
743         }
744 }
745
746 void viewer_list_clear_disconnect_popup(wifi_manager_ap_h ap)
747 {
748         if (!g_disconnect_popup)
749                 return;
750
751         if (ap && g_disconnect_popup->ap &&
752                         wlan_manager_is_same_network(g_disconnect_popup->ap, ap) != TRUE)
753                 return;
754
755         if (g_disconnect_popup->popup)
756                 evas_object_del(g_disconnect_popup->popup);
757
758         if (g_disconnect_popup->ap)
759                 wifi_manager_ap_destroy(g_disconnect_popup->ap);
760
761         g_free(g_disconnect_popup);
762         g_disconnect_popup = NULL;
763 }
764
765 static void __viewer_list_disconnect_cancel_cb(void *data,
766                 Evas_Object *obj, void *event_info)
767 {
768         struct connecting_cancel_popup_data *popup =
769                         (struct connecting_cancel_popup_data *)data;
770         if (!popup)
771                 return;
772
773         if (popup->popup)
774                 evas_object_del(popup->popup);
775
776         if (popup->ap)
777                 wifi_manager_ap_destroy(popup->ap);
778
779         g_free(popup);
780         g_disconnect_popup = NULL;
781 }
782
783 static gboolean __viewer_list_update_ap(gpointer data)
784 {
785         wifi_manager_ap_h ap = (wifi_manager_ap_h)data;
786
787         viewer_manager_update_item_favorite_status(ap);
788         wifi_manager_ap_destroy(ap);
789
790         return FALSE;
791 }
792
793 static void __viewer_list_disconnect_ok_cb(void *data,
794                 Evas_Object *obj, void *event_info)
795 {
796         guint id;
797         struct connecting_cancel_popup_data *popup =
798                         (struct connecting_cancel_popup_data *)data;
799         if (!popup)
800                 return;
801
802         wlan_manager_disconnect(popup->ap);
803         wlan_manager_forget(popup->ap);
804
805         if (popup->popup)
806                 evas_object_del(popup->popup);
807
808         id = common_util_managed_idle_add(__viewer_list_update_ap, (gpointer)popup->ap);
809         if (!id) {
810                 viewer_manager_update_item_favorite_status(popup->ap);
811                 wifi_manager_ap_destroy(popup->ap);
812         }
813
814         g_free(popup);
815         g_disconnect_popup = NULL;
816 }
817
818 static void __viewer_list_disconnect_popup(wifi_device_info_t *device_info,
819                 Evas_Object *win_main)
820 {
821         popup_btn_info_t popup_data;
822         struct connecting_cancel_popup_data *popup = NULL;
823
824         memset(&popup_data, 0, sizeof(popup_data));
825
826         popup = g_try_new0(struct connecting_cancel_popup_data, 1);
827         if (!popup)
828                 return;
829
830         g_disconnect_popup = popup;
831         wifi_manager_ap_clone(&popup->ap, device_info->ap);
832
833         popup_data.title_txt = "IDS_WIFI_OPT_FORGET_NETWORK";
834         popup_data.info_txt = "IDS_WIFI_POP_CURRENT_NETWORK_WILL_BE_DISCONNECTED";
835         popup_data.btn1_cb = __viewer_list_disconnect_cancel_cb;
836         popup_data.btn1_txt = "IDS_WIFI_SK_CANCEL";
837         popup_data.btn1_data = popup;
838         popup_data.btn2_cb = __viewer_list_disconnect_ok_cb;
839         popup_data.btn2_txt = "IDS_WIFI_SK_FORGET";
840         popup_data.btn2_data = popup;
841
842         popup->popup = common_utils_show_info_popup(win_main, &popup_data);
843 }
844
845 static void __viewer_list_item_clicked_cb(void *data, Evas_Object *obj,
846                 void *event_info)
847 {
848         __COMMON_FUNC_ENTER__;
849
850         assertm_if(NULL == event_info, "event_info is NULL!!");
851         assertm_if(NULL == obj, "obj is NULL!!");
852
853         Elm_Object_Item *it = (Elm_Object_Item *)event_info;
854         ug_genlist_data_t *gdata = NULL;
855         wifi_device_info_t *device_info = NULL;
856
857         gdata = (ug_genlist_data_t *)elm_object_item_data_get(it);
858         retm_if(NULL == gdata);
859
860         device_info = gdata->device_info;
861         retm_if(NULL == device_info || NULL == device_info->ssid);
862
863         int item_state = gdata->radio_mode;
864         int current_state = 0;
865
866         SECURE_INFO_LOG(UG_NAME_NORMAL, "ssid --- %s", device_info->ssid);
867         INFO_LOG(UG_NAME_NORMAL, "ap --- %p", device_info->ap);
868         INFO_LOG(UG_NAME_NORMAL, "current item_state state is --- %d", item_state);
869
870         if (ug_app_state->is_lbhome == EINA_TRUE &&
871                         ug_app_state->app_control != NULL) {
872                 INFO_LOG(UG_NAME_NORMAL, "exit with reply");
873                 char *bssid = NULL;
874                 app_control_h reply;
875
876                 app_control_create(&reply);
877                 wifi_manager_ap_get_bssid(device_info->ap, &bssid);
878                 SECURE_INFO_LOG(UG_NAME_NORMAL, "bssid %s, ssid %s", bssid, device_info->ssid);
879
880                 app_control_add_extra_data(reply, "bssid", bssid);
881                 app_control_add_extra_data(reply, "ssid", device_info->ssid);
882                 app_control_reply_to_launch_request(reply, ug_app_state->app_control,
883                                 APP_CONTROL_RESULT_SUCCEEDED);
884                 app_control_destroy(reply);
885                 g_free(bssid);
886                 wifi_exit();
887                 return;
888         }
889
890         switch (item_state) {
891         case VIEWER_ITEM_RADIO_MODE_OFF:
892                 current_state = viewer_manager_header_mode_get();
893
894                 INFO_LOG(UG_NAME_NORMAL, "Clicked AP information\n");
895                 INFO_LOG(UG_NAME_NORMAL, "header mode [%d]", current_state);
896
897                 switch (current_state) {
898                 case HEADER_MODE_ON:
899                 case HEADER_MODE_CONNECTED:
900                 case HEADER_MODE_CONNECTING:
901                 case HEADER_MODE_SEARCHING:
902                         viewer_list_wifi_connect(device_info);
903                         break;
904
905                 case HEADER_MODE_OFF:
906                 case HEADER_MODE_ACTIVATING:
907                 case HEADER_MODE_DEACTIVATING:
908                 default:
909                         INFO_LOG(UG_NAME_NORMAL, "Ignore click");
910                         break;
911                 }
912                 break;
913
914         case VIEWER_ITEM_RADIO_MODE_CONNECTING:
915         case VIEWER_ITEM_RADIO_MODE_CONFIGURATION:
916                 __viewer_list_disconnect_popup(device_info, ug_app_state->layout_main);
917                 break;
918         case VIEWER_ITEM_RADIO_MODE_CONNECTED:
919         default:
920                 INFO_LOG(UG_NAME_NORMAL, "Ignore click");
921                 break;
922         }
923
924         elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
925
926         __COMMON_FUNC_EXIT__;
927 }
928
929 static char *viewer_list_get_device_status_txt(wifi_device_info_t *wifi_device,
930                 VIEWER_ITEM_RADIO_MODES mode)
931 {
932         char *status_txt = NULL;
933         int current_state = 0;
934
935         current_state = viewer_manager_header_mode_get();
936         /* The strings are currently hard coded. It will be replaced with string ids later */
937         if (VIEWER_ITEM_RADIO_MODE_CONNECTING == mode) {
938                 status_txt = g_strdup(sc(PACKAGE, I18N_TYPE_Connecting));
939         } else if (VIEWER_ITEM_RADIO_MODE_CONFIGURATION == mode) {
940                 status_txt = g_strdup(sc(PACKAGE, I18N_TYPE_Obtaining_IP_addr));
941         } else if (VIEWER_ITEM_RADIO_MODE_CONNECTED == mode) {
942                 if (connection_manager_is_wifi_connection_used() ||
943                                 current_state == HEADER_MODE_CONNECTED) {
944                         status_txt = g_strdup(sc(PACKAGE, I18N_TYPE_Connected));
945                 }
946         } else if (VIEWER_ITEM_RADIO_MODE_OFF == mode) {
947                 status_txt = common_utils_get_ap_security_type_info_txt(PACKAGE,
948                         wifi_device, true);
949         } else {
950                 status_txt = g_strdup(sc(PACKAGE, I18N_TYPE_Unknown));
951                 INFO_LOG(UG_NAME_NORMAL, "Invalid mode: %d", mode);
952         }
953
954         return status_txt;
955 }
956
957 Evas_Object* viewer_list_create(Evas_Object *win)
958 {
959         __COMMON_FUNC_ENTER__;
960
961         assertm_if(NULL == win, "NULL!!");
962         assertm_if(NULL != viewer_list, "Err!!");
963
964         viewer_list = elm_genlist_add(win);
965         assertm_if(NULL == viewer_list, "NULL!!");
966
967         if (wifi_get_ug_type() == UG_VIEW_OOBE) {
968                 elm_object_style_set(viewer_list, "solid/default");
969                 elm_object_color_class_color_set(viewer_list, "bg", 255, 255, 255, 255);
970         }
971
972         // To use multiline textblock/entry/editfield in genlist, set height_for_width mode
973         // then the item's height is calculated while the item's width fits to genlist width.
974         elm_genlist_mode_set(viewer_list, ELM_LIST_COMPRESS);
975         //elm_genlist_realization_mode_set(viewer_list, EINA_TRUE);
976
977         evas_object_size_hint_weight_set(viewer_list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
978         evas_object_size_hint_align_set(viewer_list, EVAS_HINT_FILL, EVAS_HINT_FILL);
979
980         itc = elm_genlist_item_class_new();
981         itc->item_style = WIFI_GENLIST_2LINE_TOP_TEXT_ICON_STYLE;
982         itc->func.text_get = _gl_listview_text_get;
983         itc->func.content_get = _gl_listview_content_get;
984         itc->func.state_get = NULL;
985         itc->func.del = _gl_listview_del;
986
987         no_wifi_device_itc = elm_genlist_item_class_new();
988         no_wifi_device_itc->item_style = WIFI_GENLIST_1LINE_TEXT_STYLE;
989         no_wifi_device_itc->func.text_get = _gl_listview_text_get;
990         no_wifi_device_itc->func.content_get = NULL;
991         no_wifi_device_itc->func.state_get = NULL;
992         no_wifi_device_itc->func.del = _gl_listview_del;
993
994         if (wifi_get_ug_type() == UG_VIEW_OOBE) {
995                 last_item_itc = elm_genlist_item_class_new();
996                 last_item_itc->item_style = WIFI_GENLIST_1LINE_TEXT_ICON_STYLE;
997                 last_item_itc->func.text_get = _gl_hidden_network_text_get;
998                 last_item_itc->func.content_get = _gl_hidden_network_content_get;
999                 last_item_itc->func.del = NULL;
1000         }
1001
1002         first_item = last_item = NULL;
1003
1004         evas_object_smart_callback_add(viewer_list, "realized",
1005                         _gl_realized, NULL);
1006         evas_object_smart_callback_add(viewer_list, "language,changed",
1007                         gl_lang_changed, NULL);
1008
1009         __COMMON_FUNC_EXIT__;
1010         return viewer_list;
1011 }
1012
1013 void viewer_list_title_item_del(void)
1014 {
1015         if (grouptitle != NULL) {
1016                 elm_object_item_del(grouptitle);
1017                 grouptitle = NULL;
1018         }
1019 }
1020
1021 void viewer_list_title_item_update(void)
1022 {
1023         if (grouptitle != NULL)
1024                 elm_genlist_item_update(grouptitle);
1025 }
1026
1027 void viewer_list_title_item_set(Elm_Object_Item *item_header)
1028 {
1029         if (item_header == NULL)
1030                 return;
1031
1032         if (grouptitle != NULL) {
1033                 elm_genlist_item_update(grouptitle);
1034                 return;
1035         }
1036
1037         //memset(&grouptitle_itc, 0, sizeof(grouptitle_itc));
1038         grouptitle_itc = elm_genlist_item_class_new();
1039         if (wifi_get_ug_type() == UG_VIEW_OOBE) {
1040                 grouptitle_itc->item_style = WIFI_GENLIST_FULL_STYLE;
1041                 grouptitle_itc->func.text_get = NULL;
1042                 grouptitle_itc->func.content_get = NULL;
1043         } else {
1044                 grouptitle_itc->item_style = WIFI_GENLIST_GROUP_INDEX_STYLE;
1045                 grouptitle_itc->func.text_get = _gl_text_available_networks_get;
1046                 grouptitle_itc->func.content_get = _gl_content_scanning_icon_get;
1047         }
1048
1049         grouptitle = elm_genlist_item_insert_after(viewer_list,
1050                         grouptitle_itc, NULL, NULL, item_header,
1051                         ELM_GENLIST_ITEM_NONE, NULL, NULL);
1052
1053         assertm_if(NULL == grouptitle, "NULL!!");
1054
1055         elm_genlist_item_select_mode_set(grouptitle,
1056                         ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1057 }
1058
1059 int viewer_list_item_radio_mode_set(Elm_Object_Item* item,
1060                 VIEWER_ITEM_RADIO_MODES mode)
1061 {
1062         __COMMON_FUNC_ENTER__;
1063
1064         if (NULL == item) {
1065                 INFO_LOG(COMMON_NAME_ERR, "item is NULL");
1066                 return FALSE;
1067         }
1068
1069         ug_genlist_data_t* gdata = (ug_genlist_data_t *) elm_object_item_data_get(item);
1070         if (NULL == gdata || NULL == gdata->device_info) {
1071                 INFO_LOG(COMMON_NAME_ERR, "gdata or device_info is NULL");
1072                 return FALSE;
1073         }
1074
1075         if (gdata->radio_mode == mode) {
1076                 SECURE_INFO_LOG(UG_NAME_NORMAL, "[%s] is already in requested state", gdata->device_info->ssid);
1077                 return FALSE;
1078         }
1079
1080         SECURE_INFO_LOG(UG_NAME_NORMAL, "[%s] AP Item State Transition from [%d] --> [%d]", gdata->device_info->ssid, gdata->radio_mode, mode);
1081         gdata->radio_mode = mode;
1082         if (gdata->device_info->ap_status_txt) {
1083                 g_free(gdata->device_info->ap_status_txt);
1084                 gdata->device_info->ap_status_txt = viewer_list_get_device_status_txt(gdata->device_info, mode);
1085         }
1086
1087         if (item != NULL)
1088                 elm_genlist_item_update(item);
1089
1090         __COMMON_FUNC_EXIT__;
1091         return TRUE;
1092 }
1093
1094 static wifi_manager_connection_state_e _convert_wifi_state_to_viewer_radio_mode(
1095                 wifi_manager_connection_state_e state)
1096 {
1097         switch (state) {
1098         case WIFI_MANAGER_CONNECTION_STATE_ASSOCIATION:
1099                 return VIEWER_ITEM_RADIO_MODE_CONNECTING;
1100         case WIFI_MANAGER_CONNECTION_STATE_CONFIGURATION:
1101                 return VIEWER_ITEM_RADIO_MODE_CONFIGURATION;
1102         case WIFI_MANAGER_CONNECTION_STATE_CONNECTED:
1103                 return VIEWER_ITEM_RADIO_MODE_CONNECTED;
1104         default:
1105                 return VIEWER_ITEM_RADIO_MODE_OFF;
1106         }
1107 }
1108
1109 Elm_Object_Item *viewer_list_item_insert_after(wifi_device_info_t *wifi_device,
1110                 Elm_Object_Item *after)
1111 {
1112         Elm_Object_Item* ret = NULL;
1113         ug_genlist_data_t* gdata = NULL;
1114         wifi_device_info_t *no_wifi_device = NULL;
1115         retvm_if(NULL == viewer_list, NULL);
1116
1117         if (_is_emulator()) {
1118                 if (wifi_device != NULL) {
1119                         wifi_device->ap_status_txt = viewer_list_get_device_status_txt(
1120                                                         wifi_device,
1121                                                         VIEWER_ITEM_RADIO_MODE_OFF);
1122                 } else {
1123                         no_wifi_device = g_try_new0(wifi_device_info_t, 1);
1124                         if (no_wifi_device == NULL)
1125                                 return NULL;
1126
1127                         no_wifi_device->ssid = g_strdup(sc(PACKAGE, I18N_TYPE_No_Wi_Fi_AP_Found));
1128                         wifi_device = no_wifi_device;
1129                 }
1130         } else {
1131                 wifi_manager_connection_state_e state = WIFI_MANAGER_CONNECTION_STATE_DISCONNECTED;
1132                 VIEWER_ITEM_RADIO_MODES rad_mode = VIEWER_ITEM_RADIO_MODE_OFF;
1133                 if (wifi_device != NULL && wifi_device->ap != NULL) {
1134                         if (wifi_manager_ap_get_connection_state(wifi_device->ap, &state) ==
1135                                         WIFI_MANAGER_ERROR_NONE) {
1136                                 rad_mode = _convert_wifi_state_to_viewer_radio_mode(state);
1137                         }
1138                         wifi_device->ap_status_txt = viewer_list_get_device_status_txt(
1139                                                         wifi_device,
1140                                                         rad_mode);
1141                 } else {
1142                         if (ug_app_state->is_first_scan == true) {
1143                                 int scan_result = wlan_manager_scan();
1144                                 if (scan_result != WLAN_MANAGER_ERR_NONE) {
1145                                         viewer_manager_hide(VIEWER_WINSET_SEARCHING);
1146                                         viewer_manager_header_mode_set(viewer_manager_header_mode_get());
1147                                 }
1148                                 ug_app_state->is_first_scan = false;
1149                                 return NULL;
1150                         }
1151                         no_wifi_device = g_try_new0(wifi_device_info_t, 1);
1152                         if (no_wifi_device == NULL)
1153                                 return NULL;
1154
1155                         no_wifi_device->ssid = g_strdup(sc(PACKAGE, I18N_TYPE_No_Wi_Fi_AP_Found));
1156                         wifi_device = no_wifi_device;
1157                 }
1158         }
1159
1160         gdata = g_try_new0(ug_genlist_data_t, 1);
1161         if (gdata == NULL) {
1162                 if (no_wifi_device) {
1163                         g_free(no_wifi_device->ssid);
1164                         g_free(no_wifi_device);
1165                 }
1166                 return NULL;
1167         }
1168
1169         gdata->device_info = wifi_device;
1170         gdata->radio_mode = VIEWER_ITEM_RADIO_MODE_OFF;
1171
1172         if (!after) {
1173                 /* If the after item is NULL then insert it as first item */
1174                 after = grouptitle;
1175         }
1176
1177         if (no_wifi_device == NULL) {
1178                 ret = elm_genlist_item_insert_after(
1179                                 viewer_list, /*obj*/
1180                                 itc,/*itc*/
1181                                 gdata,/*data*/
1182                                 NULL,/*parent*/
1183                                 after, /*after than*/
1184                                 ELM_GENLIST_ITEM_NONE, /*flags*/
1185                                 __viewer_list_item_clicked_cb,/*func*/
1186                                 NULL);/*func_data*/
1187         } else {
1188                 ret = elm_genlist_item_insert_after(
1189                                 viewer_list, /*obj*/
1190                                 no_wifi_device_itc,/*itc*/
1191                                 gdata,/*data*/
1192                                 NULL,/*parent*/
1193                                 after, /*after than*/
1194                                 ELM_GENLIST_ITEM_NONE, /*flags*/
1195                                 __viewer_list_item_clicked_cb,/*func*/
1196                                 NULL);/*func_data*/
1197         }
1198
1199         if (!ret) {
1200                 assertm_if(NULL == ret, "NULL!!");
1201                 g_free(gdata);
1202         } else {
1203                 /* SECURE_DEBUG_LOG(UG_NAME_NORMAL,
1204                                 "* item add complete item [%p] ssid:[%s] security[%d] size:[%d]",
1205                                 ret,
1206                                 wifi_device->ssid,
1207                                 wifi_device->security_mode,
1208                                 viewer_list_item_size_get()); */
1209
1210                 if (after == grouptitle) {
1211                         first_item = ret;
1212                         if (!last_item)
1213                                 last_item = ret;
1214                 } else {
1215                         last_item = ret;
1216                         if (!first_item)
1217                                 first_item = ret;
1218                 }
1219
1220                 if (ret != NULL)
1221                         elm_genlist_item_update(ret);
1222         }
1223
1224         return ret;
1225 }
1226
1227 void viewer_list_item_del(Elm_Object_Item *it)
1228 {
1229         if (it == NULL)
1230                 return;
1231
1232         if (it == first_item)
1233                 first_item = elm_genlist_item_next_get(first_item);
1234         else if (it == last_item)
1235                 last_item = elm_genlist_item_prev_get(last_item);
1236         elm_object_item_del(it);
1237 }
1238
1239 int viewer_list_item_size_get()
1240 {
1241         int ret = 0;
1242         Elm_Object_Item *it = first_item;
1243
1244         while (it) {
1245                 ret++;
1246                 if (it == last_item)
1247                         break;
1248                 it = elm_genlist_item_next_get(it);
1249         }
1250
1251         return ret;
1252 }
1253
1254 void viewer_list_item_clear(void)
1255 {
1256         __COMMON_FUNC_ENTER__;
1257
1258         Elm_Object_Item *it = first_item;
1259         Elm_Object_Item *nxt = NULL;
1260
1261         while (it) {
1262                 nxt = elm_genlist_item_next_get(it);
1263                 elm_object_item_del(it);
1264                 if (it == last_item)
1265                         break;
1266                 it = nxt;
1267         }
1268
1269         first_item = last_item = NULL;
1270
1271         __COMMON_FUNC_EXIT__;
1272 }
1273
1274 void viewer_list_item_enable_all(void)
1275 {
1276         __COMMON_FUNC_ENTER__;
1277
1278         Elm_Object_Item *it = first_item;
1279
1280         while (it) {
1281                 elm_object_item_disabled_set(it, EINA_FALSE);
1282
1283                 if (it == last_item)
1284                         break;
1285
1286                 it = elm_genlist_item_next_get(it);
1287         }
1288
1289         __COMMON_FUNC_EXIT__;
1290 }
1291
1292 void viewer_list_item_disable_all(void)
1293 {
1294         __COMMON_FUNC_ENTER__;
1295
1296         Elm_Object_Item *it = first_item;
1297
1298         while (it) {
1299                 elm_object_item_disabled_set(it, EINA_TRUE);
1300
1301                 if (it == last_item)
1302                         break;
1303
1304                 it = elm_genlist_item_next_get(it);
1305         }
1306
1307         __COMMON_FUNC_EXIT__;
1308 }
1309
1310 Elm_Object_Item* item_get_for_ap(wifi_manager_ap_h ap)
1311 {
1312         __COMMON_FUNC_ENTER__;
1313         if (!ap) {
1314                 __COMMON_FUNC_EXIT__;
1315                 return NULL;
1316         }
1317
1318         char *essid = NULL;
1319         wifi_manager_security_type_e sec_type = WIFI_MANAGER_SECURITY_TYPE_NONE;
1320
1321         if (WIFI_MANAGER_ERROR_NONE != wifi_manager_ap_get_essid(ap, &essid)) {
1322                 __COMMON_FUNC_EXIT__;
1323                 return NULL;
1324         } else if (WIFI_MANAGER_ERROR_NONE != wifi_manager_ap_get_security_type(ap, &sec_type)) {
1325                 g_free(essid);
1326                 __COMMON_FUNC_EXIT__;
1327                 return NULL;
1328         }
1329
1330         Elm_Object_Item *it = first_item;
1331         while (it) {
1332                 ug_genlist_data_t* gdata = elm_object_item_data_get(it);
1333                 wifi_device_info_t *device_info = NULL;
1334                 if (gdata && (device_info = gdata->device_info)) {
1335                         if (!g_strcmp0(device_info->ssid, essid) && device_info->security_mode == sec_type)
1336                                 break;
1337                 }
1338                 if (it == last_item) {
1339                         it = NULL;
1340                         break;
1341                 }
1342                 it = elm_genlist_item_next_get(it);
1343         }
1344
1345         g_free(essid);
1346         __COMMON_FUNC_EXIT__;
1347         return it;
1348 }
1349
1350 Elm_Object_Item* item_get_for_ssid(const char *ssid)
1351 {
1352         Elm_Object_Item *it = first_item;
1353         while (it) {
1354                 ug_genlist_data_t* gdata = elm_object_item_data_get(it);
1355                 wifi_device_info_t *device_info = NULL;
1356                 if (gdata && (device_info = gdata->device_info)) {
1357                         if (!g_strcmp0(device_info->ssid, ssid))
1358                                 break;
1359                 }
1360                 if (it == last_item) {
1361                         it = NULL;
1362                         break;
1363                 }
1364                 it = elm_genlist_item_next_get(it);
1365         }
1366
1367         return it;
1368 }
1369
1370 static void _hidden_network_cb(void* data, Evas_Object* obj, void* event_info)
1371 {
1372     __COMMON_FUNC_ENTER__;
1373
1374     view_hidden_ap_popup_create(ug_app_state->parent_layout, PACKAGE);
1375
1376     __COMMON_FUNC_EXIT__;
1377 }
1378
1379 void viewer_list_item_hidden_network_set(Elm_Object_Item *item)
1380 {
1381         if (item == NULL)
1382                 return;
1383
1384         last_item = elm_genlist_item_append(viewer_list,
1385                         last_item_itc, NULL, item,
1386                         ELM_GENLIST_ITEM_NONE, _hidden_network_cb, NULL);
1387
1388         elm_genlist_item_select_mode_set(last_item,
1389                         ELM_OBJECT_SELECT_MODE_ALWAYS);
1390
1391         elm_genlist_item_update(last_item);
1392 }