DLog macro is changed
[apps/native/ug-wifi-direct.git] / ug-wifidirect / src / wfd_ug_main_view.c
1 /*
2 *  WiFi-Direct UG
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
21 #include <libintl.h>
22
23 #include <assert.h>
24 #include <glib.h>
25
26 #include <Elementary.h>
27 #include <vconf.h>
28 #include <ui-gadget-module.h>
29 #include <wifi-direct.h>
30
31 #include "wfd_ug.h"
32 #include "wfd_ug_view.h"
33 #include "wfd_client.h"
34
35 /**
36  *      This function let the ug call it when click 'back' button
37  *      @return   void
38  *      @param[in] data the pointer to the main data structure
39  *      @param[in] obj the pointer to the evas object
40  *      @param[in] event_info the pointer to the event information
41  */
42 void _back_btn_cb(void *data, Evas_Object * obj, void *event_info)
43 {
44         __WDUG_LOG_FUNC_ENTER__;
45         struct ug_data *ugd = (struct ug_data *) data;
46
47         if (!ugd) {
48                 WDUG_LOGE("The param is NULL\n");
49                 return;
50         }
51
52         wfd_ug_view_free_peers(ugd);
53
54         int ret = -1;
55         service_h service = NULL;
56         ret = service_create(&service);
57         if (ret) {
58                 WDUG_LOGE("Failed to create service");
59                 return;
60         }
61
62         wfd_refresh_wifi_direct_state(ugd);
63         if (ugd->wfd_status > WIFI_DIRECT_STATE_CONNECTING) {
64                 service_add_extra_data(service, "Connection", "TRUE");
65         } else {
66                 service_add_extra_data(service, "Connection", "FALSE");
67         }
68
69         ug_send_result(ugd->ug, service);
70         service_destroy(service);
71         ug_destroy_me(ugd->ug);
72
73         __WDUG_LOG_FUNC_EXIT__;
74         return;
75 }
76
77 /**
78  *      This function let the ug call it when click 'scan' button
79  *      @return   void
80  *      @param[in] data the pointer to the main data structure
81  *      @param[in] obj the pointer to the evas object
82  *      @param[in] event_info the pointer to the event information
83  */
84 void _scan_btn_cb(void *data, Evas_Object *obj, void *event_info)
85 {
86         __WDUG_LOG_FUNC_ENTER__;
87
88         struct ug_data *ugd = (struct ug_data *) data;
89         int ret = -1;
90         char *btn_text = NULL;
91
92         if (NULL == ugd) {
93                 WDUG_LOGE("Incorrect parameter(NULL)\n");
94                 return;
95         }
96
97         btn_text = (char *)elm_object_text_get(obj);
98         if (NULL == btn_text) {
99                 WDUG_LOGE("Incorrect button text(NULL)\n");
100                 return;
101         }
102
103         if (0 == strcmp(btn_text, _("IDS_WFD_BUTTON_SCAN"))) {
104                 wfd_refresh_wifi_direct_state(ugd);
105                 WDUG_LOGD("Start discovery again, status: %d\n", ugd->wfd_status);
106
107                 /* if connected, show the popup*/
108                 if (ugd->wfd_status >= WIFI_DIRECT_STATE_CONNECTED) {
109                         wfd_ug_act_popup(ugd, IDS_WFD_POP_SCAN_AGAIN, POP_TYPE_SCAN_AGAIN);
110                 } else if (WIFI_DIRECT_STATE_DEACTIVATED == ugd->wfd_status) {
111                         wfd_client_switch_on(ugd);
112                         __WDUG_LOG_FUNC_EXIT__;
113                         return;
114                 } else {
115                         ret = wifi_direct_start_discovery(FALSE, MAX_SCAN_TIME_OUT);
116                         if (ret != WIFI_DIRECT_ERROR_NONE) {
117                                 WDUG_LOGE("Failed to start discovery. [%d]\n", ret);
118                                 ugd->is_re_discover = TRUE;
119                                 wifi_direct_cancel_discovery();
120                         } else {
121                                 WDUG_LOGD("Discovery is started\n");
122                                 ugd->is_re_discover = FALSE;
123                         }
124                 }
125         } else if (0 == strcmp(btn_text, _("IDS_WFD_BUTTON_STOPSCAN"))) {
126                 WDUG_LOGD("Stop discoverying.\n");
127                 ugd->head_text_mode = HEAD_TEXT_TYPE_DIRECT;
128                 wfd_ug_view_refresh_glitem(ugd->head);
129
130                 /* stop scaning */
131                 ugd->is_re_discover = FALSE;
132                 wifi_direct_cancel_discovery();
133         }
134
135         __WDUG_LOG_FUNC_EXIT__;
136         return;
137 }
138
139 /**
140  *      This function let the ug call it when click header
141  *      @return   void
142  *      @param[in] data the pointer to the main data structure
143  *      @param[in] obj the pointer to the evas object
144  *      @param[in] event_info the pointer to the event information
145  */
146 static void _gl_header_sel(void *data, Evas_Object *obj, void *event_info)
147 {
148         __WDUG_LOG_FUNC_ENTER__;
149         if (NULL == data) {
150                 WDUG_LOGE("Incorrect parameter(NULL)\n");
151                 __WDUG_LOG_FUNC_EXIT__;
152                 return;
153         }
154
155         struct ug_data *ugd = (struct ug_data *) data;
156         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
157
158         if (item != NULL) {
159                 elm_genlist_item_selected_set(item, EINA_FALSE);
160         }
161
162         /* turn on/off wfd */
163         if (!ugd->wfd_onoff) {
164                 WDUG_LOGD("wifi-direct switch on\n");
165                 wfd_client_switch_on(ugd);
166         } else {
167                 WDUG_LOGD("wifi-direct switch off\n");
168                 wfd_client_switch_off(ugd);
169         }
170
171         __WDUG_LOG_FUNC_EXIT__;
172 }
173
174 /**
175  *      This function let the ug call it when click avaliable peer to connect
176  *      @return   void
177  *      @param[in] data the pointer to the main data structure
178  *      @param[in] obj the pointer to the evas object
179  *      @param[in] event_info the pointer to the event information
180  */
181 static void _gl_peer_sel(void *data, Evas_Object *obj, void *event_info)
182 {
183         __WDUG_LOG_FUNC_ENTER__;
184         assertm_if(NULL == obj, "NULL!!");
185         assertm_if(NULL == data, "NULL!!");
186         device_type_s *peer = (device_type_s *) data;
187         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
188         int res;
189
190         if (data == NULL) {
191                 WDUG_LOGE("Incorrect parameter(NULL)\n");
192                 return;
193         }
194
195         if (item != NULL) {
196                 elm_genlist_item_selected_set(item, EINA_FALSE);
197         }
198
199         if (peer->conn_status == PEER_CONN_STATUS_DISCONNECTED || peer->is_group_owner == TRUE) {
200                 WDUG_LOGD("Connect with peer [%s]\n", peer->mac_addr);
201                 res = wfd_client_connect((const char *) peer->mac_addr);
202                 if (res != 0) {
203                         WDUG_LOGE("Failed to send connection request. [%d]\n", res);
204                         return;
205                 }
206         } else {
207                 res = wfd_client_disconnect((const char *)peer->mac_addr);
208                 if (res != 0) {
209                         WDUG_LOGE("Failed to send disconnection request. [%d]\n", res);
210                         return;
211                 }
212         }
213
214         __WDUG_LOG_FUNC_EXIT__;
215         return;
216 }
217
218 /**
219  *      This function let the ug call it when click busy peer
220  *      @return   void
221  *      @param[in] data the pointer to the main data structure
222  *      @param[in] obj the pointer to the evas object
223  *      @param[in] event_info the pointer to the event information
224  */
225 static void _gl_busy_peer_sel(void *data, Evas_Object *obj, void *event_info)
226 {
227         __WDUG_LOG_FUNC_ENTER__;
228         struct ug_data *ugd = (struct ug_data *) data;
229
230         elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
231         WDUG_LOGD("Busy device is clicked");
232         wfd_ug_warn_popup(ugd, IDS_WFD_POP_WARN_BUSY_DEVICE, POP_TYPE_BUSY_DEVICE_POPUP);
233
234         __WDUG_LOG_FUNC_EXIT__;
235 }
236
237 /**
238  *      This function let the ug call it when click about item
239  *      @return   void
240  *      @param[in] data the pointer to the main data structure
241  *      @param[in] obj the pointer to the evas object
242  *      @param[in] event_info the pointer to the event information
243  */
244 static void _gl_about_wifi_sel(void *data, Evas_Object *obj, void *event_info)
245 {
246         __WDUG_LOG_FUNC_ENTER__;
247         struct ug_data *ugd = (struct ug_data *) data;
248
249         WDUG_LOGD("About wifi clicked");
250         _wifid_create_about_view(ugd);
251         elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
252
253         __WDUG_LOG_FUNC_EXIT__;
254 }
255
256 /**
257  *      This function let the ug call it when click 'multi connect' button
258  *      @return   void
259  *      @param[in] data the pointer to the main data structure
260  *      @param[in] obj the pointer to the evas object
261  *      @param[in] event_info the pointer to the event information
262  */
263 void _wifid_create_multibutton_cb(void *data, Evas_Object * obj, void *event_info)
264 {
265         __WDUG_LOG_FUNC_ENTER__;
266         struct ug_data *ugd = (struct ug_data *) data;
267         const char *text_lbl = NULL;
268
269         text_lbl = elm_object_text_get(ugd->multi_btn);
270         WDUG_LOGD("text_lbl = %s", text_lbl);
271
272         if (ugd->multi_connect_mode == WFD_MULTI_CONNECT_MODE_IN_PROGRESS) {
273                 ugd->multi_connect_mode = WFD_MULTI_CONNECT_MODE_NONE;
274                 if (0 == strcmp(_("IDS_WFD_BUTTON_CANCEL"), text_lbl)) {
275                         wfd_ug_act_popup(ugd, _("IDS_WFD_POP_CANCEL_CONNECT"), POP_TYPE_DISCONNECT_ALL);
276                 } else {
277                         WDUG_LOGD("Invalid Case\n");
278                 }
279         } else {
280                 if (0 == strcmp(_("IDS_WFD_BUTTON_MULTI"), text_lbl)) {
281                         wfd_create_multiconnect_view(ugd);
282                 } else if (0 == strcmp(_("IDS_WFD_BUTTON_CANCEL"), text_lbl)) {
283                         wfd_ug_act_popup(ugd, _("IDS_WFD_POP_CANCEL_CONNECT"), POP_TYPE_DISCONNECT_ALL);
284                 } else if (0 == strcmp(_("IDS_WFD_BUTTON_DISCONNECT_ALL"), text_lbl)) {
285                         wfd_ug_act_popup(ugd, _("IDS_WFD_POP_DISCONNECT"), POP_TYPE_DISCONNECT_ALL);
286                 } else if (0 == strcmp(_("IDS_WFD_BUTTON_DISCONNECT"), text_lbl)) {
287                         wfd_ug_act_popup(ugd, _("IDS_WFD_POP_DISCONNECT"), POP_TYPE_DISCONNECT);
288                 } else {
289                         WDUG_LOGD("Invalid Case\n");
290                 }
291         }
292
293         __WDUG_LOG_FUNC_EXIT__;
294 }
295
296 /**
297  *      This function let the ug change the text of multi button
298  *      @return   If success, return 0, else return -1
299  *      @param[in] data the pointer to the main data structure
300  */
301 int _change_multi_button_title(void *data)
302 {
303         __WDUG_LOG_FUNC_ENTER__;
304         struct ug_data *ugd = (struct ug_data *) data;
305
306         if (ugd->multi_button_item == NULL) {
307                 return -1;
308         }
309
310         wfd_refresh_wifi_direct_state(ugd);
311         if (ugd->wfd_status == WIFI_DIRECT_STATE_CONNECTING) {
312                 elm_object_text_set(ugd->multi_btn, _("IDS_WFD_BUTTON_CANCEL"));
313         } else if (ugd->wfd_status > WIFI_DIRECT_STATE_CONNECTING) {
314                 if (ugd->gl_connected_peer_cnt > 1) {
315                         elm_object_text_set(ugd->multi_btn, _("IDS_WFD_BUTTON_DISCONNECT_ALL"));
316                 } else {
317                         elm_object_text_set(ugd->multi_btn, _("IDS_WFD_BUTTON_DISCONNECT"));
318                 }
319         } else {
320                 elm_object_text_set(ugd->multi_btn, _("IDS_WFD_BUTTON_MULTI"));
321         }
322
323         evas_object_show(ugd->multi_btn);
324         __WDUG_LOG_FUNC_EXIT__;
325
326         return 0;
327 }
328
329 /**
330  *      This function let the ug update the genlist item
331  *      @return   void
332  *      @param[in] obj the pointer to genlist item
333  */
334 void wfd_ug_view_refresh_glitem(void *obj)
335 {
336         __WDUG_LOG_FUNC_ENTER__;
337         elm_genlist_item_update(obj);
338         __WDUG_LOG_FUNC_EXIT__;
339 }
340
341 /**
342  *      This function let the ug refresh the attributes of button
343  *      @return   void
344  *      @param[in] obj the pointer to the button
345  *      @param[in] text the pointer to the text of button
346  *      @param[in] enable whether the button is disabled
347  */
348 void wfd_ug_view_refresh_button(void *obj, const char *text, int enable)
349 {
350         __WDUG_LOG_FUNC_ENTER__;
351
352         if (NULL == obj || NULL == text) {
353                 WDUG_LOGE("Incorrect parameter(NULL)\n");
354                 return;
355         }
356
357         WDUG_LOGD("Set the attributes of button: text[%s], enabled[%d]\n", text, enable);
358         elm_object_text_set(obj, text);
359         elm_object_disabled_set(obj, !enable);
360
361         __WDUG_LOG_FUNC_EXIT__;
362 }
363
364 /**
365  *      This function let the ug know whether current device is connected by me
366  *      @return   If connected, return TRUE, else return FALSE
367  *      @param[in] ugd the pointer to the main data structure
368  *      @param[in] dev the pointer to the device
369  */
370 static bool __wfd_is_device_connected_with_me(struct ug_data *ugd, device_type_s *dev)
371 {
372         __WDUG_LOG_FUNC_ENTER__;
373         int i = 0;
374
375         for (i = 0; i < ugd->raw_connected_peer_cnt; i++) {
376                 if (strncmp(ugd->raw_connected_peers[i].mac_addr,
377                         dev->mac_addr, strlen(ugd->raw_connected_peers[i].mac_addr)) == 0) {
378                         return TRUE;
379                 }
380         }
381
382         __WDUG_LOG_FUNC_EXIT__;
383         return FALSE;
384 }
385
386 /**
387  *      This function let the ug know whether current device is connected by other peer
388  *      @return   If connected, return TRUE, else return FALSE
389  *      @param[in] ugd the pointer to the main data structure
390  *      @param[in] dev the pointer to the device
391  */
392 static bool __wfd_is_device_busy(struct ug_data *ugd, device_type_s *dev)
393 {
394         __WDUG_LOG_FUNC_ENTER__;
395
396         if (ugd->I_am_group_owner == TRUE) {
397                 if (dev->is_connected || dev->is_group_owner) {
398                         return TRUE;
399                 } else {
400                         return FALSE;
401                 }
402         } else {
403                 if (dev->is_connected == TRUE && dev->is_group_owner == TRUE) {
404                         return FALSE;
405                 }
406
407                 if (dev->is_connected == TRUE && dev->is_group_owner == FALSE) {
408                         return TRUE;
409                 }
410
411                 if (dev->is_connected == FALSE) {
412                         return FALSE;
413                 }
414         }
415
416         __WDUG_LOG_FUNC_EXIT__;
417         return FALSE;
418 }
419
420 /**
421  *      This function let the ug calculate how many devices are avaliable
422  *      @return   TRUE
423  *      @param[in] ugd the pointer to the main data structure
424  *      @param[in] dev the pointer to the number of avaliable devices
425  */
426 static bool __wfd_is_any_device_available(struct ug_data *ugd, int* no_of_available_dev)
427 {
428         __WDUG_LOG_FUNC_ENTER__;
429         int i = 0;
430
431         for (i = 0; i < ugd->raw_discovered_peer_cnt; i++) {
432                 /* Not include the device which is connected with me */
433                 if (__wfd_is_device_connected_with_me(ugd, &ugd->raw_discovered_peers[i])) {
434                         continue;
435                 }
436                 if (!__wfd_is_device_busy(ugd, &ugd->raw_discovered_peers[i]) &&
437                         ugd->raw_discovered_peers[i].conn_status != PEER_CONN_STATUS_FAILED_TO_CONNECT) {
438                         (*no_of_available_dev)++;
439                 }
440         }
441
442         __WDUG_LOG_FUNC_EXIT__;
443         return TRUE;
444 }
445
446 /**
447  *      This function let the ug calculate how many devices are busy
448  *      @return   TRUE
449  *      @param[in] ugd the pointer to the main data structure
450  *      @param[in] dev the pointer to the number of busy devices
451  */
452 static bool __wfd_is_any_device_busy(struct ug_data *ugd, int* no_of_busy_dev)
453 {
454         __WDUG_LOG_FUNC_ENTER__;
455         int i = 0;
456
457         for (i = 0; i < ugd->raw_discovered_peer_cnt; i++) {
458                 /* Not include the device which is connected with me */
459                 if (__wfd_is_device_connected_with_me(ugd, &ugd->raw_discovered_peers[i])) {
460                         continue;
461                 }
462                 if (__wfd_is_device_busy(ugd, &ugd->raw_discovered_peers[i])) {
463                         (*no_of_busy_dev)++;
464                 }
465         }
466
467         __WDUG_LOG_FUNC_EXIT__;
468         return TRUE;
469 }
470
471 /**
472  *      This function let the ug calculate how many devices are connected failed
473  *      @return   TRUE
474  *      @param[in] ugd the pointer to the main data structure
475  *      @param[in] dev the pointer to the number of connected failed devices
476  */
477 static bool __wfd_is_any_device_connect_failed(struct ug_data *ugd, int* no_of_connect_failed_dev)
478 {
479         __WDUG_LOG_FUNC_ENTER__;
480         int i = 0;
481
482         for (i = 0; i < ugd->raw_discovered_peer_cnt; i++) {
483                 /* Not include the device which is connected with me */
484                 if (__wfd_is_device_connected_with_me(ugd, &ugd->raw_discovered_peers[i])) {
485                         continue;
486                 }
487                 if (!__wfd_is_device_busy(ugd, &ugd->raw_discovered_peers[i]) &&
488                         ugd->raw_discovered_peers[i].conn_status == PEER_CONN_STATUS_FAILED_TO_CONNECT) {
489                         (*no_of_connect_failed_dev)++;
490                 }
491
492         }
493
494         __WDUG_LOG_FUNC_EXIT__;
495         return TRUE;
496 }
497
498 /**
499  *      This function let the ug get the device status
500  *      @return  If success, return 0-3(available: 0, connected: 1, busy: 2, connected failed: 3), else return -1
501  *      @param[in] ugd the pointer to the main data structure
502  *      @param[in] device the pointer to the number of connected failed devices
503  */
504 int wfd_get_device_status(void *data, device_type_s *device)
505 {
506         __WDUG_LOG_FUNC_ENTER__;
507         int ret = -1;
508         int status = -1;
509         struct ug_data *ugd = (struct ug_data *) data;
510
511         if (ugd == NULL) {
512                 WDUG_LOGE("Incorrect parameter(NULL)");
513                 return -1;
514         }
515
516         /* check whether it is connected device  */
517         ret = __wfd_is_device_connected_with_me(ugd, device);
518         if (ret) {
519                 WDUG_LOGD("This is connected device");
520                 status = 1;
521                 goto err_exit;
522         }
523
524         /* check whether it is busy device  */
525         ret = __wfd_is_device_busy(ugd, device);
526         if (ret) {
527                 WDUG_LOGD("This is busy device");
528                 status = 2;
529                 goto err_exit;
530         }
531
532         /* check whether it is available device  */
533         if (device->conn_status != PEER_CONN_STATUS_FAILED_TO_CONNECT) {
534                 WDUG_LOGD("This is available device");
535                 status = 0;
536         } else {
537                 WDUG_LOGD("This is connected failed device");
538                 status = 3;
539         }
540
541 err_exit:
542         __WDUG_LOG_FUNC_EXIT__;
543         return status;
544 }
545
546 /**
547  *      This function let the ug delete the separator
548  *      @return   void
549  *      @param[in] data the pointer to the main data structure
550  *      @param[in] obj the pointer to the evas object
551  */
552 static void __wfd_separator_del(void *data, Evas_Object *obj)
553 {
554         __WDUG_LOG_FUNC_ENTER__;
555         elm_genlist_item_class_free(data);
556         return;
557 }
558
559 /**
560  *      This function let the ug add a dialogue separator
561  *      @return   the separator item
562  *      @param[in] genlist the pointer to the genlist
563  *      @param[in] separator_style the style of separator
564  */
565 Elm_Object_Item *wfd_add_dialogue_separator(Evas_Object *genlist, const char *separator_style)
566 {
567         __WDUG_LOG_FUNC_ENTER__;
568         assertm_if(NULL == genlist, "NULL!!");
569
570         static Elm_Genlist_Item_Class *separator_itc;
571         separator_itc = elm_genlist_item_class_new();
572         separator_itc->item_style = separator_style;
573         separator_itc->func.text_get = NULL;
574         separator_itc->func.content_get = NULL;
575         separator_itc->func.state_get = NULL;
576         separator_itc->func.del = __wfd_separator_del;
577
578         Elm_Object_Item *sep = elm_genlist_item_append(
579                                         genlist,
580                                         separator_itc,
581                                         separator_itc,
582                                         NULL,
583                                         ELM_GENLIST_ITEM_GROUP,
584                                         NULL,
585                                         NULL);
586
587         assertm_if(NULL == sep, "NULL!!");
588
589         elm_genlist_item_select_mode_set(sep, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
590
591         __WDUG_LOG_FUNC_EXIT__;
592         return sep;
593 }
594
595 /**
596  *      This function let the ug create the main genlist
597  *      @return   the main genlist
598  *      @param[in] data the pointer to the main data structure
599  */
600 static Evas_Object *_create_basic_genlist(void *data)
601 {
602         __WDUG_LOG_FUNC_ENTER__;
603         struct ug_data *ugd = (struct ug_data *) data;
604         Evas_Object *genlist;
605
606         genlist = elm_genlist_add(ugd->naviframe);
607         wfd_add_dialogue_separator(genlist, "dialogue/separator");
608         ugd->head = elm_genlist_item_append(genlist, &head_itc, ugd, NULL,
609                 ELM_GENLIST_ITEM_NONE, _gl_header_sel, (void *)ugd);
610
611         __WDUG_LOG_FUNC_EXIT__;
612         return genlist;
613 }
614
615 /**
616  *      This function let the ug create the about item to append the genlist
617  *      @return   the main item
618  *      @param[in] data the pointer to the main data structure
619  */
620 static Evas_Object *_create_about_genlist(void *data)
621 {
622         __WDUG_LOG_FUNC_ENTER__;
623         struct ug_data *ugd = (struct ug_data *) data;
624
625         ugd->about_wfd_sep_high_item = wfd_add_dialogue_separator(ugd->genlist, "dialogue/separator");
626         ugd->about_wfd_item = elm_genlist_item_append(ugd->genlist, &name_itc, ugd, NULL,
627                 ELM_GENLIST_ITEM_NONE, _gl_about_wifi_sel, (void *)ugd);
628         ugd->about_wfd_sep_low_item = wfd_add_dialogue_separator(ugd->genlist, "dialogue/separator/end");
629
630         __WDUG_LOG_FUNC_EXIT__;
631         return ugd->genlist;
632 }
633
634 /**
635  *      This function let the ug create no device item to append the genlist
636  *      @return   the main item
637  *      @param[in] data the pointer to the main data structure
638  */
639 static Evas_Object *_create_no_device_genlist(void *data)
640 {
641         __WDUG_LOG_FUNC_ENTER__;
642         struct ug_data *ugd = (struct ug_data *) data;
643
644         ugd->nodevice_title_item = elm_genlist_item_append(ugd->genlist, &title_itc, (void *)ugd, NULL,
645                 ELM_GENLIST_ITEM_NONE, NULL, NULL);
646         ugd->nodevice_item = elm_genlist_item_append(ugd->genlist, &noitem_itc, (void *)ugd, NULL,
647                 ELM_GENLIST_ITEM_NONE, NULL, NULL);
648         elm_genlist_item_select_mode_set(ugd->nodevice_item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
649
650         __WDUG_LOG_FUNC_EXIT__;
651         return ugd->genlist;
652 }
653
654 /**
655  *      This function let the ug create multi connect button
656  *      @return   0
657  *      @param[in] data the pointer to the main data structure
658  */
659 int _create_multi_button_genlist(void *data)
660 {
661         __WDUG_LOG_FUNC_ENTER__;
662         struct ug_data *ugd = (struct ug_data *) data;
663
664         wfd_refresh_wifi_direct_state(ugd);
665
666         /* show the button */
667         if (ugd->multi_connect_mode != WFD_MULTI_CONNECT_MODE_NONE) {
668                 if (ugd->raw_multi_selected_peer_cnt > 1 ||
669                         ugd->gl_connected_peer_cnt > 0 ||
670                         ugd->wfd_status == WIFI_DIRECT_STATE_CONNECTING) {
671                         ugd->multi_button_sep_item = wfd_add_dialogue_separator(ugd->genlist, "dialogue/separator");
672                         ugd->multi_button_item = elm_genlist_item_append(ugd->genlist, &button_itc, ugd, NULL,
673                                 ELM_GENLIST_ITEM_NONE, NULL, NULL);
674                 }
675         } else {
676                 if (ugd->gl_available_peer_cnt > 1 ||
677                         ugd->gl_connected_peer_cnt > 0 ||
678                         ugd->wfd_status == WIFI_DIRECT_STATE_CONNECTING) {
679                         ugd->multi_button_sep_item = wfd_add_dialogue_separator(ugd->genlist, "dialogue/separator");
680                         ugd->multi_button_item = elm_genlist_item_append(ugd->genlist, &button_itc, ugd, NULL,
681                                 ELM_GENLIST_ITEM_NONE, NULL, NULL);
682                 }
683         }
684
685         __WDUG_LOG_FUNC_EXIT__;
686         return 0;
687 }
688
689 /**
690  *      This function let the ug create busy device list
691  *      @return   0
692  *      @param[in] data the pointer to the main data structure
693  */
694 int _create_busy_dev_list(void *data)
695 {
696         __WDUG_LOG_FUNC_ENTER__;
697         struct ug_data *ugd = (struct ug_data *) data;
698
699         ugd->busy_wfd_item = elm_genlist_item_append(ugd->genlist, &title_busy_itc, (void *)ugd, NULL,
700                 ELM_GENLIST_ITEM_NONE, NULL, NULL);
701         elm_genlist_item_select_mode_set(ugd->busy_wfd_item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
702
703         __WDUG_LOG_FUNC_EXIT__;
704         return 0;
705 }
706
707 /**
708  *      This function let the ug create avaliable device list
709  *      @return   0
710  *      @param[in] data the pointer to the main data structure
711  */
712 static int _create_available_dev_genlist(void *data)
713 {
714         __WDUG_LOG_FUNC_ENTER__;
715         struct ug_data *ugd = (struct ug_data *) data;
716
717         ugd->avlbl_wfd_item = elm_genlist_item_append(ugd->genlist, &title_itc, (void *)ugd, NULL,
718                 ELM_GENLIST_ITEM_NONE, NULL, NULL);
719
720         __WDUG_LOG_FUNC_EXIT__;
721         return 0;
722 }
723
724 /**
725  *      This function let the ug create multi connect device list
726  *      @return   0
727  *      @param[in] data the pointer to the main data structure
728  */
729 static int _create_multi_connect_dev_genlist(void *data)
730 {
731         __WDUG_LOG_FUNC_ENTER__;
732         struct ug_data *ugd = (struct ug_data *) data;
733
734         ugd->multi_connect_wfd_item = elm_genlist_item_append(ugd->genlist, &title_multi_connect_itc, (void *)ugd, NULL,
735                 ELM_GENLIST_ITEM_NONE, NULL, NULL);
736
737         __WDUG_LOG_FUNC_EXIT__;
738         return 0;
739 }
740
741 /**
742  *      This function let the ug create connected device list
743  *      @return   0
744  *      @param[in] data the pointer to the main data structure
745  */
746 int _create_connected_dev_genlist(void *data)
747 {
748         __WDUG_LOG_FUNC_ENTER__;
749         struct ug_data *ugd = (struct ug_data *) data;
750
751         ugd->conn_wfd_item = elm_genlist_item_append(ugd->genlist, &title_conn_itc, (void *)ugd, NULL,
752                 ELM_GENLIST_ITEM_NONE, NULL, NULL);
753         elm_genlist_item_select_mode_set(ugd->conn_wfd_item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
754
755         __WDUG_LOG_FUNC_EXIT__;
756         return 0;
757 }
758
759 /**
760  *      This function let the ug create connected falied device list
761  *      @return   0
762  *      @param[in] data the pointer to the main data structure
763  */
764 int _create_connected_failed_dev_genlist(void *data)
765 {
766         __WDUG_LOG_FUNC_ENTER__;
767         struct ug_data *ugd = (struct ug_data *) data;
768
769         ugd->conn_failed_wfd_item = elm_genlist_item_append(ugd->genlist, &title_conn_failed_itc, (void *)ugd, NULL,
770                 ELM_GENLIST_ITEM_NONE, NULL, NULL);
771         elm_genlist_item_select_mode_set(ugd->conn_failed_wfd_item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
772
773         __WDUG_LOG_FUNC_EXIT__;
774         return 0;
775 }
776
777 /**
778  *      This function let the ug make the display callback for connect failed peers
779  *      @return   if stop the timer, return ECORE_CALLBACK_CANCEL, else return ECORE_CALLBACK_RENEW
780  *      @param[in] data the pointer to the user data
781  */
782 static Eina_Bool _connect_failed_peers_display_cb(void *user_data)
783 {
784         int interval = 0;
785         int res = -1;
786         struct ug_data *ugd = (struct ug_data *) user_data;
787
788         if (NULL == ugd) {
789                 WDUG_LOGE("NULL parameters.\n");
790                 return ECORE_CALLBACK_CANCEL;
791         }
792
793         /* check the timeout, if not timeout, keep the cb */
794         interval = time(NULL) - ugd->last_display_time;
795         if (interval < MAX_DISPLAY_TIME_OUT) {
796                 return ECORE_CALLBACK_RENEW;
797         }
798
799         /* start discovery again */
800         res = wifi_direct_start_discovery(FALSE, MAX_SCAN_TIME_OUT);
801         if (res != WIFI_DIRECT_ERROR_NONE) {
802                 WDUG_LOGE("Failed to start discovery. [%d]\n", res);
803                 ugd->is_re_discover = TRUE;
804                 wifi_direct_cancel_discovery();
805         } else {
806                 WDUG_LOGD("Discovery is started\n");
807                 ugd->is_re_discover = FALSE;
808         }
809
810         return ECORE_CALLBACK_CANCEL;
811 }
812
813 /**
814  *      This function let the ug free the peers
815  *      @return   void
816  *      @param[in] data the pointer to the main data structure
817  */
818 void wfd_ug_view_free_peers(void *data)
819 {
820         __WDUG_LOG_FUNC_ENTER__;
821         struct ug_data *ugd = (struct ug_data *) data;
822         int i = 0;
823
824         for (i = 0; i < ugd->gl_connected_peer_cnt; i++) {
825                 WDUG_LOGD("%dth connected peer = %x is deleted\n", i, ugd->gl_connected_peers[i]);
826                 if (ugd->gl_connected_peers[i].gl_item != NULL) {
827                         elm_object_item_del(ugd->gl_connected_peers[i].gl_item);
828                         ugd->gl_connected_peers[i].gl_item = NULL;
829                         WDUG_LOGD("Deleted item\n");
830                 }
831         }
832
833         ugd->gl_connected_peer_cnt = 0;
834
835         for (i = 0; i < ugd->gl_connected_failed_peer_cnt; i++) {
836                 WDUG_LOGD("%dth connected failed peer = %x is deleted\n", i, ugd->gl_connected_failed_peers[i]);
837                 if (ugd->gl_connected_failed_peers[i].gl_item != NULL) {
838                     elm_object_item_del(ugd->gl_connected_failed_peers[i].gl_item);
839                     ugd->gl_connected_failed_peers[i].gl_item = NULL;
840                     WDUG_LOGD("Deleted item\n");
841                 }
842         }
843
844         ugd->gl_connected_failed_peer_cnt = 0;
845
846         for (i = 0; i < ugd->gl_available_peer_cnt; i++) {
847                 WDUG_LOGD("%dth discovered peer = %x is deleted\n", i, ugd->gl_available_peers[i]);
848                 if (ugd->gl_available_peers[i].gl_item != NULL) {
849                         elm_object_item_del(ugd->gl_available_peers[i].gl_item);
850                         ugd->gl_available_peers[i].gl_item = NULL;
851                         WDUG_LOGD("Deleted item\n");
852                 }
853         }
854
855         ugd->gl_available_peer_cnt = 0;
856
857         for (i = 0; i < ugd->gl_busy_peer_cnt; i++) {
858                 WDUG_LOGD("%dth busy peer = %x is deleted\n", i, ugd->gl_busy_peers[i]);
859                 if (ugd->gl_busy_peers[i].gl_item != NULL) {
860                         elm_object_item_del(ugd->gl_busy_peers[i].gl_item);
861                         ugd->gl_busy_peers[i].gl_item = NULL;
862                         WDUG_LOGD("Deleted item\n");
863                 }
864         }
865
866         ugd->gl_busy_peer_cnt = 0;
867
868         for (i = 0; i < ugd->gl_multi_connect_peer_cnt; i++) {
869                 WDUG_LOGD("%dth multi connect peer = %x is deleted\n", i, ugd->gl_multi_connect_peers[i]);
870                 if (ugd->gl_multi_connect_peers[i].gl_item != NULL) {
871                         elm_object_item_del(ugd->gl_multi_connect_peers[i].gl_item);
872                         ugd->gl_multi_connect_peers[i].gl_item = NULL;
873                         WDUG_LOGD("Deleted item\n");
874                 }
875         }
876
877         ugd->gl_multi_connect_peer_cnt = 0;
878
879         if (ugd->nodevice_title_item != NULL) {
880                 elm_object_item_del(ugd->nodevice_title_item);
881                 ugd->nodevice_title_item = NULL;
882         }
883
884         if (ugd->nodevice_item != NULL) {
885                 elm_object_item_del(ugd->nodevice_item);
886                 ugd->nodevice_item = NULL;
887         }
888
889         if (ugd->about_wfd_item != NULL) {
890                 elm_object_item_del(ugd->about_wfd_item);
891                 ugd->about_wfd_item = NULL;
892         }
893
894         if (ugd->about_wfd_sep_high_item != NULL) {
895                 elm_object_item_del(ugd->about_wfd_sep_high_item);
896                 ugd->about_wfd_sep_high_item = NULL;
897         }
898
899         if (ugd->about_wfd_sep_low_item != NULL) {
900                 elm_object_item_del(ugd->about_wfd_sep_low_item);
901                 ugd->about_wfd_sep_low_item = NULL;
902         }
903
904         if (ugd->conn_wfd_item != NULL) {
905                 elm_object_item_del(ugd->conn_wfd_item);
906                 ugd->conn_wfd_item = NULL;
907         }
908
909         if (ugd->conn_failed_wfd_item != NULL) {
910                 elm_object_item_del(ugd->conn_failed_wfd_item);
911                 ugd->conn_failed_wfd_item = NULL;
912         }
913
914         if (ugd->display_timer != NULL) {
915                 ecore_timer_del(ugd->display_timer);
916                 ugd->display_timer = NULL;
917         }
918
919         if (ugd->multi_connect_wfd_item != NULL) {
920                 elm_object_item_del(ugd->multi_connect_wfd_item);
921                 ugd->multi_connect_wfd_item = NULL;
922         }
923
924         if (ugd->avlbl_wfd_item != NULL) {
925                 elm_object_item_del(ugd->avlbl_wfd_item);
926                 ugd->avlbl_wfd_item = NULL;
927         }
928
929         if (ugd->busy_wfd_item != NULL) {
930                 elm_object_item_del(ugd->busy_wfd_item);
931                 ugd->busy_wfd_item = NULL;
932         }
933
934         if (ugd->multi_button_item != NULL) {
935                 elm_object_item_del(ugd->multi_button_item);
936                 ugd->multi_button_item = NULL;
937         }
938
939         if (ugd->multi_button_sep_item != NULL) {
940                 elm_object_item_del(ugd->multi_button_sep_item);
941                 ugd->multi_button_sep_item = NULL;
942         }
943
944         __WDUG_LOG_FUNC_EXIT__;
945 }
946
947 /**
948  *      This function let the ug update the peers
949  *      @return   void
950  *      @param[in] data the pointer to the main data structure
951  */
952 void wfd_ug_view_update_peers(void *data)
953 {
954         __WDUG_LOG_FUNC_ENTER__;
955         struct ug_data *ugd = (struct ug_data *) data;
956         int no_of_busy_dev = 0;
957         int no_of_available_dev = 0;
958         int no_of_conn_dev = 0;
959         int no_of_conn_failed_dev = 0;
960         int i = 0 ;
961         int res = 0;
962         bool is_group_owner = FALSE;
963         int count = 0;
964
965         wfd_ug_view_free_peers(ugd);
966
967         if (ugd->wfd_status == WIFI_DIRECT_STATE_DEACTIVATED) {
968                 WDUG_LOGD("Device is deactivated, no need to update UI.");
969                 _create_about_genlist(ugd);
970                 return;
971         }
972
973         res = wifi_direct_is_group_owner(&is_group_owner);
974         if (res != WIFI_DIRECT_ERROR_NONE) {
975                 WDUG_LOGD("Fail to get group_owner_state. ret=[%d]", res);
976                 ugd->I_am_group_owner = FALSE;
977         } else {
978                 ugd->I_am_group_owner = is_group_owner;
979         }
980
981         __wfd_is_any_device_busy(ugd, &no_of_busy_dev);
982         __wfd_is_any_device_available(ugd, &no_of_available_dev);
983         __wfd_is_any_device_connect_failed(ugd, &no_of_conn_failed_dev);
984         no_of_conn_dev = ugd->raw_connected_peer_cnt;
985
986         ugd->gl_available_peer_cnt = no_of_available_dev;
987         ugd->gl_connected_peer_cnt = no_of_conn_dev;
988         ugd->gl_connected_failed_peer_cnt = no_of_conn_failed_dev;
989         ugd->gl_busy_peer_cnt = no_of_busy_dev;
990
991         WDUG_LOGD("conn_dev=[%d], conn_failed_dev=[%d], avail_dev=[%d], busy_dev=[%d], GO=[%d]\n",
992                 no_of_conn_dev, no_of_conn_failed_dev, no_of_available_dev, no_of_busy_dev, is_group_owner);
993
994         if (no_of_conn_dev == 0 && no_of_conn_failed_dev == 0 &&
995                 no_of_available_dev == 0 && no_of_busy_dev == 0) {
996                 WDUG_LOGE("There are No peers\n");
997                 _create_no_device_genlist(ugd);
998                 _create_about_genlist(ugd);
999                 return;
1000         }
1001
1002         /* display connect peers */
1003         if (no_of_conn_dev > 0) {
1004                 if (!ugd->conn_wfd_item) {
1005                         _create_connected_dev_genlist(ugd);
1006                 }
1007
1008                 count = 0;
1009                 for (i = 0; i < ugd->raw_connected_peer_cnt; i++) {
1010                         if (ugd->gl_connected_peers[count].gl_item) {
1011                                 elm_object_item_del(ugd->gl_connected_peers[count].gl_item);
1012                         }
1013
1014                         memcpy(&ugd->gl_connected_peers[count], &ugd->raw_connected_peers[i], sizeof(device_type_s));
1015                         ugd->gl_connected_peers[count].gl_item = elm_genlist_item_append(ugd->genlist, &peer_conn_itc,
1016                                 (void *)&(ugd->gl_connected_peers[i]), NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
1017                         elm_genlist_item_select_mode_set(ugd->gl_connected_peers[count].gl_item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1018                         count++;
1019                 }
1020         }
1021
1022         if (ugd->multi_connect_mode != WFD_MULTI_CONNECT_MODE_NONE) {
1023                 if (ugd->raw_multi_selected_peer_cnt > 0) {
1024                         if (ugd->raw_connected_peer_cnt < ugd->raw_multi_selected_peer_cnt &&
1025                                 ugd->multi_connect_wfd_item == NULL) {
1026                                 _create_multi_connect_dev_genlist(ugd);
1027                         }
1028
1029                         count = 0;
1030                         for (i = 0; i < ugd->raw_multi_selected_peer_cnt; i++) {
1031                                 if (ugd->raw_multi_selected_peers[i].conn_status != PEER_CONN_STATUS_CONNECTED) {
1032                                         if (ugd->gl_multi_connect_peers[count].gl_item) {
1033                                                 elm_object_item_del(ugd->gl_multi_connect_peers[count].gl_item);
1034                                         }
1035
1036                                         memcpy(&ugd->gl_multi_connect_peers[count], &ugd->raw_multi_selected_peers[i], sizeof(device_type_s));
1037                                         ugd->gl_multi_connect_peers[count].gl_item = elm_genlist_item_append(ugd->genlist, &peer_itc,
1038                                                 (void *) &(ugd->gl_multi_connect_peers[count]), NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
1039                                         count++;
1040                                 }
1041                         }
1042
1043                         ugd->gl_multi_connect_peer_cnt = count;
1044                 }
1045
1046                 _create_multi_button_genlist(ugd);
1047         } else {
1048                 /*
1049                 * Note that
1050                 * If GC, no display available peers
1051                 * Otherwise, display available peers
1052                 */
1053                 if (no_of_available_dev > 0 && (no_of_conn_dev == 0 || is_group_owner == TRUE)) {
1054                         if (ugd->avlbl_wfd_item == NULL) {
1055                                 _create_available_dev_genlist(ugd);
1056                         }
1057
1058                         count = 0;
1059                         for (i = 0; i < ugd->raw_discovered_peer_cnt; i++) {
1060                                 /* Not include the device which is connected with me */
1061                                 if (__wfd_is_device_connected_with_me(ugd, &ugd->raw_discovered_peers[i])) {
1062                                         continue;
1063                                 }
1064                                 if (!__wfd_is_device_busy(ugd, &ugd->raw_discovered_peers[i]) &&
1065                                         ugd->raw_discovered_peers[i].conn_status != PEER_CONN_STATUS_FAILED_TO_CONNECT) {
1066                                         if (ugd->gl_available_peers[count].gl_item) {
1067                                                 elm_object_item_del(ugd->gl_available_peers[count].gl_item);
1068                                         }
1069
1070                                         memcpy(&ugd->gl_available_peers[count], &ugd->raw_discovered_peers[i], sizeof(device_type_s));
1071                                         ugd->gl_available_peers[count].gl_item = elm_genlist_item_append(ugd->genlist, &peer_itc,
1072                                                 (void *)&(ugd->gl_available_peers[count]), NULL, ELM_GENLIST_ITEM_NONE, _gl_peer_sel,
1073                                                 (void *)&(ugd->gl_available_peers[count]));
1074                                         count++;
1075                                 }
1076                         }
1077                 }
1078
1079                 /* display connect failed peers */
1080                 if (no_of_conn_failed_dev > 0) {
1081                         if (!ugd->conn_failed_wfd_item) {
1082                                 _create_connected_failed_dev_genlist(ugd);
1083                         }
1084
1085                         /* add timer for disappearing failed peers after N secs */
1086                         if (NULL == ugd->display_timer) {
1087                                 ugd->last_display_time = time(NULL);
1088                                 ugd->display_timer = ecore_timer_add(5.0, (Ecore_Task_Cb)_connect_failed_peers_display_cb, ugd);
1089                         }
1090
1091                         count = 0;
1092                         for (i = 0; i < ugd->raw_discovered_peer_cnt; i++) {
1093                                 /* Not include the device which is connected with me */
1094                                 if (__wfd_is_device_connected_with_me(ugd, &ugd->raw_discovered_peers[i])) {
1095                                         continue;
1096                                 }
1097                                 if (!__wfd_is_device_busy(ugd, &ugd->raw_discovered_peers[i]) &&
1098                                         ugd->raw_discovered_peers[i].conn_status == PEER_CONN_STATUS_FAILED_TO_CONNECT) {
1099                                         if (ugd->gl_connected_failed_peers[count].gl_item) {
1100                                                 elm_object_item_del(ugd->gl_connected_failed_peers[count].gl_item);
1101                                         }
1102
1103                                         memcpy(&ugd->gl_connected_failed_peers[count], &ugd->raw_discovered_peers[i], sizeof(device_type_s));
1104                                         ugd->gl_connected_failed_peers[count].gl_item = elm_genlist_item_append(ugd->genlist, &peer_conn_failed_itc,
1105                                                 (void *)&(ugd->gl_connected_failed_peers[count]), NULL, ELM_GENLIST_ITEM_NONE, NULL, ugd);
1106                                         elm_genlist_item_select_mode_set(ugd->gl_connected_failed_peers[count].gl_item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1107                                         count++;
1108                                 }
1109                         }
1110                 }
1111
1112                 _create_multi_button_genlist(ugd);
1113
1114                 /* If connected, not display busy device */
1115                 if (no_of_conn_dev == 0 && no_of_busy_dev > 0) {
1116                         if (ugd->busy_wfd_item == NULL) {
1117                                 _create_busy_dev_list(ugd);
1118                         }
1119
1120                         count = 0;
1121                         for (i = 0; i < ugd->raw_discovered_peer_cnt; i++) {
1122                                 /* Not include the device which is connected with me */
1123                                 if (__wfd_is_device_connected_with_me(ugd, &ugd->raw_discovered_peers[i])) {
1124                                         continue;
1125                                 }
1126                                 if (__wfd_is_device_busy(ugd, &ugd->raw_discovered_peers[i]) == TRUE) {
1127                                         if (ugd->gl_busy_peers[count].gl_item) {
1128                                                 elm_object_item_del(ugd->gl_busy_peers[count].gl_item);
1129                                         }
1130
1131                                         memcpy(&ugd->gl_busy_peers[count], &ugd->raw_discovered_peers[i], sizeof(device_type_s));
1132                                         ugd->gl_busy_peers[count].gl_item = elm_genlist_item_append(ugd->genlist, &peer_busy_itc,
1133                                                 (void *)&(ugd->gl_busy_peers[count]), NULL, ELM_GENLIST_ITEM_NONE, _gl_busy_peer_sel, ugd);
1134                                         count++;
1135                                 }
1136                         }
1137                 }
1138         }
1139         _create_about_genlist(ugd);
1140
1141         __WDUG_LOG_FUNC_EXIT__;
1142 }
1143
1144 /**
1145  *      This function let the ug create the main view
1146  *      @return   void
1147  *      @param[in] data the pointer to the main data structure
1148  */
1149 void create_wfd_ug_view(void *data)
1150 {
1151         __WDUG_LOG_FUNC_ENTER__;
1152         struct ug_data *ugd = (struct ug_data *) data;
1153         Elm_Object_Item *navi_item = NULL;
1154
1155         if (ugd == NULL) {
1156                 WDUG_LOGE("Incorrect parameter(NULL)");
1157                 return;
1158         }
1159
1160         ugd->naviframe = elm_naviframe_add(ugd->base);
1161         elm_object_part_content_set(ugd->base, "elm.swallow.content", ugd->naviframe);
1162         evas_object_show(ugd->naviframe);
1163
1164         ugd->back_btn = elm_button_add(ugd->naviframe);
1165         elm_object_style_set(ugd->back_btn, "naviframe/back_btn/default");
1166         evas_object_smart_callback_add(ugd->back_btn, "clicked", _back_btn_cb, (void *)ugd);
1167         elm_object_focus_allow_set(ugd->back_btn, EINA_FALSE);
1168
1169         ugd->genlist = _create_basic_genlist(ugd);
1170         if (ugd->genlist == NULL) {
1171                 WDUG_LOGE("Failed to create basic genlist");
1172                 return;
1173         }
1174
1175         evas_object_show(ugd->genlist);
1176         wfd_refresh_wifi_direct_state(ugd);
1177         if (ugd->wfd_status > WIFI_DIRECT_STATE_ACTIVATING) {
1178                 ugd->wfd_onoff = TRUE;
1179         }
1180
1181         navi_item = elm_naviframe_item_push(ugd->naviframe, _("IDS_WFD_HEADER_WIFI_DIRECT"), ugd->back_btn, NULL, ugd->genlist, NULL);
1182         /* create scan button */
1183         ugd->scan_btn = elm_button_add(ugd->naviframe);
1184         elm_object_style_set(ugd->scan_btn, "naviframe/toolbar/default");
1185         elm_object_text_set(ugd->scan_btn, _("IDS_WFD_BUTTON_SCAN"));
1186         evas_object_smart_callback_add(ugd->scan_btn, "clicked", _scan_btn_cb, (void *)ugd);
1187         elm_object_item_part_content_set(navi_item, "toolbar_button1", ugd->scan_btn);
1188
1189         __WDUG_LOG_FUNC_EXIT__;
1190 }