From 1a94010d6b284b65495559af15abb31e4a0caee7 Mon Sep 17 00:00:00 2001 From: Jehun Lim Date: Thu, 24 Sep 2015 10:58:35 +0900 Subject: [PATCH] albumdata: add function to get media list in the album Change-Id: I77198f34b3f9a493855961b6e9ac555218c954b0 Signed-off-by: Jehun Lim --- include/data/albumdata.h | 10 ++-- include/data/datamgr.h | 4 +- include/data/folderdata.h | 4 +- include/data/mediadata.h | 14 ++++-- src/data/albumdata.c | 124 +++++++++++++++++++++++++++++++++++++++++----- src/data/folderdata.c | 4 +- src/data/mediadata.c | 16 +++--- src/grid/grid_gallery.c | 4 +- src/grid/grid_movie.c | 7 +-- src/grid/grid_music.c | 9 ++-- src/layout/gallery.c | 5 +- src/layout/movie.c | 9 ++-- src/layout/music.c | 9 ++-- 13 files changed, 165 insertions(+), 54 deletions(-) diff --git a/include/data/albumdata.h b/include/data/albumdata.h index 6bc7ed2..0d566bc 100644 --- a/include/data/albumdata.h +++ b/include/data/albumdata.h @@ -20,9 +20,13 @@ struct data_ops; enum album_group_type { - E_ALBUM_NAME = 0, - E_ALBUM_ARTIST, - E_ALBUM_MAX + E_GROUP_ALBUM_NAME = 0, + E_GROUP_ALBUM_ARTIST, + E_GROUP_ALBUM_MAX +}; + +enum album_list_type { + E_LIST_ALBUM_MEDIA = 0, }; struct album_info { diff --git a/include/data/datamgr.h b/include/data/datamgr.h index 734b225..f0222b3 100644 --- a/include/data/datamgr.h +++ b/include/data/datamgr.h @@ -38,10 +38,10 @@ enum source_type { struct data_ops { void *(*create)(const char *media_type, int source_type); void (*destroy)(void *handle); - Eina_List *(*get_list)(void *handle); - int (*get_count)(void *handle, int type); + Eina_List *(*get_list)(void *handle, int type, void *data); Eina_List *(*get_group)(void *handle, int type, void *data); void (*free_group)(Eina_List *list); + int (*get_count)(void *handle, int type); }; struct datamgr { diff --git a/include/data/folderdata.h b/include/data/folderdata.h index 965e630..af1af0a 100644 --- a/include/data/folderdata.h +++ b/include/data/folderdata.h @@ -20,8 +20,8 @@ struct data_ops; enum folder_group_type { - E_FOLDER_NAME, - E_FOLDER_MAX + E_GROUP_FOLDER_NAME, + E_GROUP_FOLDER_MAX }; struct folder_info { diff --git a/include/data/mediadata.h b/include/data/mediadata.h index bc75495..709bb67 100644 --- a/include/data/mediadata.h +++ b/include/data/mediadata.h @@ -20,11 +20,15 @@ struct data_ops; enum media_group_type { - E_MEDIA_DATE = 0, - E_MEDIA_NAME, - E_MEDIA_GENRE, - E_MEDIA_TYPE, - E_MEDIA_MAX + E_GROUP_MEDIA_DATE = 0, + E_GROUP_MEDIA_NAME, + E_GROUP_MEDIA_GENRE, + E_GROUP_MEDIA_TYPE, + E_GROUP_MEDIA_MAX +}; + +enum media_list_type { + E_LIST_MEDIA = 0, }; enum media_file_type { diff --git a/src/data/albumdata.c b/src/data/albumdata.c index 8a20235..1cd6b95 100644 --- a/src/data/albumdata.c +++ b/src/data/albumdata.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "data/datamgr.h" @@ -37,9 +38,16 @@ static int _compare_artist(struct group_info *, struct album_info *); static void *_get_data_artist(struct album_info *); static char *_get_artist(struct album_info *); +enum _filter_type { + E_FILTER_ALBUM = 0, + E_FILTER_MEDIA +}; struct albumdata { Eina_List *album_list; + Eina_List *media_list; + + int group_type; const char *media_type; int source_type; @@ -53,15 +61,15 @@ struct _group_info { group_name_get name_get; }; -static struct _group_info g_group_info[E_ALBUM_MAX] = { - [E_ALBUM_NAME] = { +static struct _group_info g_group_info[E_GROUP_ALBUM_MAX] = { + [E_GROUP_ALBUM_NAME] = { .sort_keyword = MEDIA_ALBUM, .get_list = _get_name_list, .media_cmp = _compare_name, .data_get = _get_data_name, .name_get = _get_name, }, - [E_ALBUM_ARTIST] = { + [E_GROUP_ALBUM_ARTIST] = { .sort_keyword = MEDIA_ALBUM_ARTIST, .get_list = _get_artist_list, .media_cmp = _compare_artist, @@ -71,7 +79,7 @@ static struct _group_info g_group_info[E_ALBUM_MAX] = { }; static bool _create_filter(struct albumdata *ad, filter_h *filter, - const char *cond, int group_type) + const char *cond, int filter_type) { filter_h tmp_filter; int ret; @@ -105,9 +113,14 @@ static bool _create_filter(struct albumdata *ad, filter_h *filter, media_filter_set_condition(tmp_filter, buf, MEDIA_CONTENT_COLLATE_DEFAULT); - media_filter_set_order(tmp_filter, MEDIA_CONTENT_ORDER_ASC, - g_group_info[group_type].sort_keyword, - MEDIA_CONTENT_COLLATE_DEFAULT); + if (filter_type == E_FILTER_ALBUM) { + media_filter_set_order(tmp_filter, MEDIA_CONTENT_ORDER_ASC, + g_group_info[ad->group_type].sort_keyword, + MEDIA_CONTENT_COLLATE_DEFAULT); + } else if (filter_type == E_FILTER_MEDIA) { + media_filter_set_order(tmp_filter, MEDIA_CONTENT_ORDER_ASC, + MEDIA_TITLE, MEDIA_CONTENT_COLLATE_DEFAULT); + } *filter = tmp_filter; @@ -162,6 +175,14 @@ static char *_get_artist(struct album_info *ai) return strndup(ai->artist, 1); } +static void _destroy_media_list(Eina_List *list) +{ + app_media *am; + + EINA_LIST_FREE(list, am) + app_media_destroy(am); +} + static void _destroy_album_list(Eina_List *list) { struct album_info *ai; @@ -175,6 +196,27 @@ static void _destroy_album_list(Eina_List *list) } } +static bool _get_each_media_info(media_info_h media_h, void *data) +{ + Eina_List **list; + app_media *am; + + if (!data) + return false; + + list = data; + + am = app_media_create(media_h); + if (!am) { + _ERR("failed to create app media"); + return false; + } + + *list = eina_list_append(*list, am); + + return true; +} + static bool _get_each_album_info(media_album_h album, void *data) { Eina_List **list; @@ -238,7 +280,7 @@ static bool _get_each_group_info(const char *group_name, void *data) snprintf(buf, sizeof(buf), "MEDIA_ALBUM_ARTIST=\"%s\"", group_name); - if (!_create_filter(ad, &filter, buf, E_ALBUM_ARTIST)) { + if (!_create_filter(ad, &filter, buf, E_FILTER_ALBUM)) { _ERR("failed to create filter"); return false; } @@ -259,6 +301,39 @@ static bool _get_each_group_info(const char *group_name, void *data) return true; } +static bool _get_media_list(struct albumdata *ad, int album_id) +{ + filter_h filter; + int ret; + + ret = media_content_connect(); + if (ret != MEDIA_CONTENT_ERROR_NONE) { + _ERR("failed to connect to media content"); + return false; + } + + if (!_create_filter(ad, &filter, NULL, E_FILTER_MEDIA)) { + _ERR("failed to create filter"); + media_content_disconnect(); + return false; + } + + ret = media_album_foreach_media_from_db(album_id, filter, + _get_each_media_info, &ad->media_list); + if (ret != MEDIA_CONTENT_ERROR_NONE) { + _ERR("failed to get media info"); + _destroy_media_list(ad->media_list); + media_filter_destroy(filter); + media_content_disconnect(); + return false; + } + + media_filter_destroy(filter); + media_content_disconnect(); + + return true; +} + static bool _get_name_list(struct albumdata *ad) { filter_h filter; @@ -270,7 +345,7 @@ static bool _get_name_list(struct albumdata *ad) return false; } - if (!_create_filter(ad, &filter, NULL, E_ALBUM_NAME)) { + if (!_create_filter(ad, &filter, NULL, E_FILTER_ALBUM)) { _ERR("failed to create filter"); media_content_disconnect(); return false; @@ -303,7 +378,7 @@ static bool _get_artist_list(struct albumdata *ad) return false; } - if (!_create_filter(ad, &filter, NULL, E_ALBUM_ARTIST)) { + if (!_create_filter(ad, &filter, NULL, E_FILTER_ALBUM)) { _ERR("failed to create filter"); media_content_disconnect(); return false; @@ -359,22 +434,43 @@ static void _destroy(void *handle) ad = handle; _destroy_album_list(ad->album_list); + _destroy_media_list(ad->media_list); free(ad); } -static Eina_List *_get_list(void *handle) +static Eina_List *_get_list(void *handle, int type, void *data) { struct albumdata *ad; + int *album_id; if (!handle) { _ERR("failed to get albumdata handle"); return NULL; } + if (!data) { + _ERR("invalid argument"); + return NULL; + } + ad = handle; - return ad->album_list; + switch (type) { + case E_LIST_ALBUM_MEDIA: + if (ad->media_list) { + _destroy_media_list(ad->media_list); + ad->media_list = NULL; + } + + album_id = data; + _get_media_list(ad, *album_id); + return ad->media_list; + default: + break; + } + + return NULL; } static int _get_count(void *handle, int type) @@ -421,13 +517,15 @@ static Eina_List *_get_group(void *handle, int type, void *data) return NULL; } - if (type < 0 || type >= E_ALBUM_MAX) { + if (type < 0 || type >= E_GROUP_ALBUM_MAX) { _ERR("invalid argument"); return NULL; } ad = handle; + ad->group_type = type; + if (ad->album_list) { _destroy_album_list(ad->album_list); ad->album_list = NULL; diff --git a/src/data/folderdata.c b/src/data/folderdata.c index fce33d3..6a9ee00 100644 --- a/src/data/folderdata.c +++ b/src/data/folderdata.c @@ -271,7 +271,7 @@ static void _destroy(void *handle) free(fd); } -static Eina_List *_get_list(void *handle) +static Eina_List *_get_list(void *handle, int type, void *data) { struct folderdata *fd; @@ -314,7 +314,7 @@ static Eina_List *_get_group(void *handle, int type, void *data) return NULL; } - if (type < 0 || type > E_FOLDER_MAX || !data) { + if (type < 0 || type > E_GROUP_FOLDER_MAX || !data) { _ERR("invalid argument"); return NULL; } diff --git a/src/data/mediadata.c b/src/data/mediadata.c index f15c691..0be0959 100644 --- a/src/data/mediadata.c +++ b/src/data/mediadata.c @@ -62,26 +62,26 @@ struct _list_info { group_name_get name_get; }; -static struct _list_info g_group_info[E_MEDIA_MAX] = { - [E_MEDIA_DATE] = { +static struct _list_info g_group_info[E_GROUP_MEDIA_MAX] = { + [E_GROUP_MEDIA_DATE] = { .sort_cmp_cb = _compare_cb_date, .media_cmp = _compare_time, .name_get = _get_time, .data_get = _get_data_time, }, - [E_MEDIA_NAME] = { + [E_GROUP_MEDIA_NAME] = { .sort_cmp_cb = _compare_cb_name, .media_cmp = _compare_title, .name_get = _get_title, .data_get = _get_data_title, }, - [E_MEDIA_GENRE] = { + [E_GROUP_MEDIA_GENRE] = { .sort_cmp_cb = _compare_cb_genre, .media_cmp = _compare_genre, .name_get = _get_genre, .data_get = _get_data_genre, }, - [E_MEDIA_TYPE] = { + [E_GROUP_MEDIA_TYPE] = { .sort_cmp_cb = _compare_cb_type, .media_cmp = _compare_type, .name_get = _get_type, @@ -480,7 +480,7 @@ static void _destroy(void *handle) free(md); } -static Eina_List *_get_list(void *handle) +static Eina_List *_get_list(void *handle, int type, void *data) { struct mediadata *md; @@ -503,7 +503,7 @@ static int _get_count(void *handle, int type) return -1; } - if (type < 0 || type >= E_MEDIA_MAX) { + if (type < 0 || type >= E_FILE_MAX) { _ERR("invalid argument"); return -1; } @@ -544,7 +544,7 @@ static Eina_List *_get_group(void *handle, int type, void *data) return NULL; } - if (type < 0 || type >= E_MEDIA_MAX) { + if (type < 0 || type >= E_GROUP_MEDIA_MAX) { _ERR("invalid argument"); return NULL; } diff --git a/src/grid/grid_gallery.c b/src/grid/grid_gallery.c index 378850f..384ec96 100644 --- a/src/grid/grid_gallery.c +++ b/src/grid/grid_gallery.c @@ -117,7 +117,7 @@ static Eina_List *_get_event_list(struct datamgr *dmgr) return NULL; } - return dmgr->ops->get_group(dmgr->handle, E_MEDIA_DATE, NULL); + return dmgr->ops->get_group(dmgr->handle, E_GROUP_MEDIA_DATE, NULL); } static Eina_List *_get_type_list(struct datamgr *dmgr) @@ -127,7 +127,7 @@ static Eina_List *_get_type_list(struct datamgr *dmgr) return NULL; } - return dmgr->ops->get_group(dmgr->handle, E_MEDIA_TYPE, NULL); + return dmgr->ops->get_group(dmgr->handle, E_GROUP_MEDIA_TYPE, NULL); } static void _free_media_list(struct datamgr *dmgr, Eina_List *list) diff --git a/src/grid/grid_movie.c b/src/grid/grid_movie.c index 6fb7708..b4e09b9 100644 --- a/src/grid/grid_movie.c +++ b/src/grid/grid_movie.c @@ -160,7 +160,7 @@ static Eina_List *_get_name_list(struct datamgr *dmgr) return NULL; } - return dmgr->ops->get_group(dmgr->handle, E_MEDIA_NAME, NULL); + return dmgr->ops->get_group(dmgr->handle, E_GROUP_MEDIA_NAME, NULL); } static Eina_List *_get_genre_list(struct datamgr *dmgr) @@ -180,7 +180,8 @@ static Eina_List *_get_genre_list(struct datamgr *dmgr) } gi->name = STR_GENRE_NAME; - gi->list = dmgr->ops->get_group(dmgr->handle, E_MEDIA_GENRE, NULL); + gi->list = dmgr->ops->get_group(dmgr->handle, + E_GROUP_MEDIA_GENRE, NULL); list = NULL; list = eina_list_append(list, gi); @@ -195,7 +196,7 @@ static Eina_List *_get_date_list(struct datamgr *dmgr) return NULL; } - return dmgr->ops->get_group(dmgr->handle, E_MEDIA_DATE, NULL); + return dmgr->ops->get_group(dmgr->handle, E_GROUP_MEDIA_DATE, NULL); } static void _free_media_list(struct datamgr *dmgr, Eina_List *list) diff --git a/src/grid/grid_music.c b/src/grid/grid_music.c index 7469bef..d25710f 100644 --- a/src/grid/grid_music.c +++ b/src/grid/grid_music.c @@ -217,7 +217,7 @@ static Eina_List *_get_song_list(struct datamgr *dmgr) return NULL; } - return dmgr->ops->get_group(dmgr->handle, E_MEDIA_NAME, NULL); + return dmgr->ops->get_group(dmgr->handle, E_GROUP_MEDIA_NAME, NULL); } static Eina_List *_get_album_list(struct datamgr *dmgr) @@ -227,7 +227,7 @@ static Eina_List *_get_album_list(struct datamgr *dmgr) return NULL; } - return dmgr->ops->get_group(dmgr->handle, E_ALBUM_NAME, NULL); + return dmgr->ops->get_group(dmgr->handle, E_GROUP_ALBUM_NAME, NULL); } static Eina_List *_get_artist_list(struct datamgr *dmgr) @@ -237,7 +237,7 @@ static Eina_List *_get_artist_list(struct datamgr *dmgr) return NULL; } - return dmgr->ops->get_group(dmgr->handle, E_ALBUM_ARTIST, NULL); + return dmgr->ops->get_group(dmgr->handle, E_GROUP_ALBUM_ARTIST, NULL); } static Eina_List *_get_genre_list(struct datamgr *dmgr) @@ -257,7 +257,8 @@ static Eina_List *_get_genre_list(struct datamgr *dmgr) } gi->name = STR_GENRE_NAME; - gi->list = dmgr->ops->get_group(dmgr->handle, E_MEDIA_GENRE, NULL); + gi->list = dmgr->ops->get_group(dmgr->handle, + E_GROUP_MEDIA_GENRE, NULL); list = NULL; list = eina_list_append(list, gi); diff --git a/src/layout/gallery.c b/src/layout/gallery.c index 2d90802..be63e3b 100644 --- a/src/layout/gallery.c +++ b/src/layout/gallery.c @@ -77,7 +77,7 @@ static void _recent_item_selected(struct _priv *priv, app_media *am) if (!dmgr) return; - vdata.list = dmgr->ops->get_list(dmgr->handle); + vdata.list = dmgr->ops->get_list(dmgr->handle, E_LIST_MEDIA, NULL); vdata.index = util_get_media_index_from_id(vdata.list, info->media_id); viewmgr_update_view(VIEW_VIEWER, UPDATE_CONTENT, &vdata); @@ -155,7 +155,8 @@ static void _update_content_list(struct _priv *priv) return; } - priv->gdata->data = dmgr->ops->get_list(dmgr->handle); + priv->gdata->data = dmgr->ops->get_list(dmgr->handle, + E_LIST_MEDIA, NULL); if (!listmgr_update_content_list(priv->listmgr, list, priv->gdata)) _ERR("failed to update list area"); diff --git a/src/layout/movie.c b/src/layout/movie.c index a3b7597..8fbe6d0 100644 --- a/src/layout/movie.c +++ b/src/layout/movie.c @@ -253,7 +253,7 @@ static void _recent_item_selected(struct _priv *priv, app_media *am) if (!dmgr) return; - vdata.list = dmgr->ops->get_list(dmgr->handle); + vdata.list = dmgr->ops->get_list(dmgr->handle, E_LIST_MEDIA, NULL); vdata.index = util_get_media_index_from_id(vdata.list, info->media_id); viewmgr_update_view(VIEW_VIEWER, UPDATE_CONTENT, &vdata); @@ -275,7 +275,7 @@ static void _recent_selected_cb(void *data, Evas_Object *obj) if (!dmgr) return; - vdata.list = dmgr->ops->get_list(dmgr->handle); + vdata.list = dmgr->ops->get_list(dmgr->handle, E_LIST_MEDIA, NULL); vdata.index = util_get_media_index(vdata.list, priv->recent_info); viewmgr_update_view(VIEW_VIEWER, UPDATE_CONTENT, &vdata); @@ -367,7 +367,8 @@ static void _update_content_list(struct _priv *priv) return; } - priv->gdata->data = dmgr->ops->get_list(dmgr->handle); + priv->gdata->data = dmgr->ops->get_list(dmgr->handle, + E_LIST_MEDIA, NULL); if (!listmgr_update_content_list(priv->listmgr, list, priv->gdata)) { _ERR("failed to update list area"); @@ -414,7 +415,7 @@ static void _update_recent_item(struct _priv *priv, const char *id) if (!dmgr) return; - list = dmgr->ops->get_list(dmgr->handle); + list = dmgr->ops->get_list(dmgr->handle, E_LIST_MEDIA, NULL); if (id) am = util_find_media_info(list, id); diff --git a/src/layout/music.c b/src/layout/music.c index d64c317..738f795 100644 --- a/src/layout/music.c +++ b/src/layout/music.c @@ -197,7 +197,7 @@ static void _recent_item_selected(struct _priv *priv, app_media *am) if (!dmgr) return; - vdata.list = dmgr->ops->get_list(dmgr->handle); + vdata.list = dmgr->ops->get_list(dmgr->handle, E_LIST_MEDIA, NULL); vdata.index = util_get_media_index_from_id(vdata.list, info->media_id); viewmgr_update_view(VIEW_MPLAYER, UPDATE_CONTENT, &vdata); @@ -219,7 +219,7 @@ static void _playing_selected_cb(void *data, Evas_Object *obj) if (!dmgr) return; - vdata.list = dmgr->ops->get_list(dmgr->handle); + vdata.list = dmgr->ops->get_list(dmgr->handle, E_LIST_MEDIA, NULL); vdata.index = util_get_media_index(vdata.list, priv->playing_info); viewmgr_update_view(VIEW_MPLAYER, UPDATE_CONTENT, &vdata); @@ -339,7 +339,8 @@ static void _update_content_list(struct _priv *priv) return; } - priv->gdata->data = dmgr->ops->get_list(dmgr->handle); + priv->gdata->data = dmgr->ops->get_list(dmgr->handle, + E_LIST_MEDIA, NULL); if (!listmgr_update_content_list(priv->listmgr, list, priv->gdata)) _ERR("failed to update list area"); @@ -384,7 +385,7 @@ static void _update_playing_item(struct _priv *priv, const char *id) if (!dmgr) return; - list = dmgr->ops->get_list(dmgr->handle); + list = dmgr->ops->get_list(dmgr->handle, E_LIST_MEDIA, NULL); if (id) am = util_find_media_info(list, id); -- 2.7.4