Implement OOBE view #6
[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.sub_title = common_utils_get_ap_security_type_info_txt(PACKAGE,
636                                 device_info, false);
637
638                 popup_info.ok_cb = __passwd_popup_ok_cb;
639                 popup_info.cancel_cb = __passwd_popup_cancel_cb;
640                 popup_info.show_wps_btn = device_info->wps_mode;
641                 popup_info.wps_btn_cb = __wps_options_popup_cb;
642                 popup_info.ap = device_info->ap;
643                 popup_info.cb_data = device_info_temp;
644                 popup_info.sec_type = sec_type;
645
646                 /* TODO: parameter with device_info */
647                 /* TODO: finally parameter with wifi_manager_ap_h, WPA, EAP */
648                 ug_app_state->passpopup = create_passwd_popup(
649                                 ug_app_state->conformant,
650                                 ug_app_state->parent_layout, PACKAGE, &popup_info);
651
652                 if (ug_app_state->passpopup == NULL)
653                         INFO_LOG(UG_NAME_ERR, "Fail to create password popup");
654
655                 g_free(popup_info.sub_title);
656                 break;
657         case WIFI_MANAGER_SECURITY_TYPE_EAP:
658                 ug_app_state->eap_view = create_eap_view(
659                                 ug_app_state->parent_layout, ugd->win_main,
660                                 ug_app_state->conformant,
661                                 PACKAGE, device_info,
662                                 viewer_manager_eap_view_deref);
663                 break;
664         default:
665                 ERROR_LOG(UG_NAME_NORMAL, "Unknown security type [%d]", sec_type);
666                 return;
667         }
668
669 }
670
671 void viewer_list_wifi_connect(wifi_device_info_t *device_info)
672 {
673         bool favorite = false;
674         pswd_popup_create_req_data_t popup_info;
675         wifi_manager_security_type_e sec_type = WIFI_MANAGER_SECURITY_TYPE_NONE;
676         wifi_device_info_t *dev_info_temp = NULL;
677         struct ug_data *ugd = (struct ug_data *)ug_app_state->gadget;
678
679         if (device_info == NULL)
680                 return;
681
682         wifi_manager_ap_is_favorite(device_info->ap, &favorite);
683         if (favorite == true) {
684                 wlan_manager_connect(device_info->ap);
685                 return;
686         }
687
688         if (ug_app_state->passpopup != NULL || ug_app_state->eap_view != NULL) {
689                 INFO_LOG(UG_NAME_ERR, "already launched popup");
690                 return;
691         }
692
693         wifi_manager_ap_get_security_type(device_info->ap, &sec_type);
694
695         switch (sec_type) {
696         case WIFI_MANAGER_SECURITY_TYPE_NONE:
697                 if (ug_app_state->is_hidden) {
698                         wifi_manager_ap_h ap;
699                         char *ssid;
700                         wifi_manager_ap_get_essid(device_info->ap, &ssid);
701                         wlan_manager_ap_hidden_create(ssid, &ap);
702                         g_free(ssid);
703                         wifi_manager_ap_set_security_type(ap, WIFI_MANAGER_SECURITY_TYPE_NONE);
704                         wlan_manager_connect(ap);
705                 } else
706                         wlan_manager_connect(device_info->ap);
707                 break;
708
709         case WIFI_MANAGER_SECURITY_TYPE_WEP:
710         case WIFI_MANAGER_SECURITY_TYPE_WPA_PSK:
711         case WIFI_MANAGER_SECURITY_TYPE_WPA2_PSK:
712                 memset(&popup_info, 0, sizeof(pswd_popup_create_req_data_t));
713
714                 dev_info_temp = view_list_item_device_info_create(device_info->ap);
715
716                 popup_info.title = device_info->ssid;
717                 popup_info.sub_title = common_utils_get_ap_security_type_info_txt(PACKAGE,
718                                 device_info, false);
719
720                 popup_info.ok_cb = __passwd_popup_ok_cb;
721                 popup_info.cancel_cb = __passwd_popup_cancel_cb;
722                 popup_info.show_wps_btn = device_info->wps_mode;
723                 popup_info.wps_btn_cb = __wps_options_popup_cb;
724                 popup_info.ap = device_info->ap;
725                 popup_info.cb_data = dev_info_temp;
726                 popup_info.sec_type = sec_type;
727
728                 /* TODO: parameter with device_info */
729                 /* TODO: finally parameter with wifi_manager_ap_h, WPA, EAP */
730                 ug_app_state->passpopup = create_passwd_popup(
731                                 ug_app_state->conformant,
732                                 ug_app_state->parent_layout, PACKAGE, &popup_info);
733
734                 if (ug_app_state->passpopup == NULL)
735                         INFO_LOG(UG_NAME_ERR, "Fail to create password popup");
736
737                 g_free(popup_info.sub_title);
738                 break;
739
740         case WIFI_MANAGER_SECURITY_TYPE_EAP:
741                 ug_app_state->eap_view = create_eap_view(
742                                 ug_app_state->parent_layout, ugd->win_main,
743                                 ug_app_state->conformant,
744                                 PACKAGE, device_info,
745                                 viewer_manager_eap_view_deref);
746                 break;
747
748         default:
749                 ERROR_LOG(UG_NAME_NORMAL, "Unknown security type[%d]", sec_type);
750                 break;
751         }
752 }
753
754 void viewer_list_clear_disconnect_popup(wifi_manager_ap_h ap)
755 {
756         if (!g_disconnect_popup)
757                 return;
758
759         if (ap && g_disconnect_popup->ap &&
760                         wlan_manager_is_same_network(g_disconnect_popup->ap, ap) != TRUE)
761                 return;
762
763         if (g_disconnect_popup->popup)
764                 evas_object_del(g_disconnect_popup->popup);
765
766         if (g_disconnect_popup->ap)
767                 wifi_manager_ap_destroy(g_disconnect_popup->ap);
768
769         g_free(g_disconnect_popup);
770         g_disconnect_popup = NULL;
771 }
772
773 static void __viewer_list_disconnect_cancel_cb(void *data,
774                 Evas_Object *obj, void *event_info)
775 {
776         struct connecting_cancel_popup_data *popup =
777                         (struct connecting_cancel_popup_data *)data;
778         if (!popup)
779                 return;
780
781         if (popup->popup)
782                 evas_object_del(popup->popup);
783
784         if (popup->ap)
785                 wifi_manager_ap_destroy(popup->ap);
786
787         g_free(popup);
788         g_disconnect_popup = NULL;
789 }
790
791 static gboolean __viewer_list_update_ap(gpointer data)
792 {
793         wifi_manager_ap_h ap = (wifi_manager_ap_h)data;
794
795         viewer_manager_update_item_favorite_status(ap);
796         wifi_manager_ap_destroy(ap);
797
798         return FALSE;
799 }
800
801 static void __viewer_list_disconnect_ok_cb(void *data,
802                 Evas_Object *obj, void *event_info)
803 {
804         guint id;
805         struct connecting_cancel_popup_data *popup =
806                         (struct connecting_cancel_popup_data *)data;
807         if (!popup)
808                 return;
809
810         wlan_manager_disconnect(popup->ap);
811         wlan_manager_forget(popup->ap);
812
813         if (popup->popup)
814                 evas_object_del(popup->popup);
815
816         id = common_util_managed_idle_add(__viewer_list_update_ap, (gpointer)popup->ap);
817         if (!id) {
818                 viewer_manager_update_item_favorite_status(popup->ap);
819                 wifi_manager_ap_destroy(popup->ap);
820         }
821
822         g_free(popup);
823         g_disconnect_popup = NULL;
824 }
825
826 static void __viewer_list_disconnect_popup(wifi_device_info_t *device_info,
827                 Evas_Object *win_main)
828 {
829         popup_btn_info_t popup_data;
830         struct connecting_cancel_popup_data *popup = NULL;
831
832         memset(&popup_data, 0, sizeof(popup_data));
833
834         popup = g_try_new0(struct connecting_cancel_popup_data, 1);
835         if (!popup)
836                 return;
837
838         g_disconnect_popup = popup;
839         wifi_manager_ap_clone(&popup->ap, device_info->ap);
840
841         popup_data.title_txt = "IDS_WIFI_OPT_FORGET_NETWORK";
842         popup_data.info_txt = "IDS_WIFI_POP_CURRENT_NETWORK_WILL_BE_DISCONNECTED";
843         popup_data.btn1_cb = __viewer_list_disconnect_cancel_cb;
844         popup_data.btn1_txt = "IDS_WIFI_SK_CANCEL";
845         popup_data.btn1_data = popup;
846         popup_data.btn2_cb = __viewer_list_disconnect_ok_cb;
847         popup_data.btn2_txt = "IDS_WIFI_SK_FORGET";
848         popup_data.btn2_data = popup;
849
850         popup->popup = common_utils_show_info_popup(win_main, &popup_data);
851 }
852
853 static void __viewer_list_item_clicked_cb(void *data, Evas_Object *obj,
854                 void *event_info)
855 {
856         __COMMON_FUNC_ENTER__;
857
858         assertm_if(NULL == event_info, "event_info is NULL!!");
859         assertm_if(NULL == obj, "obj is NULL!!");
860
861         Elm_Object_Item *it = (Elm_Object_Item *)event_info;
862         ug_genlist_data_t *gdata = NULL;
863         wifi_device_info_t *device_info = NULL;
864
865         gdata = (ug_genlist_data_t *)elm_object_item_data_get(it);
866         retm_if(NULL == gdata);
867
868         device_info = gdata->device_info;
869         retm_if(NULL == device_info || NULL == device_info->ssid);
870
871         int item_state = gdata->radio_mode;
872         int current_state = 0;
873
874         SECURE_INFO_LOG(UG_NAME_NORMAL, "ssid --- %s", device_info->ssid);
875         INFO_LOG(UG_NAME_NORMAL, "ap --- %p", device_info->ap);
876         INFO_LOG(UG_NAME_NORMAL, "current item_state state is --- %d", item_state);
877
878         if (ug_app_state->is_lbhome == EINA_TRUE &&
879                         ug_app_state->app_control != NULL) {
880                 INFO_LOG(UG_NAME_NORMAL, "exit with reply");
881                 char *bssid = NULL;
882                 app_control_h reply;
883
884                 app_control_create(&reply);
885                 wifi_manager_ap_get_bssid(device_info->ap, &bssid);
886                 SECURE_INFO_LOG(UG_NAME_NORMAL, "bssid %s, ssid %s", bssid, device_info->ssid);
887
888                 app_control_add_extra_data(reply, "bssid", bssid);
889                 app_control_add_extra_data(reply, "ssid", device_info->ssid);
890                 app_control_reply_to_launch_request(reply, ug_app_state->app_control,
891                                 APP_CONTROL_RESULT_SUCCEEDED);
892                 app_control_destroy(reply);
893                 g_free(bssid);
894                 wifi_exit();
895                 return;
896         }
897
898         switch (item_state) {
899         case VIEWER_ITEM_RADIO_MODE_OFF:
900                 current_state = viewer_manager_header_mode_get();
901
902                 INFO_LOG(UG_NAME_NORMAL, "Clicked AP information\n");
903                 INFO_LOG(UG_NAME_NORMAL, "header mode [%d]", current_state);
904
905                 switch (current_state) {
906                 case HEADER_MODE_ON:
907                 case HEADER_MODE_CONNECTED:
908                 case HEADER_MODE_CONNECTING:
909                 case HEADER_MODE_SEARCHING:
910                         viewer_list_wifi_connect(device_info);
911                         break;
912
913                 case HEADER_MODE_OFF:
914                 case HEADER_MODE_ACTIVATING:
915                 case HEADER_MODE_DEACTIVATING:
916                 default:
917                         INFO_LOG(UG_NAME_NORMAL, "Ignore click");
918                         break;
919                 }
920                 break;
921
922         case VIEWER_ITEM_RADIO_MODE_CONNECTING:
923         case VIEWER_ITEM_RADIO_MODE_CONFIGURATION:
924                 __viewer_list_disconnect_popup(device_info, ug_app_state->layout_main);
925                 break;
926         case VIEWER_ITEM_RADIO_MODE_CONNECTED:
927         default:
928                 INFO_LOG(UG_NAME_NORMAL, "Ignore click");
929                 break;
930         }
931
932         elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
933
934         __COMMON_FUNC_EXIT__;
935 }
936
937 static char *viewer_list_get_device_status_txt(wifi_device_info_t *wifi_device,
938                 VIEWER_ITEM_RADIO_MODES mode)
939 {
940         char *status_txt = NULL;
941         int current_state = 0;
942
943         current_state = viewer_manager_header_mode_get();
944         /* The strings are currently hard coded. It will be replaced with string ids later */
945         if (VIEWER_ITEM_RADIO_MODE_CONNECTING == mode) {
946                 status_txt = g_strdup(sc(PACKAGE, I18N_TYPE_Connecting));
947         } else if (VIEWER_ITEM_RADIO_MODE_CONFIGURATION == mode) {
948                 status_txt = g_strdup(sc(PACKAGE, I18N_TYPE_Obtaining_IP_addr));
949         } else if (VIEWER_ITEM_RADIO_MODE_CONNECTED == mode) {
950                 if (connection_manager_is_wifi_connection_used() ||
951                                 current_state == HEADER_MODE_CONNECTED) {
952                         status_txt = g_strdup(sc(PACKAGE, I18N_TYPE_Connected));
953                 }
954         } else if (VIEWER_ITEM_RADIO_MODE_OFF == mode) {
955                 status_txt = common_utils_get_ap_security_type_info_txt(PACKAGE,
956                         wifi_device, true);
957         } else {
958                 status_txt = g_strdup(sc(PACKAGE, I18N_TYPE_Unknown));
959                 INFO_LOG(UG_NAME_NORMAL, "Invalid mode: %d", mode);
960         }
961
962         return status_txt;
963 }
964
965 Evas_Object* viewer_list_create(Evas_Object *win)
966 {
967         __COMMON_FUNC_ENTER__;
968
969         assertm_if(NULL == win, "NULL!!");
970         assertm_if(NULL != viewer_list, "Err!!");
971
972         viewer_list = elm_genlist_add(win);
973         assertm_if(NULL == viewer_list, "NULL!!");
974
975         if (wifi_get_ug_type() == UG_VIEW_OOBE) {
976                 elm_object_style_set(viewer_list, "solid/default");
977                 elm_object_color_class_color_set(viewer_list, "bg", 255, 255, 255, 255);
978         }
979
980         // To use multiline textblock/entry/editfield in genlist, set height_for_width mode
981         // then the item's height is calculated while the item's width fits to genlist width.
982         elm_genlist_mode_set(viewer_list, ELM_LIST_COMPRESS);
983         //elm_genlist_realization_mode_set(viewer_list, EINA_TRUE);
984
985         evas_object_size_hint_weight_set(viewer_list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
986         evas_object_size_hint_align_set(viewer_list, EVAS_HINT_FILL, EVAS_HINT_FILL);
987
988         itc = elm_genlist_item_class_new();
989         itc->item_style = WIFI_GENLIST_2LINE_TOP_TEXT_ICON_STYLE;
990         itc->func.text_get = _gl_listview_text_get;
991         itc->func.content_get = _gl_listview_content_get;
992         itc->func.state_get = NULL;
993         itc->func.del = _gl_listview_del;
994
995         no_wifi_device_itc = elm_genlist_item_class_new();
996         no_wifi_device_itc->item_style = WIFI_GENLIST_1LINE_TEXT_STYLE;
997         no_wifi_device_itc->func.text_get = _gl_listview_text_get;
998         no_wifi_device_itc->func.content_get = NULL;
999         no_wifi_device_itc->func.state_get = NULL;
1000         no_wifi_device_itc->func.del = _gl_listview_del;
1001
1002         if (wifi_get_ug_type() == UG_VIEW_OOBE) {
1003                 last_item_itc = elm_genlist_item_class_new();
1004                 last_item_itc->item_style = WIFI_GENLIST_1LINE_TEXT_ICON_STYLE;
1005                 last_item_itc->func.text_get = _gl_hidden_network_text_get;
1006                 last_item_itc->func.content_get = _gl_hidden_network_content_get;
1007                 last_item_itc->func.del = NULL;
1008         }
1009
1010         first_item = last_item = NULL;
1011
1012         evas_object_smart_callback_add(viewer_list, "realized",
1013                         _gl_realized, NULL);
1014         evas_object_smart_callback_add(viewer_list, "language,changed",
1015                         gl_lang_changed, NULL);
1016
1017         __COMMON_FUNC_EXIT__;
1018         return viewer_list;
1019 }
1020
1021 void viewer_list_title_item_del(void)
1022 {
1023         if (grouptitle != NULL) {
1024                 elm_object_item_del(grouptitle);
1025                 grouptitle = NULL;
1026         }
1027 }
1028
1029 void viewer_list_title_item_update(void)
1030 {
1031         if (grouptitle != NULL)
1032                 elm_genlist_item_update(grouptitle);
1033 }
1034
1035 void viewer_list_title_item_set(Elm_Object_Item *item_header)
1036 {
1037         if (item_header == NULL)
1038                 return;
1039
1040         if (grouptitle != NULL) {
1041                 elm_genlist_item_update(grouptitle);
1042                 return;
1043         }
1044
1045         //memset(&grouptitle_itc, 0, sizeof(grouptitle_itc));
1046         grouptitle_itc = elm_genlist_item_class_new();
1047         if (wifi_get_ug_type() == UG_VIEW_OOBE) {
1048                 grouptitle_itc->item_style = WIFI_GENLIST_FULL_STYLE;
1049                 grouptitle_itc->func.text_get = NULL;
1050                 grouptitle_itc->func.content_get = NULL;
1051         } else {
1052                 grouptitle_itc->item_style = WIFI_GENLIST_GROUP_INDEX_STYLE;
1053                 grouptitle_itc->func.text_get = _gl_text_available_networks_get;
1054                 grouptitle_itc->func.content_get = _gl_content_scanning_icon_get;
1055         }
1056
1057         grouptitle = elm_genlist_item_insert_after(viewer_list,
1058                         grouptitle_itc, NULL, NULL, item_header,
1059                         ELM_GENLIST_ITEM_NONE, NULL, NULL);
1060
1061         assertm_if(NULL == grouptitle, "NULL!!");
1062
1063         elm_genlist_item_select_mode_set(grouptitle,
1064                         ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1065 }
1066
1067 int viewer_list_item_radio_mode_set(Elm_Object_Item* item,
1068                 VIEWER_ITEM_RADIO_MODES mode)
1069 {
1070         __COMMON_FUNC_ENTER__;
1071
1072         if (NULL == item) {
1073                 INFO_LOG(COMMON_NAME_ERR, "item is NULL");
1074                 return FALSE;
1075         }
1076
1077         ug_genlist_data_t* gdata = (ug_genlist_data_t *) elm_object_item_data_get(item);
1078         if (NULL == gdata || NULL == gdata->device_info) {
1079                 INFO_LOG(COMMON_NAME_ERR, "gdata or device_info is NULL");
1080                 return FALSE;
1081         }
1082
1083         if (gdata->radio_mode == mode) {
1084                 SECURE_INFO_LOG(UG_NAME_NORMAL, "[%s] is already in requested state", gdata->device_info->ssid);
1085                 return FALSE;
1086         }
1087
1088         SECURE_INFO_LOG(UG_NAME_NORMAL, "[%s] AP Item State Transition from [%d] --> [%d]", gdata->device_info->ssid, gdata->radio_mode, mode);
1089         gdata->radio_mode = mode;
1090         if (gdata->device_info->ap_status_txt) {
1091                 g_free(gdata->device_info->ap_status_txt);
1092                 gdata->device_info->ap_status_txt = viewer_list_get_device_status_txt(gdata->device_info, mode);
1093         }
1094
1095         if (item != NULL)
1096                 elm_genlist_item_update(item);
1097
1098         __COMMON_FUNC_EXIT__;
1099         return TRUE;
1100 }
1101
1102 static wifi_manager_connection_state_e _convert_wifi_state_to_viewer_radio_mode(
1103                 wifi_manager_connection_state_e state)
1104 {
1105         switch (state) {
1106         case WIFI_MANAGER_CONNECTION_STATE_ASSOCIATION:
1107                 return VIEWER_ITEM_RADIO_MODE_CONNECTING;
1108         case WIFI_MANAGER_CONNECTION_STATE_CONFIGURATION:
1109                 return VIEWER_ITEM_RADIO_MODE_CONFIGURATION;
1110         case WIFI_MANAGER_CONNECTION_STATE_CONNECTED:
1111                 return VIEWER_ITEM_RADIO_MODE_CONNECTED;
1112         default:
1113                 return VIEWER_ITEM_RADIO_MODE_OFF;
1114         }
1115 }
1116
1117 Elm_Object_Item *viewer_list_item_insert_after(wifi_device_info_t *wifi_device,
1118                 Elm_Object_Item *after)
1119 {
1120         Elm_Object_Item* ret = NULL;
1121         ug_genlist_data_t* gdata = NULL;
1122         wifi_device_info_t *no_wifi_device = NULL;
1123         retvm_if(NULL == viewer_list, NULL);
1124
1125         if (_is_emulator()) {
1126                 if (wifi_device != NULL) {
1127                         wifi_device->ap_status_txt = viewer_list_get_device_status_txt(
1128                                                         wifi_device,
1129                                                         VIEWER_ITEM_RADIO_MODE_OFF);
1130                 } else {
1131                         no_wifi_device = g_try_new0(wifi_device_info_t, 1);
1132                         if (no_wifi_device == NULL)
1133                                 return NULL;
1134
1135                         no_wifi_device->ssid = g_strdup(sc(PACKAGE, I18N_TYPE_No_Wi_Fi_AP_Found));
1136                         wifi_device = no_wifi_device;
1137                 }
1138         } else {
1139                 wifi_manager_connection_state_e state = WIFI_MANAGER_CONNECTION_STATE_DISCONNECTED;
1140                 VIEWER_ITEM_RADIO_MODES rad_mode = VIEWER_ITEM_RADIO_MODE_OFF;
1141                 if (wifi_device != NULL && wifi_device->ap != NULL) {
1142                         if (wifi_manager_ap_get_connection_state(wifi_device->ap, &state) ==
1143                                         WIFI_MANAGER_ERROR_NONE) {
1144                                 rad_mode = _convert_wifi_state_to_viewer_radio_mode(state);
1145                         }
1146                         wifi_device->ap_status_txt = viewer_list_get_device_status_txt(
1147                                                         wifi_device,
1148                                                         rad_mode);
1149                 } else {
1150                         if (ug_app_state->is_first_scan == true) {
1151                                 int scan_result = wlan_manager_scan();
1152                                 if (scan_result != WLAN_MANAGER_ERR_NONE) {
1153                                         viewer_manager_hide(VIEWER_WINSET_SEARCHING);
1154                                         viewer_manager_header_mode_set(viewer_manager_header_mode_get());
1155                                 }
1156                                 ug_app_state->is_first_scan = false;
1157                                 return NULL;
1158                         }
1159                         no_wifi_device = g_try_new0(wifi_device_info_t, 1);
1160                         if (no_wifi_device == NULL)
1161                                 return NULL;
1162
1163                         no_wifi_device->ssid = g_strdup(sc(PACKAGE, I18N_TYPE_No_Wi_Fi_AP_Found));
1164                         wifi_device = no_wifi_device;
1165                 }
1166         }
1167
1168         gdata = g_try_new0(ug_genlist_data_t, 1);
1169         if (gdata == NULL) {
1170                 if (no_wifi_device) {
1171                         g_free(no_wifi_device->ssid);
1172                         g_free(no_wifi_device);
1173                 }
1174                 return NULL;
1175         }
1176
1177         gdata->device_info = wifi_device;
1178         gdata->radio_mode = VIEWER_ITEM_RADIO_MODE_OFF;
1179
1180         if (!after) {
1181                 /* If the after item is NULL then insert it as first item */
1182                 after = grouptitle;
1183         }
1184
1185         if (no_wifi_device == NULL) {
1186                 ret = elm_genlist_item_insert_after(
1187                                 viewer_list, /*obj*/
1188                                 itc,/*itc*/
1189                                 gdata,/*data*/
1190                                 NULL,/*parent*/
1191                                 after, /*after than*/
1192                                 ELM_GENLIST_ITEM_NONE, /*flags*/
1193                                 __viewer_list_item_clicked_cb,/*func*/
1194                                 NULL);/*func_data*/
1195         } else {
1196                 ret = elm_genlist_item_insert_after(
1197                                 viewer_list, /*obj*/
1198                                 no_wifi_device_itc,/*itc*/
1199                                 gdata,/*data*/
1200                                 NULL,/*parent*/
1201                                 after, /*after than*/
1202                                 ELM_GENLIST_ITEM_NONE, /*flags*/
1203                                 __viewer_list_item_clicked_cb,/*func*/
1204                                 NULL);/*func_data*/
1205         }
1206
1207         if (!ret) {
1208                 assertm_if(NULL == ret, "NULL!!");
1209                 g_free(gdata);
1210         } else {
1211                 /* SECURE_DEBUG_LOG(UG_NAME_NORMAL,
1212                                 "* item add complete item [%p] ssid:[%s] security[%d] size:[%d]",
1213                                 ret,
1214                                 wifi_device->ssid,
1215                                 wifi_device->security_mode,
1216                                 viewer_list_item_size_get()); */
1217
1218                 if (after == grouptitle) {
1219                         first_item = ret;
1220                         if (!last_item)
1221                                 last_item = ret;
1222                 } else {
1223                         last_item = ret;
1224                         if (!first_item)
1225                                 first_item = ret;
1226                 }
1227
1228                 if (ret != NULL)
1229                         elm_genlist_item_update(ret);
1230         }
1231
1232         return ret;
1233 }
1234
1235 void viewer_list_item_del(Elm_Object_Item *it)
1236 {
1237         if (it == NULL)
1238                 return;
1239
1240         if (it == first_item)
1241                 first_item = elm_genlist_item_next_get(first_item);
1242         else if (it == last_item)
1243                 last_item = elm_genlist_item_prev_get(last_item);
1244         elm_object_item_del(it);
1245 }
1246
1247 int viewer_list_item_size_get()
1248 {
1249         int ret = 0;
1250         Elm_Object_Item *it = first_item;
1251
1252         while (it) {
1253                 ret++;
1254                 if (it == last_item)
1255                         break;
1256                 it = elm_genlist_item_next_get(it);
1257         }
1258
1259         return ret;
1260 }
1261
1262 void viewer_list_item_clear(void)
1263 {
1264         __COMMON_FUNC_ENTER__;
1265
1266         Elm_Object_Item *it = first_item;
1267         Elm_Object_Item *nxt = NULL;
1268
1269         while (it) {
1270                 nxt = elm_genlist_item_next_get(it);
1271                 elm_object_item_del(it);
1272                 if (it == last_item)
1273                         break;
1274                 it = nxt;
1275         }
1276
1277         first_item = last_item = NULL;
1278
1279         __COMMON_FUNC_EXIT__;
1280 }
1281
1282 void viewer_list_item_enable_all(void)
1283 {
1284         __COMMON_FUNC_ENTER__;
1285
1286         Elm_Object_Item *it = first_item;
1287
1288         while (it) {
1289                 elm_object_item_disabled_set(it, EINA_FALSE);
1290
1291                 if (it == last_item)
1292                         break;
1293
1294                 it = elm_genlist_item_next_get(it);
1295         }
1296
1297         __COMMON_FUNC_EXIT__;
1298 }
1299
1300 void viewer_list_item_disable_all(void)
1301 {
1302         __COMMON_FUNC_ENTER__;
1303
1304         Elm_Object_Item *it = first_item;
1305
1306         while (it) {
1307                 elm_object_item_disabled_set(it, EINA_TRUE);
1308
1309                 if (it == last_item)
1310                         break;
1311
1312                 it = elm_genlist_item_next_get(it);
1313         }
1314
1315         __COMMON_FUNC_EXIT__;
1316 }
1317
1318 Elm_Object_Item* item_get_for_ap(wifi_manager_ap_h ap)
1319 {
1320         __COMMON_FUNC_ENTER__;
1321         if (!ap) {
1322                 __COMMON_FUNC_EXIT__;
1323                 return NULL;
1324         }
1325
1326         char *essid = NULL;
1327         wifi_manager_security_type_e sec_type = WIFI_MANAGER_SECURITY_TYPE_NONE;
1328
1329         if (WIFI_MANAGER_ERROR_NONE != wifi_manager_ap_get_essid(ap, &essid)) {
1330                 __COMMON_FUNC_EXIT__;
1331                 return NULL;
1332         } else if (WIFI_MANAGER_ERROR_NONE != wifi_manager_ap_get_security_type(ap, &sec_type)) {
1333                 g_free(essid);
1334                 __COMMON_FUNC_EXIT__;
1335                 return NULL;
1336         }
1337
1338         Elm_Object_Item *it = first_item;
1339         while (it) {
1340                 ug_genlist_data_t* gdata = elm_object_item_data_get(it);
1341                 wifi_device_info_t *device_info = NULL;
1342                 if (gdata && (device_info = gdata->device_info)) {
1343                         if (!g_strcmp0(device_info->ssid, essid) && device_info->security_mode == sec_type)
1344                                 break;
1345                 }
1346                 if (it == last_item) {
1347                         it = NULL;
1348                         break;
1349                 }
1350                 it = elm_genlist_item_next_get(it);
1351         }
1352
1353         g_free(essid);
1354         __COMMON_FUNC_EXIT__;
1355         return it;
1356 }
1357
1358 Elm_Object_Item* item_get_for_ssid(const char *ssid)
1359 {
1360         Elm_Object_Item *it = first_item;
1361         while (it) {
1362                 ug_genlist_data_t* gdata = elm_object_item_data_get(it);
1363                 wifi_device_info_t *device_info = NULL;
1364                 if (gdata && (device_info = gdata->device_info)) {
1365                         if (!g_strcmp0(device_info->ssid, ssid))
1366                                 break;
1367                 }
1368                 if (it == last_item) {
1369                         it = NULL;
1370                         break;
1371                 }
1372                 it = elm_genlist_item_next_get(it);
1373         }
1374
1375         return it;
1376 }
1377
1378 static void _hidden_network_cb(void* data, Evas_Object* obj, void* event_info)
1379 {
1380     __COMMON_FUNC_ENTER__;
1381
1382     view_hidden_ap_popup_create(ug_app_state->parent_layout, PACKAGE);
1383
1384     __COMMON_FUNC_EXIT__;
1385 }
1386
1387 void viewer_list_item_hidden_network_set(Elm_Object_Item *item)
1388 {
1389         if (item == NULL)
1390                 return;
1391
1392         last_item = elm_genlist_item_append(viewer_list,
1393                         last_item_itc, NULL, item,
1394                         ELM_GENLIST_ITEM_NONE, _hidden_network_cb, NULL);
1395
1396         elm_genlist_item_select_mode_set(last_item,
1397                         ELM_OBJECT_SELECT_MODE_ALWAYS);
1398
1399         elm_genlist_item_update(last_item);
1400 }