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