2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <metadata_extractor.h>
19 #include <image_util.h>
23 #include "email-debug.h"
24 #include "email-composer.h"
25 #include "email-composer-util.h"
26 #include "email-composer-attachment.h"
27 #include "email-composer-filetype.h"
28 #include "email-composer-callback.h"
29 #include "email-composer-recipient.h"
30 #include "email-composer-js.h"
32 EmailComposerUGD *g_ugd;
34 static void _composer_attachment_delete_icon_clicked_cb(void *data, Evas_Object *obj, void *event_info);
35 static void _composer_attachment_delete_all_icon_clicked_cb(void *data, Evas_Object *obj, void *event_info);
36 static void _composer_attachment_contracted_item_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
37 static void _composer_attachment_unfocus(void *data, Evas_Object *obj, const char *emission, const char *source);
39 static void _composer_attachment_mouse_clicked(void *data, Evas_Object *obj, const char *emission, const char *source);
43 * Returns total size of attachments including attachments, inline images and new files to be attached/inserted.
45 * @param [in] ugd composer ui gadget data
46 * @param [in] files_list contains 'to be attached/inserted' filepaths. NULL is passed if there is no new files
48 * @return total size or -1 incase of 'stat' error
50 int _composer_get_attachments_total_size(EmailComposerUGD *ugd)
56 int total_attachments_size = 0;
58 struct stat file_info;
61 Eina_Iterator *it = NULL;
62 Evas_Object *attachment_obj = NULL;
63 email_attachment_data_t *attachment_data = NULL;
65 it = eina_list_iterator_new(ugd->attachment_item_obj_list);
67 while (eina_iterator_next(it, (void **)&attachment_obj)) {
69 attachment_data = evas_object_data_get(attachment_obj, "attachment_data");
71 if (attachment_data) {
73 if ((return_stat = stat(attachment_data->attachment_path, &file_info)) == -1) {
74 debug_log("stat Error(%d): %s", errno, strerror(errno));
75 return COMPOSER_ERROR_INVALID_FILE;
78 debug_log("attach_size in byte : %d", file_info.st_size);
80 /* if (file_info.st_size / 1024 > 1)
81 temp_file_size = file_info.st_size / 1024;
85 attach_size += file_info.st_size;
90 eina_iterator_free(it);
93 if (EINA_TRUE == ugd->has_body_html) {
95 inline_size = _composer_get_inline_images_size(ugd);
96 if (inline_size < 0) {
97 debug_log("Failed to get inline images total size");
98 return COMPOSER_ERROR_INVALID_FILE_SIZE;
102 debug_log("existing attachments size = %d, existing inline images size = %d", attach_size, inline_size);
104 total_attachments_size = inline_size + attach_size;
106 debug_log("total size = %d", total_attachments_size);
108 return total_attachments_size;
112 * Returns total size of files
114 * @param [in] files_list contains file paths
116 * @return total size or -1 incase of 'stat' error
118 int _composer_get_files_size(Eina_List *files_list)
123 return COMPOSER_ERROR_NULL_POINTER;
125 Eina_List *list = files_list;
132 EINA_LIST_FOREACH(list, l, recv) {
133 debug_log("File : %s", recv);
135 file_size = ecore_file_size(recv);
136 debug_log("file_size : %d", file_size);
137 temp_size = temp_size + file_size;
138 debug_log("total_size : %d", temp_size);
141 debug_log("Files total size : %d", temp_size);
146 * Returns total size of inline images in mail body
148 * @param [in] ugd composer ui gadget data
150 * @return total size or -1 incase of 'stat' error
152 int _composer_get_inline_images_size(EmailComposerUGD *ugd)
157 if (EINA_TRUE == ugd->has_body_html) {
158 debug_log("listOfImageUrls count : %d", eina_list_count(ugd->listOfImageUrls));
159 if (eina_list_count(ugd->listOfImageUrls) > 0) {
161 Eina_List *list = ugd->listOfImageUrls;
165 Eina_List *inline_list = NULL;
167 EINA_LIST_FOREACH(list, l, recv) {
168 if (strncmp(recv, "file://", 7) == 0) {
169 debug_log("Inline image : %s", recv + 7);
170 inline_list = eina_list_append(inline_list, recv + 7);
173 if (eina_list_count(inline_list) > 0) {
174 total_size = _composer_get_files_size(inline_list); // -1 on 'stat' error of inline image file
177 eina_list_free(inline_list);
180 //eina_list_free(listOfImageUrls);
183 debug_log("Inline images total size : %d", total_size);
187 void _composer_attachment_reset(EmailComposerUGD *ugd)
191 Eina_Iterator *it = NULL;
192 Evas_Object *attachment_obj = NULL;
193 email_attachment_data_t *attachment_data = NULL;
195 it = eina_list_iterator_new(ugd->attachment_item_obj_list);
197 while (eina_iterator_next(it, (void **)&attachment_obj)) {
199 attachment_data = evas_object_data_get(attachment_obj, "attachment_data");
201 if (attachment_data) {
202 debug_log("attachment_data file name to be removed : %s", attachment_data->attachment_path);
204 email_free_attachment_data(&attachment_data, 1);
205 attachment_data = NULL;
208 elm_box_unpack(ugd->attachment_item_box, attachment_obj);
209 evas_object_del(attachment_obj);
212 if (ugd->new_mail_info) {
213 if (ugd->new_mail_info->mail_data) {
214 ugd->new_mail_info->mail_data->attachment_count = 0;
218 if (ugd->attachment_item_box) {
219 //elm_box_unpack(ugd->subject_box, ugd->attachment_item_box);
220 evas_object_del(ugd->attachment_item_box);
221 ugd->attachment_item_box = NULL;
225 eina_iterator_free(it);
228 if (ugd->attachment_item_obj_list) {
229 eina_list_free(ugd->attachment_item_obj_list);
230 ugd->attachment_item_obj_list = NULL;
233 if (ugd->attachment_contracted_item) {
234 elm_box_unpack(ugd->attachment_item_box, ugd->attachment_contracted_item);
235 evas_object_del(ugd->attachment_contracted_item);
236 ugd->attachment_contracted_item = NULL;
240 void _composer_attachment_create_list(EmailComposerUGD *ugd, Eina_List *attachment_list, Eina_Bool is_inline)
244 if (attachment_list == NULL)
247 int nTobeAttachedCount = eina_list_count(attachment_list);
248 debug_log("nTobeAttachedCount : %d", nTobeAttachedCount);
250 if (nTobeAttachedCount <= 0)
253 int nAttachmentObjListCount = eina_list_count(ugd->attachment_item_obj_list);
254 debug_log("nAttachmentObjListCount : %d", nAttachmentObjListCount);
256 if (ugd->attachment_item_box == NULL) {
257 Evas_Object *attachment_item_box;
258 attachment_item_box = _composer_create_box(ugd->main_layout);
259 elm_object_focus_allow_set(attachment_item_box, EINA_TRUE);
260 elm_object_part_content_set(ugd->c_layout, "_attachment_field", attachment_item_box);
261 ugd->attachment_item_box = attachment_item_box;
263 _composer_attachment_expand_items(ugd);
266 bool bDuplicated = FALSE;
270 struct stat file_info;
273 email_attachment_data_t *attachment_data = NULL;
275 int nCount = nAttachmentObjListCount;
276 int total_attachments_size = _composer_get_attachments_total_size(ugd);
278 EINA_LIST_FOREACH(attachment_list, l, recv) {
280 bDuplicated = _composer_attachment_duplicate_check(ugd, recv);
283 debug_log("Attachment is duplicated");
285 if (ugd->composer_noti) {
286 evas_object_del(ugd->composer_noti);
287 ugd->composer_noti = NULL;
289 ugd->composer_noti = _composer_create_noti(ugd, false, dgettext("sys_string", "IDS_COM_POP_WARNING"), _("IDS_EMAIL_POP_FILE_ALREADY_EXISTS"), 0, NULL, NULL, 2.0,
290 _composer_noti_response_cb);
296 EINA_LIST_FOREACH(attachment_list, l, recv) {
298 bDuplicated = _composer_attachment_duplicate_check(ugd, recv);
303 if ((return_stat = stat(recv, &file_info)) == -1) {
304 debug_log("stat Error(%d): %s", errno, strerror(errno));
305 eina_list_free(attachment_list);
306 attachment_list = NULL;
308 if (ugd->composer_noti) {
309 evas_object_del(ugd->composer_noti);
310 ugd->composer_noti = NULL;
312 ugd->composer_noti = _composer_create_noti(ugd, false, dgettext("sys_string", "IDS_COM_POP_WARNING"),
313 _("IDS_EMAIL_POP_UNABLE_TO_ATTACH_FILE"), 0, NULL, NULL, 1.5, _composer_noti_response_cb);
317 /* if (file_info.st_size / 1024 > 1)
318 temp_file_size = file_info.st_size / 1024;
322 total_attachments_size += file_info.st_size;
324 if (total_attachments_size > MAX_ATTACHMENT_SIZE) {
325 debug_log("Total size is over");
327 char msg[MAX_STR_LEN] = { 0, };
328 snprintf(msg, sizeof(msg), _("IDS_EMAIL_POP_UNABLE_TO_ATTACH_MAXIMUM_SIZE_OF_FILES_IS_PD_KB"), MAX_ATTACHMENT_SIZE / 1024);
330 if (ugd->composer_noti) {
331 evas_object_del(ugd->composer_noti);
332 ugd->composer_noti = NULL;
334 ugd->composer_noti = _composer_create_noti(ugd, false, dgettext("sys_string", "IDS_COM_POP_WARNING"), msg, 0, NULL, NULL, 2.0,
335 _composer_noti_response_cb);
337 eina_list_free(attachment_list);
338 attachment_list = NULL;
343 if (nCount >= MAX_ATTACHMENT_ITEM) {
344 debug_log("Total count is over");
346 char msg[MAX_STR_LEN] = { 0, };
347 snprintf(msg, sizeof(msg), _("IDS_EMAIL_POP_UNABLE_TO_ATTACH_MAXIMUM_NUMBER_OF_FILES_IS_PD"), MAX_ATTACHMENT_ITEM);
349 if (ugd->composer_noti) {
350 evas_object_del(ugd->composer_noti);
351 ugd->composer_noti = NULL;
353 ugd->composer_noti = _composer_create_noti(ugd, false, dgettext("sys_string", "IDS_COM_POP_WARNING"), msg, 0, NULL, NULL, 2.0,
354 _composer_noti_response_cb);
356 eina_list_free(attachment_list);
357 attachment_list = NULL;
362 attachment_data = (email_attachment_data_t *)calloc(1, sizeof(email_attachment_data_t));
365 tokens = g_strsplit(recv, "/", -1);
367 attachment_data->attachment_name = COMPOSER_STRDUP(tokens[g_strv_length(tokens) - 1]);
368 attachment_data->attachment_path = COMPOSER_STRDUP(recv);
369 attachment_data->save_status = 1;
370 attachment_data->attachment_size = file_info.st_size;
373 attachment_data->inline_content_status = 1;
375 debug_log("attachment_name = %s, attachment_path = %s", attachment_data->attachment_name, attachment_data->attachment_path);
379 _composer_attachment_create_list_box(ugd, attachment_data);
384 if (_composer_check_recipient_is_empty(ugd)) {
385 if (!ugd->bSendBtnDisabled) {
386 elm_object_disabled_set(ugd->send_btn, EINA_TRUE);
387 ugd->bSendBtnDisabled = true;
390 if (ugd->bSendBtnDisabled) {
391 elm_object_disabled_set(ugd->send_btn, EINA_FALSE);
392 ugd->bSendBtnDisabled = false;
396 eina_list_free(attachment_list);
397 attachment_list = NULL;
400 void _composer_attachment_create_list_box(EmailComposerUGD *ugd, email_attachment_data_t *attachment_data)
402 debug_log("file name: %s", attachment_data->attachment_path);
404 if (attachment_data->attachment_path) {
405 if (attachment_data->inline_content_status == EINA_FALSE) {
408 Evas_Object *attachment_item = elm_layout_add(ugd->attachment_item_box);
410 elm_layout_file_set(attachment_item, COMPOSER_EDJ_NAME, "layout.attachment");
411 evas_object_size_hint_weight_set(attachment_item, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
412 evas_object_size_hint_align_set(attachment_item, EVAS_HINT_FILL, EVAS_HINT_FILL);
414 Evas_Object *delete_icon = NULL;
416 _composer_attachment_add_thumbnail(ugd, attachment_item, attachment_data->attachment_path);
417 delete_icon = _composer_attachment_add_delete_icon(ugd, attachment_item);
418 _composer_attachment_add_filename(ugd, attachment_data, attachment_item);
420 Evas_Object *attachment_base = elm_layout_add(ugd->attachment_item_box);
421 elm_layout_theme_set(attachment_base, "layout", "application", "noindicator");
422 evas_object_size_hint_weight_set(attachment_base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
423 evas_object_size_hint_align_set(attachment_base, EVAS_HINT_FILL, EVAS_HINT_FILL);
424 evas_object_show(attachment_base);
425 elm_object_part_content_set(attachment_base, "elm.swallow.content", attachment_item);
427 elm_box_pack_end(ugd->attachment_item_box, attachment_base);
428 evas_object_show(attachment_base);
430 evas_object_data_set(delete_icon, "delete_attachment", attachment_base);
432 ugd->attachment_item_obj_list = eina_list_append(ugd->attachment_item_obj_list, attachment_base);
433 _composer_attachment_set_attach_data(ugd, attachment_base, attachment_data);
435 edje_object_signal_callback_add(_EDJ(attachment_item), "clicked", "*", _composer_attachment_mouse_clicked, attachment_data);
437 edje_object_signal_callback_add(_EDJ(attachment_item), "clicked", "*", _composer_attachment_unfocus, ugd);
439 Evas_Object *attachment_base = elm_layout_add(ugd->attachment_item_box);
441 ugd->attachment_item_obj_list = eina_list_append(ugd->attachment_item_obj_list, attachment_base);
442 _composer_attachment_set_attach_data(ugd, attachment_base, attachment_data);
446 _composer_attachment_expand_items(ugd);
449 void _composer_attachment_add_thumbnail(EmailComposerUGD *ugd, Evas_Object *parent, char *filePath)
453 Evas_Object *thumb_nail;
454 const char *path = NULL;
456 if (ugd->attachment_list_compressed) {
457 thumb_nail = elm_icon_add(parent);
459 path = g_strdup(COMPOSER_ICON_DIR "/05_email_icon_attach_40x40.png");
460 debug_log("path = %s", path);
461 elm_icon_file_set(thumb_nail, path, NULL);
464 debug_log("savename = %s", filePath);
466 thumb_nail = elm_icon_add(parent);
468 path = g_strdup(MYFILE_IMGE_PATH "/myfile_icon_etc.png");
469 elm_icon_file_set(thumb_nail, path, NULL);
471 thumb_nail = _composer_attachment_make_thumbnail(ugd, filePath, parent);
475 elm_object_part_content_set(parent, "attachment.thumbnail.icon", thumb_nail);
476 evas_object_show(thumb_nail);
480 Evas_Object *_composer_attachment_add_delete_icon(EmailComposerUGD *ugd, Evas_Object *parent)
484 Evas_Object *delete_icon = elm_button_add(parent);
485 elm_object_style_set(delete_icon, "minus");
486 // elm_object_focus_allow_set(delete_icon, EINA_TRUE);
487 elm_object_part_content_set(parent, "attachment.delete.icon", delete_icon);
489 evas_object_show(delete_icon);
491 if (ugd->attachment_list_compressed)
492 evas_object_smart_callback_add(delete_icon, "clicked", _composer_attachment_delete_all_icon_clicked_cb, ugd);
494 evas_object_smart_callback_add(delete_icon, "clicked", _composer_attachment_delete_icon_clicked_cb, ugd);
499 void _composer_attachment_add_filename(EmailComposerUGD *ugd, email_attachment_data_t * attachment_data, Evas_Object *parent)
505 char file_string[128] = { 0, };
507 if (ugd->attachment_list_compressed) {
508 size = _composer_get_attachments_total_size(ugd);
510 char temp_name[16] = { 0, };
511 snprintf(temp_name, sizeof(temp_name), _("IDS_EMAIL_BODY_PD_ATTACHMENTS"), eina_list_count(ugd->attachment_item_obj_list));
512 file_name = g_strdup(temp_name);
514 // TODO: what does the below line mean?
515 if (ugd->new_mail_info->mail_data->file_path_html && (g_strcmp0(ugd->new_mail_info->mail_data->file_path_html, attachment_data->attachment_path) == 0)) {
516 size = email_get_file_size(attachment_data->attachment_path);
517 debug_log("Original html body size(%d)", size);
519 size = attachment_data->attachment_size;
520 debug_log("Attachment size(%d)", size);
522 file_name = g_strdup(attachment_data->attachment_name);
525 char *file_size = (char *)email_get_file_size_string((guint64)size);
527 snprintf(file_string, sizeof(file_string), "%s (%s)", file_name, file_size);
528 edje_object_part_text_set(_EDJ(parent), "attachment.filename", file_string);
534 Evas_Object *_composer_attachment_make_thumbnail(EmailComposerUGD *ugd, char *filePath, Evas_Object *parent)
538 Evas_Object *icon = NULL;
539 icon = elm_icon_add(parent);
542 const char *key = NULL;
546 debug_log("file path: %s", filePath);
548 char *m_type = (char *)efreet_mime_type_get(ecore_file_file_get(filePath));
551 type = g_strdup(m_type);
553 debug_log("mime type: %s", type);
554 efreet_mime_shutdown();
556 char thumb_path[MAX_ATTACHMENT_FILE_LEN + 1] = { 0, };
558 path = g_strdup(ATTACHMENT_ETC_FILE_PATH);
560 char *temp = g_strdup(filePath);
561 char *temp_filepath = g_strdup(filePath);
562 char *token = strtok(temp, "/");
565 token = strtok(NULL, "/");
569 struct _mtd *mtd = (struct _mtd *)mtd_main;
571 while (mtd && mtd->key) {
572 if (strncmp(type, mtd->key, strlen(type)) == 0) {
578 path = g_strdup(mtd->icon_path);
584 debug_log("file path : %s", filePath);
586 if (strncmp(type, ATTACHMENT_MEDIA_IMAGE, 5) == 0 || strncmp(type, ATTACHMENT_MEDIA_VIDEO, 5) == 0) {
587 int err = _composer_attachment_make_ethumb(filePath, thumb_path);
589 if (err != COMPOSER_ERROR_NONE)
591 } else if (strncmp(type, ATTACHMENT_MEDIA_AUDIO, 5) == 0) {
592 metadata_extractor_h metadata = NULL;
593 int ret = METADATA_EXTRACTOR_ERROR_NONE;
594 void *artwork = NULL;
595 int artwork_size = 0;
596 char *artwork_mime = NULL;
598 ret = metadata_extractor_create(&metadata);
599 debug_log("metadata_extractor_create: %d", ret);
601 debug_log("metadata extractor create failed");
605 ret = metadata_extractor_set_path(metadata, filePath);
606 debug_log("metadata_extractor_set_path: %d", ret);
608 ret = metadata_extractor_get_artwork(metadata, &artwork, &artwork_size, &artwork_mime);
609 debug_log("metadata_extractor_get_artwork: %d", ret);
610 debug_log("artwork_mime: %s, artwork_size: %d", artwork_mime, artwork_size);
613 gchar *mm_path = NULL;
614 int fd = g_file_open_tmp(NULL, &mm_path, NULL);
617 FILE *fp = fdopen(fd, "w");
619 debug_log("fail to fdopen()");
622 if (fwrite((unsigned char *)artwork, 1, artwork_size, fp) != artwork_size/*1*/) {
623 debug_log("fail to fwrite()");
634 snprintf(thumb_path, sizeof(thumb_path), "%s", mm_path);
636 debug_log("file : %s, album art_path : %s", filePath, thumb_path);
647 g_free(artwork_mime);
649 ret = metadata_extractor_destroy(metadata);
650 debug_log("metadata_extractor_destroy: %d", ret);
654 token = strtok(temp_filepath, ".");
656 token = strtok(NULL, ".");
658 if (g_strcmp0(token, ATTACHMENT_MEDIA_VCALENDAR) == 0) {
659 snprintf(thumb_path, sizeof(thumb_path), "%s", ATTACHMENT_VCALENDAR_FILE_PATH);
660 } else if (g_strcmp0(token, ATTACHMENT_MEDIA_VCARD) == 0) {
661 snprintf(thumb_path, sizeof(thumb_path), "%s", ATTACHMENT_VCARD_FILE_PATH);
664 debug_log("thumb_path: %s", thumb_path);
667 if (strlen(thumb_path)) {
668 elm_icon_file_set(icon, thumb_path, NULL);
670 elm_icon_file_set(icon, path, key);
675 if (strncmp(type, ATTACHMENT_MEDIA_IMAGE, 5) == 0) {
676 _composer_make_default_thumbnail(icon, filePath, COMPOSER_ATTACHMENT_ITEM_IMAGE);
677 } else if (strncmp(type, ATTACHMENT_MEDIA_AUDIO, 5) == 0) {
678 _composer_make_default_thumbnail(icon, filePath, COMPOSER_ATTACHMENT_ITEM_SOUND);
679 } else if (strncmp(type, ATTACHMENT_MEDIA_VIDEO, 5) == 0) {
680 _composer_make_default_thumbnail(icon, filePath, COMPOSER_ATTACHMENT_ITEM_VIDEO);
682 _composer_make_default_thumbnail(icon, filePath, COMPOSER_ATTACHMENT_ITEM_ETC);
704 temp_filepath = NULL;
710 int _composer_attachment_make_ethumb(const char *source, char *target)
714 debug_log("file path: %s", source);
716 char *type = (char *)efreet_mime_type_get(ecore_file_file_get(source));
717 char *mime_type = g_strdup(type);
718 debug_log("mime type: %s", mime_type);
719 efreet_mime_shutdown();
722 if (strncmp(mime_type, "image", 5) == 0) {
723 strncpy(target, source, MAX_ATTACHMENT_FILE_LEN);
724 } else if (strncmp(mime_type, "video", 5) == 0) {
725 metadata_extractor_h metadata = NULL;
726 int ret = METADATA_EXTRACTOR_ERROR_NONE;
727 char *video_width = NULL;
728 char *video_height = NULL;
729 char *video_track_cnt = NULL;
730 void *video_thumbnail = NULL;
731 int video_thumbnail_len = 0;
735 ret = metadata_extractor_create(&metadata);
736 debug_log("metadata_extractor_create: %d", ret);
738 debug_log("metadata extractor create failed");
739 return COMPOSER_ERROR_ETHUMB_FAIL;
742 ret = metadata_extractor_set_path(metadata, source);
743 debug_log("metadata_extractor_set_path: %d", ret);
745 ret = metadata_extractor_get_metadata(metadata, METADATA_VIDEO_WIDTH, &video_width);
746 debug_log("metadata_extractor_get_metadata: %d [video_width:%s]", ret, video_width);
747 ret = metadata_extractor_get_metadata(metadata, METADATA_VIDEO_HEIGHT, &video_height);
748 debug_log("metadata_extractor_get_metadata: %d [video_height:%s]", ret, video_height);
749 ret = metadata_extractor_get_metadata(metadata, METADATA_HAS_VIDEO, &video_track_cnt);
750 debug_log("metadata_extractor_get_metadata: %d [video_track_cnt:%s]", ret, video_track_cnt);
752 ret = metadata_extractor_get_frame(metadata, &video_thumbnail, &video_thumbnail_len);
753 debug_log("metadata_extractor_get_frame: %d (video_thumbnail_len:%d)", ret, video_thumbnail_len);
755 if (video_thumbnail) {
757 char filename[MAX_ATTACHMENT_FILE_LEN] = { 0, };
758 char *file_name = NULL;
759 char *file_ext = NULL;
761 email_parse_get_filename_n_ext_from_path(source, &file_name, &file_ext);
762 snprintf(filename, sizeof(filename), "%s%s%s%s", DATADIR"/", file_name, file_ext, ".jpg");
767 video_w = atoi(video_width);
769 video_h = atoi(video_height);
770 mm_ret = image_util_encode_jpeg(video_thumbnail,
772 IMAGE_UTIL_COLORSPACE_RGB888, 70, filename);
774 if (ecore_file_exists(filename)) {
775 strncpy(target, filename, MAX_ATTACHMENT_FILE_LEN);
776 // snprintf(thumb_path, sizeof(thumb_path), "%s", filename);
777 debug_log("file : %s, thumb_path : %s", source, target);
779 g_free(video_thumbnail);
785 g_free(video_height);
787 g_free(video_track_cnt);
789 ret = metadata_extractor_destroy(metadata);
790 debug_log("metadata_extractor_destroy: %d", ret);
796 return COMPOSER_ERROR_NONE;
799 void _composer_ethumb_generate_cb(void *data, Ethumb *e, Eina_Bool success)
801 if (success == EINA_TRUE) {
802 debug_log("Succeed in thumbnail generation");
804 debug_log("Fail to create thumbnail");
808 void _composer_attachment_set_attach_data(EmailComposerUGD *ugd, Evas_Object *parent, email_attachment_data_t *attachment_data)
812 evas_object_data_set(parent, "attachment_data", attachment_data);
815 static void _composer_attachment_delete_icon_clicked_cb(void *data, Evas_Object *obj, void *event_info)
825 EmailComposerUGD *ugd = (EmailComposerUGD *)data;
827 if (EINA_FALSE == ewk_view_script_execute(ugd->body_ewkview, COMPOSER_JS_GET_IMAGE_LIST, _composer_get_image_list_cb, (void *)ugd)) {
828 debug_log("COMPOSER_JS_GET_IMAGE_LIST error.");
831 Evas_Object *object = NULL;
832 object = evas_object_data_get(obj, "delete_attachment");
834 ugd->attachment_item_obj_list = eina_list_remove(ugd->attachment_item_obj_list, object);
836 email_attachment_data_t *attachment_data = NULL;
837 attachment_data = evas_object_data_get(object, "attachment_data");
839 if (attachment_data) {
840 debug_log("attachment_data file name = %s", attachment_data->attachment_path);
842 email_free_attachment_data(&attachment_data, 1);
843 attachment_data = NULL;
846 elm_box_unpack(ugd->attachment_item_box, object);
847 evas_object_del(object);
849 if (ugd->attachment_item_obj_list == NULL) {
850 ugd->selected_entry = ugd->priv_selected_entry;
851 ugd->priv_selected_entry = NULL;
853 _composer_mbe_set_focus(ugd);
856 static void _composer_attachment_delete_all_icon_clicked_cb(void *data, Evas_Object *obj, void *event_info)
866 EmailComposerUGD *ugd = (EmailComposerUGD *)data;
868 Eina_Iterator *it = NULL;
869 Evas_Object *attachment_obj = NULL;
870 email_attachment_data_t *attachment_data = NULL;
872 it = eina_list_iterator_new(ugd->attachment_item_obj_list);
874 while (eina_iterator_next(it, (void **)&attachment_obj)) {
876 attachment_data = evas_object_data_get(attachment_obj, "attachment_data");
878 if (attachment_data) {
879 debug_log("attachment_data file name to be removed : %s", attachment_data->attachment_path);
881 email_free_attachment_data(&attachment_data, 1);
882 attachment_data = NULL;
885 elm_box_unpack(ugd->attachment_item_box, attachment_obj);
886 evas_object_del(attachment_obj);
889 ugd->new_mail_info->mail_data->attachment_count = 0;
891 if (ugd->attachment_item_box) {
892 evas_object_del(ugd->attachment_item_box);
893 ugd->attachment_item_box = NULL;
897 eina_iterator_free(it);
900 if (ugd->attachment_item_obj_list) {
901 eina_list_free(ugd->attachment_item_obj_list);
902 ugd->attachment_item_obj_list = NULL;
905 if (ugd->attachment_contracted_item) {
906 elm_box_unpack(ugd->attachment_item_box, ugd->attachment_contracted_item);
907 evas_object_del(ugd->attachment_contracted_item);
908 ugd->attachment_contracted_item = NULL;
909 ugd->attachment_list_compressed = FALSE;
912 if (_composer_check_recipient_is_empty(ugd)) {
913 if (!ugd->bSendBtnDisabled) {
914 elm_object_disabled_set(ugd->send_btn, EINA_TRUE);
915 ugd->bSendBtnDisabled = true;
918 if (ugd->bSendBtnDisabled) {
919 elm_object_disabled_set(ugd->send_btn, EINA_FALSE);
920 ugd->bSendBtnDisabled = false;
924 if (ugd->selected_entry == ugd->body_ewkview) {
925 _composer_mbe_set_focus(ugd);
929 bool _composer_attachment_duplicate_check(EmailComposerUGD *ugd, char *pszAttachedFilePath)
931 debug_log("to be attached file path : %s", pszAttachedFilePath);
936 bool bDuplicated = FALSE;
938 Eina_Iterator *it = NULL;
939 Evas_Object *obj = NULL;
940 email_attachment_data_t *attachment_data = NULL;
942 it = eina_list_iterator_new(ugd->attachment_item_obj_list);
944 while (eina_iterator_next(it, (void **)&obj)) {
945 attachment_data = evas_object_data_get(obj, "attachment_data");
946 debug_log("attachment_data->attachment_path = %s", attachment_data->attachment_path);
948 if (strcmp(pszAttachedFilePath, attachment_data->attachment_path) == 0) {
949 debug_log("Attached file path is duplicated");
956 eina_iterator_free(it);
962 void _composer_attachment_expand_items(EmailComposerUGD *ugd)
966 if (ugd->attachment_list_compressed == EINA_FALSE)
969 if (ugd->attachment_contracted_item) {
970 elm_box_unpack(ugd->attachment_item_box, ugd->attachment_contracted_item);
971 evas_object_hide(ugd->attachment_contracted_item);
974 Eina_List *list = NULL;
975 Evas_Object *attachment_item = NULL;
977 EINA_LIST_FOREACH(ugd->attachment_item_obj_list, list, attachment_item) {
978 if (attachment_item) {
979 elm_box_pack_end(ugd->attachment_item_box, attachment_item);
980 evas_object_show(attachment_item);
984 ugd->attachment_list_compressed = EINA_FALSE;
987 void _composer_attachment_contract_items(EmailComposerUGD *ugd)
991 int nAttachmentObjCount = eina_list_count(ugd->attachment_item_obj_list);
993 debug_log("attachment_count = %d", nAttachmentObjCount);
994 debug_log("attachment_list_compressed = %d", ugd->attachment_list_compressed);
996 if (nAttachmentObjCount > 1 && !ugd->attachment_list_compressed) {
997 ugd->attachment_list_compressed = EINA_TRUE;
999 Eina_List *list = NULL;
1000 Evas_Object *attachment_item = NULL;
1002 EINA_LIST_FOREACH(ugd->attachment_item_obj_list, list, attachment_item) {
1003 if (attachment_item) {
1004 elm_box_unpack(ugd->attachment_item_box, attachment_item);
1005 evas_object_hide(attachment_item);
1009 if (ugd->attachment_contracted_item) {
1010 elm_box_pack_start(ugd->attachment_item_box, ugd->attachment_contracted_item);
1011 evas_object_show(ugd->attachment_contracted_item);
1013 Evas_Object *contracted_item = evas_object_data_get(ugd->attachment_contracted_item, "attachment_item");
1014 debug_log("contracted_item = %p", contracted_item);
1015 _composer_attachment_add_filename(ugd, NULL, contracted_item);
1017 _composer_attachment_create_contracted_box(ugd);
1022 void _composer_attachment_create_contracted_box(EmailComposerUGD *ugd)
1026 Evas_Object *contracted_item = NULL;
1027 contracted_item = elm_layout_add(ugd->attachment_item_box);
1029 elm_layout_file_set(contracted_item, COMPOSER_EDJ_NAME, "layout.attachment");
1030 evas_object_size_hint_weight_set(contracted_item, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1031 evas_object_size_hint_align_set(contracted_item, EVAS_HINT_FILL, EVAS_HINT_FILL);
1033 _composer_attachment_add_thumbnail(ugd, contracted_item, NULL);
1034 _composer_attachment_add_delete_icon(ugd, contracted_item);
1035 _composer_attachment_add_filename(ugd, NULL, contracted_item);
1037 edje_object_signal_callback_add(_EDJ(contracted_item), "clicked", "*", _composer_attachment_contracted_item_clicked_cb, ugd);
1039 Evas_Object *contracted_base = elm_layout_add(ugd->attachment_item_box);
1040 elm_layout_theme_set(contracted_base, "layout", "application", "noindicator");
1041 evas_object_size_hint_weight_set(contracted_base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1042 evas_object_size_hint_align_set(contracted_base, EVAS_HINT_FILL, EVAS_HINT_FILL);
1044 evas_object_show(contracted_base);
1045 elm_object_part_content_set(contracted_base, "elm.swallow.content", contracted_item);
1047 elm_box_pack_start(ugd->attachment_item_box, contracted_base);
1049 ugd->attachment_contracted_item = contracted_base;
1051 evas_object_show(contracted_base);
1053 evas_object_data_set(ugd->attachment_contracted_item, "attachment_item", contracted_item);
1056 static void _composer_attachment_contracted_item_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
1060 EmailComposerUGD *ugd = (EmailComposerUGD *)data;
1062 if (ugd->selected_entry == ugd->body_ewkview) {
1063 debug_log("Webkit unfocused");
1064 evas_object_focus_set(ugd->body_ewkview, EINA_FALSE);
1065 if (ewk_view_script_execute(ugd->body_ewkview, COMPOSER_JS_SET_UNFOCUS, _composer_script_executed_cb, 0) == EINA_FALSE)
1066 debug_log("COMPOSER_JS_SET_UNFOCUS failed.");
1069 elm_object_focus_set(obj, EINA_TRUE);
1071 _composer_attachment_expand_items(ugd);
1073 ugd->priv_selected_entry = ugd->selected_entry;
1074 ugd->selected_entry = ugd->attachment_contracted_item;
1075 // ugd->bringin_timer = ecore_timer_add(0.5f, _composer_bringin_cb, ugd);
1079 static void _composer_attachment_mouse_clicked(void *data, Evas_Object *obj, const char *emission, const char *source)
1083 email_attachment_data_t *item_list = (email_attachment_data_t *) data;
1085 debug_log("savename = %s", item_list->attachment_path);
1088 service_h service = NULL;
1089 ret = service_create(&service);
1090 debug_log("service_create: %d", ret);
1092 debug_log("service create failed");
1095 ret = service_set_operation(service, SERVICE_OPERATION_VIEW);
1096 debug_log("service_set_operation: %d", ret);
1097 ret = service_set_uri(service, item_list->attachment_path);
1098 debug_log("service_set_uri: %d", ret);
1099 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_VIDEO_PLAYER_LAUNCH_APP, "email");
1100 debug_log("service_add_extra_data: %d", ret);
1101 ret = service_send_launch_request(service, NULL, NULL);
1102 debug_log("service_send_launch_request: %d", ret);
1103 if (ret != SERVICE_ERROR_NONE) {
1104 if (g_ugd->composer_noti) {
1105 evas_object_del(g_ugd->composer_noti);
1106 g_ugd->composer_noti = NULL;
1108 g_ugd->composer_noti = _composer_create_noti(g_ugd, false, dgettext("sys_string", "IDS_COM_POP_WARNING"),
1109 _("IDS_EMAIL_POP_THIS_ATTACHMENT_CANNOT_BE_DISPLAYED"), 0, NULL, NULL, 1.5, _composer_noti_response_cb);
1111 ret = service_destroy(service);
1112 debug_log("service_destroy: %d", ret);
1116 static void _composer_attachment_unfocus(void *data, Evas_Object *obj, const char *emission, const char *source)
1120 EmailComposerUGD *ugd = (EmailComposerUGD *)data;
1122 Evas_Object *mbe = NULL;
1123 if (ugd->selected_entry == ugd->to_mbe_entry)
1125 else if (ugd->selected_entry == ugd->cc_mbe_entry)
1127 else if (ugd->selected_entry == ugd->bcc_mbe_entry)
1130 /* For unfocus TO mbe */
1132 elm_object_focus_set(ugd->to_mbe, EINA_FALSE);
1134 elm_object_focus_set(ugd->cc_mbe, EINA_FALSE);
1136 elm_object_focus_set(ugd->bcc_mbe, EINA_FALSE);