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