Fix N_SE-22522, uri of filepath is supported
[apps/core/preloaded/message-app.git] / composer / src / ui-composer / msg-ui-composer-main.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 /* includes*/
18 #include <Ecore_X.h>
19 #include <tapi_common.h>
20 #include <TapiUtility.h>
21 #include <utilX.h>
22
23 #include "msg-ui-composer-main.h"
24 #include "msg-ui-composer-recipient.h"
25 #include "msg-ui-composer-popup.h"
26 #include "msg-ui-composer-predictsearch.h"
27 #include "msg-ui-composer-subject.h"
28 #include "msg-ui-composer-body.h"
29 #include "msg-ui-composer-pageduration.h"
30 #include "msg-ui-composer-message.h"
31 #include "msg-ui-composer-common.h"
32 #include "msg-ui-composer-external.h"
33 #include "msg-ui-composer-bubble.h"
34 #include "msg-ui-composer-main.h"       /*for page duration, it should be removed if more option concept is changed*/
35
36 #include "msg-ui-common-utility.h"
37
38 #define COMPOSER_BUNDLE_ATTACH_TOKEN "\n"
39 #define COMPOSER_BUNDLE_RECP_TOKEN ","
40
41 /*==================================================================================================
42 *                                                               FUNCTION IMPLEMENTATIONS
43 *==================================================================================================*/
44 static COMPOSER_EDIT_STATE_E __msg_ui_composer_edit_check(MSG_COMPOSER_VIEW_DATA_S *cd)
45 {
46         D_ENTER;
47         D_MSG_RETVM_IF(cd == NULL, COMPOSER_EDIT_NONE, "Composer Data == NULL");
48
49         bool isvalid_address = false;
50         bool iscontent_edited = false;
51
52         if (cd->msg_ug_mode == MSG_UG_MODE_FULL_COMPOSER || cd->msg_ug_mode == MSG_UG_MODE_ONLY_COMPOSER) {
53                 int recipient_count = msg_ui_composer_recipient_count_get(cd->recipient);
54                 if (recipient_count > 0) {
55                         isvalid_address = true;
56                 }
57
58                 const char *entry_str = msg_ui_composer_recipient_entry_text_get(cd->recipient);
59                 if (entry_str && strlen(entry_str)) {
60                         if (msg_ui_composer_recipient_vaild_check(entry_str) == EINA_TRUE)
61                                 isvalid_address = true;
62                 }
63         } else if (cd->msg_ug_mode == MSG_UG_MODE_BUBBLE_COMPOSER) {
64                 isvalid_address = true;
65         }
66
67         /* valid address & there is body content */
68         if (msg_ui_composer_common_is_send_possible(cd) == true)
69                 iscontent_edited = true;
70
71         if (isvalid_address && iscontent_edited)
72                 return COMPOSER_EDIT_RECIPIENT_AND_BODY;
73         else if (isvalid_address)
74                 return COMPOSER_EDIT_RECIPIENT;
75         else if (iscontent_edited)
76                 return COMPOSER_EDIT_BODY;
77         else
78                 return COMPOSER_EDIT_NONE;
79 }
80
81 static void __msgc_vconf_changed_cb(keynode_t *key, void *data)
82 {
83         D_ENTER;
84
85         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
86         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
87         D_MSG_RETM_IF(key == NULL, "key is NULL");
88
89         int index = 0;
90         int font_size = 0;
91         int converted_size = 0;
92         char *key_name = NULL;
93
94         key_name = vconf_keynode_get_name(key);
95         if (!key_name) {
96                 D_EMSG("key_name is NULL");
97                 return;
98         }
99
100         if (!strcmp(key_name, VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE)) {
101                 index = vconf_keynode_get_int(key);
102                 font_size = msg_common_get_font_size_from_index(index);
103                 converted_size = (MSGC_BODY_FONT_SIZE * font_size) / MSG_APP_FONT_SIZE_NORMAL;
104
105                 cd->font_size = converted_size;
106
107                 /* sync current font size as accessibility font index */
108                 if (msg_common_set_font_size(index) == FALSE)
109                         D_EMSG("msg_common_set_font_size(index = %d) is failed !!", index);
110
111                 /* sync msg accessibility font size with accessibility font index */
112                 if (msg_common_set_access_font_size(index) == FALSE)
113                         D_EMSG("vconf_set_int(VCONFKEY_MSG_APP_ACCESS_FONT_SIZE) is failed !!, [%d]", index);
114         } else if (!strcmp(key_name, VCONFKEY_MSG_APP_FONT_SIZE)) {
115                 index = vconf_keynode_get_int(key);
116                 font_size = msg_common_get_font_size_from_index(index);
117                 converted_size = (MSGC_BODY_FONT_SIZE * font_size) / MSG_APP_FONT_SIZE_NORMAL;
118
119                 cd->font_size = converted_size;
120         } else {
121                 D_EMSG("key did not match.");
122         }
123
124         D_MSG("font size = %d", font_size);
125         D_MSG("converted font size = %d", converted_size);
126
127         D_LEAVE;
128 }
129
130 static void __msgc_init_font_size(MSG_COMPOSER_VIEW_DATA_S *cd)
131 {
132         D_ENTER;
133         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
134
135         int index = 0;
136         int access_font_index = 0;
137         int msg_access_font_index = 0;
138         int font_size = 0;
139         int converted_size = 0;
140
141         /* get msg accessibility font index */
142         if (msg_common_get_access_font_size(&msg_access_font_index) == FALSE) {
143                 D_EMSG("msg_common_get_access_font_size is failed !!");
144                 msg_access_font_index = MSG_APP_FONT_SIZE_INDEX_NORMAL; /* 1 */
145         }
146
147         /* get accessibility font index */
148         if (vconf_get_int(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &access_font_index) < 0) {
149                 D_EMSG("vconf_get_int(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE) is failed !!");
150                 access_font_index = MSG_SYS_FONT_SIZE_INDEX_NORMAL;     /* 1 */
151         }
152
153         if (msg_common_get_font_size(&index) == FALSE) {
154                 D_EMSG("msg_common_get_font_size() is failed");
155                 cd->font_size = MSGC_BODY_FONT_SIZE;
156                 return;
157         } else {
158                 D_MSG("selected font_size index = %d", index);
159         }
160
161         D_MSG("VCONFKEY_MSG_APP_ACCESS_FONT_SIZE = %d", msg_access_font_index);
162         D_MSG("VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE = %d", access_font_index);
163
164         if (msg_access_font_index != access_font_index) {
165                 font_size = msg_common_get_font_size_from_index(access_font_index);
166
167                 /* sync current font size as accessibility font index */
168                 if (msg_common_set_font_size(access_font_index) == FALSE)
169                         D_EMSG("msg_common_set_font_size(index = %d) is failed !!", access_font_index);
170
171                 /* sync msg accessibility font size with accessibility font index */
172                 if (msg_common_set_access_font_size(access_font_index) == FALSE)
173                         D_EMSG("vconf_set_int(VCONFKEY_MSG_APP_ACCESS_FONT_SIZE) is failed !!, [%d]", access_font_index);
174         } else {
175                 font_size = msg_common_get_font_size_from_index(index);
176         }
177
178         converted_size = (MSGC_BODY_FONT_SIZE * font_size) / MSG_APP_FONT_SIZE_NORMAL;
179
180         cd->font_size = converted_size;
181         D_MSG("font size = %d, converted_size = %d", font_size, converted_size);
182
183         D_LEAVE;
184 }
185
186 static void __msgc_parse_recipient_list(MSG_COMPOSER_VIEW_DATA_S *cd, const char *address)
187 {
188         D_ENTER;
189         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
190         D_MSG_RETM_IF(address == NULL, "address is NULL");
191
192         bool bMaxCount = false;
193         bool bInvalidNum = false;
194         bool bDup = false;
195
196         Eina_List *recipient_list = make_tokenize_list(address, ",");
197
198         if (recipient_list) {
199                 Eina_List *l = NULL;
200                 char *recipient;
201                 EINA_LIST_FOREACH(recipient_list, l, recipient) {
202                         if (recipient) {
203                                 D_MSG("TO = %s", recipient);
204                                 if (msg_ui_composer_recipient_count_get(cd->recipient) >= COMPOSER_RECIPIENT_COUNT_MAX) {
205                                         bMaxCount = true;
206                                         g_free(recipient);
207                                         break;
208                                 }
209
210                                 if (msg_ui_composer_recipient_duplicate_check(cd->recipient, recipient) == COMPOSER_RETURN_RECIPIENT_DUPLICATE) {
211                                         bDup = true;
212                                         g_free(recipient);
213                                         continue;
214                                 }
215
216                                 if (msg_ui_composer_recipient_vaild_check(recipient) == EINA_FALSE) {
217                                         bInvalidNum = true;
218                                 } else {
219                                         msg_ui_composer_recipient_append(cd->recipient, recipient, 0);
220                                 }
221
222                                 g_free(recipient);
223                         }
224                 }
225
226                 D_MSG("bMaxCount = %d, bInvalidNum = %d, bDup = %d", bMaxCount, bInvalidNum, bDup);
227                 if (bMaxCount) {
228                         msg_ui_composer_common_tickernoti(cd, COMPOSER_TICKERNOTI_COUNT_MAX);
229                 } else if (bInvalidNum) {
230                         msg_ui_composer_status_btn_popup_show(cd, MSGC_STR_NOTI_RECIPIENT_INVALID, 0, MSGC_STR_BUTTON_OK);
231                 } else if (bDup) {
232                         msg_ui_composer_common_tickernoti(cd, COMPOSER_TICKERNOTI_DUP_RECP);
233                 }
234         }
235
236         D_LEAVE;
237 }
238
239 static void __msgc_ui_parse_mmsto_uri(MSG_COMPOSER_VIEW_DATA_S *cd, service_h svc_handle, const char *uri)
240 {
241         D_ENTER;
242         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
243         D_MSG_RETM_IF(svc_handle == NULL, "svc_handle is NULL");
244         D_MSG_RETM_IF(uri == NULL, "uri is NULL");
245
246         char *content = NULL;
247         char *recipient = NULL;
248         char *body_text = NULL;
249         char *subject = NULL;
250         char *attachment = NULL;
251         char *cc = NULL;
252         char *scheme = g_strdup(uri);
253
254         if (scheme) {
255                 strtok_r(scheme, ":", &content);
256
257                 if (content) {
258                         if (g_ascii_isdigit(content[0]) || (content[0] == '+' && g_ascii_isdigit(content[1]))) {
259                                 recipient = strtok_r(NULL, "?", &content);
260                                 cc = strtok_r(NULL, "&", &content);
261                                 if (cc)
262                                         strtok_r(NULL, "=", &cc);
263
264                                 D_MSG("RECIPIENT = [%s]", recipient);
265                                 if (recipient)
266                                         __msgc_parse_recipient_list(cd, (const char *)recipient);
267                         }
268                 }
269                 g_free(scheme);
270         } else {
271                 if ((service_get_extra_data(svc_handle, SERVICE_DATA_TO, &recipient) == SERVICE_ERROR_NONE) && recipient) {
272                         __msgc_parse_recipient_list(cd, (const char *)recipient);
273                 }
274         }
275
276         if ((service_get_extra_data(svc_handle, SERVICE_DATA_TEXT, &body_text) == SERVICE_ERROR_NONE) && body_text)
277                 msg_ui_composer_body_set_loaded_text(cd, (const char *)body_text, 0);
278
279         if ((service_get_extra_data(svc_handle, SERVICE_DATA_SUBJECT, &subject) == SERVICE_ERROR_NONE) && subject)
280                 msg_ui_composer_subject_set_loaded_data(cd, (const char *)subject);
281
282         if ((service_get_extra_data(svc_handle, MSG_BUNDLE_KEY_ATTACHFILE, &attachment) == SERVICE_ERROR_NONE) && attachment) {
283                 cd->attachlist = make_tokenize_list((const char *)attachment, COMPOSER_BUNDLE_ATTACH_TOKEN);
284                 if (cd->attachlist)
285                         msg_ui_composer_body_items_add(cd);
286         }
287
288         D_LEAVE;
289 }
290
291 static void __msgc_ui_parse_file_uri(MSG_COMPOSER_VIEW_DATA_S *cd, service_h svc_handle, const char *uri)
292 {
293         D_ENTER;
294         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
295         D_MSG_RETM_IF(uri == NULL, "uri is NULL");
296
297         char *content = NULL;
298         char attachment[DEF_IMG_PATH_LEN + 1] = {0, };
299         int i = 0;
300         int len = 0;
301         char *scheme = g_strdup(uri);
302
303         if (scheme) {
304                 strtok_r(scheme, ":", &content);
305                 D_MSG("content = [%s]", content);
306
307                 if (content) {
308                         len = strlen(content) - 2;
309                         if (len <= 0) {
310                                 D_EMSG("len is less than 0 !!");
311                                 g_free(scheme);
312                                 return;
313                         }
314
315                         /* Remove '//' from content string */
316                         for (i = 0; i < len; i++) {
317                                 attachment[i] = content[i+2];
318                         }
319
320                         if (attachment[0] != '\0') {
321                                 D_MSG("APPSVC ATTACHMENT = [%s]", attachment);
322                                 cd->attachlist = make_tokenize_list((const char *)attachment, COMPOSER_BUNDLE_ATTACH_TOKEN);
323                                 if (cd->attachlist)
324                                         msg_ui_composer_body_items_add(cd);
325                         }
326                 }
327                 g_free(scheme);
328         } else {
329                 D_EMSG("scheme is NULL!!");
330         }
331
332         D_LEAVE;
333 }
334
335 static void __msg_ui_parse_sms_uri(MSG_COMPOSER_VIEW_DATA_S *cd, service_h svc_handle, const char *uri)
336 {
337         D_ENTER;
338         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
339         D_MSG_RETM_IF(svc_handle == NULL, "svc_handle is NULL");
340         D_MSG_RETM_IF(uri == NULL, "uri is NULL");
341
342         char *content = NULL;
343         char *recipient = NULL;
344         char *body_text = NULL;
345         char *scheme = g_strdup(uri);
346
347         if (scheme) {
348                 strtok_r(scheme, ":", &content);
349
350                 if (content) {
351                         if (g_ascii_isdigit(content[0]) || (content[0] == '+' && g_ascii_isdigit(content[1]))) {
352                                 recipient = strtok_r(NULL, "?", &content);
353                                 D_MSG("RECIPIENT = [%s]", recipient);
354
355                                 if (recipient)
356                                         __msgc_parse_recipient_list(cd, (const char *)recipient);
357                         }
358                 }
359                 g_free(scheme);
360         } else {
361                 if ((service_get_extra_data(svc_handle, SERVICE_DATA_TO, &recipient) == SERVICE_ERROR_NONE) && recipient)
362                         __msgc_parse_recipient_list(cd, (const char *)recipient);
363         }
364
365         if ((service_get_extra_data(svc_handle, SERVICE_DATA_TEXT, &body_text) == SERVICE_ERROR_NONE) && body_text)
366                 msg_ui_composer_body_set_loaded_text(cd, (const char *)body_text, 0);
367
368         D_LEAVE;
369 }
370
371 static void __msgc_get_service_app_svc_op(MSG_COMPOSER_VIEW_DATA_S *cd, service_h svc_handle, char *operation)
372 {
373         D_ENTER;
374         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
375         D_MSG_RETM_IF(svc_handle == NULL, "svc_handle is NULL");
376         D_MSG_RETM_IF(operation == NULL, "operation is NULL");
377
378         char *uri = NULL;
379         char *recipient = NULL;
380         char *body_text = NULL;
381         char *attachment = NULL;
382         char *subject = NULL;
383
384         if (g_strcmp0(operation, SERVICE_OPERATION_SEND) == 0) {
385                 if (service_get_uri(svc_handle, &uri) == SERVICE_ERROR_NONE)
386                         D_MSG("URI = [%s]", uri);
387
388                 if (uri) {
389                         if (g_str_has_prefix(uri, MSG_BUNDLE_VALUE_MMSTO_URI)) { /* MMS URI : mmsto */
390                                  __msgc_ui_parse_mmsto_uri(cd, svc_handle, (const char *)uri);
391                         } else if (g_str_has_prefix(uri, MSG_BUNDLE_VALUE_FILE_URI)) { /* URI : file */
392                                  __msgc_ui_parse_file_uri(cd, svc_handle, (const char *)uri);
393                         } else if (g_str_has_prefix(uri, "/")) {
394                                 cd->attachlist = make_tokenize_list((const char *)uri, COMPOSER_BUNDLE_ATTACH_TOKEN);
395                                 if (cd->attachlist)
396                                         msg_ui_composer_body_items_add(cd);
397                         } else {
398                                 D_EMSG("Not supported URI type");
399                                 return;
400                         }
401                 } else {
402                         if ((service_get_extra_data(svc_handle, SERVICE_DATA_TO, &recipient) == SERVICE_ERROR_NONE) && recipient)
403                                 __msgc_parse_recipient_list(cd, (const char *)recipient);
404
405                         if ((service_get_extra_data(svc_handle, SERVICE_DATA_TEXT, &body_text) == SERVICE_ERROR_NONE) && body_text)
406                                 msg_ui_composer_body_set_loaded_text(cd, (const char *)body_text, 0);
407
408                         if ((service_get_extra_data(svc_handle, SERVICE_DATA_SUBJECT, &subject) == SERVICE_ERROR_NONE) && subject)
409                                 msg_ui_composer_subject_set_loaded_data(cd, (const char *)subject);
410
411                         if ((service_get_extra_data(svc_handle, MSG_BUNDLE_KEY_ATTACHFILE, &attachment) == SERVICE_ERROR_NONE) && attachment) {
412                                 cd->attachlist = make_tokenize_list((const char *)attachment, COMPOSER_BUNDLE_ATTACH_TOKEN);
413                                 if (cd->attachlist)
414                                         msg_ui_composer_body_items_add(cd);
415                         }
416                 }
417         } else if (g_strcmp0(operation, SERVICE_OPERATION_SEND_TEXT) == 0) {
418                 if (service_get_uri(svc_handle, &uri) == SERVICE_ERROR_NONE)
419                         D_MSG("URI = [%s]", uri);
420
421                 if (uri) {
422                         if (g_str_has_prefix(uri, MSG_BUNDLE_VALUE_SMS_URI)) {  /* SMS URI : sms */
423                                 __msg_ui_parse_sms_uri(cd, svc_handle, (const char *)uri);
424                         } else {
425                                 D_EMSG("Not supported mime type");
426                                 return;
427                         }
428                 } else {
429                         if ((service_get_extra_data(svc_handle, SERVICE_DATA_TO, &recipient) == SERVICE_ERROR_NONE) && recipient)
430                                 __msgc_parse_recipient_list(cd, (const char *)recipient);
431
432                         if ((service_get_extra_data(svc_handle, SERVICE_DATA_TEXT, &body_text) == SERVICE_ERROR_NONE) && body_text)
433                                 msg_ui_composer_body_set_loaded_text(cd, (const char *)body_text, 0);
434                 }
435         } else {
436                 D_EMSG("Invalid operation type !!");
437         }
438
439         D_LEAVE;
440 }
441
442 /* function definitions*/
443 static void __msg_ui_composer_bundle_data_process(MSG_COMPOSER_VIEW_DATA_S *cd, service_h svc_handle)
444 {
445         D_ENTER;
446         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
447         D_MSG_RETM_IF(svc_handle == NULL, "Bundle Data is NULL");
448
449         char *bundle_txt = NULL;
450
451         if (cd->isAppControl) { /* composer launching from appcontrol */
452                 char *operation = NULL;
453
454                 service_get_operation(svc_handle, &operation);
455                 __msgc_get_service_app_svc_op(cd, svc_handle, operation);
456         } else {
457                 if (cd->composer_mode == MSG_COMPOSER_MODE_EDIT || cd->composer_mode == MSG_COMPOSER_MODE_FORWARD) {
458                         if ((service_get_extra_data(svc_handle, MSG_BUNDLE_KEY_MSG_ID, &bundle_txt) == SERVICE_ERROR_NONE) && bundle_txt) {
459                                 bool set_recipient = false;
460                                 int msg_id = atoi(bundle_txt);
461
462                                 if (cd->composer_mode == MSG_COMPOSER_MODE_EDIT)
463                                         set_recipient = true;
464
465                                 msg_ui_composer_message_init();
466                                 msg_ui_composer_message_load_message(cd->msg_handle, msg_id);
467                                 if (msg_ui_composer_message_set_loaded_data(cd, set_recipient) != COMPOSER_RETURN_CREATION_WARINING_MODE_FAIL)
468                                         msg_ui_composer_message_destroy();
469
470                         } else {
471                                 D_EMSG("there is no msgid");
472                         }
473                 } else {
474                         if ((service_get_extra_data(svc_handle, MSG_BUNDLE_KEY_TO, &bundle_txt) == SERVICE_ERROR_NONE) && bundle_txt) {
475                                 __msgc_parse_recipient_list(cd, bundle_txt);
476                         } else {
477                                 if ((service_get_extra_data(svc_handle, MSG_BUNDLE_KEY_NUMBER_INDEX, &bundle_txt)== SERVICE_ERROR_NONE) && bundle_txt) {
478                                         char *recipient = NULL;
479                                         char *index  = NULL;
480                                         char *save_p = NULL;
481                                         int idx = 0;
482
483                                         char *copy_string = MSG_STRDUP(bundle_txt);
484                                         if (copy_string) {
485
486                                                 recipient = strtok_r(copy_string, "/", &save_p);
487                                                 if (recipient) {
488                                                         index = strtok_r(NULL, "/", &save_p);
489                                                         if (index) {
490                                                                 D_MSG("NUMBER_INDEX = %s[%s]", recipient, index);
491                                                                 idx = atoi(index);
492                                                         } else {
493                                                                 idx = 0;
494                                                         }
495
496                                                         if (msg_ui_composer_recipient_count_get(cd->recipient) >= COMPOSER_RECIPIENT_COUNT_MAX) {
497                                                                 msg_ui_composer_common_tickernoti(cd, COMPOSER_TICKERNOTI_COUNT_MAX);
498                                                         } else {
499                                                                 if (msg_ui_composer_recipient_duplicate_check(cd->recipient, recipient) == COMPOSER_RETURN_RECIPIENT_DUPLICATE) {
500                                                                         msg_ui_composer_common_tickernoti(cd, COMPOSER_TICKERNOTI_DUP_RECP);
501                                                                 } else {
502                                                                         if (msg_ui_composer_recipient_vaild_check(recipient) == EINA_FALSE) {
503                                                                                 msg_ui_composer_status_btn_popup_show(cd, MSGC_STR_NOTI_RECIPIENT_INVALID, 0, MSGC_STR_BUTTON_OK);
504                                                                         } else {
505                                                                                 msg_ui_composer_recipient_append(cd->recipient, recipient, idx);
506                                                                         }
507                                                                 }
508                                                         }
509                                                 }
510
511                                                 g_free(copy_string);
512                                         }
513                                 }
514                         }
515
516                         if (SERVICE_ERROR_NONE == service_get_extra_data(svc_handle, MSG_BUNDLE_KEY_SUBJECT, &bundle_txt))
517                                 msg_ui_composer_subject_set_loaded_data(cd, bundle_txt);
518
519                         if (SERVICE_ERROR_NONE == service_get_extra_data(svc_handle, MSG_BUNDLE_KEY_BODY, &bundle_txt))
520                                 msg_ui_composer_body_set_loaded_text(cd, bundle_txt, 0);
521
522                         if (SERVICE_ERROR_NONE == service_get_extra_data(svc_handle, MSG_BUNDLE_KEY_ATTACHFILE, &bundle_txt)) {
523                                 cd->attachlist = make_tokenize_list(bundle_txt, COMPOSER_BUNDLE_ATTACH_TOKEN);
524                                 if (cd->attachlist)
525                                         msg_ui_composer_body_items_add(cd);
526                         }
527                 }
528         }
529
530         D_LEAVE;
531 }
532
533 static void __msg_ui_composer_sent_status_cb(msg_handle_t Handle, msg_struct_t pStatus, void *pUserParam)
534 {
535         D_ENTER;
536         D_LEAVE;
537
538         return;
539 }
540
541 static void __end_popup_ok_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
542 {
543         D_ENTER;
544         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
545         D_MSG_RETM_IF(cd == NULL, "composer data is NULL");
546
547         MSGC_EVAS_OBJECT_DEL(cd->popup_end);
548
549         ug_destroy_me(cd->ug);
550 }
551
552 static void __end_popup_cancel_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
553 {
554         D_ENTER;
555         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
556         D_MSG_RETM_IF(cd == NULL, "composer data is NULL");
557
558         MSGC_EVAS_OBJECT_DEL(cd->popup_end);
559
560         cd->isclosed = false;
561
562         msg_ui_composer_last_focus_load(cd);
563         D_LEAVE;
564 }
565
566 static void  __msg_ui_composer_end_popup(MSG_COMPOSER_VIEW_DATA_S *cd)
567 {
568         D_ENTER;
569
570         MSGC_EVAS_OBJECT_DEL(cd->popup_end);
571
572         Evas_Object *popup = msg_ui_composer_status_popup_show(cd->main_window, cd, MSGC_STR_POP_DISCARD_Q, 0);
573         Evas_Object *btn1 = elm_button_add(popup);
574         elm_object_style_set(btn1, "popup_button/default");
575         elm_object_text_set(btn1, MSGC_STR_BUTTON_OK);
576         elm_object_part_content_set(popup, "button1", btn1);
577         evas_object_smart_callback_add(btn1, "clicked", __end_popup_ok_btn_clicked_cb, cd);
578         Evas_Object *btn2 = elm_button_add(popup);
579         elm_object_style_set(btn2, "popup_button/default");
580         elm_object_text_set(btn2, MSGC_STR_BUTTON_CANCEL);
581         elm_object_part_content_set(popup, "button2", btn2);
582         evas_object_smart_callback_add(btn2, "clicked", __end_popup_cancel_btn_clicked_cb, cd);
583         elm_object_focus_set(popup, EINA_TRUE);
584         evas_object_show(popup);
585
586         cd->popup_end = popup;
587
588         D_LEAVE;
589         return;
590 }
591
592 static void __naviframe_back_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
593 {
594         D_ENTER;
595         D_MSG_RETM_IF(data == NULL, "Data == NULL");
596         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
597
598         COMPOSER_EDIT_STATE_E edit_state = __msg_ui_composer_edit_check(cd);
599         D_MSG("edit_state = %d", edit_state);
600
601         if (cd->msg_ug_mode == MSG_UG_MODE_FULL_COMPOSER || cd->msg_ug_mode == MSG_UG_MODE_ONLY_COMPOSER) {
602                 if (cd->isclosed) {
603                         D_EMSG("back btn is already called");
604                         return;
605                 }
606
607                 /* isclosed is set to prevent showing invalid popup*/
608                 cd->isclosed = true;
609
610                 if (edit_state == COMPOSER_EDIT_RECIPIENT || edit_state == COMPOSER_EDIT_BODY) {
611                         __msg_ui_composer_end_popup(cd);
612                         return;
613                 }
614         } else if (cd->msg_ug_mode == MSG_UG_MODE_BUBBLE_COMPOSER) {
615                 if (edit_state == COMPOSER_EDIT_RECIPIENT) {
616
617                         PMSG_BUBBLE_DATA bubble_data = cd->bubble_data;
618
619                         if (bubble_data->title_menu_opened)
620                                 msg_ui_bubble_close_title_menu_genlist(bubble_data);
621
622                         if (bubble_data->bubble_count == 0) {
623                                 int err = MSG_SUCCESS;
624
625                                 if (bubble_data->isDraft == true)
626                                         err = msg_delete_thread_message_list(bubble_data->msgHandle, bubble_data->threadId, false);
627
628                                 if (err == MSG_SUCCESS) {
629                                         service_h svc_handle;
630                                         char buf[DEF_BUF_LEN_S] = {0,};
631
632                                         if (service_create(&svc_handle) < 0 || svc_handle == NULL) {
633                                                 D_EMSG("service_create() is failed !!");
634                                         } else {
635                                                 service_add_extra_data(svc_handle, MSG_BUNDLE_KEY_RESULT, MSG_BUNDLE_VALUE_DEL_ALL);
636                                                 snprintf(buf, sizeof(buf), "%d", bubble_data->threadId);
637                                                 service_add_extra_data(svc_handle, MSG_BUNDLE_KEY_THREAD_ID, buf);
638                                                 ug_send_result(cd->ug, svc_handle);
639
640                                                 service_destroy(svc_handle);
641                                         }
642                                 } else {
643                                         D_MSG("msg_delete_thread_message_list failed");
644                                 }
645                         }
646                 }
647         }
648
649         ug_destroy_me(cd->ug);
650
651         D_LEAVE;
652 }
653
654 static void __preview_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
655 {
656         D_ENTER;
657         MSG_COMPOSER_VIEW_DATA_S *cd = data;
658         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
659         D_MSG_RETM_IF(cd->navi_it == NULL, "Naviitem is NULL");
660
661         msg_struct_t msgInfo = NULL;
662         msg_ui_composer_message_init();
663         msg_ui_composer_read_preview_message(cd);
664
665         /* make preview message data */
666         msgInfo = msg_ui_composer_message_make_preview(cd->msg_handle);
667
668         if (msgInfo)
669                 msg_ui_composer_external_call(cd, COMPOSER_EXT_TYPE_MSGVIEWER, msgInfo);
670
671         msg_ui_composer_message_destroy();
672
673         if (cd->ctx_popup) {
674                 evas_object_del(cd->ctx_popup);
675                 cd->ctx_popup = NULL;
676         }
677
678         D_LEAVE;
679 }
680
681 static void __pageduration_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
682 {
683         D_ENTER;
684         MSG_COMPOSER_VIEW_DATA_S *cd = data;
685         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
686         D_MSG_RETM_IF(cd->navi_it == NULL, "Naviitem is NULL");
687
688         msg_ui_composer_pageduration_popup_create(cd);
689
690         if (cd->ctx_popup) {
691                 evas_object_del(cd->ctx_popup);
692                 cd->ctx_popup = NULL;
693         }
694
695         D_LEAVE;
696 }
697
698 static void __msg_ui_composer_ctxpopup_dismissed_cb(void *data, Evas_Object *obj, void *event_info)
699 {
700         MSG_UI_ENTER();
701         MSG_COMPOSER_VIEW_DATA_S *cd = data;
702
703         if (cd->ctx_popup) {
704                 evas_object_del(cd->ctx_popup);
705                 cd->ctx_popup = NULL;
706         }
707
708         MSG_UI_LEAVE();
709 }
710
711 static void msg_composer_naviframe_more_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
712 {
713         MSG_UI_ENTER();
714         MSG_UI_RET_IF(MSG_UI_LEVEL_ERR, !data || !obj);
715
716         MSG_COMPOSER_VIEW_DATA_S *cd = data;
717         PMSG_BUBBLE_DATA bubble_data = cd->bubble_data;
718         Evas_Object *ctx_popup = NULL;
719
720         if (cd->popup_end) {
721                 evas_object_del(cd->popup_end);
722                 cd->popup_end = NULL;
723         }
724
725         if (bubble_data) {
726                 if (bubble_data->popup) {
727                         evas_object_del(bubble_data->popup);
728                         bubble_data->popup = NULL;
729                 }
730
731                 if (bubble_data->title_menu_opened)
732                         msg_ui_bubble_close_title_menu_genlist(bubble_data);
733         }
734
735         /* fix ctx_popup flashing issue because of focus */
736         ctx_popup = elm_ctxpopup_add(cd->main_window);
737         elm_ctxpopup_direction_priority_set(ctx_popup, ELM_CTXPOPUP_DIRECTION_DOWN,
738                                                  ELM_CTXPOPUP_DIRECTION_UNKNOWN,
739                                                  ELM_CTXPOPUP_DIRECTION_UNKNOWN,
740                                                  ELM_CTXPOPUP_DIRECTION_UNKNOWN);
741
742         evas_object_smart_callback_add(ctx_popup, "dismissed", __msg_ui_composer_ctxpopup_dismissed_cb, cd);
743
744         if (cd->msg_ug_mode == MSG_UG_MODE_BUBBLE_COMPOSER)
745                 elm_ctxpopup_item_append(ctx_popup, dgettext("sys_string", "IDS_COM_SK_DELETE"), NULL, msg_ui_bubble_more_delete_clicked_cb, cd);
746
747         if (cd->msg_type == COMPOSER_MSG_TYPE_MMS) {
748                 /* preview */
749                 if (msg_ui_composer_body_has_media(cd))
750                         elm_ctxpopup_item_append(ctx_popup, MSGC_STR_PREVIEW, NULL, __preview_btn_clicked_cb, cd);
751
752                 /* page duration */
753                 char buf[DEF_BUF_LEN_S + 1] = {0,};
754                 char duration[DEF_BUF_LEN_D + 1] = {0,};
755                 const char *str = _MSGSTR("IDS_MSGC_OPT2_DURATION_HPS_SEC_ABB");
756                 int pageduration = msg_ui_composer_pageduration_value_get(cd);
757
758                 snprintf(duration, sizeof(duration)-1, "%d", pageduration);
759                 snprintf(buf, sizeof(buf)-1, str, duration);
760                 elm_ctxpopup_item_append(ctx_popup, buf, NULL, __pageduration_btn_clicked_cb, cd);
761         }
762
763         if (cd->msg_ug_mode == MSG_UG_MODE_BUBBLE_COMPOSER)
764                 elm_ctxpopup_item_append(ctx_popup, dgettext(MESSAGE_PKGNAME, "IDS_MSG_HEADER_BACKUP"), NULL, msg_ui_bubble_backup_clicked_cb, cd);
765
766         Evas_Coord x = 0;
767         Evas_Coord y = 0;
768         Evas_Coord w = 0;
769         Evas_Coord h = 0;
770         evas_object_geometry_get(cd->more_btn, &x, &y, &w, &h);
771         evas_object_move(ctx_popup, (x+(w/2)) , y+h);
772         evas_object_show(ctx_popup);
773
774         cd->ctx_popup = ctx_popup;
775
776         MSG_UI_LEAVE();
777 }
778
779 static void __naviframe_compose_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
780 {
781         D_ENTER;
782         MSG_UI_RET_IF(MSG_UI_LEVEL_ERR, !data || !obj);
783
784         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
785
786         if (cd->bubble_data->popup) {
787                 evas_object_del(cd->bubble_data->popup);
788                 cd->bubble_data->popup = NULL;
789         }
790
791         service_h svc_handle;
792
793         if (service_create(&svc_handle) < 0 || svc_handle == NULL) {
794                 D_EMSG("service_create() is failed !!");
795         } else {
796                 service_add_extra_data(svc_handle, MSG_BUNDLE_KEY_MODE, MSG_BUNDLE_VALUE_EDIT);
797                 service_add_extra_data(svc_handle, MSG_BUNDLE_KEY_FROM, MSG_BUNDLE_VALUE_INTERNAL);
798                 msg_ui_composer_launch_composer_create(cd, svc_handle);
799                 service_destroy(svc_handle);
800         }
801         D_LEAVE;
802 }
803
804 static Evas_Object *__naviframe_back_btn_create(Evas_Object *parent, void *data, bool title)
805 {
806         D_ENTER;
807         D_MSG_RETVM_IF(parent == NULL, NULL, "parent == NULL");
808         D_MSG_RETVM_IF(data == NULL, NULL, "data == NULL");
809         D_MSG("Title type = %d", title);
810
811         Evas_Object *btn = NULL;
812         btn = elm_button_add(parent);
813         if (btn == NULL)
814                 return NULL;
815
816         if (title == true) {
817                 elm_object_style_set(btn, "naviframe/back_btn/default");
818         } else {
819                 elm_object_style_set(btn, "naviframe/back_btn/default");
820         }
821         evas_object_smart_callback_add(btn, "clicked", __naviframe_back_btn_clicked_cb, data);
822         evas_object_show(btn);
823         D_LEAVE;
824         return btn;
825 }
826
827 static Evas_Object *__naviframe_more_btn_create(Evas_Object *parent, void *data)
828 {
829         D_ENTER;
830         D_MSG_RETVM_IF(parent == NULL, NULL, "parent == NULL");
831         D_MSG_RETVM_IF(data == NULL, NULL, "data == NULL");
832
833         Evas_Object *btn = elm_button_add(parent);
834         if (!btn)
835                 return NULL;
836
837         elm_object_style_set(btn, "naviframe/more/default");
838
839         evas_object_smart_callback_add(btn, "clicked", msg_composer_naviframe_more_btn_clicked_cb, data);
840         evas_object_show(btn);
841         D_LEAVE;
842         return btn;
843 }
844
845 static Evas_Object *__naviframe_compose_btn_create(Evas_Object *parent, void *data)
846 {
847         D_ENTER;
848         D_MSG_RETVM_IF(parent == NULL, NULL, "parent == NULL");
849         D_MSG_RETVM_IF(data == NULL, NULL, "data == NULL");
850
851         Evas_Object *btn = elm_button_add(parent);
852         if (!btn)
853                 return NULL;
854         elm_object_style_set(btn, "naviframe/title_icon");
855
856         Evas_Object *icon = elm_icon_add(btn);
857         elm_image_file_set(icon, MSG_IMAGES_EDJ, MSG_UI_THREAD_LIST_TITLE_ICON_COMPOSE);
858         elm_image_resizable_set(icon, 1, 1);
859         evas_object_image_smooth_scale_set(icon, 0);
860         elm_object_content_set(btn, icon);
861         evas_object_smart_callback_add(btn, "clicked", __naviframe_compose_btn_clicked_cb, data);
862         D_LEAVE;
863
864         return btn;
865 }
866
867 void msg_ui_composer_reset_request(MSG_COMPOSER_VIEW_DATA_S *cd, service_h svc_handle)
868 {
869         D_ENTER;
870
871         if (!cd)
872                 return;
873
874         COMPOSER_EDIT_STATE_E edit_state = __msg_ui_composer_edit_check(cd);
875         D_MSG("edit_state = %d", edit_state);
876         D_MSG("composer mode = %d, msg_ug_mode = %d", cd->composer_mode, cd->msg_ug_mode);
877
878         if (cd->msg_ug_mode == MSG_UG_MODE_FULL_COMPOSER || cd->msg_ug_mode == MSG_UG_MODE_ONLY_COMPOSER) {
879                 if (edit_state == COMPOSER_EDIT_RECIPIENT_AND_BODY) {
880                         /* auto saving */
881                         msg_ui_composer_message_init();
882
883                         if (msg_ui_composer_get_message_data(cd) == COMPOSER_RETURN_SUCCESS) {
884                                 msg_ui_composer_save_message(cd->msg_handle);
885                         }
886
887                         msg_ui_composer_message_destroy();
888                 }
889         } else if (cd->msg_ug_mode == MSG_UG_MODE_BUBBLE_COMPOSER) {
890                 if (edit_state == COMPOSER_EDIT_RECIPIENT) {
891                         PMSG_BUBBLE_DATA bubble_data = cd->bubble_data;
892
893                         if (bubble_data->title_menu_opened)
894                                 msg_ui_bubble_close_title_menu_genlist(bubble_data);
895
896                         if (bubble_data->bubble_count == 0) {
897                                 int err = MSG_SUCCESS;
898
899                                 if (bubble_data->isDraft == true)
900                                         err = msg_delete_thread_message_list(bubble_data->msgHandle, bubble_data->threadId, false);
901
902                                 if (err == MSG_SUCCESS) {
903                                         service_h svc_handle;
904                                         if (service_create(&svc_handle) < 0 || svc_handle == NULL) {
905                                                 D_EMSG("service_create() is failed !!");
906                                         } else {
907                                                 char buf[DEF_BUF_LEN_S] = {0,};
908                                                 service_add_extra_data(svc_handle, MSG_BUNDLE_KEY_RESULT, MSG_BUNDLE_VALUE_DEL_ALL);
909                                                 snprintf(buf, sizeof(buf), "%d", bubble_data->threadId);
910                                                 service_add_extra_data(svc_handle, MSG_BUNDLE_KEY_THREAD_ID, buf);
911
912                                                 ug_send_result(cd->ug, svc_handle);
913
914                                                 service_destroy(svc_handle);
915                                         }
916                                 } else {
917                                         D_MSG("msg_delete_thread_message_list failed");
918                                 }
919                         } else {
920                                 /* delete draft message */
921                                 msg_struct_list_s msg_list = {0,};
922
923                                 if (msg_get_message_list(cd->msg_handle, MSG_DRAFT_ID, bubble_data->threadId, 0, 0, &msg_list) == COMPOSER_RETURN_SUCCESS) {
924                                         int i = 0;
925                                         int msgid = 0;
926
927                                         for (i = 0; i < msg_list.nCount; i++) {
928                                                 msg_get_int_value(msg_list.msg_struct_info[i], MSG_MESSAGE_ID_INT, &msgid);
929                                                 D_MSG("draft msg_id is %d", msgid);
930                                                 if (msg_delete_message(cd->msg_handle, msgid) != COMPOSER_RETURN_SUCCESS)
931                                                         D_EMSG("msg_ui_comp_core_delete_message is failed = %d", msgid);
932                                         }
933                                 }
934
935                                 msg_release_list_struct(&msg_list);
936                         }
937                 } else if (edit_state == COMPOSER_EDIT_RECIPIENT_AND_BODY) {
938                         /* auto saving */
939                         msg_ui_composer_message_init();
940
941                         if (msg_ui_composer_get_message_data(cd) == COMPOSER_RETURN_SUCCESS) {
942                                 msg_ui_composer_save_message(cd->msg_handle);
943                         }
944
945                         msg_ui_composer_message_destroy();
946                 }
947
948                 /* clear recipient_list of bubble composer */
949                 msg_ui_composer_recipient_clear_recipient_list(cd);
950         }
951
952         /*process reset*/
953         msg_ui_composer_reset(cd, svc_handle);
954
955         D_LEAVE;
956 }
957
958 /*
959  *      1. clear all composer editing obj
960  *      2. make composer using bundle val
961 */
962 COMPOSER_RETURN_TYPE_E msg_ui_composer_reset(MSG_COMPOSER_VIEW_DATA_S *cd, service_h svc_handle)
963 {
964         D_ENTER;
965         if (!cd)
966                 return COMPOSER_RETURN_FAIL;
967
968         if (cd->working_path) {
969                 ecore_file_recursive_rm(cd->working_path);
970                 g_free(cd->working_path);
971         }
972
973         cd->working_path = msg_composer_create_working_dir();
974
975         if (cd->working_path == NULL) {
976                 D_EMSG("Fail of make working dir!!!");
977                 return COMPOSER_RETURN_FAIL;
978         }
979
980         if (svc_handle) {
981                 msg_ui_composer_clear(cd);
982
983                 char *thread_id = NULL;
984                 char *msg_id = NULL;
985                 char *composer_mode = NULL;
986                 char *from = NULL;
987
988                 service_get_extra_data(svc_handle, MSG_BUNDLE_KEY_THREAD_ID, &thread_id);
989                 service_get_extra_data(svc_handle, MSG_BUNDLE_KEY_MSG_ID, &msg_id);
990                 service_get_extra_data(svc_handle, MSG_BUNDLE_KEY_MODE, &composer_mode);
991                 service_get_extra_data(svc_handle, MSG_BUNDLE_KEY_FROM, &from);
992
993                 if (composer_mode) {
994                         if (g_strcmp0(composer_mode, MSG_BUNDLE_VALUE_EDIT) == 0)
995                                 cd->composer_mode = MSG_COMPOSER_MODE_EDIT;
996                         else if (g_strcmp0(composer_mode, MSG_BUNDLE_VALUE_FORWARD) == 0)
997                                 cd->composer_mode = MSG_COMPOSER_MODE_FORWARD;
998                         else
999                                 cd->composer_mode = MSG_COMPOSER_MODE_NORMAL;
1000                 } else {
1001                         cd->composer_mode = MSG_COMPOSER_MODE_NORMAL;
1002                 }
1003
1004                 if (from && g_strcmp0(from, MSG_BUNDLE_VALUE_INTERNAL) == 0)
1005                         cd->isMsgInternal = true;
1006                 else
1007                         cd->isMsgInternal = false;
1008
1009                 /*Change to Bubble view*/
1010                 if ((thread_id || msg_id) && cd->composer_mode == MSG_COMPOSER_MODE_NORMAL) {
1011                         D_MSG("bubble view composer mode = %d, msg_ug_mode = %d", cd->composer_mode, cd->msg_ug_mode);
1012
1013                         if (cd->msg_ug_mode == MSG_UG_MODE_FULL_COMPOSER) {
1014                                 D_MSG("change bubble view");
1015                                 msg_ui_composer_change_bubble_view(cd);
1016                                 msg_ui_bubble_parse_bubble_data(cd->bubble_data, svc_handle);
1017                                 msg_ui_bubble_start_view(cd->bubble_data);
1018                                 msg_ui_composer_navi_title_set((void *)cd);
1019
1020                                 /* set recipient list for bubble composer */
1021                                 msg_ui_composer_recipient_set_recipient_list(cd, cd->bubble_data->threadId);
1022                         } else if (cd->msg_ug_mode == MSG_UG_MODE_BUBBLE_COMPOSER) {
1023                                 D_MSG("reload bubble view");
1024                                 msg_ui_bubble_parse_bubble_data(cd->bubble_data, svc_handle);
1025                                 msg_ui_bubble_list_load(cd->bubble_data);
1026                                 msg_ui_composer_navi_title_set((void *)cd);
1027
1028                                 /* set recipient list for bubble composer */
1029                                 msg_ui_composer_recipient_set_recipient_list(cd, cd->bubble_data->threadId);
1030                         } else {
1031                                 D_EMSG("Invalid type");
1032                         }
1033
1034                         cd->msg_ug_mode = MSG_UG_MODE_BUBBLE_COMPOSER;
1035                 } else {
1036                         D_MSG("normal composer composer mode = %d, msg_ug_mode = %d", cd->composer_mode, cd->msg_ug_mode);
1037
1038                         if (cd->msg_ug_mode == MSG_UG_MODE_BUBBLE_COMPOSER) {
1039                                 D_MSG("change composer view");
1040                                 if (cd->bubble_data) {
1041                                         cd->bubble_data->ug_state = BUBBLE_UG_DESTROY;
1042                                         msg_ui_bubble_deinit_bubble_data(cd->bubble_data);
1043                                         cd->bubble_data = NULL;
1044                                 }
1045
1046                                 msg_ui_composer_change_composer_view(cd);
1047                         }
1048
1049                         if (cd->isMsgInternal == true)
1050                                 cd->msg_ug_mode = MSG_UG_MODE_FULL_COMPOSER;
1051                         else
1052                                 cd->msg_ug_mode = MSG_UG_MODE_ONLY_COMPOSER;
1053
1054                         __msg_ui_composer_bundle_data_process(cd, svc_handle);
1055                 }
1056         }
1057
1058         D_LEAVE;
1059         return COMPOSER_RETURN_SUCCESS;
1060 }
1061
1062 COMPOSER_RETURN_TYPE_E msg_ui_composer_start(MSG_COMPOSER_VIEW_DATA_S *cd, service_h svc_handle)
1063 {
1064         D_ENTER;
1065         D_MSG_RETVM_IF(cd == NULL, COMPOSER_RETURN_FAIL, "Composer Data is NULL");
1066
1067         COMPOSER_RETURN_TYPE_E ret = COMPOSER_RETURN_SUCCESS;
1068         cd->state = COMPOSER_STATE_TYPE_RUNNING;
1069
1070         /* bundle data parsing */
1071         if (svc_handle) {
1072                 if (cd->msg_ug_mode == MSG_UG_MODE_FULL_COMPOSER || cd->msg_ug_mode == MSG_UG_MODE_ONLY_COMPOSER) {
1073                         cd->isLoad = true;
1074                         __msg_ui_composer_bundle_data_process(cd, svc_handle);
1075
1076                         if (cd->attachlist == NULL)
1077                                 cd->isLoad = false;
1078
1079                 } else if (cd->msg_ug_mode == MSG_UG_MODE_BUBBLE_COMPOSER) {
1080                         D_MSG("START BUBBLE COMPOSER");
1081                         PMSG_BUBBLE_DATA bubble_data = (PMSG_BUBBLE_DATA)cd->bubble_data;
1082                         msg_ui_bubble_parse_bubble_data(bubble_data, svc_handle);
1083                         msg_ui_bubble_start_view(bubble_data);
1084                         msg_ui_composer_navi_title_set((void *)cd);
1085
1086                         /* set recipient list for bubble composer */
1087                         msg_ui_composer_recipient_set_recipient_list(cd, cd->bubble_data->threadId);
1088                 }
1089         }
1090
1091         /* set first focus*/
1092         if (cd->msg_ug_mode == MSG_UG_MODE_FULL_COMPOSER || cd->msg_ug_mode == MSG_UG_MODE_ONLY_COMPOSER) {
1093                 if (!msg_ui_composer_popup_exist(cd)) {
1094
1095                         int recipient_count = msg_ui_composer_recipient_count_get(cd->recipient);
1096
1097                         if (recipient_count > 0) {
1098                                 msg_ui_composer_body_focus_set(cd, 0);
1099                                 msg_ui_composer_recipient_expanded_set(cd->recipient, EINA_FALSE);
1100                         } else {
1101                                 msg_ui_composer_recipient_focus_set(cd->recipient);
1102                         }
1103                 }
1104         }
1105
1106         D_LEAVE;
1107         return ret;
1108 }
1109
1110 static void __msg_composer_auto_save_and_delete_msg(MSG_COMPOSER_VIEW_DATA_S *cd)
1111 {
1112         D_ENTER;
1113         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
1114
1115         /* save and delete msg */
1116         if (!cd->disable_auto_save_mode) {
1117                 COMPOSER_EDIT_STATE_E edit_state = __msg_ui_composer_edit_check(cd);
1118                 if (edit_state == COMPOSER_EDIT_RECIPIENT_AND_BODY) {
1119                         /* auto save composer data */
1120                         msg_ui_composer_message_init();
1121
1122                         if (msg_ui_composer_get_message_data(cd) == COMPOSER_RETURN_SUCCESS) {
1123                                 D_MSG("save draft message");
1124                                 msg_ui_composer_save_message(cd->msg_handle);
1125                                 /* show saved ticker popup */
1126                                 msg_ui_composer_common_tickernoti(cd, COMPOSER_TICKERNOTI_AUTO_SAVED);
1127                         }
1128
1129                         msg_ui_composer_message_destroy();
1130                 } else if (edit_state == COMPOSER_EDIT_RECIPIENT) {
1131                         if (cd->msg_ug_mode == MSG_UG_MODE_BUBBLE_COMPOSER) {
1132                                 /* delete draft message */
1133                                 MSG_BUBBLE_DATA *bubble_data = cd->bubble_data;
1134
1135                                 if (bubble_data) {
1136                                         msg_struct_list_s msg_list = {0,};
1137
1138                                         if (msg_get_message_list(cd->msg_handle, MSG_DRAFT_ID, bubble_data->threadId, 0, 0, &msg_list) == MSG_SUCCESS) {
1139                                                 int i = 0;
1140                                                 int msgid = 0;
1141
1142                                                 D_MSG("delete draft message");
1143                                                 for (i = 0; i < msg_list.nCount; i++) {
1144                                                         msg_get_int_value(msg_list.msg_struct_info[i], MSG_MESSAGE_ID_INT, &msgid);
1145                                                         D_MSG("draft msg_id is %d", msgid);
1146                                                         if (msg_delete_message(cd->msg_handle, msgid) != COMPOSER_RETURN_SUCCESS)
1147                                                                 D_EMSG("msg_ui_comp_core_delete_message is failed = %d", msgid);
1148                                                 }
1149                                         }
1150                                         msg_release_list_struct(&msg_list);
1151                                 }
1152                         }
1153                 }
1154         }
1155
1156         D_LEAVE;
1157 }
1158
1159 COMPOSER_RETURN_TYPE_E msg_ui_composer_destroy(MSG_COMPOSER_VIEW_DATA_S *cd)
1160 {
1161         D_ENTER;
1162
1163         COMPOSER_RETURN_TYPE_E ret = COMPOSER_RETURN_SUCCESS;
1164         if (!cd)
1165                 return COMPOSER_RETURN_FAIL;
1166
1167         D_PRINT("===== Composer UG Destroy Start =====");
1168
1169         __msg_composer_auto_save_and_delete_msg(cd);
1170
1171         /* discoonect volume key handler */
1172         msg_ui_composer_disconnect_handler(cd);
1173
1174         contacts_disconnect2();
1175
1176         D_PRINT("----- Unregister vconf callback -----");
1177         if (vconf_ignore_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, __msgc_vconf_changed_cb) < 0) {
1178                 D_EMSG("Fail to unregister vconf CB with [%s]", VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE);
1179         }
1180         if (vconf_ignore_key_changed(VCONFKEY_MSG_APP_FONT_SIZE, __msgc_vconf_changed_cb) < 0) {
1181                 D_EMSG("Fail to unregister vconf CB with [%s]", VCONFKEY_MSG_APP_FONT_SIZE);
1182         }
1183
1184         if (cd->tapi_handle) {
1185                 if (tel_deinit(cd->tapi_handle) != TAPI_API_SUCCESS)
1186                         D_EMSG("tel_deinit is failed");
1187                 cd->tapi_handle = NULL;
1188         }
1189
1190         if(cd->job_thread_end) {
1191                 D_PRINT("----- Job Delete -----");
1192                 ecore_job_del(cd->job_thread_end);
1193                 cd->job_thread_end = NULL;
1194         }
1195
1196         if(cd->attach_thread) {
1197                 D_PRINT("----- Thread Delete -----");
1198                 ecore_thread_cancel(cd->attach_thread);
1199                 cd->attach_thread = NULL;
1200         }
1201
1202         if (cd->last_focus_idler) {
1203                 D_PRINT("----- idler Delete -----");
1204                 ecore_idler_del(cd->last_focus_idler);
1205                 cd->last_focus_idler = NULL;
1206         }
1207
1208         if (cd->flight_mode_timer) {
1209                 ecore_timer_del(cd->flight_mode_timer);
1210                 cd->flight_mode_timer = NULL;
1211         }
1212
1213         if (cd->recipient) {
1214                 D_PRINT("----- Recipient Delete -----");
1215                 msg_ui_composer_recipient_delete(cd->recipient);
1216                 cd->recipient = NULL;
1217         }
1218
1219         D_PRINT("----- Recipient list Clear -----");
1220         msg_ui_composer_recipient_clear_recipient_list(cd);
1221
1222         D_PRINT("----- Predict Search Delete -----");
1223         msg_ui_composer_predictsearch_list_delete(cd);
1224
1225         D_PRINT("----- Body Delete -----");
1226         msg_ui_composer_body_delete(cd);
1227
1228         D_PRINT("----- Close Msg Handle -----");
1229         msg_close_msg_handle(&cd->msg_handle);
1230
1231         D_PRINT("----- Delete Popup  -----");
1232         msg_ui_composer_popup_delete_all(cd);
1233
1234         if (cd->working_path) {
1235                 ecore_file_recursive_rm(cd->working_path);
1236                 g_free(cd->working_path);
1237                 cd->working_path = NULL;
1238         }
1239
1240         if (cd->th) {
1241                 elm_theme_extension_del(cd->th, MSG_CUSTOM_WINSET_EDJ);
1242                 elm_theme_free(cd->th);
1243                 cd->th = NULL;
1244         }
1245
1246         /* rollback indicator mode to previous mode */
1247         elm_win_indicator_mode_set(cd->main_window, cd->indicator_mode);
1248
1249         D_PRINT("===== Composer UG Destroy End =====");
1250
1251         D_LEAVE;
1252         return ret;
1253 }
1254
1255 void msg_ui_composer_change_language(MSG_COMPOSER_VIEW_DATA_S *cd)
1256 {
1257         D_ENTER;
1258         D_MSG_RETM_IF(cd == NULL, "cd is NULL");
1259
1260         if (cd->msg_ug_mode == MSG_UG_MODE_FULL_COMPOSER || cd->msg_ug_mode == MSG_UG_MODE_ONLY_COMPOSER) {
1261                 /* destroy popup */
1262                 msg_ui_composer_popup_delete_all(cd);
1263
1264                 if (cd->ctx_popup) {
1265                         evas_object_del(cd->ctx_popup);
1266                         cd->ctx_popup = NULL;
1267                 }
1268
1269                 /* title */
1270                 msg_ui_composer_navi_title_set(cd);
1271
1272                 /* recipient */
1273                 if (cd->recipient) {
1274                         Evas_Object *mbe = cd->recipient->mbe;
1275
1276                         /* set mbe label */
1277                         char label_txt[TO_FIELD_LABEL_SIZE_MAX] = { 0, };
1278                         gsize len = 0;
1279
1280                         len = snprintf(label_txt, (gsize)sizeof(label_txt), "%s:", MSGC_STR_TO);
1281                         if (len == -1) {
1282                                 D_EMSG("len = %d", len);
1283                         } else if (len > 0) {
1284                                 label_txt[len] = '\0';
1285                                 elm_object_text_set(mbe, label_txt);
1286                         } else {
1287                                 D_EMSG("len = %d", len);
1288                         }
1289
1290                         /* set guide text */
1291                         elm_object_part_text_set(mbe, "guide", MSGC_STR_ADD_RECIPIENT);
1292                 }
1293
1294                 /* subject */
1295                 if (cd->sub_data.entry)
1296                         edje_object_part_text_set(_EDJ(cd->sub_data.layout), "subject.guidetxt", MSGC_STR_SUBJECT);
1297
1298                 /* attachment */
1299                 if (cd->ly_attach_main) {
1300                         char buf[DEF_BUF_LEN_S + 1] = {0,};
1301                         const char *str = _MSGSTR("IDS_MSGC_BODY_PD_ATTACHMENTS");
1302
1303                         snprintf(buf, sizeof(buf), str, cd->attach_data.attachment_Cnt);
1304                         edje_object_part_text_set(_EDJ(cd->ly_attach_main), "text.filename", buf);
1305                 }
1306
1307                 /* mms size */
1308                 if (cd->msg_type == COMPOSER_MSG_TYPE_MMS)
1309                         msg_ui_composer_body_info_area_update(cd);
1310         }
1311
1312         cd->isclosed = false;
1313
1314         D_LEAVE;
1315 }
1316
1317 COMPOSER_RETURN_TYPE_E msg_ui_composer_rotate(MSG_COMPOSER_VIEW_DATA_S *cd, COMPOSER_ROTATE_TYPE_E rotate)
1318 {
1319         D_ENTER;
1320         D_MSG_RETVM_IF(cd == NULL, COMPOSER_RETURN_FAIL, "cd is NULL");
1321
1322         cd->rotate = rotate;
1323         D_MSG("rotate val [%d]", rotate);
1324
1325         if (cd->msg_ug_mode == MSG_UG_MODE_FULL_COMPOSER || cd->msg_ug_mode == MSG_UG_MODE_ONLY_COMPOSER) {
1326
1327                 RECIPIENT_S *r = cd->recipient;
1328                 if (!r) return COMPOSER_RETURN_FAIL;
1329
1330                 if (rotate == COMPOSER_ROTATE_PORTRAIT || rotate == COMPOSER_ROTATE_PORTRAIT_UPSIDEDOWN) {
1331                         elm_layout_theme_set(cd->base, "layout", "application", "default");
1332
1333                         elm_win_indicator_mode_set(cd->main_window, ELM_WIN_INDICATOR_SHOW);
1334
1335                         elm_box_horizontal_set(r->bx_main, EINA_FALSE);
1336                         elm_scroller_content_min_limit(r->sc, EINA_FALSE, EINA_TRUE);
1337                         evas_object_size_hint_max_set(r->sc, 9999, COMPOSER_RECIPIENT_PORTRAIT_HEIGHT_MAX);
1338                 } else if (rotate == COMPOSER_ROTATE_LANDSCAPE || rotate == COMPOSER_ROTATE_LANDSCAPE_UPSIDEDOWN) {
1339                         elm_layout_theme_set(cd->base, "layout", "application", "noindicator");/*hide indicator in Landscape*/
1340                         elm_win_indicator_mode_set(cd->main_window, ELM_WIN_INDICATOR_HIDE);
1341                         D_MSG("hide indicator");
1342                         elm_box_horizontal_set(r->bx_main, EINA_TRUE);
1343                         elm_scroller_content_min_limit(r->sc, EINA_FALSE, EINA_FALSE);
1344                         evas_object_size_hint_max_set(r->sc, 9999, -1);
1345                 }
1346
1347                 /* change body scroller size */
1348                 msg_ui_composer_change_body_scroll_size(cd, 0);
1349
1350         } else if (cd->msg_ug_mode == MSG_UG_MODE_BUBBLE_COMPOSER) {
1351                 if (rotate == COMPOSER_ROTATE_PORTRAIT || rotate == COMPOSER_ROTATE_PORTRAIT_UPSIDEDOWN) {
1352                         if (cd->bubble_data)
1353                                 cd->bubble_data->isRotate = false;
1354
1355                         if (cd->compose_btn) {
1356                                 evas_object_hide(cd->compose_btn);
1357                                 elm_object_part_content_unset(cd->navi_title_layout, "compose_btn");
1358                         }
1359                 } else if (rotate == COMPOSER_ROTATE_LANDSCAPE || rotate == COMPOSER_ROTATE_LANDSCAPE_UPSIDEDOWN) {
1360                         if (cd->bubble_data) {
1361                                 cd->bubble_data->isRotate = true;
1362
1363                                 if (cd->compose_btn && cd->bubble_data->viewmode == BUBBLE_NORMAL_VIEW) {
1364                                         evas_object_show(cd->compose_btn);
1365                                         elm_object_part_content_set(cd->navi_title_layout, "compose_btn", cd->compose_btn);
1366                                 }
1367                         }
1368                 }
1369
1370                 elm_win_indicator_mode_set(cd->main_window, ELM_WIN_INDICATOR_SHOW);
1371
1372                 /* change body scroller size */
1373                 msg_ui_composer_change_body_scroll_size(cd, 0);
1374
1375         } else {
1376                 D_EMSG("Unknown Composer Mode");
1377                 return COMPOSER_RETURN_FAIL;
1378         }
1379
1380         D_LEAVE;
1381         return COMPOSER_RETURN_SUCCESS;
1382 }
1383
1384 COMPOSER_RETURN_TYPE_E msg_ui_composer_init(MSG_COMPOSER_VIEW_DATA_S *cd)
1385 {
1386         D_ENTER;
1387
1388         if (cd == NULL) {
1389                 D_EMSG("[ASSERT] pcmop_data is NULL");
1390                 return COMPOSER_RETURN_FAIL;
1391         }
1392
1393         /* create message handle */
1394         if (msg_open_msg_handle(&cd->msg_handle) != MSG_SUCCESS) {
1395                 D_EMSG("[ASSERT] msg-server doesn't response !!!");
1396                 return COMPOSER_RETURN_FAIL;
1397         }
1398
1399         /* set message sent status callback */
1400         if (msg_reg_sent_status_callback(cd->msg_handle, &__msg_ui_composer_sent_status_cb, cd) != MSG_SUCCESS) {
1401                 D_EMSG("[ASSERT] sent status callback register error!!!");
1402                 return COMPOSER_RETURN_FAIL;
1403         }
1404
1405         /* connect contacts svc*/
1406         if (contacts_connect2() != 0) {
1407                 D_EMSG("[ASSERT] Fail of contacts_connect2 !!!");
1408                 return COMPOSER_RETURN_FAIL;
1409         }
1410
1411         cd->working_path = msg_composer_create_working_dir();
1412         if (cd->working_path == NULL) {
1413                 D_EMSG("[ASSERT] Fail of make working dir!!!");
1414                 return COMPOSER_RETURN_FAIL;
1415         }
1416
1417         /* set default message type is SMS */
1418         cd->msg_type = COMPOSER_MSG_TYPE_SMS;
1419
1420         /* get sms setting */
1421         msg_struct_t sms_sent_opt = msg_create_struct(MSG_STRUCT_SETTING_SMS_SEND_OPT);
1422
1423         if (msg_get_sms_send_opt(cd->msg_handle, sms_sent_opt) != MSG_SUCCESS) {
1424                 D_EMSG("Getting SMS_SEND_OP ERROR");
1425         } else {
1426                 msg_get_int_value(sms_sent_opt, MSG_SMS_SENDOPT_ENCODE_TYPE_INT, &cd->encode_mode);
1427                 D_MSG("SMS Encode mode is %d", cd->encode_mode);
1428         }
1429
1430         msg_release_struct(&sms_sent_opt);
1431
1432         if (cd->cms_max_page == 0) {
1433                 // TODO: get cms max page from msgfw when it is supported by msgfw.
1434                 cd->cms_max_page = COMPOSER_CMS_MAX_PAGE;
1435         }
1436
1437         /* get mms max size */
1438         if (cd->mms_max_size == 0) {
1439                 msg_struct_t setting = msg_create_struct(MSG_STRUCT_SETTING_MSGSIZE_OPT);
1440
1441                 if (msg_get_msgsize_opt(cd->msg_handle, setting) != MSG_SUCCESS) {
1442                         D_EMSG("Getting MMS MAX SIZE ERROR");
1443                 } else {
1444                         if (setting)
1445                                 msg_get_int_value(setting, MSG_MESSAGE_SIZE_INT, &cd->mms_max_size);
1446
1447                         D_MSG("msg max size = [%d KB] !!!", cd->mms_max_size);
1448                         cd->mms_max_size = cd->mms_max_size * 1024;
1449                 }
1450                 msg_release_struct(&setting);
1451         }
1452
1453         /* set default font size*/
1454         __msgc_init_font_size(cd);
1455
1456         /* coonect volume key handler */
1457         msg_ui_composer_connect_handler(cd);
1458
1459         /* register vconf callback function */
1460         if (vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, __msgc_vconf_changed_cb, cd) < 0) {
1461                 D_EMSG("Fail to register vconf CB with [%s]", VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE);
1462         }
1463         if (vconf_notify_key_changed(VCONFKEY_MSG_APP_FONT_SIZE, __msgc_vconf_changed_cb, cd) < 0) {
1464                 D_EMSG("Fail to register vconf CB with [%s]", VCONFKEY_MSG_APP_FONT_SIZE);
1465         }
1466
1467         cd->th = elm_theme_new();
1468         elm_theme_ref_set(cd->th, NULL);
1469         elm_theme_extension_add(cd->th, MSG_CUSTOM_WINSET_EDJ);
1470
1471         return COMPOSER_RETURN_SUCCESS;
1472 }
1473
1474 /*
1475  * Create Composer First View
1476  */
1477 COMPOSER_RETURN_TYPE_E msg_ui_composer_create(MSG_COMPOSER_VIEW_DATA_S *cd)
1478 {
1479         D_ENTER;
1480         D_MSG_RETVM_IF(cd == NULL, COMPOSER_RETURN_FAIL, "Composer data is NULL");
1481         D_MSG_RETVM_IF(cd->main_window == NULL, COMPOSER_RETURN_FAIL, "main_window is NULL");
1482         D_MSG_RETVM_IF(cd->base == NULL, COMPOSER_RETURN_FAIL, "base layout is NULL");
1483
1484         Evas_Object *navi_frame = NULL;
1485         Evas_Object *more_button = NULL;
1486         Evas_Object *compose_button = NULL;
1487         Evas_Object *content_layout = NULL;
1488         Elm_Object_Item *navi_it = NULL;
1489         Evas_Object *back_btn = NULL;
1490
1491         /* State Set */
1492         cd->state = COMPOSER_STATE_TYPE_CREATE;
1493
1494         /* Create naviframe */
1495         navi_frame = elm_naviframe_add(cd->base);
1496         if (!navi_frame) {
1497                 D_EMSG("naviframe add fail");
1498                 goto error_return;
1499         }
1500
1501         evas_object_show(navi_frame);
1502         cd->navi_bar = navi_frame;
1503
1504         /* Create content layout */
1505         content_layout = elm_layout_add(navi_frame);
1506         if (!content_layout) {
1507                 D_EMSG("layout add fail");
1508                 goto error_return;
1509         }
1510
1511         if (cd->msg_ug_mode == MSG_UG_MODE_FULL_COMPOSER || cd->msg_ug_mode == MSG_UG_MODE_ONLY_COMPOSER) {
1512                 elm_layout_file_set(content_layout, MSGC_UI_DEFAULT_EDJ, MSGC_EDJ_GRP_CONTENT_LAYOUT);
1513         } else if (cd->msg_ug_mode == MSG_UG_MODE_BUBBLE_COMPOSER){
1514                 elm_layout_file_set(content_layout, MSGC_UI_DEFAULT_EDJ, MSGC_EDJ_GRP_CONTENT_LAYOUT);
1515                 edje_object_signal_emit(_EDJ(content_layout), "change.bubble", "*");
1516         } else {
1517                 D_EMSG("UG mode Unknown");
1518                 goto error_return;
1519         }
1520
1521         evas_object_size_hint_weight_set(content_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1522         evas_object_size_hint_align_set(content_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
1523         edje_object_signal_emit(_EDJ(content_layout), "hide.predictsearch", "*");
1524         evas_object_show(content_layout);
1525
1526         cd->content_layout = content_layout;
1527
1528         /*Create content*/
1529         if (cd->msg_ug_mode == MSG_UG_MODE_FULL_COMPOSER || cd->msg_ug_mode == MSG_UG_MODE_ONLY_COMPOSER) {
1530                 cd->recipient = msg_ui_composer_recipient_create(content_layout, 1, cd);
1531                 if (cd->recipient == NULL)
1532                         goto error_return;
1533
1534                 elm_object_part_content_set(content_layout, "swl.recipient", cd->recipient->bx_main);
1535
1536                 Evas_Object *predict_search_layout = msg_ui_composer_predictsearch_list_create(content_layout, cd);
1537                 elm_object_part_content_set(content_layout, "swl.predictsearch", predict_search_layout);
1538
1539         } else {
1540                 PMSG_BUBBLE_DATA bubble_data = msg_ui_bubble_init_bubble_data(cd->msg_handle, cd);
1541                 if (!bubble_data) {
1542                         goto error_return;
1543                 }
1544
1545                 cd->bubble_data = bubble_data;
1546
1547                 Evas_Object *bubble_layout = msg_ui_bubble_create_view(content_layout, cd->bubble_data);
1548                 if (!bubble_layout) {
1549                         goto error_return;
1550                 }
1551                 elm_object_part_content_set(content_layout, "swl.bubble.content", bubble_layout);
1552         }
1553
1554         Evas_Object *body_layout = msg_ui_composer_body_create(cd, content_layout);
1555         if (!body_layout) {
1556                 goto error_return;
1557         }
1558
1559         elm_object_part_content_set(content_layout, "swl.composer.body", body_layout);
1560
1561         cd->ly_body = body_layout;
1562
1563         /*Push content to navi frame*/
1564         if (cd->msg_ug_mode == MSG_UG_MODE_FULL_COMPOSER || cd->msg_ug_mode == MSG_UG_MODE_ONLY_COMPOSER) {
1565                 if (cd->isMsgInternal)
1566                         back_btn = __naviframe_back_btn_create(navi_frame, (void *)cd, false);
1567                 else
1568                         back_btn = __naviframe_back_btn_create(navi_frame, (void *)cd, true);
1569         } else {
1570                 back_btn = __naviframe_back_btn_create(navi_frame, (void *)cd, false);
1571         }
1572
1573         navi_it = elm_naviframe_item_push(navi_frame, NULL, NULL, NULL, content_layout, "empty");
1574
1575         cd->navi_it = navi_it;
1576         cd->back_btn = back_btn;
1577
1578         /* create navi title layout */
1579         cd->navi_title_layout = msg_ui_composer_create_navi_title_bar(cd);
1580         msg_ui_composer_navi_title_set(cd);
1581         elm_object_item_part_content_set(cd->navi_it, "title", cd->navi_title_layout);
1582
1583         /*Create more button*/
1584         more_button = __naviframe_more_btn_create(navi_frame, cd);
1585
1586         elm_object_part_content_set(cd->navi_title_layout, "more_btn", more_button);
1587         elm_object_part_content_set(cd->navi_title_layout, "prev_btn", back_btn);
1588
1589         cd->more_btn = more_button;
1590
1591         /*Create compose button*/
1592         compose_button = __naviframe_compose_btn_create(navi_frame, cd);
1593
1594         if (cd->bubble_data != NULL && cd->bubble_data->isRotate == true) {
1595                 evas_object_show(compose_button);
1596                 elm_object_part_content_set(cd->navi_title_layout, "compose_btn", compose_button);
1597         } else {
1598                 evas_object_hide(compose_button);
1599                 elm_object_part_content_unset(cd->navi_title_layout, "compose_btn");
1600         }
1601
1602         cd->compose_btn = compose_button;
1603
1604         /* set navibar to main layout (base) */
1605         elm_object_part_content_set(cd->base, "elm.swallow.content", navi_frame);
1606
1607         D_LEAVE;
1608         return COMPOSER_RETURN_SUCCESS;
1609
1610 error_return:
1611         return COMPOSER_RETURN_FAIL;
1612 }
1613
1614 COMPOSER_RETURN_TYPE_E msg_ui_composer_bubble_data_set(MSG_COMPOSER_VIEW_DATA_S *cd, int thread_id)
1615 {
1616         D_ENTER;
1617         D_MSG_RETVM_IF(cd == NULL, COMPOSER_RETURN_FAIL, "Composer data is NULL");
1618         D_MSG_RETVM_IF(cd->msg_ug_mode != MSG_UG_MODE_BUBBLE_COMPOSER, COMPOSER_RETURN_FAIL, "msg_ug_mode is NOT BUBBLE TYPE");
1619         D_MSG_RETVM_IF(thread_id <=  0, COMPOSER_RETURN_FAIL, "Composer mode is Not Full");
1620         D_MSG_RETVM_IF(cd->bubble_data == NULL, COMPOSER_RETURN_FAIL, "bubble data is NULL");
1621
1622         PMSG_BUBBLE_DATA bubble_data = cd->bubble_data;
1623         msg_struct_t threadInfo = NULL;
1624         int err;
1625
1626         /*Create bubble list*/
1627         bubble_data->threadId = thread_id;
1628         D_MSG("Thread ID = %d", bubble_data->threadId);
1629
1630         msg_struct_list_s addrList;
1631         int i = 0;
1632         memset(&addrList, 0x00, sizeof(msg_struct_list_s));
1633
1634         err = msg_get_address_list(bubble_data->msgHandle, bubble_data->threadId, &addrList);
1635
1636         if (err == MSG_SUCCESS) {
1637                 bubble_data->addr_list.addr_cnt = addrList.nCount;
1638
1639                 for (i = 0; i<addrList.nCount; i++) {
1640                         int contact_id = 0;
1641                         msg_get_int_value(addrList.msg_struct_info[i], MSG_ADDRESS_INFO_CONTACT_ID_INT, &contact_id);
1642                         /** addresss */
1643                         msg_get_str_value(addrList.msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, bubble_data->addr_list.addr_info[i].address, DEF_THREAD_ADDR_LEN);
1644
1645                         /** contact ID & display name */
1646                         if (contact_id > 0) {
1647                                 bubble_data->addr_list.addr_info[i].contact_id = contact_id;
1648                                 msg_get_str_value(addrList.msg_struct_info[i], MSG_ADDRESS_INFO_DISPLAYNAME_STR, bubble_data->addr_list.addr_info[i].name, DEF_THREAD_NAME_LEN);
1649                         } else {
1650                                 bubble_data->addr_list.addr_info[i].contact_id = 0;
1651                         }
1652                 }
1653
1654                 msg_release_list_struct(&addrList);
1655         } else {
1656                 D_MSG("[ERROR] msg_get_address_list returns error [%d]", err);
1657         }
1658
1659         threadInfo = msg_create_struct(MSG_STRUCT_THREAD_INFO);
1660         err = msg_get_thread(bubble_data->msgHandle, bubble_data->threadId, threadInfo);
1661
1662         if (err == MSG_SUCCESS)
1663                 msg_get_str_value(threadInfo, MSG_THREAD_NAME_STR, bubble_data->threadName, DEF_THREAD_NAME_LEN);
1664         else
1665                 D_MSG("[ERROR] msg_get_trhead returns error [%d", err);
1666
1667         msg_release_struct(&threadInfo);
1668
1669         return COMPOSER_RETURN_SUCCESS;
1670 }
1671
1672 COMPOSER_RETURN_TYPE_E msg_ui_composer_change_composer_view(MSG_COMPOSER_VIEW_DATA_S *cd)
1673 {
1674         D_ENTER;
1675         D_MSG_RETVM_IF(cd == NULL, COMPOSER_RETURN_FAIL, "Composer data is NULL");
1676         D_MSG_RETVM_IF(cd->msg_ug_mode != MSG_UG_MODE_BUBBLE_COMPOSER, COMPOSER_RETURN_FAIL, "Composer mode is Not Full");
1677
1678         /*Change Mode */
1679         cd->msg_ug_mode = MSG_UG_MODE_ONLY_COMPOSER;
1680
1681         /*Change content layout to composer layout*/
1682         edje_object_signal_emit(_EDJ(cd->content_layout), "change.composer", "*");
1683
1684         elm_scroller_content_min_limit(cd->body_scroll, 0, 0);
1685
1686         cd->recipient = msg_ui_composer_recipient_create(cd->content_layout, 1, cd);
1687         elm_object_part_content_set(cd->content_layout, "swl.recipient", cd->recipient->bx_main);
1688
1689         Evas_Object *predict_search_layout = msg_ui_composer_predictsearch_list_create(cd->content_layout, cd);
1690         elm_object_part_content_set(cd->content_layout, "swl.predictsearch", predict_search_layout);
1691
1692         MSGC_EVAS_OBJECT_DEL(cd->back_btn);
1693         Evas_Object *back_btn = __naviframe_back_btn_create(cd->navi_bar, (void *)cd, true);
1694         elm_object_part_content_set(cd->navi_title_layout, "prev_btn", back_btn);
1695         cd->back_btn = back_btn;
1696
1697         msg_ui_composer_navi_title_set(cd);
1698
1699         D_LEAVE;
1700         return COMPOSER_RETURN_SUCCESS;
1701 }
1702
1703 COMPOSER_RETURN_TYPE_E msg_ui_composer_change_bubble_view(MSG_COMPOSER_VIEW_DATA_S *cd)
1704 {
1705         D_ENTER;
1706         D_MSG_RETVM_IF(cd == NULL, COMPOSER_RETURN_FAIL, "Composer data is NULL");
1707         D_MSG_RETVM_IF(cd->msg_ug_mode != MSG_UG_MODE_FULL_COMPOSER, COMPOSER_RETURN_FAIL, "Composer mode is Not Full");
1708
1709         /*Change Mode */
1710         cd->msg_ug_mode = MSG_UG_MODE_BUBBLE_COMPOSER;
1711
1712         /*Change content layout to bubble layout*/
1713         edje_object_signal_emit(_EDJ(cd->content_layout), "hide.predictsearch", "*");
1714         edje_object_signal_emit(_EDJ(cd->content_layout), "change.bubble", "*");
1715
1716         elm_scroller_content_min_limit(cd->body_scroll, 0, 1);
1717         evas_object_size_hint_max_set(cd->body_scroll, 9999, 250);
1718
1719         /*Init bubble data*/
1720         PMSG_BUBBLE_DATA bubble_data = msg_ui_bubble_init_bubble_data(cd->msg_handle, cd);
1721         if (!bubble_data)
1722                 return COMPOSER_RETURN_FAIL;
1723
1724         cd->bubble_data = (void *)bubble_data;
1725
1726         /*Change naviframe layout for bubble*/
1727         Evas_Object *cancel_btn = __naviframe_back_btn_create(cd->navi_bar, (void *)cd, false);
1728         elm_object_part_content_set(cd->navi_title_layout, "prev_btn", cancel_btn);
1729         cd->back_btn = cancel_btn;
1730
1731         Evas_Object *layout = msg_ui_bubble_create_view(cd->content_layout, cd->bubble_data); // First parameter should be 'content_layout'.
1732         elm_object_part_content_set(cd->content_layout, "swl.bubble.content", layout);
1733
1734         /*remove unused layout*/
1735         MSGC_EVAS_OBJECT_DEL(cd->ly_recipient);
1736         msg_ui_composer_recipient_delete(cd->recipient);
1737         cd->recipient = NULL;
1738
1739         msg_ui_composer_predictsearch_list_delete(cd);
1740
1741         return COMPOSER_RETURN_SUCCESS;
1742 }
1743
1744 /*
1745  * msg_ui_composer_editable_set
1746  * editable == FALSE : hide body content & disable more button & close option header
1747  * editable == TRUE : show body content layout
1748  * */
1749 void msg_ui_composer_editable_set(MSG_COMPOSER_VIEW_DATA_S *cd, Eina_Bool editable)
1750 {
1751         D_ENTER;
1752         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
1753
1754         if (editable == EINA_FALSE){
1755                 Evas_Object *body_layout = elm_object_part_content_unset(cd->content_layout, "swl.composer.body");
1756                 evas_object_hide(body_layout);
1757
1758                 if (cd->more_btn)
1759                         elm_object_disabled_set(cd->more_btn, EINA_TRUE);
1760         } else {
1761                 elm_object_part_content_set(cd->content_layout, "swl.composer.body", cd->ly_body);
1762                 evas_object_show(cd->ly_body);
1763
1764                 if (cd->more_btn)
1765                         elm_object_disabled_set(cd->more_btn, EINA_FALSE);
1766
1767         }
1768
1769         D_LEAVE;
1770 }
1771
1772 void msg_ui_composer_bubble_del_all(void *data, service_h svc_handle)
1773 {
1774         D_ENTER;
1775
1776         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
1777         D_MSG_RETM_IF(cd == NULL, "Composer data is NULL");
1778
1779         ug_send_result(cd->ug, svc_handle);
1780 }
1781
1782 Evas_Object *msg_ui_composer_create_navi_title_bar(void *data)
1783 {
1784         D_ENTER;
1785
1786         if (!data) {
1787                 D_EMSG("[ERROR] data is NULL");
1788                 return NULL;
1789         }
1790
1791         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
1792
1793         Evas_Object *title_layout = elm_layout_add(cd->navi_bar);
1794         elm_layout_file_set(title_layout, MSG_COMMON_EDJ, "title");
1795         evas_object_size_hint_weight_set(title_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1796         evas_object_size_hint_align_set(title_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
1797         evas_object_show(title_layout);
1798
1799         return title_layout;
1800 }
1801
1802 void msg_ui_composer_navi_title_set(void *data)
1803 {
1804         D_ENTER;
1805
1806         if (!data) {
1807                 D_EMSG("data is NULL");
1808                 return;
1809         }
1810
1811         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
1812         PMSG_BUBBLE_DATA bubble_data = cd->bubble_data;
1813
1814         if (cd->msg_ug_mode == MSG_UG_MODE_FULL_COMPOSER || cd->msg_ug_mode == MSG_UG_MODE_ONLY_COMPOSER) {
1815                 elm_object_part_text_set(cd->navi_title_layout, "title_text", MSGC_STR_NEW_MESSAGE);
1816         } else if (cd->msg_ug_mode ==  MSG_UG_MODE_BUBBLE_COMPOSER) {
1817                 Evas_Object *title_button = NULL;
1818
1819                 elm_object_part_text_set(cd->navi_title_layout, "title_text", ""); // text part clear first
1820
1821                 title_button = elm_button_add(cd->navi_bar);
1822
1823                 elm_object_theme_set(title_button, cd->th);
1824                 elm_object_style_set(title_button, "title_button");
1825
1826                 evas_object_size_hint_weight_set(title_button, 0.0, 0.0);
1827                 evas_object_size_hint_align_set(title_button, EVAS_HINT_FILL, EVAS_HINT_FILL);
1828
1829                 if (bubble_data->addr_list.addr_cnt == 1) {
1830                         if (bubble_data->addr_list.addr_info[0].contact_id > 0 && bubble_data->addr_list.addr_info[0].name[0] != '\0')
1831                                 elm_object_text_set(title_button, bubble_data->addr_list.addr_info[0].name);
1832                         else if (bubble_data->addr_list.addr_info[0].address[0] != '\0')
1833                                 elm_object_text_set(title_button, bubble_data->addr_list.addr_info[0].address);
1834                         else
1835                                 elm_object_text_set(title_button, dgettext("sys_string", "IDS_COM_BODY_UNKNOWN"));
1836                 } else if (bubble_data->addr_list.addr_cnt > 1) {
1837                         char title_text[DEF_BUF_LEN+1] = {0,};
1838
1839                         if (bubble_data->addr_list.addr_info[0].contact_id > 0 && bubble_data->addr_list.addr_info[0].name[0] != '\0')
1840                                 snprintf(title_text, sizeof(title_text), "%s +%d", bubble_data->addr_list.addr_info[0].name, bubble_data->addr_list.addr_cnt-1);
1841                         else if (bubble_data->addr_list.addr_info[0].address[0] != '\0')
1842                                 snprintf(title_text, sizeof(title_text), "%s +%d", bubble_data->addr_list.addr_info[0].address, bubble_data->addr_list.addr_cnt-1);
1843                         else
1844                                 snprintf(title_text, sizeof(title_text), "%s +%d", dgettext("sys_string", "IDS_COM_BODY_UNKNOWN"), bubble_data->addr_list.addr_cnt-1);
1845
1846                         elm_object_text_set(title_button, title_text);
1847                 } else {
1848                         elm_object_text_set(title_button, dgettext("sys_string", "IDS_COM_BODY_UNKNOWN"));
1849                 }
1850
1851                 evas_object_show(title_button);
1852                 elm_object_part_content_set(cd->navi_title_layout, "title_btn", title_button);
1853                 evas_object_smart_callback_add(title_button, "clicked", msg_ui_bubble_title_button_clicked_cb, cd);
1854
1855                 bubble_data->title_button = title_button;
1856         } else {
1857                 D_EMSG("Invalid msg_ui_mode [%d]", cd->msg_ug_mode);
1858                 return;
1859         }
1860 }
1861
1862 static Eina_Bool __msgc_up_key_long_press_cb(void *data)
1863 {
1864         D_ENTER;
1865         D_MSG_RETVM_IF(data == NULL, EINA_FALSE, "cd is NULL");
1866         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
1867
1868         if (!msg_common_increase_font_size()) {
1869                 cd->vol_up_key_longpress = NULL;
1870                 return EINA_FALSE;
1871         }
1872
1873         /* apply font size */
1874         if (cd->msg_ug_mode == MSG_UG_MODE_BUBBLE_COMPOSER)
1875                 msg_common_apply_font_size("bubble", cd->content_layout);
1876
1877         msg_ui_composer_apply_font_size(cd, false);
1878
1879         return EINA_TRUE;
1880 }
1881
1882 static Eina_Bool __msgc_down_key_long_press_cb(void *data)
1883 {
1884         D_ENTER;
1885         D_MSG_RETVM_IF(data == NULL, EINA_FALSE, "cd is NULL");
1886         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
1887
1888         if (!msg_common_decrease_font_size()) {
1889                 cd->vol_down_key_longpress = NULL;
1890                 return EINA_FALSE;
1891         }
1892
1893         /* apply font size */
1894         if (cd->msg_ug_mode == MSG_UG_MODE_BUBBLE_COMPOSER)
1895                 msg_common_apply_font_size("bubble", cd->content_layout);
1896
1897         msg_ui_composer_apply_font_size(cd, false);
1898
1899         return EINA_TRUE;
1900 }
1901
1902 Eina_Bool msg_ui_composer_key_release_cb(void *data, int type, void *event)
1903 {
1904         D_ENTER;
1905         D_MSG_RETVM_IF(data == NULL, EINA_FALSE, "cd is NULL");
1906         D_MSG_RETVM_IF(event == NULL, EINA_FALSE, "event is NULL");
1907         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
1908         Ecore_Event_Key *ev = (Ecore_Event_Key *)event;
1909         int use_volume_key = false;
1910
1911         vconf_get_bool(VCONFKEY_MSG_APP_USE_VOLUME_KEY, &use_volume_key);
1912
1913         if (use_volume_key) {
1914                 if (!g_strcmp0(ev->keyname, KEY_VOLUMEUP)) {    /* KEY_VOLUMEUP */
1915                         D_MSG("KEY_VOLUMEUP is released");
1916
1917                         if (cd->vol_up_key_longpress) {
1918                                 ecore_timer_del(cd->vol_up_key_longpress);
1919                                 cd->vol_up_key_longpress = NULL;
1920                         }
1921                 } else if (!g_strcmp0(ev->keyname, KEY_VOLUMEDOWN)) {   /* KEY_VOLUMEDOWN */
1922                         D_MSG("KEY_VOLUMEDOWN is released");
1923
1924                         if (cd->vol_down_key_longpress) {
1925                                 ecore_timer_del(cd->vol_down_key_longpress);
1926                                 cd->vol_down_key_longpress = NULL;
1927                         }
1928                 } else {
1929                         D_MSG("key_name is not applicable!");
1930                 }
1931         } else {
1932                 D_MSG("Use volume key setting is not activated. Do volume key action");
1933         }
1934
1935         return EINA_TRUE;
1936 }
1937
1938 Eina_Bool msg_ui_composer_key_press_cb(void *data, int type, void *event)
1939 {
1940         D_ENTER;
1941         D_MSG_RETVM_IF(data == NULL, EINA_FALSE, "cd is NULL");
1942         D_MSG_RETVM_IF(event == NULL, EINA_FALSE, "event is NULL");
1943         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
1944         Ecore_Event_Key *ev = (Ecore_Event_Key *)event;
1945         int use_volume_key = false;
1946
1947         vconf_get_bool(VCONFKEY_MSG_APP_USE_VOLUME_KEY, &use_volume_key);
1948
1949         if (use_volume_key) {
1950                 if (!g_strcmp0(ev->keyname, KEY_VOLUMEUP)) {    /* KEY_VOLUMEUP */
1951                         D_MSG("KEY_VOLUMEUP is pressed");
1952
1953                         msg_common_increase_font_size();
1954
1955                         /* apply font size */
1956                         if (cd->msg_ug_mode == MSG_UG_MODE_BUBBLE_COMPOSER)
1957                                 msg_common_apply_font_size("bubble", cd->content_layout);
1958
1959                         msg_ui_composer_apply_font_size(cd, false);
1960
1961                         cd->vol_up_key_longpress = ecore_timer_add(0.1, (Ecore_Task_Cb) __msgc_up_key_long_press_cb, (void *)cd);
1962                 } else if (!g_strcmp0(ev->keyname, KEY_VOLUMEDOWN)) {   /* KEY_VOLUMEDOWN */
1963                         D_MSG("KEY_VOLUMEDOWN is pressed");
1964
1965                         msg_common_decrease_font_size();
1966
1967                         /* apply font size */
1968                         if (cd->msg_ug_mode == MSG_UG_MODE_BUBBLE_COMPOSER)
1969                                 msg_common_apply_font_size("bubble", cd->content_layout);
1970
1971                         msg_ui_composer_apply_font_size(cd, false);
1972
1973                         cd->vol_down_key_longpress = ecore_timer_add(0.1, (Ecore_Task_Cb) __msgc_down_key_long_press_cb, (void *)cd);
1974                 } else {
1975                         D_MSG("key_name is not applicable!");
1976                 }
1977         } else {
1978                 D_MSG("Use volume key setting is not activated. Do volume key action");
1979         }
1980
1981         return EINA_TRUE;
1982 }
1983
1984 void msg_ui_composer_connect_handler(MSG_COMPOSER_VIEW_DATA_S *cd)
1985 {
1986         D_ENTER;
1987         D_MSG_RETM_IF(cd == NULL, "cd is NULL");
1988
1989         int use_volume_key = 0;
1990         vconf_get_bool(VCONFKEY_MSG_APP_USE_VOLUME_KEY, &use_volume_key);
1991
1992         if (use_volume_key) {
1993                 msg_ui_composer_grab_key_setting(cd->xdisplay, cd->main_window);
1994                 /* connect key handler for volume up/down */
1995                 if (!cd->volkey_press_handler)
1996                         cd->volkey_press_handler = ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, msg_ui_composer_key_press_cb, (void *)cd);
1997
1998                 if (!cd->volkey_release_handler)
1999                         cd->volkey_release_handler = ecore_event_handler_add(ECORE_EVENT_KEY_UP, msg_ui_composer_key_release_cb, (void *)cd);
2000         }
2001         D_MSG("use_volume_key = %d", use_volume_key);
2002
2003         D_LEAVE;
2004 }
2005
2006 void msg_ui_composer_disconnect_handler(MSG_COMPOSER_VIEW_DATA_S *cd)
2007 {
2008         D_ENTER;
2009         D_MSG_RETM_IF(cd == NULL, "cd is NULL");
2010
2011         if (cd->volkey_press_handler) {
2012                 ecore_event_handler_del(cd->volkey_press_handler);
2013                 cd->volkey_press_handler = NULL;
2014         }
2015
2016         if (cd->vol_down_key_longpress) {
2017                 ecore_timer_del(cd->vol_down_key_longpress);
2018                 cd->vol_down_key_longpress = NULL;
2019         }
2020
2021         if (cd->volkey_release_handler) {
2022                 ecore_event_handler_del(cd->volkey_release_handler);
2023                 cd->volkey_release_handler = NULL;
2024         }
2025
2026         if (cd->vol_up_key_longpress) {
2027                 ecore_timer_del(cd->vol_up_key_longpress);
2028                 cd->vol_up_key_longpress = NULL;
2029         }
2030
2031         msg_ui_composer_ungrab_key_setting(cd->xdisplay, cd->main_window);
2032
2033         D_LEAVE;
2034 }