Merge "Apply thread list options and create split view"
[apps/core/preloaded/message-app.git] / composer / src / ui-composer / msg-ui-composer-common.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
18 #include <Elementary.h>
19 #include <utilX.h>
20 #include <Ecore_X.h>
21 #include <mmf/mm_error.h>
22 #include <metadata_extractor.h>
23 #include <image_util.h>
24
25 #include "msg-ui-composer-common.h"
26 #include "msg-ui-composer-subject.h"
27 #include "msg-ui-composer-body.h"
28 #include "msg-ui-composer-body-callback.h"
29 #include "msg-ui-composer-attachment.h"
30 #include "msg-ui-composer-recipient.h"
31 #include "msg-ui-composer-popup.h"
32 #include "msg-ui-composer-data.h"
33 #include "msg-ui-composer-bubble.h"
34 #include "msg-ui-composer-main.h"
35
36 /* MIME type table*/
37
38 const composer_mime_type_t composer_mime_table[] = {
39 /*audio*/
40         {"aac", "audio/aac", COMPOSER_MEDIA_TYPE_AUDIO},
41         {"amr", "audio/amr", COMPOSER_MEDIA_TYPE_AUDIO},
42         {"amr", "audio/x-amr", COMPOSER_MEDIA_TYPE_AUDIO},
43         {"amr", "audio/amr-wb", COMPOSER_MEDIA_TYPE_AUDIO},
44         {"imy", "audio/imelody", COMPOSER_MEDIA_TYPE_AUDIO},
45         {"imy", "audio/imy", COMPOSER_MEDIA_TYPE_AUDIO},
46         {"imy", "audio/iMelody", COMPOSER_MEDIA_TYPE_AUDIO},
47         {"imy", "audio/melody", COMPOSER_MEDIA_TYPE_AUDIO},
48         {"imy", "audio/x-iMelody", COMPOSER_MEDIA_TYPE_AUDIO},
49         {"imy", "text/iMelody", COMPOSER_MEDIA_TYPE_AUDIO},
50         {"imy", "text/x-iMelody", COMPOSER_MEDIA_TYPE_AUDIO},
51         {"imy", "text/x-imelody", COMPOSER_MEDIA_TYPE_AUDIO},
52         {"mid", "audio/mid", COMPOSER_MEDIA_TYPE_AUDIO},
53         {"mid", "audio/midi", COMPOSER_MEDIA_TYPE_AUDIO},
54         {"mid", "audio/x-mid", COMPOSER_MEDIA_TYPE_AUDIO},
55         {"mid", "audio/x-midi", COMPOSER_MEDIA_TYPE_AUDIO},
56         {"midi", "audio/mid", COMPOSER_MEDIA_TYPE_AUDIO},
57         {"mmf", "application/vnd.smaf", COMPOSER_MEDIA_TYPE_AUDIO},
58         {"mmf", "application/x-smaf", COMPOSER_MEDIA_TYPE_AUDIO},
59         {"mmf", "audio/mmf", COMPOSER_MEDIA_TYPE_AUDIO},
60         {"mmf", "audio/smaf", COMPOSER_MEDIA_TYPE_AUDIO},
61         {"mmf", "audio/x-mmf", COMPOSER_MEDIA_TYPE_AUDIO},
62         {"mmf", "audio/x-smaf", COMPOSER_MEDIA_TYPE_AUDIO},
63         {"mp3", "audio/mpeg", COMPOSER_MEDIA_TYPE_AUDIO},
64         {"mp3", "audio/mp3", COMPOSER_MEDIA_TYPE_AUDIO},
65         {"mp3", "audio/mpg3", COMPOSER_MEDIA_TYPE_AUDIO},
66         {"mp3", "audio/mpeg3", COMPOSER_MEDIA_TYPE_AUDIO},
67         {"mp3", "audio/mpg", COMPOSER_MEDIA_TYPE_AUDIO},
68         {"mp3", "audio/x-mp3", COMPOSER_MEDIA_TYPE_AUDIO},
69         {"mp3", "audio/x-mpeg", COMPOSER_MEDIA_TYPE_AUDIO},
70         {"mp3", "audio/x-mpeg3", COMPOSER_MEDIA_TYPE_AUDIO},
71         {"mp3", "audio/x-mpegaudio", COMPOSER_MEDIA_TYPE_AUDIO},
72         {"mp3", "audio/x-mpg", COMPOSER_MEDIA_TYPE_AUDIO},
73         {"mpg", "audio/x-mpeg", COMPOSER_MEDIA_TYPE_AUDIO},
74         {"m4a", "audio/m4a", COMPOSER_MEDIA_TYPE_AUDIO},
75         {"ra", "audio/x-pn-realaudio", COMPOSER_MEDIA_TYPE_AUDIO},
76         {"rm", "audio/vnd.rn-realaudio", COMPOSER_MEDIA_TYPE_AUDIO},
77         {"rm", "audio/x-pn-multirate-realaudio", COMPOSER_MEDIA_TYPE_AUDIO},
78         {"rm", "audio/x-pn-multirate-realaudio-live", COMPOSER_MEDIA_TYPE_AUDIO},
79         {"spm", "audio/sp-midi", COMPOSER_MEDIA_TYPE_AUDIO},
80         {"wav", "audio/wav", COMPOSER_MEDIA_TYPE_AUDIO},
81         {"wav", "audio/wave", COMPOSER_MEDIA_TYPE_AUDIO},
82         {"wav", "audio/x-wav", COMPOSER_MEDIA_TYPE_AUDIO},
83         {"wav", "audio/x-wave", COMPOSER_MEDIA_TYPE_AUDIO},
84         {"wma", "audio/wma", COMPOSER_MEDIA_TYPE_AUDIO},
85         {"wma", "audio/x-ms-wma", COMPOSER_MEDIA_TYPE_AUDIO},
86         {"xmf", "audio/mobile-xmf", COMPOSER_MEDIA_TYPE_AUDIO},
87         {"xmf", "audio/xmf", COMPOSER_MEDIA_TYPE_AUDIO},
88         {"xmf", "audio/x-xmf", COMPOSER_MEDIA_TYPE_AUDIO},
89 /*image*/
90         {"bmp", "image/bmp", COMPOSER_MEDIA_TYPE_IMAGE},
91         {"bmp", "image/x-bmp", COMPOSER_MEDIA_TYPE_IMAGE},
92         {"gif", "image/gif", COMPOSER_MEDIA_TYPE_IMAGE},
93         {"GIF", "image/gif", COMPOSER_MEDIA_TYPE_IMAGE},
94         {"gif", "image/vnd.tmo.my5-gif", COMPOSER_MEDIA_TYPE_IMAGE},
95         {"jpg", "image/jpg", COMPOSER_MEDIA_TYPE_IMAGE},
96         {"jpg", "image/jpeg", COMPOSER_MEDIA_TYPE_IMAGE},
97         {"jpg", "image/vnd.tmo.my5-jpg", COMPOSER_MEDIA_TYPE_IMAGE},
98         {"jpeg", "image/jpeg", COMPOSER_MEDIA_TYPE_IMAGE},
99         {"JPG", "image/jpeg", COMPOSER_MEDIA_TYPE_IMAGE},
100         {"jpg", "image/pjpeg", COMPOSER_MEDIA_TYPE_IMAGE},
101         {"jpe", "image/jpeg", COMPOSER_MEDIA_TYPE_IMAGE},
102         {"png", "image/png", COMPOSER_MEDIA_TYPE_IMAGE},
103         {"wbmp", "image/vnd.wap.wbmp", COMPOSER_MEDIA_TYPE_IMAGE},
104         {"wbmp", "image/wbmp", COMPOSER_MEDIA_TYPE_IMAGE},
105         {"swf", "application/x-shockwave-flash", COMPOSER_MEDIA_TYPE_UNKNOWN},
106         {"tif", "image/tiff", COMPOSER_MEDIA_TYPE_IMAGE},
107         {"tif", "image/tif", COMPOSER_MEDIA_TYPE_IMAGE},
108         {"pmd", "audio/pmd", COMPOSER_MEDIA_TYPE_IMAGE},
109 /*video*/
110         {"3gp", "audio/3gpp", COMPOSER_MEDIA_TYPE_VIDEO},
111         {"3gp", "video/3gpp", COMPOSER_MEDIA_TYPE_VIDEO},
112         {"3gp", "video/3gp", COMPOSER_MEDIA_TYPE_VIDEO},
113         {"3gp", "video/h263", COMPOSER_MEDIA_TYPE_VIDEO},
114         {"3gp", "video/mp4v-es", COMPOSER_MEDIA_TYPE_VIDEO},
115         {"asf", "audio/x-ms-asf", COMPOSER_MEDIA_TYPE_VIDEO},
116         {"asf", "video/x-ms-asf", COMPOSER_MEDIA_TYPE_VIDEO},
117         {"asx", "video/x-ms-asf", COMPOSER_MEDIA_TYPE_VIDEO},
118         {"avi", "video/avi", COMPOSER_MEDIA_TYPE_VIDEO},
119         {"mp2", "video/mpeg", COMPOSER_MEDIA_TYPE_VIDEO},
120         {"mp4", "audio/mp4", COMPOSER_MEDIA_TYPE_VIDEO},
121         {"mp4", "audio/MP4A-LATM", COMPOSER_MEDIA_TYPE_VIDEO},
122         {"mp4", "audio/mpeg4", COMPOSER_MEDIA_TYPE_VIDEO},
123         {"mp4", "video/mp4", COMPOSER_MEDIA_TYPE_VIDEO},
124         {"mp4", "video/mpeg4", COMPOSER_MEDIA_TYPE_VIDEO},
125         {"mp4", "video/x-mp4", COMPOSER_MEDIA_TYPE_VIDEO},
126         {"mp4", "video/x-pv-mp4", COMPOSER_MEDIA_TYPE_VIDEO},
127         {"mpg", "video/mpeg", COMPOSER_MEDIA_TYPE_VIDEO},
128         {"mpeg", "video/mpeg", COMPOSER_MEDIA_TYPE_VIDEO},
129         {"rm", "video/x-pn-multirate-realvideo", COMPOSER_MEDIA_TYPE_VIDEO},
130         {"rm", "video/vnd.rn-realmedia", COMPOSER_MEDIA_TYPE_VIDEO},
131         {"rm", "video/vnd.rn-realvideo", COMPOSER_MEDIA_TYPE_VIDEO},
132         {"rv", "video/x-pn-realvideo", COMPOSER_MEDIA_TYPE_VIDEO},
133         {"sdp", "application/sdp", COMPOSER_MEDIA_TYPE_VIDEO},
134         {"sdp", "video/sdp", COMPOSER_MEDIA_TYPE_VIDEO},
135         {"wmv", "video/x-ms-wmv", COMPOSER_MEDIA_TYPE_VIDEO},
136 /*text*/
137         {"txt", "text/plain", COMPOSER_MEDIA_TYPE_TEXT},
138         {"text", "text/plain", COMPOSER_MEDIA_TYPE_TEXT},
139         {"html", "text/html", COMPOSER_MEDIA_TYPE_TEXT},
140         {"htm", "text/html", COMPOSER_MEDIA_TYPE_TEXT},
141         {"wml", "text/vnd.wap.wml", COMPOSER_MEDIA_TYPE_TEXT},
142         {"xml", "text/xml", COMPOSER_MEDIA_TYPE_TEXT},
143 /*vObject*/
144         {"vbm", "text/x-vbookmark", COMPOSER_MEDIA_TYPE_UNKNOWN},
145         {"vcf", "text/x-vcard", COMPOSER_MEDIA_TYPE_UNKNOWN},
146         {"vcs", "text/x-vCalendar", COMPOSER_MEDIA_TYPE_UNKNOWN},
147         {"vnt", "text/x-vnote", COMPOSER_MEDIA_TYPE_UNKNOWN},
148 /*drm*/
149         {"dcf", "application/vnd.oma.drm.content", COMPOSER_MEDIA_TYPE_DRM},
150         {"dm", "application/vnd.oma.drm.message", COMPOSER_MEDIA_TYPE_DRM},
151         {"odf", "application/vnd.oma.drm.dcf", COMPOSER_MEDIA_TYPE_DRM},
152         {"oro", "application/vnd.oma.drm.ro+xml", COMPOSER_MEDIA_TYPE_DRM},
153         {"ro", "application/vnd.oma.drm.rights+xml", COMPOSER_MEDIA_TYPE_DRM},
154         {"ro", "application/vnd.oma.drm.rights+wbxml", COMPOSER_MEDIA_TYPE_DRM},
155 /*doc*/
156         {"doc", "application/msword", COMPOSER_MEDIA_TYPE_UNKNOWN},
157         {"doc", "applcation/vnd.ms-word", COMPOSER_MEDIA_TYPE_UNKNOWN},
158         {"xls", "application/vnd.ms-excel", COMPOSER_MEDIA_TYPE_UNKNOWN},
159         {"xls", "application/x-msexcel", COMPOSER_MEDIA_TYPE_UNKNOWN},
160         {"ppt", "application/vnd.ms-powerpoint", COMPOSER_MEDIA_TYPE_UNKNOWN},
161         {"ppt", "application/x-mspowerpoint", COMPOSER_MEDIA_TYPE_UNKNOWN},
162         {"pdf", "application/pdf", COMPOSER_MEDIA_TYPE_UNKNOWN},
163 /*etc*/
164         {"rm ", "application/vnd.rn-realmedia", COMPOSER_MEDIA_TYPE_UNKNOWN},
165         {"smi", "application/smil", COMPOSER_MEDIA_TYPE_UNKNOWN},
166         {"smil", "application/smil", COMPOSER_MEDIA_TYPE_UNKNOWN},
167         {"xml", "application/vnd.oma.drm.roap-pdu+xml", COMPOSER_MEDIA_TYPE_UNKNOWN},
168         {"xml", "application/vnd.oma.drm.roap-trigger+xml", COMPOSER_MEDIA_TYPE_UNKNOWN},
169         {"xxx", "application/octet-stream", COMPOSER_MEDIA_TYPE_UNKNOWN},
170 };
171
172 char *msg_ui_composer_edj_get(MSG_COMPOSER_VIEW_DATA_S *cd)
173 {
174         return MSGC_UI_DEFAULT_EDJ;
175 }
176
177 Evas_Object *msg_ui_composer_load_edj(Evas_Object *parent, const char *edj_file, const char *group)
178 {
179         Evas_Object *layout;
180         layout = elm_layout_add(parent);
181
182         elm_layout_file_set(layout, edj_file, group);
183         return layout;
184 }
185
186 Evas_Object *msg_ui_composer_layout_create(Evas_Object *parent, bool indicator)
187 {
188         D_ENTER;
189         D_MSG_RETVM_IF(parent == NULL, NULL, "parent object  == NULL");
190
191         Evas_Object *layout;
192
193         layout = elm_layout_add(parent);
194         if (layout == NULL) {
195                 D_EMSG("[ASSERT] elm_layout_add failed!!");
196                 return NULL;
197         }
198
199         if (indicator == true)
200                 elm_layout_theme_set(layout, "layout", "application", "default");
201         else
202                 elm_layout_theme_set(layout, "layout", "application", "noindicator");
203
204         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
205         evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
206         evas_object_show(layout);
207         D_LEAVE;
208         return layout;
209 }
210
211 Evas_Object *msg_ui_composer_conformant_create(Evas_Object *parent_win, Evas_Object *inner)
212 {
213         D_ENTER;
214         Evas_Object *conform;
215         D_MSG_RETVM_IF(!parent_win, NULL,"Inputted Paremeter Window is Invalid");
216         D_MSG_RETVM_IF(!inner, NULL,"Inputted Paremeter Content is Invalid");
217
218         conform = elm_conformant_add(parent_win);
219         D_MSG_RETVM_IF(!conform, NULL,"Fail to Create conformant object");
220
221         elm_win_conformant_set(parent_win, EINA_TRUE);
222         evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
223         evas_object_size_hint_align_set(conform, EVAS_HINT_FILL, EVAS_HINT_FILL);
224         elm_win_resize_object_add(parent_win, conform);
225         evas_object_show(conform);
226
227         elm_object_content_set(conform, inner);
228         D_LEAVE;
229         return conform;
230 }
231
232 Evas_Object *msg_ui_composer_bg_create(Evas_Object *parent)
233 {
234         D_MSG_RETVM_IF(parent == NULL, NULL, "parent object  == NULL");
235     Evas_Object *bg = elm_bg_add(parent);
236     evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
237     evas_object_show(bg);
238     return bg;
239 }
240
241 Evas_Object *msg_ui_composer_toolbar_create(Evas_Object *parent)
242 {
243         MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
244
245         Evas_Object *toolbar = NULL;
246
247         toolbar = elm_toolbar_add(parent);
248         elm_toolbar_shrink_mode_set(toolbar, ELM_TOOLBAR_SHRINK_EXPAND);
249
250         return toolbar;
251 }
252
253 int64 msg_composer_get_file_size(const char *path)
254 {
255         return ecore_file_size(path);
256 }
257
258 char *msg_common_get_file_ext(const char *a_pszfile_name)
259 {
260         if (a_pszfile_name != NULL) {
261                 int nlen = strlen(a_pszfile_name);
262                 char *psztemp = (char *)a_pszfile_name + nlen;
263
264                 while (nlen--) {
265                         psztemp--;
266                         if (*psztemp == '.') {
267                                 psztemp++;
268                                 break;
269                         }
270                 }
271                 return psztemp;
272         }
273
274         return NULL;
275 }
276
277 COMPOSER_MEDIA_TYPE_E msg_composer_get_media_type(const char *a_pszfile_path)
278 {
279         char *pext = NULL;
280         unsigned int nmimeidx = 0;
281         unsigned int nmime_max = 0;
282
283         if (a_pszfile_path == NULL)
284                 return COMPOSER_MEDIA_TYPE_UNKNOWN;
285
286         pext = msg_common_get_file_ext(a_pszfile_path);
287         nmime_max = (sizeof(composer_mime_table) / sizeof(composer_mime_type_t));
288
289         for (; nmimeidx < nmime_max; nmimeidx++) {
290                 int nlen = strlen(composer_mime_table[nmimeidx].m_szextend);
291
292                 if (strncasecmp(composer_mime_table[nmimeidx].m_szextend, pext, nlen) == 0) {
293                         return composer_mime_table[nmimeidx].m_ncontent_type;
294                 }
295         }
296
297         return COMPOSER_MEDIA_TYPE_UNKNOWN;
298 }
299
300 COMPOSER_RETURN_TYPE_E msg_composer_common_get_media_duration(const char *file_path, int *duration)
301 {
302         D_ENTER;
303
304         metadata_extractor_h metadata_h = NULL;
305         int ret = METADATA_EXTRACTOR_ERROR_NONE;
306         char *value = NULL;
307
308         if (!file_path || !duration) {
309                 D_EMSG("file_path or duration is not exist");
310                 return COMPOSER_RETURN_FAIL;
311         }
312
313         ret = metadata_extractor_create(&metadata_h);
314         if (ret != METADATA_EXTRACTOR_ERROR_NONE) {
315                 D_EMSG("metadata_extractor_create is failed ret = %d", ret);
316                 return COMPOSER_RETURN_FAIL;
317         }
318
319         ret = metadata_extractor_set_path(metadata_h, file_path);
320         if (ret != METADATA_EXTRACTOR_ERROR_NONE) {
321                 D_EMSG("metadata_extractor_set_path is failed ret = %d", ret);
322                 metadata_extractor_destroy(metadata_h);
323                 return COMPOSER_RETURN_FAIL;
324         }
325
326         ret = metadata_extractor_get_metadata(metadata_h, METADATA_DURATION, &value);
327         if (ret != METADATA_EXTRACTOR_ERROR_NONE) {
328                 D_EMSG("metadata_extractor_get_metadata is failed ret = %d", ret);
329                 metadata_extractor_destroy(metadata_h);
330                 return COMPOSER_RETURN_FAIL;
331         }
332
333         if (value) {
334                 *duration = atoi(value);
335                 free(value);
336         }
337
338         D_MSG("file : %s, duration : %d", file_path, *duration);
339
340         metadata_extractor_destroy(metadata_h);
341
342         D_LEAVE;
343
344         return COMPOSER_RETURN_SUCCESS;
345 }
346
347 COMPOSER_RETURN_TYPE_E msg_composer_common_get_thumbnail(MSG_COMPOSER_VIEW_DATA_S *cd, const char *src_file_path, char *thumb_file_path, int size_thumb_file_path)
348 {
349         D_ENTER;
350         COMPOSER_MEDIA_TYPE_E media_type;
351         int ret;
352         char temp_img_file[COMPOSER_FILEPATH_LEN_MAX] = {0,};
353         char *filename_without_ext = NULL;
354         const char *filename = NULL;
355
356         if (!src_file_path || !thumb_file_path) {
357                 D_EMSG("file path or thumbnail path is NULL");
358                 return COMPOSER_RETURN_NULL_POINTER;
359         }
360
361         if (!ecore_file_exists(src_file_path)) {
362                 D_EMSG("file path is not exist");
363                 return COMPOSER_RETURN_NULL_POINTER;
364         }
365
366         media_type = msg_composer_get_media_type(src_file_path);
367         if (media_type == COMPOSER_MEDIA_TYPE_VIDEO) {
368
369                 filename = ecore_file_file_get(src_file_path);
370                 if (filename) {
371                         filename_without_ext = ecore_file_strip_ext(filename);
372
373                         if (filename_without_ext) {
374                                 snprintf(temp_img_file, sizeof(temp_img_file)-1, "%s/temp_image_%s.jpg", cd->working_path, filename_without_ext);
375                                 g_free(filename_without_ext);
376                         } else {
377                                 return COMPOSER_RETURN_FAIL;
378                         }
379
380                 } else {
381                         return COMPOSER_RETURN_FAIL;
382                 }
383
384                 /* get image of video*/
385                 ret = msg_composer_common_get_image_in_video(src_file_path, temp_img_file);
386                 if (ret == COMPOSER_RETURN_SUCCESS) {
387                         strncpy(thumb_file_path, temp_img_file, size_thumb_file_path);
388                 }
389         } else {
390                 D_EMSG("media type is not video type media_type = %d !!", media_type);
391                 return COMPOSER_RETURN_FAIL;
392         }
393
394         D_LEAVE;
395         return COMPOSER_RETURN_SUCCESS;
396 }
397
398 void msg_ui_composer_clear(MSG_COMPOSER_VIEW_DATA_S *cd)
399 {
400         D_ENTER;
401         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
402
403         /*Clear recipient */
404         if (cd->recipient)
405                 msg_ui_composer_recipient_clear(cd->recipient);
406
407         /*Clear Body*/
408         if (cd->isSubject) {
409                 msg_ui_composer_subject_clear(cd);
410                 cd->isSubject = false;
411         }
412
413         if (cd->attach_data.attachment_Cnt > 0) {
414                 msg_ui_composer_attachment_clear(cd);
415         }
416
417         msg_ui_composer_body_clear(cd);
418
419         D_LEAVE;
420 }
421
422 static void __msg_ui_composer_change_to_sms(MSG_COMPOSER_VIEW_DATA_S *cd)
423 {
424         D_ENTER;
425
426         if (!cd) {
427                 MSG_UI_DEBUG(MSG_UI_LEVEL_ASSERT, "[ASSERT] composer data is NULL");
428                 return;
429         }
430
431         MSG_COMPOSER_BODY_PAGE_S *page_data = NULL;
432         MSG_COMPOSER_BODY_S *body_data = &cd->body_data;
433
434         /* reset region info */
435         body_data->region_order = COMPOSER_REGION_ORDER_UNDETERMINDED;
436
437         page_data = (MSG_COMPOSER_BODY_PAGE_S *)eina_list_nth(cd->body_data.page_list, 0);
438
439         char *body_text = elm_entry_markup_to_utf8(elm_entry_entry_get(page_data->entry));
440         if (body_text) {
441                 msg_ui_composer_body_info_area_update(cd);
442                 free(body_text);
443         }
444
445         D_LEAVE;
446 }
447
448 static void __msg_ui_composer_change_to_mms(MSG_COMPOSER_VIEW_DATA_S *cd)
449 {
450         D_ENTER;
451
452         if (!cd) {
453                 MSG_UI_DEBUG(MSG_UI_LEVEL_ASSERT, "[ASSERT] composer data is NULL");
454                 return;
455         }
456
457         msg_ui_composer_body_info_area_update(cd);
458         D_LEAVE;
459 }
460
461 COMPOSER_RETURN_TYPE_E msg_ui_composer_change_message_type(MSG_COMPOSER_VIEW_DATA_S *cd, COMPOSER_MSG_TYPE_E msg_type)
462 {
463         D_ENTER;
464         if (!cd) {
465                 MSG_UI_DEBUG(MSG_UI_LEVEL_ASSERT, "[ASSERT] composer data is NULL");
466                 return COMPOSER_RETURN_FAIL;
467         }
468
469         if (cd->msg_type == msg_type) {
470                 MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "[DEBUG] it doesn't need to change message type");
471                 return COMPOSER_RETURN_SUCCESS;
472         }
473
474         switch (msg_type) {
475         case COMPOSER_MSG_TYPE_SMS:
476                 msg_ui_composer_common_tickernoti(cd, COMPOSER_TICKERNOTI_CHANGED_SMS);
477
478                 cd->msg_type = COMPOSER_MSG_TYPE_SMS;
479                 __msg_ui_composer_change_to_sms(cd);
480                 msg_ui_composer_toolbar_top_item_change(cd, true);
481                 break;
482         case COMPOSER_MSG_TYPE_MMS:
483                 if (cd->loading_draft == false)
484                         msg_ui_composer_common_tickernoti(cd, COMPOSER_TICKERNOTI_CHANGED_MMS);
485                 else
486                         cd->loading_draft = false;
487
488                 cd->msg_type = COMPOSER_MSG_TYPE_MMS;
489                 __msg_ui_composer_change_to_mms(cd);
490                 msg_ui_composer_toolbar_top_item_change(cd, false);
491                 break;
492         default:
493                 MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "[DEBUG] invalid message type");
494                 return COMPOSER_RETURN_FAIL;
495         }
496
497         bool ret = msg_ui_composer_common_is_send_possible(cd);
498         msg_ui_composer_body_update_send_btn_icon(cd, !ret);
499
500         D_LEAVE;
501         return COMPOSER_RETURN_SUCCESS;
502 }
503
504 COMPOSER_MSG_TYPE_E msg_ui_composer_check_message_type(MSG_COMPOSER_VIEW_DATA_S *cd)
505 {
506         D_ENTER;
507
508         if (!cd) {
509                 MSG_UI_DEBUG(MSG_UI_LEVEL_ASSERT, "[ASSSERT] composer data in NULL");
510                 return COMPOSER_MSG_TYPE_INVALID;
511         }
512
513         if (cd->isSubject)
514                 return COMPOSER_MSG_TYPE_MMS;
515
516         if (cd->attach_data.attachment_Cnt > 0)
517                 return COMPOSER_MSG_TYPE_MMS;
518
519         if (msg_ui_composer_body_is_mms(cd) == EINA_TRUE)
520                 return COMPOSER_MSG_TYPE_MMS;
521
522         if (msg_ui_composer_recipient_is_mms(cd) == EINA_TRUE)
523                 return COMPOSER_MSG_TYPE_MMS;
524
525         return COMPOSER_MSG_TYPE_SMS;
526 }
527
528 void msg_ui_composer_message_type_check_and_change(MSG_COMPOSER_VIEW_DATA_S *cd)
529 {
530         D_ENTER;
531
532         COMPOSER_MSG_TYPE_E checked_type;
533
534         checked_type = msg_ui_composer_check_message_type(cd);
535
536         if (cd->msg_type == COMPOSER_MSG_TYPE_SMS && checked_type == COMPOSER_MSG_TYPE_MMS) {
537                 D_MSG("### Message Type Change from [SMS] to [MMS] ###");
538                 msg_ui_composer_change_message_type(cd, COMPOSER_MSG_TYPE_MMS);
539         } else if (cd->msg_type == COMPOSER_MSG_TYPE_MMS && checked_type == COMPOSER_MSG_TYPE_SMS) {
540                 D_MSG("### Message Type Change from [MMS] to [SMS] ###");
541                 msg_ui_composer_change_message_type(cd, COMPOSER_MSG_TYPE_SMS);
542         } else {
543                 D_MSG("Now msg type is [%d] & checked msg type is [%d](0: INVAILD, 1: SMS, 2: MMS)", cd->msg_type, checked_type);
544         }
545
546         D_LEAVE;
547 }
548
549 Eina_Bool msg_ui_composer_last_focus_load(void *data)
550 {
551         D_ENTER;
552         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
553         if(!cd) return EINA_FALSE;
554
555         if (cd->last_focus_entry == NULL) {
556                 D_MSG("NO ENTRY FOCUS");
557                 return EINA_FALSE;
558         }
559
560         elm_object_focus_set(cd->last_focus_entry, EINA_TRUE);
561         D_MSG("### Focused Entry Load = %p",cd->last_focus_entry);
562         D_LEAVE;
563         return EINA_FALSE;
564 }
565
566 void msg_ui_composer_last_focused_entry_set(void *data, Evas_Object *entry)
567 {
568         MSG_COMPOSER_VIEW_DATA_S *cd;
569         cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
570         cd->last_focus_entry = entry;
571 }
572
573 Evas_Object *msg_ui_composer_last_focused_entry_get(void *data)
574 {
575         MSG_COMPOSER_VIEW_DATA_S *cd;
576         cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
577         if (!cd) return NULL;
578
579         return cd->last_focus_entry;
580 }
581
582 Evas_Object *msg_ui_composer_last_body_entry_get(void *data)
583 {
584         D_ENTER;
585
586         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
587
588         MSG_COMPOSER_BODY_PAGE_S *page_data = eina_list_nth(cd->body_data.page_list, cd->current_edit_entry);
589         D_MSG("cd->current_edit_entry = %d", cd->current_edit_entry);
590
591         if (page_data && page_data->entry) {
592                 return page_data->entry;
593         } else {
594                 D_MSG("No Entry Saved");
595                 return NULL;
596         }
597
598         D_LEAVE;
599         return NULL;
600 }
601
602 bool msg_ui_composer_last_focus_is_recipient(void *data)
603 {
604         D_ENTER;
605         D_MSG_RETVM_IF(data == NULL, false, "data is NULL");
606
607         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
608         RECIPIENT_S *recipient = cd->recipient;
609         Evas_Object *last_focus = msg_ui_composer_last_focused_entry_get(cd);
610
611         if (last_focus && recipient) {
612                 if (last_focus == recipient->mbe) {
613                         return true;
614                 }
615         }
616
617         D_LEAVE;
618         return false;
619 }
620
621 void bundle_send_to_result(void *data, char *key, char *val)
622 {
623         D_ENTER;
624         D_MSG("key = %s, val = %s", key, val);
625
626         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
627         service_h svc_handle;
628         if (service_create(&svc_handle) < 0 || svc_handle == NULL) {
629                 D_EMSG("service_create() is failed !!");
630         } else {
631                 service_add_extra_data(svc_handle, key, val);
632                 ug_send_result(cd->ug, svc_handle);
633                 service_destroy(svc_handle);
634         }
635         D_LEAVE;
636 }
637
638 bool msg_ui_composer_common_is_send_possible(MSG_COMPOSER_VIEW_DATA_S *cd)
639 {
640         D_ENTER;
641
642         if (!cd) {
643                 MSG_UI_DEBUG(MSG_UI_LEVEL_ASSERT, "[ASSERT] composer data is NULL");
644                 return false;
645         }
646
647         MSG_COMPOSER_BODY_S *body_data = &cd->body_data;
648         MSG_COMPOSER_BODY_PAGE_S *page_data = NULL;
649
650         if (cd->msg_type == COMPOSER_MSG_TYPE_MMS) {
651                 if (cd->isSubject) {
652                         char *subject = elm_entry_markup_to_utf8(elm_entry_entry_get(cd->sub_data.entry));
653                         if (subject && strlen(subject) > 0) {
654                                 g_free(subject);
655                                 return true;
656                         } else {
657                                 g_free(subject);
658                         }
659                 }
660
661                 if (cd->attach_data.attachment_Cnt > 0) {
662                         return true;
663                 }
664
665                 int i = 0;
666                 for (i = 0; i < cd->body_data.page_count; i++) {
667                         page_data = (MSG_COMPOSER_BODY_PAGE_S *)eina_list_nth(body_data->page_list, i);
668
669                         if (page_data->is_image_item)
670                                 return true;
671
672                         if (page_data->is_sound_item)
673                                 return true;
674
675                         char *body_text = elm_entry_markup_to_utf8(elm_entry_entry_get(page_data->entry));
676                         if (body_text) {
677                                 if (strlen(body_text) > 0) {
678                                         g_free(body_text);
679                                         return true;
680                                 }
681                                 g_free(body_text);
682                         }
683                 }
684         } else if (cd->msg_type == COMPOSER_MSG_TYPE_SMS) {
685                 page_data = (MSG_COMPOSER_BODY_PAGE_S *)eina_list_nth(body_data->page_list, 0);
686                 if(page_data) {
687                         char *body_text = elm_entry_markup_to_utf8(elm_entry_entry_get(page_data->entry));
688                         if (body_text) {
689                                 if (strlen(body_text) > 0) {
690                                         g_free(body_text);
691                                         return true;
692                                 }
693                                 g_free(body_text);
694                         }
695                 }
696         } else {
697                 MSG_UI_DEBUG(MSG_UI_LEVEL_ASSERT, "[ASSERT] invalid message type");
698                 return false;
699         }
700
701         D_LEAVE;
702         return false;
703 }
704
705 COMPOSER_RETURN_TYPE_E msg_composer_common_get_image_in_video(const char *video_file_path, char *image_file_path)
706 {
707         D_ENTER;
708
709         COMPOSER_MEDIA_TYPE_E media_type;
710         metadata_extractor_h metadata_h = NULL;
711         int ret = METADATA_EXTRACTOR_ERROR_NONE;
712         int video_w = 0;
713         int video_h = 0;
714         int thumbsize = 0;
715         void *thumbnail = NULL;
716         char *value = NULL;
717
718         media_type = msg_composer_get_media_type(video_file_path);
719         if (media_type != COMPOSER_MEDIA_TYPE_VIDEO) {
720                 D_EMSG("It is not video file %s", video_file_path);
721                 return COMPOSER_RETURN_FAIL;
722         }
723
724         ret = metadata_extractor_create(&metadata_h);
725         if (ret != METADATA_EXTRACTOR_ERROR_NONE) {
726                 D_EMSG("metadata_extractor_create is failed ret = %d", ret);
727                 return COMPOSER_RETURN_FAIL;
728         }
729
730         ret = metadata_extractor_set_path(metadata_h, video_file_path);
731         if (ret != METADATA_EXTRACTOR_ERROR_NONE) {
732                 D_EMSG("metadata_extractor_set_path is failed ret = %d", ret);
733                 metadata_extractor_destroy(metadata_h);
734                 return COMPOSER_RETURN_FAIL;
735         }
736
737         ret = metadata_extractor_get_metadata(metadata_h, METADATA_VIDEO_WIDTH, &value);
738         if (ret != METADATA_EXTRACTOR_ERROR_NONE) {
739                 D_EMSG("metadata_extractor_get_metadata is failed ret = %d", ret);
740                 metadata_extractor_destroy(metadata_h);
741                 return COMPOSER_RETURN_FAIL;
742         }
743
744         if (value) {
745                 video_w = atoi(value);
746                 free(value);
747                 value = NULL;
748         }
749
750         ret = metadata_extractor_get_metadata(metadata_h, METADATA_VIDEO_HEIGHT, &value);
751         if (ret != METADATA_EXTRACTOR_ERROR_NONE) {
752                 D_EMSG("metadata_extractor_get_metadata is failed ret = %d", ret);
753                 metadata_extractor_destroy(metadata_h);
754                 return COMPOSER_RETURN_FAIL;
755         }
756
757         if (value) {
758                 video_h = atoi(value);
759                 free(value);
760                 value = NULL;
761         }
762
763         ret = metadata_extractor_get_frame(metadata_h, &thumbnail, &thumbsize);
764         if (ret != METADATA_EXTRACTOR_ERROR_NONE) {
765                 D_EMSG("metadata_extractor_get_frame is failed ret = %d", ret);
766                 metadata_extractor_destroy(metadata_h);
767                 return COMPOSER_RETURN_FAIL;
768         }
769
770         if (thumbnail) {
771                 ret = image_util_encode_jpeg((unsigned char *)thumbnail, video_w, video_h, IMAGE_UTIL_COLORSPACE_RGB888, 100, image_file_path);
772
773                 free(thumbnail);
774
775                 if (ret != IMAGE_UTIL_ERROR_NONE) {
776                         D_EMSG("image_util_encode_jpeg is failed ret = %d", ret);
777                         metadata_extractor_destroy(metadata_h);
778                         return COMPOSER_RETURN_FAIL;
779                 }
780         }
781
782         metadata_extractor_destroy(metadata_h);
783
784         D_LEAVE;
785         return COMPOSER_RETURN_SUCCESS;
786 }
787
788 COMPOSER_RETURN_TYPE_E msg_ui_composer_common_get_file(MSG_COMPOSER_VIEW_DATA_S *cd, const char * src_file_path, char *dst_file_path, int size_dst_file_path)
789 {
790         D_ENTER;
791         const char *filename = NULL;
792         int i = 0;
793         char temp_file_path[COMPOSER_FILEPATH_LEN_MAX] = {0,};
794
795         if (ecore_file_exists(src_file_path) == EINA_FALSE) {
796                 return COMPOSER_RETURN_FAIL;
797         }
798
799         filename = ecore_file_file_get(src_file_path);
800         if (filename) {
801                 snprintf(temp_file_path, sizeof(temp_file_path)-1, "%s%s", cd->working_path, filename);
802
803                 while(ecore_file_exists(temp_file_path)){
804                         bzero(temp_file_path, sizeof(temp_file_path));
805                         snprintf(temp_file_path, sizeof(temp_file_path)-1, "%s%d_%s", cd->working_path, i, filename);
806                         i++;
807
808                         if (i < 0) return COMPOSER_RETURN_FAIL;
809                 }
810
811
812                 if (ecore_file_cp(src_file_path, temp_file_path) == EINA_FALSE) {
813                         D_MSG("temp_file_path = %s", temp_file_path);
814                         return COMPOSER_RETURN_FAIL;
815                 }
816
817                 strncpy(dst_file_path, temp_file_path, size_dst_file_path);
818                 D_MSG("copy file from %s to %s", src_file_path, dst_file_path);
819
820         } else {
821                         return COMPOSER_RETURN_FAIL;
822         }
823
824         D_LEAVE;
825         return COMPOSER_RETURN_SUCCESS;
826 }
827
828 static char *__get_item_tag(char *text)
829 {
830         char *fulltext;
831         char *tagStart;
832         char *tagEnd;
833         int tagStrLength = 0;
834
835         if (text == NULL)
836                 return NULL;
837
838         fulltext = text;
839         D_MSG("text(%p)[%d] = %s", text, strlen(text),text);
840
841         tagStart = strstr(fulltext, "<item");
842         if (tagStart) {
843                 tagEnd = strchr(tagStart, '>');
844                 if (tagEnd) {
845                         tagStrLength = tagEnd - tagStart + 1;
846                         return strndup(tagStart, tagStrLength);
847                 }
848         }
849
850         return NULL;
851 }
852
853 static char *__remove_item_tag(char *text)
854 {
855         char *fulltext = NULL;
856         char *tagStart = NULL;
857         char *tagEnd = NULL;
858         char *braceStart = NULL;
859         char *braceEnd = NULL;
860         char *postStr = NULL;
861
862         int strLength = 0;
863         int postStrLength = 0;
864         bool isitemTag = false;
865
866         if (text == NULL)
867                 return NULL;
868
869         char *textBuf = strdup(text);
870
871         if (!textBuf) {
872                 D_EMSG("strdup is failed");
873                 return NULL;
874         }
875
876         fulltext = textBuf;
877         strLength = strlen(textBuf);
878         D_MSG("text length = %d, text = [%s]", strLength, textBuf);
879
880         while ((tagStart = strstr(fulltext, "<item"))) {
881                 braceEnd = strchr(tagStart, '>');
882                 if (braceEnd) {
883                         braceStart = strstr(braceEnd, "</item>");
884                         if (braceStart) {
885                                 tagEnd = (braceStart + strlen("</item>") - 1);
886                         } else {
887                                 D_EMSG("There is no close item tag");
888                                 tagEnd = braceEnd;
889                         }
890                 } else {
891                         D_EMSG("There is no close tag");
892                         g_free(textBuf);
893                         return NULL;
894                 }
895
896                 postStrLength = strLength - (tagEnd - fulltext + 1);
897                 postStr = strndup(tagEnd + 1, postStrLength);
898                 if (!postStr) {
899                         D_EMSG("strndup is failed");
900                         g_free(textBuf);
901                         return NULL;
902                 }
903
904                 strncpy(tagStart, postStr, postStrLength);
905                 *(tagStart + postStrLength) = '\0';
906                 D_MSG("after textBuf = [%s]", textBuf);
907
908                 g_free(postStr);
909                 postStr = NULL;
910
911                 isitemTag = true;
912         }
913
914         if (isitemTag)
915                 return textBuf;
916
917         g_free(textBuf);
918
919         return NULL;
920 }
921
922 static char *__get_tag_value(const char *tag_str, const char *tag_name)
923 {
924         char *tag;
925
926         if (!tag_name || !tag_str)
927                 return NULL;
928
929         if ((tag = strstr(tag_str, tag_name))) {
930                 if (tag[strlen(tag_name)] == '_')
931                         return NULL;
932                 char *value = strchr(tag, '=');
933                 if (value) {
934
935                         do {
936                                 value++;
937                         } while (!isalnum(*value) && *value != '#');
938
939                         int spCnt = 5;
940                         char *spArray[spCnt];
941                         spArray[0] = strchr(value, '>');
942                         spArray[1] = strchr(value, '\"');
943                         spArray[2] = strchr(value, '\'');
944                         spArray[3] = strchr(value, '\t');
945                         spArray[4] = strchr(value, '\n');
946                         char *valueEnd = strchr(value, '\0');
947
948                         int i;
949                         int start = 0;
950                         if (!strcmp(tag_str, "item") && !strcmp(tag_name, "href"))
951                                 start = 1;
952
953                         for (i = start; i < spCnt; i++) {
954                                 if (spArray[i] && spArray[i] < valueEnd) {
955                                         valueEnd = spArray[i];
956                                 }
957                         }
958
959                         int valueLength = valueEnd - value;
960                         return strndup(value, valueLength);
961                 }
962         }
963
964         return NULL;
965 }
966
967 void msg_composer_entry_filter_addimage(void *data, Evas_Object *entry, char **text)
968 {
969         D_ENTER;
970
971         char *item_val = NULL;
972         char *item_tag = NULL;
973         char *filepath = NULL;
974         char *realpath = NULL;
975
976         MSG_COMPOSER_VIEW_DATA_S *cd = data;
977
978         D_MSG_RETM_IF(cd == NULL, "Composer Data is Invalid");
979         D_MSG_RETM_IF(entry == NULL,"Parameter Entry is Invalid");
980         D_MSG_RETM_IF((!text || !(*text)),"Parameter Text is Invalid");
981
982         /*get <item xxx> tag at insert text*/
983         item_tag = __get_item_tag(*text);
984
985         if (item_tag) {
986
987                 D_MSG("item_tag = %s", item_tag);
988
989                 /*get value of href in the item tag*/
990                 item_val = __get_tag_value(item_tag, "href");
991                 if (item_val) {
992                         D_MSG("item_href_val = %s", item_val);
993                         filepath = strstr(item_val, "file:");
994                         if (filepath) {
995                                 realpath = filepath + 5;
996                         } else {
997                                 realpath = filepath;
998                         }
999
1000                         if (realpath) {
1001                                 if (ecore_file_exists(realpath) == EINA_TRUE) {
1002                                         char * list_item_data  = g_strdup(realpath);
1003                                         if (list_item_data) {
1004                                                 cd->attachlist= eina_list_append(cd->attachlist, list_item_data);
1005                                                 msg_ui_composer_body_items_add(data);
1006                                         } else {
1007                                                 D_EMSG("Fail to g_strdup");
1008                                         }
1009                                 } else {
1010                                         D_EMSG("File is NOT exist %s", realpath);
1011                                 }
1012                         } else {
1013                                 D_EMSG("File Path is NULL");
1014                         }
1015
1016                         g_free(item_val);
1017                 }
1018
1019                 g_free(item_tag);
1020
1021                 /* remove item tag */
1022                 char *removed_text = __remove_item_tag(*text);
1023                 g_free(*text);
1024
1025                 if (removed_text)
1026                         *text = removed_text;
1027                 else
1028                         *text = NULL;
1029
1030         }
1031         D_LEAVE;
1032 }
1033
1034
1035 void
1036 msg_composer_entry_filter_remove_markup(void *data, Evas_Object *entry, char **text)
1037 {
1038         D_ENTER;
1039         D_MSG_RETM_IF(text == NULL || *text == NULL, "New Text is NULL");
1040
1041         char *preedit_str = NULL;
1042         char *utf8_text = NULL;
1043         char *convert_text = NULL;
1044         D_MSG("text [%s]", *text);
1045         /* Check preeditting text and return if it exist*/
1046         preedit_str = strstr(*text, "<preedit>");
1047         if (preedit_str)
1048                 return;
1049
1050         /* convert from markup text to utf8 text from entry */
1051         utf8_text  = elm_entry_markup_to_utf8(*text);
1052
1053         if (utf8_text) {
1054                 /* If the string contains "Carrage return ('\n'), it should be changed "<br>" to show properly*/
1055                 convert_text = elm_entry_utf8_to_markup(utf8_text);
1056                 if(convert_text) {
1057                         free(*text);
1058                         *text = strdup(convert_text);
1059                         free(convert_text);
1060                 }
1061                 free(utf8_text);
1062         }
1063
1064         D_LEAVE;
1065 }
1066
1067 int msg_ui_composer_convert_UTF8ToUCS2(unsigned char *pDestText, int maxLength, const char *pSrcText, int srcTextLen)
1068 {
1069         D_ENTER;
1070         int textLen = 0;
1071         unsigned char *unicodeTemp = (unsigned char*)pDestText;
1072
1073         int ucs2Length = 0;
1074         int remainedBuffer = maxLength;
1075
1076         if(maxLength == 0 || pSrcText == NULL || pDestText ==  NULL)
1077         {
1078                 MSG_UI_DEBUG(MSG_UI_LEVEL_ASSERT,"[ASSERT]UTF8 to UCS2 Failed as text length is NULL \n");
1079                 return -1;
1080         }
1081
1082         // null terminated string
1083         if (srcTextLen == -1) {
1084                 textLen = strlen((char*)pSrcText);
1085                 srcTextLen = textLen;
1086         } else {
1087                 textLen = srcTextLen;
1088         }
1089
1090         GIConv cd;
1091         int err=0;
1092
1093         cd = g_iconv_open("UCS-2BE", "UTF8");
1094
1095         if (cd > 0)
1096         {
1097                 err = g_iconv(cd, (char**)&pSrcText, (gsize*)&textLen, (char**)&unicodeTemp, (gsize*)&remainedBuffer);
1098         }
1099
1100         ucs2Length = maxLength - remainedBuffer;
1101
1102         g_iconv_close(cd);
1103
1104         D_LEAVE;
1105         return ucs2Length;
1106 }
1107
1108 void msg_ui_composer_common_tickernoti(MSG_COMPOSER_VIEW_DATA_S *cd, COMPOSER_TICKERNOTI_TYPE_E tickertype)
1109 {
1110         char popup_msg[DEF_BUF_LEN_L] = {0,};
1111
1112         D_MSG_RETM_IF(cd == NULL, "Composer Data is Invalid");
1113
1114         if (tickertype == COMPOSER_TICKERNOTI_COUNT_MAX) {
1115                 const char *str = MSGC_STR_NOTI_RECIPIENT_MAX;
1116                 snprintf(popup_msg, sizeof(popup_msg), str, COMPOSER_RECIPIENT_COUNT_MAX);
1117         } else if (tickertype == COMPOSER_TICKERNOTI_DUP_RECP) {
1118                 snprintf(popup_msg, sizeof(popup_msg), MSGC_STR_NOTI_RECIPIENT_DUP);
1119         } else if (tickertype == COMPOSER_TICKERNOTI_INVALID_RECP) {
1120                 snprintf(popup_msg, sizeof(popup_msg), MSGC_STR_NOTI_RECIPIENT_INVALID);
1121         } else if (tickertype == COMPOSER_TICKERNOTI_CHANGED_SMS) {
1122                 snprintf(popup_msg, sizeof(popup_msg), MSGC_STR_NOTI_CHANGE_SMS);
1123         } else if (tickertype == COMPOSER_TICKERNOTI_CHANGED_MMS) {
1124                 snprintf(popup_msg, sizeof(popup_msg), MSGC_STR_NOTI_CHANGE_MMS);
1125         } else if (tickertype == COMPOSER_TICKERNOTI_AUTO_SAVED) {
1126                 snprintf(popup_msg, sizeof(popup_msg), _MSGSTR("IDS_MSGC_POP_MESSAGE_SAVED_AS_DRAFT"));
1127         } else if (tickertype == COMPOSER_TICKERNOTI_NO_RECIPIENT) {
1128                 snprintf(popup_msg, sizeof(popup_msg), _MSGSTR("IDS_MSGF_POP_NO_RECIPIENTS_ADDED_ENTER_RECIPIENTS"));
1129         } else if (tickertype == COMPOSER_TICKERNOTI_MAXLENGHT_CHAR) {
1130                 snprintf(popup_msg, sizeof(popup_msg), _MSGSTR("IDS_MSGF_POP_MAXIMUM_CHARACTERS"));
1131         } else {
1132                 return;
1133         }
1134
1135         msg_ui_composer_status_noti_show(popup_msg);
1136 }
1137
1138 int msg_ui_composer_get_keypad_height(Evas_Object *entry)
1139 {
1140         D_MSG_RETVM_IF(entry == NULL, 0, "param is NULL");
1141         int keypad_x = 0;
1142         int keypad_y = 0;
1143         int keypad_w = 0;
1144         int keypad_h = 0;
1145
1146         Ecore_IMF_Context *entry_ctx = elm_entry_imf_context_get(entry);
1147         ecore_imf_context_input_panel_geometry_get(entry_ctx, &keypad_x, &keypad_y, &keypad_w, &keypad_h);
1148
1149         return keypad_h;
1150 }
1151
1152 void msg_ui_composer_change_body_scroll_size(MSG_COMPOSER_VIEW_DATA_S *cd, int keypad_height)
1153 {
1154         D_ENTER;
1155         D_MSG_RETM_IF(cd == NULL, "Composer Data is Invalid");
1156
1157         int total_height = 0;
1158         int scroll_height = 0;
1159         int scroll_x = 0;
1160         int scroll_y = 0;
1161         int scroll_w = 0;
1162         int scroll_h = 0;
1163
1164         elm_scroller_region_get(cd->body_scroll, &scroll_x, &scroll_y, &scroll_w, &scroll_h);
1165         D_MSG("scroll region x=%d, y=%d, w=%d, h=%d", scroll_x, scroll_y, scroll_w, scroll_h);
1166
1167         if (cd->rotate == COMPOSER_ROTATE_PORTRAIT || cd->rotate == COMPOSER_ROTATE_PORTRAIT_UPSIDEDOWN)
1168                 total_height = (cd->window_h > cd->window_w) ? cd->window_h : cd->window_w;
1169         else
1170                 total_height = (cd->window_h > cd->window_w) ? cd->window_w : cd->window_h;
1171
1172         if (cd->msg_ug_mode == MSG_UG_MODE_FULL_COMPOSER || cd->msg_ug_mode == MSG_UG_MODE_ONLY_COMPOSER) {
1173                 RECIPIENT_S *rd = cd->recipient;
1174                 D_MSG_RETM_IF(rd == NULL, "recipient Data is NULL");
1175                 int recipient_h = 0;
1176
1177                 recipient_h = rd->recipient_h;
1178
1179                 D_MSG("recipient_h = %d", recipient_h);
1180                 if (cd->rotate == COMPOSER_ROTATE_PORTRAIT || cd->rotate == COMPOSER_ROTATE_PORTRAIT_UPSIDEDOWN)
1181                         scroll_height = (total_height - keypad_height - recipient_h - MSGC_NAVIBAR_TITLE_H - MSGC_BODY_PADDING - MSGC_INDICATOR_H);
1182                 else
1183                         scroll_height = (total_height - keypad_height - recipient_h - MSGC_NAVIBAR_TITLE_H - MSGC_BODY_PADDING);
1184
1185                 D_MSG("scroll_height = %d", scroll_height);
1186
1187                 if (scroll_height <= COMPOSER_FRAME_BODY_LANDSCAPE_HEIGHT_MIN)
1188                         scroll_height = COMPOSER_FRAME_BODY_LANDSCAPE_HEIGHT_MIN;
1189
1190                 if (scroll_h != scroll_height) {
1191                         evas_object_size_hint_max_set(cd->body_scroll, 9999, scroll_height);
1192                         elm_scroller_content_min_limit(cd->body_scroll, EINA_FALSE, EINA_TRUE);
1193                         D_MSG("scroll size updated w = %d, h = %d", scroll_w, scroll_height);
1194                 }
1195         } else if (cd->msg_ug_mode == MSG_UG_MODE_BUBBLE_COMPOSER) {
1196                 scroll_height = (total_height - keypad_height - MSGC_NAVIBAR_TITLE_H - MSGC_INDICATOR_H - MSGC_BODY_PADDING);
1197                 D_MSG("scroll_height = %d", scroll_height);
1198
1199                 if (scroll_height <= COMPOSER_FRAME_BODY_LANDSCAPE_HEIGHT_MIN)
1200                         scroll_height = COMPOSER_FRAME_BODY_LANDSCAPE_HEIGHT_MIN;
1201
1202                 if (scroll_h != scroll_height) {
1203                         evas_object_size_hint_max_set(cd->body_scroll, 9999, scroll_height);
1204                         elm_scroller_content_min_limit(cd->body_scroll, EINA_FALSE, EINA_TRUE);
1205                         D_MSG("scroll size updated w = %d, h = %d", scroll_w, scroll_height);
1206                 }
1207         } else {
1208                 D_EMSG("Unknown Composer Mode");
1209         }
1210
1211         D_LEAVE;
1212 }
1213
1214 void msg_ui_composer_make_default_body_size(MSG_COMPOSER_VIEW_DATA_S *cd)
1215 {
1216         D_ENTER;
1217         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
1218
1219         int scroll_height = COMPOSER_FRAME_BODY_LANDSCAPE_HEIGHT_MIN;
1220
1221         cd->is_default_body_size = true;
1222
1223         msg_ui_composer_contract_attach_list(cd);
1224
1225         evas_object_size_hint_max_set(cd->body_scroll, 9999, scroll_height);
1226         elm_scroller_content_min_limit(cd->body_scroll, EINA_FALSE, EINA_TRUE);
1227         /* move scroll to top */
1228         elm_scroller_region_show(cd->body_scroll, 0, 0, 0, 0);
1229
1230         evas_object_event_callback_add(cd->body_box, EVAS_CALLBACK_MOUSE_UP, msg_ui_composer_body_body_layout_clicked_cb, cd);
1231
1232         D_LEAVE;
1233 }
1234
1235 void msg_ui_composer_entry_imf_resize_cb(void * data, Ecore_IMF_Context *ctx, int value)
1236 {
1237         D_ENTER;
1238         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
1239         D_MSG_RETM_IF(cd == NULL, "Composer Data is Invalid");
1240         D_MSG_RETM_IF(ctx == NULL, "Ecore_IMF_Context is Invalid");
1241         int keypad_x = 0;
1242         int keypad_y = 0;
1243         int keypad_w = 0;
1244         int keypad_h = 0;
1245
1246         ecore_imf_context_input_panel_geometry_get(ctx, &keypad_x, &keypad_y, &keypad_w, &keypad_h);
1247         D_MSG("keypad x = %d, y = %d, w = %d, h = %d", keypad_x, keypad_y, keypad_w, keypad_h);
1248         D_MSG("cd->make_default_body_size = %d", cd->make_default_body_size);
1249
1250         if (cd->make_default_body_size) {
1251                  if (!cd->is_keypad_show)
1252                          cd->make_default_body_size = false;
1253         } else {
1254                 if (keypad_w != 0 && keypad_h != 0)
1255                         msg_ui_composer_change_body_scroll_size(cd, keypad_h);
1256         }
1257
1258         D_LEAVE;
1259 }
1260
1261 void msg_ui_composer_entry_imf_state_cb(void * data, Ecore_IMF_Context *ctx, int value)
1262 {
1263         D_ENTER;
1264
1265         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
1266         D_MSG_RETM_IF(cd == NULL, "Composer Data is Invalid");
1267         D_MSG_RETM_IF(ctx == NULL, "Ecore_IMF_Context is Invalid");
1268
1269         if (value == ECORE_IMF_INPUT_PANEL_STATE_SHOW) {
1270                 int keypad_x = 0;
1271                 int keypad_y = 0;
1272                 int keypad_w = 0;
1273                 int keypad_h = 0;
1274
1275                 D_MSG("Imf status SHOW");
1276
1277                 cd->is_keypad_show = true;
1278
1279                 ecore_imf_context_input_panel_geometry_get(ctx, &keypad_x, &keypad_y, &keypad_w, &keypad_h);
1280                 D_MSG("keypad x = %d, y = %d, w = %d, h = %d", keypad_x, keypad_y, keypad_w, keypad_h);
1281
1282                 msg_ui_composer_change_body_scroll_size(cd, keypad_h);
1283         } else if (value == ECORE_IMF_INPUT_PANEL_STATE_HIDE) {
1284                 D_MSG("Imf status HIDE");
1285
1286                 cd->is_keypad_show = false;
1287
1288                 D_MSG("cd->make_default_body_size = %d", cd->make_default_body_size);
1289
1290                 if (cd->make_default_body_size) {
1291                         cd->make_default_body_size = false;
1292                         msg_ui_composer_make_default_body_size(cd);
1293                 } else {
1294                 msg_ui_composer_change_body_scroll_size(cd, 0);
1295                 }
1296         } else {
1297                 D_EMSG("imf status INVALID");
1298         }
1299
1300         D_LEAVE;
1301 }
1302
1303 int msg_ui_composer_get_font_size(int index, int type)
1304 {
1305         D_ENTER;
1306         D_MSG("index = %d, type = %d", index, type);
1307
1308         int font_size = MSG_APP_FONT_SIZE_NORMAL;
1309
1310         if (type == COMPOSER_MSG_FONT_SIZE) {
1311                 switch (index) {
1312                 case MSG_APP_FONT_SIZE_INDEX_GIANT:
1313                         font_size = MSG_APP_FONT_SIZE_GIANT;
1314                         break;
1315                 case MSG_APP_FONT_SIZE_INDEX_HUGE:
1316                         font_size = MSG_APP_FONT_SIZE_HUGE;
1317                         break;
1318                 case MSG_APP_FONT_SIZE_INDEX_LARGE:
1319                         font_size = MSG_APP_FONT_SIZE_LARGE;
1320                         break;
1321                 case MSG_APP_FONT_SIZE_INDEX_NORMAL:
1322                         font_size = MSG_APP_FONT_SIZE_NORMAL;
1323                         break;
1324                 case MSG_APP_FONT_SIZE_INDEX_SMALL:
1325                         font_size = MSG_APP_FONT_SIZE_SMALL;
1326                         break;
1327                 case MSG_APP_FONT_SIZE_INDEX_SYSTEM_FONT:
1328                 default:
1329                         D_MSG("get defulat size index = %d", index);
1330                         font_size = MSG_APP_FONT_SIZE_NORMAL;
1331                         break;
1332                 }
1333         } else if (type == COMPOSER_SYSTEM_FONT_SIZE) {
1334                 switch (index) {
1335                 case MSG_SYS_FONT_SIZE_INDEX_GIANT:
1336                         font_size = MSG_APP_FONT_SIZE_HUGE + 4;
1337                         break;
1338                 case MSG_SYS_FONT_SIZE_INDEX_HUGE:
1339                         font_size = MSG_APP_FONT_SIZE_HUGE;
1340                         break;
1341                 case MSG_SYS_FONT_SIZE_INDEX_LARGE:
1342                         font_size = MSG_APP_FONT_SIZE_LARGE;
1343                         break;
1344                 case MSG_SYS_FONT_SIZE_INDEX_NORMAL:
1345                         font_size = MSG_APP_FONT_SIZE_NORMAL;
1346                         break;
1347                 case MSG_SYS_FONT_SIZE_INDEX_SMALL:
1348                         font_size = MSG_APP_FONT_SIZE_SMALL;
1349                         break;
1350                 default:
1351                         D_MSG("get defulat size index = %d", index);
1352                         font_size = MSG_APP_FONT_SIZE_NORMAL;
1353                         break;
1354                 }
1355         } else {
1356                 D_EMSG("Invalid font type");
1357         }
1358
1359         D_LEAVE;
1360
1361         return font_size;
1362 }
1363
1364 void msg_ui_composer_apply_font_size(MSG_COMPOSER_VIEW_DATA_S *cd)
1365 {
1366         D_ENTER;
1367         D_MSG_RETM_IF(cd == NULL, "Composer Data is Invalid");
1368
1369         int converted_size = 0;
1370
1371         if (cd->font_size.last_updated_setting == COMPOSER_SYSTEM_FONT_SIZE) {
1372                 converted_size = cd->font_size.sys_font_size;
1373         } else if (cd->font_size.last_updated_setting == COMPOSER_MSG_FONT_SIZE) {
1374                 converted_size = cd->font_size.msg_font_size;
1375         } else {
1376                 D_EMSG("Invalid type");
1377                 return;
1378         }
1379
1380         /* apply font size */
1381         char font_style_str[DEF_BUF_LEN_S + 1] = {0,};
1382         snprintf(font_style_str, sizeof(font_style_str), "DEFAULT='font_size=%d'", converted_size);
1383         D_MSG("font_style_str = (%s)", font_style_str);
1384
1385         msg_ui_composer_body_apply_font_size(cd, font_style_str);
1386
1387         D_LEAVE;
1388 }
1389