4 * Copyright 2012 Samsung Electronics Co., Ltd
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
10 * http://floralicense.org/license
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.
26 #include <Elementary.h>
28 #include <ui-gadget-module.h>
29 #include <wifi-direct.h>
32 #include "wfd_ug_view.h"
33 #include "wfd_client.h"
36 * This function let the ug call it when click 'back' button
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
42 void _back_btn_cb(void *data, Evas_Object * obj, void *event_info)
44 __WDUG_LOG_FUNC_ENTER__;
45 struct ug_data *ugd = (struct ug_data *) data;
48 WDUG_LOGE("The param is NULL\n");
52 wfd_ug_view_free_peers(ugd);
55 service_h service = NULL;
56 ret = service_create(&service);
58 WDUG_LOGE("Failed to create service");
62 wfd_refresh_wifi_direct_state(ugd);
63 if (ugd->wfd_status > WIFI_DIRECT_STATE_CONNECTING) {
64 service_add_extra_data(service, "Connection", "TRUE");
66 service_add_extra_data(service, "Connection", "FALSE");
69 ug_send_result(ugd->ug, service);
70 service_destroy(service);
71 ug_destroy_me(ugd->ug);
73 __WDUG_LOG_FUNC_EXIT__;
78 * This function let the ug call it when click 'scan' button
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
84 void _scan_btn_cb(void *data, Evas_Object *obj, void *event_info)
86 __WDUG_LOG_FUNC_ENTER__;
88 struct ug_data *ugd = (struct ug_data *) data;
90 char *btn_text = NULL;
93 WDUG_LOGE("Incorrect parameter(NULL)\n");
97 btn_text = (char *)elm_object_text_get(obj);
98 if (NULL == btn_text) {
99 WDUG_LOGE("Incorrect button text(NULL)\n");
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);
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__;
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();
121 WDUG_LOGD("Discovery is started\n");
122 ugd->is_re_discover = FALSE;
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);
131 ugd->is_re_discover = FALSE;
132 wifi_direct_cancel_discovery();
135 __WDUG_LOG_FUNC_EXIT__;
140 * This function let the ug call it when click header
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
146 static void _gl_header_sel(void *data, Evas_Object *obj, void *event_info)
148 __WDUG_LOG_FUNC_ENTER__;
150 WDUG_LOGE("Incorrect parameter(NULL)\n");
151 __WDUG_LOG_FUNC_EXIT__;
155 struct ug_data *ugd = (struct ug_data *) data;
156 Elm_Object_Item *item = (Elm_Object_Item *)event_info;
159 elm_genlist_item_selected_set(item, EINA_FALSE);
162 /* turn on/off wfd */
163 if (!ugd->wfd_onoff) {
164 WDUG_LOGD("wifi-direct switch on\n");
165 wfd_client_switch_on(ugd);
167 WDUG_LOGD("wifi-direct switch off\n");
168 wfd_client_switch_off(ugd);
171 __WDUG_LOG_FUNC_EXIT__;
175 * This function let the ug call it when click genlist item
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
181 static void _gl_item_sel(void *data, Evas_Object *obj, void *event_info)
183 __WDUG_LOG_FUNC_ENTER__;
185 WDUG_LOGE("Incorrect parameter(NULL)\n");
186 __WDUG_LOG_FUNC_EXIT__;
190 struct ug_data *ugd = (struct ug_data *) data;
191 Elm_Object_Item *item = (Elm_Object_Item *)event_info;
194 elm_genlist_item_selected_set(item, EINA_FALSE);
197 __WDUG_LOG_FUNC_EXIT__;
201 * This function let the ug call it when click avaliable peer to connect
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
207 static void _gl_peer_sel(void *data, Evas_Object *obj, void *event_info)
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;
217 WDUG_LOGE("Incorrect parameter(NULL)\n");
222 elm_genlist_item_selected_set(item, EINA_FALSE);
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);
229 WDUG_LOGE("Failed to send connection request. [%d]\n", res);
233 res = wfd_client_disconnect((const char *)peer->mac_addr);
235 WDUG_LOGE("Failed to send disconnection request. [%d]\n", res);
240 __WDUG_LOG_FUNC_EXIT__;
245 * This function let the ug call it when click busy peer
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
251 static void _gl_busy_peer_sel(void *data, Evas_Object *obj, void *event_info)
253 __WDUG_LOG_FUNC_ENTER__;
254 struct ug_data *ugd = (struct ug_data *) data;
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);
260 __WDUG_LOG_FUNC_EXIT__;
264 * This function let the ug call it when click about item
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
270 static void _gl_about_wifi_sel(void *data, Evas_Object *obj, void *event_info)
272 __WDUG_LOG_FUNC_ENTER__;
273 struct ug_data *ugd = (struct ug_data *) data;
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);
279 __WDUG_LOG_FUNC_EXIT__;
283 * This function let the ug call it when click 'multi connect' button
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
289 void _wifid_create_multibutton_cb(void *data, Evas_Object * obj, void *event_info)
291 __WDUG_LOG_FUNC_ENTER__;
292 struct ug_data *ugd = (struct ug_data *) data;
293 const char *text_lbl = NULL;
295 text_lbl = elm_object_text_get(ugd->multi_btn);
296 WDUG_LOGD("text_lbl = %s", text_lbl);
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);
303 WDUG_LOGD("Invalid Case\n");
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);
315 WDUG_LOGD("Invalid Case\n");
319 __WDUG_LOG_FUNC_EXIT__;
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
327 int _change_multi_button_title(void *data)
329 __WDUG_LOG_FUNC_ENTER__;
330 struct ug_data *ugd = (struct ug_data *) data;
332 if (ugd->multi_button_item == NULL) {
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"));
343 elm_object_text_set(ugd->multi_btn, _("IDS_WFD_BUTTON_DISCONNECT"));
346 elm_object_text_set(ugd->multi_btn, _("IDS_WFD_BUTTON_MULTI"));
349 evas_object_show(ugd->multi_btn);
350 __WDUG_LOG_FUNC_EXIT__;
356 * This function let the ug update the genlist item
358 * @param[in] obj the pointer to genlist item
360 void wfd_ug_view_refresh_glitem(void *obj)
362 __WDUG_LOG_FUNC_ENTER__;
363 elm_genlist_item_update(obj);
364 __WDUG_LOG_FUNC_EXIT__;
368 * This function let the ug refresh the attributes of button
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
374 void wfd_ug_view_refresh_button(void *obj, const char *text, int enable)
376 __WDUG_LOG_FUNC_ENTER__;
378 if (NULL == obj || NULL == text) {
379 WDUG_LOGE("Incorrect parameter(NULL)\n");
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);
387 __WDUG_LOG_FUNC_EXIT__;
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
396 static bool __wfd_is_device_connected_with_me(struct ug_data *ugd, device_type_s *dev)
398 __WDUG_LOG_FUNC_ENTER__;
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) {
408 __WDUG_LOG_FUNC_EXIT__;
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
418 static bool __wfd_is_device_busy(struct ug_data *ugd, device_type_s *dev)
420 __WDUG_LOG_FUNC_ENTER__;
422 if (ugd->I_am_group_owner == TRUE) {
423 if (dev->is_connected || dev->is_group_owner) {
429 if (dev->is_connected == TRUE && dev->is_group_owner == TRUE) {
433 if (dev->is_connected == TRUE && dev->is_group_owner == FALSE) {
437 if (dev->is_connected == FALSE) {
442 __WDUG_LOG_FUNC_EXIT__;
447 * This function let the ug calculate how many devices are avaliable
449 * @param[in] ugd the pointer to the main data structure
450 * @param[in] dev the pointer to the number of avaliable devices
452 static bool __wfd_is_any_device_available(struct ug_data *ugd, int* no_of_available_dev)
454 __WDUG_LOG_FUNC_ENTER__;
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])) {
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)++;
468 __WDUG_LOG_FUNC_EXIT__;
473 * This function let the ug calculate how many devices are busy
475 * @param[in] ugd the pointer to the main data structure
476 * @param[in] dev the pointer to the number of busy devices
478 static bool __wfd_is_any_device_busy(struct ug_data *ugd, int* no_of_busy_dev)
480 __WDUG_LOG_FUNC_ENTER__;
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])) {
488 if (__wfd_is_device_busy(ugd, &ugd->raw_discovered_peers[i])) {
493 __WDUG_LOG_FUNC_EXIT__;
498 * This function let the ug calculate how many devices are connected failed
500 * @param[in] ugd the pointer to the main data structure
501 * @param[in] dev the pointer to the number of connected failed devices
503 static bool __wfd_is_any_device_connect_failed(struct ug_data *ugd, int* no_of_connect_failed_dev)
505 __WDUG_LOG_FUNC_ENTER__;
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])) {
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)++;
520 __WDUG_LOG_FUNC_EXIT__;
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
530 int wfd_get_device_status(void *data, device_type_s *device)
532 __WDUG_LOG_FUNC_ENTER__;
535 struct ug_data *ugd = (struct ug_data *) data;
538 WDUG_LOGE("Incorrect parameter(NULL)");
542 /* check whether it is connected device */
543 ret = __wfd_is_device_connected_with_me(ugd, device);
545 WDUG_LOGD("This is connected device");
550 /* check whether it is busy device */
551 ret = __wfd_is_device_busy(ugd, device);
553 WDUG_LOGD("This is busy device");
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");
563 WDUG_LOGD("This is connected failed device");
568 __WDUG_LOG_FUNC_EXIT__;
573 * This function let the ug delete the separator
575 * @param[in] data the pointer to the main data structure
576 * @param[in] obj the pointer to the evas object
578 static void __wfd_separator_del(void *data, Evas_Object *obj)
580 __WDUG_LOG_FUNC_ENTER__;
581 elm_genlist_item_class_free(data);
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
591 Elm_Object_Item *wfd_add_dialogue_separator(Evas_Object *genlist, const char *separator_style)
593 __WDUG_LOG_FUNC_ENTER__;
594 assertm_if(NULL == genlist, "NULL!!");
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;
604 Elm_Object_Item *sep = elm_genlist_item_append(
609 ELM_GENLIST_ITEM_GROUP,
613 assertm_if(NULL == sep, "NULL!!");
615 elm_genlist_item_select_mode_set(sep, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
617 __WDUG_LOG_FUNC_EXIT__;
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
626 static Evas_Object *_create_basic_genlist(void *data)
628 __WDUG_LOG_FUNC_ENTER__;
629 struct ug_data *ugd = (struct ug_data *) data;
630 Evas_Object *genlist;
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);
637 __WDUG_LOG_FUNC_EXIT__;
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
646 static Evas_Object *_create_about_genlist(void *data)
648 __WDUG_LOG_FUNC_ENTER__;
649 struct ug_data *ugd = (struct ug_data *) data;
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");
656 __WDUG_LOG_FUNC_EXIT__;
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
665 static Evas_Object *_create_no_device_genlist(void *data)
667 __WDUG_LOG_FUNC_ENTER__;
668 struct ug_data *ugd = (struct ug_data *) data;
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);
676 __WDUG_LOG_FUNC_EXIT__;
681 * This function let the ug create multi connect button
683 * @param[in] data the pointer to the main data structure
685 int _create_multi_button_genlist(void *data)
687 __WDUG_LOG_FUNC_ENTER__;
688 struct ug_data *ugd = (struct ug_data *) data;
690 wfd_refresh_wifi_direct_state(ugd);
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);
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);
711 __WDUG_LOG_FUNC_EXIT__;
716 * This function let the ug create busy device list
718 * @param[in] data the pointer to the main data structure
720 int _create_busy_dev_list(void *data)
722 __WDUG_LOG_FUNC_ENTER__;
723 struct ug_data *ugd = (struct ug_data *) data;
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);
729 __WDUG_LOG_FUNC_EXIT__;
734 * This function let the ug create avaliable device list
736 * @param[in] data the pointer to the main data structure
738 static int _create_available_dev_genlist(void *data)
740 __WDUG_LOG_FUNC_ENTER__;
741 struct ug_data *ugd = (struct ug_data *) data;
743 ugd->avlbl_wfd_item = elm_genlist_item_append(ugd->genlist, &title_itc, (void *)ugd, NULL,
744 ELM_GENLIST_ITEM_NONE, NULL, NULL);
746 __WDUG_LOG_FUNC_EXIT__;
751 * This function let the ug create multi connect device list
753 * @param[in] data the pointer to the main data structure
755 static int _create_multi_connect_dev_genlist(void *data)
757 __WDUG_LOG_FUNC_ENTER__;
758 struct ug_data *ugd = (struct ug_data *) data;
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);
763 __WDUG_LOG_FUNC_EXIT__;
768 * This function let the ug create connected device list
770 * @param[in] data the pointer to the main data structure
772 int _create_connected_dev_genlist(void *data)
774 __WDUG_LOG_FUNC_ENTER__;
775 struct ug_data *ugd = (struct ug_data *) data;
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);
781 __WDUG_LOG_FUNC_EXIT__;
786 * This function let the ug create connected falied device list
788 * @param[in] data the pointer to the main data structure
790 int _create_connected_failed_dev_genlist(void *data)
792 __WDUG_LOG_FUNC_ENTER__;
793 struct ug_data *ugd = (struct ug_data *) data;
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);
799 __WDUG_LOG_FUNC_EXIT__;
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
808 static Eina_Bool _connect_failed_peers_display_cb(void *user_data)
812 struct ug_data *ugd = (struct ug_data *) user_data;
815 WDUG_LOGE("NULL parameters.\n");
816 return ECORE_CALLBACK_CANCEL;
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;
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();
832 WDUG_LOGD("Discovery is started\n");
833 ugd->is_re_discover = FALSE;
836 return ECORE_CALLBACK_CANCEL;
840 * This function let the ug free the peers
842 * @param[in] data the pointer to the main data structure
844 void wfd_ug_view_free_peers(void *data)
846 __WDUG_LOG_FUNC_ENTER__;
847 struct ug_data *ugd = (struct ug_data *) data;
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");
859 ugd->gl_connected_peer_cnt = 0;
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");
870 ugd->gl_connected_failed_peer_cnt = 0;
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");
881 ugd->gl_available_peer_cnt = 0;
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");
892 ugd->gl_busy_peer_cnt = 0;
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");
903 ugd->gl_multi_connect_peer_cnt = 0;
905 if (ugd->nodevice_title_item != NULL) {
906 elm_object_item_del(ugd->nodevice_title_item);
907 ugd->nodevice_title_item = NULL;
910 if (ugd->nodevice_item != NULL) {
911 elm_object_item_del(ugd->nodevice_item);
912 ugd->nodevice_item = NULL;
915 if (ugd->about_wfd_item != NULL) {
916 elm_object_item_del(ugd->about_wfd_item);
917 ugd->about_wfd_item = NULL;
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;
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;
930 if (ugd->conn_wfd_item != NULL) {
931 elm_object_item_del(ugd->conn_wfd_item);
932 ugd->conn_wfd_item = NULL;
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;
940 if (ugd->display_timer != NULL) {
941 ecore_timer_del(ugd->display_timer);
942 ugd->display_timer = NULL;
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;
950 if (ugd->avlbl_wfd_item != NULL) {
951 elm_object_item_del(ugd->avlbl_wfd_item);
952 ugd->avlbl_wfd_item = NULL;
955 if (ugd->busy_wfd_item != NULL) {
956 elm_object_item_del(ugd->busy_wfd_item);
957 ugd->busy_wfd_item = NULL;
960 if (ugd->multi_button_item != NULL) {
961 elm_object_item_del(ugd->multi_button_item);
962 ugd->multi_button_item = NULL;
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;
970 __WDUG_LOG_FUNC_EXIT__;
974 * This function let the ug update the peers
976 * @param[in] data the pointer to the main data structure
978 void wfd_ug_view_update_peers(void *data)
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;
988 bool is_group_owner = FALSE;
991 wfd_ug_view_free_peers(ugd);
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);
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;
1004 ugd->I_am_group_owner = is_group_owner;
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;
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;
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);
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);
1028 /* display connect peers */
1029 if (no_of_conn_dev > 0) {
1030 if (!ugd->conn_wfd_item) {
1031 _create_connected_dev_genlist(ugd);
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);
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);
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);
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);
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);
1069 ugd->gl_multi_connect_peer_cnt = count;
1072 _create_multi_button_genlist(ugd);
1076 * If GC, no display available peers
1077 * Otherwise, display available peers
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);
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])) {
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);
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]));
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);
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);
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])) {
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);
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);
1138 _create_multi_button_genlist(ugd);
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);
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])) {
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);
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);
1165 _create_about_genlist(ugd);
1167 __WDUG_LOG_FUNC_EXIT__;
1171 * This function let the ug create the main view
1173 * @param[in] data the pointer to the main data structure
1175 void create_wfd_ug_view(void *data)
1177 __WDUG_LOG_FUNC_ENTER__;
1178 struct ug_data *ugd = (struct ug_data *) data;
1179 Elm_Object_Item *navi_item = NULL;
1182 WDUG_LOGE("Incorrect parameter(NULL)");
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);
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);
1195 ugd->genlist = _create_basic_genlist(ugd);
1196 if (ugd->genlist == NULL) {
1197 WDUG_LOGE("Failed to create basic genlist");
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;
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);
1215 __WDUG_LOG_FUNC_EXIT__;