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 _win_profile_changed_cb(void *data, Evas_Object *obj, void *event);
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 *_update_tab_bar(EmailViewerUGD *ug_data);
81 static Evas_Object *_create_partial_body_dn_btn(EmailViewerUGD *ug_data);
82 static Evas_Object *_create_bg(Evas_Object *win);
84 static void _create_down_progress(char *message, popup_cb resp_cb);
85 static void _create_down_progress_ex(int index, EMAIL_VIEWER_PROGRESSBAR_TYPE p_type);
86 static void _destroy_down_progress_ex(void *data, Evas_Object *obj, void *event_info);
87 static void _create_more_ctxpopup(EmailViewerUGD *ug_data);
88 static void _delete_evas_objects(EmailViewerUGD *ug_data);
90 /* callback functions */
91 static void _back_cb(void *data, Evas_Object *obj, void *event_info);
92 static void _prev_mail_cb(void *data, Evas_Object *obj, void *event_info);
93 static void _next_mail_cb(void *data, Evas_Object *obj, void *event_info);
94 static void _reply_cb(void *data, Evas_Object *obj, void *event_info);
95 static void _reply_all_cb(void *data, Evas_Object *obj, void *event_info);
96 static void _reply_option_cb(void *data, Evas_Object *obj, void *event_info);
97 static void _forward_cb(void *data, Evas_Object *obj, void *event_info);
98 static void _resend_cb(void *data, Evas_Object *obj, void *event_info);
99 static void _delete_cb(void *data, Evas_Object *obj, void *event_info);
100 static void _move_cb(void *data, Evas_Object *obj, void *event_info);
101 static void _more_cb(void *data, Evas_Object *obj, void *event_info);
102 static void _body_down_cb(void *data, Evas_Object *obj, void *event_info);
103 static void _subject_favorite_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
104 static void _subject_detail_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
105 static void _attachment_item_collapse_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
106 static void _attachment_save_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
107 static void _attachment_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
108 static void _attachment_save_all_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
109 static void _attachment_bg_set_cb(void *data, Evas * evas, Evas_Object *obj, void *event_info);
110 static void _attachment_bg_unset_cb(void *data, Evas * evas, Evas_Object *obj, void *event_info);
111 static void _mark_as_unread_cb(void *data, Evas_Object *obj, void *event_info);
112 static void _mark_as_read_cb(void *data, Evas_Object *obj, void *event_info);
113 static void _save_email_cb(void *data, Evas_Object *obj, void *event_info);
114 static Eina_Bool _save_email_prog_cb(void *data);
116 static void _ctxpopup_detail_contact_cb(void *data, Evas_Object *obj, void *event_info);
117 static void _ctxpopup_send_email_cb(void *data, Evas_Object *obj, void *event_info);
118 static void _ctxpopup_add_contact_cb(void *data, Evas_Object *obj, void *event_info);
119 static void _ctxpopup_add_block_rule_cb(void *data, Evas_Object *obj, void *event_info);
120 static void _popup_waiting_response_cb(void *data, Evas_Object *obj, void *event_info);
121 static void _popup_response_cb(void *data, Evas_Object *obj, void *event_info);
122 static void _popup_response_delete_ok_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_multi_up_cb(void *data, Evas * evas, Evas_Object *obj, void *event_info);
126 static void _webview_multi_down_cb(void *data, Evas * evas, Evas_Object *obj, void *event_info);
127 static void _webview_policy_navigation_decide_cb(void *data, Evas_Object *obj, void *event_info);
129 static void _outter_scroller_bottom_hit_cb(void *data, Evas_Object *obj, void *event_info);
130 static void _outter_scroller_top_hit_cb(void *data, Evas_Object *obj, void *event_info);
131 static void _outter_scroller_scroll_cb(void *data, Evas_Object *obj, void *event_info);
133 static void _mbe_focused_cb(void *data, Evas_Object *obj, void *event_info);
134 static void _mbe_unfocused_cb(void *data, Evas_Object *obj, void *event_info);
135 static void _mbe_added_cb(void *data, Evas_Object *obj, void *event_info);
136 static void _mbe_selected_cb(void *data, Evas_Object *obj, void *event_info);
137 static void _destroy_down_progress_cb(void *data, Evas_Object *obj, void *event_info);
139 /* Logic Functions */
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 _show_select_info(EmailViewerUGD *ug_data, char *str);
146 static void _save_attachment(EmailViewerUGD *ug_data, int index);
147 static void _show_attachment(EmailViewerUGD *ug_data, int index);
148 static void _save_attachment_all(EmailViewerUGD *ug_data);
149 static void _dbus_receiver_setup(EmailViewerUGD *ug_data);
150 static void _dbus_receiver_remove(EmailViewerUGD *ug_data);
151 static void _on_edbus_event_email_viewer_receive(void *local_data, DBusMessage *message);
153 static void _delete_contacts_list(EMAIL_CONTACT_LIST_INFO_S *contacts_list_item);
154 static void *_contact_search_by_email(EmailViewerUGD *ug_data, const char *search_word);
155 static void _set_value_down_progress(double val);
156 static void _set_value_down_progress_by_index(double val, int index);
157 static void _cancel_download_attachment(EmailViewerUGD *ug_data);
160 static char *_get_service_fail_type(int type);
161 static Evas_Object *_load_edj(Evas_Object *parent, const char *file, const char *group);
164 static Eina_Bool _gl_state_get(void *data, Evas_Object *obj, const char *part);
165 static void _gl_del(void *data, Evas_Object *obj);
166 static char *_gl_text_get(void *data, Evas_Object *obj, const char *part);
167 static Evas_Object *_gl_content_get(void *data, Evas_Object *obj, const char *part);
168 static void _move_here_cb(void *data, Evas_Object *obj, void *event_info);
169 static void _move_back_cb(void *data, Evas_Object *obj, void *event_info);
172 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
176 EmailViewerUGD *ug_data;
181 ug_data = calloc(1, sizeof(EmailViewerUGD));
185 _g_ug_data = ug_data;
188 ops->create = on_create;
189 ops->start = on_start;
190 ops->pause = on_pause;
191 ops->resume = on_resume;
192 ops->destroy = on_destroy;
193 ops->message = on_message;
194 ops->event = on_event;
195 ops->key_event = on_key_event;
197 ops->opt = UG_OPT_INDICATOR_ENABLE;
202 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
205 EmailViewerUGD *ug_data;
217 static void *on_create(ui_gadget_h ug, enum ug_mode mode, service_h data, void *priv)
220 EmailViewerUGD *ug_data;
221 char *account_id = NULL;
222 char *mail_id = NULL;
223 char *mailbox_id = NULL;
224 char *binternal = NULL;
225 char *landscape = NULL;
234 debug_log("account_id and mail_id are required by arguments");
235 ug_data->b_direct_destroy = 1;
236 ug_destroy_me(ug_data->ug);
241 /* email engine initialize */
242 if (email_engine_initialize() == FALSE) {
243 debug_log("Failed to initialize email engine");
244 ug_data->b_direct_destroy = 1;
245 ug_destroy_me(ug_data->ug);
250 /* Elm_Theme *theme = elm_theme_new();
251 elm_theme_ref_set(theme, NULL);
252 ug_data->theme = theme;
253 elm_theme_extension_add(ug_data->theme, EV_THEME_PATH);*/
256 ret = service_get_extra_data(data, EMAIL_BUNDLE_KEY_ACCOUNT_ID, (char **)&account_id);
257 debug_log("service_get_extra_data: %d", ret);
258 debug_log("account_id:%s", account_id);
259 ret = service_get_extra_data(data, EMAIL_BUNDLE_KEY_MAIL_ID, (char **)&mail_id);
260 debug_log("service_get_extra_data: %d", ret);
261 debug_log("mail_id:%s", mail_id);
262 ret = service_get_extra_data(data, EMAIL_BUNDLE_KEY_MAILBOX, (char **)&mailbox_id);
263 debug_log("service_get_extra_data: %d", ret);
264 debug_log("mailbox:%s", mailbox_id);
265 ret = service_get_extra_data(data, EMAIL_BUNDLE_KEY_INTERNAL, (char **)&binternal);
266 debug_log("service_get_extra_data: %d", ret);
267 debug_log("binternal:%s", binternal);
268 ret = service_get_extra_data(data, EMAIL_BUNDLE_KEY_FIRST_LANDSCAPE, (char **)&landscape);
269 debug_log("service_get_extra_data: %d", ret);
270 debug_log("landscape:%s", landscape);
273 ug_data->isRotate = atoi(landscape);
274 debug_log("@@@@ Landscape = %d @@@@", ug_data->isRotate);
279 ug_data->account_id = atoi(account_id);
280 ug_data->folder_list = email_engine_get_ca_mailbox_list_using_glist(ug_data->account_id);
285 ug_data->mail_id = atoi(mail_id);
290 g_free(ug_data->mailbox_name);
291 ug_data->mailbox_name = NULL;
292 ug_data->mailbox_id = atoi(mailbox_id);
296 email_mail_data_t *mail_data = NULL;
297 if ((err = email_get_mail_data(ug_data->mail_id, &mail_data)) != EMAIL_ERROR_NONE) {
298 debug_log("fail to get mail - err (%d)", err);
301 if (mail_data == NULL) {
302 debug_log("mail_data is NULL");
305 if (mail_data->server_mailbox_name)
306 ug_data->mailbox_name = g_strdup(mail_data->server_mailbox_name);
307 ug_data->mailbox_type = mail_data->mailbox_type;
308 debug_log("server_mailbox_name:%s", mail_data->server_mailbox_name);
309 debug_log("mailbox_name:%s", ug_data->mailbox_name);
310 debug_log("mailbox_type:%d", ug_data->mailbox_type);
313 debug_log("email_free_mail is called");
314 email_free_mail_data(&(mail_data), 1);
320 ug_data->b_internal = atoi(binternal);
321 if (ug_data->b_internal == 1)
322 debug_log("############Launched from email-mailbox###############");
326 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);
328 if (ug_data->account_id <= 0 || ug_data->mail_id <= 0 || ug_data->mailbox_id <= 0) {
329 debug_log("Required bundle parameters are missing!");
330 ug_data->timeout_popup = elm_popup_add(ug_get_window());
331 evas_object_size_hint_weight_set(ug_data->timeout_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
332 elm_popup_timeout_set(ug_data->timeout_popup, 2);
333 elm_object_text_set(ug_data->timeout_popup, _("IDS_EMAIL_POP_UNABLE_TO_OPEN_EMAIL_MESSAGE"));
334 elm_object_part_text_set(ug_data->timeout_popup, "title,text", _("IDS_EMAIL_POP_ALERT"));
335 evas_object_smart_callback_add(ug_data->timeout_popup, "block,clicked", _popup_response_to_destroy_cb, ug_data);
336 evas_object_smart_callback_add(ug_data->timeout_popup, "timeout", _popup_response_to_destroy_cb, ug_data);
337 evas_object_show(ug_data->timeout_popup);
339 return elm_layout_add(ug_get_window());
342 ug_data->win_main = ug_get_window();
344 char *proxy_address = vconf_get_str(VCONFKEY_NETWORK_PROXY);
345 debug_log("network proxy: %s", proxy_address);
346 if (proxy_address && (g_strcmp0(proxy_address, "") != 0)) {
347 ewk_context_proxy_uri_set(ewk_context_default_get(), proxy_address);
354 ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
355 debug_log("WINDOW W[%d] H[%d]", w, h);
359 ug_data->scale_factor = elm_scale_get();
360 debug_log("ELM Scale[%f]", ug_data->scale_factor);
363 ug_data->webview_width = 710.0;
364 ug_data->webview_height = 949.0;
365 ug_data->webview_width_landscape = 710.0;
366 ug_data->webview_height_landscape = 568.0;
367 ug_data->webview_margin = 633;
368 ug_data->webview_margin_landscape = 379;
369 } else if (w == 720) {
370 ug_data->webview_width = 710.0;
371 ug_data->webview_height = 1021.0;
372 ug_data->webview_width_landscape = 710.0;
373 ug_data->webview_height_landscape = 558.0;
374 ug_data->webview_margin = 1029;
375 ug_data->webview_margin_landscape = 558;
377 ug_data->webview_width = 710.0;
378 ug_data->webview_height = 949.0;
379 ug_data->webview_width_landscape = 710.0;
380 ug_data->webview_height_landscape = 568.0;
381 ug_data->webview_margin = 633;
382 ug_data->webview_margin_landscape = 379;
385 ug_data->evas = evas_object_evas_get(ug_data->win_main);
387 /* Double_Scroller */
390 email_account_t *account = NULL;
391 if (email_engine_get_account_full_data(ug_data->account_id, &account)) {
392 debug_log("email_engine_get_account");
394 ug_data->account_type = account->incoming_server_type;
395 snprintf(ug_data->account_email_address, sizeof(ug_data->account_email_address), "%s", account->user_email_address);
397 account_user_data_t *ud = (account_user_data_t*)account->user_data;
399 debug_log("show_images is %d", ud->show_images);
400 ug_data->b_show_remote_images = ud->show_images;
402 email_free_account(&account, 1);
408 _dbus_receiver_setup(ug_data);
410 _init_viewer_data(ug_data->account_id, ug_data->mail_id, NULL, ug_data);
411 _create_view(ug_data);
413 _check_body_download(ug_data);
415 ug_data->base = ug_data->layout_main;
417 ug_data->display_download_result = TRUE;
419 return ug_data->base;
422 static void on_start(ui_gadget_h ug, service_h data, void *priv)
427 static void on_pause(ui_gadget_h ug, service_h data, void *priv)
432 static void on_resume(ui_gadget_h ug, service_h data, void *priv)
437 static void on_destroy(ui_gadget_h ug, service_h data, void *pd)
440 EmailViewerUGD *ug_data;
449 if (ug_data->b_direct_destroy)
453 EmailViewerPrivate *priv = ug_data->email_data;
454 EmailViewerProp *prop = ug_data->property;
456 int att_len = g_list_length(prop->attachments);
458 if (priv->email_handle != 0)
459 email_engine_stop_working(ug_data->account_id, priv->email_handle);
461 for (i = 0; i < att_len; i++) {
462 if (priv->download_all_email_handle[i] != 0)
463 email_engine_stop_working(ug_data->account_id, priv->download_all_email_handle[i]);
466 /* if (ug_data->theme) {
467 elm_theme_extension_del(ug_data->theme, EV_THEME_PATH);
468 elm_theme_free(ug_data->theme);
469 ug_data->theme = NULL;
472 _delete_evas_objects(ug_data);
474 debug_log("free webview_data");
475 if (ug_data->webview_data) {
476 free(ug_data->webview_data);
477 ug_data->webview_data = NULL;
480 if (ecore_file_exists(DIR_TMP_PREFIX"/mail.txt"))
481 ecore_file_remove(DIR_TMP_PREFIX"/mail.txt");
483 debug_log("free address info list");
484 email_free_address_info_list(&(priv->addrs_info_list));
485 ug_data->from_list = NULL;
486 ug_data->to_list = NULL;
487 ug_data->cc_list = NULL;
488 ug_data->bcc_list = NULL;
490 debug_log("free mail_info");
491 if (ug_data->email_data->mail_info) {
492 email_free_mail_data(&(ug_data->email_data->mail_info), 1);
493 ug_data->email_data->mail_info = NULL;
496 if (ug_data->email_data->attachment_info && ug_data->email_data->attachment_count > 0) {
497 email_free_attachment_data(&(ug_data->email_data->attachment_info), ug_data->email_data->attachment_count);
498 ug_data->email_data->attachment_info = NULL;
499 ug_data->email_data->attachment_count = 0;
502 debug_log("free email_data");
503 if (ug_data->email_data) {
504 free(ug_data->email_data);
505 ug_data->email_data = NULL;
508 debug_log("free attachment");
509 if (ug_data->property->attachments) {
511 LIST_ITER_START(i, ug_data->property->attachments) {
512 EmailAttachmentType *info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, ug_data->property->attachments);
519 g_list_free(ug_data->property->attachments);
520 ug_data->property->attachments = NULL;
523 debug_log("free property");
524 if (ug_data->property) {
525 free(ug_data->property);
526 ug_data->property = NULL;
529 ug_data->base = NULL;
531 _dbus_receiver_remove(NULL);
532 int ret = e_dbus_shutdown();
533 debug_log("ret: %d", ret);
535 email_engine_finalize();
541 static void on_message(ui_gadget_h ug, service_h msg, service_h data, void *priv)
548 debug_log("_g_ug_data - %p", _g_ug_data);
549 if (_g_ug_data != NULL) {
550 debug_log("Hide previous mail data");
551 _hide_view(_g_ug_data);
554 char *account_id = NULL;
555 char *mail_id = NULL;
556 char *mailbox_id = NULL;
557 char *binternal = NULL;
558 char *landscape = NULL;
560 EmailViewerUGD *ug_data = (EmailViewerUGD *)priv;
561 _g_ug_data = ug_data;
565 ret = service_get_extra_data(msg, EMAIL_BUNDLE_KEY_ACCOUNT_ID, (char **)&account_id);
566 debug_log("service_get_extra_data: %d", ret);
567 debug_log("account_id:%s", account_id);
568 ret = service_get_extra_data(msg, EMAIL_BUNDLE_KEY_MAIL_ID, (char **)&mail_id);
569 debug_log("service_get_extra_data: %d", ret);
570 debug_log("mail_id:%s", mail_id);
571 ret = service_get_extra_data(msg, EMAIL_BUNDLE_KEY_MAILBOX, (char **)&mailbox_id);
572 debug_log("service_get_extra_data: %d", ret);
573 debug_log("mailbox:%s", mailbox_id);
574 ret = service_get_extra_data(msg, EMAIL_BUNDLE_KEY_INTERNAL, (char **)&binternal);
575 debug_log("service_get_extra_data: %d", ret);
576 debug_log("binternal:%s", binternal);
577 ret = service_get_extra_data(msg, EMAIL_BUNDLE_KEY_FIRST_LANDSCAPE, (char **)&landscape);
578 debug_log("service_get_extra_data: %d", ret);
579 debug_log("landscape:%s", landscape);
582 ug_data->isRotate = atoi(landscape);
583 debug_log("@@@@ Landscape = %d @@@@", ug_data->isRotate);
588 ug_data->account_id = atoi(account_id);
589 ug_data->folder_list = email_engine_get_ca_mailbox_list_using_glist(ug_data->account_id);
594 ug_data->mail_id = atoi(mail_id);
599 g_free(ug_data->mailbox_name);
600 ug_data->mailbox_name = NULL;
601 ug_data->mailbox_id = atoi(mailbox_id);
605 email_mail_data_t *mail_data = NULL;
606 if ((err = email_get_mail_data(ug_data->mail_id, &mail_data)) != EMAIL_ERROR_NONE) {
607 debug_log("fail to get mail - err (%d)", err);
610 if (mail_data == NULL) {
611 debug_log("mail_data is NULL");
614 if (mail_data->server_mailbox_name)
615 ug_data->mailbox_name = g_strdup(mail_data->server_mailbox_name);
616 ug_data->mailbox_type = mail_data->mailbox_type;
617 debug_log("server_mailbox_name:%s", mail_data->server_mailbox_name);
618 debug_log("mailbox_name:%s", ug_data->mailbox_name);
619 debug_log("mailbox_type:%d", ug_data->mailbox_type);
622 debug_log("email_free_mail is called");
623 email_free_mail_data(&(mail_data), 1);
629 ug_data->b_internal = atoi(binternal);
630 if (ug_data->b_internal == 1)
631 debug_log("############Launched from email-mailbox###############");
635 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);
637 if (ug_data->account_id <= 0 || ug_data->mail_id <= 0 || ug_data->mailbox_id <= 0) {
638 debug_log("Required bundle parameters are missing!");
643 email_account_t *account = NULL;
644 if (email_engine_get_account_full_data(ug_data->account_id, &account)) {
645 debug_log("email_engine_get_account");
647 ug_data->account_type = account->incoming_server_type;
648 snprintf(ug_data->account_email_address, sizeof(ug_data->account_email_address), "%s", account->user_email_address);
650 account_user_data_t *ud = (account_user_data_t*)account->user_data;
652 debug_log("show_images is %d", ud->show_images);
653 ug_data->b_show_remote_images = ud->show_images;
655 email_free_account(&account, 1);
659 Ewk_Setting *setting = ewk_view_setting_get(ug_data->webview);
661 debug_log("b_show_remote_images is %d", ug_data->b_show_remote_images);
662 if (ewk_setting_load_remote_images_set(setting, ug_data->b_show_remote_images) == EINA_FALSE) {
663 debug_log("SET remote images is FAILED!");
667 _init_viewer_data(ug_data->account_id, ug_data->mail_id, NULL, ug_data);
669 evas_object_show(ug_data->layout_main);
670 evas_object_raise(ug_data->layout_main);
672 _reset_view(ug_data);
674 ug_data->display_download_result = TRUE;
677 static void on_event(ui_gadget_h ug, enum ug_event event, service_h data, void *priv)
684 EmailViewerUGD *ug_data = (EmailViewerUGD *)priv;
685 EmailViewerProp *prop = ug_data->property;
686 char date_time[MAX_STR_LEN] = { 0, };
687 char *formatted_date = NULL;
690 debug_log("rotate event = %d", event);
693 case UG_EVENT_LOW_MEMORY:
695 case UG_EVENT_LOW_BATTERY:
697 case UG_EVENT_LANG_CHANGE:
699 case UG_EVENT_ROTATE_PORTRAIT:
700 case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
701 if (ug_data->b_internal && ug_data->isRotate == true) {
702 ewk_view_command_execute(ug_data->webview, "Unselect", NULL);
703 debug_log("In Full view - Showing navi bar");
704 elm_naviframe_item_title_visible_set(ug_data->navi_main_it, EINA_TRUE);
706 if (ug_data->con_popup) {
707 evas_object_del(ug_data->con_popup);
708 ug_data->con_popup = NULL;
711 if (ug_data->navi_move_it1) {
713 Evas_Object *move_back_btn = elm_button_add(ug_data->navi_bar);
714 elm_object_style_set(move_back_btn, "naviframe/back_btn/default");
715 evas_object_smart_callback_add(move_back_btn, "clicked", _move_back_cb, ug_data);
716 elm_object_item_part_content_set(ug_data->navi_move_it1, "prev_btn", move_back_btn);
717 elm_naviframe_item_title_visible_set(ug_data->navi_move_it1, EINA_TRUE);
718 if (ug_data->move_cbar) {
719 elm_object_item_part_content_unset(ug_data->navi_move_it1, "controlbar");
720 evas_object_del(ug_data->move_cbar);
721 ug_data->move_cbar = NULL;
725 if (ug_data->b_btn) {
726 evas_object_smart_callback_del(ug_data->b_btn, "clicked", _back_cb);
727 evas_object_del(ug_data->b_btn);
728 ug_data->b_btn = NULL;
731 ug_data->b_btn = elm_button_add(ug_data->navi_bar);
732 elm_object_style_set(ug_data->b_btn, "naviframe/back_btn/default");
733 evas_object_smart_callback_add(ug_data->b_btn, "clicked", _back_cb, ug_data);
734 elm_object_item_part_content_set(ug_data->navi_main_it, "prev_btn", ug_data->b_btn);
736 ug_data->isRotate = false;
741 case UG_EVENT_ROTATE_LANDSCAPE:
742 case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
743 if (ug_data->b_internal && ug_data->isRotate == false) {
744 ewk_view_command_execute(ug_data->webview, "Unselect", NULL);
745 debug_log("In Split view - Hiding navi bar");
746 elm_naviframe_item_title_visible_set(ug_data->navi_main_it, EINA_FALSE);
748 if (ug_data->con_popup) {
749 evas_object_del(ug_data->con_popup);
750 ug_data->con_popup = NULL;
753 if (ug_data->navi_move_it1) {
755 ug_data->move_cbar = elm_toolbar_add(ug_data->navi_bar);
756 elm_toolbar_shrink_mode_set(ug_data->move_cbar, ELM_TOOLBAR_SHRINK_EXPAND);
757 elm_object_style_set(ug_data->move_cbar, "naviframe");
758 evas_object_show(ug_data->move_cbar);
760 elm_object_item_disabled_set(elm_toolbar_item_append(ug_data->move_cbar, NULL, "", NULL, NULL), EINA_TRUE);
761 elm_toolbar_item_append(ug_data->move_cbar, NULL, dgettext("sys_string", "IDS_COM_SK_CANCEL"), _move_back_cb, ug_data);
762 elm_object_item_part_content_set(ug_data->navi_move_it1, "controlbar", ug_data->move_cbar);
764 Evas_Object *move_back_btn = elm_object_item_part_content_get(ug_data->navi_move_it1, "prev_btn");
766 evas_object_smart_callback_del(move_back_btn, "clicked", _move_back_cb);
767 evas_object_del(move_back_btn);
768 elm_object_item_part_content_set(ug_data->navi_move_it1, "prev_btn", NULL);
770 elm_naviframe_item_title_visible_set(ug_data->navi_move_it1, EINA_FALSE);
773 if (ug_data->b_btn) {
774 evas_object_smart_callback_del(ug_data->b_btn, "clicked", _back_cb);
775 evas_object_del(ug_data->b_btn);
776 ug_data->b_btn = NULL;
777 elm_object_item_part_content_set(ug_data->navi_main_it, "prev_btn", NULL);
780 ug_data->isRotate = true;
785 case UG_EVENT_REGION_CHANGE:
786 appcore_get_timeformat(&icu_timeformat);
787 /* ICU API to set default locale */
788 if (icu_timeformat == APPCORE_TIME_FORMAT_12)
789 formatted_date = email_get_date_text(icu_locale, "yMdhms", &(prop->mktime));
791 formatted_date = email_get_date_text(icu_locale, "yMdHms", &(prop->mktime));
792 ret = snprintf(date_time, MAX_STR_LEN, "%s", formatted_date);
794 free(formatted_date);
795 formatted_date = NULL;
797 edje_object_part_text_set(_EDJ(ug_data->ly_subject), "elm.text.sub", date_time);
798 evas_object_show(ug_data->ly_subject);
806 static void on_key_event(ui_gadget_h ug, enum ug_key_event event, service_h data, void *priv)
813 EmailViewerUGD *ug_data = (EmailViewerUGD *)priv;
814 EmailViewerPrivate *private = ug_data->email_data;
815 EmailViewerProp *prop = ug_data->property;
818 case UG_KEY_EVENT_END:
820 if (ug_data->notify != NULL || ug_data->pb_notify != NULL || ug_data->timeout_popup != NULL) {
821 if (ug_data->timeout_popup) {
822 evas_object_del(ug_data->timeout_popup);
823 ug_data->timeout_popup = NULL;
826 if (ug_data->notify) {
827 evas_object_del(ug_data->notify);
828 ug_data->notify = NULL;
831 if (ug_data->pb_notify) {
833 int att_len = g_list_length(prop->attachments);
835 evas_object_del(ug_data->pb_notify);
836 ug_data->pb_notify = NULL;
838 if (private->email_handle != 0)
839 email_engine_stop_working(ug_data->account_id, private->email_handle);
841 for (i = 0; i < att_len; i++) {
842 if (private->download_all_email_handle[i] != 0)
843 email_engine_stop_working(ug_data->account_id, private->download_all_email_handle[i]);
847 if (ug_data->pb_notify_lb) {
848 evas_object_del(ug_data->pb_notify_lb);
849 ug_data->pb_notify_lb = NULL;
852 if (ug_data->isRotate == false && ug_data->b_internal) {
853 /* Viewer to hide, so set left content (mailbox) size to full */
854 _notify_mailbox_size(ug_data, "MAILBOX_RESIZE_FULL");
857 if (ug_data->b_internal)
860 ug_destroy_me(ug_data->ug);
864 service_h service = NULL;
866 ret = service_create(&service);
867 debug_log("service_create: %d", ret);
869 debug_log("service create failed");
873 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_MSG, EMAIL_BUNDLE_VAL_END_KEY);
874 debug_log("service_add_extra_data: %d", ret);
876 ug_send_message(_g_mailbox_ug, service);
878 ret = service_destroy(service);
879 debug_log("service_destroy: %d", ret);
888 static void layout_cb(ui_gadget_h ug, enum ug_mode mode, void *priv)
891 Evas_Object *base, *win;
896 base = ug_get_layout(ug);
900 win = ug_get_window();
903 case UG_MODE_FULLVIEW:
904 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
905 elm_win_resize_object_add(win, base);
906 evas_object_show(base);
913 static void result_cb(ui_gadget_h ug, service_h result, void *priv)
920 EmailViewerUGD *ug_data = (EmailViewerUGD *)priv;
921 EmailViewerProp *prop = ug_data->property;
922 EmailViewerPrivate *private = ug_data->email_data;
924 if (ug == ug_data->ug_composer) {
926 int ret = service_get_extra_data(result, EMAIL_BUNDLE_KEY_SAVE_ALL, (char **)&cmd);
927 debug_log("service_get_extra_data: %d", ret);
928 debug_log("return of bundle_get_val for save all(%s)", cmd);
930 debug_log("save all from composer(%s), real_att_len(%d), att_len(%d)", cmd, prop->real_att_len, prop->att_len);
932 if (prop->real_att_len == 1) {
933 private->b_all_att_save = TRUE;
934 _save_attachment(ug_data, 0);
935 } else if (prop->real_att_len > 1) {
936 _save_attachment_all(ug_data);
942 ret = service_get_extra_data(result, EMAIL_BUNDLE_KEY_CANCEL_ALL, (char **)&cmd);
943 debug_log("service_get_extra_data: %d", ret);
944 debug_log("return of bundle_get_val for cancel all(%s)", cmd);
946 debug_log("cancel all attachment from composer(%s)", cmd);
948 _cancel_download_attachment(ug_data);
955 static void destroy_cb(ui_gadget_h ug, void *priv)
961 EmailViewerUGD *ug_data = (EmailViewerUGD *)priv;
962 EmailViewerProp *prop = ug_data->property;
963 ug_data->display_download_result = TRUE;
965 if (ug == ug_data->ug_composer) {
966 ug_data->ug_composer = NULL;
971 if (ug_data->b_contact_ug_launched) {
972 debug_log("change navibar title label");
973 EMAIL_CONTACT_LIST_INFO_S *contact_list_item = NULL;
974 contact_list_item = (EMAIL_CONTACT_LIST_INFO_S *)_contact_search_by_email(ug_data, prop->sender);
976 if (contact_list_item) {
977 elm_object_item_text_set(ug_data->navi_main_it, contact_list_item->display_name);
978 _delete_contacts_list(contact_list_item);
980 elm_object_item_text_set(ug_data->navi_main_it, prop->sender_display_name);
983 ug_data->b_contact_ug_launched = FALSE;
987 static ui_gadget_h create_ug(char *ug_name, service_h bd, void *data)
991 struct ug_cbs cbs = { 0, };
993 cbs.layout_cb = layout_cb;
994 cbs.result_cb = result_cb;
995 cbs.destroy_cb = destroy_cb;
998 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
1000 ug = ug_create(ug_data->ug, ug_name, UG_MODE_FULLVIEW, bd, &cbs);
1005 static void _create_view(EmailViewerUGD *ug_data)
1010 Evas_Object *prev_btn;
1011 Evas_Object *next_btn;
1012 EmailViewerProp *prop = ug_data->property;
1014 ug_data->bg = _create_bg(ug_data->win_main);
1017 ug_data->layout_main = elm_layout_add(ug_data->win_main);
1019 if (ug_data->b_internal)
1020 elm_layout_theme_set(ug_data->layout_main, "layout", "application", "noindicator");
1022 elm_layout_theme_set(ug_data->layout_main, "layout", "application", "default");
1023 evas_object_size_hint_weight_set(ug_data->layout_main, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1024 evas_object_show(ug_data->layout_main);
1026 elm_object_part_content_set(ug_data->layout_main, "elm.swallow.bg", ug_data->bg);
1029 elm_win_indicator_mode_set(ug_data->win_main, ELM_WIN_INDICATOR_SHOW);
1031 evas_object_smart_callback_add(ug_data->win_main, "profile,changed", _win_profile_changed_cb, ug_data);
1033 /* navigation Bar */
1034 _create_navigation_bar(ug_data);
1036 /* push navigation bar */
1037 ug_data->sub_ly = elm_layout_add(ug_data->navi_bar);
1038 elm_layout_theme_set(ug_data->sub_ly, "layout", "application", "noindicator");
1039 evas_object_size_hint_weight_set(ug_data->sub_ly, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1040 evas_object_show(ug_data->sub_ly);
1043 b_btn = elm_button_add(ug_data->navi_bar);
1044 elm_object_style_set(b_btn, "naviframe/back_btn/default");
1045 evas_object_smart_callback_add(b_btn, "clicked", _back_cb, ug_data);
1046 ug_data->b_btn = b_btn;
1048 ug_data->navi_main_it = elm_naviframe_item_push(ug_data->navi_bar, prop->sender_display_name, b_btn, NULL, ug_data->sub_ly, NULL);
1050 if (ug_data->b_internal) {
1051 /* Left : previous button */
1052 prev_btn = elm_button_add(ug_data->navi_bar);
1053 Evas_Object *prev_ic = elm_icon_add(prev_btn);
1054 elm_icon_file_set(prev_ic, IMGDIR "/M02_icon_previous.png", NULL);
1055 elm_object_style_set(prev_btn, "naviframe/title/default");
1056 evas_object_size_hint_aspect_set(prev_ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
1057 elm_icon_resizable_set(prev_ic, 0.8, 0.8);
1058 elm_object_part_content_set(prev_btn, "icon", prev_ic);
1059 elm_object_item_part_content_set(ug_data->navi_main_it, "title_left_btn", prev_btn);
1060 evas_object_smart_callback_add(prev_btn, "clicked", _prev_mail_cb, ug_data);
1061 ug_data->prev_btn = prev_btn;
1063 /* Right : next button */
1064 next_btn = elm_button_add(ug_data->navi_bar);
1065 Evas_Object *next_ic = elm_icon_add(next_btn);
1066 elm_icon_file_set(next_ic, IMGDIR "/M02_icon_next.png", NULL);
1067 elm_object_style_set(next_btn, "naviframe/title/default");
1068 evas_object_size_hint_aspect_set(next_ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
1069 elm_icon_resizable_set(next_ic, 0.8, 0.8);
1070 elm_object_part_content_set(next_btn, "icon", next_ic);
1071 elm_object_item_part_content_set(ug_data->navi_main_it, "title_right_btn", next_btn);
1072 evas_object_smart_callback_add(next_btn, "clicked", _next_mail_cb, ug_data);
1073 ug_data->next_btn = next_btn;
1076 /* create scroller */
1077 ug_data->scroller = elm_scroller_add(ug_data->navi_bar);
1078 evas_object_propagate_events_set(ug_data->scroller, EINA_FALSE);
1079 elm_scroller_bounce_set(ug_data->scroller, EINA_FALSE, EINA_TRUE);
1080 elm_scroller_policy_set(ug_data->scroller, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF);
1081 evas_object_show(ug_data->scroller);
1082 evas_object_smart_callback_add(ug_data->scroller, "edge,bottom", _outter_scroller_bottom_hit_cb, ug_data);
1083 evas_object_smart_callback_add(ug_data->scroller, "edge,top", _outter_scroller_top_hit_cb, ug_data);
1084 evas_object_smart_callback_add(ug_data->scroller, "scroll,drag,start", _outter_scroller_scroll_cb, ug_data);
1086 /* create conformant */
1087 elm_win_conformant_set(ug_data->win_main, EINA_TRUE);
1088 ug_data->conformant = elm_conformant_add(ug_data->sub_ly);
1089 elm_object_style_set(ug_data->conformant, "internal_layout");
1090 evas_object_size_hint_weight_set(ug_data->conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1091 evas_object_size_hint_align_set(ug_data->conformant, EVAS_HINT_FILL, EVAS_HINT_FILL);
1092 elm_object_content_set(ug_data->conformant, ug_data->scroller);
1093 elm_object_part_content_set(ug_data->sub_ly, "elm.swallow.content", ug_data->conformant);
1094 evas_object_show(ug_data->conformant);
1096 if (ug_data->from_list != NULL) {
1097 email_address_info_t *addrs_info = NULL;
1098 int n_from_list = g_list_length(ug_data->from_list);
1099 debug_log("from list count [%d]", n_from_list);
1101 if (n_from_list > 0) {
1102 addrs_info = (email_address_info_t *) g_list_nth_data(ug_data->from_list, 0);
1103 debug_log("From Address:%s", addrs_info->address);
1104 debug_log("Display Name:%s", addrs_info->display_name);
1105 debug_log("Storage Type:%d", addrs_info->storage_type);
1106 debug_log("Contact ID:%d", addrs_info->contact_id);
1108 g_free(prop->sender_display_name);
1109 prop->sender_display_name = g_strdup(addrs_info->display_name);
1110 g_free(prop->sender);
1111 prop->sender = g_strdup(addrs_info->address);
1113 if (addrs_info->display_name && strlen(addrs_info->display_name) > 0)
1114 elm_object_item_text_set(ug_data->navi_main_it, addrs_info->display_name);
1116 elm_object_item_text_set(ug_data->navi_main_it, addrs_info->address);
1120 /* create main box */
1121 ug_data->main_bx = elm_box_add(ug_data->navi_bar);
1122 evas_object_size_hint_weight_set(ug_data->main_bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1123 evas_object_size_hint_align_set(ug_data->main_bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
1124 evas_object_show(ug_data->main_bx);
1125 elm_object_content_set(ug_data->scroller, ug_data->main_bx);
1127 if (ug_data->property->has_attachment)
1128 ug_data->got_att = 1;
1130 ug_data->got_att = 0;
1132 /* packing subject, addrs, attachment */
1133 _create_subject(ug_data);
1135 if (ug_data->got_att) {
1136 _create_attach(ug_data);
1139 if (ug_data->isRotate == true) {
1140 debug_log("In Split view - Hiding navi bar");
1141 elm_naviframe_item_title_visible_set(ug_data->navi_main_it, EINA_FALSE);
1143 if (ug_data->b_btn) {
1144 debug_log("hiding back button");
1146 evas_object_smart_callback_del(ug_data->b_btn, "clicked", _back_cb);
1147 evas_object_del(ug_data->b_btn);
1148 ug_data->b_btn = NULL;
1150 elm_object_item_part_content_set(ug_data->navi_main_it, "prev_btn", NULL);
1155 static void _reset_view(EmailViewerUGD *ug_data)
1158 EmailViewerProp *prop = ug_data->property;
1160 char date_time[MAX_STR_LEN] = { 0, };
1162 debug_log("@@@@@@@@@@ isRotate = %d", ug_data->isRotate);
1163 if (ug_data->isRotate == true) {
1164 debug_log("In Split view - Hiding navi bar");
1165 elm_naviframe_item_title_visible_set(ug_data->navi_main_it, EINA_FALSE);
1167 if (ug_data->b_btn) {
1168 debug_log("hiding back button");
1170 evas_object_smart_callback_del(ug_data->b_btn, "clicked", _back_cb);
1171 evas_object_del(ug_data->b_btn);
1172 ug_data->b_btn = NULL;
1174 elm_object_item_part_content_set(ug_data->navi_main_it, "prev_btn", NULL);
1177 /* Set scroller to start - height made 480 to consider viewer in split view */
1178 elm_scroller_region_show(ug_data->scroller, 0, 0, (int)((double)ug_data->main_h * 0.6), ug_data->main_w);
1180 debug_log("In Full view - Showing navi bar");
1181 elm_naviframe_item_title_visible_set(ug_data->navi_main_it, EINA_TRUE);
1183 if (ug_data->b_btn) {
1185 evas_object_smart_callback_del(ug_data->b_btn, "clicked", _back_cb);
1186 evas_object_del(ug_data->b_btn);
1187 ug_data->b_btn = NULL;
1190 debug_log("showing back button");
1192 ug_data->b_btn = elm_button_add(ug_data->navi_bar);
1193 elm_object_style_set(ug_data->b_btn, "naviframe/back_btn/default");
1194 evas_object_smart_callback_add(ug_data->b_btn, "clicked", _back_cb, ug_data);
1196 elm_object_item_part_content_set(ug_data->navi_main_it, "prev_btn", ug_data->b_btn);
1198 /* Set scroller to start */
1199 elm_scroller_region_show(ug_data->scroller, 0, 0, ug_data->main_w, ug_data->main_h);
1202 if (ug_data->from_list != NULL) {
1203 email_address_info_t *addrs_info = NULL;
1204 int n_from_list = g_list_length(ug_data->from_list);
1205 debug_log("from list count [%d]", n_from_list);
1207 if (n_from_list > 0) {
1208 addrs_info = (email_address_info_t *) g_list_nth_data(ug_data->from_list, 0);
1210 debug_log("From Address:%s", addrs_info->address);
1211 debug_log("Display Name:%s", addrs_info->display_name);
1212 debug_log("Storage Type:%d", addrs_info->storage_type);
1213 debug_log("Contact ID:%d", addrs_info->contact_id);
1214 g_free(prop->sender_display_name);
1215 prop->sender_display_name = g_strdup(addrs_info->display_name);
1216 g_free(prop->sender);
1217 prop->sender = g_strdup(addrs_info->address);
1219 if (addrs_info->display_name && strlen(addrs_info->display_name) > 0)
1220 elm_object_item_text_set(ug_data->navi_main_it, addrs_info->display_name);
1222 elm_object_item_text_set(ug_data->navi_main_it, addrs_info->address);
1226 elm_object_item_text_set(ug_data->navi_main_it, prop->sender_display_name);
1230 char *_subject = elm_entry_utf8_to_markup(prop->subject);
1231 if (!g_strcmp0(_subject, "")) {
1233 _subject = g_strdup(_("IDS_EMAIL_BODY_NO_SUBJECT"));
1235 char *_subject_concated = g_strconcat("<font_size=44><color=#000000FF>", _subject, "</color></font_size>", NULL);
1236 elm_object_text_set(ug_data->lb_subject, _subject_concated);
1237 elm_label_wrap_width_set(ug_data->lb_subject, ug_data->main_w - (int)(110 * ug_data->scale_factor));
1238 elm_label_line_wrap_set(ug_data->lb_subject, ELM_WRAP_WORD);
1240 g_free(_subject_concated);
1242 /* reset date & time */
1243 char *formatted_date = NULL;
1245 if (icu_timeformat == APPCORE_TIME_FORMAT_12)
1246 formatted_date = email_get_date_text(icu_locale, "yMdhms", &(prop->mktime));
1248 formatted_date = email_get_date_text(icu_locale, "yMdHms", &(prop->mktime));
1249 ret = snprintf(date_time, MAX_STR_LEN, "%s", formatted_date);
1251 free(formatted_date);
1252 formatted_date = NULL;
1254 elm_object_part_text_set(ug_data->ly_subject, "elm.text.sub", date_time);
1256 Evas_Object *favorite_icon = elm_icon_add(ug_data->ly_subject);
1257 switch(prop->favorite)
1259 case EMAIL_FLAG_NONE:
1260 elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_icon_favorite_off.png", NULL);
1262 case EMAIL_FLAG_FLAGED:
1263 elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_icon_favorite_on.png", NULL);
1265 case EMAIL_FLAG_TASK_STATUS_CLEAR:
1266 elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_Flag_Clear.png", NULL);
1268 case EMAIL_FLAG_TASK_STATUS_ACTIVE:
1269 elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_Flag_Active.png", NULL);
1271 case EMAIL_FLAG_TASK_STATUS_COMPLETE:
1272 elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_Flag_Complete.png", NULL);
1275 evas_object_size_hint_aspect_set(favorite_icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
1276 elm_icon_resizable_set(favorite_icon, 1, 1);
1277 evas_object_del(elm_object_part_content_unset(ug_data->ly_subject, "elm.icon.favorite"));
1278 elm_object_part_content_set(ug_data->ly_subject, "elm.icon.favorite", favorite_icon);
1279 evas_object_show(favorite_icon);
1281 evas_object_show(ug_data->ly_subject);
1282 elm_box_pack_end(ug_data->main_bx, ug_data->ly_subject);
1284 Evas_Object *edje = elm_layout_edje_get(ug_data->ly_subject);
1286 if (!ug_data->to_list && !ug_data->cc_list && !ug_data->bcc_list) {
1287 edje_object_signal_emit(edje, "elm,state,arrow_hidden", "elm");
1289 edje_object_signal_callback_add(edje, "elm,action,expand,toggle", "elm", _subject_detail_clicked_cb, ug_data->ly_subject);
1292 if (prop->has_attachment)
1293 ug_data->got_att = 1;
1295 ug_data->got_att = 0;
1297 /* pack attachment if it exist */
1298 if (ug_data->got_att) {
1299 _create_attach(ug_data);
1302 /* check body downloaded */
1303 _check_body_download(ug_data);
1306 void _hide_view(EmailViewerUGD *ug_data)
1309 EmailViewerProp *prop = ug_data->property;
1310 EmailViewerPrivate *priv = ug_data->email_data;
1312 debug_log("Cancelling all attachment downloads");
1313 _cancel_download_attachment(ug_data);
1315 ug_data->display_download_result = FALSE;
1318 if (elm_naviframe_top_item_get(ug_data->navi_bar) != ug_data->navi_main_it) {
1319 ug_data->navi_move_it1 = NULL;
1320 elm_naviframe_item_pop_to(ug_data->navi_main_it);
1323 evas_object_hide(ug_data->layout_main);
1324 elm_box_unpack_all(ug_data->main_bx);
1325 elm_object_scroll_freeze_pop(ug_data->scroller);
1327 evas_object_hide(ug_data->ly_subject);
1328 evas_object_hide(ug_data->lb_subject);
1329 evas_object_hide(ug_data->webview_bx);
1330 evas_object_hide(ug_data->webview);
1332 if (ug_data->partial_dn_btn) {
1333 evas_object_del(ug_data->partial_dn_btn);
1334 ug_data->partial_dn_btn = NULL;
1337 if (ug_data->partial_dn_btn_bx) {
1338 evas_object_del(ug_data->partial_dn_btn_bx);
1339 ug_data->partial_dn_btn_bx = NULL;
1342 if (ug_data->ctr_bar) {
1343 elm_object_item_part_content_unset(ug_data->navi_main_it, "controlbar");
1344 evas_object_del(ug_data->ctr_bar);
1345 ug_data->ctr_bar = NULL;
1347 ug_data->reply_ctr_it = NULL;
1348 ug_data->replyall_ctr_it = NULL;
1349 ug_data->forward_ctr_it = NULL;
1350 ug_data->calendar_ctr_it = NULL;
1351 ug_data->resend_ctr_it = NULL;
1352 ug_data->move_ctr_it = NULL;
1353 ug_data->del_ctr_it = NULL;
1356 if (ug_data->to_ly) {
1357 evas_object_del(ug_data->to_ly);
1358 ug_data->to_ly = NULL;
1361 if (ug_data->cc_ly) {
1362 evas_object_del(ug_data->cc_ly);
1363 ug_data->cc_ly = NULL;
1366 if (ug_data->bcc_ly) {
1367 evas_object_del(ug_data->bcc_ly);
1368 ug_data->bcc_ly = NULL;
1371 if (ug_data->got_att) {
1374 evas_object_del(ug_data->attach_hd_bk);
1375 ug_data->attach_hd_ly = NULL;
1376 ug_data->attach_hd_bk = NULL;
1378 if (prop->real_att_len > 1) {
1379 for (i = 0; i < prop->real_att_len; i++) {
1380 if (ug_data->attach_ex_ly != NULL) {
1381 if (ug_data->attach_ex_ly[i] != NULL) {
1382 debug_log("index %d", i);
1383 evas_object_del(ug_data->attach_ex_bk[i]);
1384 ug_data->attach_ex_ly[i] = NULL;
1385 ug_data->attach_ex_bk[i] = NULL;
1390 if (ug_data->attach_ex_ly != NULL) {
1391 free(ug_data->attach_ex_ly);
1392 ug_data->attach_ex_ly = NULL;
1393 ug_data->attach_ex_bk = NULL;
1397 for (i = 0; i <= prop->att_len; i++) {
1398 if (ug_data->progress_bar_ly[i] != NULL) {
1399 evas_object_del(ug_data->progress_bar_ly[i]);
1400 ug_data->progress_bar_ly[i] = NULL;
1401 ug_data->progress_bar[i] = NULL;
1406 if (ug_data->con_popup != NULL) {
1407 evas_object_del(ug_data->con_popup);
1408 ug_data->con_popup = NULL;
1411 if (ug_data->notify != NULL) {
1412 evas_object_del(ug_data->notify);
1413 ug_data->notify = NULL;
1416 edje_object_signal_emit(_EDJ(ug_data->ly_subject), "elm,state,contracted", "elm");
1417 edje_object_signal_callback_del(_EDJ(ug_data->ly_subject), "elm,action,expand,toggle", "elm", _subject_detail_clicked_cb);
1419 evas_object_hide(ug_data->noc_bx);
1420 evas_object_hide(ug_data->dn_btn);
1422 if (ecore_file_exists(EMAIL_TMP_FILE_PATH ".html"))
1423 ecore_file_remove(EMAIL_TMP_FILE_PATH ".html");
1425 if (ecore_file_exists(DIR_TMP_PREFIX"/mail.txt"))
1426 ecore_file_remove(DIR_TMP_PREFIX"/mail.txt");
1428 ewk_view_uri_set(ug_data->webview, EMAIL_DEFAULT_HTML);
1430 debug_log("free address info list");
1431 email_free_address_info_list(&(priv->addrs_info_list));
1432 ug_data->from_list = NULL;
1433 ug_data->to_list = NULL;
1434 ug_data->cc_list = NULL;
1435 ug_data->bcc_list = NULL;
1437 ug_data->got_att = 0;
1438 ug_data->subject_onoff_flag = 0;
1439 ug_data->attach_onoff_flag = 0;
1440 ug_data->b_partial_body = 0;
1441 ug_data->b_internal = 0;
1442 ug_data->scroller_locked = 0;
1443 ug_data->m_is_multi_touch = 0;
1445 ug_data->navi_move_it1 = NULL;
1447 /* Double_Scroller */
1449 ug_data->b_load_finished = EINA_FALSE;
1450 ug_data->b_show_remote_images = EINA_FALSE;
1451 ug_data->is_webview_scrolling = EINA_FALSE;
1452 ug_data->is_main_scroller_scrolling = EINA_FALSE;
1455 static void _win_profile_changed_cb(void *data, Evas_Object *obj, void *event)
1459 debug_log("data is NULL");
1463 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
1465 const char *profile = elm_config_profile_get();
1466 if (!g_strcmp0(profile, "desktop"))
1467 elm_layout_theme_set(ug_data->layout_main, "layout", "application", "noindicator");
1469 elm_layout_theme_set(ug_data->layout_main, "layout", "application", "default");
1471 evas_object_size_hint_weight_set(ug_data->layout_main, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1472 elm_win_resize_object_add(ug_data->win_main, ug_data->layout_main);
1473 evas_object_show(ug_data->layout_main);
1476 static Evas_Object *_create_navigation_bar(EmailViewerUGD *ug_data)
1479 Evas_Object *navi_bar;
1481 navi_bar = elm_naviframe_add(ug_data->layout_main);
1482 if (navi_bar == NULL) {
1483 debug_log("navi_bar == NULL");
1487 elm_object_part_content_set(ug_data->layout_main, "elm.swallow.content", navi_bar);
1488 evas_object_show(navi_bar);
1490 ug_data->navi_bar = navi_bar;
1494 static Evas_Object *_create_subject(EmailViewerUGD *ug_data)
1497 EmailViewerProp *prop = ug_data->property;
1499 char date_time[MAX_STR_LEN] = { 0, };
1501 /* append subject */
1502 Evas_Object *di = elm_layout_add(ug_data->navi_bar);
1503 elm_layout_file_set(di, EV_THEME_PATH, "layout.email.detail_subject");
1504 evas_object_size_hint_align_set(di, EVAS_HINT_FILL, 0.0);
1506 Evas_Object *subject_label;
1507 subject_label = elm_label_add(di);
1508 elm_object_part_content_set(di, "elm.text", subject_label);
1509 char *subject = elm_entry_utf8_to_markup(prop->subject);
1510 if (!g_strcmp0(subject, "")) {
1512 subject = g_strdup(_("IDS_EMAIL_BODY_NO_SUBJECT"));
1514 char *subject_tagged = g_strconcat("<font_size=44><color=#000000FF>", subject, "</color></font_size>", NULL);
1515 elm_object_text_set(subject_label, subject_tagged);
1516 elm_label_wrap_width_set(subject_label, ug_data->main_w - (int)(110 * ug_data->scale_factor));
1517 elm_label_line_wrap_set(subject_label, ELM_WRAP_WORD);
1518 ug_data->lb_subject = subject_label;
1520 g_free(subject_tagged);
1522 char *formatted_date = NULL;
1524 if (icu_timeformat == APPCORE_TIME_FORMAT_12)
1525 formatted_date = email_get_date_text(icu_locale, "yMdhms", &(prop->mktime));
1527 formatted_date = email_get_date_text(icu_locale, "yMdHms", &(prop->mktime));
1528 ret = snprintf(date_time, MAX_STR_LEN, "%s", formatted_date);
1529 free(formatted_date);
1530 formatted_date = NULL;
1532 elm_object_part_text_set(di, "elm.text.sub", date_time);
1534 Evas_Object *favorite_icon = elm_icon_add(di);
1535 switch(prop->favorite)
1537 case EMAIL_FLAG_NONE:
1538 elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_icon_favorite_off.png", NULL);
1540 case EMAIL_FLAG_FLAGED:
1541 elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_icon_favorite_on.png", NULL);
1543 case EMAIL_FLAG_TASK_STATUS_CLEAR:
1544 elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_Flag_Clear.png", NULL);
1546 case EMAIL_FLAG_TASK_STATUS_ACTIVE:
1547 elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_Flag_Active.png", NULL);
1549 case EMAIL_FLAG_TASK_STATUS_COMPLETE:
1550 elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_Flag_Complete.png", NULL);
1553 evas_object_size_hint_aspect_set(favorite_icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
1554 elm_icon_resizable_set(favorite_icon, 1, 1);
1555 elm_object_part_content_set(di, "elm.icon.favorite", favorite_icon);
1556 evas_object_show(favorite_icon);
1558 evas_object_show(di);
1559 elm_box_pack_end(ug_data->main_bx, di);
1560 ug_data->ly_subject = di;
1562 Evas_Object *edje = elm_layout_edje_get(di);
1564 if (ug_data->to_list || ug_data->cc_list || ug_data->bcc_list) {
1565 edje_object_signal_callback_add(edje, "elm,action,expand,toggle", "elm", _subject_detail_clicked_cb, di);
1567 edje_object_signal_emit(edje, "elm,state,arrow_hidden", "elm");
1569 edje_object_signal_callback_add(edje, "elm,action,toggle", "elm", _subject_favorite_clicked_cb, di);
1574 static Evas_Object *_create_to_addrs(EmailViewerUGD *ug_data)
1577 email_address_info_t *addrs_info = NULL;
1578 Elm_Object_Item *mbe_item;
1580 if (ug_data->to_list == NULL) {
1581 debug_log("to_list is NULL");
1585 int n_to_list = g_list_length(ug_data->to_list);
1588 if (n_to_list <= 0) {
1589 debug_log("to_list count is 0");
1593 Evas_Object *di = elm_layout_add(ug_data->main_bx);
1594 elm_layout_file_set(di, EV_THEME_PATH, "layout.email.to_cc");
1595 evas_object_size_hint_align_set(di, EVAS_HINT_FILL, 0.0);
1596 evas_object_show(di);
1597 ug_data->to_ly = di;
1598 elm_box_pack_after(ug_data->main_bx, di, ug_data->ly_subject);
1600 Evas_Object *to_mbe = elm_multibuttonentry_add(ug_data->main_bx);
1601 char desc[MAX_STR_LEN] = { 0, };
1602 snprintf(desc, MAX_STR_LEN, "%s:", dgettext("sys_string", "IDS_COM_BODY_TO"));
1603 char *to_str = g_strconcat("<font_size=36><color=#000000FF>", desc, "</color></font_size>", NULL);
1604 elm_object_text_set(to_mbe, to_str);
1607 evas_object_smart_callback_add(to_mbe, "item,clicked", _mbe_selected_cb, ug_data);
1608 evas_object_smart_callback_add(to_mbe, "item,added", _mbe_added_cb, ug_data);
1609 evas_object_smart_callback_add(to_mbe, "focused", _mbe_focused_cb, ug_data);
1610 evas_object_smart_callback_add(to_mbe, "unfocused", _mbe_unfocused_cb, ug_data);
1611 elm_object_part_content_set(di, "elm.icon", to_mbe);
1612 ug_data->to_mbe = to_mbe;
1614 Evas_Object *entry = elm_multibuttonentry_entry_get(to_mbe);
1616 elm_entry_editable_set(entry, EINA_FALSE);
1618 if (n_to_list > EMAIL_VIEW_MAX_TO_COUNT)
1619 n_to_list = EMAIL_VIEW_MAX_TO_COUNT;
1621 for (i = 0; i < n_to_list; i++) {
1622 addrs_info = (email_address_info_t *) g_list_nth_data(ug_data->to_list, i);
1623 debug_log("Address:%s", addrs_info->address);
1624 debug_log("Display Name:%s", addrs_info->display_name);
1625 debug_log("Storage Type:%d", addrs_info->storage_type);
1626 debug_log("Contact ID:%d", addrs_info->contact_id);
1628 if (addrs_info->display_name && strlen(addrs_info->display_name) > 0)
1629 mbe_item = elm_multibuttonentry_item_append(to_mbe, addrs_info->display_name, NULL, NULL);
1631 mbe_item = elm_multibuttonentry_item_append(to_mbe, addrs_info->address, NULL, NULL);
1632 elm_object_item_data_set(mbe_item, addrs_info);
1638 static Evas_Object *_create_cc_addrs(EmailViewerUGD *ug_data)
1641 email_address_info_t *addrs_info = NULL;
1642 Elm_Object_Item *mbe_item;
1644 if (ug_data->cc_list == NULL) {
1645 debug_log("cc_list is NULL");
1649 int n_cc_list = g_list_length(ug_data->cc_list);
1652 if (n_cc_list <= 0) {
1653 debug_log("cc_list count is 0");
1657 Evas_Object *di = elm_layout_add(ug_data->main_bx);
1658 elm_layout_file_set(di, EV_THEME_PATH, "layout.email.to_cc");
1659 evas_object_size_hint_align_set(di, EVAS_HINT_FILL, 0.0);
1660 evas_object_show(di);
1661 ug_data->cc_ly = di;
1663 if (ug_data->to_ly) {
1664 elm_box_pack_after(ug_data->main_bx, di, ug_data->to_ly);
1666 elm_box_pack_after(ug_data->main_bx, di, ug_data->ly_subject);
1669 Evas_Object *cc_mbe = elm_multibuttonentry_add(ug_data->main_bx);
1670 char desc[MAX_STR_LEN] = { 0, };
1671 snprintf(desc, MAX_STR_LEN, "%s:", _("IDS_EMAIL_BODY_CC"));
1672 char *cc_str = g_strconcat("<font_size=36><color=#000000FF>", desc, "</color></font_size>", NULL);
1673 elm_object_text_set(cc_mbe, cc_str);
1675 evas_object_smart_callback_add(cc_mbe, "item,clicked", _mbe_selected_cb, ug_data);
1676 evas_object_smart_callback_add(cc_mbe, "item,added", _mbe_added_cb, ug_data);
1677 evas_object_smart_callback_add(cc_mbe, "focused", _mbe_focused_cb, ug_data);
1678 evas_object_smart_callback_add(cc_mbe, "unfocused", _mbe_unfocused_cb, ug_data);
1679 elm_object_part_content_set(di, "elm.icon", cc_mbe);
1680 ug_data->cc_mbe = cc_mbe;
1682 Evas_Object *entry = elm_multibuttonentry_entry_get(cc_mbe);
1684 elm_entry_editable_set(entry, EINA_FALSE);
1686 if (n_cc_list > EMAIL_VIEW_MAX_CC_COUNT)
1687 n_cc_list = EMAIL_VIEW_MAX_CC_COUNT;
1689 for (i = 0; i < n_cc_list; i++) {
1690 addrs_info = (email_address_info_t *) g_list_nth_data(ug_data->cc_list, i);
1692 if (addrs_info->display_name && strlen(addrs_info->display_name) > 0)
1693 mbe_item = elm_multibuttonentry_item_append(cc_mbe, addrs_info->display_name, NULL, NULL);
1695 mbe_item = elm_multibuttonentry_item_append(cc_mbe, addrs_info->address, NULL, NULL);
1696 elm_object_item_data_set(mbe_item, addrs_info);
1702 static Evas_Object *_create_bcc_addrs(EmailViewerUGD *ug_data)
1705 email_address_info_t *addrs_info = NULL;
1706 Elm_Object_Item *mbe_item;
1708 if (ug_data->bcc_list == NULL) {
1709 debug_log("bcc_list is NULL");
1713 int n_bcc_list = g_list_length(ug_data->bcc_list);
1716 if (n_bcc_list <= 0) {
1717 debug_log("bcc_list count is 0");
1721 Evas_Object *di = elm_layout_add(ug_data->main_bx);
1722 elm_layout_file_set(di, EV_THEME_PATH, "layout.email.to_cc");
1723 evas_object_size_hint_align_set(di, EVAS_HINT_FILL, 0.0);
1724 evas_object_show(di);
1725 ug_data->bcc_ly = di;
1727 if (ug_data->cc_ly) {
1728 elm_box_pack_after(ug_data->main_bx, di, ug_data->cc_ly);
1730 if (ug_data->to_ly && ug_data->cc_ly == NULL) {
1731 elm_box_pack_after(ug_data->main_bx, di, ug_data->to_ly);
1733 if (ug_data->to_ly == NULL && ug_data->cc_ly == NULL) {
1734 elm_box_pack_after(ug_data->main_bx, di, ug_data->ly_subject);
1737 Evas_Object *bcc_mbe = elm_multibuttonentry_add(ug_data->main_bx);
1738 char desc[MAX_STR_LEN] = { 0, };
1739 snprintf(desc, MAX_STR_LEN, "%s:", _("IDS_EMAIL_BODY_BCC"));
1740 char *bcc_str = g_strconcat("<font_size=36><color=#000000FF>", desc, "</color></font_size>", NULL);
1741 elm_object_text_set(bcc_mbe, bcc_str);
1743 evas_object_smart_callback_add(bcc_mbe, "item,clicked", _mbe_selected_cb, ug_data);
1744 evas_object_smart_callback_add(bcc_mbe, "item,added", _mbe_added_cb, ug_data);
1745 evas_object_smart_callback_add(bcc_mbe, "focused", _mbe_focused_cb, ug_data);
1746 evas_object_smart_callback_add(bcc_mbe, "unfocused", _mbe_unfocused_cb, ug_data);
1747 elm_object_part_content_set(di, "elm.icon", bcc_mbe);
1748 ug_data->bcc_mbe = bcc_mbe;
1750 Evas_Object *entry = elm_multibuttonentry_entry_get(bcc_mbe);
1752 elm_entry_editable_set(entry, EINA_FALSE);
1754 if (n_bcc_list > EMAIL_VIEW_MAX_BCC_COUNT)
1755 n_bcc_list = EMAIL_VIEW_MAX_BCC_COUNT;
1757 for (i = 0; i < n_bcc_list; i++) {
1758 addrs_info = (email_address_info_t *) g_list_nth_data(ug_data->bcc_list, i);
1760 if (addrs_info->display_name && strlen(addrs_info->display_name) > 0)
1761 mbe_item = elm_multibuttonentry_item_append(bcc_mbe, addrs_info->display_name, NULL, NULL);
1763 mbe_item = elm_multibuttonentry_item_append(bcc_mbe, addrs_info->address, NULL, NULL);
1764 elm_object_item_data_set(mbe_item, addrs_info);
1770 static Evas_Object *_create_attach(EmailViewerUGD *ug_data)
1774 EmailViewerProp *prop = ug_data->property;
1775 char buff[MAX_STR_LEN];
1777 int att_len = prop->real_att_len;
1780 RETURN_VAL_IF_FAIL(prop->attachments != NULL, NULL);
1781 RETURN_VAL_IF_FAIL(att_len > 0, NULL);
1783 GList *attachment_list = prop->attachments;
1786 LIST_ITER_START(i, attachment_list) {
1787 EmailAttachmentType *info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, attachment_list);
1789 if (info && !info->inline_content) {
1790 if (info->size < 1024) {
1791 g_sprintf(buff, "%s (%d %s)", info->name, (gint) info->size, dgettext("sys_string", "IDS_COM_BODY_B"));
1793 gdouble tmpsize = (gdouble) (info->size / 1024.);
1794 if (tmpsize < 1024) {
1795 g_sprintf(buff, "%s (%.2f %s)", info->name, tmpsize, dgettext("sys_string", "IDS_COM_BODY_KB"));
1798 if (tmpsize < 1024) {
1799 g_sprintf(buff, "%s (%.2f %s)", info->name, tmpsize, dgettext("sys_string", "IDS_COM_BODY_MB"));
1802 g_sprintf(buff, "%s (%.2f %s)", info->name, tmpsize, dgettext("sys_string", "IDS_COM_BODY_GB"));
1807 Evas_Object *di = elm_layout_add(ug_data->navi_bar);
1808 elm_layout_file_set(di, EV_THEME_PATH, "layout.email.attachment_item");
1809 evas_object_size_hint_align_set(di, EVAS_HINT_FILL, 0.0);
1810 evas_object_show(di);
1811 elm_box_pack_after(ug_data->main_bx, di, ug_data->ly_subject);
1813 Evas_Object *thumbnail = NULL;
1815 if (info->download_yn) {
1816 thumbnail = viewer_make_thumbnail(info->path, di);
1818 thumbnail = viewer_make_thumbnail(NULL, di);
1819 evas_object_size_hint_aspect_set(thumbnail, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
1820 elm_icon_resizable_set(thumbnail, 1, 1);
1821 elm_object_part_content_set(di, "elm.icon", thumbnail);
1822 evas_object_show(thumbnail);
1824 elm_object_part_text_set(di, "elm.text", buff);
1828 Evas_Object *edje = elm_layout_edje_get(di);
1829 edje_object_signal_callback_add(edje, "elm,action,download", "elm", _attachment_save_cb, (void *)att_index);
1830 edje_object_signal_callback_add(edje, "clicked", "*", _attachment_clicked_cb, (void *)att_index);
1832 Evas_Object *text_bg = NULL;
1833 text_bg = (Evas_Object *)edje_object_part_object_get(_EDJ(di), "elm.event.rect");
1836 evas_object_event_callback_add(text_bg, EVAS_CALLBACK_MOUSE_DOWN, _attachment_bg_set_cb, (void *)att_index);
1837 evas_object_event_callback_add(text_bg, EVAS_CALLBACK_MOUSE_UP, _attachment_bg_unset_cb, (void *)att_index);
1840 ug_data->attach_hd_ly = di;
1841 ug_data->attach_hd_bk = di;
1844 } else if (att_len > 1) {
1845 gint64 total_size = prop->total_att_size;
1847 Evas_Object *di = elm_layout_add(ug_data->navi_bar);
1848 elm_layout_file_set(di, EV_THEME_PATH, "layout.email.attachment_head");
1849 evas_object_size_hint_align_set(di, EVAS_HINT_FILL, 0.0);
1850 snprintf(buff, sizeof(buff), "%d %s", att_len, _("IDS_EMAIL_BODY_ATTACHMENTS"));
1852 Evas_Object *att_head_label;
1853 att_head_label = elm_label_add(di);
1854 elm_object_part_content_set(di, "elm.text", att_head_label);
1856 char *buff_tagged = g_strconcat("<font_size=35><color=#000000FF>", buff, "<color></font_size>", NULL);
1857 elm_object_text_set(att_head_label, buff_tagged);
1858 g_free(buff_tagged);
1860 if (total_size < 1024) {
1861 g_sprintf(buff, "(%d %s)", (gint) total_size, dgettext("sys_string", "IDS_COM_BODY_B"));
1863 gdouble tmpsize = (gdouble) (total_size / 1024.);
1865 if (tmpsize < 1024) {
1866 g_sprintf(buff, "(%.2f %s)", tmpsize, dgettext("sys_string", "IDS_COM_BODY_KB"));
1870 if (tmpsize < 1024) {
1871 g_sprintf(buff, "(%.2f %s)", tmpsize, dgettext("sys_string", "IDS_COM_BODY_MB"));
1874 g_sprintf(buff, "(%.2f %s)", tmpsize, dgettext("sys_string", "IDS_COM_BODY_GB"));
1879 edje_object_part_text_set(_EDJ(di), "elm.text.sub", buff);
1881 Evas_Object *edje = elm_layout_edje_get(di);
1882 edje_object_signal_callback_add(edje, "att,icon,save,all", "", _attachment_save_all_cb, di);
1883 edje_object_signal_callback_add(edje, "elm,action,expand,toggle", "elm", _attachment_item_collapse_cb, di);
1884 evas_object_show(di);
1885 elm_box_pack_after(ug_data->main_bx, di, ug_data->ly_subject);
1886 ug_data->attach_hd_ly = di;
1887 ug_data->attach_hd_bk = di;
1889 debug_log("Attachment doesn't exist");
1895 static Evas_Object *_create_attach_ex(EmailViewerUGD *ug_data)
1899 EmailViewerProp *prop = ug_data->property;
1900 char buff[MAX_STR_LEN];
1903 int att_len = prop->real_att_len;
1906 RETURN_VAL_IF_FAIL(prop->attachments != NULL, NULL);
1907 RETURN_VAL_IF_FAIL(att_len > 0, NULL);
1909 GList *attachment_list = prop->attachments;
1911 ug_data->attach_ex_ly = (Evas_Object **)calloc(att_len, sizeof(Evas_Object *));
1912 ug_data->attach_ex_bk = (Evas_Object **)calloc(att_len, sizeof(Evas_Object *));
1914 LIST_ITER_START(i, attachment_list) {
1915 EmailAttachmentType *info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, attachment_list);
1917 if (info && !info->inline_content) {
1918 if (info->size < 1024) {
1919 g_sprintf(buff, "%s (%d %s)", info->name, (gint) info->size, dgettext("sys_string", "IDS_COM_BODY_B"));
1921 gdouble tmpsize = (gdouble) (info->size / 1024.);
1922 if (tmpsize < 1024) {
1923 g_sprintf(buff, "%s (%.2f %s)", info->name, tmpsize, dgettext("sys_string", "IDS_COM_BODY_KB"));
1926 if (tmpsize < 1024) {
1927 g_sprintf(buff, "%s (%.2f %s)", info->name, tmpsize, dgettext("sys_string", "IDS_COM_BODY_MB"));
1930 g_sprintf(buff, "%s (%.2f %s)", info->name, tmpsize, dgettext("sys_string", "IDS_COM_BODY_GB"));
1935 Evas_Object *di = elm_layout_add(ug_data->navi_bar);
1936 elm_layout_file_set(di, EV_THEME_PATH, "layout.email.attachment_item");
1937 evas_object_size_hint_align_set(di, EVAS_HINT_FILL, 0.0);
1938 elm_box_pack_after(ug_data->main_bx, di, ug_data->attach_hd_ly);
1939 evas_object_show(di);
1941 Evas_Object *thumbnail = NULL;
1943 if (info->download_yn) {
1944 thumbnail = viewer_make_thumbnail(info->path, di);
1946 thumbnail = viewer_make_thumbnail(NULL, di);
1947 evas_object_size_hint_aspect_set(thumbnail, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
1948 elm_icon_resizable_set(thumbnail, 1, 1);
1949 elm_object_part_content_set(di, "elm.icon", thumbnail);
1950 evas_object_show(thumbnail);
1952 elm_object_part_text_set(di, "elm.text", buff);
1956 Evas_Object *edje = elm_layout_edje_get(di);
1957 edje_object_signal_callback_add(edje, "elm,action,download", "elm", _attachment_save_cb, (void *)att_index);
1958 edje_object_signal_callback_add(edje, "clicked", "*", _attachment_clicked_cb, (void *)att_index);
1960 Evas_Object *text_bg = NULL;
1961 text_bg = (Evas_Object *)edje_object_part_object_get(_EDJ(di), "elm.event.rect");
1964 evas_object_event_callback_add(text_bg, EVAS_CALLBACK_MOUSE_DOWN, _attachment_bg_set_cb, (void *)att_index);
1965 evas_object_event_callback_add(text_bg, EVAS_CALLBACK_MOUSE_UP, _attachment_bg_unset_cb, (void *)att_index);
1968 debug_log("attach ly %d, att_index %d", j, i);
1970 ug_data->attach_ex_ly[j] = di;
1971 ug_data->attach_ex_bk[j] = di;
1980 static Evas_Object *_create_body(EmailViewerUGD *ug_data)
1983 EmailViewerProp *prop = ug_data->property;
1984 EmailViewerPrivate *priv = ug_data->email_data;
1988 if (ug_data->noc_bx) {
1989 elm_box_unpack(ug_data->main_bx, ug_data->noc_bx);
1990 evas_object_hide(ug_data->noc_bx);
1993 if (ug_data->dn_btn) {
1994 evas_object_hide(ug_data->dn_btn);
1997 if (ug_data->webview_bx) {
1998 _init_webview_data(ug_data);
2000 ewk_view_scale_set(ug_data->webview, 1.0f, 0, 0);
2002 if (prop->has_html) {
2004 ug_data->webview_data->body_type_prev = BODY_TYPE_HTML;
2005 ug_data->webview_data->body_type = BODY_TYPE_HTML;
2006 ug_data->webview_data->uri = prop->body_uri;
2009 ug_data->webview_data->body_type_prev = BODY_TYPE_TEXT;
2010 ug_data->webview_data->body_type = BODY_TYPE_TEXT;
2011 ug_data->webview_data->text_content = prop->body;
2014 viewer_set_webview_content(ug_data, 0);
2016 evas_object_show(ug_data->webview_bx);
2017 evas_object_show(ug_data->webview);
2018 elm_box_pack_end(ug_data->main_bx, ug_data->webview_bx);
2020 _update_tab_bar(ug_data);
2022 /* create webview layout */
2023 ug_data->webview_bx = _load_edj(ug_data->navi_bar, EV_THEME_PATH, "layout.email.web_view");
2024 if (ug_data->webview_bx == NULL) {
2025 debug_log("Cannot load edj");
2029 evas_object_size_hint_align_set(ug_data->webview_bx, EVAS_HINT_FILL, 0.0);
2030 evas_object_show(ug_data->webview_bx);
2031 elm_box_pack_end(ug_data->main_bx, ug_data->webview_bx);
2033 /* create webview */
2034 if (NULL == ug_data->webview) {
2035 _init_webview_data(ug_data);
2036 viewer_get_webview(ug_data, prop->has_html);
2038 if (prop->has_html) {
2039 ug_data->webview_data->body_type_prev = BODY_TYPE_HTML;
2040 ug_data->webview_data->body_type = BODY_TYPE_HTML;
2041 ug_data->webview_data->uri = prop->body_uri;
2043 ug_data->webview_data->body_type_prev = BODY_TYPE_TEXT;
2044 ug_data->webview_data->body_type = BODY_TYPE_TEXT;
2045 ug_data->webview_data->text_content = prop->body;
2047 viewer_set_webview_content(ug_data, 0);
2050 evas_object_show(ug_data->webview);
2051 elm_object_part_content_set(ug_data->webview_bx, "web_body", ug_data->webview);
2055 if (ug_data->isRotate) {
2056 resized_w = ug_data->webview_width_landscape * ug_data->scale_factor;
2057 resized_h = ug_data->webview_height_landscape * ug_data->scale_factor;
2059 resized_w = ug_data->webview_width * ug_data->scale_factor;
2060 resized_h = ug_data->webview_height * ug_data->scale_factor;
2062 debug_log("resized_w:%d, resized_h:%d", resized_w, resized_h);
2064 evas_object_size_hint_min_set(ug_data->webview, resized_w, resized_h);
2066 /* set touch callbacks */
2067 evas_object_smart_callback_add(ug_data->webview, "policy,navigation,decide", _webview_policy_navigation_decide_cb, ug_data);
2068 evas_object_event_callback_add(ug_data->webview, EVAS_CALLBACK_MULTI_DOWN, _webview_multi_down_cb, ug_data);
2069 evas_object_event_callback_add(ug_data->webview, EVAS_CALLBACK_MULTI_UP, _webview_multi_up_cb, ug_data);
2071 /* update control Bar */
2072 _update_tab_bar(ug_data);
2075 viewer_set_mail_seen(prop, priv->mail_info);
2077 if (ug_data->timer) {
2078 ecore_timer_del(ug_data->timer);
2079 ug_data->timer = NULL;
2082 debug_log("send message - list unlock");
2083 ug_data->timer = ecore_timer_add(0.0, viewer_send_message, ug_data);
2085 return ug_data->webview_bx;
2088 static Evas_Object *_create_tab_bar(EmailViewerUGD *ug_data)
2092 EmailViewerProp *prop = ug_data->property;
2094 obj = elm_toolbar_add(ug_data->navi_bar);
2095 elm_toolbar_shrink_mode_set(obj, ELM_TOOLBAR_SHRINK_EXPAND);
2096 elm_object_style_set(obj, "naviframe");
2098 if (ug_data->mailbox_type == EMAIL_MAILBOX_TYPE_INBOX || ug_data->mailbox_type == EMAIL_MAILBOX_TYPE_SENTBOX ||
2099 ug_data->mailbox_type == EMAIL_MAILBOX_TYPE_TRASH || ug_data->mailbox_type == EMAIL_MAILBOX_TYPE_SPAMBOX) {
2100 int n_to_list = g_list_length(ug_data->to_list);
2101 int n_cc_list = g_list_length(ug_data->cc_list);
2102 debug_log("to:%d, cc:%d", n_to_list, n_cc_list);
2103 if (n_to_list + n_cc_list >= 2)
2104 ug_data->reply_ctr_it = elm_toolbar_item_append(obj, ICON_REPLY, dgettext("sys_string", "IDS_COM_SK_REPLY"), _reply_option_cb, ug_data);
2106 ug_data->reply_ctr_it = elm_toolbar_item_append(obj, ICON_REPLY, dgettext("sys_string", "IDS_COM_SK_REPLY"), _reply_cb, ug_data);
2107 ug_data->forward_ctr_it = elm_toolbar_item_append(obj, ICON_FORWARD, dgettext("sys_string", "IDS_COM_BODY_FORWARD"), _forward_cb, ug_data);
2108 ug_data->del_ctr_it = elm_toolbar_item_append(obj, ICON_DELETE, dgettext("sys_string", "IDS_COM_SK_DELETE"), _delete_cb, ug_data);
2109 ug_data->more_ctr_it = elm_toolbar_item_append(obj, ICON_CONTROLBAR_MORE, dgettext("sys_string", "IDS_COM_SK_MORE"), _more_cb, ug_data);
2111 elm_object_item_disabled_set(ug_data->reply_ctr_it, EINA_TRUE);
2112 elm_object_item_disabled_set(ug_data->forward_ctr_it, EINA_TRUE);
2113 } else if (ug_data->mailbox_type == EMAIL_MAILBOX_TYPE_OUTBOX) {
2114 debug_log("save_status: %d", prop->status2);
2115 if (prop->status2 == EMAIL_MAIL_STATUS_SEND_FAILURE) {
2116 ug_data->resend_ctr_it = elm_toolbar_item_append(obj, ICON_RESEND, _("IDS_EMAIL_SK_RESEND"), _resend_cb, ug_data);
2117 ug_data->del_ctr_it = elm_toolbar_item_append(obj, ICON_DELETE, dgettext("sys_string", "IDS_COM_SK_DELETE"), _delete_cb, ug_data);
2119 ug_data->del_ctr_it = elm_toolbar_item_append(obj, ICON_DELETE, dgettext("sys_string", "IDS_COM_SK_DELETE"), _delete_cb, ug_data);
2122 ug_data->del_ctr_it = elm_toolbar_item_append(obj, ICON_DELETE, dgettext("sys_string", "IDS_COM_SK_DELETE"), _delete_cb, ug_data);
2123 ug_data->move_ctr_it = elm_toolbar_item_append(obj, ICON_MOVE, _("IDS_EMAIL_SK_MOVE"), _move_cb, ug_data);
2126 elm_object_item_part_content_set(ug_data->navi_main_it, "controlbar", obj);
2127 ug_data->ctr_bar = obj;
2132 static Evas_Object *_update_tab_bar(EmailViewerUGD *ug_data)
2136 if (ug_data->mailbox_type == EMAIL_MAILBOX_TYPE_INBOX || ug_data->mailbox_type == EMAIL_MAILBOX_TYPE_SENTBOX ||
2137 ug_data->mailbox_type == EMAIL_MAILBOX_TYPE_TRASH || ug_data->mailbox_type == EMAIL_MAILBOX_TYPE_SPAMBOX) {
2138 elm_object_item_disabled_set(ug_data->reply_ctr_it, EINA_FALSE);
2139 elm_object_item_disabled_set(ug_data->forward_ctr_it, EINA_FALSE);
2145 static Evas_Object *_create_partial_body_dn_btn(EmailViewerUGD *ug_data)
2149 ug_data->partial_dn_btn_bx = _load_edj(ug_data->navi_bar, EV_THEME_PATH, "layout.email.partial_download_btn");
2150 if (ug_data->partial_dn_btn_bx == NULL) {
2151 debug_log("Cannot load edj");
2155 evas_object_size_hint_align_set(ug_data->partial_dn_btn_bx, EVAS_HINT_FILL, 0.0);
2156 evas_object_show(ug_data->partial_dn_btn_bx);
2157 elm_box_pack_before(ug_data->main_bx, ug_data->partial_dn_btn_bx, ug_data->webview_bx);
2159 Evas_Object *dn_btn = elm_button_add(ug_data->navi_bar);
2160 elm_object_text_set(dn_btn, _("IDS_EMAIL_BODY_DOWNLOAD_FULL_MESSAGE"));
2161 evas_object_smart_callback_add(dn_btn, "clicked", _body_down_cb, (void *)ug_data);
2162 /*elm_object_theme_set(dn_btn, ug_data->theme);*/
2163 elm_object_style_set(dn_btn, "text_only/style2");
2164 evas_object_show(dn_btn);
2165 ug_data->partial_dn_btn = dn_btn;
2167 elm_object_part_content_set(ug_data->partial_dn_btn_bx, "button", ug_data->partial_dn_btn);
2169 return ug_data->partial_dn_btn_bx;
2172 static Evas_Object *_create_bg(Evas_Object *win)
2176 Evas_Object *bg = elm_bg_add(win);
2177 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2178 elm_win_resize_object_add(win, bg);
2179 evas_object_show(bg);
2184 static void _create_down_progress(char *message, popup_cb resp_cb)
2189 debug_log("data is NULL");
2193 EmailViewerUGD *ug_data = _g_ug_data;
2194 Evas_Object *notify, *pb;
2196 notify = elm_popup_add(ug_data->win_main);
2198 debug_log("elm_popup_add returns NULL");
2201 evas_object_size_hint_weight_set(notify, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2202 ug_data->pb_notify = notify;
2204 elm_object_part_text_set(notify, "title,text", message);
2206 pb = elm_progressbar_add(notify);
2208 elm_object_style_set(pb, "list_progress");
2210 elm_progressbar_horizontal_set(pb, EINA_TRUE);
2211 evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, EVAS_HINT_FILL);
2212 evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2213 evas_object_show(pb);
2214 elm_progressbar_value_set(pb, 0.0);
2215 elm_object_content_set(notify, pb);
2216 ug_data->pb_notify_lb = pb;
2218 Evas_Object *btn1 = elm_button_add(notify);
2219 elm_object_style_set(btn1, "popup_button/default");
2220 elm_object_text_set(btn1, dgettext("sys_string", "IDS_COM_SK_CANCEL"));
2221 elm_object_part_content_set(notify, "button1", btn1);
2222 evas_object_smart_callback_add(btn1, "clicked", resp_cb, ug_data);
2223 debug_log("Cancel btn1 for downloading body: %p", btn1);
2225 evas_object_show(notify);
2228 static void _create_down_progress_ex(int index, EMAIL_VIEWER_PROGRESSBAR_TYPE p_type)
2233 debug_log("data is NULL");
2237 EmailViewerUGD *ug_data = _g_ug_data;
2238 EmailViewerProp *prop = ug_data->property;
2239 EmailViewerPrivate *priv = ug_data->email_data;
2241 if (!prop || !prop->attachments) {
2251 if (ug_data->forward_ctr_it)
2252 elm_object_item_disabled_set(ug_data->forward_ctr_it, EINA_TRUE);
2258 elm_scroller_region_get(ug_data->scroller, &scr_x, &scr_y, &scr_w, &scr_h);
2259 debug_log("scroller region> x[%d] y[%d] w[%d] h[%d]", scr_x, scr_y, scr_w, scr_h);
2261 GList *attachment_list = prop->attachments;
2263 debug_log("index %d of attachment_count %d", index, prop->att_len);
2265 EmailAttachmentType *info = NULL;
2266 info = g_list_nth_data(attachment_list, index);
2268 debug_log("info is NULL");
2271 Evas_Object *pbar_ly = elm_layout_add(ug_data->navi_bar);
2272 elm_layout_file_set(pbar_ly, EV_THEME_PATH, "layout.email.attachment_downloading");
2273 evas_object_size_hint_align_set(pbar_ly, EVAS_HINT_FILL, 0.0);
2274 evas_object_show(pbar_ly);
2275 ug_data->progress_bar_ly[index + 1] = pbar_ly;
2278 char buff[MAX_STR_LEN] = { 0, };
2280 Evas_Object *downloading_label1;
2281 downloading_label1 = elm_label_add(pbar_ly);
2282 elm_object_part_content_set(pbar_ly, "elm.text.1", downloading_label1);
2283 char *text_tagged = g_strconcat("<font_size=32><align=left><color=#000000FF>", info->name, "</color></align></font_size>", NULL);
2284 elm_object_text_set(downloading_label1, text_tagged);
2285 elm_label_ellipsis_set(downloading_label1, EINA_TRUE);
2286 elm_label_wrap_width_set(downloading_label1, ug_data->main_w - 240);
2287 g_free(text_tagged);
2289 if (info->size < 1024) {
2290 g_sprintf(buff, "%d %s", (gint) info->size, dgettext("sys_string", "IDS_COM_BODY_B"));
2292 gdouble tmpsize = (gdouble) (info->size / 1024.);
2294 if (tmpsize < 1024) {
2295 g_sprintf(buff, "%.2f %s", tmpsize, dgettext("sys_string", "IDS_COM_BODY_KB"));
2299 if (tmpsize < 1024) {
2300 g_sprintf(buff, "%.2f %s", tmpsize, dgettext("sys_string", "IDS_COM_BODY_MB"));
2303 g_sprintf(buff, "%.2f %s", tmpsize, dgettext("sys_string", "IDS_COM_BODY_GB"));
2308 Evas_Object *downloading_label3;
2309 downloading_label3 = elm_label_add(pbar_ly);
2310 elm_object_part_content_set(pbar_ly, "elm.text.3", downloading_label3);
2311 text_tagged = g_strconcat("<font_size=26><align=right><color=#646464FF>", buff, "</color></align></font_size>", NULL);
2312 elm_object_text_set(downloading_label3, text_tagged);
2313 g_free(text_tagged);
2316 Evas_Object *progressbar = elm_progressbar_add(pbar_ly);
2317 elm_progressbar_horizontal_set(progressbar, EINA_TRUE);
2318 elm_object_style_set(progressbar, "list_progress");
2319 elm_object_part_content_set(pbar_ly, "elm.icon.2", progressbar);
2320 ug_data->progress_bar[index + 1] = progressbar;
2321 evas_object_show(progressbar);
2323 Evas_Object *cancel_btn = elm_button_add(pbar_ly);
2324 /*elm_object_theme_set(cancel_btn, ug_data->theme);*/
2325 elm_object_style_set(cancel_btn, "text_only/style2");
2326 elm_object_text_set(cancel_btn, dgettext("sys_string", "IDS_COM_SK_CANCEL"));
2328 elm_object_part_content_set(pbar_ly, "elm.icon.1", cancel_btn);
2329 evas_object_show(cancel_btn);
2330 evas_object_smart_callback_add(cancel_btn, "clicked", _destroy_down_progress_ex, (void *)index);
2331 debug_log("Cancel button for attachment downloading progress popup: %p", cancel_btn);
2333 /* packing progress layout */
2334 if (p_type == EMAIL_VIEWER_PROGRESSBAR_ATT && prop->real_att_len > 1) {
2335 for (i = 0; i < prop->att_len; i++) {
2336 info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, attachment_list);
2337 if (info && !info->inline_content) {
2339 if (ug_data->attach_ex_ly != NULL && ug_data->attach_ex_ly[j] != NULL) {
2341 elm_box_pack_after(ug_data->main_bx, pbar_ly, ug_data->attach_ex_ly[j]);
2342 elm_box_unpack(ug_data->main_bx, ug_data->attach_ex_ly[j]);
2343 evas_object_hide(ug_data->attach_ex_ly[j]);
2344 ug_data->attach_ex_ly[j] = pbar_ly;
2351 if ((p_type == EMAIL_VIEWER_PROGRESSBAR_ATT && prop->real_att_len == 1) || (p_type == EMAIL_VIEWER_PROGRESSBAR_ATT_ALL)) {
2353 elm_box_pack_after(ug_data->main_bx, pbar_ly, ug_data->attach_hd_ly);
2354 elm_box_unpack(ug_data->main_bx, ug_data->attach_hd_ly);
2355 evas_object_hide(ug_data->attach_hd_ly);
2356 ug_data->attach_hd_ly = pbar_ly;
2359 elm_object_focus_set(pbar_ly, EINA_TRUE);
2360 elm_scroller_region_show(ug_data->scroller, scr_x, scr_y, scr_w, scr_h);
2363 static void _destroy_down_progress_ex(void *data, Evas_Object *obj, void *event_info)
2368 debug_log("data is NULL");
2372 EmailViewerUGD *ug_data = _g_ug_data;
2373 EmailViewerPrivate *priv = ug_data->email_data;
2374 EmailViewerProp *prop = ug_data->property;
2376 if (!prop || !prop->attachments) {
2390 elm_scroller_region_get(ug_data->scroller, &scr_x, &scr_y, &scr_w, &scr_h);
2391 debug_log("scroller region> x[%d] y[%d] w[%d] h[%d]", scr_x, scr_y, scr_w, scr_h);
2393 GList *attachment_list = prop->attachments;
2394 int index = (int)data;
2397 /* Cancel the download in email-service */
2399 debug_log("index[%d] download_all_cnt[%d] email_handle[%d]", index, priv->download_all_cnt, priv->download_all_email_handle[index]);
2400 if (priv->download_all_email_handle[index] != 0) {
2401 email_engine_stop_working(ug_data->account_id, priv->download_all_email_handle[index]);
2402 priv->download_all_email_handle[index] = 0;
2405 (priv->download_all_cnt)--;
2407 if (priv->download_all_cnt == 0)
2408 priv->b_all_att_save = FALSE;
2409 } else if (index == -1) {
2410 for (i = 0; i < prop->att_len; i++) {
2411 EmailAttachmentType *info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, attachment_list);
2412 if (info && !info->inline_content) {
2413 debug_log("index[%d] download_all_cnt[%d] email_handle[%d]", i, priv->download_all_cnt, priv->download_all_email_handle[i]);
2414 if (priv->download_all_email_handle[i] != 0) {
2415 email_engine_stop_working(ug_data->account_id, priv->download_all_email_handle[i]);
2418 priv->download_all_email_handle[i] = 0;
2420 priv->download_all_cnt = 0;
2421 priv->b_all_att_save = FALSE;
2424 /* upack and delete, pack again */
2426 debug_log("real_att_len:%d", prop->real_att_len);
2427 if (prop->real_att_len == 1) {
2428 debug_log("index[%d]", index);
2429 elm_box_pack_after(ug_data->main_bx, ug_data->attach_hd_bk, ug_data->attach_hd_ly);
2430 elm_box_unpack(ug_data->main_bx, ug_data->attach_hd_ly);
2431 evas_object_del(ug_data->attach_hd_ly);
2432 ug_data->attach_hd_ly = ug_data->attach_hd_bk;
2433 evas_object_show(ug_data->attach_hd_ly);
2434 elm_object_focus_set(ug_data->attach_hd_ly, EINA_TRUE);
2435 ug_data->progress_bar[index + 1] = NULL;
2436 ug_data->progress_bar_ly[index + 1] = NULL;
2437 } else if (prop->real_att_len > 1) {
2438 for (i = 0; i < prop->att_len; i++) {
2439 EmailAttachmentType *info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, attachment_list);
2440 if (info && !info->inline_content) {
2442 debug_log("index[%d]", i);
2443 debug_log("attach_onoff_flag:%d", ug_data->attach_onoff_flag);
2444 if (ug_data->attach_onoff_flag > 0) {
2445 elm_box_pack_after(ug_data->main_bx, ug_data->attach_ex_bk[j], ug_data->attach_ex_ly[j]);
2446 elm_box_unpack(ug_data->main_bx, ug_data->attach_ex_ly[j]);
2447 evas_object_del(ug_data->attach_ex_ly[j]);
2448 ug_data->attach_ex_ly[j] = ug_data->attach_ex_bk[j];
2449 evas_object_show(ug_data->attach_ex_ly[j]);
2450 elm_object_focus_set(ug_data->attach_ex_ly[j], EINA_TRUE);
2451 ug_data->progress_bar[index + 1] = NULL;
2452 ug_data->progress_bar_ly[index + 1] = NULL;
2454 evas_object_del(ug_data->attach_ex_ly[j]);
2455 ug_data->attach_ex_ly[j] = ug_data->attach_ex_bk[j];
2456 ug_data->progress_bar[index + 1] = NULL;
2457 ug_data->progress_bar_ly[index + 1] = NULL;
2464 } else if (index == -1) {
2465 debug_log("index[%d]", index);
2466 elm_box_pack_after(ug_data->main_bx, ug_data->attach_hd_bk, ug_data->attach_hd_ly);
2467 elm_box_unpack(ug_data->main_bx, ug_data->attach_hd_ly);
2468 evas_object_del(ug_data->attach_hd_ly);
2469 ug_data->attach_hd_ly = ug_data->attach_hd_bk;
2470 evas_object_show(ug_data->attach_hd_ly);
2471 elm_object_focus_set(ug_data->attach_hd_ly, EINA_TRUE);
2472 ug_data->progress_bar[index + 1] = NULL;
2473 ug_data->progress_bar_ly[index + 1] = NULL;
2476 elm_scroller_region_show(ug_data->scroller, scr_x, scr_y, scr_w, scr_h);
2478 if (priv && priv->download_all_cnt <= 0) {
2479 if (ug_data->forward_ctr_it)
2480 elm_object_item_disabled_set(ug_data->forward_ctr_it, EINA_FALSE);
2484 static void _create_more_ctxpopup(EmailViewerUGD *ug_data)
2488 debug_log("ug_data is NULL");
2492 EmailViewerProp *prop = ug_data->property;
2493 EMAIL_CONTACT_LIST_INFO_S *contact_list_item = NULL;
2494 contact_list_item = (EMAIL_CONTACT_LIST_INFO_S *)_contact_search_by_email(ug_data, prop->sender);
2496 if (ug_data->con_popup) {
2497 evas_object_del(ug_data->con_popup);
2498 ug_data->con_popup = NULL;
2501 ug_data->con_popup = elm_ctxpopup_add(ug_data->navi_bar);
2502 if (ug_data->con_popup == NULL) {
2503 debug_log("cannot create context popup");
2507 if (contact_list_item) {
2508 debug_log("Contact Item Exist: index[%d]", contact_list_item->index);
2509 char index[10] = { 0, };
2510 snprintf(index, sizeof(index), "%d", contact_list_item->index);
2512 if (email_engine_check_seen_mail(ug_data->account_id, ug_data->mail_id))
2513 elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_MARK_AS_UNREAD"), NULL, _mark_as_unread_cb, ug_data);
2515 elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_MARK_AS_READ"), NULL, _mark_as_read_cb, ug_data);
2517 elm_ctxpopup_item_append(ug_data->con_popup, dgettext("sys_string", "IDS_COM_BODY_MOVE"), NULL, _move_cb, ug_data);
2518 elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_SAVE_EMAIL_ABB"), NULL, _save_email_cb, ug_data);
2519 elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_VIEW_CONTACT"), NULL, _ctxpopup_detail_contact_cb, g_strdup(index));
2520 ug_data->more_ctx_block_item = elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_BLOCK"), NULL, _ctxpopup_add_block_rule_cb, prop->sender);
2522 _delete_contacts_list(contact_list_item);
2524 if (email_engine_check_seen_mail(ug_data->account_id, ug_data->mail_id))
2525 elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_MARK_AS_UNREAD"), NULL, _mark_as_unread_cb, ug_data);
2527 elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_MARK_AS_READ"), NULL, _mark_as_read_cb, ug_data);
2529 elm_ctxpopup_item_append(ug_data->con_popup, dgettext("sys_string", "IDS_COM_BODY_MOVE"), NULL, _move_cb, ug_data);
2530 elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_SAVE_EMAIL_ABB"), NULL, _save_email_cb, ug_data);
2531 elm_ctxpopup_item_append(ug_data->con_popup, dgettext("sys_string", "IDS_COM_OPT_ADD_TO_CONTACTS"), NULL, _ctxpopup_add_contact_cb, prop->sender);
2532 ug_data->more_ctx_block_item = elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_BLOCK"), NULL, _ctxpopup_add_block_rule_cb, prop->sender);
2536 email_rule_t *rule_list = NULL;
2538 /* get the rule list from service */
2539 if (email_get_rule_list(&rule_list, &count) < 0) {
2540 debug_log("email_get_rule_list failed");
2543 for (i = 0; i < count; i++) {
2544 if (rule_list[i].type == EMAIL_FILTER_FROM) {
2545 debug_log("block address %s", rule_list[i].value);
2547 if (g_strcmp0(rule_list[i].value, prop->sender) == 0) {
2548 debug_log("[%s] already blocked", rule_list[i].value);
2549 if (ug_data->more_ctx_block_item)
2550 elm_object_item_disabled_set(ug_data->more_ctx_block_item, EINA_TRUE);
2555 /* free email rule_list */
2556 email_free_rule(&rule_list, count);
2559 Evas_Coord x, y, w, h;
2560 evas_pointer_canvas_xy_get(ug_data->evas, &x, &y);
2561 // evas_object_move(ug_data->con_popup, x, y - 20);
2562 evas_object_geometry_get(ug_data->ctr_bar, &x, &y, &w, &h);
2563 debug_log("x:%d, y:%d, w:%d, h:%d, mx:%d", x, y, w, h, ((w - x) * 6) / 7);
2564 evas_object_move(ug_data->con_popup, ((w - x) * 6) / 7 , y);
2565 evas_object_show(ug_data->con_popup);
2568 static void _create_reply_ctxpopup(EmailViewerUGD *ug_data)
2572 debug_log("ug_data is NULL");
2576 if (ug_data->con_popup) {
2577 evas_object_del(ug_data->con_popup);
2578 ug_data->con_popup = NULL;
2581 ug_data->con_popup = elm_ctxpopup_add(ug_data->navi_bar);
2582 if (ug_data->con_popup == NULL) {
2583 debug_log("cannot create context popup");
2587 elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_TO_SENDER_ABB"), NULL, _reply_cb, ug_data);
2588 elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_TO_ALL_ABB"), NULL, _reply_all_cb, ug_data);
2591 evas_pointer_canvas_xy_get(ug_data->evas, &x, &y);
2592 evas_object_move(ug_data->con_popup, x, y - 20);
2593 evas_object_show(ug_data->con_popup);
2596 static void _delete_evas_objects(EmailViewerUGD *ug_data)
2599 EmailViewerProp *prop = ug_data->property;
2601 if (ug_data->webview) {
2602 evas_object_del(ug_data->webview);
2603 ug_data->webview = NULL;
2606 if (ug_data->webview_bx) {
2607 evas_object_del(ug_data->webview_bx);
2608 ug_data->webview_bx = NULL;
2611 if (ug_data->scroller) {
2612 evas_object_del(ug_data->scroller);
2613 ug_data->scroller = NULL;
2616 if (ug_data->main_bx) {
2617 evas_object_del(ug_data->main_bx);
2618 ug_data->main_bx = NULL;
2621 if (ug_data->b_btn) {
2622 evas_object_del(ug_data->b_btn);
2623 ug_data->b_btn = NULL;
2626 if (ug_data->sub_ly) {
2627 evas_object_del(ug_data->sub_ly);
2628 ug_data->sub_ly = NULL;
2631 if (ug_data->navi_bar) {
2632 evas_object_del(ug_data->navi_bar);
2633 ug_data->navi_bar = NULL;
2636 if (ug_data->ctr_bar) {
2637 evas_object_del(ug_data->ctr_bar);
2638 ug_data->ctr_bar = NULL;
2641 if (ug_data->layout_main) {
2642 evas_object_del(ug_data->layout_main);
2643 ug_data->layout_main = NULL;
2646 if (ug_data->con_popup) {
2647 evas_object_del(ug_data->con_popup);
2648 ug_data->con_popup = NULL;
2651 if (ug_data->select_info) {
2652 evas_object_del(ug_data->select_info);
2653 ug_data->select_info = NULL;
2656 if (ug_data->selectioninfo_layout != NULL) {
2657 evas_object_del(ug_data->selectioninfo_layout);
2658 ug_data->selectioninfo_layout = NULL;
2661 if (ug_data->notify) {
2662 evas_object_del(ug_data->notify);
2663 ug_data->notify = NULL;
2666 if (ug_data->pb_notify) {
2667 evas_object_del(ug_data->pb_notify);
2668 ug_data->pb_notify = NULL;
2671 if (ug_data->pb_notify_lb) {
2672 evas_object_del(ug_data->pb_notify_lb);
2673 ug_data->pb_notify_lb = NULL;
2676 if (ug_data->partial_dn_btn) {
2677 evas_object_del(ug_data->partial_dn_btn);
2678 ug_data->partial_dn_btn = NULL;
2681 if (ug_data->partial_dn_btn_bx) {
2682 evas_object_del(ug_data->partial_dn_btn_bx);
2683 ug_data->partial_dn_btn_bx = NULL;
2686 if (ug_data->waiting_timer) {
2687 ecore_timer_del(ug_data->waiting_timer);
2688 ug_data->waiting_timer = NULL;
2691 if (ug_data->timer) {
2692 ecore_timer_del(ug_data->timer);
2693 ug_data->timer = NULL;
2696 if (ug_data->idler) {
2697 ecore_idler_del(ug_data->idler);
2698 ug_data->idler = NULL;
2701 if (ug_data->got_att) {
2704 evas_object_del(ug_data->attach_hd_bk);
2705 ug_data->attach_hd_ly = NULL;
2706 ug_data->attach_hd_bk = NULL;
2708 if (prop->real_att_len > 1) {
2709 for (i = 0; i < prop->real_att_len; i++) {
2710 if (ug_data->attach_ex_ly != NULL) {
2711 if (ug_data->attach_ex_ly[i] != NULL) {
2712 debug_log("index %d", i);
2713 evas_object_del(ug_data->attach_ex_bk[i]);
2714 ug_data->attach_ex_ly[i] = NULL;
2715 ug_data->attach_ex_bk[i] = NULL;
2720 if (ug_data->attach_ex_ly != NULL) {
2721 free(ug_data->attach_ex_ly);
2722 ug_data->attach_ex_ly = NULL;
2723 ug_data->attach_ex_bk = NULL;
2727 for (i = 0; i <= prop->att_len; i++) {
2728 if (ug_data->progress_bar_ly[i] != NULL) {
2729 evas_object_del(ug_data->progress_bar_ly[i]);
2730 ug_data->progress_bar_ly[i] = NULL;
2731 ug_data->progress_bar[i] = NULL;
2737 void _launch_composer(EmailViewerUGD *ug_data, int type)
2742 debug_log("ug_data is NULL");
2746 EmailViewerPrivate *priv = ug_data->email_data;
2750 service_h service = NULL;
2752 ret = service_create(&service);
2753 debug_log("service_create: %d", ret);
2755 debug_log("service create failed");
2759 char rtype[10] = { 0, };
2760 snprintf(rtype, sizeof(rtype), "%d", type);
2761 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_RUN_TYPE, rtype);
2762 debug_log("service_add_extra_data: %d", ret);
2764 memset(tmp, 0x0, sizeof(tmp));
2765 snprintf(tmp, sizeof(tmp), "%d", priv->account_id);
2766 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_ACCOUNT_ID, tmp);
2767 debug_log("service_add_extra_data: %d", ret);
2769 memset(tmp, 0x0, sizeof(tmp));
2770 snprintf(tmp, sizeof(tmp), "%d", priv->mailbox_id);
2771 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_MAILBOX, tmp);
2772 debug_log("service_add_extra_data: %d", ret);
2774 memset(tmp, 0x0, sizeof(tmp));
2775 snprintf(tmp, sizeof(tmp), "%d", priv->mail_id);
2776 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_MAIL_ID, tmp);
2777 debug_log("service_add_extra_data: %d", ret);
2779 ug_data->ug_composer = create_ug(UG_NAME_EMAIL_COMPOSER, service, ug_data);
2781 ret = service_destroy(service);
2782 debug_log("service_destroy: %d", ret);
2785 static void _back_cb(void *data, Evas_Object *obj, void *event_info)
2789 if (_g_ug_data == NULL) {
2790 debug_log("_g_ug_data is NULL");
2795 debug_log("data is NULL");
2798 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
2800 if (ug_data->con_popup != NULL) {
2801 evas_object_del(ug_data->con_popup);
2802 ug_data->con_popup = NULL;
2805 debug_log("isRoate = %d", ug_data->isRotate);
2806 if (ug_data->isRotate == false && ug_data->b_internal) {
2807 /* Viewer to hide, so set left content (mailbox) size to full */
2808 _notify_mailbox_size(ug_data, "MAILBOX_RESIZE_FULL");
2811 if (ug_data->b_internal != 1) {
2812 debug_log("ug_destory_me");
2813 ug_destroy_me(ug_data->ug);
2815 _hide_view(ug_data);
2819 static void _prev_mail_cb(void *data, Evas_Object *obj, void *event_info)
2823 debug_log("data is NULL");
2827 /* send next or previous mail request to mailbox. */
2829 service_h service = NULL;
2831 ret = service_create(&service);
2832 debug_log("service_create: %d", ret);
2834 debug_log("service create failed");
2838 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_MSG, EMAIL_BUNDLE_VAL_PREV_MSG);
2839 debug_log("service_add_extra_data: %d", ret);
2840 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_DO_DELETE, "0");
2841 debug_log("service_add_extra_data: %d", ret);
2843 ug_send_message(_g_mailbox_ug, service);
2845 ret = service_destroy(service);
2846 debug_log("service_destroy: %d", ret);
2849 static void _next_mail_cb(void *data, Evas_Object *obj, void *event_info)
2853 debug_log("data is NULL");
2857 /* send next or previous mail request to mailbox. */
2859 service_h service = NULL;
2861 ret = service_create(&service);
2862 debug_log("service_create: %d", ret);
2864 debug_log("service create failed");
2868 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_MSG, EMAIL_BUNDLE_VAL_NEXT_MSG);
2869 debug_log("service_add_extra_data: %d", ret);
2870 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_DO_DELETE, "0");
2871 debug_log("service_add_extra_data: %d", ret);
2873 ug_send_message(_g_mailbox_ug, service);
2875 ret = service_destroy(service);
2876 debug_log("service_destroy: %d", ret);
2879 static void _reply_cb(void *data, Evas_Object *obj, void *event_info)
2883 debug_log("data is NULL");
2887 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
2889 if (ug_data->con_popup) {
2890 evas_object_del(ug_data->con_popup);
2891 ug_data->con_popup = NULL;
2894 ug_data->display_download_result = FALSE;
2896 _launch_composer(ug_data, RUN_COMPOSER_REPLY);
2898 if (ug_data->notify) {
2899 evas_object_del(ug_data->notify);
2900 ug_data->notify = NULL;
2904 static void _reply_all_cb(void *data, Evas_Object *obj, void *event_info)
2908 debug_log("data is NULL");
2912 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
2914 if (ug_data->con_popup) {
2915 evas_object_del(ug_data->con_popup);
2916 ug_data->con_popup = NULL;
2919 ug_data->display_download_result = FALSE;
2921 _launch_composer(ug_data, RUN_COMPOSER_REPLY_ALL);
2923 if (ug_data->notify) {
2924 evas_object_del(ug_data->notify);
2925 ug_data->notify = NULL;
2929 static void _reply_option_cb(void *data, Evas_Object *obj, void *event_info)
2933 debug_log("data is NULL");
2937 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
2939 _create_reply_ctxpopup(ug_data);
2942 static void _forward_cb(void *data, Evas_Object *obj, void *event_info)
2946 debug_log("data is NULL");
2950 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
2952 ug_data->display_download_result = FALSE;
2954 _launch_composer(ug_data, RUN_COMPOSER_FORWARD);
2957 static void _resend_cb(void *data, Evas_Object *obj, void *event_info)
2962 static void _delete_cb(void *data, Evas_Object *obj, void *event_info)
2966 debug_log("data is NULL");
2970 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
2972 if (ug_data->con_popup) {
2973 evas_object_del(ug_data->con_popup);
2974 ug_data->con_popup = NULL;
2977 _create_notify(ug_data, NULL, dgettext("sys_string", "IDS_COM_POP_DELETE_Q"),
2978 2, dgettext("sys_string", "IDS_COM_SK_DELETE"),
2979 _popup_response_delete_ok_cb, dgettext("sys_string", "IDS_COM_SK_CANCEL"),
2980 _popup_response_cb, NULL);
2983 static void _move_cb(void *data, Evas_Object *obj, void *event_info)
2987 debug_log("data is NULL");
2991 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
2992 EmailViewerPrivate *priv = ug_data->email_data;
2994 if (ug_data->con_popup) {
2995 evas_object_del(ug_data->con_popup);
2996 ug_data->con_popup = NULL;
2999 Evas_Object *gl = elm_genlist_add(ug_data->navi_bar);
3000 evas_object_show(gl);
3002 ug_data->itc1.item_style = "1text.1icon.2";
3003 ug_data->itc1.func.text_get = _gl_text_get;
3004 ug_data->itc1.func.content_get = _gl_content_get;
3005 ug_data->itc1.func.state_get = _gl_state_get;
3006 ug_data->itc1.func.del = _gl_del;
3008 Elm_Object_Item *navi_it = NULL;
3009 navi_it = elm_naviframe_item_push(ug_data->navi_bar, dgettext("sys_string", "IDS_COM_BODY_MOVE"), NULL, NULL, gl, NULL);
3010 ug_data->navi_move_it1 = navi_it;
3011 if (ug_data->isRotate)
3012 elm_naviframe_item_title_visible_set(ug_data->navi_move_it1, EINA_FALSE);
3014 email_mailbox_t *mailbox_list = NULL;
3015 int mailbox_count = 0;
3018 email_get_mailbox_list(priv->account_id, -1, &mailbox_list, &mailbox_count);
3019 debug_log("folder count %d", mailbox_count);
3020 ug_data->move_mailbox_list = mailbox_list;
3021 ug_data->move_mailbox_count = mailbox_count;
3023 for (i = 0; i < mailbox_count; i++) {
3024 if (g_strcmp0(ug_data->mailbox_name, mailbox_list[i].mailbox_name) != 0) {
3025 if (mailbox_list[i].mailbox_type != EMAIL_MAILBOX_TYPE_OUTBOX &&
3026 mailbox_list[i].mailbox_type != EMAIL_MAILBOX_TYPE_SENTBOX &&
3027 mailbox_list[i].mailbox_type != EMAIL_MAILBOX_TYPE_DRAFT &&
3028 mailbox_list[i].mailbox_type != EMAIL_MAILBOX_TYPE_TRASH &&
3029 mailbox_list[i].mailbox_type != EMAIL_MAILBOX_TYPE_ALL_EMAILS &&
3030 mailbox_list[i].mailbox_type != EMAIL_MAILBOX_TYPE_SEARCH_RESULT)
3031 if (g_strcmp0(mailbox_list[i].alias, "[Gmail]")) {
3032 elm_genlist_item_append(gl, &ug_data->itc1, (void *)&(mailbox_list[i]), NULL, ELM_GENLIST_ITEM_NONE, _move_here_cb, (void *)&(mailbox_list[i]));
3037 /*if (ug_data->b_internal)
3038 elm_layout_theme_set(ug_data->layout_main, "layout", "application", "noindicator");
3040 elm_layout_theme_set(ug_data->layout_main, "layout", "application", "default");*/
3042 Evas_Object *move_back_btn = NULL;
3043 if (ug_data->isRotate) {
3044 ug_data->move_cbar = elm_toolbar_add(ug_data->navi_bar);
3045 elm_toolbar_shrink_mode_set(ug_data->move_cbar, ELM_TOOLBAR_SHRINK_EXPAND);
3046 elm_object_style_set(ug_data->move_cbar, "naviframe");
3047 evas_object_show(ug_data->move_cbar);
3049 elm_object_item_disabled_set(elm_toolbar_item_append(ug_data->move_cbar, NULL, "", NULL, NULL), EINA_TRUE);
3050 elm_toolbar_item_append(ug_data->move_cbar, NULL, dgettext("sys_string", "IDS_COM_SK_CANCEL"), _move_back_cb, ug_data);
3051 elm_object_item_part_content_set(navi_it, "controlbar", ug_data->move_cbar);
3053 move_back_btn = elm_object_item_part_content_get(navi_it, "prev_btn");
3054 if (move_back_btn) {
3055 evas_object_del(move_back_btn);
3056 elm_object_item_part_content_set(navi_it, "prev_btn", NULL);
3059 move_back_btn = elm_object_item_part_content_get(navi_it, "prev_btn");
3060 if (move_back_btn) {
3061 evas_object_del(move_back_btn);
3062 move_back_btn = elm_button_add(ug_data->navi_bar);
3063 elm_object_style_set(move_back_btn, "naviframe/back_btn/default");
3064 evas_object_smart_callback_add(move_back_btn, "clicked", _move_back_cb, ug_data);
3065 elm_object_item_part_content_set(navi_it, "prev_btn", move_back_btn);
3070 static void _more_cb(void *data, Evas_Object *obj, void *event_info)
3074 debug_log("data is NULL");
3078 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
3080 _create_more_ctxpopup(ug_data);
3083 static void _body_down_cb(void *data, Evas_Object *obj, void *event_info)
3087 debug_log("data is NULL");
3093 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
3094 EmailViewerPrivate *priv = ug_data->email_data;
3096 /* check already downloaded */
3097 int body_download_status = ug_data->property->body_download;
3099 if (body_download_status == 0) { //EMAIL_BODY_DOWNLOAD_STATUS_NONE
3100 debug_log("only header downloaded -> need body download");
3101 } else if (body_download_status == 1) { //EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED
3102 debug_log("already downloaded fully, create body directly");
3105 if (viewer_get_internal_mail_info(ug_data->property, ug_data->email_data)) {
3107 viewer_make_internal_mail(ug_data->property, ug_data->email_data);
3110 if (ug_data->b_partial_body) {
3115 elm_scroller_region_get(ug_data->scroller, &scr_x, &scr_y, &scr_w, &scr_h);
3116 debug_log("scroller region> x[%d] y[%d] w[%d] h[%d]", scr_x, scr_y, scr_w, scr_h);
3118 elm_box_unpack(ug_data->main_bx, ug_data->partial_dn_btn_bx);
3119 if (ug_data->partial_dn_btn) {
3120 evas_object_del(ug_data->partial_dn_btn);
3121 ug_data->partial_dn_btn = NULL;
3123 if (ug_data->partial_dn_btn_bx) {
3124 evas_object_del(ug_data->partial_dn_btn_bx);
3125 ug_data->partial_dn_btn_bx = NULL;
3128 if (ug_data->property->has_html) {
3129 ug_data->webview_data->body_type = BODY_TYPE_HTML;
3130 ug_data->webview_data->uri = ug_data->property->body_uri;
3132 ug_data->webview_data->body_type = BODY_TYPE_TEXT;
3133 ug_data->webview_data->text_content = ug_data->property->body;
3136 viewer_set_webview_content(ug_data, 1);
3137 ug_data->b_partial_body = 0;
3139 elm_object_focus_set(ug_data->ly_subject, EINA_TRUE);
3140 elm_scroller_region_show(ug_data->scroller, scr_x, scr_y, scr_w, scr_h);
3142 if (ug_data->property->has_attachment)
3143 ug_data->got_att = 1;
3145 ug_data->got_att = 0;
3147 /* pack attachment if it exist */
3148 if (ug_data->got_att) {
3149 _create_attach(ug_data);
3152 _create_body(ug_data);
3156 } else if (body_download_status == 2) { //EMAILL_BODY_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED
3157 debug_log("body downloaded partially -> need full body download");
3160 ret = email_engine_body_download(priv->account_id, priv->mail_id, &handle);
3163 priv->email_handle = handle;
3164 debug_log("succeed in email_engine_body_download");
3165 _create_down_progress(dgettext("sys_string", "IDS_COM_POP_DOWNLOADING"), _destroy_down_progress_cb);
3167 /* If attachment download is in progress, first cancel to attachment download of the mail and then carry out body download */
3168 _cancel_download_attachment(ug_data);
3171 debug_log("unable to download mail body");
3172 _create_notify(ug_data, dgettext("sys_string", "IDS_COM_POP_WARNING"),
3173 _("IDS_EMAIL_POP_UNABLE_TO_DOWNLOAD"), 1,
3174 dgettext("sys_string", "IDS_COM_SK_OK"),
3175 _popup_response_cb, NULL, NULL, NULL);
3179 static void _subject_favorite_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
3183 debug_log("data is NULL");
3187 EmailViewerUGD *ug_data = _g_ug_data;
3188 EmailViewerProp *prop = ug_data->property;
3189 int err = EMAIL_ERROR_NONE;
3191 if (ug_data->con_popup) {
3192 evas_object_del(ug_data->con_popup);
3193 ug_data->con_popup = NULL;
3196 debug_log("Before prop->favorite: %d", prop->favorite);
3197 switch(prop->favorite) {
3198 case EMAIL_FLAG_NONE:
3199 prop->favorite = EMAIL_FLAG_FLAGED;
3201 case EMAIL_FLAG_FLAGED:
3202 prop->favorite = EMAIL_FLAG_NONE;
3204 case EMAIL_FLAG_TASK_STATUS_CLEAR:
3205 prop->favorite = EMAIL_FLAG_TASK_STATUS_ACTIVE;
3207 case EMAIL_FLAG_TASK_STATUS_ACTIVE:
3208 prop->favorite = EMAIL_FLAG_TASK_STATUS_COMPLETE;
3210 case EMAIL_FLAG_TASK_STATUS_COMPLETE:
3211 prop->favorite = EMAIL_FLAG_TASK_STATUS_CLEAR;
3214 debug_log("Never here");
3216 debug_log("After prop->favorite: %d", prop->favorite);
3218 err = email_set_flags_field(ug_data->account_id, &ug_data->mail_id, 1, EMAIL_FLAGS_FLAGGED_FIELD, prop->favorite, 1);
3219 if (err != EMAIL_ERROR_NONE) {
3220 _create_notify(ug_data, _("IDS_EMAIL_POP_ALERT"),
3221 N_("Failed to set favourite"), 0,
3222 NULL, NULL, NULL, NULL, _popup_response_cb);
3226 evas_object_del(elm_object_part_content_unset(ug_data->ly_subject, "elm.icon.favorite"));
3227 Evas_Object *favorite_icon = elm_icon_add(ug_data->ly_subject);
3228 switch(prop->favorite)
3230 case EMAIL_FLAG_NONE:
3231 elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_icon_favorite_off.png", NULL);
3233 case EMAIL_FLAG_FLAGED:
3234 elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_icon_favorite_on.png", NULL);
3236 case EMAIL_FLAG_TASK_STATUS_CLEAR:
3237 elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_Flag_Clear.png", NULL);
3239 case EMAIL_FLAG_TASK_STATUS_ACTIVE:
3240 elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_Flag_Active.png", NULL);
3242 case EMAIL_FLAG_TASK_STATUS_COMPLETE:
3243 elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_Flag_Complete.png", NULL);
3246 debug_log("Never here");
3248 evas_object_size_hint_aspect_set(favorite_icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
3249 elm_icon_resizable_set(favorite_icon, 1, 1);
3250 elm_object_part_content_set(ug_data->ly_subject, "elm.icon.favorite", favorite_icon);
3251 evas_object_show(favorite_icon);
3254 static void _subject_detail_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
3258 debug_log("data is NULL");
3262 Evas_Object *item = (Evas_Object *)data;
3263 EmailViewerUGD *ug_data = _g_ug_data;
3265 if (!(ug_data->subject_onoff_flag)) {
3266 edje_object_signal_emit(_EDJ(item), "elm,state,expanded", "elm");
3267 (ug_data->subject_onoff_flag)++;
3269 _create_to_addrs(ug_data);
3270 _create_cc_addrs(ug_data);
3271 _create_bcc_addrs(ug_data);
3273 edje_object_signal_emit(_EDJ(item), "elm,state,contracted", "elm");
3274 (ug_data->subject_onoff_flag)--;
3276 if (ug_data->to_ly) {
3277 elm_box_unpack(ug_data->main_bx, ug_data->to_ly);
3278 evas_object_del(ug_data->to_ly);
3279 ug_data->to_ly = NULL;
3281 if (ug_data->cc_ly) {
3282 elm_box_unpack(ug_data->main_bx, ug_data->cc_ly);
3283 evas_object_del(ug_data->cc_ly);
3284 ug_data->cc_ly = NULL;
3286 if (ug_data->bcc_ly) {
3287 elm_box_unpack(ug_data->main_bx, ug_data->bcc_ly);
3288 evas_object_del(ug_data->bcc_ly);
3289 ug_data->bcc_ly = NULL;
3292 elm_object_focus_set(ug_data->ly_subject, EINA_TRUE);
3296 static void _attachment_item_collapse_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
3299 if (!data || !_g_ug_data) {
3300 debug_log("data is NULL");
3304 Evas_Object *item = (Evas_Object *)data;
3305 EmailViewerUGD *ug_data = _g_ug_data;
3306 EmailViewerProp *prop = ug_data->property;
3309 debug_log("attach_onoff_flag:%d", ug_data->attach_onoff_flag);
3310 if (!(ug_data->attach_onoff_flag)) {
3311 debug_log("attachments expanded");
3312 edje_object_signal_emit(_EDJ(item), "elm,state,expanded", "elm");
3313 (ug_data->attach_onoff_flag)++;
3315 if (ug_data->attach_ex_ly == NULL)
3316 _create_attach_ex(ug_data);
3318 for (i = 0; i < prop->real_att_len; i++) {
3319 debug_log("index %d", i);
3320 elm_box_pack_after(ug_data->main_bx, ug_data->attach_ex_ly[i], ug_data->attach_hd_ly);
3321 evas_object_show(ug_data->attach_ex_ly[i]);
3325 debug_log("attachments contracted");
3326 edje_object_signal_emit(_EDJ(item), "elm,state,contracted", "elm");
3327 ug_data->attach_onoff_flag = 0;
3329 for (i = 0; i < prop->real_att_len; i++) {
3330 if (ug_data->attach_ex_ly[i] != NULL) {
3331 debug_log("index %d", i);
3332 elm_box_unpack(ug_data->main_bx, ug_data->attach_ex_ly[i]);
3333 evas_object_hide(ug_data->attach_ex_ly[i]);
3339 static void _attachment_save_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
3344 debug_log("ug_data is NULL");
3348 EmailViewerUGD *ug_data = _g_ug_data;
3349 int att_index = (int)data;
3351 ug_data->display_download_result = FALSE;
3353 debug_log("Selected item index = %d", att_index);
3354 _show_attachment(ug_data, att_index);
3357 static void _attachment_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
3362 debug_log("ug_data is NULL");
3366 EmailViewerUGD *ug_data = _g_ug_data;
3367 int att_index = (int)data;
3369 debug_log("Selected item index = %d", att_index);
3370 ug_data->display_download_result = TRUE;
3371 _show_attachment(ug_data, att_index);
3374 static void _attachment_save_all_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
3378 debug_log("ug_data is NULL");
3382 EmailViewerUGD *ug_data = _g_ug_data;
3384 _save_attachment_all(ug_data);
3387 static void _attachment_bg_set_cb(void *data, Evas * evas, Evas_Object *obj, void *event_info)
3391 debug_log("ug_data is NULL");
3395 EmailViewerUGD *ug_data = _g_ug_data;
3396 EmailViewerProp *prop = ug_data->property;
3398 int att_index = (int)data;
3399 debug_log("att_index = %d, attachments count = %d", att_index, prop->real_att_len);
3401 if (prop->real_att_len > 1) {
3404 GList *attachment_list = prop->attachments;
3405 LIST_ITER_START(i, attachment_list) {
3406 EmailAttachmentType *info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, attachment_list);
3407 if (info && !info->inline_content) {
3413 edje_object_signal_emit(_EDJ(ug_data->attach_ex_ly[j]), "pressed", "elm.event.rect");
3416 edje_object_signal_emit(_EDJ(ug_data->attach_hd_ly), "pressed", "elm.event.rect");
3419 static void _attachment_bg_unset_cb(void *data, Evas * evas, Evas_Object *obj, void *event_info)
3423 debug_log("ug_data is NULL");
3427 EmailViewerUGD *ug_data = _g_ug_data;
3428 EmailViewerProp *prop = ug_data->property;
3430 int att_index = (int)data;
3431 debug_log("att_index = %d, attachments count = %d", att_index, prop->real_att_len);
3433 if (prop->real_att_len > 1) {
3436 GList *attachment_list = prop->attachments;
3437 LIST_ITER_START(i, attachment_list) {
3438 EmailAttachmentType *info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, attachment_list);
3439 if (info && !info->inline_content) {
3445 edje_object_signal_emit(_EDJ(ug_data->attach_ex_ly[j]), "unpressed", "elm.event.rect");
3448 edje_object_signal_emit(_EDJ(ug_data->attach_hd_ly), "unpressed", "elm.event.rect");
3451 static void _mark_as_unread_cb(void *data, Evas_Object *obj, void *event_info)
3455 debug_log("data is NULL");
3459 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
3460 EmailViewerPrivate *priv = ug_data->email_data;
3462 if (ug_data->con_popup) {
3463 evas_object_del(ug_data->con_popup);
3464 ug_data->con_popup = NULL;
3468 debug_log("ug_data->mail_id(%d), priv->mail_id(%d), mail_info->mail_id(%d))", ug_data->mail_id, priv->mail_id, priv->mail_info->mail_id);
3470 err = email_set_flags_field(ug_data->account_id, &ug_data->mail_id, 1, EMAIL_FLAGS_SEEN_FIELD, 0, 1);
3471 debug_log("email_set_flags_field - err(%d)", err);
3473 if (err != EMAIL_ERROR_NONE) {
3474 _create_notify(ug_data, _("IDS_EMAIL_POP_ALERT"),
3475 _("IDS_EMAIL_POP_FAILED_TO_MARK_AS_UNREAD"), 0,
3476 NULL, NULL, NULL, NULL, _popup_response_cb);
3478 char str[128] = { 0, };
3479 snprintf(str, sizeof(str), "%s", _("IDS_EMAIL_POP_MARKED_AS_UNREAD"));
3480 _show_select_info(ug_data, str);
3484 static void _mark_as_read_cb(void *data, Evas_Object *obj, void *event_info)
3488 debug_log("data is NULL");
3492 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
3493 EmailViewerPrivate *priv = ug_data->email_data;
3495 if (ug_data->con_popup) {
3496 evas_object_del(ug_data->con_popup);
3497 ug_data->con_popup = NULL;
3501 debug_log("ug_data->mail_id(%d), priv->mail_id(%d), mail_info->mail_id(%d))", ug_data->mail_id, priv->mail_id, priv->mail_info->mail_id);
3503 err = email_set_flags_field(priv->mail_info->account_id, &ug_data->mail_id, 1, EMAIL_FLAGS_SEEN_FIELD, 1, 1);
3504 debug_log("email_set_flags_field - err(%d)", err);
3506 if (err != EMAIL_ERROR_NONE) {
3507 _create_notify(ug_data, _("IDS_EMAIL_POP_ALERT"),
3508 _("IDS_EMAIL_POP_FAILED_TO_MARK_AS_READ"), 0,
3509 NULL, NULL, NULL, NULL, _popup_response_cb);
3511 char str[128] = { 0, };
3512 snprintf(str, sizeof(str), "%s", _("IDS_EMAIL_POP_MARKED_AS_READ"));
3513 _show_select_info(ug_data, str);
3517 static void _create_waiting_popup(EmailViewerUGD *ug_data, const char *title_text, const char *style)
3520 if (title_text == NULL) {
3521 debug_log("popup text is null");
3525 Evas_Object *popup = elm_popup_add(ug_data->win_main);
3526 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
3527 elm_object_part_text_set(popup, "title,text", title_text);
3529 Evas_Object *progress = elm_progressbar_add(popup);
3530 elm_object_style_set(progress, style);
3531 elm_progressbar_pulse_set(progress, EINA_TRUE);
3532 elm_progressbar_pulse(progress, EINA_TRUE);
3533 evas_object_show(progress);
3535 elm_object_content_set(popup, progress);
3537 Evas_Object *btn1 = elm_button_add(popup);
3538 elm_object_style_set(btn1, "popup_button/default");
3539 elm_object_text_set(btn1, dgettext("sys_string", "IDS_COM_SK_CANCEL"));
3540 elm_object_part_content_set(popup, "button1", btn1);
3541 evas_object_smart_callback_add(btn1, "clicked", _popup_waiting_response_cb, ug_data);
3543 ug_data->timeout_popup = popup;
3545 evas_object_show(popup);
3548 static void _save_email_cb(void *data, Evas_Object *obj, void *event_info)
3552 debug_log("data is NULL");
3556 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
3558 if (ug_data->con_popup) {
3559 evas_object_del(ug_data->con_popup);
3560 ug_data->con_popup = NULL;
3563 if (ug_data->timeout_popup) {
3564 evas_object_del(ug_data->timeout_popup);
3565 ug_data->timeout_popup = NULL;
3567 _create_waiting_popup(ug_data, dgettext("sys_string", "IDS_COM_POP_SAVING_ING"), "pending_list"); //"list_process"
3569 if (ug_data->waiting_timer) {
3570 ecore_timer_del(ug_data->waiting_timer);
3571 ug_data->waiting_timer = NULL;
3573 ug_data->waiting_timer = ecore_timer_add(0.2, _save_email_prog_cb, ug_data);
3576 static Eina_Bool _save_email_prog_cb(void *data)
3580 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
3583 debug_log("ug_data->mail_id(%d), priv->mail_id(%d), mail_info->mail_id(%d))", ug_data->mail_id, ug_data->email_data->mail_id, ug_data->email_data->mail_info->mail_id);
3585 email_mail_data_t *mail_t = NULL;
3586 err = email_get_mail_data(ug_data->email_data->mail_id, &mail_t);
3587 debug_log("email_get_mail_data - err (%d)", err);
3589 if (mail_t == NULL) {
3590 debug_log("mail_t is NULL");
3594 email_attachment_data_t *attachment_t = NULL;
3595 int attachment_count = 0;
3596 err = email_get_attachment_data_list(ug_data->email_data->mail_id, &attachment_t, &attachment_count);
3597 debug_log("email_get_attachment_data_list - err (%d)", err);
3599 char file_name[MAX_PATH_LEN] = { 0, };
3600 snprintf(file_name, sizeof(file_name), "%s_%d_%d.%s", DIR_DEFAULT_MEDIA_PHONE"/Downloads/email", ug_data->account_id, ug_data->mail_id, "eml");
3601 char *output_file_path = g_strdup(file_name);
3602 debug_log("output_file_path(%s)", file_name, output_file_path);
3604 err = email_write_mime_file(mail_t, attachment_t, attachment_count, &output_file_path);
3605 debug_log("email_write_mime_file - err(%d)", err);
3607 g_free(output_file_path);
3610 email_free_mail_data(&(mail_t), 1);
3614 if (attachment_t && attachment_count > 0) {
3615 email_free_attachment_data(&(attachment_t), attachment_count);
3616 attachment_t = NULL;
3617 attachment_count = 0;
3620 if (ug_data->timeout_popup) {
3621 evas_object_del(ug_data->timeout_popup);
3622 ug_data->timeout_popup = NULL;
3625 if (err != EMAIL_ERROR_NONE) {
3626 _create_notify(ug_data, _("IDS_EMAIL_POP_ALERT"),
3627 dgettext("sys_string", "IDS_COM_POP_UNABLE_TO_SAVE"), 0,
3628 NULL, NULL, NULL, NULL, _popup_response_cb);
3631 char str[128] = { 0, };
3632 snprintf(str, sizeof(str), "%s", N_("Saved in My files"));
3633 int ret = status_message_post(str);
3635 debug_log("status_message_post failed: %d", ret);
3637 _create_notify(ug_data, dgettext("sys_string", "IDS_COM_OPT_INFORMATION"),
3638 N_("Saved in My files"), 0,
3639 NULL, NULL, NULL, NULL, _popup_response_cb);
3643 if (ug_data->waiting_timer) {
3644 ecore_timer_del(ug_data->waiting_timer);
3645 ug_data->waiting_timer = NULL;
3651 static void _ctxpopup_detail_contact_cb(void *data, Evas_Object *obj, void *event_info)
3654 if (data == NULL || _g_ug_data == NULL) {
3655 debug_log("data is NULL");
3659 EmailViewerUGD *ug_data = _g_ug_data;
3661 if (ug_data->con_popup) {
3662 evas_object_del(ug_data->con_popup);
3663 ug_data->con_popup = NULL;
3666 char *index = (char *)data;
3667 char type[10] = { 0, };
3669 service_h service = NULL;
3671 ret = service_create(&service);
3672 debug_log("service_create: %d", ret);
3674 debug_log("service create failed");
3678 snprintf(type, sizeof(type), "%d", CT_UG_REQUEST_DETAIL);
3680 ret = service_add_extra_data(service, CT_UG_BUNDLE_TYPE, type);
3681 debug_log("service_add_extra_data: %d", ret);
3682 ret = service_add_extra_data(service, CT_UG_BUNDLE_ID, index);
3683 debug_log("service_add_extra_data: %d", ret);
3685 create_ug(UG_CONTACTS_DETAILS, service, ug_data);
3687 ret = service_destroy(service);
3688 debug_log("service_destroy: %d", ret);
3690 debug_log("set flag for contact ug");
3691 ug_data->b_contact_ug_launched = TRUE;
3694 static void _ctxpopup_send_email_cb(void *data, Evas_Object *obj, void *event_info)
3697 if (!data || !_g_ug_data) {
3698 debug_log("data is NULL");
3702 EmailViewerUGD *ug_data = _g_ug_data;
3704 if (ug_data->con_popup == NULL) {
3705 debug_log("con_popup is NULL");
3709 if (ug_data->con_popup) {
3710 evas_object_del(ug_data->con_popup);
3711 ug_data->con_popup = NULL;
3714 debug_log("email: %s", (char *)data);
3717 service_h service = NULL;
3719 ret = service_create(&service);
3720 debug_log("service_create: %d", ret);
3722 debug_log("service create failed");
3726 char rtype[10] = { 0, };
3727 snprintf(rtype, sizeof(rtype), "%d", RUN_COMPOSER_EXTERNAL);
3729 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_RUN_TYPE, rtype);
3730 debug_log("service_add_extra_data: %d", ret);
3731 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_TO, (char *)data);
3732 debug_log("service_add_extra_data: %d", ret);
3733 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_CC, NULL);
3734 debug_log("service_add_extra_data: %d", ret);
3735 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_BCC, NULL);
3736 debug_log("service_add_extra_data: %d", ret);
3737 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_SUBJECT, NULL);
3738 debug_log("service_add_extra_data: %d", ret);
3739 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_BODY, NULL);
3740 debug_log("service_add_extra_data: %d", ret);
3741 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_ATTACHMENT, NULL);
3742 debug_log("service_add_extra_data: %d", ret);
3744 ug_data->ug_composer = create_ug(UG_NAME_EMAIL_COMPOSER, service, ug_data);
3746 ret = service_destroy(service);
3747 debug_log("service_destroy: %d", ret);
3750 static void _ctxpopup_add_contact_cb(void *data, Evas_Object *obj, void *event_info)
3753 if (!data || !_g_ug_data) {
3754 debug_log("data is NULL");
3758 char tmp[MAX_STR_LEN] = { 0, };
3759 EmailViewerUGD *ug_data = _g_ug_data;
3761 if (ug_data->con_popup == NULL) {
3762 debug_log("con_popup is NULL");
3766 if (ug_data->con_popup) {
3767 evas_object_del(ug_data->con_popup);
3768 ug_data->con_popup = NULL;
3772 service_h service = NULL;
3774 ret = service_create(&service);
3775 debug_log("service_create: %d", ret);
3777 debug_log("service create failed");
3781 if (ug_data->create_contact_arg == CONTACTUI_REQ_ADD_PHONE_NUMBER) {
3782 snprintf(tmp, sizeof(tmp), "%d", CT_UG_REQUEST_ADD_WITH_NUM);
3783 ret = service_add_extra_data(service, CT_UG_BUNDLE_TYPE, tmp);
3784 debug_log("service_add_extra_data: %d", ret);
3785 ret = service_add_extra_data(service, CT_UG_BUNDLE_NUM, (char *)data);
3786 debug_log("service_add_extra_data: %d", ret);
3788 if (ug_data->create_contact_arg == CONTACTUI_REQ_ADD_EMAIL) {
3789 snprintf(tmp, sizeof(tmp), "%d", CT_UG_REQUEST_ADD_WITH_EMAIL);
3790 ret = service_add_extra_data(service, CT_UG_BUNDLE_TYPE, tmp);
3791 debug_log("service_add_extra_data: %d", ret);
3792 ret = service_add_extra_data(service, CT_UG_BUNDLE_EMAIL, (char *)data);
3793 debug_log("service_add_extra_data: %d", ret);
3795 if (ug_data->create_contact_arg == CONTACTUI_REQ_ADD_URL) {
3796 snprintf(tmp, sizeof(tmp), "%d", CT_UG_REQUEST_ADD_WITH_WEB);
3797 ret = service_add_extra_data(service, CT_UG_BUNDLE_TYPE, tmp);
3798 debug_log("service_add_extra_data: %d", ret);
3799 ret = service_add_extra_data(service, CT_UG_BUNDLE_WEB, (char *)data);
3800 debug_log("service_add_extra_data: %d", ret);
3803 create_ug(UG_CONTACTS_DETAILS, service, ug_data);
3805 ret = service_destroy(service);
3806 debug_log("service_destroy: %d", ret);
3809 static void _ctxpopup_add_block_rule_cb(void *data, Evas_Object *obj, void *event_info)
3813 if (!data || !_g_ug_data) {
3814 debug_log("data is NULL");
3818 EmailViewerUGD *ug_data = _g_ug_data;
3819 EmailViewerPrivate *priv = ug_data->email_data;
3820 char *addr = (char *)data;
3822 debug_log("Block address: %s", addr);
3824 if (ug_data->con_popup) {
3825 evas_object_del(ug_data->con_popup);
3826 ug_data->con_popup = NULL;
3830 email_rule_t *rule = NULL;
3832 /* add filtering rule */
3833 rule = malloc(sizeof(email_rule_t));
3834 rule->account_id = priv->account_id;
3835 rule->type = EMAIL_FILTER_FROM;
3836 rule->value = g_strdup(addr);
3837 rule->faction = EMAIL_FILTER_BLOCK;
3840 email_mailbox_t *mail_box = NULL;
3841 if ((err = email_get_mailbox_by_mailbox_type(ug_data->account_id, ug_data->mailbox_type, &mail_box)) != EMAIL_ERROR_NONE) {
3842 debug_log("email_get_mailbox_by_mailbox_type failed! - err (%d)", err);
3845 if (mail_box == NULL) {
3846 debug_log("mail_box is NULL");
3849 rule->target_mailbox_id = mail_box->mailbox_id;
3852 debug_log("email_free_mailbox is called");
3853 email_free_mailbox(&mail_box, 1);
3858 rule->flag2 = RULE_TYPE_INCLUDES;
3860 ret = email_add_rule(rule);
3862 debug_log("email_add_rule failed %d", ret);
3863 _create_notify(ug_data, _("IDS_EMAIL_POP_ALERT"),
3864 _("IDS_EMAIL_POP_FAILED_TO_ADD_BLOCK_RULE"), 0,
3865 NULL, NULL, NULL, NULL, _popup_response_cb);
3868 vconf_ret = vconf_set_int(EMAIL_VCONF_KEY_BLOCK_RULE_CHANGED, 1);
3869 if (vconf_ret == -1) {
3870 debug_log("fail to set vconf int(spam_rule_changed)");
3871 _create_notify(ug_data, _("IDS_EMAIL_POP_ALERT"),
3872 _("IDS_EMAIL_POP_FAILED_TO_ADD_BLOCK_RULE"), 0,
3873 NULL, NULL, NULL, NULL, _popup_response_cb);
3875 char str[128] = { 0, };
3876 snprintf(str, sizeof(str), "%s", _("IDS_EMAIL_POP_BLOCKED"));
3877 ret = status_message_post(str);
3879 debug_log("status_message_post failed: %d", ret);
3883 email_free_rule(&rule, 1);
3886 static void _popup_waiting_response_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;
3901 if (ug_data->timeout_popup) {
3902 evas_object_del(ug_data->timeout_popup);
3903 ug_data->timeout_popup = NULL;
3907 static void _popup_response_cb(void *data, Evas_Object *obj, void *event_info)
3911 debug_log("_g_ug_data is NULL");
3916 debug_log("data is NULL");
3920 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
3922 if (ug_data->notify) {
3923 evas_object_del(ug_data->notify);
3924 ug_data->notify = NULL;
3928 static void _popup_response_delete_ok_cb(void *data, Evas_Object *obj, void *event_info)
3932 debug_log("_g_ug_data is NULL");
3937 debug_log("data is NULL");
3941 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
3943 if (ug_data->notify) {
3944 evas_object_del(ug_data->notify);
3945 ug_data->notify = NULL;
3948 if (ug_data->mailbox_type == EMAIL_MAILBOX_TYPE_TRASH)
3949 _delete_email(ug_data);
3951 _move_email(ug_data, _find_folder_id_using_folder_type(ug_data, EMAIL_MAILBOX_TYPE_TRASH), TRUE);
3953 if (ug_data->isRotate == false && ug_data->b_internal) {
3954 _notify_mailbox_size(ug_data, "MAILBOX_RESIZE_FULL");
3958 if (ug_data->b_internal) {
3959 _hide_view(ug_data);
3961 /* send next or previous mail request to mailbox. */
3963 service_h service = NULL;
3965 ret = service_create(&service);
3966 debug_log("service_create: %d", ret);
3968 debug_log("service create failed");
3972 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_MSG, EMAIL_BUNDLE_VAL_NEXT_MSG);
3973 debug_log("service_add_extra_data: %d", ret);
3974 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_DO_DELETE, "1");
3975 debug_log("service_add_extra_data: %d", ret);
3977 ug_send_message(_g_mailbox_ug, service);
3979 ret = service_destroy(service);
3980 debug_log("service_destroy: %d", ret);
3982 ug_destroy_me(ug_data->ug);
3985 static void _popup_response_to_destroy_cb(void *data, Evas_Object *obj, void *event_info)
3989 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
3990 evas_object_del(obj);
3992 ug_data->b_direct_destroy = 1;
3993 ug_destroy_me(ug_data->ug);
3997 static void _webview_multi_up_cb(void *data, Evas * evas, Evas_Object *obj, void *event_info)
4000 if (_g_ug_data == NULL)
4004 debug_log("data is NULL");
4008 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
4010 ug_data->m_is_multi_touch = FALSE;
4012 if (ug_data->scroller_locked) {
4013 ug_data->scroller_locked = FALSE;
4014 debug_log("<<unlock scroller>>");
4015 debug_log("<<lock webview>>");
4019 static void _webview_multi_down_cb(void *data, Evas * evas, Evas_Object *obj, void *event_info)
4022 if (_g_ug_data == NULL)
4026 debug_log("data is NULL");
4030 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
4032 ug_data->m_is_multi_touch = TRUE;
4033 if (ug_data->scroller_locked == FALSE) {
4034 ug_data->scroller_locked = TRUE;
4035 debug_log("<<lock scroller>>");
4036 debug_log("<<unlock webview>>");
4040 static void _webview_policy_navigation_decide_cb(void *data, Evas_Object *obj, void *event_info)
4044 debug_log("data is NULL");
4048 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
4049 Ewk_Policy_Decision *policy_decision = (Ewk_Policy_Decision *)event_info;
4050 Ewk_Policy_Navigation_Type pd_type = ewk_policy_decision_navigation_type_get(policy_decision);
4051 debug_log("Ewk_Policy_Navigation_Type:%d", pd_type);
4053 const char *uri = NULL;
4054 uri = ewk_view_uri_get(ug_data->webview);
4055 debug_log("ewk_view_uri_get(%s)", uri);
4057 if (ug_data->b_load_finished == EINA_TRUE) {
4058 ewk_policy_decision_ignore(policy_decision);
4060 debug_log("url:%s", ewk_policy_decision_url_get(policy_decision));
4061 debug_log("scheme:%s", ewk_policy_decision_scheme_get(policy_decision));
4062 debug_log("cookie:%s", ewk_policy_decision_cookie_get(policy_decision));
4063 debug_log("host:%s", ewk_policy_decision_host_get(policy_decision));
4064 debug_log("response_mime:%s", ewk_policy_decision_response_mime_get(policy_decision));
4066 char *url = (char *)ewk_policy_decision_url_get(policy_decision);
4068 if ((strncmp(url, "http://", 7) == 0) ||
4069 (strncmp(url, "https://", 8) == 0) ||
4070 (strncmp(url, "ftp://", 6) == 0) ||
4071 (strncmp(url, "mms://", 6) == 0) ||
4072 (strncmp(url, "file://", 7) == 0) ||
4073 (strncmp(url, "rtsp://", 7) == 0) ||
4074 (strncmp(url, "wap://", 6) == 0)) {
4076 service_h service = NULL;
4077 ret = service_create(&service);
4078 debug_log("service_create: %d", ret);
4080 debug_log("service create failed");
4083 ret = service_set_operation(service, SERVICE_OPERATION_VIEW);
4084 debug_log("service_set_operation: %d", ret);
4085 ret = service_set_uri(service, url);
4086 debug_log("service_set_uri: %d", ret);
4087 ret = service_send_launch_request(service, NULL, NULL);
4088 debug_log("service_send_launch_request: %d", ret);
4089 ret = service_destroy(service);
4090 debug_log("service_destroy: %d", ret);
4093 if (strncmp(url, "tel:", 4) == 0) {
4094 char refined_num[MAX_STR_LEN] = { 0, };
4097 while (url[i] != '\0') {
4098 if (url[i] >= '0' && url[i] <= '9')
4099 refined_num[j++] = url[i];
4103 char *number = refined_num;
4104 debug_log("number: %s", number);
4107 service_h service = NULL;
4108 char telnum[255] = { 0, };
4109 ret = service_create(&service);
4110 debug_log("service_create: %d", ret);
4112 debug_log("service create failed");
4115 ret = service_set_operation(service, SERVICE_OPERATION_CALL);
4116 debug_log("service_set_operation: %d", ret);
4117 snprintf(telnum, sizeof(telnum), "tel:%s", number); /* Number to make a call */
4118 ret = service_set_uri(service, telnum);
4119 debug_log("service_set_uri: %d", ret);
4120 ret = service_add_extra_data(service, "ctindex", "-1"); /* If you don't know ctindex, you don't have to add it. */
4121 debug_log("service_add_extra_data: %d", ret);
4122 ret = service_send_launch_request(service, NULL, NULL);
4123 debug_log("service_send_launch_request: %d", ret);
4124 ret = service_destroy(service);
4125 debug_log("service_destroy: %d", ret);
4128 if (strncmp(url, "mailto:", 7) == 0) {
4130 service_h service = NULL;
4131 ret = service_create(&service);
4132 debug_log("service_create: %d", ret);
4134 debug_log("service create failed");
4138 char rtype[10] = { 0, };
4139 snprintf(rtype, sizeof(rtype), "%d", RUN_COMPOSER_EXTERNAL);
4141 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_RUN_TYPE, rtype);
4142 debug_log("service_add_extra_data: %d", ret);
4143 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_TO, &url[7]);
4144 debug_log("service_add_extra_data: %d", ret);
4146 ug_data->ug_composer = create_ug(UG_NAME_EMAIL_COMPOSER, service, ug_data);
4148 ret = service_destroy(service);
4149 debug_log("service_destroy: %d", ret);
4152 if (ug_data->timeout_popup) {
4153 evas_object_del(ug_data->timeout_popup);
4154 ug_data->timeout_popup = NULL;
4156 _create_waiting_popup(ug_data, _("IDS_EMAIL_POP_LOADING_CONTENTS_ING"), "list_process");
4158 if (pd_type == EWK_POLICY_NAVIGATION_TYPE_LINK_CLICKED) {
4159 debug_log("Link click is ignored.");
4160 ewk_policy_decision_ignore(policy_decision);
4166 /* Double_Scroller */
4167 static void _outter_scroller_bottom_hit_cb(void *data, Evas_Object *obj, void *event_info)
4171 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
4172 int res = email_engine_check_body_download(ug_data->email_data->mail_id);
4174 if (ug_data->is_main_scroller_scrolling && res != 0) {
4175 debug_log("Main scroller hold push");
4176 elm_object_scroll_freeze_push(ug_data->scroller); //stop
4177 ewk_view_vertical_panning_hold_set(ug_data->webview, EINA_FALSE); //restart
4178 ug_data->is_main_scroller_scrolling = EINA_FALSE;
4179 ug_data->is_webview_scrolling = EINA_TRUE;
4183 static void _outter_scroller_top_hit_cb(void *data, Evas_Object *obj, void *event_info)
4188 static void _outter_scroller_scroll_cb(void *data, Evas_Object *obj, void *event_info)
4191 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
4193 ug_data->is_main_scroller_scrolling = EINA_TRUE;
4196 static void _mbe_focused_cb(void *data, Evas_Object *obj, void *event_info)
4199 Elm_Object_Item *item = elm_multibuttonentry_selected_item_get(obj);
4200 elm_multibuttonentry_item_selected_set(item, EINA_FALSE);
4203 static void _mbe_unfocused_cb(void *data, Evas_Object *obj, void *event_info)
4208 static void _mbe_added_cb(void *data, Evas_Object *obj, void *event_info)
4213 static void _mbe_selected_cb(void *data, Evas_Object *obj, void *event_info)
4216 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
4217 email_address_info_t *addrs_info = NULL;
4218 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
4219 debug_log("selected item:%s", elm_object_item_text_get(item));
4221 addrs_info = elm_object_item_data_get(item);
4224 EMAIL_CONTACT_LIST_INFO_S *contact_list_item = NULL;
4225 contact_list_item = (EMAIL_CONTACT_LIST_INFO_S *)_contact_search_by_email(ug_data, addrs_info->address);
4227 if (ug_data->con_popup != NULL) {
4228 evas_object_del(ug_data->con_popup);
4229 ug_data->con_popup = NULL;
4232 ug_data->con_popup = elm_ctxpopup_add(ug_data->navi_bar);
4233 if (ug_data->con_popup == NULL) {
4234 debug_log("cannot create context popup");
4238 if (contact_list_item) {
4239 debug_log("Contact Item Exist: index[%d]", contact_list_item->index);
4240 char index[10] = { 0, };
4241 snprintf(index, sizeof(index), "%d", contact_list_item->index);
4243 elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_VIEW_CONTACT"), NULL, _ctxpopup_detail_contact_cb, g_strdup(index));
4244 elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_SEND_EMAIL"), NULL, _ctxpopup_send_email_cb, addrs_info->address);
4245 ug_data->ctx_block_item = elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_BLOCK"), NULL, _ctxpopup_add_block_rule_cb, addrs_info->address);
4246 _delete_contacts_list(contact_list_item);
4248 elm_ctxpopup_item_append(ug_data->con_popup, dgettext("sys_string", "IDS_COM_OPT_ADD_TO_CONTACTS"), NULL, _ctxpopup_add_contact_cb, addrs_info->address);
4249 elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_SEND_EMAIL"), NULL, _ctxpopup_send_email_cb, addrs_info->address);
4250 ug_data->ctx_block_item = elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_BLOCK"), NULL, _ctxpopup_add_block_rule_cb, addrs_info->address);
4254 email_rule_t *rule_list = NULL;
4256 /* get the rule list from service */
4257 if (email_get_rule_list(&rule_list, &count) < 0) {
4258 debug_log("email_get_rule_list failed");
4261 for (i = 0; i < count; i++) {
4262 if (rule_list[i].type == EMAIL_FILTER_FROM/*TYPE_BLOCK_ADDRESS*/) {
4263 debug_log("block address %s", rule_list[i].value);
4265 if (g_strcmp0(rule_list[i].value, addrs_info->address) == 0) {
4266 debug_log("[%s] already blocked", rule_list[i].value);
4267 if (ug_data->ctx_block_item)
4268 elm_object_item_disabled_set(ug_data->ctx_block_item, EINA_TRUE);
4273 /* free email rule_list */
4274 email_free_rule(&rule_list, count);
4277 evas_pointer_canvas_xy_get(ug_data->evas, &x, &y);
4278 debug_log("canvas x:%d, y:%d", x, y);
4279 evas_object_move(ug_data->con_popup, x, y);
4280 evas_object_show(ug_data->con_popup);
4283 static void _destroy_down_progress_cb(void *data, Evas_Object *obj, void *event_info)
4288 debug_log("data is NULL");
4292 EmailViewerUGD *ug_data = _g_ug_data;
4293 EmailViewerPrivate *priv = ug_data->email_data;
4295 email_engine_stop_working(ug_data->account_id, priv->email_handle);
4297 if (ug_data->pb_notify) {
4298 evas_object_del(ug_data->pb_notify);
4299 ug_data->pb_notify = NULL;
4302 if (ug_data->pb_notify_lb) {
4303 evas_object_del(ug_data->pb_notify_lb);
4304 ug_data->pb_notify_lb = NULL;
4308 if (priv->att_file_id) {
4309 free(priv->att_file_id);
4310 priv->att_file_id = NULL;
4313 priv->file_size = 0;
4314 priv->attachment_id = -1;
4315 priv->multi_body = FALSE;
4319 static void _init_viewer_data(int account_id, int mail_id, char *srv_mail_id, EmailViewerUGD *ug_data)
4322 EmailViewerPrivate *priv = NULL;
4323 EmailViewerProp *prop = NULL;
4324 email_address_info_list_t *addrs_info_list = NULL;
4326 /* Create Email Viewer Private Structure */
4327 if (ug_data->email_data) {
4328 if (ug_data->email_data->mail_info) {
4329 debug_log("mail_info freed");
4330 email_free_mail_data(&(ug_data->email_data->mail_info), 1);
4331 ug_data->email_data->mail_info = NULL;
4334 if (ug_data->email_data->attachment_info && ug_data->email_data->attachment_count > 0) {
4335 debug_log("attachment_info freed p[%p] n[%d]", ug_data->email_data->attachment_info, ug_data->email_data->attachment_count);
4336 email_free_attachment_data(&(ug_data->email_data->attachment_info), ug_data->email_data->attachment_count);
4337 ug_data->email_data->attachment_info = NULL;
4338 ug_data->email_data->attachment_count = 0;
4341 memset(ug_data->email_data, 0x0, sizeof(EmailViewerPrivate));
4342 priv = ug_data->email_data;
4344 priv = (EmailViewerPrivate *)malloc(sizeof(EmailViewerPrivate));
4345 memset(priv, 0x0, sizeof(EmailViewerPrivate));
4346 ug_data->email_data = priv;
4349 /* Create Email Viewer Property Structure */
4350 if (ug_data->property) {
4351 if (ug_data->property->attachments) {
4353 LIST_ITER_START(i, ug_data->property->attachments) {
4354 EmailAttachmentType *info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, ug_data->property->attachments);
4361 g_list_free(ug_data->property->attachments);
4363 memset(ug_data->property, 0x0, sizeof(EmailViewerProp));
4364 prop = ug_data->property;
4366 prop = (EmailViewerProp *)malloc(sizeof(EmailViewerProp));
4367 memset(prop, 0x0, sizeof(EmailViewerProp));
4368 ug_data->property = prop;
4371 /* Set account ID */
4372 priv->account_id = account_id;
4373 prop->account_id = account_id;
4376 priv->mail_id = mail_id;
4377 prop->mail_id = mail_id;
4379 priv->mailbox_id = ug_data->mailbox_id;
4380 prop->src_box = ug_data->mailbox_name;
4381 debug_log("mailbox_name [%s]", ug_data->mailbox_name);
4383 /* Get mail_info from service, and fill property */
4384 if (viewer_get_internal_mail_info(ug_data->property, ug_data->email_data)) {
4385 viewer_make_internal_mail(ug_data->property, ug_data->email_data);
4388 email_get_address_info_list(priv->mail_id, &addrs_info_list);
4390 if (addrs_info_list) {
4391 ug_data->from_list = addrs_info_list->from;
4392 ug_data->to_list = addrs_info_list->to;
4393 ug_data->cc_list = addrs_info_list->cc;
4394 ug_data->bcc_list = addrs_info_list->bcc;
4395 priv->addrs_info_list = addrs_info_list;
4398 ug_data->option_header_opened = 0;
4401 static int _init_webview_data(EmailViewerUGD *ug_data)
4405 EmailViewerWebview *wvd;
4407 if (ug_data->webview_data == NULL) {
4408 wvd = (EmailViewerWebview *)malloc(sizeof(EmailViewerWebview));
4409 memset(wvd, 0x0, sizeof(EmailViewerWebview));
4410 ug_data->webview_data = wvd;
4413 if (STR_VALID(ug_data->property->charset)) {
4414 ug_data->webview_data->charset = g_strdup(ug_data->property->charset);
4415 debug_log("charset:%s", ug_data->webview_data->charset);
4417 ug_data->webview_data->charset = DEFAULT_CHARSET;
4418 debug_log("charset:%s", ug_data->webview_data->charset);
4424 static Eina_Bool _check_body_download(void *data)
4428 debug_log("data is NULL");
4429 return ECORE_CALLBACK_CANCEL;
4432 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
4434 _create_tab_bar(ug_data);
4436 /* check mail body downloaded */
4437 int body_download_status = ug_data->property->body_download;
4439 if (body_download_status == 0) { //EMAIL_BODY_DOWNLOAD_STATUS_NONE
4440 debug_log("need body download");
4441 ug_data->b_noc = 1; /* Double_Scroller */
4443 if (ug_data->noc_bx) {
4444 debug_log("no content layout exist");
4445 evas_object_show(ug_data->noc_bx);
4446 elm_object_text_set(ug_data->dn_btn, _("IDS_EMAIL_BODY_DOWNLOAD_MESSAGE"));
4447 evas_object_show(ug_data->dn_btn);
4448 elm_box_pack_end(ug_data->main_bx, ug_data->noc_bx);
4450 /* add body download button */
4451 ug_data->noc_bx = _load_edj(ug_data->navi_bar, EV_THEME_PATH, "layout.email.no_content");
4452 if (ug_data->noc_bx == NULL) {
4453 debug_log("Cannot load edj");
4454 return ECORE_CALLBACK_CANCEL;
4457 evas_object_size_hint_align_set(ug_data->noc_bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
4458 evas_object_size_hint_weight_set(ug_data->noc_bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
4459 evas_object_show(ug_data->noc_bx);
4460 elm_box_pack_end(ug_data->main_bx, ug_data->noc_bx);
4462 Evas_Object *dn_btn = elm_button_add(ug_data->navi_bar);
4463 /*elm_object_theme_set(dn_btn, ug_data->theme);*/
4464 elm_object_style_set(dn_btn, "text_only/style2");
4465 elm_object_text_set(dn_btn, _("IDS_EMAIL_BODY_DOWNLOAD_MESSAGE"));
4466 evas_object_smart_callback_add(dn_btn, "clicked", _body_down_cb, (void *)ug_data);
4467 evas_object_show(dn_btn);
4468 ug_data->dn_btn = dn_btn;
4470 elm_object_part_content_set(ug_data->noc_bx, "btn", ug_data->dn_btn);
4471 debug_log("no content layout created");
4474 elm_object_focus_set(ug_data->noc_bx, EINA_TRUE);
4475 if (ug_data->timer) {
4476 ecore_timer_del(ug_data->timer);
4477 ug_data->timer = NULL;
4480 ug_data->timer = ecore_timer_add(0.0, viewer_send_message, ug_data);
4481 } else if (body_download_status == 1) { //EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED
4482 debug_log("check mail downloaded - ok");
4484 _create_body(ug_data);
4485 } else if (body_download_status == 2) { //EMAIL_BODY_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED
4487 debug_log("Partial Body");
4488 ug_data->b_partial_body = 1;
4489 _create_body(ug_data);
4490 _create_partial_body_dn_btn(ug_data);
4493 return ECORE_CALLBACK_CANCEL;
4496 static int _update_attachment_info(EmailViewerUGD *ug_data, int index)
4499 EmailViewerProp *prop = ug_data->property;
4502 int attach_index = 0;
4504 /* update attachment information */
4505 LIST_ITER_START(i, prop->attachments) {
4506 EmailAttachmentType *info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, prop->attachments);
4508 if (info && !info->inline_content) {
4509 debug_log("info->index[%d] index[%d]", info->index, index);
4511 if (info->index == index) {
4512 info->download_yn = TRUE;
4513 info->path = email_engine_get_attachment_path(info->attach_id);
4517 if (prop->real_att_len > 1) {
4518 Evas_Object *thumbnail = viewer_make_thumbnail(info->path, ug_data->attach_ex_bk[j]);
4519 Evas_Object *content = elm_object_part_content_unset(ug_data->attach_ex_bk[j], "elm.icon");
4520 evas_object_del(content);
4521 elm_object_part_content_set(ug_data->attach_ex_bk[j], "elm.icon", thumbnail);
4522 evas_object_show(thumbnail);
4524 Evas_Object *thumbnail = viewer_make_thumbnail(info->path, ug_data->attach_hd_bk);
4525 Evas_Object *content = elm_object_part_content_unset(ug_data->attach_hd_bk, "elm.icon");
4526 evas_object_del(content);
4527 elm_object_part_content_set(ug_data->attach_hd_bk, "elm.icon", thumbnail);
4528 evas_object_show(thumbnail);
4538 debug_log("return id[%d]", attach_index);
4540 return attach_index;
4543 static int _get_attachment_info_index(EmailViewerUGD *ug_data, int index)
4547 EmailViewerProp *prop = ug_data->property;
4549 int attach_index = 0;
4551 /* update attachment information */
4552 LIST_ITER_START(i, prop->attachments) {
4553 EmailAttachmentType *info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, prop->attachments);
4555 debug_log("info->index[%d] index[%d]", info->index, index);
4556 if (info->index == index) {
4563 debug_log("return id[%d]", attach_index);
4565 return attach_index;
4568 static void _show_select_info(EmailViewerUGD *ug_data, char *str)
4572 if (ug_data->select_info != NULL) {
4573 evas_object_del(ug_data->select_info);
4574 ug_data->select_info = NULL;
4577 if (ug_data->selectioninfo_layout != NULL) {
4578 evas_object_del(ug_data->selectioninfo_layout);
4579 ug_data->selectioninfo_layout = NULL;
4582 ug_data->select_info = elm_notify_add(ug_data->win_main);
4583 elm_notify_orient_set(ug_data->select_info, ELM_NOTIFY_ORIENT_BOTTOM);
4585 ug_data->selectioninfo_layout = elm_layout_add(ug_data->layout_main);
4586 elm_object_content_set(ug_data->select_info, ug_data->selectioninfo_layout);
4588 elm_layout_theme_set(ug_data->selectioninfo_layout, "standard", "selectioninfo", "vertical/bottom_64");
4590 edje_object_part_text_set(_EDJ(ug_data->selectioninfo_layout), "elm.text", str);
4591 elm_notify_timeout_set(ug_data->select_info, 3);
4592 evas_object_show(ug_data->select_info);
4595 static void _save_attachment(EmailViewerUGD *ug_data, int index)
4598 EmailViewerPrivate *priv = ug_data->email_data;
4599 EmailViewerProp *prop = ug_data->property;
4600 char newpath[MAX_PATH_LEN] = { 0, };
4602 RETURN_IF_FAIL(prop->attachments != NULL);
4603 EmailAttachmentType *info = g_list_nth_data(prop->attachments, index);
4606 debug_log("EmailAttachmentType *info is NULL");
4610 if (!info->download_yn) {
4612 gboolean res = FALSE;
4614 if (ug_data->progress_bar[index + 1] != NULL) {
4615 debug_log("Already getting downloaded...!");
4616 _create_notify(ug_data, dgettext("sys_string", "IDS_COM_POP_WARNING"),
4617 _("IDS_EMAIL_POP_ALREADY_DOWNLOADING_T_HEADER"), 1,
4618 dgettext("sys_string", "IDS_COM_SK_OK"),
4619 _popup_response_cb, NULL, NULL, NULL);
4623 debug_log("Need attachment download");
4624 /* download attachment */
4625 priv->b_att_save = TRUE;
4627 res = email_engine_attachment_download(priv->account_id, priv->mail_id, info->index, &handle);
4630 priv->download_all_cnt++;
4631 debug_log("Assigning Handle[%d] Index[%d] download_all_cnt[%d]", handle, index, priv->download_all_cnt);
4632 priv->download_all_email_handle[index] = handle;
4633 _create_down_progress_ex(index, EMAIL_VIEWER_PROGRESSBAR_ATT);
4634 ug_data->display_download_result = TRUE;
4636 priv->b_att_save = FALSE;
4637 _create_notify(ug_data, dgettext("sys_string", "IDS_COM_POP_WARNING"),
4638 _("IDS_EMAIL_POP_UNABLE_TO_OPEN_ATTACHMENT"), 1,
4639 dgettext("sys_string", "IDS_COM_SK_OK"), _popup_response_cb,
4646 if (info && STR_VALID(info->path)) {
4648 debug_log("path[%s]", info->path);
4649 ret = email_attachments_save_file(info->path, newpath, NULL);
4650 if (ret == EMAIL_EXT_SAVE_ERR_NONE) {
4651 char str[128] = { 0, };
4652 snprintf(str, sizeof(str), "%s", dgettext("sys_string", "IDS_COM_POP_SAVED"));
4653 ret = status_message_post(str);
4655 debug_log("status_message_post failed: %d", ret);
4660 static void _show_attachment(EmailViewerUGD *ug_data, int index)
4663 EmailViewerPrivate *priv = ug_data->email_data;
4664 EmailViewerProp *prop = ug_data->property;
4665 EmailAttachmentType *info = g_list_nth_data(prop->attachments, index);
4666 char newpath[MAX_PATH_LEN] = { 0, };
4669 debug_log("EmailAttachmentType *info is NULL");
4673 debug_log("attach_id:%d, index:%d, name(%s), path(%s), size:%d, download_yn:%d, drm:%d, inline_content:%d",
4674 info->attach_id, info->index, info->name, info->path, (gint) info->size, info->download_yn, info->drm, info->inline_content);
4676 if (!info->download_yn) {
4678 gboolean res = FALSE;
4679 debug_log("Need attachment download");
4681 priv->b_att_open = TRUE;
4683 res = email_engine_attachment_download(priv->account_id, priv->mail_id, info->index, &handle);
4686 priv->download_all_email_handle[index] = handle;
4687 priv->download_all_cnt++;
4688 _create_down_progress_ex(index, EMAIL_VIEWER_PROGRESSBAR_ATT);
4690 priv->b_att_open = FALSE;
4691 _create_notify(ug_data, dgettext("sys_string", "IDS_COM_POP_WARNING"),
4692 _("IDS_EMAIL_POP_UNABLE_TO_OPEN_ATTACHMENT"), 1,
4693 dgettext("sys_string", "IDS_COM_SK_OK"), _popup_response_cb,
4699 gboolean res = FALSE;
4700 res = email_attachments_save_file(info->path, newpath, NULL);
4701 debug_log("Result:%d, Saved Path:%s", res, newpath);
4703 if (res == EMAIL_EXT_SAVE_ERR_NONE) {
4704 char str[128] = { 0, };
4705 snprintf(str, sizeof(str), "%s", dgettext("sys_string", "IDS_COM_POP_SAVED"));
4706 int ret = status_message_post(str);
4708 debug_log("status_message_post failed: %d", ret);
4710 if (g_str_has_suffix(info->path, ".vcs")) {
4714 fp = fopen(newpath, "r");
4716 debug_error("fopen(%s) is failed.", newpath);
4717 calendar_disconnect();
4722 if (stat(newpath, &st) == -1) {
4723 debug_error("file(%s), stat Error(%d): %s", newpath, errno, strerror(errno));
4725 calendar_disconnect();
4729 int size = st.st_size;
4730 char *raw_data = calloc(size + 1, sizeof(char));
4732 debug_error("calloc is failed.");
4734 calendar_disconnect();
4739 if ((n = fread(raw_data, 1, size, fp)) != size) {
4740 debug_error("error in fread");
4743 calendar_disconnect();
4749 calendar_list_h list = NULL;
4751 ret = calendar_vcalendar_parse_to_calendar(raw_data, &list);
4753 if( list && ret == CALENDAR_ERROR_NONE) {
4754 calendar_db_insert_records(list, NULL, NULL);
4755 debug_log("vcalendar is registered to calendar");
4759 calendar_disconnect();
4761 media_file_register(newpath);
4762 } else if (res == EMAIL_EXT_SAVE_ERR_ALREADY_EXIST && !ug_data->display_download_result) {
4763 _create_notify(ug_data, _("IDS_EMAIL_POP_ALERT"),
4764 dgettext("sys_string", "IDS_COM_POP_ALREDY_EXISTS"), 0,
4765 NULL, NULL, NULL, NULL, _popup_response_cb);
4768 debug_log("display_download_result:%d", ug_data->display_download_result);
4769 if (ug_data->display_download_result) {
4770 if (res == EMAIL_EXT_SAVE_ERR_NONE || res == EMAIL_EXT_SAVE_ERR_ALREADY_EXIST) {
4772 service_h service = NULL;
4773 ret = service_create(&service);
4774 debug_log("service_create: %d", ret);
4776 debug_log("service create failed");
4779 ret = service_set_operation(service, SERVICE_OPERATION_VIEW);
4780 debug_log("service_set_operation: %d", ret);
4781 ret = service_set_uri(service, newpath);
4782 debug_log("service_set_uri: %d", ret);
4783 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_VIDEO_PLAYER_LAUNCH_APP, "email");
4784 debug_log("service_add_extra_data: %d", ret);
4785 ret = service_send_launch_request(service, NULL, NULL);
4786 debug_log("service_send_launch_request: %d", ret);
4787 if (ret != SERVICE_ERROR_NONE) {
4788 _create_notify(ug_data, dgettext("sys_string", "IDS_COM_POP_WARNING"),
4789 _("IDS_EMAIL_POP_THIS_ATTACHMENT_CANNOT_BE_DISPLAYED"), 0,
4790 NULL, NULL, NULL, NULL, _popup_response_cb);
4792 ret = service_destroy(service);
4793 debug_log("service_destroy: %d", ret);
4795 debug_log("EMAIL_EXT_SAVE_ERR_UNKNOWN");
4800 static void _save_attachment_all(EmailViewerUGD *ug_data)
4803 EmailViewerPrivate *priv = ug_data->email_data;
4804 EmailViewerProp *prop = ug_data->property;
4805 EmailAttachmentType *info = NULL;
4808 int att_len = g_list_length(prop->attachments);
4810 if (priv->b_all_att_save)
4814 if (ug_data->forward_ctr_it)
4815 elm_object_item_disabled_set(ug_data->forward_ctr_it, EINA_TRUE);
4818 for (i = 0; i < att_len; i++) {
4819 info = g_list_nth_data(prop->attachments, i);
4821 if (info && !info->inline_content) {
4822 if (!info->download_yn) {
4823 if (ug_data->progress_bar_ly[i + 1] == NULL) {
4825 gboolean res = FALSE;
4826 debug_log("Need attachment [%d] download", i);
4828 res = email_engine_attachment_download(priv->account_id, priv->mail_id, info->index, &handle);
4831 priv->download_all_cnt++;
4832 priv->download_all_email_handle[i] = handle;
4833 priv->b_all_att_save = TRUE;
4835 debug_log("attach_onoff_flag:%d", ug_data->attach_onoff_flag);
4836 if (priv->b_all_att_save) {
4837 if (ug_data->attach_onoff_flag == 0) {
4838 _attachment_item_collapse_cb(ug_data->attach_hd_bk, NULL, NULL, NULL);
4842 _create_down_progress_ex(i, EMAIL_VIEWER_PROGRESSBAR_ATT);
4843 ug_data->display_download_result = TRUE;
4845 priv->download_all_fail_cnt++;
4852 debug_log("download [%d], failed [%d]", priv->download_all_cnt, priv->download_all_fail_cnt);
4855 static void _dbus_receiver_setup(EmailViewerUGD *ug_data)
4859 int ret = e_dbus_init();
4860 debug_log("ret: %d", ret);
4864 if (_g_viewer_dbus_conn == NULL) {
4866 dbus_error_init(&derror);
4867 _g_viewer_dbus_conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
4869 if (_g_viewer_dbus_conn == NULL) {
4870 debug_log("e_dbus_bus_get return NULL");
4874 if (e_dbus_request_name(_g_viewer_dbus_conn, "User.Email.StorageChange", 0, NULL, NULL) == NULL) {
4875 debug_critical("Failed to e_dbus_request_name()");
4879 if (_g_viewer_signal_handler_storage != NULL) {
4880 debug_log("_g_viewer_signal_handler_storage != NULL");
4883 _g_viewer_signal_handler_storage = e_dbus_signal_handler_add(_g_viewer_dbus_conn, NULL,
4884 "/User/Email/StorageChange",
4885 "User.Email.StorageChange",
4886 "email", _on_edbus_event_email_viewer_receive, ug_data);
4888 if (_g_viewer_signal_handler_storage == NULL) {
4889 debug_log("Failed to e_dbus_signal_handler_add()");
4894 if (e_dbus_request_name(_g_viewer_dbus_conn, "User.Email.NetworkStatus", 0, NULL, NULL) == NULL) {
4895 debug_log("Failed to e_dbus_request_name()");
4899 if (_g_viewer_signal_handler_network != NULL) {
4900 debug_log("_g_viewer_signal_handler_network != NULL");
4903 _g_viewer_signal_handler_network = e_dbus_signal_handler_add(_g_viewer_dbus_conn, NULL,
4904 "/User/Email/NetworkStatus",
4905 "User.Email.NetworkStatus",
4906 "email", _on_edbus_event_email_viewer_receive, ug_data);
4908 if (_g_viewer_signal_handler_network == NULL) {
4909 debug_log("Failed to e_dbus_signal_handler_add()");
4915 static void _dbus_receiver_remove(EmailViewerUGD *ug_data)
4919 if (_g_viewer_signal_handler_storage != NULL) {
4920 e_dbus_signal_handler_del(_g_viewer_dbus_conn, _g_viewer_signal_handler_storage);
4921 _g_viewer_signal_handler_storage = NULL;
4924 if (_g_viewer_signal_handler_network != NULL) {
4925 e_dbus_signal_handler_del(_g_viewer_dbus_conn, _g_viewer_signal_handler_network);
4926 _g_viewer_signal_handler_network = NULL;
4929 if (e_dbus_release_name(_g_viewer_dbus_conn, "User.Email.StorageChange", NULL, NULL) == NULL) {
4930 debug_critical("e_dbus_release_name to failed");
4933 if (e_dbus_release_name(_g_viewer_dbus_conn, "User.Email.NetworkStatus", NULL, NULL) == NULL) {
4934 debug_critical("e_dbus_release_name to failed");
4937 if (_g_viewer_dbus_conn != NULL) {
4938 /*e_dbus_connection_close(_g_viewer_dbus_conn);*/
4939 _g_viewer_dbus_conn = NULL;
4943 static void _on_edbus_event_email_viewer_receive(void *data, DBusMessage *message)
4948 debug_log("data is NULL");
4952 EmailViewerUGD *ug_data = _g_ug_data;
4953 EmailViewerPrivate *priv = ug_data->email_data;
4954 char fail_msg[MAX_STR_LEN] = { 0, };
4957 if (dbus_message_is_signal(message, "User.Email.StorageChange", "email")) {
4958 debug_log("User.Email.StorageChange");
4965 dbus_error_init(&error);
4966 if (dbus_message_get_args(message, &error, DBUS_TYPE_INT32, &subtype,
4967 DBUS_TYPE_INT32, &data1, DBUS_TYPE_INT32, &data2,
4968 DBUS_TYPE_STRING, &data3, DBUS_TYPE_INVALID)) {
4969 debug_log("STORE_ENABLE: subtype: %d, data1: %d, data2: %d, data3: %s", subtype, data1, data2, data3);
4972 case NOTI_ACCOUNT_ADD:
4973 if (get_app_paused()) {
4974 debug_log("account added during pause status");
4976 if (ug_data->isRotate == false && ug_data->b_internal) {
4977 /* Viewer to hide, so set left content (mailbox) size to full */
4978 _notify_mailbox_size(ug_data, "MAILBOX_RESIZE_FULL");
4981 if (ug_data->b_internal != 1) {
4982 debug_log("ug_destory_me");
4983 ug_destroy_me(ug_data->ug);
4985 _hide_view(ug_data);
4990 case NOTI_ACCOUNT_DELETE:
4991 if (get_app_paused()) {
4992 debug_log("account deleted during pause status");
4995 if (ug_data->isRotate == false && ug_data->b_internal) {
4996 /* Viewer to hide, so set left content (mailbox) size to full */
4997 _notify_mailbox_size(ug_data, "MAILBOX_RESIZE_FULL");
5000 if (email_engine_get_default_account(&account_id)) {
5001 if (ug_data->b_internal != 1) {
5002 debug_log("ug_destory_me");
5003 ug_destroy_me(ug_data->ug);
5005 _hide_view(ug_data);
5011 case NOTI_ACCOUNT_UPDATE:
5012 if (get_app_paused()) {
5013 debug_log("account updated during pause status");
5018 debug_warning("unknown type");
5022 debug_critical("receive data error: %s", error.message);
5023 dbus_error_free(&error);
5025 } else if (dbus_message_is_signal(message, "User.Email.NetworkStatus", "email")) {
5034 dbus_error_init(&error);
5036 if (dbus_message_get_args(message, &error, DBUS_TYPE_INT32, &subtype,
5037 DBUS_TYPE_INT32, &data1, DBUS_TYPE_STRING, &data2,
5038 DBUS_TYPE_INT32, &data3, DBUS_TYPE_INT32, &data4, DBUS_TYPE_INVALID)) {
5039 debug_log("subtype: %d, data1: %d, data2: %s, data3: %d, data4: %d", subtype, data1, data2, data3, data4);
5042 case NOTI_DOWNLOAD_BODY_START:
5043 /* DATA1[mail_id] DATA2[file_id] DATA3[body_size] DATA4[received size] */
5044 debug_log("receive noti, DOWNLOAD_BODY");
5045 if (priv->mail_id == data1) {
5046 priv->file_id = g_strdup(data2);
5047 priv->file_size = data3;
5050 _set_value_down_progress(0.0);
5052 double per = (double)data4 / (double)data3;
5053 _set_value_down_progress(per);
5056 debug_log("mail_id is different");
5057 debug_log("expected mail_id [%d], received mail_id [%d]", priv->mail_id, data1);
5061 case NOTI_DOWNLOAD_MULTIPART_BODY:
5062 /* DATA1[mail_id] DATA2[file_id] DATA3[body_size] DATA4[received size] */
5063 debug_log("receive noti, DOWNLOAD_MULTIPART_BODY");
5064 if (priv->mail_id == data1) {
5065 priv->file_id = g_strdup(data2);
5066 priv->file_size = data3;
5067 priv->multi_body = TRUE;
5070 _set_value_down_progress(0.0);
5072 double per = (double)data4 / (double)data3;
5073 _set_value_down_progress(per);
5076 debug_log("mail_id is different");
5077 debug_log("expected mail_id [%d], received mail_id [%d]", priv->mail_id, data1);
5081 case NOTI_DOWNLOAD_BODY_FINISH:
5082 /* DATA1[mail_id] DATA2[NULL] DATA3[handle_id] */
5083 debug_log("receive noti, DOWNLOAD_BODY_FINISH");
5084 if (priv->email_handle == data3 && priv->mail_id == data1) {
5085 priv->email_handle = 0;
5087 ug_data->b_load_finished = EINA_FALSE;
5089 /* delete progress */
5090 if (ug_data->pb_notify) {
5091 _set_value_down_progress(1.0);
5092 _destroy_down_progress_cb(NULL, NULL, NULL);
5095 char str[128] = { 0, };
5096 snprintf(str, sizeof(str), "%s", dgettext("sys_string", "IDS_COM_BODY_DOWNLOADED"));
5097 int ret = status_message_post(str);
5099 debug_log("status_message_post failed: %d", ret);
5102 if (viewer_get_internal_mail_info(ug_data->property, ug_data->email_data)) {
5103 viewer_make_internal_mail(ug_data->property, ug_data->email_data);
5105 /* create att and body */
5106 if (ug_data->b_partial_body) {
5111 elm_scroller_region_get(ug_data->scroller, &scr_x, &scr_y, &scr_w, &scr_h);
5112 debug_log("scroller region> x[%d] y[%d] w[%d] h[%d]", scr_x, scr_y, scr_w, scr_h);
5114 elm_box_unpack(ug_data->main_bx, ug_data->partial_dn_btn_bx);
5115 if (ug_data->partial_dn_btn) {
5116 evas_object_del(ug_data->partial_dn_btn);
5117 ug_data->partial_dn_btn = NULL;
5119 if (ug_data->partial_dn_btn_bx) {
5120 evas_object_del(ug_data->partial_dn_btn_bx);
5121 ug_data->partial_dn_btn_bx = NULL;
5124 if (ug_data->property->has_html) {
5125 ug_data->webview_data->body_type = BODY_TYPE_HTML;
5126 ug_data->webview_data->uri = ug_data->property->body_uri;
5128 ug_data->webview_data->body_type = BODY_TYPE_TEXT;
5129 ug_data->webview_data->text_content = ug_data->property->body;
5132 viewer_set_webview_content(ug_data, 1);
5134 elm_object_focus_set(ug_data->ly_subject, EINA_TRUE);
5135 elm_scroller_region_show(ug_data->scroller, scr_x, scr_y, scr_w, scr_h);
5138 if (ug_data->property->has_attachment)
5139 ug_data->got_att = 1;
5141 ug_data->got_att = 0;
5143 /* pack attachment if it exist */
5144 if (ug_data->got_att) {
5145 _create_attach(ug_data);
5148 _create_body(ug_data);
5151 debug_log("email_handle or mail_id is different");
5152 debug_log("expected mail_id [%d], received mail_id [%d]", priv->mail_id, data1);
5153 debug_log("expected email_handle [%d], received email_handle [%d]", priv->email_handle, data3);
5157 case NOTI_DOWNLOAD_BODY_FAIL:
5158 /* DATA1[mail_id] DATA2[NULL] DATA3[handle_id] */
5159 debug_log("receive noti, DOWNLOAD_BODY_FAIL");
5160 if (priv->email_handle == data3 && priv->mail_id == data1) {
5161 priv->email_handle = 0;
5163 /* delete progress */
5164 if (ug_data->pb_notify) {
5165 _destroy_down_progress_cb(NULL, NULL, NULL);
5168 char *err_msg = _get_service_fail_type(data4);
5169 snprintf(fail_msg, sizeof(fail_msg), "%s<br>%s", _("IDS_EMAIL_POP_UNABLE_TO_DOWNLOAD"), err_msg);
5170 _create_notify(ug_data, dgettext("sys_string", "IDS_COM_POP_WARNING"),
5171 fail_msg, 1, dgettext("sys_string", "IDS_COM_SK_OK"),
5172 _popup_response_cb, NULL, NULL, NULL);
5175 debug_log("email_handle or mail_id is different");
5176 debug_log("expected mail_id [%d], received mail_id [%d]", priv->mail_id, data1);
5177 debug_log("expected email_handle [%d], received email_handle [%d]", priv->email_handle, data3);
5181 case NOTI_DOWNLOAD_ATTACH_START:
5182 /* DATA1[mail_id] DATA2[file_id] DATA3[attachment_id] DATA4[percentage] */
5183 debug_log("receive noti, DOWNLOAD_ATTACHMENT");
5184 if (priv->mail_id == data1) {
5185 priv->att_file_id = g_strdup(data2);
5186 priv->attachment_id = data3;
5189 /* Set the progressbar of particular attachment_id */
5190 _set_value_down_progress_by_index(0.0, priv->attachment_id);
5193 double per = (double)data4 / 100.0;
5194 /* Set the progressbar of particular attachment_id */
5195 _set_value_down_progress_by_index(per, priv->attachment_id);
5198 debug_log("mail_id is different");
5199 debug_log("expected mail_id [%d], received mail_id [%d]", priv->mail_id, data1);
5203 case NOTI_DOWNLOAD_ATTACH_FINISH:
5204 /* DATA1[mail_id] DATA2[NULL] DATA3[attachment_id] */
5205 debug_log("receive noti, DOWNLOAD_ATTACH_FINISH");
5207 if (priv->mail_id == data1) {
5208 int attach_index = 0;
5209 int attachment_id = (int)data3;
5210 debug_log("download_all_cnt [%d]", priv->download_all_cnt);
5212 if (priv->download_all_cnt > 0) {
5213 _set_value_down_progress_by_index(1.0, attachment_id);
5214 attach_index = _update_attachment_info(ug_data, attachment_id);
5215 if (priv->b_all_att_save) {
5216 _destroy_down_progress_ex((void *)attach_index, NULL, NULL);
5217 _save_attachment(ug_data, attach_index);
5218 if (priv->download_all_cnt == 0) {
5219 priv->b_all_att_save = FALSE;
5222 _destroy_down_progress_ex((void *)attach_index, NULL, NULL);
5223 _show_attachment(ug_data, attach_index);
5227 debug_log("mail_id or attachment_id is different");
5228 debug_log("expected mail_id [%d], received mail_id [%d]", priv->mail_id, data1);
5232 case NOTI_DOWNLOAD_ATTACH_FAIL:
5233 /* DATA1[mail_id] DATA2[NULL] DATA3[attachment_id] */
5234 debug_log("receive noti, DOWNLOAD_ATTACH_FAIL");
5235 if (priv->mail_id == data1) {
5236 int attach_index = _get_attachment_info_index(ug_data, data3);
5237 debug_log("download_all_cnt[%d]", priv->download_all_cnt);
5239 if (priv->download_all_cnt > 0) {
5240 if (ug_data->progress_bar[data3] != NULL && data4 != EMAIL_ERROR_CANCELLED)
5241 _destroy_down_progress_ex((void *)attach_index, NULL, NULL);
5243 debug_log("Download already cancelled, No need to destroy again..!");
5245 if (data4 != EMAIL_ERROR_CANCELLED && ug_data->ug_composer == NULL) {
5246 char *err_msg = _get_service_fail_type(data4);
5247 snprintf(fail_msg, sizeof(fail_msg), "%s<br>%s", _("IDS_EMAIL_POP_UNABLE_TO_DOWNLOAD"), err_msg);
5248 _create_notify(ug_data, dgettext("sys_string", "IDS_COM_POP_WARNING"), fail_msg, 1,
5249 dgettext("sys_string", "IDS_COM_SK_OK"),
5250 _popup_response_cb, NULL, NULL, NULL);
5254 if (priv->b_all_att_save && priv->download_all_cnt == 0) {
5255 priv->b_all_att_save = FALSE;
5259 debug_log("mail_id is different");
5260 debug_log("expected mail_id [%d], received mail_id [%d]", priv->mail_id, data1);
5265 debug_log("unknown type");
5269 debug_log("receive data error: %s", error.message);
5270 dbus_error_free(&error);
5272 /*return DBUS_HANDLER_RESULT_HANDLED;*/
5275 /*return DBUS_HANDLER_RESULT_HANDLED;*/
5279 static void _delete_contacts_list(EMAIL_CONTACT_LIST_INFO_S *contacts_list_item)
5283 if (contacts_list_item) {
5284 g_free(contacts_list_item->display);
5285 contacts_list_item->display = NULL;
5286 g_free(contacts_list_item->email_address);
5287 contacts_list_item->email_address = NULL;
5288 g_free(contacts_list_item);
5289 contacts_list_item = NULL;
5293 static void *_contact_search_by_email(EmailViewerUGD *ug_data, const char *search_word)
5296 if (!ug_data || !_g_ug_data) {
5297 debug_log("data is NULL");
5301 int ret = CTS_SUCCESS;
5302 CTSiter *iter = NULL;
5304 EMAIL_CONTACT_LIST_INFO_S *contacts_list_item = NULL;
5305 contacts_svc_connect();
5307 debug_log("search_word = %s", search_word);
5309 if (contacts_svc_get_list_with_str(CTS_LIST_EMAILINFOS_WITH_EMAIL, search_word, &iter) != CTS_SUCCESS) {
5313 ret = contacts_svc_iter_next(iter);
5315 if (CTS_SUCCESS == ret) {
5316 CTSvalue *row_info = NULL;
5318 row_info = contacts_svc_iter_get_info(iter);
5320 contacts_list_item = (EMAIL_CONTACT_LIST_INFO_S *)calloc(1, sizeof(EMAIL_CONTACT_LIST_INFO_S));
5322 int index = contacts_svc_value_get_int(row_info, CTS_LIST_EMAIL_CONTACT_ID_INT);
5324 contacts_list_item->index = index;
5325 contacts_list_item->display = g_strdup(contacts_svc_value_get_str(row_info, CTS_LIST_EMAIL_CONTACT_DISPLAY_STR));
5326 contacts_list_item->email_address = g_strdup(contacts_svc_value_get_str(row_info, CTS_LIST_EMAIL_ADDR_STR));
5328 snprintf(contacts_list_item->display_name, sizeof(contacts_list_item->display_name), "%s", contacts_list_item->display);
5331 contacts_svc_value_free(row_info);
5334 contacts_svc_iter_remove(iter);
5337 contacts_svc_disconnect();
5339 return contacts_list_item;
5342 static void _set_value_down_progress(double val)
5347 debug_log("data is NULL");
5350 char buf[30] = { 0, };
5351 EmailViewerUGD *ug_data = _g_ug_data;
5353 sprintf(buf, "%s: %d", dgettext("sys_string", "IDS_COM_POP_DOWNLOADING"), (int)val);
5355 if (ug_data->pb_notify_lb) {
5356 elm_progressbar_value_set(ug_data->pb_notify_lb, val);
5357 elm_object_text_set(ug_data->pb_notify_lb, buf);
5361 static void _set_value_down_progress_by_index(double val, int index)
5366 debug_log("data is NULL");
5370 EmailViewerUGD *ug_data = _g_ug_data;
5371 EmailViewerProp *prop = ug_data->property;
5374 debug_log("val(%f) is MINUS", val);
5378 if (index < 0 || index >= ATTACH_MAX) {
5379 debug_log("index(%d) is overflowed", index);
5384 debug_log("prop is NULL");
5388 if (prop->attachments == NULL) {
5389 debug_log("attachments is NULL");
5393 int per = val * 100;
5394 int attach_index = _get_attachment_info_index(ug_data, index);
5395 EmailAttachmentType *info = g_list_nth_data(prop->attachments, attach_index);
5398 debug_log("info is NULL");
5401 if (ug_data->progress_bar[index] == NULL) {
5402 debug_log("obj is NULL");
5406 char *pszTemp = NULL;
5407 pszTemp = (char *)elm_object_style_get(ug_data->progress_bar[index]);
5409 if (STR_INVALID(pszTemp))
5412 if (g_strcmp0(pszTemp, "pending_list") == 0) {
5413 debug_log("pending_list so return");
5417 elm_progressbar_value_set(ug_data->progress_bar[index], val);
5419 if (ug_data->progress_bar_ly[index] != NULL) {
5420 char buf[30] = { 0, };
5421 snprintf(buf, sizeof(buf), "%d%%", per);
5423 Evas_Object *downloading_label2;
5424 downloading_label2 = elm_label_add(ug_data->progress_bar_ly[index]);
5425 elm_object_part_content_set(ug_data->progress_bar_ly[index], "elm.text.2", downloading_label2);
5426 char *buf_tagged = g_strconcat("<font_size=26><align=left><color=#646464FF>", buf, "</align></font_size>", NULL);
5427 elm_object_text_set(downloading_label2, buf_tagged);
5432 static void _cancel_download_attachment(EmailViewerUGD *ug_data)
5436 gboolean is_cancel = FALSE;
5439 debug_log("data is NULL");
5443 EmailViewerPrivate *priv = ug_data->email_data;
5444 EmailViewerProp *prop = ug_data->property;
5446 if (priv && priv->download_all_cnt <= 0) {
5447 debug_log("No attachment download to be cancelled!");
5451 for (i = 0; i <= prop->att_len; i++) {
5452 if (ug_data->progress_bar_ly[i]) {
5453 Evas_Object *btn = elm_object_part_content_get(ug_data->progress_bar_ly[i], "elm.icon.1");
5454 debug_log("Cancel btn for downloading attachment: %p", btn);
5456 evas_object_smart_callback_call(btn, "clicked", NULL);
5462 if (is_cancel == TRUE && ug_data->ug_composer == NULL) {
5463 _create_notify(ug_data, dgettext("sys_string", "IDS_COM_POP_WARNING"), _("IDS_EMAIL_POP_CANCELLING_ATTACHMENT_DOWNLOAD_ING"),
5464 1, dgettext("sys_string", "IDS_COM_SK_OK"), _popup_response_cb,
5469 static char *_get_service_fail_type(int type)
5474 char str[MAX_STR_LEN] = { 0, };
5477 snprintf(str, sizeof(str), "%s: %s", _("IDS_EMAIL_POP_FAILED_TO_ACTIVATE_PDP"), N_("IP full"));
5478 return g_strdup(str);
5479 } else if (type == -176) {
5480 ret = _("IDS_EMAIL_POP_NO_SERVICE");
5481 return g_strdup(ret);
5482 } else if (type == -181) {
5483 snprintf(str, sizeof(str), "%s: %s", _("IDS_EMAIL_POP_FAILED_TO_ACTIVATE_PDP"), N_("Transport Error"));
5484 return g_strdup(str);
5485 } else if (type == EMAIL_ERROR_NETWORK_TOO_BUSY) {
5486 ret = _("IDS_EMAIL_POP_NETWORK_BUSY");
5487 return g_strdup(ret);
5488 } else if (type == EMAIL_ERROR_LOGIN_ALLOWED_EVERY_15_MINS) {
5489 snprintf(str, sizeof(str), _("IDS_EMAIL_POP_YOU_CAN_ONLY_LOG_IN_ONCE_EVERY_PD_MINUTES"), 15);
5490 return g_strdup(str);
5491 } else if (type == EMAIL_ERROR_CONNECTION_FAILURE) {
5492 ret = dgettext("sys_string", "IDS_COM_POP_CONNECTION_FAILED");
5493 return g_strdup(ret);
5494 } else if (type == EMAIL_ERROR_LOGIN_FAILURE) {
5495 ret = _("IDS_EMAIL_POP_LOG_IN_FAILED");
5496 return g_strdup(ret);
5497 } else if (type == EMAIL_ERROR_AUTHENTICATE) {
5498 ret = _("IDS_EMAIL_POP_AUTHENTICATION_FAILED");
5499 return g_strdup(ret);
5500 } else if (type == EMAIL_ERROR_CANCELLED) {
5501 ret = _("IDS_EMAIL_POP_DOWNLOAD_CANCELLED");
5502 return g_strdup(ret);
5503 } else if (type == EMAIL_ERROR_MAIL_NOT_FOUND_ON_SERVER) {
5504 ret = _("IDS_EMAIL_POP_EMAIL_DELETED_FROM_SERVER");
5505 return g_strdup(ret);
5506 } else if (type == EMAIL_ERROR_NO_SUCH_HOST) {
5507 ret = _("IDS_EMAIL_POP_HOST_NOT_FOUND");
5508 return g_strdup(ret);
5509 } else if (type == EMAIL_ERROR_INVALID_SERVER) {
5510 ret = _("IDS_EMAIL_POP_SERVER_NOT_AVAILABLE");
5511 return g_strdup(ret);
5512 } else if (type == EMAIL_ERROR_MAIL_MEMORY_FULL) {
5513 ret = _("IDS_EMAIL_POP_DEVICE_STORAGE_FULL");
5514 return g_strdup(ret);
5515 } else if (type == EMAIL_ERROR_FAILED_BY_SECURITY_POLICY) {
5516 ret = _("IDS_EMAIL_POP_DOWNLOADING_ATTACHMENTS_ON_THE_MOBILE_DEVICE_IS_NOT_ALLOWED_BY_EXCHANGE_SERVER_POLICY");
5517 return g_strdup(ret);
5519 snprintf(str, sizeof(str), "%s (%d)", dgettext("sys_string", "IDS_COM_POP_INTERNAL_ERROR"), type);
5520 return g_strdup(str);
5524 static Evas_Object *_load_edj(Evas_Object *parent, const char *file, const char *group)
5530 eo = elm_layout_add(parent);
5532 r = elm_layout_file_set(eo, file, group);
5534 evas_object_del(eo);
5538 evas_object_size_hint_weight_set(eo, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
5545 static Eina_Bool _gl_state_get(void *data, Evas_Object *obj, const char *part)
5551 static void _gl_del(void *data, Evas_Object *obj)
5555 if (_g_ug_data == NULL) {
5556 debug_log("ug_data is NULL");
5560 EmailViewerUGD *ug_data = _g_ug_data;
5562 if (ug_data->move_mailbox_list) {
5563 email_free_mailbox(&ug_data->move_mailbox_list, ug_data->move_mailbox_count);
5564 ug_data->move_mailbox_list = NULL;
5565 ug_data->move_mailbox_count = 0;
5571 static char *_gl_text_get(void *data, Evas_Object *obj, const char *part)
5574 email_mailbox_t *mailbox_list = NULL;
5575 mailbox_list = (email_mailbox_t *) data;
5577 if (g_strcmp0(part, "elm.text") == 0) {
5578 char buf[MAX_STR_LEN] = { 0, };
5579 if (mailbox_list && mailbox_list->alias) {
5580 snprintf(buf, sizeof(buf), "%s", mailbox_list->alias);
5581 return g_strdup(buf);
5588 static Evas_Object *_gl_content_get(void *data, Evas_Object *obj, const char *part)
5592 if (g_strcmp0(part, "elm.icon") == 0) {
5593 Evas_Object *icon = elm_icon_add(obj);
5594 elm_icon_file_set(icon, IMGDIR "/U01_icon_folder.png", NULL);
5595 evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
5603 static void _move_here_cb(void *data, Evas_Object *obj, void *event_info)
5607 if (data == NULL || _g_ug_data == NULL) {
5608 debug_log("data is NULL");
5612 email_mailbox_t *mailbox_list = NULL;
5613 mailbox_list = (email_mailbox_t *) data;
5615 EmailViewerUGD *ug_data = _g_ug_data;
5616 int folder_id = mailbox_list->mailbox_id;
5618 _move_email(ug_data, folder_id, FALSE);
5620 ug_data->navi_move_it1 = NULL;
5621 elm_naviframe_item_pop_to(ug_data->navi_main_it);
5623 if (ug_data->isRotate == false && ug_data->b_internal) {
5624 /* Viewer to hide, so set left content (mailbox) size to full */
5625 _notify_mailbox_size(ug_data, "MAILBOX_RESIZE_FULL");
5628 if (ug_data->b_internal) {
5629 _hide_view(ug_data);
5631 /* send next or previous mail request to mailbox. */
5633 service_h service = NULL;
5635 ret = service_create(&service);
5636 debug_log("service_create: %d", ret);
5638 debug_log("service create failed");
5642 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_MSG, EMAIL_BUNDLE_VAL_NEXT_MSG);
5643 debug_log("service_add_extra_data: %d", ret);
5644 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_DO_DELETE, "1");
5645 debug_log("service_add_extra_data: %d", ret);
5647 ug_send_message(_g_mailbox_ug, service);
5649 ret = service_destroy(service);
5650 debug_log("service_destroy: %d", ret);
5652 ug_destroy_me(ug_data->ug);
5656 static void _move_back_cb(void *data, Evas_Object *obj, void *event_info)
5660 if (data == NULL || _g_ug_data == NULL) {
5661 debug_log("data is NULL");
5665 EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
5667 elm_naviframe_item_pop(ug_data->navi_bar);
5668 ug_data->navi_move_it1 = NULL;
5670 /*if (ug_data->b_internal)
5671 elm_layout_theme_set(ug_data->layout_main, "layout", "controlbar", "default");
5673 elm_layout_theme_set(ug_data->layout_main, "layout", "application", "controlbar");*/