7611aad2932cfe9c414855f6bf56d4ba14c9f476
[apps/core/preloaded/email.git] / composer / src / email-composer-callback.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 #include <string.h>
18 #include <status.h>
19
20 #include "email-composer.h"
21 #include "email-composer-util.h"
22 #include "email-composer-recipient.h"
23 #include "email-composer-attachment.h"
24 #include "email-composer-callback.h"
25 #include "email-composer-predictive-search.h"
26 #include "email-composer-js.h"
27 #include "email-composer-contents.h"
28
29 #define ACCOUNT_ICON_OTHERS IMGDIR"/icon_email.png"
30
31 static EmailComposerUGD *g_ugd = NULL;
32
33 bool edit_mode = false;
34 bool edit_mode_bs = false;
35
36 int email_cnt = 0;
37
38 EmailList email_list[MAX_RECIPIENT_COUNT];
39
40 static Elm_Genlist_Item_Class itc;
41 static Elm_Genlist_Item_Class from_itc;
42 static Elm_Genlist_Item_Class myemail_itc;
43 static Elm_Genlist_Item_Class priority_itc;
44 static Elm_Genlist_Item_Class tracking_itc;
45
46 static void _composer_mbe_popup_change_addr_selected_cb(void *data, Evas_Object *obj, void *event_info);
47 static void _composer_from_change_response_cb(void *data, Evas_Object *obj, void *event_info);
48 static void _composer_from_close_response_cb(EmailComposerUGD *ugd);
49 static void _composer_from_radio_cb(void *data, Evas_Object *obj, void *event_info);
50 static void _composer_from_gl_sel(void *data, Evas_Object *obj, void *event_info);
51
52 static void _composer_myemail_change_response_cb(void *data, Evas_Object *obj, void *event_info);
53 static void _composer_myemail_close_response_cb(EmailComposerUGD *ugd);
54 static void _composer_myemail_radio_cb(void *data, Evas_Object *obj, void *event_info);
55 static void _composer_myemail_gl_sel(void *data, Evas_Object *obj, void *event_info);
56
57 static Eina_Bool _composer_cc_mbe_set_focus(void *data);
58 Eina_Bool _composer_get_html_content_for_draft_cb(void *data);
59 static void _composer_plain_text_get_cb(Evas_Object *o, const char *plain_text, void *user_data);
60 static void _composer_get_latest_info_content_cb(Evas_Object *o, const char *result, void *data);
61 static void _composer_get_latest_html_content_cb(Evas_Object *o, const char *result, void *data);
62
63 void _composer_edit_field_changed_cb(void *data, Evas_Object *obj, void *event_info)
64 {
65         debug_log("");
66
67         if (data == NULL || obj == NULL) {
68                 return;
69         }
70
71         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
72
73         if (obj == ugd->subject_entry) {
74                 _composer_check_entry_max(ugd, ugd->subject_entry, MAX_SUBJECT_LEN);
75
76                 if (_composer_check_recipient_is_empty(ugd)) {
77                         if (!ugd->bSendBtnDisabled) {
78                                 elm_object_disabled_set(ugd->send_btn, EINA_TRUE);
79                                 elm_object_disabled_set(ugd->send_btm_btn, EINA_TRUE);
80                                 ugd->bSendBtnDisabled = true;
81                         }
82                 } else {
83                         if (ugd->bSendBtnDisabled) {
84                                 elm_object_disabled_set(ugd->send_btn, EINA_FALSE);
85                                 elm_object_disabled_set(ugd->send_btm_btn, EINA_FALSE);
86                                 ugd->bSendBtnDisabled = false;
87                         }
88                 }
89         } else if (obj == ugd->body_ewkview) {
90                 if (_composer_check_recipient_is_empty(ugd)) {
91                         if (!ugd->bSendBtnDisabled) {
92                                 elm_object_disabled_set(ugd->send_btn, EINA_TRUE);
93                                 elm_object_disabled_set(ugd->send_btm_btn, EINA_TRUE);
94                                 ugd->bSendBtnDisabled = true;
95                         }
96                 } else {
97                         if (ugd->bSendBtnDisabled) {
98                                 elm_object_disabled_set(ugd->send_btn, EINA_FALSE);
99                                 elm_object_disabled_set(ugd->send_btm_btn, EINA_FALSE);
100                                 ugd->bSendBtnDisabled = false;
101                         }
102                 }
103         }
104 }
105
106 static void _composer_move_ctxpopup_more(EmailComposerUGD *ugd, Evas_Object *btn)
107 {
108         Evas_Coord x, y, w , h;
109         evas_object_geometry_get(btn, &x, &y, &w, &h);
110         debug_log("is_ime_hided:%d, x(%d), y(%d), w(%d), h(%d)", ugd->is_ime_hided, x, y, w, h);
111         if (ugd->is_ime_hided == FALSE)
112                 evas_object_move(ugd->context_popup, x + (w / 2), y + h);
113         else
114                 evas_object_move(ugd->context_popup, x + (w / 2), y);
115 }
116
117 static void _composer_ctxpopup_dismissed_cb(void *data, Evas_Object *obj, void *event_info)
118 {
119         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
120
121         ugd->focus_status = COMPOSER_FOCUS_STATUS_NONE;
122
123         evas_object_del(ugd->context_popup);
124         ugd->context_popup = NULL;
125 }
126
127 void _composer_more_toolbar_button_cb(void *data, Evas_Object *obj, void *event_info)
128 {
129         debug_enter();
130
131         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
132
133         Evas_Object* icon = NULL;
134
135         if(ugd->context_popup) {
136                 evas_object_del(ugd->context_popup);
137                 ugd->context_popup = NULL;
138         }
139
140         ugd->context_popup = elm_ctxpopup_add(ugd->main_layout);
141         elm_ctxpopup_direction_priority_set(ugd->context_popup, ELM_CTXPOPUP_DIRECTION_DOWN,
142                                                  ELM_CTXPOPUP_DIRECTION_UNKNOWN,
143                                                  ELM_CTXPOPUP_DIRECTION_UNKNOWN,
144                                                  ELM_CTXPOPUP_DIRECTION_UNKNOWN);
145         elm_object_style_set(ugd->context_popup, "more_button");
146         evas_object_smart_callback_add(ugd->context_popup, "dismissed", _composer_ctxpopup_dismissed_cb, ugd);
147
148         elm_object_focus_set(ugd->context_popup, EINA_TRUE);
149         ugd->focus_status = COMPOSER_FOCUS_STATUS_SELECTED; // more button is clicked!!
150
151         icon = elm_icon_add(ugd->context_popup);
152         elm_image_file_set(icon, IMGDIR "/M02_icon_popup_send_email.png", NULL);
153         elm_ctxpopup_item_append(ugd->context_popup, _("IDS_EMAIL_OPT_SEND_EMAIL_TO_MYSELF_ABB"), icon, _composer_cbar_send_myself_clicked, ugd);
154         icon = NULL;
155
156         icon = elm_icon_add(ugd->context_popup);
157         elm_image_file_set(icon, IMGDIR "/M02_icon_popup_add cc.png", NULL);
158         if (ugd->cc_added) {
159                 elm_ctxpopup_item_append(ugd->context_popup, N_("Remove Cc/Bcc"), icon, _composer_cbar_cc_clicked, ugd);
160         } else {
161                 elm_ctxpopup_item_append(ugd->context_popup, _("IDS_EMAIL_OPT_ADD_CC_BCC"), icon, _composer_cbar_cc_clicked, ugd);
162         }
163         icon = NULL;
164
165         icon = elm_icon_add(ugd->context_popup);
166         elm_image_file_set(icon, IMGDIR "/M02_icon_popup_save.png", NULL);
167         elm_ctxpopup_item_append(ugd->context_popup, dgettext("sys_string", "IDS_COM_POP_SAVE_IN_DRAFTS"), icon, _composer_cbar_save_as_draft_clicked, ugd);
168         icon = NULL;
169
170         icon = elm_icon_add(ugd->context_popup);
171         elm_image_file_set(icon, IMGDIR "/M02_icon_popup_priority.png", NULL);
172         elm_ctxpopup_item_append(ugd->context_popup, _("IDS_EMAIL_BODY_PRIORITY"), icon, _composer_cbar_priority_clicked, ugd);
173         icon = NULL;
174
175         icon = elm_icon_add(ugd->context_popup);
176         elm_image_file_set(icon, IMGDIR "/M02_icon_popup_tracking.png", NULL);
177         elm_ctxpopup_item_append(ugd->context_popup, _("IDS_EMAIL_OPT_TRACKING"), icon, _composer_cbar_tracking_clicked, ugd);
178         icon = NULL;
179
180         _composer_move_ctxpopup_more(ugd, obj);
181
182         evas_object_show(ugd->context_popup);
183 }
184
185 void _composer_back_button_cb(void *data, Evas_Object *obj, void *event_info)
186 {
187         debug_log("");
188
189         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
190
191         elm_object_tree_focus_allow_set(ugd->c_layout, EINA_FALSE); // block the focus not to open IME.
192
193         if (EINA_FALSE == ewk_view_script_execute(ugd->body_ewkview, COMPOSER_JS_GET_LATEST_INFO_CONTENT, _composer_get_latest_info_content_cb, (void *)ugd))
194                 debug_log("COMPOSER_JS_GET_LATEST_INFO_CONTENT failed.");
195
196         if (EINA_FALSE == ewk_view_script_execute(ugd->body_ewkview, COMPOSER_JS_GET_LATEST_HTML_CONTENT, _composer_get_latest_html_content_cb, (void *)ugd))
197                 debug_log("COMPOSER_JS_GET_LATEST_HTML_CONTENT failed.");
198
199         ugd->bringin_timer = ecore_timer_add(0.5, _composer_get_html_content_for_draft_cb, ugd);
200
201         debug_log("Cancel Button Clicked: %p, %p", ugd->cancel_btn, ugd->cancel_btm_btn);
202 }
203
204 void _composer_mbe_changed_cb(void *data, Evas_Object *obj, void *event_info)
205 {
206         debug_log("");
207
208         if (data == NULL || obj == NULL) {
209                 return;
210         }
211
212         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
213
214         if (ugd->clipboard_on) {
215                 debug_log("MBE Lost Focus");
216                 _composer_mbe_set_focus(ugd);
217         }
218
219         if (obj == ugd->to_mbe_entry) {
220                 debug_log("TO");
221                 _composer_check_email_address(ugd, ugd->to_mbe_entry);
222         } else if (obj == ugd->cc_mbe_entry) {
223                 debug_log("CC");
224                 _composer_check_email_address(ugd, ugd->cc_mbe_entry);
225         } else if (obj == ugd->bcc_mbe_entry) {
226                 debug_log("BCC");
227                 _composer_check_email_address(ugd, ugd->bcc_mbe_entry);
228         }
229 }
230
231 void _composer_mbe_longpressed_cb(void *data, Evas_Object *obj, void *event_info)
232 {
233         debug_log("");
234
235         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
236
237         ugd->clipboard_on = true;
238 }
239
240 void _composer_mbe_added_cb(void *data, Evas_Object *obj, void *event_info)
241 {
242         debug_log("");
243
244         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
245
246         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
247
248         EmailRecpInfo *ri = NULL;
249
250         bool is_contact_info = false;
251         bool is_always_bcc = false;
252         bool is_from_addr = false;
253
254         char *addr = elm_entry_markup_to_utf8((char *)elm_object_item_text_get(item));
255         debug_log("utf8 address : %s", addr);
256
257         if (addr == NULL) {
258                 debug_log("Added - Address is NULL");
259
260                 return;
261         }
262
263         char temp_addr[MAX_RECIPIENT_ADDRESSES_LEN + 1] = { 0, };
264
265         ri = (EmailRecpInfo *) elm_object_item_data_get(item);
266
267         if (ri) {
268                 is_contact_info = ri->is_contact_info;
269                 is_always_bcc = ri->is_always_bcc;
270                 is_from_addr = ri->is_from_addr;
271
272                 strncpy(temp_addr, ri->email_list[ri->selected_email_idx].email_addr, MAX_RECIPIENT_ADDRESSES_LEN - 1);
273                 temp_addr[MAX_RECIPIENT_ADDRESSES_LEN] = '\0';
274
275                 debug_log("is_contact_info = %d", is_contact_info);
276                 debug_log("is_always_bcc = %d", is_always_bcc);
277                 debug_log("is_from_addr = %d", is_from_addr);
278         } else {
279                 strncpy(temp_addr, addr, MAX_RECIPIENT_ADDRESSES_LEN - 1);
280                 temp_addr[MAX_RECIPIENT_ADDRESSES_LEN] = '\0';
281         }
282
283         free(addr);
284
285         debug_log("email_addr = %s", temp_addr);
286
287         if (!is_contact_info && !is_always_bcc && !is_from_addr) {
288                 if (ugd->to_recipients_cnt > MAX_RECIPIENT_COUNT) {
289                         char msg[MAX_STR_LEN] = { 0, };
290                         snprintf(msg, sizeof(msg), _("IDS_EMAIL_POP_MAXIMUM_NUMBER_OF_RECIPIENTS_HPD_REACHED"), MAX_RECIPIENT_COUNT);
291
292                         if (ugd->composer_noti) {
293                                 evas_object_del(ugd->composer_noti);
294                                 ugd->composer_noti = NULL;
295                         }
296                         ugd->composer_noti = _composer_create_noti(ugd, false, dgettext("sys_string", "IDS_COM_POP_WARNING"),
297                                 msg, 0, NULL, NULL, 1.0, _composer_noti_response_cb);
298
299                         elm_object_item_del(item);
300
301                         return;
302                 } else if (!_composer_is_valid_email(temp_addr)) {
303                         if (ugd->composer_noti) {
304                                 evas_object_del(ugd->composer_noti);
305                                 ugd->composer_noti = NULL;
306                         }
307                         ugd->composer_noti = _composer_create_noti(ugd, false, dgettext("sys_string", "IDS_COM_POP_WARNING"),
308                                 _("IDS_EMAIL_POP_INVALID_EMAIL_ADDRESS"), 0, NULL, NULL, 1.5, _composer_noti_response_cb);
309
310                         elm_object_item_del(item);
311
312                         return;
313                 }
314
315                 EmailRecpInfo *new_ri = (EmailRecpInfo *) calloc(1, sizeof(EmailRecpInfo));
316                 snprintf(new_ri->email_list[0].email_addr, sizeof(new_ri->email_list[0].email_addr), "%s", temp_addr);
317                 debug_log("email_addr = %s", new_ri->email_list[0].email_addr);
318                 new_ri->selected_email_idx = 0;
319                 new_ri->display_name = NULL;
320                 new_ri->email_cnt = 1;
321                 new_ri->is_contact_info = false;
322                 new_ri->is_from_addr = false;
323                 new_ri->is_always_bcc = false;
324
325                 if ((ugd->me_added == false) && (obj == ugd->to_mbe)) {
326                         debug_log("display_name = %s", ugd->account_info->account->user_display_name);
327                         EmailRecpInfo *from_ri = NULL;
328                         Elm_Object_Item *from_item = NULL;
329                         from_item = elm_multibuttonentry_first_item_get(ugd->from_mbe);
330                         if (from_item) {
331                                 from_ri = elm_object_item_data_get(from_item);
332                                 debug_log("from_ri = %s", from_ri->email_list[0].email_addr);
333                                 if (g_strcmp0(new_ri->email_list[0].email_addr, from_ri->email_list[0].email_addr) == 0) {
334                                         new_ri->display_name = ugd->account_info->account->user_display_name;
335                                         new_ri->is_from_addr = true;
336                                         elm_object_text_set(ugd->add_me_btn, N_("Remove me"));
337                                         ugd->me_added = true;
338                                 }
339                         } else {
340                                 debug_log("account name = %s", ugd->account_info->account_name);
341                                 if (g_strcmp0(new_ri->email_list[0].email_addr, ugd->account_info->account_name) == 0) {
342                                         new_ri->display_name = ugd->account_info->account->user_display_name;
343                                         new_ri->is_from_addr = true;
344                                         elm_object_text_set(ugd->add_me_btn, N_("Remove me"));
345                                         ugd->me_added = true;
346                                 }
347                         }
348                 }
349                 elm_object_item_data_set(item, new_ri);
350         }
351
352         if (obj == ugd->to_mbe) {
353                 ugd->to_recipients_cnt++;
354         } else if (obj == ugd->cc_mbe) {
355                 ugd->cc_recipients_cnt++;
356         } else if (obj == ugd->bcc_mbe) {
357                 ugd->bcc_recipients_cnt++;
358         }
359
360         if ((obj == ugd->to_mbe) || (obj == ugd->cc_mbe) || (obj == ugd->bcc_mbe)) {
361                 if (ugd->bSendBtnDisabled && !_composer_check_recipient_is_empty(ugd)) {
362                         elm_object_disabled_set(ugd->send_btn, EINA_FALSE);
363                         elm_object_disabled_set(ugd->send_btm_btn, EINA_FALSE);
364                         ugd->bSendBtnDisabled = false;
365                 }
366         }
367 }
368
369 void _composer_mbe_deleted_cb(void *data, Evas_Object *obj, void *event_info)
370 {
371         debug_log("");
372
373         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
374         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
375
376         if (obj == ugd->to_mbe) {
377                 debug_log("to_mbe");
378                 char *addr = elm_entry_markup_to_utf8((char *)elm_object_item_text_get(item));
379                 debug_log("utf8 address : %s", addr);
380
381                 EmailRecpInfo *from_ri = NULL;
382                 Elm_Object_Item *from_item = NULL;
383                 from_item = elm_multibuttonentry_first_item_get(ugd->from_mbe);
384
385                 if (from_item) {
386                         from_ri = elm_object_item_data_get(from_item);
387
388                         debug_log("from_ri = %s", from_ri->email_list[0].email_addr);
389                 }
390
391                 debug_log("ugd->me_added = %d", ugd->me_added);
392                 if (ugd->me_added == true) {
393                         debug_log("account name = %s", ugd->account_info->account_name);
394                         if (from_ri) {
395                                 if (g_strcmp0(addr, from_ri->email_list[0].email_addr) == 0) {
396                                         ugd->me_added = false;
397                                         elm_object_text_set(ugd->add_me_btn, N_("Add me"));
398                                 }
399                         } else {
400                                 if (g_strcmp0(addr, ugd->account_info->account_name) == 0) {
401                                         ugd->me_added = false;
402                                         elm_object_text_set(ugd->add_me_btn, N_("Add me"));
403                                 }
404                         }
405                 }
406
407                 if (ugd->to_recipients_cnt > 0)
408                         ugd->to_recipients_cnt--;
409
410                 if (addr) {
411                         g_free(addr);
412                         addr = NULL;
413                 }
414         } else if (obj == ugd->cc_mbe) {
415                 debug_log("cc_mbe");
416
417                 if (ugd->cc_recipients_cnt > 0)
418                         ugd->cc_recipients_cnt--;
419         } else if (obj == ugd->bcc_mbe) {
420                 debug_log("bcc_mbe");
421
422                 if (ugd->bcc_recipients_cnt > 0)
423                         ugd->bcc_recipients_cnt--;
424         }
425
426         if ((obj == ugd->to_mbe) || (obj == ugd->cc_mbe) || (obj == ugd->bcc_mbe)) {
427                 if (!ugd->bSendBtnDisabled && _composer_check_recipient_is_empty(ugd)) {
428                         elm_object_disabled_set(ugd->send_btn, EINA_TRUE);
429                         elm_object_disabled_set(ugd->send_btm_btn, EINA_TRUE);
430                         ugd->bSendBtnDisabled = true;
431                 }
432         }
433 }
434
435 Eina_Bool _composer_unfocus_selected_mbe(void *data)
436 {
437         debug_log("");
438
439         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
440
441         debug_log("selected_entry = %x, to_mbe_entry = %x, cc_mbe_entry = %x, bcc_mbe_entry = %x",
442                 ugd->selected_entry, ugd->to_mbe_entry, ugd->cc_mbe_entry, ugd->bcc_mbe_entry);
443
444         if (ugd->selected_entry == ugd->to_mbe_entry) {
445                 debug_log("to_mbe");
446                 elm_object_focus_set(ugd->to_mbe, EINA_FALSE);
447         } else if (ugd->selected_entry == ugd->cc_mbe_entry) {
448                 debug_log("cc_mbe");
449                 elm_object_focus_set(ugd->cc_mbe, EINA_FALSE);
450         } else if (ugd->selected_entry == ugd->bcc_mbe_entry) {
451                 debug_log("bcc_mbe");
452                 elm_object_focus_set(ugd->bcc_mbe, EINA_FALSE);
453         }
454
455         if (ugd->mbe_unfocus_timer) {
456                 ecore_timer_del(ugd->mbe_unfocus_timer);
457                 ugd->mbe_unfocus_timer = NULL;
458         }
459
460         return EINA_FALSE;
461 }
462
463 void _composer_mbe_selected_cb(void *data, Evas_Object *obj, void *event_info)
464 {
465         debug_log("");
466
467         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
468
469         int index = 0;
470         EmailRecpInfo *ri = NULL;
471
472         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
473
474         ri = (EmailRecpInfo *) elm_object_item_data_get(item);
475
476         debug_log("is_contact_info = %d", ri->is_contact_info);
477         debug_log("is_always_bcc = %d", ri->is_always_bcc);
478         debug_log("is_from_addr = %d", ri->is_from_addr);
479
480         if (obj == ugd->from_mbe) {
481                 debug_log("from selected");
482
483                 _composer_from_show_popup(ugd);
484         } else {
485                 debug_log("");
486
487                 ugd->is_mbe_selected = true;
488
489                 index = ri->selected_email_idx;
490
491                 Evas_Object *pu_list;
492
493                 if (ugd->composer_popup) {
494                         evas_object_del(ugd->composer_popup);
495                         ugd->composer_popup = NULL;
496                 }
497
498                 Evas_Object *   popup = elm_popup_add(ugd->win_main);
499                 elm_object_style_set(popup, "min_menustyle");
500                 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
501                 ugd->popup_list = eina_list_append(ugd->popup_list, popup);
502
503                 debug_log("display_name:%s, index:%d", ri->display_name, index);
504                 if (ri->display_name) {
505                         char *email_str = g_strconcat(ri->display_name, " <", ri->email_list[index].email_addr, ">", NULL);
506                         char *contact_str = elm_entry_utf8_to_markup(email_str);
507                         debug_log("email_str:%s", email_str);
508                         debug_log("contact_str:%s", contact_str);
509                         elm_object_part_text_set(popup, "title,text", contact_str);
510                         g_free(contact_str);
511                 } else {
512                         elm_object_part_text_set(popup, "title,text", ri->email_list[index].email_addr);
513                 }
514
515                 Evas_Object *btn_close = elm_button_add(popup);
516                 elm_object_style_set(btn_close, "popup_button/default");
517                 elm_object_text_set(btn_close, dgettext("sys_string", "IDS_COM_POP_CLOSE"));
518                 elm_object_part_content_set(popup, "button1", btn_close);
519                 evas_object_smart_callback_add(btn_close, "clicked", _composer_popup_response_cb, ugd);
520
521                 pu_list = elm_list_add(popup);
522                 elm_list_mode_set(pu_list, ELM_LIST_EXPAND);
523
524                 elm_list_item_append(pu_list, dgettext("sys_string", "IDS_COM_SK_DELETE"), NULL, NULL, _composer_mbe_popup_delete_cb, ugd);
525                 elm_list_item_append(pu_list, dgettext("sys_string", "IDS_COM_SK_EDIT"), NULL, NULL, _composer_mbe_popup_edit_cb, ugd);
526
527                 if (obj != ugd->to_mbe)
528                         elm_list_item_append(pu_list, _("IDS_EMAIL_BODY_MOVE_TO_TO"), NULL, NULL, _composer_mbe_popup_move_to_to_cb, ugd);
529                 if (obj != ugd->cc_mbe)
530                         elm_list_item_append(pu_list, _("IDS_EMAIL_OPT_MOVE_TO_CC"), NULL, NULL, _composer_mbe_popup_move_to_cc_cb, ugd);
531                 if (obj != ugd->bcc_mbe)
532                         elm_list_item_append(pu_list, _("IDS_EMAIL_OPT_MOVE_TO_BCC"), NULL, NULL, _composer_mbe_popup_move_to_bcc_cb, ugd);
533
534                 debug_log("email_cnt = %d", ri->email_cnt);
535                 if (ri->is_contact_info == true) {
536                         if (ri->email_cnt > 1) {
537                                 elm_list_item_append(pu_list, _("IDS_EMAIL_OPT_CHANGE_EMAIL_ADDRESS_ABB"), NULL, NULL, _composer_mbe_popup_change_addr_cb, ugd);
538                         }
539                 }
540
541                 elm_list_go(pu_list);
542                 elm_object_content_set(popup, pu_list);
543                 evas_object_show(popup);
544                 elm_object_focus_set(popup, EINA_TRUE);
545
546                 ugd->composer_popup = popup;
547                 debug_log("composer_popup = %x, is_mbe_selected = %d", ugd->composer_popup, ugd->is_mbe_selected);
548         }
549 }
550
551 void _composer_mbe_focused_cb(void *data, Evas_Object *obj, void *event_info)
552 {
553         debug_log("");
554
555         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
556
557         debug_log("focus_status: %d", ugd->focus_status);
558
559         if (COMPOSER_FOCUS_STATUS_NONE == ugd->focus_status) {
560                 if (obj == ugd->to_mbe) {
561                         edje_object_signal_emit(_EDJ(ugd->to_ly), "show.button", "*");
562                 }
563                 else if (obj == ugd->cc_mbe) {
564                         edje_object_signal_emit(_EDJ(ugd->cc_ly), "show.button", "*");
565                 }
566                 else if (obj == ugd->bcc_mbe) {
567                         edje_object_signal_emit(_EDJ(ugd->bcc_ly), "show.button", "*");
568                 }
569
570                 _composer_attachment_contract_items(ugd);
571                 elm_multibuttonentry_expanded_set(obj, TRUE);
572
573                 ugd->selected_entry = elm_multibuttonentry_entry_get(obj);
574                 debug_log("MBE editable:%d", elm_multibuttonentry_editable_get(obj));
575                 elm_layout_sizing_eval(ugd->c_layout);
576         } else {
577                 if (ugd->selected_entry == ugd->body_ewkview) {
578                         if (EINA_TRUE == elm_object_focus_get(ugd->to_mbe))
579                                 elm_object_focus_set(ugd->to_mbe, EINA_FALSE);
580                         else if (EINA_TRUE == elm_object_focus_get(ugd->cc_mbe))
581                                 elm_object_focus_set(ugd->cc_mbe, EINA_FALSE);
582                         else if (EINA_TRUE == elm_object_focus_get(ugd->bcc_mbe))
583                                 elm_object_focus_set(ugd->bcc_mbe, EINA_FALSE);
584                 }
585         }
586 }
587
588 void _composer_mbe_unfocused_cb(void *data, Evas_Object *obj, void *event_info)
589 {
590         debug_enter();
591
592         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
593
594         debug_log("composer_popup = %x, is_mbe_selected = %d", ugd->composer_popup, ugd->is_mbe_selected);
595         if (ugd->ps_list) {
596                 _composer_ps_stop(ugd);
597                 ugd->sc_timer = ecore_timer_add(0.5, _composer_ps_scroll_pop, ugd);
598                 if (ugd->is_mbe_selected)
599                         return;
600         }
601
602         if (ugd->focus_status == COMPOSER_FOCUS_STATUS_SELECTED) {
603                 elm_object_tree_focus_allow_set(ugd->c_layout, EINA_FALSE); // block the focus not to open IME.
604                 ugd->focus_status = COMPOSER_FOCUS_STATUS_NONE;
605                 return;
606         }
607
608         debug_log("obj = %x, to_mbe = %x, cc_mbe = %x, bcc_mbe = %x", obj, ugd->to_mbe, ugd->cc_mbe, ugd->bcc_mbe);
609         if (obj == ugd->to_mbe) {
610                 edje_object_signal_emit(_EDJ(ugd->to_ly), "hide.button", "*");
611         }
612         else if (obj == ugd->cc_mbe) {
613                 edje_object_signal_emit(_EDJ(ugd->cc_ly), "hide.button", "*");
614         }
615         else if (obj == ugd->bcc_mbe) {
616                 edje_object_signal_emit(_EDJ(ugd->bcc_ly), "hide.button", "*");
617         }
618
619         elm_multibuttonentry_expanded_set(obj, FALSE);
620 }
621
622 Eina_Bool _composer_mbe_verified_item_cb(Evas_Object *obj, const char *item_label, void *item_data, void *data)
623 {
624         debug_log("");
625
626         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
627
628         if (!item_label) {
629                 debug_log("Item_label is NULL");
630                 return EINA_FALSE;
631         }
632
633         if (item_data) {
634                 debug_log("Normally Added");
635                 return EINA_TRUE;
636         }
637
638         debug_log("item_label = %s", item_label);
639
640         debug_log("is_recipient_duplicated:%d", ugd->is_recipient_duplicated);
641         if (ugd->is_recipient_duplicated == TRUE) {
642                 ugd->is_recipient_duplicated = FALSE;
643                 return EINA_FALSE;
644         }
645
646         if (_composer_is_valid_email(item_label)) {
647                 EmailRecpInfo *ri = (EmailRecpInfo *) calloc(1, sizeof(EmailRecpInfo));
648                 ri->selected_email_idx = 0;
649                 snprintf(ri->email_list[0].email_addr, sizeof(ri->email_list[0].email_addr), "%s", item_label);
650                 ri->display_name = NULL;
651                 ri->email_cnt = 1;
652                 ri->is_contact_info = false;
653                 ri->is_always_bcc = false;
654                 ri->is_from_addr = false;
655
656                 if (_composer_check_recipient_is_duplicated(ugd, obj, ri)) {
657                         if (ugd->composer_noti) {
658                                 evas_object_del(ugd->composer_noti);
659                                 ugd->composer_noti = NULL;
660                         }
661                         ugd->composer_noti = _composer_create_noti(ugd, false, dgettext("sys_string", "IDS_COM_POP_WARNING"), dgettext("sys_string", "IDS_COM_POP_ALREDY_EXISTS"),
662                                 0, NULL, NULL, 1.5, _composer_noti_response_cb);
663
664                         free(ri);
665                         goto err_return;
666                 }
667
668                 char msg[MAX_STR_LEN] = { 0, };
669                 snprintf(msg, sizeof(msg), _("IDS_EMAIL_POP_MAXIMUM_NUMBER_OF_RECIPIENTS_HPD_REACHED"), MAX_RECIPIENT_COUNT);
670
671                 if (obj == ugd->to_mbe) {
672                         if (ugd->to_recipients_cnt >= MAX_RECIPIENT_COUNT) {
673                                 if (ugd->composer_noti) {
674                                         evas_object_del(ugd->composer_noti);
675                                         ugd->composer_noti = NULL;
676                                 }
677                                 ugd->composer_noti = _composer_create_noti(ugd, false, dgettext("sys_string", "IDS_COM_POP_WARNING"), msg,
678                                         0, NULL, NULL, 1.0, _composer_noti_response_cb);
679
680                                 free(ri);
681                                 goto err_return;
682                         }
683                 } else if (obj == ugd->cc_mbe) {
684                         if (ugd->cc_recipients_cnt >= MAX_RECIPIENT_COUNT) {
685                                 if (ugd->composer_noti) {
686                                         evas_object_del(ugd->composer_noti);
687                                         ugd->composer_noti = NULL;
688                                 }
689                                 ugd->composer_noti = _composer_create_noti(ugd, false, dgettext("sys_string", "IDS_COM_POP_WARNING"), msg,
690                                         0, NULL, NULL, 1.0, _composer_noti_response_cb);
691
692                                 free(ri);
693                                 goto err_return;
694                         }
695                 } else if (obj == ugd->bcc_mbe) {
696                         if (ugd->bcc_recipients_cnt >= MAX_RECIPIENT_COUNT) {
697                                 if (ugd->composer_noti) {
698                                         evas_object_del(ugd->composer_noti);
699                                         ugd->composer_noti = NULL;
700                                 }
701                                 ugd->composer_noti = _composer_create_noti(ugd, false, dgettext("sys_string", "IDS_COM_POP_WARNING"), msg,
702                                         0, NULL, NULL, 1.0, _composer_noti_response_cb);
703
704                                 free(ri);
705                                 goto err_return;
706                         }
707                 }
708                 free(ri);
709         } else {
710                 debug_log("Invalid Address");
711
712                 if (ugd->composer_noti) {
713                         evas_object_del(ugd->composer_noti);
714                         ugd->composer_noti = NULL;
715                 }
716                 ugd->composer_noti = _composer_create_noti(ugd, false, dgettext("sys_string", "IDS_COM_POP_WARNING"), _("IDS_EMAIL_POP_INVALID_EMAIL_ADDRESS"),
717                         0, NULL, NULL, 1.0, _composer_noti_response_cb);
718
719                 goto err_return;
720         }
721
722         return EINA_TRUE;
723
724 err_return:
725         debug_log("err-return");
726
727         elm_entry_cursor_end_set(elm_multibuttonentry_entry_get(obj));
728
729         if (_composer_check_popup_exist(ugd))
730                 elm_object_focus_set(ugd->composer_noti, EINA_TRUE);
731
732         return EINA_FALSE;
733 }
734
735 void _composer_mbe_popup_delete_cb(void *data, Evas_Object *obj, void *event_info)
736 {
737         debug_log("");
738
739         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
740
741         Evas_Object *mbe = NULL;
742
743         if (ugd->selected_entry == ugd->to_mbe_entry) {
744                 debug_log("@@@ to MBE @@@");
745                 mbe = ugd->to_mbe;
746         } else if (ugd->selected_entry == ugd->cc_mbe_entry) {
747                 debug_log("@@@ cc MBE @@@");
748                 mbe = ugd->cc_mbe;
749         } else if (ugd->selected_entry == ugd->bcc_mbe_entry) {
750                 debug_log("@@@ bcc MBE @@@");
751                 mbe = ugd->bcc_mbe;
752         }
753
754         Elm_Object_Item *item = elm_multibuttonentry_selected_item_get(mbe);
755
756         if (item && mbe == ugd->bcc_mbe) {
757                 elm_object_item_data_get(item);
758         }
759
760         elm_object_item_del(item);
761
762         if (ugd->popup_list)
763                 ugd->popup_list = eina_list_remove(ugd->popup_list, ugd->composer_noti);
764         if (ugd->composer_noti) {
765                 evas_object_del(ugd->composer_noti);
766                 ugd->composer_noti = NULL;
767         }
768         if (ugd->composer_popup) {
769                 evas_object_del(ugd->composer_popup);
770                 ugd->composer_popup = NULL;
771         }
772         ugd->is_mbe_selected = false;
773 }
774
775 void _composer_mbe_popup_edit_cb(void *data, Evas_Object *obj, void *event_info)
776 {
777         debug_log("In");
778
779         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
780
781         EmailRecpInfo *ri = NULL;
782
783         Evas_Object *mbe = NULL;
784
785         if (ugd->selected_entry == ugd->to_mbe_entry) {
786                 mbe = ugd->to_mbe;
787         } else if (ugd->selected_entry == ugd->cc_mbe_entry) {
788                 mbe = ugd->cc_mbe;
789         } else if (ugd->selected_entry == ugd->bcc_mbe_entry) {
790                 mbe = ugd->bcc_mbe;
791         }
792
793         Elm_Object_Item *item = elm_multibuttonentry_selected_item_get(mbe);
794         debug_log("item:%p", item);
795
796         int index = 0;
797
798         ri = (EmailRecpInfo *) elm_object_item_data_get(item);
799
800         if (ri)
801                 index = ri->selected_email_idx;
802         else {
803                 debug_log("ri is NULL");
804                 return;
805         }
806
807         elm_object_item_del(item);
808
809         debug_log("email_addr = %s", ri->email_list[index].email_addr);
810         elm_entry_entry_set(ugd->selected_entry, ri->email_list[index].email_addr);
811         elm_entry_cursor_end_set(ugd->selected_entry);
812
813         edit_mode = true;
814         edit_mode_bs = true;
815
816         if (ugd->popup_list)
817                 ugd->popup_list = eina_list_remove(ugd->popup_list, ugd->composer_noti);
818         if (ugd->composer_noti) {
819                 evas_object_del(ugd->composer_noti);
820                 ugd->composer_noti = NULL;
821         }
822         if (ugd->composer_popup) {
823                 evas_object_del(ugd->composer_popup);
824                 ugd->composer_popup = NULL;
825         }
826         ugd->is_mbe_selected = false;
827
828         debug_log("Out");
829 }
830
831 void _composer_mbe_popup_move_to_to_cb(void *data, Evas_Object *obj, void *event_info)
832 {
833         debug_log("");
834
835         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
836         Evas_Object *mbe = NULL;
837         EmailRecpInfo *ri = NULL;
838
839         if (ugd->selected_entry == ugd->to_mbe_entry) {
840                 mbe = ugd->to_mbe;
841         } else if (ugd->selected_entry == ugd->cc_mbe_entry) {
842                 mbe = ugd->cc_mbe;
843         } else if (ugd->selected_entry == ugd->bcc_mbe_entry) {
844                 mbe = ugd->bcc_mbe;
845         }
846
847         Elm_Object_Item *item = elm_multibuttonentry_selected_item_get(mbe);
848         if (item) {
849                 ri = (EmailRecpInfo *) elm_object_item_data_get(item);
850                 if (ri) {
851                         elm_object_item_del(item);
852                         if (ri->display_name)
853                                 elm_multibuttonentry_item_append(ugd->to_mbe, ri->display_name, NULL, ri);
854                         else
855                                 elm_multibuttonentry_item_append(ugd->to_mbe, ri->email_list[ri->selected_email_idx].email_addr, NULL, ri);
856                 }
857                 else {
858                         debug_log("ri is NULL");
859                 }
860         }
861
862         elm_object_focus_set(ugd->to_mbe, EINA_TRUE);
863
864         if (ugd->popup_list)
865                 ugd->popup_list = eina_list_remove(ugd->popup_list, ugd->composer_noti);
866
867         if (ugd->composer_noti) {
868                 evas_object_del(ugd->composer_noti);
869                 ugd->composer_noti = NULL;
870         }
871
872         if (ugd->composer_popup) {
873                 evas_object_del(ugd->composer_popup);
874                 ugd->composer_popup = NULL;
875         }
876         ugd->is_mbe_selected = false;
877 }
878
879 void _composer_mbe_popup_move_to_cc_cb(void *data, Evas_Object *obj, void *event_info)
880 {
881         debug_log("");
882
883         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
884         Evas_Object *mbe = NULL;
885         EmailRecpInfo *ri = NULL;
886
887         if (ugd->selected_entry == ugd->to_mbe_entry) {
888                 mbe = ugd->to_mbe;
889         } else if (ugd->selected_entry == ugd->cc_mbe_entry) {
890                 mbe = ugd->cc_mbe;
891         } else if (ugd->selected_entry == ugd->bcc_mbe_entry) {
892                 mbe = ugd->bcc_mbe;
893         }
894
895         if (!ugd->cc_added) {
896                 edje_object_signal_emit(_EDJ(ugd->c_layout), "show.cc", "*");
897                 email_composer_create_cc_field(ugd);
898                 edje_object_signal_emit(_EDJ(ugd->c_layout), "show.bcc", "*");
899                 email_composer_create_bcc_field(ugd);
900                 elm_object_text_set(ugd->cc_btn, N_("Remove Cc/Bcc"));
901                 ugd->b_cc_bcc = false;
902         }
903
904         Elm_Object_Item *item = elm_multibuttonentry_selected_item_get(mbe);
905         if (item) {
906                 ri = (EmailRecpInfo *) elm_object_item_data_get(item);
907                 if (ri) {
908                         elm_object_item_del(item);
909                         if (ri->display_name)
910                                 elm_multibuttonentry_item_append(ugd->cc_mbe, ri->display_name, NULL, ri);
911                         else
912                                 elm_multibuttonentry_item_append(ugd->cc_mbe, ri->email_list[ri->selected_email_idx].email_addr, NULL, ri);
913                 }
914                 else {
915                         debug_log("ri is NULL");
916                 }
917         }
918
919         elm_object_focus_set(ugd->cc_mbe, EINA_TRUE);
920
921         if (ugd->popup_list)
922                 ugd->popup_list = eina_list_remove(ugd->popup_list, ugd->composer_noti);
923
924         if (ugd->composer_noti) {
925                 evas_object_del(ugd->composer_noti);
926                 ugd->composer_noti = NULL;
927         }
928
929         if (ugd->composer_popup) {
930                 evas_object_del(ugd->composer_popup);
931                 ugd->composer_popup = NULL;
932         }
933         ugd->is_mbe_selected = false;
934 }
935
936 void _composer_mbe_popup_move_to_bcc_cb(void *data, Evas_Object *obj, void *event_info)
937 {
938         debug_log("");
939
940         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
941         Evas_Object *mbe = NULL;
942         EmailRecpInfo *ri = NULL;
943
944         if (ugd->selected_entry == ugd->to_mbe_entry) {
945                 mbe = ugd->to_mbe;
946         } else if (ugd->selected_entry == ugd->cc_mbe_entry) {
947                 mbe = ugd->cc_mbe;
948         } else if (ugd->selected_entry == ugd->bcc_mbe_entry) {
949                 mbe = ugd->bcc_mbe;
950         }
951
952         if (!ugd->bcc_added) {
953                 edje_object_signal_emit(_EDJ(ugd->c_layout), "show.bcc", "*");
954                 email_composer_create_bcc_field(ugd);
955                 edje_object_signal_emit(_EDJ(ugd->c_layout), "show.cc", "*");
956                 email_composer_create_cc_field(ugd);
957                 elm_object_text_set(ugd->cc_btn, N_("Remove Cc/Bcc"));
958                 ugd->b_cc_bcc = false;
959         }
960
961         Elm_Object_Item *item = elm_multibuttonentry_selected_item_get(mbe);
962         if (item) {
963                 ri = (EmailRecpInfo *) elm_object_item_data_get(item);
964                 if (ri) {
965                         elm_object_item_del(item);
966                         if (ri->display_name)
967                                 elm_multibuttonentry_item_append(ugd->bcc_mbe, ri->display_name, NULL, ri);
968                         else
969                                 elm_multibuttonentry_item_append(ugd->bcc_mbe, ri->email_list[ri->selected_email_idx].email_addr, NULL, ri);
970                 }
971                 else {
972                         debug_log("ri is NULL");
973                 }
974         }
975
976         elm_object_focus_set(ugd->bcc_mbe, EINA_TRUE);
977
978         if (ugd->popup_list)
979                 ugd->popup_list = eina_list_remove(ugd->popup_list, ugd->composer_noti);
980
981         if (ugd->composer_noti) {
982                 evas_object_del(ugd->composer_noti);
983                 ugd->composer_noti = NULL;
984         }
985
986         if (ugd->composer_popup) {
987                 evas_object_del(ugd->composer_popup);
988                 ugd->composer_popup = NULL;
989         }
990         ugd->is_mbe_selected = false;
991 }
992
993 void _composer_mbe_popup_change_addr_cb(void *data, Evas_Object *obj, void *event_info)
994 {
995         debug_log("");
996
997         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
998
999         EmailRecpInfo *ri = NULL;
1000
1001         Evas_Object *mbe = NULL;
1002
1003         int i;
1004
1005         if (ugd->selected_entry == ugd->to_mbe_entry) {
1006                 mbe = ugd->to_mbe;
1007         } else if (ugd->selected_entry == ugd->cc_mbe_entry) {
1008                 mbe = ugd->cc_mbe;
1009         } else if (ugd->selected_entry == ugd->bcc_mbe_entry) {
1010                 mbe = ugd->bcc_mbe;
1011         }
1012
1013         Elm_Object_Item *item = elm_multibuttonentry_selected_item_get(mbe);
1014         ugd->selected_item = item;
1015         debug_log("@@@ Elm_Object_Item = %p @@@", item);
1016         ri = (EmailRecpInfo *) elm_object_item_data_get(item);
1017
1018         for (i = 0; i < ri->email_cnt; i++) {
1019                 snprintf(email_list[i].email_addr, MAX_RECIPIENT_ADDRESS_LEN, "%s", ri->email_list[i].email_addr);
1020                 email_list[i].email_type = ri->email_list[i].email_type;
1021         }
1022
1023         email_cnt = ri->email_cnt;
1024
1025         _composer_mbe_create_change_addr_list(ugd);
1026
1027         if (ugd->popup_list)
1028                 ugd->popup_list = eina_list_remove(ugd->popup_list, ugd->composer_noti);
1029
1030         if (ugd->composer_noti) {
1031                 evas_object_del(ugd->composer_noti);
1032                 ugd->composer_noti = NULL;
1033         }
1034
1035         if (ugd->composer_popup) {
1036                 evas_object_del(ugd->composer_popup);
1037                 ugd->composer_popup = NULL;
1038         }
1039         ugd->is_mbe_selected = false;
1040 }
1041
1042 static void _composer_mbe_popup_change_addr_selected_cb(void *data, Evas_Object *obj, void *event_info)
1043 {
1044         debug_log("");
1045
1046         if (data == NULL)
1047                 return;
1048
1049         if (obj == NULL)
1050                 return;
1051
1052         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
1053
1054         int selected_idx = 0;
1055         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
1056
1057         if (item != NULL) {
1058                 selected_idx = (int)elm_object_item_data_get(item);
1059                 debug_log("selected_idx = %d", selected_idx);
1060                 debug_log("email_addr:%s", email_list[selected_idx].email_addr);
1061
1062                 EmailRecpInfo *ri = NULL;
1063                 Evas_Object *mbe = NULL;
1064
1065                 if (ugd->selected_entry == ugd->to_mbe_entry) {
1066                         mbe = ugd->to_mbe;
1067                 } else if (ugd->selected_entry == ugd->cc_mbe_entry) {
1068                         mbe = ugd->cc_mbe;
1069                 } else if (ugd->selected_entry == ugd->bcc_mbe_entry) {
1070                         mbe = ugd->bcc_mbe;
1071                 }
1072
1073                 Elm_Object_Item *item = elm_multibuttonentry_selected_item_get(mbe);
1074                 ugd->selected_item = item;
1075                 debug_log("@@@ Elm_Object_Item = %p @@@", item);
1076                 ri = (EmailRecpInfo *) elm_object_item_data_get(item);
1077
1078                 ri->selected_email_idx = selected_idx;
1079         }
1080
1081         if (ugd->popup_list)
1082                 ugd->popup_list = eina_list_remove(ugd->popup_list, ugd->change_addr_noti);
1083
1084         if (ugd->change_addr_noti) {
1085                 debug_log("");
1086                 evas_object_del(ugd->change_addr_noti);
1087                 ugd->change_addr_noti = NULL;
1088         }
1089 }
1090
1091 char *_composer_change_addr_gl_text_get(void *data, Evas_Object *obj, const char *part)
1092 {
1093         int index = (int)data;
1094         const char *email_str = NULL;
1095
1096         debug_log("label index = %d, email_type = %d", index, email_list[index].email_type);
1097
1098         if (!g_strcmp0(part, "elm.text")) {
1099                 if (email_list[index].email_type == 0)
1100                         email_str = g_strconcat(_("IDS_EMAIL_OPT_OTHER"), ": ", email_list[index].email_addr, NULL);
1101                 else if (email_list[index].email_type == 2)
1102                         email_str = g_strconcat(dgettext("sys_string", "IDS_COM_BODY_HOME"), ": ", email_list[index].email_addr, NULL);
1103                 else if (email_list[index].email_type == 4)
1104                         email_str = g_strconcat(dgettext("sys_string", "IDS_COM_BODY_WORK"), ": ", email_list[index].email_addr, NULL);
1105                 else
1106                         email_str = g_strconcat(_("IDS_EMAIL_OPT_OTHER"), ": ", email_list[index].email_addr, NULL);
1107
1108                 debug_log("email_type(%d), email_str(%s)", email_list[index].email_type, email_str);
1109                 return g_strdup(email_str);
1110         }
1111
1112         return NULL;
1113 }
1114
1115 void _composer_mbe_change_addr_response_cb(void *data, Evas_Object *obj, void *event_info)
1116 {
1117         debug_log("");
1118
1119         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
1120
1121         Evas_Object *mbe = NULL;
1122
1123         if (ugd->selected_entry == ugd->to_mbe_entry) {
1124                 mbe = ugd->to_mbe;
1125         } else if (ugd->selected_entry == ugd->cc_mbe_entry) {
1126                 mbe = ugd->cc_mbe;
1127         } else if (ugd->selected_entry == ugd->bcc_mbe_entry) {
1128                 mbe = ugd->bcc_mbe;
1129         }
1130
1131         elm_object_item_data_get(ugd->selected_item);
1132
1133         char *pszBtnText = (char *)elm_object_text_get(obj);
1134         debug_log("selected button text = %s", pszBtnText);
1135
1136         if (ugd->popup_list) {
1137                 debug_log("popup count = %d", eina_list_count(ugd->popup_list));
1138                 debug_log("obj: %p", obj);
1139                 debug_log("change_addr_noti: %p", ugd->change_addr_noti);
1140
1141                 ugd->popup_list = eina_list_remove(ugd->popup_list, ugd->change_addr_noti/*obj*/);
1142         }
1143
1144         if (ugd->change_addr_noti) {
1145                 evas_object_del(ugd->change_addr_noti);
1146                 ugd->change_addr_noti = NULL;
1147         }
1148 }
1149
1150 void _composer_cancel_send_mail_cb(void *data, Evas_Object *obj, void *event_info)
1151 {
1152         debug_log("");
1153         if (data == NULL) {
1154                 debug_log("data is NULL");
1155                 return;
1156         }
1157
1158         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
1159
1160         int err = email_cancel_sending_mail(ugd->new_mail_info->mail_data->mail_id);
1161
1162         _composer_webkit_set_body_script(data);
1163         elm_object_tree_focus_allow_set(ugd->c_layout, EINA_TRUE); // block the focus not to open IME.
1164         elm_object_disabled_set(ugd->send_btn, EINA_FALSE);
1165         elm_object_disabled_set(ugd->cancel_btn, EINA_FALSE);
1166         elm_object_disabled_set(ugd->send_btm_btn, EINA_FALSE);
1167         elm_object_disabled_set(ugd->cancel_btm_btn, EINA_FALSE);
1168
1169         if (err != EMAIL_ERROR_NONE) {
1170                 debug_warning("email_engine_cancel_send_mail failed - err(%d)", err);
1171         } else {
1172                 if (ugd->composer_noti) {
1173                         evas_object_del(ugd->composer_noti);
1174                         ugd->composer_noti = NULL;
1175                 }
1176
1177                 ugd->send_result = COMPOSER_ERROR_SEND_FAIL;
1178                 debug_log("Cancelled to send email");
1179         }
1180 }
1181
1182 Eina_Bool _composer_send_mail_cb(void *data)
1183 {
1184         debug_log("");
1185
1186         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
1187
1188         if (ugd->send_timer) {
1189                 debug_log("delete send_timer");
1190                 ecore_timer_del(ugd->send_timer);
1191                 ugd->send_timer = NULL;
1192         }
1193
1194         ugd->send_result = _composer_send_mail(ugd);
1195
1196         if (ugd->selected_entry == ugd->body_ewkview) {
1197                 evas_object_focus_set(ugd->body_ewkview, EINA_FALSE);
1198         } else {
1199                 Ecore_IMF_Context *imf_context = NULL;
1200                 imf_context = elm_entry_imf_context_get(ugd->selected_entry);
1201                 if (imf_context)
1202                         ecore_imf_context_input_panel_hide(imf_context);
1203         }
1204
1205         if (ugd->composer_noti) {
1206                 evas_object_del(ugd->composer_noti);
1207                 ugd->composer_noti = NULL;
1208         }
1209
1210         ugd->composer_noti = elm_popup_add(ugd->main_layout);
1211         debug_log("composer_noti: %p", ugd->composer_noti);
1212         if (!ugd->composer_noti) {
1213                 debug_log("elm_popup_add returns NULL");
1214                 return EINA_FALSE;
1215         }
1216
1217         evas_object_size_hint_weight_set(ugd->composer_noti, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1218
1219         if (ugd->send_result == COMPOSER_ERROR_NONE) {
1220                 char temp_text[128];
1221                 snprintf(temp_text, sizeof(temp_text), "%s", dgettext("sys_string", "IDS_COM_POP_SENDING"));
1222                 elm_object_part_text_set(ugd->composer_noti, "title,text", temp_text);
1223
1224                 Evas_Object *progressbar = elm_progressbar_add(ugd->composer_noti);
1225                 elm_object_style_set(progressbar, "list_process");//"pending_list"//"list_progress"
1226                 elm_progressbar_horizontal_set(progressbar, EINA_TRUE);
1227                 evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL, EVAS_HINT_FILL);
1228                 evas_object_size_hint_weight_set(progressbar, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1229                 evas_object_show(progressbar);
1230                 elm_progressbar_pulse(progressbar, EINA_TRUE);
1231                 elm_object_content_set(ugd->composer_noti, progressbar);
1232
1233                 Evas_Object *btn1 = elm_button_add(ugd->composer_noti);
1234                 elm_object_style_set(btn1, "popup_button/default");
1235                 elm_object_text_set(btn1, dgettext("sys_string", "IDS_COM_SK_CANCEL"));
1236                 elm_object_part_content_set(ugd->composer_noti, "button1", btn1);
1237                 evas_object_smart_callback_add(btn1, "clicked", _composer_cancel_send_mail_cb, ugd);
1238
1239                 /*
1240                         After sending, not to focus mbe.
1241                 */
1242                 if (!ugd->b_sending)
1243                         ugd->b_sending = true;
1244
1245                 evas_object_show(ugd->composer_noti);
1246                 ugd->send_timer = ecore_timer_add(2.0, _composer_send_popup_finish_cb, ugd);
1247         } else if (ugd->send_result == COMPOSER_ERROR_SEND_FAIL) {
1248                 if (ugd->composer_noti) {
1249                         evas_object_del(ugd->composer_noti);
1250                         ugd->composer_noti = NULL;
1251                 }
1252                 ugd->composer_noti = _composer_create_noti(ugd, false, dgettext("sys_string", "IDS_COM_POP_WARNING"),
1253                         _("IDS_EMAIL_POP_UNABLE_TO_SEND_EMAIL"), 0, NULL, NULL, 1.5, _composer_fail_to_send_popup_cb);
1254         }
1255
1256         return EINA_TRUE;
1257 }
1258
1259 Eina_Bool _composer_region_show_cb(void *data)
1260 {
1261         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
1262
1263         Evas_Coord sc_width = 0, sc_height = 0;
1264         elm_scroller_region_get(ugd->main_scroller, 0, 0, &sc_width, &sc_height);
1265
1266         Evas_Coord from_height = 0;
1267         if (ugd->from_ly)
1268                 evas_object_geometry_get(ugd->from_ly, NULL, NULL, NULL, &from_height);
1269
1270         Evas_Coord to_height = 0;
1271         evas_object_geometry_get(ugd->to_ly, NULL, NULL, NULL, &to_height);
1272
1273         Evas_Coord cc_height = 0;
1274         if (ugd->cc_ly)
1275                 evas_object_geometry_get(ugd->cc_ly, NULL, NULL, NULL, &cc_height);
1276
1277         Evas_Coord bcc_height = 0;
1278         if (ugd->bcc_ly)
1279                 evas_object_geometry_get(ugd->bcc_ly, NULL, NULL, NULL, &bcc_height);
1280
1281         Evas_Coord sub_height = 0;
1282         evas_object_geometry_get(ugd->subject_ly, NULL, NULL, NULL, &sub_height);
1283
1284         Evas_Coord att_height = 0;
1285         if (ugd->attachment_contracted_item)
1286                 evas_object_geometry_get(ugd->attachment_contracted_item, NULL, NULL, NULL, &att_height);
1287
1288         debug_log("scroller = w:%d, h:%d", sc_width, sc_height);
1289         debug_log("from_height = %d", from_height);
1290         debug_log("  to_height = %d", to_height);
1291         debug_log("  cc_height = %d", cc_height);
1292         debug_log(" bcc_height = %d", bcc_height);
1293         debug_log(" sub_height = %d", sub_height);
1294         debug_log(" att_height = %d", att_height);
1295
1296         // 10 means "top_line" size. it should be modified. it should get from edc part.
1297         if (ugd->selected_entry == ugd->to_mbe_entry) {
1298                 debug_log("selected_entry = to_mbe_entry");
1299                 elm_scroller_region_show(ugd->main_scroller, 0, 10 + from_height, sc_width, sc_height);
1300         } else if (ugd->selected_entry == ugd->cc_mbe_entry) {
1301                 debug_log("selected_entry = cc_mbe_entry");
1302                 elm_scroller_region_show(ugd->main_scroller, 0, 10 + from_height + to_height, sc_width, sc_height);
1303         } else if (ugd->selected_entry == ugd->bcc_mbe_entry) {
1304                 debug_log("selected_entry = bcc_mbe_entry");
1305                 elm_scroller_region_show(ugd->main_scroller, 0, 10 + from_height + to_height + cc_height, sc_width, sc_height);
1306         } else if (ugd->selected_entry == ugd->subject_entry) {
1307                 debug_log("selected_entry = subject_entry");
1308                 elm_scroller_region_show(ugd->main_scroller, 0, 10 + from_height + to_height + cc_height + bcc_height, sc_width, sc_height);
1309         } else if (ugd->selected_entry == ugd->attachment_contracted_item) {
1310                 debug_log("selected_entry = attachment_contracted_item");
1311                 elm_scroller_region_show(ugd->main_scroller, 0, 10 + from_height + to_height + cc_height + bcc_height + sub_height, sc_width, sc_height);
1312         } else if (ugd->selected_entry == ugd->body_ewkview) {
1313                 debug_log("selected_entry = body_ewkview");
1314                 elm_scroller_region_show(ugd->main_scroller, 0, 10 + from_height + to_height + cc_height + bcc_height + sub_height + att_height, sc_width, sc_height);
1315         }
1316
1317         return ECORE_CALLBACK_CANCEL;
1318 }
1319
1320 Eina_Bool _composer_bringin_cb(void *data)
1321 {
1322         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
1323
1324         Evas_Coord sc_width = 0, sc_height = 0;
1325         elm_scroller_region_get(ugd->main_scroller, 0, 0, &sc_width, &sc_height);
1326
1327         Evas_Coord from_height = 0;
1328         if (ugd->from_ly)
1329                 evas_object_geometry_get(ugd->from_ly, NULL, NULL, NULL, &from_height);
1330
1331         Evas_Coord to_height = 0;
1332         evas_object_geometry_get(ugd->to_ly, NULL, NULL, NULL, &to_height);
1333
1334         Evas_Coord cc_height = 0;
1335         if (ugd->cc_ly)
1336                 evas_object_geometry_get(ugd->cc_ly, NULL, NULL, NULL, &cc_height);
1337
1338         Evas_Coord bcc_height = 0;
1339         if (ugd->bcc_ly)
1340                 evas_object_geometry_get(ugd->bcc_ly, NULL, NULL, NULL, &bcc_height);
1341
1342         Evas_Coord sub_height = 0;
1343         evas_object_geometry_get(ugd->subject_ly, NULL, NULL, NULL, &sub_height);
1344
1345         Evas_Coord att_height = 0;
1346         if (ugd->attachment_contracted_item)
1347                 evas_object_geometry_get(ugd->attachment_contracted_item, NULL, NULL, NULL, &att_height);
1348
1349         debug_log("scroller = w:%d, h:%d", sc_width, sc_height);
1350         debug_log("from_height = %d", from_height);
1351         debug_log("  to_height = %d", to_height);
1352         debug_log("  cc_height = %d", cc_height);
1353         debug_log(" bcc_height = %d", bcc_height);
1354         debug_log(" sub_height = %d", sub_height);
1355         debug_log(" att_height = %d", att_height);
1356
1357         // 10 means "top_line" size. it should be modified. it should get from edc part.
1358         if (ugd->selected_entry == ugd->to_mbe_entry) {
1359                 debug_log("selected_entry = to_mbe_entry");
1360                 elm_scroller_region_bring_in(ugd->main_scroller, 0, 10 + from_height, sc_width, sc_height);
1361         } else if (ugd->selected_entry == ugd->cc_mbe_entry) {
1362                 debug_log("selected_entry = cc_mbe_entry");
1363                 elm_scroller_region_bring_in(ugd->main_scroller, 0, 10 + from_height + to_height, sc_width, sc_height);
1364         } else if (ugd->selected_entry == ugd->bcc_mbe_entry) {
1365                 debug_log("selected_entry = bcc_mbe_entry");
1366                 elm_scroller_region_bring_in(ugd->main_scroller, 0, 10 + from_height + to_height + cc_height, sc_width, sc_height);
1367         } else if (ugd->selected_entry == ugd->subject_entry) {
1368                 debug_log("selected_entry = subject_entry");
1369                 elm_scroller_region_bring_in(ugd->main_scroller, 0, 10 + from_height + to_height + cc_height + bcc_height, sc_width, sc_height);
1370         } else if (ugd->selected_entry == ugd->attachment_contracted_item) {
1371                 debug_log("selected_entry = attachment_contracted_item");
1372                 elm_scroller_region_bring_in(ugd->main_scroller, 0, 10 + from_height + to_height + cc_height + bcc_height + sub_height, sc_width, sc_height);
1373         } else if (ugd->selected_entry == ugd->body_ewkview) {
1374                 debug_log("selected_entry = body_ewkview");
1375                 elm_scroller_region_bring_in(ugd->main_scroller, 0, 10 + from_height + to_height + cc_height + bcc_height + sub_height + att_height, sc_width, sc_height);
1376         }
1377
1378         if (ugd->bringin_timer) {
1379                 ecore_timer_del(ugd->bringin_timer);
1380                 ugd->bringin_timer = NULL;
1381         }
1382
1383         return ECORE_CALLBACK_CANCEL;
1384 }
1385
1386 Eina_Bool _composer_mbe_popup_del(void *data)
1387 {
1388         debug_log("");
1389         Evas_Object *obj = (Evas_Object *)data;
1390
1391         evas_object_del(obj);
1392         obj = NULL;
1393
1394         return EINA_FALSE;
1395 }
1396
1397 Eina_Bool _composer_mbe_create_change_addr_list(EmailComposerUGD *ugd)
1398 {
1399         debug_log("");
1400
1401         if (ugd->change_addr_noti) {
1402                 evas_object_del(ugd->change_addr_noti);
1403                 ugd->change_addr_noti = NULL;
1404         }
1405         ugd->change_addr_noti = _composer_create_noti_with_list(ugd, false, _("IDS_EMAIL_HEADER_SELECT_EMAIL_ADDRESS"), NULL, 1,
1406                 dgettext("sys_string", "IDS_COM_SK_CANCEL"), NULL, 0.0, _composer_mbe_change_addr_response_cb);
1407
1408
1409         Elm_Object_Item *gen_item;
1410         Evas_Object *genlist;
1411         int index;
1412
1413         itc.item_style = "1text";
1414         itc.func.text_get = _composer_change_addr_gl_text_get;
1415         itc.func.content_get = NULL;
1416         itc.func.state_get = NULL;
1417         itc.func.del = NULL;
1418
1419         genlist = elm_genlist_add(ugd->change_addr_noti);
1420
1421         evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1422         evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
1423
1424         debug_log("ri->email_cnt = %d", email_cnt);
1425
1426         for (index = 0; index < email_cnt; index++) {
1427                 gen_item = elm_genlist_item_append(genlist, &itc, (void *)index, NULL, ELM_GENLIST_ITEM_NONE, _composer_mbe_popup_change_addr_selected_cb, ugd);
1428
1429                 elm_object_item_data_set(gen_item, (void *)index);
1430                 elm_genlist_item_update(gen_item);
1431         }
1432
1433         elm_genlist_tree_effect_enabled_set(genlist, EINA_FALSE);
1434
1435 #ifdef _POPUP_WITH_LIST
1436         debug_log("index:%d", index);
1437         if (index > 5)
1438                 index = 5;
1439         Evas_Object *box = elm_box_add(ugd->change_addr_noti);
1440         evas_object_size_hint_min_set(box, 610 * elm_config_scale_get(), 113 * index * elm_config_scale_get());
1441         evas_object_show(genlist);
1442         elm_box_pack_end(box, genlist);
1443         elm_object_content_set(ugd->change_addr_noti, box);
1444 #else
1445         elm_object_content_set(ugd->change_addr_noti, genlist);
1446 #endif
1447
1448         return EINA_FALSE;
1449 }
1450
1451 Eina_Bool _composer_send_popup_finish_cb(void *data)
1452 {
1453         debug_log("");
1454         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
1455
1456         _composer_popup_end(ugd, ugd->send_result);
1457         return EINA_TRUE;
1458 }
1459
1460 void _composer_fail_to_send_popup_cb(void *data, Evas_Object *obj, void *event_info)
1461 {
1462         debug_log("");
1463         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
1464
1465         elm_object_tree_focus_allow_set(ugd->c_layout, EINA_TRUE);
1466
1467         if (ugd->popup_list) {
1468                 debug_log("popup count = %d", eina_list_count(ugd->popup_list));
1469                 debug_log("obj: %p", obj);
1470                 debug_log("composer_noti: %p", ugd->composer_noti);
1471
1472                 ugd->popup_list = eina_list_remove(ugd->popup_list, ugd->composer_noti/*obj*/);
1473         }
1474
1475         if (ugd->composer_noti) {
1476                 evas_object_del(ugd->composer_noti);
1477                 ugd->composer_noti = NULL;
1478         }
1479
1480         elm_object_disabled_set(ugd->send_btn, EINA_FALSE);
1481         elm_object_disabled_set(ugd->cancel_btn, EINA_FALSE);
1482         elm_object_disabled_set(ugd->send_btm_btn, EINA_FALSE);
1483         elm_object_disabled_set(ugd->cancel_btm_btn, EINA_FALSE);
1484
1485         ugd->bSendBtnDisabled = false;
1486 }
1487
1488 void _composer_check_email_address(EmailComposerUGD *ugd, Evas_Object *entry)
1489 {
1490         debug_log("");
1491
1492         char *temp = elm_entry_markup_to_utf8(elm_entry_entry_get(entry));
1493
1494         if (!temp)
1495                 return;
1496
1497         debug_log("temp = %s, edit_mode = %d", temp, edit_mode);
1498
1499         if (edit_mode == true) {
1500                 edit_mode = false;
1501                 free(temp);
1502                 return;
1503         }
1504
1505         if (strlen(temp) == 0) {
1506                 if (ugd->ps_on) {
1507                         _composer_ps_stop(ugd);
1508                         ugd->sc_timer = ecore_timer_add(0.5, _composer_ps_scroll_pop, ugd);
1509                 }
1510         } else if (strlen(temp)) {
1511                 debug_log("temp = %s", temp);
1512
1513                 memset(ugd->ps_keyword, 0x00, sizeof(ugd->ps_keyword));
1514                 strncpy(ugd->ps_keyword, temp, sizeof(ugd->ps_keyword) - 1);
1515
1516                 _composer_ps_add_timer(ugd);
1517         }
1518
1519         free(temp);
1520 }
1521
1522 void _composer_check_entry_max(EmailComposerUGD *ugd, Evas_Object *entry, int max_len)
1523 {
1524         debug_log("");
1525         const char *temp = elm_entry_entry_get(entry);
1526
1527         debug_log("subject len = %d", strlen(temp));
1528         if (strlen(temp) >= max_len) {
1529                 debug_log("Subject length is Over");
1530
1531                 char subject[MAX_SUBJECT_LEN] = { 0, };
1532                 strncpy(subject, temp, sizeof(subject) - 1);
1533
1534                 elm_entry_entry_set(entry, subject);
1535                 elm_entry_cursor_end_set(entry);
1536
1537                 if (ugd->composer_noti) {
1538                         evas_object_del(ugd->composer_noti);
1539                         ugd->composer_noti = NULL;
1540                 }
1541                 ugd->composer_noti = _composer_create_noti(ugd, false, dgettext("sys_string", "IDS_COM_POP_WARNING"), _("IDS_EMAIL_POP_UNABLE_TO_ENTER_TEXT"), 0, NULL, NULL, 1.5, _composer_noti_response_cb);
1542         }
1543 }
1544
1545 void _composer_from_show_popup(EmailComposerUGD *ugd)
1546 {
1547         debug_log("");
1548
1549         int acc_index;
1550
1551         g_ugd = ugd;
1552
1553         if (ugd->composer_noti) {
1554                 evas_object_del(ugd->composer_noti);
1555                 ugd->composer_noti = NULL;
1556         }
1557         ugd->composer_noti = _composer_create_noti_with_list(ugd, false, _("IDS_EMAIL_BODY_FROM"), NULL, 1, dgettext("sys_string", "IDS_COM_SK_OK"), NULL, 0.0, _composer_from_change_response_cb);
1558
1559         from_itc.item_style = "email.2text.3icon.3";
1560         from_itc.func.text_get = _composer_from_gl_text_get;
1561         from_itc.func.content_get = _composer_from_gl_content_get;
1562         from_itc.func.state_get = NULL;
1563         from_itc.func.del = NULL;
1564
1565         elm_genlist_clear(ugd->account_gen_list);
1566         ugd->account_gen_list = elm_genlist_add(ugd->composer_noti);
1567         elm_object_theme_set(ugd->account_gen_list, ugd->th);
1568
1569         evas_object_size_hint_weight_set(ugd->account_gen_list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1570         evas_object_size_hint_align_set(ugd->account_gen_list, EVAS_HINT_FILL, EVAS_HINT_FILL);
1571
1572         for (acc_index = 0; acc_index < ugd->account_info->account_count; acc_index++) {
1573                 elm_genlist_item_append(ugd->account_gen_list, &from_itc, (void *)acc_index, NULL, ELM_GENLIST_ITEM_NONE, _composer_from_gl_sel, (void *)acc_index);
1574         }
1575
1576         elm_genlist_tree_effect_enabled_set(ugd->account_gen_list, EINA_FALSE);
1577
1578 #ifdef _POPUP_WITH_LIST
1579         debug_log("acc_index:%d", acc_index);
1580         if (acc_index > 5)
1581                 acc_index = 5;
1582         Evas_Object *box = elm_box_add(ugd->composer_noti);
1583         evas_object_size_hint_min_set(box, 610 * elm_config_scale_get(), 120 * acc_index * elm_config_scale_get());
1584         evas_object_show(ugd->account_gen_list);
1585         elm_box_pack_end(box, ugd->account_gen_list);
1586         elm_object_content_set(ugd->composer_noti, box);
1587 #else
1588         elm_object_content_set(ugd->composer_noti, ugd->account_gen_list);
1589 #endif
1590 }
1591
1592 char *_composer_from_gl_text_get(void *data, Evas_Object *obj, const char *part)
1593 {
1594         int index = (int)data;
1595
1596         debug_log("label index = %d", index);
1597
1598         if (!strncmp(part, "elm.text.1", 10)) {
1599                 debug_log("email_addr = %s", g_ugd->account_info->account_list[index].account_name);
1600                 return g_strdup(g_ugd->account_info->account_list[index].account_name);
1601         } else if (!strncmp(part, "elm.text.2", 10)) {
1602                 debug_log("email_addr = %s", g_ugd->account_info->account_list[index].user_email_address);
1603                 return g_strdup(g_ugd->account_info->account_list[index].user_email_address);
1604         } else {
1605                 debug_log("part is invalid");
1606         }
1607
1608         return NULL;
1609 }
1610
1611 Evas_Object *_composer_from_gl_content_get(void *data, Evas_Object *obj, const char *part)
1612 {
1613         int count = (int)data;
1614
1615         debug_log("count = %d", count);
1616         debug_log("account_id = %d", g_ugd->account_info->account_list[count].account_id);
1617         debug_log("default account_id = %d", g_ugd->account_info->account_id);
1618
1619         if (!strncmp(part, "elm.icon.1", 10)) {
1620                 g_ugd->account_info->account_rd[count] = elm_radio_add(obj);
1621                 elm_radio_state_value_set(g_ugd->account_info->account_rd[count], count);
1622
1623                 if (count == 0) {
1624                         g_ugd->account_info->account_rdg = g_ugd->account_info->account_rd[count];
1625                 } else
1626                         elm_radio_group_add(g_ugd->account_info->account_rd[count], g_ugd->account_info->account_rdg);
1627
1628                 if (g_ugd->account_info->account_list[count].account_id == g_ugd->account_info->account_id)
1629                         elm_radio_value_set(g_ugd->account_info->account_rdg, count);
1630
1631                 evas_object_smart_callback_add(g_ugd->account_info->account_rd[count], "changed", _composer_from_radio_cb, g_ugd);
1632
1633                 return g_ugd->account_info->account_rd[count];
1634         } else if (!strncmp(part, "elm.icon.2", 10)) {
1635                 Evas_Object *icon = elm_icon_add(obj);
1636
1637                 debug_log("logo_icon_path:%s", g_ugd->account_info->account_list[count].logo_icon_path);
1638                 if (g_ugd->account_info->account_list[count].logo_icon_path)
1639                         elm_image_file_set(icon, g_ugd->account_info->account_list[count].logo_icon_path, NULL);
1640                 else
1641                         elm_image_file_set(icon, ACCOUNT_ICON_OTHERS, NULL);
1642                 evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
1643
1644                 return icon;
1645         } else if (!strncmp(part, "elm.swallow.colorbar", 20)) {
1646                 account_user_data_t *ud = (account_user_data_t *)g_ugd->account_info->account_list[count].user_data;
1647                 unsigned int val = ud->index_color;
1648                 int r = (val & 0xff000000) >> 24;
1649                 int g = (val & 0x00ff0000) >> 16;
1650                 int b = (val & 0x0000ff00) >> 8;
1651                 int a = val & 0x000000ff;
1652
1653                 Evas_Object *color_bar = evas_object_rectangle_add(evas_object_evas_get(obj));
1654                 evas_object_size_hint_fill_set(color_bar, EVAS_HINT_FILL, EVAS_HINT_FILL);
1655                 evas_object_color_set(color_bar, r, g, b, a);
1656
1657                 return color_bar;
1658         } else {
1659                 debug_log("part is invalid");
1660         }
1661
1662         return NULL;
1663 }
1664
1665 static void _composer_from_gl_sel(void *data, Evas_Object *obj, void *event_info)
1666 {
1667         debug_log("index:%d", (int)data);
1668
1669         int index = (int)data;
1670
1671         elm_radio_value_set(g_ugd->account_info->account_rdg, index);
1672
1673         _composer_from_close_response_cb(g_ugd);
1674 }
1675
1676 static void _composer_from_change_response_cb(void *data, Evas_Object *obj, void *event_info)
1677 {
1678         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
1679
1680         debug_log("composer_noti : %p", ugd->composer_noti);
1681
1682         char *pszBtnText = (char *)elm_object_text_get(obj);
1683         debug_log("selected button text = %s", pszBtnText);
1684
1685         _composer_from_close_response_cb(ugd);
1686 }
1687
1688 static void _composer_from_close_response_cb(EmailComposerUGD *ugd)
1689 {
1690         debug_log("composer_noti : %p", ugd->composer_noti);
1691
1692         int set_val = elm_radio_value_get(ugd->account_info->account_rdg);
1693
1694         debug_log("set_val = %d", set_val);
1695
1696         ugd->account_info->account_id = ugd->account_info->account_list[set_val].account_id;
1697
1698         if (ugd->account_info->account_name) {
1699                 g_free(ugd->account_info->account_name);
1700                 ugd->account_info->account_name = NULL;
1701         }
1702
1703         ugd->account_info->account_name = g_strdup(ugd->account_info->account_list[set_val].user_email_address);
1704
1705         debug_log("account_id = %d", ugd->account_info->account_id);
1706
1707         debug_log("priority = %d, %d", (*ugd->account_info->account).options.priority, ugd->account_info->account_list[set_val].options.priority);
1708
1709         Elm_Object_Item *from_item = NULL;
1710         from_item = elm_multibuttonentry_first_item_get(ugd->from_mbe);
1711
1712         EmailRecpInfo *from_ri = NULL;
1713
1714         if (from_item) {
1715                 from_ri = elm_object_item_data_get(from_item);
1716
1717                 debug_log("from_ri = %s", from_ri->email_list[0].email_addr);
1718         }
1719
1720         debug_log("add_my_address_to_bcc = %d, %d", ugd->account_info->account->options.add_my_address_to_bcc, ugd->account_info->account_list[set_val].options.add_my_address_to_bcc);
1721
1722         debug_log("remove bcc myself if it is");
1723         Elm_Object_Item *bcc_item = NULL;
1724         bcc_item = elm_multibuttonentry_first_item_get(ugd->bcc_mbe);
1725
1726         while (bcc_item) {
1727                 EmailRecpInfo *bcc_ri = NULL;
1728                 int index = 0;
1729
1730                 bcc_ri = (EmailRecpInfo *) elm_object_item_data_get(bcc_item);
1731
1732                 index = bcc_ri->selected_email_idx;
1733
1734                 debug_log("bcc_ri email_addr = %s, from_ri email_addr = %s, is_always_bcc = %d", bcc_ri->email_list[index].email_addr, from_ri->email_list[0].email_addr, bcc_ri->is_always_bcc);
1735
1736                 if ((g_strcmp0(bcc_ri->email_list[index].email_addr, from_ri->email_list[0].email_addr) == 0) && (bcc_ri->is_always_bcc == true)) {
1737                         elm_object_item_del(bcc_item);
1738                         break;
1739                 }
1740
1741                 bcc_item = elm_multibuttonentry_item_next_get(bcc_item);
1742         }
1743
1744         debug_log("remove cc myself if it is");
1745         Elm_Object_Item *cc_item = NULL;
1746         cc_item = elm_multibuttonentry_first_item_get(ugd->cc_mbe);
1747
1748         while (cc_item) {
1749                 EmailRecpInfo *cc_ri = NULL;
1750                 int index = 0;
1751
1752                 cc_ri = (EmailRecpInfo *) elm_object_item_data_get(cc_item);
1753
1754                 index = cc_ri->selected_email_idx;
1755
1756                 debug_log("cc_ri email_addr = %s, from_ri email_addr = %s, is_always_bcc = %d", cc_ri->email_list[index].email_addr, from_ri->email_list[0].email_addr, cc_ri->is_always_bcc);
1757
1758                 if ((g_strcmp0(cc_ri->email_list[index].email_addr, from_ri->email_list[0].email_addr) == 0) && (cc_ri->is_always_bcc == true)) {
1759                         elm_object_item_del(cc_item);
1760                         break;
1761                 }
1762
1763                 cc_item = elm_multibuttonentry_item_next_get(cc_item);
1764         }
1765
1766         if (ugd->account_info->account_list[set_val].options.add_my_address_to_bcc == EMAIL_ADD_MY_ADDRESS_OPTION_ALWAYS_ADD_TO_BCC) {
1767                 debug_log("always bcc on");
1768                 EmailRecpInfo *new_bcc_ri = (EmailRecpInfo *) calloc(1, sizeof(EmailRecpInfo));
1769
1770                 new_bcc_ri->selected_email_idx = 0;
1771                 new_bcc_ri->display_name = ugd->account_info->account_list[set_val].user_display_name;
1772                 snprintf(new_bcc_ri->email_list[0].email_addr, MAX_RECIPIENT_ADDRESS_LEN, "%s", ugd->account_info->account_list[set_val].user_email_address);
1773                 new_bcc_ri->email_cnt = 1;
1774                 new_bcc_ri->is_contact_info = false;
1775                 new_bcc_ri->is_always_bcc = true;
1776                 new_bcc_ri->is_from_addr = false;
1777
1778                 bcc_item = elm_multibuttonentry_first_item_get(ugd->bcc_mbe);
1779                 elm_multibuttonentry_item_insert_before(ugd->bcc_mbe, bcc_item, g_strdup(new_bcc_ri->display_name), NULL, new_bcc_ri);
1780         } else if (ugd->account_info->account_list[set_val].options.add_my_address_to_bcc == EMAIL_ADD_MY_ADDRESS_OPTION_ALWAYS_ADD_TO_CC) {
1781                 debug_log("always cc on");
1782                 EmailRecpInfo *new_cc_ri = (EmailRecpInfo *) calloc(1, sizeof(EmailRecpInfo));
1783
1784                 new_cc_ri->selected_email_idx = 0;
1785                 new_cc_ri->display_name = ugd->account_info->account_list[set_val].user_display_name;
1786                 snprintf(new_cc_ri->email_list[0].email_addr, MAX_RECIPIENT_ADDRESS_LEN, "%s", ugd->account_info->account_list[set_val].user_email_address);
1787                 new_cc_ri->email_cnt = 1;
1788                 new_cc_ri->is_contact_info = false;
1789                 new_cc_ri->is_always_bcc = true;
1790                 new_cc_ri->is_from_addr = false;
1791
1792                 cc_item = elm_multibuttonentry_first_item_get(ugd->cc_mbe);
1793                 elm_multibuttonentry_item_insert_before(ugd->cc_mbe, cc_item, g_strdup(new_cc_ri->display_name), NULL, new_cc_ri);
1794         } else {
1795                 debug_log("always bcc/cc off");
1796         }
1797
1798         EmailRecpInfo *new_from_ri = (EmailRecpInfo *) calloc(1, sizeof(EmailRecpInfo));
1799
1800         new_from_ri->selected_email_idx = 0;
1801         new_from_ri->display_name = ugd->account_info->account_list[set_val].user_display_name;
1802         snprintf(new_from_ri->email_list[0].email_addr, MAX_RECIPIENT_ADDRESS_LEN, "%s", ugd->account_info->account_list[set_val].user_email_address);
1803         new_from_ri->email_cnt = 1;
1804         new_from_ri->is_contact_info = false;
1805         new_from_ri->is_always_bcc = false;
1806         new_from_ri->is_from_addr = true;
1807
1808         elm_object_item_del(from_item);
1809
1810         elm_multibuttonentry_item_append(ugd->from_mbe, g_strdup(new_from_ri->display_name), NULL, new_from_ri);
1811
1812         if (ugd->selected_entry == ugd->to_mbe_entry) {
1813                 elm_object_focus_set(ugd->to_mbe, EINA_TRUE);
1814         } else if (ugd->selected_entry == ugd->cc_mbe_entry) {
1815                 elm_object_focus_set(ugd->cc_mbe, EINA_TRUE);
1816         } else if (ugd->selected_entry == ugd->bcc_mbe_entry) {
1817                 elm_object_focus_set(ugd->bcc_mbe, EINA_TRUE);
1818         }
1819
1820         if (ugd->account_gen_list) {
1821                 elm_genlist_clear(ugd->account_gen_list);
1822
1823                 evas_object_del(ugd->account_gen_list);
1824                 ugd->account_gen_list = NULL;
1825         }
1826
1827         if (ugd->popup_list) {
1828                 debug_log("popup count = %d", eina_list_count(ugd->popup_list));
1829                 debug_log("composer_noti: %p", ugd->composer_noti);
1830
1831                 ugd->popup_list = eina_list_remove(ugd->popup_list, ugd->composer_noti);
1832         }
1833
1834         if (ugd->composer_noti) {
1835                 debug_log("@@@ ELM_POPUP_RESPONSE_CLOSE @@@");
1836                 _composer_popup_delete(ugd->composer_noti);
1837                 ugd->composer_noti = NULL;
1838         }
1839 }
1840
1841 static void _composer_from_radio_cb(void *data, Evas_Object *obj, void *event_info)
1842 {
1843         debug_log("");
1844
1845         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
1846         int i;
1847
1848         for (i = 0; i < ugd->account_info->account_count; i++) {
1849                 if (obj == ugd->account_info->account_rd[i]) {
1850                         debug_log("account_id = %d", ugd->account_info->account_list[i].account_id);
1851                         elm_radio_value_set(ugd->account_info->account_rdg, i);
1852                 }
1853         }
1854 }
1855
1856 void _composer_select_myemail_popup(EmailComposerUGD *ugd)
1857 {
1858         debug_log("");
1859
1860         int acc_index;
1861
1862         g_ugd = ugd;
1863
1864         if (ugd->composer_noti) {
1865                 evas_object_del(ugd->composer_noti);
1866                 ugd->composer_noti = NULL;
1867         }
1868         ugd->composer_noti = _composer_create_noti_with_list(ugd, false, _("IDS_EMAIL_HEADER_SELECT_EMAIL_ADDRESS"), NULL, 1, dgettext("sys_string", "IDS_COM_SK_OK"), NULL, 0.0, _composer_myemail_change_response_cb);
1869         elm_object_focus_set(ugd->composer_noti, EINA_TRUE);
1870
1871         myemail_itc.item_style = "email.2text.3icon.3";
1872         myemail_itc.func.text_get = _composer_myemail_gl_text_get;
1873         myemail_itc.func.content_get = _composer_myemail_gl_content_get;
1874         myemail_itc.func.state_get = NULL;
1875         myemail_itc.func.del = NULL;
1876
1877         elm_genlist_clear(ugd->account_gen_list);
1878         ugd->account_gen_list = elm_genlist_add(ugd->composer_noti);
1879         elm_object_theme_set(ugd->account_gen_list, ugd->th);
1880
1881         evas_object_size_hint_weight_set(ugd->account_gen_list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1882         evas_object_size_hint_align_set(ugd->account_gen_list, EVAS_HINT_FILL, EVAS_HINT_FILL);
1883
1884         for (acc_index = 0; acc_index < ugd->account_info->account_count; acc_index++) {
1885                 elm_genlist_item_append(ugd->account_gen_list, &myemail_itc, (void *)acc_index, NULL, ELM_GENLIST_ITEM_NONE, _composer_myemail_gl_sel, (void *)acc_index);
1886         }
1887
1888 #ifdef _POPUP_WITH_LIST
1889         debug_log("acc_index:%d", acc_index);
1890         if (acc_index > 5)
1891                 acc_index = 5;
1892         Evas_Object *box = elm_box_add(ugd->composer_noti);
1893         evas_object_size_hint_min_set(box, 610 * elm_config_scale_get(), 120 * acc_index * elm_config_scale_get());
1894         evas_object_show(ugd->account_gen_list);
1895         elm_box_pack_end(box, ugd->account_gen_list);
1896         elm_object_content_set(ugd->composer_noti, box);
1897 #else
1898         elm_object_content_set(ugd->composer_noti, ugd->account_gen_list);
1899 #endif
1900 }
1901
1902 char *_composer_myemail_gl_text_get(void *data, Evas_Object *obj, const char *part)
1903 {
1904         int index = (int)data;
1905
1906         debug_log("label index = %d", index);
1907
1908         if (!strncmp(part, "elm.text.1", 10)) {
1909                 debug_log("email_addr = %s", g_ugd->account_info->account_list[index].account_name);
1910                 return g_strdup(g_ugd->account_info->account_list[index].account_name);
1911         } else if (!strncmp(part, "elm.text.2", 10)) {
1912                 debug_log("email_addr = %s", g_ugd->account_info->account_list[index].user_email_address);
1913                 return g_strdup(g_ugd->account_info->account_list[index].user_email_address);
1914         } else {
1915                 debug_log("part is invalid");
1916         }
1917
1918         return NULL;
1919 }
1920
1921 Evas_Object *_composer_myemail_gl_content_get(void *data, Evas_Object *obj, const char *part)
1922 {
1923         int count = (int)data;
1924
1925         debug_log("count = %d", count);
1926         debug_log("account_id = %d", g_ugd->account_info->account_list[count].account_id);
1927         debug_log("default account_id = %d", g_ugd->account_info->account_id);
1928
1929         if (!strncmp(part, "elm.icon.1", 10)) {
1930                 g_ugd->account_info->account_rd[count] = elm_radio_add(obj);
1931                 elm_radio_state_value_set(g_ugd->account_info->account_rd[count], count);
1932
1933                 if (count == 0) {
1934                         g_ugd->account_info->account_rdg = g_ugd->account_info->account_rd[count];
1935                 } else
1936                         elm_radio_group_add(g_ugd->account_info->account_rd[count], g_ugd->account_info->account_rdg);
1937
1938                 if (g_ugd->account_info->account_list[count].account_id == g_ugd->account_info->account_id)
1939                         elm_radio_value_set(g_ugd->account_info->account_rdg, count);
1940
1941                 evas_object_smart_callback_add(g_ugd->account_info->account_rd[count], "changed", _composer_myemail_radio_cb, g_ugd);
1942
1943                 return g_ugd->account_info->account_rd[count];
1944         } else if (!strncmp(part, "elm.icon.2", 10)) {
1945                 Evas_Object *icon = elm_icon_add(obj);
1946
1947                 debug_log("logo_icon_path:%s", g_ugd->account_info->account_list[count].logo_icon_path);
1948                 if (g_ugd->account_info->account_list[count].logo_icon_path)
1949                         elm_image_file_set(icon, g_ugd->account_info->account_list[count].logo_icon_path, NULL);
1950                 else
1951                         elm_image_file_set(icon, ACCOUNT_ICON_OTHERS, NULL);
1952                 evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
1953
1954                 return icon;
1955         } else if (!strncmp(part, "elm.swallow.colorbar", 20)) {
1956                 account_user_data_t *ud = (account_user_data_t *)g_ugd->account_info->account_list[count].user_data;
1957                 unsigned int val = ud->index_color;
1958                 int r = (val & 0xff000000) >> 24;
1959                 int g = (val & 0x00ff0000) >> 16;
1960                 int b = (val & 0x0000ff00) >> 8;
1961                 int a = val & 0x000000ff;
1962
1963                 Evas_Object *color_bar = evas_object_rectangle_add(evas_object_evas_get(obj));
1964                 evas_object_size_hint_fill_set(color_bar, EVAS_HINT_FILL, EVAS_HINT_FILL);
1965                 evas_object_color_set(color_bar, r, g, b, a);
1966
1967                 return color_bar;
1968         } else {
1969                 debug_log("part is invalid");
1970         }
1971
1972         return NULL;
1973 }
1974
1975 static void _composer_myemail_gl_sel(void *data, Evas_Object *obj, void *event_info)
1976 {
1977         debug_log("index:%d", (int)data);
1978
1979         int index = (int)data;
1980
1981         elm_radio_value_set(g_ugd->account_info->account_rdg, index);
1982
1983         _composer_myemail_close_response_cb(g_ugd);
1984 }
1985
1986 static void _composer_myemail_change_response_cb(void *data, Evas_Object *obj, void *event_info)
1987 {
1988         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
1989
1990         debug_log("composer_noti : %p", ugd->composer_noti);
1991
1992         char *pszBtnText = (char *)elm_object_text_get(obj);
1993         debug_log("selected button text = %s", pszBtnText);
1994
1995         _composer_myemail_close_response_cb(ugd);
1996 }
1997
1998 static void _composer_myemail_close_response_cb(EmailComposerUGD *ugd)
1999 {
2000         debug_log("composer_noti : %p", ugd->composer_noti);
2001
2002         int set_val = elm_radio_value_get(ugd->account_info->account_rdg);
2003
2004         debug_log("set_val = %d", set_val);
2005         debug_log("account_id = %d", ugd->account_info->account_list[set_val].account_id);
2006
2007         elm_object_tree_focus_allow_set(ugd->c_layout, EINA_TRUE); // block the focus not to open IME.
2008
2009         EmailRecpInfo *new_to_ri = (EmailRecpInfo *) calloc(1, sizeof(EmailRecpInfo));
2010
2011         new_to_ri->selected_email_idx = 0;
2012         new_to_ri->display_name = ugd->account_info->account_list[set_val].user_display_name;
2013         snprintf(new_to_ri->email_list[0].email_addr, MAX_RECIPIENT_ADDRESS_LEN, "%s", ugd->account_info->account_list[set_val].user_email_address);
2014         new_to_ri->email_cnt = 1;
2015         new_to_ri->is_contact_info = false;
2016         new_to_ri->is_always_bcc = false;
2017         new_to_ri->is_from_addr = true;
2018         debug_log("my email_addr = %s, display_name = %s", new_to_ri->email_list[0].email_addr, new_to_ri->display_name);
2019
2020         elm_multibuttonentry_item_append(ugd->to_mbe, g_strdup(new_to_ri->display_name), NULL, new_to_ri);
2021
2022         if (ugd->selected_entry == ugd->to_mbe_entry) {
2023                 elm_object_focus_set(ugd->to_mbe, EINA_TRUE);
2024         } else if (ugd->selected_entry == ugd->cc_mbe_entry) {
2025                 elm_object_focus_set(ugd->cc_mbe, EINA_TRUE);
2026         } else if (ugd->selected_entry == ugd->bcc_mbe_entry) {
2027                 elm_object_focus_set(ugd->bcc_mbe, EINA_TRUE);
2028         }
2029
2030         if (ugd->account_gen_list) {
2031                 elm_genlist_clear(ugd->account_gen_list);
2032
2033                 evas_object_del(ugd->account_gen_list);
2034                 ugd->account_gen_list = NULL;
2035         }
2036
2037         if (ugd->popup_list) {
2038                 debug_log("popup count = %d", eina_list_count(ugd->popup_list));
2039                 debug_log("composer_noti: %p", ugd->composer_noti);
2040
2041                 ugd->popup_list = eina_list_remove(ugd->popup_list, ugd->composer_noti);
2042         }
2043
2044         if (ugd->composer_noti) {
2045                 debug_log("@@@ ELM_POPUP_RESPONSE_CLOSE @@@");
2046                 _composer_popup_delete(ugd->composer_noti);
2047                 ugd->composer_noti = NULL;
2048         }
2049 }
2050
2051 static void _composer_myemail_radio_cb(void *data, Evas_Object *obj, void *event_info)
2052 {
2053         debug_log("");
2054
2055         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
2056         int i;
2057
2058         for (i = 0; i < ugd->account_info->account_count; i++) {
2059                 if (obj == ugd->account_info->account_rd[i]) {
2060                         debug_log("account_id = %d", ugd->account_info->account_list[i].account_id);
2061                         elm_radio_value_set(ugd->account_info->account_rdg, i);
2062                 }
2063         }
2064 }
2065
2066 void _composer_cbar_cc_clicked(void *data, Evas_Object *obj, void *event_info)
2067 {
2068         debug_log("");
2069
2070         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
2071
2072         if(ugd->context_popup) {
2073                 evas_object_del(ugd->context_popup);
2074                 ugd->context_popup = NULL;
2075         }
2076
2077         elm_object_tree_focus_allow_set(ugd->c_layout, EINA_TRUE); // block the focus not to open IME.
2078
2079         if (ugd->cc_added) {
2080                 if (ugd->b_cc_bcc) {
2081                         debug_log("b_cc_bcc is ON");
2082                         return;
2083                 }
2084
2085                 edje_object_signal_emit(_EDJ(ugd->c_layout), "hide.cc", "*");
2086                 email_composer_delete_cc_field(ugd);
2087                 edje_object_signal_emit(_EDJ(ugd->c_layout), "hide.bcc", "*");
2088                 email_composer_delete_bcc_field(ugd);
2089                 elm_object_text_set(ugd->cc_btn, _("IDS_EMAIL_OPT_ADD_CC_BCC"));
2090
2091                 if (ugd->b_cc_ps_open == true) {
2092                         edje_object_signal_emit(_EDJ(ugd->c_layout), "show.to", "*");
2093                         ugd->b_cc_ps_open = false;
2094                 }
2095
2096                 ugd->b_cc_bcc = false;
2097
2098                 elm_layout_sizing_eval(ugd->c_layout);
2099
2100                 if (!_composer_check_popup_exist(ugd)) {
2101                         ugd->idler_set_focus = ecore_idler_add(_composer_mbe_set_focus, ugd);
2102                 }
2103         } else {
2104                 if (ugd->b_cc_bcc) {
2105                         debug_log("b_cc_bcc is ON");
2106                         return;
2107                 }
2108
2109                 if (ugd->clipboard_on) {
2110                         ugd->clipboard_on = false;
2111                 }
2112
2113                 edje_object_signal_emit(_EDJ(ugd->c_layout), "show.cc", "*");
2114                 email_composer_create_cc_field(ugd);
2115                 edje_object_signal_emit(_EDJ(ugd->c_layout), "show.bcc", "*");
2116                 email_composer_create_bcc_field(ugd);
2117                 elm_object_text_set(ugd->cc_btn, N_("Remove Cc/Bcc"));
2118
2119                 elm_layout_sizing_eval(ugd->c_layout);
2120
2121                 ugd->idler_set_focus = ecore_idler_add(_composer_cc_mbe_set_focus, ugd);
2122         }
2123 }
2124
2125 void _composer_cbar_send_myself_clicked(void *data, Evas_Object *obj, void *event_info)
2126 {
2127         debug_log("");
2128         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
2129
2130         if(ugd->context_popup) {
2131                 evas_object_del(ugd->context_popup);
2132                 ugd->context_popup = NULL;
2133         }
2134
2135         _composer_select_myemail_popup(ugd);
2136 }
2137
2138 static void _composer_cbar_save_as_draft_cb(Evas_Object *o, const char *result, void *data)
2139 {
2140         debug_log("");
2141         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
2142
2143         if (NULL != ugd->latest_html_content) {
2144                 g_free(ugd->latest_html_content);
2145                 ugd->latest_html_content = NULL;
2146         }
2147
2148         if (result != NULL) {
2149                 ugd->latest_html_content = g_strdup(result);
2150                 debug_log("ugd->latest_html_content => %s", ugd->latest_html_content);
2151         }
2152
2153         if (ugd->timeout_noti) {
2154                 debug_log("delete timeout_noti");
2155                 evas_object_del(ugd->timeout_noti);
2156                 ugd->timeout_noti = NULL;
2157         }
2158
2159         if (ugd->composer_noti) {
2160                 debug_log("delete composer_noti");
2161                 evas_object_del(ugd->composer_noti);
2162                 ugd->composer_noti = NULL;
2163         }
2164
2165         if (ugd->ps_list) {
2166                 debug_log("ps stop");
2167                 _composer_ps_stop(ugd);
2168                 ugd->sc_timer = ecore_timer_add(0.5, _composer_ps_scroll_pop, ugd);
2169         }
2170
2171         if (ugd->selected_entry == ugd->body_ewkview) {
2172                 evas_object_focus_set(ugd->body_ewkview, EINA_FALSE);
2173         } else {
2174                 Ecore_IMF_Context *imf_context = NULL;
2175                 imf_context = elm_entry_imf_context_get(ugd->selected_entry);
2176                 if (imf_context)
2177                         ecore_imf_context_input_panel_hide(imf_context);
2178         }
2179
2180         if (_composer_check_mail_is_modified(ugd)) {
2181                 debug_log("mail is changed.");
2182                 ugd->save_drafts = 1;
2183         } else {
2184                 debug_log("mail is NOT changed.");
2185                 ugd->save_drafts = 0;
2186
2187                 char str[128] = { 0, };
2188                 snprintf(str, sizeof(str), "%s", _("IDS_EMAIL_OPT_COMPOSE_EMAIL"));
2189                 int ret = status_message_post(str);
2190                 if (ret)
2191                         debug_log("status_message_post failed: %d", ret);
2192
2193                 elm_object_tree_focus_allow_set(ugd->c_layout, EINA_TRUE); // block the focus not to open IME.
2194                 _composer_webkit_set_body_script(ugd);
2195                 if (ewk_view_script_execute(ugd->body_ewkview, COMPOSER_JS_ENABLE_EDITABLE, _composer_script_executed_cb, ugd) == EINA_FALSE)
2196                         debug_log("COMPOSER_JS_ENABLE_EDITABLE failed.");
2197                 return;
2198         }
2199
2200         if (ugd->need_download == EINA_TRUE) {
2201                 _composer_download_attachment(ugd);
2202         } else {
2203                 _composer_save_draft_mail(ugd);
2204         }
2205 }
2206
2207 void _composer_cbar_save_as_draft_clicked(void *data, Evas_Object *obj, void *event_info)
2208 {
2209         debug_log("");
2210
2211         if (!data) {
2212                 debug_log("data is NULL");
2213                 return;
2214         }
2215
2216         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
2217
2218         if(ugd->context_popup) {
2219                 evas_object_del(ugd->context_popup);
2220                 ugd->context_popup = NULL;
2221         }
2222
2223         if (EINA_FALSE == ewk_view_script_execute(ugd->body_ewkview, COMPOSER_JS_GET_LATEST_INFO_CONTENT, _composer_get_latest_info_content_cb, (void *)ugd))
2224                 debug_log("COMPOSER_JS_GET_ORIGINAL_INFO_CONTENT failed.");
2225
2226         if (EINA_FALSE == ewk_view_script_execute(ugd->body_ewkview, COMPOSER_JS_GET_LATEST_HTML_CONTENT, _composer_get_latest_html_content_cb, (void *)ugd))
2227                 debug_log("COMPOSER_JS_GET_ORIGINAL_HTML_CONTENT failed.");
2228
2229         if (EINA_FALSE == ewk_view_plain_text_get(ugd->body_ewkview, _composer_plain_text_get_cb, (void *)ugd))
2230                 debug_log("ewk_view_plain_text_get Failed");
2231
2232         if (EINA_FALSE == ewk_view_script_execute(ugd->body_ewkview, COMPOSER_JS_GET_IMAGE_LIST, _composer_get_image_list_cb, (void *)ugd))
2233                 debug_log("COMPOSER_JS_GET_IMAGE_LIST error.");
2234
2235         if (EINA_FALSE == ewk_view_script_execute(ugd->body_ewkview, COMPOSER_JS_GET_LATEST_HTML_CONTENT, _composer_cbar_save_as_draft_cb, (void *)ugd))
2236                 debug_log("COMPOSER_JS_GET_HTML_CONTENT failed.");
2237 }
2238
2239 static void _composer_priority_radio_cb(void *data, Evas_Object *obj, void *event_info)
2240 {
2241         debug_log("");
2242
2243         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
2244         int i;
2245
2246         for (i = 0; i < 3; i++) {
2247                 if (obj == ugd->priority_rd[i]) {
2248                         elm_radio_value_set(ugd->priority_rdg, i);
2249                 }
2250         }
2251 }
2252
2253 static char *_composer_priority_gl_text_get(void *data, Evas_Object *obj, const char *part)
2254 {
2255         int index = (int)data;
2256
2257         debug_log("\n text index = %d", index);
2258
2259         if (!g_strcmp0(part, "elm.text")) {
2260                 if (index == 0)
2261                         return strdup(_("IDS_EMAIL_BODY_HIGH_M_PRIORITY"));
2262                 else if (index == 1)
2263                         return strdup(_("IDS_EMAIL_BODY_NORMAL_M_EMAILPRIORITY"));
2264                 else if (index == 2)
2265                         return strdup(_("IDS_EMAIL_BODY_LOW_M_EMAILPRIORITY"));
2266         }
2267         return NULL;
2268 }
2269
2270 static Evas_Object *_composer_priority_gl_content_get(void *data, Evas_Object *obj, const char *part)
2271 {
2272         int index = (int)data;
2273
2274         debug_log("\n content index = %d", index);
2275
2276         if (!strcmp(part, "elm.icon") || !strcmp(part, "elm.swallow.icon")) {
2277                 g_ugd->priority_rd[index] = elm_radio_add(obj);
2278                 elm_radio_state_value_set(g_ugd->priority_rd[index], index);
2279
2280                 if (index == 0) {
2281                         g_ugd->priority_rdg = g_ugd->priority_rd[index];
2282                 } else {
2283                         elm_radio_group_add(g_ugd->priority_rd[index], g_ugd->priority_rdg);
2284                 }
2285
2286                 if (g_ugd->priority_option == EMAIL_MAIL_PRIORITY_HIGH) {
2287                         elm_radio_value_set(g_ugd->priority_rdg, 0);
2288                 } else if ( g_ugd->priority_option == EMAIL_MAIL_PRIORITY_NORMAL) {
2289                         elm_radio_value_set(g_ugd->priority_rdg, 1);
2290                 } else if ( g_ugd->priority_option == EMAIL_MAIL_PRIORITY_LOW) {
2291                         elm_radio_value_set(g_ugd->priority_rdg, 2);
2292                 } else {
2293                         debug_log("\n g_ugd->priority_option4 = %d", g_ugd->priority_option);
2294                 }
2295
2296                 evas_object_smart_callback_add(g_ugd->priority_rd[index], "changed", _composer_priority_radio_cb, g_ugd);
2297
2298                 return g_ugd->priority_rd[index];
2299         }
2300
2301         return NULL;
2302 }
2303
2304 static Eina_Bool _composer_priority_gl_state_get(void *data, Evas_Object *obj, const char *part)
2305 {
2306         debug_log("");
2307         return EINA_FALSE;
2308 }
2309
2310 static void _composer_priority_gl_del(void *data, Evas_Object *obj)
2311 {
2312         debug_log("");
2313         return;
2314 }
2315
2316 static void _composer_priority_gl_sel(void *data, Evas_Object *obj, void *event_info)
2317 {
2318         int index = (int)data;
2319
2320         elm_radio_value_set(g_ugd->priority_rdg, index);
2321
2322         if (index == 0) {
2323                 g_ugd->priority_option = EMAIL_MAIL_PRIORITY_HIGH;
2324         } else if (index == 1) {
2325                 g_ugd->priority_option = EMAIL_MAIL_PRIORITY_NORMAL;
2326         } else if (index == 2) {
2327                 g_ugd->priority_option = EMAIL_MAIL_PRIORITY_LOW;
2328         } else {
2329                 debug_log("\n g_ugd->priority_option = %d", g_ugd->priority_option);
2330         }
2331         debug_log("\n _composer_priority_gl_sel : priority_option = %d", g_ugd->priority_option);
2332
2333         if (g_ugd->composer_noti) {
2334                 evas_object_del(g_ugd->composer_noti);
2335                 g_ugd->composer_noti = NULL;
2336         }
2337 }
2338
2339 void _composer_cbar_priority_clicked(void *data, Evas_Object *obj, void *event_info)
2340 {
2341         debug_log("");
2342
2343         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
2344         Elm_Object_Item *gen_item[3];
2345         int index;
2346
2347         if(ugd->context_popup) {
2348                 evas_object_del(ugd->context_popup);
2349                 ugd->context_popup = NULL;
2350         }
2351
2352         g_ugd = ugd;
2353
2354         Evas_Object *popup;
2355
2356         if (ugd->composer_noti) {
2357                 evas_object_del(ugd->composer_noti);
2358                 ugd->composer_noti = NULL;
2359         }
2360         popup = _composer_create_noti_with_list(ugd, false, _("IDS_EMAIL_BODY_PRIORITY"), NULL, 1,
2361                 dgettext("sys_string", "IDS_COM_POP_CLOSE"), NULL, 0.0, _composer_noti_response_cb);
2362
2363         ugd->composer_noti = popup;
2364         elm_object_focus_set(popup, EINA_TRUE);
2365
2366         if (ugd->clipboard_on) {
2367                 ugd->clipboard_on = false;
2368         }
2369
2370         if (ugd->cc_added) {
2371                 if (ugd->b_cc_ps_open == true) {
2372                         edje_object_signal_emit(_EDJ(ugd->c_layout), "show.to", "*");
2373                         ugd->b_cc_ps_open = false;
2374                 }
2375         }
2376
2377         if (ugd->b_bcc_ps_open == true) {
2378                 edje_object_signal_emit(_EDJ(ugd->c_layout), "show.to", "*");
2379
2380                 if (ugd->cc_added) {
2381                         edje_object_signal_emit(_EDJ(ugd->c_layout), "show.cc", "*");
2382                 }
2383
2384                 ugd->b_bcc_ps_open = false;
2385         }
2386
2387         priority_itc.item_style = "1text.1icon.2";
2388         priority_itc.func.text_get = _composer_priority_gl_text_get;
2389         priority_itc.func.content_get = _composer_priority_gl_content_get;
2390         priority_itc.func.state_get = _composer_priority_gl_state_get;
2391         priority_itc.func.del = _composer_priority_gl_del;
2392
2393         Evas_Object *priority_genlist;
2394         priority_genlist = elm_genlist_add(ugd->composer_noti);
2395
2396         evas_object_size_hint_weight_set(priority_genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2397         evas_object_size_hint_align_set(priority_genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
2398
2399         for (index = 0; index < 3; index++) {
2400                 gen_item[index] = elm_genlist_item_append(priority_genlist, &priority_itc, (void *)index, NULL, ELM_GENLIST_ITEM_NONE, _composer_priority_gl_sel, (void *)index);
2401         }
2402
2403 #ifdef _POPUP_WITH_LIST
2404         Evas_Object *box = elm_box_add(ugd->composer_noti);
2405         evas_object_size_hint_min_set(box, 610 * elm_config_scale_get(), 113 * index * elm_config_scale_get());
2406         evas_object_show(priority_genlist);
2407         elm_box_pack_end(box, priority_genlist);
2408         elm_object_content_set(ugd->composer_noti, box);
2409 #else
2410         elm_object_content_set(ugd->composer_noti, priority_genlist);
2411 #endif
2412
2413 }
2414
2415 static char *_composer_tracking_gl_text_get(void *data, Evas_Object *obj, const char *part)
2416 {
2417         int index = (int)data;
2418
2419         debug_log("\n text index = %d", index);
2420
2421         if (!g_strcmp0(part, "elm.text")) {
2422                 if (index == 0)
2423                         return strdup(N_("Read report"));
2424                 else if (index == 1)
2425                         return strdup(N_("Delivery report"));
2426         }
2427         return NULL;
2428 }
2429
2430 static Evas_Object *_composer_tracking_gl_content_get(void *data, Evas_Object *obj, const char *part)
2431 {
2432         int index = (int)data;
2433
2434         debug_log("\n content index = %d", index);
2435
2436         if (!strcmp(part, "elm.icon") || !strcmp(part, "elm.swallow.icon")) {
2437                 Evas_Object *check = elm_check_add(obj);
2438
2439                 if (index == 0 && g_ugd->tracking_option[0] == 1) {
2440                         debug_log("Read report");
2441                         elm_check_state_set(check, EINA_TRUE);
2442                 } else if (index == 1 && g_ugd->tracking_option[1] == 1) {
2443                         debug_log("Delivery report");
2444                         elm_check_state_set(check, EINA_TRUE);
2445                 } else {
2446                         debug_log("NONE");
2447                         elm_check_state_set(check, EINA_FALSE);
2448                 }
2449
2450                 evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2451                 evas_object_size_hint_align_set(check, EVAS_HINT_FILL, EVAS_HINT_FILL);
2452
2453                 return check;
2454         }
2455
2456         return NULL;
2457 }
2458
2459 static Eina_Bool _composer_tracking_gl_state_get(void *data, Evas_Object *obj, const char *part)
2460 {
2461         debug_log("");
2462         return EINA_FALSE;
2463 }
2464
2465 static void _composer_tracking_gl_del(void *data, Evas_Object *obj)
2466 {
2467         debug_log("");
2468         return;
2469 }
2470
2471 static void _composer_tracking_gl_sel(void *data, Evas_Object *obj, void *event_info)
2472 {
2473         int index;
2474         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
2475
2476         debug_log("\nsel index = %d", (int)data);
2477
2478         if (item != NULL) {
2479                 index = (int)elm_object_item_data_get(item);
2480                 elm_genlist_item_selected_set(item, EINA_FALSE);
2481
2482                 debug_log("tracking_option[%d]:%d, !tracking_option[%d]:%d", index, g_ugd->tracking_option[index], index, !g_ugd->tracking_option[index]);
2483                 g_ugd->tracking_option[index] = !g_ugd->tracking_option[index];
2484
2485                 elm_genlist_item_update(item);
2486         }
2487 }
2488
2489 void _composer_cbar_tracking_clicked(void *data, Evas_Object *obj, void *event_info)
2490 {
2491         debug_log("");
2492
2493         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
2494         Elm_Object_Item *gen_item[2];
2495         int index;
2496
2497         if(ugd->context_popup) {
2498                 evas_object_del(ugd->context_popup);
2499                 ugd->context_popup = NULL;
2500         }
2501
2502         g_ugd = ugd;
2503
2504         Evas_Object *popup;
2505
2506         if (ugd->composer_noti) {
2507                 evas_object_del(ugd->composer_noti);
2508                 ugd->composer_noti = NULL;
2509         }
2510         popup = _composer_create_noti_with_list(ugd, false, _("IDS_EMAIL_OPT_TRACKING"), NULL, 1,
2511                 dgettext("sys_string", "IDS_COM_POP_CLOSE"), NULL, 0.0, _composer_noti_response_cb);
2512
2513         ugd->composer_noti = popup;
2514         elm_object_focus_set(popup, EINA_TRUE);
2515
2516         if (ugd->clipboard_on) {
2517                 ugd->clipboard_on = false;
2518         }
2519
2520         if (ugd->cc_added) {
2521                 if (ugd->b_cc_ps_open == true) {
2522                         edje_object_signal_emit(_EDJ(ugd->c_layout), "show.to", "*");
2523                         ugd->b_cc_ps_open = false;
2524                 }
2525         }
2526
2527         if (ugd->b_bcc_ps_open == true) {
2528                 edje_object_signal_emit(_EDJ(ugd->c_layout), "show.to", "*");
2529
2530                 if (ugd->cc_added) {
2531                         edje_object_signal_emit(_EDJ(ugd->c_layout), "show.cc", "*");
2532                 }
2533
2534                 ugd->b_bcc_ps_open = false;
2535         }
2536
2537         tracking_itc.item_style = "1text.1icon.2";
2538         tracking_itc.func.text_get = _composer_tracking_gl_text_get;
2539         tracking_itc.func.content_get = _composer_tracking_gl_content_get;
2540         tracking_itc.func.state_get = _composer_tracking_gl_state_get;
2541         tracking_itc.func.del = _composer_tracking_gl_del;
2542
2543         Evas_Object *tracking_genlist;
2544         tracking_genlist = elm_genlist_add(ugd->composer_noti);
2545
2546         evas_object_size_hint_weight_set(tracking_genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2547         evas_object_size_hint_align_set(tracking_genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
2548
2549         for (index = 0; index < 2; index++) {
2550                 gen_item[index] = elm_genlist_item_append(tracking_genlist, &tracking_itc, (void *)index, NULL, ELM_GENLIST_ITEM_NONE, _composer_tracking_gl_sel, (void *)index);
2551         }
2552
2553 #ifdef _POPUP_WITH_LIST
2554         Evas_Object *box = elm_box_add(ugd->composer_noti);
2555         evas_object_size_hint_min_set(box, 610 * elm_config_scale_get(), 113 * index * elm_config_scale_get());
2556         evas_object_show(tracking_genlist);
2557         elm_box_pack_end(box, tracking_genlist);
2558         elm_object_content_set(ugd->composer_noti, box);
2559 #else
2560         elm_object_content_set(ugd->composer_noti, tracking_genlist);
2561 #endif
2562 }
2563
2564 void _composer_cbar_send_clicked(void *data, Evas_Object *obj, void *event_info)
2565 {
2566         debug_log("");
2567
2568         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
2569
2570         if(ugd->context_popup) {
2571                 evas_object_del(ugd->context_popup);
2572                 ugd->context_popup = NULL;
2573         }
2574
2575         if (_composer_check_recipient_is_empty(ugd)) {
2576                 if (ugd->composer_noti) {
2577                         evas_object_del(ugd->composer_noti);
2578                         ugd->composer_noti = NULL;
2579                 }
2580                 ugd->composer_noti = _composer_create_noti(ugd, false, dgettext("sys_string", "IDS_COM_POP_WARNING"),
2581                         _("IDS_EMAIL_POP_NO_RECIPIENTS_ADDED_ENTER_RECIPIENTS"), 0, NULL, NULL, 1.5, _composer_fail_to_send_popup_cb);
2582
2583                 return;
2584         }
2585
2586         debug_log("Send Button Clicked");
2587         elm_object_tree_focus_allow_set(ugd->c_layout, EINA_FALSE); // block the focus not to open IME.
2588
2589         if (ugd->fw_attach_cnt > 0) {
2590                 if (ugd->fw_attach_cnt != g_list_length(ugd->fw_attachment_list)) {
2591                         if (ugd->account_info->account_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC) {
2592                                 ugd->need_download = EINA_TRUE;
2593                         }
2594                 } else {
2595                         if (ugd->account_info->account_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC) {
2596                                 ugd->need_download = EINA_FALSE;
2597                         }
2598                 }
2599         }
2600
2601         if (EINA_FALSE == ewk_view_script_execute(ugd->body_ewkview, COMPOSER_JS_GET_LATEST_INFO_CONTENT, _composer_get_latest_info_content_cb, (void *)ugd))
2602                 debug_log("COMPOSER_JS_GET_ORIGINAL_INFO_CONTENT failed.");
2603
2604         if (EINA_FALSE == ewk_view_script_execute(ugd->body_ewkview, COMPOSER_JS_GET_LATEST_HTML_CONTENT, _composer_get_latest_html_content_cb, (void *)ugd))
2605                 debug_log("COMPOSER_JS_GET_ORIGINAL_HTML_CONTENT failed.");
2606
2607         if (EINA_FALSE == ewk_view_plain_text_get(ugd->body_ewkview, _composer_plain_text_get_cb, (void *)ugd))
2608                 debug_log("ewk_view_plain_text_get Failed");
2609
2610         if (EINA_FALSE == ewk_view_script_execute(ugd->body_ewkview, COMPOSER_JS_GET_IMAGE_LIST, _composer_get_image_list_cb, (void *)ugd))
2611                 debug_log("COMPOSER_JS_GET_IMAGE_LIST error.");
2612
2613         debug_log("selected_entry = %x, to_mbe_entry = %x, cc_mbe_entry = %x, bcc_mbe_entry = %x, subject_entry = %x, body_ewkview = %x",
2614                 ugd->selected_entry, ugd->to_mbe_entry, ugd->cc_mbe_entry, ugd->bcc_mbe_entry, ugd->subject_entry, ugd->body_ewkview);
2615
2616         elm_object_disabled_set(ugd->send_btn, EINA_TRUE);
2617         elm_object_disabled_set(ugd->cancel_btn, EINA_TRUE);
2618         elm_object_disabled_set(ugd->send_btm_btn, EINA_TRUE);
2619         elm_object_disabled_set(ugd->cancel_btm_btn, EINA_TRUE);
2620
2621         if (!ugd->b_sending)
2622                 ugd->b_sending = true;
2623
2624         if (ugd->need_download == EINA_TRUE) {
2625                 _composer_download_attachment(ugd);
2626         } else {
2627                 ugd->bSendBtnDisabled = true;
2628                 ugd->send_timer = ecore_timer_add(0.5, _composer_send_mail_cb, ugd);
2629         }
2630 }
2631
2632 static Eina_Bool _composer_cc_mbe_set_focus(void *data)
2633 {
2634         debug_log("");
2635
2636         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
2637
2638         if (ugd->idler_set_focus) {
2639                 ecore_idler_del(ugd->idler_set_focus);
2640                 ugd->idler_set_focus = NULL;
2641         }
2642
2643         elm_object_focus_set(ugd->cc_mbe, EINA_TRUE);
2644
2645         ugd->b_cc_bcc = false;
2646
2647         return EINA_FALSE;
2648 }
2649
2650 void _composer_script_executed_cb(Evas_Object *o, const char *result, void *data)
2651 {
2652         debug_log("");
2653         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
2654
2655         if (ugd) {
2656                 _composer_mbe_set_focus(ugd);
2657         }
2658 }
2659
2660 void _composer_focus_script_executed_cb(Evas_Object *o, const char *result, void *data)
2661 {
2662         debug_log("");
2663 }
2664
2665 Eina_Bool _composer_get_html_content_for_draft_cb(void *data)
2666 {
2667         debug_enter();
2668
2669         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
2670
2671         elm_object_disabled_set(ugd->cancel_btn, EINA_FALSE); // It prevents clicking the cancel button several times
2672         elm_object_disabled_set(ugd->cancel_btm_btn, EINA_FALSE);
2673         if (EINA_FALSE == ewk_view_plain_text_get(ugd->body_ewkview, _composer_plain_text_get_cb, (void *)ugd)) {
2674                 debug_log("ewk_view_plain_text_get Failed");
2675         }
2676
2677         if (EINA_FALSE == ewk_view_script_execute(ugd->body_ewkview, COMPOSER_JS_GET_IMAGE_LIST, _composer_get_image_list_cb, (void *)ugd)) {
2678                 debug_log("COMPOSER_JS_GET_IMAGE_LIST error.");
2679         }
2680
2681         if (ugd->timeout_noti) {
2682                 debug_log("delete timeout_noti");
2683                 evas_object_del(ugd->timeout_noti);
2684                 ugd->timeout_noti = NULL;
2685         }
2686
2687         if (ugd->composer_noti) {
2688                 debug_log("delete composer_noti");
2689                 evas_object_del(ugd->composer_noti);
2690                 ugd->composer_noti = NULL;
2691         }
2692
2693         if (ugd->ps_list) {
2694                 debug_log("ps stop");
2695                 _composer_ps_stop(ugd);
2696                 ugd->sc_timer = ecore_timer_add(0.5, _composer_ps_scroll_pop, ugd);
2697         }
2698
2699         if (ugd->selected_entry == ugd->body_ewkview) {
2700                 evas_object_focus_set(ugd->body_ewkview, EINA_FALSE);
2701         } else {
2702                 Ecore_IMF_Context *imf_context = NULL;
2703                 imf_context = elm_entry_imf_context_get(ugd->selected_entry);
2704                 if (imf_context)
2705                         ecore_imf_context_input_panel_hide(imf_context);
2706         }
2707
2708         if (_composer_check_mail_is_modified(ugd)) {
2709                 debug_log("mail is changed.");
2710                 ugd->save_drafts = 1;
2711         } else {
2712                 debug_log("mail is NOT changed.");
2713                 ugd->save_drafts = 0;
2714         }
2715
2716         if (ugd->save_drafts) {
2717                 ugd->composer_noti = _composer_create_popup(ugd, false, NULL, dgettext("sys_string", "IDS_COM_POP_SAVE_TO_DRAFTS_Q"), 3,
2718                         dgettext("sys_string", "IDS_COM_SK_YES"), dgettext("sys_string", "IDS_COM_SK_NO"), dgettext("sys_string", "IDS_COM_SK_CANCEL"), 0.0, _composer_save_popup_response_cb);
2719         } else {
2720                 if (elm_multibuttonentry_first_item_get(ugd->to_mbe))
2721                         elm_multibuttonentry_clear(ugd->to_mbe);
2722                 if (elm_multibuttonentry_first_item_get(ugd->cc_mbe))
2723                         elm_multibuttonentry_clear(ugd->cc_mbe);
2724                 if (elm_multibuttonentry_first_item_get(ugd->bcc_mbe))
2725                         elm_multibuttonentry_clear(ugd->bcc_mbe);
2726
2727                 ug_destroy_me(ugd->ug_main);
2728         }
2729
2730         if (ugd->bringin_timer) {
2731                 ecore_timer_del(ugd->bringin_timer);
2732                 ugd->bringin_timer = NULL;
2733         }
2734
2735         return ECORE_CALLBACK_CANCEL;
2736 }
2737
2738 void _composer_get_latest_info_content_cb(Evas_Object *o, const char *result, void *data)
2739 {
2740         debug_log("");
2741         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
2742         debug_log("result: \n%s", result);
2743
2744         if (NULL != ugd->latest_info_content) {
2745                 g_free(ugd->latest_info_content);
2746                 ugd->latest_info_content = NULL;
2747         }
2748
2749         if (result != NULL) {
2750                 ugd->latest_info_content = g_strdup(result);
2751                 debug_log("ugd->latest_info_content : \n%s", ugd->latest_info_content);
2752         }
2753 }
2754
2755 static void _composer_get_latest_html_content_cb(Evas_Object *o, const char *result, void *data)
2756 {
2757         debug_log("");
2758         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
2759         debug_log("result: \n%s", result);
2760
2761         if (NULL != ugd->latest_html_content) {
2762                 g_free(ugd->latest_html_content);
2763                 ugd->latest_html_content = NULL;
2764         }
2765
2766         if (result != NULL) {
2767                 ugd->latest_html_content = g_strdup(result);
2768                 debug_log("ugd->latest_html_content : \n%s", ugd->latest_html_content);
2769         }
2770 }
2771
2772 static void _composer_plain_text_get_cb(Evas_Object *o, const char *plain_text, void *user_data)
2773 {
2774         debug_log("");
2775
2776         EmailComposerUGD *ugd = (EmailComposerUGD *) user_data;
2777
2778         if (NULL != ugd->plain_content) {
2779                 g_free(ugd->plain_content);
2780                 ugd->plain_content = NULL;
2781         }
2782
2783         ugd->plain_content = g_strdup(plain_text);
2784         debug_log("ugd->plain_content => %s", ugd->plain_content);
2785 }
2786
2787 void _composer_get_image_list_cb(Evas_Object *o, const char *result, void *data)
2788 {
2789         debug_log("");
2790
2791         char *list = NULL;
2792         EmailComposerUGD *ugd = (EmailComposerUGD *) data;
2793
2794         if (ugd->listOfImageUrls) {
2795                 eina_list_free(ugd->listOfImageUrls);
2796                 ugd->listOfImageUrls = NULL;
2797         }
2798
2799         if (result != NULL) {
2800                 debug_log("listOFImageUrls => %s", result);
2801                 list = g_strdup(result);
2802
2803                 char *token = strtok(list, ",");
2804                 while (token != NULL) {
2805                         if (token) {
2806                                 ugd->listOfImageUrls = eina_list_append(ugd->listOfImageUrls, token);
2807                                 token = strtok(NULL, ",");
2808                         }
2809                 }
2810         }
2811 }