Modify the genlist item style for IOT profile
[apps/native/bluetooth-share-ui.git] / src / bt-share-ui-view.c
1 /*
2 * bluetooth-share-ui
3 *
4 * Copyright 2012 Samsung Electronics Co., Ltd
5 *
6 * Contact: Hocheol Seo <hocheol.seo@samsung.com>
7 *           GirishAshok Joshi <girish.joshi@samsung.com>
8 *           DoHyun Pyun <dh79.pyun@samsung.com>
9 *
10 * Licensed under the Flora License, Version 1.1 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.tizenopensource.org/license
15 *
16 * Unless required by applicable law or agreed to in writing,
17 * software distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 *
22 */
23
24 #include <glib.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <time.h>
28 #if 0
29 #include <Ecore_X.h>
30 #include <utilX.h>
31 #endif
32 #include <Elementary.h>
33 #include <efl_extension.h>
34 #include <aul.h>
35 #include <app.h>
36 #include <vconf.h>
37 #include <vconf-keys.h>
38 #include <bluetooth-share-api.h>
39 #include <bluetooth_internal.h>
40 #include <notification.h>
41 #include <notification_internal.h>
42 #include <notification_list.h>
43
44 #include "applog.h"
45 #include "bt-share-ui-view.h"
46 #include "bt-share-ui-popup.h"
47 #include "bt-share-ui-ipc.h"
48 #include "bt-share-ui-resource.h"
49 #include "bt-share-ui-widget.h"
50 #include "bt-share-ui-main.h"
51
52 #define NOTI_OPS_APP_ID "bluetooth-share-opp-server"
53 #define NOTI_OPC_APP_ID "bluetooth-share-opp-client"
54
55 #define BT_DEFAULT_MEM_PHONE 0
56 #define BT_DEFAULT_MEM_MMC 1
57
58 #define BT_DOWNLOAD_PHONE_FOLDER "/opt/usr/media/Downloads"
59 #define BT_DOWNLOAD_MMC_FOLDER "/opt/media/SDCardA1"
60 #define BT_CONTACT_SHARE_TMP_DIR BT_DOWNLOAD_PHONE_FOLDER "/.bluetooth"
61
62 extern bt_share_appdata_t *app_state;
63
64 static Evas_Object *__bt_add_tr_data_genlist(Evas_Object *parent,
65                                                   bt_share_appdata_t *ad);
66
67 void _bt_delete_selected_notification(bt_share_tr_type_e tr_type,
68                                         int noti_id, const char *opp_role)
69 {
70         notification_list_h list_head;
71         notification_list_h list_traverse;
72         notification_h noti;
73         int priv_id;
74
75         notification_get_list(NOTIFICATION_TYPE_NOTI, -1, &list_head);
76         list_traverse = list_head;
77
78         while (list_traverse != NULL) {
79                 noti = notification_list_get_data(list_traverse);
80                 notification_get_id(noti, NULL, &priv_id);
81                 if (priv_id == noti_id) {
82                         DBG_SECURE("Deleting Notification ID: %d", noti_id);
83                         if (notification_delete_by_priv_id(opp_role,
84                                         NOTIFICATION_TYPE_NOTI, priv_id)
85                                         != NOTIFICATION_ERROR_NONE)
86                                 ERR("Could Not Delete Notification");
87                         break;
88                 }
89                 list_traverse = notification_list_get_next(list_traverse);
90         }
91 }
92
93 static void __bt_get_noti_id_opp_role_and_table(bt_share_appdata_t *ad, int *noti_id,
94                 char **opp_role, bt_tr_db_table_e *table)
95 {
96         sqlite3 *db = bt_share_open_db();
97
98         if (ad->tr_type == BT_TR_OUTBOUND) {
99                 *noti_id = bt_share_get_noti_id(db, BT_DB_OUTBOUND, ad->transfer_info->db_sid);
100                 *opp_role = NOTI_OPC_APP_ID;
101                 *table = BT_DB_OUTBOUND;
102         } else {
103                 *noti_id = bt_share_get_noti_id(db, BT_DB_INBOUND, ad->transfer_info->db_sid);
104                 *opp_role = NOTI_OPS_APP_ID;
105                 *table = BT_DB_INBOUND;
106         }
107
108         bt_share_close_db(db);
109 }
110
111 void _bt_share_ui_handle_transfer_disconnected(bt_share_appdata_t *ad,
112                 bt_share_tr_type_e type)
113 {
114         FN_START;
115         ret_if(ad == NULL);
116
117         if (ad->progress_item) {
118                 DBG("Updating Status");
119                 Elm_Object_Item *git = elm_genlist_item_insert_after(ad->tr_genlist,
120                                 ad->tr_status_itc, ad, NULL,
121                                 ad->device_item, ELM_GENLIST_ITEM_NONE,
122                                 NULL, NULL);
123                 if (git == NULL) {
124                         ERR("elm_genlist_item_insert_after is failed!");
125                 } else {
126                         elm_genlist_item_select_mode_set(git,
127                                                  ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
128                         ad->status_item = git;
129                 }
130
131                 elm_object_item_del(ad->progress_item);
132                 ad->progress_item = NULL;
133                 ad->progressbar = NULL;
134         }
135
136         FN_END;
137 }
138
139 void _bt_share_ui_handle_transfer_complete(bt_share_appdata_t *ad,
140                 char *address, bt_share_tr_type_e type)
141 {
142         FN_START;
143         ret_if(ad == NULL || ad->transfer_info == NULL || ad->transfer_info->device_address == NULL);
144         DBG_SECURE("Received Address: %s", address);
145         DBG_SECURE("Device Address: %s", ad->transfer_info->device_address);
146
147         ret_if(g_strcmp0(ad->transfer_info->device_address, address));
148
149         FN_END;
150 }
151
152 void _bt_share_ui_handle_transfer_started(bt_share_appdata_t *ad,
153                 char *address, char *file_name, unsigned long size, int transfer_id,
154                 bt_share_tr_type_e type)
155 {
156         FN_START;
157         ret_if(ad == NULL || ad->transfer_info == NULL || ad->transfer_info->device_address == NULL);
158         DBG_SECURE("Received Address: %s", address);
159         DBG_SECURE("Device Address: %s", ad->transfer_info->device_address);
160         ret_if(g_strcmp0(ad->transfer_info->device_address, address));
161
162         ad->transfer_info->filename = g_strdup(file_name);
163         DBG_SECURE("Transfer ID: %d", transfer_id);
164         ad->transfer_info->size = size;
165         ad->transfer_info->percentage = 0;
166         ad->transfer_info->current_file++;
167
168         if (ad->status_item) {
169                 elm_object_item_del(ad->status_item);
170                 ad->status_item = NULL;
171         }
172
173         if (ad->progress_item) {
174                 _bt_share_genlist_item_text_update(ad->progress_item, BT_SHARE_ITEM_PART_PROGRESSBAR_FILE_NAME);
175                 _bt_share_genlist_item_content_update(ad->progress_item, BT_SHARE_ITEM_PART_PROGRESSBAR_ICON);
176         } else {
177                 /* Create Progress bar if not present */
178                 Elm_Object_Item *git = elm_genlist_item_insert_after(ad->tr_genlist,
179                                 ad->tr_progress_itc, ad, NULL, ad->device_item,
180                                 ELM_GENLIST_ITEM_NONE, NULL, NULL);
181                 if (git == NULL) {
182                         ERR("elm_genlist_item_append is failed!");
183                 } else {
184                         elm_genlist_item_select_mode_set(git,
185                                                  ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
186                         ad->progress_item = git;
187                 }
188         }
189
190         if (!ad->toolbar_button) {
191                 /* Create Stop Button if not present */
192                 ad->toolbar_button = _bt_share_create_toolbar_button(ad,
193                                 BT_STR_STOP);
194         }
195
196         FN_END;
197 }
198
199 Evas_Object *_bt_create_win(const char *name)
200 {
201         Evas_Object *eo = NULL;
202
203         eo = elm_win_add(NULL, name, ELM_WIN_BASIC);
204         retv_if(!eo, NULL);
205
206         elm_win_title_set(eo, name);
207         elm_win_borderless_set(eo, EINA_TRUE);
208         return eo;
209 }
210
211 void _bt_terminate_app(void)
212 {
213         DBG("Terminate BT SHARE UI");
214         elm_exit();
215 }
216
217 static void __bt_clear_view(void *data)
218 {
219         DBG("+");
220
221         bt_share_appdata_t *ad = (bt_share_appdata_t *)data;
222         ret_if(!ad);
223
224         if (ad->tr_genlist) {
225                 elm_genlist_clear(ad->tr_genlist);
226                 ad->tr_genlist = NULL;
227                 ad->device_item = NULL;
228                 ad->progress_item = NULL;
229                 ad->status_item = NULL;
230                 ad->file_title_item = NULL;
231                 ad->tr_data_itc = NULL;
232                 ad->progressbar = NULL;
233         }
234
235         if (ad->navi_fr) {
236                 evas_object_del(ad->navi_fr);
237                 ad->navi_fr = NULL;
238         }
239
240         if (ad->tr_view) {
241                 evas_object_del(ad->tr_view);
242                 ad->tr_view = NULL;
243         }
244         DBG("-");
245 }
246
247 static Eina_Bool __bt_back_button_cb(void *data, Elm_Object_Item *it)
248 {
249         DBG("pop current view ");
250         retvm_if(!data, EINA_FALSE, "invalid parameter!");
251
252         bt_share_appdata_t *ad = (bt_share_appdata_t *)data;
253         int ret;
254
255         __bt_clear_view(data);
256
257         if (ad->tr_data_list) {
258                 ret = bt_share_release_tr_data_list(ad->tr_data_list);
259
260                 if (ret != BT_SHARE_ERR_NONE)
261                         ERR("Transfer data release failed ");
262                 ad->tr_data_list = NULL;
263         }
264
265         _bt_terminate_app();
266
267         return EINA_FALSE;
268 }
269
270 static Evas_Object *__bt_tr_progress_icon_get(void *data, Evas_Object *obj,
271                                             const char *part)
272 {
273         FN_START;
274
275         Evas_Object *progress_layout = NULL;
276         Evas_Object *progressbar = NULL;
277         bt_share_appdata_t *ad = NULL;
278
279         retv_if(data == NULL, NULL);
280         ad = (bt_share_appdata_t *)data;
281
282         bt_share_transfer_data_t *transfer_info = ad->transfer_info;
283
284         if (!strcmp(part, BT_SHARE_ITEM_PART_PROGRESSBAR_ICON)) {
285                 char buff[BT_STR_PROGRESS_MAX_LEN] = { 0, };
286                 char *markup_text = NULL;
287
288                 DBG("Creating new progress layout!!!");
289                 progress_layout = elm_layout_add(obj);
290                 elm_layout_file_set(progress_layout, EDJFILE, "popup_text_progressbar_view_layout");
291                 evas_object_size_hint_align_set(progress_layout, EVAS_HINT_FILL,
292                                 EVAS_HINT_FILL);
293                 evas_object_size_hint_weight_set(progress_layout, EVAS_HINT_EXPAND,
294                                 EVAS_HINT_EXPAND);
295                 evas_object_show(progress_layout);
296
297                 DBG("Creating new progressbar!!!");
298                 progressbar = elm_progressbar_add(progress_layout);
299
300                 elm_progressbar_unit_format_set(progressbar, NULL);
301                 elm_progressbar_horizontal_set(progressbar, EINA_TRUE);
302                 evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL,
303                                 EVAS_HINT_FILL);
304                 evas_object_size_hint_weight_set(progressbar, EVAS_HINT_EXPAND,
305                                 EVAS_HINT_EXPAND);
306                 elm_progressbar_pulse(progressbar, EINA_TRUE);
307
308                 evas_object_show(progressbar);
309                 ad->progressbar = progressbar;
310
311                 markup_text = elm_entry_utf8_to_markup(transfer_info->filename);
312                 DBG_SECURE("Filename: %s", markup_text);
313
314                 DBG("Filename: %s", markup_text);
315
316                 elm_object_part_text_set(progress_layout, "elm.text.description", markup_text);
317                 g_free(markup_text);
318
319                 elm_object_part_content_set(progress_layout, "progressbar", progressbar);
320
321                 elm_progressbar_value_set(progressbar,
322                                 (double) transfer_info->percentage / 100);
323
324                 elm_object_signal_emit(progressbar, "elm,bottom,text,show", "elm");
325
326                 snprintf(buff, BT_STR_PROGRESS_MAX_LEN - 1 , "%d%%", transfer_info->percentage);
327                 elm_object_part_text_set(progressbar, "elm.text.bottom.left", buff);
328
329                 if (ad->launch_mode == BT_LAUNCH_ONGOING &&
330                                 ad->tr_type == BT_TR_OUTBOUND) {
331                         memset(buff, 0, BT_STR_PROGRESS_MAX_LEN);
332                         snprintf(buff, BT_STR_PROGRESS_MAX_LEN - 1 , "[%d/%d]",
333                                         transfer_info->current_file, transfer_info->total_files);
334                         elm_object_part_text_set(progressbar, "elm.text.bottom.right", buff);
335                 }
336         }
337
338         return progress_layout;
339 }
340
341 static Evas_Object *__bt_tr_icon_get(void *data, Evas_Object *obj,
342                                             const char *part)
343 {
344         Evas_Object *ly = NULL;
345         Evas_Object *icon = NULL;
346         bt_tr_data_t *info = NULL;
347         bt_share_appdata_t *ad = app_state;
348         char *img = NULL;
349         bt_gl_data_t *gl_data = NULL;
350
351         retv_if(!data, NULL);
352         gl_data = (bt_gl_data_t *)data;
353
354         info = gl_data->tr_data;
355         retv_if(!info, NULL);
356
357         if (!strcmp(part, BT_SHARE_ITEM_PART_FILE_TRANSFER_STATUS_ICON)) {
358                 ly = elm_layout_add(obj);
359                 if (info->tr_status == BT_TRANSFER_SUCCESS ||
360                                 info->tr_status == BT_TRANSFER_FAIL) {
361                         icon = elm_image_add(obj);
362                         if (ad->tr_type == BT_TR_OUTBOUND) {
363                                 img = (info->tr_status == BT_TRANSFER_SUCCESS) ?
364                                                 BT_ICON_SEND_PASS : BT_ICON_SEND_FAIL;
365                         } else {
366                                 img = (info->tr_status == BT_TRANSFER_SUCCESS) ?
367                                                 BT_ICON_RECV_PASS : BT_ICON_RECV_FAIL;
368                         }
369
370                         elm_image_file_set(icon, EDJ_IMAGES, img);
371                         evas_object_size_hint_align_set(icon, EVAS_HINT_FILL,
372                                         EVAS_HINT_FILL);
373                         evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND,
374                                         EVAS_HINT_EXPAND);
375
376                         evas_object_show(icon);
377                         evas_object_size_hint_min_set(icon, ELM_SCALE_SIZE(40), ELM_SCALE_SIZE(40));
378                         return icon;
379                 } else if (info->tr_status == BT_TRANSFER_ONGOING) {
380 #if 0
381                         int ret;
382                         ret = elm_layout_file_set(ly, EDJ_BT_ICON_ANIMATION,
383                                 (ad->tr_type == BT_TR_OUTBOUND ? BT_ANI_UPLOAD : BT_ANI_DOWNLOAD));
384                         if (ret == EINA_FALSE)
385                                 ERR("Error in setting layout file");
386 #endif
387                         icon = elm_progressbar_add(obj);
388
389                         if (TIZEN_COMMON)
390                                 elm_object_style_set(icon, "process_small");
391                         else
392                                 elm_object_style_set(icon, "process_medium");
393
394                         evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, 0.5);
395                         evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
396                         elm_progressbar_pulse(icon, TRUE);
397                         return icon;
398                 } else if (info->tr_status == BT_TRANSFER_PENDING) {
399                         icon = elm_progressbar_add(obj);
400
401                         if (TIZEN_COMMON)
402                                 elm_object_style_set(icon, "process_small");
403                         else
404                                 elm_object_style_set(icon, "process_medium");
405
406                         evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, 0.5);
407                         evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
408                         elm_progressbar_pulse(icon, TRUE);
409                         return icon;
410                 }
411         }
412         return ly;
413 }
414
415 #if 0
416 void _bt_util_get_number(char *source, char *dest)
417 {
418         int len = 7;
419         int slen = 0;
420         char buf[9];
421
422         slen = strlen(source);
423         slen--;
424         buf[8] = '\0';
425         while (len > -1) {
426                 if (slen > -1) {
427                         if (isdigit(source[slen])) {
428                                 buf[len] = source[slen];
429                                 --len;
430                         }
431                         --slen;
432                 } else {
433                         break;
434                 }
435         }
436         if (len < 0)
437                 len = 0;
438         strcpy(dest, &buf[len]);
439 }
440
441 void _bt_util_get_contact_name(int lcontact_id, char **contact_name)
442 {
443         int ret = 0;
444         int count = 0;
445         contacts_filter_h filter = NULL;
446         contacts_query_h query = NULL;
447         contacts_list_h list = NULL;
448         contacts_record_h record = NULL;
449         char *name = NULL;
450
451         DBG("+");
452         ret = contacts_filter_create(_contacts_contact._uri, &filter);
453         if (ret != CONTACTS_ERROR_NONE) {
454                 ERR("Fail to create filter for contacts");
455                 goto fail;
456         }
457
458         ret = contacts_filter_add_int(filter, _contacts_contact.id,
459                         CONTACTS_MATCH_EXACTLY, lcontact_id);
460         if (ret != CONTACTS_ERROR_NONE) {
461                 ERR("Fail to add str to filter for contacts");
462                 goto fail;
463         }
464
465         ret = contacts_query_create(_contacts_contact._uri, &query);
466         if (ret != CONTACTS_ERROR_NONE) {
467                 ERR("Fail to create qurey for contacts");
468                 goto fail;
469         }
470
471         ret = contacts_query_set_filter(query, filter);
472         if (ret != CONTACTS_ERROR_NONE) {
473                 ERR("Fail to set filter for contacts");
474                 goto fail;
475         }
476
477         ret = contacts_db_get_count_with_query(query, &count);
478         if (ret != CONTACTS_ERROR_NONE) {
479                 ERR("Fail to get count from db");
480                 goto fail;
481         }
482
483         if (count < 1) {
484                 DBG("No match");
485                 goto fail;
486         }
487         DBG("count = %d", count);
488         ret = contacts_db_get_records_with_query(query, 0, 0, &list);
489         if (ret != CONTACTS_ERROR_NONE) {
490                 ERR("Fail to get records from db");
491                 goto fail;
492         }
493         contacts_list_first(list);
494
495         while (ret == CONTACTS_ERROR_NONE) {
496                 contacts_list_get_current_record_p(list, &record);
497                 contacts_record_get_str_p(record,
498                                 _contacts_contact.display_name,
499                                 &name);
500                 if (name != NULL) {
501                         *contact_name = g_strdup(name);
502                         break;
503                 }
504
505                 ret = contacts_list_next(list);
506         }
507
508 fail:
509         if (filter)
510                 contacts_filter_destroy(filter);
511
512         if (query)
513                 contacts_query_destroy(query);
514
515         if (list)
516                 contacts_list_destroy(list, true);
517         DBG("-");
518         return;
519 }
520
521 unsigned int bt_crc32(const void *src, unsigned long src_sz)
522 {
523         return (crc32(0, src, src_sz) & 0xFFFF);
524 }
525
526 void _bt_util_get_contact_info(unsigned char *auth_info, int *contact_id, char **contact_name)
527 {
528         unsigned int shash = 0;
529         unsigned int chash = 0;
530         char pnumber[20] = {0,};
531         char str_hash[7] = {0,};
532         int ret = CONTACTS_ERROR_NONE;
533         char *number = NULL;
534         int lcontact_id = 0;
535         int count = 0;
536
537         contacts_filter_h filter = NULL;
538         contacts_query_h query = NULL;
539         contacts_list_h list = NULL;
540         contacts_record_h record = NULL;
541
542         retm_if(!auth_info, "auth_info is NULL");
543         retm_if(!contact_id, "contact_id is NULL");
544         retm_if(!contact_name, "contact_name is NULL");
545         DBG("+");
546         if (contacts_connect() != CONTACTS_ERROR_NONE) {
547                 ERR("contacts_connect failed");
548                 return;
549         }
550
551         memcpy(&shash, auth_info, 3);
552         shash = ntohl(shash);
553         shash >>= 8;
554
555         memcpy(&chash, &auth_info[3], 2);
556         chash = ntohl(chash);
557         chash >>= 16;
558
559         g_snprintf(str_hash, 7, "%X", shash);
560
561         ret = contacts_filter_create(_contacts_quick_connect_info._uri, &filter);
562         if (ret != CONTACTS_ERROR_NONE) {
563                 ERR("Fail to create filter for contacts");
564                 goto fail;
565         }
566
567         ret = contacts_filter_add_str(filter, _contacts_quick_connect_info.hash,
568                         CONTACTS_MATCH_EXACTLY, str_hash);
569         if (ret != CONTACTS_ERROR_NONE) {
570                 ERR("Fail to add str to filter for contacts");
571                 goto fail;
572         }
573
574         ret = contacts_query_create(_contacts_quick_connect_info._uri, &query);
575         if (ret != CONTACTS_ERROR_NONE) {
576                 ERR("Fail to create qurey for contacts");
577                 goto fail;
578         }
579
580         ret = contacts_query_set_filter(query, filter);
581         if (ret != CONTACTS_ERROR_NONE) {
582                 ERR("Fail to set filter for contacts");
583                 goto fail;
584         }
585
586         ret = contacts_db_get_count_with_query(query, &count);
587         if (ret != CONTACTS_ERROR_NONE) {
588                 ERR("Fail to get count from db");
589                 goto fail;
590         }
591
592         if (count < 1) {
593                 DBG("No match");
594                 goto fail;
595         }
596
597         ret = contacts_db_get_records_with_query(query, 0, 0, &list);
598         if (ret != CONTACTS_ERROR_NONE) {
599                 ERR("Fail to get records from db");
600                 goto fail;
601         }
602
603         contacts_list_first(list);
604
605         while (ret == CONTACTS_ERROR_NONE) {
606                 contacts_list_get_current_record_p(list, &record);
607                 contacts_record_get_str_p(record,
608                                 _contacts_quick_connect_info.number,
609                                 &number);
610                 DBG_SECURE("number: [%s]", number);
611                 if (number != NULL) {
612                         _bt_util_get_number(number, pnumber);
613                         DBG_SECURE("pnumber: [%s]", pnumber);
614
615                         DBG_SECURE("CRC [%X], [%X]", chash, bt_crc32(pnumber, strlen(pnumber)));
616
617                         if (bt_crc32(pnumber , strlen(pnumber)) == chash) {
618                                 contacts_record_get_int(record,
619                                                 _contacts_quick_connect_info.contact_id,
620                                                 &lcontact_id);
621                                 *contact_id = lcontact_id;
622                                 _bt_util_get_contact_name(lcontact_id, contact_name);
623                                 DBG_SECURE("contact id : %d", lcontact_id);
624                                 break;
625                         }
626                 }
627                 ret = contacts_list_next(list);
628         }
629
630 fail:
631         if (filter)
632                 contacts_filter_destroy(filter);
633
634         if (query)
635                 contacts_query_destroy(query);
636
637         if (list)
638                 contacts_list_destroy(list, true);
639
640         contacts_disconnect();
641
642         DBG("-");
643 }
644 #endif
645
646 static char *__bt_tr_device_label_get(void *data, Evas_Object *obj,
647                                       const char *part)
648 {
649         FN_START;
650         retv_if(data == NULL, NULL);
651         bt_share_appdata_t *ad = (bt_share_appdata_t *)data;
652         char *markup_text = NULL;
653
654         retv_if(ad->transfer_info == NULL, NULL);
655
656         if (!strcmp(part, BT_SHARE_ITEM_PART_DEVICE_NAME_TITLE) ||
657                  !strcmp(part, BT_SHARE_ITEM_PART_DEVICE_NAME_TITLE_COMMON)) {
658                 return g_strdup(BT_STR_DEVICENAME);
659         } else if (!strcmp(part, BT_SHARE_ITEM_PART_DEVICE_NAME) ||
660                                 !strcmp(part, BT_SHARE_ITEM_PART_DEVICE_NAME_COMMON)) {
661                 bt_share_transfer_data_t *transfer_info = ad->transfer_info;
662                 DBG_SECURE("Device : %s", transfer_info->device_name);
663                 if (ad->bt_status == BT_ADAPTER_ENABLED) {
664                         bt_error_e ret = BT_ERROR_NONE;
665                         bt_device_info_s *dev_info = NULL;
666
667                         /* Get the contact name from manufacturer data */
668                         DBG_SECURE("Address : %s", transfer_info->device_address);
669                         ret =  bt_adapter_get_bonded_device_info(transfer_info->device_address, &dev_info);
670                         if (ret == BT_ERROR_NONE) {
671                                 DBG_SECURE("Using remote name [%s] only.", dev_info->remote_name);
672                                 markup_text = elm_entry_utf8_to_markup(dev_info->remote_name);
673 #if 0
674                                 unsigned char auth_info[5] = {0, };
675                                 int contact_id = -1;
676                                 char *contact_name = NULL;
677                                 gboolean is_alias_set = FALSE;
678                                 ret = bt_adapter_get_bonded_device_is_alias_set(dev_info->remote_address, &is_alias_set);
679                                 if (ret != BT_ERROR_NONE)
680                                         ERR("bt_adapter_get_bonded_device_is_alias_set() is failed!!! error: 0x%04X", ret);
681
682                                 if (is_alias_set == TRUE) {
683                                         DBG_SECURE("Device alias is set. Using remote name [%s] only.", dev_info->remote_name);
684                                         markup_text = elm_entry_utf8_to_markup(dev_info->remote_name);
685                                 } else if (dev_info->manufacturer_data_len >= 30 &&
686                                                 dev_info->manufacturer_data[0] == 0x00 &&
687                                                 dev_info->manufacturer_data[1] == 0x75) {
688                                         unsigned char auth_info_null[5];
689                                         memset(auth_info_null, 0X0, 5);
690                                         memcpy(auth_info, &(dev_info->manufacturer_data[10]), 5);
691
692                                         /* Check for validity of auth_info */
693                                         if (memcmp(auth_info, auth_info_null, 5)) {
694                                                 _bt_util_get_contact_info(auth_info, &contact_id, &contact_name);
695                                                 DBG_SECURE("contact id : %d | contact name : %s", contact_id, contact_name);
696                                                 if (contact_name) {
697                                                         markup_text = elm_entry_utf8_to_markup(contact_name);
698                                                         g_free(contact_name);
699                                                 }
700                                         }
701                                 }
702 #endif
703                                 bt_adapter_free_device_info(dev_info);
704                         } else {
705                                 ERR("bt_adapter_get_bonded_device_info() is failed!!! error: 0x%04X", ret);
706                         }
707                 }
708
709                 if (!markup_text)
710                         markup_text = elm_entry_utf8_to_markup(transfer_info->device_name);
711
712                 return markup_text;
713         }
714         FN_END;
715         return NULL;
716 }
717
718 static char *__bt_tr_status_label_get(void *data, Evas_Object *obj,
719                                       const char *part)
720 {
721         FN_START;
722         retv_if(data == NULL, NULL);
723         bt_share_appdata_t *ad = (bt_share_appdata_t *)data;
724         bt_share_transfer_data_t *transfer_info = ad->transfer_info;
725         char *tmp_success = NULL;
726         char *tmp_failed = NULL;
727         char *ret_str = NULL;
728
729         retv_if(transfer_info == NULL, NULL);
730
731         if (!strcmp(part, BT_SHARE_ITEM_PART_TRANSFER_TYPE_TITLE)) {
732                 if (ad->tr_type == BT_TR_INBOUND)
733                         return (transfer_info->success > 0) ?
734                                 g_strdup(BT_STR_FILE_RECEIVED) :
735                                 g_strdup(BT_STR_RECEIVING_FAILED);
736                 else
737                         return (transfer_info->success > 0) ?
738                                 g_strdup(BT_STR_FILE_SENT) :
739                                 g_strdup(BT_STR_SENDING_FAILED);
740         } else if (!strcmp(part, BT_SHARE_ITEM_PART_TRANSFER_STATUS)) {
741                 char *stms_str = NULL;
742
743                 DBG_SECURE("Success %d, Failed %d", transfer_info->success, transfer_info->failed);
744                 if (transfer_info->success == 0 &&
745                                 transfer_info->failed == 0)
746                         return NULL;
747
748                 stms_str = (ad->tr_type == BT_TR_INBOUND) ? BT_STR_PD_RECEIVED : BT_STR_PD_SENT;
749                 tmp_success = g_strdup_printf(stms_str, transfer_info->success);
750
751                 stms_str = BT_STR_PD_FAILED;
752                 tmp_failed = g_strdup_printf(stms_str, transfer_info->failed);
753
754                 ret_str = g_strdup_printf("%s, %s", tmp_success, tmp_failed);
755
756                 g_free(tmp_success);
757                 g_free(tmp_failed);
758                 return ret_str;
759         }
760         FN_END;
761         return NULL;
762 }
763
764 #if 0
765 static char *__bt_tr_progress_label_get(void *data, Evas_Object *obj,
766                                       const char *part)
767 {
768         FN_START;
769         retv_if(data == NULL, NULL);
770         bt_share_appdata_t *ad = (bt_share_appdata_t *)data;
771         char *markup_text = NULL;
772
773         retv_if(ad->transfer_info == NULL, NULL);
774
775         if (!strcmp(part, BT_SHARE_ITEM_PART_PROGRESSBAR_FILE_NAME)) {
776                 bt_share_transfer_data_t *transfer_info = ad->transfer_info;
777                 markup_text = elm_entry_utf8_to_markup(transfer_info->filename);
778                 DBG_SECURE("Filename: %s", markup_text);
779                 return markup_text;
780         }
781
782         FN_END;
783         return NULL;
784 }
785 #endif
786
787 static char *__bt_tr_file_title_label_get(void *data, Evas_Object *obj,
788                                       const char *part)
789 {
790         FN_START;
791         if (!strcmp(part, BT_SHARE_ITEM_PART_FILE_LIST_TITLE)) {
792                 DBG("File List");
793                 return g_strdup(BT_STR_FILE_LIST);
794         }
795         FN_END;
796         return NULL;
797 }
798
799 static char *__bt_tr_label_get(void *data, Evas_Object *obj,
800                                       const char *part)
801 {
802         FN_START;
803         bt_tr_data_t *info = NULL;
804         char *name = NULL;
805         char buf[BT_GLOBALIZATION_STR_LENGTH] = { 0 };
806         bt_gl_data_t *gl_data = NULL;
807         char *markup_text = NULL;
808         retv_if(data == NULL, NULL);
809         gl_data = (bt_gl_data_t *)data;
810         retvm_if(gl_data == NULL, NULL, "gl_data is NULL!");
811
812         info = gl_data->tr_data;
813         retv_if(info == NULL, NULL);
814
815         if (!strcmp(part, BT_SHARE_ITEM_PART_FILE_NAME)) {
816                 name = strrchr(info->file_path, '/');
817                 if (name != NULL)
818                         name++;
819                 else
820                         name = info->file_path;
821                 markup_text = elm_entry_utf8_to_markup(name);
822
823                 g_strlcpy(buf, markup_text, BT_GLOBALIZATION_STR_LENGTH);
824         } else if (!strcmp(part, BT_SHARE_ITEM_PART_FILE_TRANSFER_STATUS_TEXT)) {
825                 DBG("info->tr_status : %d", info->tr_status);
826                 if (info->tr_status == BT_TRANSFER_SUCCESS) {
827                         if (gl_data->tr_inbound)
828                                 g_strlcpy(buf, BT_STR_RECEIVED, BT_GLOBALIZATION_STR_LENGTH);
829                         else
830                                 g_strlcpy(buf, BT_STR_SENT, BT_GLOBALIZATION_STR_LENGTH);
831                 } else if (info->tr_status == BT_TRANSFER_FAIL) {
832                         g_strlcpy(buf, BT_STR_FAILED, BT_GLOBALIZATION_STR_LENGTH);
833                 } else if (info->tr_status == BT_TRANSFER_ONGOING) {
834                         if (gl_data->tr_inbound)
835                                 g_strlcpy(buf, BT_STR_RECEIVING, BT_GLOBALIZATION_STR_LENGTH);
836                         else
837                                 g_strlcpy(buf, BT_STR_SENDING, BT_GLOBALIZATION_STR_LENGTH);
838                 } else if (info->tr_status == BT_TRANSFER_PENDING) {
839                         g_strlcpy(buf, BT_STR_WAITING, BT_GLOBALIZATION_STR_LENGTH);
840                 }
841         } else if (!strcmp(part, BT_SHARE_ITEM_PART_FILE_SIZE)) {
842                 char *size;
843
844                 if ((info->tr_status == BT_TRANSFER_ONGOING ||
845                                 info->tr_status == BT_TRANSFER_PENDING) && gl_data->tr_inbound)
846                         return NULL;
847
848                 if (info->size > 1024 * 1024 * 1024) { //GB
849                         size = g_strdup_printf("%.2f GB", (float)info->size / (1024 * 1024 * 1024));
850                 } else if (info->size > 1024 * 1024) { //MB
851                         size = g_strdup_printf("%.1f MB", (float)info->size / (1024 * 1024));
852                 } else if (info->size > 1024) { //KB
853                         size = g_strdup_printf("%.1f KB", (float)info->size / (1024));
854                 } else {
855                         size = g_strdup_printf("%d B", info->size);
856                 }
857
858                 g_strlcpy(buf, size, BT_GLOBALIZATION_STR_LENGTH);
859                 g_free(size);
860         } else {
861                 DBG("empty text for label.");
862                 return NULL;
863         }
864         if (markup_text)
865                 free(markup_text);
866
867         FN_END;
868         return strdup(buf);
869 }
870
871 static void  __bt_tr_del(void *data, Evas_Object *obj)
872 {
873         bt_gl_data_t *gl_data;
874         gl_data = (bt_gl_data_t *)data;
875
876         g_free(gl_data);
877 }
878
879 #if 0
880 static void __bt_genlist_realized_cb(void *data,
881                         Evas_Object *obj, void *event_info)
882 {
883         retm_if(event_info == NULL, "Invalid param\n");
884
885         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
886 #ifdef KIRAN_ACCESSIBILITY
887         Evas_Object *ao;
888         char str[BT_STR_ACCES_INFO_MAX_LEN] = {0, };
889 #endif
890         char *name;
891         char *date;
892         bt_tr_data_t *info;
893         bt_gl_data_t *gl_data;
894
895         gl_data = (bt_gl_data_t *)elm_object_item_data_get(item);
896         ret_if(gl_data == NULL);
897
898         info = gl_data->tr_data;
899
900         ret_if(info == NULL);
901         ret_if(info->dev_name == NULL);
902         ret_if(info->file_path == NULL);
903
904         name = strrchr(info->file_path, '/');
905         if (name != NULL)
906                 name++;
907         else
908                 name = info->file_path;
909
910         date = __bt_get_tr_timedate((time_t)(info->timestamp));
911
912 #ifdef KIRAN_ACCESSIBILITY
913         snprintf(str, sizeof(str), "%s, %s, %s, %s",
914                         BT_STR_ACC_ICON, name, info->dev_name, date);
915         ao = elm_object_item_access_object_get(item);
916         elm_access_info_set(ao, ELM_ACCESS_INFO, str);
917 #endif
918         g_free(date);
919 }
920 #endif
921
922 static void __bt_popup_del_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
923 {
924         FN_START;
925         retm_if(data == NULL, "data is NULL");
926         bt_share_appdata_t *ad = (bt_share_appdata_t *)data;
927
928         if (ad->info_popup) {
929                 evas_object_del(ad->info_popup);
930                 ad->info_popup = NULL;
931         }
932         FN_END;
933 }
934
935 void __bt_popup_del_by_timeout(void *data, Evas_Object *obj, void *event_info)
936 {
937         FN_START;
938         bt_share_appdata_t *ad = (bt_share_appdata_t *)data;
939         ret_if(!ad);
940         if (ad->info_popup) {
941                 evas_object_del(ad->info_popup);
942                 ad->info_popup = NULL;
943         }
944         FN_END;
945 }
946
947 Evas_Object *__bt_create_error_popup(bt_share_appdata_t *ad)
948 {
949         FN_START;
950         Evas_Object *popup = NULL;
951         retvm_if(ad == NULL, NULL, "ad is NULL");
952
953         popup = elm_popup_add(ad->win);
954         retvm_if(popup == NULL, NULL, "popup is NULL");
955
956         elm_object_focus_set(popup, EINA_FALSE);
957         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
958
959         elm_object_text_set(popup, BT_STR_UNABLE_TO_FIND_APPLICATION);
960
961         elm_popup_timeout_set(popup, 3);
962         evas_object_smart_callback_add(popup, "timeout", (Evas_Smart_Cb)__bt_popup_del_by_timeout, ad);
963         evas_object_show(popup);
964         evas_object_event_callback_add(popup, EVAS_CALLBACK_DEL, __bt_popup_del_cb, ad);
965
966         ad->info_popup = popup;
967
968         FN_END;
969         return popup;
970 }
971
972 static bt_file_type_e __get_file_type(const char *name)
973 {
974         FN_START;
975
976         char *extn = NULL;
977
978         extn = strrchr(name, '.');
979         if (extn != NULL)
980                 extn++;
981
982         if (extn != NULL) {
983                 DBG("extn : %s", extn);
984                 if (!strcasecmp(extn, "png") || !strcasecmp(extn, "bmp") || !strcasecmp(extn, "gif") ||
985                          !strcasecmp(extn, "jpg") || !strcasecmp(extn, "jpeg") || !strcasecmp(extn, "jpe") ||
986                           !strcasecmp(extn, "jp2") || !strcasecmp(extn, "pjpeg") || !strcasecmp(extn, "tif") ||
987                            !strcasecmp(extn, "wbmp") || !strcasecmp(extn, "wmf"))
988                         return BT_FILE_IMAGE;
989                 else if (!strcasecmp(extn, "vcf"))
990                         return BT_FILE_VCARD;
991                 else if (!strcasecmp(extn, "vcs"))
992                         return BT_FILE_VCAL;
993                 else if (!strcasecmp(extn, "vbm"))
994                         return BT_FILE_VBOOKMARK;
995         }
996         FN_END;
997         return BT_FILE_OTHER;
998 }
999
1000 static gboolean __bt_open_file(const char *path)
1001 {
1002         FN_START;
1003         app_control_h handle;
1004         int ret;
1005         bt_file_type_e file_type;
1006         bt_share_appdata_t *ad = app_state;
1007
1008         app_control_create(&handle);
1009         app_control_set_operation(handle, APP_CONTROL_OPERATION_VIEW);
1010         app_control_set_uri(handle, path);
1011
1012         file_type = __get_file_type(path);
1013
1014         if (file_type == BT_FILE_IMAGE) {
1015                 app_control_set_mime(handle, "image/*");
1016                 app_control_add_extra_data(handle, "Path", path);
1017                 app_control_set_launch_mode(handle, APP_CONTROL_LAUNCH_MODE_GROUP);
1018         }
1019
1020         ret = app_control_send_launch_request(handle, NULL, NULL);
1021
1022         if (ret == APP_CONTROL_ERROR_APP_NOT_FOUND)
1023                 __bt_create_error_popup(ad);
1024
1025         app_control_destroy(handle);
1026         FN_END;
1027         return TRUE;
1028 }
1029
1030 static Elm_Object_Item * __bt_add_file_title_item(bt_share_appdata_t *ad)
1031 {
1032         retvm_if(!ad, NULL, "ad is NULL!");
1033         retvm_if(!ad->tr_genlist, NULL, "tr_genlist is NULL!");
1034         retvm_if(ad->file_title_item, NULL, "file_title_item is exist");
1035
1036         Elm_Object_Item *git = NULL;
1037         git = elm_genlist_item_append(ad->tr_genlist,
1038                         ad->tr_file_title_itc, NULL,
1039                         NULL, ELM_GENLIST_ITEM_NONE,
1040                         NULL, NULL);
1041
1042         if (git == NULL) {
1043                 ERR("elm_genlist_item_append is failed!");
1044         } else {
1045                 elm_genlist_item_select_mode_set(git,
1046                                          ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1047                 ad->file_title_item = git;
1048         }
1049
1050         return git;
1051 }
1052
1053 static void __bt_tr_data_item_sel(void *data, Evas_Object *obj, void *event_info)
1054 {
1055         bt_share_appdata_t *ad = app_state;
1056         bt_gl_data_t *gl_data = (bt_gl_data_t *) data;
1057         bt_tr_data_t *info = NULL;
1058         char *path = NULL;
1059         char *ext = NULL;
1060         int default_memory = 0;
1061
1062         ret_if(data == NULL);
1063         ret_if(event_info == NULL);
1064
1065         FN_START;
1066
1067         elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
1068
1069         info = gl_data->tr_data;
1070         retm_if(info->file_path == NULL, "File Path is NULL");
1071
1072         ext = strrchr(info->file_path, '.');
1073         if (ext++) {
1074                 if (0 == g_strcmp0(ext, "vcf")) {
1075                         if (gl_data->tr_inbound == true) {
1076                                 if (info->tr_status == BT_TRANSFER_SUCCESS)
1077                                         _bt_create_info_popup(ad, BT_STR_RECEIVED_VCF_FILE_ALREADY_IMPORTED_TO_CONTACTS);
1078                         } else {
1079                                 _bt_create_info_popup(ad, BT_STR_VCF_FILES_ARE_TEMPORARY_AND_CANT_BE_OPENED);
1080                         }
1081                         return;
1082                 }
1083         }
1084
1085         if (gl_data->tr_inbound == true) {
1086                 if (info->tr_status == BT_TRANSFER_SUCCESS) {
1087                         if (vconf_get_int(VCONFKEY_SETAPPL_DEFAULT_MEM_BLUETOOTH_INT, &default_memory) != 0)
1088                                 ERR("vconf get failed");
1089
1090                         if (default_memory == BT_DEFAULT_MEM_PHONE)
1091                                 path = g_strdup_printf("%s/%s", BT_DOWNLOAD_PHONE_FOLDER, info->file_path);
1092                         else if (default_memory == BT_DEFAULT_MEM_MMC)
1093                                 path = g_strdup_printf("%s/%s", BT_DOWNLOAD_MMC_FOLDER, info->file_path);
1094
1095                         if (path)
1096                                 INFO_SECURE("path : %s", path);
1097                         else
1098                                 INFO_SECURE("path is empty");
1099
1100                         if (path && access(path, F_OK) == 0)
1101                                 __bt_open_file(path);
1102                         else
1103                                 _bt_create_info_popup(ad, BT_STR_FILE_NOT_EXIST);
1104
1105                         g_free(path);
1106                 }
1107         } else {
1108                 path = info->file_path;
1109                 INFO_SECURE("path : %s", path);
1110
1111                 if (path && access(path, F_OK) == 0) {
1112                         if (g_str_has_prefix(path, BT_CONTACT_SHARE_TMP_DIR) == TRUE)
1113                                 /* TODO: change to proper string when UX is updated */
1114                                 _bt_create_info_popup(ad, BT_STR_FILE_NOT_EXIST);
1115                         else
1116                                 __bt_open_file(path);
1117                 } else {
1118                         _bt_create_info_popup(ad, BT_STR_FILE_NOT_EXIST);
1119                 }
1120         }
1121
1122         FN_END;
1123 }
1124
1125 void _bt_genlist_prepend_tr_data_item(bt_share_appdata_t *ad,
1126                                 Evas_Object *genlist, bt_tr_data_t *info, int tr_type)
1127 {
1128         FN_START;
1129         retm_if(ad == NULL || info == NULL, "Invalid parameters!");
1130         retm_if(ad->tr_data_itc == NULL, "ad->tr_data_itc is NULL!");
1131
1132         bt_gl_data_t *gl_data = NULL;
1133
1134         gl_data = g_new0(bt_gl_data_t, 1);
1135         gl_data->tr_data = info;
1136         DBG("info->tr_status : %d", info->tr_status);
1137         if (tr_type == BT_TR_OUTBOUND || tr_type == BT_TR_INBOUND) {
1138                 if (info->tr_status == BT_TRANSFER_SUCCESS)
1139                         ad->transfer_info->success++;
1140                 else if (info->tr_status == BT_TRANSFER_FAIL)
1141                         ad->transfer_info->failed++;
1142         }
1143
1144         if (tr_type == BT_TR_OUTBOUND) {
1145                 gl_data->tr_inbound = false;
1146
1147                 if (ad->outbound_latest_id < info->id)
1148                         ad->outbound_latest_id = info->id;
1149         } else if (tr_type == BT_TR_INBOUND) {
1150                 gl_data->tr_inbound = true;
1151
1152                 if (ad->inbound_latest_id < info->id)
1153                         ad->inbound_latest_id = info->id;
1154         }
1155
1156         elm_genlist_item_append(genlist, ad->tr_data_itc, gl_data, NULL,
1157                         ELM_GENLIST_ITEM_NONE, __bt_tr_data_item_sel, gl_data);
1158
1159         evas_object_show(genlist);
1160
1161         FN_END;
1162 }
1163
1164 void __bt_update_transfer_count(bt_share_appdata_t *ad, bt_tr_data_t *info)
1165 {
1166         if (info->tr_status == BT_TRANSFER_SUCCESS)
1167                 ad->transfer_info->success++;
1168         else
1169                 ad->transfer_info->failed++;
1170
1171         if (ad->status_item)
1172                 elm_genlist_item_fields_update(ad->status_item, "*",
1173                                 ELM_GENLIST_ITEM_FIELD_TEXT);
1174 }
1175
1176 void _bt_genlist_append_tr_data_item(bt_share_appdata_t *ad,
1177                                         bt_tr_data_t *info, int tr_type)
1178 {
1179         FN_START;
1180
1181         ret_if(ad == NULL || info == NULL);
1182         ret_if(ad->tr_data_itc == NULL);
1183         ret_if(ad->tr_genlist == NULL);
1184
1185         Elm_Object_Item *git = NULL;
1186
1187         if (elm_genlist_items_count(ad->tr_genlist) == 0) {
1188                 Evas_Object *genlist = NULL;
1189                 Elm_Object_Item *navi_it = NULL;
1190
1191                 genlist = __bt_add_tr_data_genlist(ad->tr_view, ad);
1192                 retm_if(genlist == NULL, "genlist is NULL!");
1193
1194                 if (ad->tr_genlist) {
1195                         DBG("Clear the previous genlist");
1196                         elm_genlist_clear(ad->tr_genlist);
1197                         ad->tr_genlist = NULL;
1198                 }
1199
1200                 ad->tr_genlist = genlist;
1201
1202                 if (ad->navi_it) {
1203                         elm_object_item_part_content_set(ad->navi_it,
1204                                         "elm.swallow.content", genlist);
1205                 } else {
1206                         navi_it = elm_naviframe_item_push(ad->navi_fr, NULL,
1207                                         NULL, NULL, genlist, NULL);
1208                         if (navi_it)
1209                                 elm_object_item_domain_translatable_text_set(navi_it,
1210                                                 BT_COMMON_PKG,
1211                                                 (ad->tr_type == BT_TR_INBOUND) ?
1212                                                                 "IDS_ST_HEADER_RECEIVE" : "IDS_ST_HEADER_SEND");
1213                         elm_naviframe_item_pop_cb_set(navi_it, __bt_back_button_cb, ad);
1214                         ad->navi_it = navi_it;
1215                 }
1216                 return;
1217         }
1218
1219         if (!ad->file_title_item) {
1220                 retm_if(NULL == __bt_add_file_title_item(ad),
1221                                 "__bt_add_file_title_item is failed");
1222         }
1223
1224         bt_gl_data_t *gl_data = NULL;
1225         gl_data = g_new0(bt_gl_data_t, 1);
1226         gl_data->tr_data = info;
1227
1228         if (tr_type == BT_TR_OUTBOUND) {
1229                 gl_data->tr_inbound = false;
1230
1231                 if (ad->outbound_latest_id < info->id)
1232                         ad->outbound_latest_id = info->id;
1233         } else if (tr_type == BT_TR_INBOUND) {
1234                 gl_data->tr_inbound = true;
1235
1236                 if (ad->inbound_latest_id < info->id)
1237                         ad->inbound_latest_id = info->id;
1238         }
1239
1240         git = elm_genlist_item_append(ad->tr_genlist, ad->tr_data_itc, gl_data,
1241                         NULL, ELM_GENLIST_ITEM_NONE, __bt_tr_data_item_sel, gl_data);
1242
1243         __bt_update_transfer_count(ad, info);
1244
1245         if (info->tr_status == BT_TRANSFER_ONGOING)
1246                 ad->current_item = git;
1247
1248         evas_object_show(ad->tr_genlist);
1249
1250         FN_END;
1251 }
1252
1253 static void __bt_share_gl_highlighted(void *data, Evas_Object *obj,
1254                                                         void *event_info)
1255 {
1256         FN_START;
1257         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
1258         bt_gl_data_t *gl_data;
1259
1260         ret_if(item == NULL);
1261
1262         gl_data = (bt_gl_data_t *)elm_object_item_data_get(item);
1263         ret_if(gl_data == NULL);
1264
1265         gl_data->highlighted = TRUE;
1266
1267         elm_genlist_item_fields_update(item, "*",
1268                                 ELM_GENLIST_ITEM_FIELD_CONTENT);
1269
1270         FN_END;
1271 }
1272
1273 static void __bt_share_gl_unhighlighted(void *data, Evas_Object *obj,
1274                                                         void *event_info)
1275 {
1276         FN_START;
1277         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
1278         bt_gl_data_t *gl_data;
1279
1280         ret_if(item == NULL);
1281
1282         gl_data = (bt_gl_data_t *)elm_object_item_data_get(item);
1283         ret_if(gl_data == NULL);
1284         gl_data->highlighted = FALSE;
1285
1286         elm_genlist_item_fields_update(item, "*",
1287                                 ELM_GENLIST_ITEM_FIELD_CONTENT);
1288
1289         FN_END;
1290 }
1291
1292 static Evas_Object *__bt_add_tr_data_genlist(Evas_Object *parent,
1293                                                   bt_share_appdata_t *ad)
1294 {
1295         FN_START;
1296         retvm_if(ad == NULL, NULL, "Inavalid parameter!");
1297
1298         Evas_Object *genlist = elm_genlist_add(parent);
1299
1300         evas_object_smart_callback_add(genlist, "highlighted",
1301                                 __bt_share_gl_highlighted, ad);
1302
1303         evas_object_smart_callback_add(genlist, "unhighlighted",
1304                                 __bt_share_gl_unhighlighted, ad);
1305
1306         elm_genlist_homogeneous_set(genlist, EINA_TRUE);
1307         ad->tr_device_itc = elm_genlist_item_class_new();
1308         if (ad->tr_device_itc) {
1309                 if (TIZEN_COMMON)
1310                         ad->tr_device_itc->item_style = "2line";
1311                 else
1312                         ad->tr_device_itc->item_style = "type1";
1313
1314                 ad->tr_device_itc->func.text_get = __bt_tr_device_label_get;
1315                 ad->tr_device_itc->func.content_get = NULL;
1316                 ad->tr_device_itc->func.state_get = NULL;
1317                 ad->tr_device_itc->func.del = NULL;
1318         }
1319
1320         ad->tr_status_itc = elm_genlist_item_class_new();
1321         if (ad->tr_status_itc) {
1322                 ad->tr_status_itc->item_style = "type1";
1323                 ad->tr_status_itc->func.text_get = __bt_tr_status_label_get;
1324                 ad->tr_status_itc->func.content_get = NULL;
1325                 ad->tr_status_itc->func.state_get = NULL;
1326                 ad->tr_status_itc->func.del = NULL;
1327         }
1328
1329         ad->tr_progress_itc = elm_genlist_item_class_new();
1330         if (ad->tr_progress_itc) {
1331                 ad->tr_progress_itc->item_style = "full";
1332                 ad->tr_progress_itc->func.text_get = NULL;
1333                 ad->tr_progress_itc->func.content_get = __bt_tr_progress_icon_get;
1334                 ad->tr_progress_itc->func.state_get = NULL;
1335                 ad->tr_progress_itc->func.del = NULL;
1336         }
1337
1338         ad->tr_file_title_itc = elm_genlist_item_class_new();
1339         if (ad->tr_file_title_itc) {
1340                 ad->tr_file_title_itc->item_style = "groupindex";
1341                 ad->tr_file_title_itc->func.text_get = __bt_tr_file_title_label_get;
1342                 ad->tr_file_title_itc->func.content_get = NULL;
1343                 ad->tr_file_title_itc->func.state_get = NULL;
1344                 ad->tr_file_title_itc->func.del = NULL;
1345         }
1346
1347         ad->tr_data_itc = elm_genlist_item_class_new();
1348         if (ad->tr_data_itc) {
1349                 ad->tr_data_itc->item_style = "type1";
1350                 ad->tr_data_itc->func.text_get = __bt_tr_label_get;
1351                 ad->tr_data_itc->func.content_get = __bt_tr_icon_get;
1352                 ad->tr_data_itc->func.state_get = NULL;
1353                 ad->tr_data_itc->func.del = __bt_tr_del;
1354         }
1355
1356         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
1357         FN_END;
1358         return genlist;
1359 }
1360
1361 static Evas_Object * __bt_create_naviframe(bt_share_appdata_t *ad)
1362 {
1363         FN_START;
1364         retv_if(ad == NULL, NULL);
1365         Evas_Object *navi_fr = NULL;
1366         /* Naviframe */
1367         navi_fr = elm_naviframe_add(ad->tr_view);
1368         eext_object_event_callback_add(navi_fr, EEXT_CALLBACK_BACK,
1369                                                 eext_naviframe_back_cb, NULL);
1370         elm_object_part_content_set(ad->tr_view, "elm.swallow.content", navi_fr);
1371         evas_object_show(navi_fr);
1372         FN_END;
1373         return navi_fr;
1374 }
1375
1376 void _bt_cb_state_changed(int result,
1377                         bt_adapter_state_e adapter_state,
1378                         void *user_data)
1379 {
1380         FN_START;
1381         DBG("bluetooth %s", adapter_state == BT_ADAPTER_ENABLED ?
1382                                 "enabled" : "disabled");
1383
1384         ret_if(!user_data);
1385         ret_if(result != BT_ERROR_NONE);
1386
1387         bt_share_appdata_t *ad = (bt_share_appdata_t *)user_data;
1388
1389         ad->bt_status = adapter_state;
1390
1391         if (adapter_state == BT_ADAPTER_ENABLED && ad->send_after_turning_on) {
1392                 DBG("Adapter enabled, resend pending items");
1393                 /* close turning on popup */
1394                 if (ad->turning_on_popup) {
1395                         evas_object_del(ad->turning_on_popup);
1396                         ad->turning_on_popup = NULL;
1397                 }
1398
1399                 _bt_share_ui_retry_failed(ad);
1400                 if (ad->launch_mode == BT_LAUNCH_TRANSFER_LIST) {
1401                         int noti_id;
1402                         char *opp_role;
1403                         bt_tr_db_table_e table;
1404
1405                         __bt_get_noti_id_opp_role_and_table(ad, &noti_id, &opp_role, &table);
1406
1407                         DBG_SECURE("Notification ID: %d", noti_id);
1408                         if (noti_id < 0) {
1409                                 ERR("Invalid Notification ID");
1410                         } else {
1411                                 sqlite3 *db = bt_share_open_db();
1412                                 bt_share_remove_tr_data_by_notification(db, table, noti_id);
1413                                 bt_share_close_db(db);
1414                                 _bt_delete_selected_notification(ad->tr_type, noti_id, opp_role);
1415                         }
1416                 }
1417
1418                 ad->send_after_turning_on = FALSE;
1419                 _bt_terminate_app();
1420         }
1421         FN_END;
1422 }
1423
1424 gboolean __bt_share_is_battery_low(void)
1425 {
1426         FN_START;
1427
1428         int value = 0;
1429         int charging = 0;
1430
1431         if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, (void *)&charging))
1432                 ERR("Get the battery charging status fail");
1433
1434         if (charging == 1)
1435                 return FALSE;
1436
1437         DBG("charging: %d", charging);
1438
1439         if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, (void *)&value)) {
1440                 ERR("Get the battery low status fail");
1441                 return FALSE;
1442         }
1443
1444         if (value <= VCONFKEY_SYSMAN_BAT_POWER_OFF)
1445                 return TRUE;
1446
1447         FN_END;
1448         return FALSE;
1449 }
1450
1451 int _bt_share_enable_bt(bt_share_appdata_t *ad)
1452 {
1453         FN_START;
1454         int ret;
1455         retv_if(ad == NULL, -1);
1456 /*
1457         if (__bt_share_is_battery_low() == TRUE) {
1458                 // Battery is critical low
1459                 _bt_main_create_information_popup(ad, BT_STR_LOW_BATTERY);
1460                 return -1;
1461         }
1462 */
1463
1464         ret = bt_adapter_enable();
1465         if (ret == BT_ERROR_ALREADY_DONE) {
1466                 _bt_cb_state_changed(BT_ERROR_NONE, BT_ADAPTER_ENABLED, ad);
1467         } else if (ret == BT_ERROR_NOW_IN_PROGRESS) {
1468                 ERR("Enabling in progress [%d]", ret);
1469         } else if (ret != BT_ERROR_NONE) {
1470                 ERR("Failed to enable bluetooth [%d]", ret);
1471         } else {
1472                 ad->turning_on_popup = _bt_share_add_turning_on_popup(ad);
1473                 ad->send_after_turning_on = TRUE;
1474         }
1475         FN_END;
1476         return 0;
1477 }
1478
1479 void _bt_share_toolbar_button_cb(void *data, Evas_Object *obj,
1480                 void *event_info)
1481 {
1482         FN_START;
1483         ret_if(!data);
1484         bt_share_appdata_t *ad = (bt_share_appdata_t *)data;
1485         bt_share_abort_data_t *abort_data = g_new0(bt_share_abort_data_t, 1);
1486
1487         const char *text = elm_object_text_get(obj);
1488
1489         if (g_strcmp0(text, BT_STR_STOP) == 0) {
1490                 if (ad->transfer_info) {
1491                         abort_data->transfer_id = ad->transfer_info->transfer_id;
1492                         abort_data->transfer_type = ad->transfer_info->transfer_type;
1493                         _bt_abort_signal_send(ad, abort_data);
1494                 }
1495         } else if (g_strcmp0(text, BT_STR_RESEND_FAILED_FILES) == 0) {
1496                 /* for BT off case */
1497                 if (ad->bt_status == BT_ADAPTER_DISABLED) {
1498                         _bt_share_enable_bt(ad);
1499                 } else {
1500                         _bt_share_ui_retry_failed(ad);
1501                         if (ad->launch_mode == BT_LAUNCH_TRANSFER_LIST) {
1502                                 int noti_id;
1503                                 char *opp_role;
1504                                 bt_tr_db_table_e table;
1505
1506                                 __bt_get_noti_id_opp_role_and_table(ad, &noti_id, &opp_role, &table);
1507
1508                                 DBG_SECURE("Notification ID: %d", noti_id);
1509                                 if (noti_id < 0) {
1510                                         ERR("Invalid Notification ID");
1511                                 } else {
1512                                         sqlite3 *db = bt_share_open_db();
1513                                         bt_share_remove_tr_data_by_notification(db, table, noti_id);
1514                                         bt_share_close_db(db);
1515                                         _bt_delete_selected_notification(ad->tr_type, noti_id, opp_role);
1516                                 }
1517                         }
1518                         _bt_terminate_app();
1519                 }
1520         }
1521
1522         g_free(abort_data);
1523         FN_END;
1524 }
1525
1526 Evas_Object * _bt_share_create_toolbar_button(bt_share_appdata_t *ad, char *text)
1527 {
1528         Evas_Object *layout = NULL;
1529         Evas_Object *toolbar_button = NULL;
1530
1531         layout = elm_layout_add(ad->navi_fr);
1532         elm_layout_file_set(layout, EDJFILE, "toolbar_button_ly");
1533
1534         toolbar_button = elm_button_add(layout);
1535
1536         /* Use "bottom" style button */
1537         elm_object_style_set(toolbar_button, "bottom");
1538         evas_object_size_hint_weight_set(toolbar_button, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1539         evas_object_size_hint_align_set(toolbar_button, EVAS_HINT_FILL, 0.5);
1540
1541         elm_object_text_set(toolbar_button, text);
1542
1543         evas_object_smart_callback_add(toolbar_button, "clicked",
1544                         _bt_share_toolbar_button_cb, ad);
1545
1546         /* Set button into "toolbar" swallow part */
1547         elm_object_part_content_set(layout, "button", toolbar_button);
1548         elm_object_item_part_content_set(ad->navi_it, "toolbar", layout);
1549         ad->toolbar_ly = layout;
1550         return toolbar_button;
1551 }
1552
1553 void _bt_share_delete_toolbar_button(bt_share_appdata_t *ad)
1554 {
1555         FN_START;
1556         ret_if(!ad);
1557
1558         if (ad->toolbar_button) {
1559                 evas_object_del(ad->toolbar_button);
1560                 ad->toolbar_button = NULL;
1561         }
1562         if (ad->toolbar_ly) {
1563                 evas_object_del(ad->toolbar_ly);
1564                 ad->toolbar_ly = NULL;
1565         }
1566         FN_END;
1567 }
1568
1569 static Eina_Bool __bt_list_item_add(bt_share_appdata_t *ad)
1570 {
1571         FN_START;
1572         int i;
1573
1574         retv_if(!ad, EINA_FALSE);
1575         GSList *tr_data_list = ad->tr_data_list;
1576         retv_if(ad->launch_mode == BT_LAUNCH_TRANSFER_LIST && !tr_data_list, EINA_FALSE);
1577
1578         /* Add first 5 genlist items */
1579         for (i = 0; NULL != tr_data_list && i < 5; i++) {
1580                 _bt_genlist_prepend_tr_data_item(ad,  ad->tr_genlist, tr_data_list->data,
1581                                                 ad->tr_type);
1582                 tr_data_list = g_slist_next(tr_data_list);
1583         }
1584
1585         if (ad->launch_mode == BT_LAUNCH_TRANSFER_LIST &&
1586                         ad->tr_type == BT_TR_OUTBOUND && ad->transfer_info->failed) {
1587                 ad->toolbar_button = _bt_share_create_toolbar_button(ad,
1588                                 BT_STR_RESEND_FAILED_FILES);
1589         }
1590
1591         FN_END;
1592
1593         return EINA_TRUE;
1594 }
1595
1596 static Eina_Bool __bt_list_item_idler(void *data)
1597 {
1598         FN_START;
1599
1600         bt_share_appdata_t *ad = (bt_share_appdata_t *)data;
1601
1602         retv_if(!ad, EINA_FALSE);
1603         GSList *tr_data_list = ad->tr_data_list;
1604         retv_if(ad->launch_mode == BT_LAUNCH_TRANSFER_LIST && !tr_data_list, EINA_FALSE);
1605
1606         DBG("Total Items in List : %d", g_slist_length(tr_data_list));
1607         /* Add rest of the genlist items */
1608         if (g_slist_length(ad->tr_data_list) >= 5) {
1609                 tr_data_list = g_slist_nth(ad->tr_data_list, 5);
1610
1611                 while (NULL != tr_data_list) {
1612                         _bt_genlist_prepend_tr_data_item(ad,  ad->tr_genlist, tr_data_list->data,
1613                                                         ad->tr_type);
1614                         tr_data_list = g_slist_next(tr_data_list);
1615                 }
1616         }
1617
1618         if (ad->launch_mode == BT_LAUNCH_TRANSFER_LIST &&
1619                         ad->tr_type == BT_TR_OUTBOUND &&
1620                         ad->transfer_info->failed &&
1621                         ad->toolbar_button == NULL) {
1622                 ad->toolbar_button = _bt_share_create_toolbar_button(ad,
1623                                 BT_STR_RESEND_FAILED_FILES);
1624         }
1625
1626         /* Delete the notification */
1627         /* TODO: Delete Notification only if
1628          * transfer(sent) is completed with no failed items or received screen related to this session */
1629         if (ad->launch_mode == BT_LAUNCH_TRANSFER_LIST &&
1630                         ((ad->tr_type == BT_TR_OUTBOUND &&
1631                                         ad->transfer_info->failed == 0) || ad->tr_type == BT_TR_INBOUND)) {
1632                 int noti_id;
1633                 char *opp_role;
1634                 bt_tr_db_table_e table;
1635
1636                 __bt_get_noti_id_opp_role_and_table(ad, &noti_id, &opp_role, &table);
1637
1638                 DBG_SECURE("Notification ID: %d", noti_id);
1639                 if (noti_id < 0) {
1640                         ERR("Invalid Notification ID");
1641                 } else {
1642                         if (ad->bt_status == BT_ADAPTER_DISABLED) {
1643                                 sqlite3 *db = bt_share_open_db();
1644                                 bt_share_remove_tr_data_by_notification(db, table, noti_id);
1645                                 bt_share_close_db(db);
1646                         }
1647                         _bt_delete_selected_notification(ad->tr_type, noti_id, opp_role);
1648                 }
1649         }
1650
1651         if (ad->status_item)
1652                 elm_genlist_item_fields_update(ad->status_item, "*",
1653                                 ELM_GENLIST_ITEM_FIELD_TEXT);
1654
1655         FN_END;
1656         return EINA_FALSE;
1657 }
1658
1659 int _bt_create_transfer_view(bt_share_appdata_t *ad)
1660 {
1661         FN_START;
1662         retv_if(ad == NULL, -1);
1663
1664         Elm_Object_Item *navi_it = NULL;
1665         Elm_Object_Item *git = NULL;
1666         Evas_Object *conform = NULL;
1667         Evas_Object *navi_fr = NULL;
1668         Evas_Object *bg = NULL;
1669         Evas_Object *layout = NULL;
1670         Evas_Object *genlist = NULL;
1671
1672         __bt_clear_view(ad);
1673         bg = _bt_create_bg(ad->win, NULL);
1674         retv_if(bg == NULL, -1);
1675         ad->bg = bg;
1676
1677         conform = _bt_create_conformant(ad->win, NULL);
1678         retvm_if(conform == NULL, -1, "conform is NULL!");
1679         ad->conform = conform;
1680
1681         bg = elm_bg_add(conform);
1682         elm_object_style_set(bg, "indicator/headerbg");
1683         elm_object_part_content_set(conform, "elm.swallow.indicator_bg", bg);
1684         evas_object_show(bg);
1685
1686         layout = _bt_create_layout(conform, EDJFILE, "share_view");
1687         ad->tr_view = layout;
1688
1689         elm_object_content_set(conform, layout);
1690         elm_win_conformant_set(ad->win, EINA_TRUE);
1691
1692         navi_fr = __bt_create_naviframe(ad);
1693         retvm_if(navi_fr == NULL, -1, "navi_fr is NULL!");
1694         ad->navi_fr = navi_fr;
1695
1696         /* Genlist */
1697         genlist = __bt_add_tr_data_genlist(layout, ad);
1698         retvm_if(genlist == NULL, -1, "genlist is NULL!");
1699         ad->tr_genlist = genlist;
1700
1701         git = elm_genlist_item_append(genlist,
1702                         ad->tr_device_itc, ad,
1703                         NULL, ELM_GENLIST_ITEM_NONE,
1704                         NULL, NULL);
1705         if (git == NULL) {
1706                 ERR("elm_genlist_item_append is failed!");
1707         } else {
1708                 elm_genlist_item_select_mode_set(git,
1709                                          ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1710                 ad->device_item = git;
1711         }
1712
1713         if (ad->launch_mode == BT_LAUNCH_TRANSFER_LIST) {
1714                 git = elm_genlist_item_append(genlist,
1715                                 ad->tr_status_itc, ad,
1716                                 NULL, ELM_GENLIST_ITEM_NONE,
1717                                 NULL, NULL);
1718                 if (git == NULL) {
1719                         ERR("elm_genlist_item_append is failed!");
1720                 } else {
1721                         elm_genlist_item_select_mode_set(git,
1722                                                  ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1723                         ad->status_item = git;
1724                 }
1725         } else if (ad->launch_mode == BT_LAUNCH_ONGOING) {
1726                 if (ad->progress_item) {
1727                         elm_object_item_del(ad->progress_item);
1728                         ad->progress_item = NULL;
1729                         ad->progressbar = NULL;
1730                 }
1731
1732                 git = elm_genlist_item_append(genlist,
1733                                 ad->tr_progress_itc, ad,
1734                                 NULL, ELM_GENLIST_ITEM_NONE,
1735                                 NULL, NULL);
1736                 if (git == NULL) {
1737                         ERR("elm_genlist_item_append is failed!");
1738                 } else {
1739                         elm_genlist_item_select_mode_set(git,
1740                                                  ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1741                         ad->progress_item = git;
1742                 }
1743         }
1744
1745         __bt_add_file_title_item(ad);
1746
1747         navi_it = elm_naviframe_item_push(navi_fr, NULL,
1748                                         NULL, NULL, genlist, NULL);
1749         if (navi_it == NULL) {
1750                 ERR("elm_naviframe_item_push is failed!");
1751         } else {
1752                 elm_object_item_domain_translatable_text_set(navi_it, BT_COMMON_PKG,
1753                 (ad->tr_type == BT_TR_INBOUND) ? "IDS_ST_HEADER_RECEIVE" : "IDS_ST_HEADER_SEND");
1754                 elm_naviframe_item_pop_cb_set(navi_it, __bt_back_button_cb, ad);
1755                 ad->navi_it = navi_it;
1756         }
1757
1758         if (ad->launch_mode == BT_LAUNCH_ONGOING) {
1759                 ad->toolbar_button = _bt_share_create_toolbar_button(ad,
1760                                 BT_STR_STOP);
1761         }
1762
1763         __bt_list_item_add(ad);
1764
1765         ad->idler = ecore_idler_add(__bt_list_item_idler, ad);
1766         if (!ad->idler)
1767                 ERR("idler can not be added");
1768
1769         FN_END;
1770         return 0;
1771 }