4 * Copyright 2012 Samsung Electronics Co., Ltd
6 * Contact: Hocheol Seo <hocheol.seo@samsung.com>
7 * GirishAshok Joshi <girish.joshi@samsung.com>
8 * DoHyun Pyun <dh79.pyun@samsung.com>
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
14 * http://www.tizenopensource.org/license
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.
32 #include <Elementary.h>
33 #include <efl_extension.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>
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"
52 #define NOTI_OPS_APP_ID "bluetooth-share-opp-server"
53 #define NOTI_OPC_APP_ID "bluetooth-share-opp-client"
55 #define BT_DEFAULT_MEM_PHONE 0
56 #define BT_DEFAULT_MEM_MMC 1
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"
62 extern bt_share_appdata_t *app_state;
64 static Evas_Object *__bt_add_tr_data_genlist(Evas_Object *parent,
65 bt_share_appdata_t *ad);
67 void _bt_delete_selected_notification(bt_share_tr_type_e tr_type,
68 int noti_id, const char *opp_role)
70 notification_list_h list_head;
71 notification_list_h list_traverse;
75 notification_get_list(NOTIFICATION_TYPE_NOTI, -1, &list_head);
76 list_traverse = list_head;
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");
89 list_traverse = notification_list_get_next(list_traverse);
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)
96 sqlite3 *db = bt_share_open_db();
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;
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;
108 bt_share_close_db(db);
111 void _bt_share_ui_handle_transfer_disconnected(bt_share_appdata_t *ad,
112 bt_share_tr_type_e type)
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,
124 ERR("elm_genlist_item_insert_after is failed!");
126 elm_genlist_item_select_mode_set(git,
127 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
128 ad->status_item = git;
131 elm_object_item_del(ad->progress_item);
132 ad->progress_item = NULL;
133 ad->progressbar = NULL;
139 void _bt_share_ui_handle_transfer_complete(bt_share_appdata_t *ad,
140 char *address, bt_share_tr_type_e type)
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);
147 ret_if(g_strcmp0(ad->transfer_info->device_address, address));
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)
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));
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++;
168 if (ad->status_item) {
169 elm_object_item_del(ad->status_item);
170 ad->status_item = NULL;
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);
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);
182 ERR("elm_genlist_item_append is failed!");
184 elm_genlist_item_select_mode_set(git,
185 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
186 ad->progress_item = git;
190 if (!ad->toolbar_button) {
191 /* Create Stop Button if not present */
192 ad->toolbar_button = _bt_share_create_toolbar_button(ad,
199 Evas_Object *_bt_create_win(const char *name)
201 Evas_Object *eo = NULL;
203 eo = elm_win_add(NULL, name, ELM_WIN_BASIC);
206 elm_win_title_set(eo, name);
207 elm_win_borderless_set(eo, EINA_TRUE);
211 void _bt_terminate_app(void)
213 DBG("Terminate BT SHARE UI");
217 static void __bt_clear_view(void *data)
221 bt_share_appdata_t *ad = (bt_share_appdata_t *)data;
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;
236 evas_object_del(ad->navi_fr);
241 evas_object_del(ad->tr_view);
247 static Eina_Bool __bt_back_button_cb(void *data, Elm_Object_Item *it)
249 DBG("pop current view ");
250 retvm_if(!data, EINA_FALSE, "invalid parameter!");
252 bt_share_appdata_t *ad = (bt_share_appdata_t *)data;
255 __bt_clear_view(data);
257 if (ad->tr_data_list) {
258 ret = bt_share_release_tr_data_list(ad->tr_data_list);
260 if (ret != BT_SHARE_ERR_NONE)
261 ERR("Transfer data release failed ");
262 ad->tr_data_list = NULL;
270 static Evas_Object *__bt_tr_progress_icon_get(void *data, Evas_Object *obj,
275 Evas_Object *progress_layout = NULL;
276 Evas_Object *progressbar = NULL;
277 bt_share_appdata_t *ad = NULL;
279 retv_if(data == NULL, NULL);
280 ad = (bt_share_appdata_t *)data;
282 bt_share_transfer_data_t *transfer_info = ad->transfer_info;
284 if (!strcmp(part, BT_SHARE_ITEM_PART_PROGRESSBAR_ICON)) {
285 char buff[BT_STR_PROGRESS_MAX_LEN] = { 0, };
286 char *markup_text = NULL;
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,
293 evas_object_size_hint_weight_set(progress_layout, EVAS_HINT_EXPAND,
295 evas_object_show(progress_layout);
297 DBG("Creating new progressbar!!!");
298 progressbar = elm_progressbar_add(progress_layout);
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,
304 evas_object_size_hint_weight_set(progressbar, EVAS_HINT_EXPAND,
306 elm_progressbar_pulse(progressbar, EINA_TRUE);
308 evas_object_show(progressbar);
309 ad->progressbar = progressbar;
311 markup_text = elm_entry_utf8_to_markup(transfer_info->filename);
312 DBG_SECURE("Filename: %s", markup_text);
314 DBG("Filename: %s", markup_text);
316 elm_object_part_text_set(progress_layout, "elm.text.description", markup_text);
319 elm_object_part_content_set(progress_layout, "progressbar", progressbar);
321 elm_progressbar_value_set(progressbar,
322 (double) transfer_info->percentage / 100);
324 elm_object_signal_emit(progressbar, "elm,bottom,text,show", "elm");
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);
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);
338 return progress_layout;
341 static Evas_Object *__bt_tr_icon_get(void *data, Evas_Object *obj,
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;
349 bt_gl_data_t *gl_data = NULL;
351 retv_if(!data, NULL);
352 gl_data = (bt_gl_data_t *)data;
354 info = gl_data->tr_data;
355 retv_if(!info, NULL);
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;
366 img = (info->tr_status == BT_TRANSFER_SUCCESS) ?
367 BT_ICON_RECV_PASS : BT_ICON_RECV_FAIL;
370 elm_image_file_set(icon, EDJ_IMAGES, img);
371 evas_object_size_hint_align_set(icon, EVAS_HINT_FILL,
373 evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND,
376 evas_object_show(icon);
377 evas_object_size_hint_min_set(icon, ELM_SCALE_SIZE(40), ELM_SCALE_SIZE(40));
379 } else if (info->tr_status == BT_TRANSFER_ONGOING) {
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");
387 icon = elm_progressbar_add(obj);
390 elm_object_style_set(icon, "process_small");
392 elm_object_style_set(icon, "process_medium");
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);
398 } else if (info->tr_status == BT_TRANSFER_PENDING) {
399 icon = elm_progressbar_add(obj);
402 elm_object_style_set(icon, "process_small");
404 elm_object_style_set(icon, "process_medium");
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);
416 void _bt_util_get_number(char *source, char *dest)
422 slen = strlen(source);
427 if (isdigit(source[slen])) {
428 buf[len] = source[slen];
438 strcpy(dest, &buf[len]);
441 void _bt_util_get_contact_name(int lcontact_id, char **contact_name)
445 contacts_filter_h filter = NULL;
446 contacts_query_h query = NULL;
447 contacts_list_h list = NULL;
448 contacts_record_h record = NULL;
452 ret = contacts_filter_create(_contacts_contact._uri, &filter);
453 if (ret != CONTACTS_ERROR_NONE) {
454 ERR("Fail to create filter for contacts");
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");
465 ret = contacts_query_create(_contacts_contact._uri, &query);
466 if (ret != CONTACTS_ERROR_NONE) {
467 ERR("Fail to create qurey for contacts");
471 ret = contacts_query_set_filter(query, filter);
472 if (ret != CONTACTS_ERROR_NONE) {
473 ERR("Fail to set filter for contacts");
477 ret = contacts_db_get_count_with_query(query, &count);
478 if (ret != CONTACTS_ERROR_NONE) {
479 ERR("Fail to get count from db");
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");
493 contacts_list_first(list);
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,
501 *contact_name = g_strdup(name);
505 ret = contacts_list_next(list);
510 contacts_filter_destroy(filter);
513 contacts_query_destroy(query);
516 contacts_list_destroy(list, true);
521 unsigned int bt_crc32(const void *src, unsigned long src_sz)
523 return (crc32(0, src, src_sz) & 0xFFFF);
526 void _bt_util_get_contact_info(unsigned char *auth_info, int *contact_id, char **contact_name)
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;
537 contacts_filter_h filter = NULL;
538 contacts_query_h query = NULL;
539 contacts_list_h list = NULL;
540 contacts_record_h record = NULL;
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");
546 if (contacts_connect() != CONTACTS_ERROR_NONE) {
547 ERR("contacts_connect failed");
551 memcpy(&shash, auth_info, 3);
552 shash = ntohl(shash);
555 memcpy(&chash, &auth_info[3], 2);
556 chash = ntohl(chash);
559 g_snprintf(str_hash, 7, "%X", shash);
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");
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");
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");
580 ret = contacts_query_set_filter(query, filter);
581 if (ret != CONTACTS_ERROR_NONE) {
582 ERR("Fail to set filter for contacts");
586 ret = contacts_db_get_count_with_query(query, &count);
587 if (ret != CONTACTS_ERROR_NONE) {
588 ERR("Fail to get count from db");
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");
603 contacts_list_first(list);
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,
610 DBG_SECURE("number: [%s]", number);
611 if (number != NULL) {
612 _bt_util_get_number(number, pnumber);
613 DBG_SECURE("pnumber: [%s]", pnumber);
615 DBG_SECURE("CRC [%X], [%X]", chash, bt_crc32(pnumber, strlen(pnumber)));
617 if (bt_crc32(pnumber , strlen(pnumber)) == chash) {
618 contacts_record_get_int(record,
619 _contacts_quick_connect_info.contact_id,
621 *contact_id = lcontact_id;
622 _bt_util_get_contact_name(lcontact_id, contact_name);
623 DBG_SECURE("contact id : %d", lcontact_id);
627 ret = contacts_list_next(list);
632 contacts_filter_destroy(filter);
635 contacts_query_destroy(query);
638 contacts_list_destroy(list, true);
640 contacts_disconnect();
646 static char *__bt_tr_device_label_get(void *data, Evas_Object *obj,
650 retv_if(data == NULL, NULL);
651 bt_share_appdata_t *ad = (bt_share_appdata_t *)data;
652 char *markup_text = NULL;
654 retv_if(ad->transfer_info == NULL, NULL);
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;
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);
674 unsigned char auth_info[5] = {0, };
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);
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);
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);
697 markup_text = elm_entry_utf8_to_markup(contact_name);
698 g_free(contact_name);
703 bt_adapter_free_device_info(dev_info);
705 ERR("bt_adapter_get_bonded_device_info() is failed!!! error: 0x%04X", ret);
710 markup_text = elm_entry_utf8_to_markup(transfer_info->device_name);
718 static char *__bt_tr_status_label_get(void *data, Evas_Object *obj,
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;
729 retv_if(transfer_info == NULL, NULL);
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);
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;
743 DBG_SECURE("Success %d, Failed %d", transfer_info->success, transfer_info->failed);
744 if (transfer_info->success == 0 &&
745 transfer_info->failed == 0)
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);
751 stms_str = BT_STR_PD_FAILED;
752 tmp_failed = g_strdup_printf(stms_str, transfer_info->failed);
754 ret_str = g_strdup_printf("%s, %s", tmp_success, tmp_failed);
765 static char *__bt_tr_progress_label_get(void *data, Evas_Object *obj,
769 retv_if(data == NULL, NULL);
770 bt_share_appdata_t *ad = (bt_share_appdata_t *)data;
771 char *markup_text = NULL;
773 retv_if(ad->transfer_info == NULL, NULL);
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);
787 static char *__bt_tr_file_title_label_get(void *data, Evas_Object *obj,
791 if (!strcmp(part, BT_SHARE_ITEM_PART_FILE_LIST_TITLE)) {
793 return g_strdup(BT_STR_FILE_LIST);
799 static char *__bt_tr_label_get(void *data, Evas_Object *obj,
803 bt_tr_data_t *info = 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!");
812 info = gl_data->tr_data;
813 retv_if(info == NULL, NULL);
815 if (!strcmp(part, BT_SHARE_ITEM_PART_FILE_NAME)) {
816 name = strrchr(info->file_path, '/');
820 name = info->file_path;
821 markup_text = elm_entry_utf8_to_markup(name);
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);
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);
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);
841 } else if (!strcmp(part, BT_SHARE_ITEM_PART_FILE_SIZE)) {
844 if ((info->tr_status == BT_TRANSFER_ONGOING ||
845 info->tr_status == BT_TRANSFER_PENDING) && gl_data->tr_inbound)
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));
855 size = g_strdup_printf("%d B", info->size);
858 g_strlcpy(buf, size, BT_GLOBALIZATION_STR_LENGTH);
861 DBG("empty text for label.");
871 static void __bt_tr_del(void *data, Evas_Object *obj)
873 bt_gl_data_t *gl_data;
874 gl_data = (bt_gl_data_t *)data;
880 static void __bt_genlist_realized_cb(void *data,
881 Evas_Object *obj, void *event_info)
883 retm_if(event_info == NULL, "Invalid param\n");
885 Elm_Object_Item *item = (Elm_Object_Item *)event_info;
886 #ifdef KIRAN_ACCESSIBILITY
888 char str[BT_STR_ACCES_INFO_MAX_LEN] = {0, };
893 bt_gl_data_t *gl_data;
895 gl_data = (bt_gl_data_t *)elm_object_item_data_get(item);
896 ret_if(gl_data == NULL);
898 info = gl_data->tr_data;
900 ret_if(info == NULL);
901 ret_if(info->dev_name == NULL);
902 ret_if(info->file_path == NULL);
904 name = strrchr(info->file_path, '/');
908 name = info->file_path;
910 date = __bt_get_tr_timedate((time_t)(info->timestamp));
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);
922 static void __bt_popup_del_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
925 retm_if(data == NULL, "data is NULL");
926 bt_share_appdata_t *ad = (bt_share_appdata_t *)data;
928 if (ad->info_popup) {
929 evas_object_del(ad->info_popup);
930 ad->info_popup = NULL;
935 void __bt_popup_del_by_timeout(void *data, Evas_Object *obj, void *event_info)
938 bt_share_appdata_t *ad = (bt_share_appdata_t *)data;
940 if (ad->info_popup) {
941 evas_object_del(ad->info_popup);
942 ad->info_popup = NULL;
947 Evas_Object *__bt_create_error_popup(bt_share_appdata_t *ad)
950 Evas_Object *popup = NULL;
951 retvm_if(ad == NULL, NULL, "ad is NULL");
953 popup = elm_popup_add(ad->win);
954 retvm_if(popup == NULL, NULL, "popup is NULL");
956 elm_object_focus_set(popup, EINA_FALSE);
957 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
959 elm_object_text_set(popup, BT_STR_UNABLE_TO_FIND_APPLICATION);
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);
966 ad->info_popup = popup;
972 static bt_file_type_e __get_file_type(const char *name)
978 extn = strrchr(name, '.');
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"))
993 else if (!strcasecmp(extn, "vbm"))
994 return BT_FILE_VBOOKMARK;
997 return BT_FILE_OTHER;
1000 static gboolean __bt_open_file(const char *path)
1003 app_control_h handle;
1005 bt_file_type_e file_type;
1006 bt_share_appdata_t *ad = app_state;
1008 app_control_create(&handle);
1009 app_control_set_operation(handle, APP_CONTROL_OPERATION_VIEW);
1010 app_control_set_uri(handle, path);
1012 file_type = __get_file_type(path);
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);
1020 ret = app_control_send_launch_request(handle, NULL, NULL);
1022 if (ret == APP_CONTROL_ERROR_APP_NOT_FOUND)
1023 __bt_create_error_popup(ad);
1025 app_control_destroy(handle);
1030 static Elm_Object_Item * __bt_add_file_title_item(bt_share_appdata_t *ad)
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");
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,
1043 ERR("elm_genlist_item_append is failed!");
1045 elm_genlist_item_select_mode_set(git,
1046 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1047 ad->file_title_item = git;
1053 static void __bt_tr_data_item_sel(void *data, Evas_Object *obj, void *event_info)
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;
1060 int default_memory = 0;
1062 ret_if(data == NULL);
1063 ret_if(event_info == NULL);
1067 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
1069 info = gl_data->tr_data;
1070 retm_if(info->file_path == NULL, "File Path is NULL");
1072 ext = strrchr(info->file_path, '.');
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);
1079 _bt_create_info_popup(ad, BT_STR_VCF_FILES_ARE_TEMPORARY_AND_CANT_BE_OPENED);
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");
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);
1096 INFO_SECURE("path : %s", path);
1098 INFO_SECURE("path is empty");
1100 if (path && access(path, F_OK) == 0)
1101 __bt_open_file(path);
1103 _bt_create_info_popup(ad, BT_STR_FILE_NOT_EXIST);
1108 path = info->file_path;
1109 INFO_SECURE("path : %s", path);
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);
1116 __bt_open_file(path);
1118 _bt_create_info_popup(ad, BT_STR_FILE_NOT_EXIST);
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)
1129 retm_if(ad == NULL || info == NULL, "Invalid parameters!");
1130 retm_if(ad->tr_data_itc == NULL, "ad->tr_data_itc is NULL!");
1132 bt_gl_data_t *gl_data = NULL;
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++;
1144 if (tr_type == BT_TR_OUTBOUND) {
1145 gl_data->tr_inbound = false;
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;
1152 if (ad->inbound_latest_id < info->id)
1153 ad->inbound_latest_id = info->id;
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);
1159 evas_object_show(genlist);
1164 void __bt_update_transfer_count(bt_share_appdata_t *ad, bt_tr_data_t *info)
1166 if (info->tr_status == BT_TRANSFER_SUCCESS)
1167 ad->transfer_info->success++;
1169 ad->transfer_info->failed++;
1171 if (ad->status_item)
1172 elm_genlist_item_fields_update(ad->status_item, "*",
1173 ELM_GENLIST_ITEM_FIELD_TEXT);
1176 void _bt_genlist_append_tr_data_item(bt_share_appdata_t *ad,
1177 bt_tr_data_t *info, int tr_type)
1181 ret_if(ad == NULL || info == NULL);
1182 ret_if(ad->tr_data_itc == NULL);
1183 ret_if(ad->tr_genlist == NULL);
1185 Elm_Object_Item *git = NULL;
1187 if (elm_genlist_items_count(ad->tr_genlist) == 0) {
1188 Evas_Object *genlist = NULL;
1189 Elm_Object_Item *navi_it = NULL;
1191 genlist = __bt_add_tr_data_genlist(ad->tr_view, ad);
1192 retm_if(genlist == NULL, "genlist is NULL!");
1194 if (ad->tr_genlist) {
1195 DBG("Clear the previous genlist");
1196 elm_genlist_clear(ad->tr_genlist);
1197 ad->tr_genlist = NULL;
1200 ad->tr_genlist = genlist;
1203 elm_object_item_part_content_set(ad->navi_it,
1204 "elm.swallow.content", genlist);
1206 navi_it = elm_naviframe_item_push(ad->navi_fr, NULL,
1207 NULL, NULL, genlist, NULL);
1209 elm_object_item_domain_translatable_text_set(navi_it,
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;
1219 if (!ad->file_title_item) {
1220 retm_if(NULL == __bt_add_file_title_item(ad),
1221 "__bt_add_file_title_item is failed");
1224 bt_gl_data_t *gl_data = NULL;
1225 gl_data = g_new0(bt_gl_data_t, 1);
1226 gl_data->tr_data = info;
1228 if (tr_type == BT_TR_OUTBOUND) {
1229 gl_data->tr_inbound = false;
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;
1236 if (ad->inbound_latest_id < info->id)
1237 ad->inbound_latest_id = info->id;
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);
1243 __bt_update_transfer_count(ad, info);
1245 if (info->tr_status == BT_TRANSFER_ONGOING)
1246 ad->current_item = git;
1248 evas_object_show(ad->tr_genlist);
1253 static void __bt_share_gl_highlighted(void *data, Evas_Object *obj,
1257 Elm_Object_Item *item = (Elm_Object_Item *)event_info;
1258 bt_gl_data_t *gl_data;
1260 ret_if(item == NULL);
1262 gl_data = (bt_gl_data_t *)elm_object_item_data_get(item);
1263 ret_if(gl_data == NULL);
1265 gl_data->highlighted = TRUE;
1267 elm_genlist_item_fields_update(item, "*",
1268 ELM_GENLIST_ITEM_FIELD_CONTENT);
1273 static void __bt_share_gl_unhighlighted(void *data, Evas_Object *obj,
1277 Elm_Object_Item *item = (Elm_Object_Item *)event_info;
1278 bt_gl_data_t *gl_data;
1280 ret_if(item == NULL);
1282 gl_data = (bt_gl_data_t *)elm_object_item_data_get(item);
1283 ret_if(gl_data == NULL);
1284 gl_data->highlighted = FALSE;
1286 elm_genlist_item_fields_update(item, "*",
1287 ELM_GENLIST_ITEM_FIELD_CONTENT);
1292 static Evas_Object *__bt_add_tr_data_genlist(Evas_Object *parent,
1293 bt_share_appdata_t *ad)
1296 retvm_if(ad == NULL, NULL, "Inavalid parameter!");
1298 Evas_Object *genlist = elm_genlist_add(parent);
1300 evas_object_smart_callback_add(genlist, "highlighted",
1301 __bt_share_gl_highlighted, ad);
1303 evas_object_smart_callback_add(genlist, "unhighlighted",
1304 __bt_share_gl_unhighlighted, ad);
1306 elm_genlist_homogeneous_set(genlist, EINA_TRUE);
1307 ad->tr_device_itc = elm_genlist_item_class_new();
1308 if (ad->tr_device_itc) {
1310 ad->tr_device_itc->item_style = "2line";
1312 ad->tr_device_itc->item_style = "type1";
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;
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;
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;
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;
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;
1356 elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
1361 static Evas_Object * __bt_create_naviframe(bt_share_appdata_t *ad)
1364 retv_if(ad == NULL, NULL);
1365 Evas_Object *navi_fr = NULL;
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);
1376 void _bt_cb_state_changed(int result,
1377 bt_adapter_state_e adapter_state,
1381 DBG("bluetooth %s", adapter_state == BT_ADAPTER_ENABLED ?
1382 "enabled" : "disabled");
1385 ret_if(result != BT_ERROR_NONE);
1387 bt_share_appdata_t *ad = (bt_share_appdata_t *)user_data;
1389 ad->bt_status = adapter_state;
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;
1399 _bt_share_ui_retry_failed(ad);
1400 if (ad->launch_mode == BT_LAUNCH_TRANSFER_LIST) {
1403 bt_tr_db_table_e table;
1405 __bt_get_noti_id_opp_role_and_table(ad, ¬i_id, &opp_role, &table);
1407 DBG_SECURE("Notification ID: %d", noti_id);
1409 ERR("Invalid Notification ID");
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);
1418 ad->send_after_turning_on = FALSE;
1419 _bt_terminate_app();
1424 gboolean __bt_share_is_battery_low(void)
1431 if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, (void *)&charging))
1432 ERR("Get the battery charging status fail");
1437 DBG("charging: %d", charging);
1439 if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, (void *)&value)) {
1440 ERR("Get the battery low status fail");
1444 if (value <= VCONFKEY_SYSMAN_BAT_POWER_OFF)
1451 int _bt_share_enable_bt(bt_share_appdata_t *ad)
1455 retv_if(ad == NULL, -1);
1457 if (__bt_share_is_battery_low() == TRUE) {
1458 // Battery is critical low
1459 _bt_main_create_information_popup(ad, BT_STR_LOW_BATTERY);
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);
1472 ad->turning_on_popup = _bt_share_add_turning_on_popup(ad);
1473 ad->send_after_turning_on = TRUE;
1479 void _bt_share_toolbar_button_cb(void *data, Evas_Object *obj,
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);
1487 const char *text = elm_object_text_get(obj);
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);
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);
1500 _bt_share_ui_retry_failed(ad);
1501 if (ad->launch_mode == BT_LAUNCH_TRANSFER_LIST) {
1504 bt_tr_db_table_e table;
1506 __bt_get_noti_id_opp_role_and_table(ad, ¬i_id, &opp_role, &table);
1508 DBG_SECURE("Notification ID: %d", noti_id);
1510 ERR("Invalid Notification ID");
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);
1518 _bt_terminate_app();
1526 Evas_Object * _bt_share_create_toolbar_button(bt_share_appdata_t *ad, char *text)
1528 Evas_Object *layout = NULL;
1529 Evas_Object *toolbar_button = NULL;
1531 layout = elm_layout_add(ad->navi_fr);
1532 elm_layout_file_set(layout, EDJFILE, "toolbar_button_ly");
1534 toolbar_button = elm_button_add(layout);
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);
1541 elm_object_text_set(toolbar_button, text);
1543 evas_object_smart_callback_add(toolbar_button, "clicked",
1544 _bt_share_toolbar_button_cb, ad);
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;
1553 void _bt_share_delete_toolbar_button(bt_share_appdata_t *ad)
1558 if (ad->toolbar_button) {
1559 evas_object_del(ad->toolbar_button);
1560 ad->toolbar_button = NULL;
1562 if (ad->toolbar_ly) {
1563 evas_object_del(ad->toolbar_ly);
1564 ad->toolbar_ly = NULL;
1569 static Eina_Bool __bt_list_item_add(bt_share_appdata_t *ad)
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);
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,
1582 tr_data_list = g_slist_next(tr_data_list);
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);
1596 static Eina_Bool __bt_list_item_idler(void *data)
1600 bt_share_appdata_t *ad = (bt_share_appdata_t *)data;
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);
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);
1611 while (NULL != tr_data_list) {
1612 _bt_genlist_prepend_tr_data_item(ad, ad->tr_genlist, tr_data_list->data,
1614 tr_data_list = g_slist_next(tr_data_list);
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);
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)) {
1634 bt_tr_db_table_e table;
1636 __bt_get_noti_id_opp_role_and_table(ad, ¬i_id, &opp_role, &table);
1638 DBG_SECURE("Notification ID: %d", noti_id);
1640 ERR("Invalid Notification ID");
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);
1647 _bt_delete_selected_notification(ad->tr_type, noti_id, opp_role);
1651 if (ad->status_item)
1652 elm_genlist_item_fields_update(ad->status_item, "*",
1653 ELM_GENLIST_ITEM_FIELD_TEXT);
1659 int _bt_create_transfer_view(bt_share_appdata_t *ad)
1662 retv_if(ad == NULL, -1);
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;
1672 __bt_clear_view(ad);
1673 bg = _bt_create_bg(ad->win, NULL);
1674 retv_if(bg == NULL, -1);
1677 conform = _bt_create_conformant(ad->win, NULL);
1678 retvm_if(conform == NULL, -1, "conform is NULL!");
1679 ad->conform = conform;
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);
1686 layout = _bt_create_layout(conform, EDJFILE, "share_view");
1687 ad->tr_view = layout;
1689 elm_object_content_set(conform, layout);
1690 elm_win_conformant_set(ad->win, EINA_TRUE);
1692 navi_fr = __bt_create_naviframe(ad);
1693 retvm_if(navi_fr == NULL, -1, "navi_fr is NULL!");
1694 ad->navi_fr = navi_fr;
1697 genlist = __bt_add_tr_data_genlist(layout, ad);
1698 retvm_if(genlist == NULL, -1, "genlist is NULL!");
1699 ad->tr_genlist = genlist;
1701 git = elm_genlist_item_append(genlist,
1702 ad->tr_device_itc, ad,
1703 NULL, ELM_GENLIST_ITEM_NONE,
1706 ERR("elm_genlist_item_append is failed!");
1708 elm_genlist_item_select_mode_set(git,
1709 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1710 ad->device_item = git;
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,
1719 ERR("elm_genlist_item_append is failed!");
1721 elm_genlist_item_select_mode_set(git,
1722 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1723 ad->status_item = git;
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;
1732 git = elm_genlist_item_append(genlist,
1733 ad->tr_progress_itc, ad,
1734 NULL, ELM_GENLIST_ITEM_NONE,
1737 ERR("elm_genlist_item_append is failed!");
1739 elm_genlist_item_select_mode_set(git,
1740 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1741 ad->progress_item = git;
1745 __bt_add_file_title_item(ad);
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!");
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;
1758 if (ad->launch_mode == BT_LAUNCH_ONGOING) {
1759 ad->toolbar_button = _bt_share_create_toolbar_button(ad,
1763 __bt_list_item_add(ad);
1765 ad->idler = ecore_idler_add(__bt_list_item_idler, ad);
1767 ERR("idler can not be added");