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