36315b294cdddb50f9261308cdde5c770d31e62e
[apps/core/preloaded/email.git] / viewer / src / email-viewer.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
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
7  *
8  *    http://www.tizenopensource.org/license
9  *
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.
15  */
16
17 #ifndef UG_MODULE_API
18 #define UG_MODULE_API __attribute__ ((visibility("default")))
19 #endif
20
21 /* Header Include */
22 #include <contacts-ug.h>
23 #include <calendar-svc-provider.h>
24 #include <media-util-register.h>
25 #include <media-util-err.h>
26 #include <app_service.h>
27 #include <status.h>
28
29 #include "email-viewer.h"
30 #include "email-viewer-webview.h"
31 #include "email-viewer-utils.h"
32 #include "email-engine.h"
33 #include "email-utils.h"
34 #include "email-common-types.h"
35 #include "email-debug.h"
36
37 #define EMAIL_VCONF_KEY_BLOCK_RULE_CHANGED      "file/private/org.tizen.email/spam_rule_changed"
38
39 /* Global Val */
40 EmailViewerUGD *_g_ug_data = NULL;
41 E_DBus_Connection *_g_viewer_dbus_conn = NULL;
42 E_DBus_Signal_Handler *_g_viewer_signal_handler_network = NULL;
43 E_DBus_Signal_Handler *_g_viewer_signal_handler_storage = NULL;
44
45 extern ui_gadget_h _g_mailbox_ug;
46 extern char *icu_locale;
47 extern enum appcore_time_format icu_timeformat;
48 extern void _set_mail_flags(EmailViewerProp *prop, EmailViewerPrivate *email_data);
49
50 /* appcore */
51 static void *on_create(ui_gadget_h ug, enum ug_mode mode, service_h data, void *priv);
52 static void on_start(ui_gadget_h ug, service_h data, void *priv);
53 static void on_pause(ui_gadget_h ug, service_h data, void *priv);
54 static void on_resume(ui_gadget_h ug, service_h data, void *priv);
55 static void on_destroy(ui_gadget_h ug, service_h data, void *pd);
56 static void on_message(ui_gadget_h ug, service_h msg, service_h data, void *priv);
57 static void on_event(ui_gadget_h ug, enum ug_event event, service_h data, void *priv);
58 static void on_key_event(ui_gadget_h ug, enum ug_key_event event, service_h data, void *priv);
59
60 /* ui-gadget */
61 static void layout_cb(ui_gadget_h ug, enum ug_mode mode, void *priv);
62 static void result_cb(ui_gadget_h ug, service_h result, void *priv);
63 static void destroy_cb(ui_gadget_h ug, void *priv);
64 static ui_gadget_h create_ug(char *ug_name, service_h bd, void *data);
65
66 /* View related */
67 static void _create_view(EmailViewerUGD *ug_data);
68 static void _reset_view(EmailViewerUGD *ug_data);
69
70 static void _win_profile_changed_cb(void *data, Evas_Object *obj, void *event);
71
72 static Evas_Object *_create_navigation_bar(EmailViewerUGD *ug_data);
73 static Evas_Object *_create_subject(EmailViewerUGD *ug_data);
74 static Evas_Object *_create_to_addrs(EmailViewerUGD *ug_data);
75 static Evas_Object *_create_cc_addrs(EmailViewerUGD *ug_data);
76 static Evas_Object *_create_bcc_addrs(EmailViewerUGD *ug_data);
77 static Evas_Object *_create_attach(EmailViewerUGD *ug_data);
78 static Evas_Object *_create_attach_ex(EmailViewerUGD *ug_data);
79 static Evas_Object *_create_body(EmailViewerUGD *ug_data);
80 static Evas_Object *_create_tab_bar(EmailViewerUGD *ug_data);
81 static Evas_Object *_update_tab_bar(EmailViewerUGD *ug_data);
82 static Evas_Object *_create_partial_body_dn_btn(EmailViewerUGD *ug_data);
83 static Evas_Object *_create_bg(Evas_Object *win);
84
85 static void _create_down_progress(char *message, popup_cb resp_cb);
86 static void _create_down_progress_ex(int index, EMAIL_VIEWER_PROGRESSBAR_TYPE p_type);
87 static void _destroy_down_progress_ex(void *data, Evas_Object *obj, void *event_info);
88 static void _create_more_ctxpopup(EmailViewerUGD *ug_data);
89 static void _delete_evas_objects(EmailViewerUGD *ug_data);
90
91 static void _launch_vcs_editor(EmailViewerUGD *ug_data);
92
93 /* callback functions */
94 static void _back_cb(void *data, Evas_Object *obj, void *event_info);
95 static void _prev_mail_cb(void *data, Evas_Object *obj, void *event_info);
96 static void _next_mail_cb(void *data, Evas_Object *obj, void *event_info);
97 static void _reply_cb(void *data, Evas_Object *obj, void *event_info);
98 static void _reply_all_cb(void *data, Evas_Object *obj, void *event_info);
99 static void _reply_option_cb(void *data, Evas_Object *obj, void *event_info);
100 static void _forward_cb(void *data, Evas_Object *obj, void *event_info);
101 static void _add_to_calendar_cb(void *data, Evas_Object *obj, void *event_info);
102 static void _resend_cb(void *data, Evas_Object *obj, void *event_info);
103 static void _delete_cb(void *data, Evas_Object *obj, void *event_info);
104 static void _move_cb(void *data, Evas_Object *obj, void *event_info);
105 static void _more_cb(void *data, Evas_Object *obj, void *event_info);
106 static void _body_down_cb(void *data, Evas_Object *obj, void *event_info);
107 static void _subject_favorite_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
108 static void _subject_detail_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
109 static void _attachment_item_collapse_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
110 static void _attachment_save_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
111 static void _attachment_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
112 static void _attachment_save_all_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
113 static void _attachment_bg_set_cb(void *data, Evas * evas, Evas_Object *obj, void *event_info);
114 static void _attachment_bg_unset_cb(void *data, Evas * evas, Evas_Object *obj, void *event_info);
115 static void _mark_as_unread_cb(void *data, Evas_Object *obj, void *event_info);
116 static void _mark_as_read_cb(void *data, Evas_Object *obj, void *event_info);
117
118 static void _ctxpopup_detail_contact_cb(void *data, Evas_Object *obj, void *event_info);
119 static void _ctxpopup_send_email_cb(void *data, Evas_Object *obj, void *event_info);
120 static void _ctxpopup_add_contact_cb(void *data, Evas_Object *obj, void *event_info);
121 static void _ctxpopup_cutlink_update_contact_cb(void *data, Evas_Object *obj, void *event_info);
122 static void _ctxpopup_select_contact_mode_email_cb(void *data, Evas_Object *obj, void *event_info);
123 static void _ctxpopup_add_block_rule_cb(void *data, Evas_Object *obj, void *event_info);
124 static void _popup_response_cb(void *data, Evas_Object *obj, void *event_info);
125 static void _popup_response_delete_ok_cb(void *data, Evas_Object *obj, void *event_info);
126 static void _popup_response_to_destroy_cb(void *data, Evas_Object *obj, void *event_info);
127
128 static void _webview_multi_up_cb(void *data, Evas * evas, Evas_Object *obj, void *event_info);
129 static void _webview_multi_down_cb(void *data, Evas * evas, Evas_Object *obj, void *event_info);
130 static void _webview_policy_navigation_decide_cb(void *data, Evas_Object *obj, void *event_info);
131
132 static void _outter_scroller_bottom_hit_cb(void *data, Evas_Object *obj, void *event_info);
133 static void _outter_scroller_top_hit_cb(void *data, Evas_Object *obj, void *event_info);
134 static void _outter_scroller_scroll_cb(void *data, Evas_Object *obj, void *event_info);
135
136 static void _mbe_added_cb(void *data, Evas_Object *obj, void *event_info);
137 static void _mbe_selected_cb(void *data, Evas_Object *obj, void *event_info);
138 static void _destroy_down_progress_cb(void *data, Evas_Object *obj, void *event_info);
139
140 /* Logic Functions */
141 static void _init_viewer_data(int account_id, int mail_id, char *srv_mail_id, EmailViewerUGD *ug_data);
142 static int _init_webview_data(EmailViewerUGD *ug_data);
143 static Eina_Bool _check_body_download(void *data);
144 static int _update_attachment_info(EmailViewerUGD *ug_data, int index);
145 static int _get_attachment_info_index(EmailViewerUGD *ug_data, int index);
146 static void _show_select_info(EmailViewerUGD *ug_data, char *str);
147 static void _save_attachment(EmailViewerUGD *ug_data, int index);
148 static void _show_attachment(EmailViewerUGD *ug_data, int index);
149 static void _save_attachment_all(EmailViewerUGD *ug_data);
150 static void _dbus_receiver_setup(EmailViewerUGD *ug_data);
151 static void _dbus_receiver_remove(EmailViewerUGD *ug_data);
152 static void _on_edbus_event_email_viewer_receive(void *local_data, DBusMessage *message);
153
154 static void _delete_contacts_list(EMAIL_CONTACT_LIST_INFO_S *contacts_list_item);
155 static void *_contact_search_by_email(EmailViewerUGD *ug_data, const char *search_word);
156 static void _set_value_down_progress(double val);
157 static void _set_value_down_progress_by_index(double val, int index);
158 static void _cancel_download_attachment(EmailViewerUGD *ug_data);
159
160 /* Util Functions */
161 static char *_get_service_fail_type(int type);
162 static Evas_Object *_load_edj(Evas_Object *parent, const char *file, const char *group);
163
164 /* genlist cb */
165 static Eina_Bool _gl_state_get(void *data, Evas_Object *obj, const char *part);
166 static void _gl_del(void *data, Evas_Object *obj);
167 static char *_gl_text_get(void *data, Evas_Object *obj, const char *part);
168 static Evas_Object *_gl_content_get(void *data, Evas_Object *obj, const char *part);
169 static void _gl_sel(void *data, Evas_Object *obj, void *event_info);
170 static char *_gl_sub_upper_text_get(void *data, Evas_Object *obj, const char *part);
171 static Evas_Object *_gl_sub_upper_icon_get(void *data, Evas_Object *obj, const char *part);
172 static void _gl_sub_upper_sel(void *data, Evas_Object *obj, void *event_info);
173 static void _move_here_cb(void *data, Evas_Object *obj, void *event_info);
174 static void _move_back_cb(void *data, Evas_Object *obj, void *event_info);
175 static void _move_back_cb2(void *data, Evas_Object *obj, void *event_info);
176
177
178 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
179 {
180         debug_log("");
181
182         EmailViewerUGD *ug_data;
183
184         if (!ops)
185                 return -1;
186
187         ug_data = calloc(1, sizeof(EmailViewerUGD));
188         if (!ug_data)
189                 return -1;
190
191         _g_ug_data = ug_data;
192 //      g_type_init();
193
194         ops->create = on_create;
195         ops->start = on_start;
196         ops->pause = on_pause;
197         ops->resume = on_resume;
198         ops->destroy = on_destroy;
199         ops->message = on_message;
200         ops->event = on_event;
201         ops->key_event = on_key_event;
202         ops->priv = ug_data;
203         ops->opt = UG_OPT_INDICATOR_ENABLE;
204
205         return 0;
206 }
207
208 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
209 {
210         debug_log("");
211         EmailViewerUGD *ug_data;
212
213         if (!ops)
214                 return;
215
216         ug_data = ops->priv;
217         if (ug_data)
218                 free(ug_data);
219
220         debug_log("~");
221 }
222
223 static void *on_create(ui_gadget_h ug, enum ug_mode mode, service_h data, void *priv)
224 {
225         debug_log("");
226         EmailViewerUGD *ug_data;
227         char *account_id = NULL;
228         char *mail_id = NULL;
229         char *mailbox_id = NULL;
230         char *binternal = NULL;
231         char *landscape = NULL;
232
233         if (!ug || !priv)
234                 return NULL;
235
236         ug_data = priv;
237         ug_data->ug = ug;
238
239         if (!data) {
240                 debug_log("account_id and mail_id are required by arguments");
241                 ug_data->b_direct_destroy = 1;
242                 ug_destroy_me(ug_data->ug);
243                 _g_ug_data = NULL;
244                 return NULL;
245         }
246
247         /* email engine initialize */
248         if (email_engine_initialize() == FALSE) {
249                 debug_log("Failed to initialize email engine");
250                 ug_data->b_direct_destroy = 1;
251                 ug_destroy_me(ug_data->ug);
252                 _g_ug_data = NULL;
253                 return NULL;
254         }
255
256 /*      Elm_Theme *theme = elm_theme_new();
257         elm_theme_ref_set(theme, NULL);
258         ug_data->theme = theme;
259         elm_theme_extension_add(ug_data->theme, EV_THEME_PATH);*/
260
261         int ret;
262         ret = service_get_extra_data(data, EMAIL_BUNDLE_KEY_ACCOUNT_ID, (char **)&account_id);
263         debug_log("service_get_extra_data: %d", ret);
264         debug_log("account_id:%s", account_id);
265         ret = service_get_extra_data(data, EMAIL_BUNDLE_KEY_MAIL_ID, (char **)&mail_id);
266         debug_log("service_get_extra_data: %d", ret);
267         debug_log("mail_id:%s", mail_id);
268         ret = service_get_extra_data(data, EMAIL_BUNDLE_KEY_MAILBOX, (char **)&mailbox_id);
269         debug_log("service_get_extra_data: %d", ret);
270         debug_log("mailbox:%s", mailbox_id);
271         ret = service_get_extra_data(data, EMAIL_BUNDLE_KEY_INTERNAL, (char **)&binternal);
272         debug_log("service_get_extra_data: %d", ret);
273         debug_log("binternal:%s", binternal);
274         ret = service_get_extra_data(data, EMAIL_BUNDLE_KEY_FIRST_LANDSCAPE, (char **)&landscape);
275         debug_log("service_get_extra_data: %d", ret);
276         debug_log("landscape:%s", landscape);
277
278         if (landscape) {
279                 ug_data->isRotate = atoi(landscape);
280                 debug_log("@@@@ Landscape = %d @@@@", ug_data->isRotate);
281                 g_free(landscape);
282         }
283
284         if (account_id) {
285                 ug_data->account_id = atoi(account_id);
286                 ug_data->folder_list = email_engine_get_ca_mailbox_list_using_glist(ug_data->account_id);
287                 g_free(account_id);
288         }
289
290         if (mail_id) {
291                 ug_data->mail_id = atoi(mail_id);
292                 g_free(mail_id);
293         }
294
295         if (mailbox_id) {
296                 g_free(ug_data->mailbox_name);
297                 ug_data->mailbox_name = NULL;
298                 ug_data->mailbox_id = atoi(mailbox_id);
299                 g_free(mailbox_id);
300
301                 int err = 0;
302                 email_mail_data_t *mail_data = NULL;
303                 if ((err = email_get_mail_data(ug_data->mail_id, &mail_data)) != EMAIL_ERROR_NONE) {
304                         debug_log("fail to get mail - err (%d)", err);
305                 }
306
307                 if (mail_data == NULL) {
308                         debug_log("mail_data is NULL");
309                 }
310
311                 ug_data->mailbox_name = g_strdup(mail_data->server_mailbox_name);
312                 ug_data->mailbox_type = mail_data->mailbox_type;
313                 debug_log("server_mailbox_name:%s", mail_data->server_mailbox_name);
314                 debug_log("mailbox_name:%s", ug_data->mailbox_name);
315                 debug_log("mailbox_type:%d", ug_data->mailbox_type);
316
317                 if (mail_data) {
318                         debug_log("email_free_mail is called");
319                         email_free_mail_data(&(mail_data), 1);
320                         mail_data = NULL;
321                 }
322         }
323
324         if (binternal) {
325                 ug_data->b_internal = atoi(binternal);
326                 if (ug_data->b_internal == 1)
327                         debug_log("############Launched from email-mailbox###############");
328                 g_free(binternal);
329         }
330
331         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);
332
333         if (ug_data->account_id <= 0 || ug_data->mail_id <= 0 || ug_data->mailbox_id <= 0) {
334                 debug_log("Required bundle parameters are missing!");
335                 ug_data->timeout_popup = elm_popup_add(ug_get_window());
336                 evas_object_size_hint_weight_set(ug_data->timeout_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
337                 elm_popup_timeout_set(ug_data->timeout_popup, 2);
338                 elm_object_text_set(ug_data->timeout_popup, _("IDS_EMAIL_POP_UNABLE_TO_OPEN_EMAIL_MESSAGE"));
339                 elm_object_part_text_set(ug_data->timeout_popup, "title,text", _("IDS_EMAIL_POP_ALERT"));
340                 evas_object_smart_callback_add(ug_data->timeout_popup, "block,clicked", _popup_response_to_destroy_cb, ug_data);
341                 evas_object_smart_callback_add(ug_data->timeout_popup, "timeout", _popup_response_to_destroy_cb, ug_data);
342                 evas_object_show(ug_data->timeout_popup);
343
344                 return elm_layout_add(ug_get_window());
345         }
346
347         ug_data->win_main = ug_get_window();
348
349         char *proxy_address = vconf_get_str(VCONFKEY_NETWORK_PROXY);
350         debug_log("network proxy: %s", proxy_address);
351         if (proxy_address && (g_strcmp0(proxy_address, "") != 0)) {
352                 ewk_context_proxy_uri_set(ewk_context_default_get(), proxy_address);
353         }
354
355         if (proxy_address)
356                 free(proxy_address);
357
358         int w, h;
359         ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
360         debug_log("WINDOW W[%d] H[%d]", w, h);
361         ug_data->main_w = w;
362         ug_data->main_h = h;
363
364         ug_data->scale_factor = elm_scale_get();
365         debug_log("ELM Scale[%f]", ug_data->scale_factor);
366
367         if (w == 480) {
368                 ug_data->webview_width = 710.0;
369                 ug_data->webview_height = 949.0;
370                 ug_data->webview_width_landscape = 710.0;
371                 ug_data->webview_height_landscape = 568.0;
372                 ug_data->webview_margin = 633;
373                 ug_data->webview_margin_landscape = 379;
374         } else if (w == 720) {
375                 ug_data->webview_width = 710.0;
376                 ug_data->webview_height = 1009.0;
377                 ug_data->webview_width_landscape = 710.0;
378                 ug_data->webview_height_landscape = 558.0;
379                 ug_data->webview_margin = 1029;
380                 ug_data->webview_margin_landscape = 558;
381         } else {
382                 ug_data->webview_width = 710.0;
383                 ug_data->webview_height = 949.0;
384                 ug_data->webview_width_landscape = 710.0;
385                 ug_data->webview_height_landscape = 568.0;
386                 ug_data->webview_margin = 633;
387                 ug_data->webview_margin_landscape = 379;
388         }
389
390         ug_data->evas = evas_object_evas_get(ug_data->win_main);
391
392         /* Double_Scroller */
393         ug_data->b_noc = 1;
394
395         email_account_t *account = NULL;
396         if (email_engine_get_account_full_data(ug_data->account_id, &account)) {
397                 debug_log("email_engine_get_account");
398                 if (account) {
399                         ug_data->account_type = account->incoming_server_type;
400                         snprintf(ug_data->account_email_address, sizeof(ug_data->account_email_address), "%s", account->user_email_address);
401
402                         account_user_data_t *ud = (account_user_data_t*)account->user_data;
403                         if (ud != NULL) {
404                                 debug_log("show_images is %d", ud->show_images);
405                                 ug_data->b_show_remote_images = ud->show_images;
406                         }
407                         email_free_account(&account, 1);
408                         account = NULL;
409                 }
410         }
411
412         /* DBUS */
413         _dbus_receiver_setup(ug_data);
414
415         _init_viewer_data(ug_data->account_id, ug_data->mail_id, NULL, ug_data);
416         _create_view(ug_data);
417
418         _check_body_download(ug_data);
419
420         ug_data->base = ug_data->layout_main;
421
422         ug_data->display_download_result = TRUE;
423
424         return ug_data->base;
425 }
426
427 static void on_start(ui_gadget_h ug, service_h data, void *priv)
428 {
429         debug_log("");
430 }
431
432 static void on_pause(ui_gadget_h ug, service_h data, void *priv)
433 {
434         debug_log("");
435 }
436
437 static void on_resume(ui_gadget_h ug, service_h data, void *priv)
438 {
439         debug_log("");
440 }
441
442 static void on_destroy(ui_gadget_h ug, service_h data, void *pd)
443 {
444         debug_log("");
445         EmailViewerUGD *ug_data;
446
447         if (!ug || !pd)
448                 return;
449
450         ug_data = pd;
451
452         _g_ug_data = NULL;
453
454         if (ug_data->b_direct_destroy)
455                 return;
456
457         /* stop engine */
458         EmailViewerPrivate *priv = ug_data->email_data;
459         EmailViewerProp *prop = ug_data->property;
460         int i = 0;
461         int att_len = g_list_length(prop->attachments);
462
463         if (priv->email_handle != 0)
464                 email_engine_stop_working(ug_data->account_id, priv->email_handle);
465
466         for (i = 0; i < att_len; i++) {
467                 if (priv->download_all_email_handle[i] != 0)
468                         email_engine_stop_working(ug_data->account_id, priv->download_all_email_handle[i]);
469         }
470
471 /*      if (ug_data->theme) {
472                 elm_theme_extension_del(ug_data->theme, EV_THEME_PATH);
473                 elm_theme_free(ug_data->theme);
474                 ug_data->theme = NULL;
475         }*/
476
477         _delete_evas_objects(ug_data);
478
479         debug_log("free webview_data");
480         if (ug_data->webview_data) {
481                 free(ug_data->webview_data);
482                 ug_data->webview_data = NULL;
483         }
484
485         debug_log("free address info list");
486         email_free_address_info_list(&(priv->addrs_info_list));
487         ug_data->from_list = NULL;
488         ug_data->to_list = NULL;
489         ug_data->cc_list = NULL;
490         ug_data->bcc_list = NULL;
491
492         debug_log("free mail_info");
493         if (ug_data->email_data->mail_info) {
494                 email_free_mail_data(&(ug_data->email_data->mail_info), 1);
495                 ug_data->email_data->mail_info = NULL;
496         }
497
498         if (ug_data->email_data->attachment_info && ug_data->email_data->attachment_count > 0) {
499                 email_free_attachment_data(&(ug_data->email_data->attachment_info), ug_data->email_data->attachment_count);
500                 ug_data->email_data->attachment_info = NULL;
501                 ug_data->email_data->attachment_count = 0;
502         }
503
504         debug_log("free email_data");
505         if (ug_data->email_data) {
506                 free(ug_data->email_data);
507                 ug_data->email_data = NULL;
508         }
509
510         debug_log("free attachment");
511         if (ug_data->property->attachments) {
512                 int i = 0;
513                 LIST_ITER_START(i, ug_data->property->attachments) {
514                         EmailAttachmentType *info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, ug_data->property->attachments);
515                         if (info->name)
516                                 free(info->name);
517                         if (info->path)
518                                 free(info->path);
519                         free(info);
520                 }
521                 g_list_free(ug_data->property->attachments);
522                 ug_data->property->attachments = NULL;
523         }
524
525         debug_log("free property");
526         if (ug_data->property) {
527                 free(ug_data->property);
528                 ug_data->property = NULL;
529         }
530
531         email_engine_finalize();
532
533         _dbus_receiver_remove(NULL);
534
535         int ret = e_dbus_shutdown();
536         debug_log("ret: %d", ret);
537         debug_log("~");
538
539         ug_data->base = NULL;
540 }
541
542 static void on_message(ui_gadget_h ug, service_h msg, service_h data, void *priv)
543 {
544         debug_log("");
545
546         if (!ug || !priv)
547                 return;
548
549         debug_log("_g_ug_data - %p", _g_ug_data);
550         if (_g_ug_data != NULL) {
551                 debug_log("Hide previous mail data");
552                 _hide_view(_g_ug_data);
553         }
554
555         char *account_id = NULL;
556         char *mail_id = NULL;
557         char *mailbox_id = NULL;
558         char *binternal = NULL;
559         char *landscape = NULL;
560
561         EmailViewerUGD *ug_data = (EmailViewerUGD *)priv;
562         _g_ug_data = ug_data;
563
564         /* reset viewer */
565         int ret;
566         ret = service_get_extra_data(msg, EMAIL_BUNDLE_KEY_ACCOUNT_ID, (char **)&account_id);
567         debug_log("service_get_extra_data: %d", ret);
568         debug_log("account_id:%s", account_id);
569         ret = service_get_extra_data(msg, EMAIL_BUNDLE_KEY_MAIL_ID, (char **)&mail_id);
570         debug_log("service_get_extra_data: %d", ret);
571         debug_log("mail_id:%s", mail_id);
572         ret = service_get_extra_data(msg, EMAIL_BUNDLE_KEY_MAILBOX, (char **)&mailbox_id);
573         debug_log("service_get_extra_data: %d", ret);
574         debug_log("mailbox:%s", mailbox_id);
575         ret = service_get_extra_data(msg, EMAIL_BUNDLE_KEY_INTERNAL, (char **)&binternal);
576         debug_log("service_get_extra_data: %d", ret);
577         debug_log("binternal:%s", binternal);
578         ret = service_get_extra_data(msg, EMAIL_BUNDLE_KEY_FIRST_LANDSCAPE, (char **)&landscape);
579         debug_log("service_get_extra_data: %d", ret);
580         debug_log("landscape:%s", landscape);
581
582         if (landscape) {
583                 ug_data->isRotate = atoi(landscape);
584                 debug_log("@@@@ Landscape = %d @@@@", ug_data->isRotate);
585                 g_free(landscape);
586         }
587
588         if (account_id) {
589                 ug_data->account_id = atoi(account_id);
590                 ug_data->folder_list = email_engine_get_ca_mailbox_list_using_glist(ug_data->account_id);
591                 g_free(account_id);
592         }
593
594         if (mail_id) {
595                 ug_data->mail_id = atoi(mail_id);
596                 g_free(mail_id);
597         }
598
599         if (mailbox_id) {
600                 g_free(ug_data->mailbox_name);
601                 ug_data->mailbox_name = NULL;
602                 ug_data->mailbox_id = atoi(mailbox_id);
603                 g_free(mailbox_id);
604
605                 int err = 0;
606                 email_mail_data_t *mail_data = NULL;
607                 if ((err = email_get_mail_data(ug_data->mail_id, &mail_data)) != EMAIL_ERROR_NONE) {
608                         debug_log("fail to get mail - err (%d)", err);
609                 }
610
611                 if (mail_data == NULL) {
612                         debug_log("mail_data is NULL");
613                 }
614
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);
620
621                 if (mail_data) {
622                         debug_log("email_free_mail is called");
623                         email_free_mail_data(&(mail_data), 1);
624                         mail_data = NULL;
625                 }
626         }
627
628         if (binternal) {
629                 ug_data->b_internal = atoi(binternal);
630                 if (ug_data->b_internal == 1)
631                         debug_log("############Launched from email-mailbox###############");
632                 g_free(binternal);
633         }
634
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);
636
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!");
639                 _g_ug_data = NULL;
640                 return;
641         }
642
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");
646                 if (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);
649
650                         account_user_data_t *ud = (account_user_data_t*)account->user_data;
651                         if (ud != NULL) {
652                                 debug_log("show_images is %d", ud->show_images);
653                                 ug_data->b_show_remote_images = ud->show_images;
654                         }
655                         email_free_account(&account, 1);
656                         account = NULL;
657                 }
658
659                 Ewk_Setting *setting = ewk_view_setting_get(ug_data->webview);
660
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!");
664                 }
665         }
666
667         _init_viewer_data(ug_data->account_id, ug_data->mail_id, NULL, ug_data);
668
669         evas_object_show(ug_data->layout_main);
670         evas_object_raise(ug_data->layout_main);
671
672         _reset_view(ug_data);
673
674         ug_data->display_download_result = TRUE;
675 }
676
677 static void on_event(ui_gadget_h ug, enum ug_event event, service_h data, void *priv)
678 {
679         debug_log("");
680
681         if (!ug || !priv)
682                 return;
683
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;
688         int ret = 0;
689
690         debug_log("rotate event = %d", event);
691
692         switch (event) {
693         case UG_EVENT_LOW_MEMORY:
694                 break;
695         case UG_EVENT_LOW_BATTERY:
696                 break;
697         case UG_EVENT_LANG_CHANGE:
698                 break;
699         case UG_EVENT_ROTATE_PORTRAIT:
700         case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
701                 if (ug_data->b_internal && ug_data->isRotate == true) {
702                         debug_log("In Full view - Showing navi bar");
703                         elm_naviframe_item_title_visible_set(ug_data->navi_main_it, EINA_TRUE);
704
705                         if (ug_data->con_popup) {
706                                 evas_object_del(ug_data->con_popup);
707                                 ug_data->con_popup = NULL;
708                         }
709
710                         if (ug_data->navi_move_it1) {
711                                 debug_log("move1");
712                                 Evas_Object *move_back_btn = elm_button_add(ug_data->navi_bar);
713                                 elm_object_style_set(move_back_btn, "naviframe/back_btn/default");
714                                 evas_object_smart_callback_add(move_back_btn, "clicked", _move_back_cb, ug_data);
715                                 elm_object_item_part_content_set(ug_data->navi_move_it1, "prev_btn", move_back_btn);
716                                 elm_naviframe_item_title_visible_set(ug_data->navi_move_it1, EINA_TRUE);
717                                 if (ug_data->move_cbar) {
718                                         elm_object_item_part_content_unset(ug_data->navi_move_it1, "controlbar");
719                                         evas_object_del(ug_data->move_cbar);
720                                         ug_data->move_cbar = NULL;
721                                 }
722                         }
723                         if (ug_data->navi_move_it2) {
724                                 debug_log("move2");
725                                 Evas_Object *move_back_btn = elm_button_add(ug_data->navi_bar);
726                                 elm_object_style_set(move_back_btn, "naviframe/back_btn/default");
727                                 evas_object_smart_callback_add(move_back_btn, "clicked", _move_back_cb2, ug_data);
728                                 elm_object_item_part_content_set(ug_data->navi_move_it2, "prev_btn", move_back_btn);
729                                 elm_naviframe_item_title_visible_set(ug_data->navi_move_it2, EINA_TRUE);
730                         }
731
732                         if (ug_data->b_btn) {
733                                 evas_object_smart_callback_del(ug_data->b_btn, "clicked", _back_cb);
734                                 evas_object_del(ug_data->b_btn);
735                                 ug_data->b_btn = NULL;
736                         }
737
738                         ug_data->b_btn = elm_button_add(ug_data->navi_bar);
739                         elm_object_style_set(ug_data->b_btn, "naviframe/back_btn/default");
740                         evas_object_smart_callback_add(ug_data->b_btn, "clicked", _back_cb, ug_data);
741                         elm_object_item_part_content_set(ug_data->navi_main_it, "prev_btn", ug_data->b_btn);
742
743                         int resized_w = ug_data->webview_width * ug_data->scale_factor;
744                         int resized_h = ug_data->webview_height * ug_data->scale_factor;
745                         evas_object_size_hint_min_set(ug_data->webview, resized_w, resized_h);
746
747                         ug_data->isRotate = false;
748                 }
749
750                 break;
751
752         case UG_EVENT_ROTATE_LANDSCAPE:
753         case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
754                 if (ug_data->b_internal && ug_data->isRotate == false) {
755                         debug_log("In Split view - Hiding navi bar");
756                         elm_naviframe_item_title_visible_set(ug_data->navi_main_it, EINA_FALSE);
757
758                         if (ug_data->con_popup) {
759                                 evas_object_del(ug_data->con_popup);
760                                 ug_data->con_popup = NULL;
761                         }
762
763                         if (ug_data->navi_move_it1) {
764                                 debug_log("move1");
765                                 ug_data->move_cbar = elm_toolbar_add(ug_data->navi_bar);
766                                 elm_toolbar_shrink_mode_set(ug_data->move_cbar, ELM_TOOLBAR_SHRINK_EXPAND);
767                                 elm_object_style_set(ug_data->move_cbar, "naviframe");
768                                 evas_object_show(ug_data->move_cbar);
769
770                                 elm_object_item_disabled_set(elm_toolbar_item_append(ug_data->move_cbar, NULL, "", NULL, NULL), EINA_TRUE);
771                                 elm_toolbar_item_append(ug_data->move_cbar, NULL, dgettext("sys_string", "IDS_COM_SK_CANCEL"), _move_back_cb, ug_data);
772                                 elm_object_item_part_content_set(ug_data->navi_move_it1, "controlbar", ug_data->move_cbar);
773
774                                 Evas_Object *move_back_btn = elm_object_item_part_content_get(ug_data->navi_move_it1, "prev_btn");
775                                 if (move_back_btn) {
776                                         evas_object_smart_callback_del(move_back_btn, "clicked", _move_back_cb);
777                                         evas_object_del(move_back_btn);
778                                         elm_object_item_part_content_set(ug_data->navi_move_it1, "prev_btn", NULL);
779                                 }
780                                 elm_naviframe_item_title_visible_set(ug_data->navi_move_it1, EINA_FALSE);
781                         }
782                         if (ug_data->navi_move_it2) {
783                                 debug_log("move2");
784                                 Evas_Object *move_back_btn = elm_object_item_part_content_get(ug_data->navi_move_it2, "prev_btn");
785                                 if (move_back_btn) {
786                                         evas_object_smart_callback_del(move_back_btn, "clicked", _move_back_cb2);
787                                         evas_object_del(move_back_btn);
788                                         elm_object_item_part_content_set(ug_data->navi_move_it2, "prev_btn", NULL);
789                                 }
790                                 elm_naviframe_item_title_visible_set(ug_data->navi_move_it2, EINA_FALSE);
791                         }
792
793                         if (ug_data->b_btn) {
794                                 evas_object_smart_callback_del(ug_data->b_btn, "clicked", _back_cb);
795                                 evas_object_del(ug_data->b_btn);
796                                 ug_data->b_btn = NULL;
797                                 elm_object_item_part_content_set(ug_data->navi_main_it, "prev_btn", NULL);
798                         }
799
800                         int resized_w = ug_data->webview_width_landscape * ug_data->scale_factor;
801                         int resized_h = ug_data->webview_height_landscape * ug_data->scale_factor;
802                         evas_object_size_hint_min_set(ug_data->webview, resized_w, resized_h);
803
804                         ug_data->isRotate = true;
805                 }
806
807                 break;
808
809         case UG_EVENT_REGION_CHANGE:
810                 appcore_get_timeformat(&icu_timeformat);
811                 /* ICU API to set default locale */
812                 if (icu_timeformat == APPCORE_TIME_FORMAT_12)
813                         formatted_date = email_get_date_text(icu_locale, "yMdhms", &(prop->mktime));
814                 else
815                         formatted_date = email_get_date_text(icu_locale, "yMdHms", &(prop->mktime));
816                 ret = snprintf(date_time, MAX_STR_LEN, "%s", formatted_date);
817
818                 free(formatted_date);
819                 formatted_date = NULL;
820
821                 edje_object_part_text_set(_EDJ(ug_data->ly_subject), "elm.text.sub", date_time);
822                 evas_object_show(ug_data->ly_subject);
823                 break;
824
825         default:
826                 break;
827         }
828 }
829
830 static void on_key_event(ui_gadget_h ug, enum ug_key_event event, service_h data, void *priv)
831 {
832         debug_log("");
833
834         if (!ug)
835                 return;
836
837         EmailViewerUGD *ug_data = (EmailViewerUGD *)priv;
838         EmailViewerPrivate *private = ug_data->email_data;
839         EmailViewerProp *prop = ug_data->property;
840
841         switch (event) {
842         case UG_KEY_EVENT_END:
843                 if (_g_ug_data) {
844                         if (ug_data->notify != NULL || ug_data->pb_notify != NULL || ug_data->timeout_popup != NULL) {
845                                 if (ug_data->timeout_popup) {
846                                         evas_object_del(ug_data->timeout_popup);
847                                         ug_data->timeout_popup = NULL;
848                                 }
849
850                                 if (ug_data->notify) {
851                                         evas_object_del(ug_data->notify);
852                                         ug_data->notify = NULL;
853                                 }
854
855                                 if (ug_data->pb_notify) {
856                                         int i = 0;
857                                         int att_len = g_list_length(prop->attachments);
858
859                                         evas_object_del(ug_data->pb_notify);
860                                         ug_data->pb_notify = NULL;
861
862                                         if (private->email_handle != 0)
863                                                 email_engine_stop_working(ug_data->account_id, private->email_handle);
864
865                                         for (i = 0; i < att_len; i++) {
866                                                 if (private->download_all_email_handle[i] != 0)
867                                                         email_engine_stop_working(ug_data->account_id, private->download_all_email_handle[i]);
868                                         }
869                                 }
870
871                                 if (ug_data->pb_notify_lb) {
872                                         evas_object_del(ug_data->pb_notify_lb);
873                                         ug_data->pb_notify_lb = NULL;
874                                 }
875                         } else {
876                                 if (ug_data->isRotate == false && ug_data->b_internal) {
877                                         /* Viewer to hide, so set left content (mailbox) size to full */
878                                         _notify_mailbox_size(ug_data, "MAILBOX_RESIZE_FULL");
879                                 }
880
881                                 if (ug_data->b_internal)
882                                         _hide_view(ug_data);
883                                 else
884                                         ug_destroy_me(ug_data->ug);
885                         }
886                 } else {
887                         int ret;
888                         service_h service = NULL;
889
890                         ret = service_create(&service);
891                         debug_log("service_create: %d", ret);
892                         if (!service) {
893                                 debug_log("service create failed");
894                                 return;
895                         }
896
897                         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_MSG, EMAIL_BUNDLE_VAL_END_KEY);
898                         debug_log("service_add_extra_data: %d", ret);
899
900                         ug_send_message(_g_mailbox_ug, service);
901
902                         ret = service_destroy(service);
903                         debug_log("service_destroy: %d", ret);
904                 }
905                 break;
906
907         default:
908                 break;
909         }
910 }
911
912 static void layout_cb(ui_gadget_h ug, enum ug_mode mode, void *priv)
913 {
914         debug_log("");
915         Evas_Object *base, *win;
916
917         if (!ug || !priv)
918                 return;
919
920         base = ug_get_layout(ug);
921         if (!base)
922                 return;
923
924         win = ug_get_window();
925
926         switch (mode) {
927         case UG_MODE_FULLVIEW:
928                 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
929                 elm_win_resize_object_add(win, base);
930                 evas_object_show(base);
931                 break;
932         default:
933                 break;
934         }
935 }
936
937 static void result_cb(ui_gadget_h ug, service_h result, void *priv)
938 {
939         debug_log("");
940
941         if (!ug || !priv)
942                 return;
943
944         EmailViewerUGD *ug_data = (EmailViewerUGD *)priv;
945         EmailViewerProp *prop = ug_data->property;
946         EmailViewerPrivate *private = ug_data->email_data;
947
948         if (ug == ug_data->ug_composer) {
949                 char *cmd = NULL;
950                 int ret = service_get_extra_data(result, EMAIL_BUNDLE_KEY_SAVE_ALL, (char **)&cmd);
951                 debug_log("service_get_extra_data: %d", ret);
952                 debug_log("return of bundle_get_val for save all(%s)", cmd);
953                 if (cmd) {
954                         debug_log("save all from composer(%s)", cmd);
955
956                         if (prop->real_att_len == 1) {
957                                 private->b_all_att_save = TRUE;
958                                 _save_attachment(ug_data, 0);
959                         } else if (prop->real_att_len > 1) {
960                                 _save_attachment_all(ug_data);
961                         }
962                         g_free(cmd);
963                         return;
964                 }
965
966                 ret = service_get_extra_data(result, EMAIL_BUNDLE_KEY_CANCEL_ALL, (char **)&cmd);
967                 debug_log("service_get_extra_data: %d", ret);
968                 debug_log("return of bundle_get_val for cancel all(%s)", cmd);
969                 if (cmd) {
970                         debug_log("cancel all attachment from composer(%s)", cmd);
971
972                         _cancel_download_attachment(ug_data);
973                         g_free(cmd);
974                         return;
975                 }
976         }
977 }
978
979 static void destroy_cb(ui_gadget_h ug, void *priv)
980 {
981         debug_log("");
982         if (!ug || !priv)
983                 return;
984
985         EmailViewerUGD *ug_data = (EmailViewerUGD *)priv;
986         EmailViewerProp *prop = ug_data->property;
987         ug_data->display_download_result = TRUE;
988
989         if (ug == ug_data->ug_composer) {
990                 ug_data->ug_composer = NULL;
991         }
992
993         ug_destroy(ug);
994
995         if (ug_data->b_contact_ug_launched) {
996                 debug_log("change navibar title label");
997                 EMAIL_CONTACT_LIST_INFO_S *contact_list_item = NULL;
998                 contact_list_item = (EMAIL_CONTACT_LIST_INFO_S *)_contact_search_by_email(ug_data, prop->sender);
999
1000                 if (contact_list_item) {
1001                         elm_object_item_text_set(ug_data->navi_main_it, contact_list_item->display_name);
1002                         _delete_contacts_list(contact_list_item);
1003                 } else {
1004                         elm_object_item_text_set(ug_data->navi_main_it, prop->sender_display_name);
1005                 }
1006
1007                 ug_data->b_contact_ug_launched = FALSE;
1008         }
1009 }
1010
1011 static ui_gadget_h create_ug(char *ug_name, service_h bd, void *data)
1012 {
1013         debug_log("");
1014         ui_gadget_h ug;
1015         struct ug_cbs cbs = { 0, };
1016
1017         cbs.layout_cb = layout_cb;
1018         cbs.result_cb = result_cb;
1019         cbs.destroy_cb = destroy_cb;
1020         cbs.priv = data;
1021
1022         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
1023
1024         ug = ug_create(ug_data->ug, ug_name, UG_MODE_FULLVIEW, bd, &cbs);
1025
1026         return ug;
1027 }
1028
1029 static void _create_view(EmailViewerUGD *ug_data)
1030 {
1031         debug_log("");
1032
1033         Evas_Object *b_btn;
1034         Evas_Object *prev_btn;
1035         Evas_Object *next_btn;
1036         EmailViewerProp *prop = ug_data->property;
1037
1038         ug_data->bg = _create_bg(ug_data->win_main);
1039
1040         /* create layout */
1041         ug_data->layout_main = elm_layout_add(ug_data->win_main);
1042
1043         if (ug_data->b_internal)
1044                 elm_layout_theme_set(ug_data->layout_main, "layout", "application", "noindicator");
1045         else
1046                 elm_layout_theme_set(ug_data->layout_main, "layout", "application", "default");
1047         evas_object_size_hint_weight_set(ug_data->layout_main, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1048         evas_object_show(ug_data->layout_main);
1049
1050         elm_object_part_content_set(ug_data->layout_main, "elm.swallow.bg", ug_data->bg);
1051
1052         /* indicator */
1053         elm_win_indicator_mode_set(ug_data->win_main, ELM_WIN_INDICATOR_SHOW);
1054
1055         evas_object_smart_callback_add(ug_data->win_main, "profile,changed", _win_profile_changed_cb, ug_data);
1056
1057         /* navigation Bar */
1058         _create_navigation_bar(ug_data);
1059
1060         /* push navigation bar */
1061         ug_data->sub_ly = elm_layout_add(ug_data->navi_bar);
1062         elm_layout_theme_set(ug_data->sub_ly, "layout", "application", "noindicator");
1063         evas_object_size_hint_weight_set(ug_data->sub_ly, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1064         evas_object_show(ug_data->sub_ly);
1065
1066         /* back button */
1067         b_btn = elm_button_add(ug_data->navi_bar);
1068         elm_object_style_set(b_btn, "naviframe/back_btn/default");
1069         evas_object_smart_callback_add(b_btn, "clicked", _back_cb, ug_data);
1070         ug_data->b_btn = b_btn;
1071
1072         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);
1073
1074         if (ug_data->b_internal) {
1075                 /* Left : previous button */
1076                 prev_btn = elm_button_add(ug_data->navi_bar);
1077                 Evas_Object *prev_ic = elm_icon_add(prev_btn);
1078                 elm_icon_file_set(prev_ic, IMGDIR "/M02_icon_previous.png", NULL);
1079                 elm_object_style_set(prev_btn, "naviframe/title/default");
1080                 evas_object_size_hint_aspect_set(prev_ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
1081                 elm_icon_resizable_set(prev_ic, 0.8, 0.8);
1082                 elm_object_part_content_set(prev_btn, "icon", prev_ic);
1083                 elm_object_item_part_content_set(ug_data->navi_main_it, "title_left_btn", prev_btn);
1084                 evas_object_smart_callback_add(prev_btn, "clicked", _prev_mail_cb, ug_data);
1085                 ug_data->prev_btn = prev_btn;
1086
1087                 /* Right : next button */
1088                 next_btn = elm_button_add(ug_data->navi_bar);
1089                 Evas_Object *next_ic = elm_icon_add(next_btn);
1090                 elm_icon_file_set(next_ic, IMGDIR "/M02_icon_next.png", NULL);
1091                 elm_object_style_set(next_btn, "naviframe/title/default");
1092                 evas_object_size_hint_aspect_set(next_ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
1093                 elm_icon_resizable_set(next_ic, 0.8, 0.8);
1094                 elm_object_part_content_set(next_btn, "icon", next_ic);
1095                 elm_object_item_part_content_set(ug_data->navi_main_it, "title_right_btn", next_btn);
1096                 evas_object_smart_callback_add(next_btn, "clicked", _next_mail_cb, ug_data);
1097                 ug_data->next_btn = next_btn;
1098         }
1099
1100         /* create scroller */
1101         ug_data->scroller = elm_scroller_add(ug_data->navi_bar);
1102         evas_object_propagate_events_set(ug_data->scroller, EINA_FALSE);
1103         elm_scroller_bounce_set(ug_data->scroller, EINA_FALSE, EINA_TRUE);
1104         elm_scroller_policy_set(ug_data->scroller, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF);
1105         evas_object_show(ug_data->scroller);
1106         evas_object_smart_callback_add(ug_data->scroller, "edge,bottom", _outter_scroller_bottom_hit_cb, ug_data);
1107         evas_object_smart_callback_add(ug_data->scroller, "edge,top", _outter_scroller_top_hit_cb, ug_data);
1108         evas_object_smart_callback_add(ug_data->scroller, "scroll,drag,start", _outter_scroller_scroll_cb, ug_data);
1109
1110         /* create conformant */
1111         elm_win_conformant_set(ug_data->win_main, EINA_TRUE);
1112         ug_data->conformant = elm_conformant_add(ug_data->sub_ly);
1113         elm_object_style_set(ug_data->conformant, "internal_layout");
1114         evas_object_size_hint_weight_set(ug_data->conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1115         evas_object_size_hint_align_set(ug_data->conformant, EVAS_HINT_FILL, EVAS_HINT_FILL);
1116         elm_object_content_set(ug_data->conformant, ug_data->scroller);
1117         elm_object_part_content_set(ug_data->sub_ly, "elm.swallow.content", ug_data->conformant);
1118         evas_object_show(ug_data->conformant);
1119
1120         if (ug_data->from_list != NULL) {
1121                 email_address_info_t *addrs_info = NULL;
1122                 int n_from_list = g_list_length(ug_data->from_list);
1123                 debug_log("from list count [%d]", n_from_list);
1124
1125                 if (n_from_list > 0) {
1126                         addrs_info = (email_address_info_t *) g_list_nth_data(ug_data->from_list, 0);
1127                         debug_log("From Address:%s", addrs_info->address);
1128                         debug_log("Display Name:%s", addrs_info->display_name);
1129                         debug_log("Storage Type:%d", addrs_info->storage_type);
1130                         debug_log("Contact ID:%d", addrs_info->contact_id);
1131                         debug_log("");
1132                         g_free(prop->sender_display_name);
1133                         prop->sender_display_name = g_strdup(addrs_info->display_name);
1134                         g_free(prop->sender);
1135                         prop->sender = g_strdup(addrs_info->address);
1136
1137                         if (addrs_info->display_name && strlen(addrs_info->display_name) > 0)
1138                                 elm_object_item_text_set(ug_data->navi_main_it, addrs_info->display_name);
1139                         else
1140                                 elm_object_item_text_set(ug_data->navi_main_it, addrs_info->address);
1141                 }
1142         }
1143
1144         /* create main box */
1145         ug_data->main_bx = elm_box_add(ug_data->navi_bar);
1146         evas_object_size_hint_weight_set(ug_data->main_bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1147         evas_object_size_hint_align_set(ug_data->main_bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
1148         evas_object_show(ug_data->main_bx);
1149         elm_object_content_set(ug_data->scroller, ug_data->main_bx);
1150
1151         if (ug_data->property->has_attachment)
1152                 ug_data->got_att = 1;
1153         else
1154                 ug_data->got_att = 0;
1155
1156         /* packing subject, addrs, attachment */
1157         _create_subject(ug_data);
1158
1159         if (ug_data->got_att) {
1160                 _create_attach(ug_data);
1161         }
1162
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);
1166
1167                 if (ug_data->b_btn) {
1168
1169                         debug_log("hiding back button");
1170
1171                         evas_object_smart_callback_del(ug_data->b_btn, "clicked", _back_cb);
1172                         evas_object_del(ug_data->b_btn);
1173                         ug_data->b_btn = NULL;
1174
1175                         elm_object_item_part_content_set(ug_data->navi_main_it, "prev_btn", NULL);
1176                 }
1177         }
1178 }
1179
1180 static void _reset_view(EmailViewerUGD *ug_data)
1181 {
1182         debug_log("");
1183         EmailViewerProp *prop = ug_data->property;
1184         int ret;
1185         char date_time[MAX_STR_LEN] = { 0, };
1186
1187         debug_log("@@@@@@@@@@ isRotate = %d", ug_data->isRotate);
1188         if (ug_data->isRotate == true) {
1189                 debug_log("In Split view - Hiding navi bar");
1190                 elm_naviframe_item_title_visible_set(ug_data->navi_main_it, EINA_FALSE);
1191
1192                 if (ug_data->b_btn) {
1193
1194                         debug_log("hiding back button");
1195
1196                         evas_object_smart_callback_del(ug_data->b_btn, "clicked", _back_cb);
1197                         evas_object_del(ug_data->b_btn);
1198                         ug_data->b_btn = NULL;
1199
1200                         elm_object_item_part_content_set(ug_data->navi_main_it, "prev_btn", NULL);
1201                 }
1202
1203                 /* Set scroller to start - height made 480 to consider viewer in split view */
1204                 elm_scroller_region_show(ug_data->scroller, 0, 0, (int)((double)ug_data->main_h * 0.6), ug_data->main_w);
1205         } else {
1206                 debug_log("In Full view - Showing navi bar");
1207                 elm_naviframe_item_title_visible_set(ug_data->navi_main_it, EINA_TRUE);
1208
1209                 if (ug_data->b_btn) {
1210
1211                         evas_object_smart_callback_del(ug_data->b_btn, "clicked", _back_cb);
1212                         evas_object_del(ug_data->b_btn);
1213                         ug_data->b_btn = NULL;
1214                 }
1215
1216                 debug_log("showing back button");
1217
1218                 ug_data->b_btn = elm_button_add(ug_data->navi_bar);
1219                 elm_object_style_set(ug_data->b_btn, "naviframe/back_btn/default");
1220                 evas_object_smart_callback_add(ug_data->b_btn, "clicked", _back_cb, ug_data);
1221
1222                 elm_object_item_part_content_set(ug_data->navi_main_it, "prev_btn", ug_data->b_btn);
1223
1224                 /* Set scroller to start */
1225                 elm_scroller_region_show(ug_data->scroller, 0, 0, ug_data->main_w, ug_data->main_h);
1226         }
1227
1228         if (ug_data->from_list != NULL) {
1229                 email_address_info_t *addrs_info = NULL;
1230                 int n_from_list = g_list_length(ug_data->from_list);
1231                 debug_log("from list count [%d]", n_from_list);
1232
1233                 if (n_from_list > 0) {
1234                         addrs_info = (email_address_info_t *) g_list_nth_data(ug_data->from_list, 0);
1235                         if (addrs_info) {
1236                                 debug_log("From Address:%s", addrs_info->address);
1237                                 debug_log("Display Name:%s", addrs_info->display_name);
1238                                 debug_log("Storage Type:%d", addrs_info->storage_type);
1239                                 debug_log("Contact ID:%d", addrs_info->contact_id);
1240                                 g_free(prop->sender_display_name);
1241                                 prop->sender_display_name = g_strdup(addrs_info->display_name);
1242                                 g_free(prop->sender);
1243                                 prop->sender = g_strdup(addrs_info->address);
1244
1245                                 if (addrs_info->display_name && strlen(addrs_info->display_name) > 0)
1246                                         elm_object_item_text_set(ug_data->navi_main_it, addrs_info->display_name);
1247                                 else
1248                                         elm_object_item_text_set(ug_data->navi_main_it, addrs_info->address);
1249                         }
1250                 }
1251         } else {
1252                 elm_object_item_text_set(ug_data->navi_main_it, prop->sender_display_name);
1253         }
1254
1255         /* reset subject */
1256         char *_subject = elm_entry_utf8_to_markup(prop->subject);
1257         char *_subject_concated = g_strconcat("<font_size=44><color=#000000FF>", _subject, "</color></font_size>", NULL);
1258         elm_object_text_set(ug_data->lb_subject, _subject_concated);
1259         elm_label_wrap_width_set(ug_data->lb_subject, ug_data->main_w - (int)(110 * ug_data->scale_factor));
1260         elm_label_line_wrap_set(ug_data->lb_subject, ELM_WRAP_WORD);
1261         g_free(_subject);
1262         g_free(_subject_concated);
1263
1264         /* reset date & time */
1265         char *formatted_date = NULL;
1266
1267         if (icu_timeformat == APPCORE_TIME_FORMAT_12)
1268                 formatted_date = email_get_date_text(icu_locale, "yMdhms", &(prop->mktime));
1269         else
1270                 formatted_date = email_get_date_text(icu_locale, "yMdHms", &(prop->mktime));
1271         ret = snprintf(date_time, MAX_STR_LEN, "%s", formatted_date);
1272
1273         free(formatted_date);
1274         formatted_date = NULL;
1275
1276         elm_object_part_text_set(ug_data->ly_subject, "elm.text.sub", date_time);
1277
1278         Evas_Object *favorite_icon = elm_icon_add(ug_data->ly_subject);
1279         switch(prop->favorite)
1280         {
1281                 case EMAIL_FLAG_NONE:
1282                         elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_icon_favorite_off.png", NULL);
1283                         break;
1284                 case EMAIL_FLAG_FLAGED:
1285                         elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_icon_favorite_on.png", NULL);
1286                         break;
1287                 case EMAIL_FLAG_TASK_STATUS_CLEAR:
1288                         elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_Flag_Clear.png", NULL);
1289                         break;
1290                 case EMAIL_FLAG_TASK_STATUS_ACTIVE:
1291                         elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_Flag_Active.png", NULL);
1292                         break;
1293                 case EMAIL_FLAG_TASK_STATUS_COMPLETE:
1294                         elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_Flag_Complete.png", NULL);
1295                         break;
1296         }
1297         evas_object_size_hint_aspect_set(favorite_icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
1298         elm_icon_resizable_set(favorite_icon, 1, 1);
1299         evas_object_del(elm_object_part_content_unset(ug_data->ly_subject, "elm.icon.favorite"));
1300         elm_object_part_content_set(ug_data->ly_subject, "elm.icon.favorite", favorite_icon);
1301         evas_object_show(favorite_icon);
1302
1303         evas_object_show(ug_data->ly_subject);
1304         elm_box_pack_end(ug_data->main_bx, ug_data->ly_subject);
1305
1306         if (prop->has_attachment)
1307                 ug_data->got_att = 1;
1308         else
1309                 ug_data->got_att = 0;
1310
1311         /* pack attachment if it exist */
1312         if (ug_data->got_att) {
1313                 _create_attach(ug_data);
1314         }
1315
1316         /* check body downloaded */
1317         _check_body_download(ug_data);
1318 }
1319
1320 void _hide_view(EmailViewerUGD *ug_data)
1321 {
1322         debug_log("");
1323         EmailViewerProp *prop = ug_data->property;
1324         EmailViewerPrivate *priv = ug_data->email_data;
1325
1326         debug_log("Cancelling all attachment downloads");
1327         _cancel_download_attachment(ug_data);
1328
1329         ug_data->display_download_result = FALSE;
1330         _g_ug_data = NULL;
1331
1332         if (elm_naviframe_top_item_get(ug_data->navi_bar) != ug_data->navi_main_it) {
1333                 ug_data->navi_move_it1 = NULL;
1334                 ug_data->navi_move_it2 = NULL;
1335                 elm_naviframe_item_pop_to(ug_data->navi_main_it);
1336         }
1337
1338         evas_object_hide(ug_data->layout_main);
1339         elm_box_unpack_all(ug_data->main_bx);
1340         elm_object_scroll_freeze_pop(ug_data->scroller);
1341
1342         evas_object_hide(ug_data->ly_subject);
1343         evas_object_hide(ug_data->lb_subject);
1344         evas_object_hide(ug_data->webview_bx);
1345         evas_object_hide(ug_data->webview);
1346
1347         if (ug_data->partial_dn_btn) {
1348                 evas_object_del(ug_data->partial_dn_btn);
1349                 ug_data->partial_dn_btn = NULL;
1350         }
1351
1352         if (ug_data->partial_dn_btn_bx) {
1353                 evas_object_del(ug_data->partial_dn_btn_bx);
1354                 ug_data->partial_dn_btn_bx = NULL;
1355         }
1356
1357         if (ug_data->ctr_bar) {
1358                 elm_object_item_part_content_unset(ug_data->navi_main_it, "controlbar");
1359                 evas_object_del(ug_data->ctr_bar);
1360                 ug_data->ctr_bar = NULL;
1361
1362                 ug_data->reply_ctr_it = NULL;
1363                 ug_data->replyall_ctr_it = NULL;
1364                 ug_data->forward_ctr_it = NULL;
1365                 ug_data->calendar_ctr_it = NULL;
1366                 ug_data->resend_ctr_it = NULL;
1367                 ug_data->move_ctr_it = NULL;
1368                 ug_data->del_ctr_it = NULL;
1369         }
1370
1371         if (ug_data->to_ly) {
1372                 evas_object_del(ug_data->to_ly);
1373                 ug_data->to_ly = NULL;
1374         }
1375
1376         if (ug_data->cc_ly) {
1377                 evas_object_del(ug_data->cc_ly);
1378                 ug_data->cc_ly = NULL;
1379         }
1380
1381         if (ug_data->bcc_ly) {
1382                 evas_object_del(ug_data->bcc_ly);
1383                 ug_data->bcc_ly = NULL;
1384         }
1385
1386         if (ug_data->got_att) {
1387                 int i;
1388
1389                 evas_object_del(ug_data->attach_hd_bk);
1390                 ug_data->attach_hd_ly = NULL;
1391                 ug_data->attach_hd_bk = NULL;
1392
1393                 if (prop->real_att_len > 1) {
1394                         for (i = 0; i < prop->real_att_len; i++) {
1395                                 if (ug_data->attach_ex_ly != NULL) {
1396                                         if (ug_data->attach_ex_ly[i] != NULL) {
1397                                                 debug_log("index %d", i);
1398                                                 evas_object_del(ug_data->attach_ex_bk[i]);
1399                                                 ug_data->attach_ex_ly[i] = NULL;
1400                                                 ug_data->attach_ex_bk[i] = NULL;
1401                                         }
1402                                 }
1403                         }
1404
1405                         if (ug_data->attach_ex_ly != NULL) {
1406                                 free(ug_data->attach_ex_ly);
1407                                 ug_data->attach_ex_ly = NULL;
1408                                 ug_data->attach_ex_bk = NULL;
1409                         }
1410                 }
1411
1412                 for (i = 0; i <= prop->att_len; i++) {
1413                         if (ug_data->progress_bar_ly[i] != NULL) {
1414                                 evas_object_del(ug_data->progress_bar_ly[i]);
1415                                 ug_data->progress_bar_ly[i] = NULL;
1416                                 ug_data->progress_bar[i] = NULL;
1417                         }
1418                 }
1419         }
1420
1421         if (ug_data->con_popup != NULL) {
1422                 evas_object_del(ug_data->con_popup);
1423                 ug_data->con_popup = NULL;
1424         }
1425
1426         if (ug_data->notify != NULL) {
1427                 evas_object_del(ug_data->notify);
1428                 ug_data->notify = NULL;
1429         }
1430
1431         edje_object_signal_emit(_EDJ(ug_data->ly_subject), "elm,state,contracted", "elm");
1432
1433         evas_object_hide(ug_data->noc_bx);
1434         evas_object_hide(ug_data->dn_btn);
1435
1436         ewk_view_uri_set(ug_data->webview, EMAIL_DEFAULT_HTML);
1437
1438         debug_log("free address info list");
1439         email_free_address_info_list(&(priv->addrs_info_list));
1440         ug_data->from_list = NULL;
1441         ug_data->to_list = NULL;
1442         ug_data->cc_list = NULL;
1443         ug_data->bcc_list = NULL;
1444
1445         ug_data->got_att = 0;
1446         ug_data->subject_onoff_flag = 0;
1447         ug_data->attach_onoff_flag = 0;
1448         ug_data->b_partial_body = 0;
1449         ug_data->b_internal = 0;
1450         ug_data->scroller_locked = 0;
1451         ug_data->m_is_multi_touch = 0;
1452
1453         ug_data->navi_move_it1 = NULL;
1454         ug_data->navi_move_it2 = NULL;
1455
1456         /* Double_Scroller */
1457         ug_data->b_noc = 1;
1458         ug_data->b_load_finished = EINA_FALSE;
1459         ug_data->b_show_remote_images = EINA_FALSE;
1460         ug_data->is_webview_scrolling = EINA_FALSE;
1461         ug_data->is_main_scroller_scrolling = EINA_FALSE;
1462 }
1463
1464 static void _win_profile_changed_cb(void *data, Evas_Object *obj, void *event)
1465 {
1466         debug_log("");
1467         if (!data) {
1468                 debug_log("data is NULL");
1469                 return;
1470         }
1471
1472         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
1473
1474         const char *profile = elm_config_profile_get();
1475         if (!g_strcmp0(profile, "desktop"))
1476                 elm_layout_theme_set(ug_data->layout_main, "layout", "application", "noindicator");
1477         else
1478                 elm_layout_theme_set(ug_data->layout_main, "layout", "application", "default");
1479
1480         evas_object_size_hint_weight_set(ug_data->layout_main, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1481         elm_win_resize_object_add(ug_data->win_main, ug_data->layout_main);
1482         evas_object_show(ug_data->layout_main);
1483 }
1484
1485 static Evas_Object *_create_navigation_bar(EmailViewerUGD *ug_data)
1486 {
1487         debug_log("");
1488         Evas_Object *navi_bar;
1489
1490         navi_bar = elm_naviframe_add(ug_data->layout_main);
1491         if (navi_bar == NULL) {
1492                 debug_log("navi_bar == NULL");
1493                 return NULL;
1494         }
1495
1496         elm_object_part_content_set(ug_data->layout_main, "elm.swallow.content", navi_bar);
1497         evas_object_show(navi_bar);
1498
1499         ug_data->navi_bar = navi_bar;
1500         return navi_bar;
1501 }
1502
1503 static Evas_Object *_create_subject(EmailViewerUGD *ug_data)
1504 {
1505         debug_log("");
1506         EmailViewerProp *prop = ug_data->property;
1507         int ret;
1508         char date_time[MAX_STR_LEN] = { 0, };
1509
1510         /* append subject */
1511         Evas_Object *di = elm_layout_add(ug_data->navi_bar);
1512         elm_layout_file_set(di, EV_THEME_PATH, "layout.email.detail_subject");
1513         evas_object_size_hint_align_set(di, EVAS_HINT_FILL, 0.0);
1514
1515         Evas_Object *subject_label;
1516         subject_label = elm_label_add(di);
1517         elm_object_part_content_set(di, "elm.text", subject_label);
1518         char *subject = elm_entry_utf8_to_markup(prop->subject);
1519         char *subject_tagged = g_strconcat("<font_size=44><color=#000000FF>", subject, "</color></font_size>", NULL);
1520         elm_object_text_set(subject_label, subject_tagged);
1521         elm_label_wrap_width_set(subject_label, ug_data->main_w - (int)(110 * ug_data->scale_factor));
1522         elm_label_line_wrap_set(subject_label, ELM_WRAP_WORD);
1523         ug_data->lb_subject = subject_label;
1524         g_free(subject);
1525         g_free(subject_tagged);
1526
1527         char *formatted_date = NULL;
1528
1529         if (icu_timeformat == APPCORE_TIME_FORMAT_12)
1530                 formatted_date = email_get_date_text(icu_locale, "yMdhms", &(prop->mktime));
1531         else
1532                 formatted_date = email_get_date_text(icu_locale, "yMdHms", &(prop->mktime));
1533         ret = snprintf(date_time, MAX_STR_LEN, "%s", formatted_date);
1534         free(formatted_date);
1535         formatted_date = NULL;
1536
1537         elm_object_part_text_set(di, "elm.text.sub", date_time);
1538
1539         Evas_Object *favorite_icon = elm_icon_add(di);
1540         switch(prop->favorite)
1541         {
1542                 case EMAIL_FLAG_NONE:
1543                         elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_icon_favorite_off.png", NULL);
1544                         break;
1545                 case EMAIL_FLAG_FLAGED:
1546                         elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_icon_favorite_on.png", NULL);
1547                         break;
1548                 case EMAIL_FLAG_TASK_STATUS_CLEAR:
1549                         elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_Flag_Clear.png", NULL);
1550                         break;
1551                 case EMAIL_FLAG_TASK_STATUS_ACTIVE:
1552                         elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_Flag_Active.png", NULL);
1553                         break;
1554                 case EMAIL_FLAG_TASK_STATUS_COMPLETE:
1555                         elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_Flag_Complete.png", NULL);
1556                         break;
1557         }
1558         evas_object_size_hint_aspect_set(favorite_icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
1559         elm_icon_resizable_set(favorite_icon, 1, 1);
1560         elm_object_part_content_set(di, "elm.icon.favorite", favorite_icon);
1561         evas_object_show(favorite_icon);
1562
1563         evas_object_show(di);
1564         elm_box_pack_end(ug_data->main_bx, di);
1565         ug_data->ly_subject = di;
1566
1567         Evas_Object *edje = elm_layout_edje_get(di);
1568
1569         if (ug_data->to_list || ug_data->cc_list || ug_data->bcc_list) {
1570                 edje_object_signal_callback_add(edje, "elm,action,expand,toggle", "elm", _subject_detail_clicked_cb, di);
1571                 edje_object_signal_callback_add(edje, "elm,action,toggle", "elm", _subject_favorite_clicked_cb, di);
1572         } else {
1573                 edje_object_signal_emit(edje, "elm,state,arrow_hidden", "elm");
1574         }
1575
1576         return di;
1577 }
1578
1579 static Evas_Object *_create_to_addrs(EmailViewerUGD *ug_data)
1580 {
1581         debug_log("");
1582         email_address_info_t *addrs_info = NULL;
1583         Elm_Object_Item *mbe_item;
1584
1585         if (ug_data->to_list == NULL) {
1586                 debug_log("to_list is NULL");
1587                 return NULL;
1588         }
1589
1590         int n_to_list = g_list_length(ug_data->to_list);
1591         int i = 0;
1592
1593         if (n_to_list <= 0) {
1594                 debug_log("to_list count is 0");
1595                 return NULL;
1596         }
1597
1598         Evas_Object *di = elm_layout_add(ug_data->main_bx);
1599         elm_layout_file_set(di, EV_THEME_PATH, "layout.email.to_cc");
1600         evas_object_size_hint_align_set(di, EVAS_HINT_FILL, 0.0);
1601         evas_object_show(di);
1602         ug_data->to_ly = di;
1603         elm_box_pack_after(ug_data->main_bx, di, ug_data->ly_subject);
1604
1605         Evas_Object *to_mbe = elm_multibuttonentry_add(ug_data->main_bx);
1606         char desc[MAX_STR_LEN] = { 0, };
1607         snprintf(desc, MAX_STR_LEN, "%s:", dgettext("sys_string", "IDS_COM_BODY_TO"));
1608         char *to_str = g_strconcat("<font_size=36><color=#000000FF>", desc, "</color></font_size>", NULL);
1609         elm_object_text_set(to_mbe, to_str);
1610         g_free(to_str);
1611
1612         evas_object_smart_callback_add(to_mbe, "item,clicked", _mbe_selected_cb, ug_data);
1613         evas_object_smart_callback_add(to_mbe, "item,added", _mbe_added_cb, ug_data);
1614         elm_object_part_content_set(di, "elm.icon", to_mbe);
1615         ug_data->to_mbe = to_mbe;
1616
1617         Evas_Object *entry = elm_multibuttonentry_entry_get(to_mbe);
1618         if (entry)
1619                 elm_entry_editable_set(entry, EINA_FALSE);
1620
1621         if (n_to_list > EMAIL_VIEW_MAX_TO_COUNT)
1622                 n_to_list = EMAIL_VIEW_MAX_TO_COUNT;
1623
1624         for (i = 0; i < n_to_list; i++) {
1625                 addrs_info = (email_address_info_t *) g_list_nth_data(ug_data->to_list, i);
1626                 debug_log("Address:%s", addrs_info->address);
1627                 debug_log("Display Name:%s", addrs_info->display_name);
1628                 debug_log("Storage Type:%d", addrs_info->storage_type);
1629                 debug_log("Contact ID:%d", addrs_info->contact_id);
1630                 debug_log("");
1631                 if (addrs_info->display_name && strlen(addrs_info->display_name) > 0)
1632                         mbe_item = elm_multibuttonentry_item_append(to_mbe, addrs_info->display_name, NULL, NULL);
1633                 else
1634                         mbe_item = elm_multibuttonentry_item_append(to_mbe, addrs_info->address, NULL, NULL);
1635                 elm_object_item_data_set(mbe_item, addrs_info);
1636         }
1637
1638         return di;
1639 }
1640
1641 static Evas_Object *_create_cc_addrs(EmailViewerUGD *ug_data)
1642 {
1643         debug_log("");
1644         email_address_info_t *addrs_info = NULL;
1645         Elm_Object_Item *mbe_item;
1646
1647         if (ug_data->cc_list == NULL) {
1648                 debug_log("cc_list is NULL");
1649                 return NULL;
1650         }
1651
1652         int n_cc_list = g_list_length(ug_data->cc_list);
1653         int i = 0;
1654
1655         if (n_cc_list <= 0) {
1656                 debug_log("cc_list count is 0");
1657                 return NULL;
1658         }
1659
1660         Evas_Object *di = elm_layout_add(ug_data->main_bx);
1661         elm_layout_file_set(di, EV_THEME_PATH, "layout.email.to_cc");
1662         evas_object_size_hint_align_set(di, EVAS_HINT_FILL, 0.0);
1663         evas_object_show(di);
1664         ug_data->cc_ly = di;
1665
1666         if (ug_data->to_ly) {
1667                 elm_box_pack_after(ug_data->main_bx, di, ug_data->to_ly);
1668         } else {
1669                 elm_box_pack_after(ug_data->main_bx, di, ug_data->ly_subject);
1670         }
1671
1672         Evas_Object *cc_mbe = elm_multibuttonentry_add(ug_data->main_bx);
1673         char desc[MAX_STR_LEN] = { 0, };
1674         snprintf(desc, MAX_STR_LEN, "%s:", _("IDS_EMAIL_BODY_CC"));
1675         char *cc_str = g_strconcat("<font_size=36><color=#000000FF>", desc, "</color></font_size>", NULL);
1676         elm_object_text_set(cc_mbe, cc_str);
1677         g_free(cc_str);
1678         evas_object_smart_callback_add(cc_mbe, "item,clicked", _mbe_selected_cb, ug_data);
1679         evas_object_smart_callback_add(cc_mbe, "item,added", _mbe_added_cb, ug_data);
1680         elm_object_part_content_set(di, "elm.icon", cc_mbe);
1681         ug_data->cc_mbe = cc_mbe;
1682
1683         Evas_Object *entry = elm_multibuttonentry_entry_get(cc_mbe);
1684         if (entry)
1685                 elm_entry_editable_set(entry, EINA_FALSE);
1686
1687         if (n_cc_list > EMAIL_VIEW_MAX_CC_COUNT)
1688                 n_cc_list = EMAIL_VIEW_MAX_CC_COUNT;
1689
1690         for (i = 0; i < n_cc_list; i++) {
1691                 addrs_info = (email_address_info_t *) g_list_nth_data(ug_data->cc_list, i);
1692
1693                 if (addrs_info->display_name && strlen(addrs_info->display_name) > 0)
1694                         mbe_item = elm_multibuttonentry_item_append(cc_mbe, addrs_info->display_name, NULL, NULL);
1695                 else
1696                         mbe_item = elm_multibuttonentry_item_append(cc_mbe, addrs_info->address, NULL, NULL);
1697                 elm_object_item_data_set(mbe_item, addrs_info);
1698         }
1699
1700         return di;
1701 }
1702
1703 static Evas_Object *_create_bcc_addrs(EmailViewerUGD *ug_data)
1704 {
1705         debug_log("");
1706         email_address_info_t *addrs_info = NULL;
1707         Elm_Object_Item *mbe_item;
1708
1709         if (ug_data->bcc_list == NULL) {
1710                 debug_log("bcc_list is NULL");
1711                 return NULL;
1712         }
1713
1714         int n_bcc_list = g_list_length(ug_data->bcc_list);
1715         int i = 0;
1716
1717         if (n_bcc_list <= 0) {
1718                 debug_log("bcc_list count is 0");
1719                 return NULL;
1720         }
1721
1722         Evas_Object *di = elm_layout_add(ug_data->main_bx);
1723         elm_layout_file_set(di, EV_THEME_PATH, "layout.email.to_cc");
1724         evas_object_size_hint_align_set(di, EVAS_HINT_FILL, 0.0);
1725         evas_object_show(di);
1726         ug_data->bcc_ly = di;
1727
1728         if (ug_data->cc_ly) {
1729                 elm_box_pack_after(ug_data->main_bx, di, ug_data->cc_ly);
1730         }
1731         if (ug_data->to_ly && ug_data->cc_ly == NULL) {
1732                 elm_box_pack_after(ug_data->main_bx, di, ug_data->to_ly);
1733         }
1734         if (ug_data->to_ly == NULL && ug_data->cc_ly == NULL) {
1735                 elm_box_pack_after(ug_data->main_bx, di, ug_data->ly_subject);
1736         }
1737
1738         Evas_Object *bcc_mbe = elm_multibuttonentry_add(ug_data->main_bx);
1739         char desc[MAX_STR_LEN] = { 0, };
1740         snprintf(desc, MAX_STR_LEN, "%s:", _("IDS_EMAIL_BODY_BCC"));
1741         char *bcc_str = g_strconcat("<font_size=36><color=#000000FF>", desc, "</color></font_size>", NULL);
1742         elm_object_text_set(bcc_mbe, bcc_str);
1743         g_free(bcc_str);
1744         evas_object_smart_callback_add(bcc_mbe, "item,clicked", _mbe_selected_cb, ug_data);
1745         evas_object_smart_callback_add(bcc_mbe, "item,added", _mbe_added_cb, ug_data);
1746         elm_object_part_content_set(di, "elm.icon", bcc_mbe);
1747         ug_data->bcc_mbe = bcc_mbe;
1748
1749         Evas_Object *entry = elm_multibuttonentry_entry_get(bcc_mbe);
1750         if (entry)
1751                 elm_entry_editable_set(entry, EINA_FALSE);
1752
1753         if (n_bcc_list > EMAIL_VIEW_MAX_BCC_COUNT)
1754                 n_bcc_list = EMAIL_VIEW_MAX_BCC_COUNT;
1755
1756         for (i = 0; i < n_bcc_list; i++) {
1757                 addrs_info = (email_address_info_t *) g_list_nth_data(ug_data->bcc_list, i);
1758
1759                 if (addrs_info->display_name && strlen(addrs_info->display_name) > 0)
1760                         mbe_item = elm_multibuttonentry_item_append(bcc_mbe, addrs_info->display_name, NULL, NULL);
1761                 else
1762                         mbe_item = elm_multibuttonentry_item_append(bcc_mbe, addrs_info->address, NULL, NULL);
1763                 elm_object_item_data_set(mbe_item, addrs_info);
1764         }
1765
1766         return di;
1767 }
1768
1769 static Evas_Object *_create_attach(EmailViewerUGD *ug_data)
1770 {
1771         debug_log("");
1772
1773         EmailViewerProp *prop = ug_data->property;
1774         char buff[MAX_STR_LEN];
1775         int i = 0;
1776         int att_len = prop->real_att_len;
1777         int att_index = 0;
1778
1779         RETURN_VAL_IF_FAIL(prop->attachments != NULL, NULL);
1780         RETURN_VAL_IF_FAIL(att_len > 0, NULL);
1781
1782         GList *attachment_list = prop->attachments;
1783
1784         if (att_len == 1) {
1785                 LIST_ITER_START(i, attachment_list) {
1786                         EmailAttachmentType *info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, attachment_list);
1787
1788                         if (info && !info->inline_content) {
1789                                 if (info->size < 1024) {
1790                                         g_sprintf(buff, "%s (%d %s)", info->name, (gint) info->size, dgettext("sys_string", "IDS_COM_BODY_B"));
1791                                 } else {
1792                                         gdouble tmpsize = (gdouble) (info->size / 1024.);
1793                                         if (tmpsize < 1024) {
1794                                                 g_sprintf(buff, "%s (%.2f %s)", info->name, tmpsize, dgettext("sys_string", "IDS_COM_BODY_KB"));
1795                                         } else {
1796                                                 tmpsize /= 1024.;
1797                                                 if (tmpsize < 1024) {
1798                                                         g_sprintf(buff, "%s (%.2f %s)", info->name, tmpsize, dgettext("sys_string", "IDS_COM_BODY_MB"));
1799                                                 } else {
1800                                                         tmpsize /= 1024.;
1801                                                         g_sprintf(buff, "%s (%.2f %s)", info->name, tmpsize, dgettext("sys_string", "IDS_COM_BODY_GB"));
1802                                                 }
1803                                         }
1804                                 }
1805
1806                                 Evas_Object *di = elm_layout_add(ug_data->navi_bar);
1807                                 elm_layout_file_set(di, EV_THEME_PATH, "layout.email.attachment_item");
1808                                 evas_object_size_hint_align_set(di, EVAS_HINT_FILL, 0.0);
1809                                 evas_object_show(di);
1810                                 elm_box_pack_after(ug_data->main_bx, di, ug_data->ly_subject);
1811
1812                                 Evas_Object *thumbnail = NULL;
1813
1814                                 if (info->download_yn) {
1815                                         thumbnail = viewer_make_thumbnail(info->path, di);
1816                                 } else
1817                                         thumbnail = viewer_make_thumbnail(NULL, di);
1818                                 evas_object_size_hint_aspect_set(thumbnail, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
1819                                 elm_icon_resizable_set(thumbnail, 1, 1);
1820                                 elm_object_part_content_set(di, "elm.icon", thumbnail);
1821                                 evas_object_show(thumbnail);
1822
1823                                 elm_object_part_text_set(di, "elm.text", buff);
1824
1825                                 att_index = i;
1826
1827                                 Evas_Object *edje = elm_layout_edje_get(di);
1828                                 edje_object_signal_callback_add(edje, "elm,action,download", "elm", _attachment_save_cb, (void *)att_index);
1829                                 edje_object_signal_callback_add(edje, "clicked", "*", _attachment_clicked_cb, (void *)att_index);
1830
1831                                 Evas_Object *text_bg = NULL;
1832                                 text_bg = (Evas_Object *)edje_object_part_object_get(_EDJ(di), "elm.event.rect");
1833
1834                                 if (text_bg) {
1835                                         evas_object_event_callback_add(text_bg, EVAS_CALLBACK_MOUSE_DOWN, _attachment_bg_set_cb, (void *)att_index);
1836                                         evas_object_event_callback_add(text_bg, EVAS_CALLBACK_MOUSE_UP, _attachment_bg_unset_cb, (void *)att_index);
1837                                 }
1838
1839                                 ug_data->attach_hd_ly = di;
1840                                 ug_data->attach_hd_bk = di;
1841                         }
1842                 }
1843         } else if (att_len > 1) {
1844                 gint64 total_size = prop->total_att_size;
1845
1846                 Evas_Object *di = elm_layout_add(ug_data->navi_bar);
1847                 elm_layout_file_set(di, EV_THEME_PATH, "layout.email.attachment_head");
1848                 evas_object_size_hint_align_set(di, EVAS_HINT_FILL, 0.0);
1849                 snprintf(buff, sizeof(buff), "%d %s", att_len, _("IDS_EMAIL_BODY_ATTACHMENTS"));
1850
1851                 Evas_Object *att_head_label;
1852                 att_head_label = elm_label_add(di);
1853                 elm_object_part_content_set(di, "elm.text", att_head_label);
1854
1855                 char *buff_tagged = g_strconcat("<font_size=35><color=#000000FF>", buff, "<color></font_size>", NULL);
1856                 elm_object_text_set(att_head_label, buff_tagged);
1857                 g_free(buff_tagged);
1858
1859                 if (total_size < 1024) {
1860                         g_sprintf(buff, "(%d %s)", (gint) total_size, dgettext("sys_string", "IDS_COM_BODY_B"));
1861                 } else {
1862                         gdouble tmpsize = (gdouble) (total_size / 1024.);
1863
1864                         if (tmpsize < 1024) {
1865                                 g_sprintf(buff, "(%.2f %s)", tmpsize, dgettext("sys_string", "IDS_COM_BODY_KB"));
1866                         } else {
1867                                 tmpsize /= 1024.;
1868
1869                                 if (tmpsize < 1024) {
1870                                         g_sprintf(buff, "(%.2f %s)", tmpsize, dgettext("sys_string", "IDS_COM_BODY_MB"));
1871                                 } else {
1872                                         tmpsize /= 1024.;
1873                                         g_sprintf(buff, "(%.2f %s)", tmpsize, dgettext("sys_string", "IDS_COM_BODY_GB"));
1874                                 }
1875                         }
1876                 }
1877
1878                 edje_object_part_text_set(_EDJ(di), "elm.text.sub", buff);
1879
1880                 Evas_Object *edje = elm_layout_edje_get(di);
1881                 edje_object_signal_callback_add(edje, "att,icon,save,all", "", _attachment_save_all_cb, di);
1882                 edje_object_signal_callback_add(edje, "elm,action,expand,toggle", "elm", _attachment_item_collapse_cb, di);
1883                 evas_object_show(di);
1884                 elm_box_pack_after(ug_data->main_bx, di, ug_data->ly_subject);
1885                 ug_data->attach_hd_ly = di;
1886                 ug_data->attach_hd_bk = di;
1887         } else {
1888                 debug_log("Attachment doesn't exist");
1889         }
1890
1891         return NULL;
1892 }
1893
1894 static Evas_Object *_create_attach_ex(EmailViewerUGD *ug_data)
1895 {
1896         debug_log("");
1897
1898         EmailViewerProp *prop = ug_data->property;
1899         char buff[MAX_STR_LEN];
1900         int i = 0;
1901         int j = 0;
1902         int att_len = prop->real_att_len;
1903         int att_index = 0;
1904
1905         RETURN_VAL_IF_FAIL(prop->attachments != NULL, NULL);
1906         RETURN_VAL_IF_FAIL(att_len > 0, NULL);
1907
1908         GList *attachment_list = prop->attachments;
1909
1910         ug_data->attach_ex_ly = (Evas_Object **)calloc(att_len, sizeof(Evas_Object *));
1911         ug_data->attach_ex_bk = (Evas_Object **)calloc(att_len, sizeof(Evas_Object *));
1912
1913         LIST_ITER_START(i, attachment_list) {
1914                 EmailAttachmentType *info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, attachment_list);
1915
1916                 if (info && !info->inline_content) {
1917                         if (info->size < 1024) {
1918                                 g_sprintf(buff, "%s (%d %s)", info->name, (gint) info->size, dgettext("sys_string", "IDS_COM_BODY_B"));
1919                         } else {
1920                                 gdouble tmpsize = (gdouble) (info->size / 1024.);
1921                                 if (tmpsize < 1024) {
1922                                         g_sprintf(buff, "%s (%.2f %s)", info->name, tmpsize, dgettext("sys_string", "IDS_COM_BODY_KB"));
1923                                 } else {
1924                                         tmpsize /= 1024.;
1925                                         if (tmpsize < 1024) {
1926                                                 g_sprintf(buff, "%s (%.2f %s)", info->name, tmpsize, dgettext("sys_string", "IDS_COM_BODY_MB"));
1927                                         } else {
1928                                                 tmpsize /= 1024.;
1929                                                 g_sprintf(buff, "%s (%.2f %s)", info->name, tmpsize, dgettext("sys_string", "IDS_COM_BODY_GB"));
1930                                         }
1931                                 }
1932                         }
1933
1934                         Evas_Object *di = elm_layout_add(ug_data->navi_bar);
1935                         elm_layout_file_set(di, EV_THEME_PATH, "layout.email.attachment_item");
1936                         evas_object_size_hint_align_set(di, EVAS_HINT_FILL, 0.0);
1937                         elm_box_pack_after(ug_data->main_bx, di, ug_data->attach_hd_ly);
1938                         evas_object_show(di);
1939
1940                         Evas_Object *thumbnail = NULL;
1941
1942                         if (info->download_yn) {
1943                                 thumbnail = viewer_make_thumbnail(info->path, di);
1944                         } else
1945                                 thumbnail = viewer_make_thumbnail(NULL, di);
1946                         evas_object_size_hint_aspect_set(thumbnail, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
1947                         elm_icon_resizable_set(thumbnail, 1, 1);
1948                         elm_object_part_content_set(di, "elm.icon", thumbnail);
1949                         evas_object_show(thumbnail);
1950
1951                         elm_object_part_text_set(di, "elm.text", buff);
1952
1953                         att_index = i;
1954
1955                         Evas_Object *edje = elm_layout_edje_get(di);
1956                         edje_object_signal_callback_add(edje, "elm,action,download", "elm", _attachment_save_cb, (void *)att_index);
1957                         edje_object_signal_callback_add(edje, "clicked", "*", _attachment_clicked_cb, (void *)att_index);
1958
1959                         Evas_Object *text_bg = NULL;
1960                         text_bg = (Evas_Object *)edje_object_part_object_get(_EDJ(di), "elm.event.rect");
1961
1962                         if (text_bg) {
1963                                 evas_object_event_callback_add(text_bg, EVAS_CALLBACK_MOUSE_DOWN, _attachment_bg_set_cb, (void *)att_index);
1964                                 evas_object_event_callback_add(text_bg, EVAS_CALLBACK_MOUSE_UP, _attachment_bg_unset_cb, (void *)att_index);
1965                         }
1966
1967                         debug_log("attach ly %d, att_index %d", j, i);
1968
1969                         ug_data->attach_ex_ly[j] = di;
1970                         ug_data->attach_ex_bk[j] = di;
1971
1972                         j++;
1973                 }
1974         }
1975
1976         return NULL;
1977 }
1978
1979 static Evas_Object *_create_body(EmailViewerUGD *ug_data)
1980 {
1981         debug_log("");
1982         EmailViewerProp *prop = ug_data->property;
1983         EmailViewerPrivate *priv = ug_data->email_data;
1984
1985         ug_data->b_noc = 0;
1986
1987         if (ug_data->noc_bx) {
1988                 elm_box_unpack(ug_data->main_bx, ug_data->noc_bx);
1989                 evas_object_hide(ug_data->noc_bx);
1990         }
1991
1992         if (ug_data->dn_btn) {
1993                 evas_object_hide(ug_data->dn_btn);
1994         }
1995
1996         if (ug_data->webview_bx) {
1997                 _init_webview_data(ug_data);
1998
1999                 if (prop->has_html) {
2000                 /* html mail */
2001                         ug_data->webview_data->body_type_prev = BODY_TYPE_HTML;
2002                         ug_data->webview_data->body_type = BODY_TYPE_HTML;
2003                         ug_data->webview_data->uri = prop->body_uri;
2004                 } else {
2005                 /* text mail */
2006                         ug_data->webview_data->body_type_prev = BODY_TYPE_TEXT;
2007                         ug_data->webview_data->body_type = BODY_TYPE_TEXT;
2008                         ug_data->webview_data->text_content = prop->body;
2009                 }
2010
2011                 viewer_set_webview_content(ug_data, 0);
2012
2013                 evas_object_show(ug_data->webview_bx);
2014                 evas_object_show(ug_data->webview);
2015                 elm_box_pack_end(ug_data->main_bx, ug_data->webview_bx);
2016
2017                 _update_tab_bar(ug_data);
2018         } else {
2019                 /* create webview layout */
2020                 ug_data->webview_bx = _load_edj(ug_data->navi_bar, EV_THEME_PATH, "layout.email.web_view");
2021                 if (ug_data->webview_bx == NULL) {
2022                         debug_log("Cannot load edj");
2023                         return NULL;
2024                 }
2025
2026                 evas_object_size_hint_align_set(ug_data->webview_bx, EVAS_HINT_FILL, 0.0);
2027                 evas_object_show(ug_data->webview_bx);
2028                 elm_box_pack_end(ug_data->main_bx, ug_data->webview_bx);
2029
2030                 /* create webview */
2031                 if (NULL == ug_data->webview) {
2032                         _init_webview_data(ug_data);
2033                         viewer_get_webview(ug_data, prop->has_html);
2034
2035                         if (prop->has_html) {
2036                                 ug_data->webview_data->body_type_prev = BODY_TYPE_HTML;
2037                                 ug_data->webview_data->body_type = BODY_TYPE_HTML;
2038                                 ug_data->webview_data->uri = prop->body_uri;
2039                         } else {
2040                                 ug_data->webview_data->body_type_prev = BODY_TYPE_TEXT;
2041                                 ug_data->webview_data->body_type = BODY_TYPE_TEXT;
2042                                 ug_data->webview_data->text_content = prop->body;
2043                         }
2044                         viewer_set_webview_content(ug_data, 0);
2045                 }
2046
2047                 evas_object_show(ug_data->webview);
2048                 elm_object_part_content_set(ug_data->webview_bx, "web_body", ug_data->webview);
2049
2050                 int resized_w = 0;
2051                 int resized_h = 0;
2052                 if (ug_data->isRotate) {
2053                         resized_w = ug_data->webview_width_landscape * ug_data->scale_factor;
2054                         resized_h = ug_data->webview_height_landscape * ug_data->scale_factor;
2055                 } else {
2056                         resized_w = ug_data->webview_width * ug_data->scale_factor;
2057                         resized_h = ug_data->webview_height * ug_data->scale_factor;
2058                 }
2059
2060                 evas_object_size_hint_min_set(ug_data->webview, resized_w, resized_h);
2061
2062                 /* set touch callbacks */
2063                 evas_object_smart_callback_add(ug_data->webview, "policy,navigation,decide", _webview_policy_navigation_decide_cb, ug_data);
2064                 evas_object_event_callback_add(ug_data->webview, EVAS_CALLBACK_MULTI_DOWN, _webview_multi_down_cb, ug_data);
2065                 evas_object_event_callback_add(ug_data->webview, EVAS_CALLBACK_MULTI_UP, _webview_multi_up_cb, ug_data);
2066
2067                 /* update control Bar */
2068                 _update_tab_bar(ug_data);
2069         }
2070
2071         viewer_set_mail_seen(prop, priv->mail_info);
2072
2073         if (ug_data->timer) {
2074                 ecore_timer_del(ug_data->timer);
2075                 ug_data->timer = NULL;
2076         }
2077
2078         debug_log("send message - list unlock");
2079         ug_data->timer = ecore_timer_add(0.0, viewer_send_message, ug_data);
2080
2081         return ug_data->webview_bx;
2082 }
2083
2084 static Evas_Object *_create_tab_bar(EmailViewerUGD *ug_data)
2085 {
2086         debug_log("");
2087
2088         EmailViewerProp *prop = ug_data->property;
2089         Evas_Object *obj;
2090         obj = elm_toolbar_add(ug_data->navi_bar);
2091         elm_toolbar_shrink_mode_set(obj, ELM_TOOLBAR_SHRINK_EXPAND);
2092         elm_object_style_set(obj, "naviframe");
2093
2094         if (ug_data->mailbox_type == EMAIL_MAILBOX_TYPE_INBOX || ug_data->mailbox_type == EMAIL_MAILBOX_TYPE_SENTBOX ||
2095                 ug_data->mailbox_type == EMAIL_MAILBOX_TYPE_TRASH || ug_data->mailbox_type == EMAIL_MAILBOX_TYPE_SPAMBOX) {
2096                 int n_to_list = g_list_length(ug_data->to_list);
2097                 int n_cc_list = g_list_length(ug_data->cc_list);
2098                 debug_log("to:%d, cc:%d", n_to_list, n_cc_list);
2099                 if (n_to_list + n_cc_list >= 2)
2100                         ug_data->reply_ctr_it = elm_toolbar_item_append(obj, ICON_REPLY, dgettext("sys_string", "IDS_COM_SK_REPLY"), _reply_option_cb, ug_data);
2101                 else
2102                         ug_data->reply_ctr_it = elm_toolbar_item_append(obj, ICON_REPLY, dgettext("sys_string", "IDS_COM_SK_REPLY"), _reply_cb, ug_data);
2103                 ug_data->forward_ctr_it = elm_toolbar_item_append(obj, ICON_FORWARD, dgettext("sys_string", "IDS_COM_BODY_FORWARD"), _forward_cb, ug_data);
2104                 ug_data->del_ctr_it = elm_toolbar_item_append(obj, ICON_DELETE, dgettext("sys_string", "IDS_COM_SK_DELETE"), _delete_cb, ug_data);
2105                 ug_data->more_ctr_it = elm_toolbar_item_append(obj, ICON_CONTROLBAR_MORE, dgettext("sys_string", "IDS_COM_SK_MORE"), _more_cb, ug_data);
2106
2107                 elm_object_item_disabled_set(ug_data->reply_ctr_it, EINA_TRUE);
2108                 elm_object_item_disabled_set(ug_data->forward_ctr_it, EINA_TRUE);
2109         } else if (ug_data->mailbox_type == EMAIL_MAILBOX_TYPE_OUTBOX) {
2110                 debug_log("save_status: %d", prop->status2);
2111                 if (prop->status2 == EMAIL_MAIL_STATUS_SEND_FAILURE) {
2112                         ug_data->resend_ctr_it = elm_toolbar_item_append(obj, ICON_RESEND, _("IDS_EMAIL_SK_RESEND"), _resend_cb, ug_data);
2113                         ug_data->del_ctr_it = elm_toolbar_item_append(obj, ICON_DELETE, dgettext("sys_string", "IDS_COM_SK_DELETE"), _delete_cb, ug_data);
2114                 } else {
2115                         ug_data->del_ctr_it = elm_toolbar_item_append(obj, ICON_DELETE, dgettext("sys_string", "IDS_COM_SK_DELETE"), _delete_cb, ug_data);
2116                 }
2117         } else {
2118                 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->move_ctr_it = elm_toolbar_item_append(obj, ICON_MOVE, _("IDS_EMAIL_SK_MOVE"), _move_cb, ug_data);
2120         }
2121
2122         elm_object_item_part_content_set(ug_data->navi_main_it, "controlbar", obj);
2123         ug_data->ctr_bar = obj;
2124
2125         return NULL;
2126 }
2127
2128 static Evas_Object *_update_tab_bar(EmailViewerUGD *ug_data)
2129 {
2130         debug_log("");
2131
2132         if (ug_data->mailbox_type == EMAIL_MAILBOX_TYPE_INBOX || ug_data->mailbox_type == EMAIL_MAILBOX_TYPE_SENTBOX ||
2133                   ug_data->mailbox_type == EMAIL_MAILBOX_TYPE_TRASH || ug_data->mailbox_type == EMAIL_MAILBOX_TYPE_SPAMBOX) {
2134                 elm_object_item_disabled_set(ug_data->reply_ctr_it, EINA_FALSE);
2135                 elm_object_item_disabled_set(ug_data->forward_ctr_it, EINA_FALSE);
2136         }
2137
2138         return NULL;
2139 }
2140
2141 static Evas_Object *_create_partial_body_dn_btn(EmailViewerUGD *ug_data)
2142 {
2143         debug_log("");
2144
2145         ug_data->partial_dn_btn_bx = _load_edj(ug_data->navi_bar, EV_THEME_PATH, "layout.email.partial_download_btn");
2146         if (ug_data->partial_dn_btn_bx == NULL) {
2147                 debug_log("Cannot load edj");
2148                 return NULL;
2149         }
2150
2151         evas_object_size_hint_align_set(ug_data->partial_dn_btn_bx, EVAS_HINT_FILL, 0.0);
2152         evas_object_show(ug_data->partial_dn_btn_bx);
2153         elm_box_pack_before(ug_data->main_bx, ug_data->partial_dn_btn_bx, ug_data->webview_bx);
2154
2155         Evas_Object *dn_btn = elm_button_add(ug_data->navi_bar);
2156         elm_object_text_set(dn_btn, _("IDS_EMAIL_BODY_DOWNLOAD_FULL_MESSAGE"));
2157         evas_object_smart_callback_add(dn_btn, "clicked", _body_down_cb, (void *)ug_data);
2158         /*elm_object_theme_set(dn_btn, ug_data->theme);*/
2159         elm_object_style_set(dn_btn, "text_only/style2");
2160         evas_object_show(dn_btn);
2161         ug_data->partial_dn_btn = dn_btn;
2162
2163         elm_object_part_content_set(ug_data->partial_dn_btn_bx, "button", ug_data->partial_dn_btn);
2164
2165         return ug_data->partial_dn_btn_bx;
2166 }
2167
2168 static Evas_Object *_create_bg(Evas_Object *win)
2169 {
2170         debug_log("");
2171
2172         Evas_Object *bg = elm_bg_add(win);
2173         evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2174         elm_win_resize_object_add(win, bg);
2175         evas_object_show(bg);
2176
2177         return bg;
2178 }
2179
2180 static void _create_down_progress(char *message, popup_cb resp_cb)
2181 {
2182         debug_log("");
2183
2184         if (!_g_ug_data) {
2185                 debug_log("data is NULL");
2186                 return;
2187         }
2188
2189         EmailViewerUGD *ug_data = _g_ug_data;
2190         Evas_Object *notify, *pb;
2191
2192         notify = elm_popup_add(ug_data->win_main);
2193         if (!notify) {
2194                 debug_log("elm_popup_add returns NULL");
2195                 return;
2196         }
2197         evas_object_size_hint_weight_set(notify, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2198         ug_data->pb_notify = notify;
2199
2200         elm_object_part_text_set(notify, "title,text", message);
2201
2202         pb = elm_progressbar_add(notify);
2203
2204         elm_object_style_set(pb, "list_progress");
2205
2206         elm_progressbar_horizontal_set(pb, EINA_TRUE);
2207         evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, EVAS_HINT_FILL);
2208         evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2209         evas_object_show(pb);
2210         elm_progressbar_value_set(pb, 0.0);
2211         elm_object_content_set(notify, pb);
2212         ug_data->pb_notify_lb = pb;
2213
2214         Evas_Object *btn1 = elm_button_add(notify);
2215         elm_object_style_set(btn1, "popup_button/default");
2216         elm_object_text_set(btn1, dgettext("sys_string", "IDS_COM_SK_CANCEL"));
2217         elm_object_part_content_set(notify, "button1", btn1);
2218         evas_object_smart_callback_add(btn1, "clicked", resp_cb, ug_data);
2219         debug_log("Cancel btn1 for downloading body: %p", btn1);
2220
2221         evas_object_show(notify);
2222 }
2223
2224 static void _create_down_progress_ex(int index, EMAIL_VIEWER_PROGRESSBAR_TYPE p_type)
2225 {
2226         debug_log("");
2227
2228         if (!_g_ug_data) {
2229                 debug_log("data is NULL");
2230                 return;
2231         }
2232
2233         EmailViewerUGD *ug_data = _g_ug_data;
2234         EmailViewerProp *prop = ug_data->property;
2235         EmailViewerPrivate *priv = ug_data->email_data;
2236
2237         if (!prop || !prop->attachments) {
2238                 debug_log("");
2239                 return;
2240         }
2241
2242         if (!priv) {
2243                 debug_log("");
2244                 return;
2245         }
2246
2247         if (ug_data->forward_ctr_it)
2248                 elm_object_item_disabled_set(ug_data->forward_ctr_it, EINA_TRUE);
2249
2250         int scr_x = 0;
2251         int scr_y = 0;
2252         int scr_w = 0;
2253         int scr_h = 0;
2254         elm_scroller_region_get(ug_data->scroller, &scr_x, &scr_y, &scr_w, &scr_h);
2255         debug_log("scroller region> x[%d] y[%d] w[%d] h[%d]", scr_x, scr_y, scr_w, scr_h);
2256
2257         GList *attachment_list = prop->attachments;
2258         int i = 0, j = 0;
2259         debug_log("index %d of attachment_count %d", index, prop->att_len);
2260
2261         EmailAttachmentType *info = NULL;
2262         info = g_list_nth_data(attachment_list, index);
2263         if (info == NULL) {
2264                 debug_log("info is NULL");
2265         }
2266
2267         Evas_Object *pbar_ly = elm_layout_add(ug_data->navi_bar);
2268         elm_layout_file_set(pbar_ly, EV_THEME_PATH, "layout.email.attachment_downloading");
2269         evas_object_size_hint_align_set(pbar_ly, EVAS_HINT_FILL, 0.0);
2270         evas_object_show(pbar_ly);
2271         ug_data->progress_bar_ly[index + 1] = pbar_ly;
2272
2273         if (info) {
2274                 char buff[MAX_STR_LEN] = { 0, };
2275
2276                 Evas_Object *downloading_label1;
2277                 downloading_label1 = elm_label_add(pbar_ly);
2278                 elm_object_part_content_set(pbar_ly, "elm.text.1", downloading_label1);
2279                 char *text_tagged = g_strconcat("<font_size=32><align=left><color=#000000FF>", info->name, "</color></align></font_size>", NULL);
2280                 elm_object_text_set(downloading_label1, text_tagged);
2281                 elm_label_ellipsis_set(downloading_label1, EINA_TRUE);
2282                 elm_label_wrap_width_set(downloading_label1, ug_data->main_w - 240);
2283                 g_free(text_tagged);
2284
2285                 if (info->size < 1024) {
2286                         g_sprintf(buff, "%d %s", (gint) info->size, dgettext("sys_string", "IDS_COM_BODY_B"));
2287                 } else {
2288                         gdouble tmpsize = (gdouble) (info->size / 1024.);
2289
2290                         if (tmpsize < 1024) {
2291                                 g_sprintf(buff, "%.2f %s", tmpsize, dgettext("sys_string", "IDS_COM_BODY_KB"));
2292                         } else {
2293                                 tmpsize /= 1024.;
2294
2295                                 if (tmpsize < 1024) {
2296                                         g_sprintf(buff, "%.2f %s", tmpsize, dgettext("sys_string", "IDS_COM_BODY_MB"));
2297                                 } else {
2298                                         tmpsize /= 1024.;
2299                                         g_sprintf(buff, "%.2f %s", tmpsize, dgettext("sys_string", "IDS_COM_BODY_GB"));
2300                                 }
2301                         }
2302                 }
2303
2304                 Evas_Object *downloading_label3;
2305                 downloading_label3 = elm_label_add(pbar_ly);
2306                 elm_object_part_content_set(pbar_ly, "elm.text.3", downloading_label3);
2307                 text_tagged = g_strconcat("<font_size=26><align=right><color=#646464FF>", buff, "</color></align></font_size>", NULL);
2308                 elm_object_text_set(downloading_label3, text_tagged);
2309                 g_free(text_tagged);
2310         }
2311
2312         Evas_Object *progressbar = elm_progressbar_add(pbar_ly);
2313         elm_progressbar_horizontal_set(progressbar, EINA_TRUE);
2314         elm_object_style_set(progressbar, "list_progress");
2315         elm_object_part_content_set(pbar_ly, "elm.icon.2", progressbar);
2316         ug_data->progress_bar[index + 1] = progressbar;
2317         evas_object_show(progressbar);
2318
2319         Evas_Object *cancel_btn = elm_button_add(pbar_ly);
2320         /*elm_object_theme_set(cancel_btn, ug_data->theme);*/
2321         elm_object_style_set(cancel_btn, "text_only/style2");
2322         elm_object_text_set(cancel_btn, dgettext("sys_string", "IDS_COM_SK_CANCEL"));
2323
2324         elm_object_part_content_set(pbar_ly, "elm.icon.1", cancel_btn);
2325         evas_object_show(cancel_btn);
2326         evas_object_smart_callback_add(cancel_btn, "clicked", _destroy_down_progress_ex, (void *)index);
2327         debug_log("Cancel button for attachment downloading progress popup: %p", cancel_btn);
2328
2329         /* packing progress layout */
2330         if (p_type == EMAIL_VIEWER_PROGRESSBAR_ATT && prop->real_att_len > 1) {
2331                 for (i = 0; i < prop->att_len; i++) {
2332                         info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, attachment_list);
2333                         if (info && !info->inline_content) {
2334                                 if (index == i) {
2335                                         if (ug_data->attach_ex_ly != NULL && ug_data->attach_ex_ly[j] != NULL) {
2336                                                 debug_log("");
2337                                                 elm_box_pack_after(ug_data->main_bx, pbar_ly, ug_data->attach_ex_ly[j]);
2338                                                 elm_box_unpack(ug_data->main_bx, ug_data->attach_ex_ly[j]);
2339                                                 evas_object_hide(ug_data->attach_ex_ly[j]);
2340                                                 ug_data->attach_ex_ly[j] = pbar_ly;
2341                                         }
2342                                 }
2343                                 j++;
2344                         }
2345                 }
2346         }
2347         if ((p_type == EMAIL_VIEWER_PROGRESSBAR_ATT && prop->real_att_len == 1) || (p_type == EMAIL_VIEWER_PROGRESSBAR_ATT_ALL)) {
2348                 debug_log("");
2349                 elm_box_pack_after(ug_data->main_bx, pbar_ly, ug_data->attach_hd_ly);
2350                 elm_box_unpack(ug_data->main_bx, ug_data->attach_hd_ly);
2351                 evas_object_hide(ug_data->attach_hd_ly);
2352                 ug_data->attach_hd_ly = pbar_ly;
2353         }
2354
2355         elm_object_focus_set(pbar_ly, EINA_TRUE);
2356         elm_scroller_region_show(ug_data->scroller, scr_x, scr_y, scr_w, scr_h);
2357 }
2358
2359 static void _destroy_down_progress_ex(void *data, Evas_Object *obj, void *event_info)
2360 {
2361         debug_log("");
2362
2363         if (!_g_ug_data) {
2364                 debug_log("data is NULL");
2365                 return;
2366         }
2367
2368         EmailViewerUGD *ug_data = _g_ug_data;
2369         EmailViewerPrivate *priv = ug_data->email_data;
2370         EmailViewerProp *prop = ug_data->property;
2371
2372         if (!prop || !prop->attachments) {
2373                 debug_log("");
2374                 return;
2375         }
2376
2377         if (!priv) {
2378                 debug_log("");
2379                 return;
2380         }
2381
2382         int scr_x = 0;
2383         int scr_y = 0;
2384         int scr_w = 0;
2385         int scr_h = 0;
2386         elm_scroller_region_get(ug_data->scroller, &scr_x, &scr_y, &scr_w, &scr_h);
2387         debug_log("scroller region> x[%d] y[%d] w[%d] h[%d]", scr_x, scr_y, scr_w, scr_h);
2388
2389         GList *attachment_list = prop->attachments;
2390         int index = (int)data;
2391         int i = 0, j = 0;
2392
2393         /* Cancel the download in email-service */
2394         if (index >= 0) {
2395                 debug_log("index[%d] download_all_cnt[%d] email_handle[%d]", index, priv->download_all_cnt, priv->download_all_email_handle[index]);
2396                 if (priv->download_all_email_handle[index] > 0) {
2397                         email_engine_stop_working(ug_data->account_id, priv->download_all_email_handle[index]);
2398                         priv->download_all_email_handle[index] = 0;
2399                 }
2400
2401                 (priv->download_all_cnt)--;
2402
2403                 if (priv->download_all_cnt == 0)
2404                         priv->b_all_att_save = FALSE;
2405         } else if (index == -1) {
2406                 for (i = 0; i < prop->att_len; i++) {
2407                         EmailAttachmentType *info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, attachment_list);
2408                         if (info && !info->inline_content) {
2409                                 debug_log("index[%d] download_all_cnt[%d] email_handle[%d]", i, priv->download_all_cnt, priv->download_all_email_handle[i]);
2410                                 if (priv->download_all_email_handle[i] > 0) {
2411                                         email_engine_stop_working(ug_data->account_id, priv->download_all_email_handle[i]);
2412                                 }
2413                         }
2414                         priv->download_all_email_handle[i] = 0;
2415                 }
2416                 priv->download_all_cnt = 0;
2417                 priv->b_all_att_save = FALSE;
2418         }
2419
2420         /* upack and delete, pack again */
2421         if (index >= 0) {
2422                 debug_log("real_att_len:%d", prop->real_att_len);
2423                 if (prop->real_att_len == 1) {
2424                         debug_log("index[%d]", index);
2425                         elm_box_pack_after(ug_data->main_bx, ug_data->attach_hd_bk, ug_data->attach_hd_ly);
2426                         elm_box_unpack(ug_data->main_bx, ug_data->attach_hd_ly);
2427                         evas_object_del(ug_data->attach_hd_ly);
2428                         ug_data->attach_hd_ly = ug_data->attach_hd_bk;
2429                         evas_object_show(ug_data->attach_hd_ly);
2430                         elm_object_focus_set(ug_data->attach_hd_ly, EINA_TRUE);
2431                         ug_data->progress_bar[index + 1] = NULL;
2432                         ug_data->progress_bar_ly[index + 1] = NULL;
2433                 } else if (prop->real_att_len > 1) {
2434                         for (i = 0; i < prop->att_len; i++) {
2435                                 EmailAttachmentType *info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, attachment_list);
2436                                 if (info && !info->inline_content) {
2437                                         if (index == i) {
2438                                                 debug_log("index[%d]", i);
2439                                                 debug_log("attach_onoff_flag:%d", ug_data->attach_onoff_flag);
2440                                                 if (ug_data->attach_onoff_flag > 0) {
2441                                                         elm_box_pack_after(ug_data->main_bx, ug_data->attach_ex_bk[j], ug_data->attach_ex_ly[j]);
2442                                                         elm_box_unpack(ug_data->main_bx, ug_data->attach_ex_ly[j]);
2443                                                         evas_object_del(ug_data->attach_ex_ly[j]);
2444                                                         ug_data->attach_ex_ly[j] = ug_data->attach_ex_bk[j];
2445                                                         evas_object_show(ug_data->attach_ex_ly[j]);
2446                                                         elm_object_focus_set(ug_data->attach_ex_ly[j], EINA_TRUE);
2447                                                         ug_data->progress_bar[index + 1] = NULL;
2448                                                         ug_data->progress_bar_ly[index + 1] = NULL;
2449                                                 } else {
2450                                                         evas_object_del(ug_data->attach_ex_ly[j]);
2451                                                         ug_data->attach_ex_ly[j] = ug_data->attach_ex_bk[j];
2452                                                         ug_data->progress_bar[index + 1] = NULL;
2453                                                         ug_data->progress_bar_ly[index + 1] = NULL;
2454                                                 }
2455                                         }
2456                                         j++;
2457                                 }
2458                         }
2459                 }
2460         } else if (index == -1) {
2461                 debug_log("index[%d]", index);
2462                 elm_box_pack_after(ug_data->main_bx, ug_data->attach_hd_bk, ug_data->attach_hd_ly);
2463                 elm_box_unpack(ug_data->main_bx, ug_data->attach_hd_ly);
2464                 evas_object_del(ug_data->attach_hd_ly);
2465                 ug_data->attach_hd_ly = ug_data->attach_hd_bk;
2466                 evas_object_show(ug_data->attach_hd_ly);
2467                 elm_object_focus_set(ug_data->attach_hd_ly, EINA_TRUE);
2468                 ug_data->progress_bar[index + 1] = NULL;
2469                 ug_data->progress_bar_ly[index + 1] = NULL;
2470         }
2471
2472         elm_scroller_region_show(ug_data->scroller, scr_x, scr_y, scr_w, scr_h);
2473
2474         if (priv && priv->download_all_cnt <= 0) {
2475                 if (ug_data->forward_ctr_it)
2476                         elm_object_item_disabled_set(ug_data->forward_ctr_it, EINA_FALSE);
2477         }
2478 }
2479
2480 static void _create_more_ctxpopup(EmailViewerUGD *ug_data)
2481 {
2482         debug_log("");
2483         if (!ug_data) {
2484                 debug_log("ug_data is NULL");
2485                 return;
2486         }
2487
2488         EmailViewerProp *prop = ug_data->property;
2489         EMAIL_CONTACT_LIST_INFO_S *contact_list_item = NULL;
2490         contact_list_item = (EMAIL_CONTACT_LIST_INFO_S *)_contact_search_by_email(ug_data, prop->sender);
2491
2492         if (ug_data->con_popup) {
2493                 evas_object_del(ug_data->con_popup);
2494                 ug_data->con_popup = NULL;
2495         }
2496
2497         ug_data->con_popup = elm_ctxpopup_add(ug_data->navi_bar);
2498         if (ug_data->con_popup == NULL) {
2499                 debug_log("cannot create context popup");
2500                 return;
2501         }
2502
2503         if (contact_list_item) {
2504                 debug_log("Contact Item Exist: index[%d]", contact_list_item->index);
2505                 char index[10] = { 0, };
2506                 snprintf(index, sizeof(index), "%d", contact_list_item->index);
2507
2508                 if (email_engine_check_seen_mail(ug_data->account_id, ug_data->mail_id))
2509                         elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_MARK_AS_UNREAD"), NULL, _mark_as_unread_cb, ug_data);
2510                 else
2511                         elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_MARK_AS_READ"), NULL, _mark_as_read_cb, ug_data);
2512
2513                 elm_ctxpopup_item_append(ug_data->con_popup, dgettext("sys_string", "IDS_COM_BODY_MOVE"), NULL, _move_cb, ug_data);
2514                 elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_VIEW_CONTACT"), NULL, _ctxpopup_detail_contact_cb, g_strdup(index));
2515                 elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_ADD_TO_CALENDAR"), NULL, _add_to_calendar_cb, ug_data);
2516                 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);
2517
2518                 _delete_contacts_list(contact_list_item);
2519         } else {
2520                 if (email_engine_check_seen_mail(ug_data->account_id, ug_data->mail_id))
2521                         elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_MARK_AS_UNREAD"), NULL, _mark_as_unread_cb, ug_data);
2522                 else
2523                         elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_MARK_AS_READ"), NULL, _mark_as_read_cb, ug_data);
2524
2525                 elm_ctxpopup_item_append(ug_data->con_popup, dgettext("sys_string", "IDS_COM_BODY_MOVE"), NULL, _move_cb, ug_data);
2526                 elm_ctxpopup_item_append(ug_data->con_popup, dgettext("sys_string", "IDS_COM_OPT_ADD_TO_CONTACTS"), NULL, _ctxpopup_select_contact_mode_email_cb, prop->sender);
2527                 elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_ADD_TO_CALENDAR"), NULL, _add_to_calendar_cb, ug_data);
2528                 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);
2529         }
2530
2531         int count, i;
2532         email_rule_t *rule_list = NULL;
2533
2534         /* get the rule list from service */
2535         if (email_get_rule_list(&rule_list, &count) < 0) {
2536                 debug_log("email_get_rule_list failed");
2537         } else {
2538                 if (count > 0) {
2539                         for (i = 0; i < count; i++) {
2540                                 if (rule_list[i].type == EMAIL_FILTER_FROM) {
2541                                         debug_log("block address %s", rule_list[i].value);
2542
2543                                         if (g_strcmp0(rule_list[i].value, prop->sender) == 0) {
2544                                                 debug_log("[%s] already blocked", rule_list[i].value);
2545                                                 if (ug_data->more_ctx_block_item)
2546                                                         elm_object_item_disabled_set(ug_data->more_ctx_block_item, EINA_TRUE);
2547                                         }
2548                                 }
2549                         }
2550                 }
2551                 /* free email rule_list */
2552                 email_free_rule(&rule_list, count);
2553         }
2554
2555         Evas_Coord x, y;
2556         evas_pointer_canvas_xy_get(ug_data->evas, &x, &y);
2557         evas_object_move(ug_data->con_popup, x, y - 20);
2558         evas_object_show(ug_data->con_popup);
2559 }
2560
2561 static void _create_reply_ctxpopup(EmailViewerUGD *ug_data)
2562 {
2563         debug_log("");
2564         if (!ug_data) {
2565                 debug_log("ug_data is NULL");
2566                 return;
2567         }
2568
2569         if (ug_data->con_popup) {
2570                 evas_object_del(ug_data->con_popup);
2571                 ug_data->con_popup = NULL;
2572         }
2573
2574         ug_data->con_popup = elm_ctxpopup_add(ug_data->navi_bar);
2575         if (ug_data->con_popup == NULL) {
2576                 debug_log("cannot create context popup");
2577                 return;
2578         }
2579
2580         elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_TO_SENDER_ABB"), NULL, _reply_cb, ug_data);
2581         elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_TO_ALL_ABB"), NULL, _reply_all_cb, ug_data);
2582
2583         Evas_Coord x, y;
2584         evas_pointer_canvas_xy_get(ug_data->evas, &x, &y);
2585         evas_object_move(ug_data->con_popup, x, y - 20);
2586         evas_object_show(ug_data->con_popup);
2587 }
2588
2589 static void _delete_evas_objects(EmailViewerUGD *ug_data)
2590 {
2591         debug_log("");
2592         EmailViewerProp *prop = ug_data->property;
2593
2594         if (ug_data->webview) {
2595                 evas_object_del(ug_data->webview);
2596                 ug_data->webview = NULL;
2597         }
2598
2599         if (ug_data->webview_bx) {
2600                 evas_object_del(ug_data->webview_bx);
2601                 ug_data->webview_bx = NULL;
2602         }
2603
2604         if (ug_data->scroller) {
2605                 evas_object_del(ug_data->scroller);
2606                 ug_data->scroller = NULL;
2607         }
2608
2609         if (ug_data->main_bx) {
2610                 evas_object_del(ug_data->main_bx);
2611                 ug_data->main_bx = NULL;
2612         }
2613
2614         if (ug_data->b_btn) {
2615                 evas_object_del(ug_data->b_btn);
2616                 ug_data->b_btn = NULL;
2617         }
2618
2619         if (ug_data->sub_ly) {
2620                 evas_object_del(ug_data->sub_ly);
2621                 ug_data->sub_ly = NULL;
2622         }
2623
2624         if (ug_data->navi_bar) {
2625                 evas_object_del(ug_data->navi_bar);
2626                 ug_data->navi_bar = NULL;
2627         }
2628
2629         if (ug_data->ctr_bar) {
2630                 evas_object_del(ug_data->ctr_bar);
2631                 ug_data->ctr_bar = NULL;
2632         }
2633
2634         if (ug_data->layout_main) {
2635                 evas_object_del(ug_data->layout_main);
2636                 ug_data->layout_main = NULL;
2637         }
2638
2639         if (ug_data->con_popup) {
2640                 evas_object_del(ug_data->con_popup);
2641                 ug_data->con_popup = NULL;
2642         }
2643
2644         if (ug_data->select_info) {
2645                 evas_object_del(ug_data->select_info);
2646                 ug_data->select_info = NULL;
2647         }
2648
2649         if (ug_data->selectioninfo_layout != NULL) {
2650                 evas_object_del(ug_data->selectioninfo_layout);
2651                 ug_data->selectioninfo_layout = NULL;
2652         }
2653
2654         if (ug_data->notify) {
2655                 evas_object_del(ug_data->notify);
2656                 ug_data->notify = NULL;
2657         }
2658
2659         if (ug_data->pb_notify) {
2660                 evas_object_del(ug_data->pb_notify);
2661                 ug_data->pb_notify = NULL;
2662         }
2663
2664         if (ug_data->pb_notify_lb) {
2665                 evas_object_del(ug_data->pb_notify_lb);
2666                 ug_data->pb_notify_lb = NULL;
2667         }
2668
2669         if (ug_data->partial_dn_btn) {
2670                 evas_object_del(ug_data->partial_dn_btn);
2671                 ug_data->partial_dn_btn = NULL;
2672         }
2673
2674         if (ug_data->partial_dn_btn_bx) {
2675                 evas_object_del(ug_data->partial_dn_btn_bx);
2676                 ug_data->partial_dn_btn_bx = NULL;
2677         }
2678
2679         if (ug_data->cutlink_timer) {
2680                 ecore_timer_del(ug_data->cutlink_timer);
2681                 ug_data->cutlink_timer = NULL;
2682         }
2683
2684         if (ug_data->timer) {
2685                 ecore_timer_del(ug_data->timer);
2686                 ug_data->timer = NULL;
2687         }
2688
2689         if (ug_data->idler) {
2690                 ecore_idler_del(ug_data->idler);
2691                 ug_data->idler = NULL;
2692         }
2693
2694         if (ug_data->got_att) {
2695                 int i;
2696
2697                 evas_object_del(ug_data->attach_hd_bk);
2698                 ug_data->attach_hd_ly = NULL;
2699                 ug_data->attach_hd_bk = NULL;
2700
2701                 if (prop->real_att_len > 1) {
2702                         for (i = 0; i < prop->real_att_len; i++) {
2703                                 if (ug_data->attach_ex_ly != NULL) {
2704                                         if (ug_data->attach_ex_ly[i] != NULL) {
2705                                                 debug_log("index %d", i);
2706                                                 evas_object_del(ug_data->attach_ex_bk[i]);
2707                                                 ug_data->attach_ex_ly[i] = NULL;
2708                                                 ug_data->attach_ex_bk[i] = NULL;
2709                                         }
2710                                 }
2711                         }
2712
2713                         if (ug_data->attach_ex_ly != NULL) {
2714                                 free(ug_data->attach_ex_ly);
2715                                 ug_data->attach_ex_ly = NULL;
2716                                 ug_data->attach_ex_bk = NULL;
2717                         }
2718                 }
2719
2720                 for (i = 0; i <= prop->att_len; i++) {
2721                         if (ug_data->progress_bar_ly[i] != NULL) {
2722                                 evas_object_del(ug_data->progress_bar_ly[i]);
2723                                 ug_data->progress_bar_ly[i] = NULL;
2724                                 ug_data->progress_bar[i] = NULL;
2725                         }
2726                 }
2727         }
2728 }
2729
2730 void _launch_composer(EmailViewerUGD *ug_data, int type)
2731 {
2732         debug_log("");
2733
2734         if (!ug_data) {
2735                 debug_log("ug_data is NULL");
2736                 return;
2737         }
2738
2739         EmailViewerPrivate *priv = ug_data->email_data;
2740         char tmp[256];
2741
2742         int ret;
2743         service_h service = NULL;
2744
2745         ret = service_create(&service);
2746         debug_log("service_create: %d", ret);
2747         if (!service) {
2748                 debug_log("service create failed");
2749                 return;
2750         }
2751
2752         char rtype[10] = { 0, };
2753         snprintf(rtype, sizeof(rtype), "%d", type);
2754         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_RUN_TYPE, rtype);
2755         debug_log("service_add_extra_data: %d", ret);
2756
2757         memset(tmp, 0x0, sizeof(tmp));
2758         snprintf(tmp, sizeof(tmp), "%d", priv->account_id);
2759         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_ACCOUNT_ID, tmp);
2760         debug_log("service_add_extra_data: %d", ret);
2761
2762         memset(tmp, 0x0, sizeof(tmp));
2763         snprintf(tmp, sizeof(tmp), "%d", priv->mailbox_id);
2764         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_MAILBOX, tmp);
2765         debug_log("service_add_extra_data: %d", ret);
2766
2767         memset(tmp, 0x0, sizeof(tmp));
2768         snprintf(tmp, sizeof(tmp), "%d", priv->mail_id);
2769         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_MAIL_ID, tmp);
2770         debug_log("service_add_extra_data: %d", ret);
2771
2772         ug_data->ug_composer = create_ug(UG_NAME_EMAIL_COMPOSER, service, ug_data);
2773
2774         ret = service_destroy(service);
2775         debug_log("service_destroy: %d", ret);
2776 }
2777
2778 static void _launch_vcs_editor(EmailViewerUGD *ug_data)
2779 {
2780         debug_log("");
2781
2782         if (!ug_data) {
2783                 debug_log("ug_data is NULL");
2784                 return;
2785         }
2786
2787         char account_id[MAX_STR_LEN] = { 0, };
2788         char mail_id[MAX_STR_LEN] = { 0, };
2789
2790         EmailViewerProp *prop = ug_data->property;
2791
2792         int ret;
2793         service_h service = NULL;
2794
2795         ret = service_create(&service);
2796         debug_log("service_create: %d", ret);
2797         if (!service) {
2798                 debug_log("service create failed");
2799                 return;
2800         }
2801
2802         snprintf(account_id, sizeof(account_id), "%d", prop->account_id);
2803         snprintf(mail_id, sizeof(mail_id), "%d", prop->mail_id);
2804
2805         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_CALENDAR_EDIT_ACCOUNT_ID, account_id);
2806         debug_log("service_add_extra_data: %d", ret);
2807         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_CALENDAR_EDIT_MAIL_ID, mail_id);
2808         debug_log("service_add_extra_data: %d", ret);
2809         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_CALENDAR_EDIT_SRC_BOX, prop->src_box);
2810         debug_log("service_add_extra_data: %d", ret);
2811         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_CALENDAR_EDIT_INDEX, EMAIL_BUNDLE_VAL_CALENDAR_EDIT_INDEX);
2812         debug_log("service_add_extra_data: %d", ret);
2813         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_CALENDAR_EDIT_NOTE, prop->subject);
2814         debug_log("service_add_extra_data: %d", ret);
2815
2816         ug_data->ug_calendar_edit = create_ug(UG_NAME_CALENDAR_EDIT, service, ug_data);
2817
2818         ret = service_destroy(service);
2819         debug_log("service_destroy: %d", ret);
2820 }
2821
2822 static void _back_cb(void *data, Evas_Object *obj, void *event_info)
2823 {
2824         debug_log("");
2825
2826         if (_g_ug_data == NULL) {
2827                 debug_log("_g_ug_data is NULL");
2828                 return;
2829         }
2830
2831         if (!data) {
2832                 debug_log("data is NULL");
2833                 return;
2834         }
2835         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
2836
2837         if (ug_data->con_popup != NULL) {
2838                 evas_object_del(ug_data->con_popup);
2839                 ug_data->con_popup = NULL;
2840         }
2841
2842         debug_log("isRoate = %d", ug_data->isRotate);
2843         if (ug_data->isRotate == false && ug_data->b_internal) {
2844                 /* Viewer to hide, so set left content (mailbox) size to full */
2845                 _notify_mailbox_size(ug_data, "MAILBOX_RESIZE_FULL");
2846         }
2847
2848         if (ug_data->b_internal != 1) {
2849                 debug_log("ug_destory_me");
2850                 ug_destroy_me(ug_data->ug);
2851         } else {
2852                 _hide_view(ug_data);
2853         }
2854 }
2855
2856 static void _prev_mail_cb(void *data, Evas_Object *obj, void *event_info)
2857 {
2858         debug_log("");
2859         if (!data) {
2860                 debug_log("data is NULL");
2861                 return;
2862         }
2863
2864         /* send next or previous mail request to mailbox. */
2865         int ret;
2866         service_h service = NULL;
2867
2868         ret = service_create(&service);
2869         debug_log("service_create: %d", ret);
2870         if (!service) {
2871                 debug_log("service create failed");
2872                 return;
2873         }
2874
2875         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_MSG, EMAIL_BUNDLE_VAL_PREV_MSG);
2876         debug_log("service_add_extra_data: %d", ret);
2877         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_DO_DELETE, "0");
2878         debug_log("service_add_extra_data: %d", ret);
2879
2880         ug_send_message(_g_mailbox_ug, service);
2881
2882         ret = service_destroy(service);
2883         debug_log("service_destroy: %d", ret);
2884 }
2885
2886 static void _next_mail_cb(void *data, Evas_Object *obj, void *event_info)
2887 {
2888         debug_log("");
2889         if (!data) {
2890                 debug_log("data is NULL");
2891                 return;
2892         }
2893
2894         /* send next or previous mail request to mailbox. */
2895         int ret;
2896         service_h service = NULL;
2897
2898         ret = service_create(&service);
2899         debug_log("service_create: %d", ret);
2900         if (!service) {
2901                 debug_log("service create failed");
2902                 return;
2903         }
2904
2905         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_MSG, EMAIL_BUNDLE_VAL_NEXT_MSG);
2906         debug_log("service_add_extra_data: %d", ret);
2907         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_DO_DELETE, "0");
2908         debug_log("service_add_extra_data: %d", ret);
2909
2910         ug_send_message(_g_mailbox_ug, service);
2911
2912         ret = service_destroy(service);
2913         debug_log("service_destroy: %d", ret);
2914 }
2915
2916 static void _reply_cb(void *data, Evas_Object *obj, void *event_info)
2917 {
2918         debug_log("");
2919         if (!data) {
2920                 debug_log("data is NULL");
2921                 return;
2922         }
2923
2924         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
2925
2926         if (ug_data->con_popup) {
2927                 evas_object_del(ug_data->con_popup);
2928                 ug_data->con_popup = NULL;
2929         }
2930
2931         ug_data->display_download_result = FALSE;
2932
2933         _launch_composer(ug_data, RUN_COMPOSER_REPLY);
2934
2935         if (ug_data->notify) {
2936                 evas_object_del(ug_data->notify);
2937                 ug_data->notify = NULL;
2938         }
2939 }
2940
2941 static void _reply_all_cb(void *data, Evas_Object *obj, void *event_info)
2942 {
2943         debug_log("");
2944         if (!data) {
2945                 debug_log("data is NULL");
2946                 return;
2947         }
2948
2949         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
2950
2951         if (ug_data->con_popup) {
2952                 evas_object_del(ug_data->con_popup);
2953                 ug_data->con_popup = NULL;
2954         }
2955
2956         ug_data->display_download_result = FALSE;
2957
2958         _launch_composer(ug_data, RUN_COMPOSER_REPLY_ALL);
2959
2960         if (ug_data->notify) {
2961                 evas_object_del(ug_data->notify);
2962                 ug_data->notify = NULL;
2963         }
2964 }
2965
2966 static void _reply_option_cb(void *data, Evas_Object *obj, void *event_info)
2967 {
2968         debug_log("");
2969         if (!data) {
2970                 debug_log("data is NULL");
2971                 return;
2972         }
2973
2974         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
2975
2976         _create_reply_ctxpopup(ug_data);
2977 }
2978
2979 static void _forward_cb(void *data, Evas_Object *obj, void *event_info)
2980 {
2981         debug_log("");
2982         if (!data) {
2983                 debug_log("data is NULL");
2984                 return;
2985         }
2986
2987         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
2988
2989         ug_data->display_download_result = FALSE;
2990
2991         _launch_composer(ug_data, RUN_COMPOSER_FORWARD);
2992 }
2993
2994 static void _add_to_calendar_cb(void *data, Evas_Object *obj, void *event_info)
2995 {
2996         debug_log("");
2997
2998         if (data == NULL)
2999                 return;
3000
3001         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
3002
3003         if (ug_data->con_popup) {
3004                 evas_object_del(ug_data->con_popup);
3005                 ug_data->con_popup = NULL;
3006         }
3007
3008         _launch_vcs_editor(ug_data);
3009 }
3010
3011 static void _resend_cb(void *data, Evas_Object *obj, void *event_info)
3012 {
3013         debug_log("");
3014 }
3015
3016 static void _delete_cb(void *data, Evas_Object *obj, void *event_info)
3017 {
3018         debug_log("");
3019         if (!data) {
3020                 debug_log("data is NULL");
3021                 return;
3022         }
3023
3024         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
3025
3026         if (ug_data->con_popup) {
3027                 evas_object_del(ug_data->con_popup);
3028                 ug_data->con_popup = NULL;
3029         }
3030
3031         _create_notify(ug_data, NULL, dgettext("sys_string", "IDS_COM_POP_DELETE_Q"),
3032                                         2, dgettext("sys_string", "IDS_COM_SK_DELETE"),
3033                                         _popup_response_delete_ok_cb, dgettext("sys_string", "IDS_COM_SK_CANCEL"),
3034                                         _popup_response_cb, NULL);
3035 }
3036
3037 static void _move_cb(void *data, Evas_Object *obj, void *event_info)
3038 {
3039         debug_log("");
3040         if (!data) {
3041                 debug_log("data is NULL");
3042                 return;
3043         }
3044
3045         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
3046         EmailViewerPrivate *priv = ug_data->email_data;
3047
3048         if (ug_data->con_popup) {
3049                 evas_object_del(ug_data->con_popup);
3050                 ug_data->con_popup = NULL;
3051         }
3052
3053         Elm_Object_Item *git = NULL;
3054         Evas_Object *gl = elm_genlist_add(ug_data->navi_bar);
3055         evas_object_show(gl);
3056
3057         ug_data->itc1.item_style = "1text.1icon.2";
3058         ug_data->itc1.func.text_get = _gl_text_get;
3059         ug_data->itc1.func.content_get = _gl_content_get;
3060         ug_data->itc1.func.state_get = _gl_state_get;
3061         ug_data->itc1.func.del = _gl_del;
3062
3063         ug_data->itc2.item_style = "1text.1icon.2";
3064         ug_data->itc2.func.text_get = _gl_sub_upper_text_get;
3065         ug_data->itc2.func.content_get = _gl_sub_upper_icon_get;
3066         ug_data->itc2.func.state_get = _gl_state_get;
3067         ug_data->itc2.func.del = NULL;
3068
3069         ug_data->itc3.item_style = "grouptitle.dialogue.seperator";
3070         ug_data->itc3.func.text_get = NULL;
3071         ug_data->itc3.func.content_get = NULL;
3072         ug_data->itc3.func.state_get = _gl_state_get;
3073         ug_data->itc3.func.del = NULL;
3074
3075         Elm_Object_Item *navi_it = NULL;
3076         navi_it = elm_naviframe_item_push(ug_data->navi_bar, dgettext("sys_string", "IDS_COM_BODY_MOVE"), NULL, NULL, gl, NULL);
3077         ug_data->navi_move_it1 = navi_it;
3078         if (ug_data->isRotate)
3079                 elm_naviframe_item_title_visible_set(ug_data->navi_move_it1, EINA_FALSE);
3080
3081         email_mailbox_t *mailbox_list = NULL;
3082         int mailbox_count = 0;
3083         int i = 0;
3084
3085         email_get_mailbox_list(priv->account_id, -1, &mailbox_list, &mailbox_count);
3086         debug_log("folder count %d", mailbox_count);
3087         ug_data->move_mailbox_list = mailbox_list;
3088         ug_data->move_mailbox_count = mailbox_count;
3089
3090         git = elm_genlist_item_append(gl, &(ug_data->itc3), NULL, NULL, ELM_GENLIST_ITEM_GROUP, NULL, NULL);
3091         elm_genlist_item_select_mode_set(git, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
3092
3093         for (i = 0; i < mailbox_count; i++) {
3094                 if (g_strcmp0(ug_data->mailbox_name, mailbox_list[i].mailbox_name) != 0) {
3095                         if (mailbox_list[i].mailbox_type != EMAIL_MAILBOX_TYPE_OUTBOX &&
3096                                 mailbox_list[i].mailbox_type != EMAIL_MAILBOX_TYPE_SENTBOX &&
3097                                 mailbox_list[i].mailbox_type != EMAIL_MAILBOX_TYPE_DRAFT &&
3098                                 mailbox_list[i].mailbox_type != EMAIL_MAILBOX_TYPE_TRASH &&
3099                                 mailbox_list[i].mailbox_type != EMAIL_MAILBOX_TYPE_ALL_EMAILS &&
3100                                 mailbox_list[i].mailbox_type != EMAIL_MAILBOX_TYPE_SEARCH_RESULT)
3101                                 if (g_strcmp0(mailbox_list[i].alias, "[Gmail]")) {
3102                                         elm_genlist_item_append(gl, &ug_data->itc1, (void *)&(mailbox_list[i]), git, ELM_GENLIST_ITEM_NONE, _gl_sel, (void *)&(mailbox_list[i]));
3103                                 }
3104                 }
3105         }
3106
3107         /*if (ug_data->b_internal)
3108                 elm_layout_theme_set(ug_data->layout_main, "layout", "application", "noindicator");
3109         else
3110                 elm_layout_theme_set(ug_data->layout_main, "layout", "application", "default");*/
3111
3112         Evas_Object *move_back_btn = NULL;
3113         if (ug_data->isRotate) {
3114                 ug_data->move_cbar = elm_toolbar_add(ug_data->navi_bar);
3115                 elm_toolbar_shrink_mode_set(ug_data->move_cbar, ELM_TOOLBAR_SHRINK_EXPAND);
3116                 elm_object_style_set(ug_data->move_cbar, "naviframe");
3117                 evas_object_show(ug_data->move_cbar);
3118
3119                 elm_object_item_disabled_set(elm_toolbar_item_append(ug_data->move_cbar, NULL, "", NULL, NULL), EINA_TRUE);
3120                 elm_toolbar_item_append(ug_data->move_cbar, NULL, dgettext("sys_string", "IDS_COM_SK_CANCEL"), _move_back_cb, ug_data);
3121                 elm_object_item_part_content_set(navi_it, "controlbar", ug_data->move_cbar);
3122
3123                 move_back_btn = elm_object_item_part_content_get(navi_it, "prev_btn");
3124                 if (move_back_btn) {
3125                         evas_object_del(move_back_btn);
3126                         elm_object_item_part_content_set(navi_it, "prev_btn", NULL);
3127                 }
3128         } else {
3129                 move_back_btn = elm_object_item_part_content_get(navi_it, "prev_btn");
3130                 if (move_back_btn) {
3131                         evas_object_del(move_back_btn);
3132                         move_back_btn = elm_button_add(ug_data->navi_bar);
3133                         elm_object_style_set(move_back_btn, "naviframe/back_btn/default");
3134                         evas_object_smart_callback_add(move_back_btn, "clicked", _move_back_cb, ug_data);
3135                         elm_object_item_part_content_set(navi_it, "prev_btn", move_back_btn);
3136                 }
3137         }
3138 }
3139
3140 static void _more_cb(void *data, Evas_Object *obj, void *event_info)
3141 {
3142         debug_log("");
3143         if (!data) {
3144                 debug_log("data is NULL");
3145                 return;
3146         }
3147
3148         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
3149
3150         _create_more_ctxpopup(ug_data);
3151 }
3152
3153 static void _body_down_cb(void *data, Evas_Object *obj, void *event_info)
3154 {
3155         debug_log("");
3156         if (!data) {
3157                 debug_log("data is NULL");
3158                 return;
3159         }
3160
3161         unsigned int handle;
3162         gboolean ret = 0;
3163         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
3164         EmailViewerPrivate *priv = ug_data->email_data;
3165
3166         /* check already downloaded */
3167         int body_download_status = ug_data->property->body_download;
3168
3169         if (body_download_status == 0) {        //EMAIL_BODY_DOWNLOAD_STATUS_NONE
3170                 debug_log("need body download");
3171         } else if (body_download_status == 1) { //EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED
3172                 debug_log("already downloaded, create body directly");
3173
3174                 /* set property */
3175                 if (viewer_get_internal_mail_info(ug_data->property, ug_data->email_data)) {
3176                         debug_log("");
3177                         viewer_make_internal_mail(ug_data->property, ug_data->email_data);
3178                 }
3179
3180                 if (ug_data->b_partial_body) {
3181                         int scr_x = 0;
3182                         int scr_y = 0;
3183                         int scr_w = 0;
3184                         int scr_h = 0;
3185                         elm_scroller_region_get(ug_data->scroller, &scr_x, &scr_y, &scr_w, &scr_h);
3186                         debug_log("scroller region> x[%d] y[%d] w[%d] h[%d]", scr_x, scr_y, scr_w, scr_h);
3187
3188                         elm_box_unpack(ug_data->main_bx, ug_data->partial_dn_btn_bx);
3189                         if (ug_data->partial_dn_btn) {
3190                                 evas_object_del(ug_data->partial_dn_btn);
3191                                 ug_data->partial_dn_btn = NULL;
3192                         }
3193                         if (ug_data->partial_dn_btn_bx) {
3194                                 evas_object_del(ug_data->partial_dn_btn_bx);
3195                                 ug_data->partial_dn_btn_bx = NULL;
3196                         }
3197
3198                         if (ug_data->property->has_html) {
3199                                 ug_data->webview_data->body_type = BODY_TYPE_HTML;
3200                                 ug_data->webview_data->uri = ug_data->property->body_uri;
3201                         } else {
3202                                 ug_data->webview_data->body_type = BODY_TYPE_TEXT;
3203                                 ug_data->webview_data->text_content = ug_data->property->body;
3204                         }
3205
3206                         viewer_set_webview_content(ug_data, 1);
3207                         ug_data->b_partial_body = 0;
3208
3209                         elm_object_focus_set(ug_data->ly_subject, EINA_TRUE);
3210                         elm_scroller_region_show(ug_data->scroller, scr_x, scr_y, scr_w, scr_h);
3211                 } else {
3212                         if (ug_data->property->has_attachment)
3213                                 ug_data->got_att = 1;
3214                         else
3215                                 ug_data->got_att = 0;
3216
3217                         /* pack attachment if it exist */
3218                         if (ug_data->got_att) {
3219                                 _create_attach(ug_data);
3220                         }
3221
3222                         _create_body(ug_data);
3223                 }
3224
3225                 return;
3226         } else if (body_download_status == 2) { //EMAILL_BODY_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED
3227                 debug_log("need full body download");
3228         }
3229
3230         ret = email_engine_body_download(priv->account_id, priv->mail_id, &handle);
3231
3232         if (ret == TRUE) {
3233                 priv->email_handle = handle;
3234                 debug_log("succeed in email_engine_body_download");
3235                 _create_down_progress(dgettext("sys_string", "IDS_COM_POP_DOWNLOADING"), _destroy_down_progress_cb);
3236
3237                 /* If attachment download is in progress, first cancel to attachment download of the mail and then carry out body download */
3238                 _cancel_download_attachment(ug_data);
3239
3240         } else {
3241                 debug_log("unable to download mail body");
3242                 _create_notify(ug_data, dgettext("sys_string", "IDS_COM_POP_WARNING"),
3243                                                 _("IDS_EMAIL_POP_UNABLE_TO_DOWNLOAD"), 1,
3244                                                 dgettext("sys_string", "IDS_COM_SK_OK"),
3245                                                 _popup_response_cb, NULL, NULL, NULL);
3246         }
3247 }
3248
3249 static void _subject_favorite_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
3250 {
3251         debug_log("");
3252         if (!data) {
3253                 debug_log("data is NULL");
3254                 return;
3255         }
3256
3257         EmailViewerUGD *ug_data = _g_ug_data;
3258         EmailViewerProp *prop = ug_data->property;
3259         int err = EMAIL_ERROR_NONE;
3260
3261         if (ug_data->con_popup) {
3262                 evas_object_del(ug_data->con_popup);
3263                 ug_data->con_popup = NULL;
3264         }
3265
3266         debug_log("Before prop->favorite: %d", prop->favorite);
3267         switch(prop->favorite) {
3268                 case EMAIL_FLAG_NONE:
3269                         prop->favorite = EMAIL_FLAG_FLAGED;
3270                         break;
3271                 case EMAIL_FLAG_FLAGED:
3272                         prop->favorite = EMAIL_FLAG_NONE;
3273                         break;
3274                 case EMAIL_FLAG_TASK_STATUS_CLEAR:
3275                         prop->favorite = EMAIL_FLAG_TASK_STATUS_ACTIVE;
3276                         break;
3277                 case EMAIL_FLAG_TASK_STATUS_ACTIVE:
3278                         prop->favorite = EMAIL_FLAG_TASK_STATUS_COMPLETE;
3279                         break;
3280                 case EMAIL_FLAG_TASK_STATUS_COMPLETE:
3281                         prop->favorite = EMAIL_FLAG_TASK_STATUS_CLEAR;
3282                         break;
3283                 default:
3284                         debug_log("Never here");
3285         }
3286         debug_log("After prop->favorite: %d", prop->favorite);
3287
3288         err = email_set_flags_field(ug_data->account_id, &ug_data->mail_id, 1, EMAIL_FLAGS_FLAGGED_FIELD, prop->favorite, 1);
3289         if (err != EMAIL_ERROR_NONE) {
3290                 _create_notify(ug_data, _("IDS_EMAIL_POP_ALERT"),
3291                                 N_("Failed to set favourite"), 0,
3292                                 NULL, NULL, NULL, NULL, _popup_response_cb);
3293                 return;
3294         }
3295
3296         evas_object_del(elm_object_part_content_unset(ug_data->ly_subject, "elm.icon.favorite"));
3297         Evas_Object *favorite_icon = elm_icon_add(ug_data->ly_subject);
3298         switch(prop->favorite)
3299         {
3300                 case EMAIL_FLAG_NONE:
3301                         elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_icon_favorite_off.png", NULL);
3302                         break;
3303                 case EMAIL_FLAG_FLAGED:
3304                         elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_icon_favorite_on.png", NULL);
3305                         break;
3306                 case EMAIL_FLAG_TASK_STATUS_CLEAR:
3307                         elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_Flag_Clear.png", NULL);
3308                         break;
3309                 case EMAIL_FLAG_TASK_STATUS_ACTIVE:
3310                         elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_Flag_Active.png", NULL);
3311                         break;
3312                 case EMAIL_FLAG_TASK_STATUS_COMPLETE:
3313                         elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_Flag_Complete.png", NULL);
3314                         break;
3315                 default:
3316                         debug_log("Never here");
3317         }
3318         evas_object_size_hint_aspect_set(favorite_icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
3319         elm_icon_resizable_set(favorite_icon, 1, 1);
3320         elm_object_part_content_set(ug_data->ly_subject, "elm.icon.favorite", favorite_icon);
3321         evas_object_show(favorite_icon);
3322
3323         /* send unread request to mailbox. */
3324         int ret;
3325         service_h service = NULL;
3326
3327         ret = service_create(&service);
3328         debug_log("service_create: %d", ret);
3329         if (!service) {
3330                 debug_log("service create failed");
3331                 return;
3332         }
3333
3334         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_MSG, EMAIL_BUNDLE_VAL_READ);
3335         debug_log("service_add_extra_data: %d", ret);
3336
3337         ug_send_message(_g_mailbox_ug, service);
3338
3339         ret = service_destroy(service);
3340         debug_log("service_destroy: %d", ret);
3341 }
3342
3343 static void _subject_detail_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
3344 {
3345         debug_log("");
3346         if (!_g_ug_data) {
3347                 debug_log("data is NULL");
3348                 return;
3349         }
3350
3351         Evas_Object *item = (Evas_Object *)data;
3352         EmailViewerUGD *ug_data = _g_ug_data;
3353
3354         if (!(ug_data->subject_onoff_flag)) {
3355                 edje_object_signal_emit(_EDJ(item), "elm,state,expanded", "elm");
3356                 (ug_data->subject_onoff_flag)++;
3357
3358                 _create_to_addrs(_g_ug_data);
3359                 _create_cc_addrs(_g_ug_data);
3360                 _create_bcc_addrs(_g_ug_data);
3361         } else {
3362                 edje_object_signal_emit(_EDJ(item), "elm,state,contracted", "elm");
3363                 (ug_data->subject_onoff_flag)--;
3364
3365                 if (ug_data->to_ly) {
3366                         elm_box_unpack(ug_data->main_bx, ug_data->to_ly);
3367                         evas_object_del(ug_data->to_ly);
3368                         ug_data->to_ly = NULL;
3369                 }
3370                 if (ug_data->cc_ly) {
3371                         elm_box_unpack(ug_data->main_bx, ug_data->cc_ly);
3372                         evas_object_del(ug_data->cc_ly);
3373                         ug_data->cc_ly = NULL;
3374                 }
3375                 if (ug_data->bcc_ly) {
3376                         elm_box_unpack(ug_data->main_bx, ug_data->bcc_ly);
3377                         evas_object_del(ug_data->bcc_ly);
3378                         ug_data->bcc_ly = NULL;
3379                 }
3380
3381                 elm_object_focus_set(ug_data->ly_subject, EINA_TRUE);
3382         }
3383 }
3384
3385 static void _attachment_item_collapse_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
3386 {
3387         debug_log("");
3388         if (!data || !_g_ug_data) {
3389                 debug_log("data is NULL");
3390                 return;
3391         }
3392
3393         Evas_Object *item = (Evas_Object *)data;
3394         EmailViewerUGD *ug_data = _g_ug_data;
3395         EmailViewerProp *prop = ug_data->property;
3396         int i = 0;
3397
3398         debug_log("attach_onoff_flag:%d", ug_data->attach_onoff_flag);
3399         if (!(ug_data->attach_onoff_flag)) {
3400                 debug_log("attachments expanded");
3401                 edje_object_signal_emit(_EDJ(item), "elm,state,expanded", "elm");
3402                 (ug_data->attach_onoff_flag)++;
3403
3404                 if (ug_data->attach_ex_ly == NULL)
3405                         _create_attach_ex(ug_data);
3406                 else {
3407                         for (i = 0; i < prop->real_att_len; i++) {
3408                                 debug_log("index %d", i);
3409                                 elm_box_pack_after(ug_data->main_bx, ug_data->attach_ex_ly[i], ug_data->attach_hd_ly);
3410                                 evas_object_show(ug_data->attach_ex_ly[i]);
3411                         }
3412                 }
3413         } else {
3414                 debug_log("attachments contracted");
3415                 edje_object_signal_emit(_EDJ(item), "elm,state,contracted", "elm");
3416                 ug_data->attach_onoff_flag = 0;
3417
3418                 for (i = 0; i < prop->real_att_len; i++) {
3419                         if (ug_data->attach_ex_ly[i] != NULL) {
3420                                 debug_log("index %d", i);
3421                                 elm_box_unpack(ug_data->main_bx, ug_data->attach_ex_ly[i]);
3422                                 evas_object_hide(ug_data->attach_ex_ly[i]);
3423                         }
3424                 }
3425         }
3426 }
3427
3428 static void _attachment_save_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
3429 {
3430         debug_log("");
3431
3432         if (!_g_ug_data) {
3433                 debug_log("ug_data is NULL");
3434                 return;
3435         }
3436
3437         EmailViewerUGD *ug_data = _g_ug_data;
3438         int att_index = (int)data;
3439
3440         ug_data->display_download_result = FALSE;
3441
3442         debug_log("Selected item index = %d", att_index);
3443         _show_attachment(ug_data, att_index);
3444 }
3445
3446 static void _attachment_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
3447 {
3448         debug_log("");
3449
3450         if (!_g_ug_data) {
3451                 debug_log("ug_data is NULL");
3452                 return;
3453         }
3454
3455         EmailViewerUGD *ug_data = _g_ug_data;
3456         int att_index = (int)data;
3457
3458         debug_log("Selected item index = %d", att_index);
3459         ug_data->display_download_result = TRUE;
3460         _show_attachment(ug_data, att_index);
3461 }
3462
3463 static void _attachment_save_all_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
3464 {
3465         debug_log("");
3466         if (!_g_ug_data) {
3467                 debug_log("ug_data is NULL");
3468                 return;
3469         }
3470
3471         EmailViewerUGD *ug_data = _g_ug_data;
3472
3473         _save_attachment_all(ug_data);
3474 }
3475
3476 static void _attachment_bg_set_cb(void *data, Evas * evas, Evas_Object *obj, void *event_info)
3477 {
3478         debug_log("");
3479         if (!_g_ug_data) {
3480                 debug_log("ug_data is NULL");
3481                 return;
3482         }
3483
3484         EmailViewerUGD *ug_data = _g_ug_data;
3485         EmailViewerProp *prop = ug_data->property;
3486
3487         int att_index = (int)data;
3488         debug_log("att_index = %d, attachments count = %d", att_index, prop->real_att_len);
3489
3490         if (prop->real_att_len > 1) {
3491                 int i = 0;
3492                 int j = 0;
3493                 GList *attachment_list = prop->attachments;
3494                 LIST_ITER_START(i, attachment_list) {
3495                         EmailAttachmentType *info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, attachment_list);
3496                         if (info && !info->inline_content) {
3497                                 if (att_index == i)
3498                                         break;
3499                                 j++;
3500                         }
3501                 }
3502                 edje_object_signal_emit(_EDJ(ug_data->attach_ex_ly[j]), "pressed", "elm.event.rect");
3503         }
3504         else
3505                 edje_object_signal_emit(_EDJ(ug_data->attach_hd_ly), "pressed", "elm.event.rect");
3506 }
3507
3508 static void _attachment_bg_unset_cb(void *data, Evas * evas, Evas_Object *obj, void *event_info)
3509 {
3510         debug_log("");
3511         if (!_g_ug_data) {
3512                 debug_log("ug_data is NULL");
3513                 return;
3514         }
3515
3516         EmailViewerUGD *ug_data = _g_ug_data;
3517         EmailViewerProp *prop = ug_data->property;
3518
3519         int att_index = (int)data;
3520         debug_log("att_index = %d, attachments count = %d", att_index, prop->real_att_len);
3521
3522         if (prop->real_att_len > 1) {
3523                 int i = 0;
3524                 int j = 0;
3525                 GList *attachment_list = prop->attachments;
3526                 LIST_ITER_START(i, attachment_list) {
3527                         EmailAttachmentType *info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, attachment_list);
3528                         if (info && !info->inline_content) {
3529                                 if (att_index == i)
3530                                         break;
3531                                 j++;
3532                         }
3533                 }
3534                 edje_object_signal_emit(_EDJ(ug_data->attach_ex_ly[j]), "unpressed", "elm.event.rect");
3535         }
3536         else
3537                 edje_object_signal_emit(_EDJ(ug_data->attach_hd_ly), "unpressed", "elm.event.rect");
3538 }
3539
3540 static void _mark_as_unread_cb(void *data, Evas_Object *obj, void *event_info)
3541 {
3542         debug_log("");
3543         if (!data) {
3544                 debug_log("data is NULL");
3545                 return;
3546         }
3547
3548         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
3549         EmailViewerPrivate *priv = ug_data->email_data;
3550
3551         if (ug_data->con_popup) {
3552                 evas_object_del(ug_data->con_popup);
3553                 ug_data->con_popup = NULL;
3554         }
3555
3556         int err = 0;
3557         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);
3558
3559         err = email_set_flags_field(ug_data->account_id, &ug_data->mail_id, 1, EMAIL_FLAGS_SEEN_FIELD, 0, 1);
3560         debug_log("email_set_flags_field - err(%d)", err);
3561
3562         if (err != EMAIL_ERROR_NONE) {
3563                 _create_notify(ug_data, _("IDS_EMAIL_POP_ALERT"),
3564                                                 _("IDS_EMAIL_POP_FAILED_TO_MARK_AS_UNREAD"), 0,
3565                                                 NULL, NULL, NULL, NULL, _popup_response_cb);
3566         } else {
3567                 char str[128] = { 0, };
3568                 snprintf(str, sizeof(str), "%s", _("IDS_EMAIL_POP_MARKED_AS_UNREAD"));
3569                 _show_select_info(ug_data, str);
3570
3571                 /* send unread request to mailbox. */
3572                 int ret;
3573                 service_h service = NULL;
3574
3575                 ret = service_create(&service);
3576                 debug_log("service_create: %d", ret);
3577                 if (!service) {
3578                         debug_log("service create failed");
3579                         return;
3580                 }
3581
3582                 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_MSG, EMAIL_BUNDLE_VAL_UNREAD);
3583                 debug_log("service_add_extra_data: %d", ret);
3584
3585                 ug_send_message(_g_mailbox_ug, service);
3586
3587                 ret = service_destroy(service);
3588                 debug_log("service_destroy: %d", ret);
3589         }
3590 }
3591
3592 static void _mark_as_read_cb(void *data, Evas_Object *obj, void *event_info)
3593 {
3594         debug_log("");
3595         if (!data) {
3596                 debug_log("data is NULL");
3597                 return;
3598         }
3599
3600         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
3601         EmailViewerPrivate *priv = ug_data->email_data;
3602
3603         if (ug_data->con_popup) {
3604                 evas_object_del(ug_data->con_popup);
3605                 ug_data->con_popup = NULL;
3606         }
3607
3608         int err = 0;
3609         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);
3610
3611         err = email_set_flags_field(priv->mail_info->account_id, &ug_data->mail_id, 1, EMAIL_FLAGS_SEEN_FIELD, 1, 1);
3612         debug_log("email_set_flags_field - err(%d)", err);
3613
3614         if (err != EMAIL_ERROR_NONE) {
3615                 _create_notify(ug_data, _("IDS_EMAIL_POP_ALERT"),
3616                                                 _("IDS_EMAIL_POP_FAILED_TO_MARK_AS_READ"), 0,
3617                                                 NULL, NULL, NULL, NULL, _popup_response_cb);
3618         } else {
3619                 char str[128] = { 0, };
3620                 snprintf(str, sizeof(str), "%s", _("IDS_EMAIL_POP_MARKED_AS_READ"));
3621                 _show_select_info(ug_data, str);
3622
3623                 /* send unread request to mailbox. */
3624                 int ret;
3625                 service_h service = NULL;
3626
3627                 ret = service_create(&service);
3628                 debug_log("service_create: %d", ret);
3629                 if (!service) {
3630                         debug_log("service create failed");
3631                         return;
3632                 }
3633
3634                 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_MSG, EMAIL_BUNDLE_VAL_READ);
3635                 debug_log("service_add_extra_data: %d", ret);
3636
3637                 ug_send_message(_g_mailbox_ug, service);
3638
3639                 ret = service_destroy(service);
3640                 debug_log("service_destroy: %d", ret);
3641         }
3642 }
3643
3644 static void _ctxpopup_detail_contact_cb(void *data, Evas_Object *obj, void *event_info)
3645 {
3646         debug_log("");
3647         if (data == NULL || _g_ug_data == NULL) {
3648                 debug_log("data is NULL");
3649                 return;
3650         }
3651
3652         EmailViewerUGD *ug_data = _g_ug_data;
3653
3654         if (ug_data->con_popup) {
3655                 evas_object_del(ug_data->con_popup);
3656                 ug_data->con_popup = NULL;
3657         }
3658
3659         char *index = (char *)data;
3660         char type[10] = { 0, };
3661         int ret;
3662         service_h service = NULL;
3663
3664         ret = service_create(&service);
3665         debug_log("service_create: %d", ret);
3666         if (!service) {
3667                 debug_log("service create failed");
3668                 return;
3669         }
3670
3671         snprintf(type, sizeof(type), "%d", CT_UG_REQUEST_DETAIL);
3672
3673         ret = service_add_extra_data(service, CT_UG_BUNDLE_TYPE, type);
3674         debug_log("service_add_extra_data: %d", ret);
3675         ret = service_add_extra_data(service, CT_UG_BUNDLE_ID, index);
3676         debug_log("service_add_extra_data: %d", ret);
3677
3678         create_ug(UG_CONTACTS_DETAILS, service, ug_data);
3679
3680         ret = service_destroy(service);
3681         debug_log("service_destroy: %d", ret);
3682
3683         debug_log("set flag for contact ug");
3684         ug_data->b_contact_ug_launched = TRUE;
3685 }
3686
3687 static void _ctxpopup_send_email_cb(void *data, Evas_Object *obj, void *event_info)
3688 {
3689         debug_log("");
3690         if (!data || !_g_ug_data) {
3691                 debug_log("data is NULL");
3692                 return;
3693         }
3694
3695         EmailViewerUGD *ug_data = _g_ug_data;
3696
3697         if (ug_data->con_popup == NULL) {
3698                 debug_log("con_popup is NULL");
3699                 return;
3700         }
3701
3702         if (ug_data->con_popup) {
3703                 evas_object_del(ug_data->con_popup);
3704                 ug_data->con_popup = NULL;
3705         }
3706
3707         debug_log("email: %s", (char *)data);
3708
3709         int ret;
3710         service_h service = NULL;
3711
3712         ret = service_create(&service);
3713         debug_log("service_create: %d", ret);
3714         if (!service) {
3715                 debug_log("service create failed");
3716                 return;
3717         }
3718
3719         char rtype[10] = { 0, };
3720         snprintf(rtype, sizeof(rtype), "%d", RUN_COMPOSER_EXTERNAL);
3721
3722         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_RUN_TYPE, rtype);
3723         debug_log("service_add_extra_data: %d", ret);
3724         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_TO, (char *)data);
3725         debug_log("service_add_extra_data: %d", ret);
3726         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_CC, NULL);
3727         debug_log("service_add_extra_data: %d", ret);
3728         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_BCC, NULL);
3729         debug_log("service_add_extra_data: %d", ret);
3730         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_SUBJECT, NULL);
3731         debug_log("service_add_extra_data: %d", ret);
3732         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_BODY, NULL);
3733         debug_log("service_add_extra_data: %d", ret);
3734         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_ATTACHMENT, NULL);
3735         debug_log("service_add_extra_data: %d", ret);
3736
3737         ug_data->ug_composer = create_ug(UG_NAME_EMAIL_COMPOSER, service, ug_data);
3738
3739         ret = service_destroy(service);
3740         debug_log("service_destroy: %d", ret);
3741 }
3742
3743 static void _ctxpopup_add_contact_cb(void *data, Evas_Object *obj, void *event_info)
3744 {
3745         debug_log("");
3746         if (!data || !_g_ug_data) {
3747                 debug_log("data is NULL");
3748                 return;
3749         }
3750
3751         char tmp[MAX_STR_LEN] = { 0, };
3752         EmailViewerUGD *ug_data = _g_ug_data;
3753
3754         if (ug_data->con_popup == NULL) {
3755                 debug_log("con_popup is NULL");
3756                 return;
3757         }
3758
3759         if (ug_data->con_popup) {
3760                 evas_object_del(ug_data->con_popup);
3761                 ug_data->con_popup = NULL;
3762         }
3763
3764         int ret;
3765         service_h service = NULL;
3766
3767         ret = service_create(&service);
3768         debug_log("service_create: %d", ret);
3769         if (!service) {
3770                 debug_log("service create failed");
3771                 return;
3772         }
3773
3774         if (ug_data->create_contact_arg == CONTACTUI_REQ_ADD_PHONE_NUMBER) {
3775                 snprintf(tmp, sizeof(tmp), "%d", CT_UG_REQUEST_ADD_WITH_NUM);
3776                 ret = service_add_extra_data(service, CT_UG_BUNDLE_TYPE, tmp);
3777                 debug_log("service_add_extra_data: %d", ret);
3778                 ret = service_add_extra_data(service, CT_UG_BUNDLE_NUM, (char *)data);
3779                 debug_log("service_add_extra_data: %d", ret);
3780         }
3781         if (ug_data->create_contact_arg == CONTACTUI_REQ_ADD_EMAIL) {
3782                 snprintf(tmp, sizeof(tmp), "%d", CT_UG_REQUEST_ADD_WITH_EMAIL);
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_EMAIL, (char *)data);
3786                 debug_log("service_add_extra_data: %d", ret);
3787         }
3788         if (ug_data->create_contact_arg == CONTACTUI_REQ_ADD_URL) {
3789                 snprintf(tmp, sizeof(tmp), "%d", CT_UG_REQUEST_ADD_WITH_WEB);
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_WEB, (char *)data);
3793                 debug_log("service_add_extra_data: %d", ret);
3794         }
3795
3796         create_ug(UG_CONTACTS_DETAILS, service, ug_data);
3797
3798         ret = service_destroy(service);
3799         debug_log("service_destroy: %d", ret);
3800 }
3801
3802 static void _ctxpopup_cutlink_update_contact_cb(void *data, Evas_Object *obj, void *event_info)
3803 {
3804         debug_log("");
3805         if (!data || !_g_ug_data) {
3806                 debug_log("data is NULL");
3807                 return;
3808         }
3809
3810         char tmp[MAX_STR_LEN] = { 0, };
3811         EmailViewerUGD *ug_data = _g_ug_data;
3812
3813         if (ug_data->con_popup == NULL) {
3814                 debug_log("con_popup is NULL");
3815                 return;
3816         }
3817
3818         if (ug_data->con_popup) {
3819                 evas_object_del(ug_data->con_popup);
3820                 ug_data->con_popup = NULL;
3821         }
3822
3823         int ret;
3824         service_h service = NULL;
3825
3826         ret = service_create(&service);
3827         debug_log("service_create: %d", ret);
3828         if (!service) {
3829                 debug_log("service create failed");
3830                 return;
3831         }
3832
3833         if (ug_data->create_contact_arg == CONTACTUI_REQ_ADD_PHONE_NUMBER) {
3834                 snprintf(tmp, sizeof(tmp), "%d", CT_UG_REQUEST_ADD_WITH_NUM);
3835                 ret = service_add_extra_data(service, CT_UG_BUNDLE_TYPE, tmp);
3836                 debug_log("service_add_extra_data: %d", ret);
3837                 ret = service_add_extra_data(service, CT_UG_BUNDLE_NUM, (char *)data);
3838                 debug_log("service_add_extra_data: %d", ret);
3839         }
3840         if (ug_data->create_contact_arg == CONTACTUI_REQ_ADD_EMAIL) {
3841                 snprintf(tmp, sizeof(tmp), "%d", CT_UG_REQUEST_ADD_WITH_EMAIL);
3842                 ret = service_add_extra_data(service, CT_UG_BUNDLE_TYPE, tmp);
3843                 debug_log("service_add_extra_data: %d", ret);
3844                 ret = service_add_extra_data(service, CT_UG_BUNDLE_EMAIL, (char *)data);
3845                 debug_log("service_add_extra_data: %d", ret);
3846         }
3847         if (ug_data->create_contact_arg == CONTACTUI_REQ_ADD_URL) {
3848                 snprintf(tmp, sizeof(tmp), "%d", CT_UG_REQUEST_ADD_WITH_WEB);
3849                 ret = service_add_extra_data(service, CT_UG_BUNDLE_TYPE, tmp);
3850                 debug_log("service_add_extra_data: %d", ret);
3851                 ret = service_add_extra_data(service, CT_UG_BUNDLE_WEB, (char *)data);
3852                 debug_log("service_add_extra_data: %d", ret);
3853         }
3854
3855         ug_data->ug_contacts_search = create_ug(UG_CONTACTS_LIST, service, ug_data);
3856
3857         ret = service_destroy(service);
3858         debug_log("service_destroy: %d", ret);
3859 }
3860
3861 static void _ctxpopup_select_contact_mode_email_cb(void *data, Evas_Object *obj, void *event_info)
3862 {
3863         debug_log("");
3864         if (!data || !_g_ug_data) {
3865                 debug_log("data is NULL");
3866                 return;
3867         }
3868
3869         EmailViewerUGD *ug_data = _g_ug_data;
3870         Evas_Coord x, y;
3871
3872         if (ug_data->con_popup) {
3873                 evas_object_del(ug_data->con_popup);
3874                 ug_data->con_popup = NULL;
3875         }
3876
3877         ug_data->con_popup = elm_ctxpopup_add(ug_data->navi_bar);
3878         if (ug_data->con_popup == NULL) {
3879                 debug_log("cannot create context popup");
3880                 return;
3881         }
3882
3883         ug_data->create_contact_arg = CONTACTUI_REQ_ADD_EMAIL;
3884         ug_data->update_contact_type = CONTACTUI_REQ_ADD_EMAIL;
3885
3886         elm_ctxpopup_item_append(ug_data->con_popup, dgettext("sys_string", "IDS_COM_OPT_CREATE_CONTACT"), NULL, _ctxpopup_add_contact_cb, data);
3887         elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_UPDATE_EXISTING"), NULL, _ctxpopup_cutlink_update_contact_cb, data);
3888
3889         evas_pointer_canvas_xy_get(ug_data->evas, &x, &y);
3890         evas_object_move(ug_data->con_popup, x, y);
3891         evas_object_show(ug_data->con_popup);
3892 }
3893
3894 static void _ctxpopup_add_block_rule_cb(void *data, Evas_Object *obj, void *event_info)
3895 {
3896         debug_log("");
3897
3898         if (!data || !_g_ug_data) {
3899                 debug_log("data is NULL");
3900                 return;
3901         }
3902
3903         EmailViewerUGD *ug_data = _g_ug_data;
3904         EmailViewerPrivate *priv = ug_data->email_data;
3905         char *addr = (char *)data;
3906
3907         debug_log("Block address: %s", addr);
3908
3909         if (ug_data->con_popup) {
3910                 evas_object_del(ug_data->con_popup);
3911                 ug_data->con_popup = NULL;
3912         }
3913
3914         int ret;
3915         email_rule_t *rule = NULL;
3916
3917         /* add filtering rule */
3918         rule = malloc(sizeof(email_rule_t));
3919         rule->account_id = priv->account_id;
3920         rule->type = EMAIL_FILTER_FROM;
3921         rule->value = g_strdup(addr);
3922         rule->faction = EMAIL_FILTER_BLOCK;
3923
3924         int err = 0;
3925         email_mailbox_t *mail_box = NULL;
3926         if ((err = email_get_mailbox_by_mailbox_type(ug_data->account_id, ug_data->mailbox_type, &mail_box)) != EMAIL_ERROR_NONE) {
3927                 debug_log("email_get_mailbox_by_mailbox_type failed! - err (%d)", err);
3928         }
3929
3930         if (mail_box == NULL) {
3931                 debug_log("mail_box is NULL");
3932         }
3933
3934         rule->target_mailbox_id = mail_box->mailbox_id;
3935
3936         if (mail_box) {
3937                 debug_log("email_free_mailbox is called");
3938                 email_free_mailbox(&mail_box, 1);
3939                 mail_box = NULL;
3940         }
3941
3942         rule->flag1 = 1;
3943         rule->flag2 = RULE_TYPE_INCLUDES;
3944
3945         ret = email_add_rule(rule);
3946         if (ret < 0) {
3947                 debug_log("email_add_rule failed %d", ret);
3948                 _create_notify(ug_data, _("IDS_EMAIL_POP_ALERT"),
3949                                                 _("IDS_EMAIL_POP_FAILED_TO_ADD_BLOCK_RULE"), 0,
3950                                                 NULL, NULL, NULL, NULL, _popup_response_cb);
3951         } else {
3952                 int vconf_ret = -1;
3953                 vconf_ret = vconf_set_int(EMAIL_VCONF_KEY_BLOCK_RULE_CHANGED, 1);
3954                 if (vconf_ret == -1) {
3955                         debug_log("fail to set vconf int(spam_rule_changed)");
3956                         _create_notify(ug_data, _("IDS_EMAIL_POP_ALERT"),
3957                                                         _("IDS_EMAIL_POP_FAILED_TO_ADD_BLOCK_RULE"), 0,
3958                                                         NULL, NULL, NULL, NULL, _popup_response_cb);
3959                 } else {
3960                         char str[128] = { 0, };
3961                         snprintf(str, sizeof(str), "%s", _("IDS_EMAIL_POP_BLOCKED"));
3962                         ret = status_message_post(str);
3963                         if (ret)
3964                                 debug_log("status_message_post failed: %d", ret);
3965                 }
3966         }
3967
3968         email_free_rule(&rule, 1);
3969 }
3970
3971 static void _popup_response_cb(void *data, Evas_Object *obj, void *event_info)
3972 {
3973         debug_log("");
3974         if (!_g_ug_data) {
3975                 debug_log("_g_ug_data is NULL");
3976                 return;
3977         }
3978
3979         if (!data) {
3980                 debug_log("data is NULL");
3981                 return;
3982         }
3983
3984         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
3985
3986         if (ug_data->notify) {
3987                 evas_object_del(ug_data->notify);
3988                 ug_data->notify = NULL;
3989         }
3990 }
3991
3992 static void _popup_response_delete_ok_cb(void *data, Evas_Object *obj, void *event_info)
3993 {
3994         debug_log("");
3995         if (!_g_ug_data) {
3996                 debug_log("_g_ug_data is NULL");
3997                 return;
3998         }
3999
4000         if (!data) {
4001                 debug_log("data is NULL");
4002                 return;
4003         }
4004
4005         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
4006
4007         if (ug_data->notify) {
4008                 evas_object_del(ug_data->notify);
4009                 ug_data->notify = NULL;
4010         }
4011
4012         if (ug_data->mailbox_type == EMAIL_MAILBOX_TYPE_TRASH)
4013                 _delete_email(ug_data);
4014         else
4015                 _move_email(ug_data, _find_folder_id_using_folder_type(ug_data, EMAIL_MAILBOX_TYPE_TRASH), TRUE);
4016
4017         if (ug_data->isRotate == false && ug_data->b_internal) {
4018                 _notify_mailbox_size(ug_data, "MAILBOX_RESIZE_FULL");
4019         }
4020
4021         /* close viewer */
4022         if (ug_data->b_internal) {
4023                 _hide_view(ug_data);
4024
4025                 /* send next or previous mail request to mailbox. */
4026                 int ret;
4027                 service_h service = NULL;
4028
4029                 ret = service_create(&service);
4030                 debug_log("service_create: %d", ret);
4031                 if (!service) {
4032                         debug_log("service create failed");
4033                         return;
4034                 }
4035
4036                 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_MSG, EMAIL_BUNDLE_VAL_NEXT_MSG);
4037                 debug_log("service_add_extra_data: %d", ret);
4038                 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_DO_DELETE, "1");
4039                 debug_log("service_add_extra_data: %d", ret);
4040
4041                 ug_send_message(_g_mailbox_ug, service);
4042
4043                 ret = service_destroy(service);
4044                 debug_log("service_destroy: %d", ret);
4045         } else
4046                 ug_destroy_me(ug_data->ug);
4047 }
4048
4049 static void _popup_response_to_destroy_cb(void *data, Evas_Object *obj, void *event_info)
4050 {
4051         debug_log("");
4052
4053         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
4054         evas_object_del(obj);
4055
4056         ug_data->b_direct_destroy = 1;
4057         ug_destroy_me(ug_data->ug);
4058         _g_ug_data = NULL;
4059 }
4060
4061 static void _webview_multi_up_cb(void *data, Evas * evas, Evas_Object *obj, void *event_info)
4062 {
4063         debug_log("");
4064         if (_g_ug_data == NULL)
4065                 return;
4066
4067         if (!data) {
4068                 debug_log("data is NULL");
4069                 return;
4070         }
4071
4072         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
4073
4074         ug_data->m_is_multi_touch = FALSE;
4075
4076         if (ug_data->scroller_locked) {
4077                 ug_data->scroller_locked = FALSE;
4078                 debug_log("<<unlock scroller>>");
4079                 debug_log("<<lock webview>>");
4080         }
4081 }
4082
4083 static void _webview_multi_down_cb(void *data, Evas * evas, Evas_Object *obj, void *event_info)
4084 {
4085         debug_log("");
4086         if (_g_ug_data == NULL)
4087                 return;
4088
4089         if (!data) {
4090                 debug_log("data is NULL");
4091                 return;
4092         }
4093
4094         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
4095
4096         ug_data->m_is_multi_touch = TRUE;
4097
4098         if (ug_data->scroller_locked == FALSE) {
4099                 ug_data->scroller_locked = TRUE;
4100                 debug_log("<<lock scroller>>");
4101                 debug_log("<<unlock webview>>");
4102         }
4103 }
4104
4105 static void _webview_policy_navigation_decide_cb(void *data, Evas_Object *obj, void *event_info)
4106 {
4107         debug_log("");
4108         if (!_g_ug_data) {
4109                 debug_log("data is NULL");
4110                 return;
4111         }
4112
4113         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
4114
4115         if (ug_data->b_load_finished == EINA_TRUE) {
4116                 Ewk_Policy_Decision *policy_decision = (Ewk_Policy_Decision *)event_info;
4117                 ewk_policy_decision_ignore(policy_decision);
4118
4119                 debug_log("url:%s", ewk_policy_decision_url_get(policy_decision));
4120                 debug_log("scheme:%s", ewk_policy_decision_scheme_get(policy_decision));
4121                 debug_log("cookie:%s", ewk_policy_decision_cookie_get(policy_decision));
4122                 debug_log("host:%s", ewk_policy_decision_host_get(policy_decision));
4123                 debug_log("response_mime:%s", ewk_policy_decision_response_mime_get(policy_decision));
4124
4125                 char *url = (char *)ewk_policy_decision_url_get(policy_decision);
4126
4127                 if ((strncmp(url, "http://", 7) == 0) ||
4128                         (strncmp(url, "https://", 8) == 0) ||
4129                         (strncmp(url, "ftp://", 6) == 0) ||
4130                         (strncmp(url, "mms://", 6) == 0) ||
4131                         (strncmp(url, "file://", 7) == 0) ||
4132                         (strncmp(url, "rtsp://", 7) == 0) ||
4133                         (strncmp(url, "wap://", 6) == 0)) {
4134                         int ret;
4135                         service_h service = NULL;
4136                         ret = service_create(&service);
4137                         debug_log("service_create: %d", ret);
4138                         if (!service) {
4139                                 debug_log("service create failed");
4140                                 return;
4141                         }
4142                         ret = service_set_operation(service, SERVICE_OPERATION_VIEW);
4143                         debug_log("service_set_operation: %d", ret);
4144                         ret = service_set_uri(service, url);
4145                         debug_log("service_set_uri: %d", ret);
4146                         ret = service_send_launch_request(service, NULL, NULL);
4147                         debug_log("service_send_launch_request: %d", ret);
4148                         ret = service_destroy(service);
4149                         debug_log("service_destroy: %d", ret);
4150                 }
4151
4152                 if (strncmp(url, "tel:", 4) == 0) {
4153                         char refined_num[MAX_STR_LEN] = { 0, };
4154                         int i = 0, j = 0;
4155
4156                         while (url[i] != '\0') {
4157                                 if (url[i] >= '0' && url[i] <= '9')
4158                                         refined_num[j++] = url[i];
4159                                 i++;
4160                         }
4161
4162                         char *number = refined_num;
4163                         debug_log("number: %s", number);
4164
4165                         int ret;
4166                         service_h service = NULL;
4167                         char telnum[255] = { 0, };
4168                         ret = service_create(&service);
4169                         debug_log("service_create: %d", ret);
4170                         if (!service) {
4171                                 debug_log("service create failed");
4172                                 return;
4173                         }
4174                         ret = service_set_operation(service, SERVICE_OPERATION_CALL);
4175                         debug_log("service_set_operation: %d", ret);
4176                         snprintf(telnum, sizeof(telnum), "tel:%s", number); /* Number to make a call */
4177                         ret = service_set_uri(service, telnum);
4178                         debug_log("service_set_uri: %d", ret);
4179                         ret = service_add_extra_data(service, "ctindex", "-1"); /* If you don't know ctindex, you don't have to add it. */
4180                         debug_log("service_add_extra_data: %d", ret);
4181                         ret = service_send_launch_request(service, NULL, NULL);
4182                         debug_log("service_send_launch_request: %d", ret);
4183                         ret = service_destroy(service);
4184                         debug_log("service_destroy: %d", ret);
4185                 }
4186
4187                 if (strncmp(url, "mailto:", 7) == 0) {
4188                         int ret;
4189                         service_h service = NULL;
4190                         ret = service_create(&service);
4191                         debug_log("service_create: %d", ret);
4192                         if (!service) {
4193                                 debug_log("service create failed");
4194                                 return;
4195                         }
4196
4197                         char rtype[10] = { 0, };
4198                         snprintf(rtype, sizeof(rtype), "%d", RUN_COMPOSER_EXTERNAL);
4199
4200                         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_RUN_TYPE, rtype);
4201                         debug_log("service_add_extra_data: %d", ret);
4202                         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_TO, &url[7]);
4203                         debug_log("service_add_extra_data: %d", ret);
4204
4205                         ug_data->ug_composer = create_ug(UG_NAME_EMAIL_COMPOSER, service, ug_data);
4206
4207                         ret = service_destroy(service);
4208                         debug_log("service_destroy: %d", ret);
4209                 }
4210         }
4211 }
4212
4213 /* Double_Scroller */
4214 static void _outter_scroller_bottom_hit_cb(void *data, Evas_Object *obj, void *event_info)
4215 {
4216         debug_log("");
4217
4218         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
4219         int res = email_engine_check_body_download(ug_data->email_data->mail_id);
4220
4221         if (ug_data->is_main_scroller_scrolling && res != 0) {
4222                 debug_log("Main scroller hold push");
4223                 elm_object_scroll_freeze_push(ug_data->scroller);       //stop
4224                 ewk_view_vertical_panning_hold_set(ug_data->webview, EINA_FALSE);       //restart
4225                 ug_data->is_main_scroller_scrolling = EINA_FALSE;
4226                 ug_data->is_webview_scrolling = EINA_TRUE;
4227         }
4228 }
4229
4230 static void _outter_scroller_top_hit_cb(void *data, Evas_Object *obj, void *event_info)
4231 {
4232         debug_log("");
4233 }
4234
4235 static void _outter_scroller_scroll_cb(void *data, Evas_Object *obj, void *event_info)
4236 {
4237         debug_log("");
4238         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
4239
4240         ug_data->is_main_scroller_scrolling = EINA_TRUE;
4241 }
4242
4243 static void _mbe_added_cb(void *data, Evas_Object *obj, void *event_info)
4244 {
4245         debug_log("");
4246 }
4247
4248 static void _mbe_selected_cb(void *data, Evas_Object *obj, void *event_info)
4249 {
4250         debug_log("");
4251         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
4252         email_address_info_t *addrs_info = NULL;
4253         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
4254         debug_log("selected item:%s", elm_object_item_text_get(item));
4255
4256         addrs_info = elm_object_item_data_get(item);
4257
4258         Evas_Coord x, y;
4259         EMAIL_CONTACT_LIST_INFO_S *contact_list_item = NULL;
4260         contact_list_item = (EMAIL_CONTACT_LIST_INFO_S *)_contact_search_by_email(ug_data, addrs_info->address);
4261
4262         if (ug_data->con_popup != NULL) {
4263                 evas_object_del(ug_data->con_popup);
4264                 ug_data->con_popup = NULL;
4265         }
4266
4267         ug_data->con_popup = elm_ctxpopup_add(ug_data->navi_bar);
4268         if (ug_data->con_popup == NULL) {
4269                 debug_log("cannot create context popup");
4270                 return;
4271         }
4272
4273         if (contact_list_item) {
4274                 debug_log("Contact Item Exist: index[%d]", contact_list_item->index);
4275                 char index[10] = { 0, };
4276                 snprintf(index, sizeof(index), "%d", contact_list_item->index);
4277
4278                 elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_VIEW_CONTACT"), NULL, _ctxpopup_detail_contact_cb, g_strdup(index));
4279                 elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_SEND_EMAIL"), NULL, _ctxpopup_send_email_cb, addrs_info->address);
4280                 elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_BLOCK"), NULL, _ctxpopup_add_block_rule_cb, addrs_info->address);
4281                 _delete_contacts_list(contact_list_item);
4282         } else {
4283                 elm_ctxpopup_item_append(ug_data->con_popup, dgettext("sys_string", "IDS_COM_OPT_ADD_TO_CONTACTS"), NULL, _ctxpopup_select_contact_mode_email_cb, addrs_info->address);
4284                 elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_SEND_EMAIL"), NULL, _ctxpopup_send_email_cb, addrs_info->address);
4285                 elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_BLOCK"), NULL, _ctxpopup_add_block_rule_cb, addrs_info->address);
4286         }
4287
4288         evas_pointer_canvas_xy_get(ug_data->evas, &x, &y);
4289         evas_object_move(ug_data->con_popup, x, y);
4290         evas_object_show(ug_data->con_popup);
4291 }
4292
4293 static void _destroy_down_progress_cb(void *data, Evas_Object *obj, void *event_info)
4294 {
4295         debug_log("");
4296
4297         if (!_g_ug_data) {
4298                 debug_log("data is NULL");
4299                 return;
4300         }
4301
4302         EmailViewerUGD *ug_data = _g_ug_data;
4303         EmailViewerPrivate *priv = ug_data->email_data;
4304
4305         email_engine_stop_working(ug_data->account_id, priv->email_handle);
4306
4307         if (ug_data->pb_notify) {
4308                 evas_object_del(ug_data->pb_notify);
4309                 ug_data->pb_notify = NULL;
4310         }
4311
4312         if (ug_data->pb_notify_lb) {
4313                 evas_object_del(ug_data->pb_notify_lb);
4314                 ug_data->pb_notify_lb = NULL;
4315         }
4316
4317         if (data == NULL) {
4318                 if (priv->att_file_id) {
4319                         free(priv->att_file_id);
4320                         priv->att_file_id = NULL;
4321                 }
4322
4323                 priv->file_size = 0;
4324                 priv->attachment_id = -1;
4325                 priv->multi_body = FALSE;
4326         }
4327 }
4328
4329 static void _init_viewer_data(int account_id, int mail_id, char *srv_mail_id, EmailViewerUGD *ug_data)
4330 {
4331         debug_log("");
4332         EmailViewerPrivate *priv = NULL;
4333         EmailViewerProp *prop = NULL;
4334         email_address_info_list_t *addrs_info_list = NULL;
4335
4336         /* Create Email Viewer Private Structure */
4337         if (ug_data->email_data) {
4338                 if (ug_data->email_data->mail_info) {
4339                         debug_log("mail_info freed");
4340                         email_free_mail_data(&(ug_data->email_data->mail_info), 1);
4341                         ug_data->email_data->mail_info = NULL;
4342                 }
4343
4344                 if (ug_data->email_data->attachment_info && ug_data->email_data->attachment_count > 0) {
4345                         debug_log("attachment_info freed p[%p] n[%d]", ug_data->email_data->attachment_info, ug_data->email_data->attachment_count);
4346                         email_free_attachment_data(&(ug_data->email_data->attachment_info), ug_data->email_data->attachment_count);
4347                         ug_data->email_data->attachment_info = NULL;
4348                         ug_data->email_data->attachment_count = 0;
4349                 }
4350
4351                 memset(ug_data->email_data, 0x0, sizeof(EmailViewerPrivate));
4352                 priv = ug_data->email_data;
4353         } else {
4354                 priv = (EmailViewerPrivate *)malloc(sizeof(EmailViewerPrivate));
4355                 memset(priv, 0x0, sizeof(EmailViewerPrivate));
4356                 ug_data->email_data = priv;
4357         }
4358
4359         /* Create Email Viewer Property Structure */
4360         if (ug_data->property) {
4361                 if (ug_data->property->attachments) {
4362                         int i = 0;
4363                         LIST_ITER_START(i, ug_data->property->attachments) {
4364                                 EmailAttachmentType *info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, ug_data->property->attachments);
4365                                 if (info->name)
4366                                         free(info->name);
4367                                 if (info->path)
4368                                         free(info->path);
4369                                 free(info);
4370                         }
4371                         g_list_free(ug_data->property->attachments);
4372                 }
4373                 memset(ug_data->property, 0x0, sizeof(EmailViewerProp));
4374                 prop = ug_data->property;
4375         } else {
4376                 prop = (EmailViewerProp *)malloc(sizeof(EmailViewerProp));
4377                 memset(prop, 0x0, sizeof(EmailViewerProp));
4378                 ug_data->property = prop;
4379         }
4380
4381         /* Set account ID */
4382         priv->account_id = account_id;
4383         prop->account_id = account_id;
4384
4385         /* Set mail ID */
4386         priv->mail_id = mail_id;
4387         prop->mail_id = mail_id;
4388
4389         priv->mailbox_id = ug_data->mailbox_id;
4390         prop->src_box = ug_data->mailbox_name;
4391         debug_log("mailbox_name [%s]", ug_data->mailbox_name);
4392
4393         /* Get mail_info from service, and fill property */
4394         if (viewer_get_internal_mail_info(ug_data->property, ug_data->email_data)) {
4395                 viewer_make_internal_mail(ug_data->property, ug_data->email_data);
4396         }
4397
4398         email_get_address_info_list(priv->mail_id, &addrs_info_list);
4399
4400         if (addrs_info_list) {
4401                 ug_data->from_list = addrs_info_list->from;
4402                 ug_data->to_list = addrs_info_list->to;
4403                 ug_data->cc_list = addrs_info_list->cc;
4404                 ug_data->bcc_list = addrs_info_list->bcc;
4405                 priv->addrs_info_list = addrs_info_list;
4406         }
4407
4408         ug_data->option_header_opened = 0;
4409 }
4410
4411 static int _init_webview_data(EmailViewerUGD *ug_data)
4412 {
4413         debug_log("");
4414
4415         EmailViewerWebview *wvd;
4416
4417         if (ug_data->webview_data == NULL) {
4418                 wvd = (EmailViewerWebview *)malloc(sizeof(EmailViewerWebview));
4419                 memset(wvd, 0x0, sizeof(EmailViewerWebview));
4420                 ug_data->webview_data = wvd;
4421         }
4422
4423         if (STR_VALID(ug_data->property->charset)) {
4424                 ug_data->webview_data->charset = g_strdup(ug_data->property->charset);
4425                 debug_log("charset:%s", ug_data->webview_data->charset);
4426         } else {
4427                 ug_data->webview_data->charset = DEFAULT_CHARSET;
4428                 debug_log("charset:%s", ug_data->webview_data->charset);
4429         }
4430
4431         return 0;
4432 }
4433
4434 static Eina_Bool _check_body_download(void *data)
4435 {
4436         debug_log("");
4437         if (!data) {
4438                 debug_log("data is NULL");
4439                 return ECORE_CALLBACK_CANCEL;
4440         }
4441
4442         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
4443
4444         _create_tab_bar(ug_data);
4445
4446         /* check mail body downloaded */
4447         int body_download_status = ug_data->property->body_download;
4448
4449         if (body_download_status == 0) {        //EMAIL_BODY_DOWNLOAD_STATUS_NONE
4450                 debug_log("need body download");
4451                 ug_data->b_noc = 1;     /* Double_Scroller */
4452
4453                 if (ug_data->noc_bx) {
4454                         debug_log("no content layout exist");
4455                         evas_object_show(ug_data->noc_bx);
4456                         elm_object_text_set(ug_data->dn_btn, _("IDS_EMAIL_BODY_DOWNLOAD_MESSAGE"));
4457                         evas_object_show(ug_data->dn_btn);
4458                         elm_box_pack_end(ug_data->main_bx, ug_data->noc_bx);
4459                 } else {
4460                         /* add body download button */
4461                         ug_data->noc_bx = _load_edj(ug_data->navi_bar, EV_THEME_PATH, "layout.email.no_content");
4462                         if (ug_data->noc_bx == NULL) {
4463                                 debug_log("Cannot load edj");
4464                                 return ECORE_CALLBACK_CANCEL;
4465                         }
4466
4467                         evas_object_size_hint_align_set(ug_data->noc_bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
4468                         evas_object_size_hint_weight_set(ug_data->noc_bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
4469                         evas_object_show(ug_data->noc_bx);
4470                         elm_box_pack_end(ug_data->main_bx, ug_data->noc_bx);
4471
4472                         Evas_Object *dn_btn = elm_button_add(ug_data->navi_bar);
4473                         /*elm_object_theme_set(dn_btn, ug_data->theme);*/
4474                         elm_object_style_set(dn_btn, "text_only/style2");
4475                         elm_object_text_set(dn_btn, _("IDS_EMAIL_BODY_DOWNLOAD_MESSAGE"));
4476                         evas_object_smart_callback_add(dn_btn, "clicked", _body_down_cb, (void *)ug_data);
4477                         evas_object_show(dn_btn);
4478                         ug_data->dn_btn = dn_btn;
4479
4480                         elm_object_part_content_set(ug_data->noc_bx, "btn", ug_data->dn_btn);
4481                         debug_log("no content layout created");
4482                 }
4483
4484                 elm_object_focus_set(ug_data->noc_bx, EINA_TRUE);
4485                 if (ug_data->timer) {
4486                         ecore_timer_del(ug_data->timer);
4487                         ug_data->timer = NULL;
4488                 }
4489
4490                 ug_data->timer = ecore_timer_add(0.0, viewer_send_message, ug_data);
4491         } else if (body_download_status == 1) { //EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED
4492                 debug_log("check mail downloaded - ok");
4493                 /* create body */
4494                 _create_body(ug_data);
4495         } else if (body_download_status == 2) { //EMAIL_BODY_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED
4496                 /* partial body */
4497                 debug_log("Partial Body");
4498                 ug_data->b_partial_body = 1;
4499                 _create_body(ug_data);
4500                 _create_partial_body_dn_btn(ug_data);
4501         }
4502
4503         return ECORE_CALLBACK_CANCEL;
4504 }
4505
4506 static int _update_attachment_info(EmailViewerUGD *ug_data, int index)
4507 {
4508         debug_log("");
4509         EmailViewerProp *prop = ug_data->property;
4510         int i = 0;
4511         int j = 0;
4512         int attach_index = 0;
4513
4514         /* update attachment information */
4515         LIST_ITER_START(i, prop->attachments) {
4516                 EmailAttachmentType *info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, prop->attachments);
4517
4518                 if (info && !info->inline_content) {
4519                         debug_log("info->index[%d] index[%d]", info->index, index);
4520
4521                         if (info->index == index) {
4522                                 info->download_yn = TRUE;
4523                                 info->path = email_engine_get_attachment_path(info->attach_id);
4524
4525                                 attach_index = i;
4526
4527                                 if (prop->real_att_len > 1) {
4528                                         Evas_Object *thumbnail = viewer_make_thumbnail(info->path, ug_data->attach_ex_bk[j]);
4529                                         Evas_Object *content = elm_object_part_content_unset(ug_data->attach_ex_bk[j], "elm.icon");
4530                                         evas_object_del(content);
4531                                         elm_object_part_content_set(ug_data->attach_ex_bk[j], "elm.icon", thumbnail);
4532                                         evas_object_show(thumbnail);
4533                                 } else {
4534                                         Evas_Object *thumbnail = viewer_make_thumbnail(info->path, ug_data->attach_hd_bk);
4535                                         Evas_Object *content = elm_object_part_content_unset(ug_data->attach_hd_bk, "elm.icon");
4536                                         evas_object_del(content);
4537                                         elm_object_part_content_set(ug_data->attach_hd_bk, "elm.icon", thumbnail);
4538                                         evas_object_show(thumbnail);
4539                                 }
4540
4541                                 break;
4542                         }
4543
4544                         j++;
4545                 }
4546         }
4547
4548         debug_log("return id[%d]", attach_index);
4549
4550         return attach_index;
4551 }
4552
4553 static int _get_attachment_info_index(EmailViewerUGD *ug_data, int index)
4554 {
4555         debug_log("");
4556
4557         EmailViewerProp *prop = ug_data->property;
4558         int i = 0;
4559         int attach_index = 0;
4560
4561         /* update attachment information */
4562         LIST_ITER_START(i, prop->attachments) {
4563                 EmailAttachmentType *info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, prop->attachments);
4564                 if (info) {
4565                         debug_log("info->index[%d] index[%d]", info->index, index);
4566                         if (info->index == index) {
4567                                 attach_index = i;
4568                                 break;
4569                         }
4570                 }
4571         }
4572
4573         debug_log("return id[%d]", attach_index);
4574
4575         return attach_index;
4576 }
4577
4578 static void _show_select_info(EmailViewerUGD *ug_data, char *str)
4579 {
4580         debug_log("");
4581
4582         if (ug_data->select_info != NULL) {
4583                 evas_object_del(ug_data->select_info);
4584                 ug_data->select_info = NULL;
4585         }
4586
4587         if (ug_data->selectioninfo_layout != NULL) {
4588                 evas_object_del(ug_data->selectioninfo_layout);
4589                 ug_data->selectioninfo_layout = NULL;
4590         }
4591
4592         ug_data->select_info = elm_notify_add(ug_data->win_main);
4593         elm_notify_orient_set(ug_data->select_info, ELM_NOTIFY_ORIENT_BOTTOM);
4594
4595         ug_data->selectioninfo_layout = elm_layout_add(ug_data->layout_main);
4596         elm_object_content_set(ug_data->select_info, ug_data->selectioninfo_layout);
4597
4598         elm_layout_theme_set(ug_data->selectioninfo_layout, "standard", "selectioninfo", "vertical/bottom_64");
4599
4600         edje_object_part_text_set(_EDJ(ug_data->selectioninfo_layout), "elm.text", str);
4601         elm_notify_timeout_set(ug_data->select_info, 3);
4602         evas_object_show(ug_data->select_info);
4603 }
4604
4605 static void _save_attachment(EmailViewerUGD *ug_data, int index)
4606 {
4607         debug_log("");
4608         EmailViewerPrivate *priv = ug_data->email_data;
4609         EmailViewerProp *prop = ug_data->property;
4610         char newpath[MAX_STR_LEN] = { 0, };
4611
4612         RETURN_IF_FAIL(prop->attachments != NULL);
4613         EmailAttachmentType *info = g_list_nth_data(prop->attachments, index);
4614
4615         if (info == NULL) {
4616                 debug_log("EmailAttachmentType *info is NULL");
4617                 return;
4618         }
4619
4620         if (!info->download_yn) {
4621                 unsigned handle = 0;
4622                 gboolean res = FALSE;
4623
4624                 if (ug_data->progress_bar[index + 1] != NULL) {
4625                         debug_log("Already getting downloaded...!");
4626                         _create_notify(ug_data, dgettext("sys_string", "IDS_COM_POP_WARNING"),
4627                                                         _("IDS_EMAIL_POP_ALREADY_DOWNLOADING_T_HEADER"), 1,
4628                                                         dgettext("sys_string", "IDS_COM_SK_OK"),
4629                                                         _popup_response_cb, NULL, NULL, NULL);
4630                         return;
4631                 }
4632
4633                 debug_log("Need attachment download");
4634                 /* download attachment */
4635                 priv->b_att_save = TRUE;
4636
4637                 res = email_engine_attachment_download(priv->account_id, priv->mail_id, info->index, &handle);
4638
4639                 if (res == TRUE) {
4640                         priv->download_all_cnt++;
4641                         debug_log("Assigning Handle[%d] Index[%d] download_all_cnt[%d]", handle, index, priv->download_all_cnt);
4642                         priv->download_all_email_handle[index] = handle;
4643                         _create_down_progress_ex(index, EMAIL_VIEWER_PROGRESSBAR_ATT);
4644                         ug_data->display_download_result = TRUE;
4645                 } else {
4646                         priv->b_att_save = FALSE;
4647                         _create_notify(ug_data, dgettext("sys_string", "IDS_COM_POP_WARNING"),
4648                                                         _("IDS_EMAIL_POP_UNABLE_TO_OPEN_ATTACHMENT"), 1,
4649                                                         dgettext("sys_string", "IDS_COM_SK_OK"), _popup_response_cb,
4650                                                         NULL, NULL, NULL);
4651                 }
4652
4653                 return;
4654         }
4655
4656         if (info && STR_VALID(info->path)) {
4657                 int ret;
4658                 debug_log("path[%s]", info->path);
4659                 ret = email_attachments_save_file(info->path, newpath, NULL);
4660                 if (ret == EMAIL_EXT_SAVE_ERR_NONE) {
4661                         char str[128] = { 0, };
4662                         snprintf(str, sizeof(str), "%s", dgettext("sys_string", "IDS_COM_POP_SAVED"));
4663                         /*_show_select_info(ug_data, str);*/
4664                         ret = status_message_post(str);
4665                         if (ret)
4666                                 debug_log("status_message_post failed: %d", ret);
4667                 }
4668         }
4669 }
4670
4671 static void _show_attachment(EmailViewerUGD *ug_data, int index)
4672 {
4673         debug_log("");
4674         EmailViewerPrivate *priv = ug_data->email_data;
4675         EmailViewerProp *prop = ug_data->property;
4676         EmailAttachmentType *info = g_list_nth_data(prop->attachments, index);
4677         char newpath[MAX_STR_LEN] = { 0, };
4678
4679         if (info == NULL) {
4680                 debug_log("EmailAttachmentType *info is NULL");
4681                 return;
4682         }
4683
4684         debug_log("attach_id:%d, index:%d, name(%s), path(%s), size:%d, download_yn:%d, drm:%d, inline_content:%d",
4685                 info->attach_id, info->index, info->name, info->path, (gint) info->size, info->download_yn, info->drm, info->inline_content);
4686
4687         if (!info->download_yn) {
4688                 unsigned handle = 0;
4689                 gboolean res = FALSE;
4690                 debug_log("Need attachment download");
4691
4692                 priv->b_att_open = TRUE;
4693
4694                 res = email_engine_attachment_download(priv->account_id, priv->mail_id, info->index, &handle);
4695
4696                 if (res == TRUE) {
4697                         priv->download_all_email_handle[index] = handle;
4698                         priv->download_all_cnt++;
4699                         _create_down_progress_ex(index, EMAIL_VIEWER_PROGRESSBAR_ATT);
4700                 } else {
4701                         priv->b_att_open = FALSE;
4702                         _create_notify(ug_data, dgettext("sys_string", "IDS_COM_POP_WARNING"),
4703                                                         _("IDS_EMAIL_POP_UNABLE_TO_OPEN_ATTACHMENT"), 1,
4704                                                         dgettext("sys_string", "IDS_COM_SK_OK"), _popup_response_cb,
4705                                                         NULL, NULL, NULL);
4706                 }
4707                 return;
4708         }
4709
4710                 gboolean res = FALSE;
4711                 res = email_attachments_save_file(info->path, newpath, NULL);
4712                 debug_log("Result:%d, Saved Path:%s", res, newpath);
4713
4714                 if (res == EMAIL_EXT_SAVE_ERR_NONE) {
4715                         char str[128] = { 0, };
4716                         snprintf(str, sizeof(str), "%s", dgettext("sys_string", "IDS_COM_POP_SAVED"));
4717                         /*_show_select_info(ug_data, str);*/
4718                         int ret = status_message_post(str);
4719                         if (ret)
4720                                 debug_log("status_message_post failed: %d", ret);
4721
4722                         if (g_str_has_suffix(info->path, ".vcs")) {
4723                                 int nResult = -1;
4724                                 int calendar_id = 1;
4725                                 calendar_svc_connect();
4726                                 nResult = calendar_svc_calendar_import(newpath, calendar_id);
4727
4728                                 debug_log("check return value of calendar_svc_util_register_vcs_file for %s - %d", newpath, nResult);
4729                                 if (nResult != CAL_SUCCESS) {
4730                                         debug_log("Failed to import path(%s) to id(%d)", newpath, calendar_id);
4731                                         return;
4732                                 }
4733                                 calendar_svc_close();
4734                         } else
4735                                 media_file_register(newpath);
4736                 } else if (res == EMAIL_EXT_SAVE_ERR_ALREADY_EXIST && !ug_data->display_download_result) {
4737                         _create_notify(ug_data, _("IDS_EMAIL_POP_ALERT"),
4738                                                         dgettext("sys_string", "IDS_COM_POP_ALREDY_EXISTS"), 0,
4739                                                         NULL, NULL, NULL, NULL, _popup_response_cb);
4740                 }
4741
4742         debug_log("display_download_result:%d", ug_data->display_download_result);
4743         if (ug_data->display_download_result) {
4744                 if (res == EMAIL_EXT_SAVE_ERR_NONE || res == EMAIL_EXT_SAVE_ERR_ALREADY_EXIST) {
4745                         int ret;
4746                         service_h service = NULL;
4747                         ret = service_create(&service);
4748                         debug_log("service_create: %d", ret);
4749                         if (!service) {
4750                                 debug_log("service create failed");
4751                                 return;
4752                         }
4753                         ret = service_set_operation(service, SERVICE_OPERATION_VIEW);
4754                         debug_log("service_set_operation: %d", ret);
4755                         ret = service_set_uri(service, newpath);
4756                         debug_log("service_set_uri: %d", ret);
4757                         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_VIDEO_PLAYER_LAUNCH_APP, "email");
4758                         debug_log("service_add_extra_data: %d", ret);
4759                         ret = service_send_launch_request(service, NULL, NULL);
4760                         debug_log("service_send_launch_request: %d", ret);
4761                         if (ret != SERVICE_ERROR_NONE) {
4762                                 _create_notify(ug_data, dgettext("sys_string", "IDS_COM_POP_WARNING"),
4763                                                                 _("IDS_EMAIL_POP_THIS_ATTACHMENT_CANNOT_BE_DISPLAYED"), 0,
4764                                                                 NULL, NULL, NULL, NULL, _popup_response_cb);
4765                         }
4766                         ret = service_destroy(service);
4767                         debug_log("service_destroy: %d", ret);
4768                 } else {
4769                         debug_log("EMAIL_EXT_SAVE_ERR_UNKNOWN");
4770                 }
4771         }
4772 }
4773
4774 static void _save_attachment_all(EmailViewerUGD *ug_data)
4775 {
4776         debug_log("");
4777         EmailViewerPrivate *priv = ug_data->email_data;
4778         EmailViewerProp *prop = ug_data->property;
4779         EmailAttachmentType *info = NULL;
4780
4781         int i = 0;
4782         int att_len = g_list_length(prop->attachments);
4783
4784         if (priv->b_all_att_save)
4785                 return;
4786
4787         if (att_len > 0) {
4788                 if (ug_data->forward_ctr_it)
4789                         elm_object_item_disabled_set(ug_data->forward_ctr_it, EINA_TRUE);
4790         }
4791
4792         for (i = 0; i < att_len; i++) {
4793                 info = g_list_nth_data(prop->attachments, i);
4794
4795                 if (info && !info->inline_content) {
4796                         if (!info->download_yn) {
4797                                 if (ug_data->progress_bar_ly[i + 1] == NULL) {
4798                                         unsigned handle = 0;
4799                                         gboolean res = FALSE;
4800                                         debug_log("Need attachment [%d] download", i);
4801
4802                                         res = email_engine_attachment_download(priv->account_id, priv->mail_id, info->index, &handle);
4803
4804                                         if (res == TRUE) {
4805                                                 priv->download_all_cnt++;
4806                                                 priv->download_all_email_handle[i] = handle;
4807                                                 priv->b_all_att_save = TRUE;
4808
4809                                                 debug_log("attach_onoff_flag:%d", ug_data->attach_onoff_flag);
4810                                                 if (priv->b_all_att_save) {
4811                                                         if (ug_data->attach_onoff_flag == 0) {
4812                                                                 _attachment_item_collapse_cb(ug_data->attach_hd_bk, NULL, NULL, NULL);
4813                                                         }
4814                                                 }
4815
4816                                                 _create_down_progress_ex(i, EMAIL_VIEWER_PROGRESSBAR_ATT);
4817                                                 ug_data->display_download_result = TRUE;
4818                                         } else {
4819                                                 priv->download_all_fail_cnt++;
4820                                         }
4821                                 }
4822                         }
4823                 }
4824         }
4825
4826         debug_log("download [%d], failed [%d]", priv->download_all_cnt, priv->download_all_fail_cnt);
4827 }
4828
4829 static void _dbus_receiver_setup(EmailViewerUGD *ug_data)
4830 {
4831         debug_log("");
4832
4833         int ret = e_dbus_init();
4834         debug_log("ret: %d", ret);
4835
4836         DBusError derror;
4837
4838         if (_g_viewer_dbus_conn == NULL) {
4839                 debug_log("");
4840                 dbus_error_init(&derror);
4841                 _g_viewer_dbus_conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
4842
4843                 if (_g_viewer_dbus_conn == NULL) {
4844                         debug_log("e_dbus_bus_get return NULL");
4845                 }
4846
4847                 /* storage */
4848                 if (e_dbus_request_name(_g_viewer_dbus_conn, "User.Email.StorageChange", 0, NULL, NULL) == NULL) {
4849                         debug_critical("Failed to e_dbus_request_name()");
4850                         return;
4851                 }
4852
4853                 if (_g_viewer_signal_handler_storage != NULL) {
4854                         debug_log("_g_viewer_signal_handler_storage != NULL");
4855                 }
4856
4857                 _g_viewer_signal_handler_storage = e_dbus_signal_handler_add(_g_viewer_dbus_conn, NULL,
4858                                                                                                                                         "/User/Email/StorageChange",
4859                                                                                                                                         "User.Email.StorageChange",
4860                                                                                                                                         "email", _on_edbus_event_email_viewer_receive, ug_data);
4861
4862                 if (_g_viewer_signal_handler_storage == NULL) {
4863                         debug_log("Failed to e_dbus_signal_handler_add()");
4864                         return;
4865                 }
4866
4867                 /* network */
4868                 if (e_dbus_request_name(_g_viewer_dbus_conn, "User.Email.NetworkStatus", 0, NULL, NULL) == NULL) {
4869                         debug_log("Failed to e_dbus_request_name()");
4870                         return;
4871                 }
4872
4873                 if (_g_viewer_signal_handler_network != NULL) {
4874                         debug_log("_g_viewer_signal_handler_network != NULL");
4875                 }
4876
4877                 _g_viewer_signal_handler_network = e_dbus_signal_handler_add(_g_viewer_dbus_conn, NULL,
4878                                                                                                                         "/User/Email/NetworkStatus",
4879                                                                                                                         "User.Email.NetworkStatus",
4880                                                                                                                         "email", _on_edbus_event_email_viewer_receive, ug_data);
4881
4882                 if (_g_viewer_signal_handler_network == NULL) {
4883                         debug_log("Failed to e_dbus_signal_handler_add()");
4884                         return;
4885                 }
4886         }
4887 }
4888
4889 static void _dbus_receiver_remove(EmailViewerUGD *ug_data)
4890 {
4891         debug_log("");
4892
4893         if (_g_viewer_signal_handler_storage != NULL) {
4894                 e_dbus_signal_handler_del(_g_viewer_dbus_conn, _g_viewer_signal_handler_storage);
4895                 _g_viewer_signal_handler_storage = NULL;
4896         }
4897
4898         if (_g_viewer_signal_handler_network != NULL) {
4899                 e_dbus_signal_handler_del(_g_viewer_dbus_conn, _g_viewer_signal_handler_network);
4900                 _g_viewer_signal_handler_network = NULL;
4901         }
4902
4903         if (e_dbus_release_name(_g_viewer_dbus_conn, "User.Email.StorageChange", NULL, NULL) == NULL) {
4904                 debug_critical("e_dbus_release_name to failed");
4905         }
4906
4907         if (e_dbus_release_name(_g_viewer_dbus_conn, "User.Email.NetworkStatus", NULL, NULL) == NULL) {
4908                 debug_critical("e_dbus_release_name to failed");
4909         }
4910
4911         if (_g_viewer_dbus_conn != NULL) {
4912                 /*e_dbus_connection_close(_g_viewer_dbus_conn);*/
4913                 _g_viewer_dbus_conn = NULL;
4914         }
4915 }
4916
4917 static void _on_edbus_event_email_viewer_receive(void *data, DBusMessage *message)
4918 {
4919         debug_log("");
4920
4921         if (!_g_ug_data) {
4922                 debug_log("data is NULL");
4923                 return;
4924         }
4925
4926         EmailViewerUGD *ug_data = _g_ug_data;
4927         EmailViewerPrivate *priv = ug_data->email_data;
4928         char fail_msg[MAX_STR_LEN] = { 0, };
4929         DBusError error;
4930
4931         if (dbus_message_is_signal(message, "User.Email.StorageChange", "email")) {
4932                 debug_log("User.Email.StorageChange");
4933
4934                 int subtype = 0;
4935                 int data1 = 0;
4936                 int data2 = 0;
4937                 char *data3 = NULL;
4938
4939                 dbus_error_init(&error);
4940                 if (dbus_message_get_args(message, &error, DBUS_TYPE_INT32, &subtype,
4941                         DBUS_TYPE_INT32, &data1, DBUS_TYPE_INT32, &data2,
4942                         DBUS_TYPE_STRING, &data3, DBUS_TYPE_INVALID)) {
4943                         debug_log("STORE_ENABLE: subtype: %d, data1: %d, data2: %d, data3: %s", subtype, data1, data2, data3);
4944
4945                         switch (subtype) {
4946                         case NOTI_ACCOUNT_ADD:
4947                                 if (get_app_paused()) {
4948                                         debug_log("account added during pause status");
4949
4950                                         if (ug_data->isRotate == false && ug_data->b_internal) {
4951                                                 /* Viewer to hide, so set left content (mailbox) size to full */
4952                                                 _notify_mailbox_size(ug_data, "MAILBOX_RESIZE_FULL");
4953                                         }
4954
4955                                         if (ug_data->b_internal != 1) {
4956                                                 debug_log("ug_destory_me");
4957                                                 ug_destroy_me(ug_data->ug);
4958                                         } else {
4959                                                 _hide_view(ug_data);
4960                                         }
4961                                 }
4962                                 break;
4963
4964                         case NOTI_ACCOUNT_DELETE:
4965                                 if (get_app_paused()) {
4966                                         debug_log("account deleted during pause status");
4967                                         int account_id = 0;
4968
4969                                         if (ug_data->isRotate == false && ug_data->b_internal) {
4970                                                 /* Viewer to hide, so set left content (mailbox) size to full */
4971                                                 _notify_mailbox_size(ug_data, "MAILBOX_RESIZE_FULL");
4972                                         }
4973
4974                                         if (email_engine_get_default_account(&account_id)) {
4975                                                 if (ug_data->b_internal != 1) {
4976                                                         debug_log("ug_destory_me");
4977                                                         ug_destroy_me(ug_data->ug);
4978                                                 } else {
4979                                                         _hide_view(ug_data);
4980                                                 }
4981                                         }
4982                                 }
4983                                 break;
4984
4985                         case NOTI_ACCOUNT_UPDATE:
4986                                 if (get_app_paused()) {
4987                                         debug_log("account updated during pause status");
4988                                 }
4989                                 break;
4990
4991                         default:
4992                                 debug_warning("unknown type");
4993                                 break;
4994                         }
4995                 } else {
4996                         debug_critical("receive data error: %s", error.message);
4997                         dbus_error_free(&error);
4998                 }
4999         } else if (dbus_message_is_signal(message, "User.Email.NetworkStatus", "email")) {
5000                 debug_log("");
5001
5002                 int subtype = 0;
5003                 int data1 = 0;
5004                 char *data2 = NULL;
5005                 int data3 = 0;
5006                 int data4 = 0;
5007
5008                 dbus_error_init(&error);
5009
5010                 if (dbus_message_get_args(message, &error, DBUS_TYPE_INT32, &subtype,
5011                         DBUS_TYPE_INT32, &data1, DBUS_TYPE_STRING, &data2,
5012                         DBUS_TYPE_INT32, &data3, DBUS_TYPE_INT32, &data4, DBUS_TYPE_INVALID)) {
5013                         debug_log("subtype: %d, data1: %d, data2: %s, data3: %d, data4: %d", subtype, data1, data2, data3, data4);
5014                         switch (subtype) {
5015
5016                         case NOTI_DOWNLOAD_BODY_START:
5017                                 /* DATA1[mail_id] DATA2[file_id] DATA3[body_size] DATA4[received size] */
5018                                 debug_log("receive noti, DOWNLOAD_BODY");
5019                                 if (priv->mail_id == data1) {
5020                                         priv->file_id = g_strdup(data2);
5021                                         priv->file_size = data3;
5022
5023                                         if (data4 == 0) {
5024                                                 _set_value_down_progress(0.0);
5025                                         } else {
5026                                                 double per = (double)data4 / (double)data3;
5027                                                 _set_value_down_progress(per);
5028                                         }
5029                                 } else {
5030                                         debug_log("mail_id is different");
5031                                         debug_log("expected mail_id [%d], received mail_id [%d]", priv->mail_id, data1);
5032                                 }
5033                                 break;
5034
5035                         case NOTI_DOWNLOAD_MULTIPART_BODY:
5036                                 /* DATA1[mail_id] DATA2[file_id] DATA3[body_size] DATA4[received size] */
5037                                 debug_log("receive noti, DOWNLOAD_MULTIPART_BODY");
5038                                 if (priv->mail_id == data1) {
5039                                         priv->file_id = g_strdup(data2);
5040                                         priv->file_size = data3;
5041                                         priv->multi_body = TRUE;
5042
5043                                         if (data4 == 0) {
5044                                                 _set_value_down_progress(0.0);
5045                                         } else {
5046                                                 double per = (double)data4 / (double)data3;
5047                                                 _set_value_down_progress(per);
5048                                         }
5049                                 } else {
5050                                         debug_log("mail_id is different");
5051                                         debug_log("expected mail_id [%d], received mail_id [%d]", priv->mail_id, data1);
5052                                 }
5053                                 break;
5054
5055                         case NOTI_DOWNLOAD_BODY_FINISH:
5056                                 /* DATA1[mail_id] DATA2[NULL] DATA3[handle_id] */
5057                                 debug_log("receive noti, DOWNLOAD_BODY_FINISH");
5058                                 if (priv->email_handle == data3 && priv->mail_id == data1) {
5059                                         priv->email_handle = 0;
5060
5061                                         ug_data->b_load_finished = EINA_FALSE;
5062
5063                                         /* delete progress */
5064                                         if (ug_data->pb_notify) {
5065                                                 _set_value_down_progress(1.0);
5066                                                 _destroy_down_progress_cb(NULL, NULL, NULL);
5067                                         }
5068
5069                                         char str[128] = { 0, };
5070                                         snprintf(str, sizeof(str), "%s", dgettext("sys_string", "IDS_COM_BODY_DOWNLOADED"));
5071                                         /*_show_select_info(ug_data, str);*/
5072                                         int ret = status_message_post(str);
5073                                         if (ret)
5074                                                 debug_log("status_message_post failed: %d", ret);
5075
5076                                         /* set property */
5077                                         if (viewer_get_internal_mail_info(ug_data->property, ug_data->email_data)) {
5078                                                 viewer_make_internal_mail(ug_data->property, ug_data->email_data);
5079                                         }
5080                                         /* create att and body */
5081                                         if (ug_data->b_partial_body) {
5082                                                 int scr_x = 0;
5083                                                 int scr_y = 0;
5084                                                 int scr_w = 0;
5085                                                 int scr_h = 0;
5086                                                 elm_scroller_region_get(ug_data->scroller, &scr_x, &scr_y, &scr_w, &scr_h);
5087                                                 debug_log("scroller region> x[%d] y[%d] w[%d] h[%d]", scr_x, scr_y, scr_w, scr_h);
5088
5089                                                 elm_box_unpack(ug_data->main_bx, ug_data->partial_dn_btn_bx);
5090                                                 if (ug_data->partial_dn_btn) {
5091                                                         evas_object_del(ug_data->partial_dn_btn);
5092                                                         ug_data->partial_dn_btn = NULL;
5093                                                 }
5094                                                 if (ug_data->partial_dn_btn_bx) {
5095                                                         evas_object_del(ug_data->partial_dn_btn_bx);
5096                                                         ug_data->partial_dn_btn_bx = NULL;
5097                                                 }
5098
5099                                                 if (ug_data->property->has_html) {
5100                                                         ug_data->webview_data->body_type = BODY_TYPE_HTML;
5101                                                         ug_data->webview_data->uri = ug_data->property->body_uri;
5102                                                 } else {
5103                                                         ug_data->webview_data->body_type = BODY_TYPE_TEXT;
5104                                                         ug_data->webview_data->text_content = ug_data->property->body;
5105                                                 }
5106
5107                                                 viewer_set_webview_content(ug_data, 1);
5108
5109                                                 elm_object_focus_set(ug_data->ly_subject, EINA_TRUE);
5110                                                 elm_scroller_region_show(ug_data->scroller, scr_x, scr_y, scr_w, scr_h);
5111                                         } else {
5112
5113                                                 if (ug_data->property->has_attachment)
5114                                                         ug_data->got_att = 1;
5115                                                 else
5116                                                         ug_data->got_att = 0;
5117
5118                                                 /* pack attachment if it exist */
5119                                                 if (ug_data->got_att) {
5120                                                         _create_attach(ug_data);
5121                                                 }
5122
5123                                                 _create_body(ug_data);
5124                                         }
5125                                 } else {
5126                                         debug_log("email_handle or mail_id is different");
5127                                         debug_log("expected mail_id [%d], received mail_id [%d]", priv->mail_id, data1);
5128                                         debug_log("expected email_handle [%d], received email_handle [%d]", priv->email_handle, data3);
5129                                 }
5130                                 break;
5131
5132                         case NOTI_DOWNLOAD_BODY_FAIL:
5133                                 /* DATA1[mail_id] DATA2[NULL] DATA3[handle_id] */
5134                                 debug_log("receive noti, DOWNLOAD_BODY_FAIL");
5135                                 if (priv->email_handle == data3 && priv->mail_id == data1) {
5136                                         priv->email_handle = 0;
5137
5138                                         /* delete progress */
5139                                         if (ug_data->pb_notify) {
5140                                                 _destroy_down_progress_cb(NULL, NULL, NULL);
5141                                         }
5142
5143                                         char *err_msg = _get_service_fail_type(data4);
5144                                         snprintf(fail_msg, sizeof(fail_msg), "%s<br>%s", _("IDS_EMAIL_POP_UNABLE_TO_DOWNLOAD"), err_msg);
5145                                         _create_notify(ug_data, dgettext("sys_string", "IDS_COM_POP_WARNING"),
5146                                                                         fail_msg, 1, dgettext("sys_string", "IDS_COM_SK_OK"),
5147                                                                         _popup_response_cb, NULL, NULL, NULL);
5148                                         g_free(err_msg);
5149                                 } else {
5150                                         debug_log("email_handle or mail_id is different");
5151                                         debug_log("expected mail_id [%d], received mail_id [%d]", priv->mail_id, data1);
5152                                         debug_log("expected email_handle [%d], received email_handle [%d]", priv->email_handle, data3);
5153                                 }
5154                                 break;
5155
5156                         case NOTI_DOWNLOAD_ATTACH_START:
5157                                 /* DATA1[mail_id] DATA2[file_id] DATA3[attachment_id] DATA4[percentage] */
5158                                 debug_log("receive noti, DOWNLOAD_ATTACHMENT");
5159                                 if (priv->mail_id == data1) {
5160                                         priv->att_file_id = g_strdup(data2);
5161                                         priv->attachment_id = data3;
5162
5163                                         if (data4 == 0) {
5164                                                 /* Set the progressbar of particular attachment_id */
5165                                                 _set_value_down_progress_by_index(0.0, priv->attachment_id);
5166                                         }
5167                                         if (data4 > 0) {
5168                                                 double per = (double)data4 / 100.0;
5169                                                 /* Set the progressbar of particular attachment_id */
5170                                                 _set_value_down_progress_by_index(per, priv->attachment_id);
5171                                         }
5172                                 } else {
5173                                         debug_log("mail_id is different");
5174                                         debug_log("expected mail_id [%d], received mail_id [%d]", priv->mail_id, data1);
5175                                 }
5176                                 break;
5177
5178                         case NOTI_DOWNLOAD_ATTACH_FINISH:
5179                                 /* DATA1[mail_id] DATA2[NULL] DATA3[attachment_id] */
5180                                 debug_log("receive noti, DOWNLOAD_ATTACH_FINISH");
5181
5182                                 if (priv->mail_id == data1) {
5183                                         int attach_index = 0;
5184                                         int attachment_id = (int)data3;
5185                                         debug_log("download_all_cnt [%d]", priv->download_all_cnt);
5186
5187                                         if (priv->download_all_cnt > 0) {
5188                                                 _set_value_down_progress_by_index(1.0, attachment_id);
5189                                                 attach_index = _update_attachment_info(ug_data, attachment_id);
5190                                                 if (priv->b_all_att_save) {
5191                                                         _destroy_down_progress_ex((void *)attach_index, NULL, NULL);
5192                                                         _save_attachment(ug_data, attach_index);
5193                                                         if (priv->download_all_cnt == 0) {
5194                                                                 priv->b_all_att_save = FALSE;
5195                                                         }
5196                                                 } else {
5197                                                         _destroy_down_progress_ex((void *)attach_index, NULL, NULL);
5198                                                         _show_attachment(ug_data, attach_index);
5199                                                 }
5200                                         }
5201                                 } else {
5202                                         debug_log("mail_id or attachment_id is different");
5203                                         debug_log("expected mail_id [%d], received mail_id [%d]", priv->mail_id, data1);
5204                                 }
5205                                 break;
5206
5207                         case NOTI_DOWNLOAD_ATTACH_FAIL:
5208                                 /* DATA1[mail_id] DATA2[NULL] DATA3[attachment_id] */
5209                                 debug_log("receive noti, DOWNLOAD_ATTACH_FAIL");
5210                                 if (priv->mail_id == data1) {
5211                                         int attach_index = _get_attachment_info_index(ug_data, data3);
5212                                         debug_log("download_all_cnt[%d]", priv->download_all_cnt);
5213
5214                                         if (priv->download_all_cnt > 0) {
5215                                                 if (ug_data->progress_bar[data3] != NULL && data4 != EMAIL_ERROR_CANCELLED)
5216                                                         _destroy_down_progress_ex((void *)attach_index, NULL, NULL);
5217                                                 else
5218                                                         debug_log("Download already cancelled, No need to destroy again..!");
5219
5220                                                 if (data4 != EMAIL_ERROR_CANCELLED && ug_data->ug_composer == NULL) {
5221                                                         char *err_msg = _get_service_fail_type(data4);
5222                                                         snprintf(fail_msg, sizeof(fail_msg), "%s<br>%s", _("IDS_EMAIL_POP_UNABLE_TO_DOWNLOAD"), err_msg);
5223                                                         _create_notify(ug_data, dgettext("sys_string", "IDS_COM_POP_WARNING"), fail_msg, 1,
5224                                                                                         dgettext("sys_string", "IDS_COM_SK_OK"),
5225                                                                                         _popup_response_cb, NULL, NULL, NULL);
5226                                                         g_free(err_msg);
5227                                                 }
5228
5229                                                 if (priv->b_all_att_save && priv->download_all_cnt == 0) {
5230                                                         priv->b_all_att_save = FALSE;
5231                                                 }
5232                                         }
5233                                 } else {
5234                                         debug_log("mail_id is different");
5235                                         debug_log("expected mail_id [%d], received mail_id [%d]", priv->mail_id, data1);
5236                                 }
5237                                 break;
5238
5239                         default:
5240                                 debug_log("unknown type");
5241                                 break;
5242                         }
5243                 } else {
5244                         debug_log("receive data error: %s", error.message);
5245                         dbus_error_free(&error);
5246                 }
5247                 /*return DBUS_HANDLER_RESULT_HANDLED;*/
5248                 return;
5249         }
5250         /*return DBUS_HANDLER_RESULT_HANDLED;*/
5251         return;
5252 }
5253
5254 static void _delete_contacts_list(EMAIL_CONTACT_LIST_INFO_S *contacts_list_item)
5255 {
5256         debug_log("");
5257
5258         if (contacts_list_item) {
5259 #ifndef _NEW_CT_SVC_API
5260                 g_free(contacts_list_item->first_name);
5261                 contacts_list_item->first_name = NULL;
5262                 g_free(contacts_list_item->last_name);
5263                 contacts_list_item->last_name = NULL;
5264 #else
5265                 g_free(contacts_list_item->display);
5266                 contacts_list_item->display = NULL;
5267 #endif
5268                 g_free(contacts_list_item->email_address);
5269                 contacts_list_item->email_address = NULL;
5270                 g_free(contacts_list_item);
5271                 contacts_list_item = NULL;
5272         }
5273 }
5274
5275 static void *_contact_search_by_email(EmailViewerUGD *ug_data, const char *search_word)
5276 {
5277         debug_log("");
5278         if (!ug_data || !_g_ug_data) {
5279                 debug_log("data is NULL");
5280                 return NULL;
5281         }
5282
5283         int ret = CTS_SUCCESS;
5284         CTSiter *iter = NULL;
5285
5286         EMAIL_CONTACT_LIST_INFO_S *contacts_list_item = NULL;
5287         contacts_svc_connect();
5288
5289         debug_log("search_word = %s", search_word);
5290
5291         if (contacts_svc_get_list_with_str(CTS_LIST_EMAILINFOS_WITH_EMAIL, search_word, &iter) != CTS_SUCCESS) {
5292                 return NULL;
5293         }
5294
5295         ret = contacts_svc_iter_next(iter);
5296
5297         if (CTS_SUCCESS == ret) {
5298                 CTSvalue *row_info = NULL;
5299
5300                 row_info = contacts_svc_iter_get_info(iter);
5301                 if (row_info) {
5302                         contacts_list_item = (EMAIL_CONTACT_LIST_INFO_S *)calloc(1, sizeof(EMAIL_CONTACT_LIST_INFO_S));
5303
5304                         int index = contacts_svc_value_get_int(row_info, CTS_LIST_EMAIL_CONTACT_ID_INT);
5305
5306                         contacts_list_item->index = index;
5307 #ifndef _NEW_CT_SVC_API
5308                         contacts_list_item->first_name = g_strdup(contacts_svc_value_get_str(row_info, CTS_LIST_EMAIL_CONTACT_FIRST_STR));
5309                         contacts_list_item->last_name = g_strdup(contacts_svc_value_get_str(row_info, CTS_LIST_EMAIL_CONTACT_LAST_STR));
5310 #else
5311                         contacts_list_item->display = g_strdup(contacts_svc_value_get_str(row_info, CTS_LIST_EMAIL_CONTACT_DISPLAY_STR));
5312 #endif
5313                         contacts_list_item->email_address = g_strdup(contacts_svc_value_get_str(row_info, CTS_LIST_EMAIL_ADDR_STR));
5314
5315 #ifndef _NEW_CT_SVC_API
5316                         char *first = contacts_list_item->first_name;
5317                         char *last = contacts_list_item->last_name;
5318                         char *display = g_strdup(contacts_svc_value_get_str(row_info, CTS_LIST_EMAIL_CONTACT_DISPLAY_STR));
5319
5320                         if (!display) {
5321                                 if (first != NULL && last != NULL) {
5322                                         if (CTS_ORDER_NAME_FIRSTLAST == contacts_svc_get_order(CTS_ORDER_OF_DISPLAY)) {
5323                                                 display = g_strconcat(first, " ", last, NULL);
5324                                         } else {
5325                                                 display = g_strconcat(last, " ", first, NULL);
5326                                         }
5327                                 } else if (first != NULL || last != NULL) {
5328                                         display = (first != NULL) ? g_strdup(first) : g_strdup(last);
5329                                 } else {
5330                                         display = g_strdup(" ");
5331                                 }
5332                         }
5333
5334                         snprintf(contacts_list_item->display_name, sizeof(contacts_list_item->display_name), "%s", display);
5335                         g_free(display);
5336 #else
5337                         snprintf(contacts_list_item->display_name, sizeof(contacts_list_item->display_name), "%s", contacts_list_item->display);
5338 #endif
5339
5340                 }
5341
5342                 contacts_svc_value_free(row_info);
5343                 row_info = NULL;
5344
5345                 contacts_svc_iter_remove(iter);
5346         }
5347
5348         contacts_svc_disconnect();
5349
5350         return contacts_list_item;
5351 }
5352
5353 static void _set_value_down_progress(double val)
5354 {
5355         debug_log("");
5356
5357         if (!_g_ug_data) {
5358                 debug_log("data is NULL");
5359                 return;
5360         }
5361         char buf[30] = { 0, };
5362         EmailViewerUGD *ug_data = _g_ug_data;
5363
5364         sprintf(buf, "%s: %d", dgettext("sys_string", "IDS_COM_POP_DOWNLOADING"), (int)val);
5365
5366         if (ug_data->pb_notify_lb) {
5367                 elm_progressbar_value_set(ug_data->pb_notify_lb, val);
5368                 elm_object_text_set(ug_data->pb_notify_lb, buf);
5369         }
5370 }
5371
5372 static void _set_value_down_progress_by_index(double val, int index)
5373 {
5374         debug_log("");
5375
5376         if (!_g_ug_data) {
5377                 debug_log("data is NULL");
5378                 return;
5379         }
5380
5381         EmailViewerUGD *ug_data = _g_ug_data;
5382         EmailViewerProp *prop = ug_data->property;
5383
5384         if (val < 0.0) {
5385                 debug_log("val(%f) is MINUS");
5386                 return;
5387         }
5388
5389         if (index < 0 || index >= ATTACH_MAX) {
5390                 debug_log("index(%d) is overflowed");
5391                 return;
5392         }
5393
5394         if (prop == NULL) {
5395                 debug_log("prop is NULL");
5396                 return;
5397         }
5398
5399         if (prop->attachments == NULL) {
5400                 debug_log("attachments is NULL");
5401                 return;
5402         }
5403
5404         int per = val * 100;
5405         int attach_index = _get_attachment_info_index(ug_data, index);
5406         EmailAttachmentType *info = g_list_nth_data(prop->attachments, attach_index);
5407
5408         if (info == NULL) {
5409                 debug_log("info is NULL");
5410         }
5411
5412         if (ug_data->progress_bar[index] == NULL) {
5413                 debug_log("obj is NULL");
5414                 return;
5415         }
5416
5417         char *pszTemp = NULL;
5418         pszTemp = (char *)elm_object_style_get(ug_data->progress_bar[index]);
5419
5420         if (STR_INVALID(pszTemp))
5421                 return;
5422
5423         if (g_strcmp0(pszTemp, "pending_list") == 0) {
5424                 debug_log("pending_list so return");
5425                 return;
5426         }
5427
5428         elm_progressbar_value_set(ug_data->progress_bar[index], val);
5429
5430         if (ug_data->progress_bar_ly[index] != NULL) {
5431                 char buf[30] = { 0, };
5432                 snprintf(buf, sizeof(buf), "%d%%", per);
5433
5434                 Evas_Object *downloading_label2;
5435                 downloading_label2 = elm_label_add(ug_data->progress_bar_ly[index]);
5436                 elm_object_part_content_set(ug_data->progress_bar_ly[index], "elm.text.2", downloading_label2);
5437                 char *buf_tagged = g_strconcat("<font_size=26><align=left><color=#646464FF>", buf, "</align></font_size>", NULL);
5438                 elm_object_text_set(downloading_label2, buf_tagged);
5439                 g_free(buf_tagged);
5440         }
5441 }
5442
5443 static void _cancel_download_attachment(EmailViewerUGD *ug_data)
5444 {
5445         debug_log("");
5446         int i = 0;
5447         gboolean is_cancel = FALSE;
5448
5449         if (!_g_ug_data) {
5450                 debug_log("data is NULL");
5451                 return;
5452         }
5453
5454         EmailViewerPrivate *priv = ug_data->email_data;
5455         EmailViewerProp *prop = ug_data->property;
5456
5457         if (priv && priv->download_all_cnt <= 0) {
5458                 debug_log("No attachment download to be cancelled!");
5459                 return;
5460         }
5461
5462         for (i = 0; i <= prop->att_len; i++) {
5463                 if (ug_data->progress_bar_ly[i]) {
5464                         Evas_Object *btn = elm_object_part_content_get(ug_data->progress_bar_ly[i], "elm.icon.1");
5465                         debug_log("Cancel btn for downloading attachment: %p", btn);
5466                         if (btn) {
5467                                 evas_object_smart_callback_call(btn, "clicked", NULL);
5468                                 is_cancel = TRUE;
5469                         }
5470                 }
5471         }
5472
5473         if (is_cancel == TRUE && ug_data->ug_composer == NULL) {
5474                 _create_notify(ug_data, dgettext("sys_string", "IDS_COM_POP_WARNING"), _("IDS_EMAIL_POP_CANCELLING_ATTACHMENT_DOWNLOAD_ING"),
5475                                                 1, dgettext("sys_string", "IDS_COM_SK_OK"), _popup_response_cb,
5476                                                 NULL, NULL, NULL);
5477         }
5478 }
5479
5480 static char *_get_service_fail_type(int type)
5481 {
5482         debug_log("");
5483
5484         char *ret = NULL;
5485         char str[MAX_STR_LEN] = { 0, };
5486
5487         if (type == -174) {
5488                 snprintf(str, sizeof(str), "%s: %s", _("IDS_EMAIL_POP_FAILED_TO_ACTIVATE_PDP"), N_("IP full"));
5489                 return g_strdup(str);
5490         } else if (type == -176) {
5491                 ret = _("IDS_EMAIL_POP_NO_SERVICE");
5492                 return g_strdup(ret);
5493         } else if (type == -181) {
5494                 snprintf(str, sizeof(str), "%s: %s", _("IDS_EMAIL_POP_FAILED_TO_ACTIVATE_PDP"), N_("Transport Error"));
5495                 return g_strdup(str);
5496         } else if (type == EMAIL_ERROR_NETWORK_TOO_BUSY) {
5497                 ret = _("IDS_EMAIL_POP_NETWORK_BUSY");
5498                 return g_strdup(ret);
5499         } else if (type == EMAIL_ERROR_LOGIN_ALLOWED_EVERY_15_MINS) {
5500                 snprintf(str, sizeof(str), _("IDS_EMAIL_POP_YOU_CAN_ONLY_LOG_IN_ONCE_EVERY_PD_MINUTES"), 15);
5501                 return g_strdup(str);
5502         } else if (type == EMAIL_ERROR_CONNECTION_FAILURE) {
5503                 ret = dgettext("sys_string", "IDS_COM_POP_CONNECTION_FAILED");
5504                 return g_strdup(ret);
5505         } else if (type == EMAIL_ERROR_LOGIN_FAILURE) {
5506                 ret = _("IDS_EMAIL_POP_LOG_IN_FAILED");
5507                 return g_strdup(ret);
5508         } else if (type == EMAIL_ERROR_AUTHENTICATE) {
5509                 ret = _("IDS_EMAIL_POP_AUTHENTICATION_FAILED");
5510                 return g_strdup(ret);
5511         } else if (type == EMAIL_ERROR_CANCELLED) {
5512                 ret = _("IDS_EMAIL_POP_DOWNLOAD_CANCELLED");
5513                 return g_strdup(ret);
5514         } else if (type == EMAIL_ERROR_MAIL_NOT_FOUND_ON_SERVER) {
5515                 ret = _("IDS_EMAIL_POP_EMAIL_DELETED_FROM_SERVER");
5516                 return g_strdup(ret);
5517         } else if (type == EMAIL_ERROR_NO_SUCH_HOST) {
5518                 ret = _("IDS_EMAIL_POP_HOST_NOT_FOUND");
5519                 return g_strdup(ret);
5520         } else if (type == EMAIL_ERROR_INVALID_SERVER) {
5521                 ret = _("IDS_EMAIL_POP_SERVER_NOT_AVAILABLE");
5522                 return g_strdup(ret);
5523         } else if (type == EMAIL_ERROR_MAIL_MEMORY_FULL) {
5524                 ret = _("IDS_EMAIL_POP_DEVICE_STORAGE_FULL");
5525                 return g_strdup(ret);
5526         } else if (type == EMAIL_ERROR_FAILED_BY_SECURITY_POLICY) {
5527                 ret = _("IDS_EMAIL_POP_DOWNLOADING_ATTACHMENTS_ON_THE_MOBILE_DEVICE_IS_NOT_ALLOWED_BY_EXCHANGE_SERVER_POLICY");
5528                 return g_strdup(ret);
5529         } else {
5530                 snprintf(str, sizeof(str), "%s (%d)", dgettext("sys_string", "IDS_COM_POP_INTERNAL_ERROR"), type);
5531                 return g_strdup(str);
5532         }
5533 }
5534
5535 static Evas_Object *_load_edj(Evas_Object *parent, const char *file, const char *group)
5536 {
5537         debug_log("");
5538         Evas_Object *eo;
5539         int r;
5540
5541         eo = elm_layout_add(parent);
5542         if (eo) {
5543                 r = elm_layout_file_set(eo, file, group);
5544                 if (!r) {
5545                         evas_object_del(eo);
5546                         return NULL;
5547                 }
5548
5549                 evas_object_size_hint_weight_set(eo, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
5550         }
5551
5552         return eo;
5553 }
5554
5555 /* genlist cb */
5556 static Eina_Bool _gl_state_get(void *data, Evas_Object *obj, const char *part)
5557 {
5558         debug_log("");
5559         return EINA_FALSE;
5560 }
5561
5562 static void _gl_del(void *data, Evas_Object *obj)
5563 {
5564         debug_log("");
5565
5566         if (_g_ug_data == NULL) {
5567                 debug_log("ug_data is NULL");
5568                 return;
5569         }
5570
5571         EmailViewerUGD *ug_data = _g_ug_data;
5572
5573         if (ug_data->move_mailbox_list) {
5574                 email_free_mailbox(&ug_data->move_mailbox_list, ug_data->move_mailbox_count);
5575                 ug_data->move_mailbox_list = NULL;
5576                 ug_data->move_mailbox_count = 0;
5577         }
5578
5579         return;
5580 }
5581
5582 static char *_gl_text_get(void *data, Evas_Object *obj, const char *part)
5583 {
5584         debug_log("");
5585         email_mailbox_t *mailbox_list = NULL;
5586         mailbox_list = (email_mailbox_t *) data;
5587
5588         if (g_strcmp0(part, "elm.text") == 0) {
5589                 char buf[MAX_STR_LEN] = { 0, };
5590                 if (mailbox_list && mailbox_list->alias) {
5591                         snprintf(buf, sizeof(buf), "%s", mailbox_list->alias);
5592                         return g_strdup(buf);
5593                 }
5594         }
5595
5596         return NULL;
5597 }
5598
5599 static Evas_Object *_gl_content_get(void *data, Evas_Object *obj, const char *part)
5600 {
5601         debug_log("");
5602
5603         if (g_strcmp0(part, "elm.icon") == 0) {
5604                 Evas_Object *icon = elm_icon_add(obj);
5605                 elm_icon_file_set(icon, IMGDIR "/U01_icon_folder.png", NULL);
5606                 evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
5607
5608                 return icon;
5609         }
5610
5611         return NULL;
5612 }
5613
5614 static void _gl_sel(void *data, Evas_Object *obj, void *event_info)
5615 {
5616         debug_log("");
5617
5618         EmailViewerUGD *ug_data = _g_ug_data;
5619         email_mailbox_t *mailbox_list = NULL;
5620         mailbox_list = (email_mailbox_t *) data;
5621         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
5622         elm_genlist_item_selected_set(item, EINA_FALSE);
5623
5624         Elm_Object_Item *git = NULL;
5625         Evas_Object *gl = elm_genlist_add(ug_data->navi_bar);
5626         evas_object_show(gl);
5627
5628         git = elm_genlist_item_append(gl, &(ug_data->itc3), NULL, NULL, ELM_GENLIST_ITEM_GROUP, NULL, NULL);
5629         elm_genlist_item_select_mode_set(git, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
5630         elm_genlist_item_append(gl, &ug_data->itc2, NULL, git, ELM_GENLIST_ITEM_NONE, _gl_sub_upper_sel, NULL);
5631
5632         Evas_Object *cbar = elm_toolbar_add(ug_data->navi_bar);
5633         elm_toolbar_shrink_mode_set(cbar, ELM_TOOLBAR_SHRINK_EXPAND);
5634         elm_object_style_set(cbar, "naviframe");
5635         evas_object_show(cbar);
5636
5637         elm_toolbar_item_append(cbar, NULL, _("IDS_EMAIL_SK3_MOVE_HERE"), _move_here_cb, mailbox_list);
5638         elm_object_item_disabled_set(elm_toolbar_item_append(cbar, NULL, "", NULL, NULL), EINA_TRUE);
5639
5640         Elm_Object_Item *navi_it = NULL;
5641         navi_it = elm_naviframe_item_push(ug_data->navi_bar, dgettext("sys_string", "IDS_COM_BODY_MOVE"), NULL, NULL, gl, NULL);
5642         elm_object_item_part_content_set(navi_it, "controlbar", cbar);
5643         ug_data->navi_move_it2 = navi_it;
5644
5645         Evas_Object *move_back_btn = NULL;
5646         if (ug_data->isRotate) {
5647                 elm_naviframe_item_title_visible_set(navi_it, EINA_FALSE);
5648                 move_back_btn = elm_object_item_part_content_get(navi_it, "prev_btn");
5649                 if (move_back_btn) {
5650                         evas_object_del(move_back_btn);
5651                         elm_object_item_part_content_set(navi_it, "prev_btn", NULL);
5652                 }
5653         } else {
5654                 move_back_btn = elm_object_item_part_content_get(navi_it, "prev_btn");
5655                 if (move_back_btn) {
5656                         evas_object_del(move_back_btn);
5657                         move_back_btn = elm_button_add(ug_data->navi_bar);
5658                         elm_object_style_set(move_back_btn, "naviframe/back_btn/default");
5659                         evas_object_smart_callback_add(move_back_btn, "clicked", _move_back_cb2, ug_data);
5660                         elm_object_item_part_content_set(navi_it, "prev_btn", move_back_btn);
5661                 }
5662         }
5663         return;
5664 }
5665
5666 static char *_gl_sub_upper_text_get(void *data, Evas_Object *obj, const char *part)
5667 {
5668         debug_log("");
5669         email_mailbox_t *mailbox_list = NULL;
5670         mailbox_list = (email_mailbox_t *) data;
5671
5672         if (g_strcmp0(part, "elm.text") == 0) {
5673                 char buf[MAX_STR_LEN] = { 0, };
5674                 snprintf(buf, sizeof(buf), "%s", _("IDS_EMAIL_MBODY_MAILBOX_LIST"));
5675                 return g_strdup(buf);
5676         }
5677
5678         return NULL;
5679 }
5680
5681 static Evas_Object *_gl_sub_upper_icon_get(void *data, Evas_Object *obj, const char *part)
5682 {
5683         debug_log("");
5684
5685         if (g_strcmp0(part, "elm.icon") == 0) {
5686                 Evas_Object *icon = elm_icon_add(obj);
5687                 elm_icon_file_set(icon, IMGDIR "/U01_icon_upper_folder_focus.png", NULL);
5688                 evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
5689
5690                 return icon;
5691         }
5692
5693         return NULL;
5694 }
5695
5696 static void _gl_sub_upper_sel(void *data, Evas_Object *obj, void *event_info)
5697 {
5698         debug_log("");
5699
5700         EmailViewerUGD *ug_data = _g_ug_data;
5701
5702         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
5703         elm_genlist_item_selected_set(item, EINA_FALSE);
5704
5705         ug_data->navi_move_it2 = NULL;
5706         elm_naviframe_item_pop(ug_data->navi_bar);
5707
5708         return;
5709 }
5710
5711 static void _move_here_cb(void *data, Evas_Object *obj, void *event_info)
5712 {
5713         debug_log("");
5714
5715         if (data == NULL || _g_ug_data == NULL) {
5716                 debug_log("data is NULL");
5717                 return;
5718         }
5719
5720         email_mailbox_t *mailbox_list = NULL;
5721         mailbox_list = (email_mailbox_t *) data;
5722
5723         EmailViewerUGD *ug_data = _g_ug_data;
5724         int folder_id = mailbox_list->mailbox_id;
5725
5726         _move_email(ug_data, folder_id, FALSE);
5727
5728         ug_data->navi_move_it1 = NULL;
5729         ug_data->navi_move_it2 = NULL;
5730         elm_naviframe_item_pop_to(ug_data->navi_main_it);
5731
5732         if (ug_data->isRotate == false && ug_data->b_internal) {
5733                 /* Viewer to hide, so set left content (mailbox) size to full */
5734                 _notify_mailbox_size(ug_data, "MAILBOX_RESIZE_FULL");
5735         }
5736
5737         if (ug_data->b_internal) {
5738                 _hide_view(ug_data);
5739
5740                 /* send next or previous mail request to mailbox. */
5741                 int ret;
5742                 service_h service = NULL;
5743
5744                 ret = service_create(&service);
5745                 debug_log("service_create: %d", ret);
5746                 if (!service) {
5747                         debug_log("service create failed");
5748                         return;
5749                 }
5750
5751                 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_MSG, EMAIL_BUNDLE_VAL_NEXT_MSG);
5752                 debug_log("service_add_extra_data: %d", ret);
5753                 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_DO_DELETE, "1");
5754                 debug_log("service_add_extra_data: %d", ret);
5755
5756                 ug_send_message(_g_mailbox_ug, service);
5757
5758                 ret = service_destroy(service);
5759                 debug_log("service_destroy: %d", ret);
5760         } else {
5761                 ug_destroy_me(ug_data->ug);
5762         }
5763 }
5764
5765 static void _move_back_cb(void *data, Evas_Object *obj, void *event_info)
5766 {
5767         debug_log("");
5768
5769         if (data == NULL || _g_ug_data == NULL) {
5770                 debug_log("data is NULL");
5771                 return;
5772         }
5773
5774         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
5775
5776         elm_naviframe_item_pop(ug_data->navi_bar);
5777         ug_data->navi_move_it1 = NULL;
5778         ug_data->navi_move_it2 = NULL;
5779
5780         /*if (ug_data->b_internal)
5781                 elm_layout_theme_set(ug_data->layout_main, "layout", "controlbar", "default");
5782         else
5783                 elm_layout_theme_set(ug_data->layout_main, "layout", "application", "controlbar");*/
5784 }
5785
5786 static void _move_back_cb2(void *data, Evas_Object *obj, void *event_info)
5787 {
5788         debug_log("");
5789
5790         if (data == NULL || _g_ug_data == NULL) {
5791                 debug_log("data is NULL");
5792                 return;
5793         }
5794
5795         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
5796
5797         elm_naviframe_item_pop(ug_data->navi_bar);
5798         ug_data->navi_move_it2 = NULL;
5799 }
5800
5801 /* EOF */