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 #define UG_MODULE_API __attribute__ ((visibility("default")))
22 #include <app_service.h>
24 #include <calendar2.h>
25 #include <media-util-register.h>
26 #include <contacts-ug.h>
28 #include "email-viewer.h"
29 #include "email-viewer-webview.h"
30 #include "email-viewer-utils.h"
31 #include "email-engine.h"
32 #include "email-utils.h"
33 #include "email-common-types.h"
34 #include "email-debug.h"
36 #define EMAIL_VCONF_KEY_BLOCK_RULE_CHANGED "file/private/org.tizen.email/spam_rule_changed"
39 EmailViewerUGD *_g_ug_data = NULL;
40 E_DBus_Connection *_g_viewer_dbus_conn = NULL;
41 E_DBus_Signal_Handler *_g_viewer_signal_handler_network = NULL;
42 E_DBus_Signal_Handler *_g_viewer_signal_handler_storage = NULL;
44 extern ui_gadget_h _g_mailbox_ug;
45 extern char *icu_locale;
46 extern enum appcore_time_format icu_timeformat;
47 extern void _set_mail_flags(EmailViewerProp *prop, EmailViewerPrivate *email_data);
50 static void *on_create(ui_gadget_h ug, enum ug_mode mode, service_h data, void *priv);
51 static void on_start(ui_gadget_h ug, service_h data, void *priv);
52 static void on_pause(ui_gadget_h ug, service_h data, void *priv);
53 static void on_resume(ui_gadget_h ug, service_h data, void *priv);
54 static void on_destroy(ui_gadget_h ug, service_h data, void *pd);
55 static void on_message(ui_gadget_h ug, service_h msg, service_h data, void *priv);
56 static void on_event(ui_gadget_h ug, enum ug_event event, service_h data, void *priv);
57 static void on_key_event(ui_gadget_h ug, enum ug_key_event event, service_h data, void *priv);
60 static void layout_cb(ui_gadget_h ug, enum ug_mode mode, void *priv);
61 static void result_cb(ui_gadget_h ug, service_h result, void *priv);
62 static void destroy_cb(ui_gadget_h ug, void *priv);
63 static ui_gadget_h create_ug(char *ug_name, service_h bd, void *data);
66 static void _create_view(EmailViewerUGD *ug_data);
67 static void _reset_view(EmailViewerUGD *ug_data);
69 static void _timezone_changed_cb(keynode_t *key, void *data);
71 static Evas_Object *_create_navigation_bar(EmailViewerUGD *ug_data);
72 static Evas_Object *_create_subject(EmailViewerUGD *ug_data);
73 static Evas_Object *_create_to_addrs(EmailViewerUGD *ug_data);
74 static Evas_Object *_create_cc_addrs(EmailViewerUGD *ug_data);
75 static Evas_Object *_create_bcc_addrs(EmailViewerUGD *ug_data);
76 static Evas_Object *_create_attach(EmailViewerUGD *ug_data);
77 static Evas_Object *_create_attach_ex(EmailViewerUGD *ug_data);
78 static Evas_Object *_create_body(EmailViewerUGD *ug_data);
79 static Evas_Object *_create_tab_bar(EmailViewerUGD *ug_data);
80 static Evas_Object *_create_partial_body_dn_btn(EmailViewerUGD *ug_data);
81 static Evas_Object *_create_bg(Evas_Object *win);
83 static void _create_down_progress(char *message, popup_cb resp_cb);
84 static void _create_down_progress_ex(int index, EMAIL_VIEWER_PROGRESSBAR_TYPE p_type);
85 static void _destroy_down_progress_ex(void *data, Evas_Object *obj, void *event_info);
86 static void _create_more_ctxpopup(EmailViewerUGD *ug_data, Evas_Object *obj);
87 static void _delete_evas_objects(EmailViewerUGD *ug_data);
89 /* callback functions */
90 static void _back_cb(void *data, Evas_Object *obj, void *event_info);
91 static void _reply_cb(void *data, Evas_Object *obj, void *event_info);
92 static void _reply_all_cb(void *data, Evas_Object *obj, void *event_info);
93 static void _reply_option_cb(void *data, Evas_Object *obj, void *event_info);
94 static void _forward_cb(void *data, Evas_Object *obj, void *event_info);
95 static void _resend_cb(void *data, Evas_Object *obj, void *event_info);
96 static void _cancel_send_cb(void *data, Evas_Object *obj, void *event_info);
97 static void _edit_email_cb(void *data, Evas_Object *obj, void *event_info);
98 static void _delete_cb(void *data, Evas_Object *obj, void *event_info);
99 static void _move_cb(void *data, Evas_Object *obj, void *event_info);
100 static void _more_cb(void *data, Evas_Object *obj, void *event_info);
101 static void _body_down_cb(void *data, Evas_Object *obj, void *event_info);
102 static void _subject_favorite_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
103 static void _subject_detail_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
104 static void _attachment_item_collapse_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
105 static void _attachment_save_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
106 static void _attachment_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
107 static void _attachment_save_all_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
108 static void _attachment_bg_set_cb(void *data, Evas * evas, Evas_Object *obj, void *event_info);
109 static void _attachment_bg_unset_cb(void *data, Evas * evas, Evas_Object *obj, void *event_info);
110 static void _mark_as_unread_cb(void *data, Evas_Object *obj, void *event_info);
111 static void _mark_as_read_cb(void *data, Evas_Object *obj, void *event_info);
112 static void _save_email_cb(void *data, Evas_Object *obj, void *event_info);
113 static Eina_Bool _save_email_prog_cb(void *data);
115 static void _ctxpopup_detail_contact_cb(void *data, Evas_Object *obj, void *event_info);
116 static void _ctxpopup_send_email_cb(void *data, Evas_Object *obj, void *event_info);
117 static void _ctxpopup_add_contact_cb(void *data, Evas_Object *obj, void *event_info);
118 static void _popup_waiting_response_cb(void *data, Evas_Object *obj, void *event_info);
119 static void _popup_response_cb(void *data, Evas_Object *obj, void *event_info);
120 static void _popup_response_delete_ok_cb(void *data, Evas_Object *obj, void *event_info);
121 static void _popup_response_move_to_trash_cb(void *data, Evas_Object *obj, void *event_info);
122 static void _popup_response_delete_permanent_cb(void *data, Evas_Object *obj, void *event_info);
123 static void _popup_response_to_destroy_cb(void *data, Evas_Object *obj, void *event_info);
125 static void _webview_policy_navigation_decide_cb(void *data, Evas_Object *obj, void *event_info);
127 static void _outter_scroller_bottom_hit_cb(void *data, Evas_Object *obj, void *event_info);
128 static void _outter_scroller_top_hit_cb(void *data, Evas_Object *obj, void *event_info);
129 static void _outter_scroller_scroll_cb(void *data, Evas_Object *obj, void *event_info);
131 static void _mbe_focused_cb(void *data, Evas_Object *obj, void *event_info);
132 static void _mbe_unfocused_cb(void *data, Evas_Object *obj, void *event_info);
133 static void _mbe_added_cb(void *data, Evas_Object *obj, void *event_info);
134 static void _mbe_selected_cb(void *data, Evas_Object *obj, void *event_info);
135 static void _destroy_down_progress_cb(void *data, Evas_Object *obj, void *event_info);
137 /* Logic Functions */
138 static int _viewer_create_temp_folder();
139 static void _viewer_remove_temp_folder();
140 static void _init_viewer_data(int account_id, int mail_id, char *srv_mail_id, EmailViewerUGD *ug_data);
141 static int _init_webview_data(EmailViewerUGD *ug_data);
142 static Eina_Bool _check_body_download(void *data);
143 static int _update_attachment_info(EmailViewerUGD *ug_data, int index);
144 static int _get_attachment_info_index(EmailViewerUGD *ug_data, int index);
145 static void _save_attachment(EmailViewerUGD *ug_data, int index);
146 static void _show_attachment(EmailViewerUGD *ug_data, int index);
147 static void _save_attachment_all(EmailViewerUGD *ug_data);
148 static void _dbus_receiver_setup(EmailViewerUGD *ug_data);
149 static void _dbus_receiver_remove(EmailViewerUGD *ug_data);
150 static void _on_edbus_event_email_viewer_receive(void *local_data, DBusMessage *message);
152 static void _delete_contacts_list(EMAIL_CONTACT_LIST_INFO_S *contacts_list_item);
153 static void *_contact_search_by_email(EmailViewerUGD *ug_data, const char *search_word);
154 static void _set_value_down_progress(double val);
155 static void _set_value_down_progress_by_index(double val, int index);
156 static void _cancel_download_attachment(EmailViewerUGD *ug_data);
159 static char *_get_service_fail_type(int type);
160 static Evas_Object *_load_edj(Evas_Object *parent, const char *file, const char *group);
163 static Eina_Bool _gl_state_get(void *data, Evas_Object *obj, const char *part);
164 static void _gl_del(void *data, Evas_Object *obj);
165 static char *_gl_text_get(void *data, Evas_Object *obj, const char *part);
166 static Evas_Object *_gl_content_get(void *data, Evas_Object *obj, const char *part);
167 static void _move_here_cb(void *data, Evas_Object *obj, void *event_info);
168 static void _move_back_cb(void *data, Evas_Object *obj, void *event_info);
171 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
175 EmailViewerUGD *ug_data;
180 ug_data = calloc(1, sizeof(EmailViewerUGD));
184 _g_ug_data = ug_data;
186 ops->create = on_create;
187 ops->start = on_start;
188 ops->pause = on_pause;
189 ops->resume = on_resume;
190 ops->destroy = on_destroy;
191 ops->message = on_message;
192 ops->event = on_event;
193 ops->key_event = on_key_event;
195 ops->opt = UG_OPT_INDICATOR_ENABLE;
200 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
203 EmailViewerUGD *ug_data;
215 static void *on_create(ui_gadget_h ug, enum ug_mode mode, service_h data, void *priv)
218 EmailViewerUGD *ug_data;
219 char *account_id = NULL;
220 char *mail_id = NULL;
221 char *mailbox_id = NULL;
222 char *binternal = NULL;
223 char *landscape = NULL;
232 debug_log("account_id and mail_id are required by arguments");
233 ug_data->b_direct_destroy = 1;
234 ug_destroy_me(ug_data->ug);
239 /* email engine initialize */
240 if (email_engine_initialize() == FALSE) {
241 debug_log("Failed to initialize email engine");
242 ug_data->b_direct_destroy = 1;
243 ug_destroy_me(ug_data->ug);
249 ret = service_get_extra_data(data, EMAIL_BUNDLE_KEY_ACCOUNT_ID, (char **)&account_id);
250 debug_log("service_get_extra_data: %d", ret);
251 debug_log("account_id:%s", account_id);
252 ret = service_get_extra_data(data, EMAIL_BUNDLE_KEY_MAIL_ID, (char **)&mail_id);
253 debug_log("service_get_extra_data: %d", ret);
254 debug_log("mail_id:%s", mail_id);
255 ret = service_get_extra_data(data, EMAIL_BUNDLE_KEY_MAILBOX, (char **)&mailbox_id);
256 debug_log("service_get_extra_data: %d", ret);
257 debug_log("mailbox:%s", mailbox_id);
258 ret = service_get_extra_data(data, EMAIL_BUNDLE_KEY_INTERNAL, (char **)&binternal);
259 debug_log("service_get_extra_data: %d", ret);
260 debug_log("binternal:%s", binternal);
261 ret = service_get_extra_data(data, EMAIL_BUNDLE_KEY_FIRST_LANDSCAPE, (char **)&landscape);
262 debug_log("service_get_extra_data: %d", ret);
263 debug_log("landscape:%s", landscape);
266 ug_data->isRotate = atoi(landscape);
267 debug_log("@@@@ Landscape = %d @@@@", ug_data->isRotate);
272 ug_data->account_id = atoi(account_id);
273 ug_data->folder_list = email_engine_get_ca_mailbox_list_using_glist(ug_data->account_id);
278 ug_data->mail_id = atoi(mail_id);
283 g_free(ug_data->mailbox_name);
284 ug_data->mailbox_name = NULL;
285 ug_data->mailbox_id = atoi(mailbox_id);
289 email_mail_data_t *mail_data = NULL;
290 if ((err = email_get_mail_data(ug_data->mail_id, &mail_data)) != EMAIL_ERROR_NONE) {
291 debug_log("fail to get mail - err (%d)", err);
294 if (mail_data == NULL) {
295 debug_log("mail_data is NULL");
296 ug_data->timeout_popup = elm_popup_add(ug_get_window());
297 evas_object_size_hint_weight_set(ug_data->timeout_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
298 elm_popup_timeout_set(ug_data->timeout_popup, 2);
299 elm_object_text_set(ug_data->timeout_popup, dgettext("sys_string", "IDS_COM_BODY_SELECTED_DATA_NOT_FOUND"));
300 elm_object_part_text_set(ug_data->timeout_popup, "title,text", _("IDS_EMAIL_POP_ALERT"));
301 evas_object_smart_callback_add(ug_data->timeout_popup, "block,clicked", _popup_response_to_destroy_cb, ug_data);
302 evas_object_smart_callback_add(ug_data->timeout_popup, "timeout", _popup_response_to_destroy_cb, ug_data);
303 evas_object_show(ug_data->timeout_popup);
305 return elm_layout_add(ug_get_window());
307 if (mail_data->server_mailbox_name)
308 ug_data->mailbox_name = g_strdup(mail_data->server_mailbox_name);
309 ug_data->mailbox_type = mail_data->mailbox_type;
310 debug_log("server_mailbox_name:%s", mail_data->server_mailbox_name);
311 debug_log("mailbox_name:%s", ug_data->mailbox_name);
312 debug_log("mailbox_type:%d", ug_data->mailbox_type);
315 debug_log("email_free_mail is called");
316 email_free_mail_data(&(mail_data), 1);
323 ug_data->b_internal = atoi(binternal);
324 if (ug_data->b_internal == 1)
325 debug_log("############Launched from email-mailbox###############");
329 debug_log("account_id [%d], mail_id [%d], mailbox_id [%d], mailbox name [%s]", ug_data->account_id, ug_data->mail_id, ug_data->mailbox_id, ug_data->mailbox_name);
331 if (ug_data->account_id <= 0 || ug_data->mail_id <= 0 || ug_data->mailbox_id <= 0) {
332 debug_log("Required bundle parameters are missing!");
333 ug_data->timeout_popup = elm_popup_add(ug_get_window());
334 evas_object_size_hint_weight_set(ug_data->timeout_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
335 elm_popup_timeout_set(ug_data->timeout_popup, 2);
336 elm_object_text_set(ug_data->timeout_popup, _("IDS_EMAIL_POP_UNABLE_TO_OPEN_EMAIL_MESSAGE"));
337 elm_object_part_text_set(ug_data->timeout_popup, "title,text", _("IDS_EMAIL_POP_ALERT"));
338 evas_object_smart_callback_add(ug_data->timeout_popup, "block,clicked", _popup_response_to_destroy_cb, ug_data);
339 evas_object_smart_callback_add(ug_data->timeout_popup, "timeout", _popup_response_to_destroy_cb, ug_data);
340 evas_object_show(ug_data->timeout_popup);
342 return elm_layout_add(ug_get_window());
345 ug_data->win_main = ug_get_window();
347 char *proxy_address = vconf_get_str(VCONFKEY_NETWORK_PROXY);
348 debug_log("network proxy: %s", proxy_address);
349 if (proxy_address && (g_strcmp0(proxy_address, "") != 0)) {
350 ewk_context_proxy_uri_set(ewk_context_default_get(), proxy_address);
357 ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
358 debug_log("WINDOW W[%d] H[%d]", w, h);
362 ug_data->scale_factor = elm_config_scale_get();
363 debug_log("ELM Scale[%f]", ug_data->scale_factor);
366 ug_data->webview_width = 710.0;
367 ug_data->webview_height = 949.0;
368 ug_data->webview_width_landscape = 710.0;
369 ug_data->webview_height_landscape = 568.0;
370 ug_data->webview_margin = 633;
371 ug_data->webview_margin_landscape = 379;
372 } else if (w == 720) {
373 ug_data->webview_width = 710.0;
374 ug_data->webview_height = 1122.0;
375 ug_data->webview_width_landscape = 710.0;
376 ug_data->webview_height_landscape = 558.0;
377 ug_data->webview_margin = 1029;
378 ug_data->webview_margin_landscape = 558;
380 ug_data->webview_width = 710.0;
381 ug_data->webview_height = 949.0;
382 ug_data->webview_width_landscape = 710.0;
383 ug_data->webview_height_landscape = 568.0;
384 ug_data->webview_margin = 633;
385 ug_data->webview_margin_landscape = 379;
388 ug_data->evas = evas_object_evas_get(ug_data->win_main);
390 /* Double_Scroller */
393 email_account_t *account = NULL;
394 if (email_engine_get_account_full_data(ug_data->account_id, &account)) {
395 debug_log("email_engine_get_account");
397 ug_data->account_type = account->incoming_server_type;
398 snprintf(ug_data->account_email_address, sizeof(ug_data->account_email_address), "%s", account->user_email_address);
400 account_user_data_t *ud = (account_user_data_t*)account->user_data;
402 debug_log("show_images is %d", ud->show_images);
403 ug_data->b_show_remote_images = ud->show_images;
409 email_free_account(&account, 1);
414 _dbus_receiver_setup(ug_data);
416 email_register_timezone_changed_callback(_timezone_changed_cb, ug_data);
418 _init_viewer_data(ug_data->account_id, ug_data->mail_id, NULL, ug_data);
419 _create_view(ug_data);
421 _check_body_download(ug_data);
423 ug_data->base = ug_data->layout_main;
425 ug_data->display_download_result = TRUE;
427 return ug_data->base;
430 static void on_start(ui_gadget_h ug, service_h data, void *priv)
435 static void on_pause(ui_gadget_h ug, service_h data, void *priv)
440 static void on_resume(ui_gadget_h ug, service_h data, void *priv)
445 static void on_destroy(ui_gadget_h ug, service_h data, void *pd)
448 EmailViewerUGD *ug_data;
457 if (ug_data->b_direct_destroy)
460 if (ug_data->email_data == NULL) {
461 debug_log("ug_data->email_data is NULL.");
465 EmailViewerPrivate *priv = ug_data->email_data;
469 if (ug_data->property) {
470 att_len = g_list_length(ug_data->property->attachments);
473 if (priv->email_handle != 0)
474 email_engine_stop_working(ug_data->account_id, priv->email_handle);
476 for (i = 0; i < att_len; i++) {
477 if (priv->download_all_email_handle[i] != 0)
478 email_engine_stop_working(ug_data->account_id, priv->download_all_email_handle[i]);
481 _delete_evas_objects(ug_data);
483 debug_log("free webview_data");
484 if (ug_data->webview_data) {
485 free(ug_data->webview_data);
486 ug_data->webview_data = NULL;
489 if (ecore_file_exists(DIR_TMP_PREFIX"/mail.txt"))
490 ecore_file_remove(DIR_TMP_PREFIX"/mail.txt");
492 debug_log("free address info list");
493 email_free_address_info_list(&(priv->addrs_info_list));
494 ug_data->from_list = NULL;
495 ug_data->to_list = NULL;
496 ug_data->cc_list = NULL;
497 ug_data->bcc_list = NULL;
499 debug_log("free mail_info");
500 if (ug_data->email_data->mail_info) {
501 email_free_mail_data(&(ug_data->email_data->mail_info), 1);
502 ug_data->email_data->mail_info = NULL;
505 if (ug_data->email_data->attachment_info && ug_data->email_data->attachment_count > 0) {
506 email_free_attachment_data(&(ug_data->email_data->attachment_info), ug_data->email_data->attachment_count);
507 ug_data->email_data->attachment_info = NULL;
508 ug_data->email_data->attachment_count = 0;
511 debug_log("free email_data");
512 free(ug_data->email_data);
513 ug_data->email_data = NULL;
515 debug_log("free attachment");
516 if (ug_data->property) {
517 if (ug_data->property->attachments) {
519 LIST_ITER_START(i, ug_data->property->attachments) {
520 EmailAttachmentType *info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, ug_data->property->attachments);
527 g_list_free(ug_data->property->attachments);
528 ug_data->property->attachments = NULL;
531 debug_log("free property");
532 if (ug_data->property) {
533 free(ug_data->property);
534 ug_data->property = NULL;
538 ug_data->base = NULL;
540 _viewer_remove_temp_folder();
541 email_deregister_timezone_changed_callback(_timezone_changed_cb);
543 _dbus_receiver_remove(NULL);
544 int ret = e_dbus_shutdown();
545 debug_log("ret: %d", ret);
547 email_engine_finalize();
552 static void on_message(ui_gadget_h ug, service_h msg, service_h data, void *priv)
559 debug_log("_g_ug_data - %p", _g_ug_data);
560 if (_g_ug_data != NULL) {
561 debug_log("Hide previous mail data");
562 _hide_view(_g_ug_data);
565 char *account_id = NULL;
566 char *mail_id = NULL;
567 char *mailbox_id = NULL;
568 char *binternal = NULL;
569 char *landscape = NULL;
571 EmailViewerUGD *ug_data = (EmailViewerUGD *)priv;
572 _g_ug_data = ug_data;
576 ret = service_get_extra_data(msg, EMAIL_BUNDLE_KEY_ACCOUNT_ID, (char **)&account_id);
577 debug_log("service_get_extra_data: %d", ret);
578 debug_log("account_id:%s", account_id);
579 ret = service_get_extra_data(msg, EMAIL_BUNDLE_KEY_MAIL_ID, (char **)&mail_id);
580 debug_log("service_get_extra_data: %d", ret);
581 debug_log("mail_id:%s", mail_id);
582 ret = service_get_extra_data(msg, EMAIL_BUNDLE_KEY_MAILBOX, (char **)&mailbox_id);
583 debug_log("service_get_extra_data: %d", ret);
584 debug_log("mailbox:%s", mailbox_id);
585 ret = service_get_extra_data(msg, EMAIL_BUNDLE_KEY_INTERNAL, (char **)&binternal);
586 debug_log("service_get_extra_data: %d", ret);
587 debug_log("binternal:%s", binternal);
588 ret = service_get_extra_data(msg, EMAIL_BUNDLE_KEY_FIRST_LANDSCAPE, (char **)&landscape);
589 debug_log("service_get_extra_data: %d", ret);
590 debug_log("landscape:%s", landscape);
593 ug_data->isRotate = atoi(landscape);
594 debug_log("@@@@ Landscape = %d @@@@", ug_data->isRotate);
599 ug_data->account_id = atoi(account_id);
600 ug_data->folder_list = email_engine_get_ca_mailbox_list_using_glist(ug_data->account_id);
605 ug_data->mail_id = atoi(mail_id);
610 g_free(ug_data->mailbox_name);
611 ug_data->mailbox_name = NULL;
612 ug_data->mailbox_id = atoi(mailbox_id);
616 email_mail_data_t *mail_data = NULL;
617 if ((err = email_get_mail_data(ug_data->mail_id, &mail_data)) != EMAIL_ERROR_NONE) {
618 debug_log("fail to get mail - err (%d)", err);
621 if (mail_data == NULL) {
622 debug_log("mail_data is NULL");
623 ug_data->timeout_popup = elm_popup_add(ug_get_window());
624 evas_object_size_hint_weight_set(ug_data->timeout_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
625 elm_popup_timeout_set(ug_data->timeout_popup, 2);
626 elm_object_text_set(ug_data->timeout_popup, dgettext("sys_string", "IDS_COM_BODY_SELECTED_DATA_NOT_FOUND"));
627 elm_object_part_text_set(ug_data->timeout_popup, "title,text", _("IDS_EMAIL_POP_ALERT"));
628 evas_object_smart_callback_add(ug_data->timeout_popup, "block,clicked", _popup_response_to_destroy_cb, ug_data);
629 evas_object_smart_callback_add(ug_data->timeout_popup, "timeout", _popup_response_to_destroy_cb, ug_data);
630 evas_object_show(ug_data->timeout_popup);
634 if (mail_data->server_mailbox_name)
635 ug_data->mailbox_name = g_strdup(mail_data->server_mailbox_name);
636 ug_data->mailbox_type = mail_data->mailbox_type;
637 debug_log("server_mailbox_name:%s", mail_data->server_mailbox_name);
638 debug_log("mailbox_name:%s", ug_data->mailbox_name);
639 debug_log("mailbox_type:%d", ug_data->mailbox_type);
642 debug_log("email_free_mail is called");
643 email_free_mail_data(&(mail_data), 1);
650 ug_data->b_internal = atoi(binternal);
651 if (ug_data->b_internal == 1)
652 debug_log("############Launched from email-mailbox###############");
656 debug_log("account_id [%d], mail_id [%d], mailbox_id[%d], mailbox name [%s]", ug_data->account_id, ug_data->mail_id, ug_data->mailbox_id, ug_data->mailbox_name);
658 if (ug_data->account_id <= 0 || ug_data->mail_id <= 0 || ug_data->mailbox_id <= 0) {
659 debug_log("Required bundle parameters are missing!");
664 email_account_t *account = NULL;
665 if (email_engine_get_account_full_data(ug_data->account_id, &account)) {
666 debug_log("email_engine_get_account");
668 ug_data->account_type = account->incoming_server_type;
669 snprintf(ug_data->account_email_address, sizeof(ug_data->account_email_address), "%s", account->user_email_address);
671 account_user_data_t *ud = (account_user_data_t*)account->user_data;
673 debug_log("show_images is %d", ud->show_images);
674 ug_data->b_show_remote_images = ud->show_images;
678 Ewk_Settings *setting = ewk_view_settings_get(ug_data->webview);
680 debug_log("b_show_remote_images is %d", ug_data->b_show_remote_images);
681 if (ewk_settings_load_remote_images_set(setting, ug_data->b_show_remote_images) == EINA_FALSE) {
682 debug_log("SET remote images is FAILED!");
687 email_free_account(&account, 1);
691 _init_viewer_data(ug_data->account_id, ug_data->mail_id, NULL, ug_data);
693 evas_object_show(ug_data->layout_main);
694 evas_object_raise(ug_data->layout_main);
696 _reset_view(ug_data);
698 ug_data->display_download_result = TRUE;
701 static void on_event(ui_gadget_h ug, enum ug_event event, service_h data, void *priv)
708 EmailViewerUGD *ug_data = (EmailViewerUGD *)priv;
709 EmailViewerProp *prop = ug_data->property;
710 char date_time[MAX_STR_LEN] = { 0, };
711 char *formatted_date = NULL;
714 debug_log("rotate event = %d", event);
717 case UG_EVENT_LOW_MEMORY:
719 case UG_EVENT_LOW_BATTERY:
721 case UG_EVENT_LANG_CHANGE:
722 if (ug_data->reply_btn)
723 elm_object_text_set(ug_data->reply_btn, dgettext("sys_string", "IDS_COM_SK_REPLY"));
724 if (ug_data->delete_btn)
725 elm_object_text_set(ug_data->delete_btn, dgettext("sys_string", "IDS_COM_SK_DELETE"));
726 if (ug_data->resend_btn)
727 elm_object_text_set(ug_data->resend_btn, _("IDS_EMAIL_SK_RESEND"));
728 if (ug_data->cancel_btn)
729 elm_object_text_set(ug_data->cancel_btn, dgettext("sys_string", "IDS_COM_SK_CANCEL"));
730 if (ug_data->move_btn)
731 elm_object_text_set(ug_data->move_btn, _("IDS_EMAIL_SK_MOVE"));
733 if (ug_data->dn_btn) {
734 elm_object_text_set(ug_data->dn_btn, _("IDS_EMAIL_BODY_DOWNLOAD_MESSAGE"));
737 if (ug_data->partial_dn_btn) {
738 elm_object_text_set(ug_data->partial_dn_btn, _("IDS_EMAIL_BODY_DOWNLOAD_FULL_MESSAGE"));
741 case UG_EVENT_ROTATE_PORTRAIT:
742 case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
743 if (ug_data->b_internal && ug_data->isRotate == true) {
744 ewk_view_command_execute(ug_data->webview, "Unselect", NULL);
745 debug_log("In Full view - Showing navi bar");
747 if (ug_data->con_popup) {
748 evas_object_del(ug_data->con_popup);
749 ug_data->con_popup = NULL;
752 if (ug_data->navi_move_it1) {
754 Evas_Object *move_back_btn = elm_button_add(ug_data->navi_bar);
755 elm_object_style_set(move_back_btn, "naviframe/back_btn/default");
756 evas_object_smart_callback_add(move_back_btn, "clicked", _move_back_cb, ug_data);
757 elm_object_item_part_content_set(ug_data->navi_move_it1, "prev_btn", move_back_btn);
758 elm_naviframe_item_title_visible_set(ug_data->navi_move_it1, EINA_TRUE);
759 if (ug_data->move_cbar) {
760 elm_object_item_part_content_unset(ug_data->navi_move_it1, "controlbar");
761 evas_object_del(ug_data->move_cbar);
762 ug_data->move_cbar = NULL;
766 if (ug_data->b_btn) {
767 evas_object_smart_callback_del(ug_data->b_btn, "clicked", _back_cb);
768 evas_object_del(ug_data->b_btn);
769 ug_data->b_btn = NULL;
772 ug_data->b_btn = elm_button_add(ug_data->navi_bar);
773 elm_object_style_set(ug_data->b_btn, "naviframe/back_btn/default");
774 evas_object_smart_callback_add(ug_data->b_btn, "clicked", _back_cb, ug_data);
775 elm_object_item_part_content_set(ug_data->navi_main_it, "prev_btn", ug_data->b_btn);
777 ug_data->isRotate = false;
782 case UG_EVENT_ROTATE_LANDSCAPE:
783 case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
784 if (ug_data->b_internal && ug_data->isRotate == false) {
785 ewk_view_command_execute(ug_data->webview, "Unselect", NULL);
786 debug_log("In Split view - Hiding navi bar");
788 if (ug_data->con_popup) {
789 evas_object_del(ug_data->con_popup);
790 ug_data->con_popup = NULL;
793 if (ug_data->navi_move_it1) {
795 Evas_Object *move_back_btn = elm_button_add(ug_data->navi_bar);
796 elm_object_style_set(move_back_btn, "naviframe/back_btn/default");
797 evas_object_smart_callback_add(move_back_btn, "clicked", _move_back_cb, ug_data);
798 elm_object_item_part_content_set(ug_data->navi_move_it1, "prev_btn", move_back_btn);
799 elm_naviframe_item_title_visible_set(ug_data->navi_move_it1, EINA_FALSE);
800 if (ug_data->move_cbar) {
801 elm_object_item_part_content_unset(ug_data->navi_move_it1, "controlbar");
802 evas_object_del(ug_data->move_cbar);
803 ug_data->move_cbar = NULL;
807 if (ug_data->b_btn) {
808 evas_object_smart_callback_del(ug_data->b_btn, "clicked", _back_cb);
809 evas_object_del(ug_data->b_btn);
810 ug_data->b_btn = NULL;
811 elm_object_item_part_content_set(ug_data->navi_main_it, "prev_btn", NULL);
814 ug_data->isRotate = true;
819 case UG_EVENT_REGION_CHANGE:
820 appcore_get_timeformat(&icu_timeformat);
821 /* ICU API to set default locale */
822 if (icu_timeformat == APPCORE_TIME_FORMAT_12)
823 formatted_date = email_get_date_text(icu_locale, "yMdhms", &(prop->mktime));
825 formatted_date = email_get_date_text(icu_locale, "yMdHms", &(prop->mktime));
826 ret = snprintf(date_time, MAX_STR_LEN, "%s", formatted_date);
828 free(formatted_date);
829 formatted_date = NULL;
831 edje_object_part_text_set(_EDJ(ug_data->ly_subject), "elm.text.sub", date_time);
832 evas_object_show(ug_data->ly_subject);
841 if (ug_data->isRotate) {
842 resized_w = ug_data->webview_width_landscape * ug_data->scale_factor;
843 resized_h = ug_data->webview_height_landscape * ug_data->scale_factor;
845 resized_w = ug_data->webview_width * ug_data->scale_factor;
846 resized_h = ug_data->webview_height * ug_data->scale_factor;
848 debug_log("resized_w:%d, resized_h:%d", resized_w, resized_h);
849 evas_object_size_hint_min_set(ug_data->webview, resized_w, resized_h);
852 static void on_key_event(ui_gadget_h ug, enum ug_key_event event, service_h data, void *priv)
859 EmailViewerUGD *ug_data = (EmailViewerUGD *)priv;
860 EmailViewerPrivate *private = ug_data->email_data;
861 EmailViewerProp *prop = ug_data->property;
864 case UG_KEY_EVENT_END:
866 if (ug_data->notify != NULL || ug_data->pb_notify != NULL || ug_data->timeout_popup != NULL) {
867 if (ug_data->timeout_popup) {
868 evas_object_del(ug_data->timeout_popup);
869 ug_data->timeout_popup = NULL;
872 if (ug_data->notify) {
873 evas_object_del(ug_data->notify);
874 ug_data->notify = NULL;
877 if (ug_data->pb_notify) {
879 int att_len = g_list_length(prop->attachments);
881 evas_object_del(ug_data->pb_notify);
882 ug_data->pb_notify = NULL;
884 if (private->email_handle != 0)
885 email_engine_stop_working(ug_data->account_id, private->email_handle);
887 for (i = 0; i < att_len; i++) {
888 if (private->download_all_email_handle[i] != 0)
889 email_engine_stop_working(ug_data->account_id, private->download_all_email_handle[i]);
893 if (ug_data->pb_notify_lb) {
894 evas_object_del(ug_data->pb_notify_lb);
895 ug_data->pb_notify_lb = NULL;
898 if (ug_data->isRotate == false && ug_data->b_internal) {
899 /* Viewer to hide, so set left content (mailbox) size to full */
900 _notify_mailbox_size(ug_data, "MAILBOX_RESIZE_FULL");
903 if (ug_data->b_internal)
906 ug_destroy_me(ug_data->ug);
910 service_h service = NULL;
912 ret = service_create(&service);
913 debug_log("service_create: %d", ret);
915 debug_log("service create failed");
919 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_MSG, EMAIL_BUNDLE_VAL_END_KEY);
920 debug_log("service_add_extra_data: %d", ret);
922 ug_send_message(_g_mailbox_ug, service);
924 ret = service_destroy(service);
925 debug_log("service_destroy: %d", ret);
934 static void layout_cb(ui_gadget_h ug, enum ug_mode mode, void *priv)
942 base = ug_get_layout(ug);
947 case UG_MODE_FULLVIEW:
948 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
949 evas_object_show(base);
956 static void result_cb(ui_gadget_h ug, service_h result, void *priv)
964 static void destroy_cb(ui_gadget_h ug, void *priv)
970 EmailViewerUGD *ug_data = (EmailViewerUGD *)priv;
971 ug_data->display_download_result = TRUE;
973 if (ug == ug_data->ug_composer) {
974 ug_data->ug_composer = NULL;
980 static ui_gadget_h create_ug(char *ug_name, service_h bd, void *data)
984 struct ug_cbs cbs = { 0, };
986 cbs.layout_cb = layout_cb;
987 cbs.result_cb = result_cb;
988 cbs.destroy_cb = destroy_cb;
991 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
993 ug = ug_create(ug_data->ug, ug_name, UG_MODE_FULLVIEW, bd, &cbs);
998 static void _create_view(EmailViewerUGD *ug_data)
1004 ug_data->bg = _create_bg(ug_data->win_main);
1007 ug_data->layout_main = elm_layout_add(ug_data->win_main);
1009 if (ug_data->b_internal)
1010 elm_layout_theme_set(ug_data->layout_main, "layout", "application", "noindicator");
1012 elm_layout_theme_set(ug_data->layout_main, "layout", "application", "default");
1013 evas_object_size_hint_weight_set(ug_data->layout_main, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1014 evas_object_show(ug_data->layout_main);
1016 elm_object_part_content_set(ug_data->layout_main, "elm.swallow.bg", ug_data->bg);
1019 elm_win_indicator_mode_set(ug_data->win_main, ELM_WIN_INDICATOR_SHOW);
1021 /* navigation Bar */
1022 _create_navigation_bar(ug_data);
1024 /* push navigation bar */
1025 ug_data->sub_ly = elm_layout_add(ug_data->navi_bar);
1026 elm_layout_theme_set(ug_data->sub_ly, "layout", "application", "noindicator");
1027 evas_object_size_hint_weight_set(ug_data->sub_ly, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1028 evas_object_show(ug_data->sub_ly);
1031 b_btn = elm_button_add(ug_data->navi_bar);
1032 elm_object_style_set(b_btn, "naviframe/back_btn/default");
1033 evas_object_smart_callback_add(b_btn, "clicked", _back_cb, ug_data);
1034 ug_data->b_btn = b_btn;
1036 ug_data->navi_main_it = elm_naviframe_item_push(ug_data->navi_bar, NULL, b_btn, NULL, ug_data->sub_ly, NULL);
1037 elm_naviframe_item_title_visible_set(ug_data->navi_main_it, EINA_FALSE);
1039 _create_tab_bar(ug_data);
1041 /* create scroller */
1042 ug_data->scroller = elm_scroller_add(ug_data->navi_bar);
1043 evas_object_propagate_events_set(ug_data->scroller, EINA_FALSE);
1044 elm_scroller_bounce_set(ug_data->scroller, EINA_FALSE, EINA_TRUE);
1045 elm_scroller_policy_set(ug_data->scroller, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF);
1046 evas_object_show(ug_data->scroller);
1047 evas_object_smart_callback_add(ug_data->scroller, "edge,bottom", _outter_scroller_bottom_hit_cb, ug_data);
1048 evas_object_smart_callback_add(ug_data->scroller, "edge,top", _outter_scroller_top_hit_cb, ug_data);
1049 evas_object_smart_callback_add(ug_data->scroller, "scroll,drag,start", _outter_scroller_scroll_cb, ug_data);
1051 elm_object_part_content_set(ug_data->sub_ly, "elm.swallow.content", ug_data->scroller);
1053 /* create main box */
1054 ug_data->main_bx = elm_box_add(ug_data->navi_bar);
1055 evas_object_size_hint_weight_set(ug_data->main_bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1056 evas_object_size_hint_align_set(ug_data->main_bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
1057 evas_object_show(ug_data->main_bx);
1058 elm_object_content_set(ug_data->scroller, ug_data->main_bx);
1060 if (ug_data->property->has_attachment)
1061 ug_data->got_att = 1;
1063 ug_data->got_att = 0;
1065 /* packing subject, addrs, attachment */
1066 _create_subject(ug_data);
1068 if (ug_data->got_att) {
1069 _create_attach(ug_data);
1072 if (ug_data->isRotate == true) {
1073 debug_log("In Split view - Hiding navi bar");
1075 if (ug_data->b_btn) {
1076 debug_log("hiding back button");
1078 evas_object_smart_callback_del(ug_data->b_btn, "clicked", _back_cb);
1079 evas_object_del(ug_data->b_btn);
1080 ug_data->b_btn = NULL;
1082 elm_object_item_part_content_set(ug_data->navi_main_it, "prev_btn", NULL);
1087 static void _reset_view(EmailViewerUGD *ug_data)
1090 EmailViewerProp *prop = ug_data->property;
1092 char date_time[MAX_STR_LEN] = { 0, };
1094 debug_log("@@@@@@@@@@ isRotate = %d", ug_data->isRotate);
1095 if (ug_data->isRotate == true) {
1096 debug_log("In Split view - Hiding navi bar");
1098 if (ug_data->b_btn) {
1099 debug_log("hiding back button");
1101 evas_object_smart_callback_del(ug_data->b_btn, "clicked", _back_cb);
1102 evas_object_del(ug_data->b_btn);
1103 ug_data->b_btn = NULL;
1105 elm_object_item_part_content_set(ug_data->navi_main_it, "prev_btn", NULL);
1108 /* Set scroller to start - height made 480 to consider viewer in split view */
1109 elm_scroller_region_show(ug_data->scroller, 0, 0, (int)((double)ug_data->main_h * 0.6), ug_data->main_w);
1111 debug_log("In Full view - Showing navi bar");
1113 if (ug_data->b_btn) {
1115 evas_object_smart_callback_del(ug_data->b_btn, "clicked", _back_cb);
1116 evas_object_del(ug_data->b_btn);
1117 ug_data->b_btn = NULL;
1120 debug_log("showing back button");
1122 ug_data->b_btn = elm_button_add(ug_data->navi_bar);
1123 elm_object_style_set(ug_data->b_btn, "naviframe/back_btn/default");
1124 evas_object_smart_callback_add(ug_data->b_btn, "clicked", _back_cb, ug_data);
1126 elm_object_item_part_content_set(ug_data->navi_main_it, "prev_btn", ug_data->b_btn);
1128 /* Set scroller to start */
1129 elm_scroller_region_show(ug_data->scroller, 0, 0, ug_data->main_w, ug_data->main_h);
1133 ug_data->lb_subject = elm_label_add(ug_data->ly_subject);
1134 evas_object_del(elm_object_part_content_unset(ug_data->ly_subject, "elm.text"));
1135 elm_object_part_content_set(ug_data->ly_subject, "elm.text", ug_data->lb_subject);
1136 char *_subject = elm_entry_utf8_to_markup(prop->subject);
1137 if (!g_strcmp0(_subject, "")) {
1139 _subject = g_strdup(_("IDS_EMAIL_BODY_NO_SUBJECT"));
1141 char *_subject_concated = g_strconcat("<font_size=44><color=#000000FF>", _subject, "</color></font_size>", NULL);
1142 elm_object_text_set(ug_data->lb_subject, _subject_concated);
1143 elm_label_wrap_width_set(ug_data->lb_subject, ug_data->main_w - (int)(110 * ug_data->scale_factor));
1144 elm_label_line_wrap_set(ug_data->lb_subject, ELM_WRAP_WORD);
1146 g_free(_subject_concated);
1148 /* reset date & time */
1149 char *formatted_date = NULL;
1151 if (icu_timeformat == APPCORE_TIME_FORMAT_12)
1152 formatted_date = email_get_date_text(icu_locale, "yMdhms", &(prop->mktime));
1154 formatted_date = email_get_date_text(icu_locale, "yMdHms", &(prop->mktime));
1155 ret = snprintf(date_time, MAX_STR_LEN, "%s", formatted_date);
1157 free(formatted_date);
1158 formatted_date = NULL;
1160 elm_object_part_text_set(ug_data->ly_subject, "elm.text.sub", date_time);
1162 Evas_Object *favorite_icon = elm_icon_add(ug_data->ly_subject);
1163 switch(prop->favorite)
1165 case EMAIL_FLAG_NONE:
1166 elm_image_file_set(favorite_icon, IMGDIR "/M02_icon_favorite_off_74x74.png", NULL);
1168 case EMAIL_FLAG_FLAGED:
1169 elm_image_file_set(favorite_icon, IMGDIR "/M02_icon_favorite_on_74x74.png", NULL);
1171 case EMAIL_FLAG_TASK_STATUS_CLEAR:
1172 elm_image_file_set(favorite_icon, IMGDIR "/M02_email_Flag_Clear.png", NULL);
1174 case EMAIL_FLAG_TASK_STATUS_ACTIVE:
1175 elm_image_file_set(favorite_icon, IMGDIR "/M02_email_Flag_Active.png", NULL);
1177 case EMAIL_FLAG_TASK_STATUS_COMPLETE:
1178 elm_image_file_set(favorite_icon, IMGDIR "/M02_email_Flag_Complete.png", NULL);
1181 evas_object_size_hint_aspect_set(favorite_icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
1182 elm_image_resizable_set(favorite_icon, 1, 1);
1183 evas_object_del(elm_object_part_content_unset(ug_data->ly_subject, "elm.icon.favorite"));
1184 elm_object_part_content_set(ug_data->ly_subject, "elm.icon.favorite", favorite_icon);
1185 evas_object_show(favorite_icon);
1187 evas_object_show(ug_data->ly_subject);
1188 elm_box_pack_end(ug_data->main_bx, ug_data->ly_subject);
1190 Evas_Object *edje = elm_layout_edje_get(ug_data->ly_subject);
1192 if (!ug_data->to_list && !ug_data->cc_list && !ug_data->bcc_list) {
1193 edje_object_signal_emit(edje, "elm,state,arrow_hidden", "elm");
1195 edje_object_signal_callback_add(edje, "elm,action,expand,toggle", "elm", _subject_detail_clicked_cb, ug_data->ly_subject);
1198 if (prop->has_attachment)
1199 ug_data->got_att = 1;
1201 ug_data->got_att = 0;
1203 /* pack attachment if it exist */
1204 if (ug_data->got_att) {
1205 _create_attach(ug_data);
1208 /* check body downloaded */
1209 _check_body_download(ug_data);
1212 void _hide_view(EmailViewerUGD *ug_data)
1215 EmailViewerProp *prop = ug_data->property;
1216 EmailViewerPrivate *priv = ug_data->email_data;
1218 debug_log("Cancelling all attachment downloads");
1219 _cancel_download_attachment(ug_data);
1221 ug_data->display_download_result = FALSE;
1224 if (elm_naviframe_top_item_get(ug_data->navi_bar) != ug_data->navi_main_it) {
1225 ug_data->navi_move_it1 = NULL;
1226 elm_naviframe_item_pop_to(ug_data->navi_main_it);
1229 evas_object_hide(ug_data->layout_main);
1230 elm_box_unpack_all(ug_data->main_bx);
1231 elm_object_scroll_freeze_pop(ug_data->scroller);
1233 evas_object_hide(ug_data->ly_subject);
1234 evas_object_hide(ug_data->lb_subject);
1235 evas_object_hide(ug_data->webview_bx);
1236 evas_object_hide(ug_data->webview);
1238 if (ug_data->partial_dn_btn) {
1239 evas_object_del(ug_data->partial_dn_btn);
1240 ug_data->partial_dn_btn = NULL;
1243 if (ug_data->partial_dn_btn_bx) {
1244 evas_object_del(ug_data->partial_dn_btn_bx);
1245 ug_data->partial_dn_btn_bx = NULL;
1248 if (ug_data->ctr_bar) {
1249 elm_object_item_part_content_unset(ug_data->navi_main_it, "controlbar");
1250 evas_object_del(ug_data->ctr_bar);
1251 ug_data->ctr_bar = NULL;
1254 if (ug_data->to_ly) {
1255 evas_object_del(ug_data->to_ly);
1256 ug_data->to_ly = NULL;
1259 if (ug_data->cc_ly) {
1260 evas_object_del(ug_data->cc_ly);
1261 ug_data->cc_ly = NULL;
1264 if (ug_data->bcc_ly) {
1265 evas_object_del(ug_data->bcc_ly);
1266 ug_data->bcc_ly = NULL;
1269 if (ug_data->got_att) {
1272 evas_object_del(ug_data->attach_hd_bk);
1273 ug_data->attach_hd_ly = NULL;
1274 ug_data->attach_hd_bk = NULL;
1276 if (prop->real_att_len > 1) {
1277 for (i = 0; i < prop->real_att_len; i++) {
1278 if (ug_data->attach_ex_ly != NULL) {
1279 if (ug_data->attach_ex_ly[i] != NULL) {
1280 debug_log("index %d", i);
1281 evas_object_del(ug_data->attach_ex_bk[i]);
1282 ug_data->attach_ex_ly[i] = NULL;
1283 ug_data->attach_ex_bk[i] = NULL;
1288 if (ug_data->attach_ex_ly != NULL) {
1289 free(ug_data->attach_ex_ly);
1290 ug_data->attach_ex_ly = NULL;
1291 ug_data->attach_ex_bk = NULL;
1295 for (i = 0; i <= prop->att_len; i++) {
1296 if (ug_data->progress_bar_ly[i] != NULL) {
1297 evas_object_del(ug_data->progress_bar_ly[i]);
1298 ug_data->progress_bar_ly[i] = NULL;
1299 ug_data->progress_bar[i] = NULL;
1304 if (ug_data->con_popup != NULL) {
1305 evas_object_del(ug_data->con_popup);
1306 ug_data->con_popup = NULL;
1309 if (ug_data->notify != NULL) {
1310 evas_object_del(ug_data->notify);
1311 ug_data->notify = NULL;
1314 edje_object_signal_emit(_EDJ(ug_data->ly_subject), "elm,state,contracted", "elm");
1315 edje_object_signal_callback_del(_EDJ(ug_data->ly_subject), "elm,action,expand,toggle", "elm", _subject_detail_clicked_cb);
1317 evas_object_hide(ug_data->noc_bx);
1318 evas_object_hide(ug_data->dn_btn);
1320 if (ecore_file_exists(EMAIL_TMP_FILE_PATH ".html"))
1321 ecore_file_remove(EMAIL_TMP_FILE_PATH ".html");
1323 if (ecore_file_exists(DIR_TMP_PREFIX"/mail.txt"))
1324 ecore_file_remove(DIR_TMP_PREFIX"/mail.txt");
1326 ewk_view_url_set(ug_data->webview, EMAIL_DEFAULT_HTML);
1328 _viewer_remove_temp_folder();
1330 debug_log("free address info list");
1331 email_free_address_info_list(&(priv->addrs_info_list));
1332 ug_data->from_list = NULL;
1333 ug_data->to_list = NULL;
1334 ug_data->cc_list = NULL;
1335 ug_data->bcc_list = NULL;
1337 ug_data->got_att = 0;
1338 ug_data->subject_onoff_flag = 0;
1339 ug_data->attach_onoff_flag = 0;
1340 ug_data->b_partial_body = 0;
1341 ug_data->b_internal = 0;
1342 ug_data->scroller_locked = 0;
1343 ug_data->m_is_multi_touch = 0;
1345 ug_data->navi_move_it1 = NULL;
1347 /* Double_Scroller */
1349 ug_data->b_load_finished = EINA_FALSE;
1350 ug_data->is_long_pressed = EINA_FALSE;
1351 ug_data->b_show_remote_images = EINA_FALSE;
1352 ug_data->is_webview_scrolling = EINA_FALSE;
1353 ug_data->is_main_scroller_scrolling = EINA_FALSE;
1356 static void _timezone_changed_cb(keynode_t *key, void *data)
1359 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
1360 EmailViewerProp *prop = ug_data->property;
1362 char date_time[MAX_STR_LEN] = { 0, };
1364 char *timezone_id = NULL;
1365 UChar utimezone_id[512] = { 0, };
1366 UErrorCode status = U_ZERO_ERROR;
1368 timezone_id = vconf_get_str(VCONFKEY_SETAPPL_TIMEZONE_ID);
1373 u_uastrcpy(utimezone_id, timezone_id);
1375 ucal_setDefaultTimeZone(utimezone_id, &status);
1377 if (U_FAILURE(status))
1380 char *formatted_date = NULL;
1382 if (icu_timeformat == APPCORE_TIME_FORMAT_12)
1383 formatted_date = email_get_date_text(icu_locale, "yMdhms", &(prop->mktime));
1385 formatted_date = email_get_date_text(icu_locale, "yMdHms", &(prop->mktime));
1386 ret = snprintf(date_time, MAX_STR_LEN, "%s", formatted_date);
1387 free(formatted_date);
1388 formatted_date = NULL;
1390 elm_object_part_text_set(ug_data->ly_subject, "elm.text.sub", date_time);
1394 static Evas_Object *_create_navigation_bar(EmailViewerUGD *ug_data)
1397 Evas_Object *navi_bar;
1399 navi_bar = elm_naviframe_add(ug_data->layout_main);
1400 if (navi_bar == NULL) {
1401 debug_log("navi_bar == NULL");
1405 elm_object_part_content_set(ug_data->layout_main, "elm.swallow.content", navi_bar);
1406 evas_object_show(navi_bar);
1408 ug_data->navi_bar = navi_bar;
1412 static Evas_Object *_create_subject(EmailViewerUGD *ug_data)
1415 EmailViewerProp *prop = ug_data->property;
1417 char date_time[MAX_STR_LEN] = { 0, };
1419 /* append subject */
1420 Evas_Object *di = elm_layout_add(ug_data->navi_bar);
1421 elm_layout_file_set(di, EV_THEME_PATH, "layout.email.detail_subject");
1422 evas_object_size_hint_align_set(di, EVAS_HINT_FILL, 0.0);
1424 Evas_Object *subject_label;
1425 subject_label = elm_label_add(di);
1426 elm_object_part_content_set(di, "elm.text", subject_label);
1427 char *subject = elm_entry_utf8_to_markup(prop->subject);
1428 if (!g_strcmp0(subject, "")) {
1430 subject = g_strdup(_("IDS_EMAIL_BODY_NO_SUBJECT"));
1432 char *subject_tagged = g_strconcat("<font_size=44><color=#000000FF>", subject, "</color></font_size>", NULL);
1433 elm_object_text_set(subject_label, subject_tagged);
1434 elm_label_wrap_width_set(subject_label, ug_data->main_w - (int)(110 * ug_data->scale_factor));
1435 elm_label_line_wrap_set(subject_label, ELM_WRAP_WORD);
1436 ug_data->lb_subject = subject_label;
1438 g_free(subject_tagged);
1440 char *formatted_date = NULL;
1442 if (icu_timeformat == APPCORE_TIME_FORMAT_12)
1443 formatted_date = email_get_date_text(icu_locale, "yMdhms", &(prop->mktime));
1445 formatted_date = email_get_date_text(icu_locale, "yMdHms", &(prop->mktime));
1446 ret = snprintf(date_time, MAX_STR_LEN, "%s", formatted_date);
1447 free(formatted_date);
1448 formatted_date = NULL;
1450 elm_object_part_text_set(di, "elm.text.sub", date_time);
1452 Evas_Object *favorite_icon = elm_icon_add(di);
1453 switch(prop->favorite)
1455 case EMAIL_FLAG_NONE:
1456 elm_image_file_set(favorite_icon, IMGDIR "/M02_icon_favorite_off_74x74.png", NULL);
1458 case EMAIL_FLAG_FLAGED:
1459 elm_image_file_set(favorite_icon, IMGDIR "/M02_icon_favorite_on_74x74.png", NULL);
1461 case EMAIL_FLAG_TASK_STATUS_CLEAR:
1462 elm_image_file_set(favorite_icon, IMGDIR "/M02_email_Flag_Clear.png", NULL);
1464 case EMAIL_FLAG_TASK_STATUS_ACTIVE:
1465 elm_image_file_set(favorite_icon, IMGDIR "/M02_email_Flag_Active.png", NULL);
1467 case EMAIL_FLAG_TASK_STATUS_COMPLETE:
1468 elm_image_file_set(favorite_icon, IMGDIR "/M02_email_Flag_Complete.png", NULL);
1471 evas_object_size_hint_aspect_set(favorite_icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
1472 elm_image_resizable_set(favorite_icon, 1, 1);
1473 elm_object_part_content_set(di, "elm.icon.favorite", favorite_icon);
1474 evas_object_show(favorite_icon);
1476 evas_object_show(di);
1477 elm_box_pack_end(ug_data->main_bx, di);
1478 ug_data->ly_subject = di;
1480 Evas_Object *edje = elm_layout_edje_get(di);
1482 if (ug_data->to_list || ug_data->cc_list || ug_data->bcc_list) {
1483 edje_object_signal_callback_add(edje, "elm,action,expand,toggle", "elm", _subject_detail_clicked_cb, di);
1485 edje_object_signal_emit(edje, "elm,state,arrow_hidden", "elm");
1487 edje_object_signal_callback_add(edje, "elm,action,toggle", "elm", _subject_favorite_clicked_cb, di);
1492 static Evas_Object *_create_to_addrs(EmailViewerUGD *ug_data)
1495 email_address_info_t *addrs_info = NULL;
1496 Elm_Object_Item *mbe_item;
1498 if (ug_data->to_list == NULL) {
1499 debug_log("to_list is NULL");
1503 int n_to_list = g_list_length(ug_data->to_list);
1506 if (n_to_list <= 0) {
1507 debug_log("to_list count is 0");
1511 Evas_Object *di = elm_layout_add(ug_data->main_bx);
1512 elm_layout_file_set(di, EV_THEME_PATH, "layout.email.to_cc");
1513 evas_object_size_hint_align_set(di, EVAS_HINT_FILL, 0.0);
1514 evas_object_show(di);
1515 ug_data->to_ly = di;
1516 elm_box_pack_after(ug_data->main_bx, di, ug_data->ly_subject);
1518 Evas_Object *to_mbe = elm_multibuttonentry_add(ug_data->main_bx);
1519 char desc[MAX_STR_LEN] = { 0, };
1520 snprintf(desc, MAX_STR_LEN, "%s:", dgettext("sys_string", "IDS_COM_BODY_TO"));
1521 char *to_str = g_strconcat("<font_size=36><color=#000000FF>", desc, "</color></font_size>", NULL);
1522 elm_object_text_set(to_mbe, to_str);
1525 evas_object_smart_callback_add(to_mbe, "item,clicked", _mbe_selected_cb, ug_data);
1526 evas_object_smart_callback_add(to_mbe, "item,added", _mbe_added_cb, ug_data);
1527 evas_object_smart_callback_add(to_mbe, "focused", _mbe_focused_cb, ug_data);
1528 evas_object_smart_callback_add(to_mbe, "unfocused", _mbe_unfocused_cb, ug_data);
1529 elm_object_part_content_set(di, "elm.icon", to_mbe);
1530 ug_data->to_mbe = to_mbe;
1532 Evas_Object *entry = elm_multibuttonentry_entry_get(to_mbe);
1534 elm_entry_editable_set(entry, EINA_FALSE);
1536 if (n_to_list > EMAIL_VIEW_MAX_TO_COUNT)
1537 n_to_list = EMAIL_VIEW_MAX_TO_COUNT;
1539 for (i = 0; i < n_to_list; i++) {
1540 addrs_info = (email_address_info_t *) g_list_nth_data(ug_data->to_list, i);
1541 debug_log("Address:%s", addrs_info->address);
1542 debug_log("Display Name:%s", addrs_info->display_name);
1543 debug_log("Storage Type:%d", addrs_info->storage_type);
1544 debug_log("Contact ID:%d", addrs_info->contact_id);
1546 if (addrs_info->display_name && strlen(addrs_info->display_name) > 0)
1547 mbe_item = elm_multibuttonentry_item_append(to_mbe, addrs_info->display_name, NULL, NULL);
1549 mbe_item = elm_multibuttonentry_item_append(to_mbe, addrs_info->address, NULL, NULL);
1550 elm_object_item_data_set(mbe_item, addrs_info);
1556 static Evas_Object *_create_cc_addrs(EmailViewerUGD *ug_data)
1559 email_address_info_t *addrs_info = NULL;
1560 Elm_Object_Item *mbe_item;
1562 if (ug_data->cc_list == NULL) {
1563 debug_log("cc_list is NULL");
1567 int n_cc_list = g_list_length(ug_data->cc_list);
1570 if (n_cc_list <= 0) {
1571 debug_log("cc_list count is 0");
1575 Evas_Object *di = elm_layout_add(ug_data->main_bx);
1576 elm_layout_file_set(di, EV_THEME_PATH, "layout.email.to_cc");
1577 evas_object_size_hint_align_set(di, EVAS_HINT_FILL, 0.0);
1578 evas_object_show(di);
1579 ug_data->cc_ly = di;
1581 if (ug_data->to_ly) {
1582 elm_box_pack_after(ug_data->main_bx, di, ug_data->to_ly);
1584 elm_box_pack_after(ug_data->main_bx, di, ug_data->ly_subject);
1587 Evas_Object *cc_mbe = elm_multibuttonentry_add(ug_data->main_bx);
1588 char desc[MAX_STR_LEN] = { 0, };
1589 snprintf(desc, MAX_STR_LEN, "%s:", _("IDS_EMAIL_BODY_CC"));
1590 char *cc_str = g_strconcat("<font_size=36><color=#000000FF>", desc, "</color></font_size>", NULL);
1591 elm_object_text_set(cc_mbe, cc_str);
1594 evas_object_smart_callback_add(cc_mbe, "item,clicked", _mbe_selected_cb, ug_data);
1595 evas_object_smart_callback_add(cc_mbe, "item,added", _mbe_added_cb, ug_data);
1596 evas_object_smart_callback_add(cc_mbe, "focused", _mbe_focused_cb, ug_data);
1597 evas_object_smart_callback_add(cc_mbe, "unfocused", _mbe_unfocused_cb, ug_data);
1598 elm_object_part_content_set(di, "elm.icon", cc_mbe);
1599 ug_data->cc_mbe = cc_mbe;
1601 Evas_Object *entry = elm_multibuttonentry_entry_get(cc_mbe);
1603 elm_entry_editable_set(entry, EINA_FALSE);
1605 if (n_cc_list > EMAIL_VIEW_MAX_CC_COUNT)
1606 n_cc_list = EMAIL_VIEW_MAX_CC_COUNT;
1608 for (i = 0; i < n_cc_list; i++) {
1609 addrs_info = (email_address_info_t *) g_list_nth_data(ug_data->cc_list, i);
1611 if (addrs_info->display_name && strlen(addrs_info->display_name) > 0)
1612 mbe_item = elm_multibuttonentry_item_append(cc_mbe, addrs_info->display_name, NULL, NULL);
1614 mbe_item = elm_multibuttonentry_item_append(cc_mbe, addrs_info->address, NULL, NULL);
1615 elm_object_item_data_set(mbe_item, addrs_info);
1621 static Evas_Object *_create_bcc_addrs(EmailViewerUGD *ug_data)
1624 email_address_info_t *addrs_info = NULL;
1625 Elm_Object_Item *mbe_item;
1627 if (ug_data->bcc_list == NULL) {
1628 debug_log("bcc_list is NULL");
1632 int n_bcc_list = g_list_length(ug_data->bcc_list);
1635 if (n_bcc_list <= 0) {
1636 debug_log("bcc_list count is 0");
1640 Evas_Object *di = elm_layout_add(ug_data->main_bx);
1641 elm_layout_file_set(di, EV_THEME_PATH, "layout.email.to_cc");
1642 evas_object_size_hint_align_set(di, EVAS_HINT_FILL, 0.0);
1643 evas_object_show(di);
1644 ug_data->bcc_ly = di;
1646 if (ug_data->cc_ly) {
1647 elm_box_pack_after(ug_data->main_bx, di, ug_data->cc_ly);
1649 if (ug_data->to_ly && ug_data->cc_ly == NULL) {
1650 elm_box_pack_after(ug_data->main_bx, di, ug_data->to_ly);
1652 if (ug_data->to_ly == NULL && ug_data->cc_ly == NULL) {
1653 elm_box_pack_after(ug_data->main_bx, di, ug_data->ly_subject);
1656 Evas_Object *bcc_mbe = elm_multibuttonentry_add(ug_data->main_bx);
1657 char desc[MAX_STR_LEN] = { 0, };
1658 snprintf(desc, MAX_STR_LEN, "%s:", _("IDS_EMAIL_BODY_BCC"));
1659 char *bcc_str = g_strconcat("<font_size=36><color=#000000FF>", desc, "</color></font_size>", NULL);
1660 elm_object_text_set(bcc_mbe, bcc_str);
1663 evas_object_smart_callback_add(bcc_mbe, "item,clicked", _mbe_selected_cb, ug_data);
1664 evas_object_smart_callback_add(bcc_mbe, "item,added", _mbe_added_cb, ug_data);
1665 evas_object_smart_callback_add(bcc_mbe, "focused", _mbe_focused_cb, ug_data);
1666 evas_object_smart_callback_add(bcc_mbe, "unfocused", _mbe_unfocused_cb, ug_data);
1667 elm_object_part_content_set(di, "elm.icon", bcc_mbe);
1668 ug_data->bcc_mbe = bcc_mbe;
1670 Evas_Object *entry = elm_multibuttonentry_entry_get(bcc_mbe);
1672 elm_entry_editable_set(entry, EINA_FALSE);
1674 if (n_bcc_list > EMAIL_VIEW_MAX_BCC_COUNT)
1675 n_bcc_list = EMAIL_VIEW_MAX_BCC_COUNT;
1677 for (i = 0; i < n_bcc_list; i++) {
1678 addrs_info = (email_address_info_t *) g_list_nth_data(ug_data->bcc_list, i);
1680 if (addrs_info->display_name && strlen(addrs_info->display_name) > 0)
1681 mbe_item = elm_multibuttonentry_item_append(bcc_mbe, addrs_info->display_name, NULL, NULL);
1683 mbe_item = elm_multibuttonentry_item_append(bcc_mbe, addrs_info->address, NULL, NULL);
1684 elm_object_item_data_set(mbe_item, addrs_info);
1690 static Evas_Object *_create_attach(EmailViewerUGD *ug_data)
1694 EmailViewerProp *prop = ug_data->property;
1695 char buff[MAX_STR_LEN];
1697 int att_len = prop->real_att_len;
1700 RETURN_VAL_IF_FAIL(prop->attachments != NULL, NULL);
1701 RETURN_VAL_IF_FAIL(att_len > 0, NULL);
1703 GList *attachment_list = prop->attachments;
1706 LIST_ITER_START(i, attachment_list) {
1707 EmailAttachmentType *info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, attachment_list);
1709 if (info && !info->inline_content) {
1710 if (info->size < 1024) {
1711 g_sprintf(buff, "%s (%d %s)", info->name, (gint) info->size, dgettext("sys_string", "IDS_COM_BODY_B"));
1713 gdouble tmpsize = (gdouble) (info->size / 1024.);
1714 if (tmpsize < 1024) {
1715 g_sprintf(buff, "%s (%.2f %s)", info->name, tmpsize, dgettext("sys_string", "IDS_COM_BODY_KB"));
1718 if (tmpsize < 1024) {
1719 g_sprintf(buff, "%s (%.2f %s)", info->name, tmpsize, dgettext("sys_string", "IDS_COM_BODY_MB"));
1722 g_sprintf(buff, "%s (%.2f %s)", info->name, tmpsize, dgettext("sys_string", "IDS_COM_BODY_GB"));
1727 Evas_Object *di = elm_layout_add(ug_data->navi_bar);
1728 elm_layout_file_set(di, EV_THEME_PATH, "layout.email.attachment_item");
1729 evas_object_size_hint_align_set(di, EVAS_HINT_FILL, 0.0);
1730 evas_object_show(di);
1731 elm_box_pack_after(ug_data->main_bx, di, ug_data->ly_subject);
1733 Evas_Object *thumbnail = NULL;
1735 if (info->download_yn) {
1736 thumbnail = viewer_make_thumbnail(info->path, di);
1738 thumbnail = viewer_make_thumbnail(NULL, di);
1739 evas_object_size_hint_aspect_set(thumbnail, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
1740 elm_image_resizable_set(thumbnail, 1, 1);
1741 elm_object_part_content_set(di, "elm.icon", thumbnail);
1742 evas_object_show(thumbnail);
1744 elm_object_part_text_set(di, "elm.text", buff);
1748 Evas_Object *edje = elm_layout_edje_get(di);
1749 edje_object_signal_callback_add(edje, "elm,action,download", "elm", _attachment_save_cb, (void *)att_index);
1750 edje_object_signal_callback_add(edje, "clicked", "*", _attachment_clicked_cb, (void *)att_index);
1752 Evas_Object *text_bg = NULL;
1753 text_bg = (Evas_Object *)edje_object_part_object_get(_EDJ(di), "elm.event.rect");
1756 evas_object_event_callback_add(text_bg, EVAS_CALLBACK_MOUSE_DOWN, _attachment_bg_set_cb, (void *)att_index);
1757 evas_object_event_callback_add(text_bg, EVAS_CALLBACK_MOUSE_UP, _attachment_bg_unset_cb, (void *)att_index);
1760 ug_data->attach_hd_ly = di;
1761 ug_data->attach_hd_bk = di;
1764 } else if (att_len > 1) {
1765 gint64 total_size = prop->total_att_size;
1767 Evas_Object *di = elm_layout_add(ug_data->navi_bar);
1768 elm_layout_file_set(di, EV_THEME_PATH, "layout.email.attachment_head");
1769 evas_object_size_hint_align_set(di, EVAS_HINT_FILL, 0.0);
1770 snprintf(buff, sizeof(buff), "%d %s", att_len, _("IDS_EMAIL_BODY_ATTACHMENTS"));
1772 Evas_Object *att_head_label;
1773 att_head_label = elm_label_add(di);
1774 elm_object_part_content_set(di, "elm.text", att_head_label);
1776 char *buff_tagged = g_strconcat("<font_size=35><color=#000000FF>", buff, "<color></font_size>", NULL);
1777 elm_object_text_set(att_head_label, buff_tagged);
1778 g_free(buff_tagged);
1780 if (total_size < 1024) {
1781 g_sprintf(buff, "(%d %s)", (gint) total_size, dgettext("sys_string", "IDS_COM_BODY_B"));
1783 gdouble tmpsize = (gdouble) (total_size / 1024.);
1785 if (tmpsize < 1024) {
1786 g_sprintf(buff, "(%.2f %s)", tmpsize, dgettext("sys_string", "IDS_COM_BODY_KB"));
1790 if (tmpsize < 1024) {
1791 g_sprintf(buff, "(%.2f %s)", tmpsize, dgettext("sys_string", "IDS_COM_BODY_MB"));
1794 g_sprintf(buff, "(%.2f %s)", tmpsize, dgettext("sys_string", "IDS_COM_BODY_GB"));
1799 edje_object_part_text_set(_EDJ(di), "elm.text.sub", buff);
1801 Evas_Object *edje = elm_layout_edje_get(di);
1802 edje_object_signal_callback_add(edje, "att,icon,save,all", "", _attachment_save_all_cb, di);
1803 edje_object_signal_callback_add(edje, "elm,action,expand,toggle", "elm", _attachment_item_collapse_cb, di);
1804 evas_object_show(di);
1805 elm_box_pack_after(ug_data->main_bx, di, ug_data->ly_subject);
1806 ug_data->attach_hd_ly = di;
1807 ug_data->attach_hd_bk = di;
1809 _create_attach_ex(ug_data);
1811 for (i = 0; i < prop->real_att_len; i++) {
1812 if (ug_data->attach_ex_ly[i] != NULL) {
1813 debug_log("index %d", i);
1814 elm_box_unpack(ug_data->main_bx, ug_data->attach_ex_ly[i]);
1815 evas_object_hide(ug_data->attach_ex_ly[i]);
1819 debug_log("Attachment doesn't exist");
1825 static Evas_Object *_create_attach_ex(EmailViewerUGD *ug_data)
1829 EmailViewerProp *prop = ug_data->property;
1830 char buff[MAX_STR_LEN];
1833 int att_len = prop->real_att_len;
1836 RETURN_VAL_IF_FAIL(prop->attachments != NULL, NULL);
1837 RETURN_VAL_IF_FAIL(att_len > 0, NULL);
1839 GList *attachment_list = prop->attachments;
1841 ug_data->attach_ex_ly = (Evas_Object **)calloc(att_len, sizeof(Evas_Object *));
1842 ug_data->attach_ex_bk = (Evas_Object **)calloc(att_len, sizeof(Evas_Object *));
1844 LIST_ITER_START(i, attachment_list) {
1845 EmailAttachmentType *info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, attachment_list);
1847 if (info && !info->inline_content) {
1848 if (info->size < 1024) {
1849 g_sprintf(buff, "%s (%d %s)", info->name, (gint) info->size, dgettext("sys_string", "IDS_COM_BODY_B"));
1851 gdouble tmpsize = (gdouble) (info->size / 1024.);
1852 if (tmpsize < 1024) {
1853 g_sprintf(buff, "%s (%.2f %s)", info->name, tmpsize, dgettext("sys_string", "IDS_COM_BODY_KB"));
1856 if (tmpsize < 1024) {
1857 g_sprintf(buff, "%s (%.2f %s)", info->name, tmpsize, dgettext("sys_string", "IDS_COM_BODY_MB"));
1860 g_sprintf(buff, "%s (%.2f %s)", info->name, tmpsize, dgettext("sys_string", "IDS_COM_BODY_GB"));
1865 Evas_Object *di = elm_layout_add(ug_data->navi_bar);
1866 elm_layout_file_set(di, EV_THEME_PATH, "layout.email.attachment_item");
1867 evas_object_size_hint_align_set(di, EVAS_HINT_FILL, 0.0);
1868 elm_box_pack_after(ug_data->main_bx, di, ug_data->attach_hd_ly);
1869 evas_object_show(di);
1871 Evas_Object *thumbnail = NULL;
1873 if (info->download_yn) {
1874 thumbnail = viewer_make_thumbnail(info->path, di);
1876 thumbnail = viewer_make_thumbnail(NULL, di);
1877 evas_object_size_hint_aspect_set(thumbnail, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
1878 elm_image_resizable_set(thumbnail, 1, 1);
1879 elm_object_part_content_set(di, "elm.icon", thumbnail);
1880 evas_object_show(thumbnail);
1882 elm_object_part_text_set(di, "elm.text", buff);
1886 Evas_Object *edje = elm_layout_edje_get(di);
1887 edje_object_signal_callback_add(edje, "elm,action,download", "elm", _attachment_save_cb, (void *)att_index);
1888 edje_object_signal_callback_add(edje, "clicked", "*", _attachment_clicked_cb, (void *)att_index);
1890 Evas_Object *text_bg = NULL;
1891 text_bg = (Evas_Object *)edje_object_part_object_get(_EDJ(di), "elm.event.rect");
1894 evas_object_event_callback_add(text_bg, EVAS_CALLBACK_MOUSE_DOWN, _attachment_bg_set_cb, (void *)att_index);
1895 evas_object_event_callback_add(text_bg, EVAS_CALLBACK_MOUSE_UP, _attachment_bg_unset_cb, (void *)att_index);
1898 debug_log("attach ly %d, att_index %d", j, i);
1900 ug_data->attach_ex_ly[j] = di;
1901 ug_data->attach_ex_bk[j] = di;
1910 static Evas_Object *_create_body(EmailViewerUGD *ug_data)
1913 EmailViewerProp *prop = ug_data->property;
1914 EmailViewerPrivate *priv = ug_data->email_data;
1918 if (ug_data->noc_bx) {
1919 elm_box_unpack(ug_data->main_bx, ug_data->noc_bx);
1920 evas_object_hide(ug_data->noc_bx);
1923 if (ug_data->dn_btn) {
1924 evas_object_hide(ug_data->dn_btn);
1927 if (ug_data->webview_bx) {
1928 _init_webview_data(ug_data);
1930 ewk_view_scale_set(ug_data->webview, 1.0f, 0, 0);
1932 if (prop->has_html) {
1934 ug_data->webview_data->body_type_prev = BODY_TYPE_HTML;
1935 ug_data->webview_data->body_type = BODY_TYPE_HTML;
1936 ug_data->webview_data->uri = prop->body_uri;
1939 ug_data->webview_data->body_type_prev = BODY_TYPE_TEXT;
1940 ug_data->webview_data->body_type = BODY_TYPE_TEXT;
1941 ug_data->webview_data->text_content = prop->body;
1944 viewer_set_webview_content(ug_data, 0);
1946 evas_object_show(ug_data->webview_bx);
1947 evas_object_show(ug_data->webview);
1948 elm_box_pack_end(ug_data->main_bx, ug_data->webview_bx);
1950 /* create webview layout */
1951 ug_data->webview_bx = _load_edj(ug_data->navi_bar, EV_THEME_PATH, "layout.email.web_view");
1952 if (ug_data->webview_bx == NULL) {
1953 debug_log("Cannot load edj");
1957 evas_object_size_hint_align_set(ug_data->webview_bx, EVAS_HINT_FILL, 0.0);
1958 evas_object_show(ug_data->webview_bx);
1959 elm_box_pack_end(ug_data->main_bx, ug_data->webview_bx);
1961 /* create webview */
1962 if (NULL == ug_data->webview) {
1963 _init_webview_data(ug_data);
1964 viewer_get_webview(ug_data, prop->has_html);
1966 if (prop->has_html) {
1967 ug_data->webview_data->body_type_prev = BODY_TYPE_HTML;
1968 ug_data->webview_data->body_type = BODY_TYPE_HTML;
1969 ug_data->webview_data->uri = prop->body_uri;
1971 ug_data->webview_data->body_type_prev = BODY_TYPE_TEXT;
1972 ug_data->webview_data->body_type = BODY_TYPE_TEXT;
1973 ug_data->webview_data->text_content = prop->body;
1975 viewer_set_webview_content(ug_data, 0);
1978 evas_object_show(ug_data->webview);
1979 elm_object_part_content_set(ug_data->webview_bx, "web_body", ug_data->webview);
1983 if (ug_data->isRotate) {
1984 resized_w = ug_data->webview_width_landscape * ug_data->scale_factor;
1985 resized_h = ug_data->webview_height_landscape * ug_data->scale_factor;
1987 resized_w = ug_data->webview_width * ug_data->scale_factor;
1988 resized_h = ug_data->webview_height * ug_data->scale_factor;
1990 debug_log("resized_w:%d, resized_h:%d", resized_w, resized_h);
1992 evas_object_size_hint_min_set(ug_data->webview, resized_w, resized_h);
1994 /* set touch callbacks */
1995 evas_object_smart_callback_add(ug_data->webview, "policy,navigation,decide", _webview_policy_navigation_decide_cb, ug_data);
1998 viewer_set_mail_seen(prop, priv->mail_info);
2000 if (ug_data->timer) {
2001 ecore_timer_del(ug_data->timer);
2002 ug_data->timer = NULL;
2005 debug_log("send message - list unlock");
2006 ug_data->timer = ecore_timer_add(0.0, viewer_send_message, ug_data);
2008 return ug_data->webview_bx;
2011 static Evas_Object *_create_toolbar_btn(Evas_Object *parent, const char *text, Evas_Smart_Cb func, void *data, const char *style)
2014 Evas_Object *btn = elm_button_add(parent);
2015 if (!btn) return NULL;
2017 elm_object_style_set(btn, style);
2019 elm_object_style_set(btn, "naviframe/toolbar/default");
2020 elm_object_text_set(btn, text);
2021 evas_object_smart_callback_add(btn, "clicked", func, data);
2025 static Evas_Object *_create_toolbar_more_btn(Evas_Object *parent, Evas_Smart_Cb func, void *data)
2028 Evas_Object *btn = elm_button_add(parent);
2029 if (!btn) return NULL;
2030 elm_object_style_set(btn, "naviframe/more/default");
2031 evas_object_smart_callback_add(btn, "clicked", func, data);
2035 static Evas_Object *_create_tab_bar(EmailViewerUGD *ug_data)
2037 debug_log("mailbox_type:%d", ug_data->mailbox_type);
2039 EmailViewerProp *prop = ug_data->property;
2040 Evas_Object *more_btn = NULL;
2042 more_btn = _create_toolbar_more_btn(ug_data->navi_bar, _more_cb, ug_data);
2043 elm_object_item_part_content_set(ug_data->navi_main_it, "toolbar_more_btn", more_btn);
2045 if (ug_data->mailbox_type == EMAIL_MAILBOX_TYPE_INBOX || ug_data->mailbox_type == EMAIL_MAILBOX_TYPE_SENTBOX ||
2046 ug_data->mailbox_type == EMAIL_MAILBOX_TYPE_TRASH || ug_data->mailbox_type == EMAIL_MAILBOX_TYPE_SPAMBOX) {
2048 int n_to_list = g_list_length(ug_data->to_list);
2049 int n_cc_list = g_list_length(ug_data->cc_list);
2050 debug_log("to:%d, cc:%d", n_to_list, n_cc_list);
2051 if (n_to_list + n_cc_list >= 2) {
2052 ug_data->reply_btn = _create_toolbar_btn(ug_data->navi_bar, dgettext("sys_string", "IDS_COM_SK_REPLY"), _reply_option_cb, ug_data, "naviframe/toolbar/left");
2054 ug_data->reply_btn = _create_toolbar_btn(ug_data->navi_bar, dgettext("sys_string", "IDS_COM_SK_REPLY"), _reply_cb, ug_data, "naviframe/toolbar/left");
2056 elm_object_item_part_content_set(ug_data->navi_main_it, "toolbar_button1", ug_data->reply_btn);
2057 ug_data->delete_btn = _create_toolbar_btn(ug_data->navi_bar, dgettext("sys_string", "IDS_COM_SK_DELETE"), _delete_cb, ug_data, "naviframe/toolbar/right");
2058 elm_object_item_part_content_set(ug_data->navi_main_it, "toolbar_button2", ug_data->delete_btn);
2059 } else if (ug_data->mailbox_type == EMAIL_MAILBOX_TYPE_OUTBOX) {
2060 debug_log("save_status: %d", prop->status2);
2061 if (prop->status2 == EMAIL_MAIL_STATUS_SEND_WAIT || prop->status2 == EMAIL_MAIL_STATUS_SEND_FAILURE) {
2062 ug_data->cancel_btn = _create_toolbar_btn(ug_data->navi_bar, dgettext("sys_string", "IDS_COM_SK_CANCEL"), _cancel_send_cb, ug_data, "naviframe/toolbar/left");
2063 elm_object_item_part_content_set(ug_data->navi_main_it, "toolbar_button1", ug_data->cancel_btn);
2064 ug_data->delete_btn = _create_toolbar_btn(ug_data->navi_bar, dgettext("sys_string", "IDS_COM_SK_DELETE"), _delete_cb, ug_data, "naviframe/toolbar/right");
2065 elm_object_item_part_content_set(ug_data->navi_main_it, "toolbar_button2", ug_data->delete_btn);
2066 } else if (prop->status2 == EMAIL_MAIL_STATUS_SEND_CANCELED) {
2067 ug_data->resend_btn = _create_toolbar_btn(ug_data->navi_bar, _("IDS_EMAIL_SK_RESEND"), _resend_cb, ug_data, "naviframe/toolbar/left");
2068 elm_object_item_part_content_set(ug_data->navi_main_it, "toolbar_button1", ug_data->resend_btn);
2069 ug_data->delete_btn = _create_toolbar_btn(ug_data->navi_bar, dgettext("sys_string", "IDS_COM_SK_DELETE"), _delete_cb, ug_data, "naviframe/toolbar/right");
2070 elm_object_item_part_content_set(ug_data->navi_main_it, "toolbar_button2", ug_data->delete_btn);
2072 ug_data->move_btn = _create_toolbar_btn(ug_data->navi_bar, _("IDS_EMAIL_SK_MOVE"), _move_cb, ug_data, "naviframe/toolbar/left");
2073 elm_object_item_part_content_set(ug_data->navi_main_it, "toolbar_button1", ug_data->move_btn);
2074 ug_data->delete_btn = _create_toolbar_btn(ug_data->navi_bar, dgettext("sys_string", "IDS_COM_SK_DELETE"), _delete_cb, ug_data, "naviframe/toolbar/right");
2075 elm_object_item_part_content_set(ug_data->navi_main_it, "toolbar_button1", ug_data->delete_btn);
2078 ug_data->move_btn = _create_toolbar_btn(ug_data->navi_bar, _("IDS_EMAIL_SK_MOVE"), _move_cb, ug_data, "naviframe/toolbar/left");
2079 elm_object_item_part_content_set(ug_data->navi_main_it, "toolbar_button1", ug_data->move_btn);
2080 ug_data->delete_btn = _create_toolbar_btn(ug_data->navi_bar, dgettext("sys_string", "IDS_COM_SK_DELETE"), _delete_cb, ug_data, "naviframe/toolbar/right");
2081 elm_object_item_part_content_set(ug_data->navi_main_it, "toolbar_button2", ug_data->delete_btn);
2087 static Evas_Object *_create_partial_body_dn_btn(EmailViewerUGD *ug_data)
2091 ug_data->partial_dn_btn_bx = _load_edj(ug_data->navi_bar, EV_THEME_PATH, "layout.email.partial_download_btn");
2092 if (ug_data->partial_dn_btn_bx == NULL) {
2093 debug_log("Cannot load edj");
2097 evas_object_size_hint_align_set(ug_data->partial_dn_btn_bx, EVAS_HINT_FILL, 0.0);
2098 evas_object_show(ug_data->partial_dn_btn_bx);
2099 elm_box_pack_before(ug_data->main_bx, ug_data->partial_dn_btn_bx, ug_data->webview_bx);
2101 Evas_Object *dn_btn = elm_button_add(ug_data->navi_bar);
2102 elm_object_text_set(dn_btn, _("IDS_EMAIL_BODY_DOWNLOAD_FULL_MESSAGE"));
2103 evas_object_smart_callback_add(dn_btn, "clicked", _body_down_cb, (void *)ug_data);
2104 elm_object_style_set(dn_btn, "text_only/style2");
2105 evas_object_show(dn_btn);
2106 ug_data->partial_dn_btn = dn_btn;
2108 elm_object_part_content_set(ug_data->partial_dn_btn_bx, "button", ug_data->partial_dn_btn);
2110 return ug_data->partial_dn_btn_bx;
2113 static Evas_Object *_create_bg(Evas_Object *win)
2117 Evas_Object *bg = elm_bg_add(win);
2118 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2119 evas_object_show(bg);
2124 static void _create_down_progress(char *message, popup_cb resp_cb)
2129 debug_log("data is NULL");
2133 EmailViewerUGD *ug_data = _g_ug_data;
2134 Evas_Object *notify, *pb;
2136 notify = elm_popup_add(ug_data->win_main);
2138 debug_log("elm_popup_add returns NULL");
2141 evas_object_size_hint_weight_set(notify, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2142 ug_data->pb_notify = notify;
2144 elm_object_part_text_set(notify, "title,text", message);
2146 pb = elm_progressbar_add(notify);
2148 elm_object_style_set(pb, "list_progress");
2150 elm_progressbar_horizontal_set(pb, EINA_TRUE);
2151 evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, EVAS_HINT_FILL);
2152 evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2153 evas_object_show(pb);
2154 elm_progressbar_value_set(pb, 0.0);
2155 elm_object_content_set(notify, pb);
2156 ug_data->pb_notify_lb = pb;
2158 Evas_Object *btn1 = elm_button_add(notify);
2159 elm_object_style_set(btn1, "popup_button/default");
2160 elm_object_text_set(btn1, dgettext("sys_string", "IDS_COM_SK_CANCEL"));
2161 elm_object_part_content_set(notify, "button1", btn1);
2162 evas_object_smart_callback_add(btn1, "clicked", resp_cb, ug_data);
2163 debug_log("Cancel btn1 for downloading body: %p", btn1);
2165 evas_object_show(notify);
2168 static void _create_down_progress_ex(int index, EMAIL_VIEWER_PROGRESSBAR_TYPE p_type)
2173 debug_log("data is NULL");
2177 EmailViewerUGD *ug_data = _g_ug_data;
2178 EmailViewerProp *prop = ug_data->property;
2179 EmailViewerPrivate *priv = ug_data->email_data;
2181 if (!prop || !prop->attachments) {
2195 elm_scroller_region_get(ug_data->scroller, &scr_x, &scr_y, &scr_w, &scr_h);
2196 debug_log("scroller region> x[%d] y[%d] w[%d] h[%d]", scr_x, scr_y, scr_w, scr_h);
2198 GList *attachment_list = prop->attachments;
2200 debug_log("index %d of attachment_count %d", index, prop->att_len);
2202 EmailAttachmentType *info = NULL;
2203 info = g_list_nth_data(attachment_list, index);
2205 debug_log("info is NULL");
2208 Evas_Object *pbar_ly = elm_layout_add(ug_data->navi_bar);
2209 elm_layout_file_set(pbar_ly, EV_THEME_PATH, "layout.email.attachment_downloading");
2210 evas_object_size_hint_align_set(pbar_ly, EVAS_HINT_FILL, 0.0);
2211 evas_object_show(pbar_ly);
2212 ug_data->progress_bar_ly[index + 1] = pbar_ly;
2215 char buff[MAX_STR_LEN] = { 0, };
2217 Evas_Object *downloading_label1;
2218 downloading_label1 = elm_label_add(pbar_ly);
2219 elm_object_part_content_set(pbar_ly, "elm.text.1", downloading_label1);
2220 char *text_tagged = g_strconcat("<font_size=32><align=left><color=#000000FF>", info->name, "</color></align></font_size>", NULL);
2221 elm_object_text_set(downloading_label1, text_tagged);
2222 elm_label_ellipsis_set(downloading_label1, EINA_TRUE);
2223 elm_label_wrap_width_set(downloading_label1, ug_data->main_w - 240);
2224 g_free(text_tagged);
2226 if (info->size < 1024) {
2227 g_sprintf(buff, "%d %s", (gint) info->size, dgettext("sys_string", "IDS_COM_BODY_B"));
2229 gdouble tmpsize = (gdouble) (info->size / 1024.);
2231 if (tmpsize < 1024) {
2232 g_sprintf(buff, "%.2f %s", tmpsize, dgettext("sys_string", "IDS_COM_BODY_KB"));
2236 if (tmpsize < 1024) {
2237 g_sprintf(buff, "%.2f %s", tmpsize, dgettext("sys_string", "IDS_COM_BODY_MB"));
2240 g_sprintf(buff, "%.2f %s", tmpsize, dgettext("sys_string", "IDS_COM_BODY_GB"));
2245 Evas_Object *downloading_label3;
2246 downloading_label3 = elm_label_add(pbar_ly);
2247 elm_object_part_content_set(pbar_ly, "elm.text.3", downloading_label3);
2248 text_tagged = g_strconcat("<font_size=26><align=right><color=#646464FF>", buff, "</color></align></font_size>", NULL);
2249 elm_object_text_set(downloading_label3, text_tagged);
2250 g_free(text_tagged);
2253 Evas_Object *progressbar = elm_progressbar_add(pbar_ly);
2254 elm_progressbar_horizontal_set(progressbar, EINA_TRUE);
2255 elm_object_style_set(progressbar, "list_progress");
2256 elm_object_part_content_set(pbar_ly, "elm.icon.2", progressbar);
2257 ug_data->progress_bar[index + 1] = progressbar;
2258 evas_object_show(progressbar);
2260 Evas_Object *cancel_btn = elm_button_add(pbar_ly);
2261 elm_object_style_set(cancel_btn, "text_only/style2");
2262 elm_object_text_set(cancel_btn, dgettext("sys_string", "IDS_COM_SK_CANCEL"));
2264 elm_object_part_content_set(pbar_ly, "elm.icon.1", cancel_btn);
2265 evas_object_show(cancel_btn);
2266 evas_object_smart_callback_add(cancel_btn, "clicked", _destroy_down_progress_ex, (void *)index);
2267 debug_log("Cancel button for attachment downloading progress popup: %p", cancel_btn);
2269 /* packing progress layout */
2270 if (p_type == EMAIL_VIEWER_PROGRESSBAR_ATT && prop->real_att_len > 1) {
2271 for (i = 0; i < prop->att_len; i++) {
2272 info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, attachment_list);
2273 if (info && !info->inline_content) {
2275 if (ug_data->attach_ex_ly != NULL && ug_data->attach_ex_ly[j] != NULL) {
2277 elm_box_pack_after(ug_data->main_bx, pbar_ly, ug_data->attach_ex_ly[j]);
2278 elm_box_unpack(ug_data->main_bx, ug_data->attach_ex_ly[j]);
2279 evas_object_hide(ug_data->attach_ex_ly[j]);
2280 ug_data->attach_ex_ly[j] = pbar_ly;
2287 if ((p_type == EMAIL_VIEWER_PROGRESSBAR_ATT && prop->real_att_len == 1) || (p_type == EMAIL_VIEWER_PROGRESSBAR_ATT_ALL)) {
2289 elm_box_pack_after(ug_data->main_bx, pbar_ly, ug_data->attach_hd_ly);
2290 elm_box_unpack(ug_data->main_bx, ug_data->attach_hd_ly);
2291 evas_object_hide(ug_data->attach_hd_ly);
2292 ug_data->attach_hd_ly = pbar_ly;
2295 elm_object_focus_set(pbar_ly, EINA_TRUE);
2296 elm_scroller_region_show(ug_data->scroller, scr_x, scr_y, scr_w, scr_h);
2299 static void _destroy_down_progress_ex(void *data, Evas_Object *obj, void *event_info)
2304 debug_log("data is NULL");
2308 EmailViewerUGD *ug_data = _g_ug_data;
2309 EmailViewerPrivate *priv = ug_data->email_data;
2310 EmailViewerProp *prop = ug_data->property;
2312 if (!prop || !prop->attachments) {
2326 elm_scroller_region_get(ug_data->scroller, &scr_x, &scr_y, &scr_w, &scr_h);
2327 debug_log("scroller region> x[%d] y[%d] w[%d] h[%d]", scr_x, scr_y, scr_w, scr_h);
2329 GList *attachment_list = prop->attachments;
2330 int index = (int)data;
2333 /* Cancel the download in email-service */
2335 debug_log("index[%d] download_all_cnt[%d] email_handle[%d]", index, priv->download_all_cnt, priv->download_all_email_handle[index]);
2336 if (priv->download_all_email_handle[index] != 0) {
2337 email_engine_stop_working(ug_data->account_id, priv->download_all_email_handle[index]);
2338 priv->download_all_email_handle[index] = 0;
2341 (priv->download_all_cnt)--;
2343 if (priv->download_all_cnt == 0)
2344 priv->b_all_att_save = FALSE;
2345 } else if (index == -1) {
2346 for (i = 0; i < prop->att_len; i++) {
2347 EmailAttachmentType *info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, attachment_list);
2348 if (info && !info->inline_content) {
2349 debug_log("index[%d] download_all_cnt[%d] email_handle[%d]", i, priv->download_all_cnt, priv->download_all_email_handle[i]);
2350 if (priv->download_all_email_handle[i] != 0) {
2351 email_engine_stop_working(ug_data->account_id, priv->download_all_email_handle[i]);
2354 priv->download_all_email_handle[i] = 0;
2356 priv->download_all_cnt = 0;
2357 priv->b_all_att_save = FALSE;
2360 /* upack and delete, pack again */
2362 debug_log("real_att_len:%d", prop->real_att_len);
2363 if (prop->real_att_len == 1) {
2364 debug_log("index[%d]", index);
2365 elm_box_pack_after(ug_data->main_bx, ug_data->attach_hd_bk, ug_data->attach_hd_ly);
2366 elm_box_unpack(ug_data->main_bx, ug_data->attach_hd_ly);
2367 evas_object_del(ug_data->attach_hd_ly);
2368 ug_data->attach_hd_ly = ug_data->attach_hd_bk;
2369 evas_object_show(ug_data->attach_hd_ly);
2370 elm_object_focus_set(ug_data->attach_hd_ly, EINA_TRUE);
2371 ug_data->progress_bar[index + 1] = NULL;
2372 ug_data->progress_bar_ly[index + 1] = NULL;
2373 } else if (prop->real_att_len > 1) {
2374 for (i = 0; i < prop->att_len; i++) {
2375 EmailAttachmentType *info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, attachment_list);
2376 if (info && !info->inline_content) {
2378 debug_log("index[%d]", i);
2379 debug_log("attach_onoff_flag:%d", ug_data->attach_onoff_flag);
2380 if (ug_data->attach_onoff_flag > 0) {
2381 elm_box_pack_after(ug_data->main_bx, ug_data->attach_ex_bk[j], ug_data->attach_ex_ly[j]);
2382 elm_box_unpack(ug_data->main_bx, ug_data->attach_ex_ly[j]);
2383 evas_object_del(ug_data->attach_ex_ly[j]);
2384 ug_data->attach_ex_ly[j] = ug_data->attach_ex_bk[j];
2385 evas_object_show(ug_data->attach_ex_ly[j]);
2386 elm_object_focus_set(ug_data->attach_ex_ly[j], EINA_TRUE);
2387 ug_data->progress_bar[index + 1] = NULL;
2388 ug_data->progress_bar_ly[index + 1] = NULL;
2390 evas_object_del(ug_data->attach_ex_ly[j]);
2391 ug_data->attach_ex_ly[j] = ug_data->attach_ex_bk[j];
2392 ug_data->progress_bar[index + 1] = NULL;
2393 ug_data->progress_bar_ly[index + 1] = NULL;
2400 } else if (index == -1) {
2401 debug_log("index[%d]", index);
2402 elm_box_pack_after(ug_data->main_bx, ug_data->attach_hd_bk, ug_data->attach_hd_ly);
2403 elm_box_unpack(ug_data->main_bx, ug_data->attach_hd_ly);
2404 evas_object_del(ug_data->attach_hd_ly);
2405 ug_data->attach_hd_ly = ug_data->attach_hd_bk;
2406 evas_object_show(ug_data->attach_hd_ly);
2407 elm_object_focus_set(ug_data->attach_hd_ly, EINA_TRUE);
2408 ug_data->progress_bar[index + 1] = NULL;
2409 ug_data->progress_bar_ly[index + 1] = NULL;
2412 elm_scroller_region_show(ug_data->scroller, scr_x, scr_y, scr_w, scr_h);
2415 static void _move_ctxpopup(Evas_Object *ctxpopup, Evas_Object *win)
2417 Evas_Coord x, y, w, h;
2419 evas_object_geometry_get(win, &x, &y, &w, &h);
2420 evas_object_move(ctxpopup, x + (w / 2), y);
2423 static void _create_more_ctxpopup(EmailViewerUGD *ug_data, Evas_Object *obj)
2427 debug_log("ug_data is NULL");
2431 EmailViewerProp *prop = ug_data->property;
2432 EMAIL_CONTACT_LIST_INFO_S *contact_list_item = NULL;
2433 contact_list_item = (EMAIL_CONTACT_LIST_INFO_S *)_contact_search_by_email(ug_data, prop->sender);
2434 Evas_Object* icon = NULL;
2436 if (ug_data->con_popup) {
2437 evas_object_del(ug_data->con_popup);
2438 ug_data->con_popup = NULL;
2441 ug_data->con_popup = elm_ctxpopup_add(ug_data->navi_bar);
2442 if (ug_data->con_popup == NULL) {
2443 debug_log("cannot create context popup");
2447 debug_log("mailbox_type:%d", ug_data->mailbox_type);
2448 if (ug_data->mailbox_type == EMAIL_MAILBOX_TYPE_OUTBOX) {
2449 if (prop->status2 == EMAIL_MAIL_STATUS_SEND_CANCELED) {
2450 icon = elm_icon_add(ug_data->con_popup);
2451 elm_image_file_set(icon, IMGDIR "/M02_popup_icon_edit.png", NULL);
2452 elm_ctxpopup_item_append(ug_data->con_popup, dgettext("sys_string", "IDS_COM_SK_EDIT"), icon, _edit_email_cb, ug_data);
2456 icon = elm_icon_add(ug_data->con_popup);
2457 elm_image_file_set(icon, IMGDIR "/M02_popup_icon_mark_as_unread.png", NULL);
2458 if (email_engine_check_seen_mail(ug_data->account_id, ug_data->mail_id)) {
2459 elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_MARK_AS_UNREAD"), icon, _mark_as_unread_cb, ug_data);
2461 elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_MARK_AS_READ"), icon, _mark_as_read_cb, ug_data);
2465 icon = elm_icon_add(ug_data->con_popup);
2466 elm_image_file_set(icon, IMGDIR "/M02_popup_icon_forward.png", NULL);
2467 elm_ctxpopup_item_append(ug_data->con_popup, dgettext("sys_string", "IDS_COM_BODY_FORWARD"), icon, _forward_cb, ug_data);
2470 icon = elm_icon_add(ug_data->con_popup);
2471 elm_image_file_set(icon, IMGDIR "/M02_popup_icon_mark_as_unread.png", NULL);
2472 if (email_engine_check_seen_mail(ug_data->account_id, ug_data->mail_id)) {
2473 elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_MARK_AS_UNREAD"), icon, _mark_as_unread_cb, ug_data);
2475 elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_MARK_AS_READ"), icon, _mark_as_read_cb, ug_data);
2479 icon = elm_icon_add(ug_data->con_popup);
2480 elm_image_file_set(icon, IMGDIR "/M02_popup_icon_move.png", NULL);
2481 elm_ctxpopup_item_append(ug_data->con_popup, dgettext("sys_string", "IDS_COM_BODY_MOVE"), icon, _move_cb, ug_data);
2484 icon = elm_icon_add(ug_data->con_popup);
2485 elm_image_file_set(icon, IMGDIR "/M02_popup_icon_save_email.png", NULL);
2486 elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_SAVE_EMAIL_ABB"), icon, _save_email_cb, ug_data);
2489 if (contact_list_item) {
2490 debug_log("Contact Item Exist: index[%d]", contact_list_item->index);
2491 char index[10] = { 0, };
2492 snprintf(index, sizeof(index), "%d", contact_list_item->index);
2493 icon = elm_icon_add(ug_data->con_popup);
2494 elm_image_file_set(icon, IMGDIR "/M02_popup_icon_view contact.png", NULL);
2495 elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_VIEW_CONTACT"), icon, _ctxpopup_detail_contact_cb, g_strdup(index));
2497 _delete_contacts_list(contact_list_item);
2499 ug_data->create_contact_arg = CONTACTUI_REQ_ADD_EMAIL;
2500 icon = elm_icon_add(ug_data->con_popup);
2501 elm_image_file_set(icon, IMGDIR "/M02_popup_icon_add_to_contacts.png", NULL);
2502 elm_ctxpopup_item_append(ug_data->con_popup, dgettext("sys_string", "IDS_COM_OPT_ADD_TO_CONTACTS"), icon, _ctxpopup_add_contact_cb, prop->sender);
2507 _move_ctxpopup(ug_data->con_popup, obj);
2508 evas_object_show(ug_data->con_popup);
2511 static void _create_reply_ctxpopup(EmailViewerUGD *ug_data)
2515 debug_log("ug_data is NULL");
2519 if (ug_data->con_popup) {
2520 evas_object_del(ug_data->con_popup);
2521 ug_data->con_popup = NULL;
2524 ug_data->con_popup = elm_ctxpopup_add(ug_data->navi_bar);
2525 if (ug_data->con_popup == NULL) {
2526 debug_log("cannot create context popup");
2530 elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_TO_SENDER_ABB"), NULL, _reply_cb, ug_data);
2531 elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_TO_ALL_ABB"), NULL, _reply_all_cb, ug_data);
2533 Evas_Coord x, y, w, h;
2534 evas_object_geometry_get(ug_data->reply_btn, &x, &y, &w, &h);
2535 evas_object_move(ug_data->con_popup, x + (w / 2), y);
2536 evas_object_show(ug_data->con_popup);
2539 static void _delete_evas_objects(EmailViewerUGD *ug_data)
2542 EmailViewerProp *prop = ug_data->property;
2544 if (ug_data->webview) {
2545 evas_object_del(ug_data->webview);
2546 ug_data->webview = NULL;
2549 if (ug_data->webview_bx) {
2550 evas_object_del(ug_data->webview_bx);
2551 ug_data->webview_bx = NULL;
2554 if (ug_data->scroller) {
2555 evas_object_del(ug_data->scroller);
2556 ug_data->scroller = NULL;
2559 if (ug_data->main_bx) {
2560 evas_object_del(ug_data->main_bx);
2561 ug_data->main_bx = NULL;
2564 if (ug_data->b_btn) {
2565 evas_object_del(ug_data->b_btn);
2566 ug_data->b_btn = NULL;
2569 if (ug_data->sub_ly) {
2570 evas_object_del(ug_data->sub_ly);
2571 ug_data->sub_ly = NULL;
2574 if (ug_data->navi_bar) {
2575 evas_object_del(ug_data->navi_bar);
2576 ug_data->navi_bar = NULL;
2579 if (ug_data->ctr_bar) {
2580 evas_object_del(ug_data->ctr_bar);
2581 ug_data->ctr_bar = NULL;
2584 if (ug_data->layout_main) {
2585 evas_object_del(ug_data->layout_main);
2586 ug_data->layout_main = NULL;
2589 if (ug_data->con_popup) {
2590 evas_object_del(ug_data->con_popup);
2591 ug_data->con_popup = NULL;
2594 if (ug_data->select_info) {
2595 evas_object_del(ug_data->select_info);
2596 ug_data->select_info = NULL;
2599 if (ug_data->selectioninfo_layout != NULL) {
2600 evas_object_del(ug_data->selectioninfo_layout);
2601 ug_data->selectioninfo_layout = NULL;
2604 if (ug_data->notify) {
2605 evas_object_del(ug_data->notify);
2606 ug_data->notify = NULL;
2609 if (ug_data->pb_notify) {
2610 evas_object_del(ug_data->pb_notify);
2611 ug_data->pb_notify = NULL;
2614 if (ug_data->pb_notify_lb) {
2615 evas_object_del(ug_data->pb_notify_lb);
2616 ug_data->pb_notify_lb = NULL;
2619 if (ug_data->partial_dn_btn) {
2620 evas_object_del(ug_data->partial_dn_btn);
2621 ug_data->partial_dn_btn = NULL;
2624 if (ug_data->partial_dn_btn_bx) {
2625 evas_object_del(ug_data->partial_dn_btn_bx);
2626 ug_data->partial_dn_btn_bx = NULL;
2629 if (ug_data->waiting_timer) {
2630 ecore_timer_del(ug_data->waiting_timer);
2631 ug_data->waiting_timer = NULL;
2634 if (ug_data->timer) {
2635 ecore_timer_del(ug_data->timer);
2636 ug_data->timer = NULL;
2639 if (ug_data->idler) {
2640 ecore_idler_del(ug_data->idler);
2641 ug_data->idler = NULL;
2644 if (ug_data->got_att) {
2647 evas_object_del(ug_data->attach_hd_bk);
2648 ug_data->attach_hd_ly = NULL;
2649 ug_data->attach_hd_bk = NULL;
2651 if (prop->real_att_len > 1) {
2652 for (i = 0; i < prop->real_att_len; i++) {
2653 if (ug_data->attach_ex_ly != NULL) {
2654 if (ug_data->attach_ex_ly[i] != NULL) {
2655 debug_log("index %d", i);
2656 evas_object_del(ug_data->attach_ex_bk[i]);
2657 ug_data->attach_ex_ly[i] = NULL;
2658 ug_data->attach_ex_bk[i] = NULL;
2663 if (ug_data->attach_ex_ly != NULL) {
2664 free(ug_data->attach_ex_ly);
2665 ug_data->attach_ex_ly = NULL;
2666 ug_data->attach_ex_bk = NULL;
2670 for (i = 0; i <= prop->att_len; i++) {
2671 if (ug_data->progress_bar_ly[i] != NULL) {
2672 evas_object_del(ug_data->progress_bar_ly[i]);
2673 ug_data->progress_bar_ly[i] = NULL;
2674 ug_data->progress_bar[i] = NULL;
2680 void _launch_composer(EmailViewerUGD *ug_data, int type)
2685 debug_log("ug_data is NULL");
2689 EmailViewerPrivate *priv = ug_data->email_data;
2693 service_h service = NULL;
2695 ret = service_create(&service);
2696 debug_log("service_create: %d", ret);
2698 debug_log("service create failed");
2702 char rtype[10] = { 0, };
2703 snprintf(rtype, sizeof(rtype), "%d", type);
2704 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_RUN_TYPE, rtype);
2705 debug_log("service_add_extra_data: %d", ret);
2707 memset(tmp, 0x0, sizeof(tmp));
2708 snprintf(tmp, sizeof(tmp), "%d", priv->account_id);
2709 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_ACCOUNT_ID, tmp);
2710 debug_log("service_add_extra_data: %d", ret);
2712 memset(tmp, 0x0, sizeof(tmp));
2713 snprintf(tmp, sizeof(tmp), "%d", priv->mailbox_id);
2714 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_MAILBOX, tmp);
2715 debug_log("service_add_extra_data: %d", ret);
2717 memset(tmp, 0x0, sizeof(tmp));
2718 snprintf(tmp, sizeof(tmp), "%d", priv->mail_id);
2719 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_MAIL_ID, tmp);
2720 debug_log("service_add_extra_data: %d", ret);
2722 ug_data->ug_composer = create_ug(UG_NAME_EMAIL_COMPOSER, service, ug_data);
2724 ret = service_destroy(service);
2725 debug_log("service_destroy: %d", ret);
2728 static void _back_cb(void *data, Evas_Object *obj, void *event_info)
2732 if (_g_ug_data == NULL) {
2733 debug_log("_g_ug_data is NULL");
2738 debug_log("data is NULL");
2741 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
2743 if (ug_data->con_popup != NULL) {
2744 evas_object_del(ug_data->con_popup);
2745 ug_data->con_popup = NULL;
2748 debug_log("isRoate = %d", ug_data->isRotate);
2749 if (ug_data->isRotate == false && ug_data->b_internal) {
2750 /* Viewer to hide, so set left content (mailbox) size to full */
2751 _notify_mailbox_size(ug_data, "MAILBOX_RESIZE_FULL");
2754 if (ug_data->b_internal != 1) {
2755 debug_log("ug_destory_me");
2756 ug_destroy_me(ug_data->ug);
2758 _hide_view(ug_data);
2762 static void _reply_cb(void *data, Evas_Object *obj, void *event_info)
2766 debug_log("data is NULL");
2770 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
2772 if (ug_data->con_popup) {
2773 evas_object_del(ug_data->con_popup);
2774 ug_data->con_popup = NULL;
2777 ug_data->display_download_result = FALSE;
2778 _launch_composer(ug_data, RUN_COMPOSER_REPLY);
2780 if (ug_data->notify) {
2781 evas_object_del(ug_data->notify);
2782 ug_data->notify = NULL;
2786 static void _reply_all_cb(void *data, Evas_Object *obj, void *event_info)
2790 debug_log("data is NULL");
2794 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
2796 if (ug_data->con_popup) {
2797 evas_object_del(ug_data->con_popup);
2798 ug_data->con_popup = NULL;
2801 ug_data->display_download_result = FALSE;
2802 _launch_composer(ug_data, RUN_COMPOSER_REPLY_ALL);
2804 if (ug_data->notify) {
2805 evas_object_del(ug_data->notify);
2806 ug_data->notify = NULL;
2810 static void _reply_option_cb(void *data, Evas_Object *obj, void *event_info)
2814 debug_log("data is NULL");
2818 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
2820 _create_reply_ctxpopup(ug_data);
2823 static void _forward_cb(void *data, Evas_Object *obj, void *event_info)
2827 debug_log("data is NULL");
2831 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
2833 if (ug_data->con_popup) {
2834 evas_object_del(ug_data->con_popup);
2835 ug_data->con_popup = NULL;
2838 ug_data->display_download_result = FALSE;
2839 _launch_composer(ug_data, RUN_COMPOSER_FORWARD);
2842 static void _resend_cb(void *data, Evas_Object *obj, void *event_info)
2846 debug_log("data is NULL");
2850 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
2853 /* Send email again */
2854 debug_log("ug_data->account_id(%d), priv->account_id(%d), mail_info->account_id(%d), prop->account_id(%d)", ug_data->account_id, ug_data->email_data->account_id, ug_data->email_data->mail_info->account_id, ug_data->property->account_id);
2855 debug_log("ug_data->mail_id(%d), priv->mail_id(%d), mail_info->mail_id(%d), prop->mail_id(%d)", ug_data->mail_id, ug_data->email_data->mail_id, ug_data->email_data->mail_info->mail_id, ug_data->property->mail_id);
2857 int err = email_send_mail(ug_data->mail_id, &handle);
2858 if (err != EMAIL_ERROR_NONE) {
2859 debug_warning("email_send_mail failed: handle(%d) - err(%d)", handle, err);
2861 debug_log("sending: handle(%d)", handle);
2864 if (ug_data->isRotate == false && ug_data->b_internal) {
2865 /* Viewer to hide, so set left content (mailbox) size to full */
2866 _notify_mailbox_size(ug_data, "MAILBOX_RESIZE_FULL");
2870 if (ug_data->b_internal) {
2871 _hide_view(ug_data);
2873 debug_log("ug_destory_me");
2874 ug_destroy_me(ug_data->ug);
2878 static void _cancel_send_cb(void *data, Evas_Object *obj, void *event_info)
2882 debug_log("data is NULL");
2886 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
2888 debug_log("ug_data->account_id(%d), priv->account_id(%d), mail_info->account_id(%d), prop->account_id(%d)", ug_data->account_id, ug_data->email_data->account_id, ug_data->email_data->mail_info->account_id, ug_data->property->account_id);
2889 debug_log("ug_data->mail_id(%d), priv->mail_id(%d), mail_info->mail_id(%d), prop->mail_id(%d)", ug_data->mail_id, ug_data->email_data->mail_id, ug_data->email_data->mail_info->mail_id, ug_data->property->mail_id);
2891 int err = email_cancel_sending_mail(ug_data->mail_id);
2892 if (err != EMAIL_ERROR_NONE) {
2893 debug_warning("email_engine_cancel_send_mail failed - err(%d)", err);
2897 static void _edit_email_cb(void *data, Evas_Object *obj, void *event_info)
2901 debug_log("data is NULL");
2905 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
2907 if (ug_data->con_popup) {
2908 evas_object_del(ug_data->con_popup);
2909 ug_data->con_popup = NULL;
2913 service_h service = NULL;
2915 ret = service_create(&service);
2916 debug_log("service_create: %d", ret);
2918 debug_log("service create failed");
2922 char rtype[10] = { 0, };
2923 snprintf(rtype, sizeof(rtype), "%d", RUN_COMPOSER_EDIT);
2924 char acctid[10] = { 0, };
2925 snprintf(acctid, sizeof(acctid), "%d", ug_data->account_id);
2926 char mailboxid[10] = { 0, };
2927 snprintf(mailboxid, sizeof(mailboxid), "%d", ug_data->mailbox_id);
2928 char mailid[10] = { 0, };
2929 snprintf(mailid, sizeof(mailid), "%d", ug_data->mail_id);
2931 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_RUN_TYPE, rtype);
2932 debug_log("service_add_extra_data: %d", ret);
2933 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_ACCOUNT_ID, acctid);
2934 debug_log("service_add_extra_data: %d", ret);
2935 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_MAILBOX, mailboxid);
2936 debug_log("service_add_extra_data: %d", ret);
2937 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_MAIL_ID, mailid);
2938 debug_log("service_add_extra_data: %d", ret);
2940 ug_data->ug_composer = create_ug(UG_NAME_EMAIL_COMPOSER, service, ug_data);
2942 ret = service_destroy(service);
2943 debug_log("service_destroy: %d", ret);
2946 static void _delete_cb(void *data, Evas_Object *obj, void *event_info)
2950 debug_log("data is NULL");
2954 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
2956 if (ug_data->con_popup) {
2957 evas_object_del(ug_data->con_popup);
2958 ug_data->con_popup = NULL;
2961 if (ug_data->mailbox_type != EMAIL_MAILBOX_TYPE_TRASH) {
2962 _create_notify_3btn(ug_data, NULL, dgettext("sys_string", "IDS_COM_POP_DELETE_Q"),
2963 3, _("IDS_EMAIL_BUTTON_MOVE_TO_RECYCLE_BIN"), _popup_response_move_to_trash_cb,
2964 _("IDS_EMAIL_BUTTON_DELETE_PERMANENTLY"), _popup_response_delete_permanent_cb,
2965 dgettext("sys_string", "IDS_COM_SK_CANCEL"), _popup_response_cb, NULL);
2967 _create_notify_3btn(ug_data, NULL, dgettext("sys_string", "IDS_COM_POP_DELETE_Q"),
2968 2, dgettext("sys_string", "IDS_COM_SK_DELETE"), _popup_response_delete_ok_cb,
2969 dgettext("sys_string", "IDS_COM_SK_CANCEL"), _popup_response_cb, NULL, NULL, NULL);
2973 static void _move_cb(void *data, Evas_Object *obj, void *event_info)
2977 debug_log("data is NULL");
2981 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
2982 EmailViewerPrivate *priv = ug_data->email_data;
2984 if (ug_data->con_popup) {
2985 evas_object_del(ug_data->con_popup);
2986 ug_data->con_popup = NULL;
2989 Evas_Object *gl = elm_genlist_add(ug_data->navi_bar);
2990 evas_object_show(gl);
2992 ug_data->itc1.item_style = "1text.1icon.2";
2993 ug_data->itc1.func.text_get = _gl_text_get;
2994 ug_data->itc1.func.content_get = _gl_content_get;
2995 ug_data->itc1.func.state_get = _gl_state_get;
2996 ug_data->itc1.func.del = _gl_del;
2998 Elm_Object_Item *navi_it = NULL;
2999 navi_it = elm_naviframe_top_item_get(ug_data->navi_bar);
3000 navi_it = elm_naviframe_item_insert_after(ug_data->navi_bar, navi_it, dgettext("sys_string", "IDS_COM_BODY_MOVE"), NULL, NULL, gl, NULL);
3001 ug_data->navi_move_it1 = navi_it;
3002 if (ug_data->isRotate)
3003 elm_naviframe_item_title_visible_set(ug_data->navi_move_it1, EINA_FALSE);
3005 email_mailbox_t *mailbox_list = NULL;
3006 int mailbox_count = 0;
3009 email_get_mailbox_list(priv->account_id, -1, &mailbox_list, &mailbox_count);
3010 debug_log("folder count %d", mailbox_count);
3011 ug_data->move_mailbox_list = mailbox_list;
3012 ug_data->move_mailbox_count = mailbox_count;
3014 for (i = 0; i < mailbox_count; i++) {
3015 if (mailbox_list[i].mailbox_id != ug_data->mailbox_id &&
3016 mailbox_list[i].mailbox_type != EMAIL_MAILBOX_TYPE_OUTBOX &&
3017 mailbox_list[i].mailbox_type != EMAIL_MAILBOX_TYPE_SENTBOX &&
3018 mailbox_list[i].mailbox_type != EMAIL_MAILBOX_TYPE_DRAFT &&
3019 mailbox_list[i].mailbox_type != EMAIL_MAILBOX_TYPE_TRASH &&
3020 mailbox_list[i].mailbox_type != EMAIL_MAILBOX_TYPE_ALL_EMAILS &&
3021 mailbox_list[i].mailbox_type != EMAIL_MAILBOX_TYPE_SEARCH_RESULT) {
3022 if (g_strcmp0(mailbox_list[i].alias, "[Gmail]")) {
3023 elm_genlist_item_append(gl, &ug_data->itc1, (void *)&(mailbox_list[i]), NULL, ELM_GENLIST_ITEM_NONE, _move_here_cb, (void *)&(mailbox_list[i]));
3025 Elm_Object_Item *item = elm_genlist_item_append(gl, &ug_data->itc1, (void *)&(mailbox_list[i]), NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
3026 elm_object_item_disabled_set(item, EINA_TRUE);
3029 Elm_Object_Item *item = elm_genlist_item_append(gl, &ug_data->itc1, (void *)&(mailbox_list[i]), NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
3030 elm_object_item_disabled_set(item, EINA_TRUE);
3034 Evas_Object *move_back_btn = NULL;
3035 move_back_btn = elm_object_item_part_content_get(navi_it, "prev_btn");
3036 if (move_back_btn) {
3037 evas_object_del(move_back_btn);
3038 move_back_btn = elm_button_add(ug_data->navi_bar);
3039 elm_object_style_set(move_back_btn, "naviframe/back_btn/default");
3040 evas_object_smart_callback_add(move_back_btn, "clicked", _move_back_cb, ug_data);
3041 elm_object_item_part_content_set(navi_it, "prev_btn", move_back_btn);
3045 static void _more_cb(void *data, Evas_Object *obj, void *event_info)
3049 debug_log("data is NULL");
3053 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
3055 _create_more_ctxpopup(ug_data, obj);
3058 static void _body_down_cb(void *data, Evas_Object *obj, void *event_info)
3062 debug_log("data is NULL");
3068 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
3069 EmailViewerPrivate *priv = ug_data->email_data;
3071 /* check already downloaded */
3072 int body_download_status = ug_data->property->body_download;
3074 if (body_download_status == 0) { //EMAIL_BODY_DOWNLOAD_STATUS_NONE
3075 debug_log("only header downloaded -> need body download");
3076 } else if (body_download_status == 1) { //EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED
3077 debug_log("already downloaded fully, create body directly");
3080 if (viewer_get_internal_mail_info(ug_data->property, ug_data->email_data)) {
3082 viewer_make_internal_mail(ug_data->property, ug_data->email_data);
3085 if (ug_data->b_partial_body) {
3090 elm_scroller_region_get(ug_data->scroller, &scr_x, &scr_y, &scr_w, &scr_h);
3091 debug_log("scroller region> x[%d] y[%d] w[%d] h[%d]", scr_x, scr_y, scr_w, scr_h);
3093 elm_box_unpack(ug_data->main_bx, ug_data->partial_dn_btn_bx);
3094 if (ug_data->partial_dn_btn) {
3095 evas_object_del(ug_data->partial_dn_btn);
3096 ug_data->partial_dn_btn = NULL;
3098 if (ug_data->partial_dn_btn_bx) {
3099 evas_object_del(ug_data->partial_dn_btn_bx);
3100 ug_data->partial_dn_btn_bx = NULL;
3103 if (ug_data->property->has_html) {
3104 ug_data->webview_data->body_type = BODY_TYPE_HTML;
3105 ug_data->webview_data->uri = ug_data->property->body_uri;
3107 ug_data->webview_data->body_type = BODY_TYPE_TEXT;
3108 ug_data->webview_data->text_content = ug_data->property->body;
3111 viewer_set_webview_content(ug_data, 1);
3112 ug_data->b_partial_body = 0;
3114 elm_object_focus_set(ug_data->ly_subject, EINA_TRUE);
3115 elm_scroller_region_show(ug_data->scroller, scr_x, scr_y, scr_w, scr_h);
3117 if (ug_data->property->has_attachment)
3118 ug_data->got_att = 1;
3120 ug_data->got_att = 0;
3122 /* pack attachment if it exist */
3123 if (ug_data->got_att) {
3124 _create_attach(ug_data);
3127 _create_body(ug_data);
3131 } else if (body_download_status == 2) { //EMAILL_BODY_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED
3132 debug_log("body downloaded partially -> need full body download");
3135 ret = email_engine_body_download(priv->account_id, priv->mail_id, &handle);
3138 priv->email_handle = handle;
3139 debug_log("succeed in email_engine_body_download(handle:%d)", priv->email_handle);
3140 _create_down_progress(dgettext("sys_string", "IDS_COM_POP_DOWNLOADING"), _destroy_down_progress_cb);
3142 /* If attachment download is in progress, first cancel to attachment download of the mail and then carry out body download */
3143 _cancel_download_attachment(ug_data);
3146 debug_log("unable to download mail body");
3147 _create_notify(ug_data, dgettext("sys_string", "IDS_COM_POP_WARNING"),
3148 _("IDS_EMAIL_POP_UNABLE_TO_DOWNLOAD"), 1,
3149 dgettext("sys_string", "IDS_COM_SK_OK"),
3150 _popup_response_cb, NULL, NULL, NULL);
3154 static void _subject_favorite_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
3158 debug_log("data is NULL");
3162 EmailViewerUGD *ug_data = _g_ug_data;
3163 EmailViewerProp *prop = ug_data->property;
3164 int err = EMAIL_ERROR_NONE;
3166 if (ug_data->con_popup) {
3167 evas_object_del(ug_data->con_popup);
3168 ug_data->con_popup = NULL;
3171 debug_log("Before prop->favorite: %d", prop->favorite);
3172 switch(prop->favorite) {
3173 case EMAIL_FLAG_NONE:
3174 prop->favorite = EMAIL_FLAG_FLAGED;
3176 case EMAIL_FLAG_FLAGED:
3177 prop->favorite = EMAIL_FLAG_NONE;
3179 case EMAIL_FLAG_TASK_STATUS_CLEAR:
3180 prop->favorite = EMAIL_FLAG_TASK_STATUS_ACTIVE;
3182 case EMAIL_FLAG_TASK_STATUS_ACTIVE:
3183 prop->favorite = EMAIL_FLAG_TASK_STATUS_COMPLETE;
3185 case EMAIL_FLAG_TASK_STATUS_COMPLETE:
3186 prop->favorite = EMAIL_FLAG_TASK_STATUS_CLEAR;
3189 debug_log("Never here");
3191 debug_log("After prop->favorite: %d", prop->favorite);
3193 err = email_set_flags_field(ug_data->account_id, &ug_data->mail_id, 1, EMAIL_FLAGS_FLAGGED_FIELD, prop->favorite, 1);
3194 if (err != EMAIL_ERROR_NONE) {
3195 _create_notify(ug_data, _("IDS_EMAIL_POP_ALERT"),
3196 N_("Failed to set favourite"), 0,
3197 NULL, NULL, NULL, NULL, _popup_response_cb);
3201 evas_object_del(elm_object_part_content_unset(ug_data->ly_subject, "elm.icon.favorite"));
3202 Evas_Object *favorite_icon = elm_icon_add(ug_data->ly_subject);
3203 switch(prop->favorite)
3205 case EMAIL_FLAG_NONE:
3206 elm_image_file_set(favorite_icon, IMGDIR "/M02_icon_favorite_off_74x74.png", NULL);
3208 case EMAIL_FLAG_FLAGED:
3209 elm_image_file_set(favorite_icon, IMGDIR "/M02_icon_favorite_on_74x74.png", NULL);
3211 case EMAIL_FLAG_TASK_STATUS_CLEAR:
3212 elm_image_file_set(favorite_icon, IMGDIR "/M02_email_Flag_Clear.png", NULL);
3214 case EMAIL_FLAG_TASK_STATUS_ACTIVE:
3215 elm_image_file_set(favorite_icon, IMGDIR "/M02_email_Flag_Active.png", NULL);
3217 case EMAIL_FLAG_TASK_STATUS_COMPLETE:
3218 elm_image_file_set(favorite_icon, IMGDIR "/M02_email_Flag_Complete.png", NULL);
3221 debug_log("Never here");
3223 evas_object_size_hint_aspect_set(favorite_icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
3224 elm_image_resizable_set(favorite_icon, 1, 1);
3225 elm_object_part_content_set(ug_data->ly_subject, "elm.icon.favorite", favorite_icon);
3226 evas_object_show(favorite_icon);
3229 static void _subject_detail_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
3233 debug_log("data is NULL");
3237 Evas_Object *item = (Evas_Object *)data;
3238 EmailViewerUGD *ug_data = _g_ug_data;
3240 if (!(ug_data->subject_onoff_flag)) {
3241 edje_object_signal_emit(_EDJ(item), "elm,state,expanded", "elm");
3242 (ug_data->subject_onoff_flag)++;
3244 _create_to_addrs(ug_data);
3245 _create_cc_addrs(ug_data);
3246 _create_bcc_addrs(ug_data);
3248 edje_object_signal_emit(_EDJ(item), "elm,state,contracted", "elm");
3249 (ug_data->subject_onoff_flag)--;
3251 if (ug_data->to_ly) {
3252 elm_box_unpack(ug_data->main_bx, ug_data->to_ly);
3253 evas_object_del(ug_data->to_ly);
3254 ug_data->to_ly = NULL;
3256 if (ug_data->cc_ly) {
3257 elm_box_unpack(ug_data->main_bx, ug_data->cc_ly);
3258 evas_object_del(ug_data->cc_ly);
3259 ug_data->cc_ly = NULL;
3261 if (ug_data->bcc_ly) {
3262 elm_box_unpack(ug_data->main_bx, ug_data->bcc_ly);
3263 evas_object_del(ug_data->bcc_ly);
3264 ug_data->bcc_ly = NULL;
3267 elm_object_focus_set(ug_data->ly_subject, EINA_TRUE);
3271 static void _attachment_item_collapse_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
3274 if (!data || !_g_ug_data) {
3275 debug_log("data is NULL");
3279 Evas_Object *item = (Evas_Object *)data;
3280 EmailViewerUGD *ug_data = _g_ug_data;
3281 EmailViewerProp *prop = ug_data->property;
3284 debug_log("attach_onoff_flag:%d", ug_data->attach_onoff_flag);
3285 if (!(ug_data->attach_onoff_flag)) {
3286 debug_log("attachments expanded");
3287 edje_object_signal_emit(_EDJ(item), "elm,state,expanded", "elm");
3288 (ug_data->attach_onoff_flag)++;
3290 if (ug_data->attach_ex_ly == NULL)
3291 _create_attach_ex(ug_data);
3293 for (i = 0; i < prop->real_att_len; i++) {
3294 debug_log("index %d", i);
3295 elm_box_pack_after(ug_data->main_bx, ug_data->attach_ex_ly[i], ug_data->attach_hd_ly);
3296 evas_object_show(ug_data->attach_ex_ly[i]);
3300 debug_log("attachments contracted");
3301 edje_object_signal_emit(_EDJ(item), "elm,state,contracted", "elm");
3302 ug_data->attach_onoff_flag = 0;
3304 for (i = 0; i < prop->real_att_len; i++) {
3305 if (ug_data->attach_ex_ly[i] != NULL) {
3306 debug_log("index %d", i);
3307 elm_box_unpack(ug_data->main_bx, ug_data->attach_ex_ly[i]);
3308 evas_object_hide(ug_data->attach_ex_ly[i]);
3314 static void _attachment_save_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
3319 debug_log("ug_data is NULL");
3323 EmailViewerUGD *ug_data = _g_ug_data;
3324 int att_index = (int)data;
3326 ug_data->display_download_result = FALSE;
3328 debug_log("Selected item index = %d", att_index);
3329 _show_attachment(ug_data, att_index);
3332 static void _attachment_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
3337 debug_log("ug_data is NULL");
3341 EmailViewerUGD *ug_data = _g_ug_data;
3342 int att_index = (int)data;
3344 debug_log("Selected item index = %d", att_index);
3345 ug_data->display_download_result = TRUE;
3346 _show_attachment(ug_data, att_index);
3349 static void _attachment_save_all_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
3353 debug_log("ug_data is NULL");
3357 EmailViewerUGD *ug_data = _g_ug_data;
3359 _save_attachment_all(ug_data);
3362 static void _attachment_bg_set_cb(void *data, Evas * evas, Evas_Object *obj, void *event_info)
3366 debug_log("ug_data is NULL");
3370 EmailViewerUGD *ug_data = _g_ug_data;
3371 EmailViewerProp *prop = ug_data->property;
3373 int att_index = (int)data;
3374 debug_log("att_index = %d, attachments count = %d", att_index, prop->real_att_len);
3376 if (prop->real_att_len > 1) {
3379 GList *attachment_list = prop->attachments;
3380 LIST_ITER_START(i, attachment_list) {
3381 EmailAttachmentType *info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, attachment_list);
3382 if (info && !info->inline_content) {
3388 edje_object_signal_emit(_EDJ(ug_data->attach_ex_ly[j]), "pressed", "elm.event.rect");
3391 edje_object_signal_emit(_EDJ(ug_data->attach_hd_ly), "pressed", "elm.event.rect");
3394 static void _attachment_bg_unset_cb(void *data, Evas * evas, Evas_Object *obj, void *event_info)
3398 debug_log("ug_data is NULL");
3402 EmailViewerUGD *ug_data = _g_ug_data;
3403 EmailViewerProp *prop = ug_data->property;
3405 int att_index = (int)data;
3406 debug_log("att_index = %d, attachments count = %d", att_index, prop->real_att_len);
3408 if (prop->real_att_len > 1) {
3411 GList *attachment_list = prop->attachments;
3412 LIST_ITER_START(i, attachment_list) {
3413 EmailAttachmentType *info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, attachment_list);
3414 if (info && !info->inline_content) {
3420 edje_object_signal_emit(_EDJ(ug_data->attach_ex_ly[j]), "unpressed", "elm.event.rect");
3423 edje_object_signal_emit(_EDJ(ug_data->attach_hd_ly), "unpressed", "elm.event.rect");
3426 static void _mark_as_unread_cb(void *data, Evas_Object *obj, void *event_info)
3430 debug_log("data is NULL");
3434 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
3436 if (ug_data->con_popup) {
3437 evas_object_del(ug_data->con_popup);
3438 ug_data->con_popup = NULL;
3442 debug_log("ug_data->mail_id(%d), priv->mail_id(%d), mail_info->mail_id(%d), prop->mail_id(%d)", ug_data->mail_id, ug_data->email_data->mail_id, ug_data->email_data->mail_info->mail_id, ug_data->property->mail_id);
3444 err = email_set_flags_field(ug_data->account_id, &ug_data->mail_id, 1, EMAIL_FLAGS_SEEN_FIELD, 0, 1);
3445 debug_log("email_set_flags_field - err(%d)", err);
3447 if (err != EMAIL_ERROR_NONE) {
3448 _create_notify(ug_data, _("IDS_EMAIL_POP_ALERT"),
3449 _("IDS_EMAIL_POP_FAILED_TO_MARK_AS_UNREAD"), 0,
3450 NULL, NULL, NULL, NULL, _popup_response_cb);
3452 char str[128] = { 0, };
3453 snprintf(str, sizeof(str), "%s", _("IDS_EMAIL_POP_MARKED_AS_UNREAD"));
3454 int ret = status_message_post(str);
3456 debug_log("status_message_post failed: %d", ret);
3460 static void _mark_as_read_cb(void *data, Evas_Object *obj, void *event_info)
3464 debug_log("data is NULL");
3468 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
3470 if (ug_data->con_popup) {
3471 evas_object_del(ug_data->con_popup);
3472 ug_data->con_popup = NULL;
3476 debug_log("ug_data->mail_id(%d), priv->mail_id(%d), mail_info->mail_id(%d), prop->mail_id(%d)", ug_data->mail_id, ug_data->email_data->mail_id, ug_data->email_data->mail_info->mail_id, ug_data->property->mail_id);
3478 err = email_set_flags_field(ug_data->account_id, &ug_data->mail_id, 1, EMAIL_FLAGS_SEEN_FIELD, 1, 1);
3479 debug_log("email_set_flags_field - err(%d)", err);
3481 if (err != EMAIL_ERROR_NONE) {
3482 _create_notify(ug_data, _("IDS_EMAIL_POP_ALERT"),
3483 _("IDS_EMAIL_POP_FAILED_TO_MARK_AS_READ"), 0,
3484 NULL, NULL, NULL, NULL, _popup_response_cb);
3486 char str[128] = { 0, };
3487 snprintf(str, sizeof(str), "%s", _("IDS_EMAIL_POP_MARKED_AS_READ"));
3488 int ret = status_message_post(str);
3490 debug_log("status_message_post failed: %d", ret);
3494 static void _create_waiting_popup(EmailViewerUGD *ug_data, const char *title_text, const char *style)
3497 if (title_text == NULL) {
3498 debug_log("popup text is null");
3502 Evas_Object *popup = elm_popup_add(ug_data->win_main);
3503 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
3504 elm_object_part_text_set(popup, "title,text", title_text);
3506 Evas_Object *progress = elm_progressbar_add(popup);
3507 elm_object_style_set(progress, style);
3508 elm_progressbar_pulse_set(progress, EINA_TRUE);
3509 elm_progressbar_pulse(progress, EINA_TRUE);
3510 evas_object_show(progress);
3512 elm_object_content_set(popup, progress);
3514 Evas_Object *btn1 = elm_button_add(popup);
3515 elm_object_style_set(btn1, "popup_button/default");
3516 elm_object_text_set(btn1, dgettext("sys_string", "IDS_COM_SK_CANCEL"));
3517 elm_object_part_content_set(popup, "button1", btn1);
3518 evas_object_smart_callback_add(btn1, "clicked", _popup_waiting_response_cb, ug_data);
3520 ug_data->timeout_popup = popup;
3522 evas_object_show(popup);
3525 static void _save_email_cb(void *data, Evas_Object *obj, void *event_info)
3529 debug_log("data is NULL");
3533 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
3535 if (ug_data->con_popup) {
3536 evas_object_del(ug_data->con_popup);
3537 ug_data->con_popup = NULL;
3540 if (ug_data->timeout_popup) {
3541 evas_object_del(ug_data->timeout_popup);
3542 ug_data->timeout_popup = NULL;
3544 _create_waiting_popup(ug_data, dgettext("sys_string", "IDS_COM_POP_SAVING_ING"), "pending_list"); //"list_process"
3546 if (ug_data->waiting_timer) {
3547 ecore_timer_del(ug_data->waiting_timer);
3548 ug_data->waiting_timer = NULL;
3550 ug_data->waiting_timer = ecore_timer_add(0.2, _save_email_prog_cb, ug_data);
3553 static Eina_Bool _save_email_prog_cb(void *data)
3557 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
3560 debug_log("ug_data->mail_id(%d), priv->mail_id(%d), mail_info->mail_id(%d), prop->mail_id(%d)", ug_data->mail_id, ug_data->email_data->mail_id, ug_data->email_data->mail_info->mail_id, ug_data->property->mail_id);
3562 email_mail_data_t *mail_t = NULL;
3563 err = email_get_mail_data(ug_data->email_data->mail_id, &mail_t);
3564 debug_log("email_get_mail_data - err (%d)", err);
3566 if (mail_t == NULL) {
3567 debug_log("mail_t is NULL");
3571 email_attachment_data_t *attachment_t = NULL;
3572 int attachment_count = 0;
3573 err = email_get_attachment_data_list(ug_data->email_data->mail_id, &attachment_t, &attachment_count);
3574 debug_log("email_get_attachment_data_list - err (%d)", err);
3576 if (err == EMAIL_ERROR_NONE) {
3577 if (!email_check_dir_exist(DIR_DEFAULT_MEDIA_PHONE"/Saved Email")) {
3579 nErr = mkdir(DIR_DEFAULT_MEDIA_PHONE"/Saved Email", 0755);
3580 debug_log("errno: %d", nErr);
3582 debug_log("Eml file folder creation failed");
3586 debug_log("Eml file folder already exists.");
3588 char *subject = elm_entry_utf8_to_markup(ug_data->property->subject);
3589 if (!g_strcmp0(subject, "")) {
3591 subject = g_strdup(_("IDS_EMAIL_BODY_NO_SUBJECT"));
3594 tzset(); /* MUST BE. */
3596 time_t now_time = time(NULL);
3598 struct tm *dummy = localtime(&now_time);
3600 memcpy(&now_tm, dummy, sizeof(struct tm));
3602 char date[9] = { 0, };
3603 if (now_tm.tm_mon + 1 < 10 && now_tm.tm_mday < 10)
3604 snprintf(date, sizeof(date), "%d0%d0%d", now_tm.tm_year + 1900, now_tm.tm_mon + 1, now_tm.tm_mday);
3605 else if (now_tm.tm_mon + 1 < 10 && now_tm.tm_mday >= 10)
3606 snprintf(date, sizeof(date), "%d0%d%d", now_tm.tm_year + 1900, now_tm.tm_mon + 1, now_tm.tm_mday);
3607 else if (now_tm.tm_mon + 1 >= 10 && now_tm.tm_mday < 10)
3608 snprintf(date, sizeof(date), "%d%d0%d", now_tm.tm_year + 1900, now_tm.tm_mon + 1, now_tm.tm_mday);
3610 snprintf(date, sizeof(date), "%d%d%d", now_tm.tm_year + 1900, now_tm.tm_mon + 1, now_tm.tm_mday);
3611 debug_log("date(%s)", date);
3613 char file_name[MAX_PATH_LEN] = { 0, };
3614 snprintf(file_name, sizeof(file_name), "%s/%s_%d_%d_%s.%s", DIR_DEFAULT_MEDIA_PHONE"/Saved Email", subject, ug_data->account_id, ug_data->mail_id, date, "eml");
3615 char *output_file_path = g_strdup(file_name);
3616 debug_log("output_file_path(%s)", file_name, output_file_path);
3618 err = email_write_mime_file(mail_t, attachment_t, attachment_count, &output_file_path);
3619 debug_log("email_write_mime_file - err(%d)", err);
3621 g_free(output_file_path);
3625 if (ug_data->timeout_popup) {
3626 evas_object_del(ug_data->timeout_popup);
3627 ug_data->timeout_popup = NULL;
3630 if (err != EMAIL_ERROR_NONE) {
3631 _create_notify(ug_data, _("IDS_EMAIL_POP_ALERT"),
3632 dgettext("sys_string", "IDS_COM_POP_UNABLE_TO_SAVE"), 0,
3633 NULL, NULL, NULL, NULL, _popup_response_cb);
3635 char str[128] = { 0, };
3636 snprintf(str, sizeof(str), "%s", _("IDS_EMAIL_POP_SAVED_IN_MY_FILES"));
3637 int ret = status_message_post(str);
3639 debug_log("status_message_post failed: %d", ret);
3643 if (ug_data->timeout_popup) {
3644 evas_object_del(ug_data->timeout_popup);
3645 ug_data->timeout_popup = NULL;
3649 email_free_mail_data(&(mail_t), 1);
3654 email_free_attachment_data(&(attachment_t), attachment_count);
3655 attachment_t = NULL;
3656 attachment_count = 0;
3659 if (ug_data->waiting_timer) {
3660 ecore_timer_del(ug_data->waiting_timer);
3661 ug_data->waiting_timer = NULL;
3667 static void _ctxpopup_detail_contact_cb(void *data, Evas_Object *obj, void *event_info)
3669 debug_log("data(%s)", data);
3670 if (data == NULL || _g_ug_data == NULL) {
3671 debug_log("data is NULL");
3675 EmailViewerUGD *ug_data = _g_ug_data;
3677 if (ug_data->con_popup) {
3678 evas_object_del(ug_data->con_popup);
3679 ug_data->con_popup = NULL;
3682 char *index = (char *)data;
3683 char type[10] = { 0, };
3685 service_h service = NULL;
3687 ret = service_create(&service);
3688 debug_log("service_create: %d", ret);
3690 debug_log("service create failed");
3694 snprintf(type, sizeof(type), "%d", CT_UG_REQUEST_DETAIL);
3696 ret = service_add_extra_data(service, CT_UG_BUNDLE_TYPE, type);
3697 debug_log("service_add_extra_data: %d", ret);
3698 ret = service_add_extra_data(service, CT_UG_BUNDLE_ID, index);
3699 debug_log("service_add_extra_data: %d", ret);
3701 create_ug(UG_CONTACTS_DETAILS, service, ug_data);
3703 ret = service_destroy(service);
3704 debug_log("service_destroy: %d", ret);
3706 debug_log("set flag for contact ug");
3707 ug_data->b_contact_ug_launched = TRUE;
3710 static void _ctxpopup_send_email_cb(void *data, Evas_Object *obj, void *event_info)
3713 if (!data || !_g_ug_data) {
3714 debug_log("data is NULL");
3718 EmailViewerUGD *ug_data = _g_ug_data;
3720 if (ug_data->con_popup == NULL) {
3721 debug_log("con_popup is NULL");
3725 if (ug_data->con_popup) {
3726 evas_object_del(ug_data->con_popup);
3727 ug_data->con_popup = NULL;
3730 debug_log("email: %s", (char *)data);
3733 service_h service = NULL;
3735 ret = service_create(&service);
3736 debug_log("service_create: %d", ret);
3738 debug_log("service create failed");
3742 char rtype[10] = { 0, };
3743 snprintf(rtype, sizeof(rtype), "%d", RUN_COMPOSER_EXTERNAL);
3745 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_RUN_TYPE, rtype);
3746 debug_log("service_add_extra_data: %d", ret);
3747 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_TO, (char *)data);
3748 debug_log("service_add_extra_data: %d", ret);
3749 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_CC, NULL);
3750 debug_log("service_add_extra_data: %d", ret);
3751 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_BCC, NULL);
3752 debug_log("service_add_extra_data: %d", ret);
3753 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_SUBJECT, NULL);
3754 debug_log("service_add_extra_data: %d", ret);
3755 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_BODY, NULL);
3756 debug_log("service_add_extra_data: %d", ret);
3757 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_ATTACHMENT, NULL);
3758 debug_log("service_add_extra_data: %d", ret);
3760 ug_data->ug_composer = create_ug(UG_NAME_EMAIL_COMPOSER, service, ug_data);
3762 ret = service_destroy(service);
3763 debug_log("service_destroy: %d", ret);
3766 static void _ctxpopup_add_contact_cb(void *data, Evas_Object *obj, void *event_info)
3768 debug_log("data(%s)", data);
3769 if (!data || !_g_ug_data) {
3770 debug_log("data is NULL");
3774 char tmp[MAX_STR_LEN] = { 0, };
3775 EmailViewerUGD *ug_data = _g_ug_data;
3777 if (ug_data->con_popup == NULL) {
3778 debug_log("con_popup is NULL");
3782 if (ug_data->con_popup) {
3783 evas_object_del(ug_data->con_popup);
3784 ug_data->con_popup = NULL;
3788 service_h service = NULL;
3790 ret = service_create(&service);
3791 debug_log("service_create: %d", ret);
3793 debug_log("service create failed");
3797 if (ug_data->create_contact_arg == CONTACTUI_REQ_ADD_PHONE_NUMBER) {
3798 snprintf(tmp, sizeof(tmp), "%d", CT_UG_REQUEST_ADD_WITH_NUM);
3799 ret = service_add_extra_data(service, CT_UG_BUNDLE_TYPE, tmp);
3800 debug_log("service_add_extra_data: %d", ret);
3801 ret = service_add_extra_data(service, CT_UG_BUNDLE_NUM, (char *)data);
3802 debug_log("service_add_extra_data: %d", ret);
3804 if (ug_data->create_contact_arg == CONTACTUI_REQ_ADD_EMAIL) {
3805 snprintf(tmp, sizeof(tmp), "%d", CT_UG_REQUEST_ADD_WITH_EMAIL);
3806 ret = service_add_extra_data(service, CT_UG_BUNDLE_TYPE, tmp);
3807 debug_log("service_add_extra_data: %d", ret);
3808 ret = service_add_extra_data(service, CT_UG_BUNDLE_EMAIL, (char *)data);
3809 debug_log("service_add_extra_data: %d", ret);
3811 if (ug_data->create_contact_arg == CONTACTUI_REQ_ADD_URL) {
3812 snprintf(tmp, sizeof(tmp), "%d", CT_UG_REQUEST_ADD_WITH_WEB);
3813 ret = service_add_extra_data(service, CT_UG_BUNDLE_TYPE, tmp);
3814 debug_log("service_add_extra_data: %d", ret);
3815 ret = service_add_extra_data(service, CT_UG_BUNDLE_WEB, (char *)data);
3816 debug_log("service_add_extra_data: %d", ret);
3819 create_ug(UG_CONTACTS_DETAILS, service, ug_data);
3821 ret = service_destroy(service);
3822 debug_log("service_destroy: %d", ret);
3825 static void _delete_ctxpopup_cb(void *data, Evas_Object *obj, void *event_info)
3828 if (_g_ug_data == NULL) {
3829 debug_log("_g_ug_data == NULL");
3833 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
3835 if (ug_data->con_popup != NULL) {
3836 evas_object_del(ug_data->con_popup);
3837 ug_data->con_popup = NULL;
3840 Elm_Object_Item *item = NULL;
3841 item = elm_multibuttonentry_selected_item_get(ug_data->to_mbe);
3842 elm_multibuttonentry_item_selected_set(item, EINA_FALSE);
3843 item = elm_multibuttonentry_selected_item_get(ug_data->cc_mbe);
3844 elm_multibuttonentry_item_selected_set(item, EINA_FALSE);
3845 item = elm_multibuttonentry_selected_item_get(ug_data->bcc_mbe);
3846 elm_multibuttonentry_item_selected_set(item, EINA_FALSE);
3849 static void _popup_waiting_response_cb(void *data, Evas_Object *obj, void *event_info)
3853 debug_log("data is NULL");
3857 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
3859 if (ug_data->timeout_popup) {
3860 evas_object_del(ug_data->timeout_popup);
3861 ug_data->timeout_popup = NULL;
3865 static void _popup_response_cb(void *data, Evas_Object *obj, void *event_info)
3869 debug_log("_g_ug_data is NULL");
3874 debug_log("data is NULL");
3878 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
3880 if (ug_data->notify) {
3881 evas_object_del(ug_data->notify);
3882 ug_data->notify = NULL;
3886 static void _popup_response_delete_ok_cb(void *data, Evas_Object *obj, void *event_info)
3890 debug_log("_g_ug_data is NULL");
3895 debug_log("data is NULL");
3899 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
3902 if (ug_data->notify) {
3903 evas_object_del(ug_data->notify);
3904 ug_data->notify = NULL;
3907 if (ug_data->mailbox_type == EMAIL_MAILBOX_TYPE_TRASH)
3908 ret = _delete_email(ug_data);
3910 ret = _move_email(ug_data, _find_folder_id_using_folder_type(ug_data, EMAIL_MAILBOX_TYPE_TRASH), TRUE);
3913 if (ug_data->isRotate == false && ug_data->b_internal) {
3914 _notify_mailbox_size(ug_data, "MAILBOX_RESIZE_FULL");
3918 if (ug_data->b_internal) {
3919 _hide_view(ug_data);
3921 /* send next or previous mail request to mailbox. */
3922 service_h service = NULL;
3924 ret = service_create(&service);
3925 debug_log("service_create: %d", ret);
3927 debug_log("service create failed");
3931 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_MSG, EMAIL_BUNDLE_VAL_NEXT_MSG);
3932 debug_log("service_add_extra_data: %d", ret);
3933 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_DO_DELETE, "1");
3934 debug_log("service_add_extra_data: %d", ret);
3936 ug_send_message(_g_mailbox_ug, service);
3938 ret = service_destroy(service);
3939 debug_log("service_destroy: %d", ret);
3941 ug_destroy_me(ug_data->ug);
3945 static void _popup_response_move_to_trash_cb(void *data, Evas_Object *obj, void *event_info)
3949 debug_log("_g_ug_data is NULL");
3954 debug_log("data is NULL");
3958 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
3961 if (ug_data->notify) {
3962 evas_object_del(ug_data->notify);
3963 ug_data->notify = NULL;
3966 ret = _move_email(ug_data, _find_folder_id_using_folder_type(ug_data, EMAIL_MAILBOX_TYPE_TRASH), TRUE);
3969 if (ug_data->isRotate == false && ug_data->b_internal) {
3970 _notify_mailbox_size(ug_data, "MAILBOX_RESIZE_FULL");
3974 if (ug_data->b_internal) {
3975 _hide_view(ug_data);
3977 /* send next or previous mail request to mailbox. */
3979 service_h service = NULL;
3981 ret = service_create(&service);
3982 debug_log("service_create: %d", ret);
3984 debug_log("service create failed");
3988 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_MSG, EMAIL_BUNDLE_VAL_NEXT_MSG);
3989 debug_log("service_add_extra_data: %d", ret);
3990 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_DO_DELETE, "1");
3991 debug_log("service_add_extra_data: %d", ret);
3993 ug_send_message(_g_mailbox_ug, service);
3995 ret = service_destroy(service);
3996 debug_log("service_destroy: %d", ret);
3998 ug_destroy_me(ug_data->ug);
4002 static void _popup_response_delete_permanent_cb(void *data, Evas_Object *obj, void *event_info)
4006 debug_log("_g_ug_data is NULL");
4011 debug_log("data is NULL");
4015 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
4018 if (ug_data->notify) {
4019 evas_object_del(ug_data->notify);
4020 ug_data->notify = NULL;
4023 ret = _delete_email(ug_data);
4026 if (ug_data->isRotate == false && ug_data->b_internal) {
4027 _notify_mailbox_size(ug_data, "MAILBOX_RESIZE_FULL");
4031 if (ug_data->b_internal) {
4032 _hide_view(ug_data);
4034 /* send next or previous mail request to mailbox. */
4035 service_h service = NULL;
4037 ret = service_create(&service);
4038 debug_log("service_create: %d", ret);
4040 debug_log("service create failed");
4044 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_MSG, EMAIL_BUNDLE_VAL_NEXT_MSG);
4045 debug_log("service_add_extra_data: %d", ret);
4046 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_DO_DELETE, "1");
4047 debug_log("service_add_extra_data: %d", ret);
4049 ug_send_message(_g_mailbox_ug, service);
4051 ret = service_destroy(service);
4052 debug_log("service_destroy: %d", ret);
4054 ug_destroy_me(ug_data->ug);
4058 static void _popup_response_to_destroy_cb(void *data, Evas_Object *obj, void *event_info)
4062 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
4063 evas_object_del(obj);
4065 ug_data->b_direct_destroy = 1;
4066 ug_destroy_me(ug_data->ug);
4070 static void _webview_policy_navigation_decide_cb(void *data, Evas_Object *obj, void *event_info)
4074 debug_log("_g_ug_data is NULL");
4078 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
4079 Ewk_Policy_Decision *policy_decision = (Ewk_Policy_Decision *)event_info;
4080 Ewk_Policy_Navigation_Type pd_type = ewk_policy_decision_navigation_type_get(policy_decision);
4081 debug_log("Ewk_Policy_Navigation_Type:%d", pd_type);
4083 const char *uri = NULL;
4084 uri = ewk_view_url_get(ug_data->webview);
4085 debug_log("ewk_view_url_get(%s)", uri);
4087 if (ug_data->b_load_finished == EINA_TRUE) {
4088 if (ug_data->is_long_pressed == EINA_TRUE) {
4089 debug_log("Long pressed!!!");
4090 ug_data->is_long_pressed = EINA_FALSE;
4091 ewk_policy_decision_ignore(policy_decision);
4095 ewk_policy_decision_ignore(policy_decision);
4097 debug_log("url:%s", ewk_policy_decision_url_get(policy_decision));
4098 debug_log("scheme:%s", ewk_policy_decision_scheme_get(policy_decision));
4099 debug_log("cookie:%s", ewk_policy_decision_cookie_get(policy_decision));
4100 debug_log("host:%s", ewk_policy_decision_host_get(policy_decision));
4101 debug_log("response_mime:%s", ewk_policy_decision_response_mime_get(policy_decision));
4103 char *url = (char *)ewk_policy_decision_url_get(policy_decision);
4105 if ((strncmp(url, "http://", 7) == 0) ||
4106 (strncmp(url, "https://", 8) == 0) ||
4107 (strncmp(url, "ftp://", 6) == 0) ||
4108 (strncmp(url, "mms://", 6) == 0) ||
4109 (strncmp(url, "file://", 7) == 0) ||
4110 (strncmp(url, "rtsp://", 7) == 0) ||
4111 (strncmp(url, "wap://", 6) == 0)) {
4113 service_h service = NULL;
4114 ret = service_create(&service);
4115 debug_log("service_create: %d", ret);
4117 debug_log("service create failed");
4120 ret = service_set_operation(service, SERVICE_OPERATION_VIEW);
4121 debug_log("service_set_operation: %d", ret);
4122 ret = service_set_uri(service, url);
4123 debug_log("service_set_uri: %d", ret);
4124 ret = service_send_launch_request(service, NULL, NULL);
4125 debug_log("service_send_launch_request: %d", ret);
4126 ret = service_destroy(service);
4127 debug_log("service_destroy: %d", ret);
4130 if (strncmp(url, "tel:", 4) == 0) {
4131 char refined_num[MAX_STR_LEN] = { 0, };
4134 while (url[i] != '\0') {
4135 if (url[i] >= '0' && url[i] <= '9')
4136 refined_num[j++] = url[i];
4140 char *number = refined_num;
4141 debug_log("number: %s", number);
4144 service_h service = NULL;
4145 char telnum[255] = { 0, };
4146 ret = service_create(&service);
4147 debug_log("service_create: %d", ret);
4149 debug_log("service create failed");
4152 ret = service_set_operation(service, SERVICE_OPERATION_CALL);
4153 debug_log("service_set_operation: %d", ret);
4154 snprintf(telnum, sizeof(telnum), "tel:%s", number); /* Number to make a call */
4155 ret = service_set_uri(service, telnum);
4156 debug_log("service_set_uri: %d", ret);
4157 ret = service_add_extra_data(service, "ctindex", "-1"); /* If you don't know ctindex, you don't have to add it. */
4158 debug_log("service_add_extra_data: %d", ret);
4159 ret = service_send_launch_request(service, NULL, NULL);
4160 debug_log("service_send_launch_request: %d", ret);
4161 ret = service_destroy(service);
4162 debug_log("service_destroy: %d", ret);
4165 if (strncmp(url, "mailto:", 7) == 0) {
4167 service_h service = NULL;
4168 ret = service_create(&service);
4169 debug_log("service_create: %d", ret);
4171 debug_log("service create failed");
4175 char rtype[10] = { 0, };
4176 snprintf(rtype, sizeof(rtype), "%d", RUN_COMPOSER_EXTERNAL);
4178 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_RUN_TYPE, rtype);
4179 debug_log("service_add_extra_data: %d", ret);
4180 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_TO, &url[7]);
4181 debug_log("service_add_extra_data: %d", ret);
4183 ug_data->ug_composer = create_ug(UG_NAME_EMAIL_COMPOSER, service, ug_data);
4185 ret = service_destroy(service);
4186 debug_log("service_destroy: %d", ret);
4189 debug_log("Loading...");
4190 if (ug_data->timeout_popup) {
4191 evas_object_del(ug_data->timeout_popup);
4192 ug_data->timeout_popup = NULL;
4194 _create_waiting_popup(ug_data, _("IDS_EMAIL_POP_LOADING_CONTENTS_ING"), "list_process");
4196 if (pd_type == EWK_POLICY_NAVIGATION_TYPE_LINK_CLICKED) {
4197 debug_log("Link click is ignored.");
4198 ewk_policy_decision_ignore(policy_decision);
4204 /* Double_Scroller */
4205 static void _outter_scroller_bottom_hit_cb(void *data, Evas_Object *obj, void *event_info)
4209 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
4210 int res = email_engine_check_body_download(ug_data->email_data->mail_id);
4212 if (ug_data->is_main_scroller_scrolling && res != 0) {
4213 debug_log("Main scroller hold push");
4214 elm_object_scroll_freeze_push(ug_data->scroller); //stop
4215 ewk_view_vertical_panning_hold_set(ug_data->webview, EINA_FALSE); //restart
4216 ug_data->is_main_scroller_scrolling = EINA_FALSE;
4217 ug_data->is_webview_scrolling = EINA_TRUE;
4221 static void _outter_scroller_top_hit_cb(void *data, Evas_Object *obj, void *event_info)
4226 static void _outter_scroller_scroll_cb(void *data, Evas_Object *obj, void *event_info)
4229 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
4231 ug_data->is_main_scroller_scrolling = EINA_TRUE;
4234 static void _mbe_focused_cb(void *data, Evas_Object *obj, void *event_info)
4239 static void _mbe_unfocused_cb(void *data, Evas_Object *obj, void *event_info)
4244 static void _mbe_added_cb(void *data, Evas_Object *obj, void *event_info)
4249 static void _mbe_selected_cb(void *data, Evas_Object *obj, void *event_info)
4252 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
4253 email_address_info_t *addrs_info = NULL;
4254 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
4255 debug_log("selected item:%s", elm_object_item_text_get(item));
4257 addrs_info = elm_object_item_data_get(item);
4260 EMAIL_CONTACT_LIST_INFO_S *contact_list_item = NULL;
4261 contact_list_item = (EMAIL_CONTACT_LIST_INFO_S *)_contact_search_by_email(ug_data, addrs_info->address);
4262 Evas_Object* icon = NULL;
4264 if (ug_data->con_popup != NULL) {
4265 evas_object_del(ug_data->con_popup);
4266 ug_data->con_popup = NULL;
4269 ug_data->con_popup = elm_ctxpopup_add(ug_data->navi_bar);
4270 if (ug_data->con_popup == NULL) {
4271 debug_log("cannot create context popup");
4274 evas_object_smart_callback_add(ug_data->con_popup, "dismissed", _delete_ctxpopup_cb, ug_data);
4276 if (contact_list_item) {
4277 debug_log("Contact Item Exist: index[%d]", contact_list_item->index);
4278 char index[10] = { 0, };
4279 snprintf(index, sizeof(index), "%d", contact_list_item->index);
4281 icon = elm_icon_add(ug_data->con_popup);
4282 elm_image_file_set(icon, IMGDIR "/M02_popup_icon_view contact.png", NULL);
4283 elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_VIEW_CONTACT"), icon, _ctxpopup_detail_contact_cb, g_strdup(index));
4285 _delete_contacts_list(contact_list_item);
4287 ug_data->create_contact_arg = CONTACTUI_REQ_ADD_EMAIL;
4288 icon = elm_icon_add(ug_data->con_popup);
4289 elm_image_file_set(icon, IMGDIR "/M02_popup_icon_add_to_contacts.png", NULL);
4290 elm_ctxpopup_item_append(ug_data->con_popup, dgettext("sys_string", "IDS_COM_OPT_ADD_TO_CONTACTS"), icon, _ctxpopup_add_contact_cb, addrs_info->address);
4294 icon = elm_icon_add(ug_data->con_popup);
4295 elm_image_file_set(icon, IMGDIR "/M02_popup_icon_send email.png", NULL);
4296 elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_SEND_EMAIL"), icon, _ctxpopup_send_email_cb, addrs_info->address);
4299 evas_pointer_canvas_xy_get(ug_data->evas, &x, &y);
4300 debug_log("canvas x:%d, y:%d", x, y);
4301 evas_object_move(ug_data->con_popup, x, y);
4302 evas_object_show(ug_data->con_popup);
4305 static void _destroy_down_progress_cb(void *data, Evas_Object *obj, void *event_info)
4310 debug_log("data is NULL");
4314 EmailViewerUGD *ug_data = _g_ug_data;
4315 EmailViewerPrivate *priv = ug_data->email_data;
4317 email_engine_stop_working(ug_data->account_id, priv->email_handle);
4319 if (ug_data->pb_notify) {
4320 evas_object_del(ug_data->pb_notify);
4321 ug_data->pb_notify = NULL;
4324 if (ug_data->pb_notify_lb) {
4325 evas_object_del(ug_data->pb_notify_lb);
4326 ug_data->pb_notify_lb = NULL;
4330 if (priv->att_file_id) {
4331 free(priv->att_file_id);
4332 priv->att_file_id = NULL;
4335 priv->file_size = 0;
4336 priv->attachment_id = -1;
4337 priv->multi_body = FALSE;
4341 static int _viewer_create_temp_folder()
4345 if (!email_check_dir_exist(EMAIL_VIEWER_TMP_FOLDER)) {
4347 nErr = mkdir(EMAIL_VIEWER_TMP_FOLDER, 0755);
4348 debug_log("errno: %d", nErr);
4350 debug_log("Email viewer temp folder creation failed");
4354 debug_log("Email viewer temp folder already exists.");
4358 static void _viewer_remove_temp_folder()
4362 struct dirent *dir_entry = NULL;
4366 dir = opendir(EMAIL_VIEWER_TMP_FOLDER);
4368 debug_log("Unable to open %s", EMAIL_VIEWER_TMP_FOLDER);
4371 while ((dir_entry = readdir(dir))) {
4372 debug_log("%s", dir_entry->d_name);
4373 if (g_strcmp0(".", dir_entry->d_name) == 0 || g_strcmp0("..", dir_entry->d_name) == 0)
4375 snprintf(buffer, 256, "%s/%s", EMAIL_VIEWER_TMP_FOLDER, dir_entry->d_name);
4376 if (-1 == remove(buffer)) {
4377 debug_log("Failed to remove buffer");
4381 rmdir(EMAIL_VIEWER_TMP_FOLDER);
4384 static void _init_viewer_data(int account_id, int mail_id, char *srv_mail_id, EmailViewerUGD *ug_data)
4387 EmailViewerPrivate *priv = NULL;
4388 EmailViewerProp *prop = NULL;
4389 email_address_info_list_t *addrs_info_list = NULL;
4391 /* Create Email Viewer Private Structure */
4392 if (ug_data->email_data) {
4393 if (ug_data->email_data->mail_info) {
4394 debug_log("mail_info freed");
4395 email_free_mail_data(&(ug_data->email_data->mail_info), 1);
4396 ug_data->email_data->mail_info = NULL;
4399 if (ug_data->email_data->attachment_info && ug_data->email_data->attachment_count > 0) {
4400 debug_log("attachment_info freed p[%p] n[%d]", ug_data->email_data->attachment_info, ug_data->email_data->attachment_count);
4401 email_free_attachment_data(&(ug_data->email_data->attachment_info), ug_data->email_data->attachment_count);
4402 ug_data->email_data->attachment_info = NULL;
4403 ug_data->email_data->attachment_count = 0;
4406 memset(ug_data->email_data, 0x0, sizeof(EmailViewerPrivate));
4407 priv = ug_data->email_data;
4409 priv = (EmailViewerPrivate *)malloc(sizeof(EmailViewerPrivate));
4410 memset(priv, 0x0, sizeof(EmailViewerPrivate));
4411 ug_data->email_data = priv;
4414 /* Create Email Viewer Property Structure */
4415 if (ug_data->property) {
4416 if (ug_data->property->attachments) {
4418 LIST_ITER_START(i, ug_data->property->attachments) {
4419 EmailAttachmentType *info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, ug_data->property->attachments);
4426 g_list_free(ug_data->property->attachments);
4428 memset(ug_data->property, 0x0, sizeof(EmailViewerProp));
4429 prop = ug_data->property;
4431 prop = (EmailViewerProp *)malloc(sizeof(EmailViewerProp));
4432 memset(prop, 0x0, sizeof(EmailViewerProp));
4433 ug_data->property = prop;
4436 /* Set account ID */
4437 priv->account_id = account_id;
4438 prop->account_id = account_id;
4441 priv->mail_id = mail_id;
4442 prop->mail_id = mail_id;
4444 priv->mailbox_id = ug_data->mailbox_id;
4445 prop->src_box = ug_data->mailbox_name;
4446 debug_log("mailbox_name [%s]", ug_data->mailbox_name);
4448 /* Get mail_info from service, and fill property */
4449 if (viewer_get_internal_mail_info(ug_data->property, ug_data->email_data)) {
4450 viewer_make_internal_mail(ug_data->property, ug_data->email_data);
4453 email_get_address_info_list(priv->mail_id, &addrs_info_list);
4455 if (addrs_info_list) {
4456 ug_data->from_list = addrs_info_list->from;
4457 ug_data->to_list = addrs_info_list->to;
4458 ug_data->cc_list = addrs_info_list->cc;
4459 ug_data->bcc_list = addrs_info_list->bcc;
4460 priv->addrs_info_list = addrs_info_list;
4463 ug_data->option_header_opened = 0;
4465 if (_viewer_create_temp_folder() < 0)
4466 debug_log("creating email viewer temp folder is failed");
4469 static int _init_webview_data(EmailViewerUGD *ug_data)
4473 EmailViewerWebview *wvd;
4475 if (ug_data->webview_data == NULL) {
4476 wvd = (EmailViewerWebview *)malloc(sizeof(EmailViewerWebview));
4477 memset(wvd, 0x0, sizeof(EmailViewerWebview));
4478 ug_data->webview_data = wvd;
4481 if (STR_VALID(ug_data->property->charset)) {
4482 ug_data->webview_data->charset = g_strdup(ug_data->property->charset);
4483 debug_log("charset:%s", ug_data->webview_data->charset);
4485 ug_data->webview_data->charset = DEFAULT_CHARSET;
4486 debug_log("charset:%s", ug_data->webview_data->charset);
4492 static Eina_Bool _check_body_download(void *data)
4496 debug_log("data is NULL");
4497 return ECORE_CALLBACK_CANCEL;
4500 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
4502 /* check mail body downloaded */
4503 int body_download_status = ug_data->property->body_download;
4505 if (body_download_status == 0) { //EMAIL_BODY_DOWNLOAD_STATUS_NONE
4506 debug_log("need body download");
4507 ug_data->b_noc = 1; /* Double_Scroller */
4509 if (ug_data->noc_bx) {
4510 debug_log("no content layout exist");
4511 evas_object_show(ug_data->noc_bx);
4512 elm_object_text_set(ug_data->dn_btn, _("IDS_EMAIL_BODY_DOWNLOAD_MESSAGE"));
4513 evas_object_show(ug_data->dn_btn);
4514 elm_box_pack_end(ug_data->main_bx, ug_data->noc_bx);
4516 /* add body download button */
4517 ug_data->noc_bx = _load_edj(ug_data->navi_bar, EV_THEME_PATH, "layout.email.no_content");
4518 if (ug_data->noc_bx == NULL) {
4519 debug_log("Cannot load edj");
4520 return ECORE_CALLBACK_CANCEL;
4523 evas_object_size_hint_align_set(ug_data->noc_bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
4524 evas_object_size_hint_weight_set(ug_data->noc_bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
4525 evas_object_show(ug_data->noc_bx);
4526 elm_box_pack_end(ug_data->main_bx, ug_data->noc_bx);
4528 Evas_Object *dn_btn = elm_button_add(ug_data->navi_bar);
4529 elm_object_style_set(dn_btn, "text_only/style2");
4530 elm_object_text_set(dn_btn, _("IDS_EMAIL_BODY_DOWNLOAD_MESSAGE"));
4531 evas_object_smart_callback_add(dn_btn, "clicked", _body_down_cb, (void *)ug_data);
4532 evas_object_show(dn_btn);
4533 ug_data->dn_btn = dn_btn;
4535 elm_object_part_content_set(ug_data->noc_bx, "btn", ug_data->dn_btn);
4536 debug_log("no content layout created");
4539 elm_object_focus_set(ug_data->noc_bx, EINA_TRUE);
4540 if (ug_data->timer) {
4541 ecore_timer_del(ug_data->timer);
4542 ug_data->timer = NULL;
4545 ug_data->timer = ecore_timer_add(0.0, viewer_send_message, ug_data);
4546 } else if (body_download_status == 1) { //EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED
4547 debug_log("check mail downloaded - ok");
4549 _create_body(ug_data);
4550 } else if (body_download_status == 2) { //EMAIL_BODY_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED
4552 debug_log("Partial Body");
4553 ug_data->b_partial_body = 1;
4554 _create_body(ug_data);
4555 _create_partial_body_dn_btn(ug_data);
4558 return ECORE_CALLBACK_CANCEL;
4561 static int _update_attachment_info(EmailViewerUGD *ug_data, int index)
4564 EmailViewerProp *prop = ug_data->property;
4567 int attach_index = 0;
4569 /* update attachment information */
4570 LIST_ITER_START(i, prop->attachments) {
4571 EmailAttachmentType *info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, prop->attachments);
4573 if (info && !info->inline_content) {
4574 debug_log("info->index[%d] index[%d]", info->index, index);
4576 if (info->index == index) {
4577 info->download_yn = TRUE;
4578 info->path = email_engine_get_attachment_path(info->attach_id);
4582 if (prop->real_att_len > 1) {
4583 Evas_Object *thumbnail = viewer_make_thumbnail(info->path, ug_data->attach_ex_bk[j]);
4584 Evas_Object *content = elm_object_part_content_unset(ug_data->attach_ex_bk[j], "elm.icon");
4585 evas_object_del(content);
4586 elm_object_part_content_set(ug_data->attach_ex_bk[j], "elm.icon", thumbnail);
4587 evas_object_show(thumbnail);
4589 Evas_Object *thumbnail = viewer_make_thumbnail(info->path, ug_data->attach_hd_bk);
4590 Evas_Object *content = elm_object_part_content_unset(ug_data->attach_hd_bk, "elm.icon");
4591 evas_object_del(content);
4592 elm_object_part_content_set(ug_data->attach_hd_bk, "elm.icon", thumbnail);
4593 evas_object_show(thumbnail);
4603 debug_log("return id[%d]", attach_index);
4605 return attach_index;
4608 static int _get_attachment_info_index(EmailViewerUGD *ug_data, int index)
4612 EmailViewerProp *prop = ug_data->property;
4614 int attach_index = 0;
4616 /* update attachment information */
4617 LIST_ITER_START(i, prop->attachments) {
4618 EmailAttachmentType *info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, prop->attachments);
4620 debug_log("info->index[%d] index[%d]", info->index, index);
4621 if (info->index == index) {
4628 debug_log("return id[%d]", attach_index);
4630 return attach_index;
4633 static void _save_attachment(EmailViewerUGD *ug_data, int index)
4636 EmailViewerPrivate *priv = ug_data->email_data;
4637 EmailViewerProp *prop = ug_data->property;
4638 char newpath[MAX_PATH_LEN] = { 0, };
4640 RETURN_IF_FAIL(prop->attachments != NULL);
4641 EmailAttachmentType *info = g_list_nth_data(prop->attachments, index);
4644 debug_log("EmailAttachmentType *info is NULL");
4648 if (!info->download_yn) {
4650 gboolean res = FALSE;
4652 if (ug_data->progress_bar[index + 1] != NULL) {
4653 debug_log("Already getting downloaded...!");
4654 _create_notify(ug_data, dgettext("sys_string", "IDS_COM_POP_WARNING"),
4655 _("IDS_EMAIL_POP_ALREADY_DOWNLOADING_T_HEADER"), 1,
4656 dgettext("sys_string", "IDS_COM_SK_OK"),
4657 _popup_response_cb, NULL, NULL, NULL);
4661 debug_log("Need attachment download");
4662 /* download attachment */
4663 priv->b_att_save = TRUE;
4665 res = email_engine_attachment_download(priv->account_id, priv->mail_id, info->index, &handle);
4668 priv->download_all_cnt++;
4669 debug_log("Assigning Handle[%d] Index[%d] download_all_cnt[%d]", handle, index, priv->download_all_cnt);
4670 priv->download_all_email_handle[index] = handle;
4671 _create_down_progress_ex(index, EMAIL_VIEWER_PROGRESSBAR_ATT);
4672 ug_data->display_download_result = TRUE;
4674 priv->b_att_save = FALSE;
4675 _create_notify(ug_data, dgettext("sys_string", "IDS_COM_POP_WARNING"),
4676 _("IDS_EMAIL_POP_UNABLE_TO_OPEN_ATTACHMENT"), 1,
4677 dgettext("sys_string", "IDS_COM_SK_OK"), _popup_response_cb,
4684 if (info && STR_VALID(info->path)) {
4686 debug_log("path[%s]", info->path);
4687 ret = email_attachments_save_file(info->path, newpath, NULL);
4688 if (ret == EMAIL_EXT_SAVE_ERR_NONE) {
4689 char str[128] = { 0, };
4690 snprintf(str, sizeof(str), "%s", dgettext("sys_string", "IDS_COM_POP_SAVED"));
4691 ret = status_message_post(str);
4693 debug_log("status_message_post failed: %d", ret);
4698 static void _show_attachment(EmailViewerUGD *ug_data, int index)
4701 EmailViewerPrivate *priv = ug_data->email_data;
4702 EmailViewerProp *prop = ug_data->property;
4703 EmailAttachmentType *info = g_list_nth_data(prop->attachments, index);
4704 char newpath[MAX_PATH_LEN] = { 0, };
4707 debug_log("EmailAttachmentType *info is NULL");
4711 debug_log("attach_id:%d, index:%d, name(%s), path(%s), size:%d, download_yn:%d, drm:%d, inline_content:%d",
4712 info->attach_id, info->index, info->name, info->path, (gint) info->size, info->download_yn, info->drm, info->inline_content);
4714 if (!info->download_yn) {
4716 gboolean res = FALSE;
4717 debug_log("Need attachment download");
4719 priv->b_att_open = TRUE;
4721 res = email_engine_attachment_download(priv->account_id, priv->mail_id, info->index, &handle);
4724 priv->download_all_email_handle[index] = handle;
4725 priv->download_all_cnt++;
4726 _create_down_progress_ex(index, EMAIL_VIEWER_PROGRESSBAR_ATT);
4728 priv->b_att_open = FALSE;
4729 _create_notify(ug_data, dgettext("sys_string", "IDS_COM_POP_WARNING"),
4730 _("IDS_EMAIL_POP_UNABLE_TO_OPEN_ATTACHMENT"), 1,
4731 dgettext("sys_string", "IDS_COM_SK_OK"), _popup_response_cb,
4737 gboolean res = FALSE;
4738 res = email_attachments_save_file(info->path, newpath, NULL);
4739 debug_log("Result:%d, Saved Path:%s", res, newpath);
4741 if (res == EMAIL_EXT_SAVE_ERR_NONE) {
4742 char str[128] = { 0, };
4743 snprintf(str, sizeof(str), "%s", dgettext("sys_string", "IDS_COM_POP_SAVED"));
4744 int ret = status_message_post(str);
4746 debug_log("status_message_post failed: %d", ret);
4748 if (g_str_has_suffix(info->path, ".vcs")) {
4749 ret = calendar_connect();
4750 if (ret != CALENDAR_ERROR_NONE) {
4751 debug_error("calendar_connect is failed.");
4756 fp = fopen(newpath, "r");
4758 debug_error("fopen(%s) is failed.", newpath);
4759 calendar_disconnect();
4764 if (stat(newpath, &st) == -1) {
4765 debug_error("file(%s), stat Error(%d): %s", newpath, errno, strerror(errno));
4767 calendar_disconnect();
4771 int size = st.st_size;
4772 char *raw_data = calloc(size + 1, sizeof(char));
4774 debug_error("calloc is failed.");
4776 calendar_disconnect();
4781 if ((n = fread(raw_data, 1, size, fp)) != size) {
4782 debug_error("error in fread");
4785 calendar_disconnect();
4791 calendar_list_h list = NULL;
4793 ret = calendar_vcalendar_parse_to_calendar(raw_data, &list);
4795 if( list && ret == CALENDAR_ERROR_NONE) {
4796 calendar_db_insert_records(list, NULL, NULL);
4797 debug_log("vcalendar is registered to calendar");
4801 calendar_list_destroy(list, true);
4802 calendar_disconnect();
4804 media_file_register(newpath);
4805 } else if (res == EMAIL_EXT_SAVE_ERR_ALREADY_EXIST && !ug_data->display_download_result) {
4806 _create_notify(ug_data, _("IDS_EMAIL_POP_ALERT"),
4807 dgettext("sys_string", "IDS_COM_POP_ALREDY_EXISTS"), 0,
4808 NULL, NULL, NULL, NULL, _popup_response_cb);
4811 debug_log("display_download_result:%d", ug_data->display_download_result);
4812 if (ug_data->display_download_result) {
4813 if (res == EMAIL_EXT_SAVE_ERR_NONE || res == EMAIL_EXT_SAVE_ERR_ALREADY_EXIST) {
4815 service_h service = NULL;
4816 ret = service_create(&service);
4817 debug_log("service_create: %d", ret);
4819 debug_log("service create failed");
4822 ret = service_set_operation(service, SERVICE_OPERATION_VIEW);
4823 debug_log("service_set_operation: %d", ret);
4824 ret = service_set_uri(service, newpath);
4825 debug_log("service_set_uri: %d", ret);
4826 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_VIDEO_PLAYER_LAUNCH_APP, "email");
4827 debug_log("service_add_extra_data: %d", ret);
4828 ret = service_send_launch_request(service, NULL, NULL);
4829 debug_log("service_send_launch_request: %d", ret);
4830 if (ret != SERVICE_ERROR_NONE) {
4831 _create_notify(ug_data, dgettext("sys_string", "IDS_COM_POP_WARNING"),
4832 _("IDS_EMAIL_POP_THIS_ATTACHMENT_CANNOT_BE_DISPLAYED"), 0,
4833 NULL, NULL, NULL, NULL, _popup_response_cb);
4835 ret = service_destroy(service);
4836 debug_log("service_destroy: %d", ret);
4838 debug_log("EMAIL_EXT_SAVE_ERR_UNKNOWN");
4843 static void _save_attachment_all(EmailViewerUGD *ug_data)
4846 EmailViewerPrivate *priv = ug_data->email_data;
4847 EmailViewerProp *prop = ug_data->property;
4848 EmailAttachmentType *info = NULL;
4851 int att_len = g_list_length(prop->attachments);
4853 if (priv->b_all_att_save)
4856 for (i = 0; i < att_len; i++) {
4857 info = g_list_nth_data(prop->attachments, i);
4859 if (info && !info->inline_content) {
4860 if (!info->download_yn) {
4861 if (ug_data->progress_bar_ly[i + 1] == NULL) {
4863 gboolean res = FALSE;
4864 debug_log("Need attachment [%d] download", i);
4866 res = email_engine_attachment_download(priv->account_id, priv->mail_id, info->index, &handle);
4869 priv->download_all_cnt++;
4870 priv->download_all_email_handle[i] = handle;
4871 priv->b_all_att_save = TRUE;
4873 debug_log("attach_onoff_flag:%d", ug_data->attach_onoff_flag);
4874 if (priv->b_all_att_save) {
4875 if (ug_data->attach_onoff_flag == 0) {
4876 _attachment_item_collapse_cb(ug_data->attach_hd_bk, NULL, NULL, NULL);
4880 _create_down_progress_ex(i, EMAIL_VIEWER_PROGRESSBAR_ATT);
4881 ug_data->display_download_result = TRUE;
4883 priv->download_all_fail_cnt++;
4890 debug_log("download [%d], failed [%d]", priv->download_all_cnt, priv->download_all_fail_cnt);
4893 static void _dbus_receiver_setup(EmailViewerUGD *ug_data)
4897 int ret = e_dbus_init();
4898 debug_log("ret: %d", ret);
4902 if (_g_viewer_dbus_conn == NULL) {
4904 dbus_error_init(&derror);
4905 _g_viewer_dbus_conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
4907 if (_g_viewer_dbus_conn == NULL) {
4908 debug_log("e_dbus_bus_get return NULL");
4912 if (e_dbus_request_name(_g_viewer_dbus_conn, "User.Email.StorageChange", 0, NULL, NULL) == NULL) {
4913 debug_critical("Failed to e_dbus_request_name()");
4917 if (_g_viewer_signal_handler_storage != NULL) {
4918 debug_log("_g_viewer_signal_handler_storage != NULL");
4921 _g_viewer_signal_handler_storage = e_dbus_signal_handler_add(_g_viewer_dbus_conn, NULL,
4922 "/User/Email/StorageChange",
4923 "User.Email.StorageChange",
4924 "email", _on_edbus_event_email_viewer_receive, ug_data);
4926 if (_g_viewer_signal_handler_storage == NULL) {
4927 debug_log("Failed to e_dbus_signal_handler_add()");
4932 if (e_dbus_request_name(_g_viewer_dbus_conn, "User.Email.NetworkStatus", 0, NULL, NULL) == NULL) {
4933 debug_log("Failed to e_dbus_request_name()");
4937 if (_g_viewer_signal_handler_network != NULL) {
4938 debug_log("_g_viewer_signal_handler_network != NULL");
4941 _g_viewer_signal_handler_network = e_dbus_signal_handler_add(_g_viewer_dbus_conn, NULL,
4942 "/User/Email/NetworkStatus",
4943 "User.Email.NetworkStatus",
4944 "email", _on_edbus_event_email_viewer_receive, ug_data);
4946 if (_g_viewer_signal_handler_network == NULL) {
4947 debug_log("Failed to e_dbus_signal_handler_add()");
4953 static void _dbus_receiver_remove(EmailViewerUGD *ug_data)
4957 if (_g_viewer_signal_handler_storage != NULL) {
4958 e_dbus_signal_handler_del(_g_viewer_dbus_conn, _g_viewer_signal_handler_storage);
4959 _g_viewer_signal_handler_storage = NULL;
4962 if (_g_viewer_signal_handler_network != NULL) {
4963 e_dbus_signal_handler_del(_g_viewer_dbus_conn, _g_viewer_signal_handler_network);
4964 _g_viewer_signal_handler_network = NULL;
4967 if (e_dbus_release_name(_g_viewer_dbus_conn, "User.Email.StorageChange", NULL, NULL) == NULL) {
4968 debug_critical("e_dbus_release_name to failed");
4971 if (e_dbus_release_name(_g_viewer_dbus_conn, "User.Email.NetworkStatus", NULL, NULL) == NULL) {
4972 debug_critical("e_dbus_release_name to failed");
4975 if (_g_viewer_dbus_conn != NULL) {
4976 _g_viewer_dbus_conn = NULL;
4980 static void _on_edbus_event_email_viewer_receive(void *data, DBusMessage *message)
4985 debug_log("data is NULL");
4989 EmailViewerUGD *ug_data = _g_ug_data;
4990 EmailViewerPrivate *priv = ug_data->email_data;
4991 char fail_msg[MAX_STR_LEN] = { 0, };
4994 if (dbus_message_is_signal(message, "User.Email.StorageChange", "email")) {
4995 debug_log("User.Email.StorageChange");
5002 dbus_error_init(&error);
5003 if (dbus_message_get_args(message, &error, DBUS_TYPE_INT32, &subtype,
5004 DBUS_TYPE_INT32, &data1, DBUS_TYPE_INT32, &data2,
5005 DBUS_TYPE_STRING, &data3, DBUS_TYPE_INVALID)) {
5006 debug_log("STORE_ENABLE: subtype: %d, data1: %d, data2: %d, data3: %s", subtype, data1, data2, data3);
5009 case NOTI_ACCOUNT_ADD:
5010 if (get_app_paused()) {
5011 debug_log("account added during pause status");
5013 if (ug_data->isRotate == false && ug_data->b_internal) {
5014 /* Viewer to hide, so set left content (mailbox) size to full */
5015 _notify_mailbox_size(ug_data, "MAILBOX_RESIZE_FULL");
5018 if (ug_data->b_internal != 1) {
5019 debug_log("ug_destory_me");
5020 ug_destroy_me(ug_data->ug);
5022 _hide_view(ug_data);
5027 case NOTI_ACCOUNT_DELETE:
5028 if (get_app_paused()) {
5029 debug_log("account deleted during pause status");
5032 if (ug_data->isRotate == false && ug_data->b_internal) {
5033 /* Viewer to hide, so set left content (mailbox) size to full */
5034 _notify_mailbox_size(ug_data, "MAILBOX_RESIZE_FULL");
5037 if (email_engine_get_default_account(&account_id)) {
5038 if (ug_data->b_internal != 1) {
5039 debug_log("ug_destory_me");
5040 ug_destroy_me(ug_data->ug);
5042 _hide_view(ug_data);
5048 case NOTI_ACCOUNT_UPDATE:
5049 if (get_app_paused()) {
5050 debug_log("account updated during pause status");
5055 debug_warning("unknown type");
5059 debug_critical("receive data error: %s", error.message);
5060 dbus_error_free(&error);
5062 } else if (dbus_message_is_signal(message, "User.Email.NetworkStatus", "email")) {
5071 dbus_error_init(&error);
5073 if (dbus_message_get_args(message, &error, DBUS_TYPE_INT32, &subtype,
5074 DBUS_TYPE_INT32, &data1, DBUS_TYPE_STRING, &data2,
5075 DBUS_TYPE_INT32, &data3, DBUS_TYPE_INT32, &data4, DBUS_TYPE_INVALID)) {
5076 debug_log("subtype: %d, data1: %d, data2: %s, data3: %d, data4: %d", subtype, data1, data2, data3, data4);
5079 case NOTI_DOWNLOAD_BODY_START:
5080 /* DATA1[mail_id] DATA2[file_id] DATA3[body_size] DATA4[received size] */
5081 debug_log("receive noti, DOWNLOAD_BODY");
5082 if (priv->mail_id == data1) {
5083 priv->file_id = g_strdup(data2);
5084 priv->file_size = data3;
5087 _set_value_down_progress(0.0);
5089 double per = (double)data4 / (double)data3;
5090 _set_value_down_progress(per);
5093 debug_log("mail_id is different");
5094 debug_log("expected mail_id [%d], received mail_id [%d]", priv->mail_id, data1);
5098 case NOTI_DOWNLOAD_MULTIPART_BODY:
5099 /* DATA1[mail_id] DATA2[file_id] DATA3[body_size] DATA4[received size] */
5100 debug_log("receive noti, DOWNLOAD_MULTIPART_BODY");
5101 if (priv->mail_id == data1) {
5102 priv->file_id = g_strdup(data2);
5103 priv->file_size = data3;
5104 priv->multi_body = TRUE;
5107 _set_value_down_progress(0.0);
5109 double per = (double)data4 / (double)data3;
5110 _set_value_down_progress(per);
5113 debug_log("mail_id is different");
5114 debug_log("expected mail_id [%d], received mail_id [%d]", priv->mail_id, data1);
5118 case NOTI_DOWNLOAD_BODY_FINISH:
5119 /* DATA1[mail_id] DATA2[NULL] DATA3[handle_id] */
5120 debug_log("receive noti, DOWNLOAD_BODY_FINISH");
5121 if (priv->email_handle == data3 && priv->mail_id == data1) {
5122 priv->email_handle = 0;
5124 ug_data->b_load_finished = EINA_FALSE;
5126 /* delete progress */
5127 if (ug_data->pb_notify) {
5128 _set_value_down_progress(1.0);
5129 _destroy_down_progress_cb(NULL, NULL, NULL);
5132 char str[128] = { 0, };
5133 snprintf(str, sizeof(str), "%s", dgettext("sys_string", "IDS_COM_BODY_DOWNLOADED"));
5134 int ret = status_message_post(str);
5136 debug_log("status_message_post failed: %d", ret);
5139 if (viewer_get_internal_mail_info(ug_data->property, ug_data->email_data)) {
5140 viewer_make_internal_mail(ug_data->property, ug_data->email_data);
5142 /* create att and body */
5143 if (ug_data->b_partial_body) {
5148 elm_scroller_region_get(ug_data->scroller, &scr_x, &scr_y, &scr_w, &scr_h);
5149 debug_log("scroller region> x[%d] y[%d] w[%d] h[%d]", scr_x, scr_y, scr_w, scr_h);
5151 elm_box_unpack(ug_data->main_bx, ug_data->partial_dn_btn_bx);
5152 if (ug_data->partial_dn_btn) {
5153 evas_object_del(ug_data->partial_dn_btn);
5154 ug_data->partial_dn_btn = NULL;
5156 if (ug_data->partial_dn_btn_bx) {
5157 evas_object_del(ug_data->partial_dn_btn_bx);
5158 ug_data->partial_dn_btn_bx = NULL;
5161 if (ug_data->property->has_html) {
5162 ug_data->webview_data->body_type = BODY_TYPE_HTML;
5163 ug_data->webview_data->uri = ug_data->property->body_uri;
5165 ug_data->webview_data->body_type = BODY_TYPE_TEXT;
5166 ug_data->webview_data->text_content = ug_data->property->body;
5169 viewer_set_webview_content(ug_data, 1);
5171 elm_object_focus_set(ug_data->ly_subject, EINA_TRUE);
5172 elm_scroller_region_show(ug_data->scroller, scr_x, scr_y, scr_w, scr_h);
5175 if (ug_data->property->has_attachment)
5176 ug_data->got_att = 1;
5178 ug_data->got_att = 0;
5180 /* pack attachment if it exist */
5181 if (ug_data->got_att) {
5182 _create_attach(ug_data);
5185 _create_body(ug_data);
5188 debug_log("email_handle or mail_id is different");
5189 debug_log("expected mail_id [%d], received mail_id [%d]", priv->mail_id, data1);
5190 debug_log("expected email_handle [%d], received email_handle [%d]", priv->email_handle, data3);
5194 case NOTI_DOWNLOAD_BODY_FAIL:
5195 /* DATA1[mail_id] DATA2[NULL] DATA3[handle_id] */
5196 debug_log("receive noti, DOWNLOAD_BODY_FAIL");
5197 if (priv->email_handle == data3 && priv->mail_id == data1) {
5198 priv->email_handle = 0;
5200 /* delete progress */
5201 if (ug_data->pb_notify) {
5202 _destroy_down_progress_cb(NULL, NULL, NULL);
5205 char *err_msg = _get_service_fail_type(data4);
5206 snprintf(fail_msg, sizeof(fail_msg), "%s<br>%s", _("IDS_EMAIL_POP_UNABLE_TO_DOWNLOAD"), err_msg);
5207 _create_notify(ug_data, dgettext("sys_string", "IDS_COM_POP_WARNING"),
5208 fail_msg, 1, dgettext("sys_string", "IDS_COM_SK_OK"),
5209 _popup_response_cb, NULL, NULL, NULL);
5212 debug_log("email_handle or mail_id is different");
5213 debug_log("expected mail_id [%d], received mail_id [%d]", priv->mail_id, data1);
5214 debug_log("expected email_handle [%d], received email_handle [%d]", priv->email_handle, data3);
5218 case NOTI_DOWNLOAD_ATTACH_START:
5219 /* DATA1[mail_id] DATA2[file_id] DATA3[attachment_id] DATA4[percentage] */
5220 debug_log("receive noti, DOWNLOAD_ATTACHMENT");
5221 if (priv->mail_id == data1) {
5222 priv->att_file_id = g_strdup(data2);
5223 priv->attachment_id = data3;
5226 /* Set the progressbar of particular attachment_id */
5227 _set_value_down_progress_by_index(0.0, priv->attachment_id);
5230 double per = (double)data4 / 100.0;
5231 /* Set the progressbar of particular attachment_id */
5232 _set_value_down_progress_by_index(per, priv->attachment_id);
5235 debug_log("mail_id is different");
5236 debug_log("expected mail_id [%d], received mail_id [%d]", priv->mail_id, data1);
5240 case NOTI_DOWNLOAD_ATTACH_FINISH:
5241 /* DATA1[mail_id] DATA2[NULL] DATA3[attachment_id] */
5242 debug_log("receive noti, DOWNLOAD_ATTACH_FINISH");
5244 if (priv->mail_id == data1) {
5245 int attach_index = 0;
5246 int attachment_id = (int)data3;
5247 debug_log("download_all_cnt [%d]", priv->download_all_cnt);
5249 if (priv->download_all_cnt > 0) {
5250 _set_value_down_progress_by_index(1.0, attachment_id);
5251 attach_index = _update_attachment_info(ug_data, attachment_id);
5252 if (priv->b_all_att_save) {
5253 _destroy_down_progress_ex((void *)attach_index, NULL, NULL);
5254 _save_attachment(ug_data, attach_index);
5255 if (priv->download_all_cnt == 0) {
5256 priv->b_all_att_save = FALSE;
5259 _destroy_down_progress_ex((void *)attach_index, NULL, NULL);
5260 _show_attachment(ug_data, attach_index);
5262 } else { // for updating attachments
5263 attach_index = _update_attachment_info(ug_data, attachment_id);
5264 debug_log("attach_index [%d]", attach_index);
5267 debug_log("mail_id or attachment_id is different");
5268 debug_log("expected mail_id [%d], received mail_id [%d]", priv->mail_id, data1);
5272 case NOTI_DOWNLOAD_ATTACH_FAIL:
5273 /* DATA1[mail_id] DATA2[NULL] DATA3[attachment_id] */
5274 debug_log("receive noti, DOWNLOAD_ATTACH_FAIL");
5275 if (priv->mail_id == data1) {
5276 int attach_index = _get_attachment_info_index(ug_data, data3);
5277 debug_log("download_all_cnt[%d]", priv->download_all_cnt);
5279 if (priv->download_all_cnt > 0) {
5280 if (ug_data->progress_bar[data3] != NULL && data4 != EMAIL_ERROR_CANCELLED)
5281 _destroy_down_progress_ex((void *)attach_index, NULL, NULL);
5283 debug_log("Download already cancelled, No need to destroy again..!");
5285 if (data4 != EMAIL_ERROR_CANCELLED && ug_data->ug_composer == NULL) {
5286 char *err_msg = _get_service_fail_type(data4);
5287 snprintf(fail_msg, sizeof(fail_msg), "%s<br>%s", _("IDS_EMAIL_POP_UNABLE_TO_DOWNLOAD"), err_msg);
5288 _create_notify(ug_data, dgettext("sys_string", "IDS_COM_POP_WARNING"), fail_msg, 1,
5289 dgettext("sys_string", "IDS_COM_SK_OK"),
5290 _popup_response_cb, NULL, NULL, NULL);
5294 if (priv->b_all_att_save && priv->download_all_cnt == 0) {
5295 priv->b_all_att_save = FALSE;
5299 debug_log("mail_id is different");
5300 debug_log("expected mail_id [%d], received mail_id [%d]", priv->mail_id, data1);
5305 debug_log("unknown type");
5309 debug_log("receive data error: %s", error.message);
5310 dbus_error_free(&error);
5317 static void _delete_contacts_list(EMAIL_CONTACT_LIST_INFO_S *contacts_list_item)
5321 if (contacts_list_item) {
5322 g_free(contacts_list_item->display);
5323 contacts_list_item->display = NULL;
5324 g_free(contacts_list_item->email_address);
5325 contacts_list_item->email_address = NULL;
5326 g_free(contacts_list_item);
5327 contacts_list_item = NULL;
5331 static void *_contact_search_by_email(EmailViewerUGD *ug_data, const char *search_word)
5334 if (!ug_data || !_g_ug_data) {
5335 debug_log("data is NULL");
5339 if (contacts_connect2() != CONTACTS_ERROR_NONE) {
5340 debug_log("Fail of contacts_connect2 !!!");
5344 int ct_ret = CONTACTS_ERROR_NONE;
5345 EMAIL_CONTACT_LIST_INFO_S *contacts_list_item = NULL;
5346 contacts_list_h list = NULL;
5348 ct_ret = email_get_contacts_list(CONTACTS_MATCH_EXACTLY, &list, search_word);
5349 debug_log("email_get_contacts_record:%d, list : %p", ct_ret, list);
5352 debug_log("list is NULL");
5353 contacts_list_destroy(list, true);
5354 contacts_disconnect2();
5358 contacts_list_item = (EMAIL_CONTACT_LIST_INFO_S *)calloc(1, sizeof(EMAIL_CONTACT_LIST_INFO_S));
5359 contacts_list_item->ugd = ug_data;
5361 ct_ret = email_get_contacts_list_info(list, contacts_list_item);
5362 if (ct_ret != CONTACTS_ERROR_NONE) {
5363 debug_log("email_get_contacts_list_info: ct_ret : %d", ct_ret);
5364 contacts_list_destroy(list, true);
5365 contacts_disconnect2();
5368 debug_log("email_get_contacts_list_info:%d, contacts_list_item : %p", ct_ret, contacts_list_item);
5370 contacts_list_destroy(list, true);
5371 contacts_disconnect2();
5373 return contacts_list_item;
5376 static void _set_value_down_progress(double val)
5381 debug_log("data is NULL");
5384 char buf[30] = { 0, };
5385 EmailViewerUGD *ug_data = _g_ug_data;
5387 sprintf(buf, "%s: %d", dgettext("sys_string", "IDS_COM_POP_DOWNLOADING"), (int)val);
5389 if (ug_data->pb_notify_lb) {
5390 elm_progressbar_value_set(ug_data->pb_notify_lb, val);
5391 elm_object_text_set(ug_data->pb_notify_lb, buf);
5395 static void _set_value_down_progress_by_index(double val, int index)
5400 debug_log("data is NULL");
5404 EmailViewerUGD *ug_data = _g_ug_data;
5405 EmailViewerProp *prop = ug_data->property;
5408 debug_log("val(%f) is MINUS", val);
5412 if (index < 0 || index >= ATTACH_MAX) {
5413 debug_log("index(%d) is overflowed", index);
5418 debug_log("prop is NULL");
5422 if (prop->attachments == NULL) {
5423 debug_log("attachments is NULL");
5427 int per = val * 100;
5428 int attach_index = _get_attachment_info_index(ug_data, index);
5429 EmailAttachmentType *info = g_list_nth_data(prop->attachments, attach_index);
5432 debug_log("info is NULL");
5435 if (ug_data->progress_bar[index] == NULL) {
5436 debug_log("obj is NULL");
5440 char *pszTemp = NULL;
5441 pszTemp = (char *)elm_object_style_get(ug_data->progress_bar[index]);
5443 if (STR_INVALID(pszTemp))
5446 if (g_strcmp0(pszTemp, "pending_list") == 0) {
5447 debug_log("pending_list so return");
5451 elm_progressbar_value_set(ug_data->progress_bar[index], val);
5453 if (ug_data->progress_bar_ly[index] != NULL) {
5454 char buf[30] = { 0, };
5455 snprintf(buf, sizeof(buf), "%d%%", per);
5457 Evas_Object *downloading_label2;
5458 downloading_label2 = elm_label_add(ug_data->progress_bar_ly[index]);
5459 elm_object_part_content_set(ug_data->progress_bar_ly[index], "elm.text.2", downloading_label2);
5460 char *buf_tagged = g_strconcat("<font_size=26><align=left><color=#646464FF>", buf, "</align></font_size>", NULL);
5461 elm_object_text_set(downloading_label2, buf_tagged);
5466 static void _cancel_download_attachment(EmailViewerUGD *ug_data)
5470 gboolean is_cancel = FALSE;
5473 debug_log("data is NULL");
5477 EmailViewerPrivate *priv = ug_data->email_data;
5478 EmailViewerProp *prop = ug_data->property;
5480 if (priv && priv->download_all_cnt <= 0) {
5481 debug_log("No attachment download to be cancelled!");
5485 for (i = 0; i <= prop->att_len; i++) {
5486 if (ug_data->progress_bar_ly[i]) {
5487 Evas_Object *btn = elm_object_part_content_get(ug_data->progress_bar_ly[i], "elm.icon.1");
5488 debug_log("Cancel btn for downloading attachment: %p", btn);
5490 evas_object_smart_callback_call(btn, "clicked", NULL);
5496 if (is_cancel == TRUE && ug_data->ug_composer == NULL) {
5497 _create_notify(ug_data, dgettext("sys_string", "IDS_COM_POP_WARNING"), _("IDS_EMAIL_POP_CANCELLING_ATTACHMENT_DOWNLOAD_ING"),
5498 1, dgettext("sys_string", "IDS_COM_SK_OK"), _popup_response_cb,
5503 static char *_get_service_fail_type(int type)
5508 char str[MAX_STR_LEN] = { 0, };
5511 snprintf(str, sizeof(str), "%s: %s", _("IDS_EMAIL_POP_FAILED_TO_ACTIVATE_PDP"), N_("IP full"));
5512 return g_strdup(str);
5513 } else if (type == -176) {
5514 ret = _("IDS_EMAIL_POP_NO_SERVICE");
5515 return g_strdup(ret);
5516 } else if (type == -181) {
5517 snprintf(str, sizeof(str), "%s: %s", _("IDS_EMAIL_POP_FAILED_TO_ACTIVATE_PDP"), N_("Transport Error"));
5518 return g_strdup(str);
5519 } else if (type == EMAIL_ERROR_NETWORK_TOO_BUSY) {
5520 ret = _("IDS_EMAIL_POP_NETWORK_BUSY");
5521 return g_strdup(ret);
5522 } else if (type == EMAIL_ERROR_LOGIN_ALLOWED_EVERY_15_MINS) {
5523 snprintf(str, sizeof(str), _("IDS_EMAIL_POP_YOU_CAN_ONLY_LOG_IN_ONCE_EVERY_PD_MINUTES"), 15);
5524 return g_strdup(str);
5525 } else if (type == EMAIL_ERROR_CONNECTION_FAILURE) {
5526 ret = dgettext("sys_string", "IDS_COM_POP_CONNECTION_FAILED");
5527 return g_strdup(ret);
5528 } else if (type == EMAIL_ERROR_LOGIN_FAILURE) {
5529 ret = _("IDS_EMAIL_POP_LOG_IN_FAILED");
5530 return g_strdup(ret);
5531 } else if (type == EMAIL_ERROR_AUTHENTICATE) {
5532 ret = _("IDS_EMAIL_POP_AUTHENTICATION_FAILED");
5533 return g_strdup(ret);
5534 } else if (type == EMAIL_ERROR_CANCELLED) {
5535 ret = _("IDS_EMAIL_POP_DOWNLOAD_CANCELLED");
5536 return g_strdup(ret);
5537 } else if (type == EMAIL_ERROR_MAIL_NOT_FOUND_ON_SERVER) {
5538 ret = _("IDS_EMAIL_POP_EMAIL_DELETED_FROM_SERVER");
5539 return g_strdup(ret);
5540 } else if (type == EMAIL_ERROR_NO_SUCH_HOST) {
5541 ret = _("IDS_EMAIL_POP_HOST_NOT_FOUND");
5542 return g_strdup(ret);
5543 } else if (type == EMAIL_ERROR_INVALID_SERVER) {
5544 ret = _("IDS_EMAIL_POP_SERVER_NOT_AVAILABLE");
5545 return g_strdup(ret);
5546 } else if (type == EMAIL_ERROR_MAIL_MEMORY_FULL) {
5547 ret = _("IDS_EMAIL_POP_DEVICE_STORAGE_FULL");
5548 return g_strdup(ret);
5549 } else if (type == EMAIL_ERROR_FAILED_BY_SECURITY_POLICY) {
5550 ret = _("IDS_EMAIL_POP_DOWNLOADING_ATTACHMENTS_ON_THE_MOBILE_DEVICE_IS_NOT_ALLOWED_BY_EXCHANGE_SERVER_POLICY");
5551 return g_strdup(ret);
5552 } else if (type == EMAIL_ERROR_ATTACHMENT_SIZE_EXCEED_POLICY_LIMIT) {
5553 ret = _("IDS_EMAIL_BODY_ATTACHMENT_EXCEEDS_THE_MAXIMUM_SIZE_ALLOWED_BY_THIS_EXCHANGE_SERVER_POLICY_ABB");
5554 return g_strdup(ret);
5555 } else if (type == EMAIL_ERROR_NETWORK_NOT_AVAILABLE) {
5556 ret = N_("Network not available");
5557 return g_strdup(ret);
5558 } else if (type == EMAIL_ERROR_FLIGHT_MODE) {
5559 ret = N_("Flight mode enabled");
5560 return g_strdup(ret);
5561 } else if (type == EMAIL_ERROR_NO_RESPONSE) {
5562 ret = N_("No server response");
5563 return g_strdup(ret);
5564 } else if (type == EMAIL_ERROR_DISCONNECTED) {
5565 ret = N_("Disconnected");
5566 return g_strdup(ret);
5567 } else if (type == EMAIL_ERROR_CONNECTION_BROKEN) {
5568 ret = N_("Connection broken");
5569 return g_strdup(ret);
5571 snprintf(str, sizeof(str), "%s (%d)", dgettext("sys_string", "IDS_COM_POP_UNKNOWN_ERROR_OCCURRED"), type);
5572 return g_strdup(str);
5576 static Evas_Object *_load_edj(Evas_Object *parent, const char *file, const char *group)
5582 eo = elm_layout_add(parent);
5584 r = elm_layout_file_set(eo, file, group);
5586 evas_object_del(eo);
5590 evas_object_size_hint_weight_set(eo, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
5597 static Eina_Bool _gl_state_get(void *data, Evas_Object *obj, const char *part)
5603 static void _gl_del(void *data, Evas_Object *obj)
5607 if (_g_ug_data == NULL) {
5608 debug_log("ug_data is NULL");
5612 EmailViewerUGD *ug_data = _g_ug_data;
5614 if (ug_data->move_mailbox_list) {
5615 email_free_mailbox(&ug_data->move_mailbox_list, ug_data->move_mailbox_count);
5616 ug_data->move_mailbox_list = NULL;
5617 ug_data->move_mailbox_count = 0;
5623 static char *_gl_text_get(void *data, Evas_Object *obj, const char *part)
5626 email_mailbox_t *mailbox_list = NULL;
5627 mailbox_list = (email_mailbox_t *) data;
5629 if (g_strcmp0(part, "elm.text") == 0) {
5630 char buf[MAX_STR_LEN] = { 0, };
5631 if (mailbox_list && mailbox_list->alias) {
5632 snprintf(buf, sizeof(buf), "%s", mailbox_list->alias);
5633 return g_strdup(buf);
5640 static Evas_Object *_gl_content_get(void *data, Evas_Object *obj, const char *part)
5644 if (g_strcmp0(part, "elm.icon") == 0) {
5645 Evas_Object *icon = elm_icon_add(obj);
5646 elm_image_file_set(icon, IMGDIR "/U01_icon_folder.png", NULL);
5647 evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
5655 static void _move_here_cb(void *data, Evas_Object *obj, void *event_info)
5659 if (data == NULL || _g_ug_data == NULL) {
5660 debug_log("data is NULL");
5664 email_mailbox_t *mailbox_list = NULL;
5665 mailbox_list = (email_mailbox_t *) data;
5667 EmailViewerUGD *ug_data = _g_ug_data;
5668 int folder_id = mailbox_list->mailbox_id;
5671 ret = _move_email(ug_data, folder_id, FALSE);
5674 ug_data->navi_move_it1 = NULL;
5675 elm_naviframe_item_pop_to(ug_data->navi_main_it);
5677 if (ug_data->isRotate == false && ug_data->b_internal) {
5678 /* Viewer to hide, so set left content (mailbox) size to full */
5679 _notify_mailbox_size(ug_data, "MAILBOX_RESIZE_FULL");
5682 if (ug_data->b_internal) {
5683 _hide_view(ug_data);
5685 /* send next or previous mail request to mailbox. */
5686 service_h service = NULL;
5688 ret = service_create(&service);
5689 debug_log("service_create: %d", ret);
5691 debug_log("service create failed");
5695 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_MSG, EMAIL_BUNDLE_VAL_NEXT_MSG);
5696 debug_log("service_add_extra_data: %d", ret);
5697 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_DO_DELETE, "1");
5698 debug_log("service_add_extra_data: %d", ret);
5700 ug_send_message(_g_mailbox_ug, service);
5702 ret = service_destroy(service);
5703 debug_log("service_destroy: %d", ret);
5705 ug_destroy_me(ug_data->ug);
5710 static void _move_back_cb(void *data, Evas_Object *obj, void *event_info)
5714 if (data == NULL || _g_ug_data == NULL) {
5715 debug_log("data is NULL");
5719 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
5721 elm_object_item_del(ug_data->navi_move_it1);
5722 ug_data->navi_move_it1 = NULL;