Add a padding before scan button in IOT common profile
[apps/native/ug-bluetooth-efl.git] / standard / bt-main-view.c
1 /*
2 * ug-bluetooth-efl
3 *
4 * Copyright 2012 Samsung Electronics Co., Ltd
5 *
6 * Contact: Hocheol Seo <hocheol.seo@samsung.com>
7 *           GirishAshok Joshi <girish.joshi@samsung.com>
8 *           DoHyun Pyun <dh79.pyun@samsung.com>
9 *
10 * Licensed under the Flora License, Version 1.1 (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
13 *
14 * http://www.tizenopensource.org/license
15 *
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.
21 *
22 */
23
24 #include <Ecore.h>
25 #include <errno.h>
26 #include <eina_list.h>
27 #include <aul.h>
28 #include <bluetooth.h>
29 #include <syspopup_caller.h>
30 #include <dbus/dbus.h>
31 #include <vconf.h>
32 #include <app_control.h>
33 #include <notification.h>
34 #include <efl_extension.h>
35 #include <bundle.h>
36
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"
42 #include "bt-debug.h"
43 #include "bt-util.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"
50
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"
53 #define APP_CONTROL_MIME_CONTACT "application/vnd.tizen.contact"
54 #define APP_CONTROL_MY_PROFILE_DATA_TYPE "my_profile"
55 #define SERVICE_SHARE_CONTACT_MODE "http://tizen.org/appcontrol/data/social/namecard_share_mode"
56 #define SERVICE_SHARE_CONTACT_ITEM "http://tizen.org/appcontrol/data/social/item_type"
57 #define SHARE_CONTACT_DATA_PATH "/opt/usr/media/Downloads/.bluetooth"
58 #define SHARE_CONTACT_ITEM_ID_ARRAY "http://tizen.org/appcontrol/data/social/item_id"
59 #define SHARE_CONTACT_ITEM_SHARE_MODE "http://tizen.org/appcontrol/data/social/namecard_share_mode"
60 #define HELP_SETUP_BLUETOOTH_URI                "tizen-help://ug-bluetooth-efl/setupbluetooth"
61
62 /* GATT Services */
63 #define HOGP_SERVICE_UUID "1812"
64
65 /**********************************************************************
66 *                                      Static Functions declaration
67 ***********************************************************************/
68
69 static void __bt_main_onoff_btn_cb(void *data, Evas_Object *obj, void *event_info);
70
71 static app_control_h __bt_main_get_bt_onoff_result(bt_ug_data *ugd,
72                                                 gboolean result);
73
74 static app_control_h __bt_main_get_pick_result(bt_ug_data *ugd, gboolean result);
75
76 static int __bt_main_request_to_send(bt_ug_data *ugd, bt_dev_t *dev);
77
78 #ifdef KIRAN_ACCESSIBILITY
79 static char *__bt_main_get_device_string(int major_class, int minor_class);
80 #endif
81 static Eina_Bool __bt_cb_register_net_state_cb(void *data);
82
83 /**********************************************************************
84 *                                               Static Functions
85 ***********************************************************************/
86
87 static char *__bt_main_onoff_label_get(void *data, Evas_Object *obj,
88                                                                 const char *part)
89 {
90         FN_START;
91         bt_ug_data *ugd = NULL;
92
93         retv_if(data == NULL, NULL);
94         ugd = (bt_ug_data *)data;
95
96         if (!strcmp("elm.text", part)) {
97                 return g_strdup(BT_STR_BLUETOOTH);
98         } else if (!strcmp("elm.text.multiline", part) || !strcmp("elm.text.sub", part)) {
99                 char buf[1024] = {0,};
100                 if (ugd->op_status == BT_ACTIVATING) {
101                         if (TIZEN_COMMON)
102                                 snprintf(buf, sizeof(buf), "<font_size=15>%s</font_size>", BT_STR_TURNING_ON_BLUETOOTH);
103                         else
104                                 snprintf(buf, sizeof(buf), "<font_size=30>%s</font_size>", BT_STR_TURNING_ON_BLUETOOTH);
105                         return g_strdup(buf);
106                 } else if (ugd->op_status == BT_DEACTIVATED) {
107                         if (TIZEN_COMMON)
108                                 snprintf(buf, sizeof(buf), "<font_size=15>%s</font_size>", BT_STR_TURN_ON_BLUETOOTH_TO_SEE_A_LIST_OF_AVAILABLE_DEVICES);
109                         else
110                                 snprintf(buf, sizeof(buf), "<font_size=30>%s</font_size>", BT_STR_TURN_ON_BLUETOOTH_TO_SEE_A_LIST_OF_AVAILABLE_DEVICES);
111
112                         return g_strdup(buf);
113                 }
114         }
115
116         FN_END;
117         return NULL;
118 }
119
120 static Evas_Object *__bt_main_onoff_icon_get(void *data, Evas_Object *obj,
121                                                 const char *part)
122 {
123         FN_START;
124
125         bt_ug_data *ugd = NULL;
126         Evas_Object *btn = NULL;
127         bool activated = false;
128         char *icon_part = NULL;
129
130         retv_if(data == NULL, NULL);
131
132         if (TIZEN_COMMON)
133                 icon_part = BT_GENLIST_ONOFF_ICON_PART_COMMON;
134         else
135                 icon_part = BT_GENLIST_ONOFF_ICON_PART;
136
137         ugd = (bt_ug_data *)data;
138
139         if (!strcmp(icon_part, part)) {
140                 if (ugd->op_status == BT_ACTIVATING
141                         || ugd->op_status == BT_DEACTIVATING) {
142                         btn = elm_progressbar_add(obj);
143
144                         if (TIZEN_COMMON)
145                                 elm_object_style_set(btn, "process_small");
146                         else
147                                 elm_object_style_set(btn, "process_medium");
148
149                         evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, 0.5);
150                         evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
151                         elm_progressbar_pulse(btn, TRUE);
152                 } else {
153                         activated = ((ugd->op_status == BT_DEACTIVATED) ||
154                                 (ugd->op_status == BT_ACTIVATING)) ? false : true;
155                         btn = elm_check_add(obj);
156                         elm_object_style_set(btn, "on&off");
157                         evas_object_pass_events_set(btn, EINA_TRUE);
158                         evas_object_propagate_events_set(btn, EINA_FALSE);
159                         elm_check_state_set(btn, activated);
160
161 #ifdef KIRAN_ACCESSIBILITY
162                         elm_access_object_unregister(btn);
163 #endif
164
165                         /* add smart callback */
166                         evas_object_smart_callback_add(btn, "changed",
167                                 __bt_main_onoff_btn_cb, ugd);
168
169                         ugd->onoff_btn = btn;
170                 }
171
172                 if (_bt_util_is_dpm_restricted(ugd->dpm_handle) == TRUE)
173                         elm_object_disabled_set(btn, EINA_TRUE);
174
175                 evas_object_show(btn);
176         }
177
178         FN_END;
179         return btn;
180 }
181
182 static char *__bt_main_rename_desc_label_get(void *data, Evas_Object *obj,
183                                               const char *part)
184 {
185         FN_START;
186
187         if (!strcmp("elm.text.multiline", part)) {
188                 char buf[1024] = {0,};
189                 snprintf(buf, sizeof(buf), "<font_size=30>%s</font_size>",
190                                 BT_STR_RENAME_DEVICE_LABEL);
191                 return g_strdup(buf);
192         }
193
194         FN_END;
195         return NULL;
196 }
197
198 static char *__bt_main_device_label_get(void *data, Evas_Object *obj,
199                                               const char *part)
200 {
201         FN_START;
202
203         bt_ug_data *ugd = NULL;
204         char buf[BT_GLOBALIZATION_STR_LENGTH] = { 0, };
205         char *dev_name = NULL;
206         char *ptr = NULL;
207 #ifdef KIRAN_ACCESSIBILITY
208         char str[BT_STR_ACCES_INFO_MAX_LEN] = { 0, };
209         Evas_Object *ao = NULL;
210 #endif
211         retv_if(data == NULL, NULL);
212
213         ugd = (bt_ug_data *)data;
214         BT_DBG("part : %s", part);
215
216         if (!strcmp("elm.text", part)) {
217                 memset(ugd->phone_name, 0x00, BT_GLOBALIZATION_STR_LENGTH);
218
219                 _bt_util_get_phone_name(ugd->phone_name, sizeof(ugd->phone_name));
220
221                 if (strlen(ugd->phone_name) == 0) {
222                         if (bt_adapter_get_name(&dev_name) == BT_ERROR_NONE) {
223                                 g_strlcpy(ugd->phone_name, dev_name,
224                                           BT_GLOBALIZATION_STR_LENGTH);
225                                 g_free(dev_name);
226                         }
227                 }
228
229                 BT_DBG("ugd->phone_name : %s[%zd]", ugd->phone_name, strlen(ugd->phone_name));
230                 /* Check the utf8 valitation & Fill the NULL in the invalid location */
231                 if (!g_utf8_validate(ugd->phone_name, -1, (const char **)&ptr))
232                         *ptr = '\0';
233
234                 dev_name = elm_entry_utf8_to_markup(ugd->phone_name);
235                 if (dev_name) {
236                         g_strlcpy(buf, dev_name, BT_GLOBALIZATION_STR_LENGTH);
237                         g_free(dev_name);
238                 } else
239                         g_strlcpy(buf, ugd->phone_name, BT_GLOBALIZATION_STR_LENGTH);
240
241 #ifdef KIRAN_ACCESSIBILITY
242                 snprintf(str, sizeof(str), "%s, %s",
243                          BT_STR_DEVICE_NAME, ugd->phone_name);
244                 ao = elm_object_item_access_object_get(ugd->device_name_item);
245                 elm_access_info_set(ao, ELM_ACCESS_INFO, str);
246 #endif
247                 FN_END;
248                 BT_DBG("buf : %s[%zd]", buf, strlen(buf));
249                 return strdup(buf);
250         } else if (!strcmp("elm.text.sub", part)) {
251                 g_strlcpy(buf, BT_STR_MY_DEVICE,
252                           BT_GLOBALIZATION_STR_LENGTH);
253 #ifdef KIRAN_ACCESSIBILITY
254                 ao = elm_object_item_access_object_get(ugd->paired_title);
255                 snprintf(str, sizeof(str), "%s, %s", BT_STR_PAIRED_DEVICES,
256                          BT_ACC_STR_GROUP_INDEX);
257                 elm_access_info_set(ao, ELM_ACCESS_INFO, str);
258 #endif
259                 FN_END;
260                 return strdup(buf);
261         } else {
262                 BT_ERR("This part name is not exist in style.");
263                 return NULL;
264         }
265 }
266
267 char* __bt_convert_rgba_to_hex(int r, int g, int b, int a)
268 {
269         int hexcolor = 0;
270         char* string = NULL;
271
272         string = g_try_malloc0(sizeof(char) * 255);
273         /* Fix : NULL_RETURNS */
274         if (string == NULL)
275                 return NULL;
276
277         hexcolor = (r << 24) + (g << 16) + (b << 8) + a;
278         sprintf(string, "%08x", hexcolor);
279
280         return string;
281 }
282
283 int _bt_idle_destroy_ug(void *data)
284 {
285         FN_START;
286
287         bt_ug_data *ugd = data;
288         app_control_h service = NULL;
289
290         retv_if(ugd == NULL, BT_UG_FAIL);
291
292         if (ugd->bt_launch_mode == BT_LAUNCH_PICK)
293                 service = __bt_main_get_pick_result(ugd, TRUE);
294         else if (ugd->bt_launch_mode == BT_LAUNCH_ONOFF)
295                 service = __bt_main_get_bt_onoff_result(ugd, TRUE);
296
297         _bt_ug_destroy(data, (void *)service);
298
299         if (service)
300                 app_control_destroy(service);
301
302         FN_END;
303         return BT_UG_ERROR_NONE;
304 }
305
306 gboolean _bt_main_is_connectable_device(bt_dev_t *dev)
307 {
308         FN_START;
309
310         bt_device_info_s *device_info = NULL;
311
312         retv_if(dev == NULL, FALSE);
313
314         /* For LE Device */
315         if (TIZEN_FEATURE_BT_HOG && dev->is_le_device) {
316                 BT_DBG("It is LE Device");
317                 return TRUE;
318         }
319
320         if (dev->service_list == 0) {
321                 if (bt_adapter_get_bonded_device_info
322                     ((const char *)dev->addr_str,
323                      &device_info) != BT_ERROR_NONE) {
324                         if (device_info)
325                                 bt_adapter_free_device_info(device_info);
326                         return FALSE;
327                 }
328                 bt_device_get_service_mask_from_uuid_list
329                     (device_info->service_uuid, device_info->service_count,
330                      &dev->service_list);
331
332                 bt_adapter_free_device_info(device_info);
333
334                 if (dev->service_list == 0) {
335                         BT_ERR("No service list");
336                         return FALSE;
337                 }
338         }
339
340         if ((dev->service_list & BT_SC_HFP_SERVICE_MASK) ||
341             (dev->service_list & BT_SC_HSP_SERVICE_MASK) ||
342             (dev->service_list & BT_SC_A2DP_SERVICE_MASK) ||
343 #ifdef TIZEN_BT_A2DP_SINK_ENABLE
344             (dev->service_list & BT_SC_A2DP_SOURCE_SERVICE_MASK) ||
345 #endif
346             (dev->service_list & BT_SC_HID_SERVICE_MASK) ||
347             (dev->service_list & BT_SC_NAP_SERVICE_MASK)) {
348                 /* Connectable device */
349                 return TRUE;
350         }
351
352         FN_END;
353         return FALSE;
354 }
355
356 static char *__bt_main_paired_device_label_get(void *data, Evas_Object *obj,
357                                       const char *part)
358 {
359         FN_START;
360
361         char *buf = NULL;
362 #ifdef KIRAN_ACCESSIBILITY
363         char str[BT_STR_ACCES_INFO_MAX_LEN] = { 0, };
364 #endif
365         bt_dev_t *dev = NULL;
366         bt_ug_data *ugd = NULL;
367         int r = 0, g = 0, b = 0, a = 0;
368
369         retv_if(data == NULL, NULL);
370
371         dev = (bt_dev_t *)data;
372         retv_if(dev == NULL, NULL);
373
374         ugd = (bt_ug_data *)dev->ugd;
375         retv_if(ugd == NULL, NULL);
376
377         if (!strcmp("elm.text", part)) {
378                 char *name = elm_entry_utf8_to_markup(dev->name);
379
380                 if (ugd->bt_launch_mode != BT_LAUNCH_PICK &&
381                         dev->is_connected > 0 && dev->highlighted == FALSE) {
382                         r = 20, g = 107, b = 147, a = 255;
383                         char *color_code = __bt_convert_rgba_to_hex(r, g, b, a);
384                         if (name) {
385                                 buf = g_strdup_printf("<color=#%s>%s</color>",
386                                         color_code,
387                                         name);
388                                 free(name);
389                         } else {
390                                 buf = g_strdup_printf("<color=#%s>%s</color>",
391                                         color_code,
392                                         dev->name);
393                         }
394                         g_free(color_code);
395                         return buf;
396                 }
397
398                 if (name) {
399                         buf = g_strdup_printf("%s",
400                                 name);
401                         free(name);
402                 } else {
403                         buf = g_strdup_printf("%s",
404                                 dev->name);
405                 }
406         } else if (!strcmp("elm.text.sub", part) && ugd->bt_launch_mode != BT_LAUNCH_PICK) {
407 #ifdef KIRAN_ACCESSIBILITY
408                 char *double_tap_string = NULL;
409                 char *device_type = NULL;
410                 Evas_Object *ao = NULL;
411 #endif
412
413                 if (dev->status == BT_IDLE) {
414                         if (_bt_main_is_connectable_device(dev)) {
415                                 if (dev->is_connected == 0) {
416                                         buf = g_strdup(BT_STR_PAIRED);
417 #ifdef KIRAN_ACCESSIBILITY
418                                         double_tap_string = NULL;
419 #endif
420                                 } else if (dev->is_connected > 0) {
421                                         buf = g_strdup(BT_STR_CONNECTED);
422 #ifdef KIRAN_ACCESSIBILITY
423                                         double_tap_string =
424                                             BT_STR_DOUBLE_TAP_DISCONNECT_D;
425 #endif
426                                 }
427                         } else {
428                                 buf = g_strdup(BT_STR_PAIRED);
429 #ifdef KIRAN_ACCESSIBILITY
430                                 double_tap_string = BT_STR_DOUBLE_TAP_CONNECT_D;
431 #endif
432                         }
433                 } else if (dev->status == BT_CONNECTING) {
434                         buf = g_strdup(BT_STR_CONNECTING);
435                 } else if (dev->status == BT_SERVICE_SEARCHING) {
436                         buf = g_strdup(BT_STR_SEARCHING_SERVICES);
437                 } else if (dev->status == BT_DISCONNECTING) {
438                         buf = g_strdup(BT_STR_DISCONNECTING);
439                 }
440 #ifdef KIRAN_ACCESSIBILITY
441                 device_type =
442                                 __bt_main_get_device_string(dev->major_class,
443                                                 dev->minor_class);
444                 if (double_tap_string != NULL && buf != NULL)
445                         snprintf(str, sizeof(str), "%s, %s, %s, %s, %s",
446                                  dev->name, buf,
447                                  device_type, double_tap_string,
448                                  BT_STR_MORE_BUTTON);
449                 else if (double_tap_string == NULL && buf != NULL)
450                         snprintf(str, sizeof(str), "%s, %s, %s, %s",
451                                  dev->name, buf,
452                                  device_type, BT_STR_MORE_BUTTON);
453
454                 g_free(device_type);
455                 ao = elm_object_item_access_object_get(dev->genlist_item);
456                 elm_access_info_set(ao, ELM_ACCESS_INFO, str);
457 #endif
458         } else {                /* for empty item */
459
460                 BT_ERR("empty text for label");
461                 return NULL;
462         }
463         FN_END;
464         return buf;
465 }
466
467 static void __bt_paired_device_profile_cb(void *data, Evas_Object *obj,
468                                      void *event_info)
469 {
470         FN_START;
471         int ret;
472         bt_dev_t *dev = NULL;
473         bt_ug_data *ugd = NULL;
474
475         ret_if(data == NULL);
476
477         dev = (bt_dev_t *)data;
478         ret_if(dev->ugd == NULL);
479
480         ugd = dev->ugd;
481
482         if (event_info)
483                 elm_genlist_item_selected_set((Elm_Object_Item *)event_info,
484                                                   EINA_FALSE);
485
486         if (ugd->op_status == BT_SEARCHING) {
487                 ret = bt_adapter_stop_device_discovery();
488                 if (ret != BT_ERROR_NONE)
489                         BT_ERR("Fail to stop discovery: %d", ret);
490         }
491
492         /* Create the profile view */
493         _bt_profile_create_view(dev);
494         FN_END;
495 }
496
497 static void __bt_rename_device_entry_changed_cb(void *data, Evas_Object *obj,
498                                 void *event_info)
499 {
500         FN_START;
501         ret_if(obj == NULL);
502         ret_if(data == NULL);
503         bt_ug_data *ugd = NULL;
504
505         ugd = (bt_ug_data *)data;
506
507         const char *entry_text = NULL;
508         char *input_str = NULL;
509
510         if (ugd->rename_entry != obj)
511                 ugd->rename_entry = obj;
512         entry_text = elm_entry_entry_get(obj);
513         input_str = elm_entry_markup_to_utf8(entry_text);
514
515         if (input_str == NULL || strlen(input_str) == 0 ||
516                                 _bt_util_is_space_str(input_str)) {
517                 BT_DBG("");
518                 elm_object_disabled_set(ugd->rename_button, EINA_TRUE);
519                 elm_entry_input_panel_return_key_disabled_set(
520                                 obj, EINA_TRUE);
521         } else {
522                 BT_DBG("");
523                 if (elm_object_disabled_get(ugd->rename_button))
524                         elm_object_disabled_set(ugd->rename_button, EINA_FALSE);
525                 if (elm_entry_input_panel_return_key_disabled_get(obj))
526                         elm_entry_input_panel_return_key_disabled_set(obj, EINA_FALSE);
527         }
528         if (input_str != NULL) {
529                 free(input_str);
530                 input_str = NULL;
531         }
532
533         FN_END;
534 }
535
536 static void __bt_rename_device_cancel_cb(void *data, Evas_Object *obj,
537                                 void *event_info)
538 {
539         FN_START;
540         bt_ug_data *ugd = NULL;
541
542         ret_if(data == NULL);
543         ugd = (bt_ug_data *)data;
544
545         if (ugd->rename_entry) {
546                 elm_entry_input_panel_hide(ugd->rename_entry);
547                 elm_object_focus_set(ugd->rename_entry, EINA_FALSE);
548         }
549
550         if (ugd->rename_popup != NULL) {
551                 evas_object_del(ugd->rename_popup);
552                 ugd->rename_popup = NULL;
553                 ugd->rename_entry_item = NULL;
554                 ugd->rename_entry = NULL;
555         }
556
557         FN_END;
558 }
559
560 static void __bt_rename_device_ok_cb(void *data, Evas_Object *obj,
561                                 void *event_info)
562 {
563         FN_START;
564         bt_ug_data *ugd = (bt_ug_data *) data;
565
566         const char *entry_str = elm_entry_entry_get(ugd->rename_entry);
567         char *device_name_str = NULL;
568         device_name_str = elm_entry_markup_to_utf8(entry_str);
569         ret_if(!device_name_str);
570         BT_DBG("Device name:[%s]", device_name_str);
571
572         if (0 != vconf_set_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR, device_name_str))
573                 BT_ERR("Set vconf[%s] failed", VCONFKEY_SETAPPL_DEVICE_NAME_STR);
574
575         _bt_update_genlist_item(ugd->device_name_item);
576
577         if (ugd->rename_entry) {
578                 elm_entry_input_panel_hide(ugd->rename_entry);
579                 elm_object_focus_set(ugd->rename_entry, EINA_FALSE);
580         }
581
582         evas_object_del(ugd->rename_popup);
583         ugd->rename_popup = NULL;
584         ugd->rename_entry_item = NULL;
585         ugd->rename_entry = NULL;
586         g_free(device_name_str);
587
588         FN_END;
589 }
590
591 static void __bt_rename_entry_changed_cb(void *data, Evas_Object *obj,
592                                 void *event_info)
593 {
594         FN_START;
595         ret_if(!data);
596         bt_ug_data *ugd = (bt_ug_data *) data;
597         ret_if(!ugd->rename_entry_item);
598
599         if (elm_object_part_content_get(obj, "elm.icon.eraser")) {
600                 if (elm_object_focus_get(obj)) {
601                         if (elm_entry_is_empty(obj)) {
602                                 elm_object_item_signal_emit(ugd->rename_entry_item,
603                                         "elm,state,eraser,hide", "");
604                         } else {
605                                 elm_object_item_signal_emit(ugd->rename_entry_item,
606                                         "elm,state,eraser,show", "");
607                         }
608                 }
609         }
610         __bt_rename_device_entry_changed_cb(data, obj, event_info);
611
612         FN_END;
613 }
614
615 static void __bt_main_entry_edit_mode_show_cb(void *data, Evas *e, Evas_Object *obj,
616                                 void *event_info)
617 {
618         evas_object_event_callback_del(obj, EVAS_CALLBACK_SHOW,
619                                                 __bt_main_entry_edit_mode_show_cb);
620
621         elm_object_focus_set(obj, EINA_TRUE);
622         elm_entry_cursor_end_set(obj);
623 }
624
625 static void __bt_main_popup_entry_activated_cb(void *data, Evas_Object *obj, void *event_info)
626 {
627         if (!obj)
628                 return;
629
630         elm_object_focus_set(obj, EINA_FALSE);
631 }
632
633 static Evas_Object *__bt_main_rename_entry_icon_get(
634                                 void *data, Evas_Object *obj, const char *part)
635 {
636         FN_START;
637         retv_if(obj == NULL || data == NULL, NULL);
638
639         Evas_Object *entry = NULL;
640         char *name_value = NULL;
641         char *name_value_utf = NULL;
642
643         static Elm_Entry_Filter_Limit_Size limit_filter_data;
644         bt_ug_data *ugd = (bt_ug_data *)data;
645
646         if (!strcmp(part, "elm.swallow.content")) {
647                 Evas_Object *layout = NULL;
648
649                 layout = elm_layout_add(obj);
650                 elm_layout_theme_set(layout, "layout", "editfield", "singleline");
651                 evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, 0.0);
652                 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, 0.0);
653
654                 name_value_utf = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
655                 retvm_if(!name_value_utf, NULL, "Get string is failed");
656
657                 name_value = elm_entry_utf8_to_markup(name_value_utf);
658
659                 entry = elm_entry_add(layout);
660                 elm_entry_single_line_set(entry, EINA_TRUE);
661                 elm_entry_scrollable_set(entry, EINA_TRUE);
662
663                 evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, 0.0);
664                 evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, 0.0);
665
666                 eext_entry_selection_back_event_allow_set(entry, EINA_TRUE);
667                 elm_object_signal_emit(entry, "elm,action,hide,search_icon", "");
668                 elm_object_part_text_set(entry, "guide", BT_STR_DEVICE_NAME);
669                 elm_object_text_set(entry, name_value);
670                 elm_entry_input_panel_imdata_set(entry, "action=disable_emoticons", 24);
671
672                 elm_entry_input_panel_return_key_type_set(entry, ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DONE);
673                 limit_filter_data.max_char_count = DEVICE_NAME_MAX_CHARACTER;
674                 elm_entry_markup_filter_append(entry,
675                         elm_entry_filter_limit_size, &limit_filter_data);
676
677                 elm_entry_cnp_mode_set(entry, ELM_CNP_MODE_PLAINTEXT);
678                 elm_entry_input_panel_layout_set(entry, ELM_INPUT_PANEL_LAYOUT_NORMAL);
679                 elm_entry_prediction_allow_set(entry, EINA_FALSE);
680                 elm_entry_autocapital_type_set(entry, ELM_AUTOCAPITAL_TYPE_NONE);
681
682                 evas_object_smart_callback_add(entry, "maxlength,reached",
683                                 _bt_util_max_len_reached_cb, ugd);
684                 evas_object_smart_callback_add(entry, "changed",
685                                 __bt_rename_entry_changed_cb, ugd);
686                 evas_object_smart_callback_add(entry, "preedit,changed",
687                                 __bt_rename_entry_changed_cb, ugd);
688                 evas_object_smart_callback_add(entry, "activated",
689                                                 __bt_main_popup_entry_activated_cb, NULL);
690                 evas_object_event_callback_add(entry, EVAS_CALLBACK_SHOW,
691                                 __bt_main_entry_edit_mode_show_cb, ugd);
692
693                 elm_entry_input_panel_show(entry);
694                 elm_object_part_content_set(layout, "elm.swallow.content", entry);
695
696                 ugd->rename_entry = entry;
697
698                 if (name_value_utf)
699                         free(name_value_utf);
700                 if (name_value)
701                         free(name_value);
702
703                 return layout;
704         }
705
706         return NULL;
707 }
708
709 static Evas_Object *__bt_main_paired_device_icon_get(void *data, Evas_Object *obj,
710                                             const char *part)
711 {
712         FN_START;
713
714         Evas_Object *btn = NULL;
715         Evas_Object *icon = NULL;
716         char *dev_icon_file = NULL;
717         bt_dev_t *dev = NULL;
718
719         retv_if(data == NULL, NULL);
720
721         dev = (bt_dev_t *)data;
722
723         if (!strcmp("elm.swallow.icon", part) || !strcmp("elm.icon", part)) {
724                 if ((dev->major_class == BT_MAJOR_DEV_CLS_MISC)
725                                 && (dev->service_list != 0))
726                         _bt_util_update_class_of_device_by_service_list(dev->service_list,
727                                         &dev->major_class, &dev->minor_class);
728
729                 dev_icon_file =
730                     _bt_main_get_device_icon(dev->major_class,
731                                              dev->minor_class,
732                                              dev->is_connected,
733                                              dev->highlighted);
734
735                 icon = _bt_create_icon(obj, dev_icon_file);
736                 evas_object_propagate_events_set(icon, EINA_FALSE);
737                 evas_object_show(icon);
738                 dev->icon = icon;
739                 if (dev->highlighted || dev->is_connected)
740                         evas_object_color_set(dev->icon, 20, 107, 147, 255);
741                 else
742                         evas_object_color_set(dev->icon, 76, 76, 76, 255);
743
744                 if (TIZEN_COMMON)
745                         evas_object_size_hint_min_set(icon, ELM_SCALE_SIZE(30), ELM_SCALE_SIZE(30));
746                 else
747                         evas_object_size_hint_min_set(icon, ELM_SCALE_SIZE(40), ELM_SCALE_SIZE(40));
748         } else if (!strcmp("elm.swallow.end", part) || !strcmp("elm.end", part)) {
749                 BT_INFO("status : %d", dev->status);
750
751                 if (dev->status == BT_IDLE) {
752                         btn = elm_button_add(obj);
753
754                         if (TIZEN_COMMON)
755                                 elm_object_style_set(btn, "info_button_small");
756                         else
757                                 elm_object_style_set(btn, "info_button");
758
759                         evas_object_propagate_events_set(btn, EINA_FALSE);
760                         evas_object_smart_callback_add(btn, "clicked",
761                                                        __bt_paired_device_profile_cb,
762                                                        (void *)dev);
763                         evas_object_show(btn);
764                         return btn;
765                 } else {
766                         btn = elm_progressbar_add(obj);
767
768                         if (TIZEN_COMMON)
769                                 elm_object_style_set(btn, "process_small");
770                         else
771                                 elm_object_style_set(btn, "process_medium");
772
773                         evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, 0.5);
774                         evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
775                         elm_progressbar_pulse(btn, TRUE);
776
777                         evas_object_show(btn);
778                         return btn;
779                 }
780
781         }
782
783         FN_END;
784         return icon;
785 }
786
787 static char *__bt_main_searched_label_get(void *data, Evas_Object *obj,
788                                           const char *part)
789 {
790         char buf[BT_GLOBALIZATION_STR_LENGTH] = { 0 };
791         bt_dev_t *dev = NULL;
792
793         if (data == NULL)
794                 return NULL;
795
796         dev = (bt_dev_t *)data;
797         if (!strcmp("elm.text", part)) {
798 #ifdef KIRAN_ACCESSIBILITY
799                 char str[BT_STR_ACCES_INFO_MAX_LEN] = { 0, };
800                 Evas_Object *ao = NULL;
801 #endif
802                 char *dev_name_markup = elm_entry_utf8_to_markup(dev->name);
803
804                 if (dev_name_markup) {
805                         g_strlcpy(buf, dev_name_markup,
806                                         BT_GLOBALIZATION_STR_LENGTH);
807                         free(dev_name_markup);
808                 } else {
809                         g_strlcpy(buf, dev->name, BT_GLOBALIZATION_STR_LENGTH);
810                 }
811
812                 BT_INFO("label : %s", buf);
813 #ifdef KIRAN_ACCESSIBILITY
814                 snprintf(str, sizeof(str), "%s, %s", dev->name,
815                          BT_STR_DOUBLE_TAP_CONNECT);
816
817                 ao = elm_object_item_access_object_get(dev->genlist_item);
818                 elm_access_info_set(ao, ELM_ACCESS_INFO, str);
819 #endif
820         } else {
821                 BT_ERR("empty text for label");
822                 return NULL;
823         }
824
825         return strdup(buf);
826 }
827
828 static Evas_Object *__bt_main_searched_icon_get(void *data,
829                                                 Evas_Object *obj,
830                                                 const char *part)
831 {
832         Evas_Object *icon = NULL;
833         char *dev_icon_file = NULL;
834         bt_dev_t *dev = NULL;
835
836         retv_if(data == NULL, NULL);
837
838         dev = (bt_dev_t *)data;
839
840         if (!strcmp("elm.swallow.icon", part) || !strcmp("elm.icon", part)) {
841                 dev_icon_file =
842                     _bt_main_get_device_icon(dev->major_class,
843                                              dev->minor_class,
844                                              dev->is_connected,
845                                              dev->highlighted);
846                 icon = _bt_create_icon(obj, dev_icon_file);
847                 if (dev->highlighted || dev->is_connected)
848                         evas_object_color_set(icon, 20, 107, 147, 255);
849                 else
850                         evas_object_color_set(icon, 76, 76, 76, 255);
851                 evas_object_propagate_events_set(icon, EINA_FALSE);
852         } else if (!strcmp("elm.swallow.end", part) || !strcmp("elm.end", part)) {
853                 if (dev->status != BT_IDLE) {
854                         icon = _bt_create_progressbar(obj, "process_medium");
855                         evas_object_color_set(icon, 76, 76, 76, 255);
856                 }
857         }
858
859         if (icon) {
860                 evas_object_show(icon);
861                 if (TIZEN_COMMON)
862                         evas_object_size_hint_min_set(icon, ELM_SCALE_SIZE(30), ELM_SCALE_SIZE(30));
863                 else
864                         evas_object_size_hint_min_set(icon, ELM_SCALE_SIZE(40), ELM_SCALE_SIZE(40));
865         }
866
867         return icon;
868 }
869
870 static char *__bt_main_no_device_label_get(void *data, Evas_Object *obj,
871                                            const char *part)
872 {
873         FN_START;
874
875         char buf[BT_GLOBALIZATION_STR_LENGTH] = { 0 };
876 #ifdef KIRAN_ACCESSIBILITY
877         bt_ug_data *ugd = NULL;
878         char str[BT_STR_ACCES_INFO_MAX_LEN] = { 0, };
879         Evas_Object *ao = NULL;
880 #endif
881         if (!strcmp("elm.text", part)) {
882                 g_strlcpy(buf, BT_STR_NO_DEVICE_FOUND,
883                           BT_GLOBALIZATION_STR_LENGTH);
884                 snprintf(buf, sizeof(buf), "<align=center>%s</align>", BT_STR_NO_DEVICE_FOUND);
885
886 #ifdef KIRAN_ACCESSIBILITY
887                 retv_if(data == NULL, NULL);
888                 ugd = (bt_ug_data *)data;
889                 g_strlcpy(str, BT_STR_NO_DEVICE_FOUND,
890                           BT_STR_ACCES_INFO_MAX_LEN);
891
892                 ao = elm_object_item_access_object_get(ugd->no_device_item);
893                 elm_access_info_set(ao, ELM_ACCESS_INFO, str);
894 #endif
895         } else {
896                 BT_ERR("empty text for label");
897                 return NULL;
898         }
899
900         FN_END;
901         return strdup(buf);
902 }
903
904 static char *__bt_main_paired_title_label_get(void *data, Evas_Object *obj,
905                                               const char *part)
906 {
907         FN_START;
908
909         char buf[BT_GLOBALIZATION_STR_LENGTH] = { 0, };
910 #ifdef KIRAN_ACCESSIBILITY
911         bt_ug_data *ugd = NULL;
912         char str[BT_STR_ACCES_INFO_MAX_LEN] = { 0, };
913         Evas_Object *ao = NULL;
914 #endif
915         if (!strcmp("elm.text", part)) {
916                 /*Label */
917                 g_strlcpy(buf, BT_STR_PAIRED_DEVICES,
918                           BT_GLOBALIZATION_STR_LENGTH);
919         } else
920                 return NULL;
921
922 #ifdef KIRAN_ACCESSIBILITY
923         retv_if(data == NULL, NULL);
924         ugd = (bt_ug_data *)data;
925         ao = elm_object_item_access_object_get(ugd->paired_title);
926         snprintf(str, sizeof(str), "%s, %s", BT_STR_PAIRED_DEVICES,
927                  BT_ACC_STR_GROUP_INDEX);
928         elm_access_info_set(ao, ELM_ACCESS_INFO, str);
929 #endif
930         FN_END;
931         return strdup(buf);
932 }
933
934 static char *__bt_main_searched_title_label_get(void *data, Evas_Object *obj,
935                                                 const char *part)
936 {
937         FN_START;
938
939         char buf[BT_GLOBALIZATION_STR_LENGTH] = { 0, };
940         bt_ug_data *ugd = NULL;
941 #ifdef KIRAN_ACCESSIBILITY
942         Evas_Object *ao = NULL;
943         char str[BT_STR_ACCES_INFO_MAX_LEN] = { 0, };
944 #endif
945
946         retv_if(data == NULL, NULL);
947
948         ugd = (bt_ug_data *)data;
949         if (!strcmp("elm.text", part)) {
950                 /* Label */
951                 if (ugd->searched_device == NULL ||
952                     eina_list_count(ugd->searched_device) == 0) {
953                         if (ugd->op_status == BT_SEARCHING) {
954                                 g_strlcpy(buf, BT_STR_SCANNING,
955                                           BT_GLOBALIZATION_STR_LENGTH);
956                         } else if (ugd->op_status == BT_ACTIVATED) {
957                                 g_strlcpy(buf, BT_STR_BLUETOOTH_DEVICES,
958                                           BT_GLOBALIZATION_STR_LENGTH);
959                         }
960                 } else {
961                         g_strlcpy(buf, BT_STR_AVAILABLE_DEVICES,
962                                   BT_GLOBALIZATION_STR_LENGTH);
963                 }
964
965 #ifdef KIRAN_ACCESSIBILITY
966                 snprintf(str, sizeof(str), "%s, %s",
967                                         buf, BT_ACC_STR_GROUP_INDEX);
968                 ao = elm_object_item_access_object_get(ugd->searched_title);
969                 elm_access_info_set(ao, ELM_ACCESS_INFO, str);
970 #endif
971         } else {
972                 return NULL;
973         }
974
975         FN_END;
976         return strdup(buf);
977 }
978
979 static Evas_Object *__bt_main_searched_title_icon_get(void *data, Evas_Object *obj,
980                                              const char *part)
981 {
982         FN_START;
983
984         bt_ug_data *ugd = NULL;
985         Evas_Object *progressbar = NULL;
986
987         retv_if(data == NULL, NULL);
988         retv_if(obj == NULL, NULL);
989         retv_if(part == NULL, NULL);
990
991         ugd = (bt_ug_data *)data;
992
993         if ((!strcmp("elm.swallow.end", part) || !strcmp("elm.end", part)) && ugd->op_status == BT_SEARCHING)
994                 progressbar = _bt_create_progressbar(obj, "process_small");
995
996         FN_END;
997         return progressbar;
998 }
999
1000 static app_control_h __bt_main_get_bt_onoff_result(bt_ug_data *ugd,
1001                                                         gboolean result)
1002 {
1003         app_control_h service = NULL;
1004         const char *result_str;
1005         bt_adapter_state_e bt_state = BT_ADAPTER_DISABLED;
1006
1007         retv_if(ugd == NULL, NULL);
1008
1009         app_control_create(&service);
1010
1011         retv_if(service == NULL, NULL);
1012
1013         if (result == TRUE)
1014                 result_str = BT_RESULT_SUCCESS;
1015         else
1016                 result_str = BT_RESULT_FAIL;
1017
1018         if (app_control_add_extra_data(service, "result", result_str) < 0)
1019                 BT_ERR("Fail to add extra data");
1020
1021         if (bt_adapter_get_state(&bt_state) == BT_ERROR_NONE) {
1022                 if (bt_state == BT_ADAPTER_ENABLED) {
1023                         if (app_control_add_extra_data(service, "bt_status", BT_ADAPTER_ON) < 0)
1024                                 BT_ERR("Fail to add extra data");
1025                 } else {
1026                         if (app_control_add_extra_data(service, "bt_status", BT_ADAPTER_OFF) < 0)
1027                                 BT_ERR("Fail to add extra data");
1028                 }
1029         } else {
1030                 BT_ERR("Fail to bt_adapter_get_state");
1031         }
1032
1033         return service;
1034 }
1035
1036 static app_control_h __bt_main_get_pick_result(bt_ug_data *ugd, gboolean result)
1037 {
1038         app_control_h service = NULL;
1039         const char *result_str;
1040         char address[BT_ADDRESS_STR_LEN] = { 0 };
1041         char value_str[BT_RESULT_STR_MAX] = { 0 };
1042         bt_dev_t *dev;
1043
1044         retv_if(ugd == NULL, NULL);
1045         retv_if(ugd->pick_device == NULL, NULL);
1046
1047         dev = ugd->pick_device;
1048
1049         app_control_create(&service);
1050
1051         retv_if(service == NULL, NULL);
1052
1053         if (result == TRUE)
1054                 result_str = BT_RESULT_SUCCESS;
1055         else
1056                 result_str = BT_RESULT_FAIL;
1057
1058         if (app_control_add_extra_data(service, "result", result_str) < 0)
1059                 BT_ERR("Fail to add extra data");
1060
1061         _bt_util_addr_type_to_addr_result_string(address, dev->bd_addr);
1062
1063         /* Original output fields will be removed */
1064         if (app_control_add_extra_data(service, "address",
1065                                    (const char *)address) < 0) {
1066                 BT_ERR("Fail to add extra data");
1067         }
1068
1069         if (app_control_add_extra_data(service, BT_APPCONTROL_ADDRESS,
1070                                    (const char *)address) < 0) {
1071                 BT_ERR("Fail to add extra data");
1072         }
1073
1074         if (app_control_add_extra_data(service, "name",
1075                                    (const char *)dev->name) < 0) {
1076                 BT_ERR("Fail to add extra data");
1077         }
1078
1079         if (app_control_add_extra_data(service, BT_APPCONTROL_NAME,
1080                                    (const char *)dev->name) < 0) {
1081                 BT_ERR("Fail to add extra data");
1082         }
1083
1084         snprintf(value_str, BT_RESULT_STR_MAX, "%d", dev->rssi);
1085
1086         if (app_control_add_extra_data(service, "rssi",
1087                                    (const char *)value_str) < 0) {
1088                 BT_ERR("Fail to add extra data");
1089         }
1090
1091         if (app_control_add_extra_data(service, BT_APPCONTROL_RSSI,
1092                                    (const char *)value_str) < 0) {
1093                 BT_ERR("Fail to add extra data");
1094         }
1095
1096         memset(value_str, 0x00, sizeof(value_str));
1097         snprintf(value_str, BT_RESULT_STR_MAX, "%d", dev->is_bonded);
1098
1099         if (app_control_add_extra_data(service, "is_bonded",
1100                                    (const char *)value_str) < 0) {
1101                 BT_ERR("Fail to add extra data");
1102         }
1103
1104         if (app_control_add_extra_data(service, BT_APPCONTROL_IS_PAIRED,
1105                                    (const char *)value_str) < 0) {
1106                 BT_ERR("Fail to add extra data");
1107         }
1108
1109         memset(value_str, 0x00, sizeof(value_str));
1110         snprintf(value_str, BT_RESULT_STR_MAX, "%d", dev->major_class);
1111
1112         if (app_control_add_extra_data(service, "major_class",
1113                                    (const char *)value_str) < 0) {
1114                 BT_ERR("Fail to add extra data");
1115         }
1116
1117         if (app_control_add_extra_data(service, BT_APPCONTROL_MAJOR_CLASS,
1118                                    (const char *)value_str) < 0) {
1119                 BT_ERR("Fail to add extra data");
1120         }
1121
1122         memset(value_str, 0x00, sizeof(value_str));
1123         snprintf(value_str, BT_RESULT_STR_MAX, "%d", dev->minor_class);
1124
1125         if (app_control_add_extra_data(service, "minor_class",
1126                                    (const char *)value_str) < 0) {
1127                 BT_ERR("Fail to add extra data");
1128         }
1129
1130         if (app_control_add_extra_data(service, BT_APPCONTROL_MINOR_CLASS,
1131                                    (const char *)value_str) < 0) {
1132                 BT_ERR("Fail to add extra data");
1133         }
1134
1135         memset(value_str, 0x00, sizeof(value_str));
1136         snprintf(value_str, BT_RESULT_STR_MAX, "%ld",
1137                  (long int)dev->service_class);
1138
1139         if (app_control_add_extra_data(service, "service_class",
1140                                    (const char *)value_str) < 0) {
1141                 BT_ERR("Fail to add extra data");
1142         }
1143
1144         if (app_control_add_extra_data(service, BT_APPCONTROL_SERVICE_CLASS,
1145                                    (const char *)value_str) < 0) {
1146                 BT_ERR("Fail to add extra data");
1147         }
1148
1149         if (app_control_add_extra_data_array(service, "uuids",
1150                                          (const char **)dev->uuids,
1151                                          dev->uuid_count) < 0) {
1152                 BT_ERR("Fail to add extra data");
1153         }
1154
1155         if (app_control_add_extra_data_array(service, BT_APPCONTROL_UUID_LIST,
1156                                          (const char **)dev->uuids,
1157                                          dev->uuid_count) < 0) {
1158                 BT_ERR("Fail to add extra data");
1159         }
1160
1161         return service;
1162 }
1163
1164 static Eina_Bool __bt_main_quit_btn_cb(void *data, Elm_Object_Item *it)
1165 {
1166         FN_START;
1167         app_control_h reply = NULL;
1168         app_control_h service = NULL;
1169         bt_ug_data *ugd = (bt_ug_data *)data;
1170
1171         retv_if(ugd == NULL, EINA_FALSE);
1172
1173         if (ugd->bt_launch_mode == BT_LAUNCH_PICK) {
1174                 app_control_create(&service);
1175
1176                 if (service == NULL) {
1177                         _bt_ug_destroy(data, NULL);
1178                         return EINA_FALSE;
1179                 }
1180
1181                 if (app_control_add_extra_data(service, "result",
1182                                            BT_RESULT_FAIL) < 0) {
1183                         BT_ERR("Fail to add extra data");
1184                 }
1185
1186                 _bt_ug_destroy(data, (void *)service);
1187
1188                 app_control_destroy(service);
1189         } else if (ugd->bt_launch_mode == BT_LAUNCH_ONOFF) {
1190                 service = __bt_main_get_bt_onoff_result(ugd, FALSE);
1191
1192                 app_control_create(&reply);
1193                 if (app_control_add_extra_data(reply, "result",
1194                                                         BT_RESULT_FAIL) < 0) {
1195                         BT_ERR("Fail to add extra data");
1196                 }
1197
1198                 BT_DBG("BT_LAUNCH_ONOFF reply to launch request");
1199                 app_control_reply_to_launch_request(reply, service,
1200                                                 APP_CONTROL_RESULT_FAILED);
1201
1202                 _bt_ug_destroy(data, (void *)service);
1203
1204                 if (service)
1205                         app_control_destroy(service);
1206                 if (reply)
1207                         app_control_destroy(reply);
1208         } else {
1209                 _bt_ug_destroy(data, NULL);
1210         }
1211
1212         FN_END;
1213         return EINA_FALSE;
1214 }
1215
1216 int _bt_main_enable_bt(void *data)
1217 {
1218         FN_START;
1219         int ret;
1220         retv_if(data == NULL, -1);
1221         bt_ug_data *ugd = (bt_ug_data *)data;
1222
1223         if (_bt_util_is_battery_low() == TRUE) {
1224                 /* Battery is critical low */
1225                 _bt_main_create_information_popup(ugd, BT_STR_LOW_BATTERY);
1226                 return -1;
1227         }
1228
1229         ret = bt_adapter_enable();
1230         if (ret != BT_ERROR_NONE)
1231                 BT_ERR("Failed to enable bluetooth [%d]", ret);
1232         else
1233                 ugd->op_status = BT_ACTIVATING;
1234
1235         FN_END;
1236         return 0;
1237 }
1238
1239 int _bt_main_disable_bt(void *data)
1240 {
1241         FN_START;
1242         int ret;
1243         retv_if(data == NULL, -1);
1244         bt_ug_data *ugd = (bt_ug_data *)data;
1245
1246         ret = bt_adapter_disable();
1247         if (ret != BT_ERROR_NONE) {
1248                 BT_ERR("Failed to disable bluetooth [%d]", ret);
1249         } else {
1250                 ugd->op_status = BT_DEACTIVATING;
1251                 elm_object_disabled_set(ugd->scan_btn, EINA_TRUE);
1252         }
1253
1254         FN_END;
1255         return 0;
1256 }
1257
1258 static void __bt_main_onoff_btn_cb(void *data, Evas_Object *obj,
1259                                    void *event_info)
1260 {
1261         FN_START;
1262         ret_if(data == NULL);
1263
1264         int ret;
1265         bt_ug_data *ugd = (bt_ug_data *)data;
1266
1267         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
1268         elm_genlist_item_selected_set(item, EINA_FALSE);
1269
1270         if (ugd->bt_launch_mode == BT_LAUNCH_HELP) {
1271                 Eina_Bool check_mode = elm_check_state_get(obj);
1272                 elm_check_state_set(obj, !check_mode);
1273
1274                 ret = notification_status_message_post(BT_STR_INVALID_ACTION_TRY_AGAIN);
1275                 if (ret != NOTIFICATION_ERROR_NONE)
1276                         BT_ERR("notification_status_message_post() is failed : %d", ret);
1277
1278                 FN_END;
1279                 return;
1280         }
1281         ret_if(ugd->op_status == BT_ACTIVATING ||
1282                 ugd->op_status == BT_DEACTIVATING);
1283
1284         elm_object_disabled_set(ugd->onoff_btn, EINA_TRUE);
1285
1286         if (ugd->op_status == BT_DEACTIVATED) {
1287                 ret = _bt_main_enable_bt(data);
1288                 ugd->op_status = BT_ACTIVATING;
1289         } else if (ugd->op_status != BT_DEACTIVATING &&
1290                 ugd->op_status != BT_ACTIVATING) {
1291                 ret = bt_adapter_disable();
1292                 if (ret != BT_ERROR_NONE) {
1293                         BT_ERR("Failed to disable bluetooth [%d]", ret);
1294                 } else {
1295                         ugd->op_status = BT_DEACTIVATING;
1296                         elm_object_disabled_set(ugd->scan_btn, EINA_TRUE);
1297                 }
1298         }
1299
1300         if (ugd->op_status == BT_ACTIVATING ||
1301                 ugd->op_status == BT_DEACTIVATING) {
1302
1303                 if (TIZEN_COMMON)
1304                         elm_object_item_signal_emit(item, "elm,state,group,single", "elm");
1305
1306                 elm_genlist_item_fields_update(ugd->onoff_item, "*",
1307                                                 ELM_GENLIST_ITEM_FIELD_TEXT);
1308                 elm_genlist_item_fields_update(ugd->onoff_item, "*",
1309                                                 ELM_GENLIST_ITEM_FIELD_CONTENT);
1310         }
1311         FN_END;
1312 }
1313
1314 static void __bt_main_controlbar_btn_cb(void *data, Evas_Object *obj,
1315                                         void *event_info)
1316 {
1317         FN_START;
1318
1319         bt_ug_data *ugd = NULL;
1320         int ret;
1321
1322         retm_if(data == NULL, "Invalid argument: bt_ug_data is NULL");
1323
1324         ugd = (bt_ug_data *)data;
1325
1326         if (ugd->op_status == BT_SEARCHING) {
1327                 if (ugd->is_discovery_started) {
1328
1329                         if (TIZEN_FEATURE_BT_HOG && ugd->is_le_discovery_started == TRUE) {
1330                                 ret = bt_adapter_le_stop_scan();
1331                                 if (!ret)
1332                                         ugd->is_le_discovery_started = FALSE;
1333                         }
1334                         if (bt_adapter_stop_device_discovery() == BT_ERROR_NONE) {
1335                                 elm_object_disabled_set(ugd->scan_btn, EINA_TRUE);
1336                                 elm_object_text_set(ugd->scan_btn, BT_STR_STOP);
1337                         } else { /*the case in which stop discovery returns error from Bluez*/
1338                                 ugd->op_status = BT_ACTIVATED;
1339                                 elm_object_text_set(ugd->scan_btn, BT_STR_SCAN);
1340
1341                                 if (ugd->searched_title == NULL)
1342                                         _bt_main_add_searched_title(ugd);
1343                                 _bt_update_genlist_item((Elm_Object_Item *)
1344                                                 ugd->searched_title);
1345                         }
1346                 }
1347         } else { /*ugd->op_status != BT_SEARCHING */
1348                 _bt_main_scan_device(ugd);
1349         }
1350
1351         FN_END;
1352 }
1353
1354 static void __bt_main_disconnect_cb(void *data, Evas_Object *obj,
1355                                     void *event_info)
1356 {
1357         FN_START;
1358
1359         bt_dev_t *dev = NULL;
1360         bt_ug_data *ugd = NULL;
1361
1362         retm_if(data == NULL, "Invalid argument: data is NULL");
1363
1364         dev = (bt_dev_t *)data;
1365         retm_if(dev->ugd == NULL, "ugd is NULL");
1366
1367         ugd = dev->ugd;
1368
1369         if (ugd->popup) {
1370                 evas_object_del(ugd->popup);
1371                 ugd->popup = NULL;
1372         }
1373
1374         _bt_main_disconnect_device(ugd, dev);
1375
1376         FN_END;
1377 }
1378
1379 static int __bt_main_request_to_send(bt_ug_data *ugd, bt_dev_t *dev)
1380 {
1381         obex_ipc_param_t param;
1382         char *value = NULL;
1383         char **array_val = NULL;
1384         int cnt;
1385         int i = 0;
1386         int ret;
1387
1388         BT_DBG("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
1389                dev->bd_addr[0], dev->bd_addr[1],
1390                dev->bd_addr[2], dev->bd_addr[3],
1391                dev->bd_addr[4], dev->bd_addr[5]);
1392
1393         memset(&param, 0x00, sizeof(obex_ipc_param_t));
1394         memcpy(param.addr, dev->bd_addr, BT_ADDRESS_LENGTH_MAX);
1395
1396         ret = app_control_get_extra_data_array(ugd->service, "files",
1397                                            &array_val, &cnt);
1398         if (ret != APP_CONTROL_ERROR_NONE) {
1399                 BT_ERR("Get data error");
1400                 goto fail;
1401         }
1402
1403         if (array_val == NULL)
1404                 goto fail;
1405
1406         param.file_cnt = cnt;
1407         param.filepath = g_new0(char *, cnt + 1);
1408         for (i = 0; i < cnt; i++) {
1409                 if (array_val[i]) {
1410                         param.filepath[i] = g_strdup(array_val[i]);
1411                         DBG_SECURE("%s", param.filepath[i]);
1412                         free(array_val[i]);
1413                         array_val[i] = NULL;
1414                 }
1415         }
1416         free(array_val);
1417         array_val = NULL;
1418
1419         param.dev_name = g_strdup(dev->name);
1420
1421         if (app_control_get_extra_data(ugd->service, "type", &value) < 0)
1422                 BT_ERR("Get data error");
1423
1424         if (value == NULL)
1425                 goto fail;
1426
1427         param.type = g_strdup(value);
1428         free(value);
1429
1430         if (_bt_ipc_send_obex_message(&param, ugd) != BT_UG_ERROR_NONE)
1431                 goto fail;
1432
1433         g_free(param.dev_name);
1434         g_free(param.type);
1435         if (param.filepath) {
1436                 for (i = 0; param.filepath[i] != NULL; i++)
1437                         g_free(param.filepath[i]);
1438                 g_free(param.filepath);
1439         }
1440
1441         return BT_UG_ERROR_NONE;
1442
1443  fail:
1444         if (array_val) {
1445                 for (i = 0; i < cnt; i++) {
1446                         if (array_val[i])
1447                                 free(array_val[i]);
1448                 }
1449         }
1450         _bt_main_launch_syspopup(ugd, BT_SYSPOPUP_REQUEST_NAME,
1451                                  BT_STR_UNABLE_TO_SEND,
1452                                  BT_SYSPOPUP_ONE_BUTTON_TYPE);
1453
1454         g_free(param.dev_name);
1455         g_free(param.type);
1456         if (param.filepath) {
1457                 for (i = 0; param.filepath[i] != NULL; i++)
1458                         g_free(param.filepath[i]);
1459                 g_free(param.filepath);
1460         }
1461
1462         return BT_UG_FAIL;
1463 }
1464
1465 static void __bt_main_paired_item_sel_cb(void *data, Evas_Object *obj,
1466                                          void *event_info)
1467 {
1468         FN_START;
1469
1470         bt_ug_data *ugd = NULL;
1471         bt_dev_t *dev = NULL;
1472         Elm_Object_Item *item = NULL;
1473         Evas_Object *btn = NULL;
1474         Evas_Object *popup_btn = NULL;
1475         int ret;
1476
1477         if (event_info)
1478                 elm_genlist_item_selected_set((Elm_Object_Item *) event_info,
1479                                       EINA_FALSE);
1480
1481         retm_if(data == NULL, "Invalid argument: bt_ug_data is NULL");
1482
1483         ugd = (bt_ug_data *)data;
1484         item = (Elm_Object_Item *) event_info;
1485
1486         ret_if(ugd->waiting_service_response == TRUE);
1487         ret_if(ugd->op_status == BT_PAIRING);
1488
1489         if (ugd->op_status == BT_SEARCHING) {
1490                 ret = bt_adapter_stop_device_discovery();
1491                 if (ret != BT_ERROR_NONE) {
1492                         BT_ERR("Fail to stop discovery");
1493                         return;
1494                 }
1495         }
1496
1497         dev = _bt_main_get_dev_info(ugd->paired_device, item);
1498         retm_if(dev == NULL, "Invalid argument: device info is NULL");
1499         retm_if(dev->status != BT_IDLE,
1500                 "Connecting / Disconnecting is in progress");
1501
1502         if ((ugd->waiting_service_response) && (dev->service_list == 0)) {
1503                 ugd->paired_item = item;
1504
1505                 _bt_main_popup_del_cb(ugd, NULL, NULL);
1506
1507                 ugd->popup_data.type = BT_POPUP_GETTING_SERVICE_LIST;
1508                 ugd->popup = _bt_create_popup(ugd, _bt_main_popup_del_cb,
1509                                                 ugd, 2);
1510
1511                 retm_if(ugd->popup == NULL, "fail to create popup!");
1512                 btn = elm_button_add(ugd->popup);
1513                 elm_object_style_set(btn, "popup");
1514                 elm_object_domain_translatable_text_set(
1515                         btn ,
1516                         PKGNAME, "IDS_BT_BUTTON_OK");
1517                 elm_object_part_content_set(ugd->popup, "button1", btn);
1518                 evas_object_smart_callback_add(btn, "clicked", (Evas_Smart_Cb)
1519                                                _bt_main_popup_del_cb, ugd);
1520
1521                 eext_object_event_callback_add(ugd->popup, EEXT_CALLBACK_BACK,
1522                                 _bt_main_popup_del_cb, ugd);
1523
1524                 evas_object_show(ugd->popup);
1525                 return;
1526         }
1527
1528         if (ugd->bt_launch_mode == BT_LAUNCH_NORMAL ||
1529             ugd->bt_launch_mode == BT_LAUNCH_CONNECT_HEADSET ||
1530             ugd->bt_launch_mode == BT_LAUNCH_USE_NFC ||
1531             ugd->bt_launch_mode == BT_LAUNCH_HELP) {
1532
1533                 ugd->paired_item = item;
1534
1535                 if ((!TIZEN_FEATURE_BT_HOG && dev->service_list == 0) || (TIZEN_FEATURE_BT_HOG && (dev->service_list == 0) && (!dev->is_le_device))) {
1536                                 if (bt_device_start_service_search
1537                                                 ((const char *)dev->addr_str) == BT_ERROR_NONE) {
1538
1539                                         dev->status = BT_SERVICE_SEARCHING;
1540                                         ugd->waiting_service_response = TRUE;
1541                                         ugd->request_timer =
1542                                                 ecore_timer_add(BT_SEARCH_SERVICE_TIMEOUT,
1543                                                                 (Ecore_Task_Cb)
1544                                                                 _bt_main_service_request_cb,
1545                                                                 ugd);
1546
1547                                         _bt_update_genlist_item(ugd->paired_item);
1548                                         return;
1549                                 } else {
1550                                         BT_ERR("service search error");
1551                                         return;
1552                                 }
1553                 }
1554
1555                         if (dev->is_connected == 0) {
1556                                 /* Not connected case */
1557                                 _bt_main_connect_device(ugd, dev);
1558                         } else {
1559
1560                         _bt_main_popup_del_cb(ugd, NULL, NULL);
1561
1562                         ugd->popup_data.type = BT_POPUP_DISCONNECT;
1563                         ugd->popup_data.data = g_strdup(dev->name);
1564                         ugd->popup = _bt_create_popup(ugd, NULL, NULL, 0);
1565                         retm_if(!ugd->popup , "fail to create popup!");
1566
1567                         popup_btn = elm_button_add(ugd->popup);
1568                         if (popup_btn) {
1569                                 elm_object_style_set(popup_btn, "popup");
1570                                 elm_object_domain_translatable_text_set(
1571                                         popup_btn ,
1572                                         PKGNAME, "IDS_BR_SK_CANCEL");
1573                                 elm_object_part_content_set(ugd->popup, "button1",
1574                                                             popup_btn);
1575                                 evas_object_smart_callback_add(popup_btn, "clicked",
1576                                                                _bt_main_popup_del_cb,
1577                                                                ugd);
1578                         }
1579
1580                         popup_btn = elm_button_add(ugd->popup);
1581                         if (popup_btn) {
1582                                 elm_object_style_set(popup_btn, "popup");
1583                                 elm_object_domain_translatable_text_set(
1584                                         popup_btn ,
1585                                         PKGNAME, "IDS_BT_SK_DISCONNECT");
1586                                 elm_object_part_content_set(ugd->popup, "button2",
1587                                                             popup_btn);
1588                                 evas_object_smart_callback_add(popup_btn, "clicked",
1589                                                                __bt_main_disconnect_cb,
1590                                                                dev);
1591                                 eext_object_event_callback_add(ugd->popup, EEXT_CALLBACK_BACK,
1592                                                 eext_popup_back_cb, NULL);
1593                         }
1594                         evas_object_show(ugd->popup);
1595
1596                 }
1597         } else if (ugd->bt_launch_mode == BT_LAUNCH_SEND_FILE) {
1598                 if (_bt_util_is_battery_low() == TRUE) {
1599                         /* Battery is critical low */
1600                         _bt_main_create_information_popup(ugd, BT_STR_LOW_BATTERY);
1601                         return;
1602                 }
1603
1604                 if (__bt_main_request_to_send(ugd, dev) == BT_UG_ERROR_NONE)
1605                         BT_DBG("Request file sending");
1606
1607                 _bt_ug_destroy(ugd, NULL);
1608         } else if (ugd->bt_launch_mode == BT_LAUNCH_PICK) {
1609                 ugd->pick_device = dev;
1610                 g_idle_add((GSourceFunc) _bt_idle_destroy_ug, ugd);
1611         }
1612
1613         FN_END;
1614 }
1615
1616 static void __bt_main_searched_item_sel_cb(void *data, Evas_Object *obj,
1617                                            void *event_info)
1618 {
1619         FN_START;
1620
1621         bt_ug_data *ugd = NULL;
1622         bt_dev_t *dev = NULL;
1623         Elm_Object_Item *item = NULL;
1624         int ret;
1625
1626         if (event_info)
1627                 elm_genlist_item_selected_set((Elm_Object_Item *) event_info,
1628                                       EINA_FALSE);
1629
1630         retm_if(data == NULL, "Invalid argument: bt_ug_data is NULL");
1631
1632         ugd = (bt_ug_data *)data;
1633
1634         ret_if(ugd->op_status == BT_PAIRING);
1635
1636         item = (Elm_Object_Item *) event_info;
1637
1638         dev = _bt_main_get_dev_info(ugd->searched_device,
1639                                     (Elm_Object_Item *) event_info);
1640         retm_if(dev == NULL, "Invalid argument: device info is NULL");
1641
1642         if (ugd->bt_launch_mode == BT_LAUNCH_USE_NFC) {
1643                 char address[18] = { 0 };
1644                 app_control_h service = NULL;
1645
1646                 app_control_create(&service);
1647
1648                 ret_if(service == NULL);
1649
1650                 BT_DBG("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X", dev->bd_addr[0],
1651                        dev->bd_addr[1], dev->bd_addr[2], dev->bd_addr[3],
1652                        dev->bd_addr[4], dev->bd_addr[5]);
1653
1654                 _bt_util_addr_type_to_addr_string(address, dev->bd_addr);
1655
1656                 if (app_control_add_extra_data(service, "device_address",
1657                                            (const char *)address) < 0) {
1658                         BT_ERR("Fail to add extra data");
1659                 }
1660
1661                 if (app_control_add_extra_data(service, "device_name",
1662                                            (const char *)dev->name) < 0) {
1663                         BT_ERR("Fail to add extra data");
1664                 }
1665
1666                 _bt_ug_destroy(ugd, (void *)service);
1667
1668                 app_control_destroy(service);
1669
1670                 return;
1671         } else if (ugd->bt_launch_mode == BT_LAUNCH_PICK) {
1672                 ugd->pick_device = dev;
1673                 g_idle_add((GSourceFunc) _bt_idle_destroy_ug, ugd);
1674                 return;
1675         }
1676
1677         ugd->searched_item = item;
1678
1679         if (_bt_util_is_battery_low() == TRUE) {
1680                 /* Battery is critical low */
1681                 _bt_main_create_information_popup(ugd, BT_STR_LOW_BATTERY);
1682                 return;
1683         }
1684
1685         if (ugd->op_status == BT_SEARCHING) {
1686                 if (TIZEN_FEATURE_BT_HOG && ugd->is_le_discovery_started == TRUE) {
1687                         ret = bt_adapter_le_stop_scan();
1688                         if (!ret)
1689                                 ugd->is_le_discovery_started = FALSE;
1690                 }
1691                 ret = bt_adapter_stop_device_discovery();
1692                 if (ret != BT_ERROR_NONE)
1693                         BT_ERR("Fail to stop discovery");
1694         }
1695
1696         if (ugd->bt_launch_mode == BT_LAUNCH_SEND_FILE) {
1697                 if (__bt_main_request_to_send(ugd, dev) == BT_UG_ERROR_NONE)
1698                         BT_DBG("Request file sending");
1699
1700                 _bt_ug_destroy(ugd, NULL);
1701                 return;
1702         }
1703
1704         if (!TIZEN_FEATURE_BT_HOG) {
1705                 if (_bt_main_request_pairing_with_effect(ugd, item) != BT_UG_ERROR_NONE)
1706                         ugd->searched_item = NULL;
1707         } else {
1708                 if (dev->is_le_device) {
1709                         if (_bt_main_request_connect_with_effect(ugd, item) != BT_UG_ERROR_NONE)
1710                                 ugd->searched_item = NULL;
1711
1712                 } else {
1713                         if (_bt_main_request_pairing_with_effect(ugd, item) != BT_UG_ERROR_NONE)
1714                                 ugd->searched_item = NULL;
1715                 }
1716         }
1717
1718         FN_END;
1719 }
1720
1721 static void __bt_main_gl_highlighted(void *data, Evas_Object *obj,
1722                                      void *event_info)
1723 {
1724         FN_START;
1725
1726         bt_ug_data *ugd;
1727         bt_dev_t *dev;
1728         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
1729
1730         ret_if(item == NULL);
1731
1732         ugd = (bt_ug_data *)data;
1733         ret_if(ugd == NULL);
1734
1735         dev = _bt_main_get_dev_info(ugd->paired_device, item);
1736         if (dev == NULL)
1737                 dev = _bt_main_get_dev_info(ugd->searched_device, item);
1738
1739         ret_if(dev == NULL);
1740
1741         dev->highlighted = TRUE;
1742
1743         /* Update text */
1744         elm_genlist_item_fields_update(item, "*", ELM_GENLIST_ITEM_FIELD_TEXT);
1745
1746         FN_END;
1747 }
1748
1749 static void __bt_main_gl_unhighlighted(void *data, Evas_Object *obj,
1750                                        void *event_info)
1751 {
1752         FN_START;
1753
1754         bt_ug_data *ugd;
1755         bt_dev_t *dev;
1756         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
1757
1758         ret_if(item == NULL);
1759
1760         ugd = (bt_ug_data *)data;
1761         ret_if(ugd == NULL);
1762
1763         dev = _bt_main_get_dev_info(ugd->paired_device, item);
1764         if (dev == NULL)
1765                 dev = _bt_main_get_dev_info(ugd->searched_device, item);
1766
1767         ret_if(dev == NULL);
1768
1769         dev->highlighted = FALSE;
1770
1771         /* Update text */
1772         elm_genlist_item_fields_update(item, "*", ELM_GENLIST_ITEM_FIELD_TEXT);
1773
1774         FN_END;
1775 }
1776
1777 void _bt_main_add_device_name_item(bt_ug_data *ugd, Evas_Object *genlist)
1778 {
1779         FN_START;
1780         retm_if(ugd->op_status == BT_DEACTIVATED, "BT is turned off");
1781
1782         if (TIZEN_COMMON) {
1783                 /* IOT common UI don't show the device name */
1784                 return;
1785         }
1786
1787         Elm_Object_Item *git = NULL;
1788         /* Device name */
1789         git = elm_genlist_item_insert_after(genlist, ugd->device_name_itc, ugd, NULL,
1790                                         ugd->onoff_item, ELM_GENLIST_ITEM_NONE, NULL, NULL);
1791         elm_genlist_item_select_mode_set(git, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1792
1793         ugd->device_name_item = git;
1794
1795         FN_END;
1796 }
1797
1798 static void __bt_main_gl_realized(void *data, Evas_Object *obj, void *event_info)
1799 {
1800         if (!data || !obj || !event_info)
1801                 return;
1802
1803         int group_type = BT_GENLIST_GROUP_MIDDLE;
1804         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
1805         Elm_Object_Item *prev_item = elm_genlist_item_prev_get(item);
1806         Elm_Object_Item *next_item = elm_genlist_item_next_get(item);
1807         bt_ug_data *ugd = (bt_ug_data *)data;
1808
1809         /* onoff / device name item style */
1810         if (item == ugd->onoff_item) {
1811                 if (TIZEN_COMMON)
1812                         group_type = BT_GENLIST_GROUP_SINGLE;
1813                 else
1814                         group_type = (next_item == NULL) ? BT_GENLIST_GROUP_SINGLE : BT_GENLIST_GROUP_TOP;
1815         } else if (item == ugd->device_name_item) {
1816                 group_type = BT_GENLIST_GROUP_BOTTOM;
1817         } else {
1818                 if (prev_item == ugd->paired_title) {
1819                         /* The first paired item */
1820                         if (next_item == ugd->searched_title)
1821                                 group_type = BT_GENLIST_GROUP_SINGLE;
1822                         else
1823                                 group_type = BT_GENLIST_GROUP_TOP;
1824                 } else if (prev_item == ugd->searched_title) {
1825                         /* The first searched item */
1826                         if (next_item == NULL)
1827                                 group_type = BT_GENLIST_GROUP_SINGLE;
1828                         else
1829                                 group_type = BT_GENLIST_GROUP_TOP;
1830                 } else if (next_item == ugd->searched_title || next_item == ugd->no_device_item || next_item == NULL) {
1831                         group_type = BT_GENLIST_GROUP_BOTTOM;
1832                 }
1833         }
1834
1835         if (group_type == BT_GENLIST_GROUP_SINGLE)
1836                 elm_object_item_signal_emit(item, "elm,state,group,single", "elm");
1837         else if (group_type == BT_GENLIST_GROUP_TOP)
1838                 elm_object_item_signal_emit(item, "elm,state,group,top", "elm");
1839         else if (group_type == BT_GENLIST_GROUP_BOTTOM)
1840                 elm_object_item_signal_emit(item, "elm,state,group,bottom", "elm");
1841         else
1842                 elm_object_item_signal_emit(item, "elm,state,group,middle", "elm");
1843 }
1844
1845 static Evas_Object *__bt_main_add_genlist_dialogue(Evas_Object *parent,
1846                                                    bt_ug_data *ugd)
1847 {
1848         FN_START;
1849         retv_if(ugd == NULL, NULL);
1850
1851         Evas_Object *genlist = NULL;
1852         Elm_Object_Item *git = NULL;
1853
1854         genlist = elm_genlist_add(parent);
1855         retv_if(!genlist, NULL);
1856         /* We shoud set the mode to compress
1857            for using dialogue/2text.2icon.3.tb */
1858         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
1859         elm_genlist_homogeneous_set(genlist, EINA_FALSE);
1860         elm_genlist_block_count_set(genlist, 3);
1861
1862         evas_object_smart_callback_add(genlist, "highlighted",
1863                                        __bt_main_gl_highlighted, ugd);
1864
1865         evas_object_smart_callback_add(genlist, "unhighlighted",
1866                                        __bt_main_gl_unhighlighted, ugd);
1867
1868         if (TIZEN_COMMON)
1869                 evas_object_smart_callback_add(genlist, "realized", __bt_main_gl_realized, ugd);
1870
1871         ugd->on_itc = elm_genlist_item_class_new();
1872         retv_if(ugd->on_itc == NULL, NULL);
1873
1874         ugd->on_itc->item_style = BT_GENLIST_1LINE_TEXT_ICON_STYLE;
1875         ugd->on_itc->func.text_get = __bt_main_onoff_label_get;
1876         ugd->on_itc->func.content_get = __bt_main_onoff_icon_get;
1877         ugd->on_itc->func.state_get = NULL;
1878         ugd->on_itc->func.del = NULL;
1879
1880         /* Set item class for dialogue seperator */
1881         ugd->off_itc = elm_genlist_item_class_new();
1882         retv_if(ugd->off_itc == NULL, NULL);
1883
1884         ugd->off_itc->item_style = BT_GENLIST_MULTILINE_TEXT_STYLE;
1885         ugd->off_itc->func.text_get = __bt_main_onoff_label_get;
1886         ugd->off_itc->func.content_get = __bt_main_onoff_icon_get;
1887         ugd->off_itc->func.state_get = NULL;
1888         ugd->off_itc->func.del = NULL;
1889
1890         /* Set item class for paired dialogue title */
1891         ugd->device_name_itc = elm_genlist_item_class_new();
1892         retv_if(ugd->device_name_itc == NULL, NULL);
1893
1894         ugd->device_name_itc->item_style = BT_GENLIST_2LINE_BOTTOM_TEXT_STYLE;
1895         ugd->device_name_itc->func.text_get = __bt_main_device_label_get;
1896         ugd->device_name_itc->func.content_get = NULL;
1897         ugd->device_name_itc->func.state_get = NULL;
1898         ugd->device_name_itc->func.del = NULL;
1899
1900         /* Set item class for paired dialogue title */
1901         ugd->paired_title_itc = elm_genlist_item_class_new();
1902         retv_if(ugd->paired_title_itc == NULL, NULL);
1903
1904         ugd->paired_title_itc->item_style = BT_GENLIST_GROUP_INDEX_STYLE;
1905         ugd->paired_title_itc->func.text_get = __bt_main_paired_title_label_get;
1906         ugd->paired_title_itc->func.content_get = NULL;
1907         ugd->paired_title_itc->func.state_get = NULL;
1908         ugd->paired_title_itc->func.del = NULL;
1909
1910         /* Set item class for searched dialogue title */
1911         ugd->searched_title_itc = elm_genlist_item_class_new();
1912         retv_if(ugd->searched_title_itc == NULL, NULL);
1913
1914         ugd->searched_title_itc->item_style = BT_GENLIST_GROUP_INDEX_STYLE;
1915         ugd->searched_title_itc->func.text_get = __bt_main_searched_title_label_get;
1916         ugd->searched_title_itc->func.content_get = __bt_main_searched_title_icon_get;
1917         ugd->searched_title_itc->func.state_get = NULL;
1918         ugd->searched_title_itc->func.del = NULL;
1919
1920         /* Set item class for paired device */
1921         ugd->paired_device_itc = elm_genlist_item_class_new();
1922         retv_if(ugd->paired_device_itc == NULL, NULL);
1923
1924         ugd->paired_device_itc->item_style = BT_GENLIST_2LINE_TOP_TEXT_ICON_STYLE;
1925         ugd->paired_device_itc->func.text_get = __bt_main_paired_device_label_get;
1926         ugd->paired_device_itc->func.content_get = __bt_main_paired_device_icon_get;
1927         ugd->paired_device_itc->func.state_get = NULL;
1928         ugd->paired_device_itc->func.del = NULL;
1929
1930         /* Set item class for searched device */
1931         ugd->searched_device_itc = elm_genlist_item_class_new();
1932         retv_if(ugd->searched_device_itc == NULL, NULL);
1933
1934         ugd->searched_device_itc->item_style = BT_GENLIST_1LINE_TEXT_ICON_STYLE;
1935         ugd->searched_device_itc->func.text_get = __bt_main_searched_label_get;
1936         ugd->searched_device_itc->func.content_get = __bt_main_searched_icon_get;
1937         ugd->searched_device_itc->func.state_get = NULL;
1938         ugd->searched_device_itc->func.del = NULL;
1939
1940         /* Set item class for no device */
1941         ugd->no_device_itc = elm_genlist_item_class_new();
1942         retv_if(ugd->no_device_itc == NULL, NULL);
1943
1944         ugd->no_device_itc->item_style = BT_GENLIST_1LINE_TEXT_STYLE;
1945         ugd->no_device_itc->func.text_get = __bt_main_no_device_label_get;
1946         ugd->no_device_itc->func.content_get = NULL;
1947         ugd->no_device_itc->func.state_get = NULL;
1948         ugd->no_device_itc->func.del = NULL;
1949
1950         if (ugd->op_status == BT_DEACTIVATED ||
1951                 ugd->op_status == BT_ACTIVATING)
1952                 git = elm_genlist_item_append(genlist, ugd->off_itc, ugd, NULL,
1953                                                                 ELM_GENLIST_ITEM_NONE,
1954                                                                 __bt_main_onoff_btn_cb, ugd);
1955         else
1956                 git = elm_genlist_item_append(genlist, ugd->on_itc, ugd, NULL,
1957                                                                 ELM_GENLIST_ITEM_NONE,
1958                                                                 __bt_main_onoff_btn_cb, ugd);
1959
1960         ugd->onoff_item = git;
1961
1962         if (_bt_util_is_dpm_restricted(ugd->dpm_handle) == TRUE)
1963                 elm_object_item_disabled_set(ugd->onoff_item, EINA_TRUE);
1964
1965         _bt_main_add_device_name_item(ugd, genlist);
1966
1967         evas_object_show(genlist);
1968
1969         FN_END;
1970         return genlist;
1971 }
1972
1973 static Evas_Object *__bt_main_add_visibility_dialogue(Evas_Object * parent,
1974                                                       bt_ug_data *ugd)
1975 {
1976         FN_START;
1977         retv_if(ugd == NULL, NULL);
1978
1979         Evas_Object *genlist = NULL;
1980         Elm_Object_Item *git = NULL;
1981
1982         genlist = elm_genlist_add(parent);
1983         /* We shoud set the mode to compress
1984            for using dialogue/2text.2icon.3.tb */
1985         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
1986         elm_genlist_homogeneous_set(genlist, EINA_FALSE);
1987         elm_genlist_block_count_set(genlist, 3);
1988
1989         evas_object_smart_callback_add(genlist, "highlighted",
1990                                        __bt_main_gl_highlighted, ugd);
1991
1992         evas_object_smart_callback_add(genlist, "unhighlighted",
1993                                        __bt_main_gl_unhighlighted, ugd);
1994
1995         ugd->on_itc = elm_genlist_item_class_new();
1996         retv_if(ugd->on_itc == NULL, NULL);
1997
1998         ugd->on_itc->item_style = BT_GENLIST_1LINE_TEXT_ICON_STYLE;
1999         ugd->on_itc->func.text_get = __bt_main_onoff_label_get;
2000         ugd->on_itc->func.content_get = __bt_main_onoff_icon_get;
2001         ugd->on_itc->func.state_get = NULL;
2002         ugd->on_itc->func.del = NULL;
2003
2004         /* Set item class for dialogue seperator */
2005         ugd->off_itc = elm_genlist_item_class_new();
2006         retv_if(ugd->off_itc == NULL, NULL);
2007
2008         ugd->off_itc->item_style = BT_GENLIST_MULTILINE_TEXT_STYLE;
2009         ugd->off_itc->func.text_get = __bt_main_onoff_label_get;
2010         ugd->off_itc->func.content_get = __bt_main_onoff_icon_get;
2011         ugd->off_itc->func.state_get = NULL;
2012         ugd->off_itc->func.del = NULL;
2013
2014         /* Set item class for paired dialogue title */
2015         ugd->device_name_itc = elm_genlist_item_class_new();
2016         retv_if(ugd->device_name_itc == NULL, NULL);
2017
2018         ugd->device_name_itc->item_style = BT_GENLIST_2LINE_BOTTOM_TEXT_STYLE;
2019         ugd->device_name_itc->func.text_get = __bt_main_device_label_get;
2020         ugd->device_name_itc->func.content_get = NULL;
2021         ugd->device_name_itc->func.state_get = NULL;
2022         ugd->device_name_itc->func.del = NULL;
2023
2024         if (ugd->op_status == BT_DEACTIVATED ||
2025                 ugd->op_status == BT_ACTIVATING)
2026                 git = elm_genlist_item_append(genlist, ugd->off_itc, ugd, NULL,
2027                                                                 ELM_GENLIST_ITEM_NONE,
2028                                                                 __bt_main_onoff_btn_cb, ugd);
2029         else
2030                 git = elm_genlist_item_append(genlist, ugd->on_itc, ugd, NULL,
2031                                                                 ELM_GENLIST_ITEM_NONE,
2032                                                                 __bt_main_onoff_btn_cb, ugd);
2033         ugd->onoff_item = git;
2034
2035         _bt_main_add_device_name_item(ugd, genlist);
2036         evas_object_show(genlist);
2037
2038         FN_END;
2039         return genlist;
2040 }
2041
2042 static Evas_Object *__bt_main_add_onoff_dialogue(Evas_Object * parent,
2043                                                       bt_ug_data *ugd)
2044 {
2045         FN_START;
2046         retv_if(ugd == NULL, NULL);
2047
2048         Evas_Object *genlist = NULL;
2049         Elm_Object_Item *git = NULL;
2050
2051         genlist = elm_genlist_add(parent);
2052         /* We shoud set the mode to compress
2053            for using dialogue/2text.2icon.3.tb */
2054         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
2055         elm_genlist_homogeneous_set(genlist, EINA_FALSE);
2056         elm_genlist_block_count_set(genlist, 3);
2057
2058         evas_object_smart_callback_add(genlist, "highlighted",
2059                                        __bt_main_gl_highlighted, ugd);
2060
2061         evas_object_smart_callback_add(genlist, "unhighlighted",
2062                                        __bt_main_gl_unhighlighted, ugd);
2063
2064         ugd->on_itc = elm_genlist_item_class_new();
2065         retv_if(ugd->on_itc == NULL, NULL);
2066
2067         ugd->on_itc->item_style = BT_GENLIST_1LINE_TEXT_ICON_STYLE;
2068         ugd->on_itc->func.text_get = __bt_main_onoff_label_get;
2069         ugd->on_itc->func.content_get = __bt_main_onoff_icon_get;
2070         ugd->on_itc->func.state_get = NULL;
2071         ugd->on_itc->func.del = NULL;
2072
2073         /* Set item class for dialogue seperator */
2074         ugd->off_itc = elm_genlist_item_class_new();
2075         retv_if(ugd->off_itc == NULL, NULL);
2076
2077         ugd->off_itc->item_style = BT_GENLIST_MULTILINE_TEXT_STYLE;
2078         ugd->off_itc->func.text_get = __bt_main_onoff_label_get;
2079         ugd->off_itc->func.content_get = __bt_main_onoff_icon_get;
2080         ugd->off_itc->func.state_get = NULL;
2081         ugd->off_itc->func.del = NULL;
2082
2083         /* Set item class for paired dialogue title */
2084         ugd->device_name_itc = elm_genlist_item_class_new();
2085         retv_if(ugd->device_name_itc == NULL, NULL);
2086
2087         ugd->device_name_itc->item_style = BT_GENLIST_2LINE_BOTTOM_TEXT_STYLE;
2088         ugd->device_name_itc->func.text_get = __bt_main_device_label_get;
2089         ugd->device_name_itc->func.content_get = NULL;
2090         ugd->device_name_itc->func.state_get = NULL;
2091         ugd->device_name_itc->func.del = NULL;
2092
2093
2094         if (ugd->op_status == BT_DEACTIVATED ||
2095                 ugd->op_status == BT_ACTIVATING)
2096                 git = elm_genlist_item_append(genlist, ugd->off_itc, ugd, NULL,
2097                                                                 ELM_GENLIST_ITEM_NONE,
2098                                                                 __bt_main_onoff_btn_cb, ugd);
2099         else
2100                 git = elm_genlist_item_append(genlist, ugd->on_itc, ugd, NULL,
2101                                                                 ELM_GENLIST_ITEM_NONE,
2102                                                                 __bt_main_onoff_btn_cb, ugd);
2103         ugd->onoff_item = git;
2104
2105         _bt_main_add_device_name_item(ugd, genlist);
2106         evas_object_show(genlist);
2107
2108         FN_END;
2109         return genlist;
2110 }
2111
2112 static gboolean __bt_main_system_popup_timer_cb(gpointer user_data)
2113 {
2114         FN_START;
2115
2116         int ret;
2117         bt_ug_data *ugd;
2118         bundle *b;
2119
2120         retv_if(user_data == NULL, FALSE);
2121
2122         ugd = (bt_ug_data *)user_data;
2123
2124         b = ugd->popup_bundle;
2125
2126         if (NULL == b) {
2127                 BT_ERR("bundle is NULL");
2128                 return FALSE;
2129         }
2130
2131         ret = syspopup_launch("bt-syspopup", b);
2132         if (ret < 0) {
2133                 BT_ERR("Sorry cannot launch popup");
2134         } else {
2135                 BT_DBG("Finally Popup launched");
2136                 bundle_free(b);
2137         }
2138
2139         FN_END;
2140         return (ret < 0) ? TRUE : FALSE;
2141 }
2142
2143 static bool __bt_main_get_mime_type(char *file)
2144 {
2145         FN_START;
2146
2147         char mime_type[BT_FILE_NAME_LEN_MAX] = { 0, };
2148         int len = strlen("image");
2149
2150         retv_if(file == NULL, FALSE);
2151
2152         if (aul_get_mime_from_file(file, mime_type,
2153                                    BT_FILE_NAME_LEN_MAX) == AUL_R_OK) {
2154                 BT_INFO("mime type=[%s]", mime_type);
2155                 if (0 != strncmp(mime_type, "image", len))
2156                         return FALSE;
2157         } else {
2158                 BT_ERR("Error getting mime type");
2159                 return FALSE;
2160         }
2161
2162         FN_END;
2163         return TRUE;
2164 }
2165
2166 static bool __bt_main_is_image_file(app_control_h service)
2167 {
2168         FN_START;
2169
2170         char *value = NULL;
2171         int number_of_files = 0;
2172         char *token = NULL;
2173         char *param = NULL;
2174         int i = 0;
2175
2176         retvm_if(service == NULL, FALSE, "Invalid data bundle");
2177
2178         if (app_control_get_extra_data(service, "filecount", &value) < 0)
2179                 BT_ERR("Get data error");
2180
2181         retv_if(value == NULL, FALSE);
2182
2183         number_of_files = atoi(value);
2184         BT_INFO("[%d] files", number_of_files);
2185         free(value);
2186         value = NULL;
2187
2188         if (number_of_files <= 0) {
2189                 BT_ERR("No File");
2190                 return FALSE;
2191         }
2192
2193         if (app_control_get_extra_data(service, "files", &value) < 0)
2194                 BT_ERR("Get data error");
2195
2196         retv_if(value == NULL, FALSE);
2197
2198         param = value;
2199         while (((token = strstr(param, "?")) != NULL) && i < number_of_files) {
2200                 *token = '\0';
2201                 if (!__bt_main_get_mime_type(param)) {
2202                         *token = '?';
2203                         free(value);
2204                         return FALSE;
2205                 }
2206                 BT_INFO("File [%d] [%s]", i, param);
2207                 *token = '?';
2208                 param = token + 1;
2209                 i++;
2210         }
2211         if (i == (number_of_files - 1)) {
2212                 if (!__bt_main_get_mime_type(param)) {
2213                         free(value);
2214                         return FALSE;
2215                 }
2216                 BT_INFO("File [%d] [%s]", i, param);
2217         } else {
2218                 BT_ERR("Count not match : [%d] / [%d]", number_of_files, i);
2219                 free(value);
2220                 return FALSE;
2221         }
2222
2223         free(value);
2224
2225         FN_END;
2226         return TRUE;
2227 }
2228
2229 bt_dev_t *_bt_main_create_searched_le_device_item(void *data)
2230 {
2231         FN_START;
2232
2233         int ret;
2234         unsigned char bd_addr[BT_ADDRESS_LENGTH_MAX];
2235         bt_dev_t *dev = NULL;
2236         bt_adapter_le_device_scan_result_info_s *dev_info = NULL;
2237         char *remote_name = NULL;
2238         int count;
2239         char **uuids;
2240         int i;
2241         int is_hog = 0;
2242
2243         retv_if(data == NULL, NULL);
2244
2245         dev_info = (bt_adapter_le_device_scan_result_info_s *) data;
2246         ret = bt_adapter_le_get_scan_result_device_name(dev_info, BT_ADAPTER_LE_PACKET_ADVERTISING, &remote_name);
2247         if (ret != BT_ERROR_NONE) {
2248                 BT_ERR("Fail to get LE device name");
2249                 return NULL;
2250         }
2251
2252         if (!remote_name)
2253                 return NULL;
2254
2255         if (strlen(remote_name) == 0) {
2256                 g_free(remote_name);
2257                 return NULL;
2258         }
2259
2260         /* only HOG Device will be shown in searched list */
2261         if (bt_adapter_le_get_scan_result_service_uuids(
2262                                 dev_info, BT_ADAPTER_LE_PACKET_ADVERTISING, &uuids, &count) == BT_ERROR_NONE) {
2263                 for (i = 0; i < count; i++) {
2264                         BT_DBG("UUID[%d] = %s", i + 1, uuids[i]);
2265                         if (g_strcmp0(HOGP_SERVICE_UUID, uuids[i]) == 0)
2266                                 is_hog++;
2267                         g_free(uuids[i]);
2268                 }
2269                 g_free(uuids);
2270         } else
2271                 BT_ERR("Fail to get LE service uuids");
2272
2273         if (!is_hog) {
2274                 g_free(remote_name);
2275                 return NULL;
2276         }
2277
2278         dev = calloc(1, sizeof(bt_dev_t));
2279         if (dev == NULL) {
2280                 g_free(remote_name);
2281                 return NULL;
2282         }
2283
2284         strncpy(dev->name, remote_name, DEVICE_NAME_MAX_LEN);
2285
2286         dev->rssi = dev_info->rssi;
2287         dev->is_le_device = TRUE;
2288
2289         _bt_util_addr_string_to_addr_type(bd_addr, dev_info->remote_address);
2290
2291         memcpy(dev->addr_str, dev_info->remote_address, BT_ADDRESS_STR_LEN);
2292
2293         memcpy(dev->bd_addr, bd_addr, BT_ADDRESS_LENGTH_MAX);
2294
2295         BT_DBG("device name [%s]", dev->name);
2296         BT_DBG("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X", dev->bd_addr[0],
2297                         dev->bd_addr[1], dev->bd_addr[2], dev->bd_addr[3],
2298                         dev->bd_addr[4], dev->bd_addr[5]);
2299
2300         g_free(remote_name);
2301         FN_END;
2302         return dev;
2303 }
2304
2305 /**********************************************************************
2306 *                                              Common Functions
2307 ***********************************************************************/
2308
2309 void _bt_main_scan_device(bt_ug_data *ugd)
2310 {
2311         FN_START;
2312         int ret;
2313
2314         ret_if(ugd == NULL);
2315
2316         if (ugd->op_status != BT_DEACTIVATED && ugd->op_status != BT_ACTIVATED) {
2317                 BT_INFO("current bluetooth status [%d]", ugd->op_status);
2318                 return;
2319         }
2320
2321         if (_bt_util_is_battery_low() == TRUE) {
2322                 /* Battery is critical low */
2323                 _bt_main_create_information_popup(ugd, BT_STR_LOW_BATTERY);
2324                 return;
2325         }
2326
2327         if (ugd->op_status == BT_DEACTIVATED) {
2328                 ret = _bt_main_enable_bt((void *)ugd);
2329                 if (!ret)
2330                         elm_object_disabled_set(ugd->scan_btn, EINA_TRUE);
2331         } else {
2332                 if (TIZEN_FEATURE_BT_HOG) {
2333                         ret = bt_adapter_le_start_scan((bt_adapter_le_scan_result_cb)_bt_cb_new_le_device_found, (void *)ugd);
2334                         if (!ret) {
2335                                 ugd->is_le_discovery_started = TRUE;
2336                                 BT_DBG("LE Discovery started");
2337                         } else {
2338                                 BT_ERR("LE Discovery failed : Error Cause[%d]", ret);
2339                         }
2340                 }
2341                 ret = bt_adapter_start_device_discovery();
2342                 if (!ret) {
2343                         /* Disable the Scan button till the BLUETOOTH_EVENT_DISCOVERY_STARTED is received */
2344                         elm_object_disabled_set(ugd->scan_btn, EINA_TRUE);
2345                         _bt_main_remove_all_searched_devices(ugd);
2346                         ugd->op_status = BT_SEARCHING;
2347                         elm_object_text_set(ugd->scan_btn, BT_STR_STOP);
2348
2349                         if (ugd->searched_title == NULL)
2350                                 _bt_main_add_searched_title(ugd);
2351                 } else {
2352                         BT_ERR("Operation failed : Error Cause[%d]", ret);
2353                 }
2354         }
2355
2356         FN_END;
2357 }
2358
2359 int _bt_main_service_request_cb(void *data)
2360 {
2361         FN_START;
2362
2363         bt_ug_data *ugd = NULL;
2364
2365         retvm_if(data == NULL, BT_UG_FAIL,
2366                  "Invalid argument: bt_ug_data is NULL");
2367
2368         ugd = (bt_ug_data *)data;
2369
2370         if (ugd->request_timer) {
2371                 ecore_timer_del(ugd->request_timer);
2372                 ugd->request_timer = NULL;
2373         }
2374
2375         /* Need to modify API: Address parameter */
2376         if (ugd->waiting_service_response == TRUE) {
2377                 bt_dev_t *dev = NULL;
2378
2379                 ugd->waiting_service_response = FALSE;
2380                 bt_device_cancel_service_search();
2381
2382                 dev =
2383                     _bt_main_get_dev_info(ugd->paired_device, ugd->paired_item);
2384                 retvm_if(dev == NULL, BT_UG_FAIL, "dev is NULL");
2385
2386                 dev->status = BT_IDLE;
2387                 _bt_update_genlist_item(ugd->paired_item);
2388                 _bt_main_connect_device(ugd, dev);
2389         } else {
2390                 ugd->paired_item = NULL;
2391         }
2392
2393         FN_END;
2394         return BT_UG_ERROR_NONE;
2395 }
2396
2397 #ifdef KIRAN_ACCESSIBILITY
2398 char *__bt_main_get_device_string(int major_class, int minor_class)
2399 {
2400         FN_START;
2401         char *device_type = NULL;
2402
2403         BT_DBG("major_class: 0x%x, minor_class: 0x%x", major_class,
2404                minor_class);
2405
2406         switch (major_class) {
2407         case BT_MAJOR_DEV_CLS_COMPUTER:
2408                 device_type = g_strdup(BT_STR_COMPUTER);
2409                 break;
2410         case BT_MAJOR_DEV_CLS_PHONE:
2411                 device_type = g_strdup(BT_STR_PHONE);
2412                 break;
2413         case BT_MAJOR_DEV_CLS_AUDIO:
2414                 if (minor_class == BTAPP_MIN_DEV_CLS_HEADPHONES)
2415                         device_type = g_strdup(BT_STR_SVC_STEREO);
2416                 else
2417                         device_type = g_strdup(BT_STR_SVC_HEADSET);
2418                 break;
2419         case BT_MAJOR_DEV_CLS_LAN_ACCESS_POINT:
2420                 device_type = g_strdup(BT_STR_LAN_ACCESS_POINT);
2421                 break;
2422         case BT_MAJOR_DEV_CLS_IMAGING:
2423                 if (minor_class == BTAPP_MIN_DEV_CLS_PRINTER)
2424                         device_type = g_strdup(BT_STR_PRINTER);
2425                 else if (minor_class == BTAPP_MIN_DEV_CLS_CAMERA)
2426                         device_type = g_strdup(BT_STR_CAMERA);
2427                 else if (minor_class == BTAPP_MIN_DEV_CLS_DISPLAY)
2428                         device_type = g_strdup(BT_STR_DISPLAY);
2429                 break;
2430         case BT_MAJOR_DEV_CLS_PERIPHERAL:
2431                 if (minor_class == BTAPP_MIN_DEV_CLS_KEY_BOARD)
2432                         device_type = g_strdup(BT_STR_KEYBOARD);
2433                 else if (minor_class == BTAPP_MIN_DEV_CLS_POINTING_DEVICE)
2434                         device_type = g_strdup(BT_STR_MOUSE);
2435                 else if (minor_class == BTAPP_MIN_DEV_CLS_GAME_PAD)
2436                         device_type = g_strdup(BT_STR_GAMING_DEVICE);
2437                 else
2438                         device_type = g_strdup(BT_STR_MOUSE);
2439                 break;
2440         case BT_MAJOR_DEV_CLS_HEALTH:
2441                 device_type = g_strdup(BT_STR_HEALTH_DEVICE);
2442                 break;
2443         default:
2444                 device_type = g_strdup(BT_STR_UNKNOWN);
2445                 break;
2446         }
2447
2448         if (device_type == NULL)
2449                 device_type = g_strdup(BT_STR_UNKNOWN);
2450
2451         FN_END;
2452         return device_type;
2453 }
2454 #endif
2455
2456 char *_bt_main_get_device_icon(int major_class, int minor_class,
2457                                int connected, gboolean highlighted)
2458 {
2459         char *icon = BT_ICON_UNKNOWN;
2460
2461         switch (major_class) {
2462         case BT_MAJOR_DEV_CLS_COMPUTER:
2463                 icon = BT_ICON_PC;
2464                 break;
2465         case BT_MAJOR_DEV_CLS_PHONE:
2466                 icon = BT_ICON_PHONE;
2467                 break;
2468         case BT_MAJOR_DEV_CLS_AUDIO:
2469                 if (minor_class == BTAPP_MIN_DEV_CLS_HEADPHONES)
2470                         icon = BT_ICON_HEADPHONE;
2471                 else if (minor_class == BTAPP_MIN_DEV_CLS_VIDEO_DISPLAY_AND_LOUD_SPEAKER)
2472                         icon = BT_ICON_DISPLAY;
2473                 else
2474                         icon = BT_ICON_HEADSET;
2475                 break;
2476         case BT_MAJOR_DEV_CLS_LAN_ACCESS_POINT:
2477                 icon = BT_ICON_NETWORK;
2478                 break;
2479         case BT_MAJOR_DEV_CLS_IMAGING:
2480                 if (minor_class == BTAPP_MIN_DEV_CLS_PRINTER)
2481                         icon = BT_ICON_PRINTER;
2482                 else if (minor_class == BTAPP_MIN_DEV_CLS_CAMERA)
2483                         icon = BT_ICON_CAMERA;
2484                 else if (minor_class == BTAPP_MIN_DEV_CLS_DISPLAY)
2485                         icon = BT_ICON_DISPLAY;
2486                 break;
2487         case BT_MAJOR_DEV_CLS_PERIPHERAL:
2488                 if (minor_class == BTAPP_MIN_DEV_CLS_KEY_BOARD)
2489                         icon = BT_ICON_KEYBOARD;
2490                 else if (minor_class == BTAPP_MIN_DEV_CLS_POINTING_DEVICE)
2491                         icon = BT_ICON_MOUSE;
2492                 else if (minor_class == BTAPP_MIN_DEV_CLS_GAME_PAD)
2493                         icon = BT_ICON_GAMING;
2494                 else
2495                         icon = BT_ICON_MOUSE;
2496                 break;
2497         case BT_MAJOR_DEV_CLS_HEALTH:
2498                 icon = BT_ICON_HEALTH;
2499                 break;
2500
2501         case BT_MAJOR_DEV_CLS_WEARABLE:
2502                 if (minor_class == BTAPP_MIN_DEV_CLS_WRIST_WATCH)
2503                         icon = BT_ICON_WATCH;
2504                 else
2505                         icon = BT_ICON_UNKNOWN;
2506                 break;
2507         default:
2508                 icon = BT_ICON_UNKNOWN;
2509                 break;
2510         }
2511
2512         return icon;
2513 }
2514
2515 void _bt_main_popup_del_cb(void *data, Evas_Object *obj, void *event_info)
2516 {
2517         FN_START;
2518         retm_if(data == NULL, "Invalid argument: struct bt_appdata is NULL");
2519
2520         bt_ug_data *ugd = (bt_ug_data *)data;
2521
2522         if (ugd->popup) {
2523                 evas_object_del(ugd->popup);
2524                 ugd->popup = NULL;
2525         }
2526         if (ugd->popup_data.data)
2527                 g_free(ugd->popup_data.data);
2528         ugd->popup_data.data = NULL;
2529
2530         ugd->back_cb = NULL;
2531
2532         FN_END;
2533 }
2534
2535 void _bt_back_btn_popup_del_cb(void *data, Evas_Object *obj, void *event_info)
2536 {
2537         FN_START;
2538         retm_if(data == NULL, "Invalid argument: struct bt_appdata is NULL");
2539
2540         bt_ug_data *ugd = (bt_ug_data *)data;
2541
2542         if (ugd->popup) {
2543                 BT_DBG("Deleting popup");
2544                 evas_object_del(ugd->popup);
2545                 ugd->popup = NULL;
2546         }
2547
2548         ugd->op_status = BT_ACTIVATED;
2549
2550         FN_END;
2551 }
2552
2553 Elm_Object_Item *_bt_main_add_paired_device_on_bond(bt_ug_data *ugd, bt_dev_t *dev)
2554 {
2555         FN_START;
2556
2557         Elm_Object_Item *git = NULL;
2558
2559         retvm_if(ugd == NULL, NULL, "Invalid argument: ugd is NULL");
2560         retvm_if(dev == NULL, NULL, "Invalid argument: dev is NULL");
2561
2562         /* Paired device Title */
2563         if (ugd->paired_title == NULL) {
2564                 if (ugd->searched_title == NULL) {
2565                         git = elm_genlist_item_append(ugd->main_genlist,
2566                                                                 ugd->paired_title_itc,
2567                                                                 (void *)ugd, NULL,
2568                                                                 ELM_GENLIST_ITEM_NONE,
2569                                                                 NULL, NULL);
2570                         elm_genlist_item_select_mode_set(git,
2571                                                          ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
2572                 } else {
2573                         git = elm_genlist_item_insert_before(ugd->main_genlist,
2574                                                                 ugd->paired_title_itc,
2575                                                                 (void *)ugd, NULL,
2576                                                                 ugd->searched_title,
2577                                                                 ELM_GENLIST_ITEM_NONE,
2578                                                                 NULL, NULL);
2579                         elm_genlist_item_select_mode_set(git,
2580                                                          ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
2581
2582                 }
2583                 ugd->paired_title = git;
2584         }
2585
2586         dev->ugd = (void *)ugd;
2587         dev->is_bonded = TRUE;
2588         dev->status = BT_IDLE;
2589
2590         /* Add the device item in the list */
2591         if (ugd->paired_device == NULL) {
2592                 git = elm_genlist_item_insert_after(ugd->main_genlist,
2593                                         ugd->paired_device_itc, dev, NULL,
2594                                         ugd->paired_title,
2595                                         ELM_GENLIST_ITEM_NONE,
2596                                         __bt_main_paired_item_sel_cb,
2597                                         ugd);;
2598         } else {
2599                 bt_dev_t *item_dev = NULL;
2600                 Elm_Object_Item *item = NULL;
2601                 Elm_Object_Item *next = NULL;
2602
2603                 item = elm_genlist_item_next_get(ugd->paired_title);
2604
2605                 while (item != NULL || item != ugd->searched_title) {
2606                         item_dev = _bt_main_get_dev_info(ugd->paired_device, item);
2607
2608                         if (item_dev && item_dev->is_connected > 0) {
2609                                 next = elm_genlist_item_next_get(item);
2610                                 if (next == NULL || next == ugd->searched_title) {
2611                                         git = elm_genlist_item_insert_after(ugd->main_genlist,
2612                                                         ugd->paired_device_itc, dev, NULL, item,
2613                                                         ELM_GENLIST_ITEM_NONE,
2614                                                         __bt_main_paired_item_sel_cb,
2615                                                         ugd);
2616                                         break;
2617                                 }
2618                                 item = next;
2619                         } else {
2620                                 git = elm_genlist_item_insert_before(ugd->main_genlist,
2621                                                 ugd->paired_device_itc, dev,
2622                                                 NULL, item, ELM_GENLIST_ITEM_NONE,
2623                                                 __bt_main_paired_item_sel_cb, ugd);
2624                                 break;
2625                         }
2626                 }
2627         }
2628         dev->genlist_item = git;
2629
2630         FN_END;
2631         return dev->genlist_item;
2632 }
2633
2634 void _bt_sort_paired_device_list(bt_ug_data *ugd, bt_dev_t *dev, int connected)
2635 {
2636         FN_START;
2637
2638         bt_dev_t *item = NULL;
2639         Elm_Object_Item *git = NULL;
2640         Eina_List *l = NULL;
2641         Eina_List *l_next = NULL;
2642
2643         retm_if(ugd == NULL, "Invalid argument: ugd is NULL");
2644         retm_if(dev == NULL, "Invalid argument: dev is NULL");
2645
2646         EINA_LIST_FOREACH_SAFE(ugd->paired_device, l, l_next, item) {
2647                 if (item && (item == dev)) {
2648                         if (connected) {
2649                                 elm_object_item_del(item->genlist_item);
2650                                 git = elm_genlist_item_insert_after(ugd->main_genlist,
2651                                                 ugd->paired_device_itc, dev, NULL,
2652                                                 ugd->paired_title,
2653                                                 ELM_GENLIST_ITEM_NONE,
2654                                                 __bt_main_paired_item_sel_cb,
2655                                                 ugd);
2656                                 dev->genlist_item = git;
2657                                 break;
2658                         } else {
2659                                 if (ugd->searched_title) {
2660                                         elm_object_item_del(item->genlist_item);
2661                                         git = elm_genlist_item_insert_before(ugd->main_genlist,
2662                                                         ugd->paired_device_itc, dev, NULL,
2663                                                         ugd->searched_title,
2664                                                         ELM_GENLIST_ITEM_NONE,
2665                                                         __bt_main_paired_item_sel_cb,
2666                                                         ugd);
2667                                         dev->genlist_item = git;
2668                                         break;
2669                                 } else {
2670                                         elm_object_item_del(item->genlist_item);
2671                                         git = elm_genlist_item_append(ugd->main_genlist,
2672                                                         ugd->paired_device_itc, dev, NULL,
2673                                                         ELM_GENLIST_ITEM_NONE,
2674                                                         __bt_main_paired_item_sel_cb,
2675                                                         ugd);
2676                                         dev->genlist_item = git;
2677                                         break;
2678
2679                                 }
2680                         }
2681                 }
2682         }
2683
2684         FN_END;
2685         return;
2686 }
2687
2688 Elm_Object_Item *_bt_main_add_paired_device(bt_ug_data *ugd, bt_dev_t *dev)
2689 {
2690         FN_START;
2691
2692         Elm_Object_Item *git = NULL;
2693
2694         retvm_if(ugd == NULL, NULL, "Invalid argument: ugd is NULL");
2695         retvm_if(dev == NULL, NULL, "Invalid argument: dev is NULL");
2696
2697         /* Paired device Title */
2698         if (ugd->paired_title == NULL) {
2699                 if (ugd->searched_title == NULL) {
2700                         git = elm_genlist_item_append(ugd->main_genlist,
2701                                                         ugd->paired_title_itc,
2702                                                         (void *)ugd, NULL,
2703                                                         ELM_GENLIST_ITEM_NONE,
2704                                                         NULL, NULL);
2705                         elm_genlist_item_select_mode_set(git,
2706                                                          ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
2707                 } else {
2708                         git = elm_genlist_item_insert_before(ugd->main_genlist,
2709                                         ugd->paired_title_itc,
2710                                                         (void *)ugd, NULL,
2711                                                         ugd->searched_title,
2712                                                         ELM_GENLIST_ITEM_NONE,
2713                                                         NULL, NULL);
2714                         elm_genlist_item_select_mode_set(git,
2715                                                          ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
2716
2717                 }
2718                 ugd->paired_title = git;
2719         }
2720
2721         dev->ugd = (void *)ugd;
2722         dev->is_bonded = TRUE;
2723         dev->status = BT_IDLE;
2724
2725         /* Add the device item in the list */
2726         if (ugd->paired_device == NULL) {
2727                 git = elm_genlist_item_insert_after(ugd->main_genlist,
2728                                                         ugd->paired_device_itc, dev, NULL,
2729                                                         ugd->paired_title,
2730                                                         ELM_GENLIST_ITEM_NONE,
2731                                                         __bt_main_paired_item_sel_cb,
2732                                                         ugd);
2733         } else {
2734                 if (dev->is_connected > 0) {
2735                         git = elm_genlist_item_insert_after(ugd->main_genlist,
2736                                                         ugd->paired_device_itc, dev, NULL,
2737                                                         ugd->paired_title,
2738                                                         ELM_GENLIST_ITEM_NONE,
2739                                                         __bt_main_paired_item_sel_cb,
2740                                                         ugd);
2741                 } else {
2742                         Elm_Object_Item *item = NULL;
2743                         Elm_Object_Item *next = NULL;
2744
2745                         item = elm_genlist_item_next_get(ugd->paired_title);
2746
2747                         while (item != NULL || item != ugd->searched_title) {
2748                                 next = elm_genlist_item_next_get(item);
2749                                 if (next == NULL || next == ugd->searched_title) {
2750                                         git = elm_genlist_item_insert_after(ugd->main_genlist,
2751                                                         ugd->paired_device_itc, dev, NULL, item,
2752                                                         ELM_GENLIST_ITEM_NONE,
2753                                                         __bt_main_paired_item_sel_cb,
2754                                                         ugd);
2755                                         break;
2756                                 }
2757                                 item = next;
2758                         }
2759                 }
2760         }
2761         dev->genlist_item = git;
2762
2763         FN_END;
2764         return dev->genlist_item;
2765 }
2766
2767 Elm_Object_Item *_bt_main_add_searched_device(bt_ug_data *ugd, bt_dev_t *dev)
2768 {
2769         FN_START;
2770
2771         Elm_Object_Item *git = NULL;
2772
2773         retvm_if(ugd == NULL, NULL, "Invalid argument: ugd is NULL");
2774         retvm_if(dev == NULL, NULL, "Invalid argument: dev is NULL");
2775
2776         if (ugd->searched_title == NULL)
2777                 _bt_main_add_searched_title(ugd);
2778
2779         retvm_if(ugd->searched_title == NULL, NULL,
2780                  "Fail to add searched title genlist item");
2781
2782         /* Searched device Item */
2783         if (ugd->searched_device == NULL) {
2784                 git =
2785                     elm_genlist_item_insert_after(ugd->main_genlist,
2786                                                   ugd->searched_device_itc, dev, NULL,
2787                                                   ugd->searched_title,
2788                                                   ELM_GENLIST_ITEM_NONE,
2789                                                   __bt_main_searched_item_sel_cb,
2790                                                   ugd);
2791         } else {
2792                 bt_dev_t *item_dev = NULL;
2793                 Elm_Object_Item *item = NULL;
2794                 Elm_Object_Item *next = NULL;
2795                 Elm_Object_Item *prev = NULL;
2796
2797                 item = elm_genlist_item_next_get(ugd->searched_title);
2798
2799                 /* check the RSSI value of searched device list add arrange its order */
2800                 while (item != NULL) {
2801                         item_dev =
2802                             _bt_main_get_dev_info(ugd->searched_device, item);
2803                         retv_if(item_dev == NULL, NULL);
2804
2805                         if (item_dev->rssi > dev->rssi) {
2806                                 prev = elm_genlist_item_prev_get(item);
2807                                 next = elm_genlist_item_next_get(item);
2808                                 if (next == NULL) {
2809                                         git =
2810                                             elm_genlist_item_insert_after
2811                                             (ugd->main_genlist,
2812                                              ugd->searched_device_itc, dev, NULL, item,
2813                                              ELM_GENLIST_ITEM_NONE,
2814                                              __bt_main_searched_item_sel_cb,
2815                                              ugd);
2816
2817                                         if (TIZEN_COMMON && prev == ugd->searched_title)
2818                                                 elm_object_item_signal_emit(item, "elm,state,group,top", "elm");
2819
2820                                         break;
2821                                 }
2822                                 item = next;
2823                         } else {
2824                                 next = elm_genlist_item_next_get(item);
2825
2826                                 git =
2827                                     elm_genlist_item_insert_before
2828                                     (ugd->main_genlist, ugd->searched_device_itc, dev,
2829                                      NULL, item, ELM_GENLIST_ITEM_NONE,
2830                                      __bt_main_searched_item_sel_cb, ugd);
2831
2832                                 if (TIZEN_COMMON) {
2833                                         if (next == NULL)
2834                                                 elm_object_item_signal_emit(item, "elm,state,group,bottom", "elm");
2835                                         else
2836                                                 elm_object_item_signal_emit(item, "elm,state,group,middle", "elm");
2837                                 }
2838
2839                                 break;
2840                         }
2841                 }
2842         }
2843
2844         dev->genlist_item = git;
2845         dev->status = BT_IDLE;
2846         dev->ugd = (void *)ugd;
2847         dev->is_bonded = FALSE;
2848
2849         FN_END;
2850         return git;
2851 }
2852
2853 Elm_Object_Item *_bt_main_add_no_device_found(bt_ug_data *ugd)
2854 {
2855         FN_START;
2856
2857         Elm_Object_Item *git = NULL;
2858
2859         retvm_if(ugd == NULL, NULL, "Invalid argument: ugd is NULL");
2860
2861         if (ugd->searched_title == NULL)
2862                 _bt_main_add_searched_title(ugd);
2863
2864         /* No device found Item */
2865         git =
2866             elm_genlist_item_insert_after(ugd->main_genlist, ugd->no_device_itc,
2867                                         ugd, NULL, ugd->searched_title,
2868                                         ELM_GENLIST_ITEM_NONE, NULL, NULL);
2869
2870         elm_genlist_item_select_mode_set(git,
2871                                         ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
2872
2873         FN_END;
2874         return git;
2875 }
2876
2877 static void __bt_move_help_ctxpopup(Evas_Object *ctx, bt_ug_data *ugd)
2878 {
2879         FN_START;
2880         Evas_Coord w, h;
2881         int pos = -1;
2882
2883         ret_if(ugd == NULL);
2884         ret_if(ugd->win_main == NULL);
2885
2886         elm_win_screen_size_get(ugd->win_main, NULL, NULL, &w, &h);
2887         pos = elm_win_rotation_get(ugd->win_main);
2888         switch (pos) {
2889         case 0:
2890         case 180:
2891         case 360:
2892                 evas_object_move(ctx, (w/2), h);
2893                 break;
2894         case 90:
2895         case 270:
2896                 evas_object_move(ctx, (h/2), w);
2897                 break;
2898         default:
2899                 evas_object_move(ctx, (w/2), h);
2900                 break;
2901         }
2902         FN_END;
2903 }
2904
2905 static void __bt_ctxpopup_rotate_cb(void *data, Evas_Object *obj, void *event_info)
2906 {
2907         FN_START;
2908         bt_ug_data *ugd = NULL;
2909         ret_if(data == NULL);
2910         ugd = (bt_ug_data *)data;
2911
2912         __bt_move_help_ctxpopup(ugd->help_more_popup, ugd);
2913         evas_object_show(ugd->win_main);
2914
2915         FN_END;
2916 }
2917
2918 static void __bt_more_popup_del_cb(void *data)
2919 {
2920         FN_START;
2921         bt_ug_data *ugd = NULL;
2922
2923         ret_if(data == NULL);
2924         ugd = (bt_ug_data *)data;
2925
2926         if (ugd->help_more_popup != NULL) {
2927                 evas_object_del(ugd->help_more_popup);
2928                 ugd->help_more_popup = NULL;
2929         }
2930
2931         FN_END;
2932 }
2933
2934 static void __bt_more_popup_more_cb(void *data,
2935                                 Evas_Object *obj, void *event_info)
2936 {
2937         FN_START;
2938         __bt_more_popup_del_cb((bt_ug_data *)data);
2939         FN_END;
2940 }
2941
2942 static void __bt_more_popup_back_cb(void *data,
2943                                 Evas_Object *obj, void *event_info)
2944 {
2945         FN_START;
2946         __bt_more_popup_del_cb((bt_ug_data *)data);
2947         FN_END;
2948 }
2949
2950 static void __bt_more_popup_dismiss_cb(void *data, Evas_Object *obj,
2951                                                 void *event)
2952 {
2953         FN_START;
2954         bt_ug_data *ugd;
2955
2956         ugd = (bt_ug_data *)data;
2957         ret_if(ugd == NULL);
2958         ret_if(ugd->help_more_popup == NULL);
2959
2960         evas_object_del(ugd->help_more_popup);
2961         ugd->help_more_popup = NULL;
2962
2963         FN_END;
2964 }
2965
2966 static void __bt_more_popup_delete_cb(void *data, Evas *e,
2967                 Evas_Object *obj,       void *event_info)
2968 {
2969         FN_START;
2970         Evas_Object *navi = (Evas_Object *)data;
2971         Evas_Object *ctx = obj;
2972
2973         ret_if(navi == NULL);
2974
2975         evas_object_smart_callback_del(ctx, "dismissed",
2976                         __bt_more_popup_dismiss_cb);
2977         evas_object_event_callback_del_full(ctx, EVAS_CALLBACK_DEL,
2978                         __bt_more_popup_delete_cb, navi);
2979         FN_END;
2980 }
2981
2982 #ifdef TIZEN_REDWOOD
2983 static void __bt_ug_layout_cb(ui_gadget_h ug, enum ug_mode mode, void *priv)
2984 {
2985         FN_START;
2986         Evas_Object *base;
2987
2988         ret_if(!ug);
2989
2990         base = ug_get_layout(ug);
2991         if (!base) {
2992                 BT_ERR("ug_get_layout() return NULL");
2993                 ug_destroy(ug);
2994                 return;
2995         }
2996
2997         evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2998         evas_object_show(base);
2999         FN_END;
3000 }
3001
3002 static void __bt_ug_destroy_cb(ui_gadget_h ug, void *data)
3003 {
3004         FN_START;
3005         ret_if(NULL == ug);
3006         ug_destroy(ug);
3007
3008         FN_END;
3009 }
3010 #endif
3011
3012 static void __bt_more_popup_rename_device_item_sel_cb(void *data,
3013                                 Evas_Object *obj, void *event_inf)
3014 {
3015         FN_START;
3016         ret_if(data == NULL);
3017         ret_if(event_inf == NULL);
3018         bt_ug_data *ugd = (bt_ug_data *)data;
3019
3020         if (event_inf)
3021                 elm_genlist_item_selected_set((Elm_Object_Item *)event_inf,
3022                                                 EINA_FALSE);
3023
3024         ret_if(ugd == NULL);
3025         ret_if(ugd->help_more_popup == NULL);
3026         evas_object_del(ugd->help_more_popup);
3027         ugd->help_more_popup = NULL;
3028         Evas_Object *popup = NULL;
3029         Evas_Object *genlist = NULL;
3030         Evas_Object *button = NULL;
3031         Elm_Object_Item *git = NULL;
3032
3033
3034         popup = elm_popup_add(ugd->base);
3035         eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK,
3036                         __bt_rename_device_cancel_cb, ugd);
3037         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
3038         evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
3039
3040         elm_object_domain_translatable_part_text_set(popup,
3041                                                 "title,text",
3042                                                 PKGNAME,
3043                                                 "IDS_ST_HEADER_RENAME_DEVICE");
3044
3045         genlist = elm_genlist_add(popup);
3046         evas_object_size_hint_weight_set(genlist,
3047                         EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
3048         evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
3049         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
3050         elm_scroller_content_min_limit(genlist, EINA_FALSE, EINA_TRUE);
3051
3052         /* Entry genlist item */
3053         ugd->rename_entry_itc = elm_genlist_item_class_new();
3054         /* Fix : NULL_RETURNS */
3055         if (ugd->rename_entry_itc) {
3056                 ugd->rename_entry_itc->item_style = BT_GENLIST_FULL_CONTENT_STYLE;
3057                 ugd->rename_entry_itc->func.text_get = NULL;
3058                 ugd->rename_entry_itc->func.content_get = __bt_main_rename_entry_icon_get;
3059                 ugd->rename_entry_itc->func.state_get = NULL;
3060                 ugd->rename_entry_itc->func.del = NULL;
3061
3062                 ugd->rename_entry_item = elm_genlist_item_append(genlist,
3063                                 ugd->rename_entry_itc, ugd,
3064                                 NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
3065         }
3066
3067         ugd->rename_desc_itc = elm_genlist_item_class_new();
3068         /* Fix : NULL_RETURNS */
3069         if (ugd->rename_desc_itc) {
3070                 ugd->rename_desc_itc->item_style = BT_GENLIST_MULTILINE_TEXT_STYLE;
3071                 ugd->rename_desc_itc->func.text_get = __bt_main_rename_desc_label_get;
3072                 ugd->rename_desc_itc->func.content_get = NULL;
3073                 ugd->rename_desc_itc->func.state_get = NULL;
3074                 ugd->rename_desc_itc->func.del = NULL;
3075
3076                 git = elm_genlist_item_append(genlist, ugd->rename_desc_itc, NULL, NULL,
3077                                 ELM_GENLIST_ITEM_NONE, NULL, NULL);
3078         }
3079         elm_genlist_item_select_mode_set(git,
3080                                          ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
3081
3082         button = elm_button_add(popup);
3083         elm_object_style_set(button, "popup");
3084         elm_object_domain_translatable_text_set(button,
3085                                                 PKGNAME,
3086                                                 "IDS_BR_SK_CANCEL");
3087         elm_object_part_content_set(popup, "button1", button);
3088         evas_object_smart_callback_add(button, "clicked",
3089                         __bt_rename_device_cancel_cb, ugd);
3090
3091         button = elm_button_add(popup);
3092         ugd->rename_button = button;
3093         elm_object_style_set(button, "popup");
3094         elm_object_domain_translatable_text_set(button,
3095                                                 PKGNAME,
3096                                                 "IDS_BT_OPT_RENAME");
3097         elm_object_part_content_set(popup, "button2", button);
3098         evas_object_smart_callback_add(button, "clicked",
3099                         __bt_rename_device_ok_cb, ugd);
3100
3101         evas_object_show(genlist);
3102
3103         elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
3104         elm_object_content_set(popup, genlist);
3105         evas_object_show(popup);
3106
3107         ugd->rename_popup = popup;
3108
3109         FN_END;
3110
3111 }
3112
3113 #ifdef TIZEN_REDWOOD
3114 static void __bt_more_popup_help_item_sel_cb(void *data,
3115                                 Evas_Object *obj, void *event_info)
3116 {
3117         FN_START;
3118         ret_if(!data);
3119
3120         bt_ug_data *ugd = (bt_ug_data *)data;
3121         app_control_h service = NULL;
3122         ui_gadget_h ug_h = NULL;
3123         struct ug_cbs cbs = {0};
3124
3125         if (ugd->popup) {
3126                 BT_DBG("delete popup");
3127                 evas_object_del(ugd->popup);
3128                 ugd->popup = NULL;
3129         }
3130
3131         app_control_create(&service);
3132         app_control_add_extra_data(service, "page", "help_settings_bluetooth");
3133
3134         cbs.layout_cb = __bt_ug_layout_cb;
3135         cbs.result_cb = NULL;
3136         cbs.destroy_cb = __bt_ug_destroy_cb;
3137         cbs.priv = NULL;
3138
3139         ug_h = ug_create(NULL, "help-efl", UG_MODE_FULLVIEW, service, &cbs);
3140         if (!ug_h)
3141                 BT_ERR("ug_create() Failed");
3142
3143         app_control_destroy(service);
3144         __bt_more_popup_del_cb((bt_ug_data *)data);
3145         FN_END;
3146 }
3147 #endif
3148
3149 static void __bt_more_menu_cb(void *data,
3150                                 Evas_Object *obj, void *event_info)
3151 {
3152         FN_START;
3153
3154         Evas_Object *more_ctxpopup = NULL;
3155         bt_ug_data *ugd;
3156
3157         ugd = (bt_ug_data *)data;
3158         ret_if(ugd == NULL);
3159         ret_if(ugd->profile_vd != NULL);
3160         ret_if(ugd->op_status == BT_ACTIVATING ||
3161                 ugd->op_status == BT_DEACTIVATED ||
3162                 ugd->op_status == BT_DEACTIVATING);
3163         ret_if(ugd->bt_launch_mode != BT_LAUNCH_NORMAL);
3164
3165         _bt_main_popup_del_cb(ugd, NULL, NULL);
3166
3167         more_ctxpopup = elm_ctxpopup_add(ugd->win_main);
3168         ugd->help_more_popup = more_ctxpopup;
3169         eext_object_event_callback_add(more_ctxpopup,
3170                         EEXT_CALLBACK_BACK, __bt_more_popup_back_cb, ugd);
3171         eext_object_event_callback_add(more_ctxpopup,
3172                         EEXT_CALLBACK_MORE, __bt_more_popup_more_cb, ugd);
3173         elm_object_style_set(more_ctxpopup, "more/default");
3174         elm_ctxpopup_auto_hide_disabled_set(more_ctxpopup, EINA_TRUE);
3175
3176         elm_ctxpopup_item_append(more_ctxpopup, BT_STR_RENAME_DEVICE_TITLE,
3177                         NULL, __bt_more_popup_rename_device_item_sel_cb, ugd);
3178
3179         evas_object_smart_callback_add(more_ctxpopup, "dismissed",
3180                         __bt_more_popup_dismiss_cb, ugd);
3181         evas_object_event_callback_add(more_ctxpopup, EVAS_CALLBACK_DEL,
3182                         __bt_more_popup_delete_cb, ugd->navi_bar);
3183         evas_object_smart_callback_add(elm_object_top_widget_get(more_ctxpopup), "rotation,changed",
3184                         __bt_ctxpopup_rotate_cb, ugd);
3185
3186         elm_ctxpopup_direction_priority_set(more_ctxpopup, ELM_CTXPOPUP_DIRECTION_UP,
3187                         ELM_CTXPOPUP_DIRECTION_DOWN,
3188                         ELM_CTXPOPUP_DIRECTION_UNKNOWN,
3189                         ELM_CTXPOPUP_DIRECTION_UNKNOWN);
3190
3191         __bt_move_help_ctxpopup(more_ctxpopup, ugd);
3192         evas_object_show(more_ctxpopup);
3193
3194         FN_END;
3195 }
3196
3197 Evas_Object * _bt_main_create_scan_button(bt_ug_data *ugd)
3198 {
3199         Evas_Object *scan_button = NULL;
3200         Evas_Object *box = NULL;
3201
3202         box = elm_box_add(ugd->navi_bar);
3203         if (!box) {
3204                 BT_DBG("Can't create box");
3205                 return NULL;
3206         }
3207
3208         scan_button = elm_button_add(box);
3209
3210         if (TIZEN_COMMON) {
3211                 /* Use "border" style button for IOT common */
3212                 elm_object_style_set(scan_button, "border");
3213         } else {
3214                 /* Use "bottom" style button */
3215                 elm_object_style_set(scan_button, "bottom");
3216         }
3217
3218         elm_object_text_set(scan_button, BT_STR_SCAN);
3219
3220         evas_object_size_hint_align_set(scan_button, EVAS_HINT_FILL, EVAS_HINT_FILL);
3221         evas_object_size_hint_weight_set(scan_button, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
3222
3223         if (TIZEN_COMMON)
3224                 evas_object_size_hint_padding_set(scan_button, 0, 0, 30, 0);
3225
3226         evas_object_smart_callback_add(scan_button, "clicked",
3227                         __bt_main_controlbar_btn_cb, ugd);
3228
3229         elm_box_pack_end(box, scan_button);
3230
3231         /* Set box into "toolbar" swallow part */
3232         elm_object_item_part_content_set(ugd->navi_it, "toolbar", box);
3233         evas_object_show(scan_button);
3234
3235         return scan_button;
3236 }
3237
3238 static void __bt_main_back_cb(void *data, Evas_Object *obj, void *event_info)
3239 {
3240         __bt_main_quit_btn_cb(data, NULL);
3241 }
3242
3243 int _bt_main_draw_list_view(bt_ug_data *ugd)
3244 {
3245         FN_START;
3246
3247         Evas_Object *navi = NULL;
3248         Evas_Object *genlist = NULL;
3249         Elm_Object_Item *navi_it = NULL;
3250         Evas_Object *back_button = NULL;
3251
3252         retv_if(ugd == NULL, BT_UG_FAIL);
3253
3254         navi = _bt_create_naviframe(ugd->base);
3255         elm_naviframe_prev_btn_auto_pushed_set(navi, EINA_FALSE);
3256         ugd->navi_bar = navi;
3257
3258         eext_object_event_callback_add(navi, EEXT_CALLBACK_BACK,
3259                                      eext_naviframe_back_cb, NULL);
3260
3261         if (ugd->bt_launch_mode != BT_LAUNCH_HELP)
3262                 eext_object_event_callback_add(navi, EEXT_CALLBACK_MORE,
3263                                                 __bt_more_menu_cb, ugd);
3264         genlist = __bt_main_add_genlist_dialogue(navi, ugd);
3265         ugd->main_genlist = genlist;
3266
3267         back_button = elm_button_add(navi);
3268         elm_object_style_set(back_button, "naviframe/end_btn/default");
3269
3270         navi_it = elm_naviframe_item_push(navi, BT_STR_BLUETOOTH, back_button, NULL,
3271                                           genlist, NULL);
3272         elm_naviframe_item_pop_cb_set(navi_it, __bt_main_quit_btn_cb, ugd);
3273         ugd->navi_it = navi_it;
3274         evas_object_smart_callback_add(back_button, "clicked", __bt_main_back_cb, ugd);
3275
3276         if (ugd->op_status == BT_ACTIVATED)
3277                 ugd->scan_btn = _bt_main_create_scan_button(ugd);
3278
3279         ugd->confirm_req = BT_NONE_REQ;
3280
3281         FN_END;
3282         return BT_UG_ERROR_NONE;
3283 }
3284
3285 int _bt_main_draw_visibility_view(bt_ug_data *ugd)
3286 {
3287         FN_START;
3288
3289         Evas_Object *navi = NULL;
3290         Evas_Object *genlist = NULL;
3291         Elm_Object_Item *navi_it;
3292
3293         retv_if(ugd == NULL, BT_UG_FAIL);
3294
3295         navi = _bt_create_naviframe(ugd->base);
3296
3297         elm_naviframe_prev_btn_auto_pushed_set(navi, EINA_FALSE);
3298
3299         eext_object_event_callback_add(navi, EEXT_CALLBACK_BACK,
3300                                      eext_naviframe_back_cb, NULL);
3301
3302         genlist = __bt_main_add_visibility_dialogue(navi, ugd);
3303
3304         navi_it =
3305             elm_naviframe_item_push(navi, BT_STR_VISIBLE, NULL, NULL, genlist,
3306                                     NULL);
3307         elm_naviframe_item_pop_cb_set(navi_it, __bt_main_quit_btn_cb, ugd);
3308         ugd->navi_it = navi_it;
3309         ugd->navi_bar = navi;
3310         ugd->main_genlist = genlist;
3311         ugd->confirm_req = BT_NONE_REQ;
3312
3313         FN_END;
3314         return BT_UG_ERROR_NONE;
3315 }
3316
3317 int _bt_main_draw_onoff_view(bt_ug_data *ugd)
3318 {
3319         FN_START;
3320
3321         Evas_Object *navi = NULL;
3322         Evas_Object *genlist = NULL;
3323         Elm_Object_Item *navi_it;
3324
3325         retv_if(ugd == NULL, BT_UG_FAIL);
3326
3327         navi = _bt_create_naviframe(ugd->base);
3328
3329         elm_naviframe_prev_btn_auto_pushed_set(navi, EINA_FALSE);
3330
3331         eext_object_event_callback_add(navi, EEXT_CALLBACK_BACK,
3332                                      eext_naviframe_back_cb, NULL);
3333
3334         genlist = __bt_main_add_onoff_dialogue(navi, ugd);
3335
3336         navi_it =
3337             elm_naviframe_item_push(navi, BT_STR_BLUETOOTH, NULL, NULL, genlist,
3338                                     NULL);
3339         elm_naviframe_item_pop_cb_set(navi_it, __bt_main_quit_btn_cb, ugd);
3340         ugd->navi_it = navi_it;
3341         ugd->navi_bar = navi;
3342         ugd->main_genlist = genlist;
3343         ugd->confirm_req = BT_NONE_REQ;
3344
3345         FN_END;
3346         return BT_UG_ERROR_NONE;
3347 }
3348
3349 static Eina_Bool __bt_cb_register_net_state_cb(void *data)
3350 {
3351         FN_START;
3352
3353         bt_dev_t *dev = NULL;
3354         Eina_List *l = NULL;
3355         Eina_List *l2 = NULL;
3356         bt_net_profile_t *profile_data = NULL;
3357         void *profile = NULL;
3358         char net_address[BT_ADDRESS_STR_LEN + 1] = { 0 };
3359
3360         bt_ug_data *ugd = (bt_ug_data *)data;
3361         if (ugd->network_timer) {
3362                 ecore_timer_del(ugd->network_timer);
3363                 ugd->network_timer = NULL;
3364         }
3365         retv_if(ugd == NULL, ECORE_CALLBACK_CANCEL);
3366         retv_if(ugd->connection == NULL, ECORE_CALLBACK_CANCEL);
3367
3368         if (ugd->paired_device) {
3369                 EINA_LIST_FOREACH(ugd->paired_device, l, dev) {
3370                         if (dev &&
3371                                 (dev->service_list & BT_SC_PANU_SERVICE_MASK ||
3372                                 dev->service_list & BT_SC_NAP_SERVICE_MASK) &&
3373                                 dev->is_connected && !dev->net_profile) {
3374                                 if (!ugd->net_profile_list)
3375                                         ugd->net_profile_list =
3376                                         _bt_get_registered_net_profile_list(ugd->connection);
3377                                 retvm_if(!ugd->net_profile_list, ECORE_CALLBACK_CANCEL,
3378                                                 "net_profile_list is NULL!");
3379
3380                                 EINA_LIST_FOREACH(ugd->net_profile_list, l2, profile_data) {
3381                                         if (profile_data &&
3382                                         profile_data->profile_h &&
3383                                         profile_data->address) {
3384                                                 _bt_util_addr_type_to_addr_net_string(net_address, dev->bd_addr);
3385                                                 if (!g_strcmp0((const char *)profile_data->address, net_address)) {
3386                                                         profile = _bt_get_registered_net_profile(ugd->connection,
3387                                                                    dev->bd_addr);
3388                                                         _bt_set_profile_state_changed_cb(profile, dev);
3389                                                 }
3390                                         }
3391                                 }
3392                         }
3393                 }
3394
3395                 if (ugd->net_profile_list) {
3396                         _bt_free_net_profile_list(ugd->net_profile_list);
3397                         ugd->net_profile_list = NULL;
3398                 }
3399
3400         }
3401
3402         FN_END;
3403         return ECORE_CALLBACK_CANCEL;
3404 }
3405
3406 static bool __bt_cb_adapter_bonded_device(bt_device_info_s *device_info,
3407                                           void *user_data)
3408 {
3409         bt_dev_t *dev = NULL;
3410         bt_ug_data *ugd = NULL;
3411         unsigned int service_class;
3412
3413         retv_if(!user_data, false);
3414         retv_if(!device_info->remote_name || strlen(device_info->remote_name) == 0, false);
3415         retv_if(!device_info->remote_address || strlen(device_info->remote_address) == 0, false);
3416
3417         ugd = (bt_ug_data *)user_data;
3418
3419         if (_bt_main_check_and_update_device(ugd->paired_device,
3420                                              device_info->remote_address,
3421                                              device_info->remote_name) >= 0) {
3422                 /* Update all realized items */
3423                 elm_genlist_realized_items_update(ugd->main_genlist);
3424
3425                 return true;
3426         }
3427
3428         dev = _bt_main_create_paired_device_item(device_info);
3429
3430         retv_if(!dev, false);
3431
3432         dev->ugd = (void *)ugd;
3433         if (device_info->is_connected)
3434                 dev->is_connected = _bt_util_check_any_profile_connected(dev);
3435         else
3436                 dev->is_connected = device_info->is_connected;
3437
3438         BT_INFO("device state(%d) overriding with profile state(%d)",
3439                 device_info->is_connected, dev->is_connected);
3440
3441         service_class = dev->service_class;
3442
3443         /* WORKAROUND for a PLM issue.
3444         For some devices, service class is 0 even if it supports OPP server. So it is
3445         not showing in the device list when user try to share files via bluetooth.
3446         So override service_class with BT_COD_SC_OBJECT_TRANSFER in that case
3447         */
3448         BT_DBG("overriding");
3449         if (service_class == 0) {
3450                 if (dev->service_list & BT_SC_OPP_SERVICE_MASK)
3451                         service_class = BT_COD_SC_OBJECT_TRANSFER;
3452         }
3453
3454         if (_bt_main_is_matched_profile(ugd->search_type,
3455                                         dev->major_class,
3456                                         service_class,
3457                                         ugd->service,
3458                                         dev->minor_class) == TRUE) {
3459                 BT_INFO("Device count [%d]",
3460                        eina_list_count(ugd->paired_device));
3461
3462                 if (_bt_main_add_paired_device(ugd, dev) != NULL) {
3463                         ugd->paired_device =
3464                             eina_list_append(ugd->paired_device, dev);
3465
3466                         if ((!TIZEN_FEATURE_BT_HOG && dev->service_list == 0) || (TIZEN_FEATURE_BT_HOG && (dev->service_list == 0) && (!dev->is_le_device))) {
3467                                 if (bt_device_start_service_search
3468                                     ((const char *)dev->addr_str) == BT_ERROR_NONE) {
3469
3470                                         ugd->paired_item = dev->genlist_item;
3471                                         dev->status = BT_SERVICE_SEARCHING;
3472                                         ugd->waiting_service_response = TRUE;
3473                                         ugd->request_timer =
3474                                             ecore_timer_add(BT_SEARCH_SERVICE_TIMEOUT,
3475                                                             (Ecore_Task_Cb)
3476                                                             _bt_main_service_request_cb,
3477                                                             ugd);
3478                                 } else {
3479                                         BT_ERR("service search error");
3480                                 }
3481                         }
3482                 }
3483         } else {
3484                 BT_ERR("Device class and search type do not match");
3485                 free(dev);
3486         }
3487         return true;
3488 }
3489
3490 void _bt_main_draw_paired_devices(bt_ug_data *ugd)
3491 {
3492         FN_START;
3493
3494         ret_if(ugd == NULL);
3495
3496         if (bt_adapter_foreach_bonded_device(__bt_cb_adapter_bonded_device,
3497                                                                         (void *)ugd) != BT_ERROR_NONE) {
3498                 BT_ERR("bt_adapter_foreach_bonded_device() failed");
3499                 return;
3500         }
3501
3502         ugd->network_timer = ecore_timer_add(1, __bt_cb_register_net_state_cb, ugd);
3503
3504         if (!ugd->network_timer)
3505                 BT_ERR("network_timer can not be added");
3506         FN_END;
3507         return;
3508 }
3509
3510 void _bt_main_remove_paired_device(bt_ug_data *ugd, bt_dev_t *dev)
3511 {
3512         FN_START;
3513
3514         bt_dev_t *item = NULL;
3515         Eina_List *l = NULL;
3516         Eina_List *l_next = NULL;
3517
3518         retm_if(ugd == NULL, "Invalid argument: ugd is NULL");
3519         retm_if(dev == NULL, "Invalid argument: dev is NULL");
3520
3521         EINA_LIST_FOREACH_SAFE(ugd->paired_device, l, l_next, item) {
3522                 if (item && (item == dev)) {
3523                         elm_object_item_del(item->genlist_item);
3524                         ugd->paired_device =
3525                             eina_list_remove_list(ugd->paired_device, l);
3526                 }
3527         }
3528
3529         if (ugd->paired_device == NULL ||
3530             eina_list_count(ugd->paired_device) == 0) {
3531                 elm_object_item_del(ugd->paired_title);
3532                 ugd->paired_title = NULL;
3533         }
3534         FN_END;
3535         return;
3536 }
3537
3538 void _bt_main_remove_all_paired_devices(bt_ug_data *ugd)
3539 {
3540         FN_START;
3541
3542         bt_dev_t *dev = NULL;
3543         Eina_List *l = NULL;
3544         Eina_List *l_next = NULL;
3545         Elm_Object_Item *item;
3546         Elm_Object_Item *next;
3547
3548         ret_if(ugd == NULL);
3549
3550         if (ugd->paired_title) {
3551                 item = elm_genlist_item_next_get(ugd->paired_title);
3552
3553                 elm_object_item_del(ugd->paired_title);
3554                 ugd->paired_title = NULL;
3555
3556                 while (item != NULL && (item != ugd->searched_title)) {
3557                         next = elm_genlist_item_next_get(item);
3558                         elm_object_item_del(item);
3559                         item = next;
3560                 }
3561         }
3562
3563         EINA_LIST_FOREACH_SAFE(ugd->paired_device, l, l_next, dev) {
3564                 ugd->paired_device =
3565                     eina_list_remove_list(ugd->paired_device, l);
3566                 _bt_util_free_device_item(dev);
3567         }
3568
3569         ugd->paired_device = NULL;
3570
3571         FN_END;
3572         return;
3573 }
3574
3575 void _bt_main_remove_searched_device(bt_ug_data *ugd, bt_dev_t *dev)
3576 {
3577         FN_START;
3578
3579         bt_dev_t *item = NULL;
3580         Eina_List *l = NULL;
3581         Eina_List *l_next = NULL;
3582
3583         ret_if(ugd == NULL);
3584
3585         EINA_LIST_FOREACH_SAFE(ugd->searched_device, l, l_next, item) {
3586                 if (item && (item == dev)) {
3587                         if (dev->genlist_item) {
3588                                 elm_object_item_del(dev->genlist_item);
3589                                 dev->genlist_item = NULL;
3590                         }
3591                         ugd->searched_device =
3592                             eina_list_remove_list(ugd->searched_device, l);
3593                         _bt_util_free_device_item(item);
3594                 }
3595         }
3596
3597         if (ugd->searched_device == NULL ||
3598                         eina_list_count(ugd->searched_device) == 0) {
3599                 elm_object_item_del(ugd->searched_title);
3600                 ugd->searched_title = NULL;
3601         }
3602         FN_END;
3603         return;
3604 }
3605
3606 void _bt_main_remove_all_searched_devices(bt_ug_data *ugd)
3607 {
3608         FN_START;
3609
3610         bt_dev_t *dev = NULL;
3611         Eina_List *l = NULL;
3612         Eina_List *l_next = NULL;
3613         Elm_Object_Item *item;
3614         Elm_Object_Item *next;
3615
3616         ret_if(ugd == NULL);
3617
3618         if (ugd->searched_title) {
3619                 item = elm_genlist_item_next_get(ugd->searched_title);
3620                 elm_object_item_del(ugd->searched_title);
3621                 ugd->searched_title = NULL;
3622
3623                 while (item != NULL) {
3624                         next = elm_genlist_item_next_get(item);
3625                         elm_object_item_del(item);
3626                         item = next;
3627                 }
3628                 ugd->no_device_item = NULL;
3629         }
3630
3631         EINA_LIST_FOREACH_SAFE(ugd->searched_device, l, l_next, dev) {
3632                 ugd->searched_device =
3633                     eina_list_remove_list(ugd->searched_device, l);
3634                 _bt_util_free_device_item(dev);
3635         }
3636
3637         ugd->searched_device = NULL;
3638
3639         FN_END;
3640         return;
3641 }
3642
3643 void _bt_main_connect_device(bt_ug_data *ugd, bt_dev_t *dev)
3644 {
3645         FN_START;
3646
3647         int headset_type = BT_AUDIO_PROFILE_TYPE_ALL;
3648         int ret;
3649         int hfp_restricted = 0x0;
3650         int a2dp_restricted = 0x0;
3651
3652         ret_if(ugd == NULL);
3653         ret_if(dev == NULL);
3654
3655 #ifdef TIZEN_BT_A2DP_SINK_ENABLE
3656         if (dev->service_list & BT_SC_A2DP_SOURCE_SERVICE_MASK) {
3657                 if (bt_audio_connect(dev->addr_str,
3658                                      BT_AUDIO_PROFILE_TYPE_A2DP_SINK) == BT_ERROR_NONE) {
3659                         ugd->connect_req = TRUE;
3660                         dev->status = BT_CONNECTING;
3661                 } else {
3662                         BT_ERR("Fail to connect BT_AUDIO_PROFILE_TYPE_A2DP_SINK");
3663                 }
3664 #else
3665 #ifndef TELEPHONY_DISABLED
3666         if ((dev->service_list & BT_SC_HFP_SERVICE_MASK) ||
3667             (dev->service_list & BT_SC_HSP_SERVICE_MASK)) {
3668                 /* Connect the  Headset */
3669                 if (dev->service_list & BT_SC_A2DP_SERVICE_MASK)
3670                         headset_type = BT_AUDIO_PROFILE_TYPE_ALL;
3671                 else
3672                         headset_type = BT_AUDIO_PROFILE_TYPE_HSP_HFP;
3673
3674                 BT_INFO("Connection type = %d", headset_type);
3675                 if (headset_type == BT_AUDIO_PROFILE_TYPE_ALL) {
3676                         /* restriction check */
3677                         bt_device_get_profile_restricted(dev->addr_str, BT_RESTRICTED_PROFILE_HFP_HS, &hfp_restricted);
3678                         bt_device_get_profile_restricted(dev->addr_str, BT_RESTRICTED_PROFILE_A2DP, &a2dp_restricted);
3679                         BT_INFO("Restricted Connection, HFP:%d, A2DP:%d", hfp_restricted, a2dp_restricted);
3680
3681                         if ((hfp_restricted == 0x1) && (a2dp_restricted == 0x1)) {
3682                                 ret = bt_device_set_profile_restricted(dev->addr_str, BT_RESTRICTED_PROFILE_HFP_HS, 0x0);
3683                                 if (ret != BT_ERROR_NONE)
3684                                         BT_ERR("Fail to set profile restriction");
3685
3686                                 ret = bt_device_set_profile_restricted(dev->addr_str, BT_RESTRICTED_PROFILE_A2DP, 0x0);
3687                                 if (ret != BT_ERROR_NONE)
3688                                         BT_ERR("Fail to set profile restriction");
3689                         }
3690                 }
3691
3692                 if (bt_audio_connect(dev->addr_str,
3693                                      headset_type) == BT_ERROR_NONE) {
3694                         ugd->connect_req = TRUE;
3695                         dev->status = BT_CONNECTING;
3696                 } else {
3697                         BT_ERR("Fail to connect Headset device");
3698                 }
3699         } else if (dev->service_list & BT_SC_A2DP_SERVICE_MASK) {
3700 #else
3701         if (dev->service_list & BT_SC_A2DP_SERVICE_MASK) {
3702 #endif
3703 #endif
3704                 if (bt_audio_connect(dev->addr_str,
3705                                      BT_AUDIO_PROFILE_TYPE_A2DP) ==
3706                     BT_ERROR_NONE) {
3707                         ugd->connect_req = TRUE;
3708                         dev->status = BT_CONNECTING;
3709                 } else {
3710                         BT_ERR("Fail to connect Headset device");
3711                 }
3712         } else if (dev->service_list & BT_SC_HID_SERVICE_MASK) {
3713                 if (TIZEN_HID) {
3714                         BT_INFO("HID connect request");
3715
3716                         if (bt_hid_host_connect(dev->addr_str) == BT_ERROR_NONE) {
3717                                 ugd->connect_req = TRUE;
3718                                 dev->status = BT_CONNECTING;
3719                         } else {
3720                                 BT_ERR("Fail to connect HID device");
3721                         }
3722                 }
3723         } else if (dev->service_list & BT_SC_NAP_SERVICE_MASK) {
3724                 void *net_profile;
3725                         if (dev->net_profile) {
3726                                 if (_bt_connect_net_profile(ugd->connection,
3727                                                             dev->net_profile,
3728                                                             dev) == BT_UG_ERROR_NONE) {
3729                                         ugd->connect_req = TRUE;
3730                                         dev->status = BT_CONNECTING;
3731                                 } else {
3732                                         BT_ERR("Fail to connect the net profile");
3733                                 }
3734                         } else {
3735                                 net_profile = _bt_get_registered_net_profile(ugd->connection,
3736                                                                    dev->bd_addr);
3737                                 if (net_profile) {
3738                                         _bt_set_profile_state_changed_cb(net_profile,
3739                                                                          dev);
3740                                         if (_bt_connect_net_profile(ugd->connection,
3741                                                                 dev->net_profile,
3742                                                                 dev) == BT_UG_ERROR_NONE) {
3743                                                 ugd->connect_req = TRUE;
3744                                                 dev->status = BT_CONNECTING;
3745                                         } else {
3746                                                 BT_ERR("Fail to connect the net profile");
3747                                         }
3748                                 }
3749                         }
3750         } else if (TIZEN_FEATURE_BT_HOG && (dev->is_le_device) && (ugd->connect_req == FALSE)) {
3751                 if (bt_gatt_connect(dev->addr_str, false) == BT_ERROR_NONE) {
3752                         ugd->connect_req = TRUE;
3753                         dev->status = BT_CONNECTING;
3754                 } else {
3755                         BT_ERR("Fail to connect le device");
3756                 }
3757         }
3758
3759         _bt_update_genlist_item((Elm_Object_Item *) dev->genlist_item);
3760
3761         FN_END;
3762 }
3763
3764 void _bt_main_disconnect_device(bt_ug_data *ugd, bt_dev_t *dev)
3765 {
3766         FN_START;
3767
3768         ret_if(ugd == NULL);
3769         ret_if(dev == NULL);
3770
3771 #ifndef TELEPHONY_DISABLED
3772         if (_bt_util_is_profile_connected(BT_HEADSET_CONNECTED,
3773                                      dev->bd_addr) == TRUE) {
3774                 BT_INFO("Disconnecting AG service");
3775                 if (bt_audio_disconnect(dev->addr_str,
3776                                         BT_AUDIO_PROFILE_TYPE_ALL) ==
3777                     BT_ERROR_NONE) {
3778                         ugd->disconn_req = true;
3779                         dev->status = BT_DISCONNECTING;
3780                 } else {
3781                         BT_ERR("Fail to connect Headset device");
3782                 }
3783         } else if (_bt_util_is_profile_connected(BT_STEREO_HEADSET_CONNECTED,
3784                  dev->bd_addr) == TRUE) {
3785 #else
3786         if (_bt_util_is_profile_connected(BT_STEREO_HEADSET_CONNECTED,
3787                  dev->bd_addr) == TRUE) {
3788 #endif
3789                 BT_INFO("Disconnecting AV service");
3790                 if (bt_audio_disconnect(dev->addr_str,
3791                                         BT_AUDIO_PROFILE_TYPE_A2DP) ==
3792                     BT_ERROR_NONE) {
3793                         ugd->disconn_req = true;
3794                         dev->status = BT_DISCONNECTING;
3795                 } else {
3796                         BT_ERR("Fail to connect Headset device");
3797                 }
3798 #ifdef TIZEN_BT_A2DP_SINK_ENABLE
3799         } else if (_bt_util_is_profile_connected(BT_MUSIC_PLAYER_CONNECTED,
3800                                 dev->bd_addr) == TRUE) {
3801                 BT_INFO("Disconnecting AV service");
3802
3803                 if (bt_audio_disconnect(dev->addr_str,
3804                                         BT_AUDIO_PROFILE_TYPE_A2DP_SINK) ==
3805                     BT_ERROR_NONE) {
3806                         ugd->disconn_req = true;
3807                         dev->status = BT_DISCONNECTING;
3808                 } else {
3809                         BT_ERR("Fail to connect Headset device");
3810                 }
3811 #endif
3812         } else if (_bt_util_is_profile_connected(BT_HID_CONNECTED,
3813                                             dev->bd_addr) == TRUE) {
3814                 BT_INFO("Disconnecting HID service!!");
3815
3816                 if (bt_hid_host_disconnect(dev->addr_str) == BT_ERROR_NONE)
3817                         dev->status = BT_DISCONNECTING;
3818                 else
3819                         BT_ERR("Fail to disconnect HID device");
3820
3821                 return;
3822          } else if (_bt_util_is_profile_connected(BT_NETWORK_SERVER_CONNECTED,
3823                                         dev->bd_addr) == TRUE) {
3824                 /* Need to check NAP server */
3825                 if (bt_nap_disconnect(dev->addr_str) == BT_UG_ERROR_NONE) {
3826                         ugd->connect_req = true;
3827                         dev->status = BT_DISCONNECTING;
3828                 } else {
3829                         BT_ERR("Failed to disconnect pan server");
3830                 }
3831          } else if (TIZEN_FEATURE_BT_HOG && dev->is_le_device) {
3832                  if (bt_gatt_disconnect(dev->addr_str) == BT_UG_ERROR_NONE) {
3833                          ugd->connect_req = true;
3834                          dev->status = BT_DISCONNECTING;
3835                  } else {
3836                          BT_ERR("Failed to disconnect gatt");
3837                  }
3838          } else {
3839                 void *net_profile;
3840                 gboolean connected = FALSE;
3841
3842                 connected = _bt_util_is_profile_connected(BT_NETWORK_CONNECTED,
3843                                                 dev->bd_addr);
3844                 if (connected) {
3845                         if (dev->net_profile) {
3846                                 if (_bt_disconnect_net_profile(ugd->connection,
3847                                                 dev->net_profile, dev) ==
3848                                                         BT_UG_ERROR_NONE) {
3849                                         ugd->connect_req = true;
3850                                         dev->status = BT_DISCONNECTING;
3851                                 } else {
3852                                         BT_ERR("Fail to disconnect the net profile");
3853                                 }
3854                         } else {
3855                                 net_profile =
3856                                         _bt_get_registered_net_profile(
3857                                                         ugd->connection,
3858                                                         dev->bd_addr);
3859                                 if (net_profile) {
3860                                         if (_bt_disconnect_net_profile(
3861                                                         ugd->connection,
3862                                                         net_profile, dev) ==
3863                                                                 BT_UG_ERROR_NONE) {
3864                                                 ugd->connect_req = true;
3865                                                 dev->status = BT_DISCONNECTING;
3866                                         } else {
3867                                                 BT_ERR("Fail to disconnect the net profile");
3868                                         }
3869                                 }
3870                         }
3871                 }
3872         }
3873
3874         _bt_update_genlist_item((Elm_Object_Item *) dev->genlist_item);
3875
3876         FN_END;
3877 }
3878
3879 int _bt_main_request_connect_with_effect(bt_ug_data *ugd,
3880                 Elm_Object_Item *seleted_item)
3881 {
3882         FN_START;
3883
3884         bt_dev_t *dev;
3885
3886         retvm_if(ugd == NULL, BT_UG_FAIL, "Invalid argument: ugd is NULL");
3887         retvm_if(seleted_item == NULL, BT_UG_FAIL,
3888                         "Invalid argument: object is NULL");
3889
3890         dev = _bt_main_get_dev_info(ugd->searched_device, seleted_item);
3891         retvm_if(dev == NULL, BT_UG_FAIL, "Invalid argument: dev is NULL");
3892
3893         if (bt_gatt_connect(dev->addr_str, false) == BT_ERROR_NONE) {
3894                 dev->status = BT_DEV_PAIRING;
3895                 ugd->op_status = BT_PAIRING;
3896                 ugd->connect_req = TRUE;
3897
3898                 elm_object_disabled_set(ugd->scan_btn, EINA_TRUE);
3899                 _bt_update_genlist_item(seleted_item);
3900         } else {
3901                 return BT_UG_FAIL;
3902         }
3903
3904         FN_END;
3905         return BT_UG_ERROR_NONE;
3906 }
3907
3908 int _bt_main_request_pairing_with_effect(bt_ug_data *ugd,
3909                                          Elm_Object_Item *seleted_item)
3910 {
3911         FN_START;
3912
3913         bt_dev_t *dev;
3914
3915         retvm_if(ugd == NULL, BT_UG_FAIL, "Invalid argument: ugd is NULL");
3916         retvm_if(seleted_item == NULL, BT_UG_FAIL,
3917                  "Invalid argument: object is NULL");
3918
3919         dev = _bt_main_get_dev_info(ugd->searched_device, seleted_item);
3920         retvm_if(dev == NULL, BT_UG_FAIL, "Invalid argument: dev is NULL");
3921
3922         if (bt_device_create_bond(dev->addr_str) == BT_ERROR_NONE) {
3923                 dev->status = BT_DEV_PAIRING;
3924                 ugd->op_status = BT_PAIRING;
3925
3926                 elm_object_disabled_set(ugd->scan_btn, EINA_TRUE);
3927                 _bt_update_genlist_item(seleted_item);
3928         } else {
3929                 return BT_UG_FAIL;
3930         }
3931
3932         FN_END;
3933         return BT_UG_ERROR_NONE;
3934 }
3935
3936 void __bt_main_parse_service(bt_ug_data *ugd, app_control_h service)
3937 {
3938         char *uri_scheme = NULL;;
3939         char *body_text = NULL;
3940         char *launch_type = NULL;
3941         char *operation = NULL;
3942         char *mime = NULL;
3943         const char *uri = NULL;
3944         const char *file_path = NULL;
3945
3946         if (TIZEN_PROFILE_TV)
3947                 return;
3948
3949         ret_if(ugd == NULL);
3950         ret_if(service == NULL);
3951
3952         if (app_control_get_operation(service, &operation) < 0)
3953                 BT_ERR("Get operation error");
3954
3955         BT_INFO("operation: %s", operation);
3956
3957         if (g_strcmp0(operation, APP_CONTROL_OPERATION_SHARE) == 0) {
3958                 char *mime = NULL;
3959
3960                 launch_type = strdup("send");
3961
3962                 app_control_get_mime(service, &mime);
3963
3964                 if (mime && strcmp(mime, APP_CONTROL_MIME_CONTACT) == 0) {
3965                         char *id_str = NULL;
3966                         app_control_get_extra_data(service, APP_CONTROL_DATA_ID, &id_str);
3967
3968                         if (id_str) {
3969                                 bool my_profile = false;
3970                                 char *data_type = NULL;
3971                                 int id = atoi(id_str);
3972
3973                                 app_control_get_extra_data(service, APP_CONTROL_DATA_TYPE, &data_type);
3974                                 my_profile = data_type && strcmp(data_type, APP_CONTROL_MY_PROFILE_DATA_TYPE) == 0;
3975                                 file_path = _bt_util_vcard_create_from_id(id, my_profile,
3976                                                                                                         BT_VCF_FOLDER_PATH);
3977
3978                                 if (file_path) {
3979                                         DBG_SECURE("file path: %s", file_path);
3980
3981                                         if (app_control_add_extra_data(service, "type", "file") < 0)
3982                                                 BT_ERR("Fail to add extra data");
3983
3984                                         if (app_control_add_extra_data_array
3985                                                 (service, "files", &file_path, 1) < 0)
3986                                                 BT_ERR("Fail to add extra data");
3987                                 }
3988
3989                                 free(data_type);
3990                                 free(id_str);
3991                         }
3992                 } else {
3993                         if (app_control_get_uri(service, (char **)&uri) < 0)
3994                                 BT_ERR("Get uri error");
3995
3996                         if (uri) {
3997                                 uri_scheme = g_uri_parse_scheme(uri);
3998                                 DBG_SECURE("uri_scheme: %s", uri_scheme);
3999
4000                                 if (uri_scheme == NULL) {
4001                                         /* File transfer */
4002                                         file_path = g_filename_from_uri(uri, NULL, NULL);
4003                                         if (app_control_add_extra_data(service, "type", "file") < 0)
4004                                                 BT_ERR("Fail to add extra data");
4005                                 } else if (g_strcmp0(uri_scheme, "file") == 0) {
4006                                         /* File transfer */
4007                                         file_path = g_filename_from_uri(uri, NULL, NULL);
4008                                         if (file_path == NULL)
4009                                                 file_path = strdup(uri + 7);    /* file:// */
4010
4011                                         if (app_control_add_extra_data(service, "type", "file") < 0)
4012                                                 BT_ERR("Fail to add extra data");
4013                                 } else {
4014                                         if (app_control_add_extra_data(service, "type", "text") < 0)
4015                                                 BT_ERR("Fail to add extra data");
4016                                 }
4017
4018                                 if (file_path == NULL) {
4019                                         BT_ERR("Not include URI info");
4020                                         file_path = strdup(uri);
4021                                 }
4022
4023                                 g_free(uri_scheme);
4024                         } else {
4025                                 char *value = NULL;
4026
4027                                 BT_INFO("url is not set");
4028                                 if (app_control_get_extra_data(service,
4029                                                 MULTI_SHARE_SERVICE_DATA_PATH, &value) < 0)
4030                                                 BT_ERR("Fail to get extra data");
4031
4032                                 if (value) {
4033                                         file_path = g_strdup(value);
4034                                         free(value);
4035
4036                                         DBG_SECURE("file_path: %s", file_path);
4037
4038                                         if (app_control_add_extra_data(service, "type", "file") < 0)
4039                                                 BT_ERR("Fail to add extra data");
4040
4041                                 } else {
4042                                         BT_ERR("Not include path info");
4043                                         goto done;
4044                                 }
4045                         }
4046
4047                         if (app_control_add_extra_data_array
4048                             (service, "files", &file_path, 1) < 0)
4049                                 BT_ERR("Fail to add extra data");
4050                 }
4051
4052                 g_free(mime);
4053         } else if (g_strcmp0(operation, APP_CONTROL_OPERATION_SHARE_TEXT) == 0) {
4054                 BT_DBG("APP_CONTROL_OPERATION_SHARE_TEXT");
4055
4056                 launch_type = strdup("send");
4057
4058                 if (app_control_get_uri(service, (char **)&uri) < 0)
4059                         BT_ERR("Get uri error");
4060
4061                 if (uri == NULL) {
4062                         if (app_control_get_extra_data(service,
4063                                                    APP_CONTROL_DATA_TEXT,
4064                                                    &body_text) !=
4065                             APP_CONTROL_ERROR_NONE) {
4066                                 BT_ERR("Get uri error");
4067                         }
4068
4069                         if (body_text == NULL) {
4070                                 goto done;
4071                         } else {
4072                                 file_path = g_strdup(body_text);
4073                                 free(body_text);
4074                         }
4075                 } else {
4076                         file_path = g_strdup(uri);
4077                 }
4078
4079                 if (file_path == NULL) {
4080                         BT_ERR("file path is NULL");
4081                         goto done;
4082                 }
4083
4084                 if (app_control_add_extra_data(service, "type", "text") < 0)
4085                         BT_ERR("Fail to add extra data");
4086
4087                 if (app_control_add_extra_data_array
4088                     (service, "files", &file_path, 1) < 0)
4089                         BT_ERR("Fail to add extra data");
4090
4091         } else if (g_strcmp0(operation, APP_CONTROL_OPERATION_MULTI_SHARE) == 0) {
4092                 char **array_value = NULL;
4093                 int array_length;
4094                 int ret, i;
4095                 char *mime = NULL;
4096
4097                 launch_type = strdup("send");
4098
4099                 int *id_list = NULL;
4100                 char **person_id = NULL;
4101                 int person_id_size = 0;
4102                 bool cancel = false;
4103
4104                 app_control_get_mime(service, &mime);
4105
4106                 if (mime && !strcmp(mime, APP_CONTROL_MIME_CONTACT)) {
4107                         if (app_control_get_extra_data_array(service, APP_CONTROL_DATA_ID,
4108                                         &person_id, &person_id_size) == APP_CONTROL_ERROR_NONE && person_id) {
4109                                 int i = 0;
4110                                 id_list = calloc(person_id_size, sizeof(int));
4111                                 if (id_list) {
4112                                         for (i = 0; i < person_id_size; i++)
4113                                                 id_list[i] = atoi(person_id[i]);
4114
4115                                         file_path = _bt_util_vcard_create_from_id_list(id_list,
4116                                                                 person_id_size, BT_VCF_FOLDER_PATH, &cancel);
4117                                         if (file_path) {
4118                                                 DBG_SECURE("file path: %s", file_path);
4119
4120                                                 if (app_control_add_extra_data(service, "type", "file") < 0)
4121                                                         BT_ERR("Fail to add extra data");
4122
4123                                                 if (app_control_add_extra_data_array
4124                                                         (service, "files", &file_path, 1) < 0)
4125                                                         BT_ERR("Fail to add extra data");
4126                                         }
4127                                 free(id_list);
4128                                 }
4129                         }
4130                         g_free(person_id);
4131                 } else {
4132                         ret = app_control_get_extra_data_array(service,
4133                                                            MULTI_SHARE_SERVICE_DATA_PATH,
4134                                                            &array_value, &array_length);
4135                         if (ret != APP_CONTROL_ERROR_NONE) {
4136                                 BT_ERR("Get data error");
4137                                 if (array_value) {
4138                                         for (i = 0; i < array_length; i++) {
4139                                                 if (array_value[i])
4140                                                         free(array_value[i]);
4141                                         }
4142                                         free(array_value);
4143                                 }
4144                                 goto done;
4145                         }
4146
4147                         if (app_control_add_extra_data_array
4148                             (service, "files", (const char **)array_value,
4149                              array_length) < 0)
4150                                 BT_ERR("Fail to add extra data");
4151
4152                         if (app_control_add_extra_data(service, "type", "file") < 0)
4153                                 BT_ERR("Fail to add extra data");
4154                         if (array_value) {
4155                                 for (i = 0; i < array_length; i++) {
4156                                         if (array_value[i])
4157                                                 free(array_value[i]);
4158                                 }
4159                                 free(array_value);
4160                         }
4161                 }
4162
4163                 g_free(mime);
4164         } else if (g_strcmp0(operation, BT_APPCONTROL_PICK_OPERATION) == 0) {
4165                 BT_DBG("Pick Operation");
4166                 launch_type = strdup("pick");
4167         } else if (g_strcmp0(operation, BT_APPCONTROL_VISIBILITY_OPERATION) == 0 ||
4168                                  g_strcmp0(operation, APP_CONTROL_OPERATION_SETTING_BT_VISIBILITY) == 0) {
4169                 BT_DBG("Visibility Operation");
4170                 launch_type = strdup("visibility");
4171         } else if (g_strcmp0(operation, BT_APPCONTROL_ONOFF_OPERATION) == 0 ||
4172                                  g_strcmp0(operation, APP_CONTROL_OPERATION_SETTING_BT_ENABLE) == 0) {
4173                 BT_DBG("onoff Operation");
4174                 launch_type = strdup("onoff");
4175         } else if (g_strcmp0(operation, APP_CONTROL_OPERATION_SHARE_CONTACT) == 0) {
4176                 BT_DBG("Share Contact Operation");
4177                 launch_type = strdup("contact");
4178         } else if (g_strcmp0(operation, BT_APPCONTROL_EDIT_OPERATION) == 0) {
4179                 BT_DBG("Edit Operation");
4180                 if (app_control_get_mime(service, &mime) < 0)
4181                         BT_ERR("Get mime error");
4182                 if (g_strcmp0(mime, BT_APPCONTROL_ONOFF_MIME) == 0)
4183                         launch_type = strdup("onoff");
4184                 else if (g_strcmp0(mime, BT_APPCONTROL_VISIBILITY_MIME) == 0)
4185                         launch_type = strdup("visibility");
4186         } else if (app_control_get_extra_data(service, "launch-type",
4187                                           &launch_type) == APP_CONTROL_ERROR_NONE) {
4188                 if (g_strcmp0(launch_type, "call") != 0) {
4189                         BT_DBG("launch-type : except call");
4190                         if (app_control_add_extra_data(service, "type", "file") < 0)
4191                                 BT_ERR("Fail to add extra data");
4192                 } else {
4193                         BT_DBG("launch-type : call");
4194                 }
4195         } else if (app_control_get_uri(service, (char **)&uri) == APP_CONTROL_ERROR_NONE &&
4196                         g_strcmp0(uri, HELP_SETUP_BLUETOOTH_URI) == 0) {
4197                 BT_DBG("Help mode");
4198                 launch_type = strdup("help");
4199         }
4200
4201  done:
4202         if (launch_type) {
4203                 BT_INFO("Launch with launch type [%s]", launch_type);
4204                 _bt_util_set_value(launch_type, &ugd->search_type,
4205                                    &ugd->bt_launch_mode);
4206         } else {
4207                 BT_DBG("launch type is NULL");
4208         }
4209
4210         if (uri)
4211                 free((void *)uri);
4212
4213         if (file_path)
4214                 free((void *)file_path);
4215
4216         if (launch_type)
4217                 free((void *)launch_type);
4218
4219         if (operation)
4220                 free(operation);
4221
4222         if (mime)
4223                 free(mime);
4224 }
4225
4226 void _bt_main_init_status(bt_ug_data *ugd, void *data)
4227 {
4228         FN_START;
4229
4230         app_control_h service = NULL;
4231         int ret;
4232         bool status = false;
4233         bt_adapter_state_e bt_state = BT_ADAPTER_DISABLED;
4234         ret_if(ugd == NULL);
4235
4236         service = data;
4237
4238         if (service != NULL) {
4239                 __bt_main_parse_service(ugd, service);
4240         } else {
4241                 ugd->search_type = MISCELLANEOUS_MAJOR_DEVICE_MASK;
4242                 ugd->bt_launch_mode = BT_LAUNCH_NORMAL;
4243         }
4244
4245         /* currently this is the workaround for relaunching bt-ug by s-finder.
4246         bt-ug is not properly working because of the previous initialization.
4247         If there was no bt-ug then this deinit code doesn't affect at all.*/
4248         bt_deinitialize();
4249
4250         if (bt_initialize() != BT_ERROR_NONE)
4251                 BT_ERR("bt_initialize() failed");
4252
4253         ret = _bt_util_create_dpm_context(ugd);
4254         if (ret != BT_UG_ERROR_NONE)
4255                 BT_ERR("_bt_util_create_dpm_context failed: %d", ret);
4256
4257         if (bt_adapter_get_state(&bt_state) != BT_ERROR_NONE)
4258                 BT_ERR("bt_adapter_get_state() failed");
4259
4260         if (bt_state == BT_ADAPTER_DISABLED) {
4261                 ugd->op_status = BT_DEACTIVATED;
4262         } else {
4263                 if (bt_adapter_is_discovering(&status) != BT_ERROR_NONE)
4264                 BT_ERR("bt_adapter_is_discovering() failed");
4265
4266                 if (status == true)
4267                         bt_adapter_stop_device_discovery();
4268
4269                 ugd->op_status = BT_ACTIVATED;
4270         }
4271
4272         FN_END;
4273 }
4274
4275 bt_dev_t *_bt_main_create_paired_device_item(void *data)
4276 {
4277         FN_START;
4278
4279         int i;
4280         unsigned char bd_addr[BT_ADDRESS_LENGTH_MAX];
4281         bt_dev_t *dev = NULL;
4282         bt_device_info_s *dev_info = NULL;
4283
4284         retv_if(data == NULL, NULL);
4285
4286         dev_info = (bt_device_info_s *)data;
4287
4288         retv_if(!dev_info->remote_name || strlen(dev_info->remote_name) == 0, NULL);
4289         retv_if(!dev_info->remote_address || strlen(dev_info->remote_address) == 0, NULL);
4290
4291         dev = malloc(sizeof(bt_dev_t));
4292         retv_if(dev == NULL, NULL);
4293
4294         memset(dev, 0, sizeof(bt_dev_t));
4295         g_strlcpy(dev->name, dev_info->remote_name,
4296                   DEVICE_NAME_MAX_LEN + 1);
4297
4298         dev->major_class = dev_info->bt_class.major_device_class;
4299         dev->minor_class = dev_info->bt_class.minor_device_class;
4300         dev->service_class = dev_info->bt_class.major_service_class_mask;
4301
4302         if (dev_info->service_uuid != NULL && dev_info->service_count > 0) {
4303                 dev->uuids = g_new0(char *, dev_info->service_count + 1);
4304
4305                 for (i = 0; i < dev_info->service_count; i++)
4306                         dev->uuids[i] = g_strdup(dev_info->service_uuid[i]);
4307
4308                 dev->uuid_count = dev_info->service_count;
4309         }
4310
4311         _bt_util_addr_string_to_addr_type(bd_addr, dev_info->remote_address);
4312
4313         memcpy(dev->addr_str, dev_info->remote_address, BT_ADDRESS_STR_LEN);
4314
4315         memcpy(dev->bd_addr, bd_addr, BT_ADDRESS_LENGTH_MAX);
4316
4317         bt_device_get_service_mask_from_uuid_list(dev_info->service_uuid,
4318                                                  dev_info->service_count,
4319                                                  &dev->service_list);
4320
4321         BT_DBG("device name [%s]", dev->name);
4322         BT_DBG("device major class [%x]", dev->major_class);
4323         BT_DBG("device minor class [%x]", dev->minor_class);
4324         BT_DBG("device service class [%x]", dev->service_class);
4325         BT_DBG("device service list %x", dev->service_list);
4326         BT_DBG("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X", dev->bd_addr[0],
4327                dev->bd_addr[1], dev->bd_addr[2], dev->bd_addr[3],
4328                dev->bd_addr[4], dev->bd_addr[5]);
4329
4330         if (dev->major_class == BT_MAJOR_DEV_CLS_MISC &&
4331                 dev->service_list != BT_SC_NONE) {
4332                 _bt_util_update_class_of_device_by_service_list(dev->service_list,
4333                                                  &dev->major_class, &dev->minor_class);
4334         }
4335
4336         /* TODO : modify for checking LE device */
4337         if (TIZEN_FEATURE_BT_HOG && (dev->major_class == 0) && (dev->minor_class == 0)) {
4338                 BT_DBG("there are no major and minor class");
4339                 dev->is_le_device = TRUE;
4340         }
4341
4342         FN_END;
4343         return dev;
4344 }
4345
4346 bt_dev_t *_bt_main_create_searched_device_item(void *data)
4347 {
4348         FN_START;
4349
4350         int i;
4351         unsigned char bd_addr[BT_ADDRESS_LENGTH_MAX];
4352         bt_dev_t *dev = NULL;
4353         bt_adapter_device_discovery_info_s *dev_info = NULL;
4354
4355         retv_if(data == NULL, NULL);
4356
4357         dev_info = (bt_adapter_device_discovery_info_s *) data;
4358
4359         if (strlen(dev_info->remote_name) == 0)
4360                 return NULL;
4361
4362         dev = calloc(1, sizeof(bt_dev_t));
4363         retv_if(dev == NULL, NULL);
4364
4365         strncpy(dev->name, dev_info->remote_name, DEVICE_NAME_MAX_LEN);
4366
4367         dev->major_class = dev_info->bt_class.major_device_class;
4368         dev->minor_class = dev_info->bt_class.minor_device_class;
4369         dev->service_class = dev_info->bt_class.major_service_class_mask;
4370         dev->rssi = dev_info->rssi;
4371         if (TIZEN_FEATURE_BT_HOG)
4372                 dev->is_le_device = FALSE;
4373
4374         if (dev_info->service_uuid != NULL && dev_info->service_count > 0) {
4375                 dev->uuids = g_new0(char *, dev_info->service_count + 1);
4376
4377                 for (i = 0; i < dev_info->service_count; i++)
4378                         dev->uuids[i] = g_strdup(dev_info->service_uuid[i]);
4379
4380                 dev->uuid_count = dev_info->service_count;
4381         }
4382
4383         _bt_util_addr_string_to_addr_type(bd_addr, dev_info->remote_address);
4384
4385         memcpy(dev->addr_str, dev_info->remote_address, BT_ADDRESS_STR_LEN);
4386
4387         memcpy(dev->bd_addr, bd_addr, BT_ADDRESS_LENGTH_MAX);
4388
4389         BT_DBG("device name [%s]", dev->name);
4390         BT_DBG("device major class [%x]", dev->major_class);
4391         BT_DBG("device minor class [%x]", dev->minor_class);
4392         BT_DBG("device service class [%x]", dev->service_class);
4393         BT_DBG("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X", dev->bd_addr[0],
4394                dev->bd_addr[1], dev->bd_addr[2], dev->bd_addr[3],
4395                dev->bd_addr[4], dev->bd_addr[5]);
4396
4397         FN_END;
4398         return dev;
4399 }
4400 static gboolean _bt_check_minor_class(unsigned int minor_class)
4401 {
4402         switch (minor_class) {
4403         case BTAPP_MIN_DEV_CLS_VIDEO_DISPLAY_AND_LOUD_SPEAKER:
4404                 return FALSE;
4405         case BTAPP_MIN_DEV_CLS_VIDEO_CONFERENCING:
4406                 return FALSE;
4407         case BTAPP_MIN_DEV_CLS_VIDEO_CAMERA:
4408                 return FALSE;
4409         case BTAPP_MIN_DEV_CLS_SET_TOP_BOX:
4410                 return FALSE;
4411         case BTAPP_MIN_DEV_CLS_VCR:
4412                 return FALSE;
4413         case BTAPP_MIN_DEV_CLS_CAM_CORDER:
4414                 return FALSE;
4415         default:
4416                 return TRUE;
4417         }
4418 }
4419
4420 gboolean _bt_main_is_matched_profile(unsigned int search_type,
4421                                      unsigned int major_class,
4422                                      unsigned int service_class,
4423                                      app_control_h service,
4424                                      unsigned int minor_class)
4425 {
4426         FN_START;
4427
4428         bt_device_major_mask_t major_mask = BT_DEVICE_MAJOR_MASK_MISC;
4429
4430         if (!TIZEN_HID) {
4431                 /* P141010-03829 : Kiran doesn't support HID device */
4432                 BT_DBG("Kiran doesn't support HID device");
4433                 retv_if(major_class == BT_MAJOR_DEV_CLS_PERIPHERAL, FALSE);
4434         }
4435
4436         if (search_type == 0x000000)
4437                 return TRUE;
4438
4439         BT_INFO("search_type: %x", search_type);
4440         BT_INFO("service_class: %x", service_class);
4441
4442         /* Check the service_class */
4443         if (service_class & search_type) {
4444                 if (search_type & OBJECT_TRANSFER_MAJOR_SERVICE_MASK &&
4445                     major_class == BT_MAJOR_DEV_CLS_IMAGING) {
4446                         if (__bt_main_is_image_file(service))
4447                                 return TRUE;
4448                 } else {
4449                         return TRUE;
4450                 }
4451         }
4452         BT_INFO("major_class %x", major_class);
4453         BT_INFO("minor_class %x", minor_class);
4454         /* Check the major class */
4455         switch (major_class) {
4456         case BT_MAJOR_DEV_CLS_COMPUTER:
4457                 major_mask = BT_DEVICE_MAJOR_MASK_COMPUTER;
4458                 break;
4459         case BT_MAJOR_DEV_CLS_PHONE:
4460                 major_mask = BT_DEVICE_MAJOR_MASK_PHONE;
4461                 break;
4462         case BT_MAJOR_DEV_CLS_LAN_ACCESS_POINT:
4463                 major_mask = BT_DEVICE_MAJOR_MASK_LAN_ACCESS_POINT;
4464                 break;
4465         case BT_MAJOR_DEV_CLS_AUDIO:
4466                 if (_bt_check_minor_class(minor_class) == TRUE)
4467                         major_mask = BT_DEVICE_MAJOR_MASK_AUDIO;
4468                 else
4469                         major_mask = BT_DEVICE_MAJOR_MASK_MISC;
4470                 break;
4471         case BT_MAJOR_DEV_CLS_IMAGING:
4472                 major_mask = BT_DEVICE_MAJOR_MASK_IMAGING;
4473                 break;
4474         case BT_MAJOR_DEV_CLS_WEARABLE:
4475                 major_mask = BT_DEVICE_MAJOR_MASK_WEARABLE;
4476                 break;
4477         case BT_MAJOR_DEV_CLS_TOY:
4478                 major_mask = BT_DEVICE_MAJOR_MASK_TOY;
4479                 break;
4480         case BT_MAJOR_DEV_CLS_HEALTH:
4481                 major_mask = BT_DEVICE_MAJOR_MASK_HEALTH;
4482                 break;
4483         case BT_MAJOR_DEV_CLS_PERIPHERAL:
4484                 if (TIZEN_HID) {
4485                         major_mask = BT_DEVICE_MAJOR_MASK_PERIPHERAL;
4486                         break;
4487                 } /* If not, goto default */
4488         default:
4489                 major_mask = BT_DEVICE_MAJOR_MASK_MISC;
4490                 break;
4491         }
4492
4493         BT_INFO("major_mask: %x", major_mask);
4494
4495         if (search_type & major_mask)
4496                 return TRUE;
4497
4498         FN_END;
4499         return FALSE;
4500 }
4501
4502 bt_dev_t *_bt_main_get_dev_info(Eina_List *list,
4503                                 Elm_Object_Item *genlist_item)
4504 {
4505         FN_START;
4506
4507         bt_dev_t *item = NULL;
4508         Eina_List *l = NULL;
4509
4510         retvm_if(list == NULL, NULL, "Invalid argument: list is NULL");
4511         retvm_if(genlist_item == NULL, NULL, "Invalid argument: obj is NULL");
4512
4513         EINA_LIST_FOREACH(list, l, item) {
4514                 if (item) {
4515                         if (item->genlist_item == genlist_item)
4516                                 return item;
4517                 }
4518         }
4519
4520         FN_END;
4521         return NULL;
4522 }
4523
4524 bt_dev_t *_bt_main_get_dev_info_by_address(Eina_List *list, char *address)
4525 {
4526         FN_START;
4527
4528         bt_dev_t *item = NULL;
4529         Eina_List *l = NULL;
4530
4531         retvm_if(list == NULL, NULL, "Invalid argument: list is NULL");
4532         retvm_if(address == NULL, NULL, "Invalid argument: addr is NULL");
4533
4534         EINA_LIST_FOREACH(list, l, item) {
4535                 if (item) {
4536                         if (memcmp(item->addr_str, address, BT_ADDRESS_STR_LEN)
4537                             == 0)
4538                                 return item;
4539                 }
4540         }
4541
4542         FN_END;
4543         return NULL;
4544 }
4545
4546 int _bt_main_check_and_update_device(Eina_List *list, char *addr, char *name)
4547 {
4548         FN_START;
4549
4550         bt_dev_t *item = NULL;
4551         Eina_List *l = NULL;
4552
4553         retv_if(list == NULL, -1);
4554         retv_if(addr == NULL, -1);
4555         retv_if(name == NULL, -1);
4556
4557         EINA_LIST_FOREACH(list, l, item) {
4558                 if (item) {
4559                         if (memcmp(item->addr_str, addr, BT_ADDRESS_STR_LEN) ==
4560                             0) {
4561                                 memset(item->name, 0x00,
4562                                        DEVICE_NAME_MAX_LEN+1);
4563                                 g_strlcpy(item->name, name,
4564                                           DEVICE_NAME_MAX_LEN);
4565                                 return 0;
4566                         }
4567                 }
4568         }
4569
4570         FN_END;
4571
4572         return -1;
4573 }
4574
4575 void _bt_main_launch_syspopup(void *data, char *event_type, char *title,
4576                               char *type)
4577 {
4578         FN_START;
4579
4580         int ret = 0;
4581         bt_ug_data *ugd = NULL;
4582         bundle *b = NULL;
4583
4584         ret_if(event_type == NULL);
4585         ret_if(type == NULL);
4586
4587         ugd = (bt_ug_data *)data;
4588
4589         b = bundle_create();
4590         ret_if(b == NULL);
4591
4592         if (event_type)
4593                 bundle_add_str(b, "event-type", event_type);
4594         if (title)
4595                 bundle_add_str(b, "title", title);
4596         if (type)
4597                 bundle_add_str(b, "type", type);
4598
4599         ret = syspopup_launch("bt-syspopup", b);
4600         if (0 > ret) {
4601                 BT_ERR("Popup launch failed...retry %d", ret);
4602                 ugd->popup_bundle = b;
4603                 ugd->popup_timer =
4604                     g_timeout_add(BT_UG_SYSPOPUP_TIMEOUT_FOR_MULTIPLE_POPUPS,
4605                                   (GSourceFunc) __bt_main_system_popup_timer_cb,
4606                                   ugd);
4607         } else {
4608                 bundle_free(b);
4609         }
4610         FN_END;
4611 }
4612
4613 void _bt_main_create_information_popup(void *data, char *msg)
4614 {
4615         FN_START;
4616         ret_if(data == NULL);
4617         bt_ug_data *ugd = (bt_ug_data *)data;
4618
4619         _bt_main_popup_del_cb(data, NULL, NULL);
4620
4621         ugd->popup_data.type = BT_POPUP_LOW_BATTERY;
4622         ugd->popup = _bt_create_popup(ugd,
4623                 _bt_main_popup_del_cb, ugd, 2);
4624         retm_if(!ugd->popup , "fail to create popup!");
4625
4626         eext_object_event_callback_add(ugd->popup, EEXT_CALLBACK_BACK,
4627                         _bt_main_popup_del_cb, ugd);
4628
4629         evas_object_show(ugd->popup);
4630         FN_END;
4631 }
4632
4633 #ifdef TIZEN_REDWOOD
4634 static gboolean __bt_main_close_help_popup_cb(gpointer data)
4635 {
4636         FN_START;
4637         retv_if(!data, FALSE);
4638         bt_ug_data *ugd = (bt_ug_data *)data;
4639
4640         if (ugd->popup) {
4641                 evas_object_del(ugd->popup);
4642                 ugd->popup = NULL;
4643         }
4644
4645         _bt_ug_destroy(data, NULL);
4646
4647         FN_END;
4648         return FALSE;
4649 }
4650 #endif
4651
4652 void _bt_main_add_searched_title(bt_ug_data *ugd)
4653 {
4654         FN_START;
4655         Elm_Object_Item *git = NULL;
4656
4657         git = elm_genlist_item_append(ugd->main_genlist,
4658                                         ugd->searched_title_itc,
4659                                         (void *)ugd, NULL,
4660                                         ELM_GENLIST_ITEM_NONE, NULL, NULL);
4661         if (git) {
4662                 elm_genlist_item_select_mode_set(git,
4663                                          ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
4664                 ugd->searched_title = git;
4665         } else {
4666                 BT_ERR("fail to append genlist item!");
4667         }
4668
4669         FN_END;
4670 }
4671
4672 void _bt_update_device_list(bt_ug_data *ugd)
4673 {
4674         Eina_List *l = NULL;
4675         bt_dev_t *dev = NULL;
4676
4677         ret_if(ugd == NULL);
4678
4679         EINA_LIST_FOREACH(ugd->paired_device, l, dev) {
4680                 if (dev)
4681                         _bt_update_genlist_item((Elm_Object_Item *)
4682                                                 dev->genlist_item);
4683         }
4684
4685         EINA_LIST_FOREACH(ugd->searched_device, l, dev) {
4686                 if (dev)
4687                         _bt_update_genlist_item((Elm_Object_Item *)
4688                                                 dev->genlist_item);
4689         }
4690 }