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