4 * Copyright 2012 Samsung Electronics Co., Ltd
6 * Contact: Hocheol Seo <hocheol.seo@samsung.com>
7 * GirishAshok Joshi <girish.joshi@samsung.com>
8 * DoHyun Pyun <dh79.pyun@samsung.com>
10 * Licensed under the Flora License, Version 1.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.tizenopensource.org/license
16 * Unless required by applicable law or agreed to in writing,
17 * software distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
26 #include <eina_list.h>
28 #include <bluetooth.h>
29 #include <syspopup_caller.h>
30 #include <dbus/dbus.h>
32 #include <app_control.h>
33 #include <notification.h>
34 #include <efl_extension.h>
37 #include "bt-main-ug.h"
38 #include "bt-string-define.h"
39 #include "bt-main-view.h"
40 #include "bt-profile-view.h"
41 #include "bt-ipc-handler.h"
44 #include "bt-callback.h"
45 #include "bt-widget.h"
46 #include "bt-resource.h"
47 #include "bt-net-connection.h"
48 #include "bluetooth_internal.h"
49 #include "syspopup_caller.h"
51 #define MULTI_SHARE_SERVICE_DATA_PATH "http://tizen.org/appcontrol/data/path"
52 #define APP_CONTROL_OPERATION_SHARE_CONTACT "http://tizen.org/appcontrol/operation/share_contact"
54 #define APP_CONTROL_MIME_CONTACT "application/vnd.tizen.contact"
55 #define APP_CONTROL_MY_PROFILE_DATA_TYPE "my_profile"
57 #define SERVICE_SHARE_CONTACT_MODE "http://tizen.org/appcontrol/data/social/namecard_share_mode"
58 #define SERVICE_SHARE_CONTACT_ITEM "http://tizen.org/appcontrol/data/social/item_type"
59 #define SHARE_CONTACT_DATA_PATH "/opt/usr/media/Downloads/.bluetooth"
60 #define SHARE_CONTACT_ITEM_ID_ARRAY "http://tizen.org/appcontrol/data/social/item_id"
61 #define SHARE_CONTACT_ITEM_SHARE_MODE "http://tizen.org/appcontrol/data/social/namecard_share_mode"
62 #define HELP_SETUP_BLUETOOTH_URI "tizen-help://ug-bluetooth-efl/setupbluetooth"
64 /**********************************************************************
65 * Static Functions declaration
66 ***********************************************************************/
68 static void __bt_main_onoff_btn_cb(void *data, Evas_Object *obj, void *event_info);
70 static app_control_h __bt_main_get_bt_onoff_result(bt_ug_data *ugd,
73 static app_control_h __bt_main_get_pick_result(bt_ug_data *ugd, gboolean result);
75 static int __bt_main_request_to_send(bt_ug_data *ugd, bt_dev_t *dev);
77 #ifdef KIRAN_ACCESSIBILITY
78 static char *__bt_main_get_device_string(int major_class, int minor_class);
80 static Eina_Bool __bt_cb_register_net_state_cb(void *data);
82 /**********************************************************************
84 ***********************************************************************/
86 static char *__bt_main_onoff_label_get(void *data, Evas_Object *obj,
90 bt_ug_data *ugd = NULL;
92 retv_if(data == NULL, NULL);
93 ugd = (bt_ug_data *)data;
95 if (!strcmp("elm.text", part)) {
96 return g_strdup(BT_STR_BLUETOOTH);
97 } else if (!strcmp("elm.text.multiline", part)) {
98 char buf[1024] = {0,};
99 if (ugd->op_status == BT_ACTIVATING) {
100 snprintf(buf, sizeof(buf), "<font_size=30>%s</font_size>", BT_STR_TURNING_ON_BLUETOOTH);
101 return g_strdup(buf);
102 } else if (ugd->op_status == BT_DEACTIVATED) {
103 snprintf(buf, sizeof(buf), "<font_size=30>%s</font_size>", BT_STR_TURN_ON_BLUETOOTH_TO_SEE_A_LIST_OF_AVAILABLE_DEVICES);
104 return g_strdup(buf);
112 static Evas_Object *__bt_main_onoff_icon_get(void *data, Evas_Object *obj,
117 bt_ug_data *ugd = NULL;
118 Evas_Object *btn = NULL;
119 bool activated = false;
121 retv_if(data == NULL, NULL);
123 ugd = (bt_ug_data *)data;
125 if (!strcmp("elm.swallow.end", part)) {
126 if (ugd->op_status == BT_ACTIVATING
127 || ugd->op_status == BT_DEACTIVATING) {
128 btn = elm_progressbar_add(obj);
129 elm_object_style_set(btn, "process_medium");
130 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, 0.5);
131 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
132 elm_progressbar_pulse(btn, TRUE);
134 activated = ((ugd->op_status == BT_DEACTIVATED) ||
135 (ugd->op_status == BT_ACTIVATING)) ? false : true;
136 btn = elm_check_add(obj);
137 elm_object_style_set(btn, "on&off");
138 evas_object_pass_events_set(btn, EINA_TRUE);
139 evas_object_propagate_events_set(btn, EINA_FALSE);
140 elm_check_state_set(btn, activated);
142 #ifdef KIRAN_ACCESSIBILITY
143 elm_access_object_unregister(btn);
146 /* add smart callback */
147 evas_object_smart_callback_add(btn, "changed",
148 __bt_main_onoff_btn_cb, ugd);
150 ugd->onoff_btn = btn;
153 if (_bt_util_is_dpm_restricted(ugd->dpm_handle) == TRUE)
154 elm_object_disabled_set(btn, EINA_TRUE);
156 evas_object_show(btn);
163 static char *__bt_main_rename_desc_label_get(void *data, Evas_Object *obj,
168 if (!strcmp("elm.text.multiline", part)) {
169 char buf[1024] = {0,};
170 snprintf(buf, sizeof(buf),"<font_size=30>%s</font_size>",
171 BT_STR_RENAME_DEVICE_LABEL);
172 return g_strdup(buf);
179 static char *__bt_main_device_label_get(void *data, Evas_Object *obj,
184 bt_ug_data *ugd = NULL;
185 char buf[BT_GLOBALIZATION_STR_LENGTH] = { 0, };
186 char *dev_name = NULL;
188 #ifdef KIRAN_ACCESSIBILITY
189 char str[BT_STR_ACCES_INFO_MAX_LEN] = { 0, };
190 Evas_Object *ao = NULL;
192 retv_if(data == NULL, NULL);
194 ugd = (bt_ug_data *)data;
195 BT_DBG("part : %s", part);
197 if (!strcmp("elm.text", part)) {
198 memset(ugd->phone_name, 0x00, BT_GLOBALIZATION_STR_LENGTH);
200 _bt_util_get_phone_name(ugd->phone_name, sizeof(ugd->phone_name));
202 if (strlen(ugd->phone_name) == 0) {
203 if (bt_adapter_get_name(&dev_name) == BT_ERROR_NONE) {
204 g_strlcpy(ugd->phone_name, dev_name,
205 BT_GLOBALIZATION_STR_LENGTH);
210 BT_DBG("ugd->phone_name : %s[%d]", ugd->phone_name, strlen(ugd->phone_name));
211 /* Check the utf8 valitation & Fill the NULL in the invalid location */
212 if (!g_utf8_validate(ugd->phone_name, -1, (const char **)&ptr))
215 dev_name = elm_entry_utf8_to_markup(ugd->phone_name);
217 g_strlcpy(buf, dev_name, BT_GLOBALIZATION_STR_LENGTH);
220 g_strlcpy(buf, ugd->phone_name, BT_GLOBALIZATION_STR_LENGTH);
222 #ifdef KIRAN_ACCESSIBILITY
223 snprintf(str, sizeof(str), "%s, %s",
224 BT_STR_DEVICE_NAME, ugd->phone_name);
225 ao = elm_object_item_access_object_get(ugd->device_name_item);
226 elm_access_info_set(ao, ELM_ACCESS_INFO, str);
229 BT_DBG("buf : %s[%d]", buf, strlen(buf));
231 } else if (!strcmp("elm.text.sub", part)) {
232 g_strlcpy(buf, BT_STR_MY_DEVICE,
233 BT_GLOBALIZATION_STR_LENGTH);
234 #ifdef KIRAN_ACCESSIBILITY
235 ao = elm_object_item_access_object_get(ugd->paired_title);
236 snprintf(str, sizeof(str), "%s, %s", BT_STR_PAIRED_DEVICES,
237 BT_ACC_STR_GROUP_INDEX);
238 elm_access_info_set(ao, ELM_ACCESS_INFO, str);
243 BT_ERR("This part name is not exist in style.");
248 char* __bt_convert_rgba_to_hex(int r, int g, int b, int a)
253 string = g_try_malloc0(sizeof(char )* 255);
254 /* Fix : NULL_RETURNS */
258 hexcolor = (r << 24) + (g << 16) + (b << 8) + a;
259 sprintf(string, "%08x", hexcolor );
264 int _bt_idle_destroy_ug(void *data)
268 bt_ug_data *ugd = data;
269 app_control_h service = NULL;
271 retv_if(ugd == NULL, BT_UG_FAIL);
273 if (ugd->bt_launch_mode == BT_LAUNCH_PICK)
274 service = __bt_main_get_pick_result(ugd, TRUE);
275 else if (ugd->bt_launch_mode == BT_LAUNCH_ONOFF)
276 service = __bt_main_get_bt_onoff_result(ugd, TRUE);
278 _bt_ug_destroy(data, (void *)service);
281 app_control_destroy(service);
284 return BT_UG_ERROR_NONE;
287 gboolean _bt_main_is_connectable_device(bt_dev_t *dev)
291 bt_device_info_s *device_info = NULL;
293 retv_if(dev == NULL, FALSE);
295 if (dev->service_list == 0) {
296 if (bt_adapter_get_bonded_device_info
297 ((const char *)dev->addr_str,
298 &device_info) != BT_ERROR_NONE) {
300 bt_adapter_free_device_info(device_info);
303 bt_device_get_service_mask_from_uuid_list
304 (device_info->service_uuid, device_info->service_count,
307 bt_adapter_free_device_info(device_info);
309 if (dev->service_list == 0) {
310 BT_ERR("No service list");
315 if ((dev->service_list & BT_SC_HFP_SERVICE_MASK) ||
316 (dev->service_list & BT_SC_HSP_SERVICE_MASK) ||
317 (dev->service_list & BT_SC_A2DP_SERVICE_MASK) ||
318 #ifdef TIZEN_BT_A2DP_SINK_ENABLE
319 (dev->service_list & BT_SC_A2DP_SOURCE_SERVICE_MASK) ||
321 (dev->service_list & BT_SC_HID_SERVICE_MASK) ||
322 (dev->service_list & BT_SC_NAP_SERVICE_MASK)) {
323 /* Connectable device */
331 static char *__bt_main_paired_device_label_get(void *data, Evas_Object *obj,
337 #ifdef KIRAN_ACCESSIBILITY
338 char str[BT_STR_ACCES_INFO_MAX_LEN] = { 0, };
340 bt_dev_t *dev = NULL;
341 bt_ug_data *ugd = NULL;
342 int r = 0, g = 0, b = 0, a = 0;
344 retv_if(data == NULL, NULL);
346 dev = (bt_dev_t *)data;
347 retv_if(dev == NULL, NULL);
349 ugd = (bt_ug_data *)dev->ugd;
350 retv_if(ugd == NULL, NULL);
352 if (!strcmp("elm.text", part)) {
353 char *name = elm_entry_utf8_to_markup(dev->name);
355 if (ugd->bt_launch_mode != BT_LAUNCH_PICK &&
356 dev->is_connected > 0 && dev->highlighted == FALSE) {
357 r = 20, g = 107, b = 147, a = 255;
358 char *color_code = __bt_convert_rgba_to_hex(r, g, b, a);;
360 buf = g_strdup_printf("<color=#%s>%s</color>",
365 buf = g_strdup_printf("<color=#%s>%s</color>",
374 buf = g_strdup_printf("%s",
378 buf = g_strdup_printf("%s",
381 } else if (!strcmp("elm.text.sub", part) && ugd->bt_launch_mode != BT_LAUNCH_PICK) {
382 #ifdef KIRAN_ACCESSIBILITY
383 char *double_tap_string = NULL;
384 char *device_type = NULL;
385 Evas_Object *ao = NULL;
388 if (dev->status == BT_IDLE) {
389 if (_bt_main_is_connectable_device(dev)) {
390 if (dev->is_connected == 0) {
391 buf = g_strdup(BT_STR_PAIRED);
392 #ifdef KIRAN_ACCESSIBILITY
393 double_tap_string = NULL;
395 } else if (dev->is_connected > 0) {
396 buf = g_strdup(BT_STR_CONNECTED);
397 #ifdef KIRAN_ACCESSIBILITY
399 BT_STR_DOUBLE_TAP_DISCONNECT_D;
403 buf = g_strdup(BT_STR_PAIRED);
404 #ifdef KIRAN_ACCESSIBILITY
405 double_tap_string = BT_STR_DOUBLE_TAP_CONNECT_D;
408 } else if (dev->status == BT_CONNECTING) {
409 buf = g_strdup(BT_STR_CONNECTING);
410 } else if (dev->status == BT_SERVICE_SEARCHING) {
411 buf = g_strdup(BT_STR_SEARCHING_SERVICES);
412 } else if (dev->status == BT_DISCONNECTING) {
413 buf = g_strdup(BT_STR_DISCONNECTING);
415 #ifdef KIRAN_ACCESSIBILITY
417 __bt_main_get_device_string(dev->major_class,
419 if (double_tap_string != NULL && buf != NULL)
420 snprintf(str, sizeof(str), "%s, %s, %s, %s, %s",
422 device_type, double_tap_string,
424 else if (double_tap_string == NULL && buf != NULL)
425 snprintf(str, sizeof(str), "%s, %s, %s, %s",
427 device_type, BT_STR_MORE_BUTTON);
430 ao = elm_object_item_access_object_get(dev->genlist_item);
431 elm_access_info_set(ao, ELM_ACCESS_INFO, str);
433 } else { /* for empty item */
435 BT_ERR("empty text for label");
442 static void __bt_paired_device_profile_cb(void *data, Evas_Object *obj,
447 bt_dev_t *dev = NULL;
448 bt_ug_data *ugd = NULL;
450 ret_if(data == NULL);
452 dev = (bt_dev_t *)data;
453 ret_if(dev->ugd == NULL);
458 elm_genlist_item_selected_set((Elm_Object_Item *)event_info,
461 if (ugd->op_status == BT_SEARCHING) {
462 ret = bt_adapter_stop_device_discovery();
463 if (ret != BT_ERROR_NONE)
464 BT_ERR("Fail to stop discovery: %d", ret);
467 /* Create the profile view */
468 _bt_profile_create_view(dev);
472 static void __bt_rename_device_entry_changed_cb(void *data, Evas_Object *obj,
477 ret_if(data == NULL);
478 bt_ug_data *ugd = NULL;
480 ugd = (bt_ug_data *)data;
482 const char *entry_text = NULL;
483 char *input_str = NULL;
485 if (ugd->rename_entry != obj)
486 ugd->rename_entry = obj;
487 entry_text = elm_entry_entry_get(obj);
488 input_str = elm_entry_markup_to_utf8(entry_text);
490 if (input_str == NULL || strlen(input_str) == 0 ||
491 _bt_util_is_space_str(input_str)) {
493 elm_object_disabled_set(ugd->rename_button, EINA_TRUE);
494 elm_entry_input_panel_return_key_disabled_set(
498 if (elm_object_disabled_get(ugd->rename_button))
499 elm_object_disabled_set(ugd->rename_button, EINA_FALSE);
500 if (elm_entry_input_panel_return_key_disabled_get(obj))
501 elm_entry_input_panel_return_key_disabled_set(obj, EINA_FALSE);
503 if(input_str != NULL) {
511 static void __bt_rename_device_cancel_cb(void *data, Evas_Object *obj,
515 bt_ug_data *ugd = NULL;
517 ret_if(data == NULL);
518 ugd = (bt_ug_data *)data;
520 if (ugd->rename_entry) {
521 elm_entry_input_panel_hide(ugd->rename_entry);
522 elm_object_focus_set(ugd->rename_entry, EINA_FALSE);
525 if (ugd->rename_popup != NULL) {
526 evas_object_del(ugd->rename_popup);
527 ugd->rename_popup = NULL;
528 ugd->rename_entry_item = NULL;
529 ugd->rename_entry = NULL;
535 static void __bt_rename_device_ok_cb(void *data, Evas_Object *obj,
539 bt_ug_data *ugd = (bt_ug_data *) data;
541 const char *entry_str = elm_entry_entry_get(ugd->rename_entry);
542 char *device_name_str = NULL;
543 device_name_str = elm_entry_markup_to_utf8(entry_str);
544 ret_if(!device_name_str);
545 BT_DBG("Device name:[%s]", device_name_str);
547 if (0 != vconf_set_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR, device_name_str)) {
548 BT_ERR("Set vconf[%s] failed",VCONFKEY_SETAPPL_DEVICE_NAME_STR);
551 _bt_update_genlist_item(ugd->device_name_item);
553 if (ugd->rename_entry) {
554 elm_entry_input_panel_hide(ugd->rename_entry);
555 elm_object_focus_set(ugd->rename_entry, EINA_FALSE);
558 evas_object_del(ugd->rename_popup);
559 ugd->rename_popup = NULL;
560 ugd->rename_entry_item = NULL;
561 ugd->rename_entry = NULL;
562 g_free(device_name_str);
567 static void __bt_rename_entry_changed_cb(void *data, Evas_Object *obj,
572 bt_ug_data *ugd = (bt_ug_data *) data;
573 ret_if(!ugd->rename_entry_item);
575 if (elm_object_part_content_get(obj, "elm.icon.eraser")) {
576 if (elm_object_focus_get(obj)) {
577 if (elm_entry_is_empty(obj)) {
578 elm_object_item_signal_emit(ugd->rename_entry_item,
579 "elm,state,eraser,hide", "");
581 elm_object_item_signal_emit(ugd->rename_entry_item,
582 "elm,state,eraser,show", "");
586 __bt_rename_device_entry_changed_cb(data, obj, event_info);
591 static void __bt_main_entry_edit_mode_show_cb(void *data, Evas *e, Evas_Object *obj,
594 evas_object_event_callback_del(obj, EVAS_CALLBACK_SHOW,
595 __bt_main_entry_edit_mode_show_cb);
597 elm_object_focus_set(obj, EINA_TRUE);
598 elm_entry_cursor_end_set(obj);
601 static void __bt_main_popup_entry_activated_cb(void *data, Evas_Object *obj, void *event_info)
606 elm_object_focus_set(obj, EINA_FALSE);
609 static Evas_Object *__bt_main_rename_entry_icon_get(
610 void *data, Evas_Object *obj, const char *part)
613 retv_if (obj == NULL || data == NULL, NULL);
615 Evas_Object *entry = NULL;
616 char *name_value = NULL;
617 char *name_value_utf = NULL;
619 static Elm_Entry_Filter_Limit_Size limit_filter_data;
620 bt_ug_data *ugd = (bt_ug_data *)data;
622 if (!strcmp(part, "elm.swallow.content")) {
623 Evas_Object *layout = NULL;
625 layout = elm_layout_add(obj);
626 elm_layout_theme_set(layout, "layout", "editfield", "singleline");
627 evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, 0.0);
628 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, 0.0);
630 name_value_utf = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
631 retvm_if (!name_value_utf, NULL, "Get string is failed");
633 name_value = elm_entry_utf8_to_markup(name_value_utf);
635 entry = elm_entry_add(layout);
636 elm_entry_single_line_set(entry, EINA_TRUE);
637 elm_entry_scrollable_set(entry, EINA_TRUE);
639 evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, 0.0);
640 evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, 0.0);
642 eext_entry_selection_back_event_allow_set(entry, EINA_TRUE);
643 elm_object_signal_emit(entry, "elm,action,hide,search_icon", "");
644 elm_object_part_text_set(entry, "guide", BT_STR_DEVICE_NAME);
645 elm_object_text_set(entry, name_value);
646 elm_entry_input_panel_imdata_set(entry, "action=disable_emoticons", 24);
648 elm_entry_input_panel_return_key_type_set(entry, ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DONE);
649 limit_filter_data.max_char_count = DEVICE_NAME_MAX_CHARACTER;
650 elm_entry_markup_filter_append(entry,
651 elm_entry_filter_limit_size, &limit_filter_data);
653 elm_entry_cnp_mode_set(entry, ELM_CNP_MODE_PLAINTEXT);
655 evas_object_smart_callback_add(entry, "maxlength,reached",
656 _bt_util_max_len_reached_cb, ugd);
657 evas_object_smart_callback_add(entry, "changed",
658 __bt_rename_entry_changed_cb, ugd);
659 evas_object_smart_callback_add(entry, "preedit,changed",
660 __bt_rename_entry_changed_cb, ugd);
661 evas_object_smart_callback_add(entry, "activated",
662 __bt_main_popup_entry_activated_cb, NULL);
663 evas_object_event_callback_add(entry, EVAS_CALLBACK_SHOW,
664 __bt_main_entry_edit_mode_show_cb, ugd);
666 elm_entry_input_panel_show(entry);
667 elm_object_part_content_set(layout, "elm.swallow.content", entry);
669 ugd->rename_entry = entry;
672 free(name_value_utf);
682 static Evas_Object *__bt_main_paired_device_icon_get(void *data, Evas_Object *obj,
687 Evas_Object *btn = NULL;
688 Evas_Object *icon = NULL;
689 char *dev_icon_file = NULL;
690 bt_dev_t *dev = NULL;
692 retv_if(data == NULL, NULL);
694 dev = (bt_dev_t *)data;
696 if (!strcmp("elm.swallow.icon", part)) {
697 if ((dev->major_class == BT_MAJOR_DEV_CLS_MISC)
698 && (dev->service_list != 0))
699 _bt_util_update_class_of_device_by_service_list(dev->service_list,
700 &dev->major_class, &dev->minor_class);
703 _bt_main_get_device_icon(dev->major_class,
708 icon = _bt_create_icon(obj, dev_icon_file);
709 evas_object_propagate_events_set(icon, EINA_FALSE);
710 evas_object_show(icon);
712 if (dev->highlighted || dev->is_connected)
713 evas_object_color_set(dev->icon, 20, 107, 147, 255);
715 evas_object_color_set(dev->icon, 76, 76, 76, 255);
717 evas_object_size_hint_min_set(icon, ELM_SCALE_SIZE(40), ELM_SCALE_SIZE(40));
718 } else if (!strcmp("elm.swallow.end", part)) {
719 BT_INFO("status : %d", dev->status);
720 if (dev->status == BT_IDLE) {
721 btn = elm_button_add(obj);
722 elm_object_style_set(btn, "info_button");
724 evas_object_propagate_events_set(btn, EINA_FALSE);
725 evas_object_smart_callback_add(btn, "clicked",
726 __bt_paired_device_profile_cb,
728 evas_object_show(btn);
732 icon = _bt_create_progressbar(obj, "process_medium");
741 static char *__bt_main_searched_label_get(void *data, Evas_Object *obj,
744 char buf[BT_GLOBALIZATION_STR_LENGTH] = { 0 };
745 bt_dev_t *dev = NULL;
750 dev = (bt_dev_t *)data;
751 if (!strcmp("elm.text", part)) {
752 #ifdef KIRAN_ACCESSIBILITY
753 char str[BT_STR_ACCES_INFO_MAX_LEN] = { 0, };
754 Evas_Object *ao = NULL;
756 char *dev_name_markup = elm_entry_utf8_to_markup(dev->name);
758 if (dev_name_markup) {
759 g_strlcpy(buf, dev_name_markup,
760 BT_GLOBALIZATION_STR_LENGTH);
761 free(dev_name_markup);
763 g_strlcpy(buf, dev->name, BT_GLOBALIZATION_STR_LENGTH);
766 BT_INFO("label : %s", buf);
767 #ifdef KIRAN_ACCESSIBILITY
768 snprintf(str, sizeof(str), "%s, %s", dev->name,
769 BT_STR_DOUBLE_TAP_CONNECT);
771 ao = elm_object_item_access_object_get(dev->genlist_item);
772 elm_access_info_set(ao, ELM_ACCESS_INFO, str);
775 BT_ERR("empty text for label");
782 static Evas_Object *__bt_main_searched_icon_get(void *data,
786 Evas_Object *icon = NULL;
787 char *dev_icon_file = NULL;
788 bt_dev_t *dev = NULL;
790 retv_if(data == NULL, NULL);
792 dev = (bt_dev_t *)data;
794 if (!strcmp("elm.swallow.icon", part)) {
796 _bt_main_get_device_icon(dev->major_class,
800 icon = _bt_create_icon(obj, dev_icon_file);
801 if (dev->highlighted || dev->is_connected)
802 evas_object_color_set(icon, 20, 107, 147, 255);
804 evas_object_color_set(icon, 76, 76, 76, 255);
805 evas_object_propagate_events_set(icon, EINA_FALSE);
806 } else if (!strcmp("elm.swallow.end", part)) {
807 if (dev->status != BT_IDLE) {
808 icon = _bt_create_progressbar(obj, "process_medium");
809 evas_object_color_set(icon, 76, 76, 76, 255);
814 evas_object_show(icon);
815 evas_object_size_hint_min_set(icon, ELM_SCALE_SIZE(40), ELM_SCALE_SIZE(40));
821 static char *__bt_main_no_device_label_get(void *data, Evas_Object *obj,
826 char buf[BT_GLOBALIZATION_STR_LENGTH] = { 0 };
827 #ifdef KIRAN_ACCESSIBILITY
828 bt_ug_data *ugd = NULL;
829 char str[BT_STR_ACCES_INFO_MAX_LEN] = { 0, };
830 Evas_Object *ao = NULL;
832 if (!strcmp("elm.text", part)) {
833 g_strlcpy(buf, BT_STR_NO_DEVICE_FOUND,
834 BT_GLOBALIZATION_STR_LENGTH);
835 snprintf(buf, sizeof(buf), "<align=center>%s</align>", BT_STR_NO_DEVICE_FOUND);
837 #ifdef KIRAN_ACCESSIBILITY
838 retv_if(data == NULL, NULL);
839 ugd = (bt_ug_data *)data;
840 g_strlcpy(str, BT_STR_NO_DEVICE_FOUND,
841 BT_STR_ACCES_INFO_MAX_LEN);
843 ao = elm_object_item_access_object_get(ugd->no_device_item);
844 elm_access_info_set(ao, ELM_ACCESS_INFO, str);
847 BT_ERR("empty text for label");
855 static char *__bt_main_paired_title_label_get(void *data, Evas_Object *obj,
860 char buf[BT_GLOBALIZATION_STR_LENGTH] = { 0, };
861 #ifdef KIRAN_ACCESSIBILITY
862 bt_ug_data *ugd = NULL;
863 char str[BT_STR_ACCES_INFO_MAX_LEN] = { 0, };
864 Evas_Object *ao = NULL;
866 if (!strcmp("elm.text", part)) {
868 g_strlcpy(buf, BT_STR_PAIRED_DEVICES,
869 BT_GLOBALIZATION_STR_LENGTH);
873 #ifdef KIRAN_ACCESSIBILITY
874 retv_if(data == NULL, NULL);
875 ugd = (bt_ug_data *)data;
876 ao = elm_object_item_access_object_get(ugd->paired_title);
877 snprintf(str, sizeof(str), "%s, %s", BT_STR_PAIRED_DEVICES,
878 BT_ACC_STR_GROUP_INDEX);
879 elm_access_info_set(ao, ELM_ACCESS_INFO, str);
885 static char *__bt_main_searched_title_label_get(void *data, Evas_Object *obj,
890 char buf[BT_GLOBALIZATION_STR_LENGTH] = { 0, };
891 bt_ug_data *ugd = NULL;
892 #ifdef KIRAN_ACCESSIBILITY
893 Evas_Object *ao = NULL;
894 char str[BT_STR_ACCES_INFO_MAX_LEN] = { 0, };
897 retv_if(data == NULL, NULL);
899 ugd = (bt_ug_data *)data;
900 if (!strcmp("elm.text", part)) {
902 if (ugd->searched_device == NULL ||
903 eina_list_count(ugd->searched_device) == 0) {
904 if (ugd->op_status == BT_SEARCHING) {
905 g_strlcpy(buf, BT_STR_SCANNING,
906 BT_GLOBALIZATION_STR_LENGTH);
907 } else if (ugd->op_status == BT_ACTIVATED) {
908 g_strlcpy(buf, BT_STR_BLUETOOTH_DEVICES,
909 BT_GLOBALIZATION_STR_LENGTH);
912 g_strlcpy(buf, BT_STR_AVAILABLE_DEVICES,
913 BT_GLOBALIZATION_STR_LENGTH);
916 #ifdef KIRAN_ACCESSIBILITY
917 snprintf(str, sizeof(str), "%s, %s",
918 buf, BT_ACC_STR_GROUP_INDEX);
919 ao = elm_object_item_access_object_get(ugd->searched_title);
920 elm_access_info_set(ao, ELM_ACCESS_INFO, str);
930 static Evas_Object *__bt_main_searched_title_icon_get(void *data, Evas_Object *obj,
935 bt_ug_data *ugd = NULL;
936 Evas_Object *progressbar = NULL;
938 retv_if(data == NULL, NULL);
939 retv_if(obj == NULL, NULL);
940 retv_if(part == NULL, NULL);
942 ugd = (bt_ug_data *)data;
944 if (!strcmp("elm.swallow.end", part) && ugd->op_status == BT_SEARCHING) {
945 progressbar = _bt_create_progressbar(obj, "process_small");
952 static app_control_h __bt_main_get_bt_onoff_result(bt_ug_data *ugd,
955 app_control_h service = NULL;
956 const char *result_str;
957 bt_adapter_state_e bt_state = BT_ADAPTER_DISABLED;
959 retv_if(ugd == NULL, NULL);
961 app_control_create(&service);
963 retv_if(service == NULL, NULL);
966 result_str = BT_RESULT_SUCCESS;
968 result_str = BT_RESULT_FAIL;
970 if (app_control_add_extra_data(service, "result", result_str) < 0) {
971 BT_ERR("Fail to add extra data");
974 if (bt_adapter_get_state(&bt_state) == BT_ERROR_NONE) {
975 if (bt_state == BT_ADAPTER_ENABLED) {
976 if (app_control_add_extra_data(service, "bt_status", BT_ADAPTER_ON) < 0) {
977 BT_ERR("Fail to add extra data");
980 if (app_control_add_extra_data(service, "bt_status", BT_ADAPTER_OFF) < 0) {
981 BT_ERR("Fail to add extra data");
985 BT_ERR("Fail to bt_adapter_get_state");
991 static app_control_h __bt_main_get_pick_result(bt_ug_data *ugd, gboolean result)
993 app_control_h service = NULL;
994 const char *result_str;
995 char address[BT_ADDRESS_STR_LEN] = { 0 };
996 char value_str[BT_RESULT_STR_MAX] = { 0 };
999 retv_if(ugd == NULL, NULL);
1000 retv_if(ugd->pick_device == NULL, NULL);
1002 dev = ugd->pick_device;
1004 app_control_create(&service);
1006 retv_if(service == NULL, NULL);
1009 result_str = BT_RESULT_SUCCESS;
1011 result_str = BT_RESULT_FAIL;
1013 if (app_control_add_extra_data(service, "result", result_str) < 0) {
1014 BT_ERR("Fail to add extra data");
1017 _bt_util_addr_type_to_addr_result_string(address, dev->bd_addr);
1019 /* Original output fields will be removed */
1020 if (app_control_add_extra_data(service, "address",
1021 (const char *)address) < 0) {
1022 BT_ERR("Fail to add extra data");
1025 if (app_control_add_extra_data(service, BT_APPCONTROL_ADDRESS,
1026 (const char *)address) < 0) {
1027 BT_ERR("Fail to add extra data");
1030 if (app_control_add_extra_data(service, "name",
1031 (const char *)dev->name) < 0) {
1032 BT_ERR("Fail to add extra data");
1035 if (app_control_add_extra_data(service, BT_APPCONTROL_NAME,
1036 (const char *)dev->name) < 0) {
1037 BT_ERR("Fail to add extra data");
1040 snprintf(value_str, BT_RESULT_STR_MAX, "%d", dev->rssi);
1042 if (app_control_add_extra_data(service, "rssi",
1043 (const char *)value_str) < 0) {
1044 BT_ERR("Fail to add extra data");
1047 if (app_control_add_extra_data(service, BT_APPCONTROL_RSSI,
1048 (const char *)value_str) < 0) {
1049 BT_ERR("Fail to add extra data");
1052 memset(value_str, 0x00, sizeof(value_str));
1053 snprintf(value_str, BT_RESULT_STR_MAX, "%d", dev->is_bonded);
1055 if (app_control_add_extra_data(service, "is_bonded",
1056 (const char *)value_str) < 0) {
1057 BT_ERR("Fail to add extra data");
1060 if (app_control_add_extra_data(service, BT_APPCONTROL_IS_PAIRED,
1061 (const char *)value_str) < 0) {
1062 BT_ERR("Fail to add extra data");
1065 memset(value_str, 0x00, sizeof(value_str));
1066 snprintf(value_str, BT_RESULT_STR_MAX, "%d", dev->major_class);
1068 if (app_control_add_extra_data(service, "major_class",
1069 (const char *)value_str) < 0) {
1070 BT_ERR("Fail to add extra data");
1073 if (app_control_add_extra_data(service, BT_APPCONTROL_MAJOR_CLASS,
1074 (const char *)value_str) < 0) {
1075 BT_ERR("Fail to add extra data");
1078 memset(value_str, 0x00, sizeof(value_str));
1079 snprintf(value_str, BT_RESULT_STR_MAX, "%d", dev->minor_class);
1081 if (app_control_add_extra_data(service, "minor_class",
1082 (const char *)value_str) < 0) {
1083 BT_ERR("Fail to add extra data");
1086 if (app_control_add_extra_data(service, BT_APPCONTROL_MINOR_CLASS,
1087 (const char *)value_str) < 0) {
1088 BT_ERR("Fail to add extra data");
1091 memset(value_str, 0x00, sizeof(value_str));
1092 snprintf(value_str, BT_RESULT_STR_MAX, "%ld",
1093 (long int)dev->service_class);
1095 if (app_control_add_extra_data(service, "service_class",
1096 (const char *)value_str) < 0) {
1097 BT_ERR("Fail to add extra data");
1100 if (app_control_add_extra_data(service, BT_APPCONTROL_SERVICE_CLASS,
1101 (const char *)value_str) < 0) {
1102 BT_ERR("Fail to add extra data");
1105 if (app_control_add_extra_data_array(service, "uuids",
1106 (const char **)dev->uuids,
1107 dev->uuid_count) < 0) {
1108 BT_ERR("Fail to add extra data");
1111 if (app_control_add_extra_data_array(service, BT_APPCONTROL_UUID_LIST,
1112 (const char **)dev->uuids,
1113 dev->uuid_count) < 0) {
1114 BT_ERR("Fail to add extra data");
1120 static Eina_Bool __bt_main_quit_btn_cb(void *data, Elm_Object_Item *it)
1123 app_control_h reply = NULL;
1124 app_control_h service = NULL;
1125 bt_ug_data *ugd = (bt_ug_data *)data;
1127 retv_if(ugd == NULL, EINA_FALSE);
1129 if (ugd->bt_launch_mode == BT_LAUNCH_PICK) {
1130 app_control_create(&service);
1132 if (service == NULL) {
1133 _bt_ug_destroy(data, NULL);
1137 if (app_control_add_extra_data(service, "result",
1138 BT_RESULT_FAIL) < 0) {
1139 BT_ERR("Fail to add extra data");
1142 _bt_ug_destroy(data, (void *)service);
1144 app_control_destroy(service);
1145 } else if (ugd->bt_launch_mode == BT_LAUNCH_ONOFF) {
1146 service = __bt_main_get_bt_onoff_result(ugd, FALSE);
1148 app_control_create(&reply);
1149 if (app_control_add_extra_data(reply, "result",
1150 BT_RESULT_FAIL) < 0) {
1151 BT_ERR("Fail to add extra data");
1154 BT_DBG("BT_LAUNCH_ONOFF reply to launch request");
1155 app_control_reply_to_launch_request(reply, service,
1156 APP_CONTROL_RESULT_FAILED);
1158 _bt_ug_destroy(data, (void *)service);
1161 app_control_destroy(service);
1163 app_control_destroy(reply);
1165 _bt_ug_destroy(data, NULL);
1172 int _bt_main_enable_bt(void *data)
1176 retv_if(data == NULL, -1);
1177 bt_ug_data *ugd = (bt_ug_data *)data;
1179 if (_bt_util_is_battery_low() == TRUE) {
1180 /* Battery is critical low */
1181 _bt_main_create_information_popup(ugd, BT_STR_LOW_BATTERY);
1185 ret = bt_adapter_enable();
1186 if (ret != BT_ERROR_NONE) {
1187 BT_ERR("Failed to enable bluetooth [%d]", ret);
1189 ugd->op_status = BT_ACTIVATING;
1196 int _bt_main_disable_bt(void *data)
1200 retv_if(data == NULL, -1);
1201 bt_ug_data *ugd = (bt_ug_data *)data;
1203 ret = bt_adapter_disable();
1204 if (ret != BT_ERROR_NONE) {
1205 BT_ERR("Failed to disable bluetooth [%d]", ret);
1207 ugd->op_status = BT_DEACTIVATING;
1208 elm_object_disabled_set(ugd->scan_btn, EINA_TRUE);
1215 static void __bt_main_onoff_btn_cb(void *data, Evas_Object *obj,
1219 ret_if(data == NULL);
1222 bt_ug_data *ugd = (bt_ug_data *)data;
1224 Elm_Object_Item *item = (Elm_Object_Item *)event_info;
1225 elm_genlist_item_selected_set(item, EINA_FALSE);
1227 if (ugd->bt_launch_mode == BT_LAUNCH_HELP) {
1228 Eina_Bool check_mode = elm_check_state_get(obj);
1229 elm_check_state_set(obj, !check_mode);
1231 ret = notification_status_message_post(BT_STR_INVALID_ACTION_TRY_AGAIN);
1232 if (ret != NOTIFICATION_ERROR_NONE)
1233 BT_ERR("notification_status_message_post() is failed : %d", ret);
1238 ret_if (ugd->op_status == BT_ACTIVATING ||
1239 ugd->op_status == BT_DEACTIVATING);
1241 elm_object_disabled_set(ugd->onoff_btn, EINA_TRUE);
1243 if (ugd->op_status == BT_DEACTIVATED) {
1244 ret = _bt_main_enable_bt(data);
1245 ugd->op_status = BT_ACTIVATING;
1246 } else if (ugd->op_status != BT_DEACTIVATING &&
1247 ugd->op_status != BT_ACTIVATING) {
1248 ret = bt_adapter_disable();
1249 if (ret != BT_ERROR_NONE) {
1250 BT_ERR("Failed to disable bluetooth [%d]", ret);
1252 ugd->op_status = BT_DEACTIVATING;
1253 elm_object_disabled_set(ugd->scan_btn, EINA_TRUE);
1257 if (ugd->op_status == BT_ACTIVATING ||
1258 ugd->op_status == BT_DEACTIVATING) {
1259 elm_genlist_item_fields_update(ugd->onoff_item, "*",
1260 ELM_GENLIST_ITEM_FIELD_TEXT);
1261 elm_genlist_item_fields_update(ugd->onoff_item, "*",
1262 ELM_GENLIST_ITEM_FIELD_CONTENT);
1267 static void __bt_main_controlbar_btn_cb(void *data, Evas_Object *obj,
1272 bt_ug_data *ugd = NULL;
1274 retm_if(data == NULL, "Invalid argument: bt_ug_data is NULL");
1276 ugd = (bt_ug_data *)data;
1278 if (ugd->op_status == BT_SEARCHING) {
1279 if (ugd->is_discovery_started) {
1280 if (bt_adapter_stop_device_discovery() == BT_ERROR_NONE) {
1281 elm_object_disabled_set(ugd->scan_btn, EINA_TRUE);
1282 elm_object_text_set(ugd->scan_btn, BT_STR_STOP);
1283 } else { /*the case in which stop discovery returns error from Bluez*/
1284 ugd->op_status = BT_ACTIVATED;
1285 elm_object_text_set(ugd->scan_btn, BT_STR_SCAN);
1287 if (ugd->searched_title == NULL)
1288 _bt_main_add_searched_title(ugd);
1289 _bt_update_genlist_item((Elm_Object_Item *)
1290 ugd->searched_title);
1293 } else { /*ugd->op_status != BT_SEARCHING */
1294 _bt_main_scan_device(ugd);
1300 static void __bt_main_disconnect_cb(void *data, Evas_Object *obj,
1305 bt_dev_t *dev = NULL;
1306 bt_ug_data *ugd = NULL;
1308 retm_if(data == NULL, "Invalid argument: data is NULL");
1310 dev = (bt_dev_t *)data;
1311 retm_if(dev->ugd == NULL, "ugd is NULL");
1316 evas_object_del(ugd->popup);
1320 _bt_main_disconnect_device(ugd, dev);
1325 static int __bt_main_request_to_send(bt_ug_data *ugd, bt_dev_t *dev)
1327 obex_ipc_param_t param;
1329 char **array_val = NULL;
1334 BT_DBG("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
1335 dev->bd_addr[0], dev->bd_addr[1],
1336 dev->bd_addr[2], dev->bd_addr[3],
1337 dev->bd_addr[4], dev->bd_addr[5]);
1339 memset(¶m, 0x00, sizeof(obex_ipc_param_t));
1340 memcpy(param.addr, dev->bd_addr, BT_ADDRESS_LENGTH_MAX);
1342 ret = app_control_get_extra_data_array(ugd->service, "files",
1344 if (ret != APP_CONTROL_ERROR_NONE) {
1345 BT_ERR("Get data error");
1349 if (array_val == NULL)
1352 param.file_cnt = cnt;
1353 param.filepath = g_new0(char *, cnt + 1);
1354 for (i = 0; i < cnt; i++) {
1356 param.filepath[i] = g_strdup(array_val[i]);
1357 DBG_SECURE("%s", param.filepath[i]);
1359 array_val[i] = NULL;
1365 param.dev_name = g_strdup(dev->name);
1367 if (app_control_get_extra_data(ugd->service, "type", &value) < 0)
1368 BT_ERR("Get data error");
1373 param.type = g_strdup(value);
1376 if (_bt_ipc_send_obex_message(¶m, ugd) != BT_UG_ERROR_NONE)
1379 g_free(param.dev_name);
1381 if (param.filepath) {
1382 for (i = 0; param.filepath[i] != NULL; i++)
1383 g_free(param.filepath[i]);
1384 g_free(param.filepath);
1387 return BT_UG_ERROR_NONE;
1391 for (i = 0; i < cnt; i++) {
1397 _bt_main_launch_syspopup(ugd, BT_SYSPOPUP_REQUEST_NAME,
1398 BT_STR_UNABLE_TO_SEND,
1399 BT_SYSPOPUP_ONE_BUTTON_TYPE);
1401 g_free(param.dev_name);
1403 if (param.filepath) {
1404 for (i = 0; param.filepath[i] != NULL; i++)
1405 g_free(param.filepath[i]);
1406 g_free(param.filepath);
1412 static void __bt_main_paired_item_sel_cb(void *data, Evas_Object *obj,
1417 bt_ug_data *ugd = NULL;
1418 bt_dev_t *dev = NULL;
1419 Elm_Object_Item *item = NULL;
1420 Evas_Object *btn = NULL;
1421 Evas_Object *popup_btn = NULL;
1425 elm_genlist_item_selected_set((Elm_Object_Item *) event_info,
1428 retm_if(data == NULL, "Invalid argument: bt_ug_data is NULL");
1430 ugd = (bt_ug_data *)data;
1431 item = (Elm_Object_Item *) event_info;
1433 ret_if(ugd->waiting_service_response == TRUE);
1434 ret_if(ugd->op_status == BT_PAIRING);
1436 if (ugd->op_status == BT_SEARCHING) {
1437 ret = bt_adapter_stop_device_discovery();
1438 if (ret != BT_ERROR_NONE) {
1439 BT_ERR("Fail to stop discovery");
1444 dev = _bt_main_get_dev_info(ugd->paired_device, item);
1445 retm_if(dev == NULL, "Invalid argument: device info is NULL");
1446 retm_if(dev->status != BT_IDLE,
1447 "Connecting / Disconnecting is in progress");
1449 if ((ugd->waiting_service_response) && (dev->service_list == 0)) {
1450 ugd->paired_item = item;
1452 _bt_main_popup_del_cb(ugd, NULL, NULL);
1454 ugd->popup_data.type = BT_POPUP_GETTING_SERVICE_LIST;
1455 ugd->popup = _bt_create_popup(ugd, _bt_main_popup_del_cb,
1458 retm_if(ugd->popup == NULL, "fail to create popup!");
1459 btn = elm_button_add(ugd->popup);
1460 elm_object_style_set(btn, "popup");
1461 elm_object_domain_translatable_text_set(
1463 PKGNAME, "IDS_BT_BUTTON_OK");
1464 elm_object_part_content_set(ugd->popup, "button1", btn);
1465 evas_object_smart_callback_add(btn, "clicked", (Evas_Smart_Cb)
1466 _bt_main_popup_del_cb, ugd);
1468 eext_object_event_callback_add(ugd->popup, EEXT_CALLBACK_BACK,
1469 _bt_main_popup_del_cb, ugd);
1471 evas_object_show(ugd->popup);
1475 if (ugd->bt_launch_mode == BT_LAUNCH_NORMAL ||
1476 ugd->bt_launch_mode == BT_LAUNCH_CONNECT_HEADSET ||
1477 ugd->bt_launch_mode == BT_LAUNCH_USE_NFC ||
1478 ugd->bt_launch_mode == BT_LAUNCH_HELP) {
1480 ugd->paired_item = item;
1482 if (dev->service_list == 0) {
1483 if (bt_device_start_service_search
1484 ((const char *)dev->addr_str) == BT_ERROR_NONE) {
1486 dev->status = BT_SERVICE_SEARCHING;
1487 ugd->waiting_service_response = TRUE;
1488 ugd->request_timer =
1489 ecore_timer_add(BT_SEARCH_SERVICE_TIMEOUT,
1491 _bt_main_service_request_cb,
1494 _bt_update_genlist_item(ugd->paired_item);
1497 BT_ERR("service search error");
1502 if (dev->is_connected == 0) {
1503 /* Not connected case */
1504 _bt_main_connect_device(ugd, dev);
1507 _bt_main_popup_del_cb(ugd, NULL, NULL);
1509 ugd->popup_data.type = BT_POPUP_DISCONNECT;
1510 ugd->popup_data.data = g_strdup(dev->name);
1511 ugd->popup = _bt_create_popup(ugd, NULL, NULL, 0);
1512 retm_if(!ugd->popup , "fail to create popup!");
1514 popup_btn = elm_button_add(ugd->popup);
1516 elm_object_style_set(popup_btn, "popup");
1517 elm_object_domain_translatable_text_set(
1519 PKGNAME, "IDS_BR_SK_CANCEL");
1520 elm_object_part_content_set(ugd->popup, "button1",
1522 evas_object_smart_callback_add(popup_btn, "clicked",
1523 _bt_main_popup_del_cb,
1527 popup_btn = elm_button_add(ugd->popup);
1529 elm_object_style_set(popup_btn, "popup");
1530 elm_object_domain_translatable_text_set(
1532 PKGNAME, "IDS_BT_SK_DISCONNECT");
1533 elm_object_part_content_set(ugd->popup, "button2",
1535 evas_object_smart_callback_add(popup_btn, "clicked",
1536 __bt_main_disconnect_cb,
1538 eext_object_event_callback_add(ugd->popup, EEXT_CALLBACK_BACK,
1539 eext_popup_back_cb, NULL);
1541 evas_object_show(ugd->popup);
1544 } else if (ugd->bt_launch_mode == BT_LAUNCH_SEND_FILE) {
1545 if (_bt_util_is_battery_low() == TRUE) {
1546 /* Battery is critical low */
1547 _bt_main_create_information_popup(ugd, BT_STR_LOW_BATTERY);
1551 if (__bt_main_request_to_send(ugd, dev) == BT_UG_ERROR_NONE)
1552 BT_DBG("Request file sending");
1554 _bt_ug_destroy(ugd, NULL);
1555 } else if (ugd->bt_launch_mode == BT_LAUNCH_PICK) {
1556 ugd->pick_device = dev;
1557 g_idle_add((GSourceFunc) _bt_idle_destroy_ug, ugd);
1563 static void __bt_main_searched_item_sel_cb(void *data, Evas_Object *obj,
1568 bt_ug_data *ugd = NULL;
1569 bt_dev_t *dev = NULL;
1570 Elm_Object_Item *item = NULL;
1574 elm_genlist_item_selected_set((Elm_Object_Item *) event_info,
1577 retm_if(data == NULL, "Invalid argument: bt_ug_data is NULL");
1579 ugd = (bt_ug_data *)data;
1581 ret_if(ugd->op_status == BT_PAIRING);
1583 item = (Elm_Object_Item *) event_info;
1585 dev = _bt_main_get_dev_info(ugd->searched_device,
1586 (Elm_Object_Item *) event_info);
1587 retm_if(dev == NULL, "Invalid argument: device info is NULL");
1589 if (ugd->bt_launch_mode == BT_LAUNCH_USE_NFC) {
1590 char address[18] = { 0 };
1591 app_control_h service = NULL;
1593 app_control_create(&service);
1595 ret_if(service == NULL);
1597 BT_DBG("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X", dev->bd_addr[0],
1598 dev->bd_addr[1], dev->bd_addr[2], dev->bd_addr[3],
1599 dev->bd_addr[4], dev->bd_addr[5]);
1601 _bt_util_addr_type_to_addr_string(address, dev->bd_addr);
1603 if (app_control_add_extra_data(service, "device_address",
1604 (const char *)address) < 0) {
1605 BT_ERR("Fail to add extra data");
1608 if (app_control_add_extra_data(service, "device_name",
1609 (const char *)dev->name) < 0) {
1610 BT_ERR("Fail to add extra data");
1613 _bt_ug_destroy(ugd, (void *)service);
1615 app_control_destroy(service);
1618 } else if (ugd->bt_launch_mode == BT_LAUNCH_PICK) {
1619 ugd->pick_device = dev;
1620 g_idle_add((GSourceFunc) _bt_idle_destroy_ug, ugd);
1624 ugd->searched_item = item;
1626 if (_bt_util_is_battery_low() == TRUE) {
1627 /* Battery is critical low */
1628 _bt_main_create_information_popup(ugd, BT_STR_LOW_BATTERY);
1632 if (ugd->op_status == BT_SEARCHING) {
1633 ret = bt_adapter_stop_device_discovery();
1634 if (ret != BT_ERROR_NONE)
1635 BT_ERR("Fail to stop discovery");
1638 if (ugd->bt_launch_mode == BT_LAUNCH_SEND_FILE) {
1640 if (__bt_main_request_to_send(ugd, dev) == BT_UG_ERROR_NONE) {
1641 BT_DBG("Request file sending");
1644 _bt_ug_destroy(ugd, NULL);
1648 if (_bt_main_request_pairing_with_effect(ugd, item) != BT_UG_ERROR_NONE) {
1649 ugd->searched_item = NULL;
1655 static void __bt_main_gl_highlighted(void *data, Evas_Object *obj,
1662 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
1664 ret_if(item == NULL);
1666 ugd = (bt_ug_data *)data;
1667 ret_if(ugd == NULL);
1669 dev = _bt_main_get_dev_info(ugd->paired_device, item);
1671 dev = _bt_main_get_dev_info(ugd->searched_device, item);
1673 ret_if(dev == NULL);
1675 dev->highlighted = TRUE;
1678 elm_genlist_item_fields_update(item, "*", ELM_GENLIST_ITEM_FIELD_TEXT);
1683 static void __bt_main_gl_unhighlighted(void *data, Evas_Object *obj,
1690 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
1692 ret_if(item == NULL);
1694 ugd = (bt_ug_data *)data;
1695 ret_if(ugd == NULL);
1697 dev = _bt_main_get_dev_info(ugd->paired_device, item);
1699 dev = _bt_main_get_dev_info(ugd->searched_device, item);
1701 ret_if(dev == NULL);
1703 dev->highlighted = FALSE;
1706 elm_genlist_item_fields_update(item, "*", ELM_GENLIST_ITEM_FIELD_TEXT);
1711 void _bt_main_add_device_name_item(bt_ug_data *ugd, Evas_Object *genlist)
1714 retm_if(ugd->op_status == BT_DEACTIVATED, "BT is turned off");
1716 Elm_Object_Item *git = NULL;
1718 git = elm_genlist_item_insert_after(genlist, ugd->device_name_itc, ugd, NULL,
1719 ugd->onoff_item, ELM_GENLIST_ITEM_NONE, NULL, NULL);
1720 elm_genlist_item_select_mode_set(git, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1722 ugd->device_name_item = git;
1727 static Evas_Object *__bt_main_add_genlist_dialogue(Evas_Object *parent,
1731 retv_if(ugd == NULL, NULL);
1733 Evas_Object *genlist = NULL;
1734 Elm_Object_Item *git = NULL;
1736 genlist = elm_genlist_add(parent);
1737 retv_if(!genlist, NULL);
1738 /* We shoud set the mode to compress
1739 for using dialogue/2text.2icon.3.tb */
1740 elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
1741 elm_genlist_homogeneous_set(genlist, EINA_FALSE);
1742 elm_genlist_block_count_set(genlist, 3);
1744 evas_object_smart_callback_add(genlist, "highlighted",
1745 __bt_main_gl_highlighted, ugd);
1747 evas_object_smart_callback_add(genlist, "unhighlighted",
1748 __bt_main_gl_unhighlighted, ugd);
1750 ugd->on_itc = elm_genlist_item_class_new();
1751 retv_if(ugd->on_itc == NULL, NULL);
1753 ugd->on_itc->item_style = BT_GENLIST_1LINE_TEXT_ICON_STYLE;
1754 ugd->on_itc->func.text_get = __bt_main_onoff_label_get;
1755 ugd->on_itc->func.content_get = __bt_main_onoff_icon_get;
1756 ugd->on_itc->func.state_get = NULL;
1757 ugd->on_itc->func.del = NULL;
1759 /* Set item class for dialogue seperator */
1760 ugd->off_itc = elm_genlist_item_class_new();
1761 retv_if(ugd->off_itc == NULL, NULL);
1763 ugd->off_itc->item_style = BT_GENLIST_MULTILINE_TEXT_STYLE;
1764 ugd->off_itc->func.text_get = __bt_main_onoff_label_get;
1765 ugd->off_itc->func.content_get = __bt_main_onoff_icon_get;
1766 ugd->off_itc->func.state_get = NULL;
1767 ugd->off_itc->func.del = NULL;
1769 /* Set item class for paired dialogue title */
1770 ugd->device_name_itc = elm_genlist_item_class_new();
1771 retv_if(ugd->device_name_itc == NULL, NULL);
1773 ugd->device_name_itc->item_style = BT_GENLIST_2LINE_BOTTOM_TEXT_STYLE;
1774 ugd->device_name_itc->func.text_get = __bt_main_device_label_get;
1775 ugd->device_name_itc->func.content_get = NULL;
1776 ugd->device_name_itc->func.state_get = NULL;
1777 ugd->device_name_itc->func.del = NULL;
1779 /* Set item class for paired dialogue title */
1780 ugd->paired_title_itc = elm_genlist_item_class_new();
1781 retv_if(ugd->paired_title_itc == NULL, NULL);
1783 ugd->paired_title_itc->item_style = BT_GENLIST_GROUP_INDEX_STYLE;
1784 ugd->paired_title_itc->func.text_get = __bt_main_paired_title_label_get;
1785 ugd->paired_title_itc->func.content_get = NULL;
1786 ugd->paired_title_itc->func.state_get = NULL;
1787 ugd->paired_title_itc->func.del = NULL;
1789 /* Set item class for searched dialogue title */
1790 ugd->searched_title_itc = elm_genlist_item_class_new();
1791 retv_if(ugd->searched_title_itc == NULL, NULL);
1793 ugd->searched_title_itc->item_style = BT_GENLIST_GROUP_INDEX_STYLE;
1794 ugd->searched_title_itc->func.text_get = __bt_main_searched_title_label_get;
1795 ugd->searched_title_itc->func.content_get = __bt_main_searched_title_icon_get;
1796 ugd->searched_title_itc->func.state_get = NULL;
1797 ugd->searched_title_itc->func.del = NULL;
1799 /* Set item class for paired device */
1800 ugd->paired_device_itc = elm_genlist_item_class_new();
1801 retv_if(ugd->paired_device_itc == NULL, NULL);
1803 ugd->paired_device_itc->item_style = BT_GENLIST_2LINE_TOP_TEXT_ICON_STYLE;
1804 ugd->paired_device_itc->func.text_get = __bt_main_paired_device_label_get;
1805 ugd->paired_device_itc->func.content_get = __bt_main_paired_device_icon_get;
1806 ugd->paired_device_itc->func.state_get = NULL;
1807 ugd->paired_device_itc->func.del = NULL;
1809 /* Set item class for searched device */
1810 ugd->searched_device_itc = elm_genlist_item_class_new();
1811 retv_if(ugd->searched_device_itc == NULL, NULL);
1813 ugd->searched_device_itc->item_style = BT_GENLIST_1LINE_TEXT_ICON_STYLE;
1814 ugd->searched_device_itc->func.text_get = __bt_main_searched_label_get;
1815 ugd->searched_device_itc->func.content_get = __bt_main_searched_icon_get;
1816 ugd->searched_device_itc->func.state_get = NULL;
1817 ugd->searched_device_itc->func.del = NULL;
1819 /* Set item class for no device */
1820 ugd->no_device_itc = elm_genlist_item_class_new();
1821 retv_if(ugd->no_device_itc == NULL, NULL);
1823 ugd->no_device_itc->item_style = BT_GENLIST_1LINE_TEXT_STYLE;
1824 ugd->no_device_itc->func.text_get = __bt_main_no_device_label_get;
1825 ugd->no_device_itc->func.content_get = NULL;
1826 ugd->no_device_itc->func.state_get = NULL;
1827 ugd->no_device_itc->func.del = NULL;
1829 if (ugd->op_status == BT_DEACTIVATED ||
1830 ugd->op_status == BT_ACTIVATING)
1831 git = elm_genlist_item_append(genlist, ugd->off_itc, ugd, NULL,
1832 ELM_GENLIST_ITEM_NONE,
1833 __bt_main_onoff_btn_cb, ugd);
1835 git = elm_genlist_item_append(genlist, ugd->on_itc, ugd, NULL,
1836 ELM_GENLIST_ITEM_NONE,
1837 __bt_main_onoff_btn_cb, ugd);
1839 ugd->onoff_item = git;
1841 if (_bt_util_is_dpm_restricted(ugd->dpm_handle) == TRUE)
1842 elm_object_item_disabled_set(ugd->onoff_item, EINA_TRUE);
1844 _bt_main_add_device_name_item(ugd, genlist);
1846 evas_object_show(genlist);
1852 static Evas_Object *__bt_main_add_visibility_dialogue(Evas_Object * parent,
1856 retv_if(ugd == NULL, NULL);
1858 Evas_Object *genlist = NULL;
1859 Elm_Object_Item *git = NULL;
1861 genlist = elm_genlist_add(parent);
1862 /* We shoud set the mode to compress
1863 for using dialogue/2text.2icon.3.tb */
1864 elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
1865 elm_genlist_homogeneous_set(genlist, EINA_FALSE);
1866 elm_genlist_block_count_set(genlist, 3);
1868 evas_object_smart_callback_add(genlist, "highlighted",
1869 __bt_main_gl_highlighted, ugd);
1871 evas_object_smart_callback_add(genlist, "unhighlighted",
1872 __bt_main_gl_unhighlighted, ugd);
1874 ugd->on_itc = elm_genlist_item_class_new();
1875 retv_if(ugd->on_itc == NULL, NULL);
1877 ugd->on_itc->item_style = BT_GENLIST_1LINE_TEXT_ICON_STYLE;
1878 ugd->on_itc->func.text_get = __bt_main_onoff_label_get;
1879 ugd->on_itc->func.content_get = __bt_main_onoff_icon_get;
1880 ugd->on_itc->func.state_get = NULL;
1881 ugd->on_itc->func.del = NULL;
1883 /* Set item class for dialogue seperator */
1884 ugd->off_itc = elm_genlist_item_class_new();
1885 retv_if(ugd->off_itc == NULL, NULL);
1887 ugd->off_itc->item_style = BT_GENLIST_MULTILINE_TEXT_STYLE;
1888 ugd->off_itc->func.text_get = __bt_main_onoff_label_get;
1889 ugd->off_itc->func.content_get = __bt_main_onoff_icon_get;
1890 ugd->off_itc->func.state_get = NULL;
1891 ugd->off_itc->func.del = NULL;
1893 /* Set item class for paired dialogue title */
1894 ugd->device_name_itc = elm_genlist_item_class_new();
1895 retv_if(ugd->device_name_itc == NULL, NULL);
1897 ugd->device_name_itc->item_style = BT_GENLIST_2LINE_BOTTOM_TEXT_STYLE;
1898 ugd->device_name_itc->func.text_get = __bt_main_device_label_get;
1899 ugd->device_name_itc->func.content_get = NULL;
1900 ugd->device_name_itc->func.state_get = NULL;
1901 ugd->device_name_itc->func.del = NULL;
1903 if (ugd->op_status == BT_DEACTIVATED ||
1904 ugd->op_status == BT_ACTIVATING)
1905 git = elm_genlist_item_append(genlist, ugd->off_itc, ugd, NULL,
1906 ELM_GENLIST_ITEM_NONE,
1907 __bt_main_onoff_btn_cb, ugd);
1909 git = elm_genlist_item_append(genlist, ugd->on_itc, ugd, NULL,
1910 ELM_GENLIST_ITEM_NONE,
1911 __bt_main_onoff_btn_cb, ugd);
1912 ugd->onoff_item = git;
1914 _bt_main_add_device_name_item(ugd, genlist);
1915 evas_object_show(genlist);
1921 static Evas_Object *__bt_main_add_onoff_dialogue(Evas_Object * parent,
1925 retv_if(ugd == NULL, NULL);
1927 Evas_Object *genlist = NULL;
1928 Elm_Object_Item *git = NULL;
1930 genlist = elm_genlist_add(parent);
1931 /* We shoud set the mode to compress
1932 for using dialogue/2text.2icon.3.tb */
1933 elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
1934 elm_genlist_homogeneous_set(genlist, EINA_FALSE);
1935 elm_genlist_block_count_set(genlist, 3);
1937 evas_object_smart_callback_add(genlist, "highlighted",
1938 __bt_main_gl_highlighted, ugd);
1940 evas_object_smart_callback_add(genlist, "unhighlighted",
1941 __bt_main_gl_unhighlighted, ugd);
1943 ugd->on_itc = elm_genlist_item_class_new();
1944 retv_if(ugd->on_itc == NULL, NULL);
1946 ugd->on_itc->item_style = BT_GENLIST_1LINE_TEXT_ICON_STYLE;
1947 ugd->on_itc->func.text_get = __bt_main_onoff_label_get;
1948 ugd->on_itc->func.content_get = __bt_main_onoff_icon_get;
1949 ugd->on_itc->func.state_get = NULL;
1950 ugd->on_itc->func.del = NULL;
1952 /* Set item class for dialogue seperator */
1953 ugd->off_itc = elm_genlist_item_class_new();
1954 retv_if(ugd->off_itc == NULL, NULL);
1956 ugd->off_itc->item_style = BT_GENLIST_MULTILINE_TEXT_STYLE;
1957 ugd->off_itc->func.text_get = __bt_main_onoff_label_get;
1958 ugd->off_itc->func.content_get = __bt_main_onoff_icon_get;
1959 ugd->off_itc->func.state_get = NULL;
1960 ugd->off_itc->func.del = NULL;
1962 /* Set item class for paired dialogue title */
1963 ugd->device_name_itc = elm_genlist_item_class_new();
1964 retv_if(ugd->device_name_itc == NULL, NULL);
1966 ugd->device_name_itc->item_style = BT_GENLIST_2LINE_BOTTOM_TEXT_STYLE;
1967 ugd->device_name_itc->func.text_get = __bt_main_device_label_get;
1968 ugd->device_name_itc->func.content_get = NULL;
1969 ugd->device_name_itc->func.state_get = NULL;
1970 ugd->device_name_itc->func.del = NULL;
1973 if (ugd->op_status == BT_DEACTIVATED ||
1974 ugd->op_status == BT_ACTIVATING)
1975 git = elm_genlist_item_append(genlist, ugd->off_itc, ugd, NULL,
1976 ELM_GENLIST_ITEM_NONE,
1977 __bt_main_onoff_btn_cb, ugd);
1979 git = elm_genlist_item_append(genlist, ugd->on_itc, ugd, NULL,
1980 ELM_GENLIST_ITEM_NONE,
1981 __bt_main_onoff_btn_cb, ugd);
1982 ugd->onoff_item = git;
1984 _bt_main_add_device_name_item(ugd, genlist);
1985 evas_object_show(genlist);
1991 static gboolean __bt_main_system_popup_timer_cb(gpointer user_data)
1999 retv_if(user_data == NULL, FALSE);
2001 ugd = (bt_ug_data *)user_data;
2003 b = ugd->popup_bundle;
2006 BT_ERR("bundle is NULL");
2010 ret = syspopup_launch("bt-syspopup", b);
2012 BT_ERR("Sorry cannot launch popup");
2014 BT_DBG("Finally Popup launched");
2019 return (ret < 0) ? TRUE : FALSE;
2022 static bool __bt_main_get_mime_type(char *file)
2026 char mime_type[BT_FILE_NAME_LEN_MAX] = { 0, };
2027 int len = strlen("image");
2029 retv_if(file == NULL, FALSE);
2031 if (aul_get_mime_from_file(file, mime_type,
2032 BT_FILE_NAME_LEN_MAX) == AUL_R_OK) {
2033 BT_INFO("mime type=[%s]", mime_type);
2034 if (0 != strncmp(mime_type, "image", len))
2037 BT_ERR("Error getting mime type");
2045 static bool __bt_main_is_image_file(app_control_h service)
2050 int number_of_files = 0;
2055 retvm_if(service == NULL, FALSE, "Invalid data bundle");
2057 if (app_control_get_extra_data(service, "filecount", &value) < 0)
2058 BT_ERR("Get data error");
2060 retv_if(value == NULL, FALSE);
2062 number_of_files = atoi(value);
2063 BT_INFO("[%d] files", number_of_files);
2067 if (number_of_files <= 0) {
2072 if (app_control_get_extra_data(service, "files", &value) < 0)
2073 BT_ERR("Get data error");
2075 retv_if(value == NULL, FALSE);
2078 while (((token = strstr(param, "?")) != NULL) && i < number_of_files) {
2080 if (!__bt_main_get_mime_type(param)) {
2085 BT_INFO("File [%d] [%s]", i, param);
2090 if (i == (number_of_files - 1)) {
2091 if (!__bt_main_get_mime_type(param)) {
2095 BT_INFO("File [%d] [%s]", i, param);
2097 BT_ERR("Count not match : [%d] / [%d]", number_of_files, i);
2108 /**********************************************************************
2110 ***********************************************************************/
2112 void _bt_main_scan_device(bt_ug_data *ugd)
2117 ret_if(ugd == NULL);
2119 if (ugd->op_status != BT_DEACTIVATED && ugd->op_status != BT_ACTIVATED) {
2120 BT_INFO("current bluetooth status [%d]", ugd->op_status);
2124 if (_bt_util_is_battery_low() == TRUE) {
2125 /* Battery is critical low */
2126 _bt_main_create_information_popup(ugd, BT_STR_LOW_BATTERY);
2130 if (ugd->op_status == BT_DEACTIVATED) {
2131 ret = _bt_main_enable_bt((void *)ugd);
2133 elm_object_disabled_set(ugd->scan_btn, EINA_TRUE);
2136 ret = bt_adapter_start_device_discovery();
2138 /* Disable the Scan button till the BLUETOOTH_EVENT_DISCOVERY_STARTED is received */
2139 elm_object_disabled_set(ugd->scan_btn, EINA_TRUE);
2140 _bt_main_remove_all_searched_devices(ugd);
2141 ugd->op_status = BT_SEARCHING;
2142 elm_object_text_set(ugd->scan_btn, BT_STR_STOP);
2144 if (ugd->searched_title == NULL)
2145 _bt_main_add_searched_title(ugd);
2147 BT_ERR("Operation failed : Error Cause[%d]", ret);
2154 int _bt_main_service_request_cb(void *data)
2158 bt_ug_data *ugd = NULL;
2160 retvm_if(data == NULL, BT_UG_FAIL,
2161 "Invalid argument: bt_ug_data is NULL");
2163 ugd = (bt_ug_data *)data;
2165 if (ugd->request_timer) {
2166 ecore_timer_del(ugd->request_timer);
2167 ugd->request_timer = NULL;
2170 /* Need to modify API: Address parameter */
2171 if (ugd->waiting_service_response == TRUE) {
2172 bt_dev_t *dev = NULL;
2174 ugd->waiting_service_response = FALSE;
2175 bt_device_cancel_service_search();
2178 _bt_main_get_dev_info(ugd->paired_device, ugd->paired_item);
2179 retvm_if(dev == NULL, BT_UG_FAIL, "dev is NULL");
2181 dev->status = BT_IDLE;
2182 _bt_update_genlist_item(ugd->paired_item);
2183 _bt_main_connect_device(ugd, dev);
2185 ugd->paired_item = NULL;
2189 return BT_UG_ERROR_NONE;
2192 #ifdef KIRAN_ACCESSIBILITY
2193 char *__bt_main_get_device_string(int major_class, int minor_class)
2196 char *device_type = NULL;
2198 BT_DBG("major_class: 0x%x, minor_class: 0x%x", major_class,
2201 switch (major_class) {
2202 case BT_MAJOR_DEV_CLS_COMPUTER:
2203 device_type = g_strdup(BT_STR_COMPUTER);
2205 case BT_MAJOR_DEV_CLS_PHONE:
2206 device_type = g_strdup(BT_STR_PHONE);
2208 case BT_MAJOR_DEV_CLS_AUDIO:
2209 if (minor_class == BTAPP_MIN_DEV_CLS_HEADPHONES)
2210 device_type = g_strdup(BT_STR_SVC_STEREO);
2212 device_type = g_strdup(BT_STR_SVC_HEADSET);
2214 case BT_MAJOR_DEV_CLS_LAN_ACCESS_POINT:
2215 device_type = g_strdup(BT_STR_LAN_ACCESS_POINT);
2217 case BT_MAJOR_DEV_CLS_IMAGING:
2218 if (minor_class == BTAPP_MIN_DEV_CLS_PRINTER)
2219 device_type = g_strdup(BT_STR_PRINTER);
2220 else if (minor_class == BTAPP_MIN_DEV_CLS_CAMERA)
2221 device_type = g_strdup(BT_STR_CAMERA);
2222 else if (minor_class == BTAPP_MIN_DEV_CLS_DISPLAY)
2223 device_type = g_strdup(BT_STR_DISPLAY);
2225 case BT_MAJOR_DEV_CLS_PERIPHERAL:
2226 if (minor_class == BTAPP_MIN_DEV_CLS_KEY_BOARD)
2227 device_type = g_strdup(BT_STR_KEYBOARD);
2228 else if (minor_class == BTAPP_MIN_DEV_CLS_POINTING_DEVICE)
2229 device_type = g_strdup(BT_STR_MOUSE);
2230 else if (minor_class == BTAPP_MIN_DEV_CLS_GAME_PAD)
2231 device_type = g_strdup(BT_STR_GAMING_DEVICE);
2233 device_type = g_strdup(BT_STR_MOUSE);
2235 case BT_MAJOR_DEV_CLS_HEALTH:
2236 device_type = g_strdup(BT_STR_HEALTH_DEVICE);
2239 device_type = g_strdup(BT_STR_UNKNOWN);
2243 if (device_type == NULL)
2244 device_type = g_strdup(BT_STR_UNKNOWN);
2251 char *_bt_main_get_device_icon(int major_class, int minor_class,
2252 int connected, gboolean highlighted)
2254 char *icon = BT_ICON_UNKNOWN;
2256 switch (major_class) {
2257 case BT_MAJOR_DEV_CLS_COMPUTER:
2260 case BT_MAJOR_DEV_CLS_PHONE:
2261 icon = BT_ICON_PHONE;
2263 case BT_MAJOR_DEV_CLS_AUDIO:
2264 if (minor_class == BTAPP_MIN_DEV_CLS_HEADPHONES)
2265 icon = BT_ICON_HEADPHONE;
2266 else if (minor_class == BTAPP_MIN_DEV_CLS_VIDEO_DISPLAY_AND_LOUD_SPEAKER)
2267 icon = BT_ICON_DISPLAY;
2269 icon = BT_ICON_HEADSET;
2271 case BT_MAJOR_DEV_CLS_LAN_ACCESS_POINT:
2272 icon = BT_ICON_NETWORK;
2274 case BT_MAJOR_DEV_CLS_IMAGING:
2275 if (minor_class == BTAPP_MIN_DEV_CLS_PRINTER)
2276 icon = BT_ICON_PRINTER;
2277 else if (minor_class == BTAPP_MIN_DEV_CLS_CAMERA)
2278 icon = BT_ICON_CAMERA;
2279 else if (minor_class == BTAPP_MIN_DEV_CLS_DISPLAY)
2280 icon = BT_ICON_DISPLAY;
2282 case BT_MAJOR_DEV_CLS_PERIPHERAL:
2283 if (minor_class == BTAPP_MIN_DEV_CLS_KEY_BOARD)
2284 icon = BT_ICON_KEYBOARD;
2285 else if (minor_class == BTAPP_MIN_DEV_CLS_POINTING_DEVICE)
2286 icon = BT_ICON_MOUSE;
2287 else if (minor_class == BTAPP_MIN_DEV_CLS_GAME_PAD)
2288 icon = BT_ICON_GAMING;
2290 icon = BT_ICON_MOUSE;
2292 case BT_MAJOR_DEV_CLS_HEALTH:
2293 icon = BT_ICON_HEALTH;
2296 case BT_MAJOR_DEV_CLS_WEARABLE:
2297 if (minor_class == BTAPP_MIN_DEV_CLS_WRIST_WATCH)
2298 icon = BT_ICON_WATCH;
2300 icon = BT_ICON_UNKNOWN;
2303 icon = BT_ICON_UNKNOWN;
2310 void _bt_main_popup_del_cb(void *data, Evas_Object *obj, void *event_info)
2313 retm_if(data == NULL, "Invalid argument: struct bt_appdata is NULL");
2315 bt_ug_data *ugd = (bt_ug_data *)data;
2318 evas_object_del(ugd->popup);
2321 if (ugd->popup_data.data)
2322 g_free(ugd->popup_data.data);
2323 ugd->popup_data.data = NULL;
2325 ugd->back_cb = NULL;
2330 void _bt_back_btn_popup_del_cb(void *data, Evas_Object *obj, void *event_info)
2333 retm_if(data == NULL, "Invalid argument: struct bt_appdata is NULL");
2335 bt_ug_data *ugd = (bt_ug_data *)data;
2338 BT_DBG("Deleting popup");
2339 evas_object_del(ugd->popup);
2343 ugd->op_status = BT_ACTIVATED;
2348 Elm_Object_Item *_bt_main_add_paired_device_on_bond(bt_ug_data *ugd, bt_dev_t *dev)
2352 Elm_Object_Item *git = NULL;
2354 retvm_if(ugd == NULL, NULL, "Invalid argument: ugd is NULL");
2355 retvm_if(dev == NULL, NULL, "Invalid argument: dev is NULL");
2357 /* Paired device Title */
2358 if (ugd->paired_title == NULL) {
2359 if (ugd->searched_title == NULL) {
2360 git = elm_genlist_item_append(ugd->main_genlist,
2361 ugd->paired_title_itc,
2363 ELM_GENLIST_ITEM_NONE,
2365 elm_genlist_item_select_mode_set(git,
2366 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
2368 git = elm_genlist_item_insert_before(ugd->main_genlist,
2369 ugd->paired_title_itc,
2371 ugd->searched_title,
2372 ELM_GENLIST_ITEM_NONE,
2374 elm_genlist_item_select_mode_set(git,
2375 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
2378 ugd->paired_title = git;
2381 dev->ugd = (void *)ugd;
2382 dev->is_bonded = TRUE;
2383 dev->status = BT_IDLE;
2385 /* Add the device item in the list */
2386 if (ugd->paired_device == NULL) {
2387 git = elm_genlist_item_insert_after(ugd->main_genlist,
2388 ugd->paired_device_itc, dev, NULL,
2390 ELM_GENLIST_ITEM_NONE,
2391 __bt_main_paired_item_sel_cb,
2394 bt_dev_t *item_dev = NULL;
2395 Elm_Object_Item *item = NULL;
2396 Elm_Object_Item *next = NULL;
2398 item = elm_genlist_item_next_get(ugd->paired_title);
2400 while (item != NULL || item != ugd->searched_title) {
2401 item_dev = _bt_main_get_dev_info(ugd->paired_device, item);
2403 if (item_dev && item_dev->is_connected > 0) {
2404 next = elm_genlist_item_next_get(item);
2405 if (next == NULL || next == ugd->searched_title) {
2406 git = elm_genlist_item_insert_after(ugd->main_genlist,
2407 ugd->paired_device_itc, dev, NULL, item,
2408 ELM_GENLIST_ITEM_NONE,
2409 __bt_main_paired_item_sel_cb,
2415 git = elm_genlist_item_insert_before(ugd->main_genlist,
2416 ugd->paired_device_itc, dev,
2417 NULL, item, ELM_GENLIST_ITEM_NONE,
2418 __bt_main_paired_item_sel_cb, ugd);
2423 dev->genlist_item = git;
2426 return dev->genlist_item;
2429 void _bt_sort_paired_device_list(bt_ug_data *ugd, bt_dev_t *dev, int connected)
2433 bt_dev_t *item = NULL;
2434 Elm_Object_Item *git = NULL;
2435 Eina_List *l = NULL;
2436 Eina_List *l_next = NULL;
2438 retm_if(ugd == NULL, "Invalid argument: ugd is NULL");
2439 retm_if(dev == NULL, "Invalid argument: dev is NULL");
2441 EINA_LIST_FOREACH_SAFE(ugd->paired_device, l, l_next, item) {
2442 if (item && (item == dev)) {
2444 elm_object_item_del(item->genlist_item);
2445 git = elm_genlist_item_insert_after(ugd->main_genlist,
2446 ugd->paired_device_itc, dev, NULL,
2448 ELM_GENLIST_ITEM_NONE,
2449 __bt_main_paired_item_sel_cb,
2451 dev->genlist_item = git;
2454 if (ugd->searched_title) {
2455 elm_object_item_del(item->genlist_item);
2456 git = elm_genlist_item_insert_before(ugd->main_genlist,
2457 ugd->paired_device_itc, dev, NULL,
2458 ugd->searched_title,
2459 ELM_GENLIST_ITEM_NONE,
2460 __bt_main_paired_item_sel_cb,
2462 dev->genlist_item = git;
2465 elm_object_item_del(item->genlist_item);
2466 git = elm_genlist_item_append(ugd->main_genlist,
2467 ugd->paired_device_itc, dev, NULL,
2468 ELM_GENLIST_ITEM_NONE,
2469 __bt_main_paired_item_sel_cb,
2471 dev->genlist_item = git;
2483 Elm_Object_Item *_bt_main_add_paired_device(bt_ug_data *ugd, bt_dev_t *dev)
2487 Elm_Object_Item *git = NULL;
2489 retvm_if(ugd == NULL, NULL, "Invalid argument: ugd is NULL");
2490 retvm_if(dev == NULL, NULL, "Invalid argument: dev is NULL");
2492 /* Paired device Title */
2493 if (ugd->paired_title == NULL) {
2494 if (ugd->searched_title == NULL) {
2495 git = elm_genlist_item_append(ugd->main_genlist,
2496 ugd->paired_title_itc,
2498 ELM_GENLIST_ITEM_NONE,
2500 elm_genlist_item_select_mode_set(git,
2501 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
2503 git = elm_genlist_item_insert_before(ugd->main_genlist,
2504 ugd->paired_title_itc,
2506 ugd->searched_title,
2507 ELM_GENLIST_ITEM_NONE,
2509 elm_genlist_item_select_mode_set(git,
2510 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
2513 ugd->paired_title = git;
2516 dev->ugd = (void *)ugd;
2517 dev->is_bonded = TRUE;
2518 dev->status = BT_IDLE;
2520 /* Add the device item in the list */
2521 if (ugd->paired_device == NULL) {
2522 git = elm_genlist_item_insert_after(ugd->main_genlist,
2523 ugd->paired_device_itc, dev, NULL,
2525 ELM_GENLIST_ITEM_NONE,
2526 __bt_main_paired_item_sel_cb,
2529 if (dev->is_connected > 0) {
2530 git = elm_genlist_item_insert_after(ugd->main_genlist,
2531 ugd->paired_device_itc, dev, NULL,
2533 ELM_GENLIST_ITEM_NONE,
2534 __bt_main_paired_item_sel_cb,
2537 Elm_Object_Item *item = NULL;
2538 Elm_Object_Item *next = NULL;
2540 item = elm_genlist_item_next_get(ugd->paired_title);
2542 while (item != NULL || item != ugd->searched_title) {
2543 next = elm_genlist_item_next_get(item);
2544 if (next == NULL || next == ugd->searched_title) {
2545 git = elm_genlist_item_insert_after(ugd->main_genlist,
2546 ugd->paired_device_itc, dev, NULL, item,
2547 ELM_GENLIST_ITEM_NONE,
2548 __bt_main_paired_item_sel_cb,
2556 dev->genlist_item = git;
2559 return dev->genlist_item;
2562 Elm_Object_Item *_bt_main_add_searched_device(bt_ug_data *ugd, bt_dev_t *dev)
2566 Elm_Object_Item *git = NULL;
2568 retvm_if(ugd == NULL, NULL, "Invalid argument: ugd is NULL");
2569 retvm_if(dev == NULL, NULL, "Invalid argument: dev is NULL");
2571 if (ugd->searched_title == NULL)
2572 _bt_main_add_searched_title(ugd);
2574 retvm_if(ugd->searched_title == NULL, NULL,
2575 "Fail to add searched title genlist item");
2577 /* Searched device Item */
2578 if (ugd->searched_device == NULL) {
2580 elm_genlist_item_insert_after(ugd->main_genlist,
2581 ugd->searched_device_itc, dev, NULL,
2582 ugd->searched_title,
2583 ELM_GENLIST_ITEM_NONE,
2584 __bt_main_searched_item_sel_cb,
2587 bt_dev_t *item_dev = NULL;
2588 Elm_Object_Item *item = NULL;
2589 Elm_Object_Item *next = NULL;
2591 item = elm_genlist_item_next_get(ugd->searched_title);
2593 /* check the RSSI value of searched device list add arrange its order */
2594 while (item != NULL) {
2596 _bt_main_get_dev_info(ugd->searched_device, item);
2597 retv_if(item_dev == NULL, NULL);
2599 if (item_dev->rssi > dev->rssi) {
2600 next = elm_genlist_item_next_get(item);
2603 elm_genlist_item_insert_after
2605 ugd->searched_device_itc, dev, NULL, item,
2606 ELM_GENLIST_ITEM_NONE,
2607 __bt_main_searched_item_sel_cb,
2614 elm_genlist_item_insert_before
2615 (ugd->main_genlist, ugd->searched_device_itc, dev,
2616 NULL, item, ELM_GENLIST_ITEM_NONE,
2617 __bt_main_searched_item_sel_cb, ugd);
2623 dev->genlist_item = git;
2624 dev->status = BT_IDLE;
2625 dev->ugd = (void *)ugd;
2626 dev->is_bonded = FALSE;
2632 Elm_Object_Item *_bt_main_add_no_device_found(bt_ug_data *ugd)
2636 Elm_Object_Item *git = NULL;
2638 retvm_if(ugd == NULL, NULL, "Invalid argument: ugd is NULL");
2640 if (ugd->searched_title == NULL)
2641 _bt_main_add_searched_title(ugd);
2643 /* No device found Item */
2645 elm_genlist_item_insert_after(ugd->main_genlist, ugd->no_device_itc,
2646 ugd, NULL, ugd->searched_title,
2647 ELM_GENLIST_ITEM_NONE, NULL, NULL);
2649 elm_genlist_item_select_mode_set(git,
2650 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
2656 static void __bt_move_help_ctxpopup(Evas_Object *ctx, bt_ug_data *ugd)
2662 ret_if(ugd == NULL);
2663 ret_if(ugd->win_main == NULL);
2665 elm_win_screen_size_get(ugd->win_main, NULL, NULL, &w, &h);
2666 pos = elm_win_rotation_get(ugd->win_main);
2671 evas_object_move(ctx, (w/2), h);
2675 evas_object_move(ctx, (h/2), w);
2678 evas_object_move(ctx, (w/2), h);
2684 static void __bt_ctxpopup_rotate_cb(void *data, Evas_Object *obj, void *event_info)
2687 bt_ug_data *ugd = NULL;
2688 ret_if(data == NULL);
2689 ugd = (bt_ug_data *)data;
2691 __bt_move_help_ctxpopup(ugd->help_more_popup, ugd);
2692 evas_object_show(ugd->win_main);
2697 static void __bt_more_popup_del_cb(void *data)
2700 bt_ug_data *ugd = NULL;
2702 ret_if(data == NULL);
2703 ugd = (bt_ug_data *)data;
2705 if (ugd->help_more_popup != NULL) {
2706 evas_object_del(ugd->help_more_popup);
2707 ugd->help_more_popup = NULL;
2713 static void __bt_more_popup_more_cb(void *data,
2714 Evas_Object *obj, void *event_info)
2717 __bt_more_popup_del_cb((bt_ug_data *)data);
2721 static void __bt_more_popup_back_cb(void *data,
2722 Evas_Object *obj, void *event_info)
2725 __bt_more_popup_del_cb((bt_ug_data *)data);
2729 static void __bt_more_popup_dismiss_cb(void *data, Evas_Object *obj,
2735 ugd = (bt_ug_data *)data;
2736 ret_if(ugd == NULL);
2737 ret_if(ugd->help_more_popup == NULL);
2739 evas_object_del(ugd->help_more_popup);
2740 ugd->help_more_popup = NULL;
2745 static void __bt_more_popup_delete_cb(void *data, Evas *e,
2746 Evas_Object *obj, void *event_info)
2749 Evas_Object *navi = (Evas_Object *)data;
2750 Evas_Object *ctx = obj;
2752 ret_if (navi == NULL);
2754 evas_object_smart_callback_del(ctx, "dismissed",
2755 __bt_more_popup_dismiss_cb);
2756 evas_object_event_callback_del_full(ctx, EVAS_CALLBACK_DEL,
2757 __bt_more_popup_delete_cb, navi);
2761 #ifdef TIZEN_REDWOOD
2762 static void __bt_ug_layout_cb(ui_gadget_h ug, enum ug_mode mode, void *priv)
2769 base = ug_get_layout(ug);
2771 BT_ERR("ug_get_layout() return NULL");
2776 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2777 evas_object_show(base);
2781 static void __bt_ug_destroy_cb(ui_gadget_h ug, void *data)
2791 static void __bt_more_popup_rename_device_item_sel_cb(void *data,
2792 Evas_Object *obj, void *event_inf)
2795 ret_if(data == NULL);
2796 ret_if(event_inf == NULL);
2797 bt_ug_data *ugd = (bt_ug_data *)data;
2800 elm_genlist_item_selected_set((Elm_Object_Item *)event_inf,
2803 ret_if(ugd == NULL);
2804 ret_if(ugd->help_more_popup == NULL);
2805 evas_object_del(ugd->help_more_popup);
2806 ugd->help_more_popup = NULL;
2807 Evas_Object *popup = NULL;
2808 Evas_Object *genlist = NULL;
2809 Evas_Object *button = NULL;
2810 Elm_Object_Item *git = NULL;
2813 popup = elm_popup_add(ugd->base);
2814 eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK,
2815 __bt_rename_device_cancel_cb, ugd);
2816 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2817 evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
2819 elm_object_domain_translatable_part_text_set(popup,
2822 "IDS_ST_HEADER_RENAME_DEVICE");
2824 genlist = elm_genlist_add(popup);
2825 evas_object_size_hint_weight_set(genlist,
2826 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2827 evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
2828 elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
2829 elm_scroller_content_min_limit(genlist, EINA_FALSE, EINA_TRUE);
2831 /* Entry genlist item */
2832 ugd->rename_entry_itc = elm_genlist_item_class_new();
2833 /* Fix : NULL_RETURNS */
2834 if (ugd->rename_entry_itc) {
2835 ugd->rename_entry_itc->item_style = BT_GENLIST_FULL_CONTENT_STYLE;
2836 ugd->rename_entry_itc->func.text_get = NULL;
2837 ugd->rename_entry_itc->func.content_get = __bt_main_rename_entry_icon_get;
2838 ugd->rename_entry_itc->func.state_get = NULL;
2839 ugd->rename_entry_itc->func.del = NULL;
2841 ugd->rename_entry_item = elm_genlist_item_append(genlist,
2842 ugd->rename_entry_itc, ugd,
2843 NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
2846 ugd->rename_desc_itc = elm_genlist_item_class_new();
2847 /* Fix : NULL_RETURNS */
2848 if (ugd->rename_desc_itc) {
2849 ugd->rename_desc_itc->item_style = BT_GENLIST_MULTILINE_TEXT_STYLE;
2850 ugd->rename_desc_itc->func.text_get = __bt_main_rename_desc_label_get;
2851 ugd->rename_desc_itc->func.content_get = NULL;
2852 ugd->rename_desc_itc->func.state_get = NULL;
2853 ugd->rename_desc_itc->func.del = NULL;
2855 git = elm_genlist_item_append(genlist, ugd->rename_desc_itc, NULL, NULL,
2856 ELM_GENLIST_ITEM_NONE, NULL, NULL);
2858 elm_genlist_item_select_mode_set(git,
2859 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
2861 button = elm_button_add(popup);
2862 elm_object_style_set(button, "popup");
2863 elm_object_domain_translatable_text_set(button,
2865 "IDS_BR_SK_CANCEL");
2866 elm_object_part_content_set(popup, "button1", button);
2867 evas_object_smart_callback_add(button, "clicked",
2868 __bt_rename_device_cancel_cb, ugd);
2870 button = elm_button_add(popup);
2871 ugd->rename_button = button;
2872 elm_object_style_set(button, "popup");
2873 elm_object_domain_translatable_text_set(button,
2875 "IDS_BT_OPT_RENAME");
2876 elm_object_part_content_set(popup, "button2", button);
2877 evas_object_smart_callback_add(button, "clicked",
2878 __bt_rename_device_ok_cb, ugd);
2880 evas_object_show(genlist);
2882 elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
2883 elm_object_content_set(popup, genlist);
2884 evas_object_show(popup);
2886 ugd->rename_popup = popup;
2892 #ifdef TIZEN_REDWOOD
2893 static void __bt_more_popup_help_item_sel_cb(void *data,
2894 Evas_Object *obj, void *event_info)
2899 bt_ug_data *ugd = (bt_ug_data *)data;
2900 app_control_h service = NULL;
2901 ui_gadget_h ug_h = NULL;
2902 struct ug_cbs cbs = {0};
2905 BT_DBG("delete popup");
2906 evas_object_del(ugd->popup);
2910 app_control_create(&service);
2911 app_control_add_extra_data(service, "page","help_settings_bluetooth");
2913 cbs.layout_cb = __bt_ug_layout_cb;
2914 cbs.result_cb = NULL;
2915 cbs.destroy_cb = __bt_ug_destroy_cb;
2918 ug_h = ug_create(NULL, "help-efl", UG_MODE_FULLVIEW, service, &cbs);
2920 BT_ERR("ug_create() Failed");
2922 app_control_destroy(service);
2923 __bt_more_popup_del_cb((bt_ug_data *)data);
2928 static void __bt_more_menu_cb(void *data,
2929 Evas_Object *obj, void *event_info)
2933 Evas_Object *more_ctxpopup = NULL;
2936 ugd = (bt_ug_data *)data;
2937 ret_if(ugd == NULL);
2938 ret_if(ugd->profile_vd != NULL);
2939 ret_if(ugd->op_status == BT_ACTIVATING ||
2940 ugd->op_status == BT_DEACTIVATED ||
2941 ugd->op_status == BT_DEACTIVATING);
2942 ret_if(ugd->bt_launch_mode != BT_LAUNCH_NORMAL);
2944 _bt_main_popup_del_cb(ugd, NULL, NULL);
2946 more_ctxpopup = elm_ctxpopup_add(ugd->win_main);
2947 ugd->help_more_popup = more_ctxpopup;
2948 eext_object_event_callback_add(more_ctxpopup,
2949 EEXT_CALLBACK_BACK, __bt_more_popup_back_cb, ugd);
2950 eext_object_event_callback_add(more_ctxpopup,
2951 EEXT_CALLBACK_MORE, __bt_more_popup_more_cb, ugd);
2952 elm_object_style_set(more_ctxpopup, "more/default");
2953 elm_ctxpopup_auto_hide_disabled_set(more_ctxpopup, EINA_TRUE);
2955 elm_ctxpopup_item_append(more_ctxpopup, BT_STR_RENAME_DEVICE_TITLE,
2956 NULL, __bt_more_popup_rename_device_item_sel_cb, ugd);
2958 evas_object_smart_callback_add(more_ctxpopup, "dismissed",
2959 __bt_more_popup_dismiss_cb, ugd);
2960 evas_object_event_callback_add(more_ctxpopup, EVAS_CALLBACK_DEL,
2961 __bt_more_popup_delete_cb, ugd->navi_bar);
2962 evas_object_smart_callback_add(elm_object_top_widget_get(more_ctxpopup), "rotation,changed",
2963 __bt_ctxpopup_rotate_cb, ugd);
2965 elm_ctxpopup_direction_priority_set(more_ctxpopup, ELM_CTXPOPUP_DIRECTION_UP,
2966 ELM_CTXPOPUP_DIRECTION_DOWN,
2967 ELM_CTXPOPUP_DIRECTION_UNKNOWN,
2968 ELM_CTXPOPUP_DIRECTION_UNKNOWN);
2970 __bt_move_help_ctxpopup(more_ctxpopup, ugd);
2971 evas_object_show(more_ctxpopup);
2976 Evas_Object * _bt_main_create_scan_button(bt_ug_data *ugd)
2978 Evas_Object *scan_button = NULL;
2980 scan_button = elm_button_add(ugd->navi_bar);
2982 /* Use "bottom" style button */
2983 elm_object_style_set(scan_button, "bottom");
2985 elm_object_text_set(scan_button, BT_STR_SCAN);
2987 evas_object_smart_callback_add(scan_button, "clicked",
2988 __bt_main_controlbar_btn_cb, ugd);
2990 /* Set button into "toolbar" swallow part */
2991 elm_object_item_part_content_set(ugd->navi_it, "toolbar", scan_button);
2996 static void __bt_main_back_cb(void *data, Evas_Object *obj, void *event_info)
2998 __bt_main_quit_btn_cb(data, NULL);
3001 int _bt_main_draw_list_view(bt_ug_data *ugd)
3005 Evas_Object *navi = NULL;
3006 Evas_Object *genlist = NULL;
3007 Elm_Object_Item *navi_it = NULL;
3008 Evas_Object *back_button = NULL;
3010 retv_if(ugd == NULL, BT_UG_FAIL);
3012 navi = _bt_create_naviframe(ugd->base);
3013 elm_naviframe_prev_btn_auto_pushed_set(navi, EINA_FALSE);
3014 ugd->navi_bar = navi;
3016 eext_object_event_callback_add(navi, EEXT_CALLBACK_BACK,
3017 eext_naviframe_back_cb, NULL);
3019 if (ugd->bt_launch_mode != BT_LAUNCH_HELP)
3020 eext_object_event_callback_add(navi, EEXT_CALLBACK_MORE,
3021 __bt_more_menu_cb, ugd);
3022 genlist = __bt_main_add_genlist_dialogue(navi, ugd);
3023 ugd->main_genlist = genlist;
3025 back_button = elm_button_add(navi);
3026 elm_object_style_set(back_button, "naviframe/end_btn/default");
3028 navi_it = elm_naviframe_item_push(navi, BT_STR_BLUETOOTH, back_button, NULL,
3030 elm_naviframe_item_pop_cb_set(navi_it, __bt_main_quit_btn_cb, ugd);
3031 ugd->navi_it = navi_it;
3032 evas_object_smart_callback_add(back_button, "clicked", __bt_main_back_cb, ugd);
3034 if (ugd->op_status == BT_ACTIVATED) {
3035 ugd->scan_btn = _bt_main_create_scan_button(ugd);
3038 ugd->confirm_req = BT_NONE_REQ;
3041 return BT_UG_ERROR_NONE;
3044 int _bt_main_draw_visibility_view(bt_ug_data *ugd)
3048 Evas_Object *navi = NULL;
3049 Evas_Object *genlist = NULL;
3050 Elm_Object_Item *navi_it;
3052 retv_if(ugd == NULL, BT_UG_FAIL);
3054 navi = _bt_create_naviframe(ugd->base);
3056 elm_naviframe_prev_btn_auto_pushed_set(navi, EINA_FALSE);
3058 eext_object_event_callback_add(navi, EEXT_CALLBACK_BACK,
3059 eext_naviframe_back_cb, NULL);
3061 genlist = __bt_main_add_visibility_dialogue(navi, ugd);
3064 elm_naviframe_item_push(navi, BT_STR_VISIBLE, NULL, NULL, genlist,
3066 elm_naviframe_item_pop_cb_set(navi_it, __bt_main_quit_btn_cb, ugd);
3067 ugd->navi_it = navi_it;
3068 ugd->navi_bar = navi;
3069 ugd->main_genlist = genlist;
3070 ugd->confirm_req = BT_NONE_REQ;
3073 return BT_UG_ERROR_NONE;
3076 int _bt_main_draw_onoff_view(bt_ug_data *ugd)
3080 Evas_Object *navi = NULL;
3081 Evas_Object *genlist = NULL;
3082 Elm_Object_Item *navi_it;
3084 retv_if(ugd == NULL, BT_UG_FAIL);
3086 navi = _bt_create_naviframe(ugd->base);
3088 elm_naviframe_prev_btn_auto_pushed_set(navi, EINA_FALSE);
3090 eext_object_event_callback_add(navi, EEXT_CALLBACK_BACK,
3091 eext_naviframe_back_cb, NULL);
3093 genlist = __bt_main_add_onoff_dialogue(navi, ugd);
3096 elm_naviframe_item_push(navi, BT_STR_BLUETOOTH, NULL, NULL, genlist,
3098 elm_naviframe_item_pop_cb_set(navi_it, __bt_main_quit_btn_cb, ugd);
3099 ugd->navi_it = navi_it;
3100 ugd->navi_bar = navi;
3101 ugd->main_genlist = genlist;
3102 ugd->confirm_req = BT_NONE_REQ;
3105 return BT_UG_ERROR_NONE;
3108 static Eina_Bool __bt_cb_register_net_state_cb(void *data)
3112 bt_dev_t *dev = NULL;
3113 Eina_List *l = NULL;
3114 Eina_List *l2 = NULL;
3115 bt_net_profile_t *profile_data = NULL;
3116 void *profile = NULL;
3117 char net_address[BT_ADDRESS_STR_LEN + 1] = { 0 };
3119 bt_ug_data *ugd = (bt_ug_data *)data;
3120 if (ugd->network_timer) {
3121 ecore_timer_del(ugd->network_timer);
3122 ugd->network_timer = NULL;
3124 retv_if(ugd == NULL, ECORE_CALLBACK_CANCEL);
3125 retv_if(ugd->connection == NULL, ECORE_CALLBACK_CANCEL);
3127 if (ugd->paired_device) {
3128 EINA_LIST_FOREACH(ugd->paired_device, l, dev) {
3130 (dev->service_list & BT_SC_PANU_SERVICE_MASK ||
3131 dev->service_list & BT_SC_NAP_SERVICE_MASK) &&
3132 dev->is_connected && !dev->net_profile) {
3133 if (!ugd->net_profile_list)
3134 ugd->net_profile_list =
3135 _bt_get_registered_net_profile_list(ugd->connection);
3136 retvm_if (!ugd->net_profile_list, ECORE_CALLBACK_CANCEL,
3137 "net_profile_list is NULL!");
3139 EINA_LIST_FOREACH(ugd->net_profile_list, l2, profile_data) {
3141 profile_data->profile_h &&
3142 profile_data->address) {
3143 _bt_util_addr_type_to_addr_net_string(net_address, dev->bd_addr);
3144 if (!g_strcmp0((const char *)profile_data->address, net_address)) {
3145 profile = _bt_get_registered_net_profile(ugd->connection,
3147 _bt_set_profile_state_changed_cb(profile, dev);
3154 if (ugd->net_profile_list) {
3155 _bt_free_net_profile_list(ugd->net_profile_list);
3156 ugd->net_profile_list = NULL;
3162 return ECORE_CALLBACK_CANCEL;
3165 static bool __bt_cb_adapter_bonded_device(bt_device_info_s *device_info,
3168 bt_dev_t *dev = NULL;
3169 bt_ug_data *ugd = NULL;
3170 unsigned int service_class;
3172 retv_if(!user_data, false);
3173 retv_if(!device_info->remote_name || strlen(device_info->remote_name) == 0, false);
3174 retv_if(!device_info->remote_address || strlen(device_info->remote_address) == 0, false);
3176 ugd = (bt_ug_data *)user_data;
3178 if (_bt_main_check_and_update_device(ugd->paired_device,
3179 device_info->remote_address,
3180 device_info->remote_name) >= 0) {
3181 /* Update all realized items */
3182 elm_genlist_realized_items_update(ugd->main_genlist);
3187 dev = _bt_main_create_paired_device_item(device_info);
3189 retv_if(!dev, false);
3191 dev->ugd = (void *)ugd;
3192 if (device_info->is_connected)
3193 dev->is_connected = _bt_util_check_any_profile_connected(dev);
3195 dev->is_connected = device_info->is_connected;
3197 BT_INFO("device state(%d) overriding with profile state(%d)",
3198 device_info->is_connected, dev->is_connected);
3200 service_class = dev->service_class;
3202 /* WORKAROUND for a PLM issue.
3203 For some devices, service class is 0 even if it supports OPP server. So it is
3204 not showing in the device list when user try to share files via bluetooth.
3205 So override service_class with BT_COD_SC_OBJECT_TRANSFER in that case
3207 BT_DBG("overriding");
3208 if (service_class == 0) {
3209 if (dev->service_list & BT_SC_OPP_SERVICE_MASK)
3210 service_class = BT_COD_SC_OBJECT_TRANSFER;
3213 if (_bt_main_is_matched_profile(ugd->search_type,
3217 dev->minor_class) == TRUE) {
3218 BT_INFO("Device count [%d]",
3219 eina_list_count(ugd->paired_device));
3221 if (_bt_main_add_paired_device(ugd, dev) != NULL) {
3222 ugd->paired_device =
3223 eina_list_append(ugd->paired_device, dev);
3225 if (dev->service_list == 0) {
3226 if (bt_device_start_service_search
3227 ((const char *)dev->addr_str) == BT_ERROR_NONE) {
3229 ugd->paired_item = dev->genlist_item;
3230 dev->status = BT_SERVICE_SEARCHING;
3231 ugd->waiting_service_response = TRUE;
3232 ugd->request_timer =
3233 ecore_timer_add(BT_SEARCH_SERVICE_TIMEOUT,
3235 _bt_main_service_request_cb,
3238 BT_ERR("service search error");
3243 BT_ERR("Device class and search type do not match");
3249 void _bt_main_draw_paired_devices(bt_ug_data *ugd)
3253 ret_if(ugd == NULL);
3255 if (bt_adapter_foreach_bonded_device(__bt_cb_adapter_bonded_device,
3256 (void *)ugd) != BT_ERROR_NONE) {
3257 BT_ERR("bt_adapter_foreach_bonded_device() failed");
3261 ugd->network_timer = ecore_timer_add(1,__bt_cb_register_net_state_cb, ugd);
3263 if (!ugd->network_timer)
3264 BT_ERR("network_timer can not be added");
3269 void _bt_main_remove_paired_device(bt_ug_data *ugd, bt_dev_t *dev)
3273 bt_dev_t *item = NULL;
3274 Eina_List *l = NULL;
3275 Eina_List *l_next = NULL;
3277 retm_if(ugd == NULL, "Invalid argument: ugd is NULL");
3278 retm_if(dev == NULL, "Invalid argument: dev is NULL");
3280 EINA_LIST_FOREACH_SAFE(ugd->paired_device, l, l_next, item) {
3281 if (item && (item == dev)) {
3282 elm_object_item_del(item->genlist_item);
3283 ugd->paired_device =
3284 eina_list_remove_list(ugd->paired_device, l);
3288 if (ugd->paired_device == NULL ||
3289 eina_list_count(ugd->paired_device) == 0) {
3290 elm_object_item_del(ugd->paired_title);
3291 ugd->paired_title = NULL;
3297 void _bt_main_remove_all_paired_devices(bt_ug_data *ugd)
3301 bt_dev_t *dev = NULL;
3302 Eina_List *l = NULL;
3303 Eina_List *l_next = NULL;
3304 Elm_Object_Item *item;
3305 Elm_Object_Item *next;
3307 ret_if(ugd == NULL);
3309 if (ugd->paired_title) {
3310 item = elm_genlist_item_next_get(ugd->paired_title);
3312 elm_object_item_del(ugd->paired_title);
3313 ugd->paired_title = NULL;
3315 while (item != NULL && (item != ugd->searched_title)) {
3316 next = elm_genlist_item_next_get(item);
3317 elm_object_item_del(item);
3322 EINA_LIST_FOREACH_SAFE(ugd->paired_device, l, l_next, dev) {
3323 ugd->paired_device =
3324 eina_list_remove_list(ugd->paired_device, l);
3325 _bt_util_free_device_item(dev);
3328 ugd->paired_device = NULL;
3334 void _bt_main_remove_searched_device(bt_ug_data *ugd, bt_dev_t *dev)
3338 bt_dev_t *item = NULL;
3339 Eina_List *l = NULL;
3340 Eina_List *l_next = NULL;
3342 ret_if(ugd == NULL);
3344 EINA_LIST_FOREACH_SAFE(ugd->searched_device, l, l_next, item) {
3345 if (item && (item == dev)) {
3346 if (dev->genlist_item) {
3347 elm_object_item_del(dev->genlist_item);
3348 dev->genlist_item = NULL;
3350 ugd->searched_device =
3351 eina_list_remove_list(ugd->searched_device, l);
3352 _bt_util_free_device_item(item);
3356 if (ugd->searched_device == NULL ||
3357 eina_list_count(ugd->searched_device) == 0) {
3358 elm_object_item_del(ugd->searched_title);
3359 ugd->searched_title = NULL;
3365 void _bt_main_remove_all_searched_devices(bt_ug_data *ugd)
3369 bt_dev_t *dev = NULL;
3370 Eina_List *l = NULL;
3371 Eina_List *l_next = NULL;
3372 Elm_Object_Item *item;
3373 Elm_Object_Item *next;
3375 ret_if(ugd == NULL);
3377 if (ugd->searched_title) {
3378 item = elm_genlist_item_next_get(ugd->searched_title);
3379 elm_object_item_del(ugd->searched_title);
3380 ugd->searched_title = NULL;
3382 while (item != NULL) {
3383 next = elm_genlist_item_next_get(item);
3384 elm_object_item_del(item);
3387 ugd->no_device_item = NULL;
3390 EINA_LIST_FOREACH_SAFE(ugd->searched_device, l, l_next, dev) {
3391 ugd->searched_device =
3392 eina_list_remove_list(ugd->searched_device, l);
3393 _bt_util_free_device_item(dev);
3396 ugd->searched_device = NULL;
3402 void _bt_main_connect_device(bt_ug_data *ugd, bt_dev_t *dev)
3406 int headset_type = BT_AUDIO_PROFILE_TYPE_ALL;
3408 ret_if(ugd == NULL);
3409 ret_if(dev == NULL);
3411 #ifdef TIZEN_BT_A2DP_SINK_ENABLE
3412 if (dev->service_list & BT_SC_A2DP_SOURCE_SERVICE_MASK) {
3413 if (bt_audio_connect(dev->addr_str,
3414 BT_AUDIO_PROFILE_TYPE_A2DP_SINK) == BT_ERROR_NONE) {
3415 ugd->connect_req = TRUE;
3416 dev->status = BT_CONNECTING;
3418 BT_ERR("Fail to connect BT_AUDIO_PROFILE_TYPE_A2DP_SINK");
3421 #ifndef TELEPHONY_DISABLED
3422 if ((dev->service_list & BT_SC_HFP_SERVICE_MASK) ||
3423 (dev->service_list & BT_SC_HSP_SERVICE_MASK)) {
3424 /* Connect the Headset */
3425 if (dev->service_list & BT_SC_A2DP_SERVICE_MASK)
3426 headset_type = BT_AUDIO_PROFILE_TYPE_ALL;
3428 headset_type = BT_AUDIO_PROFILE_TYPE_HSP_HFP;
3430 BT_INFO("Connection type = %d", headset_type);
3432 if (bt_audio_connect(dev->addr_str,
3433 headset_type) == BT_ERROR_NONE) {
3434 ugd->connect_req = TRUE;
3435 dev->status = BT_CONNECTING;
3437 BT_ERR("Fail to connect Headset device");
3439 } else if (dev->service_list & BT_SC_A2DP_SERVICE_MASK) {
3441 if (dev->service_list & BT_SC_A2DP_SERVICE_MASK) {
3444 if (bt_audio_connect(dev->addr_str,
3445 BT_AUDIO_PROFILE_TYPE_A2DP) ==
3447 ugd->connect_req = TRUE;
3448 dev->status = BT_CONNECTING;
3450 BT_ERR("Fail to connect Headset device");
3452 } else if (dev->service_list & BT_SC_HID_SERVICE_MASK) {
3454 BT_INFO("HID connect request");
3456 if (bt_hid_host_connect(dev->addr_str) == BT_ERROR_NONE) {
3457 ugd->connect_req = TRUE;
3458 dev->status = BT_CONNECTING;
3460 BT_ERR("Fail to connect HID device");
3463 } else if (dev->service_list & BT_SC_NAP_SERVICE_MASK) {
3465 if (dev->net_profile) {
3466 if (_bt_connect_net_profile(ugd->connection,
3468 dev) == BT_UG_ERROR_NONE) {
3469 ugd->connect_req = TRUE;
3470 dev->status = BT_CONNECTING;
3472 BT_ERR("Fail to connect the net profile");
3475 net_profile = _bt_get_registered_net_profile(ugd->connection,
3478 _bt_set_profile_state_changed_cb(net_profile,
3480 if (_bt_connect_net_profile(ugd->connection,
3482 dev) == BT_UG_ERROR_NONE) {
3483 ugd->connect_req = TRUE;
3484 dev->status = BT_CONNECTING;
3486 BT_ERR("Fail to connect the net profile");
3492 _bt_update_genlist_item((Elm_Object_Item *) dev->genlist_item);
3497 void _bt_main_disconnect_device(bt_ug_data *ugd, bt_dev_t *dev)
3501 ret_if(ugd == NULL);
3502 ret_if(dev == NULL);
3504 #ifndef TELEPHONY_DISABLED
3505 if (_bt_util_is_profile_connected(BT_HEADSET_CONNECTED,
3506 dev->bd_addr) == TRUE) {
3507 BT_INFO("Disconnecting AG service");
3508 if (bt_audio_disconnect(dev->addr_str,
3509 BT_AUDIO_PROFILE_TYPE_ALL) ==
3511 ugd->disconn_req = true;
3512 dev->status = BT_DISCONNECTING;
3514 BT_ERR("Fail to connect Headset device");
3516 } else if (_bt_util_is_profile_connected(BT_STEREO_HEADSET_CONNECTED,
3517 dev->bd_addr) == TRUE) {
3519 if (_bt_util_is_profile_connected(BT_STEREO_HEADSET_CONNECTED,
3520 dev->bd_addr) == TRUE) {
3522 BT_INFO("Disconnecting AV service");
3523 if (bt_audio_disconnect(dev->addr_str,
3524 BT_AUDIO_PROFILE_TYPE_A2DP) ==
3526 ugd->disconn_req = true;
3527 dev->status = BT_DISCONNECTING;
3529 BT_ERR("Fail to connect Headset device");
3531 #ifdef TIZEN_BT_A2DP_SINK_ENABLE
3532 } else if (_bt_util_is_profile_connected(BT_MUSIC_PLAYER_CONNECTED,
3533 dev->bd_addr) == TRUE) {
3534 BT_INFO("Disconnecting AV service");
3536 if (bt_audio_disconnect(dev->addr_str,
3537 BT_AUDIO_PROFILE_TYPE_A2DP_SINK) ==
3539 ugd->disconn_req = true;
3540 dev->status = BT_DISCONNECTING;
3542 BT_ERR("Fail to connect Headset device");
3545 } else if (_bt_util_is_profile_connected(BT_HID_CONNECTED,
3546 dev->bd_addr) == TRUE) {
3547 BT_INFO("Disconnecting HID service!!");
3549 if (bt_hid_host_disconnect(dev->addr_str) == BT_ERROR_NONE) {
3550 dev->status = BT_DISCONNECTING;
3552 BT_ERR("Fail to disconnect HID device");
3555 } else if (_bt_util_is_profile_connected(BT_NETWORK_SERVER_CONNECTED,
3556 dev->bd_addr) == TRUE) {
3557 /* Need to check NAP server */
3558 if (bt_nap_disconnect(dev->addr_str) == BT_UG_ERROR_NONE) {
3559 ugd->connect_req = true;
3560 dev->status = BT_DISCONNECTING;
3562 BT_ERR("Failed to disconnect pan server");
3566 gboolean connected = FALSE;
3568 connected = _bt_util_is_profile_connected(BT_NETWORK_CONNECTED,
3571 if (dev->net_profile) {
3572 if (_bt_disconnect_net_profile(ugd->connection,
3573 dev->net_profile, dev) ==
3575 ugd->connect_req = true;
3576 dev->status = BT_DISCONNECTING;
3578 BT_ERR("Fail to disconnect the net profile");
3582 _bt_get_registered_net_profile(
3586 if (_bt_disconnect_net_profile(
3588 net_profile, dev) ==
3590 ugd->connect_req = true;
3591 dev->status = BT_DISCONNECTING;
3593 BT_ERR("Fail to disconnect the net profile");
3600 _bt_update_genlist_item((Elm_Object_Item *) dev->genlist_item);
3605 int _bt_main_request_pairing_with_effect(bt_ug_data *ugd,
3606 Elm_Object_Item *seleted_item)
3612 retvm_if(ugd == NULL, BT_UG_FAIL, "Invalid argument: ugd is NULL");
3613 retvm_if(seleted_item == NULL, BT_UG_FAIL,
3614 "Invalid argument: object is NULL");
3616 dev = _bt_main_get_dev_info(ugd->searched_device, seleted_item);
3617 retvm_if(dev == NULL, BT_UG_FAIL, "Invalid argument: dev is NULL");
3619 if (bt_device_create_bond(dev->addr_str) == BT_ERROR_NONE) {
3620 dev->status = BT_DEV_PAIRING;
3621 ugd->op_status = BT_PAIRING;
3623 elm_object_disabled_set(ugd->scan_btn, EINA_TRUE);
3624 _bt_update_genlist_item(seleted_item);
3630 return BT_UG_ERROR_NONE;
3633 void __bt_main_parse_service(bt_ug_data *ugd, app_control_h service)
3636 char *uri_scheme = NULL;;
3637 char *body_text = NULL;
3638 char *launch_type = NULL;
3639 char *operation = NULL;
3641 const char *uri = NULL;
3642 const char *file_path = NULL;
3644 ret_if(ugd == NULL);
3645 ret_if(service == NULL);
3647 if (app_control_get_operation(service, &operation) < 0)
3648 BT_ERR("Get operation error");
3650 BT_INFO("operation: %s", operation);
3652 if (g_strcmp0(operation, APP_CONTROL_OPERATION_SHARE) == 0) {
3655 launch_type = strdup("send");
3657 app_control_get_mime(service, &mime);
3659 if (mime && strcmp(mime, APP_CONTROL_MIME_CONTACT) == 0) {
3660 char *id_str = NULL;
3661 app_control_get_extra_data(service, APP_CONTROL_DATA_ID, &id_str);
3664 bool my_profile = false;
3665 char *data_type = NULL;
3666 int id = atoi(id_str);
3668 app_control_get_extra_data(service, APP_CONTROL_DATA_TYPE, &data_type);
3669 my_profile = data_type && strcmp(data_type, APP_CONTROL_MY_PROFILE_DATA_TYPE) == 0;
3670 file_path = _bt_util_vcard_create_from_id(id, my_profile,
3671 BT_VCF_FOLDER_PATH);
3674 DBG_SECURE("file path: %s", file_path);
3676 if (app_control_add_extra_data(service, "type", "file") < 0)
3677 BT_ERR("Fail to add extra data");
3679 if (app_control_add_extra_data_array
3680 (service, "files", &file_path, 1) < 0)
3681 BT_ERR("Fail to add extra data");
3688 if (app_control_get_uri(service, (char **)&uri) < 0)
3689 BT_ERR("Get uri error");
3692 uri_scheme = g_uri_parse_scheme(uri);
3693 DBG_SECURE("uri_scheme: %s", uri_scheme);
3695 if (uri_scheme == NULL) {
3697 file_path = g_filename_from_uri(uri, NULL, NULL);
3698 if (app_control_add_extra_data(service, "type", "file") < 0)
3699 BT_ERR("Fail to add extra data");
3700 } else if (g_strcmp0(uri_scheme, "file") == 0) {
3702 file_path = g_filename_from_uri(uri, NULL, NULL);
3703 if (file_path == NULL) {
3704 file_path = strdup(uri + 7); /* file:// */
3706 if (app_control_add_extra_data(service, "type", "file") < 0)
3707 BT_ERR("Fail to add extra data");
3709 if (app_control_add_extra_data(service, "type", "text") < 0)
3710 BT_ERR("Fail to add extra data");
3713 if (file_path == NULL) {
3714 BT_ERR("Not include URI info");
3715 file_path = strdup(uri);
3722 BT_INFO("url is not set");
3723 if (app_control_get_extra_data(service,
3724 MULTI_SHARE_SERVICE_DATA_PATH, &value) < 0)
3725 BT_ERR("Fail to get extra data");
3728 file_path = g_strdup(value);
3731 DBG_SECURE("file_path: %s", file_path);
3733 if (app_control_add_extra_data(service, "type", "file") < 0)
3734 BT_ERR("Fail to add extra data");
3737 BT_ERR("Not include path info");
3742 if (app_control_add_extra_data_array
3743 (service, "files", &file_path, 1) < 0)
3744 BT_ERR("Fail to add extra data");
3748 } else if (g_strcmp0(operation, APP_CONTROL_OPERATION_SHARE_TEXT) == 0) {
3749 BT_DBG("APP_CONTROL_OPERATION_SHARE_TEXT");
3751 launch_type = strdup("send");
3753 if (app_control_get_uri(service, (char **)&uri) < 0)
3754 BT_ERR("Get uri error");
3757 if (app_control_get_extra_data(service,
3758 APP_CONTROL_DATA_TEXT,
3760 APP_CONTROL_ERROR_NONE) {
3761 BT_ERR("Get uri error");
3764 if (body_text == NULL) {
3767 file_path = g_strdup(body_text);
3771 file_path = g_strdup(uri);
3774 if (file_path == NULL) {
3775 BT_ERR("file path is NULL");
3779 if (app_control_add_extra_data(service, "type", "text") < 0)
3780 BT_ERR("Fail to add extra data");
3782 if (app_control_add_extra_data_array
3783 (service, "files", &file_path, 1) < 0)
3784 BT_ERR("Fail to add extra data");
3786 } else if (g_strcmp0(operation, APP_CONTROL_OPERATION_MULTI_SHARE) == 0) {
3787 char **array_value = NULL;
3792 launch_type = strdup("send");
3794 int *id_list = NULL;
3795 char **person_id = NULL;
3796 int person_id_size = 0;
3797 bool cancel = false;
3799 app_control_get_mime(service, &mime);
3801 if (mime && !strcmp(mime, APP_CONTROL_MIME_CONTACT)) {
3802 if (app_control_get_extra_data_array(service, APP_CONTROL_DATA_ID,
3803 &person_id, &person_id_size) == APP_CONTROL_ERROR_NONE && person_id) {
3805 id_list = calloc(person_id_size, sizeof(int));
3807 for (i = 0; i < person_id_size; i++) {
3808 id_list[i] = atoi(person_id[i]);
3810 file_path = _bt_util_vcard_create_from_id_list(id_list,
3811 person_id_size, BT_VCF_FOLDER_PATH, &cancel);
3813 DBG_SECURE("file path: %s", file_path);
3815 if (app_control_add_extra_data(service, "type", "file") < 0)
3816 BT_ERR("Fail to add extra data");
3818 if (app_control_add_extra_data_array
3819 (service, "files", &file_path, 1) < 0)
3820 BT_ERR("Fail to add extra data");
3827 ret = app_control_get_extra_data_array(service,
3828 MULTI_SHARE_SERVICE_DATA_PATH,
3829 &array_value, &array_length);
3830 if (ret != APP_CONTROL_ERROR_NONE) {
3831 BT_ERR("Get data error");
3833 for (i = 0; i < array_length; i++) {
3834 if (array_value[i]) {
3835 free(array_value[i]);
3843 if (app_control_add_extra_data_array
3844 (service, "files", (const char **)array_value,
3846 BT_ERR("Fail to add extra data");
3848 if (app_control_add_extra_data(service, "type", "file") < 0)
3849 BT_ERR("Fail to add extra data");
3851 for (i = 0; i < array_length; i++) {
3852 if (array_value[i]) {
3853 free(array_value[i]);
3861 } else if (g_strcmp0(operation, BT_APPCONTROL_PICK_OPERATION) == 0) {
3862 BT_DBG("Pick Operation");
3863 launch_type = strdup("pick");
3864 } else if (g_strcmp0(operation, BT_APPCONTROL_VISIBILITY_OPERATION) == 0 ||
3865 g_strcmp0(operation, APP_CONTROL_OPERATION_SETTING_BT_VISIBILITY) == 0 ) {
3866 BT_DBG("Visibility Operation");
3867 launch_type = strdup("visibility");
3868 } else if (g_strcmp0(operation, BT_APPCONTROL_ONOFF_OPERATION) == 0 ||
3869 g_strcmp0(operation, APP_CONTROL_OPERATION_SETTING_BT_ENABLE) == 0 ) {
3870 BT_DBG("onoff Operation");
3871 launch_type = strdup("onoff");
3872 } else if (g_strcmp0(operation, APP_CONTROL_OPERATION_SHARE_CONTACT) == 0) {
3873 BT_DBG("Share Contact Operation");
3874 launch_type = strdup("contact");
3875 } else if (g_strcmp0(operation, BT_APPCONTROL_EDIT_OPERATION ) == 0) {
3876 BT_DBG("Edit Operation");
3877 if (app_control_get_mime(service, &mime) < 0)
3878 BT_ERR("Get mime error");
3879 if (g_strcmp0(mime, BT_APPCONTROL_ONOFF_MIME) == 0) {
3880 launch_type = strdup("onoff");
3881 } else if(g_strcmp0(mime, BT_APPCONTROL_VISIBILITY_MIME) == 0) {
3882 launch_type = strdup("visibility");
3884 } else if (app_control_get_extra_data(service, "launch-type",
3885 &launch_type) == APP_CONTROL_ERROR_NONE) {
3886 if (g_strcmp0(launch_type, "call") != 0) {
3887 BT_DBG("launch-type : except call");
3888 if (app_control_add_extra_data(service, "type", "file") < 0)
3889 BT_ERR("Fail to add extra data");
3891 BT_DBG("launch-type : call");
3893 } else if (app_control_get_uri(service, (char **)&uri) == APP_CONTROL_ERROR_NONE &&
3894 g_strcmp0(uri, HELP_SETUP_BLUETOOTH_URI) == 0) {
3895 BT_DBG("Help mode");
3896 launch_type = strdup("help");
3901 BT_INFO("Launch with launch type [%s]", launch_type);
3902 _bt_util_set_value(launch_type, &ugd->search_type,
3903 &ugd->bt_launch_mode);
3905 BT_DBG("launch type is NULL");
3912 free((void *)file_path);
3915 free((void *)launch_type);
3925 void _bt_main_init_status(bt_ug_data *ugd, void *data)
3929 app_control_h service = NULL;
3931 bool status = false;
3932 bt_adapter_state_e bt_state = BT_ADAPTER_DISABLED;
3933 ret_if(ugd == NULL);
3937 if (service != NULL) {
3938 __bt_main_parse_service(ugd, service);
3940 ugd->search_type = MISCELLANEOUS_MAJOR_DEVICE_MASK;
3941 ugd->bt_launch_mode = BT_LAUNCH_NORMAL;
3944 /* currently this is the workaround for relaunching bt-ug by s-finder.
3945 bt-ug is not properly working because of the previous initialization.
3946 If there was no bt-ug then this deinit code doesn't affect at all.*/
3949 if (bt_initialize() != BT_ERROR_NONE)
3950 BT_ERR("bt_initialize() failed");
3952 ret = _bt_util_create_dpm_context(ugd);
3953 if (ret != BT_UG_ERROR_NONE)
3954 BT_ERR("_bt_util_create_dpm_context failed: %d", ret);
3956 if (bt_adapter_get_state(&bt_state) != BT_ERROR_NONE)
3957 BT_ERR("bt_adapter_get_state() failed");
3959 if (bt_state == BT_ADAPTER_DISABLED) {
3960 ugd->op_status = BT_DEACTIVATED;
3962 if (bt_adapter_is_discovering(&status) != BT_ERROR_NONE)
3963 BT_ERR("bt_adapter_is_discovering() failed");
3966 bt_adapter_stop_device_discovery();
3968 ugd->op_status = BT_ACTIVATED;
3974 bt_dev_t *_bt_main_create_paired_device_item(void *data)
3979 unsigned char bd_addr[BT_ADDRESS_LENGTH_MAX];
3980 bt_dev_t *dev = NULL;
3981 bt_device_info_s *dev_info = NULL;
3983 retv_if(data == NULL, NULL);
3985 dev_info = (bt_device_info_s *)data;
3987 retv_if(!dev_info->remote_name || strlen(dev_info->remote_name) == 0, NULL);
3988 retv_if(!dev_info->remote_address || strlen(dev_info->remote_address) == 0, NULL);
3990 dev = malloc(sizeof(bt_dev_t));
3991 retv_if(dev == NULL, NULL);
3993 memset(dev, 0, sizeof(bt_dev_t));
3994 g_strlcpy(dev->name, dev_info->remote_name,
3995 DEVICE_NAME_MAX_LEN + 1);
3997 dev->major_class = dev_info->bt_class.major_device_class;
3998 dev->minor_class = dev_info->bt_class.minor_device_class;
3999 dev->service_class = dev_info->bt_class.major_service_class_mask;
4001 if (dev_info->service_uuid != NULL && dev_info->service_count > 0) {
4002 dev->uuids = g_new0(char *, dev_info->service_count + 1);
4004 for (i = 0; i < dev_info->service_count; i++) {
4005 dev->uuids[i] = g_strdup(dev_info->service_uuid[i]);
4008 dev->uuid_count = dev_info->service_count;
4011 _bt_util_addr_string_to_addr_type(bd_addr, dev_info->remote_address);
4013 memcpy(dev->addr_str, dev_info->remote_address, BT_ADDRESS_STR_LEN);
4015 memcpy(dev->bd_addr, bd_addr, BT_ADDRESS_LENGTH_MAX);
4017 bt_device_get_service_mask_from_uuid_list(dev_info->service_uuid,
4018 dev_info->service_count,
4019 &dev->service_list);
4021 BT_DBG("device name [%s]", dev->name);
4022 BT_DBG("device major class [%x]", dev->major_class);
4023 BT_DBG("device minor class [%x]", dev->minor_class);
4024 BT_DBG("device service class [%x]", dev->service_class);
4025 BT_DBG("device service list %x", dev->service_list);
4026 BT_DBG("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X", dev->bd_addr[0],
4027 dev->bd_addr[1], dev->bd_addr[2], dev->bd_addr[3],
4028 dev->bd_addr[4], dev->bd_addr[5]);
4030 if (dev->major_class == BT_MAJOR_DEV_CLS_MISC &&
4031 dev->service_list != BT_SC_NONE) {
4032 _bt_util_update_class_of_device_by_service_list(dev->service_list,
4033 &dev->major_class, &dev->minor_class);
4040 bt_dev_t *_bt_main_create_searched_device_item(void *data)
4045 unsigned char bd_addr[BT_ADDRESS_LENGTH_MAX];
4046 bt_dev_t *dev = NULL;
4047 bt_adapter_device_discovery_info_s *dev_info = NULL;
4049 retv_if(data == NULL, NULL);
4051 dev_info = (bt_adapter_device_discovery_info_s *) data;
4053 if (strlen(dev_info->remote_name) == 0)
4056 dev = calloc(1, sizeof(bt_dev_t));
4057 retv_if(dev == NULL, NULL);
4059 strncpy(dev->name, dev_info->remote_name, DEVICE_NAME_MAX_LEN);
4061 dev->major_class = dev_info->bt_class.major_device_class;
4062 dev->minor_class = dev_info->bt_class.minor_device_class;
4063 dev->service_class = dev_info->bt_class.major_service_class_mask;
4064 dev->rssi = dev_info->rssi;
4066 if (dev_info->service_uuid != NULL && dev_info->service_count > 0) {
4067 dev->uuids = g_new0(char *, dev_info->service_count + 1);
4069 for (i = 0; i < dev_info->service_count; i++) {
4070 dev->uuids[i] = g_strdup(dev_info->service_uuid[i]);
4073 dev->uuid_count = dev_info->service_count;
4076 _bt_util_addr_string_to_addr_type(bd_addr, dev_info->remote_address);
4078 memcpy(dev->addr_str, dev_info->remote_address, BT_ADDRESS_STR_LEN);
4080 memcpy(dev->bd_addr, bd_addr, BT_ADDRESS_LENGTH_MAX);
4082 BT_DBG("device name [%s]", dev->name);
4083 BT_DBG("device major class [%x]", dev->major_class);
4084 BT_DBG("device minor class [%x]", dev->minor_class);
4085 BT_DBG("device service class [%x]", dev->service_class);
4086 BT_DBG("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X", dev->bd_addr[0],
4087 dev->bd_addr[1], dev->bd_addr[2], dev->bd_addr[3],
4088 dev->bd_addr[4], dev->bd_addr[5]);
4093 static gboolean _bt_check_minor_class(unsigned int minor_class)
4095 switch(minor_class) {
4096 case BTAPP_MIN_DEV_CLS_VIDEO_DISPLAY_AND_LOUD_SPEAKER:
4098 case BTAPP_MIN_DEV_CLS_VIDEO_CONFERENCING:
4100 case BTAPP_MIN_DEV_CLS_VIDEO_CAMERA:
4102 case BTAPP_MIN_DEV_CLS_SET_TOP_BOX:
4104 case BTAPP_MIN_DEV_CLS_VCR:
4106 case BTAPP_MIN_DEV_CLS_CAM_CORDER:
4113 gboolean _bt_main_is_matched_profile(unsigned int search_type,
4114 unsigned int major_class,
4115 unsigned int service_class,
4116 app_control_h service,
4117 unsigned int minor_class)
4121 bt_device_major_mask_t major_mask = BT_DEVICE_MAJOR_MASK_MISC;
4124 /* P141010-03829 : Kiran doesn't support HID device */
4125 BT_DBG("Kiran doesn't support HID device");
4126 retv_if(major_class == BT_MAJOR_DEV_CLS_PERIPHERAL, FALSE);
4129 if (search_type == 0x000000)
4132 BT_INFO("search_type: %x", search_type);
4133 BT_INFO("service_class: %x", service_class);
4135 /* Check the service_class */
4136 if (service_class & search_type) {
4137 if (search_type & OBJECT_TRANSFER_MAJOR_SERVICE_MASK &&
4138 major_class == BT_MAJOR_DEV_CLS_IMAGING) {
4139 if (__bt_main_is_image_file(service))
4145 BT_INFO("major_class %x", major_class);
4146 BT_INFO("minor_class %x", minor_class);
4147 /* Check the major class */
4148 switch (major_class) {
4149 case BT_MAJOR_DEV_CLS_COMPUTER:
4150 major_mask = BT_DEVICE_MAJOR_MASK_COMPUTER;
4152 case BT_MAJOR_DEV_CLS_PHONE:
4153 major_mask = BT_DEVICE_MAJOR_MASK_PHONE;
4155 case BT_MAJOR_DEV_CLS_LAN_ACCESS_POINT:
4156 major_mask = BT_DEVICE_MAJOR_MASK_LAN_ACCESS_POINT;
4158 case BT_MAJOR_DEV_CLS_AUDIO:
4159 if (_bt_check_minor_class(minor_class) == TRUE)
4160 major_mask = BT_DEVICE_MAJOR_MASK_AUDIO;
4162 major_mask = BT_DEVICE_MAJOR_MASK_MISC;
4165 case BT_MAJOR_DEV_CLS_PERIPHERAL:
4166 major_mask = BT_DEVICE_MAJOR_MASK_PERIPHERAL;
4169 case BT_MAJOR_DEV_CLS_IMAGING:
4170 major_mask = BT_DEVICE_MAJOR_MASK_IMAGING;
4172 case BT_MAJOR_DEV_CLS_WEARABLE:
4173 major_mask = BT_DEVICE_MAJOR_MASK_WEARABLE;
4175 case BT_MAJOR_DEV_CLS_TOY:
4176 major_mask = BT_DEVICE_MAJOR_MASK_TOY;
4178 case BT_MAJOR_DEV_CLS_HEALTH:
4179 major_mask = BT_DEVICE_MAJOR_MASK_HEALTH;
4182 major_mask = BT_DEVICE_MAJOR_MASK_MISC;
4186 BT_INFO("major_mask: %x", major_mask);
4188 if (search_type & major_mask)
4195 bt_dev_t *_bt_main_get_dev_info(Eina_List *list,
4196 Elm_Object_Item *genlist_item)
4200 bt_dev_t *item = NULL;
4201 Eina_List *l = NULL;
4203 retvm_if(list == NULL, NULL, "Invalid argument: list is NULL");
4204 retvm_if(genlist_item == NULL, NULL, "Invalid argument: obj is NULL");
4206 EINA_LIST_FOREACH(list, l, item) {
4208 if (item->genlist_item == genlist_item)
4217 bt_dev_t *_bt_main_get_dev_info_by_address(Eina_List *list, char *address)
4221 bt_dev_t *item = NULL;
4222 Eina_List *l = NULL;
4224 retvm_if(list == NULL, NULL, "Invalid argument: list is NULL");
4225 retvm_if(address == NULL, NULL, "Invalid argument: addr is NULL");
4227 EINA_LIST_FOREACH(list, l, item) {
4229 if (memcmp(item->addr_str, address, BT_ADDRESS_STR_LEN)
4239 int _bt_main_check_and_update_device(Eina_List *list, char *addr, char *name)
4243 bt_dev_t *item = NULL;
4244 Eina_List *l = NULL;
4246 retv_if(list == NULL, -1);
4247 retv_if(addr == NULL, -1);
4248 retv_if(name == NULL, -1);
4250 EINA_LIST_FOREACH(list, l, item) {
4252 if (memcmp(item->addr_str, addr, BT_ADDRESS_STR_LEN) ==
4254 memset(item->name, 0x00,
4255 DEVICE_NAME_MAX_LEN+1);
4256 g_strlcpy(item->name, name,
4257 DEVICE_NAME_MAX_LEN);
4268 void _bt_main_launch_syspopup(void *data, char *event_type, char *title,
4274 bt_ug_data *ugd = NULL;
4277 ret_if(event_type == NULL);
4278 ret_if(type == NULL);
4280 ugd = (bt_ug_data *)data;
4282 b = bundle_create();
4286 bundle_add_str(b, "event-type", event_type);
4288 bundle_add_str(b, "title", title);
4290 bundle_add_str(b, "type", type);
4292 ret = syspopup_launch("bt-syspopup", b);
4294 BT_ERR("Popup launch failed...retry %d", ret);
4295 ugd->popup_bundle = b;
4297 g_timeout_add(BT_UG_SYSPOPUP_TIMEOUT_FOR_MULTIPLE_POPUPS,
4298 (GSourceFunc) __bt_main_system_popup_timer_cb,
4306 void _bt_main_create_information_popup(void *data, char *msg)
4309 ret_if(data == NULL);
4310 bt_ug_data *ugd = (bt_ug_data *)data;
4312 _bt_main_popup_del_cb(data, NULL, NULL);
4314 ugd->popup_data.type = BT_POPUP_LOW_BATTERY;
4315 ugd->popup = _bt_create_popup(ugd,
4316 _bt_main_popup_del_cb, ugd, 2);
4317 retm_if(!ugd->popup , "fail to create popup!");
4319 eext_object_event_callback_add(ugd->popup, EEXT_CALLBACK_BACK,
4320 _bt_main_popup_del_cb, ugd);
4322 evas_object_show(ugd->popup);
4326 #ifdef TIZEN_REDWOOD
4327 static gboolean __bt_main_close_help_popup_cb(gpointer data)
4330 retv_if(!data, FALSE);
4331 bt_ug_data *ugd = (bt_ug_data *)data;
4334 evas_object_del(ugd->popup);
4338 _bt_ug_destroy(data, NULL);
4345 void _bt_main_add_searched_title(bt_ug_data *ugd)
4348 Elm_Object_Item *git = NULL;
4350 git = elm_genlist_item_append(ugd->main_genlist,
4351 ugd->searched_title_itc,
4353 ELM_GENLIST_ITEM_NONE, NULL, NULL);
4355 elm_genlist_item_select_mode_set(git,
4356 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
4357 ugd->searched_title = git;
4359 BT_ERR("fail to append genlist item!");
4365 void _bt_update_device_list(bt_ug_data *ugd)
4367 Eina_List *l = NULL;
4368 bt_dev_t *dev = NULL;
4370 ret_if(ugd == NULL);
4372 EINA_LIST_FOREACH(ugd->paired_device, l, dev) {
4374 _bt_update_genlist_item((Elm_Object_Item *)
4378 EINA_LIST_FOREACH(ugd->searched_device, l, dev) {
4380 _bt_update_genlist_item((Elm_Object_Item *)