Fix genlist item line problem
[apps/native/ug-wifi-efl.git] / sources / ui-gadget / viewers-layout / wifi_viewer_list.c
1 /*
2  * Wi-Fi
3  *
4  * Copyright 2012-2013 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://floralicense.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 "common_utils.h"
22 #include "ug_wifi.h"
23 #include "wlan_manager.h"
24 #include "view_detail.h"
25 #include "viewer_list.h"
26 #include "viewer_manager.h"
27 #include "appcoreWrapper.h"
28 #include "i18nmanager.h"
29
30 #define LIST_ITEM_CONNECTED_AP_FONT_SIZE                28
31 #define LIST_ITEM_CONNECTED_AP_FONT_COLOR               "#3B73B6"
32 #define LIST_ITEM_CONNECTED_AP_FONT_COLOR_HL    "#FFFFFF"
33 #define FIRST_ITEM_NUMBER                                               8
34
35
36 static Evas_Object* viewer_list = NULL;
37 static Elm_Object_Item* first_item = NULL;
38 static Elm_Object_Item* last_item = NULL;
39
40 static Elm_Genlist_Item_Class itc;
41 static Elm_Genlist_Item_Class grouptitle_itc;
42 static Elm_Object_Item* grouptitle = NULL;
43
44 extern wifi_appdata *ug_app_state;
45
46 static void _gl_listview_more_btn_cb(void *data, Evas_Object *obj, void *event_info)
47 {
48         __COMMON_FUNC_ENTER__;
49
50         INFO_LOG(UG_NAME_NORMAL,"=================\n");
51         INFO_LOG(UG_NAME_NORMAL," %s %d\n", __func__ ,__LINE__);
52         INFO_LOG(UG_NAME_NORMAL,"=================\n");
53
54         if (data == NULL) {
55                 __COMMON_FUNC_EXIT__;
56                 return;
57         }
58
59         wifi_device_info_t *device_info = (wifi_device_info_t *)data;
60
61         DEBUG_LOG(UG_NAME_NORMAL, "ssid [%s]", device_info->ssid);
62
63         view_detail(device_info, ug_app_state->layout_main);
64
65         __COMMON_FUNC_EXIT__;
66 }
67
68 static char* _gl_listview_text_get(void *data, Evas_Object *obj, const char *part)
69 {
70         char* det = NULL;
71
72         ug_genlist_data_t* gdata = (ug_genlist_data_t*) data;
73         retvm_if(NULL == gdata || NULL == gdata->device_info, NULL);
74
75         assertm_if(NULL == gdata->device_info->ssid, "NULL!!");
76         assertm_if(NULL == gdata->device_info->ap_status_txt, "NULL!!");
77
78         if (!strncmp(part, "elm.text.1", strlen(part))) {
79                 det = g_strdup(gdata->device_info->ssid);
80                 assertm_if(NULL == det, "NULL!!");
81         } else if (!strncmp(part, "elm.text.2", strlen(part))) {
82                 if (VIEWER_ITEM_RADIO_MODE_CONNECTED == gdata->radio_mode) {
83                         if (FALSE == gdata->highlighted)
84                                 det = g_strdup_printf("<color=%s><b>%s</b></color>", LIST_ITEM_CONNECTED_AP_FONT_COLOR, gdata->device_info->ap_status_txt);
85                         else
86                                 det = g_strdup_printf("<color=%s><b>%s</b></color>", LIST_ITEM_CONNECTED_AP_FONT_COLOR_HL, gdata->device_info->ap_status_txt);
87                 } else
88                         det = g_strdup(gdata->device_info->ap_status_txt);
89                 assertm_if(NULL == det, "NULL!!");
90         }
91         return det;
92 }
93
94 static Evas_Object *_gl_listview_content_get(void *data, Evas_Object *obj, const char *part)
95 {
96         ug_genlist_data_t *gdata = (ug_genlist_data_t *)data;
97         retvm_if(NULL == gdata, NULL);
98
99         Evas_Object *icon = NULL;
100
101         if (gdata->device_info->ap_image_path == NULL) {
102                 /* if there is no ap_image_path (NO AP Found situation) */
103                 DEBUG_LOG(UG_NAME_ERR, "Fatal: Image path is NULL");
104         } else if (!strncmp(part, "elm.icon.1", strlen(part))) {
105                 /* for strength */
106                 char *temp_str = NULL;
107                 icon = elm_image_add(obj);
108                 retvm_if(NULL == icon, NULL);
109
110                 if (FALSE == gdata->highlighted)
111                         temp_str = g_strdup_printf("%s.png", gdata->device_info->ap_image_path);
112                 else
113                         temp_str = g_strdup_printf("%s_press.png", gdata->device_info->ap_image_path);
114                 elm_image_file_set(icon, temp_str, NULL);
115                 g_free(temp_str);
116         } else if (!strncmp(part, "elm.icon.2", strlen(part))) {
117                 if (VIEWER_ITEM_RADIO_MODE_CONNECTING == gdata->radio_mode) {
118                         icon = elm_progressbar_add(obj);
119                         retvm_if(NULL == icon, NULL);
120
121                         elm_object_style_set(icon, "list_process");
122                         evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, 0.5);
123                         evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
124                         elm_progressbar_pulse(icon, TRUE);
125                 } else {
126                         icon = elm_button_add(obj);
127                         retvm_if(NULL == icon, NULL);
128
129                         elm_object_style_set(icon, "reveal");
130                         evas_object_smart_callback_add(icon, "clicked", _gl_listview_more_btn_cb, gdata->device_info);
131                         evas_object_propagate_events_set(icon, EINA_FALSE);
132                 }
133         }
134
135         return icon;
136 }
137
138 static void _gl_listview_del(void* data, Evas_Object* obj)
139 {
140         if (data == NULL)
141                 return;
142
143         ug_genlist_data_t* gdata = (ug_genlist_data_t*) data;
144         retm_if(NULL == gdata || NULL == gdata->device_info);
145
146         DEBUG_LOG(UG_NAME_NORMAL, "del target ssid:[%s]", gdata->device_info->ssid);
147
148         g_free(gdata->device_info->ap_image_path);
149         g_free(gdata->device_info->ap_status_txt);
150         g_free(gdata->device_info->ssid);
151         wifi_ap_destroy(gdata->device_info->ap);
152         g_free(gdata->device_info);
153         g_free(gdata);
154
155         return;
156 }
157
158 static char* _gl_text_title_get(void *data, Evas_Object *obj, const char *part)
159 {
160         assertm_if(NULL == obj, "NULL!!");
161         assertm_if(NULL == part, "NULL!!");
162
163         return (char*) g_strdup(sc(PACKAGE, I18N_TYPE_WiFi_network));
164 }
165
166 static Evas_Object *_gl_content_title_get(void *data, Evas_Object *obj, const char *part)
167 {
168         __COMMON_FUNC_ENTER__;
169
170         Evas_Object *title_progressbar = NULL;
171
172         if (HEADER_MODE_SEARCHING == viewer_manager_header_mode_get()) {
173                 if (!strcmp(part, "elm.icon")) {
174                         title_progressbar  = elm_progressbar_add(obj);
175                         elm_object_style_set(title_progressbar, "list_process_small");
176                         elm_progressbar_horizontal_set(title_progressbar, EINA_TRUE);
177                         elm_progressbar_pulse(title_progressbar, EINA_TRUE);
178                 }
179         }
180
181         __COMMON_FUNC_EXIT__;
182         return title_progressbar;
183 }
184
185 Elm_Object_Item* viewer_list_get_first_item(void)
186 {
187         return first_item;
188 }
189
190 static Elm_Object_Item* viewer_list_get_last_item(void)
191 {
192         return last_item;
193 }
194
195 static char *_access_info_cb(void *data, Evas_Object *obj)
196 {
197         char *strength = NULL;
198         char *buf = NULL;
199
200         ug_genlist_data_t *gdata = (ug_genlist_data_t *)data;
201         if (!gdata)
202                 return NULL;
203
204         strength = common_utils_get_rssi_text(PACKAGE, gdata->device_info->rssi);
205         buf = g_strdup_printf("%s %s %s", strength, gdata->device_info->ssid, gdata->device_info->ap_status_txt);
206
207         g_free(strength);
208         return buf;
209 }
210
211 static void _gl_realized(void *data, Evas_Object *obj, void *event_info)
212 {
213         HEADER_MODES header_mode = viewer_manager_header_mode_get();
214
215         if (header_mode == HEADER_MODE_ACTIVATING ||
216                 header_mode == HEADER_MODE_DEACTIVATING ||
217                 header_mode == HEADER_MODE_OFF)
218                 return ;
219
220         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
221         int index = (int)elm_genlist_item_index_get(item);
222         int first_item_index = (int)elm_genlist_item_index_get(viewer_list_get_first_item());
223         int last_item_index = (int)elm_genlist_item_index_get(viewer_list_get_last_item());
224
225         if (last_item_index == FIRST_ITEM_NUMBER)
226                 return ;
227
228         if (first_item_index == -1) {
229                 int group_index = (int)elm_genlist_item_index_get(grouptitle);
230                 first_item_index = group_index+1;
231         }
232
233         if (first_item_index <= index && first_item_index - last_item_index) {
234                 if(index == first_item_index)
235                         elm_object_item_signal_emit(item, "elm,state,top", "");
236                 else if (index == last_item_index)
237                         elm_object_item_signal_emit(item, "elm,state,bottom", "");
238                 else
239                         elm_object_item_signal_emit(item, "elm,state,center", "");
240
241                 Evas_Object *ao = elm_object_item_access_object_get(item);
242                 elm_access_info_cb_set(ao, ELM_ACCESS_INFO, _access_info_cb, elm_object_item_data_get(item));
243                 elm_access_info_set(ao, ELM_ACCESS_TYPE, "double tap to connect device");
244                 elm_access_info_set(ao, ELM_ACCESS_STATE, "More button");
245         }
246 }
247
248 static void _gl_highlighted(void *data, Evas_Object *obj, void *event_info)
249 {
250         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
251         if (item) {
252                 ug_genlist_data_t *gdata = (ug_genlist_data_t *)elm_object_item_data_get(item);
253                 if (gdata) {
254                         gdata->highlighted = TRUE;
255                         elm_genlist_item_fields_update(item, "elm.icon.1", ELM_GENLIST_ITEM_FIELD_CONTENT);
256                         elm_genlist_item_fields_update(item, "elm.text.2", ELM_GENLIST_ITEM_FIELD_TEXT);
257                 }
258         }
259 }
260
261 static void _gl_unhighlighted(void *data, Evas_Object *obj, void *event_info)
262 {
263         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
264         if (item) {
265                 ug_genlist_data_t *gdata = (ug_genlist_data_t *)elm_object_item_data_get(item);
266                 if (gdata) {
267                         gdata->highlighted = FALSE;
268                         elm_genlist_item_fields_update(item, "elm.icon.1", ELM_GENLIST_ITEM_FIELD_CONTENT);
269                         elm_genlist_item_fields_update(item, "elm.text.2", ELM_GENLIST_ITEM_FIELD_TEXT);
270                 }
271         }
272 }
273
274 static void __passwd_popup_cancel_cb(void *data,  Evas_Object *obj,
275                 void *event_info)
276 {
277         __COMMON_FUNC_ENTER__;
278
279         if (ug_app_state->passpopup == NULL)
280                 return;
281
282         passwd_popup_free(ug_app_state->passpopup);
283         ug_app_state->passpopup = NULL;
284
285         __COMMON_FUNC_EXIT__;
286 }
287
288 static void __passwd_popup_ok_cb(void *data, Evas_Object *obj, void *event_info)
289 {
290         __COMMON_FUNC_ENTER__;
291
292         wifi_ap_h ap = NULL;
293         int password_len = 0;
294         const char *password = NULL;
295         wifi_security_type_e sec_type = WIFI_SECURITY_TYPE_NONE;
296
297         if (ug_app_state->passpopup == NULL)
298                 return;
299
300         ap = passwd_popup_get_ap(ug_app_state->passpopup);
301         password = passwd_popup_get_txt(ug_app_state->passpopup);
302         password_len = strlen(password);
303
304         wifi_ap_get_security_type(ap, &sec_type);
305
306         switch (sec_type) {
307         case WIFI_SECURITY_TYPE_WEP:
308                 if (password_len != 5 && password_len != 13 &&
309                                 password_len != 26 && password_len != 10) {
310                         winset_popup_mode_set(ug_app_state->popup_manager,
311                                         POPUP_OPTION_WEP_PSWD_LEN_ERROR, NULL);
312
313                         goto popup_ok_cb_exit;
314                 }
315                 break;
316
317         case WIFI_SECURITY_TYPE_WPA_PSK:
318         case WIFI_SECURITY_TYPE_WPA2_PSK:
319                 if (password_len < 8 || password_len > 63) {
320                         winset_popup_mode_set(ug_app_state->popup_manager,
321                                         POPUP_OPTION_WPA_PSWD_LEN_ERROR, NULL);
322
323                         goto popup_ok_cb_exit;
324                 }
325                 break;
326
327         default:
328                 ERROR_LOG(UG_NAME_NORMAL, "Wrong security mode: %d", sec_type);
329                 passwd_popup_free(ug_app_state->passpopup);
330                 ug_app_state->passpopup = NULL;
331
332                 goto popup_ok_cb_exit;
333         }
334
335         wlan_manager_connect_with_password(ap, password);
336
337         passwd_popup_free(ug_app_state->passpopup);
338         ug_app_state->passpopup = NULL;
339
340 popup_ok_cb_exit:
341         g_free((gpointer)password);
342
343         __COMMON_FUNC_EXIT__;
344 }
345
346 static void __wps_pbc_popup_cancel_connecting(void *data, Evas_Object *obj,
347                 void *event_info)
348 {
349         if (ug_app_state->passpopup == NULL)
350                 return;
351
352         wifi_ap_h ap = passwd_popup_get_ap(ug_app_state->passpopup);;
353
354         int ret = wlan_manager_disconnect(ap);
355         if (ret != WLAN_MANAGER_ERR_NONE)
356                 ERROR_LOG(UG_NAME_NORMAL, "Failed WPS PBC cancellation [0x%x]", ap);
357
358         passwd_popup_free(ug_app_state->passpopup);
359         ug_app_state->passpopup = NULL;
360
361         viewer_manager_header_mode_set(HEADER_MODE_ON);
362 }
363
364 static void _wps_btn_cb(void* data, Evas_Object* obj, void* event_info)
365 {
366         __COMMON_FUNC_ENTER__;
367         if (!ug_app_state->passpopup) {
368                 return;
369         }
370
371         wifi_ap_h ap = passwd_popup_get_ap(ug_app_state->passpopup);
372         int ret = wlan_manager_wps_connect(ap);
373         if (ret == WLAN_MANAGER_ERR_NONE) {
374                 create_pbc_popup(ug_app_state->passpopup, __wps_pbc_popup_cancel_connecting, NULL);
375         } else {
376                 ERROR_LOG(UG_NAME_NORMAL, "wlan_manager_wps_connect failed");
377                 passwd_popup_free(ug_app_state->passpopup);
378                 ug_app_state->passpopup = NULL;
379         }
380
381         __COMMON_FUNC_EXIT__;
382 }
383
384 static void __viewer_list_wifi_connect(wifi_device_info_t *device_info)
385 {
386         int rv;
387         bool favorite = false;
388         Evas_Object* navi_frame = NULL;
389         pswd_popup_create_req_data_t popup_info;
390         wifi_security_type_e sec_type = WIFI_SECURITY_TYPE_NONE;
391
392         if (device_info == NULL)
393                 return;
394
395         wifi_ap_is_favorite(device_info->ap, &favorite);
396
397         if (favorite == true) {
398                 rv = wlan_manager_connect(device_info->ap);
399                 return;
400         }
401
402         wifi_ap_get_security_type(device_info->ap, &sec_type);
403
404         switch (sec_type) {
405         case WIFI_SECURITY_TYPE_NONE:
406                 rv = wlan_manager_connect(device_info->ap);
407                 break;
408
409         case WIFI_SECURITY_TYPE_WEP:
410         case WIFI_SECURITY_TYPE_WPA_PSK:
411         case WIFI_SECURITY_TYPE_WPA2_PSK:
412                 memset(&popup_info, 0, sizeof(pswd_popup_create_req_data_t));
413
414                 popup_info.title = device_info->ssid;
415                 popup_info.ok_cb = __passwd_popup_ok_cb;
416                 popup_info.cancel_cb = __passwd_popup_cancel_cb;
417                 popup_info.show_wps_btn = device_info->wps_mode;
418                 popup_info.wps_btn_cb = _wps_btn_cb;
419                 popup_info.ap = device_info->ap;
420                 popup_info.cb_data = NULL;
421
422                 /* TODO: parameter with device_info */
423                 /* TODO: finally parameter with wifi_ap_h, WPA, EAP */
424                 ug_app_state->passpopup = create_passwd_popup(
425                                 ug_app_state->layout_main, PACKAGE, &popup_info);
426
427                 if (ug_app_state->passpopup == NULL)
428                         INFO_LOG(UG_NAME_ERR, "Fail to create password popup");
429
430                 break;
431
432         case WIFI_SECURITY_TYPE_EAP:
433                 navi_frame = viewer_manager_get_naviframe();
434                 ug_app_state->eap_view = create_eap_view(
435                                 ug_app_state->layout_main, navi_frame, PACKAGE, device_info);
436                 break;
437
438         default:
439                 ERROR_LOG(UG_NAME_NORMAL, "Unknown security type [%d]", sec_type);
440                 break;
441         }
442 }
443
444 static void __viewer_list_item_clicked_cb(void *data, Evas_Object *obj,
445                 void *event_info)
446 {
447         __COMMON_FUNC_ENTER__;
448
449         assertm_if(NULL == event_info, "event_info is NULL!!");
450         assertm_if(NULL == obj, "obj is NULL!!");
451
452         Elm_Object_Item *it = (Elm_Object_Item *)event_info;
453         ug_genlist_data_t *gdata = NULL;
454         wifi_device_info_t *device_info = NULL;
455
456         gdata = (ug_genlist_data_t *)elm_object_item_data_get(it);
457         retm_if(NULL == gdata);
458
459         device_info = gdata->device_info;
460         retm_if(NULL == device_info || NULL == device_info->ssid);
461
462         int item_state = gdata->radio_mode;
463         int current_state = 0;
464
465         INFO_LOG(UG_NAME_NORMAL, "ssid --- %s", device_info->ssid);
466         INFO_LOG(UG_NAME_NORMAL, "ap --- 0x%x", device_info->ap);
467         INFO_LOG(UG_NAME_NORMAL, "current item_state state is --- %d\n", item_state);
468
469         switch (item_state) {
470         case VIEWER_ITEM_RADIO_MODE_OFF:
471                 current_state = viewer_manager_header_mode_get();
472
473                 INFO_LOG(UG_NAME_NORMAL, "Clicked AP information\n");
474                 INFO_LOG(UG_NAME_NORMAL, "header mode [%d]", current_state);
475
476                 switch (current_state) {
477                 case HEADER_MODE_ON:
478                 case HEADER_MODE_CONNECTED:
479                 case HEADER_MODE_CONNECTING:
480                         __viewer_list_wifi_connect(device_info);
481                         break;
482
483                 case HEADER_MODE_OFF:
484                 case HEADER_MODE_SEARCHING:
485                 case HEADER_MODE_ACTIVATING:
486                 case HEADER_MODE_DEACTIVATING:
487                 default:
488                         INFO_LOG(UG_NAME_NORMAL, "Ignore click");
489                         break;
490                 }
491                 break;
492
493         case VIEWER_ITEM_RADIO_MODE_CONNECTING:
494         case VIEWER_ITEM_RADIO_MODE_CONNECTED:
495         default:
496                 INFO_LOG(UG_NAME_NORMAL, "Ignore click");
497                 break;
498         }
499
500         elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
501
502         __COMMON_FUNC_EXIT__;
503 }
504
505 static char *viewer_list_get_device_status_txt(wifi_device_info_t *wifi_device, VIEWER_ITEM_RADIO_MODES mode)
506 {
507         char *status_txt = NULL;
508         /* The strings are currently hard coded. It will be replaced with string ids later */
509         if (VIEWER_ITEM_RADIO_MODE_CONNECTING == mode) {
510                 status_txt = g_strdup(sc(PACKAGE, I18N_TYPE_Connecting));
511         } else if (VIEWER_ITEM_RADIO_MODE_CONNECTED == mode) {
512                 status_txt = g_strdup(sc(PACKAGE, I18N_TYPE_Connected));
513         } else if (VIEWER_ITEM_RADIO_MODE_OFF == mode) {
514                 status_txt = common_utils_get_ap_security_type_info_txt(PACKAGE, wifi_device);
515         } else {
516                 status_txt = g_strdup(WIFI_UNKNOWN_DEVICE_STATUS_STR);
517                 INFO_LOG(UG_NAME_NORMAL, "Invalid mode: %d", mode);
518         }
519         return status_txt;
520 }
521
522 Evas_Object* viewer_list_create(Evas_Object *win)
523 {
524         __COMMON_FUNC_ENTER__;
525
526         assertm_if(NULL == win, "NULL!!");
527         assertm_if(NULL != viewer_list, "Err!!");
528
529         viewer_list = elm_genlist_add(win);
530         assertm_if(NULL == viewer_list, "NULL!!");
531
532         elm_object_style_set(viewer_list, "dialogue");
533         elm_genlist_mode_set(viewer_list, ELM_LIST_LIMIT);
534
535         evas_object_size_hint_weight_set(viewer_list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
536         evas_object_size_hint_align_set(viewer_list, EVAS_HINT_FILL, EVAS_HINT_FILL);
537
538         itc.item_style = "dialogue/2text.2icon.3.tb";
539         itc.func.text_get = _gl_listview_text_get;
540         itc.func.content_get = _gl_listview_content_get;
541         itc.func.state_get = NULL;
542         itc.func.del = _gl_listview_del;
543
544         first_item = last_item = NULL;
545
546         evas_object_smart_callback_add(viewer_list, "realized", _gl_realized, NULL);
547         evas_object_smart_callback_add(viewer_list, "highlighted", _gl_highlighted, NULL);
548         evas_object_smart_callback_add(viewer_list, "unhighlighted", _gl_unhighlighted, NULL);
549
550         __COMMON_FUNC_EXIT__;
551         return viewer_list;
552 }
553
554 int viewer_list_destroy(void)
555 {
556         __COMMON_FUNC_ENTER__;
557
558         assertm_if(NULL == viewer_list, "NULL!!");
559         viewer_list_item_clear();
560         evas_object_del(viewer_list);
561         viewer_list = NULL;
562
563         __COMMON_FUNC_EXIT__;
564         return TRUE;
565 }
566
567 void viewer_list_title_item_del(void)
568 {
569         if (grouptitle) {
570                 elm_object_item_del(grouptitle);
571                 grouptitle = NULL;
572         }
573 }
574
575 void viewer_list_title_item_update(void)
576 {
577         elm_genlist_item_update(grouptitle);
578 }
579
580 void viewer_list_title_item_set(void)
581 {
582         if (grouptitle != NULL || viewer_list_item_size_get() != 0)
583                 return;
584
585         // To use multiline textblock/entry/editfield in genlist, set height_for_width mode
586         // then the item's height is calculated while the item's width fits to genlist width.
587         elm_genlist_mode_set(viewer_list, ELM_LIST_COMPRESS);
588
589         grouptitle_itc.item_style = "dialogue/title";
590         grouptitle_itc.func.text_get = _gl_text_title_get;
591         grouptitle_itc.func.content_get = _gl_content_title_get;
592         grouptitle_itc.func.state_get = NULL;
593         grouptitle_itc.func.del = NULL;
594
595         assertm_if(NULL != grouptitle, "Err!!");
596
597         grouptitle = elm_genlist_item_append(viewer_list,
598                         &grouptitle_itc,
599                         NULL,
600                         NULL,
601                         ELM_GENLIST_ITEM_NONE,
602                         NULL,
603                         NULL);
604
605         assertm_if(NULL == grouptitle, "NULL!!");
606
607         elm_genlist_item_select_mode_set(grouptitle, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
608 }
609
610 int viewer_list_item_radio_mode_set(Elm_Object_Item* item,
611                 VIEWER_ITEM_RADIO_MODES mode)
612 {
613         __COMMON_FUNC_ENTER__;
614
615         if (NULL == item) {
616                 INFO_LOG(COMMON_NAME_ERR, "item is NULL");
617                 return FALSE;
618         }
619
620         ug_genlist_data_t* gdata = (ug_genlist_data_t *) elm_object_item_data_get(item);
621         if (NULL == gdata || NULL == gdata->device_info) {
622                 INFO_LOG(COMMON_NAME_ERR, "gdata or device_info is NULL");
623                 return FALSE;
624         }
625
626         if (gdata->radio_mode == mode) {
627                 INFO_LOG(UG_NAME_NORMAL, "[%s] is already in requested state", gdata->device_info->ssid);
628                 return FALSE;
629         }
630
631         INFO_LOG(UG_NAME_NORMAL, "[%s] AP Item State Transition from [%d] --> [%d]", gdata->device_info->ssid, gdata->radio_mode, mode);
632         gdata->radio_mode = mode;
633         if (gdata->device_info->ap_status_txt) {
634                 g_free(gdata->device_info->ap_status_txt);
635                 gdata->device_info->ap_status_txt = viewer_list_get_device_status_txt(gdata->device_info, mode);
636         }
637
638         elm_genlist_item_update(item);
639
640         __COMMON_FUNC_EXIT__;
641         return TRUE;
642 }
643
644 Elm_Object_Item* viewer_list_item_insert_after(wifi_ap_h ap, Elm_Object_Item *after)
645 {
646         Elm_Object_Item* ret = NULL;
647         wifi_security_type_e sec_type;
648
649         retvm_if(NULL == viewer_list, NULL);
650
651         wifi_device_info_t *wifi_device = NULL;
652
653         if (ap == NULL) {
654                 wifi_device = wlan_manager_profile_device_info_blank_create();
655                 retvm_if(NULL == wifi_device, NULL);
656         } else {
657                 wifi_device = g_new0(wifi_device_info_t, 1);
658                 retvm_if(NULL == wifi_device, NULL);
659
660                 if (WIFI_ERROR_NONE != wifi_ap_clone(&(wifi_device->ap), ap)) {
661                         goto FREE_DEVICE_INFO;
662                 } else if (WIFI_ERROR_NONE != wifi_ap_get_essid(ap, &(wifi_device->ssid))) {
663                         goto FREE_DEVICE_INFO;
664                 } else if (WIFI_ERROR_NONE != wifi_ap_get_rssi(ap, &(wifi_device->rssi))) {
665                         goto FREE_DEVICE_INFO;
666                 } else if (WIFI_ERROR_NONE != wifi_ap_get_security_type(ap, &sec_type)) {
667                         goto FREE_DEVICE_INFO;
668                 } else if (WIFI_ERROR_NONE != wifi_ap_is_wps_supported(ap, &(wifi_device->wps_mode))) {
669                         goto FREE_DEVICE_INFO;
670                 }
671                 wifi_device->security_mode = common_utils_get_sec_mode(sec_type);
672                 wifi_device->ap_status_txt = viewer_list_get_device_status_txt(wifi_device, VIEWER_ITEM_RADIO_MODE_OFF);
673                 common_utils_get_device_icon(WIFI_APP_IMAGE_DIR,
674                                 wifi_device,
675                                 &wifi_device->ap_image_path);
676
677         }
678         ug_genlist_data_t* gdata = g_new0(ug_genlist_data_t, 1);
679         retvm_if(NULL == gdata, NULL);
680
681         gdata->device_info = wifi_device;
682         gdata->radio_mode = VIEWER_ITEM_RADIO_MODE_OFF;
683
684         if (!after) {   /* If the after item is NULL then insert it as first item */
685                 after = grouptitle;
686         }
687
688         ret = elm_genlist_item_insert_after(
689                         viewer_list, /*obj*/
690                         &itc,/*itc*/
691                         gdata,/*data*/
692                         NULL,/*parent*/
693                         after, /*after than*/
694                         ELM_GENLIST_ITEM_NONE, /*flags*/
695                         __viewer_list_item_clicked_cb,/*func*/
696                         NULL);/*func_data*/
697
698         if (!ret) {
699                 assertm_if(NULL == ret, "NULL!!");
700                 g_free(gdata);
701         } else {
702                 DEBUG_LOG(UG_NAME_NORMAL,
703                                 "* item add complete item [0x%x] ssid:[%s] security[%d] size:[%d]",
704                                 ret,
705                                 wifi_device->ssid,
706                                 wifi_device->security_mode,
707                                 viewer_list_item_size_get());
708
709                 if (after == grouptitle) {
710                         first_item = ret;
711                         if (!last_item)
712                                 last_item = ret;
713                 } else {
714                         last_item = ret;
715                         if (!first_item)
716                                 first_item = ret;
717                 }
718
719                 elm_genlist_item_update(ret);
720         }
721
722 FREE_DEVICE_INFO:
723         if (!ret && wifi_device) {
724                 wifi_ap_destroy(wifi_device->ap);
725                 g_free(wifi_device->ap_image_path);
726                 g_free(wifi_device->ap_status_txt);
727                 g_free(wifi_device->ssid);
728                 g_free(wifi_device);
729         }
730
731         return ret;
732 }
733
734 void viewer_list_item_del(Elm_Object_Item *it)
735 {
736         if (it == NULL)
737                 return;
738
739         if (it == first_item) {
740                 first_item = elm_genlist_item_next_get(first_item);
741         } else if (it == last_item) {
742                 last_item = elm_genlist_item_prev_get(last_item);
743         }
744         elm_object_item_del(it);
745 }
746
747 int viewer_list_item_size_get()
748 {
749         __COMMON_FUNC_ENTER__;
750         int ret = 0;
751         Elm_Object_Item *it = first_item;
752
753         while(it) {
754                 ret++;
755                 if (it == last_item)
756                         break;
757                 it = elm_genlist_item_next_get(it);
758         }
759
760         __COMMON_FUNC_EXIT__;
761         return ret;
762 }
763
764 void viewer_list_item_clear(void)
765 {
766         __COMMON_FUNC_ENTER__;
767
768         Elm_Object_Item *it = first_item;
769         Elm_Object_Item *nxt = NULL;
770
771         while(it) {
772                 nxt = elm_genlist_item_next_get(it);
773                 elm_object_item_del(it);
774                 if (it == last_item)
775                         break;
776                 it = nxt;
777         }
778
779         first_item = last_item = NULL;
780
781         __COMMON_FUNC_EXIT__;
782 }
783
784 void viewer_list_item_enable_all(void)
785 {
786         __COMMON_FUNC_ENTER__;
787
788         Elm_Object_Item *it = first_item;
789
790         while(it) {
791                 elm_object_item_disabled_set(it, EINA_FALSE);
792
793                 if (it == last_item)
794                         break;
795
796                 it = elm_genlist_item_next_get(it);
797         }
798
799         __COMMON_FUNC_EXIT__;
800 }
801
802 void viewer_list_item_disable_all(void)
803 {
804         __COMMON_FUNC_ENTER__;
805
806         Elm_Object_Item *it = first_item;
807
808         while(it) {
809                 elm_object_item_disabled_set(it, EINA_TRUE);
810
811                 if (it == last_item)
812                         break;
813
814                 it = elm_genlist_item_next_get(it);
815         }
816
817         __COMMON_FUNC_EXIT__;
818 }
819
820 Elm_Object_Item* item_get_for_ap(wifi_ap_h ap)
821 {
822         __COMMON_FUNC_ENTER__;
823         if (!ap) {
824                 __COMMON_FUNC_EXIT__;
825                 return NULL;
826         }
827         
828         char *essid = NULL;
829         wifi_security_type_e type = WIFI_SECURITY_TYPE_NONE;
830
831         if (WIFI_ERROR_NONE != wifi_ap_get_essid(ap, &essid)) {
832                 __COMMON_FUNC_EXIT__;
833                 return NULL;
834         } else if (WIFI_ERROR_NONE != wifi_ap_get_security_type(ap, &type)) {
835                 __COMMON_FUNC_EXIT__;
836                 return NULL;
837         }
838
839         Elm_Object_Item *it = first_item;
840         wlan_security_mode_type_t sec_mode = common_utils_get_sec_mode(type);
841         while(it) {
842                 ug_genlist_data_t* gdata = elm_object_item_data_get(it);
843                 wifi_device_info_t *device_info = NULL;
844                 if (gdata && (device_info = gdata->device_info)) {
845                         if (!g_strcmp0(device_info->ssid, essid) && device_info->security_mode == sec_mode)
846                                 break;
847                 }
848                 if (it == last_item) {
849                         it = NULL;
850                         break;
851                 }
852                 it = elm_genlist_item_next_get(it);
853         }
854
855         g_free(essid);
856         __COMMON_FUNC_EXIT__;
857         return it;
858 }