summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyuho Jo <kyuho.jo@samsung.com>2016-03-23 05:35:03 (GMT)
committerKyuho Jo <kyuho.jo@samsung.com>2016-03-23 05:35:03 (GMT)
commitcbf881c56718003d8306d01ca56b1b4092ca7d57 (patch)
tree1470df861838eb6665da225eeeff02cb41b6d683
parent656e5b2644786a48d00930c159e93e912a10132f (diff)
downloadair_mediahub-cbf881c56718003d8306d01ca56b1b4092ca7d57.zip
air_mediahub-cbf881c56718003d8306d01ca56b1b4092ca7d57.tar.gz
air_mediahub-cbf881c56718003d8306d01ca56b1b4092ca7d57.tar.bz2
Replace repeated codes with functionsrefs/changes/94/63294/1
Change-Id: If73e66c73307df020d2d7acda2e37dd58fd94c12 Signed-off-by: Kyuho Jo <kyuho.jo@samsung.com>
-rw-r--r--include/util/util.h3
-rw-r--r--src/data/albumdata.c41
-rw-r--r--src/data/mediadata.c74
-rw-r--r--src/util/util.c58
4 files changed, 90 insertions, 86 deletions
diff --git a/include/util/util.h b/include/util/util.h
index 846e4fc..3076e44 100644
--- a/include/util/util.h
+++ b/include/util/util.h
@@ -19,6 +19,7 @@
#include <media_content.h>
#include <app_media.h>
+#include <utils_i18n.h>
bool util_check_movie_type(const char *str);
bool util_launch_request(const char *appid, const char *key, const char *value);
@@ -36,6 +37,8 @@ Evas_Object *util_add_table(Evas_Object *base, int padding_x, int padding_y);
void util_time_string(char *str, int size, unsigned int ms, bool full);
void util_up_string(char *str);
+i18n_uchar* util_convert_to_UTF16_string(const char *source_string);
+char* util_convert_to_UTF8_string(i18n_uchar *sourct_string);
int util_get_media_index(Eina_List *list, void *info);
int util_get_media_index_from_id(Eina_List *list, const char *id);
diff --git a/src/data/albumdata.c b/src/data/albumdata.c
index 92b816a..ae9833a 100644
--- a/src/data/albumdata.c
+++ b/src/data/albumdata.c
@@ -21,6 +21,7 @@
#include <utils_i18n.h>
#include "data/datamgr.h"
+#include "util/util.h"
struct albumdata;
@@ -194,21 +195,21 @@ static int _compare_name(struct group_info *gi, struct album_info *ai)
int32_t result = -1;
i18n_uchar *converted_group_name = NULL;
- i18n_uchar *converted_album_name = NULL;
+ i18n_uchar *converted_album_title = NULL;
- converted_group_name = _convert_to_UTF16_string(gi->data);
- converted_album_name = _convert_to_UTF16_string(ai->name);
+ converted_group_name = util_convert_to_UTF16_string(gi->data);
+ converted_album_title = util_convert_to_UTF16_string(ai->name);
- if (converted_group_name && converted_album_name) {
- result = i18n_ustring_case_compare_n(converted_group_name, converted_album_name, 1, I18N_USTRING_U_FOLD_CASE_DEFAULT);
+ if (converted_group_name && converted_album_title) {
+ result = i18n_ustring_case_compare_n(converted_group_name, converted_album_title, 1, I18N_USTRING_U_FOLD_CASE_DEFAULT);
}
if (converted_group_name) {
free(converted_group_name);
}
- if (converted_album_name) {
- free(converted_album_name);
+ if (converted_album_title) {
+ free(converted_album_title);
}
return result;
@@ -246,16 +247,16 @@ static char *_get_name(struct album_info *ai)
i18n_uchar *converted_string = NULL;
i18n_uchar sub_string[10] = { 0, };
- converted_string = _convert_to_UTF16_string(ai->name);
+ converted_string = util_convert_to_UTF16_string(ai->name);
if (converted_string == NULL) {
- _ERR("_convert_to_UTF16_string failed");
+ _ERR("util_convert_to_UTF16_string failed");
goto OUT;
}
/* Get a character (not a byte) from left */
i18n_ustring_copy_n(sub_string, converted_string, 1);
- result_str = _convert_to_UTF8_string(sub_string);
+ result_str = util_convert_to_UTF8_string(sub_string);
OUT:
@@ -272,21 +273,21 @@ static int _compare_artist(struct group_info *gi, struct album_info *ai)
int32_t result = -1;
i18n_uchar *converted_group_name = NULL;
- i18n_uchar *converted_artist_name = NULL;
+ i18n_uchar *converted_artist = NULL;
- converted_group_name = _convert_to_UTF16_string(gi->data);
- converted_artist_name = _convert_to_UTF16_string(ai->artist);
+ converted_group_name = util_convert_to_UTF16_string(gi->data);
+ converted_artist = util_convert_to_UTF16_string(ai->artist);
- if (converted_group_name && converted_artist_name) {
- result = i18n_ustring_case_compare_n(converted_group_name, converted_artist_name, 1, I18N_USTRING_U_FOLD_CASE_DEFAULT);
+ if (converted_group_name && converted_artist) {
+ result = i18n_ustring_case_compare_n(converted_group_name, converted_artist, 1, I18N_USTRING_U_FOLD_CASE_DEFAULT);
}
if (converted_group_name) {
free(converted_group_name);
}
- if (converted_artist_name) {
- free(converted_artist_name);
+ if (converted_artist) {
+ free(converted_artist);
}
return result;
@@ -324,16 +325,16 @@ static char *_get_artist(struct album_info *ai)
i18n_uchar *converted_string = NULL;
i18n_uchar sub_string[10] = { 0, };
- converted_string = _convert_to_UTF16_string(ai->artist);
+ converted_string = util_convert_to_UTF16_string(ai->artist);
if (converted_string == NULL) {
- _ERR("_convert_to_UTF16_string failed");
+ _ERR("util_convert_to_UTF16_string failed");
goto OUT;
}
/* Get a character (not a byte) from left */
i18n_ustring_copy_n(sub_string, converted_string, 1);
- result_str = _convert_to_UTF8_string(sub_string);
+ result_str = util_convert_to_UTF8_string(sub_string);
OUT:
diff --git a/src/data/mediadata.c b/src/data/mediadata.c
index 50d4ac1..eac8507 100644
--- a/src/data/mediadata.c
+++ b/src/data/mediadata.c
@@ -18,9 +18,9 @@
#include <media_content.h>
#include <app_debug.h>
#include <app_media.h>
-#include <utils_i18n.h>
#include "data/datamgr.h"
+#include "util/util.h"
#define STR_IMAGE_NAME "Photo"
#define STR_VIDEO_NAME "Video"
@@ -142,64 +142,6 @@ static char *_get_date_string(struct tm *tm)
return strdup(buf);
}
-static i18n_uchar* _convert_to_UTF16_string(const char *source_string)
-{
- int buffer_length = 0;
- i18n_error_code_e error_from_i18n;
- i18n_uchar *converted_string = NULL;
-
- /* Calc buffer size for converted UTF16 string */
- i18n_ustring_from_UTF8(NULL, 0, &buffer_length, source_string, -1, &error_from_i18n);
-
- converted_string = malloc((buffer_length + 2) * sizeof(i18n_uchar));
- if (converted_string == NULL) {
- _ERR("malloc failed");
- goto OUT;
- }
-
- /* Convert to i18n(UTF16) string */
- i18n_ustring_from_UTF8(converted_string, buffer_length + 1, &buffer_length, source_string, -1, &error_from_i18n);
- if (error_from_i18n != I18N_ERROR_NONE) {
- _ERR("i18n_ustring_from_UTF8 returns [%d]", error_from_i18n);
- free(converted_string);
- goto OUT;
- }
- converted_string[buffer_length] = (i18n_uchar)0;
-
-OUT:
-
- return converted_string;
-}
-
-static char* _convert_to_UTF8_string(i18n_uchar *sourct_string)
-{
- int buffer_length = 0;
- i18n_error_code_e error_from_i18n;
- char *converted_string = NULL;
-
- i18n_ustring_to_UTF8(NULL, 0, &buffer_length, sourct_string, -1, &error_from_i18n);
-
- converted_string = malloc((buffer_length + 2) * sizeof(char));
- if (converted_string == NULL) {
- _ERR("malloc failed");
- goto OUT;
- }
-
- /* Convert to UTF8 */
- i18n_ustring_to_UTF8(converted_string, buffer_length + 1, &buffer_length, sourct_string, -1, &error_from_i18n);
- if (error_from_i18n != I18N_ERROR_NONE) {
- _ERR("i18n_ustring_to_UTF8 returns [%d]", error_from_i18n);
- free(converted_string);
- converted_string = NULL;
- goto OUT;
- }
- converted_string[buffer_length] = '\0';
-
-OUT:
-
- return converted_string;
-}
-
static int _compare_title(struct group_info *gi, app_media_info *info)
{
if (!gi->data || !info->title)
@@ -209,8 +151,8 @@ static int _compare_title(struct group_info *gi, app_media_info *info)
i18n_uchar *converted_group_name = NULL;
i18n_uchar *converted_media_title = NULL;
- converted_group_name = _convert_to_UTF16_string(gi->data);
- converted_media_title = _convert_to_UTF16_string(info->title);
+ converted_group_name = util_convert_to_UTF16_string(gi->data);
+ converted_media_title = util_convert_to_UTF16_string(info->title);
if (converted_group_name && converted_media_title) {
result = i18n_ustring_case_compare_n(converted_group_name, converted_media_title, 1, I18N_USTRING_U_FOLD_CASE_DEFAULT);
@@ -235,13 +177,13 @@ static void *_get_data_title(app_media_info *info)
char *result_str = NULL;
i18n_uchar *converted_string = NULL;
- converted_string = _convert_to_UTF16_string(info->title);
+ converted_string = util_convert_to_UTF16_string(info->title);
if (converted_string == NULL) {
_ERR("_convert_to_UTF16_string failed");
goto OUT;
}
- result_str = _convert_to_UTF8_string(converted_string);
+ result_str = util_convert_to_UTF8_string(converted_string);
OUT:
if (converted_string)
@@ -259,17 +201,17 @@ static char *_get_title(app_media_info *info)
i18n_uchar *converted_string = NULL;
i18n_uchar sub_string[10] = { 0, };
- converted_string = _convert_to_UTF16_string(info->title);
+ converted_string = util_convert_to_UTF16_string(info->title);
if (converted_string == NULL) {
- _ERR("_convert_to_UTF16_string failed");
+ _ERR("util_convert_to_UTF16_string failed");
goto OUT;
}
/* Get a character (not a byte) from left */
i18n_ustring_copy_n(sub_string, converted_string, 1);
- result_str = _convert_to_UTF8_string(sub_string);
+ result_str = util_convert_to_UTF8_string(sub_string);
OUT:
diff --git a/src/util/util.c b/src/util/util.c
index 9ce3081..cb84c9e 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -455,3 +455,61 @@ Elm_Image_Orient util_get_orient(media_content_orientation_e orient)
return o;
}
+
+i18n_uchar* util_convert_to_UTF16_string(const char *source_string)
+{
+ int buffer_length = 0;
+ i18n_error_code_e error_from_i18n;
+ i18n_uchar *converted_string = NULL;
+
+ /* Calc buffer size for converted UTF16 string */
+ i18n_ustring_from_UTF8(NULL, 0, &buffer_length, source_string, -1, &error_from_i18n);
+
+ converted_string = malloc((buffer_length + 2) * sizeof(i18n_uchar));
+ if (converted_string == NULL) {
+ _ERR("malloc failed");
+ goto OUT;
+ }
+
+ /* Convert to i18n(UTF16) string */
+ i18n_ustring_from_UTF8(converted_string, buffer_length + 1, &buffer_length, source_string, -1, &error_from_i18n);
+ if (error_from_i18n != I18N_ERROR_NONE) {
+ _ERR("i18n_ustring_from_UTF8 returns [%d]", error_from_i18n);
+ free(converted_string);
+ goto OUT;
+ }
+ converted_string[buffer_length] = (i18n_uchar)0;
+
+OUT:
+
+ return converted_string;
+}
+
+char* util_convert_to_UTF8_string(i18n_uchar *sourct_string)
+{
+ int buffer_length = 0;
+ i18n_error_code_e error_from_i18n;
+ char *converted_string = NULL;
+
+ i18n_ustring_to_UTF8(NULL, 0, &buffer_length, sourct_string, -1, &error_from_i18n);
+
+ converted_string = malloc((buffer_length + 2) * sizeof(char));
+ if (converted_string == NULL) {
+ _ERR("malloc failed");
+ goto OUT;
+ }
+
+ /* Convert to UTF8 */
+ i18n_ustring_to_UTF8(converted_string, buffer_length + 1, &buffer_length, sourct_string, -1, &error_from_i18n);
+ if (error_from_i18n != I18N_ERROR_NONE) {
+ _ERR("i18n_ustring_to_UTF8 returns [%d]", error_from_i18n);
+ free(converted_string);
+ converted_string = NULL;
+ goto OUT;
+ }
+ converted_string[buffer_length] = '\0';
+
+OUT:
+
+ return converted_string;
+}