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