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