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