change sound path of mms media
[apps/core/preloaded/message-app.git] / common / msg-ui-common-utility.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 /*=================
19  * INCLUDE HEADERS
20  * ================= */
21 #include <msg-ui-util.h>
22 #include <msg-ui-common-utility.h>
23 #include <msg-ui-image-resource.h>
24
25 /* for i18n */
26 #include <unicode/uloc.h>
27 #include <unicode/ucal.h>
28 #include <unicode/udat.h>
29 #include <unicode/udatpg.h>
30 #include <unicode/ustring.h>
31
32 #include <stdlib.h>
33 #include <vconf-keys.h>
34 #include <bundle.h>
35 #include <syspopup_caller.h>
36 #include <drm_client.h>
37
38 static char *icon_array[MSG_APP_FILE_TYPE_MAX] = {
39         [MSG_APP_FILE_TYPE_IMAGE] = MSG_COMMON_FILE_IMAGE_ICON,
40         [MSG_APP_FILE_TYPE_VIDEO] = MSG_COMMON_FILE_VIDEO_ICON,
41         [MSG_APP_FILE_TYPE_MUSIC] = MSG_COMMON_FILE_MUSIC_ICON,
42         [MSG_APP_FILE_TYPE_SOUND] = MSG_COMMON_FILE_SOUND_ICON,
43         [MSG_APP_FILE_TYPE_PDF] = MSG_COMMON_FILE_PDF_ICON,
44         [MSG_APP_FILE_TYPE_DOC] = MSG_COMMON_FILE_DOC_ICON,
45         [MSG_APP_FILE_TYPE_PPT] = MSG_COMMON_FILE_PPT_ICON,
46         [MSG_APP_FILE_TYPE_EXCEL] = MSG_COMMON_FILE_EXCEL_ICON,
47         [MSG_APP_FILE_TYPE_VOICE] = MSG_COMMON_FILE_VOICE_ICON,
48         [MSG_APP_FILE_TYPE_HTML] = MSG_COMMON_FILE_HTML_ICON,
49         [MSG_APP_FILE_TYPE_FLASH] = MSG_COMMON_FILE_FLASH_ICON,
50         [MSG_APP_FILE_TYPE_TXT] = MSG_COMMON_FILE_TXT_ICON,
51         [MSG_APP_FILE_TYPE_VCONTACT] = MSG_COMMON_FILE_VCONTACT_ICON,
52         [MSG_APP_FILE_TYPE_VCALENDAR] = MSG_COMMON_FILE_VCALENDAR_ICON,
53         [MSG_APP_FILE_TYPE_VNOTE] = MSG_COMMON_FILE_VNOTE_ICON,
54         [MSG_APP_FILE_TYPE_RSS] = MSG_COMMON_FILE_RSS_ICON,
55         [MSG_APP_FILE_TYPE_JAVA] = MSG_COMMON_FILE_JAVA_ICON,
56         [MSG_APP_FILE_TYPE_ETC] = MSG_COMMON_FILE_ETC_ICON,
57 };
58
59 /*==========================
60  * FUNCTION IMPLEMENTATIONS
61  *========================== */
62 const char *msg_common_get_default_locale()
63 {
64         const char *locale;
65         UErrorCode status = U_ZERO_ERROR;
66         /* ICU API to set default locale */
67         uloc_setDefault(getenv("LC_TIME"), &status);
68         locale = uloc_getDefault();
69
70         return locale;
71 }
72
73 int msg_common_get_timeformat()
74 {
75         int timeformat = 0;
76
77         if (vconf_get_int(VCONFKEY_REGIONFORMAT_TIME1224, &timeformat) < 0)
78                 return MSG_TIME_FORMAT_UNKNOWN;
79
80         if (timeformat == VCONFKEY_TIME_FORMAT_12)
81                 return MSG_TIME_FORMAT_12H;
82         else if (timeformat == VCONFKEY_TIME_FORMAT_24)
83                 return MSG_TIME_FORMAT_24H;
84         else
85                 return MSG_TIME_FORMAT_UNKNOWN;
86 }
87
88 char *msg_common_get_date_best_pattern(const char* locale, char* skeleton)
89 {
90         MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
91         MSG_UI_RETV_IF(MSG_UI_LEVEL_ERR, locale == NULL || skeleton == NULL, NULL);
92
93         UErrorCode status = U_ZERO_ERROR;
94         UDateTimePatternGenerator *generator = NULL;
95         UChar bestPattern[MSG_COMMON_MAX_UCHAR_PATTERN_LEN + 1] = {0,};
96         char bestPatternString[MSG_COMMON_MAX_CHAR_PATTERN_LEN + 1] = {0,};
97         int32_t bestPatternCapacity = 0;
98         int32_t bestPatternLength = 0;
99
100         UChar customSkeleton[MSG_COMMON_MAX_UCHAR_PATTERN_LEN + 1] = {0,};
101         int skeletonLength = 0;
102
103         skeletonLength = strlen(skeleton);
104         /* convert char to uchar */
105         if (skeletonLength <= MSG_COMMON_MAX_UCHAR_PATTERN_LEN)
106                 u_uastrncpy(customSkeleton, skeleton, skeletonLength);
107         else
108                 u_uastrncpy(customSkeleton, skeleton, MSG_COMMON_MAX_UCHAR_PATTERN_LEN);
109
110         generator = udatpg_open(locale, &status);
111         bestPatternCapacity = MSG_COMMON_MAX_UCHAR_PATTERN_LEN;
112
113         /* get bestpattern from customskeletom of uchar */
114         bestPatternLength = udatpg_getBestPattern(generator, customSkeleton, u_strlen(customSkeleton), bestPattern, bestPatternCapacity, &status);
115
116         /* convert uchar to char to know bestpatternstring */
117         u_austrcpy(bestPatternString, bestPattern);
118
119         udatpg_close(generator);
120
121         MSG_UI_LEAVE(MSG_UI_LEVEL_DEBUG);
122
123         return strdup(bestPatternString);
124 }
125
126 char *msg_common_get_formatted_date(const char* locale, char* bestPattern, void *time)
127 {
128         MSG_UI_RETV_IF(MSG_UI_LEVEL_ERR, locale == NULL || bestPattern == NULL || time == NULL, NULL);
129
130         UErrorCode status = U_ZERO_ERROR;
131         UDate date;
132         UDateFormat *date_format = NULL;
133         UChar uBestPattern[MSG_COMMON_MAX_UCHAR_PATTERN_LEN + 1] = {0,};
134         UChar formatted[MSG_COMMON_MAX_UCHAR_PATTERN_LEN + 1] = {0,};
135         char formattedString[MSG_COMMON_MAX_CHAR_PATTERN_LEN + 1] = {0,};
136         int32_t formattedCapacity = 0;
137         int patternLength = 0, formattedLength = 0;
138
139         patternLength = strlen(bestPattern);
140         /* convert char to uchar */
141         if (patternLength <= MSG_COMMON_MAX_UCHAR_PATTERN_LEN)
142                 u_uastrncpy(uBestPattern, bestPattern, patternLength);
143         else
144                 u_uastrncpy(uBestPattern, bestPattern, MSG_COMMON_MAX_UCHAR_PATTERN_LEN);
145
146         /* convert time_t to UDate, if it is */
147         if (time) {
148                 time_t msg_time = *(time_t *) time;
149                 date = (UDate) msg_time * 1000; /* Equivalent to Date = ucal_getNow() in Milliseconds */
150         } else
151                 date = ucal_getNow();
152
153         date_format = udat_open(UDAT_IGNORE, UDAT_IGNORE, locale, NULL, -1, uBestPattern, -1, &status);
154         formattedCapacity = MSG_COMMON_MAX_UCHAR_PATTERN_LEN;
155         /* get formatted string */
156         formattedLength = udat_format(date_format, date, formatted, formattedCapacity, NULL, &status);
157         /* convert uchar to char */
158         u_austrcpy(formattedString, formatted);
159
160         udat_close(date_format);
161
162         return strdup(formattedString);
163 }
164
165 char *msg_common_get_date_text(const char* locale, char* skeleton, void* time)
166 {
167         MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
168         MSG_UI_RETV_IF(MSG_UI_LEVEL_ERR, locale == NULL, NULL);
169         MSG_UI_RETV_IF(MSG_UI_LEVEL_ERR, skeleton == NULL, NULL);
170
171         UChar customSkeleton[MSG_COMMON_MAX_UCHAR_PATTERN_LEN + 1] = {0,};
172         int skeletonLength = 0;
173
174         skeletonLength = strlen(skeleton);
175         /* convert char to uchar */
176         if (skeletonLength <= MSG_COMMON_MAX_UCHAR_PATTERN_LEN)
177                 u_uastrncpy(customSkeleton, skeleton, skeletonLength);
178         else
179                 u_uastrncpy(customSkeleton, skeleton, MSG_COMMON_MAX_UCHAR_PATTERN_LEN);
180
181         UErrorCode status = U_ZERO_ERROR;
182         UDateTimePatternGenerator *generator = NULL;
183         UDateFormat *date_format = NULL;
184         UDate date;
185         UChar bestPattern[MSG_COMMON_MAX_UCHAR_PATTERN_LEN + 1] = {0,};
186         UChar formatted[MSG_COMMON_MAX_UCHAR_PATTERN_LEN + 1] = {0,};
187         char bestPatternString[MSG_COMMON_MAX_CHAR_PATTERN_LEN + 1] = {0,};
188         char formattedString[MSG_COMMON_MAX_CHAR_PATTERN_LEN + 1] = {0,};
189         int32_t bestPatternCapacity = 0;
190         int32_t bestPatternLength = 0;
191         int32_t formattedCapacity = 0;
192         int32_t formattedLength = 0;
193
194         generator = udatpg_open(locale, &status);
195         bestPatternCapacity = MSG_COMMON_MAX_UCHAR_PATTERN_LEN;
196
197         /* get bestpattern from customskeletom of uchar */
198         bestPatternLength = udatpg_getBestPattern(generator, customSkeleton, u_strlen(customSkeleton), bestPattern, bestPatternCapacity, &status);
199
200         /* convert uchar to char to know bestpatternstring */
201         u_austrcpy(bestPatternString, bestPattern);
202
203         /* convert time_t to UDate, if it is */
204         if (time) {
205                 time_t msg_time = *(time_t *) time;
206                 date = (UDate) msg_time * 1000; /* Equivalent to Date = ucal_getNow() in Milliseconds */
207         } else
208                 date = ucal_getNow();
209
210         date_format = udat_open(UDAT_IGNORE, UDAT_IGNORE, locale, NULL, -1, bestPattern, -1, &status);
211         formattedCapacity = MSG_COMMON_MAX_UCHAR_PATTERN_LEN;
212         /* get formatted string */
213         formattedLength = udat_format(date_format, date, formatted, formattedCapacity, NULL, &status);
214         /* convert uchar to char */
215         u_austrcpy(formattedString, formatted);
216
217         udatpg_close(generator);
218         udat_close(date_format);
219
220         return strdup(formattedString);
221 }
222
223 char *msg_common_get_display_date(const char* locale, char* bestPattern, time_t *msg_t)
224 {
225         struct tm msg_time, cur_time;
226         time_t cur_t;
227         char msg_date_buf[DEF_BUF_LEN] = { '0', };
228         char *date_str = NULL;
229         int diffday = 0, msg_day = 0, cur_day = 0;
230
231         cur_t = (time_t) time(NULL);
232
233         localtime_r(msg_t, &msg_time);
234         localtime_r(&cur_t, &cur_time);
235
236         msg_day = (msg_time.tm_year - 1900) * 365 + msg_time.tm_yday + (msg_time.tm_year - 1900 - 1) / 4;
237         cur_day = (cur_time.tm_year - 1900) * 365 + cur_time.tm_yday + (cur_time.tm_year - 1900 - 1) / 4;
238
239         diffday = cur_day - msg_day;
240
241         if (diffday == 0)
242                 snprintf(msg_date_buf, sizeof(msg_date_buf), "%s", dgettext("sys_string", "IDS_COM_BODY_TODAY"));
243         else if (diffday == 1)
244                 snprintf(msg_date_buf, sizeof(msg_date_buf), "%s", dgettext("sys_string", "IDS_COM_BODY_YESTERDAY"));
245         else {
246                 date_str = msg_common_get_formatted_date(locale, bestPattern, msg_t);
247                 if (date_str) {
248                         strncpy(msg_date_buf, date_str, sizeof(msg_date_buf) - 1);
249                         free(date_str);
250                 }
251         }
252
253         return strdup(msg_date_buf);
254 }
255
256 static MSG_BOOL __msg_common_make_normal_markup_text(Eina_Strbuf *markup_text, Eina_Strbuf *font_style, const char *src, int strlen)
257 {
258         MSG_UI_RETV_IF(MSG_UI_LEVEL_ERR, markup_text == NULL, FALSE);
259         MSG_UI_RETV_IF(MSG_UI_LEVEL_ERR, font_style == NULL, FALSE);
260         MSG_UI_RETV_IF(MSG_UI_LEVEL_ERR, src == NULL, FALSE);
261
262         char *tmp_body_buf = NULL;
263         tmp_body_buf = (char *) calloc(strlen + 1, sizeof(char));
264         if (tmp_body_buf) {
265                 strncpy(tmp_body_buf, src, strlen);
266         } else {
267                 MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "calloc is failed");
268                 return FALSE;
269         }
270
271         eina_strbuf_append_printf(markup_text, "%s%s%s", MSG_COMMON_TAG_TEXT, eina_strbuf_string_get(font_style), tmp_body_buf);
272         if (tmp_body_buf) {
273                 free(tmp_body_buf);
274                 tmp_body_buf = NULL;
275         }
276
277         return TRUE;
278 }
279
280 Eina_Strbuf *msg_common_get_markup_text(const char *src, int fontsize, char *fontcolor, char *fontstyle)
281 {
282         MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
283         MSG_UI_RETV_IF(MSG_UI_LEVEL_ERR, src == NULL, NULL);
284
285         const char *src_text = src;
286
287         if (src_text && strlen(src_text) > 0) {
288                 Eina_Strbuf *markup_text = NULL;
289                 Eina_Strbuf *font_buf = NULL;
290                 char *token = NULL;
291                 char *tmp_buf = NULL;
292                 char *remained_string = NULL;
293                 int src_text_len = 0;
294
295                 src_text_len = strlen(src_text);
296                 MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "src_text_len : %d", src_text_len);
297                 tmp_buf = (char *) calloc(src_text_len + 1, sizeof(char));
298                 if (tmp_buf == NULL) {
299                         MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "tmp mem alloc is failed!");
300                         return NULL;
301                 }
302
303                 font_buf = eina_strbuf_new();
304                 if (font_buf == NULL) {
305                         MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "font_buf eina_strbuf_new is failed!");
306                         if (tmp_buf) {
307                                 free(tmp_buf);
308                                 tmp_buf = NULL;
309                         }
310                         return NULL;
311                 }
312
313                 markup_text = eina_strbuf_new();
314                 if (markup_text == NULL) {
315                         MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "markup_text eina_strbuf_new is failed!");
316                         if (tmp_buf) {
317                                 free(tmp_buf);
318                                 tmp_buf = NULL;
319                         }
320
321                         if (font_buf) {
322                                 eina_strbuf_free(font_buf);
323                                 font_buf = NULL;
324                         }
325                         return NULL;
326                 }
327
328                 /* make font style */
329                 if (fontstyle)
330                         eina_strbuf_append_printf(font_buf, "<%s>", fontstyle);
331
332 /*
333  *              unsupport font size
334  *              if (fontsize > 0)
335  *                      eina_strbuf_append_printf(font_buf, "<font_size=%d>", fontsize);
336  */
337                 if (fontcolor)
338                         eina_strbuf_append_printf(font_buf, "<color=%s>", fontcolor);
339                 MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "font_buf : (%s)", eina_strbuf_string_get(font_buf));
340
341                 snprintf(tmp_buf, src_text_len + 1, "%s\n", (char *) src_text);
342
343                 token = strtok_r(tmp_buf, "\n", &remained_string);
344
345                 int token_len = 0;
346
347                 while (token) {
348                         token_len = strlen(token);
349
350                         if (token[token_len - 1] == 0x0D) { /* if Enter is added via Window system, CR+LF is added. */
351                                 MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "CR length is decreased");
352                                 token_len = token_len - 1;
353                         }
354
355                         if (!__msg_common_make_normal_markup_text(markup_text, font_buf, token, token_len))
356                                 MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "__msg_common_make_normal_markup_text is failed");
357
358                         token = strtok_r(NULL, "\n", &remained_string);
359                         if (token)
360                                 eina_strbuf_append(markup_text, "<br>");
361                 }
362
363                 if (tmp_buf) {
364                         free(tmp_buf);
365                         tmp_buf = NULL;
366                 }
367
368                 if (font_buf) {
369                         eina_strbuf_free(font_buf);
370                         font_buf = NULL;
371                 }
372
373                 return markup_text;
374         } else {
375                 return NULL;
376         }
377 }
378
379 MSG_BOOL msg_common_is_valid_phone_number(const char *address)
380 {
381         MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
382         MSG_UI_RETVM_IF(MSG_UI_LEVEL_ERR, address == NULL, FALSE, "address is NULL");
383
384         int addr_len = 0;
385         addr_len = strlen(address);
386
387         if (addr_len == 0)
388                 return FALSE;
389
390         /*  length check phone address should be longer than 2 and shorter than 40 */
391         if (addr_len > 2 && addr_len <= MSG_COMMON_NUMBER_MAX_LEN) {
392                 const char *pszOneChar = address;
393
394                 if (*pszOneChar == '+')
395                         ++pszOneChar;
396
397                 while (*pszOneChar) {
398                         if (!isdigit(*pszOneChar) && (*pszOneChar != '*') && (*pszOneChar != '#'))
399                                 return FALSE;
400
401                         ++pszOneChar;
402                 }
403
404                 return TRUE;
405         } else {
406                 MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "invalid address length [%d]", addr_len);
407                 return FALSE;
408         }
409 }
410
411 MSG_BOOL msg_common_is_valid_email_addr(const char *address)
412 {
413         MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
414         MSG_UI_RETVM_IF(MSG_UI_LEVEL_ERR, address == NULL, FALSE, "address is NULL");
415
416         const char *pszOneChar = address;
417         MSG_BOOL bIsPrefixStringCorrect = FALSE;
418         MSG_BOOL bIsSurfixStringCorrect = FALSE;
419         MSG_BOOL bIsExistAt = FALSE;
420
421         for (; *pszOneChar != '\0'; ++pszOneChar) {
422                 if (bIsExistAt == FALSE) {
423                         if (isalnum(*pszOneChar) || *pszOneChar == '.' || *pszOneChar == '_' || *pszOneChar == '-') {
424                                 bIsPrefixStringCorrect = TRUE;
425                                 continue;
426                         } else if (*pszOneChar == '@') {
427                                 if (bIsPrefixStringCorrect == FALSE)
428                                         return FALSE;
429                                 else
430                                         bIsExistAt = TRUE;
431                         } else {
432                                 return FALSE;
433                         }
434                 } else {
435                         if (isalnum(*pszOneChar) || *pszOneChar == '.' || *pszOneChar == '_' || *pszOneChar == '-') {
436                                 bIsSurfixStringCorrect = TRUE;
437                                 continue;
438                         } else {
439                                 return FALSE;
440                         }
441                 }
442         }
443
444         return (bIsPrefixStringCorrect) && (bIsSurfixStringCorrect) && (bIsExistAt);
445 }
446
447 MSG_BOOL msg_common_is_connected_call(void)
448 {
449         int call_status = 0;
450
451         if (vconf_get_int(VCONFKEY_CALL_STATE, &call_status) < 0)
452                 return FALSE;
453
454         MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "call_status = %d", call_status);
455
456         if (call_status != VCONFKEY_CALL_OFF)
457                 return TRUE;
458         else
459                 return FALSE;
460 }
461
462 MSG_BOOL msg_common_is_sim_inserted(void)
463 {
464         int sim_slot_status = 0;
465
466         if (vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &sim_slot_status) < 0)
467                 return FALSE;
468
469         MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "sim_slot_status = %d", sim_slot_status);
470
471         if (sim_slot_status == VCONFKEY_TELEPHONY_SIM_INSERTED)
472                 return TRUE;
473         else
474                 return FALSE;
475 }
476
477 MSG_BOOL msg_common_get_font_size(int *index, int *font_size)
478 {
479         MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
480         MSG_UI_RETV_IF(MSG_UI_LEVEL_ERR, index == NULL, FALSE);
481         MSG_UI_RETV_IF(MSG_UI_LEVEL_ERR, font_size == NULL, FALSE);
482
483         if (vconf_get_int(VCONFKEY_MSG_APP_FONT_SIZE, index) < 0) {
484                 MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "vconf_get_int(font_size) is failed !!");
485                 return FALSE;
486         } else {
487                 MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "selected index = %d", *index);
488         }
489
490         switch (*index) {
491         case MSG_APP_FONT_SIZE_INDEX_HUGE :
492                 *font_size = MSG_APP_FONT_SIZE_HUGE;
493                 break;
494         case MSG_APP_FONT_SIZE_INDEX_LARGE :
495                 *font_size = MSG_APP_FONT_SIZE_LARGE;
496                 break;
497         case MSG_APP_FONT_SIZE_INDEX_NORMAL :
498                 *font_size = MSG_APP_FONT_SIZE_NORMAL;
499                 break;
500         case MSG_APP_FONT_SIZE_INDEX_SMALL :
501                 *font_size = MSG_APP_FONT_SIZE_SMALL;
502                 break;
503         case MSG_APP_FONT_SIZE_INDEX_TINY :
504                 *font_size = MSG_APP_FONT_SIZE_TINY;
505                 break;
506         case MSG_APP_FONT_SIZE_INDEX_SYSTEM_FONT :
507         default :
508                 *font_size = MSG_APP_FONT_SIZE_NORMAL;
509                 break;
510         }
511
512         return TRUE;
513 }
514
515 MSG_BOOL msg_common_set_font_size(int index)
516 {
517         MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
518
519         if (index < MSG_APP_FONT_SIZE_INDEX_SYSTEM_FONT ||
520                 index >= MSG_APP_FONT_SIZE_INDEX_MAX) {
521                 MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "invalid index = %d", index);
522                 return FALSE;
523         } else {
524                 MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "selected index = %d", index);
525         }
526
527         if (vconf_set_int(VCONFKEY_MSG_APP_FONT_SIZE, index) < 0) {
528                 MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "vconf_set_int(font_size) is failed !!");
529                 return FALSE;
530         }
531
532         return TRUE;
533 }
534
535 MSG_BOOL msg_common_apply_font_size(const char *widget_name, Evas_Object *obj)
536 {
537         MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
538         MSG_UI_RETV_IF(MSG_UI_LEVEL_ERR, widget_name == NULL, FALSE);
539         MSG_UI_RETV_IF(MSG_UI_LEVEL_ERR, obj == NULL, FALSE);
540
541         int index = 0;
542         int font_size = 0;
543         Evas_Font_Size font_size_scale = 0;
544
545         if (msg_common_get_font_size(&index, &font_size) != TRUE) {
546                 MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "msg_common_get_font_size() is failed !!");
547                 return FALSE;
548         } else {
549                 MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "selected index = %d", index);
550         }
551
552         if (index == MSG_APP_FONT_SIZE_INDEX_SYSTEM_FONT) {
553                 edje_text_class_del(widget_name);
554         } else {
555                 /* Calculate the scale factor */
556                 font_size_scale -= (font_size * 100) / MSG_APP_FONT_SIZE_NORMAL;
557
558                 MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "font_size = %d, font_size_scale = %d", font_size, font_size_scale);
559
560                 edje_text_class_del(widget_name);
561                 edje_text_class_set(widget_name, NULL, font_size_scale);
562                 elm_widget_theme_specific(obj, NULL, EINA_TRUE);
563         }
564
565         return TRUE;
566 }
567
568 void msg_common_reset_font_size(const char *widget_name)
569 {
570         MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
571         MSG_UI_RET_IF(MSG_UI_LEVEL_ERR, widget_name == NULL);
572
573         edje_text_class_del(widget_name);
574
575         return;
576 }
577
578 static char *__msg_common_get_file_ext(const char *a_pszfile_name)
579 {
580         if (a_pszfile_name != NULL) {
581                 int nlen = strlen(a_pszfile_name);
582                 char *psztemp = (char *)a_pszfile_name + nlen;
583
584                 while (nlen--) {
585                         psztemp--;
586                         if (*psztemp == '.') {
587                                 psztemp++;
588                                 break;
589                         }
590                 }
591                 return psztemp;
592         }
593
594         return NULL;
595 }
596
597 static MSG_BOOL __msg_common_is_drm_file(const char *filepath)
598 {
599         D_ENTER;
600         D_MSG_RETVM_IF(filepath == NULL, FALSE, "filepath is NULL");
601         drm_bool_type_e is_drm_file = DRM_UNKNOWN;
602         int ret = DRM_RETURN_SUCCESS;
603
604         ret = drm_is_drm_file(filepath, &is_drm_file);
605
606         if (ret == DRM_RETURN_SUCCESS && is_drm_file == DRM_TRUE) {
607                 return TRUE;
608         } else {
609                 D_MSG("ret = %d", ret);
610                 return FALSE;
611         }
612 }
613
614 static MSG_APP_FILE_TYPE_E __msg_common_get_file_type_by_file_ext(const char *file_ext, const char *fullpath)
615 {
616         D_ENTER;
617         int i = 0;
618
619         if (file_ext == NULL) {
620                 D_EMSG("file_ext is NULL");
621                 return MSG_APP_FILE_TYPE_ETC;
622         }
623
624         switch (file_ext[i]) {
625         case 'a':
626         case 'A':
627                 if (strcasecmp("ASF", &file_ext[i]) == 0) {
628                         return MSG_APP_FILE_TYPE_VIDEO;
629                 }
630                 if (strcasecmp("AMR", &file_ext[i]) == 0) {
631                         return MSG_APP_FILE_TYPE_VOICE;
632                 }
633                 if (strcasecmp("AWB", &file_ext[i]) == 0) {
634                         return MSG_APP_FILE_TYPE_VOICE;
635                 }
636                 if (strcasecmp("AAC", &file_ext[i]) == 0) {
637                         return MSG_APP_FILE_TYPE_MUSIC;
638                 }
639                 if (strcasecmp("AVI", &file_ext[i]) == 0) {
640                         return MSG_APP_FILE_TYPE_VIDEO;
641                 }
642                 if (strcasecmp("AAC", &file_ext[i]) == 0) {
643                         return MSG_APP_FILE_TYPE_MUSIC;
644                 }
645                 break;
646
647         case 'b':
648         case 'B':
649                 if (strcasecmp("BMP", &file_ext[i]) == 0) {
650                         return MSG_APP_FILE_TYPE_IMAGE;
651                 }
652                 break;
653
654         case 'd':
655         case 'D':
656                 if (strcasecmp("DOC", &file_ext[i]) == 0) {
657                         return MSG_APP_FILE_TYPE_DOC;
658                 }
659                 if (strcasecmp("DOCX", &file_ext[i]) == 0) {
660                         return MSG_APP_FILE_TYPE_DOC;
661                 }
662                 if (strcasecmp("DIVX", &file_ext[i]) == 0) {
663                         if (__msg_common_is_drm_file(fullpath) == 0) {
664                                 return MSG_APP_FILE_TYPE_DRM;
665                         } else {
666                                 return MSG_APP_FILE_TYPE_VIDEO;
667                         }
668                 }
669                 if (strcasecmp("DCF", &file_ext[i]) == 0) {
670                         return MSG_APP_FILE_TYPE_DRM;
671                 }
672                 break;
673
674         case 'g':
675         case 'G':
676                 if (strcasecmp("GIF", &file_ext[i]) == 0) {
677                         return MSG_APP_FILE_TYPE_IMAGE;
678                 }
679                 if (strcasecmp("G72", &file_ext[i]) == 0) {
680                         return MSG_APP_FILE_TYPE_MUSIC;
681                 }
682                 break;
683
684         case 'h':
685         case 'H':
686                 if (strcasecmp("H263", &file_ext[i]) == 0) {
687                         return MSG_APP_FILE_TYPE_MUSIC;
688                 }
689                 if (strcasecmp("HTML", &file_ext[i]) == 0) {
690                         return MSG_APP_FILE_TYPE_HTML;
691                 }
692                 if (strcasecmp("HTM", &file_ext[i]) == 0) {
693                         return MSG_APP_FILE_TYPE_HTML;
694                 }
695                 break;
696
697         case 'i':
698         case 'I':
699                 if (strcasecmp("IMY", &file_ext[i]) == 0) {
700                         return MSG_APP_FILE_TYPE_SOUND;
701                 }
702                 break;
703
704         case 'j':
705         case 'J':
706                 if (strcasecmp("JAD", &file_ext[i]) == 0) {
707                         return MSG_APP_FILE_TYPE_JAVA;
708                 }
709                 if (strcasecmp("JAR", &file_ext[i]) == 0) {
710                         return MSG_APP_FILE_TYPE_JAVA;
711                 }
712
713                 if (strcasecmp("JPG", &file_ext[i]) == 0) {
714                         return MSG_APP_FILE_TYPE_IMAGE;
715                 }
716                 if (strcasecmp("JPEG", &file_ext[i]) == 0) {
717                         return MSG_APP_FILE_TYPE_IMAGE;
718                 }
719                 if (strcasecmp("JPE", &file_ext[i]) == 0) {
720                         return MSG_APP_FILE_TYPE_IMAGE;
721                 }
722                 break;
723
724         case 'm':
725         case 'M':
726                 if (strcasecmp("MMF", &file_ext[i]) == 0) {
727                         return MSG_APP_FILE_TYPE_SOUND;
728                 }
729                 if (strcasecmp("MP3", &file_ext[i]) == 0) {
730                         return MSG_APP_FILE_TYPE_MUSIC;
731                 }
732                 if (strcasecmp("MID", &file_ext[i]) == 0) {
733                         return MSG_APP_FILE_TYPE_SOUND;
734                 }
735                 if (strcasecmp("MIDI", &file_ext[i]) == 0) {
736                         return MSG_APP_FILE_TYPE_SOUND;
737                 }
738                 if (strcasecmp("MP4", &file_ext[i]) == 0) {
739                         return MSG_APP_FILE_TYPE_VIDEO;
740                 }
741                 if (strcasecmp("MPG", &file_ext[i]) == 0) {
742                         return MSG_APP_FILE_TYPE_VIDEO;
743                 }
744                 if (strcasecmp("MPEG", &file_ext[i]) == 0) {
745                         return MSG_APP_FILE_TYPE_VIDEO;
746                 }
747                 if (strcasecmp("M4A", &file_ext[i]) == 0) {
748                         return MSG_APP_FILE_TYPE_MUSIC;
749                 }
750                 if (strcasecmp("M3G", &file_ext[i]) == 0) {
751                         return MSG_APP_FILE_TYPE_FLASH;
752                 }
753                 if (strcasecmp("MXMF", &file_ext[i]) == 0) {
754                         return MSG_APP_FILE_TYPE_SOUND;
755                 }
756                 if (strcasecmp("MKV", &file_ext[i]) == 0) {
757                         return MSG_APP_FILE_TYPE_VIDEO;
758                 }
759                 if (strcasecmp("MKA", &file_ext[i]) == 0) {
760                         return MSG_APP_FILE_TYPE_MUSIC;
761                 }
762                 break;
763
764         case 'o':
765         case 'O':
766                 if (strcasecmp("opml", &file_ext[i]) == 0) {
767                         return MSG_APP_FILE_TYPE_RSS;
768                 }
769                 break;
770
771         case 'p':
772         case 'P':
773                 if (strcasecmp("PNG", &file_ext[i]) == 0) {
774                         return MSG_APP_FILE_TYPE_IMAGE;
775                 }
776                 if (strcasecmp("PJPEG", &file_ext[i]) == 0) {
777                         return MSG_APP_FILE_TYPE_IMAGE;
778                 }
779                 if (strcasecmp("PDF", &file_ext[i]) == 0) {
780                         return MSG_APP_FILE_TYPE_PDF;
781                 }
782                 if (strcasecmp("PPT", &file_ext[i]) == 0) {
783                         return MSG_APP_FILE_TYPE_PPT;
784                 }
785                 if (strcasecmp("PPTX", &file_ext[i]) == 0) {
786                         return MSG_APP_FILE_TYPE_PPT;
787                 }
788                 break;
789
790         case 'r':
791         case 'R':
792                 break;
793
794         case 's':
795         case 'S':
796                 if (strcasecmp("SDP", &file_ext[i]) == 0) {
797                         return MSG_APP_FILE_TYPE_VIDEO;
798                 }
799                 if (strcasecmp("SPM", &file_ext[i]) == 0) {
800                         return MSG_APP_FILE_TYPE_SOUND;
801                 }
802                 if (strcasecmp("SMP", &file_ext[i]) == 0) {
803                         return MSG_APP_FILE_TYPE_SOUND;
804                 }
805                 if (strcasecmp("SPF", &file_ext[i]) == 0) {
806                         return MSG_APP_FILE_TYPE_SOUND;
807                 }
808                 if (strcasecmp("SWF", &file_ext[i]) == 0) {
809                         return MSG_APP_FILE_TYPE_FLASH;
810                 }
811                 if (strcasecmp("SVG", &file_ext[i]) == 0) {
812                         return MSG_APP_FILE_TYPE_SVG;
813                 }
814                 if (strcasecmp("SVGZ", &file_ext[i]) == 0) {
815                         return MSG_APP_FILE_TYPE_SVG;
816                 }
817                 break;
818
819         case 't':
820         case 'T':
821                 if (strcasecmp("TXT", &file_ext[i]) == 0) {
822                         return MSG_APP_FILE_TYPE_TXT;
823                 }
824                 break;
825
826         case 'v':
827         case 'V':
828                 if (strcasecmp("VCF", &file_ext[i]) == 0) {
829                         return MSG_APP_FILE_TYPE_VCONTACT;
830                 }
831                 if (strcasecmp("VCS", &file_ext[i]) == 0) {
832                         return MSG_APP_FILE_TYPE_VCALENDAR;
833                 }
834                 if (strcasecmp("VNT", &file_ext[i]) == 0) {
835                         return MSG_APP_FILE_TYPE_VNOTE;
836                 }
837                 if (strcasecmp("VBM", &file_ext[i]) == 0) {
838                         return MSG_APP_FILE_TYPE_VBOOKMARK;
839                 }
840                 break;
841
842         case 'w':
843         case 'W':
844                 if (strcasecmp("WAV", &file_ext[i]) == 0) {
845                         return MSG_APP_FILE_TYPE_SOUND;
846                 }
847                 if (strcasecmp("WBMP", &file_ext[i]) == 0) {
848                         return MSG_APP_FILE_TYPE_IMAGE;
849                 }
850                 if (strcasecmp("WGT", &file_ext[i]) == 0) {
851                         return MSG_APP_FILE_TYPE_WGT;
852                 }
853                 if (strcasecmp("WMA", &file_ext[i]) == 0) {
854                         return MSG_APP_FILE_TYPE_MUSIC;
855                 }
856                 if (strcasecmp("WMV", &file_ext[i]) == 0) {
857                         return MSG_APP_FILE_TYPE_VIDEO;
858                 }
859                 break;
860
861         case 'x':
862         case 'X':
863                 if (strcasecmp("XLS", &file_ext[i]) == 0) {
864                         return MSG_APP_FILE_TYPE_EXCEL;
865                 }
866                 if (strcasecmp("XLSX", &file_ext[i]) == 0) {
867                         return MSG_APP_FILE_TYPE_EXCEL;
868                 }
869                 if (strcasecmp("XMF", &file_ext[i]) == 0) {
870                         return MSG_APP_FILE_TYPE_SOUND;
871                 }
872                 if (strcasecmp("XHTML", &file_ext[i]) == 0) {
873                         return MSG_APP_FILE_TYPE_HTML;
874                 }
875                 break;
876
877         case '3':
878                 if (strcasecmp("3GP", &file_ext[i]) == 0) {
879                         return MSG_APP_FILE_TYPE_VIDEO;
880                 }
881                 if (strcasecmp("3GPP", &file_ext[i]) == 0) {
882                         return MSG_APP_FILE_TYPE_VIDEO;
883                 }
884                 if (strcasecmp("3G2", &file_ext[i]) == 0) {
885                         return MSG_APP_FILE_TYPE_VIDEO;
886                 }
887                 break;
888         }
889
890         return MSG_APP_FILE_TYPE_ETC;
891 }
892
893 const char *__msg_common_get_file_icon_by_file_type(MSG_APP_FILE_TYPE_E file_type)
894 {
895         const char *icon_path = MSG_COMMON_FILE_ETC_ICON;
896         if (file_type < MSG_APP_FILE_TYPE_NONE || file_type > MSG_APP_FILE_TYPE_MAX) {
897                 D_EMSG("Invalid file_type!! file_type = %d", file_type);
898                 return NULL;
899         }
900
901         if (icon_array[file_type]) {
902                 icon_path = icon_array[file_type];
903         }
904
905         return icon_path;
906 }
907
908 const char *msg_common_get_file_icon(const char *filepath)
909 {
910         D_ENTER;
911         D_MSG_RETVM_IF(filepath == NULL, NULL, "filepath is NULL");
912         const char *icon_path = MSG_COMMON_FILE_ETC_ICON;
913         char *file_ext = __msg_common_get_file_ext(filepath);
914
915         if (file_ext) {
916                 MSG_APP_FILE_TYPE_E file_type = MSG_APP_FILE_TYPE_NONE;
917
918                 file_type = __msg_common_get_file_type_by_file_ext(file_ext, filepath);
919                 icon_path = __msg_common_get_file_icon_by_file_type(file_type);
920         } else {
921                 D_EMSG("file_ext is NULL");
922         }
923
924         return icon_path;
925 }