261650fd2b2d6f879fe893fb96b1cdbb1b9ffd3d
[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, &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
555         } else {
556                 bool is_closed = false;
557
558                 if (ret == COMPOSER_RETURN_NO_SIM) {
559                         D_EMSG("Send Fail : NO SIM");
560                         Evas_Object *popup = msg_ui_composer_status_popup_show(cd->main_window, cd, MSGC_STR_POP_NOSIM, 1);
561
562                         if (cd->msg_ug_mode == MSG_UG_MODE_ONLY_COMPOSER || cd->composer_mode == MSG_COMPOSER_MODE_FORWARD) {
563                                 is_closed = true;
564                                 evas_object_event_callback_add(popup, EVAS_CALLBACK_DEL, __nosim_popup_delete_cb, cd);
565                         } else if (cd->msg_ug_mode == MSG_UG_MODE_FULL_COMPOSER) {
566                                 __msgc_show_bubble_view(cd, tid);
567                         }
568
569                         msg_ui_composer_clear(cd);
570                 } else {
571                         D_EMSG("Send Fail : Unable Send");
572                         if ((cd->msg_ug_mode == MSG_UG_MODE_ONLY_COMPOSER || cd->composer_mode == MSG_COMPOSER_MODE_FORWARD)) {
573                                 /* set saved msg flag */
574                                 cd->disable_auto_save_mode = true;
575                                 ug_destroy_me(cd->ug);
576                         } else {
577                                 msg_ui_composer_status_popup_show(cd->main_window, cd, MSGC_STR_POP_UNABLE_SEND, COMPOSER_STATUS_POPUP_DEFAULT_TIME);
578                         }
579                 }
580
581                 if (!is_closed)
582                         cd->composer_mode = MSG_COMPOSER_MODE_NORMAL;
583
584                 goto error_return;
585         }
586
587         msg_ui_composer_set_body_keypad_layout(cd, ELM_INPUT_PANEL_LAYOUT_NORMAL);
588         msg_ui_composer_message_destroy();
589         D_LEAVE;
590         return;
591
592 error_return:
593         msg_ui_composer_set_body_keypad_layout(cd, ELM_INPUT_PANEL_LAYOUT_NORMAL);
594         msg_ui_composer_message_destroy();
595
596         if (cd->send_button)
597                 elm_object_disabled_set(cd->send_button, EINA_FALSE);
598
599         D_LEAVE;
600 }
601
602 void msg_ui_composer_body_send_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
603 {
604         D_ENTER;
605         D_MSG_RETM_IF(data == NULL, "Composer Data is NULL");
606
607         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
608
609         if (cd->send_button)
610                 elm_object_disabled_set(cd->send_button, EINA_TRUE);
611
612         cd->send_check_exception_type = SEND_CHECK_EXCEPTION_TYPE_NONE;
613         msg_ui_composer_body_make_and_send_message(cd, cd->send_check_exception_type);
614
615         D_LEAVE;
616         return;
617 }
618
619 void msg_ui_composer_body_add_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
620 {
621         D_ENTER;
622
623         if (!data) {
624                 MSG_UI_DEBUG(MSG_UI_LEVEL_ASSERT, "[ASSERT] error data is NULL");
625                 return;
626         }
627
628         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
629
630         if (cd->add_button_clicked)
631                 return;
632
633         cd->add_button_clicked = true;
634         __add_list_popup_show(cd);
635
636         D_LEAVE;
637 }
638
639 void msg_ui_composer_body_entry_maxlength_reached_cb(void *data, Evas_Object *obj, void *event_info)
640 {
641         D_ENTER;
642         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
643         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
644
645         msg_ui_composer_common_tickernoti(cd, COMPOSER_TICKERNOTI_MAXLENGHT_CHAR);
646
647         D_LEAVE;
648 }
649
650 void msg_ui_composer_body_entry_changed_cb(void *data, Evas_Object *obj, void *event_info)
651 {
652         D_ENTER;
653         D_MSG_RETM_IF(data == NULL, "Composer Data is NULL");
654         D_MSG_RETM_IF(obj == NULL, "entry obj is NULL");
655
656         MSG_COMPOSER_VIEW_DATA_S *cd = data;
657         MSG_COMPOSER_BODY_PAGE_S *page_data = NULL;
658
659         page_data = evas_object_data_get(obj, "page_data");
660         if (page_data == NULL)
661                 return;
662
663         char *body_text = elm_entry_markup_to_utf8(elm_entry_entry_get(obj));
664         if (body_text == NULL)
665                 return;
666
667         int text_len = strlen(body_text);
668         if (text_len <= 0) {
669                 page_data->text_info.encode = COMPOSER_CHAR_ENCODE_UNICODE;
670                 page_data->text_info.char_count = 0;
671         } else {
672                 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);
673         }
674         g_free(body_text);
675
676         msg_ui_composer_message_type_check_and_change(cd);
677
678         msg_ui_composer_body_info_area_update(cd);
679
680         if (msg_ui_composer_common_is_send_possible(cd)) {
681                 elm_object_disabled_set(cd->send_button, EINA_FALSE);
682                 msg_ui_composer_body_update_send_btn_icon(cd, false);
683         } else {
684                 elm_object_disabled_set(cd->send_button, EINA_TRUE);
685                 msg_ui_composer_body_update_send_btn_icon(cd, true);
686         }
687
688         D_LEAVE;
689 }
690
691 void msg_ui_composer_body_entry_press_cb(void *data, Evas_Object *obj, void *event_info)
692 {
693         D_ENTER;
694         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
695         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
696
697         if (msg_ui_composer_recipient_addr_type_get(cd->recipient) == COMPOSER_RECP_ADDR_INVALID) {
698                 elm_entry_context_menu_disabled_set(obj, EINA_TRUE);
699                 elm_entry_magnifier_disabled_set(obj, EINA_TRUE);
700         } else {
701                 elm_entry_context_menu_disabled_set(obj, EINA_FALSE);
702                 elm_entry_magnifier_disabled_set(obj, EINA_FALSE);
703         }
704
705         D_LEAVE;
706 }
707
708 void msg_ui_composer_body_entry_clicked_cb(void *data, Evas_Object *obj, void *event_info)
709 {
710         D_ENTER;
711         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
712         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
713
714         int attach_count = msg_ui_composer_get_attach_count(cd);
715
716         if (attach_count > 1)
717                 msg_ui_composer_contract_attach_list(cd);
718
719         D_LEAVE;
720 }
721
722 void msg_ui_composer_body_entry_unfocused_cb(void *data, Evas_Object *obj, void *event_info)
723 {
724         D_ENTER;
725
726         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
727         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
728
729         if (cd->msg_type == COMPOSER_MSG_TYPE_MMS) {
730                 MSG_COMPOSER_BODY_S *body_data = &cd->body_data;
731
732                 int page_count = body_data->page_count;
733
734                 if (page_count == 1) {
735                         D_MSG("There is 1 page !!!");
736                 } else {
737                         MSG_COMPOSER_BODY_PAGE_S *page_data = evas_object_data_get(obj, "page_data");
738                         if (page_data == NULL) {
739                                 D_EMSG("page_data is NULL");
740                         } else {
741                                 /* hide delete button */
742                                 D_MSG("hide delete button");
743                                 edje_object_signal_emit(_EDJ(page_data->upper_layout), "hide.delete", "*");
744                         }
745                 }
746         }
747
748         D_LEAVE;
749 }
750
751 void msg_ui_composer_body_entry_focused_cb(void *data, Evas_Object *obj, void *event_info)
752 {
753         D_ENTER;
754
755         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
756         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
757
758         if (msg_ui_composer_recipient_addr_type_get(cd->recipient) == COMPOSER_RECP_ADDR_INVALID) {
759                 /* if focused_cb is called twice becuase of double click, move focus to popup */
760                 if (msg_ui_composer_popup_exist(cd))
761                         msg_ui_composer_popup_focus(cd);
762
763                 return;
764         }
765
766         if (cd->msg_type == COMPOSER_MSG_TYPE_MMS) {
767                 MSG_COMPOSER_BODY_S *body_data = &cd->body_data;
768
769                 Eina_List *page_list = body_data->page_list;
770                 int page_count = body_data->page_count;
771
772                 if (page_count == 1) {
773                         D_MSG("page NO.1 focused !!!");
774                         cd->current_edit_entry = 0;
775                 } else {
776                         MSG_COMPOSER_BODY_PAGE_S *page_data = NULL;
777                         int i = 0;
778
779                         for (i = 0; i < page_count; i++) {
780                                 page_data = (MSG_COMPOSER_BODY_PAGE_S *)eina_list_nth(page_list, i);
781                                 if (page_data->entry == obj) {
782                                         D_MSG("page NO.[%d]/[%d] focused !!!", i + 1, page_count);
783                                         cd->current_edit_entry = i;
784                                         break;
785                                 }
786                         }
787                         page_data = evas_object_data_get(obj, "page_data");
788                         if (page_data == NULL) {
789                                 D_EMSG("page_data is NULL");
790                         } else {
791                                 /* show delete button */
792                                 D_MSG("show delete button");
793                                 edje_object_signal_emit(_EDJ(page_data->upper_layout), "show.delete", "*");
794                         }
795                 }
796         } else if (cd->msg_type == COMPOSER_MSG_TYPE_SMS) {
797                 cd->current_edit_entry = 0;
798         } else {
799                 D_MSG("message composer invalid message type");
800         }
801
802         msg_ui_composer_last_focused_entry_set(data, obj);
803
804         D_LEAVE;
805 }
806
807 void msg_ui_composer_body_page_del_btn_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
808 {
809         D_ENTER;
810         D_MSG_RETM_IF(obj == NULL, "obj is NULL");
811         elm_image_file_set(obj, MSG_IMAGES_EDJ, MSGC_IMG_DEL_BTN_PRESS_ICON);
812 }
813
814 void msg_ui_composer_body_page_del_btn_up_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
815 {
816         D_ENTER;
817         D_MSG_RETM_IF(obj == NULL, "obj is NULL");
818         elm_image_file_set(obj, MSG_IMAGES_EDJ, MSGC_IMG_PAGE_DEL_ICON);
819 }
820
821 void msg_ui_composer_body_page_del_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
822 {
823         D_ENTER;
824
825         if (!data) {
826                 MSG_UI_DEBUG(MSG_UI_LEVEL_ASSERT, "[ASSERT] Callback data is NULL");
827                 return;
828         }
829
830         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
831         Evas_Object *layout = evas_object_data_get(obj, "layout");
832
833         msg_ui_composer_mms_body_remove_page(cd, layout);
834
835         msg_ui_composer_message_type_check_and_change(cd);
836
837         msg_ui_composer_body_info_area_update(cd);
838
839         /* in invalid recipient case, give focus to other widget to call verify_cb of recipient */
840         if (msg_ui_composer_last_focus_is_recipient(cd)) {
841                 const char *recipient = msg_ui_composer_recipient_entry_text_get(cd->recipient);
842
843                 if (recipient && recipient[0] != '\0') {
844                         if (!msg_ui_composer_recipient_vaild_check(recipient))
845                                 elm_object_focus_set(cd->back_btn, EINA_TRUE);
846                 }
847         }
848         D_LEAVE;
849 }
850
851 static void __msg_ui_composer_body_launch_media_item(void *data, Evas_Object *obj)
852 {
853         D_ENTER;
854         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
855         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
856         D_MSG_RETM_IF(obj == NULL, "obj is NULL");
857
858         Evas_Object *layout = NULL;
859         MSG_COMPOSER_BODY_PAGE_S *page_data = NULL;
860         MSG_COMPOSER_BODY_S *body_data = &cd->body_data;
861         Eina_List *page_list = body_data->page_list;
862         int page_count = body_data->page_count;
863         int i = 0;
864         char file_path[COMPOSER_FILEPATH_LEN_MAX + 1] = {0, };
865
866         layout = evas_object_data_get(obj, "layout");
867
868         if (!layout || !page_list) {
869                 D_EMSG("Invalid data layout = %x, page_list = %x", layout, page_list);
870                 return;
871         }
872
873         for (i = 0; i < page_count; i++) {
874                 page_data = (MSG_COMPOSER_BODY_PAGE_S *)eina_list_nth(page_list, i);
875
876                 if (!page_data) {
877                         D_EMSG("page data is NULL !!!");
878                         return;
879                 }
880
881                 if (page_data->sound_item == layout) {
882                         strncpy(file_path, page_data->sound_file_path, COMPOSER_FILEPATH_LEN_MAX);
883                         break;
884                 } else if (page_data->image_item == layout) {
885                         strncpy(file_path, page_data->image_file_path, COMPOSER_FILEPATH_LEN_MAX);
886                         break;
887                 }
888         }
889
890         if (file_path[0] != '\0') {
891                 COMPOSER_EXT_TYPE_E type = COMPOSER_EXT_TYPE_COMMON;
892                 COMPOSER_MEDIA_TYPE_E media_type = msg_composer_get_media_type(file_path);
893
894                 if (media_type == COMPOSER_MEDIA_TYPE_IMAGE) {
895                         type = COMPOSER_EXT_TYPE_IMAGE;
896                 } else if (media_type == COMPOSER_MEDIA_TYPE_VIDEO) {
897                         type = COMPOSER_EXT_TYPE_COMMON;
898                 } else if (media_type == COMPOSER_MEDIA_TYPE_AUDIO) {
899                         type = COMPOSER_EXT_TYPE_SOUND;
900                 } else {
901                         type = COMPOSER_EXT_TYPE_COMMON;
902                 }
903
904                 msg_ui_composer_external_call(cd, type, file_path);
905         }
906
907         D_LEAVE;
908 }
909
910 void msg_ui_composer_body_media_layout_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
911 {
912         D_ENTER;
913         D_MSG_RETM_IF(data == NULL, "data is NULL");
914         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
915
916         __msg_ui_composer_body_launch_media_item(cd, obj);
917
918         D_LEAVE;
919 }
920
921 void msg_ui_composer_body_media_thumb_icon_clicked_cb(void *data, Evas_Object *obj, void *event_info)
922 {
923         D_ENTER;
924         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
925         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
926
927         if (!cd->is_default_body_size)
928                 __msg_ui_composer_body_launch_media_item(cd, obj);
929
930         D_LEAVE;
931 }
932
933 void msg_ui_composer_body_media_del_btn_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
934 {
935         D_ENTER;
936         D_MSG_RETM_IF(obj == NULL, "obj is NULL");
937         int media_type = 0;
938
939         media_type = (int)evas_object_data_get(obj, "media_type");
940         D_MSG("media_type = %d", media_type);
941
942         if (media_type == COMPOSER_MEDIA_TYPE_AUDIO)
943                 elm_image_file_set(obj, MSG_IMAGES_EDJ, MSGC_IMG_DEL_BTN_PRESS_ICON);
944         else
945                 elm_image_file_set(obj, MSG_IMAGES_EDJ, MSGC_IMG_INSERT_DEL_PRESS_ICON);
946 }
947
948 void msg_ui_composer_body_media_del_btn_up_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
949 {
950         D_ENTER;
951         D_MSG_RETM_IF(obj == NULL, "obj is NULL");
952         int media_type = 0;
953
954         media_type = (int)evas_object_data_get(obj, "media_type");
955
956         if (media_type == COMPOSER_MEDIA_TYPE_AUDIO)
957                 elm_image_file_set(obj, MSG_IMAGES_EDJ, MSGC_SOUND_INSERT_DEL_ICON);
958         else
959                 elm_image_file_set(obj, MSG_IMAGES_EDJ, MSGC_IMG_INSERT_DEL_ICON);
960 }
961
962 void msg_ui_composer_body_media_del_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
963 {
964         D_ENTER;
965
966         if (!data || !obj) {
967                 MSG_UI_DEBUG(MSG_UI_LEVEL_ASSERT, "[ASSERT] NULL pointer error");
968                 return;
969         }
970
971         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
972         MSG_COMPOSER_BODY_S *body_data = &cd->body_data;
973         MSG_COMPOSER_BODY_PAGE_S *page_data = NULL;
974         Eina_List *page_list = body_data->page_list;
975         int page_count = body_data->page_count;
976         int body_length = 0;
977
978         if (!cd->is_default_body_size) {
979                 Evas_Object *delete_layout = (Evas_Object *)evas_object_data_get(obj, "layout");
980
981                 int i = 0;
982
983                 for (i = 0; i < page_count; i++) {
984                         page_data = (MSG_COMPOSER_BODY_PAGE_S *)eina_list_nth(page_list, i);
985
986                         if (!page_data) {
987                                 MSG_UI_DEBUG(MSG_UI_LEVEL_ASSERT, "[ASSERT] page data is NULL !!!");
988                                 return;
989                         }
990
991                         if (page_data->sound_item == delete_layout) {
992                                 msg_ui_composer_mms_insert_item_remove(cd, delete_layout, COMPOSER_MEDIA_TYPE_AUDIO);
993
994                                 char *body_text = elm_entry_markup_to_utf8(elm_entry_entry_get(page_data->entry));
995                                 if (!body_text)
996                                         return;
997
998                                 body_length = strlen(body_text);
999
1000                                 if (body_length == 0 && !page_data->is_image_item)
1001                                         msg_ui_composer_mms_body_remove_page(cd, page_data->layout);
1002
1003                                 g_free(body_text);
1004
1005                                 break;
1006                         } else if (page_data->image_item == delete_layout) {
1007
1008                                 char *body_text = elm_entry_markup_to_utf8(elm_entry_entry_get(page_data->entry));
1009                                 if (!body_text)
1010                                         return;
1011
1012                                 body_length = strlen(body_text);
1013
1014                                 if (page_data->isVideo) {
1015                                         msg_ui_composer_mms_insert_item_remove(cd, delete_layout, COMPOSER_MEDIA_TYPE_VIDEO);
1016                                 } else {
1017                                         msg_ui_composer_mms_insert_item_remove(cd, delete_layout, COMPOSER_MEDIA_TYPE_IMAGE);
1018                                 }
1019
1020                                 if (body_length == 0 && !page_data->is_sound_item)
1021                                         msg_ui_composer_mms_body_remove_page(cd, page_data->layout);
1022
1023                                 g_free(body_text);
1024                                 break;
1025                         }
1026                 }
1027
1028                 msg_ui_composer_message_type_check_and_change(cd);
1029         }
1030
1031         /* in invalid recipient case, give focus to other widget to call verify_cb of recipient */
1032         if (msg_ui_composer_last_focus_is_recipient(cd)) {
1033                 const char *recipient = msg_ui_composer_recipient_entry_text_get(cd->recipient);
1034
1035                 if (recipient && recipient[0] != '\0') {
1036                         if (!msg_ui_composer_recipient_vaild_check(recipient))
1037                                 elm_object_focus_set(cd->back_btn, EINA_TRUE);
1038                 }
1039         }
1040
1041         D_LEAVE;
1042 }
1043
1044 void msg_ui_composer_body_body_layout_resize_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
1045 {
1046         D_ENTER;
1047
1048         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
1049         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
1050         Evas_Coord x = 0;
1051         Evas_Coord y = 0;
1052         Evas_Coord w = 0;
1053         Evas_Coord h = 0;
1054
1055         evas_object_geometry_get(obj, &x, &y, &w, &h);
1056         D_MSG("body layout height = %d", h);
1057
1058         cd->ly_body_h = h;
1059
1060         if (h >= COMPOSER_ENOUGH_TEXT_RENDERING_BODY_HEIGHT)
1061                 msg_ui_composer_body_info_area_update(cd);
1062         else
1063                 edje_object_part_text_set(_EDJ(cd->ly_body), "text.char_count", "");
1064
1065         D_LEAVE;
1066 }
1067
1068 void msg_ui_composer_body_body_layout_clicked_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
1069 {
1070         D_ENTER;
1071         D_MSG_RETM_IF(data == NULL, "data is NULL");
1072         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
1073
1074         msg_ui_composer_body_focus_set(cd, 0);
1075
1076         evas_object_event_callback_del(cd->body_box, EVAS_CALLBACK_MOUSE_UP, msg_ui_composer_body_body_layout_clicked_cb);
1077
1078         cd->is_default_body_size = false;
1079
1080         D_LEAVE;
1081 }
1082