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>
27 #include <efl_assist.h>
29 #include <ui-gadget-module.h>
30 #include <wifi-direct.h>
33 #include "wfd_ug_view.h"
34 #include "wfd_client.h"
37 * This function let the ug call it when click 'back' button
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
43 Eina_Bool _back_btn_cb(void *data, Elm_Object_Item *it)
45 __WDUG_LOG_FUNC_ENTER__;
46 struct ug_data *ugd = (struct ug_data *) data;
49 WDUG_LOGE("The param is NULL\n");
53 wfd_ug_view_free_peers(ugd);
56 service_h service = NULL;
57 ret = service_create(&service);
59 WDUG_LOGE("Failed to create service");
63 wfd_refresh_wifi_direct_state(ugd);
64 if (ugd->wfd_status > WIFI_DIRECT_STATE_CONNECTING) {
65 service_add_extra_data(service, "Connection", "TRUE");
67 service_add_extra_data(service, "Connection", "FALSE");
70 ug_send_result(ugd->ug, service);
71 service_destroy(service);
72 ug_destroy_me(ugd->ug);
74 __WDUG_LOG_FUNC_EXIT__;
79 * This function let the ug call it when click 'scan' button
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
85 void _scan_btn_cb(void *data, Evas_Object *obj, void *event_info)
87 __WDUG_LOG_FUNC_ENTER__;
89 struct ug_data *ugd = (struct ug_data *) data;
91 char *btn_text = NULL;
94 WDUG_LOGE("Incorrect parameter(NULL)\n");
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");
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);
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__;
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();
122 WDUG_LOGD("Discovery is started\n");
123 ugd->is_re_discover = FALSE;
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);
132 ugd->is_re_discover = FALSE;
133 wifi_direct_cancel_discovery();
136 __WDUG_LOG_FUNC_EXIT__;
141 * This function let the ug call it when click header
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
147 static void _gl_header_sel(void *data, Evas_Object *obj, void *event_info)
149 __WDUG_LOG_FUNC_ENTER__;
151 WDUG_LOGE("Incorrect parameter(NULL)\n");
152 __WDUG_LOG_FUNC_EXIT__;
156 struct ug_data *ugd = (struct ug_data *) data;
157 Elm_Object_Item *item = (Elm_Object_Item *)event_info;
160 elm_genlist_item_selected_set(item, EINA_FALSE);
163 /* turn on/off wfd */
164 if (!ugd->wfd_onoff) {
165 WDUG_LOGD("wifi-direct switch on\n");
166 wfd_client_switch_on(ugd);
168 WDUG_LOGD("wifi-direct switch off\n");
169 wfd_client_switch_off(ugd);
172 __WDUG_LOG_FUNC_EXIT__;
176 * This function let the ug call it when click genlist item
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
182 static void _gl_item_sel(void *data, Evas_Object *obj, void *event_info)
184 __WDUG_LOG_FUNC_ENTER__;
186 WDUG_LOGE("Incorrect parameter(NULL)\n");
187 __WDUG_LOG_FUNC_EXIT__;
191 struct ug_data *ugd = (struct ug_data *) data;
192 Elm_Object_Item *item = (Elm_Object_Item *)event_info;
195 elm_genlist_item_selected_set(item, EINA_FALSE);
198 __WDUG_LOG_FUNC_EXIT__;
202 * This function let the ug call it when click avaliable peer to connect
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
208 static void _gl_peer_sel(void *data, Evas_Object *obj, void *event_info)
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;
218 WDUG_LOGE("Incorrect parameter(NULL)\n");
223 elm_genlist_item_selected_set(item, EINA_FALSE);
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);
230 WDUG_LOGE("Failed to send connection request. [%d]\n", res);
234 res = wfd_client_disconnect((const char *)peer->mac_addr);
236 WDUG_LOGE("Failed to send disconnection request. [%d]\n", res);
241 __WDUG_LOG_FUNC_EXIT__;
246 * This function let the ug call it when click busy peer
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
252 static void _gl_busy_peer_sel(void *data, Evas_Object *obj, void *event_info)
254 __WDUG_LOG_FUNC_ENTER__;
255 struct ug_data *ugd = (struct ug_data *) data;
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);
261 __WDUG_LOG_FUNC_EXIT__;
265 * This function let the ug call it when click about item
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
271 static void _gl_about_wifi_sel(void *data, Evas_Object *obj, void *event_info)
273 __WDUG_LOG_FUNC_ENTER__;
274 struct ug_data *ugd = (struct ug_data *) data;
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);
280 __WDUG_LOG_FUNC_EXIT__;
284 * This function let the ug call it when click 'multi connect' button
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
290 void _wifid_create_multibutton_cb(void *data, Evas_Object * obj, void *event_info)
292 __WDUG_LOG_FUNC_ENTER__;
293 struct ug_data *ugd = (struct ug_data *) data;
294 const char *text_lbl = NULL;
296 text_lbl = elm_object_text_get(ugd->multi_btn);
297 WDUG_LOGD("text_lbl = %s", text_lbl);
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);
304 WDUG_LOGD("Invalid Case\n");
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);
316 WDUG_LOGD("Invalid Case\n");
320 __WDUG_LOG_FUNC_EXIT__;
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
328 int _change_multi_button_title(void *data)
330 __WDUG_LOG_FUNC_ENTER__;
331 struct ug_data *ugd = (struct ug_data *) data;
333 if (ugd->multi_button_item == NULL) {
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"));
344 elm_object_text_set(ugd->multi_btn, _("IDS_WFD_BUTTON_DISCONNECT"));
347 elm_object_text_set(ugd->multi_btn, _("IDS_WFD_BUTTON_MULTI"));
350 evas_object_show(ugd->multi_btn);
351 __WDUG_LOG_FUNC_EXIT__;
357 * This function let the ug update the genlist item
359 * @param[in] obj the pointer to genlist item
361 void wfd_ug_view_refresh_glitem(void *obj)
363 __WDUG_LOG_FUNC_ENTER__;
364 elm_genlist_item_update(obj);
365 __WDUG_LOG_FUNC_EXIT__;
369 * This function let the ug refresh the attributes of button
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
375 void wfd_ug_view_refresh_button(void *obj, const char *text, int enable)
377 __WDUG_LOG_FUNC_ENTER__;
379 if (NULL == obj || NULL == text) {
380 WDUG_LOGE("Incorrect parameter(NULL)\n");
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);
388 __WDUG_LOG_FUNC_EXIT__;
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
397 static bool __wfd_is_device_connected_with_me(struct ug_data *ugd, device_type_s *dev)
399 __WDUG_LOG_FUNC_ENTER__;
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) {
409 __WDUG_LOG_FUNC_EXIT__;
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
419 static bool __wfd_is_device_busy(struct ug_data *ugd, device_type_s *dev)
421 __WDUG_LOG_FUNC_ENTER__;
423 if (ugd->I_am_group_owner == TRUE) {
424 if (dev->is_connected || dev->is_group_owner) {
430 if (dev->is_connected == TRUE && dev->is_group_owner == TRUE) {
434 if (dev->is_connected == TRUE && dev->is_group_owner == FALSE) {
438 if (dev->is_connected == FALSE) {
443 __WDUG_LOG_FUNC_EXIT__;
448 * This function let the ug calculate how many devices are avaliable
450 * @param[in] ugd the pointer to the main data structure
451 * @param[in] dev the pointer to the number of avaliable devices
453 static bool __wfd_is_any_device_available(struct ug_data *ugd, int* no_of_available_dev)
455 __WDUG_LOG_FUNC_ENTER__;
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])) {
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)++;
469 __WDUG_LOG_FUNC_EXIT__;
474 * This function let the ug calculate how many devices are busy
476 * @param[in] ugd the pointer to the main data structure
477 * @param[in] dev the pointer to the number of busy devices
479 static bool __wfd_is_any_device_busy(struct ug_data *ugd, int* no_of_busy_dev)
481 __WDUG_LOG_FUNC_ENTER__;
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])) {
489 if (__wfd_is_device_busy(ugd, &ugd->raw_discovered_peers[i])) {
494 __WDUG_LOG_FUNC_EXIT__;
499 * This function let the ug calculate how many devices are connected failed
501 * @param[in] ugd the pointer to the main data structure
502 * @param[in] dev the pointer to the number of connected failed devices
504 static bool __wfd_is_any_device_connect_failed(struct ug_data *ugd, int* no_of_connect_failed_dev)
506 __WDUG_LOG_FUNC_ENTER__;
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])) {
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)++;
521 __WDUG_LOG_FUNC_EXIT__;
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
531 int wfd_get_device_status(void *data, device_type_s *device)
533 __WDUG_LOG_FUNC_ENTER__;
536 struct ug_data *ugd = (struct ug_data *) data;
539 WDUG_LOGE("Incorrect parameter(NULL)");
543 /* check whether it is connected device */
544 ret = __wfd_is_device_connected_with_me(ugd, device);
546 WDUG_LOGD("This is connected device");
551 /* check whether it is busy device */
552 ret = __wfd_is_device_busy(ugd, device);
554 WDUG_LOGD("This is busy device");
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");
564 WDUG_LOGD("This is connected failed device");
569 __WDUG_LOG_FUNC_EXIT__;
574 * This function let the ug delete the separator
576 * @param[in] data the pointer to the main data structure
577 * @param[in] obj the pointer to the evas object
579 static void __wfd_separator_del(void *data, Evas_Object *obj)
581 __WDUG_LOG_FUNC_ENTER__;
582 elm_genlist_item_class_free(data);
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
592 Elm_Object_Item *wfd_add_dialogue_separator(Evas_Object *genlist, const char *separator_style)
594 __WDUG_LOG_FUNC_ENTER__;
595 assertm_if(NULL == genlist, "NULL!!");
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;
605 Elm_Object_Item *sep = elm_genlist_item_append(
610 ELM_GENLIST_ITEM_GROUP,
614 assertm_if(NULL == sep, "NULL!!");
616 elm_genlist_item_select_mode_set(sep, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
618 __WDUG_LOG_FUNC_EXIT__;
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
627 static Evas_Object *_create_basic_genlist(void *data)
629 __WDUG_LOG_FUNC_ENTER__;
630 struct ug_data *ugd = (struct ug_data *) data;
631 Evas_Object *genlist;
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);
638 __WDUG_LOG_FUNC_EXIT__;
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
647 static Evas_Object *_create_about_genlist(void *data)
649 __WDUG_LOG_FUNC_ENTER__;
650 struct ug_data *ugd = (struct ug_data *) data;
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");
657 __WDUG_LOG_FUNC_EXIT__;
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
666 static Evas_Object *_create_no_device_genlist(void *data)
668 __WDUG_LOG_FUNC_ENTER__;
669 struct ug_data *ugd = (struct ug_data *) data;
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);
677 __WDUG_LOG_FUNC_EXIT__;
682 * This function let the ug create multi connect button
684 * @param[in] data the pointer to the main data structure
686 int _create_multi_button_genlist(void *data)
688 __WDUG_LOG_FUNC_ENTER__;
689 struct ug_data *ugd = (struct ug_data *) data;
691 wfd_refresh_wifi_direct_state(ugd);
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);
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);
712 __WDUG_LOG_FUNC_EXIT__;
717 * This function let the ug create busy device list
719 * @param[in] data the pointer to the main data structure
721 int _create_busy_dev_list(void *data)
723 __WDUG_LOG_FUNC_ENTER__;
724 struct ug_data *ugd = (struct ug_data *) data;
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);
730 __WDUG_LOG_FUNC_EXIT__;
735 * This function let the ug create avaliable device list
737 * @param[in] data the pointer to the main data structure
739 static int _create_available_dev_genlist(void *data)
741 __WDUG_LOG_FUNC_ENTER__;
742 struct ug_data *ugd = (struct ug_data *) data;
744 ugd->avlbl_wfd_item = elm_genlist_item_append(ugd->genlist, &title_itc, (void *)ugd, NULL,
745 ELM_GENLIST_ITEM_NONE, NULL, NULL);
747 __WDUG_LOG_FUNC_EXIT__;
752 * This function let the ug create multi connect device list
754 * @param[in] data the pointer to the main data structure
756 static int _create_multi_connect_dev_genlist(void *data)
758 __WDUG_LOG_FUNC_ENTER__;
759 struct ug_data *ugd = (struct ug_data *) data;
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);
764 __WDUG_LOG_FUNC_EXIT__;
769 * This function let the ug create connected device list
771 * @param[in] data the pointer to the main data structure
773 int _create_connected_dev_genlist(void *data)
775 __WDUG_LOG_FUNC_ENTER__;
776 struct ug_data *ugd = (struct ug_data *) data;
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);
782 __WDUG_LOG_FUNC_EXIT__;
787 * This function let the ug create connected falied device list
789 * @param[in] data the pointer to the main data structure
791 int _create_connected_failed_dev_genlist(void *data)
793 __WDUG_LOG_FUNC_ENTER__;
794 struct ug_data *ugd = (struct ug_data *) data;
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);
800 __WDUG_LOG_FUNC_EXIT__;
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
809 static Eina_Bool _connect_failed_peers_display_cb(void *user_data)
813 struct ug_data *ugd = (struct ug_data *) user_data;
816 WDUG_LOGE("NULL parameters.\n");
817 return ECORE_CALLBACK_CANCEL;
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;
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();
833 WDUG_LOGD("Discovery is started\n");
834 ugd->is_re_discover = FALSE;
837 return ECORE_CALLBACK_CANCEL;
841 * This function let the ug free the peers
843 * @param[in] data the pointer to the main data structure
845 void wfd_ug_view_free_peers(void *data)
847 __WDUG_LOG_FUNC_ENTER__;
848 struct ug_data *ugd = (struct ug_data *) data;
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");
860 ugd->gl_connected_peer_cnt = 0;
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");
871 ugd->gl_connected_failed_peer_cnt = 0;
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");
882 ugd->gl_available_peer_cnt = 0;
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");
893 ugd->gl_busy_peer_cnt = 0;
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");
904 ugd->gl_multi_connect_peer_cnt = 0;
906 if (ugd->nodevice_title_item != NULL) {
907 elm_object_item_del(ugd->nodevice_title_item);
908 ugd->nodevice_title_item = NULL;
911 if (ugd->nodevice_item != NULL) {
912 elm_object_item_del(ugd->nodevice_item);
913 ugd->nodevice_item = NULL;
916 if (ugd->about_wfd_item != NULL) {
917 elm_object_item_del(ugd->about_wfd_item);
918 ugd->about_wfd_item = NULL;
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;
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;
931 if (ugd->conn_wfd_item != NULL) {
932 elm_object_item_del(ugd->conn_wfd_item);
933 ugd->conn_wfd_item = NULL;
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;
941 if (ugd->display_timer != NULL) {
942 ecore_timer_del(ugd->display_timer);
943 ugd->display_timer = NULL;
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;
951 if (ugd->avlbl_wfd_item != NULL) {
952 elm_object_item_del(ugd->avlbl_wfd_item);
953 ugd->avlbl_wfd_item = NULL;
956 if (ugd->busy_wfd_item != NULL) {
957 elm_object_item_del(ugd->busy_wfd_item);
958 ugd->busy_wfd_item = NULL;
961 if (ugd->multi_button_item != NULL) {
962 elm_object_item_del(ugd->multi_button_item);
963 ugd->multi_button_item = NULL;
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;
971 __WDUG_LOG_FUNC_EXIT__;
975 * This function let the ug update the peers
977 * @param[in] data the pointer to the main data structure
979 void wfd_ug_view_update_peers(void *data)
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;
989 bool is_group_owner = FALSE;
992 wfd_ug_view_free_peers(ugd);
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);
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;
1005 ugd->I_am_group_owner = is_group_owner;
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;
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;
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);
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);
1029 /* display connect peers */
1030 if (no_of_conn_dev > 0) {
1031 if (!ugd->conn_wfd_item) {
1032 _create_connected_dev_genlist(ugd);
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);
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);
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);
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);
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);
1070 ugd->gl_multi_connect_peer_cnt = count;
1073 _create_multi_button_genlist(ugd);
1077 * If GC, no display available peers
1078 * Otherwise, display available peers
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);
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])) {
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);
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]));
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);
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);
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])) {
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);
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);
1139 _create_multi_button_genlist(ugd);
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);
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])) {
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);
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);
1166 _create_about_genlist(ugd);
1168 __WDUG_LOG_FUNC_EXIT__;
1172 * This function let the ug create the main view
1174 * @param[in] data the pointer to the main data structure
1176 void create_wfd_ug_view(void *data)
1178 __WDUG_LOG_FUNC_ENTER__;
1179 struct ug_data *ugd = (struct ug_data *) data;
1180 Elm_Object_Item *navi_item = NULL;
1183 WDUG_LOGE("Incorrect parameter(NULL)");
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);
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);
1198 ugd->genlist = _create_basic_genlist(ugd);
1199 if (ugd->genlist == NULL) {
1200 WDUG_LOGE("Failed to create basic genlist");
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;
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);
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);
1222 __WDUG_LOG_FUNC_EXIT__;