4 * Copyright 2012 Samsung Electronics Co., Ltd
6 * Licensed under the Flora License, Version 1.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.tizenopensource.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 avaliable peer to connect
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_peer_sel(void *data, Evas_Object *obj, void *event_info)
183 __WDUG_LOG_FUNC_ENTER__;
184 assertm_if(NULL == obj, "NULL!!");
185 assertm_if(NULL == data, "NULL!!");
186 device_type_s *peer = (device_type_s *) data;
187 Elm_Object_Item *item = (Elm_Object_Item *)event_info;
191 WDUG_LOGE("Incorrect parameter(NULL)\n");
196 elm_genlist_item_selected_set(item, EINA_FALSE);
199 if (peer->conn_status == PEER_CONN_STATUS_DISCONNECTED || peer->is_group_owner == TRUE) {
200 WDUG_LOGD("Connect with peer [%s]\n", peer->mac_addr);
201 res = wfd_client_connect((const char *) peer->mac_addr);
203 WDUG_LOGE("Failed to send connection request. [%d]\n", res);
207 res = wfd_client_disconnect((const char *)peer->mac_addr);
209 WDUG_LOGE("Failed to send disconnection request. [%d]\n", res);
214 __WDUG_LOG_FUNC_EXIT__;
219 * This function let the ug call it when click busy peer
221 * @param[in] data the pointer to the main data structure
222 * @param[in] obj the pointer to the evas object
223 * @param[in] event_info the pointer to the event information
225 static void _gl_busy_peer_sel(void *data, Evas_Object *obj, void *event_info)
227 __WDUG_LOG_FUNC_ENTER__;
228 struct ug_data *ugd = (struct ug_data *) data;
230 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
231 WDUG_LOGD("Busy device is clicked");
232 wfd_ug_warn_popup(ugd, IDS_WFD_POP_WARN_BUSY_DEVICE, POP_TYPE_BUSY_DEVICE_POPUP);
234 __WDUG_LOG_FUNC_EXIT__;
238 * This function let the ug call it when click about item
240 * @param[in] data the pointer to the main data structure
241 * @param[in] obj the pointer to the evas object
242 * @param[in] event_info the pointer to the event information
244 static void _gl_about_wifi_sel(void *data, Evas_Object *obj, void *event_info)
246 __WDUG_LOG_FUNC_ENTER__;
247 struct ug_data *ugd = (struct ug_data *) data;
249 WDUG_LOGD("About wifi clicked");
250 _wifid_create_about_view(ugd);
251 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
253 __WDUG_LOG_FUNC_EXIT__;
257 * This function let the ug call it when click 'multi connect' button
259 * @param[in] data the pointer to the main data structure
260 * @param[in] obj the pointer to the evas object
261 * @param[in] event_info the pointer to the event information
263 void _wifid_create_multibutton_cb(void *data, Evas_Object * obj, void *event_info)
265 __WDUG_LOG_FUNC_ENTER__;
266 struct ug_data *ugd = (struct ug_data *) data;
267 const char *text_lbl = NULL;
269 text_lbl = elm_object_text_get(ugd->multi_btn);
270 WDUG_LOGD("text_lbl = %s", text_lbl);
272 if (ugd->multi_connect_mode == WFD_MULTI_CONNECT_MODE_IN_PROGRESS) {
273 ugd->multi_connect_mode = WFD_MULTI_CONNECT_MODE_NONE;
274 if (0 == strcmp(_("IDS_WFD_BUTTON_CANCEL"), text_lbl)) {
275 wfd_ug_act_popup(ugd, _("IDS_WFD_POP_CANCEL_CONNECT"), POP_TYPE_DISCONNECT_ALL);
277 WDUG_LOGD("Invalid Case\n");
280 if (0 == strcmp(_("IDS_WFD_BUTTON_MULTI"), text_lbl)) {
281 wfd_create_multiconnect_view(ugd);
282 } else if (0 == strcmp(_("IDS_WFD_BUTTON_CANCEL"), text_lbl)) {
283 wfd_ug_act_popup(ugd, _("IDS_WFD_POP_CANCEL_CONNECT"), POP_TYPE_DISCONNECT_ALL);
284 } else if (0 == strcmp(_("IDS_WFD_BUTTON_DISCONNECT_ALL"), text_lbl)) {
285 wfd_ug_act_popup(ugd, _("IDS_WFD_POP_DISCONNECT"), POP_TYPE_DISCONNECT_ALL);
286 } else if (0 == strcmp(_("IDS_WFD_BUTTON_DISCONNECT"), text_lbl)) {
287 wfd_ug_act_popup(ugd, _("IDS_WFD_POP_DISCONNECT"), POP_TYPE_DISCONNECT);
289 WDUG_LOGD("Invalid Case\n");
293 __WDUG_LOG_FUNC_EXIT__;
297 * This function let the ug change the text of multi button
298 * @return If success, return 0, else return -1
299 * @param[in] data the pointer to the main data structure
301 int _change_multi_button_title(void *data)
303 __WDUG_LOG_FUNC_ENTER__;
304 struct ug_data *ugd = (struct ug_data *) data;
306 if (ugd->multi_button_item == NULL) {
310 wfd_refresh_wifi_direct_state(ugd);
311 if (ugd->wfd_status == WIFI_DIRECT_STATE_CONNECTING) {
312 elm_object_text_set(ugd->multi_btn, _("IDS_WFD_BUTTON_CANCEL"));
313 } else if (ugd->wfd_status > WIFI_DIRECT_STATE_CONNECTING) {
314 if (ugd->gl_connected_peer_cnt > 1) {
315 elm_object_text_set(ugd->multi_btn, _("IDS_WFD_BUTTON_DISCONNECT_ALL"));
317 elm_object_text_set(ugd->multi_btn, _("IDS_WFD_BUTTON_DISCONNECT"));
320 elm_object_text_set(ugd->multi_btn, _("IDS_WFD_BUTTON_MULTI"));
323 evas_object_show(ugd->multi_btn);
324 __WDUG_LOG_FUNC_EXIT__;
330 * This function let the ug update the genlist item
332 * @param[in] obj the pointer to genlist item
334 void wfd_ug_view_refresh_glitem(void *obj)
336 __WDUG_LOG_FUNC_ENTER__;
337 elm_genlist_item_update(obj);
338 __WDUG_LOG_FUNC_EXIT__;
342 * This function let the ug refresh the attributes of button
344 * @param[in] obj the pointer to the button
345 * @param[in] text the pointer to the text of button
346 * @param[in] enable whether the button is disabled
348 void wfd_ug_view_refresh_button(void *obj, const char *text, int enable)
350 __WDUG_LOG_FUNC_ENTER__;
352 if (NULL == obj || NULL == text) {
353 WDUG_LOGE("Incorrect parameter(NULL)\n");
357 WDUG_LOGD("Set the attributes of button: text[%s], enabled[%d]\n", text, enable);
358 elm_object_text_set(obj, text);
359 elm_object_disabled_set(obj, !enable);
361 __WDUG_LOG_FUNC_EXIT__;
365 * This function let the ug know whether current device is connected by me
366 * @return If connected, return TRUE, else return FALSE
367 * @param[in] ugd the pointer to the main data structure
368 * @param[in] dev the pointer to the device
370 static bool __wfd_is_device_connected_with_me(struct ug_data *ugd, device_type_s *dev)
372 __WDUG_LOG_FUNC_ENTER__;
375 for (i = 0; i < ugd->raw_connected_peer_cnt; i++) {
376 if (strncmp(ugd->raw_connected_peers[i].mac_addr,
377 dev->mac_addr, strlen(ugd->raw_connected_peers[i].mac_addr)) == 0) {
382 __WDUG_LOG_FUNC_EXIT__;
387 * This function let the ug know whether current device is connected by other peer
388 * @return If connected, return TRUE, else return FALSE
389 * @param[in] ugd the pointer to the main data structure
390 * @param[in] dev the pointer to the device
392 static bool __wfd_is_device_busy(struct ug_data *ugd, device_type_s *dev)
394 __WDUG_LOG_FUNC_ENTER__;
396 if (ugd->I_am_group_owner == TRUE) {
397 if (dev->is_connected || dev->is_group_owner) {
403 if (dev->is_connected == TRUE && dev->is_group_owner == TRUE) {
407 if (dev->is_connected == TRUE && dev->is_group_owner == FALSE) {
411 if (dev->is_connected == FALSE) {
416 __WDUG_LOG_FUNC_EXIT__;
421 * This function let the ug calculate how many devices are avaliable
423 * @param[in] ugd the pointer to the main data structure
424 * @param[in] dev the pointer to the number of avaliable devices
426 static bool __wfd_is_any_device_available(struct ug_data *ugd, int* no_of_available_dev)
428 __WDUG_LOG_FUNC_ENTER__;
431 for (i = 0; i < ugd->raw_discovered_peer_cnt; i++) {
432 /* Not include the device which is connected with me */
433 if (__wfd_is_device_connected_with_me(ugd, &ugd->raw_discovered_peers[i])) {
436 if (!__wfd_is_device_busy(ugd, &ugd->raw_discovered_peers[i]) &&
437 ugd->raw_discovered_peers[i].conn_status != PEER_CONN_STATUS_FAILED_TO_CONNECT) {
438 (*no_of_available_dev)++;
442 __WDUG_LOG_FUNC_EXIT__;
447 * This function let the ug calculate how many devices are busy
449 * @param[in] ugd the pointer to the main data structure
450 * @param[in] dev the pointer to the number of busy devices
452 static bool __wfd_is_any_device_busy(struct ug_data *ugd, int* no_of_busy_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])) {
467 __WDUG_LOG_FUNC_EXIT__;
472 * This function let the ug calculate how many devices are connected failed
474 * @param[in] ugd the pointer to the main data structure
475 * @param[in] dev the pointer to the number of connected failed devices
477 static bool __wfd_is_any_device_connect_failed(struct ug_data *ugd, int* no_of_connect_failed_dev)
479 __WDUG_LOG_FUNC_ENTER__;
482 for (i = 0; i < ugd->raw_discovered_peer_cnt; i++) {
483 /* Not include the device which is connected with me */
484 if (__wfd_is_device_connected_with_me(ugd, &ugd->raw_discovered_peers[i])) {
487 if (!__wfd_is_device_busy(ugd, &ugd->raw_discovered_peers[i]) &&
488 ugd->raw_discovered_peers[i].conn_status == PEER_CONN_STATUS_FAILED_TO_CONNECT) {
489 (*no_of_connect_failed_dev)++;
494 __WDUG_LOG_FUNC_EXIT__;
499 * This function let the ug get the device status
500 * @return If success, return 0-3(available: 0, connected: 1, busy: 2, connected failed: 3), else return -1
501 * @param[in] ugd the pointer to the main data structure
502 * @param[in] device the pointer to the number of connected failed devices
504 int wfd_get_device_status(void *data, device_type_s *device)
506 __WDUG_LOG_FUNC_ENTER__;
509 struct ug_data *ugd = (struct ug_data *) data;
512 WDUG_LOGE("Incorrect parameter(NULL)");
516 /* check whether it is connected device */
517 ret = __wfd_is_device_connected_with_me(ugd, device);
519 WDUG_LOGD("This is connected device");
524 /* check whether it is busy device */
525 ret = __wfd_is_device_busy(ugd, device);
527 WDUG_LOGD("This is busy device");
532 /* check whether it is available device */
533 if (device->conn_status != PEER_CONN_STATUS_FAILED_TO_CONNECT) {
534 WDUG_LOGD("This is available device");
537 WDUG_LOGD("This is connected failed device");
542 __WDUG_LOG_FUNC_EXIT__;
547 * This function let the ug delete the separator
549 * @param[in] data the pointer to the main data structure
550 * @param[in] obj the pointer to the evas object
552 static void __wfd_separator_del(void *data, Evas_Object *obj)
554 __WDUG_LOG_FUNC_ENTER__;
555 elm_genlist_item_class_free(data);
560 * This function let the ug add a dialogue separator
561 * @return the separator item
562 * @param[in] genlist the pointer to the genlist
563 * @param[in] separator_style the style of separator
565 Elm_Object_Item *wfd_add_dialogue_separator(Evas_Object *genlist, const char *separator_style)
567 __WDUG_LOG_FUNC_ENTER__;
568 assertm_if(NULL == genlist, "NULL!!");
570 static Elm_Genlist_Item_Class *separator_itc;
571 separator_itc = elm_genlist_item_class_new();
572 separator_itc->item_style = separator_style;
573 separator_itc->func.text_get = NULL;
574 separator_itc->func.content_get = NULL;
575 separator_itc->func.state_get = NULL;
576 separator_itc->func.del = __wfd_separator_del;
578 Elm_Object_Item *sep = elm_genlist_item_append(
583 ELM_GENLIST_ITEM_GROUP,
587 assertm_if(NULL == sep, "NULL!!");
589 elm_genlist_item_select_mode_set(sep, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
591 __WDUG_LOG_FUNC_EXIT__;
596 * This function let the ug create the main genlist
597 * @return the main genlist
598 * @param[in] data the pointer to the main data structure
600 static Evas_Object *_create_basic_genlist(void *data)
602 __WDUG_LOG_FUNC_ENTER__;
603 struct ug_data *ugd = (struct ug_data *) data;
604 Evas_Object *genlist;
606 genlist = elm_genlist_add(ugd->naviframe);
607 wfd_add_dialogue_separator(genlist, "dialogue/separator");
608 ugd->head = elm_genlist_item_append(genlist, &head_itc, ugd, NULL,
609 ELM_GENLIST_ITEM_NONE, _gl_header_sel, (void *)ugd);
611 __WDUG_LOG_FUNC_EXIT__;
616 * This function let the ug create the about item to append the genlist
617 * @return the main item
618 * @param[in] data the pointer to the main data structure
620 static Evas_Object *_create_about_genlist(void *data)
622 __WDUG_LOG_FUNC_ENTER__;
623 struct ug_data *ugd = (struct ug_data *) data;
625 ugd->about_wfd_sep_high_item = wfd_add_dialogue_separator(ugd->genlist, "dialogue/separator");
626 ugd->about_wfd_item = elm_genlist_item_append(ugd->genlist, &name_itc, ugd, NULL,
627 ELM_GENLIST_ITEM_NONE, _gl_about_wifi_sel, (void *)ugd);
628 ugd->about_wfd_sep_low_item = wfd_add_dialogue_separator(ugd->genlist, "dialogue/separator/end");
630 __WDUG_LOG_FUNC_EXIT__;
635 * This function let the ug create no device item to append the genlist
636 * @return the main item
637 * @param[in] data the pointer to the main data structure
639 static Evas_Object *_create_no_device_genlist(void *data)
641 __WDUG_LOG_FUNC_ENTER__;
642 struct ug_data *ugd = (struct ug_data *) data;
644 ugd->nodevice_title_item = elm_genlist_item_append(ugd->genlist, &title_itc, (void *)ugd, NULL,
645 ELM_GENLIST_ITEM_NONE, NULL, NULL);
646 ugd->nodevice_item = elm_genlist_item_append(ugd->genlist, &noitem_itc, (void *)ugd, NULL,
647 ELM_GENLIST_ITEM_NONE, NULL, NULL);
648 elm_genlist_item_select_mode_set(ugd->nodevice_item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
650 __WDUG_LOG_FUNC_EXIT__;
655 * This function let the ug create multi connect button
657 * @param[in] data the pointer to the main data structure
659 int _create_multi_button_genlist(void *data)
661 __WDUG_LOG_FUNC_ENTER__;
662 struct ug_data *ugd = (struct ug_data *) data;
664 wfd_refresh_wifi_direct_state(ugd);
666 /* show the button */
667 if (ugd->multi_connect_mode != WFD_MULTI_CONNECT_MODE_NONE) {
668 if (ugd->raw_multi_selected_peer_cnt > 1 ||
669 ugd->gl_connected_peer_cnt > 0 ||
670 ugd->wfd_status == WIFI_DIRECT_STATE_CONNECTING) {
671 ugd->multi_button_sep_item = wfd_add_dialogue_separator(ugd->genlist, "dialogue/separator");
672 ugd->multi_button_item = elm_genlist_item_append(ugd->genlist, &button_itc, ugd, NULL,
673 ELM_GENLIST_ITEM_NONE, NULL, NULL);
676 if (ugd->gl_available_peer_cnt > 1 ||
677 ugd->gl_connected_peer_cnt > 0 ||
678 ugd->wfd_status == WIFI_DIRECT_STATE_CONNECTING) {
679 ugd->multi_button_sep_item = wfd_add_dialogue_separator(ugd->genlist, "dialogue/separator");
680 ugd->multi_button_item = elm_genlist_item_append(ugd->genlist, &button_itc, ugd, NULL,
681 ELM_GENLIST_ITEM_NONE, NULL, NULL);
685 __WDUG_LOG_FUNC_EXIT__;
690 * This function let the ug create busy device list
692 * @param[in] data the pointer to the main data structure
694 int _create_busy_dev_list(void *data)
696 __WDUG_LOG_FUNC_ENTER__;
697 struct ug_data *ugd = (struct ug_data *) data;
699 ugd->busy_wfd_item = elm_genlist_item_append(ugd->genlist, &title_busy_itc, (void *)ugd, NULL,
700 ELM_GENLIST_ITEM_NONE, NULL, NULL);
701 elm_genlist_item_select_mode_set(ugd->busy_wfd_item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
703 __WDUG_LOG_FUNC_EXIT__;
708 * This function let the ug create avaliable device list
710 * @param[in] data the pointer to the main data structure
712 static int _create_available_dev_genlist(void *data)
714 __WDUG_LOG_FUNC_ENTER__;
715 struct ug_data *ugd = (struct ug_data *) data;
717 ugd->avlbl_wfd_item = elm_genlist_item_append(ugd->genlist, &title_itc, (void *)ugd, NULL,
718 ELM_GENLIST_ITEM_NONE, NULL, NULL);
720 __WDUG_LOG_FUNC_EXIT__;
725 * This function let the ug create multi connect device list
727 * @param[in] data the pointer to the main data structure
729 static int _create_multi_connect_dev_genlist(void *data)
731 __WDUG_LOG_FUNC_ENTER__;
732 struct ug_data *ugd = (struct ug_data *) data;
734 ugd->multi_connect_wfd_item = elm_genlist_item_append(ugd->genlist, &title_multi_connect_itc, (void *)ugd, NULL,
735 ELM_GENLIST_ITEM_NONE, NULL, NULL);
737 __WDUG_LOG_FUNC_EXIT__;
742 * This function let the ug create connected device list
744 * @param[in] data the pointer to the main data structure
746 int _create_connected_dev_genlist(void *data)
748 __WDUG_LOG_FUNC_ENTER__;
749 struct ug_data *ugd = (struct ug_data *) data;
751 ugd->conn_wfd_item = elm_genlist_item_append(ugd->genlist, &title_conn_itc, (void *)ugd, NULL,
752 ELM_GENLIST_ITEM_NONE, NULL, NULL);
753 elm_genlist_item_select_mode_set(ugd->conn_wfd_item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
755 __WDUG_LOG_FUNC_EXIT__;
760 * This function let the ug create connected falied device list
762 * @param[in] data the pointer to the main data structure
764 int _create_connected_failed_dev_genlist(void *data)
766 __WDUG_LOG_FUNC_ENTER__;
767 struct ug_data *ugd = (struct ug_data *) data;
769 ugd->conn_failed_wfd_item = elm_genlist_item_append(ugd->genlist, &title_conn_failed_itc, (void *)ugd, NULL,
770 ELM_GENLIST_ITEM_NONE, NULL, NULL);
771 elm_genlist_item_select_mode_set(ugd->conn_failed_wfd_item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
773 __WDUG_LOG_FUNC_EXIT__;
778 * This function let the ug make the display callback for connect failed peers
779 * @return if stop the timer, return ECORE_CALLBACK_CANCEL, else return ECORE_CALLBACK_RENEW
780 * @param[in] data the pointer to the user data
782 static Eina_Bool _connect_failed_peers_display_cb(void *user_data)
786 struct ug_data *ugd = (struct ug_data *) user_data;
789 WDUG_LOGE("NULL parameters.\n");
790 return ECORE_CALLBACK_CANCEL;
793 /* check the timeout, if not timeout, keep the cb */
794 interval = time(NULL) - ugd->last_display_time;
795 if (interval < MAX_DISPLAY_TIME_OUT) {
796 return ECORE_CALLBACK_RENEW;
799 /* start discovery again */
800 res = wifi_direct_start_discovery(FALSE, MAX_SCAN_TIME_OUT);
801 if (res != WIFI_DIRECT_ERROR_NONE) {
802 WDUG_LOGE("Failed to start discovery. [%d]\n", res);
803 ugd->is_re_discover = TRUE;
804 wifi_direct_cancel_discovery();
806 WDUG_LOGD("Discovery is started\n");
807 ugd->is_re_discover = FALSE;
810 return ECORE_CALLBACK_CANCEL;
814 * This function let the ug free the peers
816 * @param[in] data the pointer to the main data structure
818 void wfd_ug_view_free_peers(void *data)
820 __WDUG_LOG_FUNC_ENTER__;
821 struct ug_data *ugd = (struct ug_data *) data;
824 for (i = 0; i < ugd->gl_connected_peer_cnt; i++) {
825 WDUG_LOGD("%dth connected peer = %x is deleted\n", i, ugd->gl_connected_peers[i]);
826 if (ugd->gl_connected_peers[i].gl_item != NULL) {
827 elm_object_item_del(ugd->gl_connected_peers[i].gl_item);
828 ugd->gl_connected_peers[i].gl_item = NULL;
829 WDUG_LOGD("Deleted item\n");
833 ugd->gl_connected_peer_cnt = 0;
835 for (i = 0; i < ugd->gl_connected_failed_peer_cnt; i++) {
836 WDUG_LOGD("%dth connected failed peer = %x is deleted\n", i, ugd->gl_connected_failed_peers[i]);
837 if (ugd->gl_connected_failed_peers[i].gl_item != NULL) {
838 elm_object_item_del(ugd->gl_connected_failed_peers[i].gl_item);
839 ugd->gl_connected_failed_peers[i].gl_item = NULL;
840 WDUG_LOGD("Deleted item\n");
844 ugd->gl_connected_failed_peer_cnt = 0;
846 for (i = 0; i < ugd->gl_available_peer_cnt; i++) {
847 WDUG_LOGD("%dth discovered peer = %x is deleted\n", i, ugd->gl_available_peers[i]);
848 if (ugd->gl_available_peers[i].gl_item != NULL) {
849 elm_object_item_del(ugd->gl_available_peers[i].gl_item);
850 ugd->gl_available_peers[i].gl_item = NULL;
851 WDUG_LOGD("Deleted item\n");
855 ugd->gl_available_peer_cnt = 0;
857 for (i = 0; i < ugd->gl_busy_peer_cnt; i++) {
858 WDUG_LOGD("%dth busy peer = %x is deleted\n", i, ugd->gl_busy_peers[i]);
859 if (ugd->gl_busy_peers[i].gl_item != NULL) {
860 elm_object_item_del(ugd->gl_busy_peers[i].gl_item);
861 ugd->gl_busy_peers[i].gl_item = NULL;
862 WDUG_LOGD("Deleted item\n");
866 ugd->gl_busy_peer_cnt = 0;
868 for (i = 0; i < ugd->gl_multi_connect_peer_cnt; i++) {
869 WDUG_LOGD("%dth multi connect peer = %x is deleted\n", i, ugd->gl_multi_connect_peers[i]);
870 if (ugd->gl_multi_connect_peers[i].gl_item != NULL) {
871 elm_object_item_del(ugd->gl_multi_connect_peers[i].gl_item);
872 ugd->gl_multi_connect_peers[i].gl_item = NULL;
873 WDUG_LOGD("Deleted item\n");
877 ugd->gl_multi_connect_peer_cnt = 0;
879 if (ugd->nodevice_title_item != NULL) {
880 elm_object_item_del(ugd->nodevice_title_item);
881 ugd->nodevice_title_item = NULL;
884 if (ugd->nodevice_item != NULL) {
885 elm_object_item_del(ugd->nodevice_item);
886 ugd->nodevice_item = NULL;
889 if (ugd->about_wfd_item != NULL) {
890 elm_object_item_del(ugd->about_wfd_item);
891 ugd->about_wfd_item = NULL;
894 if (ugd->about_wfd_sep_high_item != NULL) {
895 elm_object_item_del(ugd->about_wfd_sep_high_item);
896 ugd->about_wfd_sep_high_item = NULL;
899 if (ugd->about_wfd_sep_low_item != NULL) {
900 elm_object_item_del(ugd->about_wfd_sep_low_item);
901 ugd->about_wfd_sep_low_item = NULL;
904 if (ugd->conn_wfd_item != NULL) {
905 elm_object_item_del(ugd->conn_wfd_item);
906 ugd->conn_wfd_item = NULL;
909 if (ugd->conn_failed_wfd_item != NULL) {
910 elm_object_item_del(ugd->conn_failed_wfd_item);
911 ugd->conn_failed_wfd_item = NULL;
914 if (ugd->display_timer != NULL) {
915 ecore_timer_del(ugd->display_timer);
916 ugd->display_timer = NULL;
919 if (ugd->multi_connect_wfd_item != NULL) {
920 elm_object_item_del(ugd->multi_connect_wfd_item);
921 ugd->multi_connect_wfd_item = NULL;
924 if (ugd->avlbl_wfd_item != NULL) {
925 elm_object_item_del(ugd->avlbl_wfd_item);
926 ugd->avlbl_wfd_item = NULL;
929 if (ugd->busy_wfd_item != NULL) {
930 elm_object_item_del(ugd->busy_wfd_item);
931 ugd->busy_wfd_item = NULL;
934 if (ugd->multi_button_item != NULL) {
935 elm_object_item_del(ugd->multi_button_item);
936 ugd->multi_button_item = NULL;
939 if (ugd->multi_button_sep_item != NULL) {
940 elm_object_item_del(ugd->multi_button_sep_item);
941 ugd->multi_button_sep_item = NULL;
944 __WDUG_LOG_FUNC_EXIT__;
948 * This function let the ug update the peers
950 * @param[in] data the pointer to the main data structure
952 void wfd_ug_view_update_peers(void *data)
954 __WDUG_LOG_FUNC_ENTER__;
955 struct ug_data *ugd = (struct ug_data *) data;
956 int no_of_busy_dev = 0;
957 int no_of_available_dev = 0;
958 int no_of_conn_dev = 0;
959 int no_of_conn_failed_dev = 0;
962 bool is_group_owner = FALSE;
965 wfd_ug_view_free_peers(ugd);
967 if (ugd->wfd_status == WIFI_DIRECT_STATE_DEACTIVATED) {
968 WDUG_LOGD("Device is deactivated, no need to update UI.");
969 _create_about_genlist(ugd);
973 res = wifi_direct_is_group_owner(&is_group_owner);
974 if (res != WIFI_DIRECT_ERROR_NONE) {
975 WDUG_LOGD("Fail to get group_owner_state. ret=[%d]", res);
976 ugd->I_am_group_owner = FALSE;
978 ugd->I_am_group_owner = is_group_owner;
981 __wfd_is_any_device_busy(ugd, &no_of_busy_dev);
982 __wfd_is_any_device_available(ugd, &no_of_available_dev);
983 __wfd_is_any_device_connect_failed(ugd, &no_of_conn_failed_dev);
984 no_of_conn_dev = ugd->raw_connected_peer_cnt;
986 ugd->gl_available_peer_cnt = no_of_available_dev;
987 ugd->gl_connected_peer_cnt = no_of_conn_dev;
988 ugd->gl_connected_failed_peer_cnt = no_of_conn_failed_dev;
989 ugd->gl_busy_peer_cnt = no_of_busy_dev;
991 WDUG_LOGD("conn_dev=[%d], conn_failed_dev=[%d], avail_dev=[%d], busy_dev=[%d], GO=[%d]\n",
992 no_of_conn_dev, no_of_conn_failed_dev, no_of_available_dev, no_of_busy_dev, is_group_owner);
994 if (no_of_conn_dev == 0 && no_of_conn_failed_dev == 0 &&
995 no_of_available_dev == 0 && no_of_busy_dev == 0) {
996 WDUG_LOGE("There are No peers\n");
997 _create_no_device_genlist(ugd);
998 _create_about_genlist(ugd);
1002 /* display connect peers */
1003 if (no_of_conn_dev > 0) {
1004 if (!ugd->conn_wfd_item) {
1005 _create_connected_dev_genlist(ugd);
1009 for (i = 0; i < ugd->raw_connected_peer_cnt; i++) {
1010 if (ugd->gl_connected_peers[count].gl_item) {
1011 elm_object_item_del(ugd->gl_connected_peers[count].gl_item);
1014 memcpy(&ugd->gl_connected_peers[count], &ugd->raw_connected_peers[i], sizeof(device_type_s));
1015 ugd->gl_connected_peers[count].gl_item = elm_genlist_item_append(ugd->genlist, &peer_conn_itc,
1016 (void *)&(ugd->gl_connected_peers[i]), NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
1017 elm_genlist_item_select_mode_set(ugd->gl_connected_peers[count].gl_item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1022 if (ugd->multi_connect_mode != WFD_MULTI_CONNECT_MODE_NONE) {
1023 if (ugd->raw_multi_selected_peer_cnt > 0) {
1024 if (ugd->raw_connected_peer_cnt < ugd->raw_multi_selected_peer_cnt &&
1025 ugd->multi_connect_wfd_item == NULL) {
1026 _create_multi_connect_dev_genlist(ugd);
1030 for (i = 0; i < ugd->raw_multi_selected_peer_cnt; i++) {
1031 if (ugd->raw_multi_selected_peers[i].conn_status != PEER_CONN_STATUS_CONNECTED) {
1032 if (ugd->gl_multi_connect_peers[count].gl_item) {
1033 elm_object_item_del(ugd->gl_multi_connect_peers[count].gl_item);
1036 memcpy(&ugd->gl_multi_connect_peers[count], &ugd->raw_multi_selected_peers[i], sizeof(device_type_s));
1037 ugd->gl_multi_connect_peers[count].gl_item = elm_genlist_item_append(ugd->genlist, &peer_itc,
1038 (void *) &(ugd->gl_multi_connect_peers[count]), NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
1043 ugd->gl_multi_connect_peer_cnt = count;
1046 _create_multi_button_genlist(ugd);
1050 * If GC, no display available peers
1051 * Otherwise, display available peers
1053 if (no_of_available_dev > 0 && (no_of_conn_dev == 0 || is_group_owner == TRUE)) {
1054 if (ugd->avlbl_wfd_item == NULL) {
1055 _create_available_dev_genlist(ugd);
1059 for (i = 0; i < ugd->raw_discovered_peer_cnt; i++) {
1060 /* Not include the device which is connected with me */
1061 if (__wfd_is_device_connected_with_me(ugd, &ugd->raw_discovered_peers[i])) {
1064 if (!__wfd_is_device_busy(ugd, &ugd->raw_discovered_peers[i]) &&
1065 ugd->raw_discovered_peers[i].conn_status != PEER_CONN_STATUS_FAILED_TO_CONNECT) {
1066 if (ugd->gl_available_peers[count].gl_item) {
1067 elm_object_item_del(ugd->gl_available_peers[count].gl_item);
1070 memcpy(&ugd->gl_available_peers[count], &ugd->raw_discovered_peers[i], sizeof(device_type_s));
1071 ugd->gl_available_peers[count].gl_item = elm_genlist_item_append(ugd->genlist, &peer_itc,
1072 (void *)&(ugd->gl_available_peers[count]), NULL, ELM_GENLIST_ITEM_NONE, _gl_peer_sel,
1073 (void *)&(ugd->gl_available_peers[count]));
1079 /* display connect failed peers */
1080 if (no_of_conn_failed_dev > 0) {
1081 if (!ugd->conn_failed_wfd_item) {
1082 _create_connected_failed_dev_genlist(ugd);
1085 /* add timer for disappearing failed peers after N secs */
1086 if (NULL == ugd->display_timer) {
1087 ugd->last_display_time = time(NULL);
1088 ugd->display_timer = ecore_timer_add(5.0, (Ecore_Task_Cb)_connect_failed_peers_display_cb, ugd);
1092 for (i = 0; i < ugd->raw_discovered_peer_cnt; i++) {
1093 /* Not include the device which is connected with me */
1094 if (__wfd_is_device_connected_with_me(ugd, &ugd->raw_discovered_peers[i])) {
1097 if (!__wfd_is_device_busy(ugd, &ugd->raw_discovered_peers[i]) &&
1098 ugd->raw_discovered_peers[i].conn_status == PEER_CONN_STATUS_FAILED_TO_CONNECT) {
1099 if (ugd->gl_connected_failed_peers[count].gl_item) {
1100 elm_object_item_del(ugd->gl_connected_failed_peers[count].gl_item);
1103 memcpy(&ugd->gl_connected_failed_peers[count], &ugd->raw_discovered_peers[i], sizeof(device_type_s));
1104 ugd->gl_connected_failed_peers[count].gl_item = elm_genlist_item_append(ugd->genlist, &peer_conn_failed_itc,
1105 (void *)&(ugd->gl_connected_failed_peers[count]), NULL, ELM_GENLIST_ITEM_NONE, NULL, ugd);
1106 elm_genlist_item_select_mode_set(ugd->gl_connected_failed_peers[count].gl_item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1112 _create_multi_button_genlist(ugd);
1114 /* If connected, not display busy device */
1115 if (no_of_conn_dev == 0 && no_of_busy_dev > 0) {
1116 if (ugd->busy_wfd_item == NULL) {
1117 _create_busy_dev_list(ugd);
1121 for (i = 0; i < ugd->raw_discovered_peer_cnt; i++) {
1122 /* Not include the device which is connected with me */
1123 if (__wfd_is_device_connected_with_me(ugd, &ugd->raw_discovered_peers[i])) {
1126 if (__wfd_is_device_busy(ugd, &ugd->raw_discovered_peers[i]) == TRUE) {
1127 if (ugd->gl_busy_peers[count].gl_item) {
1128 elm_object_item_del(ugd->gl_busy_peers[count].gl_item);
1131 memcpy(&ugd->gl_busy_peers[count], &ugd->raw_discovered_peers[i], sizeof(device_type_s));
1132 ugd->gl_busy_peers[count].gl_item = elm_genlist_item_append(ugd->genlist, &peer_busy_itc,
1133 (void *)&(ugd->gl_busy_peers[count]), NULL, ELM_GENLIST_ITEM_NONE, _gl_busy_peer_sel, ugd);
1139 _create_about_genlist(ugd);
1141 __WDUG_LOG_FUNC_EXIT__;
1145 * This function let the ug create the main view
1147 * @param[in] data the pointer to the main data structure
1149 void create_wfd_ug_view(void *data)
1151 __WDUG_LOG_FUNC_ENTER__;
1152 struct ug_data *ugd = (struct ug_data *) data;
1153 Elm_Object_Item *navi_item = NULL;
1156 WDUG_LOGE("Incorrect parameter(NULL)");
1160 ugd->naviframe = elm_naviframe_add(ugd->base);
1161 elm_object_part_content_set(ugd->base, "elm.swallow.content", ugd->naviframe);
1162 evas_object_show(ugd->naviframe);
1164 ugd->back_btn = elm_button_add(ugd->naviframe);
1165 elm_object_style_set(ugd->back_btn, "naviframe/back_btn/default");
1166 evas_object_smart_callback_add(ugd->back_btn, "clicked", _back_btn_cb, (void *)ugd);
1167 elm_object_focus_allow_set(ugd->back_btn, EINA_FALSE);
1169 ugd->genlist = _create_basic_genlist(ugd);
1170 if (ugd->genlist == NULL) {
1171 WDUG_LOGE("Failed to create basic genlist");
1175 evas_object_show(ugd->genlist);
1176 wfd_refresh_wifi_direct_state(ugd);
1177 if (ugd->wfd_status > WIFI_DIRECT_STATE_ACTIVATING) {
1178 ugd->wfd_onoff = TRUE;
1181 navi_item = elm_naviframe_item_push(ugd->naviframe, _("IDS_WFD_HEADER_WIFI_DIRECT"), ugd->back_btn, NULL, ugd->genlist, NULL);
1182 /* create scan button */
1183 ugd->scan_btn = elm_button_add(ugd->naviframe);
1184 elm_object_style_set(ugd->scan_btn, "naviframe/toolbar/default");
1185 elm_object_text_set(ugd->scan_btn, _("IDS_WFD_BUTTON_SCAN"));
1186 evas_object_smart_callback_add(ugd->scan_btn, "clicked", _scan_btn_cb, (void *)ugd);
1187 elm_object_item_part_content_set(navi_item, "toolbar_button1", ugd->scan_btn);
1189 __WDUG_LOG_FUNC_EXIT__;