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