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.
25 #include <Elementary.h>
27 #include <ui-gadget-module.h>
28 #include <wifi-direct.h>
31 #include "wfd_ug_view.h"
32 #include "wfd_client.h"
34 Elm_Gen_Item_Class sep_itc;
35 Elm_Gen_Item_Class sep_itc_end;
36 Elm_Gen_Item_Class head_itc;
37 Elm_Gen_Item_Class name_itc;
38 Elm_Gen_Item_Class title_itc;
39 Elm_Gen_Item_Class peer_itc;
40 Elm_Gen_Item_Class noitem_itc;
41 Elm_Gen_Item_Class help_itc;
42 Elm_Gen_Item_Class button_itc;
44 Elm_Gen_Item_Class title_conn_itc;
45 Elm_Gen_Item_Class peer_conn_itc;
47 Elm_Gen_Item_Class title_busy_itc;
48 Elm_Gen_Item_Class peer_busy_itc;
50 Elm_Gen_Item_Class title_multi_connect_itc;
51 Elm_Gen_Item_Class peer_multi_connect_itc;
53 Elm_Gen_Item_Class title_conn_failed_itc;
54 Elm_Gen_Item_Class peer_conn_failed_itc;
57 static char *_gl_header_label_get(void *data, Evas_Object * obj, const char *part)
60 struct ug_data *ugd = (struct ug_data*) data;
61 DBG(LOG_VERBOSE, "%s", part);
65 DBG(LOG_ERROR, "Incorrect parameter(NULL)\n");
69 if(!strcmp(part, "elm.text.1"))
71 DBG(LOG_VERBOSE, "Current text mode [%d]\n", ugd->head_text_mode);
72 switch(ugd->head_text_mode)
74 case HEAD_TEXT_TYPE_DIRECT:
75 case HEAD_TEXT_TYPE_ACTIVATED:
76 case HEAD_TEXT_TYPE_SCANING:
77 return strdup(dgettext("sys_string", "IDS_COM_OPT1_WI_FI_DIRECT"));
79 case HEAD_TEXT_TYPE_DEACTIVATING:
80 return strdup(_("IDS_WFD_BODY_DEACTIVATING")); // "Deactivating Wi-Fi Direct..."
82 case HEAD_TEXT_TYPE_ACTIVATING:
83 return strdup(_("IDS_WFD_BODY_ACTIVATING")); //"Activating Wi-Fi Direct..."
89 else if(!strcmp(part, "elm.text.1"))
91 return strdup(dgettext("sys_string", "IDS_COM_OPT1_WI_FI_DIRECT"));
92 } else if(!strcmp(part, "elm.text.2"))
94 return strdup(ugd->dev_name);
101 static Evas_Object *_gl_header_icon_get(void *data, Evas_Object * obj, const char *part)
104 struct ug_data *ugd = (struct ug_data*) data;
105 Evas_Object *onoff = NULL;
109 DBG(LOG_ERROR, "Incorrect parameter(NULL)\n");
113 if(ugd->head_text_mode == HEAD_TEXT_TYPE_ACTIVATING ||
114 ugd->head_text_mode == HEAD_TEXT_TYPE_DEACTIVATING)
117 DBG(LOG_VERBOSE, "%s", part);
118 onoff = elm_check_add(obj);
119 elm_object_style_set(onoff, "on&off");
120 elm_check_state_set(onoff, ugd->wfd_onoff);
121 evas_object_smart_callback_add(onoff, "changed", _wfd_onoff_btn_cb, ugd);
122 evas_object_show(onoff);
130 static char *_gl_name_label_get(void *data, Evas_Object *obj, const char *part)
133 struct ug_data *ugd = (struct ug_data*) data;
137 DBG(LOG_ERROR, "Incorrect parameter(NULL)\n");
141 DBG(LOG_VERBOSE, "%s", part);
143 if(!strcmp(part, "elm.text"))
145 return strdup(IDS_WFD_TITLE_ABOUT_WIFI); // "Device name"
147 else if(!strcmp(part, "elm.text.2"))
149 return strdup(ugd->dev_name);
158 static char *_gl_title_label_get(void *data, Evas_Object *obj,
162 struct ug_data *ugd = (struct ug_data*) data;
166 DBG(LOG_ERROR, "Incorrect parameter(NULL)\n");
170 if (!strcmp(part, "elm.text"))
172 if (ugd->multiconn_view_genlist != NULL)
174 // It's called at Multi connect view...
175 if(ugd->gl_available_dev_cnt_at_multiconn_view > 0)
176 return strdup(_("IDS_WFD_BODY_AVAILABLE_DEVICES")); // "Available devices"
178 return strdup(_("IDS_WFD_BODY_WIFI_DIRECT_DEVICES")); // "Wi-Fi Direct devices"
182 // It's called at Main View
183 if(ugd->gl_available_peer_cnt > 0)
184 return strdup(_("IDS_WFD_BODY_AVAILABLE_DEVICES")); // "Available devices"
186 return strdup(_("IDS_WFD_BODY_WIFI_DIRECT_DEVICES")); // "Wi-Fi Direct devices"
195 static Evas_Object *_gl_title_content_get(void *data, Evas_Object *obj, const char *part)
197 Evas_Object *progressbar = NULL;
198 struct ug_data *ugd = (struct ug_data*) data;
201 DBG(LOG_ERROR, "Incorrect parameter(NULL)\n");
205 if (!strcmp(part, "elm.icon")) {
206 if (HEAD_TEXT_TYPE_SCANING == ugd->head_text_mode) {
207 progressbar = elm_progressbar_add(obj);
208 elm_object_style_set(progressbar, "list_process_small");
209 elm_progressbar_horizontal_set(progressbar, EINA_TRUE);
210 elm_progressbar_pulse(progressbar, EINA_TRUE);
211 evas_object_show(progressbar);
220 static char *_gl_peer_label_get(void *data, Evas_Object * obj, const char *part)
223 assertm_if(NULL == obj, "NULL!!");
224 assertm_if(NULL == part, "NULL!!");
226 device_type_s *peer = (device_type_s*) data;
227 char buf[WFD_GLOBALIZATION_STR_LENGTH] = { 0, };
228 DBG(LOG_VERBOSE, "%s", part);
231 DBG(LOG_ERROR, "Incorrect parameter(NULL)\n");
235 if (!strcmp(part, "elm.text.1"))
238 return strdup(peer->ssid);
240 else if (!strcmp(part, "elm.text.2"))
242 switch (peer->conn_status) {
243 case PEER_CONN_STATUS_DISCONNECTED:
244 g_strlcpy(buf, IDS_WFD_TAP_TO_CONNECT,
245 WFD_GLOBALIZATION_STR_LENGTH);
248 case PEER_CONN_STATUS_CONNECTING:
249 g_strlcpy(buf, IDS_WFD_CONNECTING,
250 WFD_GLOBALIZATION_STR_LENGTH);
253 case PEER_CONN_STATUS_CONNECTED:
254 g_strlcpy(buf, IDS_WFD_CONNECTED,
255 WFD_GLOBALIZATION_STR_LENGTH);
258 case PEER_CONN_STATUS_FAILED_TO_CONNECT:
259 g_strlcpy(buf, IDS_WFD_FAILED_TO_CONNECT,
260 WFD_GLOBALIZATION_STR_LENGTH);
263 case PEER_CONN_STATUS_WAIT_FOR_CONNECT:
264 g_strlcpy(buf, IDS_WFD_WAITING_FOR_CONNECT,
265 WFD_GLOBALIZATION_STR_LENGTH);
269 g_strlcpy(buf, IDS_WFD_TAP_TO_CONNECT,
270 WFD_GLOBALIZATION_STR_LENGTH);
284 static Evas_Object *_gl_peer_icon_get(void *data, Evas_Object * obj, const char *part)
287 assertm_if(NULL == obj, "NULL!!");
288 assertm_if(NULL == part, "NULL!!");
290 device_type_s *peer = (device_type_s*) data;
291 Evas_Object *icon = NULL;
295 DBG(LOG_ERROR, "Incorrect parameter(NULL)\n");
299 if(!strcmp(part, "elm.icon.2"))
301 DBG(LOG_VERBOSE, "elm.icon.2 - connection status [%d]\n", peer->conn_status);
302 if(peer->conn_status == PEER_CONN_STATUS_CONNECTING)
304 icon = elm_progressbar_add(obj);
305 elm_object_style_set(icon, "list_process");
306 elm_progressbar_pulse(icon, EINA_TRUE);
308 else if(peer->conn_status == PEER_CONN_STATUS_CONNECTED)
311 icon = elm_icon_add(obj);
312 elm_icon_file_set(icon, WFD_ICON_CONNECTED, NULL);
317 evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
318 elm_icon_resizable_set(icon, 1, 1);
319 evas_object_show(icon);
321 else if(!strcmp(part, "elm.icon.1"))
323 DBG(LOG_VERBOSE, "elm.icon.1 - category [%d]\n", peer->category);
324 char *img_path = NULL;
325 switch(peer->category)
327 case WFD_DEVICE_TYPE_COMPUTER:
328 if (peer->conn_status == PEER_CONN_STATUS_CONNECTED) {
329 img_path = WFD_ICON_DEVICE_COMPUTER_CONNECT;
331 img_path = WFD_ICON_DEVICE_COMPUTER;
334 case WFD_DEVICE_TYPE_INPUT_DEVICE:
335 if (peer->conn_status == PEER_CONN_STATUS_CONNECTED) {
336 img_path = WFD_ICON_DEVICE_INPUT_DEVICE_CONNECT;
338 img_path = WFD_ICON_DEVICE_INPUT_DEVICE;
341 case WFD_DEVICE_TYPE_PRINTER:
342 if (peer->conn_status == PEER_CONN_STATUS_CONNECTED) {
343 img_path = WFD_ICON_DEVICE_PRINTER_CONNECT;
345 img_path = WFD_ICON_DEVICE_PRINTER;
348 case WFD_DEVICE_TYPE_CAMERA:
349 if (peer->conn_status == PEER_CONN_STATUS_CONNECTED) {
350 img_path = WFD_ICON_DEVICE_CAMERA_CONNECT;
352 img_path = WFD_ICON_DEVICE_CAMERA;
355 case WFD_DEVICE_TYPE_STORAGE:
356 if (peer->conn_status == PEER_CONN_STATUS_CONNECTED) {
357 img_path = WFD_ICON_DEVICE_STORAGE_CONNECT;
359 img_path = WFD_ICON_DEVICE_STORAGE;
362 case WFD_DEVICE_TYPE_NW_INFRA:
363 if (peer->conn_status == PEER_CONN_STATUS_CONNECTED) {
364 img_path = WFD_ICON_DEVICE_NETWORK_INFRA_CONNECT;
366 img_path = WFD_ICON_DEVICE_NETWORK_INFRA;
369 case WFD_DEVICE_TYPE_DISPLAYS:
370 if (peer->conn_status == PEER_CONN_STATUS_CONNECTED) {
371 img_path = WFD_ICON_DEVICE_DISPLAY_CONNECT;
373 img_path = WFD_ICON_DEVICE_DISPLAY;
376 case WFD_DEVICE_TYPE_MM_DEVICES:
377 if (peer->conn_status == PEER_CONN_STATUS_CONNECTED) {
378 img_path = WFD_ICON_DEVICE_MULTIMEDIA_DEVICE_CONNECT;
380 img_path = WFD_ICON_DEVICE_MULTIMEDIA_DEVICE;
383 case WFD_DEVICE_TYPE_GAME_DEVICES:
384 if (peer->conn_status == PEER_CONN_STATUS_CONNECTED) {
385 img_path = WFD_ICON_DEVICE_GAMING_DEVICE_CONNECT;
387 img_path = WFD_ICON_DEVICE_GAMING_DEVICE;
390 case WFD_DEVICE_TYPE_TELEPHONE:
391 if (peer->conn_status == PEER_CONN_STATUS_CONNECTED) {
392 img_path = WFD_ICON_DEVICE_TELEPHONE_CONNECT;
394 img_path = WFD_ICON_DEVICE_TELEPHONE;
397 case WFD_DEVICE_TYPE_AUDIO:
398 if (peer->conn_status == PEER_CONN_STATUS_CONNECTED) {
399 img_path = WFD_ICON_DEVICE_AUDIO_DEVICE_CONNECT;
401 img_path = WFD_ICON_DEVICE_AUDIO_DEVICE;
405 if (peer->conn_status == PEER_CONN_STATUS_CONNECTED) {
406 img_path = WFD_ICON_DEVICE_COMPUTER_CONNECT;
408 img_path = WFD_ICON_DEVICE_COMPUTER;
415 icon = elm_icon_add(obj);
416 elm_icon_file_set(icon, img_path, NULL);
417 evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
418 elm_icon_resizable_set(icon, 1, 1);
419 evas_object_show(icon);
432 static char *_gl_noitem_text_get(void *data, Evas_Object * obj,
439 DBG(LOG_ERROR, "Incorrect parameter(NULL)\n");
444 return strdup(IDS_WFD_NOCONTENT);
448 static char *_gl_help_label_get(void *data, Evas_Object * obj, const char *part)
451 DBG(LOG_VERBOSE, "%s", part);
453 return strdup("Help");
457 static Evas_Object *_gl_button_get(void *data, Evas_Object * obj, const char *part)
460 struct ug_data *ugd = (struct ug_data*) data;
463 DBG(LOG_VERBOSE, "%s", part);
465 ugd->multi_btn = elm_button_add(obj);
467 wfd_refresh_wifi_direct_state(ugd);
469 if (ugd->multi_connect_mode == WFD_MULTI_CONNECT_MODE_COMPLETED)
471 elm_object_text_set(ugd->multi_btn, IDS_WFD_BUTTON_DISCONNECT);
472 DBG(LOG_VERBOSE, "button: Disconnect\n");
474 // Don't connect "clicked" callback.
475 return ugd->multi_btn;
478 if (ugd->wfd_status == WFD_LINK_STATUS_CONNECTING)
480 elm_object_text_set(ugd->multi_btn, IDS_WFD_BUTTON_CANCEL);
481 DBG(LOG_VERBOSE, "button: Cancel connect\n");
483 else if (ugd->wfd_status >= WFD_LINK_STATUS_CONNECTED)
485 if (ugd->gl_connected_peer_cnt > 1)
487 elm_object_text_set(ugd->multi_btn, IDS_WFD_BUTTON_DISCONNECT_ALL);
488 DBG(LOG_VERBOSE, "button: Disconnect All\n");
492 elm_object_text_set(ugd->multi_btn, IDS_WFD_BUTTON_DISCONNECT);
493 DBG(LOG_VERBOSE, "button: Disconnect\n");
498 elm_object_text_set(ugd->multi_btn, IDS_WFD_BUTTON_MULTI);
499 DBG(LOG_VERBOSE, "button: Multi connect\n");
502 evas_object_smart_callback_add(ugd->multi_btn, "clicked", _wifid_create_multibutton_cb, ugd);
503 evas_object_show(ugd->multi_btn);
507 return ugd->multi_btn;
511 static char *_gl_conn_dev_title_label_get(void *data, Evas_Object *obj,
518 DBG(LOG_ERROR, "Incorrect parameter(NULL)\n");
522 if (!strcmp(part, "elm.text"))
524 return strdup(IDS_WFD_BODY_CONNECTED_DEVICES);
533 static char *_gl_peer_conn_dev_label_get(void *data, Evas_Object * obj, const char *part)
536 assertm_if(NULL == obj, "NULL!!");
537 assertm_if(NULL == part, "NULL!!");
539 device_type_s *peer = (device_type_s*) data;
541 char buf[WFD_GLOBALIZATION_STR_LENGTH] = { 0, };
542 DBG(LOG_VERBOSE, "%s", part);
545 DBG(LOG_ERROR, "Incorrect parameter(NULL)\n");
549 if (!strcmp(part, "elm.text.1"))
551 return strdup(peer->ssid);
555 g_strlcpy(buf, IDS_WFD_CONNECTED,
556 WFD_GLOBALIZATION_STR_LENGTH);
562 static char *_gl_conn_failed_dev_title_label_get(void *data, Evas_Object *obj,
569 DBG(LOG_ERROR, "Incorrect parameter(NULL)\n");
573 if (!strcmp(part, "elm.text"))
575 return strdup(IDS_WFD_BODY_FAILED_DEVICES);
584 static char *_gl_peer_conn_failed_dev_label_get(void *data, Evas_Object * obj, const char *part)
587 assertm_if(NULL == obj, "NULL!!");
588 assertm_if(NULL == part, "NULL!!");
590 device_type_s *peer = (device_type_s*) data;
592 char buf[WFD_GLOBALIZATION_STR_LENGTH] = { 0, };
593 DBG(LOG_VERBOSE, "%s", part);
596 DBG(LOG_ERROR, "Incorrect parameter(NULL)\n");
600 if (!strcmp(part, "elm.text.1"))
602 return strdup(peer->ssid);
606 g_strlcpy(buf, IDS_WFD_FAILED_TO_CONNECT,
607 WFD_GLOBALIZATION_STR_LENGTH);
613 static char *_gl_multi_connect_dev_title_label_get(void *data, Evas_Object *obj,
617 struct ug_data *ugd = wfd_get_ug_data();
621 DBG(LOG_ERROR, "Incorrect parameter(NULL)\n");
625 if (!strcmp(part, "elm.text"))
627 if (ugd->multi_connect_mode == WFD_MULTI_CONNECT_MODE_IN_PROGRESS)
628 return strdup(_("IDS_WFD_BODY_AVAILABLE_DEVICES")); // "Available devices"
629 else if (ugd->multi_connect_mode == WFD_MULTI_CONNECT_MODE_COMPLETED)
630 return strdup(IDS_WFD_BODY_FAILED_DEVICES); // "Available devices"
639 static char *_gl_busy_dev_title_label_get(void *data, Evas_Object *obj,
646 DBG(LOG_ERROR, "Incorrect parameter(NULL)\n");
650 if (!strcmp(part, "elm.text"))
652 return strdup(IDS_WFD_BODY_BUSY_DEVICES);
661 static char *_gl_peer_busy_dev_label_get(void *data, Evas_Object * obj, const char *part)
664 assertm_if(NULL == obj, "NULL!!");
665 assertm_if(NULL == part, "NULL!!");
666 device_type_s *peer = (device_type_s*) data;
667 char buf[WFD_GLOBALIZATION_STR_LENGTH] = { 0, };
668 DBG(LOG_VERBOSE, "%s", part);
671 DBG(LOG_ERROR, "Incorrect parameter(NULL)\n");
674 DBG(LOG_VERBOSE, "peer->ssid = %s", peer->ssid);
675 if (!strcmp(part, "elm.text.1"))
677 return strdup(peer->ssid);
681 g_strlcpy(buf, IDS_WFD_CONNECTED_WITH_OTHER_DEVICE,
682 WFD_GLOBALIZATION_STR_LENGTH);
688 static void _gl_peer_del(void *data, Evas_Object * obj)
691 assertm_if(NULL == obj, "NULL!!");
692 assertm_if(NULL == data, "NULL!!");
698 void initialize_gen_item_class()
700 sep_itc.item_style = "dialogue/separator";
701 sep_itc.func.text_get = NULL;
702 sep_itc.func.content_get = NULL;
703 sep_itc.func.state_get = NULL;
704 sep_itc.func.del = NULL;
706 sep_itc_end.item_style = "dialogue/separator/end";
707 sep_itc_end.func.text_get = NULL;
708 sep_itc_end.func.content_get = NULL;
709 sep_itc_end.func.state_get = NULL;
710 sep_itc_end.func.del = NULL;
712 head_itc.item_style = "dialogue/2text.1icon.6";
713 head_itc.func.text_get = _gl_header_label_get;
714 head_itc.func.content_get = _gl_header_icon_get;
715 head_itc.func.state_get = NULL;
717 name_itc.item_style = "dialogue/1text";
718 name_itc.func.text_get = _gl_name_label_get;
719 name_itc.func.content_get = NULL;
720 name_itc.func.state_get = NULL;
721 name_itc.func.del = NULL;
723 title_itc.item_style = "dialogue/title";
724 title_itc.func.text_get = _gl_title_label_get;
725 title_itc.func.content_get = _gl_title_content_get;
726 title_itc.func.state_get = NULL;
727 title_itc.func.del = NULL;
729 peer_itc.item_style = "dialogue/2text.2icon.3";
730 peer_itc.func.text_get = _gl_peer_label_get;
731 peer_itc.func.content_get = _gl_peer_icon_get;
732 peer_itc.func.state_get = NULL;
733 peer_itc.func.del = _gl_peer_del;
735 noitem_itc.item_style ="dialogue/1text";
736 noitem_itc.func.text_get = _gl_noitem_text_get;
737 noitem_itc.func.content_get = NULL;
738 noitem_itc.func.state_get = NULL;
739 noitem_itc.func.del = NULL;
741 help_itc.item_style = "dialogue/1text";
742 help_itc.func.text_get = _gl_help_label_get;
743 help_itc.func.content_get = NULL;
744 help_itc.func.state_get = NULL;
745 help_itc.func.del = NULL;
747 button_itc.item_style = "1icon";
748 button_itc.func.text_get = NULL;
749 button_itc.func.content_get = _gl_button_get;
750 button_itc.func.state_get = NULL;
751 button_itc.func.del = NULL;
753 title_conn_itc.item_style = "dialogue/title";
754 title_conn_itc.func.text_get = _gl_conn_dev_title_label_get;
755 title_conn_itc.func.content_get = NULL;
756 title_conn_itc.func.state_get = NULL;
757 title_conn_itc.func.del = NULL;
759 peer_conn_itc.item_style = "dialogue/2text.2icon.3";
760 peer_conn_itc.func.text_get = _gl_peer_conn_dev_label_get;
761 peer_conn_itc.func.content_get = _gl_peer_icon_get;
762 peer_conn_itc.func.state_get = NULL;
763 peer_conn_itc.func.del = _gl_peer_del;
765 title_conn_failed_itc.item_style = "dialogue/title";
766 title_conn_failed_itc.func.text_get = _gl_conn_failed_dev_title_label_get;
767 title_conn_failed_itc.func.content_get = NULL;
768 title_conn_failed_itc.func.state_get = NULL;
769 title_conn_failed_itc.func.del = NULL;
771 peer_conn_failed_itc.item_style = "dialogue/2text.2icon.3";
772 peer_conn_failed_itc.func.text_get = _gl_peer_conn_failed_dev_label_get;
773 peer_conn_failed_itc.func.content_get = _gl_peer_icon_get;
774 peer_conn_failed_itc.func.state_get = NULL;
775 peer_conn_failed_itc.func.del = _gl_peer_del;
777 title_busy_itc.item_style = "dialogue/title";
778 title_busy_itc.func.text_get = _gl_busy_dev_title_label_get;
779 title_busy_itc.func.content_get = NULL;
780 title_busy_itc.func.state_get = NULL;
781 title_busy_itc.func.del = NULL;
783 peer_busy_itc.item_style = "dialogue/2text.2icon.3";
784 peer_busy_itc.func.text_get = _gl_peer_busy_dev_label_get;
785 peer_busy_itc.func.content_get = _gl_peer_icon_get;
786 peer_busy_itc.func.state_get = NULL;
787 peer_busy_itc.func.del = _gl_peer_del;
789 title_multi_connect_itc.item_style = "dialogue/title";
790 title_multi_connect_itc.func.text_get = _gl_multi_connect_dev_title_label_get;
791 title_multi_connect_itc.func.content_get = NULL;
792 title_multi_connect_itc.func.state_get = NULL;
793 title_multi_connect_itc.func.del = NULL;
796 peer_multi_connect_itc.item_style = "dialogue/2text.2icon.3";
797 peer_multi_connect_itc.func.text_get = _gl_peer_label_get;
798 peer_multi_connect_itc.func.content_get = _gl_peer_icon_get;
799 peer_multi_connect_itc.func.state_get = NULL;
800 peer_multi_connect_itc.func.del = _gl_peer_del;