Fix N_SE-24338, mms draft message issue
[apps/core/preloaded/message-app.git] / composer / src / ui-composer / msg-ui-composer-body-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://floralicense.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
18  /* includes */
19 #include "msg-ui-composer-body.h"
20 #include "msg-ui-composer-recipient.h"
21 #include "msg-ui-composer-main.h"
22 #include "msg-ui-composer-body-page.h"
23 #include "msg-ui-composer-body-callback.h"
24 #include "msg-ui-composer-common.h"
25 #include "msg-ui-composer-attachment.h"
26 #include "msg-ui-composer-subject.h"
27 #include "msg-ui-composer-message.h"
28 #include "msg-ui-composer-popup.h"
29 #include "msg-ui-composer-util.h"
30 #include "msg-ui-composer-external.h"
31 #include "syspopup_caller.h"
32 #include <tapi_common.h>
33 #include <ITapiModem.h>
34
35
36 /*==================================================================================================
37 *                                                               FUNCTION IMPLEMENTATIONS
38 *==================================================================================================*/
39 static void __add_list_popup_clicked_cb(void *data, Evas_Object *obj, void *event_info)
40 {
41         D_ENTER;
42
43         if (!data || !event_info) {
44                 D_EMSG("invalid argument, argument data is NULL");
45                 return;
46         }
47
48         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
49
50         if (cd->add_menu_clicked)
51                 return;
52
53         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
54         elm_list_item_selected_set(item, EINA_FALSE);
55
56         const char *label = elm_object_item_text_get(item);
57         if (!label) {
58                 D_EMSG("label is NULL !!");
59                 return;
60         }
61
62         cd->add_menu_clicked = true;
63
64         MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "label = %s", label);
65         if (cd->isAppControl && cd->isEmulator) {
66                 if (!g_strcmp0(label, MSGC_STR_SUBJECT)) {
67                         msg_ui_composer_add_subject(cd);
68                 } else {
69                         D_EMSG("Unknown Menu List Item");
70                 }
71         } else {
72                 if (!g_strcmp0(label, MSGC_STR_SUBJECT)) {
73                         msg_ui_composer_add_subject(cd);
74                 } else if (!g_strcmp0(label, MSGC_STR_GALLERY)) {
75                         msg_ui_composer_external_call(cd, COMPOSER_EXT_TYPE_GALLERY, NULL);
76                 } else if (!g_strcmp0(label, MSGC_STR_MYFILE)) {
77                         msg_ui_composer_external_call(cd, COMPOSER_EXT_TYPE_MYFILE, NULL);
78                 } else if (!g_strcmp0(label, _MSGSTR("IDS_MSGC_BODY_TAKE_PICTURE"))) {
79                         msg_ui_composer_external_call(cd, COMPOSER_EXT_TYPE_CAMERA, NULL);
80                 } else if (!g_strcmp0(label, _MSGSTR("IDS_MSGC_BODY_CAPTURE_VIDEO"))) {
81                         msg_ui_composer_external_call(cd, COMPOSER_EXT_TYPE_CAMCORDER, NULL);
82                 } else if (!g_strcmp0(label, MSGC_STR_CONTACT)) {
83                         msg_ui_composer_external_call(cd, COMPOSER_EXT_TYPE_NAMECARD, NULL);
84                 } else if (!g_strcmp0(label, _SYSSTR("IDS_COM_BODY_CALENDAR"))) {
85                         msg_ui_composer_external_call(cd, COMPOSER_EXT_TYPE_CALENDAR, NULL);
86                 } else if (!g_strcmp0(label, _SYSSTR("IDS_COM_BODY_MEMO"))) {
87                         msg_ui_composer_external_call(cd, COMPOSER_EXT_TYPE_MEMO, NULL);
88                 } else {
89                         D_EMSG("Unknown Menu List Item");
90                 }
91         }
92
93         MSGC_EVAS_OBJECT_DEL(cd->add_popup);
94         cd->add_button_clicked = false;
95         cd->add_menu_clicked = false;
96         D_LEAVE;
97 }
98
99 static void __add_list_popup_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
100 {
101         D_ENTER;
102
103         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
104         D_MSG_RETM_IF(cd == NULL, "composer data is NULL");
105         MSGC_EVAS_OBJECT_DEL(cd->add_popup);
106         cd->add_button_clicked = false;
107         cd->add_menu_clicked = false;
108
109         D_LEAVE;
110 }
111
112 static void __add_list_popup_show(void *data)
113 {
114         D_ENTER;
115
116         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
117         Evas_Object *popup = NULL;
118         Evas_Object *list = NULL;
119         int count = 0;
120         int list_padding = 4;
121
122
123         list = elm_list_add(cd->main_window);
124         D_MSG_RETM_IF(list == NULL, "list is NULL");
125         elm_list_mode_set(list, ELM_LIST_EXPAND);
126
127         Elm_Object_Item *item = NULL;
128
129         if (cd->isAppControl && cd->isEmulator) {
130                 item = elm_list_item_append(list, MSGC_STR_SUBJECT, NULL, NULL, __add_list_popup_clicked_cb, data);
131                 ++count;
132
133                 if (cd->isSubject)
134                         elm_object_item_disabled_set(item, EINA_TRUE);
135         } else {
136                 if (!cd->isSubject) {
137                         elm_list_item_append(list, MSGC_STR_SUBJECT, NULL, NULL, __add_list_popup_clicked_cb, data);
138                         ++count;
139                 }
140
141                 elm_list_item_append(list, MSGC_STR_GALLERY, NULL, NULL, __add_list_popup_clicked_cb, data);
142                 ++count;
143                 elm_list_item_append(list, _MSGSTR("IDS_MSGC_BODY_TAKE_PICTURE"), NULL, NULL, __add_list_popup_clicked_cb, data);
144                 ++count;
145                 elm_list_item_append(list, _MSGSTR("IDS_MSGC_BODY_CAPTURE_VIDEO"), NULL, NULL, __add_list_popup_clicked_cb, data);
146                 ++count;
147                 elm_list_item_append(list, MSGC_STR_MYFILE, NULL, NULL, __add_list_popup_clicked_cb, data);
148                 ++count;
149                 elm_list_item_append(list, MSGC_STR_CONTACT, NULL, NULL, __add_list_popup_clicked_cb, data);
150                 ++count;
151                 elm_list_item_append(list, _SYSSTR("IDS_COM_BODY_CALENDAR"), NULL, NULL, __add_list_popup_clicked_cb, data);
152                 ++count;
153                 elm_list_item_append(list, _SYSSTR("IDS_COM_BODY_MEMO"), NULL, NULL, __add_list_popup_clicked_cb, data);
154                 ++count;
155         }
156
157         elm_list_go(list);
158
159         if (count >= 4) {
160                 count = 4;
161
162                 int popup_height = MSGC_POPUP_LIST_H * count + list_padding;
163                 evas_object_size_hint_max_set(list, -1, popup_height * elm_config_scale_get());
164         }
165
166         popup = msg_ui_composer_list_popup_create(cd, _SYSSTR("IDS_COM_POP_ATTACH"), list, "min_menustyle");
167
168         Evas_Object *btn1 = elm_button_add(popup);
169         elm_object_style_set(btn1, "popup_button/default");
170         elm_object_text_set(btn1, MSGC_STR_BUTTON_CLOSE);
171         elm_object_part_content_set(popup, "button1", btn1);
172         evas_object_smart_callback_add(btn1, "clicked", __add_list_popup_btn_clicked_cb, cd);
173
174         cd->add_popup = popup;
175
176         D_LEAVE;
177 }
178
179 static void __msgc_show_bubble_view(void *data, msg_thread_id_t tid)
180 {
181         D_ENTER;
182         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
183         D_MSG_RETM_IF(cd == NULL, "cd is NULL");
184
185         /* show indicator area */
186         elm_layout_theme_set(cd->base, "layout", "application", "default");
187
188         elm_win_indicator_mode_set(cd->main_window, ELM_WIN_INDICATOR_SHOW);
189
190         msg_ui_composer_change_bubble_view(cd);
191
192         if (tid <= 0) {
193                 D_EMSG("Can not find tid = %d !!", tid);
194                 msg_ui_composer_message_destroy();
195                 ug_destroy_me(cd->ug);
196
197                 return;
198         }
199
200         msg_ui_composer_bubble_data_set(cd, tid);
201         msg_ui_bubble_start_view(cd->bubble_data);
202         msg_ui_composer_navi_title_set((void *)cd);
203
204         /* set recipient list for bubble composer */
205         msg_ui_composer_recipient_set_recipient_list(cd, tid);
206
207         D_LEAVE;
208 }
209
210 static void __nosim_popup_delete_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
211 {
212         D_ENTER;
213
214         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
215         D_MSG_RETM_IF(cd == NULL, "Composer data is NULL");
216
217         if (cd->msg_ug_mode == MSG_UG_MODE_ONLY_COMPOSER || cd->composer_mode == MSG_COMPOSER_MODE_FORWARD) {
218                 /* set saved msg flag */
219                 cd->disable_auto_save_mode = true;
220                 ug_destroy_me(cd->ug);
221         }
222
223         D_LEAVE;
224 }
225
226 static void __unsupported_character_popup_yes_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
227 {
228         D_ENTER;
229         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
230         D_MSG_RETM_IF(cd == NULL, "composer data is NULL");
231
232         MSGC_EVAS_OBJECT_DEL(cd->popup_end);
233
234         cd->send_check_exception_type |= SEND_CHECK_EXCEPTION_TYPE_ENCODING_MODE;
235         msg_ui_composer_body_make_and_send_message(cd, cd->send_check_exception_type);
236
237         D_LEAVE;
238 }
239
240 static void __unsupported_character_popup_no_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
241 {
242         D_ENTER;
243         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
244         D_MSG_RETM_IF(cd == NULL, "composer data is NULL");
245
246         MSGC_EVAS_OBJECT_DEL(cd->popup_end);
247
248         if (cd->send_button)
249                 elm_object_disabled_set(cd->send_button, EINA_FALSE);
250
251         msg_ui_composer_last_focus_load(cd);
252
253         D_LEAVE;
254 }
255
256 static void __msgc_flight_mode_tapi_cb(TapiHandle *handle, int result, void *data, void *user_data)
257 {
258         D_ENTER;
259         bool is_success = false;
260
261         switch (result) {
262         case TAPI_POWER_FLIGHT_MODE_RESP_ON:
263                 D_MSG("TAPI_POWER_FLIGHT_MODE_RESP_ON");
264                 break;
265
266         case TAPI_POWER_FLIGHT_MODE_RESP_OFF:
267                 D_MSG("TAPI_POWER_FLIGHT_MODE_RESP_OFF");
268                 is_success = true;
269                 break;
270
271         case TAPI_POWER_FLIGHT_MODE_RESP_FAIL:
272                 D_MSG("TAPI_POWER_FLIGHT_MODE_RESP_FAIL");
273                 break;
274
275         case TAPI_POWER_FLIGHT_MODE_RESP_MAX:
276                 D_MSG("TAPI_POWER_FLIGHT_MODE_RESP_MAX");
277                 break;
278         default:
279                 D_MSG("result = %d", result);
280                 break;
281         }
282
283         if (!is_success)
284                 D_EMSG("flight mode off is failed");
285
286         D_LEAVE;
287 }
288
289 static Eina_Bool __msgc_flight_mode_enabled_check_timer_cb(void *data)
290 {
291         D_MSG_RETVM_IF(data == NULL, ECORE_CALLBACK_CANCEL, "data is NULL");
292         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
293
294         int network_status = -1;
295         static int count = 0;
296         bool ret = false;
297
298         if (count >= 100) {     /* 0.5 sec * 100 = 50 sec */
299                 D_EMSG("self time expiration");
300                 MSGC_EVAS_OBJECT_DEL(cd->progress_popup);
301                 goto return_end;
302         }
303
304         ++count;
305
306         /* check if call network is enabled - to send message l*/
307         ret = msg_composer_get_network_status(&network_status);
308         if (ret == true) {
309                 if (network_status == VCONFKEY_TELEPHONY_SVCTYPE_NONE ||
310                                 network_status == VCONFKEY_TELEPHONY_SVCTYPE_NOSVC ||
311                                 network_status == VCONFKEY_TELEPHONY_SVCTYPE_EMERGENCY ||
312                                 network_status == VCONFKEY_TELEPHONY_SVCTYPE_SEARCH) {
313                         D_MSG("Cannot send message - check again");
314                         return ECORE_CALLBACK_RENEW;
315                 }
316         } else {
317                 D_EMSG("msg_composer_get_network_status is failed");
318                 return ECORE_CALLBACK_RENEW;
319         }
320
321         MSGC_EVAS_OBJECT_DEL(cd->progress_popup);
322
323         D_MSG("try to send message");
324         msg_ui_composer_body_make_and_send_message(cd, SEND_CHECK_EXCEPTION_TYPE_NONE);
325
326 return_end:
327
328         count = 0;
329         cd->flight_mode_timer = NULL;
330
331         return ECORE_CALLBACK_CANCEL;
332 }
333
334 static void __flight_mode_popup_ok_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
335 {
336         D_ENTER;
337         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
338         D_MSG_RETM_IF(cd == NULL, "composer data is NULL");
339
340         Evas_Object *check = (Evas_Object *)evas_object_data_get(cd->custom_popup, "check_box");
341
342         if (elm_check_state_get(check)) {
343                 /* set flight mode off*/
344                 if (msg_composer_set_flight_mode(cd->tapi_handle, TAPI_POWER_FLIGHT_MODE_LEAVE, __msgc_flight_mode_tapi_cb, NULL) == false) {
345                         D_EMSG("msg_composer_set_flight_mode is failed");
346                 } else {
347                         /* show progress popup */
348                         MSGC_EVAS_OBJECT_DEL(cd->progress_popup);
349                         cd->progress_popup = msg_ui_composer_progress_popup_show(cd, _MSGSTR("Disabling Flight mode"));
350
351                         /* give focus to back btn to hide keypad */
352                         elm_object_focus_set(cd->back_btn, EINA_TRUE);
353
354                         if (cd->flight_mode_timer) {
355                                 ecore_timer_del(cd->flight_mode_timer);
356                                 cd->flight_mode_timer = NULL;
357                         }
358                         cd->flight_mode_timer = ecore_timer_add(0.5, __msgc_flight_mode_enabled_check_timer_cb, cd);
359                 }
360         } else {
361                 D_MSG("checkbox is not checked");
362         }
363
364         MSGC_EVAS_OBJECT_DEL(cd->custom_popup);
365
366         if (cd->send_button)
367                 elm_object_disabled_set(cd->send_button, EINA_FALSE);
368
369         D_LEAVE;
370 }
371
372 static void __flight_mode_popup_cancel_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
373 {
374         D_ENTER;
375         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
376         D_MSG_RETM_IF(cd == NULL, "composer data is NULL");
377
378         MSGC_EVAS_OBJECT_DEL(cd->custom_popup);
379
380         if (cd->send_button)
381                 elm_object_disabled_set(cd->send_button, EINA_FALSE);
382
383         D_LEAVE;
384 }
385
386 static COMPOSER_RETURN_TYPE_E __msgc_check_condition_to_send_msg(void *data, int check_exption_type)
387 {
388         D_ENTER;
389         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
390         D_MSG_RETVM_IF(cd == NULL, COMPOSER_RETURN_FAIL, "composer data is NULL");
391
392         /* check flight mode */
393         int flight_mode = 0;
394         if (msg_composer_get_flight_mode(&flight_mode) && flight_mode) {
395                 /*get tapi handle */
396                 if (!cd->tapi_handle)
397                         cd->tapi_handle = (void *)tel_init(NULL);
398
399                 if (!cd->tapi_handle) {
400                         D_EMSG("tel_init is failed");
401                 } else {
402                         /* show popup */
403                         Evas_Object *popup = NULL;
404                         Evas_Object *btn1 = NULL;
405                         Evas_Object *btn2 = NULL;
406                         char *popup_msg = _MSGSTR("IDS_MSGC_POP_UNABLE_TO_SEND_MESSAGES_WHILE_IN_FLIGHT_MODE_DISABLE_FLIGHT_MODE_AND_TRY_AGAIN");
407                         char *checkbox_msg = _MSGSTR("IDS_MSGC_HEADER_DISABLE_FLIGHT_MODE_ABB");
408
409                         MSGC_EVAS_OBJECT_DEL(cd->custom_popup);
410
411                         popup = msg_ui_composer_checkbox_popup_create(cd, NULL, popup_msg, checkbox_msg);
412
413                         btn1 = msg_ui_composer_popup_button_create(popup, _SYSSTR("IDS_COM_SK_OK"));
414                         elm_object_part_content_set(popup, "button1", btn1);
415                         evas_object_smart_callback_add(btn1, "clicked", __flight_mode_popup_ok_btn_clicked_cb, cd);
416                         btn2 = msg_ui_composer_popup_button_create(popup, _SYSSTR("IDS_COM_SK_CANCEL"));
417                         elm_object_part_content_set(popup, "button2", btn2);
418                         evas_object_smart_callback_add(btn2, "clicked", __flight_mode_popup_cancel_btn_clicked_cb, cd);
419
420                         cd->custom_popup = popup;
421
422                         elm_object_focus_set(popup, EINA_TRUE);
423                 }
424
425                 return COMPOSER_RETURN_FAIL;
426         }
427
428         /*Check recipient available sending*/
429         RECIPIENT_S *rd = cd->recipient;
430         if (rd) {
431                 /*add recipient, if entry text exist*/
432                 Evas_Object *entry = elm_multibuttonentry_entry_get(rd->mbe);
433                 char *entry_txt = elm_entry_markup_to_utf8(elm_entry_entry_get(entry));
434                 if (entry_txt) {
435                         if (strlen(entry_txt) > 0) {
436                                 if (NULL == elm_multibuttonentry_item_append(rd->mbe, entry_txt, NULL, NULL)) {
437                                         g_free(entry_txt);
438
439                                         if (cd->send_button)
440                                                 elm_object_disabled_set(cd->send_button, EINA_FALSE);
441
442                                         return COMPOSER_RETURN_FAIL;
443                                 }
444                         }
445                         g_free(entry_txt);
446                 }
447
448                 /*check recipient count is zero*/
449                 if (msg_ui_composer_recipient_count_get(rd) == 0) {
450                         D_EMSG("there is no recipient");
451                         //msg_ui_composer_common_tickernoti(cd, COMPOSER_TICKERNOTI_NO_RECIPIENT);
452
453                         /* change focus to recipient */
454                         if (cd->msg_ug_mode == MSG_UG_MODE_ONLY_COMPOSER || cd->msg_ug_mode == MSG_UG_MODE_FULL_COMPOSER)
455                                 msg_ui_composer_recipient_focus_set(cd->recipient);
456
457                         if (cd->send_button)
458                                 elm_object_disabled_set(cd->send_button, EINA_FALSE);
459
460                         return COMPOSER_RETURN_FAIL;
461                 }
462         }
463
464         if (!(check_exption_type & SEND_CHECK_EXCEPTION_TYPE_ENCODING_MODE)) {
465                 if (cd->msg_type == COMPOSER_MSG_TYPE_SMS) {
466                         if (cd->body_data.page_list) {
467                                 MSG_COMPOSER_BODY_PAGE_S *page_data = NULL;
468                                 page_data = (MSG_COMPOSER_BODY_PAGE_S *)eina_list_nth(cd->body_data.page_list, 0);
469
470                                 if (page_data && page_data->text_info.encode == COMPOSER_CHAR_ENCODE_GSM7_ABNORMAL) {
471                                         MSGC_EVAS_OBJECT_DEL(cd->popup_end);
472                                         Evas_Object *popup = msg_ui_composer_status_popup_show(cd->navi_bar, cd, _MSGSTR("Some characters may be lost. Continue?"), 0);
473                                         Evas_Object *btn1 = msg_ui_composer_popup_button_create(popup, _SYSSTR("IDS_COM_SK_YES"));
474                                         elm_object_part_content_set(popup, "button1", btn1);
475                                         evas_object_smart_callback_add(btn1, "clicked", __unsupported_character_popup_yes_btn_clicked_cb, cd);
476                                         Evas_Object *btn2 = msg_ui_composer_popup_button_create(popup, _SYSSTR("IDS_COM_SK_NO"));
477                                         elm_object_part_content_set(popup, "button2", btn2);
478                                         evas_object_smart_callback_add(btn2, "clicked", __unsupported_character_popup_no_btn_clicked_cb, cd);
479
480                                         cd->popup_end = popup;
481                                         elm_object_focus_set(popup, EINA_TRUE);
482
483                                         return COMPOSER_RETURN_FAIL;
484                                 }
485                         }
486                 }
487         }
488
489         D_LEAVE;
490         return COMPOSER_RETURN_SUCCESS;
491 }
492
493 void msg_ui_composer_body_make_and_send_message(void *data, int check_exception_type)
494 {
495         D_ENTER;
496         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
497         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
498         msg_thread_id_t tid = 0;
499
500         if (__msgc_check_condition_to_send_msg(cd, check_exception_type) != COMPOSER_RETURN_SUCCESS) {
501                 D_EMSG("__msgc_check_condition_to_send_msg is failed");
502                 return;
503         }
504
505         /*Make message*/
506         msg_ui_composer_message_init();
507
508         if (msg_ui_composer_recipient_read_data(cd) != COMPOSER_RETURN_SUCCESS) {
509                 D_EMSG("Make recipient data Error");
510                 goto error_return;
511         }
512
513         if (__msg_ui_composer_body_read_data(cd) != COMPOSER_RETURN_SUCCESS) {
514                 D_EMSG("Make body data Error");
515                 goto error_return;
516         }
517
518         /*Send message*/
519         COMPOSER_RETURN_TYPE_E ret = msg_ui_composer_message_make_and_send(cd->msg_handle, cd->msg_id, &tid);
520
521         /* reset region info */
522         MSG_COMPOSER_BODY_S *body_data = &cd->body_data;
523         body_data->region_order = COMPOSER_REGION_ORDER_UNDETERMINDED;
524         cd->send_check_exception_type = SEND_CHECK_EXCEPTION_TYPE_NONE;
525
526         if (ret == COMPOSER_RETURN_SUCCESS) {
527                 D_MSG("Send Success");
528
529                 if (cd->msg_ug_mode == MSG_UG_MODE_ONLY_COMPOSER || cd->composer_mode == MSG_COMPOSER_MODE_FORWARD) {
530                         /* set saved msg flag */
531                         cd->disable_auto_save_mode = true;
532                         ug_destroy_me(cd->ug);
533                 } else if (cd->msg_ug_mode == MSG_UG_MODE_FULL_COMPOSER) {
534                         __msgc_show_bubble_view(cd, tid);
535                         msg_ui_composer_clear(cd);
536
537                         service_h svc_handle;
538                         if (service_create(&svc_handle) < 0 || svc_handle == NULL) {
539                                 D_EMSG("service_create() is failed !!");
540                         } else {
541                                 char buf[DEF_BUF_LEN_S] = {0,};
542                                 snprintf(buf, sizeof(buf), "%d", tid);
543                                 service_add_extra_data(svc_handle, MSG_BUNDLE_KEY_THREAD_ID, buf);
544
545                                 ug_send_result(cd->ug, svc_handle);
546
547                                 service_destroy(svc_handle);
548                         }
549                 } else {
550                         msg_ui_composer_clear(cd);
551                 }
552
553                 cd->composer_mode = MSG_COMPOSER_MODE_NORMAL;
554                 cd->msg_id = 0;
555
556         } else {
557                 bool is_closed = false;
558
559                 if (ret == COMPOSER_RETURN_NO_SIM) {
560                         D_EMSG("Send Fail : NO SIM");
561                         Evas_Object *popup = msg_ui_composer_status_popup_show(cd->main_window, cd, MSGC_STR_POP_NOSIM, 1);
562
563                         if (cd->msg_ug_mode == MSG_UG_MODE_ONLY_COMPOSER || cd->composer_mode == MSG_COMPOSER_MODE_FORWARD) {
564                                 is_closed = true;
565                                 evas_object_event_callback_add(popup, EVAS_CALLBACK_DEL, __nosim_popup_delete_cb, cd);
566                         } else if (cd->msg_ug_mode == MSG_UG_MODE_FULL_COMPOSER) {
567                                 __msgc_show_bubble_view(cd, tid);
568                         }
569
570                         msg_ui_composer_clear(cd);
571                 } else {
572                         D_EMSG("Send Fail : Unable Send");
573                         if ((cd->msg_ug_mode == MSG_UG_MODE_ONLY_COMPOSER || cd->composer_mode == MSG_COMPOSER_MODE_FORWARD)) {
574                                 /* set saved msg flag */
575                                 cd->disable_auto_save_mode = true;
576                                 ug_destroy_me(cd->ug);
577                         } else {
578                                 msg_ui_composer_status_popup_show(cd->main_window, cd, MSGC_STR_POP_UNABLE_SEND, COMPOSER_STATUS_POPUP_DEFAULT_TIME);
579                         }
580                 }
581
582                 if (!is_closed) {
583                         cd->composer_mode = MSG_COMPOSER_MODE_NORMAL;
584                         cd->msg_id = 0;
585                 }
586
587                 goto error_return;
588         }
589
590         msg_ui_composer_set_body_keypad_layout(cd, ELM_INPUT_PANEL_LAYOUT_NORMAL);
591         msg_ui_composer_message_destroy();
592         D_LEAVE;
593         return;
594
595 error_return:
596         msg_ui_composer_set_body_keypad_layout(cd, ELM_INPUT_PANEL_LAYOUT_NORMAL);
597         msg_ui_composer_message_destroy();
598
599         if (cd->send_button)
600                 elm_object_disabled_set(cd->send_button, EINA_FALSE);
601
602         D_LEAVE;
603 }
604
605 void msg_ui_composer_body_send_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
606 {
607         D_ENTER;
608         D_MSG_RETM_IF(data == NULL, "Composer Data is NULL");
609
610         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
611
612         if (cd->send_button)
613                 elm_object_disabled_set(cd->send_button, EINA_TRUE);
614
615         cd->send_check_exception_type = SEND_CHECK_EXCEPTION_TYPE_NONE;
616         msg_ui_composer_body_make_and_send_message(cd, cd->send_check_exception_type);
617
618         D_LEAVE;
619         return;
620 }
621
622 void msg_ui_composer_body_add_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
623 {
624         D_ENTER;
625
626         if (!data) {
627                 MSG_UI_DEBUG(MSG_UI_LEVEL_ASSERT, "[ASSERT] error data is NULL");
628                 return;
629         }
630
631         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
632
633         if (cd->add_button_clicked)
634                 return;
635
636         cd->add_button_clicked = true;
637         __add_list_popup_show(cd);
638
639         D_LEAVE;
640 }
641
642 void msg_ui_composer_body_entry_maxlength_reached_cb(void *data, Evas_Object *obj, void *event_info)
643 {
644         D_ENTER;
645         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
646         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
647
648         msg_ui_composer_common_tickernoti(cd, COMPOSER_TICKERNOTI_MAXLENGHT_CHAR);
649
650         D_LEAVE;
651 }
652
653 void msg_ui_composer_body_entry_changed_cb(void *data, Evas_Object *obj, void *event_info)
654 {
655         D_ENTER;
656         D_MSG_RETM_IF(data == NULL, "Composer Data is NULL");
657         D_MSG_RETM_IF(obj == NULL, "entry obj is NULL");
658
659         MSG_COMPOSER_VIEW_DATA_S *cd = data;
660         MSG_COMPOSER_BODY_PAGE_S *page_data = NULL;
661
662         page_data = evas_object_data_get(obj, "page_data");
663         if (page_data == NULL)
664                 return;
665
666         char *body_text = elm_entry_markup_to_utf8(elm_entry_entry_get(obj));
667         if (body_text == NULL)
668                 return;
669
670         int text_len = strlen(body_text);
671         if (text_len <= 0) {
672                 page_data->text_info.encode = COMPOSER_CHAR_ENCODE_UNICODE;
673                 page_data->text_info.char_count = 0;
674         } else {
675                 page_data->text_info.encode = msg_ui_composer_body_entry_char_count(cd, (const char *)body_text, &page_data->text_info.char_count, &page_data->text_info.page_size);
676         }
677         g_free(body_text);
678
679         msg_ui_composer_message_type_check_and_change(cd);
680
681         msg_ui_composer_body_info_area_update(cd);
682
683         if (msg_ui_composer_common_is_send_possible(cd)) {
684                 elm_object_disabled_set(cd->send_button, EINA_FALSE);
685                 msg_ui_composer_body_update_send_btn_icon(cd, false);
686         } else {
687                 elm_object_disabled_set(cd->send_button, EINA_TRUE);
688                 msg_ui_composer_body_update_send_btn_icon(cd, true);
689         }
690
691         D_LEAVE;
692 }
693
694 void msg_ui_composer_body_entry_press_cb(void *data, Evas_Object *obj, void *event_info)
695 {
696         D_ENTER;
697         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
698         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
699
700         if (msg_ui_composer_recipient_addr_type_get(cd->recipient) == COMPOSER_RECP_ADDR_INVALID) {
701                 elm_entry_context_menu_disabled_set(obj, EINA_TRUE);
702                 elm_entry_magnifier_disabled_set(obj, EINA_TRUE);
703         } else {
704                 elm_entry_context_menu_disabled_set(obj, EINA_FALSE);
705                 elm_entry_magnifier_disabled_set(obj, EINA_FALSE);
706         }
707
708         D_LEAVE;
709 }
710
711 void msg_ui_composer_body_entry_clicked_cb(void *data, Evas_Object *obj, void *event_info)
712 {
713         D_ENTER;
714         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
715         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
716
717         int attach_count = msg_ui_composer_get_attach_count(cd);
718
719         if (attach_count > 1)
720                 msg_ui_composer_contract_attach_list(cd);
721
722         D_LEAVE;
723 }
724
725 void msg_ui_composer_body_entry_unfocused_cb(void *data, Evas_Object *obj, void *event_info)
726 {
727         D_ENTER;
728
729         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
730         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
731
732         if (cd->msg_type == COMPOSER_MSG_TYPE_MMS) {
733                 MSG_COMPOSER_BODY_S *body_data = &cd->body_data;
734
735                 int page_count = body_data->page_count;
736
737                 if (page_count == 1) {
738                         D_MSG("There is 1 page !!!");
739                 } else {
740                         MSG_COMPOSER_BODY_PAGE_S *page_data = evas_object_data_get(obj, "page_data");
741                         if (page_data == NULL) {
742                                 D_EMSG("page_data is NULL");
743                         } else {
744                                 /* hide delete button */
745                                 D_MSG("hide delete button");
746                                 edje_object_signal_emit(_EDJ(page_data->upper_layout), "hide.delete", "*");
747                         }
748                 }
749         }
750
751         D_LEAVE;
752 }
753
754 void msg_ui_composer_body_entry_focused_cb(void *data, Evas_Object *obj, void *event_info)
755 {
756         D_ENTER;
757
758         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
759         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
760
761         if (msg_ui_composer_recipient_addr_type_get(cd->recipient) == COMPOSER_RECP_ADDR_INVALID) {
762                 /* if focused_cb is called twice becuase of double click, move focus to popup */
763                 if (msg_ui_composer_popup_exist(cd))
764                         msg_ui_composer_popup_focus(cd);
765
766                 return;
767         }
768
769         if (cd->msg_type == COMPOSER_MSG_TYPE_MMS) {
770                 MSG_COMPOSER_BODY_S *body_data = &cd->body_data;
771
772                 Eina_List *page_list = body_data->page_list;
773                 int page_count = body_data->page_count;
774
775                 if (page_count == 1) {
776                         D_MSG("page NO.1 focused !!!");
777                         cd->current_edit_entry = 0;
778                 } else {
779                         MSG_COMPOSER_BODY_PAGE_S *page_data = NULL;
780                         int i = 0;
781
782                         for (i = 0; i < page_count; i++) {
783                                 page_data = (MSG_COMPOSER_BODY_PAGE_S *)eina_list_nth(page_list, i);
784                                 if (page_data->entry == obj) {
785                                         D_MSG("page NO.[%d]/[%d] focused !!!", i + 1, page_count);
786                                         cd->current_edit_entry = i;
787                                         break;
788                                 }
789                         }
790                         page_data = evas_object_data_get(obj, "page_data");
791                         if (page_data == NULL) {
792                                 D_EMSG("page_data is NULL");
793                         } else {
794                                 /* show delete button */
795                                 D_MSG("show delete button");
796                                 edje_object_signal_emit(_EDJ(page_data->upper_layout), "show.delete", "*");
797                         }
798                 }
799         } else if (cd->msg_type == COMPOSER_MSG_TYPE_SMS) {
800                 cd->current_edit_entry = 0;
801         } else {
802                 D_MSG("message composer invalid message type");
803         }
804
805         msg_ui_composer_last_focused_entry_set(data, obj);
806
807         D_LEAVE;
808 }
809
810 void msg_ui_composer_body_page_del_btn_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
811 {
812         D_ENTER;
813         D_MSG_RETM_IF(obj == NULL, "obj is NULL");
814         elm_image_file_set(obj, MSG_IMAGES_EDJ, MSGC_IMG_DEL_BTN_PRESS_ICON);
815 }
816
817 void msg_ui_composer_body_page_del_btn_up_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
818 {
819         D_ENTER;
820         D_MSG_RETM_IF(obj == NULL, "obj is NULL");
821         elm_image_file_set(obj, MSG_IMAGES_EDJ, MSGC_IMG_PAGE_DEL_ICON);
822 }
823
824 void msg_ui_composer_body_page_del_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
825 {
826         D_ENTER;
827
828         if (!data) {
829                 MSG_UI_DEBUG(MSG_UI_LEVEL_ASSERT, "[ASSERT] Callback data is NULL");
830                 return;
831         }
832
833         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
834         Evas_Object *layout = evas_object_data_get(obj, "layout");
835
836         msg_ui_composer_mms_body_remove_page(cd, layout);
837
838         msg_ui_composer_message_type_check_and_change(cd);
839
840         msg_ui_composer_body_info_area_update(cd);
841
842         /* in invalid recipient case, give focus to other widget to call verify_cb of recipient */
843         if (msg_ui_composer_last_focus_is_recipient(cd)) {
844                 const char *recipient = msg_ui_composer_recipient_entry_text_get(cd->recipient);
845
846                 if (recipient && recipient[0] != '\0') {
847                         if (!msg_ui_composer_recipient_vaild_check(recipient))
848                                 elm_object_focus_set(cd->back_btn, EINA_TRUE);
849                 }
850         }
851         D_LEAVE;
852 }
853
854 static void __msg_ui_composer_body_launch_media_item(void *data, Evas_Object *obj)
855 {
856         D_ENTER;
857         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
858         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
859         D_MSG_RETM_IF(obj == NULL, "obj is NULL");
860
861         Evas_Object *layout = NULL;
862         MSG_COMPOSER_BODY_PAGE_S *page_data = NULL;
863         MSG_COMPOSER_BODY_S *body_data = &cd->body_data;
864         Eina_List *page_list = body_data->page_list;
865         int page_count = body_data->page_count;
866         int i = 0;
867         char file_path[COMPOSER_FILEPATH_LEN_MAX + 1] = {0, };
868
869         layout = evas_object_data_get(obj, "layout");
870
871         if (!layout || !page_list) {
872                 D_EMSG("Invalid data layout = %x, page_list = %x", layout, page_list);
873                 return;
874         }
875
876         for (i = 0; i < page_count; i++) {
877                 page_data = (MSG_COMPOSER_BODY_PAGE_S *)eina_list_nth(page_list, i);
878
879                 if (!page_data) {
880                         D_EMSG("page data is NULL !!!");
881                         return;
882                 }
883
884                 if (page_data->sound_item == layout) {
885                         strncpy(file_path, page_data->sound_file_path, COMPOSER_FILEPATH_LEN_MAX);
886                         break;
887                 } else if (page_data->image_item == layout) {
888                         strncpy(file_path, page_data->image_file_path, COMPOSER_FILEPATH_LEN_MAX);
889                         break;
890                 }
891         }
892
893         if (file_path[0] != '\0') {
894                 COMPOSER_EXT_TYPE_E type = COMPOSER_EXT_TYPE_COMMON;
895                 COMPOSER_MEDIA_TYPE_E media_type = msg_composer_get_media_type(file_path);
896
897                 if (media_type == COMPOSER_MEDIA_TYPE_IMAGE) {
898                         type = COMPOSER_EXT_TYPE_IMAGE;
899                 } else if (media_type == COMPOSER_MEDIA_TYPE_VIDEO) {
900                         type = COMPOSER_EXT_TYPE_COMMON;
901                 } else if (media_type == COMPOSER_MEDIA_TYPE_AUDIO) {
902                         type = COMPOSER_EXT_TYPE_SOUND;
903                 } else {
904                         type = COMPOSER_EXT_TYPE_COMMON;
905                 }
906
907                 msg_ui_composer_external_call(cd, type, file_path);
908         }
909
910         D_LEAVE;
911 }
912
913 void msg_ui_composer_body_media_layout_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
914 {
915         D_ENTER;
916         D_MSG_RETM_IF(data == NULL, "data is NULL");
917         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
918
919         __msg_ui_composer_body_launch_media_item(cd, obj);
920
921         D_LEAVE;
922 }
923
924 void msg_ui_composer_body_media_thumb_icon_clicked_cb(void *data, Evas_Object *obj, void *event_info)
925 {
926         D_ENTER;
927         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
928         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
929
930         if (!cd->is_default_body_size)
931                 __msg_ui_composer_body_launch_media_item(cd, obj);
932
933         D_LEAVE;
934 }
935
936 void msg_ui_composer_body_media_del_btn_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
937 {
938         D_ENTER;
939         D_MSG_RETM_IF(obj == NULL, "obj is NULL");
940         int media_type = 0;
941
942         media_type = (int)evas_object_data_get(obj, "media_type");
943         D_MSG("media_type = %d", media_type);
944
945         if (media_type == COMPOSER_MEDIA_TYPE_AUDIO)
946                 elm_image_file_set(obj, MSG_IMAGES_EDJ, MSGC_IMG_DEL_BTN_PRESS_ICON);
947         else
948                 elm_image_file_set(obj, MSG_IMAGES_EDJ, MSGC_IMG_INSERT_DEL_PRESS_ICON);
949 }
950
951 void msg_ui_composer_body_media_del_btn_up_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
952 {
953         D_ENTER;
954         D_MSG_RETM_IF(obj == NULL, "obj is NULL");
955         int media_type = 0;
956
957         media_type = (int)evas_object_data_get(obj, "media_type");
958
959         if (media_type == COMPOSER_MEDIA_TYPE_AUDIO)
960                 elm_image_file_set(obj, MSG_IMAGES_EDJ, MSGC_SOUND_INSERT_DEL_ICON);
961         else
962                 elm_image_file_set(obj, MSG_IMAGES_EDJ, MSGC_IMG_INSERT_DEL_ICON);
963 }
964
965 void msg_ui_composer_body_media_del_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
966 {
967         D_ENTER;
968
969         if (!data || !obj) {
970                 MSG_UI_DEBUG(MSG_UI_LEVEL_ASSERT, "[ASSERT] NULL pointer error");
971                 return;
972         }
973
974         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
975         MSG_COMPOSER_BODY_S *body_data = &cd->body_data;
976         MSG_COMPOSER_BODY_PAGE_S *page_data = NULL;
977         Eina_List *page_list = body_data->page_list;
978         int page_count = body_data->page_count;
979         int body_length = 0;
980
981         if (!cd->is_default_body_size) {
982                 Evas_Object *delete_layout = (Evas_Object *)evas_object_data_get(obj, "layout");
983
984                 int i = 0;
985
986                 for (i = 0; i < page_count; i++) {
987                         page_data = (MSG_COMPOSER_BODY_PAGE_S *)eina_list_nth(page_list, i);
988
989                         if (!page_data) {
990                                 MSG_UI_DEBUG(MSG_UI_LEVEL_ASSERT, "[ASSERT] page data is NULL !!!");
991                                 return;
992                         }
993
994                         if (page_data->sound_item == delete_layout) {
995                                 msg_ui_composer_mms_insert_item_remove(cd, delete_layout, COMPOSER_MEDIA_TYPE_AUDIO);
996
997                                 char *body_text = elm_entry_markup_to_utf8(elm_entry_entry_get(page_data->entry));
998                                 if (!body_text)
999                                         return;
1000
1001                                 body_length = strlen(body_text);
1002
1003                                 if (body_length == 0 && !page_data->is_image_item)
1004                                         msg_ui_composer_mms_body_remove_page(cd, page_data->layout);
1005
1006                                 g_free(body_text);
1007
1008                                 break;
1009                         } else if (page_data->image_item == delete_layout) {
1010
1011                                 char *body_text = elm_entry_markup_to_utf8(elm_entry_entry_get(page_data->entry));
1012                                 if (!body_text)
1013                                         return;
1014
1015                                 body_length = strlen(body_text);
1016
1017                                 if (page_data->isVideo) {
1018                                         msg_ui_composer_mms_insert_item_remove(cd, delete_layout, COMPOSER_MEDIA_TYPE_VIDEO);
1019                                 } else {
1020                                         msg_ui_composer_mms_insert_item_remove(cd, delete_layout, COMPOSER_MEDIA_TYPE_IMAGE);
1021                                 }
1022
1023                                 if (body_length == 0 && !page_data->is_sound_item)
1024                                         msg_ui_composer_mms_body_remove_page(cd, page_data->layout);
1025
1026                                 g_free(body_text);
1027                                 break;
1028                         }
1029                 }
1030
1031                 msg_ui_composer_message_type_check_and_change(cd);
1032         }
1033
1034         /* in invalid recipient case, give focus to other widget to call verify_cb of recipient */
1035         if (msg_ui_composer_last_focus_is_recipient(cd)) {
1036                 const char *recipient = msg_ui_composer_recipient_entry_text_get(cd->recipient);
1037
1038                 if (recipient && recipient[0] != '\0') {
1039                         if (!msg_ui_composer_recipient_vaild_check(recipient))
1040                                 elm_object_focus_set(cd->back_btn, EINA_TRUE);
1041                 }
1042         }
1043
1044         D_LEAVE;
1045 }
1046
1047 void msg_ui_composer_body_body_layout_resize_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
1048 {
1049         D_ENTER;
1050
1051         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
1052         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
1053         Evas_Coord x = 0;
1054         Evas_Coord y = 0;
1055         Evas_Coord w = 0;
1056         Evas_Coord h = 0;
1057
1058         evas_object_geometry_get(obj, &x, &y, &w, &h);
1059         D_MSG("body layout height = %d", h);
1060
1061         cd->ly_body_h = h;
1062
1063         if (h >= COMPOSER_ENOUGH_TEXT_RENDERING_BODY_HEIGHT)
1064                 msg_ui_composer_body_info_area_update(cd);
1065         else
1066                 edje_object_part_text_set(_EDJ(cd->ly_body), "text.char_count", "");
1067
1068         D_LEAVE;
1069 }
1070
1071 void msg_ui_composer_body_body_layout_clicked_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
1072 {
1073         D_ENTER;
1074         D_MSG_RETM_IF(data == NULL, "data is NULL");
1075         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
1076
1077         msg_ui_composer_body_focus_set(cd, 0);
1078
1079         evas_object_event_callback_del(cd->body_box, EVAS_CALLBACK_MOUSE_UP, msg_ui_composer_body_body_layout_clicked_cb);
1080
1081         cd->is_default_body_size = false;
1082
1083         D_LEAVE;
1084 }
1085