Fix the build error for emulator
[apps/native/ug-bluetooth-efl.git] / emulator / 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-debug.h"
41 #include "bt-util.h"
42 #include "bt-callback.h"
43 #include "bt-widget.h"
44 #include "bt-resource.h"
45 #include "bt-emulator-api.h"
46 #include "bluetooth_internal.h"
47 #include "syspopup_caller.h"
48
49 #define MULTI_SHARE_SERVICE_DATA_PATH "http://tizen.org/appcontrol/data/path"
50 #define APP_CONTROL_OPERATION_SHARE_CONTACT "http://tizen.org/appcontrol/operation/share_contact"
51 #define SERVICE_SHARE_CONTACT_MODE "http://tizen.org/appcontrol/data/social/namecard_share_mode"
52 #define SERVICE_SHARE_CONTACT_ITEM "http://tizen.org/appcontrol/data/social/item_type"
53 #define SHARE_CONTACT_DATA_PATH "/opt/usr/media/Downloads/.bluetooth"
54 #define SHARE_CONTACT_ITEM_ID_ARRAY "http://tizen.org/appcontrol/data/social/item_id"
55 #define SHARE_CONTACT_ITEM_SHARE_MODE "http://tizen.org/appcontrol/data/social/namecard_share_mode"
56 #define HELP_SETUP_BLUETOOTH_URI                "tizen-help://ug-bluetooth-efl/setupbluetooth"
57
58 /**********************************************************************
59 *                                      Static Functions declaration
60 ***********************************************************************/
61
62 static void __bt_main_onoff_btn_cb(void *data, Evas_Object *obj, void *event_info);
63
64 static app_control_h __bt_main_get_bt_onoff_result(bt_ug_data *ugd,
65                                                 gboolean result);
66
67 /**********************************************************************
68 *                                               Static Functions
69 ***********************************************************************/
70
71 static char *__bt_main_onoff_label_get(void *data, Evas_Object *obj,
72                                                                 const char *part)
73 {
74         FN_START;
75         bt_ug_data *ugd = NULL;
76
77         retv_if(data == NULL, NULL);
78         ugd = (bt_ug_data *)data;
79
80         if (!strcmp("elm.text", part)) {
81                 return g_strdup(BT_STR_BLUETOOTH);
82         } else if (!strcmp("elm.text.multiline", part)) {
83                 char buf[1024] = {0,};
84                 if (ugd->op_status == BT_ACTIVATING) {
85                         snprintf(buf, sizeof(buf), "<font_size=30>%s</font_size>", BT_STR_TURNING_ON_BLUETOOTH);
86                         return g_strdup(buf);
87                 } else if (ugd->op_status == BT_DEACTIVATED) {
88                         snprintf(buf, sizeof(buf), "<font_size=30>%s</font_size>", BT_STR_TURN_ON_BLUETOOTH_TO_SEE_A_LIST_OF_AVAILABLE_DEVICES);
89                         return g_strdup(buf);
90                 }
91         }
92
93         FN_END;
94         return NULL;
95 }
96
97 static Evas_Object *__bt_main_onoff_icon_get(void *data, Evas_Object *obj,
98                                                 const char *part)
99 {
100         FN_START;
101
102         bt_ug_data *ugd = NULL;
103         Evas_Object *btn = NULL;
104         bool activated = false;
105
106         retv_if(data == NULL, NULL);
107
108         ugd = (bt_ug_data *)data;
109
110         if (!strcmp("elm.swallow.end", part)) {
111                 if (ugd->op_status == BT_ACTIVATING
112                         || ugd->op_status == BT_DEACTIVATING) {
113                         btn = elm_progressbar_add(obj);
114                         elm_object_style_set(btn, "process_medium");
115                         evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, 0.5);
116                         evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
117                         elm_progressbar_pulse(btn, TRUE);
118                 } else {
119                         activated = ((ugd->op_status == BT_DEACTIVATED) ||
120                                 (ugd->op_status == BT_ACTIVATING)) ? false : true;
121                         btn = elm_check_add(obj);
122                         elm_object_style_set(btn, "on&off");
123                         evas_object_pass_events_set(btn, EINA_TRUE);
124                         evas_object_propagate_events_set(btn, EINA_FALSE);
125                         elm_check_state_set(btn, activated);
126
127                         /* add smart callback */
128                         evas_object_smart_callback_add(btn, "changed",
129                                 __bt_main_onoff_btn_cb, ugd);
130
131                         ugd->onoff_btn = btn;
132                 }
133
134                 evas_object_show(btn);
135         }
136
137         FN_END;
138         return btn;
139 }
140
141 static char *__bt_main_rename_desc_label_get(void *data, Evas_Object *obj,
142                                               const char *part)
143 {
144         FN_START;
145
146         if (!strcmp("elm.text.multiline", part)) {
147                 char buf[1024] = {0,};
148                 snprintf(buf, sizeof(buf), "<font_size=30>%s</font_size>",
149                                 BT_STR_RENAME_DEVICE_LABEL);
150                 return g_strdup(buf);
151         }
152
153         FN_END;
154         return NULL;
155 }
156
157 static char *__bt_main_device_label_get(void *data, Evas_Object *obj,
158                                               const char *part)
159 {
160         FN_START;
161
162         bt_ug_data *ugd = NULL;
163         char buf[BT_GLOBALIZATION_STR_LENGTH] = { 0, };
164         char *dev_name = NULL;
165         char *ptr = NULL;
166         retv_if(data == NULL, NULL);
167
168         ugd = (bt_ug_data *)data;
169         BT_DBG("part : %s", part);
170
171         if (!strcmp("elm.text", part)) {
172                 memset(ugd->phone_name, 0x00, BT_GLOBALIZATION_STR_LENGTH);
173
174                 _bt_util_get_phone_name(ugd->phone_name, sizeof(ugd->phone_name));
175
176                 if (strlen(ugd->phone_name) == 0) {
177                         if (bt_emulator_get_name(&dev_name) == BT_ERROR_NONE) {
178                                 g_strlcpy(ugd->phone_name, dev_name,
179                                           BT_GLOBALIZATION_STR_LENGTH);
180                                 g_free(dev_name);
181                         }
182                 }
183
184                 BT_DBG("ugd->phone_name : %s[%d]", ugd->phone_name, strlen(ugd->phone_name));
185                 /* Check the utf8 valitation & Fill the NULL in the invalid location */
186                 if (!g_utf8_validate(ugd->phone_name, -1, (const char **)&ptr))
187                         *ptr = '\0';
188
189                 dev_name = elm_entry_utf8_to_markup(ugd->phone_name);
190                 if (dev_name) {
191                         g_strlcpy(buf, dev_name, BT_GLOBALIZATION_STR_LENGTH);
192                         g_free(dev_name);
193                 } else
194                         g_strlcpy(buf, ugd->phone_name, BT_GLOBALIZATION_STR_LENGTH);
195
196                 FN_END;
197                 BT_DBG("buf : %s[%d]", buf, strlen(buf));
198                 return strdup(buf);
199         } else if (!strcmp("elm.text.sub", part)) {
200                 g_strlcpy(buf, BT_STR_MY_DEVICE,
201                           BT_GLOBALIZATION_STR_LENGTH);
202                 FN_END;
203                 return strdup(buf);
204         } else {
205                 BT_ERR("This part name is not exist in style.");
206                 return NULL;
207         }
208 }
209
210 char* __bt_convert_rgba_to_hex(int r, int g, int b, int a)
211 {
212         int hexcolor = 0;
213         char* string = NULL;
214
215         string = g_try_malloc0(sizeof(char) * 255);
216         /* Fix : NULL_RETURNS */
217         if (string == NULL)
218                 return NULL;
219
220         hexcolor = (r << 24) + (g << 16) + (b << 8) + a;
221         sprintf(string, "%08x", hexcolor);
222
223         return string;
224 }
225
226 int _bt_idle_destroy_ug(void *data)
227 {
228         FN_START;
229
230         bt_ug_data *ugd = data;
231         app_control_h service = NULL;
232
233         retv_if(ugd == NULL, BT_UG_FAIL);
234
235         _bt_ug_destroy(data, (void *)service);
236
237         if (service)
238                 app_control_destroy(service);
239
240         FN_END;
241         return BT_UG_ERROR_NONE;
242 }
243
244 static void __bt_rename_device_entry_changed_cb(void *data, Evas_Object *obj,
245                                 void *event_info)
246 {
247         FN_START;
248         ret_if(obj == NULL);
249         ret_if(data == NULL);
250         bt_ug_data *ugd = NULL;
251
252         ugd = (bt_ug_data *)data;
253
254         const char *entry_text = NULL;
255         char *input_str = NULL;
256
257         if (ugd->rename_entry != obj)
258                 ugd->rename_entry = obj;
259         entry_text = elm_entry_entry_get(obj);
260         input_str = elm_entry_markup_to_utf8(entry_text);
261
262         if (input_str == NULL || strlen(input_str) == 0 ||
263                                 _bt_util_is_space_str(input_str)) {
264                 BT_DBG("");
265                 elm_object_disabled_set(ugd->rename_button, EINA_TRUE);
266                 elm_entry_input_panel_return_key_disabled_set(
267                                 obj, EINA_TRUE);
268         } else {
269                 BT_DBG("");
270                 if (elm_object_disabled_get(ugd->rename_button))
271                         elm_object_disabled_set(ugd->rename_button, EINA_FALSE);
272                 if (elm_entry_input_panel_return_key_disabled_get(obj))
273                         elm_entry_input_panel_return_key_disabled_set(obj, EINA_FALSE);
274         }
275         if (input_str != NULL) {
276                 free(input_str);
277                 input_str = NULL;
278         }
279
280         FN_END;
281 }
282
283 static void __bt_rename_device_cancel_cb(void *data, Evas_Object *obj,
284                                 void *event_info)
285 {
286         FN_START;
287         bt_ug_data *ugd = NULL;
288
289         ret_if(data == NULL);
290         ugd = (bt_ug_data *)data;
291
292         if (ugd->rename_entry) {
293                 elm_entry_input_panel_hide(ugd->rename_entry);
294                 elm_object_focus_set(ugd->rename_entry, EINA_FALSE);
295         }
296
297         if (ugd->rename_popup != NULL) {
298                 evas_object_del(ugd->rename_popup);
299                 ugd->rename_popup = NULL;
300                 ugd->rename_entry_item = NULL;
301                 ugd->rename_entry = NULL;
302         }
303
304         FN_END;
305 }
306
307 static void __bt_rename_device_ok_cb(void *data, Evas_Object *obj,
308                                 void *event_info)
309 {
310         FN_START;
311         bt_ug_data *ugd = (bt_ug_data *) data;
312
313         const char *entry_str = elm_entry_entry_get(ugd->rename_entry);
314         char *device_name_str = NULL;
315         device_name_str = elm_entry_markup_to_utf8(entry_str);
316         ret_if(!device_name_str);
317         BT_DBG("Device name:[%s]", device_name_str);
318
319         if (0 != vconf_set_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR, device_name_str))
320                 BT_ERR("Set vconf[%s] failed", VCONFKEY_SETAPPL_DEVICE_NAME_STR);
321
322         _bt_update_genlist_item(ugd->device_name_item);
323
324         if (ugd->rename_entry) {
325                 elm_entry_input_panel_hide(ugd->rename_entry);
326                 elm_object_focus_set(ugd->rename_entry, EINA_FALSE);
327         }
328
329         evas_object_del(ugd->rename_popup);
330         ugd->rename_popup = NULL;
331         ugd->rename_entry_item = NULL;
332         ugd->rename_entry = NULL;
333         g_free(device_name_str);
334
335         FN_END;
336 }
337
338 static void __bt_rename_entry_changed_cb(void *data, Evas_Object *obj,
339                                 void *event_info)
340 {
341         FN_START;
342         ret_if(!data);
343         bt_ug_data *ugd = (bt_ug_data *) data;
344         ret_if(!ugd->rename_entry_item);
345
346         if (elm_object_part_content_get(obj, "elm.icon.eraser")) {
347                 if (elm_object_focus_get(obj)) {
348                         if (elm_entry_is_empty(obj)) {
349                                 elm_object_item_signal_emit(ugd->rename_entry_item,
350                                         "elm,state,eraser,hide", "");
351                         } else {
352                                 elm_object_item_signal_emit(ugd->rename_entry_item,
353                                         "elm,state,eraser,show", "");
354                         }
355                 }
356         }
357         __bt_rename_device_entry_changed_cb(data, obj, event_info);
358
359         FN_END;
360 }
361
362 static void __bt_main_entry_edit_mode_show_cb(void *data, Evas *e, Evas_Object *obj,
363                                 void *event_info)
364 {
365         evas_object_event_callback_del(obj, EVAS_CALLBACK_SHOW,
366                                                 __bt_main_entry_edit_mode_show_cb);
367
368         elm_object_focus_set(obj, EINA_TRUE);
369         elm_entry_cursor_end_set(obj);
370 }
371
372 static void __bt_main_popup_entry_activated_cb(void *data, Evas_Object *obj, void *event_info)
373 {
374         if (!obj)
375                 return;
376
377         elm_object_focus_set(obj, EINA_FALSE);
378 }
379
380 static Evas_Object *__bt_main_rename_entry_icon_get(
381                                 void *data, Evas_Object *obj, const char *part)
382 {
383         FN_START;
384         retv_if(obj == NULL || data == NULL, NULL);
385
386         Evas_Object *entry = NULL;
387         char *name_value = NULL;
388         char *name_value_utf = NULL;
389
390         static Elm_Entry_Filter_Limit_Size limit_filter_data;
391         bt_ug_data *ugd = (bt_ug_data *)data;
392
393         if (!strcmp(part, "elm.swallow.content")) {
394                 Evas_Object *layout = NULL;
395
396                 layout = elm_layout_add(obj);
397                 elm_layout_theme_set(layout, "layout", "editfield", "singleline");
398                 evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, 0.0);
399                 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, 0.0);
400
401                 name_value_utf = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
402                 retvm_if(!name_value_utf, NULL, "Get string is failed");
403
404                 name_value = elm_entry_utf8_to_markup(name_value_utf);
405
406                 entry = elm_entry_add(layout);
407                 elm_entry_single_line_set(entry, EINA_TRUE);
408                 elm_entry_scrollable_set(entry, EINA_TRUE);
409
410                 evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, 0.0);
411                 evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, 0.0);
412
413                 eext_entry_selection_back_event_allow_set(entry, EINA_TRUE);
414                 elm_object_signal_emit(entry, "elm,action,hide,search_icon", "");
415                 elm_object_part_text_set(entry, "guide", BT_STR_DEVICE_NAME);
416                 elm_object_text_set(entry, name_value);
417                 elm_entry_input_panel_imdata_set(entry, "action=disable_emoticons", 24);
418
419                 elm_entry_input_panel_return_key_type_set(entry, ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DONE);
420                 limit_filter_data.max_char_count = DEVICE_NAME_MAX_CHARACTER;
421                 elm_entry_markup_filter_append(entry,
422                         elm_entry_filter_limit_size, &limit_filter_data);
423
424                 elm_entry_cnp_mode_set(entry, ELM_CNP_MODE_PLAINTEXT);
425                 elm_entry_input_panel_layout_set(entry, ELM_INPUT_PANEL_LAYOUT_NORMAL);
426                 elm_entry_prediction_allow_set(entry, EINA_FALSE);
427                 elm_entry_autocapital_type_set(entry, ELM_AUTOCAPITAL_TYPE_NONE);
428
429                 evas_object_smart_callback_add(entry, "maxlength,reached",
430                                 _bt_util_max_len_reached_cb, ugd);
431                 evas_object_smart_callback_add(entry, "changed",
432                                 __bt_rename_entry_changed_cb, ugd);
433                 evas_object_smart_callback_add(entry, "preedit,changed",
434                                 __bt_rename_entry_changed_cb, ugd);
435                 evas_object_smart_callback_add(entry, "activated",
436                                                 __bt_main_popup_entry_activated_cb, NULL);
437                 evas_object_event_callback_add(entry, EVAS_CALLBACK_SHOW,
438                                 __bt_main_entry_edit_mode_show_cb, ugd);
439
440                 elm_entry_input_panel_show(entry);
441                 elm_object_part_content_set(layout, "elm.swallow.content", entry);
442
443                 ugd->rename_entry = entry;
444
445                 if (name_value_utf)
446                         free(name_value_utf);
447                 if (name_value)
448                         free(name_value);
449
450                 return layout;
451         }
452
453         return NULL;
454 }
455
456 static char *__bt_main_searched_label_get(void *data, Evas_Object *obj,
457                                           const char *part)
458 {
459         char buf[BT_GLOBALIZATION_STR_LENGTH] = { 0 };
460         bt_dev_t *dev = NULL;
461
462         if (data == NULL)
463                 return NULL;
464
465         dev = (bt_dev_t *)data;
466         if (!strcmp("elm.text", part)) {
467                 char *dev_name_markup = elm_entry_utf8_to_markup(dev->name);
468
469                 if (dev_name_markup) {
470                         g_strlcpy(buf, dev_name_markup,
471                                         BT_GLOBALIZATION_STR_LENGTH);
472                         free(dev_name_markup);
473                 } else {
474                         g_strlcpy(buf, dev->name, BT_GLOBALIZATION_STR_LENGTH);
475                 }
476
477                 BT_INFO("label : %s", buf);
478         } else {
479                 BT_ERR("empty text for label");
480                 return NULL;
481         }
482
483         return strdup(buf);
484 }
485
486 static Evas_Object *__bt_main_searched_icon_get(void *data,
487                                                 Evas_Object *obj,
488                                                 const char *part)
489 {
490         Evas_Object *icon = NULL;
491         char *dev_icon_file = NULL;
492         bt_dev_t *dev = NULL;
493
494         retv_if(data == NULL, NULL);
495
496         dev = (bt_dev_t *)data;
497
498         if (!strcmp("elm.swallow.icon", part)) {
499                 dev_icon_file =
500                     _bt_main_get_device_icon(dev->major_class,
501                                              dev->minor_class,
502                                              dev->is_connected,
503                                              dev->highlighted);
504                 icon = _bt_create_icon(obj, dev_icon_file);
505                 if (dev->highlighted || dev->is_connected)
506                         evas_object_color_set(icon, 20, 107, 147, 255);
507                 else
508                         evas_object_color_set(icon, 76, 76, 76, 255);
509                 evas_object_propagate_events_set(icon, EINA_FALSE);
510         } else if (!strcmp("elm.swallow.end", part)) {
511                 if (dev->status != BT_IDLE) {
512                         icon = _bt_create_progressbar(obj, "process_medium");
513                         evas_object_color_set(icon, 76, 76, 76, 255);
514                 }
515         }
516
517         if (icon) {
518                 evas_object_show(icon);
519                 evas_object_size_hint_min_set(icon, ELM_SCALE_SIZE(40), ELM_SCALE_SIZE(40));
520         }
521
522         return icon;
523 }
524
525 static char *__bt_main_no_device_label_get(void *data, Evas_Object *obj,
526                                            const char *part)
527 {
528         FN_START;
529
530         char buf[BT_GLOBALIZATION_STR_LENGTH] = { 0 };
531         if (!strcmp("elm.text", part)) {
532                 g_strlcpy(buf, BT_STR_NO_DEVICE_FOUND,
533                           BT_GLOBALIZATION_STR_LENGTH);
534                 snprintf(buf, sizeof(buf), "<align=center>%s</align>", BT_STR_NO_DEVICE_FOUND);
535         } else {
536                 BT_ERR("empty text for label");
537                 return NULL;
538         }
539
540         FN_END;
541         return strdup(buf);
542 }
543
544 static char *__bt_main_searched_title_label_get(void *data, Evas_Object *obj,
545                                                 const char *part)
546 {
547         FN_START;
548
549         char buf[BT_GLOBALIZATION_STR_LENGTH] = { 0, };
550         bt_ug_data *ugd = NULL;
551
552         retv_if(data == NULL, NULL);
553
554         ugd = (bt_ug_data *)data;
555         if (!strcmp("elm.text", part)) {
556                 /* Label */
557                 if (ugd->searched_device == NULL ||
558                     eina_list_count(ugd->searched_device) == 0) {
559                         if (ugd->op_status == BT_SEARCHING) {
560                                 g_strlcpy(buf, BT_STR_SCANNING,
561                                           BT_GLOBALIZATION_STR_LENGTH);
562                         } else if (ugd->op_status == BT_ACTIVATED) {
563                                 g_strlcpy(buf, BT_STR_BLUETOOTH_DEVICES,
564                                           BT_GLOBALIZATION_STR_LENGTH);
565                         }
566                 } else {
567                         g_strlcpy(buf, BT_STR_AVAILABLE_DEVICES,
568                                   BT_GLOBALIZATION_STR_LENGTH);
569                 }
570         } else {
571                 return NULL;
572         }
573
574         FN_END;
575         return strdup(buf);
576 }
577
578 static Evas_Object *__bt_main_searched_title_icon_get(void *data, Evas_Object *obj,
579                                              const char *part)
580 {
581         FN_START;
582
583         bt_ug_data *ugd = NULL;
584         Evas_Object *progressbar = NULL;
585
586         retv_if(data == NULL, NULL);
587         retv_if(obj == NULL, NULL);
588         retv_if(part == NULL, NULL);
589
590         ugd = (bt_ug_data *)data;
591
592         if (!strcmp("elm.swallow.end", part) && ugd->op_status == BT_SEARCHING)
593                 progressbar = _bt_create_progressbar(obj, "process_small");
594
595         FN_END;
596         return progressbar;
597 }
598
599 static app_control_h __bt_main_get_bt_onoff_result(bt_ug_data *ugd,
600                                                         gboolean result)
601 {
602         app_control_h service = NULL;
603         const char *result_str;
604         bt_adapter_state_e bt_state = BT_ADAPTER_DISABLED;
605
606         retv_if(ugd == NULL, NULL);
607
608         app_control_create(&service);
609
610         retv_if(service == NULL, NULL);
611
612         if (result == TRUE)
613                 result_str = BT_RESULT_SUCCESS;
614         else
615                 result_str = BT_RESULT_FAIL;
616
617         if (app_control_add_extra_data(service, "result", result_str) < 0)
618                 BT_ERR("Fail to add extra data");
619
620         if (bt_adapter_get_state(&bt_state) == BT_ERROR_NONE) {
621                 if (bt_state == BT_ADAPTER_ENABLED) {
622                         if (app_control_add_extra_data(service, "bt_status", BT_ADAPTER_ON) < 0)
623                                 BT_ERR("Fail to add extra data");
624                 } else {
625                         if (app_control_add_extra_data(service, "bt_status", BT_ADAPTER_OFF) < 0)
626                                 BT_ERR("Fail to add extra data");
627                 }
628         } else {
629                 BT_ERR("Fail to bt_adapter_get_state");
630         }
631
632         return service;
633 }
634
635 static Eina_Bool __bt_main_quit_btn_cb(void *data, Elm_Object_Item *it)
636 {
637         FN_START;
638         app_control_h reply = NULL;
639         app_control_h service = NULL;
640         bt_ug_data *ugd = (bt_ug_data *)data;
641
642         retv_if(ugd == NULL, EINA_FALSE);
643
644         if (ugd->bt_launch_mode == BT_LAUNCH_PICK) {
645                 app_control_create(&service);
646
647                 if (service == NULL) {
648                         _bt_ug_destroy(data, NULL);
649                         return EINA_FALSE;
650                 }
651
652                 if (app_control_add_extra_data(service, "result",
653                                            BT_RESULT_FAIL) < 0) {
654                         BT_ERR("Fail to add extra data");
655                 }
656
657                 _bt_ug_destroy(data, (void *)service);
658
659                 app_control_destroy(service);
660         } else if (ugd->bt_launch_mode == BT_LAUNCH_ONOFF) {
661                 service = __bt_main_get_bt_onoff_result(ugd, FALSE);
662
663                 app_control_create(&reply);
664                 if (app_control_add_extra_data(reply, "result",
665                                                         BT_RESULT_FAIL) < 0) {
666                         BT_ERR("Fail to add extra data");
667                 }
668
669                 BT_DBG("BT_LAUNCH_ONOFF reply to launch request");
670                 app_control_reply_to_launch_request(reply, service,
671                                                 APP_CONTROL_RESULT_FAILED);
672
673                 _bt_ug_destroy(data, (void *)service);
674
675                 if (service)
676                         app_control_destroy(service);
677                 if (reply)
678                         app_control_destroy(reply);
679         } else {
680                 _bt_ug_destroy(data, NULL);
681         }
682
683         FN_END;
684         return EINA_FALSE;
685 }
686
687 int _bt_main_enable_bt(void *data)
688 {
689         FN_START;
690         int ret;
691         retv_if(data == NULL, -1);
692         bt_ug_data *ugd = (bt_ug_data *)data;
693
694         ret = bt_emulator_enable();
695         if (ret != BT_ERROR_NONE)
696                 BT_ERR("Failed to enable bluetooth [%d]", ret);
697         else
698                 ugd->op_status = BT_ACTIVATING;
699
700         FN_END;
701         return 0;
702 }
703
704 int _bt_main_disable_bt(void *data)
705 {
706         FN_START;
707         int ret;
708         retv_if(data == NULL, -1);
709         bt_ug_data *ugd = (bt_ug_data *)data;
710
711         ret = bt_emulator_disable();
712         if (ret != BT_ERROR_NONE) {
713                 BT_ERR("Failed to disable bluetooth [%d]", ret);
714         } else {
715                 ugd->op_status = BT_DEACTIVATING;
716                 elm_object_disabled_set(ugd->scan_btn, EINA_TRUE);
717         }
718
719         FN_END;
720         return 0;
721 }
722
723 static void __bt_main_onoff_btn_cb(void *data, Evas_Object *obj,
724                                    void *event_info)
725 {
726         FN_START;
727         ret_if(data == NULL);
728
729         int ret;
730         bt_ug_data *ugd = (bt_ug_data *)data;
731
732         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
733         elm_genlist_item_selected_set(item, EINA_FALSE);
734
735         if (ugd->bt_launch_mode == BT_LAUNCH_HELP) {
736                 Eina_Bool check_mode = elm_check_state_get(obj);
737                 elm_check_state_set(obj, !check_mode);
738
739                 ret = notification_status_message_post(BT_STR_INVALID_ACTION_TRY_AGAIN);
740                 if (ret != NOTIFICATION_ERROR_NONE)
741                         BT_ERR("notification_status_message_post() is failed : %d", ret);
742
743                 FN_END;
744                 return;
745         }
746         ret_if(ugd->op_status == BT_ACTIVATING ||
747                 ugd->op_status == BT_DEACTIVATING);
748
749         elm_object_disabled_set(ugd->onoff_btn, EINA_TRUE);
750
751         if (ugd->op_status == BT_DEACTIVATED) {
752                 ret = _bt_main_enable_bt(data);
753                 ugd->op_status = BT_ACTIVATING;
754         } else if (ugd->op_status != BT_DEACTIVATING &&
755                 ugd->op_status != BT_ACTIVATING) {
756                 ret = bt_emulator_disable();
757                 if (ret != BT_ERROR_NONE) {
758                         BT_ERR("Failed to disable bluetooth [%d]", ret);
759                 } else {
760                         ugd->op_status = BT_DEACTIVATING;
761                         elm_object_disabled_set(ugd->scan_btn, EINA_TRUE);
762                 }
763         }
764
765         if (ugd->op_status == BT_ACTIVATING ||
766                 ugd->op_status == BT_DEACTIVATING) {
767                 elm_genlist_item_fields_update(ugd->onoff_item, "*",
768                                                 ELM_GENLIST_ITEM_FIELD_TEXT);
769                 elm_genlist_item_fields_update(ugd->onoff_item, "*",
770                                                 ELM_GENLIST_ITEM_FIELD_CONTENT);
771         }
772         FN_END;
773 }
774
775 static void __bt_main_controlbar_btn_cb(void *data, Evas_Object *obj,
776                                         void *event_info)
777 {
778         FN_START;
779
780         bt_ug_data *ugd = NULL;
781
782         retm_if(data == NULL, "Invalid argument: bt_ug_data is NULL");
783
784         ugd = (bt_ug_data *)data;
785
786         if (ugd->op_status == BT_SEARCHING) {
787                 if (ugd->is_discovery_started) {
788                         if (bt_emulator_stop_device_discovery() == BT_ERROR_NONE) {
789                                 elm_object_disabled_set(ugd->scan_btn, EINA_TRUE);
790                                 elm_object_text_set(ugd->scan_btn, BT_STR_STOP);
791                         } else { /*the case in which stop discovery returns error from Bluez*/
792                                 ugd->op_status = BT_ACTIVATED;
793                                 elm_object_text_set(ugd->scan_btn, BT_STR_SCAN);
794
795                                 if (ugd->searched_title == NULL)
796                                         _bt_main_add_searched_title(ugd);
797                                 _bt_update_genlist_item((Elm_Object_Item *)
798                                                 ugd->searched_title);
799                         }
800                 }
801         } else { /*ugd->op_status != BT_SEARCHING */
802                 _bt_main_scan_device(ugd);
803         }
804
805         FN_END;
806 }
807
808 static void __bt_main_searched_item_sel_cb(void *data, Evas_Object *obj,
809                                            void *event_info)
810 {
811         FN_START;
812
813         bt_ug_data *ugd = NULL;
814         bt_dev_t *dev = NULL;
815         Elm_Object_Item *item = NULL;
816         int ret;
817
818         if (event_info)
819                 elm_genlist_item_selected_set((Elm_Object_Item *) event_info,
820                                       EINA_FALSE);
821
822         retm_if(data == NULL, "Invalid argument: bt_ug_data is NULL");
823
824         ugd = (bt_ug_data *)data;
825
826         ret_if(ugd->op_status == BT_PAIRING);
827
828         item = (Elm_Object_Item *) event_info;
829
830         dev = _bt_main_get_dev_info(ugd->searched_device,
831                                     (Elm_Object_Item *) event_info);
832         retm_if(dev == NULL, "Invalid argument: device info is NULL");
833
834         ugd->searched_item = item;
835
836         if (ugd->op_status == BT_SEARCHING) {
837                 ret = bt_emulator_stop_device_discovery();
838                 if (ret != BT_ERROR_NONE)
839                         BT_ERR("Fail to stop discovery");
840         }
841
842         FN_END;
843 }
844
845 static void __bt_main_gl_highlighted(void *data, Evas_Object *obj,
846                                      void *event_info)
847 {
848         FN_START;
849
850         bt_ug_data *ugd;
851         bt_dev_t *dev;
852         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
853
854         ret_if(item == NULL);
855
856         ugd = (bt_ug_data *)data;
857         ret_if(ugd == NULL);
858
859         dev = _bt_main_get_dev_info(ugd->searched_device, item);
860         ret_if(dev == NULL);
861
862         dev->highlighted = TRUE;
863
864         /* Update text */
865         elm_genlist_item_fields_update(item, "*", ELM_GENLIST_ITEM_FIELD_TEXT);
866
867         FN_END;
868 }
869
870 static void __bt_main_gl_unhighlighted(void *data, Evas_Object *obj,
871                                        void *event_info)
872 {
873         FN_START;
874
875         bt_ug_data *ugd;
876         bt_dev_t *dev;
877         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
878
879         ret_if(item == NULL);
880
881         ugd = (bt_ug_data *)data;
882         ret_if(ugd == NULL);
883
884         dev = _bt_main_get_dev_info(ugd->searched_device, item);
885         ret_if(dev == NULL);
886
887         dev->highlighted = FALSE;
888
889         /* Update text */
890         elm_genlist_item_fields_update(item, "*", ELM_GENLIST_ITEM_FIELD_TEXT);
891
892         FN_END;
893 }
894
895 void _bt_main_add_device_name_item(bt_ug_data *ugd, Evas_Object *genlist)
896 {
897         FN_START;
898         retm_if(ugd->op_status == BT_DEACTIVATED, "BT is turned off");
899
900         Elm_Object_Item *git = NULL;
901         /* Device name */
902         git = elm_genlist_item_insert_after(genlist, ugd->device_name_itc, ugd, NULL,
903                                         ugd->onoff_item, ELM_GENLIST_ITEM_NONE, NULL, NULL);
904         elm_genlist_item_select_mode_set(git, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
905
906         ugd->device_name_item = git;
907
908         FN_END;
909 }
910
911 static Evas_Object *__bt_main_add_genlist_dialogue(Evas_Object *parent,
912                                                    bt_ug_data *ugd)
913 {
914         FN_START;
915         retv_if(ugd == NULL, NULL);
916
917         Evas_Object *genlist = NULL;
918         Elm_Object_Item *git = NULL;
919
920         genlist = elm_genlist_add(parent);
921         retv_if(!genlist, NULL);
922         /* We shoud set the mode to compress
923            for using dialogue/2text.2icon.3.tb */
924         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
925         elm_genlist_homogeneous_set(genlist, EINA_FALSE);
926         elm_genlist_block_count_set(genlist, 3);
927
928         evas_object_smart_callback_add(genlist, "highlighted",
929                                        __bt_main_gl_highlighted, ugd);
930
931         evas_object_smart_callback_add(genlist, "unhighlighted",
932                                        __bt_main_gl_unhighlighted, ugd);
933
934         ugd->on_itc = elm_genlist_item_class_new();
935         retv_if(ugd->on_itc == NULL, NULL);
936
937         ugd->on_itc->item_style = BT_GENLIST_1LINE_TEXT_ICON_STYLE;
938         ugd->on_itc->func.text_get = __bt_main_onoff_label_get;
939         ugd->on_itc->func.content_get = __bt_main_onoff_icon_get;
940         ugd->on_itc->func.state_get = NULL;
941         ugd->on_itc->func.del = NULL;
942
943         /* Set item class for dialogue seperator */
944         ugd->off_itc = elm_genlist_item_class_new();
945         retv_if(ugd->off_itc == NULL, NULL);
946
947         ugd->off_itc->item_style = BT_GENLIST_MULTILINE_TEXT_STYLE;
948         ugd->off_itc->func.text_get = __bt_main_onoff_label_get;
949         ugd->off_itc->func.content_get = __bt_main_onoff_icon_get;
950         ugd->off_itc->func.state_get = NULL;
951         ugd->off_itc->func.del = NULL;
952
953         /* Set item class for paired dialogue title */
954         ugd->device_name_itc = elm_genlist_item_class_new();
955         retv_if(ugd->device_name_itc == NULL, NULL);
956
957         ugd->device_name_itc->item_style = BT_GENLIST_2LINE_BOTTOM_TEXT_STYLE;
958         ugd->device_name_itc->func.text_get = __bt_main_device_label_get;
959         ugd->device_name_itc->func.content_get = NULL;
960         ugd->device_name_itc->func.state_get = NULL;
961         ugd->device_name_itc->func.del = NULL;
962
963         /* Set item class for searched dialogue title */
964         ugd->searched_title_itc = elm_genlist_item_class_new();
965         retv_if(ugd->searched_title_itc == NULL, NULL);
966
967         ugd->searched_title_itc->item_style = BT_GENLIST_GROUP_INDEX_STYLE;
968         ugd->searched_title_itc->func.text_get = __bt_main_searched_title_label_get;
969         ugd->searched_title_itc->func.content_get = __bt_main_searched_title_icon_get;
970         ugd->searched_title_itc->func.state_get = NULL;
971         ugd->searched_title_itc->func.del = NULL;
972
973         /* Set item class for searched device */
974         ugd->searched_device_itc = elm_genlist_item_class_new();
975         retv_if(ugd->searched_device_itc == NULL, NULL);
976
977         ugd->searched_device_itc->item_style = BT_GENLIST_1LINE_TEXT_ICON_STYLE;
978         ugd->searched_device_itc->func.text_get = __bt_main_searched_label_get;
979         ugd->searched_device_itc->func.content_get = __bt_main_searched_icon_get;
980         ugd->searched_device_itc->func.state_get = NULL;
981         ugd->searched_device_itc->func.del = NULL;
982
983         /* Set item class for no device */
984         ugd->no_device_itc = elm_genlist_item_class_new();
985         retv_if(ugd->no_device_itc == NULL, NULL);
986
987         ugd->no_device_itc->item_style = BT_GENLIST_1LINE_TEXT_STYLE;
988         ugd->no_device_itc->func.text_get = __bt_main_no_device_label_get;
989         ugd->no_device_itc->func.content_get = NULL;
990         ugd->no_device_itc->func.state_get = NULL;
991         ugd->no_device_itc->func.del = NULL;
992
993         if (ugd->op_status == BT_DEACTIVATED ||
994                 ugd->op_status == BT_ACTIVATING)
995                 git = elm_genlist_item_append(genlist, ugd->off_itc, ugd, NULL,
996                                                                 ELM_GENLIST_ITEM_NONE,
997                                                                 __bt_main_onoff_btn_cb, ugd);
998         else
999                 git = elm_genlist_item_append(genlist, ugd->on_itc, ugd, NULL,
1000                                                                 ELM_GENLIST_ITEM_NONE,
1001                                                                 __bt_main_onoff_btn_cb, ugd);
1002
1003         ugd->onoff_item = git;
1004
1005         _bt_main_add_device_name_item(ugd, genlist);
1006
1007         evas_object_show(genlist);
1008
1009         FN_END;
1010         return genlist;
1011 }
1012
1013 static gboolean __bt_main_system_popup_timer_cb(gpointer user_data)
1014 {
1015         FN_START;
1016
1017         int ret;
1018         bt_ug_data *ugd;
1019         bundle *b;
1020
1021         retv_if(user_data == NULL, FALSE);
1022
1023         ugd = (bt_ug_data *)user_data;
1024
1025         b = ugd->popup_bundle;
1026
1027         if (NULL == b) {
1028                 BT_ERR("bundle is NULL");
1029                 return FALSE;
1030         }
1031
1032         ret = syspopup_launch("bt-syspopup", b);
1033         if (ret < 0) {
1034                 BT_ERR("Sorry cannot launch popup");
1035         } else {
1036                 BT_DBG("Finally Popup launched");
1037                 bundle_free(b);
1038         }
1039
1040         FN_END;
1041         return (ret < 0) ? TRUE : FALSE;
1042 }
1043
1044 static bool __bt_main_get_mime_type(char *file)
1045 {
1046         FN_START;
1047
1048         char mime_type[BT_FILE_NAME_LEN_MAX] = { 0, };
1049         int len = strlen("image");
1050
1051         retv_if(file == NULL, FALSE);
1052
1053         if (aul_get_mime_from_file(file, mime_type,
1054                                    BT_FILE_NAME_LEN_MAX) == AUL_R_OK) {
1055                 BT_INFO("mime type=[%s]", mime_type);
1056                 if (0 != strncmp(mime_type, "image", len))
1057                         return FALSE;
1058         } else {
1059                 BT_ERR("Error getting mime type");
1060                 return FALSE;
1061         }
1062
1063         FN_END;
1064         return TRUE;
1065 }
1066
1067 static bool __bt_main_is_image_file(app_control_h service)
1068 {
1069         FN_START;
1070
1071         char *value = NULL;
1072         int number_of_files = 0;
1073         char *token = NULL;
1074         char *param = NULL;
1075         int i = 0;
1076
1077         retvm_if(service == NULL, FALSE, "Invalid data bundle");
1078
1079         if (app_control_get_extra_data(service, "filecount", &value) < 0)
1080                 BT_ERR("Get data error");
1081
1082         retv_if(value == NULL, FALSE);
1083
1084         number_of_files = atoi(value);
1085         BT_INFO("[%d] files", number_of_files);
1086         free(value);
1087         value = NULL;
1088
1089         if (number_of_files <= 0) {
1090                 BT_ERR("No File");
1091                 return FALSE;
1092         }
1093
1094         if (app_control_get_extra_data(service, "files", &value) < 0)
1095                 BT_ERR("Get data error");
1096
1097         retv_if(value == NULL, FALSE);
1098
1099         param = value;
1100         while (((token = strstr(param, "?")) != NULL) && i < number_of_files) {
1101                 *token = '\0';
1102                 if (!__bt_main_get_mime_type(param)) {
1103                         *token = '?';
1104                         free(value);
1105                         return FALSE;
1106                 }
1107                 BT_INFO("File [%d] [%s]", i, param);
1108                 *token = '?';
1109                 param = token + 1;
1110                 i++;
1111         }
1112         if (i == (number_of_files - 1)) {
1113                 if (!__bt_main_get_mime_type(param)) {
1114                         free(value);
1115                         return FALSE;
1116                 }
1117                 BT_INFO("File [%d] [%s]", i, param);
1118         } else {
1119                 BT_ERR("Count not match : [%d] / [%d]", number_of_files, i);
1120                 free(value);
1121                 return FALSE;
1122         }
1123
1124         free(value);
1125
1126         FN_END;
1127         return TRUE;
1128 }
1129
1130 /**********************************************************************
1131 *                                              Common Functions
1132 ***********************************************************************/
1133
1134 void _bt_main_scan_device(bt_ug_data *ugd)
1135 {
1136         FN_START;
1137         int ret;
1138
1139         ret_if(ugd == NULL);
1140
1141         if (ugd->op_status != BT_DEACTIVATED && ugd->op_status != BT_ACTIVATED) {
1142                 BT_INFO("current bluetooth status [%d]", ugd->op_status);
1143                 return;
1144         }
1145
1146         if (ugd->op_status == BT_DEACTIVATED) {
1147                 ret = _bt_main_enable_bt((void *)ugd);
1148                 if (!ret)
1149                         elm_object_disabled_set(ugd->scan_btn, EINA_TRUE);
1150         } else {
1151                 ret = bt_emulator_start_device_discovery();
1152                 if (!ret) {
1153                         /* Disable the Scan button till the BLUETOOTH_EVENT_DISCOVERY_STARTED is received */
1154                         elm_object_disabled_set(ugd->scan_btn, EINA_TRUE);
1155                         _bt_main_remove_all_searched_devices(ugd);
1156                         ugd->op_status = BT_SEARCHING;
1157                         elm_object_text_set(ugd->scan_btn, BT_STR_STOP);
1158
1159                         if (ugd->searched_title == NULL)
1160                                 _bt_main_add_searched_title(ugd);
1161                 } else {
1162                         BT_ERR("Operation failed : Error Cause[%d]", ret);
1163                 }
1164         }
1165
1166         FN_END;
1167 }
1168
1169 char *_bt_main_get_device_icon(int major_class, int minor_class,
1170                                int connected, gboolean highlighted)
1171 {
1172         char *icon = BT_ICON_UNKNOWN;
1173
1174         switch (major_class) {
1175         case BT_MAJOR_DEV_CLS_COMPUTER:
1176                 icon = BT_ICON_PC;
1177                 break;
1178         case BT_MAJOR_DEV_CLS_PHONE:
1179                 icon = BT_ICON_PHONE;
1180                 break;
1181         case BT_MAJOR_DEV_CLS_AUDIO:
1182                 if (minor_class == BTAPP_MIN_DEV_CLS_HEADPHONES)
1183                         icon = BT_ICON_HEADPHONE;
1184                 else if (minor_class == BTAPP_MIN_DEV_CLS_VIDEO_DISPLAY_AND_LOUD_SPEAKER)
1185                         icon = BT_ICON_DISPLAY;
1186                 else
1187                         icon = BT_ICON_HEADSET;
1188                 break;
1189         case BT_MAJOR_DEV_CLS_LAN_ACCESS_POINT:
1190                 icon = BT_ICON_NETWORK;
1191                 break;
1192         case BT_MAJOR_DEV_CLS_IMAGING:
1193                 if (minor_class == BTAPP_MIN_DEV_CLS_PRINTER)
1194                         icon = BT_ICON_PRINTER;
1195                 else if (minor_class == BTAPP_MIN_DEV_CLS_CAMERA)
1196                         icon = BT_ICON_CAMERA;
1197                 else if (minor_class == BTAPP_MIN_DEV_CLS_DISPLAY)
1198                         icon = BT_ICON_DISPLAY;
1199                 break;
1200         case BT_MAJOR_DEV_CLS_PERIPHERAL:
1201                 if (minor_class == BTAPP_MIN_DEV_CLS_KEY_BOARD)
1202                         icon = BT_ICON_KEYBOARD;
1203                 else if (minor_class == BTAPP_MIN_DEV_CLS_POINTING_DEVICE)
1204                         icon = BT_ICON_MOUSE;
1205                 else if (minor_class == BTAPP_MIN_DEV_CLS_GAME_PAD)
1206                         icon = BT_ICON_GAMING;
1207                 else
1208                         icon = BT_ICON_MOUSE;
1209                 break;
1210         case BT_MAJOR_DEV_CLS_HEALTH:
1211                 icon = BT_ICON_HEALTH;
1212                 break;
1213
1214         case BT_MAJOR_DEV_CLS_WEARABLE:
1215                 if (minor_class == BTAPP_MIN_DEV_CLS_WRIST_WATCH)
1216                         icon = BT_ICON_WATCH;
1217                 else
1218                         icon = BT_ICON_UNKNOWN;
1219                 break;
1220         default:
1221                 icon = BT_ICON_UNKNOWN;
1222                 break;
1223         }
1224
1225         return icon;
1226 }
1227
1228 void _bt_main_popup_del_cb(void *data, Evas_Object *obj, void *event_info)
1229 {
1230         FN_START;
1231         retm_if(data == NULL, "Invalid argument: struct bt_appdata is NULL");
1232
1233         bt_ug_data *ugd = (bt_ug_data *)data;
1234
1235         if (ugd->popup) {
1236                 evas_object_del(ugd->popup);
1237                 ugd->popup = NULL;
1238         }
1239         if (ugd->popup_data.data)
1240                 g_free(ugd->popup_data.data);
1241         ugd->popup_data.data = NULL;
1242
1243         ugd->back_cb = NULL;
1244
1245         FN_END;
1246 }
1247
1248 void _bt_back_btn_popup_del_cb(void *data, Evas_Object *obj, void *event_info)
1249 {
1250         FN_START;
1251         retm_if(data == NULL, "Invalid argument: struct bt_appdata is NULL");
1252
1253         bt_ug_data *ugd = (bt_ug_data *)data;
1254
1255         if (ugd->popup) {
1256                 BT_DBG("Deleting popup");
1257                 evas_object_del(ugd->popup);
1258                 ugd->popup = NULL;
1259         }
1260
1261         ugd->op_status = BT_ACTIVATED;
1262
1263         FN_END;
1264 }
1265
1266 Elm_Object_Item *_bt_main_add_searched_device(bt_ug_data *ugd, bt_dev_t *dev)
1267 {
1268         FN_START;
1269
1270         Elm_Object_Item *git = NULL;
1271
1272         retvm_if(ugd == NULL, NULL, "Invalid argument: ugd is NULL");
1273         retvm_if(dev == NULL, NULL, "Invalid argument: dev is NULL");
1274
1275         if (ugd->searched_title == NULL)
1276                 _bt_main_add_searched_title(ugd);
1277
1278         retvm_if(ugd->searched_title == NULL, NULL,
1279                  "Fail to add searched title genlist item");
1280
1281         /* Searched device Item */
1282         if (ugd->searched_device == NULL) {
1283                 git =
1284                     elm_genlist_item_insert_after(ugd->main_genlist,
1285                                                   ugd->searched_device_itc, dev, NULL,
1286                                                   ugd->searched_title,
1287                                                   ELM_GENLIST_ITEM_NONE,
1288                                                   __bt_main_searched_item_sel_cb,
1289                                                   ugd);
1290         } else {
1291                 bt_dev_t *item_dev = NULL;
1292                 Elm_Object_Item *item = NULL;
1293                 Elm_Object_Item *next = NULL;
1294
1295                 item = elm_genlist_item_next_get(ugd->searched_title);
1296
1297                 /* check the RSSI value of searched device list add arrange its order */
1298                 while (item != NULL) {
1299                         item_dev =
1300                             _bt_main_get_dev_info(ugd->searched_device, item);
1301                         retv_if(item_dev == NULL, NULL);
1302
1303                         if (item_dev->rssi > dev->rssi) {
1304                                 next = elm_genlist_item_next_get(item);
1305                                 if (next == NULL) {
1306                                         git =
1307                                             elm_genlist_item_insert_after
1308                                             (ugd->main_genlist,
1309                                              ugd->searched_device_itc, dev, NULL, item,
1310                                              ELM_GENLIST_ITEM_NONE,
1311                                              __bt_main_searched_item_sel_cb,
1312                                              ugd);
1313                                         break;
1314                                 }
1315                                 item = next;
1316                         } else {
1317                                 git =
1318                                     elm_genlist_item_insert_before
1319                                     (ugd->main_genlist, ugd->searched_device_itc, dev,
1320                                      NULL, item, ELM_GENLIST_ITEM_NONE,
1321                                      __bt_main_searched_item_sel_cb, ugd);
1322                                 break;
1323                         }
1324                 }
1325         }
1326
1327         dev->genlist_item = git;
1328         dev->status = BT_IDLE;
1329         dev->ugd = (void *)ugd;
1330         dev->is_bonded = FALSE;
1331
1332         FN_END;
1333         return git;
1334 }
1335
1336 Elm_Object_Item *_bt_main_add_no_device_found(bt_ug_data *ugd)
1337 {
1338         FN_START;
1339
1340         Elm_Object_Item *git = NULL;
1341
1342         retvm_if(ugd == NULL, NULL, "Invalid argument: ugd is NULL");
1343
1344         if (ugd->searched_title == NULL)
1345                 _bt_main_add_searched_title(ugd);
1346
1347         /* No device found Item */
1348         git =
1349             elm_genlist_item_insert_after(ugd->main_genlist, ugd->no_device_itc,
1350                                         ugd, NULL, ugd->searched_title,
1351                                         ELM_GENLIST_ITEM_NONE, NULL, NULL);
1352
1353         elm_genlist_item_select_mode_set(git,
1354                                         ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1355
1356         FN_END;
1357         return git;
1358 }
1359
1360 static void __bt_move_help_ctxpopup(Evas_Object *ctx, bt_ug_data *ugd)
1361 {
1362         FN_START;
1363         Evas_Coord w, h;
1364         int pos = -1;
1365
1366         ret_if(ugd == NULL);
1367         ret_if(ugd->win_main == NULL);
1368
1369         elm_win_screen_size_get(ugd->win_main, NULL, NULL, &w, &h);
1370         pos = elm_win_rotation_get(ugd->win_main);
1371         switch (pos) {
1372         case 0:
1373         case 180:
1374         case 360:
1375                 evas_object_move(ctx, (w/2), h);
1376                 break;
1377         case 90:
1378         case 270:
1379                 evas_object_move(ctx, (h/2), w);
1380                 break;
1381         default:
1382                 evas_object_move(ctx, (w/2), h);
1383                 break;
1384         }
1385         FN_END;
1386 }
1387
1388 static void __bt_ctxpopup_rotate_cb(void *data, Evas_Object *obj, void *event_info)
1389 {
1390         FN_START;
1391         bt_ug_data *ugd = NULL;
1392         ret_if(data == NULL);
1393         ugd = (bt_ug_data *)data;
1394
1395         __bt_move_help_ctxpopup(ugd->help_more_popup, ugd);
1396         evas_object_show(ugd->win_main);
1397
1398         FN_END;
1399 }
1400
1401 static void __bt_more_popup_del_cb(void *data)
1402 {
1403         FN_START;
1404         bt_ug_data *ugd = NULL;
1405
1406         ret_if(data == NULL);
1407         ugd = (bt_ug_data *)data;
1408
1409         if (ugd->help_more_popup != NULL) {
1410                 evas_object_del(ugd->help_more_popup);
1411                 ugd->help_more_popup = NULL;
1412         }
1413
1414         FN_END;
1415 }
1416
1417 static void __bt_more_popup_more_cb(void *data,
1418                                 Evas_Object *obj, void *event_info)
1419 {
1420         FN_START;
1421         __bt_more_popup_del_cb((bt_ug_data *)data);
1422         FN_END;
1423 }
1424
1425 static void __bt_more_popup_back_cb(void *data,
1426                                 Evas_Object *obj, void *event_info)
1427 {
1428         FN_START;
1429         __bt_more_popup_del_cb((bt_ug_data *)data);
1430         FN_END;
1431 }
1432
1433 static void __bt_more_popup_dismiss_cb(void *data, Evas_Object *obj,
1434                                                 void *event)
1435 {
1436         FN_START;
1437         bt_ug_data *ugd;
1438
1439         ugd = (bt_ug_data *)data;
1440         ret_if(ugd == NULL);
1441         ret_if(ugd->help_more_popup == NULL);
1442
1443         evas_object_del(ugd->help_more_popup);
1444         ugd->help_more_popup = NULL;
1445
1446         FN_END;
1447 }
1448
1449 static void __bt_more_popup_delete_cb(void *data, Evas *e,
1450                 Evas_Object *obj,       void *event_info)
1451 {
1452         FN_START;
1453         Evas_Object *navi = (Evas_Object *)data;
1454         Evas_Object *ctx = obj;
1455
1456         ret_if(navi == NULL);
1457
1458         evas_object_smart_callback_del(ctx, "dismissed",
1459                         __bt_more_popup_dismiss_cb);
1460         evas_object_event_callback_del_full(ctx, EVAS_CALLBACK_DEL,
1461                         __bt_more_popup_delete_cb, navi);
1462         FN_END;
1463 }
1464
1465 static void __bt_more_popup_rename_device_item_sel_cb(void *data,
1466                                 Evas_Object *obj, void *event_inf)
1467 {
1468         FN_START;
1469         ret_if(data == NULL);
1470         ret_if(event_inf == NULL);
1471         bt_ug_data *ugd = (bt_ug_data *)data;
1472
1473         if (event_inf)
1474                 elm_genlist_item_selected_set((Elm_Object_Item *)event_inf,
1475                                                 EINA_FALSE);
1476
1477         ret_if(ugd == NULL);
1478         ret_if(ugd->help_more_popup == NULL);
1479         evas_object_del(ugd->help_more_popup);
1480         ugd->help_more_popup = NULL;
1481         Evas_Object *popup = NULL;
1482         Evas_Object *genlist = NULL;
1483         Evas_Object *button = NULL;
1484         Elm_Object_Item *git = NULL;
1485
1486
1487         popup = elm_popup_add(ugd->base);
1488         eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK,
1489                         __bt_rename_device_cancel_cb, ugd);
1490         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1491         evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
1492
1493         elm_object_domain_translatable_part_text_set(popup,
1494                                                 "title,text",
1495                                                 PKGNAME,
1496                                                 "IDS_ST_HEADER_RENAME_DEVICE");
1497
1498         genlist = elm_genlist_add(popup);
1499         evas_object_size_hint_weight_set(genlist,
1500                         EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1501         evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
1502         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
1503         elm_scroller_content_min_limit(genlist, EINA_FALSE, EINA_TRUE);
1504
1505         /* Entry genlist item */
1506         ugd->rename_entry_itc = elm_genlist_item_class_new();
1507         /* Fix : NULL_RETURNS */
1508         if (ugd->rename_entry_itc) {
1509                 ugd->rename_entry_itc->item_style = BT_GENLIST_FULL_CONTENT_STYLE;
1510                 ugd->rename_entry_itc->func.text_get = NULL;
1511                 ugd->rename_entry_itc->func.content_get = __bt_main_rename_entry_icon_get;
1512                 ugd->rename_entry_itc->func.state_get = NULL;
1513                 ugd->rename_entry_itc->func.del = NULL;
1514
1515                 ugd->rename_entry_item = elm_genlist_item_append(genlist,
1516                                 ugd->rename_entry_itc, ugd,
1517                                 NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
1518         }
1519
1520         ugd->rename_desc_itc = elm_genlist_item_class_new();
1521         /* Fix : NULL_RETURNS */
1522         if (ugd->rename_desc_itc) {
1523                 ugd->rename_desc_itc->item_style = BT_GENLIST_MULTILINE_TEXT_STYLE;
1524                 ugd->rename_desc_itc->func.text_get = __bt_main_rename_desc_label_get;
1525                 ugd->rename_desc_itc->func.content_get = NULL;
1526                 ugd->rename_desc_itc->func.state_get = NULL;
1527                 ugd->rename_desc_itc->func.del = NULL;
1528
1529                 git = elm_genlist_item_append(genlist, ugd->rename_desc_itc, NULL, NULL,
1530                                 ELM_GENLIST_ITEM_NONE, NULL, NULL);
1531         }
1532         elm_genlist_item_select_mode_set(git,
1533                                          ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1534
1535         button = elm_button_add(popup);
1536         elm_object_style_set(button, "popup");
1537         elm_object_domain_translatable_text_set(button,
1538                                                 PKGNAME,
1539                                                 "IDS_BR_SK_CANCEL");
1540         elm_object_part_content_set(popup, "button1", button);
1541         evas_object_smart_callback_add(button, "clicked",
1542                         __bt_rename_device_cancel_cb, ugd);
1543
1544         button = elm_button_add(popup);
1545         ugd->rename_button = button;
1546         elm_object_style_set(button, "popup");
1547         elm_object_domain_translatable_text_set(button,
1548                                                 PKGNAME,
1549                                                 "IDS_BT_OPT_RENAME");
1550         elm_object_part_content_set(popup, "button2", button);
1551         evas_object_smart_callback_add(button, "clicked",
1552                         __bt_rename_device_ok_cb, ugd);
1553
1554         evas_object_show(genlist);
1555
1556         elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
1557         elm_object_content_set(popup, genlist);
1558         evas_object_show(popup);
1559
1560         ugd->rename_popup = popup;
1561
1562         FN_END;
1563
1564 }
1565
1566 static void __bt_more_menu_cb(void *data,
1567                                 Evas_Object *obj, void *event_info)
1568 {
1569         FN_START;
1570
1571         Evas_Object *more_ctxpopup = NULL;
1572         bt_ug_data *ugd;
1573
1574         ugd = (bt_ug_data *)data;
1575         ret_if(ugd == NULL);
1576         ret_if(ugd->op_status == BT_ACTIVATING ||
1577                 ugd->op_status == BT_DEACTIVATED ||
1578                 ugd->op_status == BT_DEACTIVATING);
1579         ret_if(ugd->bt_launch_mode != BT_LAUNCH_NORMAL);
1580
1581         _bt_main_popup_del_cb(ugd, NULL, NULL);
1582
1583         more_ctxpopup = elm_ctxpopup_add(ugd->win_main);
1584         ugd->help_more_popup = more_ctxpopup;
1585         eext_object_event_callback_add(more_ctxpopup,
1586                         EEXT_CALLBACK_BACK, __bt_more_popup_back_cb, ugd);
1587         eext_object_event_callback_add(more_ctxpopup,
1588                         EEXT_CALLBACK_MORE, __bt_more_popup_more_cb, ugd);
1589         elm_object_style_set(more_ctxpopup, "more/default");
1590         elm_ctxpopup_auto_hide_disabled_set(more_ctxpopup, EINA_TRUE);
1591
1592         elm_ctxpopup_item_append(more_ctxpopup, BT_STR_RENAME_DEVICE_TITLE,
1593                         NULL, __bt_more_popup_rename_device_item_sel_cb, ugd);
1594
1595         evas_object_smart_callback_add(more_ctxpopup, "dismissed",
1596                         __bt_more_popup_dismiss_cb, ugd);
1597         evas_object_event_callback_add(more_ctxpopup, EVAS_CALLBACK_DEL,
1598                         __bt_more_popup_delete_cb, ugd->navi_bar);
1599         evas_object_smart_callback_add(elm_object_top_widget_get(more_ctxpopup), "rotation,changed",
1600                         __bt_ctxpopup_rotate_cb, ugd);
1601
1602         elm_ctxpopup_direction_priority_set(more_ctxpopup, ELM_CTXPOPUP_DIRECTION_UP,
1603                         ELM_CTXPOPUP_DIRECTION_DOWN,
1604                         ELM_CTXPOPUP_DIRECTION_UNKNOWN,
1605                         ELM_CTXPOPUP_DIRECTION_UNKNOWN);
1606
1607         __bt_move_help_ctxpopup(more_ctxpopup, ugd);
1608         evas_object_show(more_ctxpopup);
1609
1610         FN_END;
1611 }
1612
1613 Evas_Object * _bt_main_create_scan_button(bt_ug_data *ugd)
1614 {
1615         Evas_Object *scan_button = NULL;
1616
1617         scan_button = elm_button_add(ugd->navi_bar);
1618
1619         /* Use "bottom" style button */
1620         elm_object_style_set(scan_button, "bottom");
1621
1622         elm_object_text_set(scan_button, BT_STR_SCAN);
1623
1624         evas_object_smart_callback_add(scan_button, "clicked",
1625                         __bt_main_controlbar_btn_cb, ugd);
1626
1627         /* Set button into "toolbar" swallow part */
1628         elm_object_item_part_content_set(ugd->navi_it, "toolbar", scan_button);
1629
1630         return scan_button;
1631 }
1632
1633 static void __bt_main_back_cb(void *data, Evas_Object *obj, void *event_info)
1634 {
1635         __bt_main_quit_btn_cb(data, NULL);
1636 }
1637
1638 int _bt_main_draw_list_view(bt_ug_data *ugd)
1639 {
1640         FN_START;
1641
1642         Evas_Object *navi = NULL;
1643         Evas_Object *genlist = NULL;
1644         Elm_Object_Item *navi_it = NULL;
1645         Evas_Object *back_button = NULL;
1646
1647         retv_if(ugd == NULL, BT_UG_FAIL);
1648
1649         navi = _bt_create_naviframe(ugd->base);
1650         elm_naviframe_prev_btn_auto_pushed_set(navi, EINA_FALSE);
1651         ugd->navi_bar = navi;
1652
1653         eext_object_event_callback_add(navi, EEXT_CALLBACK_BACK,
1654                                      eext_naviframe_back_cb, NULL);
1655
1656         if (ugd->bt_launch_mode != BT_LAUNCH_HELP)
1657                 eext_object_event_callback_add(navi, EEXT_CALLBACK_MORE,
1658                                                 __bt_more_menu_cb, ugd);
1659         genlist = __bt_main_add_genlist_dialogue(navi, ugd);
1660         ugd->main_genlist = genlist;
1661
1662         back_button = elm_button_add(navi);
1663         elm_object_style_set(back_button, "naviframe/end_btn/default");
1664
1665         navi_it = elm_naviframe_item_push(navi, BT_STR_BLUETOOTH, back_button, NULL,
1666                                           genlist, NULL);
1667         elm_naviframe_item_pop_cb_set(navi_it, __bt_main_quit_btn_cb, ugd);
1668         ugd->navi_it = navi_it;
1669         evas_object_smart_callback_add(back_button, "clicked", __bt_main_back_cb, ugd);
1670
1671         if (ugd->op_status == BT_ACTIVATED)
1672                 ugd->scan_btn = _bt_main_create_scan_button(ugd);
1673
1674         FN_END;
1675         return BT_UG_ERROR_NONE;
1676 }
1677
1678 void _bt_main_remove_searched_device(bt_ug_data *ugd, bt_dev_t *dev)
1679 {
1680         FN_START;
1681
1682         bt_dev_t *item = NULL;
1683         Eina_List *l = NULL;
1684         Eina_List *l_next = NULL;
1685
1686         ret_if(ugd == NULL);
1687
1688         EINA_LIST_FOREACH_SAFE(ugd->searched_device, l, l_next, item) {
1689                 if (item && (item == dev)) {
1690                         if (dev->genlist_item) {
1691                                 elm_object_item_del(dev->genlist_item);
1692                                 dev->genlist_item = NULL;
1693                         }
1694                         ugd->searched_device =
1695                             eina_list_remove_list(ugd->searched_device, l);
1696                         _bt_util_free_device_item(item);
1697                 }
1698         }
1699
1700         if (ugd->searched_device == NULL ||
1701                         eina_list_count(ugd->searched_device) == 0) {
1702                 elm_object_item_del(ugd->searched_title);
1703                 ugd->searched_title = NULL;
1704         }
1705         FN_END;
1706         return;
1707 }
1708
1709 void _bt_main_remove_all_searched_devices(bt_ug_data *ugd)
1710 {
1711         FN_START;
1712
1713         bt_dev_t *dev = NULL;
1714         Eina_List *l = NULL;
1715         Eina_List *l_next = NULL;
1716         Elm_Object_Item *item;
1717         Elm_Object_Item *next;
1718
1719         ret_if(ugd == NULL);
1720
1721         if (ugd->searched_title) {
1722                 item = elm_genlist_item_next_get(ugd->searched_title);
1723                 elm_object_item_del(ugd->searched_title);
1724                 ugd->searched_title = NULL;
1725
1726                 while (item != NULL) {
1727                         next = elm_genlist_item_next_get(item);
1728                         elm_object_item_del(item);
1729                         item = next;
1730                 }
1731                 ugd->no_device_item = NULL;
1732         }
1733
1734         EINA_LIST_FOREACH_SAFE(ugd->searched_device, l, l_next, dev) {
1735                 ugd->searched_device =
1736                     eina_list_remove_list(ugd->searched_device, l);
1737                 _bt_util_free_device_item(dev);
1738         }
1739
1740         ugd->searched_device = NULL;
1741
1742         FN_END;
1743         return;
1744 }
1745
1746 void __bt_main_parse_service(bt_ug_data *ugd, app_control_h service)
1747 {
1748         char *launch_type = NULL;
1749         char *operation = NULL;
1750         char *mime = NULL;
1751         const char *uri = NULL;
1752         const char *file_path = NULL;
1753
1754         ret_if(ugd == NULL);
1755         ret_if(service == NULL);
1756
1757         if (app_control_get_operation(service, &operation) < 0)
1758                 BT_ERR("Get operation error");
1759
1760         BT_INFO("operation: %s", operation);
1761
1762         if (g_strcmp0(operation, BT_APPCONTROL_PICK_OPERATION) == 0) {
1763                 BT_DBG("Pick Operation");
1764                 launch_type = strdup("pick");
1765         } else if (g_strcmp0(operation, BT_APPCONTROL_VISIBILITY_OPERATION) == 0 ||
1766                                  g_strcmp0(operation, APP_CONTROL_OPERATION_SETTING_BT_VISIBILITY) == 0) {
1767                 BT_DBG("Visibility Operation");
1768                 launch_type = strdup("visibility");
1769         } else if (g_strcmp0(operation, BT_APPCONTROL_ONOFF_OPERATION) == 0 ||
1770                                  g_strcmp0(operation, APP_CONTROL_OPERATION_SETTING_BT_ENABLE) == 0) {
1771                 BT_DBG("onoff Operation");
1772                 launch_type = strdup("onoff");
1773         } else if (g_strcmp0(operation, APP_CONTROL_OPERATION_SHARE_CONTACT) == 0) {
1774                 BT_DBG("Share Contact Operation");
1775                 launch_type = strdup("contact");
1776         } else if (g_strcmp0(operation, BT_APPCONTROL_EDIT_OPERATION) == 0) {
1777                 BT_DBG("Edit Operation");
1778                 if (app_control_get_mime(service, &mime) < 0)
1779                         BT_ERR("Get mime error");
1780                 if (g_strcmp0(mime, BT_APPCONTROL_ONOFF_MIME) == 0)
1781                         launch_type = strdup("onoff");
1782                 else if (g_strcmp0(mime, BT_APPCONTROL_VISIBILITY_MIME) == 0)
1783                         launch_type = strdup("visibility");
1784         } else if (app_control_get_extra_data(service, "launch-type",
1785                                           &launch_type) == APP_CONTROL_ERROR_NONE) {
1786                 if (g_strcmp0(launch_type, "call") != 0) {
1787                         BT_DBG("launch-type : except call");
1788                         if (app_control_add_extra_data(service, "type", "file") < 0)
1789                                 BT_ERR("Fail to add extra data");
1790                 } else {
1791                         BT_DBG("launch-type : call");
1792                 }
1793         } else if (app_control_get_uri(service, (char **)&uri) == APP_CONTROL_ERROR_NONE &&
1794                         g_strcmp0(uri, HELP_SETUP_BLUETOOTH_URI) == 0) {
1795                 BT_DBG("Help mode");
1796                 launch_type = strdup("help");
1797         }
1798
1799         if (launch_type) {
1800                 BT_INFO("Launch with launch type [%s]", launch_type);
1801                 _bt_util_set_value(launch_type, &ugd->search_type,
1802                                    &ugd->bt_launch_mode);
1803         } else {
1804                 BT_DBG("launch type is NULL");
1805         }
1806
1807         if (uri)
1808                 free((void *)uri);
1809
1810         if (file_path)
1811                 free((void *)file_path);
1812
1813         if (launch_type)
1814                 free((void *)launch_type);
1815
1816         if (operation)
1817                 free(operation);
1818
1819         if (mime)
1820                 free(mime);
1821 }
1822
1823 void _bt_main_init_status(bt_ug_data *ugd, void *data)
1824 {
1825         FN_START;
1826
1827         app_control_h service = NULL;
1828         bool status = false;
1829         bt_adapter_state_e bt_state = BT_ADAPTER_DISABLED;
1830         ret_if(ugd == NULL);
1831
1832         service = data;
1833
1834         if (service != NULL) {
1835                 __bt_main_parse_service(ugd, service);
1836         } else {
1837                 ugd->search_type = MISCELLANEOUS_MAJOR_DEVICE_MASK;
1838                 ugd->bt_launch_mode = BT_LAUNCH_NORMAL;
1839         }
1840
1841         if (bt_emulator_get_state(&bt_state) != BT_ERROR_NONE)
1842                 BT_ERR("bt_adapter_get_state() failed");
1843
1844         if (bt_state == BT_ADAPTER_DISABLED) {
1845                 ugd->op_status = BT_DEACTIVATED;
1846         } else {
1847                 if (bt_emulator_is_discovering(&status) != BT_ERROR_NONE)
1848                 BT_ERR("bt_adapter_is_discovering() failed");
1849
1850                 if (status == true)
1851                         bt_emulator_stop_device_discovery();
1852
1853                 ugd->op_status = BT_ACTIVATED;
1854         }
1855
1856         FN_END;
1857 }
1858
1859 bt_dev_t *_bt_main_create_searched_device_item(void *data)
1860 {
1861         FN_START;
1862
1863         int i;
1864         unsigned char bd_addr[BT_ADDRESS_LENGTH_MAX];
1865         bt_dev_t *dev = NULL;
1866         bt_adapter_device_discovery_info_s *dev_info = NULL;
1867
1868         retv_if(data == NULL, NULL);
1869
1870         dev_info = (bt_adapter_device_discovery_info_s *) data;
1871
1872         if (strlen(dev_info->remote_name) == 0)
1873                 return NULL;
1874
1875         dev = calloc(1, sizeof(bt_dev_t));
1876         retv_if(dev == NULL, NULL);
1877
1878         strncpy(dev->name, dev_info->remote_name, DEVICE_NAME_MAX_LEN);
1879
1880         dev->major_class = dev_info->bt_class.major_device_class;
1881         dev->minor_class = dev_info->bt_class.minor_device_class;
1882         dev->service_class = dev_info->bt_class.major_service_class_mask;
1883         dev->rssi = dev_info->rssi;
1884
1885         if (dev_info->service_uuid != NULL && dev_info->service_count > 0) {
1886                 dev->uuids = g_new0(char *, dev_info->service_count + 1);
1887
1888                 for (i = 0; i < dev_info->service_count; i++)
1889                         dev->uuids[i] = g_strdup(dev_info->service_uuid[i]);
1890
1891                 dev->uuid_count = dev_info->service_count;
1892         }
1893
1894         _bt_util_addr_string_to_addr_type(bd_addr, dev_info->remote_address);
1895
1896         memcpy(dev->addr_str, dev_info->remote_address, BT_ADDRESS_STR_LEN);
1897
1898         memcpy(dev->bd_addr, bd_addr, BT_ADDRESS_LENGTH_MAX);
1899
1900         BT_DBG("device name [%s]", dev->name);
1901         BT_DBG("device major class [%x]", dev->major_class);
1902         BT_DBG("device minor class [%x]", dev->minor_class);
1903         BT_DBG("device service class [%x]", dev->service_class);
1904         BT_DBG("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X", dev->bd_addr[0],
1905                dev->bd_addr[1], dev->bd_addr[2], dev->bd_addr[3],
1906                dev->bd_addr[4], dev->bd_addr[5]);
1907
1908         FN_END;
1909         return dev;
1910 }
1911 static gboolean _bt_check_minor_class(unsigned int minor_class)
1912 {
1913         switch (minor_class) {
1914         case BTAPP_MIN_DEV_CLS_VIDEO_DISPLAY_AND_LOUD_SPEAKER:
1915                 return FALSE;
1916         case BTAPP_MIN_DEV_CLS_VIDEO_CONFERENCING:
1917                 return FALSE;
1918         case BTAPP_MIN_DEV_CLS_VIDEO_CAMERA:
1919                 return FALSE;
1920         case BTAPP_MIN_DEV_CLS_SET_TOP_BOX:
1921                 return FALSE;
1922         case BTAPP_MIN_DEV_CLS_VCR:
1923                 return FALSE;
1924         case BTAPP_MIN_DEV_CLS_CAM_CORDER:
1925                 return FALSE;
1926         default:
1927                 return TRUE;
1928         }
1929 }
1930
1931 gboolean _bt_main_is_matched_profile(unsigned int search_type,
1932                                      unsigned int major_class,
1933                                      unsigned int service_class,
1934                                      app_control_h service,
1935                                      unsigned int minor_class)
1936 {
1937         FN_START;
1938
1939         bt_device_major_mask_t major_mask = BT_DEVICE_MAJOR_MASK_MISC;
1940
1941         if (search_type == 0x000000)
1942                 return TRUE;
1943
1944         BT_INFO("search_type: %x", search_type);
1945         BT_INFO("service_class: %x", service_class);
1946
1947         /* Check the service_class */
1948         if (service_class & search_type) {
1949                 if (search_type & OBJECT_TRANSFER_MAJOR_SERVICE_MASK &&
1950                     major_class == BT_MAJOR_DEV_CLS_IMAGING) {
1951                         if (__bt_main_is_image_file(service))
1952                                 return TRUE;
1953                 } else {
1954                         return TRUE;
1955                 }
1956         }
1957         BT_INFO("major_class %x", major_class);
1958         BT_INFO("minor_class %x", minor_class);
1959         /* Check the major class */
1960         switch (major_class) {
1961         case BT_MAJOR_DEV_CLS_COMPUTER:
1962                 major_mask = BT_DEVICE_MAJOR_MASK_COMPUTER;
1963                 break;
1964         case BT_MAJOR_DEV_CLS_PHONE:
1965                 major_mask = BT_DEVICE_MAJOR_MASK_PHONE;
1966                 break;
1967         case BT_MAJOR_DEV_CLS_LAN_ACCESS_POINT:
1968                 major_mask = BT_DEVICE_MAJOR_MASK_LAN_ACCESS_POINT;
1969                 break;
1970         case BT_MAJOR_DEV_CLS_AUDIO:
1971                 if (_bt_check_minor_class(minor_class) == TRUE)
1972                         major_mask = BT_DEVICE_MAJOR_MASK_AUDIO;
1973                 else
1974                         major_mask = BT_DEVICE_MAJOR_MASK_MISC;
1975                 break;
1976         case BT_MAJOR_DEV_CLS_IMAGING:
1977                 major_mask = BT_DEVICE_MAJOR_MASK_IMAGING;
1978                 break;
1979         case BT_MAJOR_DEV_CLS_WEARABLE:
1980                 major_mask = BT_DEVICE_MAJOR_MASK_WEARABLE;
1981                 break;
1982         case BT_MAJOR_DEV_CLS_TOY:
1983                 major_mask = BT_DEVICE_MAJOR_MASK_TOY;
1984                 break;
1985         case BT_MAJOR_DEV_CLS_HEALTH:
1986                 major_mask = BT_DEVICE_MAJOR_MASK_HEALTH;
1987                 break;
1988         case BT_MAJOR_DEV_CLS_PERIPHERAL:
1989                 major_mask = BT_DEVICE_MAJOR_MASK_PERIPHERAL;
1990                 break;
1991         default:
1992                 major_mask = BT_DEVICE_MAJOR_MASK_MISC;
1993                 break;
1994         }
1995
1996         BT_INFO("major_mask: %x", major_mask);
1997
1998         if (search_type & major_mask)
1999                 return TRUE;
2000
2001         FN_END;
2002         return FALSE;
2003 }
2004
2005 bt_dev_t *_bt_main_get_dev_info(Eina_List *list,
2006                                 Elm_Object_Item *genlist_item)
2007 {
2008         FN_START;
2009
2010         bt_dev_t *item = NULL;
2011         Eina_List *l = NULL;
2012
2013         retvm_if(list == NULL, NULL, "Invalid argument: list is NULL");
2014         retvm_if(genlist_item == NULL, NULL, "Invalid argument: obj is NULL");
2015
2016         EINA_LIST_FOREACH(list, l, item) {
2017                 if (item) {
2018                         if (item->genlist_item == genlist_item)
2019                                 return item;
2020                 }
2021         }
2022
2023         FN_END;
2024         return NULL;
2025 }
2026
2027 bt_dev_t *_bt_main_get_dev_info_by_address(Eina_List *list, char *address)
2028 {
2029         FN_START;
2030
2031         bt_dev_t *item = NULL;
2032         Eina_List *l = NULL;
2033
2034         retvm_if(list == NULL, NULL, "Invalid argument: list is NULL");
2035         retvm_if(address == NULL, NULL, "Invalid argument: addr is NULL");
2036
2037         EINA_LIST_FOREACH(list, l, item) {
2038                 if (item) {
2039                         if (memcmp(item->addr_str, address, BT_ADDRESS_STR_LEN)
2040                             == 0)
2041                                 return item;
2042                 }
2043         }
2044
2045         FN_END;
2046         return NULL;
2047 }
2048
2049 int _bt_main_check_and_update_device(Eina_List *list, char *addr, char *name)
2050 {
2051         FN_START;
2052
2053         bt_dev_t *item = NULL;
2054         Eina_List *l = NULL;
2055
2056         retv_if(list == NULL, -1);
2057         retv_if(addr == NULL, -1);
2058         retv_if(name == NULL, -1);
2059
2060         EINA_LIST_FOREACH(list, l, item) {
2061                 if (item) {
2062                         if (memcmp(item->addr_str, addr, BT_ADDRESS_STR_LEN) ==
2063                             0) {
2064                                 memset(item->name, 0x00,
2065                                        DEVICE_NAME_MAX_LEN+1);
2066                                 g_strlcpy(item->name, name,
2067                                           DEVICE_NAME_MAX_LEN);
2068                                 return 0;
2069                         }
2070                 }
2071         }
2072
2073         FN_END;
2074
2075         return -1;
2076 }
2077
2078 void _bt_main_launch_syspopup(void *data, char *event_type, char *title,
2079                               char *type)
2080 {
2081         FN_START;
2082
2083         int ret = 0;
2084         bt_ug_data *ugd = NULL;
2085         bundle *b = NULL;
2086
2087         ret_if(event_type == NULL);
2088         ret_if(type == NULL);
2089
2090         ugd = (bt_ug_data *)data;
2091
2092         b = bundle_create();
2093         ret_if(b == NULL);
2094
2095         if (event_type)
2096                 bundle_add_str(b, "event-type", event_type);
2097         if (title)
2098                 bundle_add_str(b, "title", title);
2099         if (type)
2100                 bundle_add_str(b, "type", type);
2101
2102         ret = syspopup_launch("bt-syspopup", b);
2103         if (0 > ret) {
2104                 BT_ERR("Popup launch failed...retry %d", ret);
2105                 ugd->popup_bundle = b;
2106                 ugd->popup_timer =
2107                     g_timeout_add(BT_UG_SYSPOPUP_TIMEOUT_FOR_MULTIPLE_POPUPS,
2108                                   (GSourceFunc) __bt_main_system_popup_timer_cb,
2109                                   ugd);
2110         } else {
2111                 bundle_free(b);
2112         }
2113         FN_END;
2114 }
2115
2116 void _bt_main_create_information_popup(void *data, char *msg)
2117 {
2118         FN_START;
2119         ret_if(data == NULL);
2120         bt_ug_data *ugd = (bt_ug_data *)data;
2121
2122         _bt_main_popup_del_cb(data, NULL, NULL);
2123
2124         ugd->popup_data.type = BT_POPUP_LOW_BATTERY;
2125         ugd->popup = _bt_create_popup(ugd,
2126                 _bt_main_popup_del_cb, ugd, 2);
2127         retm_if(!ugd->popup , "fail to create popup!");
2128
2129         eext_object_event_callback_add(ugd->popup, EEXT_CALLBACK_BACK,
2130                         _bt_main_popup_del_cb, ugd);
2131
2132         evas_object_show(ugd->popup);
2133         FN_END;
2134 }
2135
2136 void _bt_main_add_searched_title(bt_ug_data *ugd)
2137 {
2138         FN_START;
2139         Elm_Object_Item *git = NULL;
2140
2141         git = elm_genlist_item_append(ugd->main_genlist,
2142                                         ugd->searched_title_itc,
2143                                         (void *)ugd, NULL,
2144                                         ELM_GENLIST_ITEM_NONE, NULL, NULL);
2145         if (git) {
2146                 elm_genlist_item_select_mode_set(git,
2147                                          ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
2148                 ugd->searched_title = git;
2149         } else {
2150                 BT_ERR("fail to append genlist item!");
2151         }
2152
2153         FN_END;
2154 }
2155
2156 void _bt_update_device_list(bt_ug_data *ugd)
2157 {
2158         Eina_List *l = NULL;
2159         bt_dev_t *dev = NULL;
2160
2161         ret_if(ugd == NULL);
2162
2163         EINA_LIST_FOREACH(ugd->searched_device, l, dev) {
2164                 if (dev)
2165                         _bt_update_genlist_item((Elm_Object_Item *)
2166                                                 dev->genlist_item);
2167         }
2168 }