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