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);
388 elm_object_style_set(icon, "process_medium");
389 evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, 0.5);
390 evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
391 elm_progressbar_pulse(icon, TRUE);
393 } else if (info->tr_status == BT_TRANSFER_PENDING) {
394 icon = elm_progressbar_add(obj);
395 elm_object_style_set(icon, "process_medium");
396 evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, 0.5);
397 evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
398 elm_progressbar_pulse(icon, TRUE);
406 void _bt_util_get_number(char *source, char *dest)
412 slen = strlen(source);
417 if (isdigit(source[slen])) {
418 buf[len] = source[slen];
428 strcpy(dest, &buf[len]);
431 void _bt_util_get_contact_name(int lcontact_id, char **contact_name)
435 contacts_filter_h filter = NULL;
436 contacts_query_h query = NULL;
437 contacts_list_h list = NULL;
438 contacts_record_h record = NULL;
442 ret = contacts_filter_create(_contacts_contact._uri, &filter);
443 if (ret != CONTACTS_ERROR_NONE) {
444 ERR("Fail to create filter for contacts");
448 ret = contacts_filter_add_int(filter, _contacts_contact.id,
449 CONTACTS_MATCH_EXACTLY, lcontact_id);
450 if (ret != CONTACTS_ERROR_NONE) {
451 ERR("Fail to add str to filter for contacts");
455 ret = contacts_query_create(_contacts_contact._uri, &query);
456 if (ret != CONTACTS_ERROR_NONE) {
457 ERR("Fail to create qurey for contacts");
461 ret = contacts_query_set_filter(query, filter);
462 if (ret != CONTACTS_ERROR_NONE) {
463 ERR("Fail to set filter for contacts");
467 ret = contacts_db_get_count_with_query(query, &count);
468 if (ret != CONTACTS_ERROR_NONE) {
469 ERR("Fail to get count from db");
477 DBG("count = %d", count);
478 ret = contacts_db_get_records_with_query(query, 0, 0, &list);
479 if (ret != CONTACTS_ERROR_NONE) {
480 ERR("Fail to get records from db");
483 contacts_list_first(list);
485 while (ret == CONTACTS_ERROR_NONE) {
486 contacts_list_get_current_record_p(list, &record);
487 contacts_record_get_str_p(record,
488 _contacts_contact.display_name,
491 *contact_name = g_strdup(name);
495 ret = contacts_list_next(list);
500 contacts_filter_destroy(filter);
503 contacts_query_destroy(query);
506 contacts_list_destroy(list, true);
511 unsigned int bt_crc32(const void *src, unsigned long src_sz)
513 return (crc32(0, src, src_sz) & 0xFFFF);
516 void _bt_util_get_contact_info(unsigned char *auth_info, int *contact_id, char **contact_name)
518 unsigned int shash = 0;
519 unsigned int chash = 0;
520 char pnumber[20] = {0,};
521 char str_hash[7] = {0,};
522 int ret = CONTACTS_ERROR_NONE;
527 contacts_filter_h filter = NULL;
528 contacts_query_h query = NULL;
529 contacts_list_h list = NULL;
530 contacts_record_h record = NULL;
532 retm_if(!auth_info, "auth_info is NULL");
533 retm_if(!contact_id, "contact_id is NULL");
534 retm_if(!contact_name, "contact_name is NULL");
536 if (contacts_connect() != CONTACTS_ERROR_NONE) {
537 ERR("contacts_connect failed");
541 memcpy(&shash, auth_info, 3);
542 shash = ntohl(shash);
545 memcpy(&chash, &auth_info[3], 2);
546 chash = ntohl(chash);
549 g_snprintf(str_hash, 7, "%X", shash);
551 ret = contacts_filter_create(_contacts_quick_connect_info._uri, &filter);
552 if (ret != CONTACTS_ERROR_NONE) {
553 ERR("Fail to create filter for contacts");
557 ret = contacts_filter_add_str(filter, _contacts_quick_connect_info.hash,
558 CONTACTS_MATCH_EXACTLY, str_hash);
559 if (ret != CONTACTS_ERROR_NONE) {
560 ERR("Fail to add str to filter for contacts");
564 ret = contacts_query_create(_contacts_quick_connect_info._uri, &query);
565 if (ret != CONTACTS_ERROR_NONE) {
566 ERR("Fail to create qurey for contacts");
570 ret = contacts_query_set_filter(query, filter);
571 if (ret != CONTACTS_ERROR_NONE) {
572 ERR("Fail to set filter for contacts");
576 ret = contacts_db_get_count_with_query(query, &count);
577 if (ret != CONTACTS_ERROR_NONE) {
578 ERR("Fail to get count from db");
587 ret = contacts_db_get_records_with_query(query, 0, 0, &list);
588 if (ret != CONTACTS_ERROR_NONE) {
589 ERR("Fail to get records from db");
593 contacts_list_first(list);
595 while (ret == CONTACTS_ERROR_NONE) {
596 contacts_list_get_current_record_p(list, &record);
597 contacts_record_get_str_p(record,
598 _contacts_quick_connect_info.number,
600 DBG_SECURE("number: [%s]", number);
601 if (number != NULL) {
602 _bt_util_get_number(number, pnumber);
603 DBG_SECURE("pnumber: [%s]", pnumber);
605 DBG_SECURE("CRC [%X], [%X]", chash, bt_crc32(pnumber, strlen(pnumber)));
607 if (bt_crc32(pnumber , strlen(pnumber)) == chash) {
608 contacts_record_get_int(record,
609 _contacts_quick_connect_info.contact_id,
611 *contact_id = lcontact_id;
612 _bt_util_get_contact_name(lcontact_id, contact_name);
613 DBG_SECURE("contact id : %d", lcontact_id);
617 ret = contacts_list_next(list);
622 contacts_filter_destroy(filter);
625 contacts_query_destroy(query);
628 contacts_list_destroy(list, true);
630 contacts_disconnect();
636 static char *__bt_tr_device_label_get(void *data, Evas_Object *obj,
640 retv_if(data == NULL, NULL);
641 bt_share_appdata_t *ad = (bt_share_appdata_t *)data;
642 char *markup_text = NULL;
644 retv_if(ad->transfer_info == NULL, NULL);
646 if (!strcmp(part, BT_SHARE_ITEM_PART_DEVICE_NAME_TITLE)) {
647 return g_strdup(BT_STR_DEVICENAME);
648 } else if (!strcmp(part, BT_SHARE_ITEM_PART_DEVICE_NAME)) {
649 bt_share_transfer_data_t *transfer_info = ad->transfer_info;
650 DBG_SECURE("Device : %s", transfer_info->device_name);
651 if (ad->bt_status == BT_ADAPTER_ENABLED) {
652 bt_error_e ret = BT_ERROR_NONE;
653 bt_device_info_s *dev_info = NULL;
655 /* Get the contact name from manufacturer data */
656 DBG_SECURE("Address : %s", transfer_info->device_address);
657 ret = bt_adapter_get_bonded_device_info(transfer_info->device_address, &dev_info);
658 if (ret == BT_ERROR_NONE) {
659 DBG_SECURE("Using remote name [%s] only.", dev_info->remote_name);
660 markup_text = elm_entry_utf8_to_markup(dev_info->remote_name);
662 unsigned char auth_info[5] = {0, };
664 char *contact_name = NULL;
665 gboolean is_alias_set = FALSE;
666 ret = bt_adapter_get_bonded_device_is_alias_set(dev_info->remote_address, &is_alias_set);
667 if (ret != BT_ERROR_NONE)
668 ERR("bt_adapter_get_bonded_device_is_alias_set() is failed!!! error: 0x%04X", ret);
670 if (is_alias_set == TRUE) {
671 DBG_SECURE("Device alias is set. Using remote name [%s] only.", dev_info->remote_name);
672 markup_text = elm_entry_utf8_to_markup(dev_info->remote_name);
673 } else if (dev_info->manufacturer_data_len >= 30 &&
674 dev_info->manufacturer_data[0] == 0x00 &&
675 dev_info->manufacturer_data[1] == 0x75) {
676 unsigned char auth_info_null[5];
677 memset(auth_info_null, 0X0, 5);
678 memcpy(auth_info, &(dev_info->manufacturer_data[10]), 5);
680 /* Check for validity of auth_info */
681 if (memcmp(auth_info, auth_info_null, 5)) {
682 _bt_util_get_contact_info(auth_info, &contact_id, &contact_name);
683 DBG_SECURE("contact id : %d | contact name : %s", contact_id, contact_name);
685 markup_text = elm_entry_utf8_to_markup(contact_name);
686 g_free(contact_name);
691 bt_adapter_free_device_info(dev_info);
693 ERR("bt_adapter_get_bonded_device_info() is failed!!! error: 0x%04X", ret);
698 markup_text = elm_entry_utf8_to_markup(transfer_info->device_name);
706 static char *__bt_tr_status_label_get(void *data, Evas_Object *obj,
710 retv_if(data == NULL, NULL);
711 bt_share_appdata_t *ad = (bt_share_appdata_t *)data;
712 bt_share_transfer_data_t *transfer_info = ad->transfer_info;
713 char *tmp_success = NULL;
714 char *tmp_failed = NULL;
715 char *ret_str = NULL;
717 retv_if(transfer_info == NULL, NULL);
719 if (!strcmp(part, BT_SHARE_ITEM_PART_TRANSFER_TYPE_TITLE)) {
720 if (ad->tr_type == BT_TR_INBOUND)
721 return (transfer_info->success > 0) ?
722 g_strdup(BT_STR_FILE_RECEIVED) :
723 g_strdup(BT_STR_RECEIVING_FAILED);
725 return (transfer_info->success > 0) ?
726 g_strdup(BT_STR_FILE_SENT) :
727 g_strdup(BT_STR_SENDING_FAILED);
728 } else if (!strcmp(part, BT_SHARE_ITEM_PART_TRANSFER_STATUS)) {
729 char *stms_str = NULL;
731 DBG_SECURE("Success %d, Failed %d", transfer_info->success, transfer_info->failed);
732 if (transfer_info->success == 0 &&
733 transfer_info->failed == 0)
736 stms_str = (ad->tr_type == BT_TR_INBOUND) ? BT_STR_PD_RECEIVED : BT_STR_PD_SENT;
737 tmp_success = g_strdup_printf(stms_str, transfer_info->success);
739 stms_str = BT_STR_PD_FAILED;
740 tmp_failed = g_strdup_printf(stms_str, transfer_info->failed);
742 ret_str = g_strdup_printf("%s, %s", tmp_success, tmp_failed);
753 static char *__bt_tr_progress_label_get(void *data, Evas_Object *obj,
757 retv_if(data == NULL, NULL);
758 bt_share_appdata_t *ad = (bt_share_appdata_t *)data;
759 char *markup_text = NULL;
761 retv_if(ad->transfer_info == NULL, NULL);
763 if (!strcmp(part, BT_SHARE_ITEM_PART_PROGRESSBAR_FILE_NAME)) {
764 bt_share_transfer_data_t *transfer_info = ad->transfer_info;
765 markup_text = elm_entry_utf8_to_markup(transfer_info->filename);
766 DBG_SECURE("Filename: %s", markup_text);
775 static char *__bt_tr_file_title_label_get(void *data, Evas_Object *obj,
779 if (!strcmp(part, BT_SHARE_ITEM_PART_FILE_LIST_TITLE)) {
781 return g_strdup(BT_STR_FILE_LIST);
787 static char *__bt_tr_label_get(void *data, Evas_Object *obj,
791 bt_tr_data_t *info = NULL;
793 char buf[BT_GLOBALIZATION_STR_LENGTH] = { 0 };
794 bt_gl_data_t *gl_data = NULL;
795 char *markup_text = NULL;
796 retv_if(data == NULL, NULL);
797 gl_data = (bt_gl_data_t *)data;
798 retvm_if(gl_data == NULL, NULL, "gl_data is NULL!");
800 info = gl_data->tr_data;
801 retv_if(info == NULL, NULL);
803 if (!strcmp(part, BT_SHARE_ITEM_PART_FILE_NAME)) {
804 name = strrchr(info->file_path, '/');
808 name = info->file_path;
809 markup_text = elm_entry_utf8_to_markup(name);
811 g_strlcpy(buf, markup_text, BT_GLOBALIZATION_STR_LENGTH);
812 } else if (!strcmp(part, BT_SHARE_ITEM_PART_FILE_TRANSFER_STATUS_TEXT)) {
813 DBG("info->tr_status : %d", info->tr_status);
814 if (info->tr_status == BT_TRANSFER_SUCCESS) {
815 if (gl_data->tr_inbound)
816 g_strlcpy(buf, BT_STR_RECEIVED, BT_GLOBALIZATION_STR_LENGTH);
818 g_strlcpy(buf, BT_STR_SENT, BT_GLOBALIZATION_STR_LENGTH);
819 } else if (info->tr_status == BT_TRANSFER_FAIL) {
820 g_strlcpy(buf, BT_STR_FAILED, BT_GLOBALIZATION_STR_LENGTH);
821 } else if (info->tr_status == BT_TRANSFER_ONGOING) {
822 if (gl_data->tr_inbound)
823 g_strlcpy(buf, BT_STR_RECEIVING, BT_GLOBALIZATION_STR_LENGTH);
825 g_strlcpy(buf, BT_STR_SENDING, BT_GLOBALIZATION_STR_LENGTH);
826 } else if (info->tr_status == BT_TRANSFER_PENDING) {
827 g_strlcpy(buf, BT_STR_WAITING, BT_GLOBALIZATION_STR_LENGTH);
829 } else if (!strcmp(part, BT_SHARE_ITEM_PART_FILE_SIZE)) {
832 if ((info->tr_status == BT_TRANSFER_ONGOING ||
833 info->tr_status == BT_TRANSFER_PENDING) && gl_data->tr_inbound)
836 if (info->size > 1024 * 1024 * 1024) { //GB
837 size = g_strdup_printf("%.2f GB", (float)info->size / (1024 * 1024 * 1024));
838 } else if (info->size > 1024 * 1024) { //MB
839 size = g_strdup_printf("%.1f MB", (float)info->size / (1024 * 1024));
840 } else if (info->size > 1024) { //KB
841 size = g_strdup_printf("%.1f KB", (float)info->size / (1024));
843 size = g_strdup_printf("%d B", info->size);
846 g_strlcpy(buf, size, BT_GLOBALIZATION_STR_LENGTH);
849 DBG("empty text for label.");
859 static void __bt_tr_del(void *data, Evas_Object *obj)
861 bt_gl_data_t *gl_data;
862 gl_data = (bt_gl_data_t *)data;
868 static void __bt_genlist_realized_cb(void *data,
869 Evas_Object *obj, void *event_info)
871 retm_if(event_info == NULL, "Invalid param\n");
873 Elm_Object_Item *item = (Elm_Object_Item *)event_info;
874 #ifdef KIRAN_ACCESSIBILITY
876 char str[BT_STR_ACCES_INFO_MAX_LEN] = {0, };
881 bt_gl_data_t *gl_data;
883 gl_data = (bt_gl_data_t *)elm_object_item_data_get(item);
884 ret_if(gl_data == NULL);
886 info = gl_data->tr_data;
888 ret_if(info == NULL);
889 ret_if(info->dev_name == NULL);
890 ret_if(info->file_path == NULL);
892 name = strrchr(info->file_path, '/');
896 name = info->file_path;
898 date = __bt_get_tr_timedate((time_t)(info->timestamp));
900 #ifdef KIRAN_ACCESSIBILITY
901 snprintf(str, sizeof(str), "%s, %s, %s, %s",
902 BT_STR_ACC_ICON, name, info->dev_name, date);
903 ao = elm_object_item_access_object_get(item);
904 elm_access_info_set(ao, ELM_ACCESS_INFO, str);
910 static void __bt_popup_del_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
913 retm_if(data == NULL, "data is NULL");
914 bt_share_appdata_t *ad = (bt_share_appdata_t *)data;
916 if (ad->info_popup) {
917 evas_object_del(ad->info_popup);
918 ad->info_popup = NULL;
923 void __bt_popup_del_by_timeout(void *data, Evas_Object *obj, void *event_info)
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 Evas_Object *__bt_create_error_popup(bt_share_appdata_t *ad)
938 Evas_Object *popup = NULL;
939 retvm_if(ad == NULL, NULL, "ad is NULL");
941 popup = elm_popup_add(ad->win);
942 retvm_if(popup == NULL, NULL, "popup is NULL");
944 elm_object_focus_set(popup, EINA_FALSE);
945 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
947 elm_object_text_set(popup, BT_STR_UNABLE_TO_FIND_APPLICATION);
949 elm_popup_timeout_set(popup, 3);
950 evas_object_smart_callback_add(popup, "timeout", (Evas_Smart_Cb)__bt_popup_del_by_timeout, ad);
951 evas_object_show(popup);
952 evas_object_event_callback_add(popup, EVAS_CALLBACK_DEL, __bt_popup_del_cb, ad);
954 ad->info_popup = popup;
960 static bt_file_type_e __get_file_type(const char *name)
966 extn = strrchr(name, '.');
971 DBG("extn : %s", extn);
972 if (!strcasecmp(extn, "png") || !strcasecmp(extn, "bmp") || !strcasecmp(extn, "gif") ||
973 !strcasecmp(extn, "jpg") || !strcasecmp(extn, "jpeg") || !strcasecmp(extn, "jpe") ||
974 !strcasecmp(extn, "jp2") || !strcasecmp(extn, "pjpeg") || !strcasecmp(extn, "tif") ||
975 !strcasecmp(extn, "wbmp") || !strcasecmp(extn, "wmf"))
976 return BT_FILE_IMAGE;
977 else if (!strcasecmp(extn, "vcf"))
978 return BT_FILE_VCARD;
979 else if (!strcasecmp(extn, "vcs"))
981 else if (!strcasecmp(extn, "vbm"))
982 return BT_FILE_VBOOKMARK;
985 return BT_FILE_OTHER;
988 static gboolean __bt_open_file(const char *path)
991 app_control_h handle;
993 bt_file_type_e file_type;
994 bt_share_appdata_t *ad = app_state;
996 app_control_create(&handle);
997 app_control_set_operation(handle, APP_CONTROL_OPERATION_VIEW);
998 app_control_set_uri(handle, path);
1000 file_type = __get_file_type(path);
1002 if (file_type == BT_FILE_IMAGE) {
1003 app_control_set_mime(handle, "image/*");
1004 app_control_add_extra_data(handle, "Path", path);
1005 app_control_set_launch_mode(handle, APP_CONTROL_LAUNCH_MODE_GROUP);
1008 ret = app_control_send_launch_request(handle, NULL, NULL);
1010 if (ret == APP_CONTROL_ERROR_APP_NOT_FOUND)
1011 __bt_create_error_popup(ad);
1013 app_control_destroy(handle);
1018 static Elm_Object_Item * __bt_add_file_title_item(bt_share_appdata_t *ad)
1020 retvm_if(!ad, NULL, "ad is NULL!");
1021 retvm_if(!ad->tr_genlist, NULL, "tr_genlist is NULL!");
1022 retvm_if(ad->file_title_item, NULL, "file_title_item is exist");
1024 Elm_Object_Item *git = NULL;
1025 git = elm_genlist_item_append(ad->tr_genlist,
1026 ad->tr_file_title_itc, NULL,
1027 NULL, ELM_GENLIST_ITEM_NONE,
1031 ERR("elm_genlist_item_append is failed!");
1033 elm_genlist_item_select_mode_set(git,
1034 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1035 ad->file_title_item = git;
1041 static void __bt_tr_data_item_sel(void *data, Evas_Object *obj, void *event_info)
1043 bt_share_appdata_t *ad = app_state;
1044 bt_gl_data_t *gl_data = (bt_gl_data_t *) data;
1045 bt_tr_data_t *info = NULL;
1048 int default_memory = 0;
1050 ret_if(data == NULL);
1051 ret_if(event_info == NULL);
1055 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
1057 info = gl_data->tr_data;
1058 retm_if(info->file_path == NULL, "File Path is NULL");
1060 ext = strrchr(info->file_path, '.');
1062 if (0 == g_strcmp0(ext, "vcf")) {
1063 if (gl_data->tr_inbound == true) {
1064 if (info->tr_status == BT_TRANSFER_SUCCESS)
1065 _bt_create_info_popup(ad, BT_STR_RECEIVED_VCF_FILE_ALREADY_IMPORTED_TO_CONTACTS);
1067 _bt_create_info_popup(ad, BT_STR_VCF_FILES_ARE_TEMPORARY_AND_CANT_BE_OPENED);
1073 if (gl_data->tr_inbound == true) {
1074 if (info->tr_status == BT_TRANSFER_SUCCESS) {
1075 if (vconf_get_int(VCONFKEY_SETAPPL_DEFAULT_MEM_BLUETOOTH_INT, &default_memory) != 0)
1076 ERR("vconf get failed");
1078 if (default_memory == BT_DEFAULT_MEM_PHONE)
1079 path = g_strdup_printf("%s/%s", BT_DOWNLOAD_PHONE_FOLDER, info->file_path);
1080 else if (default_memory == BT_DEFAULT_MEM_MMC)
1081 path = g_strdup_printf("%s/%s", BT_DOWNLOAD_MMC_FOLDER, info->file_path);
1084 INFO_SECURE("path : %s", path);
1086 INFO_SECURE("path is empty");
1088 if (path && access(path, F_OK) == 0)
1089 __bt_open_file(path);
1091 _bt_create_info_popup(ad, BT_STR_FILE_NOT_EXIST);
1096 path = info->file_path;
1097 INFO_SECURE("path : %s", path);
1099 if (path && access(path, F_OK) == 0) {
1100 if (g_str_has_prefix(path, BT_CONTACT_SHARE_TMP_DIR) == TRUE)
1101 /* TODO: change to proper string when UX is updated */
1102 _bt_create_info_popup(ad, BT_STR_FILE_NOT_EXIST);
1104 __bt_open_file(path);
1106 _bt_create_info_popup(ad, BT_STR_FILE_NOT_EXIST);
1113 void _bt_genlist_prepend_tr_data_item(bt_share_appdata_t *ad,
1114 Evas_Object *genlist, bt_tr_data_t *info, int tr_type)
1117 retm_if(ad == NULL || info == NULL, "Invalid parameters!");
1118 retm_if(ad->tr_data_itc == NULL, "ad->tr_data_itc is NULL!");
1120 bt_gl_data_t *gl_data = NULL;
1122 gl_data = g_new0(bt_gl_data_t, 1);
1123 gl_data->tr_data = info;
1124 DBG("info->tr_status : %d", info->tr_status);
1125 if (tr_type == BT_TR_OUTBOUND || tr_type == BT_TR_INBOUND) {
1126 if (info->tr_status == BT_TRANSFER_SUCCESS)
1127 ad->transfer_info->success++;
1128 else if (info->tr_status == BT_TRANSFER_FAIL)
1129 ad->transfer_info->failed++;
1132 if (tr_type == BT_TR_OUTBOUND) {
1133 gl_data->tr_inbound = false;
1135 if (ad->outbound_latest_id < info->id)
1136 ad->outbound_latest_id = info->id;
1137 } else if (tr_type == BT_TR_INBOUND) {
1138 gl_data->tr_inbound = true;
1140 if (ad->inbound_latest_id < info->id)
1141 ad->inbound_latest_id = info->id;
1144 elm_genlist_item_append(genlist, ad->tr_data_itc, gl_data, NULL,
1145 ELM_GENLIST_ITEM_NONE, __bt_tr_data_item_sel, gl_data);
1147 evas_object_show(genlist);
1152 void __bt_update_transfer_count(bt_share_appdata_t *ad, bt_tr_data_t *info)
1154 if (info->tr_status == BT_TRANSFER_SUCCESS)
1155 ad->transfer_info->success++;
1157 ad->transfer_info->failed++;
1159 if (ad->status_item)
1160 elm_genlist_item_fields_update(ad->status_item, "*",
1161 ELM_GENLIST_ITEM_FIELD_TEXT);
1164 void _bt_genlist_append_tr_data_item(bt_share_appdata_t *ad,
1165 bt_tr_data_t *info, int tr_type)
1169 ret_if(ad == NULL || info == NULL);
1170 ret_if(ad->tr_data_itc == NULL);
1171 ret_if(ad->tr_genlist == NULL);
1173 Elm_Object_Item *git = NULL;
1175 if (elm_genlist_items_count(ad->tr_genlist) == 0) {
1176 Evas_Object *genlist = NULL;
1177 Elm_Object_Item *navi_it = NULL;
1179 genlist = __bt_add_tr_data_genlist(ad->tr_view, ad);
1180 retm_if(genlist == NULL, "genlist is NULL!");
1182 if (ad->tr_genlist) {
1183 DBG("Clear the previous genlist");
1184 elm_genlist_clear(ad->tr_genlist);
1185 ad->tr_genlist = NULL;
1188 ad->tr_genlist = genlist;
1191 elm_object_item_part_content_set(ad->navi_it,
1192 "elm.swallow.content", genlist);
1194 navi_it = elm_naviframe_item_push(ad->navi_fr, NULL,
1195 NULL, NULL, genlist, NULL);
1197 elm_object_item_domain_translatable_text_set(navi_it,
1199 (ad->tr_type == BT_TR_INBOUND) ?
1200 "IDS_ST_HEADER_RECEIVE" : "IDS_ST_HEADER_SEND");
1201 elm_naviframe_item_pop_cb_set(navi_it, __bt_back_button_cb, ad);
1202 ad->navi_it = navi_it;
1207 if (!ad->file_title_item) {
1208 retm_if(NULL == __bt_add_file_title_item(ad),
1209 "__bt_add_file_title_item is failed");
1212 bt_gl_data_t *gl_data = NULL;
1213 gl_data = g_new0(bt_gl_data_t, 1);
1214 gl_data->tr_data = info;
1216 if (tr_type == BT_TR_OUTBOUND) {
1217 gl_data->tr_inbound = false;
1219 if (ad->outbound_latest_id < info->id)
1220 ad->outbound_latest_id = info->id;
1221 } else if (tr_type == BT_TR_INBOUND) {
1222 gl_data->tr_inbound = true;
1224 if (ad->inbound_latest_id < info->id)
1225 ad->inbound_latest_id = info->id;
1228 git = elm_genlist_item_append(ad->tr_genlist, ad->tr_data_itc, gl_data,
1229 NULL, ELM_GENLIST_ITEM_NONE, __bt_tr_data_item_sel, gl_data);
1231 __bt_update_transfer_count(ad, info);
1233 if (info->tr_status == BT_TRANSFER_ONGOING)
1234 ad->current_item = git;
1236 evas_object_show(ad->tr_genlist);
1241 static void __bt_share_gl_highlighted(void *data, Evas_Object *obj,
1245 Elm_Object_Item *item = (Elm_Object_Item *)event_info;
1246 bt_gl_data_t *gl_data;
1248 ret_if(item == NULL);
1250 gl_data = (bt_gl_data_t *)elm_object_item_data_get(item);
1251 ret_if(gl_data == NULL);
1253 gl_data->highlighted = TRUE;
1255 elm_genlist_item_fields_update(item, "*",
1256 ELM_GENLIST_ITEM_FIELD_CONTENT);
1261 static void __bt_share_gl_unhighlighted(void *data, Evas_Object *obj,
1265 Elm_Object_Item *item = (Elm_Object_Item *)event_info;
1266 bt_gl_data_t *gl_data;
1268 ret_if(item == NULL);
1270 gl_data = (bt_gl_data_t *)elm_object_item_data_get(item);
1271 ret_if(gl_data == NULL);
1272 gl_data->highlighted = FALSE;
1274 elm_genlist_item_fields_update(item, "*",
1275 ELM_GENLIST_ITEM_FIELD_CONTENT);
1280 static Evas_Object *__bt_add_tr_data_genlist(Evas_Object *parent,
1281 bt_share_appdata_t *ad)
1284 retvm_if(ad == NULL, NULL, "Inavalid parameter!");
1286 Evas_Object *genlist = elm_genlist_add(parent);
1288 evas_object_smart_callback_add(genlist, "highlighted",
1289 __bt_share_gl_highlighted, ad);
1291 evas_object_smart_callback_add(genlist, "unhighlighted",
1292 __bt_share_gl_unhighlighted, ad);
1294 elm_genlist_homogeneous_set(genlist, EINA_TRUE);
1295 ad->tr_device_itc = elm_genlist_item_class_new();
1296 if (ad->tr_device_itc) {
1297 ad->tr_device_itc->item_style = "type1";
1298 ad->tr_device_itc->func.text_get = __bt_tr_device_label_get;
1299 ad->tr_device_itc->func.content_get = NULL;
1300 ad->tr_device_itc->func.state_get = NULL;
1301 ad->tr_device_itc->func.del = NULL;
1304 ad->tr_status_itc = elm_genlist_item_class_new();
1305 if (ad->tr_status_itc) {
1306 ad->tr_status_itc->item_style = "type1";
1307 ad->tr_status_itc->func.text_get = __bt_tr_status_label_get;
1308 ad->tr_status_itc->func.content_get = NULL;
1309 ad->tr_status_itc->func.state_get = NULL;
1310 ad->tr_status_itc->func.del = NULL;
1313 ad->tr_progress_itc = elm_genlist_item_class_new();
1314 if (ad->tr_progress_itc) {
1315 ad->tr_progress_itc->item_style = "full";
1316 ad->tr_progress_itc->func.text_get = NULL;
1317 ad->tr_progress_itc->func.content_get = __bt_tr_progress_icon_get;
1318 ad->tr_progress_itc->func.state_get = NULL;
1319 ad->tr_progress_itc->func.del = NULL;
1322 ad->tr_file_title_itc = elm_genlist_item_class_new();
1323 if (ad->tr_file_title_itc) {
1324 ad->tr_file_title_itc->item_style = "groupindex";
1325 ad->tr_file_title_itc->func.text_get = __bt_tr_file_title_label_get;
1326 ad->tr_file_title_itc->func.content_get = NULL;
1327 ad->tr_file_title_itc->func.state_get = NULL;
1328 ad->tr_file_title_itc->func.del = NULL;
1331 ad->tr_data_itc = elm_genlist_item_class_new();
1332 if (ad->tr_data_itc) {
1333 ad->tr_data_itc->item_style = "type1";
1334 ad->tr_data_itc->func.text_get = __bt_tr_label_get;
1335 ad->tr_data_itc->func.content_get = __bt_tr_icon_get;
1336 ad->tr_data_itc->func.state_get = NULL;
1337 ad->tr_data_itc->func.del = __bt_tr_del;
1340 elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
1345 static Evas_Object * __bt_create_naviframe(bt_share_appdata_t *ad)
1348 retv_if(ad == NULL, NULL);
1349 Evas_Object *navi_fr = NULL;
1351 navi_fr = elm_naviframe_add(ad->tr_view);
1352 eext_object_event_callback_add(navi_fr, EEXT_CALLBACK_BACK,
1353 eext_naviframe_back_cb, NULL);
1354 elm_object_part_content_set(ad->tr_view, "elm.swallow.content", navi_fr);
1355 evas_object_show(navi_fr);
1360 void _bt_cb_state_changed(int result,
1361 bt_adapter_state_e adapter_state,
1365 DBG("bluetooth %s", adapter_state == BT_ADAPTER_ENABLED ?
1366 "enabled" : "disabled");
1369 ret_if(result != BT_ERROR_NONE);
1371 bt_share_appdata_t *ad = (bt_share_appdata_t *)user_data;
1373 ad->bt_status = adapter_state;
1375 if (adapter_state == BT_ADAPTER_ENABLED && ad->send_after_turning_on) {
1376 DBG("Adapter enabled, resend pending items");
1377 /* close turning on popup */
1378 if (ad->turning_on_popup) {
1379 evas_object_del(ad->turning_on_popup);
1380 ad->turning_on_popup = NULL;
1383 _bt_share_ui_retry_failed(ad);
1384 if (ad->launch_mode == BT_LAUNCH_TRANSFER_LIST) {
1387 bt_tr_db_table_e table;
1389 __bt_get_noti_id_opp_role_and_table(ad, ¬i_id, &opp_role, &table);
1391 DBG_SECURE("Notification ID: %d", noti_id);
1393 ERR("Invalid Notification ID");
1395 sqlite3 *db = bt_share_open_db();
1396 bt_share_remove_tr_data_by_notification(db, table, noti_id);
1397 bt_share_close_db(db);
1398 _bt_delete_selected_notification(ad->tr_type, noti_id, opp_role);
1402 ad->send_after_turning_on = FALSE;
1403 _bt_terminate_app();
1408 gboolean __bt_share_is_battery_low(void)
1415 if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, (void *)&charging))
1416 ERR("Get the battery charging status fail");
1421 DBG("charging: %d", charging);
1423 if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, (void *)&value)) {
1424 ERR("Get the battery low status fail");
1428 if (value <= VCONFKEY_SYSMAN_BAT_POWER_OFF)
1435 int _bt_share_enable_bt(bt_share_appdata_t *ad)
1439 retv_if(ad == NULL, -1);
1441 if (__bt_share_is_battery_low() == TRUE) {
1442 // Battery is critical low
1443 _bt_main_create_information_popup(ad, BT_STR_LOW_BATTERY);
1448 ret = bt_adapter_enable();
1449 if (ret == BT_ERROR_ALREADY_DONE) {
1450 _bt_cb_state_changed(BT_ERROR_NONE, BT_ADAPTER_ENABLED, ad);
1451 } else if (ret == BT_ERROR_NOW_IN_PROGRESS) {
1452 ERR("Enabling in progress [%d]", ret);
1453 } else if (ret != BT_ERROR_NONE) {
1454 ERR("Failed to enable bluetooth [%d]", ret);
1456 ad->turning_on_popup = _bt_share_add_turning_on_popup(ad);
1457 ad->send_after_turning_on = TRUE;
1463 void _bt_share_toolbar_button_cb(void *data, Evas_Object *obj,
1468 bt_share_appdata_t *ad = (bt_share_appdata_t *)data;
1469 bt_share_abort_data_t *abort_data = g_new0(bt_share_abort_data_t, 1);
1471 const char *text = elm_object_text_get(obj);
1473 if (g_strcmp0(text, BT_STR_STOP) == 0) {
1474 if (ad->transfer_info) {
1475 abort_data->transfer_id = ad->transfer_info->transfer_id;
1476 abort_data->transfer_type = ad->transfer_info->transfer_type;
1477 _bt_abort_signal_send(ad, abort_data);
1479 } else if (g_strcmp0(text, BT_STR_RESEND_FAILED_FILES) == 0) {
1480 /* for BT off case */
1481 if (ad->bt_status == BT_ADAPTER_DISABLED) {
1482 _bt_share_enable_bt(ad);
1484 _bt_share_ui_retry_failed(ad);
1485 if (ad->launch_mode == BT_LAUNCH_TRANSFER_LIST) {
1488 bt_tr_db_table_e table;
1490 __bt_get_noti_id_opp_role_and_table(ad, ¬i_id, &opp_role, &table);
1492 DBG_SECURE("Notification ID: %d", noti_id);
1494 ERR("Invalid Notification ID");
1496 sqlite3 *db = bt_share_open_db();
1497 bt_share_remove_tr_data_by_notification(db, table, noti_id);
1498 bt_share_close_db(db);
1499 _bt_delete_selected_notification(ad->tr_type, noti_id, opp_role);
1502 _bt_terminate_app();
1510 Evas_Object * _bt_share_create_toolbar_button(bt_share_appdata_t *ad, char *text)
1512 Evas_Object *layout = NULL;
1513 Evas_Object *toolbar_button = NULL;
1515 layout = elm_layout_add(ad->navi_fr);
1516 elm_layout_file_set(layout, EDJFILE, "toolbar_button_ly");
1518 toolbar_button = elm_button_add(layout);
1520 /* Use "bottom" style button */
1521 elm_object_style_set(toolbar_button, "bottom");
1522 evas_object_size_hint_weight_set(toolbar_button, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1523 evas_object_size_hint_align_set(toolbar_button, EVAS_HINT_FILL, 0.5);
1525 elm_object_text_set(toolbar_button, text);
1527 evas_object_smart_callback_add(toolbar_button, "clicked",
1528 _bt_share_toolbar_button_cb, ad);
1530 /* Set button into "toolbar" swallow part */
1531 elm_object_part_content_set(layout, "button", toolbar_button);
1532 elm_object_item_part_content_set(ad->navi_it, "toolbar", layout);
1533 ad->toolbar_ly = layout;
1534 return toolbar_button;
1537 void _bt_share_delete_toolbar_button(bt_share_appdata_t *ad)
1542 if (ad->toolbar_button) {
1543 evas_object_del(ad->toolbar_button);
1544 ad->toolbar_button = NULL;
1546 if (ad->toolbar_ly) {
1547 evas_object_del(ad->toolbar_ly);
1548 ad->toolbar_ly = NULL;
1553 static Eina_Bool __bt_list_item_add(bt_share_appdata_t *ad)
1558 retv_if(!ad, EINA_FALSE);
1559 GSList *tr_data_list = ad->tr_data_list;
1560 retv_if(ad->launch_mode == BT_LAUNCH_TRANSFER_LIST && !tr_data_list, EINA_FALSE);
1562 /* Add first 5 genlist items */
1563 for (i = 0; NULL != tr_data_list && i < 5; i++) {
1564 _bt_genlist_prepend_tr_data_item(ad, ad->tr_genlist, tr_data_list->data,
1566 tr_data_list = g_slist_next(tr_data_list);
1569 if (ad->launch_mode == BT_LAUNCH_TRANSFER_LIST &&
1570 ad->tr_type == BT_TR_OUTBOUND && ad->transfer_info->failed) {
1571 ad->toolbar_button = _bt_share_create_toolbar_button(ad,
1572 BT_STR_RESEND_FAILED_FILES);
1580 static Eina_Bool __bt_list_item_idler(void *data)
1584 bt_share_appdata_t *ad = (bt_share_appdata_t *)data;
1586 retv_if(!ad, EINA_FALSE);
1587 GSList *tr_data_list = ad->tr_data_list;
1588 retv_if(ad->launch_mode == BT_LAUNCH_TRANSFER_LIST && !tr_data_list, EINA_FALSE);
1590 DBG("Total Items in List : %d", g_slist_length(tr_data_list));
1591 /* Add rest of the genlist items */
1592 if (g_slist_length(ad->tr_data_list) >= 5) {
1593 tr_data_list = g_slist_nth(ad->tr_data_list, 5);
1595 while (NULL != tr_data_list) {
1596 _bt_genlist_prepend_tr_data_item(ad, ad->tr_genlist, tr_data_list->data,
1598 tr_data_list = g_slist_next(tr_data_list);
1602 if (ad->launch_mode == BT_LAUNCH_TRANSFER_LIST &&
1603 ad->tr_type == BT_TR_OUTBOUND &&
1604 ad->transfer_info->failed &&
1605 ad->toolbar_button == NULL) {
1606 ad->toolbar_button = _bt_share_create_toolbar_button(ad,
1607 BT_STR_RESEND_FAILED_FILES);
1610 /* Delete the notification */
1611 /* TODO: Delete Notification only if
1612 * transfer(sent) is completed with no failed items or received screen related to this session */
1613 if (ad->launch_mode == BT_LAUNCH_TRANSFER_LIST &&
1614 ((ad->tr_type == BT_TR_OUTBOUND &&
1615 ad->transfer_info->failed == 0) || ad->tr_type == BT_TR_INBOUND)) {
1618 bt_tr_db_table_e table;
1620 __bt_get_noti_id_opp_role_and_table(ad, ¬i_id, &opp_role, &table);
1622 DBG_SECURE("Notification ID: %d", noti_id);
1624 ERR("Invalid Notification ID");
1626 if (ad->bt_status == BT_ADAPTER_DISABLED) {
1627 sqlite3 *db = bt_share_open_db();
1628 bt_share_remove_tr_data_by_notification(db, table, noti_id);
1629 bt_share_close_db(db);
1631 _bt_delete_selected_notification(ad->tr_type, noti_id, opp_role);
1635 if (ad->status_item)
1636 elm_genlist_item_fields_update(ad->status_item, "*",
1637 ELM_GENLIST_ITEM_FIELD_TEXT);
1643 int _bt_create_transfer_view(bt_share_appdata_t *ad)
1646 retv_if(ad == NULL, -1);
1648 Elm_Object_Item *navi_it = NULL;
1649 Elm_Object_Item *git = NULL;
1650 Evas_Object *conform = NULL;
1651 Evas_Object *navi_fr = NULL;
1652 Evas_Object *bg = NULL;
1653 Evas_Object *layout = NULL;
1654 Evas_Object *genlist = NULL;
1656 __bt_clear_view(ad);
1657 bg = _bt_create_bg(ad->win, NULL);
1658 retv_if(bg == NULL, -1);
1661 conform = _bt_create_conformant(ad->win, NULL);
1662 retvm_if(conform == NULL, -1, "conform is NULL!");
1663 ad->conform = conform;
1665 bg = elm_bg_add(conform);
1666 elm_object_style_set(bg, "indicator/headerbg");
1667 elm_object_part_content_set(conform, "elm.swallow.indicator_bg", bg);
1668 evas_object_show(bg);
1670 layout = _bt_create_layout(conform, EDJFILE, "share_view");
1671 ad->tr_view = layout;
1673 elm_object_content_set(conform, layout);
1674 elm_win_conformant_set(ad->win, EINA_TRUE);
1676 navi_fr = __bt_create_naviframe(ad);
1677 retvm_if(navi_fr == NULL, -1, "navi_fr is NULL!");
1678 ad->navi_fr = navi_fr;
1681 genlist = __bt_add_tr_data_genlist(layout, ad);
1682 retvm_if(genlist == NULL, -1, "genlist is NULL!");
1683 ad->tr_genlist = genlist;
1685 git = elm_genlist_item_append(genlist,
1686 ad->tr_device_itc, ad,
1687 NULL, ELM_GENLIST_ITEM_NONE,
1690 ERR("elm_genlist_item_append is failed!");
1692 elm_genlist_item_select_mode_set(git,
1693 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1694 ad->device_item = git;
1697 if (ad->launch_mode == BT_LAUNCH_TRANSFER_LIST) {
1698 git = elm_genlist_item_append(genlist,
1699 ad->tr_status_itc, ad,
1700 NULL, ELM_GENLIST_ITEM_NONE,
1703 ERR("elm_genlist_item_append is failed!");
1705 elm_genlist_item_select_mode_set(git,
1706 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1707 ad->status_item = git;
1709 } else if (ad->launch_mode == BT_LAUNCH_ONGOING) {
1710 if (ad->progress_item) {
1711 elm_object_item_del(ad->progress_item);
1712 ad->progress_item = NULL;
1713 ad->progressbar = NULL;
1716 git = elm_genlist_item_append(genlist,
1717 ad->tr_progress_itc, ad,
1718 NULL, ELM_GENLIST_ITEM_NONE,
1721 ERR("elm_genlist_item_append is failed!");
1723 elm_genlist_item_select_mode_set(git,
1724 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1725 ad->progress_item = git;
1729 __bt_add_file_title_item(ad);
1731 navi_it = elm_naviframe_item_push(navi_fr, NULL,
1732 NULL, NULL, genlist, NULL);
1733 if (navi_it == NULL) {
1734 ERR("elm_naviframe_item_push is failed!");
1736 elm_object_item_domain_translatable_text_set(navi_it, BT_COMMON_PKG,
1737 (ad->tr_type == BT_TR_INBOUND) ? "IDS_ST_HEADER_RECEIVE" : "IDS_ST_HEADER_SEND");
1738 elm_naviframe_item_pop_cb_set(navi_it, __bt_back_button_cb, ad);
1739 ad->navi_it = navi_it;
1742 if (ad->launch_mode == BT_LAUNCH_ONGOING) {
1743 ad->toolbar_button = _bt_share_create_toolbar_button(ad,
1747 __bt_list_item_add(ad);
1749 ad->idler = ecore_idler_add(__bt_list_item_idler, ad);
1751 ERR("idler can not be added");