2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <media_info_private.h>
21 int media_album_get_album_count_from_db(filter_h filter, int *album_count)
23 int ret = MEDIA_CONTENT_ERROR_NONE;
25 if (album_count != NULL)
26 ret = _media_db_get_group_count(filter, MEDIA_GROUP_ALBUM, album_count);
28 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
29 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
35 int media_album_foreach_album_from_db(filter_h filter, media_album_cb callback, void *user_data)
37 int ret = MEDIA_CONTENT_ERROR_NONE;
39 if (callback == NULL) {
40 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
41 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
44 ret = _media_db_get_album(filter, callback, user_data);
49 int media_album_get_media_count_from_db(int album_id, filter_h filter, int *media_count)
51 int ret = MEDIA_CONTENT_ERROR_NONE;
53 if ((album_id > 0) && (media_count != NULL))
54 ret = _media_db_get_group_item_count_by_id(album_id, filter, MEDIA_GROUP_ALBUM, media_count);
56 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
57 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
63 int media_album_foreach_media_from_db(int album_id, filter_h filter, media_info_cb callback, void *user_data)
65 int ret = MEDIA_CONTENT_ERROR_NONE;
67 if ((album_id > 0) && (callback != NULL))
68 ret = _media_db_get_group_item_by_id(album_id, filter, callback, user_data, MEDIA_GROUP_ALBUM);
70 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
71 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
77 int media_album_get_album_from_db(int album_id, media_album_h *album)
79 int ret = MEDIA_CONTENT_ERROR_NONE;
80 sqlite3_stmt *stmt = NULL;
81 char select_query[DEFAULT_QUERY_SIZE] = {0, };
83 media_content_retvm_if(album_id <= 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid album_id [%d]", album_id);
84 media_content_retvm_if(album == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid album");
86 memset(select_query, 0x00, sizeof(select_query));
88 snprintf(select_query, sizeof(select_query), SELECT_ALBUM_FROM_ALBUM, album_id);
90 ret = _content_get_result(select_query, &stmt);
91 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
93 if (sqlite3_step(stmt) == SQLITE_ROW) {
94 media_album_s *_album = (media_album_s*)calloc(1, sizeof(media_album_s));
96 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
97 SQLITE3_FINALIZE(stmt);
98 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
101 _album->album_id = album_id;
102 _album->name = g_strdup((const char *)sqlite3_column_text(stmt, 0));
103 _album->artist = g_strdup((const char *)sqlite3_column_text(stmt, 1));
104 _album->album_art_path = g_strdup((const char *)sqlite3_column_text(stmt, 2));
106 *album = (media_album_h)_album;
109 SQLITE3_FINALIZE(stmt);
114 int media_album_destroy(media_album_h album)
116 int ret = MEDIA_CONTENT_ERROR_NONE;
117 media_album_s *_album = (media_album_s*)album;
120 SAFE_FREE(_album->name);
121 SAFE_FREE(_album->artist);
122 SAFE_FREE(_album->album_art_path);
125 ret = MEDIA_CONTENT_ERROR_NONE;
127 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
128 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
134 int media_album_clone(media_album_h *dst, media_album_h src)
136 int ret = MEDIA_CONTENT_ERROR_NONE;
137 media_album_s *_src = (media_album_s*)src;
140 media_album_s *_dst = (media_album_s*)calloc(1, sizeof(media_album_s));
141 media_content_retvm_if(_dst == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
143 _dst->album_id = _src->album_id;
145 if (_src->name != NULL) {
146 _dst->name = g_strdup(_src->name);
147 if (_dst->name == NULL) {
148 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
149 media_album_destroy((media_album_h)_dst);
150 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
154 if (_src->artist != NULL) {
155 _dst->artist = g_strdup(_src->artist);
156 if (_dst->artist == NULL) {
157 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
158 media_album_destroy((media_album_h)_dst);
159 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
163 if (_src->album_art_path != NULL) {
164 _dst->album_art_path = g_strdup(_src->album_art_path);
165 if (_dst->album_art_path == NULL) {
166 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
167 media_album_destroy((media_album_h)_dst);
168 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
172 *dst = (media_album_h)_dst;
174 ret = MEDIA_CONTENT_ERROR_NONE;
176 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
177 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
183 int media_album_get_album_id(media_album_h album, int *album_id)
185 int ret = MEDIA_CONTENT_ERROR_NONE;
186 media_album_s *_album = (media_album_s*)album;
188 if (_album && album_id) {
189 *album_id = _album->album_id;
190 ret = MEDIA_CONTENT_ERROR_NONE;
192 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
193 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
199 int media_album_get_name(media_album_h album, char **name)
201 int ret = MEDIA_CONTENT_ERROR_NONE;
202 media_album_s *_album = (media_album_s*)album;
205 if (_album->name != NULL) {
206 *name = g_strdup(_album->name);
207 media_content_retvm_if(*name == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
212 ret = MEDIA_CONTENT_ERROR_NONE;
214 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
215 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
221 int media_album_get_artist(media_album_h album, char **artist)
223 int ret = MEDIA_CONTENT_ERROR_NONE;
224 media_album_s *_album = (media_album_s*)album;
227 if (_album->artist != NULL) {
228 *artist = g_strdup(_album->artist);
229 media_content_retvm_if(*artist == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
234 ret = MEDIA_CONTENT_ERROR_NONE;
236 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
237 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
243 int media_album_get_album_art(media_album_h album, char **album_art)
245 int ret = MEDIA_CONTENT_ERROR_NONE;
246 media_album_s *_album = (media_album_s*)album;
249 if (_album->album_art_path != NULL) {
250 *album_art = g_strdup(_album->album_art_path);
251 media_content_retvm_if(*album_art == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
256 ret = MEDIA_CONTENT_ERROR_NONE;
258 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
259 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
265 int media_group_get_group_count_from_db(filter_h filter, media_group_e group, int *group_count)
267 int ret = MEDIA_CONTENT_ERROR_NONE;
268 #ifdef _USE_TVPD_MODE
269 if ((group < MEDIA_CONTENT_GROUP_DISPLAY_NAME) || (group >= MEDIA_GROUP_MAX) || (group_count == NULL)) {
271 if ((group < MEDIA_CONTENT_GROUP_DISPLAY_NAME) || (group >= MEDIA_CONTENT_GROUP_MAX) || (group_count == NULL)) {
273 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
274 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
276 ret = _media_db_get_media_group_count(group, filter, group_count);
281 #ifdef _USE_TVPD_MODE
282 int media_group_foreach_group_and_count_from_db(filter_h filter, media_group_e group, media_group_and_count_cb callback, void *user_data)
284 int ret = MEDIA_CONTENT_ERROR_NONE;
286 if ((callback == NULL) || (group < MEDIA_CONTENT_GROUP_DISPLAY_NAME) || (group >= MEDIA_GROUP_MAX)) {
287 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
288 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
290 ret = _media_db_get_media_group_and_count(group, filter, callback, user_data);
297 int media_group_foreach_group_from_db(filter_h filter, media_group_e group, media_group_cb callback, void *user_data)
299 int ret = MEDIA_CONTENT_ERROR_NONE;
300 #ifdef _USE_TVPD_MODE
301 if ((callback == NULL) || (group < MEDIA_CONTENT_GROUP_DISPLAY_NAME) || (group >= MEDIA_GROUP_MAX)) {
303 if ((callback == NULL) || (group < MEDIA_CONTENT_GROUP_DISPLAY_NAME) || (group >= MEDIA_CONTENT_GROUP_MAX)) {
305 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
306 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
308 ret = _media_db_get_media_group(group, filter, callback, user_data);
314 int media_group_get_media_count_from_db(const char *group_name, media_group_e group, filter_h filter, int *media_count)
316 int ret = MEDIA_CONTENT_ERROR_NONE;
317 #ifdef _USE_TVPD_MODE
318 if ((media_count == NULL) || (group < MEDIA_CONTENT_GROUP_DISPLAY_NAME) || (group >= MEDIA_GROUP_MAX)) {
320 if ((media_count == NULL) || (group < MEDIA_CONTENT_GROUP_DISPLAY_NAME) || (group >= MEDIA_CONTENT_GROUP_MAX)) {
322 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
323 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
325 ret = _media_db_get_media_group_item_count(group_name, filter, group, media_count);
331 int media_group_foreach_media_from_db(const char *group_name, media_group_e group, filter_h filter, media_info_cb callback, void *user_data)
333 int ret = MEDIA_CONTENT_ERROR_NONE;
334 #ifdef _USE_TVPD_MODE
335 if ((callback == NULL) || (group < MEDIA_CONTENT_GROUP_DISPLAY_NAME) || (group >= MEDIA_GROUP_MAX)) {
337 if ((callback == NULL) || (group < MEDIA_CONTENT_GROUP_DISPLAY_NAME) || (group >= MEDIA_CONTENT_GROUP_MAX)) {
339 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
340 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
342 ret = _media_db_get_media_group_item(group_name, filter, group, callback, user_data);