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