summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHyerim Kim <rimi.kim@samsung.com>2016-03-23 14:02:01 +0900
committerHyerim Kim <rimi.kim@samsung.com>2016-03-23 14:05:41 +0900
commit656e5b2644786a48d00930c159e93e912a10132f (patch)
tree5dd805c820a82d55f3cb8f4ddc4059cab74031de
parentff47085ef33f952fde702e8042ca6c5312dc3c9a (diff)
downloadair_mediahub-656e5b2644786a48d00930c159e93e912a10132f.tar.gz
air_mediahub-656e5b2644786a48d00930c159e93e912a10132f.tar.bz2
air_mediahub-656e5b2644786a48d00930c159e93e912a10132f.zip
Fixed bugs to display sorted list by artist in Music category
Signed-off-by: Hyerim Kim <rimi.kim@samsung.com> Change-Id: I83f7589f228f06137270f04e2f778663e2243e2b
-rw-r--r--src/data/albumdata.c195
-rw-r--r--src/data/mediadata.c19
2 files changed, 199 insertions, 15 deletions
diff --git a/src/data/albumdata.c b/src/data/albumdata.c
index a2448ea..92b816a 100644
--- a/src/data/albumdata.c
+++ b/src/data/albumdata.c
@@ -18,6 +18,7 @@
#include <media_content.h>
#include <app_debug.h>
#include <app_media.h>
+#include <utils_i18n.h>
#include "data/datamgr.h"
@@ -70,7 +71,7 @@ static struct _group_info g_group_info[E_GROUP_ALBUM_MAX] = {
.name_get = _get_name,
},
[E_GROUP_ALBUM_ARTIST] = {
- .sort_keyword = MEDIA_ALBUM_ARTIST,
+ .sort_keyword = MEDIA_ARTIST,
.get_list = _get_artist_list,
.media_cmp = _compare_artist,
.data_get = _get_data_artist,
@@ -78,6 +79,66 @@ static struct _group_info g_group_info[E_GROUP_ALBUM_MAX] = {
},
};
+
+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 bool _create_filter(struct albumdata *ad, filter_h *filter,
const char *cond, int filter_type)
{
@@ -94,7 +155,7 @@ static bool _create_filter(struct albumdata *ad, filter_h *filter,
snprintf(buf, sizeof(buf), "%s", ad->media_type);
if (ad->source_type != E_SOURCE_ALL) {
- char s1[64];
+ char s1[128];
snprintf(s1, sizeof(s1), " AND MEDIA_STORAGE_TYPE=%d",
ad->source_type);
@@ -103,7 +164,7 @@ static bool _create_filter(struct albumdata *ad, filter_h *filter,
}
if (cond) {
- char s2[64];
+ char s2[128];
snprintf(s2, sizeof(s2), " AND %s", cond);
strncat(buf, s2, strlen(s2));
@@ -131,7 +192,26 @@ static int _compare_name(struct group_info *gi, struct album_info *ai)
if (!gi->data || !ai->name)
return -1;
- return strncasecmp(gi->data, ai->name, 1);
+ int32_t result = -1;
+ i18n_uchar *converted_group_name = NULL;
+ i18n_uchar *converted_album_name = NULL;
+
+ converted_group_name = _convert_to_UTF16_string(gi->data);
+ converted_album_name = _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) {
+ free(converted_group_name);
+ }
+
+ if (converted_album_name) {
+ free(converted_album_name);
+ }
+
+ return result;
}
static void *_get_data_name(struct album_info *ai)
@@ -139,7 +219,22 @@ static void *_get_data_name(struct album_info *ai)
if (!ai->name)
return NULL;
- return strdup(ai->name);
+ char *result_str = NULL;
+ i18n_uchar *converted_string = NULL;
+
+ converted_string = _convert_to_UTF16_string(ai->name);
+
+ if (converted_string == NULL) {
+ _ERR("_convert_to_UTF16_string failed");
+ goto OUT;
+ }
+ result_str = _convert_to_UTF8_string(converted_string);
+
+OUT:
+ if (converted_string)
+ free(converted_string);
+
+ return result_str;
}
static char *_get_name(struct album_info *ai)
@@ -147,7 +242,27 @@ static char *_get_name(struct album_info *ai)
if (!ai->name)
return NULL;
- return strndup(ai->name, 1);
+ char *result_str = NULL;
+ i18n_uchar *converted_string = NULL;
+ i18n_uchar sub_string[10] = { 0, };
+
+ converted_string = _convert_to_UTF16_string(ai->name);
+
+ if (converted_string == NULL) {
+ _ERR("_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);
+
+OUT:
+
+ if (converted_string)
+ free(converted_string);
+
+ return result_str;
}
static int _compare_artist(struct group_info *gi, struct album_info *ai)
@@ -155,7 +270,26 @@ static int _compare_artist(struct group_info *gi, struct album_info *ai)
if (!gi->data || !ai->artist)
return -1;
- return strncasecmp(gi->data, ai->artist, 1);
+ int32_t result = -1;
+ i18n_uchar *converted_group_name = NULL;
+ i18n_uchar *converted_artist_name = NULL;
+
+ converted_group_name = _convert_to_UTF16_string(gi->data);
+ converted_artist_name = _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) {
+ free(converted_group_name);
+ }
+
+ if (converted_artist_name) {
+ free(converted_artist_name);
+ }
+
+ return result;
}
static void *_get_data_artist(struct album_info *ai)
@@ -163,7 +297,22 @@ static void *_get_data_artist(struct album_info *ai)
if (!ai->artist)
return NULL;
- return strdup(ai->artist);
+ char *result_str = NULL;
+ i18n_uchar *converted_string = NULL;
+
+ converted_string = _convert_to_UTF16_string(ai->artist);
+
+ if (converted_string == NULL) {
+ _ERR("_convert_to_UTF16_string failed");
+ goto OUT;
+ }
+ result_str = _convert_to_UTF8_string(converted_string);
+
+OUT:
+ if (converted_string)
+ free(converted_string);
+
+ return result_str;
}
static char *_get_artist(struct album_info *ai)
@@ -171,7 +320,27 @@ static char *_get_artist(struct album_info *ai)
if (!ai->artist)
return NULL;
- return strndup(ai->artist, 1);
+ char *result_str = NULL;
+ i18n_uchar *converted_string = NULL;
+ i18n_uchar sub_string[10] = { 0, };
+
+ converted_string = _convert_to_UTF16_string(ai->artist);
+
+ if (converted_string == NULL) {
+ _ERR("_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);
+
+OUT:
+
+ if (converted_string)
+ free(converted_string);
+
+ return result_str;
}
static void _destroy_media_list(Eina_List *list)
@@ -297,7 +466,7 @@ static bool _get_each_group_info(const char *group_name, void *data)
ad = data;
- snprintf(buf, sizeof(buf), "MEDIA_ALBUM_ARTIST=\"%s\"", group_name);
+ snprintf(buf, sizeof(buf), "MEDIA_ARTIST=\"%s\"", group_name);
if (!_create_filter(ad, &filter, buf, E_FILTER_ALBUM)) {
_ERR("failed to create filter");
@@ -404,7 +573,7 @@ static bool _get_artist_list(struct albumdata *ad, const char *cond)
}
ret = media_group_foreach_group_from_db(filter,
- MEDIA_CONTENT_GROUP_ALBUM_ARTIST,
+ MEDIA_CONTENT_GROUP_ARTIST,
_get_each_group_info, ad);
if (ret != MEDIA_CONTENT_ERROR_NONE) {
_ERR("failed to get group info");
@@ -463,7 +632,7 @@ static Eina_List *_get_list(void *handle, int type, void *data)
struct albumdata *ad;
int *album_id;
char *artist;
- char buf[64];
+ char buf[128];
if (!handle) {
_ERR("failed to get albumdata handle");
@@ -498,7 +667,7 @@ static Eina_List *_get_list(void *handle, int type, void *data)
artist = data;
- snprintf(buf, sizeof(buf), "MEDIA_ALBUM_ARTIST=\"%s\"", artist);
+ snprintf(buf, sizeof(buf), "MEDIA_ARTIST=\"%s\"", artist);
_get_name_list(ad, buf);
return ad->album_list;
diff --git a/src/data/mediadata.c b/src/data/mediadata.c
index d4dcc41..50d4ac1 100644
--- a/src/data/mediadata.c
+++ b/src/data/mediadata.c
@@ -232,7 +232,22 @@ static void *_get_data_title(app_media_info *info)
if (!info->title)
return NULL;
- return strdup(info->title);
+ char *result_str = NULL;
+ i18n_uchar *converted_string = NULL;
+
+ converted_string = _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);
+
+OUT:
+ if (converted_string)
+ free(converted_string);
+
+ return result_str;
}
static char *_get_title(app_media_info *info)
@@ -481,7 +496,7 @@ static int _compare_cb_name(const void *data1, const void *data2)
info1 = app_media_get_info(am1);
info2 = app_media_get_info(am2);
- if (!info1 || !info2 || !info1->display_name || !info2->display_name)
+ if (!info1 || !info2 || !info1->title || !info2->title)
return -1;
return strcasecmp(info1->title, info2->title);