#include <media_filter.h>
#include <media_info.h>
#include <media_info_private.h>
-#include <media_playlist.h>
#include <media_util_private.h>
-
-#define PLAYLIST_ARRAY_SIZE 20
-#define PLAYLIST_ARRAY_EXPAND 10
-#define MAX_TMP_STR 2048
-
-static void __media_playlist_item_add(media_playlist_s *playlist, media_playlist_item_s *item_s);
-static void __media_playlist_item_release(media_playlist_s *playlist);
-static int __media_playlist_insert_playlist_record(const char *playlist_name, int *playlist_id);
-static int __media_playlist_insert_item_to_playlist(int playlist_id, const char *media_id);
-static int __media_playlist_remove_item_from_playlist(int playlist_id, int playlist_member_id);
-static int __media_playlist_update_playlist_name(int playlist_id, const char *playlist_name);
-static int __media_playlist_update_thumbnail_path(int playlist_id, const char *path);
-static int __media_playlist_update_play_order(int playlist_id, int playlist_member_id, int play_order);
-static int __media_playlist_reset_file(const char* playlist_path);
-static int __media_playlist_append_to_file(const char* playlist_path, const char* path);
-static int __media_playlist_import_item_from_file(const char* playlist_path, char*** const item_list, int* item_count);
-static int __media_playlist_destroy_import_item(char** item_list, int item_count);
-static void __media_playlist_destroy_export_item(gpointer data);
-
-static void __media_playlist_item_add(media_playlist_s *playlist, media_playlist_item_s *item_s)
+// LCOV_EXCL_START
+static void __media_playlist_item_free(gpointer item)
{
- playlist->item_list = g_list_append(playlist->item_list, item_s);
+ media_playlist_item_s *_item = (media_playlist_item_s *)item;
+
+ g_free(_item->media_id);
+ g_free(_item->playlist_name);
+ g_free(_item->thumbnail_path);
+ g_free(_item);
}
static void __media_playlist_item_release(media_playlist_s *playlist)
{
- int idx = 0;
- int list_cnt = 0;
- media_playlist_item_s *item = NULL;
-
- list_cnt = g_list_length(playlist->item_list);
-
- media_content_debug("list_cnt : [%d]", list_cnt);
-
- for (idx = 0; idx < list_cnt; idx++) {
- item = (media_playlist_item_s*)g_list_nth_data(playlist->item_list, idx);
- if (item != NULL) {
- SAFE_FREE(item->media_id);
- SAFE_FREE(item->playlist_name);
- SAFE_FREE(item->thumbnail_path);
- SAFE_FREE(item);
- }
- }
+ if (!playlist || !playlist->item_list)
+ return;
- g_list_free(playlist->item_list);
+ g_list_free_full(playlist->item_list, __media_playlist_item_free);
playlist->item_list = NULL;
-
}
static int __media_playlist_insert_playlist_record(const char *playlist_name, int *playlist_id)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
- char *query_str = NULL;
- char *select_query = NULL;
+ char *query = NULL;
sqlite3_stmt *stmt = NULL;
- query_str = sqlite3_mprintf(INSERT_PLAYLIST_TO_PLAYLIST, playlist_name);
+ query = sqlite3_mprintf(INSERT_PLAYLIST_TO_PLAYLIST, playlist_name);
- ret = _content_query_sql(query_str);
- SQLITE3_SAFE_FREE(query_str);
- media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
+ ret = _content_query_sql(query);
+ SQLITE3_SAFE_FREE(query);
+ content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
- select_query = sqlite3_mprintf(SELECT_PLAYLIST_ID_FROM_PLAYLIST, playlist_name);
+ query = sqlite3_mprintf(SELECT_PLAYLIST_ID_FROM_PLAYLIST, playlist_name);
- ret = _content_query_prepare(&stmt, select_query, NULL, NULL);
- SQLITE3_SAFE_FREE(select_query);
- media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
+ ret = _content_get_result(query, &stmt);
+ SQLITE3_SAFE_FREE(query);
+ content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
- while (sqlite3_step(stmt) == SQLITE_ROW)
- *playlist_id = (int)sqlite3_column_int(stmt, 0);
+ if (sqlite3_step(stmt) == SQLITE_ROW)
+ *playlist_id = sqlite3_column_int(stmt, 0);
SQLITE3_FINALIZE(stmt);
{
int ret = MEDIA_CONTENT_ERROR_NONE;
sqlite3_stmt *stmt = NULL;
- char select_query[DEFAULT_QUERY_SIZE];
- char *query_str = NULL;
+ char *query = NULL;
int play_order = 0;
- memset(select_query, 0x00, sizeof(select_query));
-
- snprintf(select_query, sizeof(select_query), SELECT_MAX_PLAY_ORDER_FROM_PLAYLIST_VIEW, playlist_id);
+ query = sqlite3_mprintf(SELECT_MAX_PLAY_ORDER_FROM_PLAYLIST_VIEW, playlist_id);
/* get the max play_order */
- ret = _content_query_prepare(&stmt, select_query, NULL, NULL);
- media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
+ ret = _content_get_result(query, &stmt);
+ SQLITE3_SAFE_FREE(query);
+ content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
- while (sqlite3_step(stmt) == SQLITE_ROW)
- play_order = (int)sqlite3_column_int(stmt, 0);
+ if (sqlite3_step(stmt) == SQLITE_ROW)
+ play_order = sqlite3_column_int(stmt, 0);
SQLITE3_FINALIZE(stmt);
- ++play_order;
+ query = sqlite3_mprintf(INSERT_PLAYLIST_ITEM_TO_PLAYLIST_MAP, playlist_id, media_id, ++play_order);
+ ret = media_svc_append_query(query, _content_get_uid());
- query_str = sqlite3_mprintf("INSERT INTO %q (playlist_id, media_uuid, play_order) values (%d, '%q', %d);",
- DB_TABLE_PLAYLIST_MAP, playlist_id, media_id, play_order);
- ret = media_svc_append_query(query_str, tzplatform_getuid(TZ_USER_NAME));
-
- return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
+ return _content_error_capi(ret);
}
static int __media_playlist_remove_item_from_playlist(int playlist_id, int playlist_member_id)
char *query_str = NULL;
query_str = sqlite3_mprintf(REMOVE_PLAYLIST_ITEM_FROM_PLAYLIST_MAP, playlist_id, playlist_member_id);
- ret = media_svc_append_query(query_str, tzplatform_getuid(TZ_USER_NAME));
+ ret = media_svc_append_query(query_str, _content_get_uid());
- return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
+ return _content_error_capi(ret);
}
static int __media_playlist_update_playlist_name(int playlist_id, const char *playlist_name)
char *query_str = NULL;
query_str = sqlite3_mprintf(UPDATE_PLAYLIST_NAME_FROM_PLAYLIST, playlist_name, playlist_id);
- ret = media_svc_append_query(query_str, tzplatform_getuid(TZ_USER_NAME));
+ ret = media_svc_append_query(query_str, _content_get_uid());
- return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
+ return _content_error_capi(ret);
}
static int __media_playlist_update_thumbnail_path(int playlist_id, const char *path)
char *query_str = NULL;
query_str = sqlite3_mprintf(UPDATE_PLAYLIST_THUMBNAIL_FROM_PLAYLIST, path, playlist_id);
- ret = media_svc_append_query(query_str, tzplatform_getuid(TZ_USER_NAME));
+ ret = media_svc_append_query(query_str, _content_get_uid());
- return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
+ return _content_error_capi(ret);
}
static int __media_playlist_update_play_order(int playlist_id, int playlist_member_id, int play_order)
char *query_str = NULL;
query_str = sqlite3_mprintf(UPDATE_PLAYLIST_ORDER_FROM_PLAYLIST_MAP, play_order, playlist_id, playlist_member_id);
- ret = media_svc_append_query(query_str, tzplatform_getuid(TZ_USER_NAME));
-
- return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
-}
-
-static bool __media_playlist_media_info_cb(media_info_h media, void *user_data)
-{
- int ret = MEDIA_CONTENT_ERROR_NONE;
- char **media_id = (char**)user_data;
+ ret = media_svc_append_query(query_str, _content_get_uid());
- ret = media_info_get_media_id(media, media_id);
- media_content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, FALSE, "media_info_get_media_id fail");
-
- return TRUE;
+ return _content_error_capi(ret);
}
static bool __media_playlist_member_cb(int playlist_member_id, media_info_h media, void *user_data)
char *path = NULL;
ret = media_info_get_file_path(media, &path);
- media_content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, FALSE, "media_info_get_file_path fail");
+ content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, FALSE, "media_info_get_file_path fail");
*list = g_list_append(*list, path);
return TRUE;
}
-static int __media_playlist_reset_file(const char* playlist_path)
+static int __media_playlist_reset_file(const char *playlist_path)
{
FILE *fp = NULL;
fp = fopen(playlist_path, "wb");
- media_content_retvm_if(fp == NULL, MEDIA_CONTENT_ERROR_INVALID_OPERATION, "fopen fail");
+ if (fp == NULL) {
+ content_stderror("fopen failed");
+ return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
+ }
fputs("", fp); /* remove previous playlist */
return MEDIA_CONTENT_ERROR_NONE;
}
-static int __media_playlist_append_to_file(const char* playlist_path, const char* path)
+static int __media_playlist_append_to_file(const char *playlist_path, const char *path)
{
FILE *fp = NULL;
fp = fopen(playlist_path, "a"); /* append only */
- media_content_retvm_if(fp == NULL, MEDIA_CONTENT_ERROR_INVALID_OPERATION, "fopen fail");
+ if (fp == NULL) {
+ content_stderror("fopen failed");
+ return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
+ }
- fputs(path, fp);
+ fputs(path, fp);
fputs("\n", fp);
fclose(fp);
return MEDIA_CONTENT_ERROR_NONE;
}
-static int __media_playlist_import_item_from_file(const char* playlist_path, char*** const item_list, int* item_count)
+static int __media_playlist_import_item_from_file(const char *playlist_path, GSList **item_list)
{
- int current_index = 0;
- int current_max_size = PLAYLIST_ARRAY_SIZE;
int tmp_str_len = 0;
- char *tmp_buf = NULL;
- char tmp_str[MAX_QUERY_SIZE] = {0, };
- char repl_item[MAX_QUERY_SIZE] = {0, };
+ char tmp_str[MAX_PATH_LEN] = {0, };
FILE *fp = NULL;
- long int file_size = 0;
-
- *item_list = NULL; *item_count = 0;
fp = fopen(playlist_path, "rb");
- media_content_retvm_if(fp == NULL, MEDIA_CONTENT_ERROR_INVALID_OPERATION, "fopen fail");
-
- fseek(fp, 0, SEEK_END);
- file_size = ftell(fp);
- fseek(fp, 0 , SEEK_SET);
-
- if (file_size == 0) {
- media_content_debug("file is empty.");
- fclose(fp);
- return MEDIA_CONTENT_ERROR_NONE;
- }
-
- *item_list = calloc(current_max_size, sizeof(char*));
- if (*item_list == NULL) {
- fclose(fp);
- SAFE_FREE(*item_list);
- media_content_error("Out of Memory");
- return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
+ if (fp == NULL) {
+ content_stderror("fopen failed");
+ return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
}
- memset(tmp_str, 0, sizeof(MAX_QUERY_SIZE));
-
- while (fgets(tmp_str, MAX_QUERY_SIZE, fp) != NULL) {
- memset(repl_item, 0, sizeof(repl_item));
- _media_content_replace_path(tmp_str, repl_item);
- tmp_str_len = strlen(repl_item);
- if (tmp_str_len > 0 && repl_item[tmp_str_len - 1] == '\n')
- repl_item[tmp_str_len - 1] = '\0';
-
- tmp_str_len = strlen(repl_item);
-
- if (tmp_str_len > 0 && repl_item[0] != '#') {
- if (!(current_index < (current_max_size - 1))) {
- current_max_size += PLAYLIST_ARRAY_EXPAND;
- char **tmp_ptr = calloc(current_max_size, sizeof(char*));
- if (tmp_ptr == NULL) {
- __media_playlist_destroy_import_item(*item_list, current_index);
- media_content_error("Out of Memory");
- fclose(fp);
- return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
- }
- memmove(tmp_ptr, *item_list, sizeof(char*) * current_index);
- SAFE_FREE(*item_list);
- *item_list = tmp_ptr;
- }
-
- (*item_list)[current_index] = malloc(tmp_str_len + 1);
- if ((*item_list)[current_index] == NULL) {
- __media_playlist_destroy_import_item(*item_list, current_index);
- media_content_error("Out of Memory");
- fclose(fp);
- return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
- }
- memset((*item_list)[current_index], 0, tmp_str_len + 1);
- memmove((*item_list)[current_index], repl_item, tmp_str_len);
-
- current_index += 1;
- }
- tmp_buf += (tmp_str_len);
- }
+ while (fgets(tmp_str, MAX_PATH_LEN, fp) != NULL) {
+ tmp_str_len = strlen(tmp_str);
+ /* Check for empty file */
+ if (tmp_str_len <= 1)
+ continue;
- *item_count = current_index;
- fclose(fp);
+ if (tmp_str[0] == '#')
+ continue;
- return MEDIA_CONTENT_ERROR_NONE;
-}
-static int __media_playlist_destroy_import_item(char** item_list, int item_count)
-{
- int i = 0;
+ if (tmp_str[tmp_str_len - 1] == '\n')
+ tmp_str[tmp_str_len - 1] = '\0';
- for (i = 0; i < item_count; ++i) {
- SAFE_FREE(item_list[i]);
- item_list[i] = NULL;
+ *item_list = g_slist_append(*item_list, g_strdup(tmp_str));
}
- if (item_list != NULL) {
- SAFE_FREE(item_list);
- item_list = NULL;
- }
+ fclose(fp);
return MEDIA_CONTENT_ERROR_NONE;
}
-static void __media_playlist_destroy_export_item(gpointer data)
-{
- SAFE_FREE(data);
- data = NULL;
-}
-
int media_playlist_insert_to_db(const char *name, media_playlist_h *playlist)
{
+ content_warn("DEPRECATION WARNING: media_playlist_insert_to_db() is deprecated and will be removed from next release.");
int ret = MEDIA_CONTENT_ERROR_NONE;
int playlist_id = 0;
- if (!STRING_VALID(name)) {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
+ content_retip_if_fail(STRING_VALID(name));
+ content_retip_if_fail(playlist);
- media_playlist_s *_playlist = (media_playlist_s*)calloc(1, sizeof(media_playlist_s));
- media_content_retvm_if(_playlist == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
+ media_playlist_s *_playlist = g_new0(media_playlist_s, 1);
ret = __media_playlist_insert_playlist_record(name, &playlist_id);
-
if (ret != MEDIA_CONTENT_ERROR_NONE) {
- SAFE_FREE(_playlist);
+ g_free(_playlist);
return ret;
}
_playlist->playlist_id = playlist_id;
- _playlist->name = strdup(name);
-
- if (_playlist->name == NULL) {
- SAFE_FREE(_playlist);
- media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
- return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
- }
+ _playlist->name = g_strdup(name);
*playlist = (media_playlist_h)_playlist;
int media_playlist_delete_from_db(int playlist_id)
{
+ content_warn("DEPRECATION WARNING: media_playlist_delete_from_db() is deprecated and will be removed from next release.");
int ret = MEDIA_CONTENT_ERROR_NONE;
char *query_str = NULL;
- if (playlist_id < 0) {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
+ content_retipm_if_fail(playlist_id >= 0, "%d", playlist_id);
query_str = sqlite3_mprintf(DELETE_PLAYLIST_FROM_PLAYLIST, playlist_id);
ret = _content_query_sql(query_str);
-
SQLITE3_SAFE_FREE(query_str);
return ret;
int media_playlist_get_playlist_count_from_db(filter_h filter, int *playlist_count)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
-
- if (playlist_count != NULL) {
- ret = _media_db_get_group_count(filter, MEDIA_GROUP_PLAYLIST, playlist_count);
- } else {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
+ content_warn("DEPRECATION WARNING: media_playlist_get_playlist_count_from_db() is deprecated and will be removed from next release.");
+ content_retip_if_fail(playlist_count);
- return ret;
+ return _media_db_get_group_count(filter, MEDIA_GROUP_PLAYLIST, playlist_count);
}
int media_playlist_foreach_playlist_from_db(filter_h filter, media_playlist_cb callback, void *user_data)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
-
- if (callback == NULL) {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
-
- ret = _media_db_get_playlist(filter, callback, user_data);
+ content_warn("DEPRECATION WARNING: media_playlist_foreach_playlist_from_db() is deprecated and will be removed from next release.");
+ content_retip_if_fail(callback);
- return ret;
+ return _media_db_get_playlist(filter, callback, user_data);
}
int media_playlist_get_media_count_from_db(int playlist_id, filter_h filter, int *media_count)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
-
- if ((playlist_id > 0) && (media_count != NULL)) {
- ret = _media_db_get_group_item_count_by_id(playlist_id, filter, MEDIA_GROUP_PLAYLIST, media_count);
- } else {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
+ content_warn("DEPRECATION WARNING: media_playlist_get_media_count_from_db() is deprecated and will be removed from next release.");
+ content_retip_if_fail(media_count);
+ content_retipm_if_fail(playlist_id > 0, "%d", playlist_id);
- return ret;
+ return _media_db_get_group_item_count_by_id(playlist_id, filter, MEDIA_GROUP_PLAYLIST, media_count);
}
int media_playlist_foreach_media_from_db(int playlist_id, filter_h filter, playlist_member_cb callback, void *user_data)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
-
- if ((playlist_id > 0) && (callback != NULL)) {
- ret = _media_db_get_playlist_item(playlist_id, filter, callback, user_data);
- } else {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
+ content_warn("DEPRECATION WARNING: media_playlist_foreach_media_from_db() is deprecated and will be removed from next release.");
+ content_retip_if_fail(callback);
+ content_retipm_if_fail(playlist_id > 0, "%d", playlist_id);
- return ret;
+ return _media_db_get_playlist_item(playlist_id, filter, callback, user_data);
}
int media_playlist_destroy(media_playlist_h playlist)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
- media_playlist_s *_playlist = (media_playlist_s*)playlist;
+ content_warn("DEPRECATION WARNING: media_playlist_destroy() is deprecated and will be removed from next release.");
+ media_playlist_s *_playlist = (media_playlist_s *)playlist;
- if (_playlist) {
- SAFE_FREE(_playlist->name);
- SAFE_FREE(_playlist->thumbnail_path);
- SAFE_FREE(_playlist);
+ content_retip_if_fail(playlist);
- ret = MEDIA_CONTENT_ERROR_NONE;
- } else {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
+ __media_playlist_item_release(_playlist);
- return ret;
+ g_free(_playlist->name);
+ g_free(_playlist->thumbnail_path);
+ g_free(_playlist);
+
+ return MEDIA_CONTENT_ERROR_NONE;
}
int media_playlist_clone(media_playlist_h *dst, media_playlist_h src)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
- media_playlist_s *_src = (media_playlist_s*)src;
+ content_warn("DEPRECATION WARNING: media_playlist_clone() is deprecated and will be removed from next release.");
+ media_playlist_s *_src = (media_playlist_s *)src;
- if (_src != NULL) {
- media_playlist_s *_dst = (media_playlist_s*)calloc(1, sizeof(media_playlist_s));
- media_content_retvm_if(_dst == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
+ content_retip_if_fail(dst);
+ content_retip_if_fail(src);
- _dst->playlist_id = _src->playlist_id;
-
- if (STRING_VALID(_src->name)) {
- _dst->name = strdup(_src->name);
- if (_dst->name == NULL) {
- media_playlist_destroy((media_playlist_h)_dst);
- media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
- return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
- }
- }
+ media_playlist_s *_dst = g_new0(media_playlist_s, 1);
- *dst = (media_playlist_h)_dst;
+ _dst->playlist_id = _src->playlist_id;
+ _dst->name = g_strdup(_src->name);
- ret = MEDIA_CONTENT_ERROR_NONE;
- } else {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
+ *dst = (media_playlist_h)_dst;
- return ret;
+ return MEDIA_CONTENT_ERROR_NONE;
}
int media_playlist_get_playlist_from_db(int playlist_id, media_playlist_h *playlist)
{
+ content_warn("DEPRECATION WARNING: media_playlist_get_playlist_from_db() is deprecated and will be removed from next release.");
int ret = MEDIA_CONTENT_ERROR_NONE;
sqlite3_stmt *stmt = NULL;
- char select_query[DEFAULT_QUERY_SIZE];
-
- if (playlist_id > 0) {
- memset(select_query, 0x00, sizeof(select_query));
+ char *query = NULL;
- snprintf(select_query, sizeof(select_query), SELECT_PLAYLIST_FROM_PLAYLIST, playlist_id);
+ content_retipm_if_fail(playlist_id > 0, "%d", playlist_id);
+ content_retip_if_fail(playlist);
- ret = _content_query_prepare(&stmt, select_query, NULL, NULL);
- media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
+ query = sqlite3_mprintf(SELECT_PLAYLIST_FROM_PLAYLIST, playlist_id);
- media_playlist_s *_playlist = NULL;
+ ret = _content_get_result(query, &stmt);
+ SQLITE3_SAFE_FREE(query);
+ content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
- while (sqlite3_step(stmt) == SQLITE_ROW) {
- if (_playlist)
- media_playlist_destroy((media_playlist_h)_playlist);
+ media_playlist_s *_playlist = NULL;
- _playlist = (media_playlist_s*)calloc(1, sizeof(media_playlist_s));
- if (_playlist == NULL) {
- media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
- SQLITE3_FINALIZE(stmt);
- return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
- }
+ if (sqlite3_step(stmt) == SQLITE_ROW) {
+ _playlist = g_new0(media_playlist_s, 1);
- _playlist->playlist_id = (int)sqlite3_column_int(stmt, 0);
- _playlist->name = g_strdup((const char *)sqlite3_column_text(stmt, 1));
- _playlist->thumbnail_path = g_strdup((const char *)sqlite3_column_text(stmt, 3));
-
- *playlist = (media_playlist_h)_playlist;
- }
+ _playlist->playlist_id = playlist_id;
+ _playlist->name = g_strdup((const char *)sqlite3_column_text(stmt, 0));
+ _playlist->thumbnail_path = g_strdup((const char *)sqlite3_column_text(stmt, 1));
- SQLITE3_FINALIZE(stmt);
+ *playlist = (media_playlist_h)_playlist;
} else {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
+ content_error("Nonexistent playlist id[%d]", playlist_id);
ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
}
+ SQLITE3_FINALIZE(stmt);
+
return ret;
}
int media_playlist_get_playlist_id(media_playlist_h playlist, int *playlist_id)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
+ content_warn("DEPRECATION WARNING: media_playlist_get_playlist_id() is deprecated and will be removed from next release.");
+ media_playlist_s *_playlist = (media_playlist_s *)playlist;
- media_playlist_s *_playlist = (media_playlist_s*)playlist;
+ content_retip_if_fail(playlist);
+ content_retip_if_fail(playlist_id);
- if ((_playlist != NULL) && (playlist_id != NULL)) {
- *playlist_id = _playlist->playlist_id;
- } else {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
+ *playlist_id = _playlist->playlist_id;
- return ret;
+ return MEDIA_CONTENT_ERROR_NONE;
}
int media_playlist_get_name(media_playlist_h playlist, char **name)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
- media_playlist_s *_playlist = (media_playlist_s*)playlist;
- if (_playlist) {
- if (STRING_VALID(_playlist->name)) {
- *name = strdup(_playlist->name);
- media_content_retvm_if(*name == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
- } else {
- *name = NULL;
- }
+ content_warn("DEPRECATION WARNING: media_playlist_get_name() is deprecated and will be removed from next release.");
+ media_playlist_s *_playlist = (media_playlist_s *)playlist;
- ret = MEDIA_CONTENT_ERROR_NONE;
- } else {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
+ content_retip_if_fail(playlist);
+ content_retip_if_fail(name);
- return ret;
+ *name = g_strdup(_playlist->name);
+
+ return MEDIA_CONTENT_ERROR_NONE;
}
int media_playlist_get_thumbnail_path(media_playlist_h playlist, char **path)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
- media_playlist_s *_playlist = (media_playlist_s*)playlist;
- if (_playlist) {
- if (STRING_VALID(_playlist->thumbnail_path)) {
- *path = strdup(_playlist->thumbnail_path);
- media_content_retvm_if(*path == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
- } else {
- *path = NULL;
- }
+ content_warn("DEPRECATION WARNING: media_playlist_get_thumbnail_path() is deprecated and will be removed from next release.");
+ media_playlist_s *_playlist = (media_playlist_s *)playlist;
- ret = MEDIA_CONTENT_ERROR_NONE;
- } else {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
+ content_retip_if_fail(playlist);
+ content_retip_if_fail(path);
- return ret;
+ *path = g_strdup(_playlist->thumbnail_path);
+
+ return MEDIA_CONTENT_ERROR_NONE;
}
int media_playlist_get_play_order(media_playlist_h playlist, int playlist_member_id, int *play_order)
{
+ content_warn("DEPRECATION WARNING: media_playlist_get_play_order() is deprecated and will be removed from next release.");
int ret = MEDIA_CONTENT_ERROR_NONE;
- media_playlist_s *_playlist = (media_playlist_s*)playlist;
- int playlist_id = 0;
+ media_playlist_s *_playlist = (media_playlist_s *)playlist;
sqlite3_stmt *stmt = NULL;
- char select_query[DEFAULT_QUERY_SIZE];
-
- if ((_playlist == NULL) || (playlist_member_id < 0) || (play_order == NULL)) {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
-
- playlist_id = _playlist->playlist_id;
+ char *query = NULL;
- memset(select_query, 0x00, sizeof(select_query));
+ content_retip_if_fail(playlist);
+ content_retipm_if_fail(playlist_member_id >= 0, "%d", playlist_member_id);
+ content_retip_if_fail(play_order);
- snprintf(select_query, sizeof(select_query), SELECT_PLAY_ORDER_FROM_PLAYLIST_VIEW, playlist_id, playlist_member_id);
+ query = sqlite3_mprintf(SELECT_PLAY_ORDER_FROM_PLAYLIST_VIEW, _playlist->playlist_id, playlist_member_id);
+ ret = _content_get_result(query, &stmt);
+ SQLITE3_SAFE_FREE(query);
+ content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
- ret = _content_query_prepare(&stmt, select_query, NULL, NULL);
- media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
-
- while (sqlite3_step(stmt) == SQLITE_ROW)
- *play_order = (int)sqlite3_column_int(stmt, 0);
+ if (sqlite3_step(stmt) == SQLITE_ROW)
+ *play_order = sqlite3_column_int(stmt, 0);
SQLITE3_FINALIZE(stmt);
int media_playlist_set_name(media_playlist_h playlist, const char *playlist_name)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
- media_playlist_s *_playlist = (media_playlist_s*)playlist;
+ content_warn("DEPRECATION WARNING: media_playlist_set_name() is deprecated and will be removed from next release.");
+ media_playlist_s *_playlist = (media_playlist_s *)playlist;
+ media_playlist_item_s *item = NULL;
- if (_playlist != NULL && STRING_VALID(playlist_name)) {
- SAFE_FREE(_playlist->name);
+ content_retip_if_fail(playlist);
+ content_retip_if_fail(STRING_VALID(playlist_name));
- media_playlist_item_s *item = (media_playlist_item_s*)calloc(1, sizeof(media_playlist_item_s));
- media_content_retvm_if(item == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
+ g_free(_playlist->name);
- item->playlist_name = strdup(playlist_name);
- item->function = MEDIA_PLAYLIST_UPDATE_PLAYLIST_NAME;
- if (item->playlist_name == NULL) {
- SAFE_FREE(item);
- media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
- return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
- }
+ item = g_new0(media_playlist_item_s, 1);
- _playlist->name = strdup(playlist_name);
- if (_playlist->name == NULL) {
- SAFE_FREE(item->playlist_name);
- SAFE_FREE(item);
- media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
- return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
- }
+ item->playlist_name = g_strdup(playlist_name);
+ item->function = MEDIA_PLAYLIST_UPDATE_PLAYLIST_NAME;
- __media_playlist_item_add(_playlist, item);
- } else {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
+ _playlist->name = g_strdup(playlist_name);
+ _playlist->item_list = g_list_append(_playlist->item_list, item);
- return ret;
+ return MEDIA_CONTENT_ERROR_NONE;
}
int media_playlist_set_thumbnail_path(media_playlist_h playlist, const char *path)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
- media_playlist_s *_playlist = (media_playlist_s*)playlist;
+ content_warn("DEPRECATION WARNING: media_playlist_set_thumbnail_path() is deprecated and will be removed from next release.");
+ media_playlist_s *_playlist = (media_playlist_s *)playlist;
+ media_playlist_item_s *item = NULL;
- if (_playlist != NULL && STRING_VALID(path)) {
- SAFE_FREE(_playlist->thumbnail_path);
+ content_retip_if_fail(playlist);
+ content_retip_if_fail(STRING_VALID(path));
- media_playlist_item_s *item = (media_playlist_item_s*)calloc(1, sizeof(media_playlist_item_s));
- media_content_retvm_if(item == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
+ g_free(_playlist->thumbnail_path);
- item->thumbnail_path = g_strdup(path);
- item->function = MEDIA_PLAYLIST_UPDATE_THUMBNAIL_PATH;
- if (item->thumbnail_path == NULL) {
- SAFE_FREE(item);
- media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
- return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
- }
+ item = g_new0(media_playlist_item_s, 1);
- _playlist->thumbnail_path = strdup(path);
- if (_playlist->thumbnail_path == NULL) {
- SAFE_FREE(item->thumbnail_path);
- SAFE_FREE(item);
- media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
- return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
- }
+ item->thumbnail_path = g_strdup(path);
+ item->function = MEDIA_PLAYLIST_UPDATE_THUMBNAIL_PATH;
- __media_playlist_item_add(_playlist, item);
- } else {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
+ _playlist->thumbnail_path = g_strdup(path);
+ _playlist->item_list = g_list_append(_playlist->item_list, item);
- return ret;
+ return MEDIA_CONTENT_ERROR_NONE;
}
int media_playlist_set_play_order(media_playlist_h playlist, int playlist_member_id, int play_order)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
- media_playlist_s *_playlist = (media_playlist_s*)playlist;
+ content_warn("DEPRECATION WARNING: media_playlist_set_play_order() is deprecated and will be removed from next release.");
+ media_playlist_s *_playlist = (media_playlist_s *)playlist;
+ media_playlist_item_s *item = NULL;
- if ((_playlist != NULL) && (playlist_member_id > 0) && (play_order >= 0)) {
- media_playlist_item_s *item = (media_playlist_item_s*)calloc(1, sizeof(media_playlist_item_s));
- media_content_retvm_if(item == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
+ content_retip_if_fail(playlist);
+ content_retipm_if_fail(playlist_member_id > 0, "%d", playlist_member_id);
+ content_retipm_if_fail(play_order >= 0, "%d", play_order);
- item->playlist_member_id = playlist_member_id;
- item->function = MEDIA_PLAYLIST_UPDATE_PLAY_ORDER;
- item->play_order = play_order;
+ item = g_new0(media_playlist_item_s, 1);
- __media_playlist_item_add(_playlist, item);
- } else {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
+ item->playlist_member_id = playlist_member_id;
+ item->function = MEDIA_PLAYLIST_UPDATE_PLAY_ORDER;
+ item->play_order = play_order;
- return ret;
+ _playlist->item_list = g_list_append(_playlist->item_list, item);
+
+ return MEDIA_CONTENT_ERROR_NONE;
}
int media_playlist_add_media(media_playlist_h playlist, const char *media_id)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
- media_playlist_s *_playlist = (media_playlist_s*)playlist;
+ content_warn("DEPRECATION WARNING: media_playlist_add_media() is deprecated and will be removed from next release.");
+ media_playlist_s *_playlist = (media_playlist_s *)playlist;
+ media_playlist_item_s *item = NULL;
- if (_playlist != NULL && STRING_VALID(media_id)) {
- media_playlist_item_s *item = (media_playlist_item_s*)calloc(1, sizeof(media_playlist_item_s));
- media_content_retvm_if(item == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
+ content_retip_if_fail(playlist);
+ content_retip_if_fail(STRING_VALID(media_id));
- item->media_id = strdup(media_id);
- item->function = MEDIA_PLAYLIST_ADD;
+ item = g_new0(media_playlist_item_s, 1);
- if (item->media_id == NULL) {
- SAFE_FREE(item);
- media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
- return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
- }
+ item->media_id = g_strdup(media_id);
+ item->function = MEDIA_PLAYLIST_ADD;
- __media_playlist_item_add(_playlist, item);
- } else {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
+ _playlist->item_list = g_list_append(_playlist->item_list, item);
- return ret;
+ return MEDIA_CONTENT_ERROR_NONE;
}
-
int media_playlist_remove_media(media_playlist_h playlist, int playlist_member_id)
{
+ content_warn("DEPRECATION WARNING: media_playlist_remove_media() is deprecated and will be removed from next release.");
+ media_playlist_s *_playlist = (media_playlist_s *)playlist;
+ media_playlist_item_s *item = NULL;
+
+ content_retip_if_fail(playlist);
+ content_retipm_if_fail(playlist_member_id > 0, "%d", playlist_member_id);
+
+ item = g_new0(media_playlist_item_s, 1);
+
+ item->playlist_member_id = playlist_member_id;
+ item->function = MEDIA_PLAYLIST_REMOVE;
+
+ _playlist->item_list = g_list_append(_playlist->item_list, item);
+
+ return MEDIA_CONTENT_ERROR_NONE;
+}
+
+void __media_playlist_foreach_request(gpointer data, gpointer user_data)
+{
int ret = MEDIA_CONTENT_ERROR_NONE;
- media_playlist_s *_playlist = (media_playlist_s*)playlist;
+ media_playlist_item_s *_playlist_item = (media_playlist_item_s *)data;
+ int playlist_id = *((int *)user_data);
- if ((_playlist != NULL) && (playlist_member_id > 0)) {
- media_playlist_item_s *item = (media_playlist_item_s*)calloc(1, sizeof(media_playlist_item_s));
- media_content_retvm_if(item == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
+ if (!_playlist_item)
+ return;
- item->playlist_member_id = playlist_member_id;
- item->function = MEDIA_PLAYLIST_REMOVE;
+ switch (_playlist_item->function) {
+ case MEDIA_PLAYLIST_ADD:
+ ret = __media_playlist_insert_item_to_playlist(playlist_id, _playlist_item->media_id);
+ break;
- __media_playlist_item_add(_playlist, item);
- } else {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
+ case MEDIA_PLAYLIST_REMOVE:
+ ret = __media_playlist_remove_item_from_playlist(playlist_id, _playlist_item->playlist_member_id);
+ break;
+
+ case MEDIA_PLAYLIST_UPDATE_PLAYLIST_NAME:
+ ret = __media_playlist_update_playlist_name(playlist_id, _playlist_item->playlist_name);
+ break;
+
+ case MEDIA_PLAYLIST_UPDATE_THUMBNAIL_PATH:
+ ret = __media_playlist_update_thumbnail_path(playlist_id, _playlist_item->thumbnail_path);
+ break;
+
+ case MEDIA_PLAYLIST_UPDATE_PLAY_ORDER:
+ ret = __media_playlist_update_play_order(playlist_id, _playlist_item->playlist_member_id, _playlist_item->play_order);
+ break;
+
+ default:
+ break;
}
- return ret;
+ if (ret != MEDIA_CONTENT_ERROR_NONE)
+ content_error("Failed some operation[%d]", _playlist_item->function);
}
int media_playlist_update_to_db(media_playlist_h playlist)
{
+ content_warn("DEPRECATION WARNING: media_playlist_update_to_db() is deprecated and will be removed from next release.");
int ret = MEDIA_CONTENT_ERROR_NONE;
- media_playlist_s *_playlist = (media_playlist_s*)playlist;
- int idx = 0;
- int length = 0;
- media_playlist_item_s *_playlist_item = NULL;
-
- if (_playlist == NULL) {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
+ media_playlist_s *_playlist = (media_playlist_s *)playlist;
- if (_playlist->item_list != NULL) {
- length = g_list_length(_playlist->item_list);
- } else {
- media_content_debug("operation list length is 0");
- return MEDIA_CONTENT_ERROR_NONE;
- }
+ content_retip_if_fail(playlist);
+ content_retvm_if(!_playlist->item_list, MEDIA_CONTENT_ERROR_NONE, "operation list length is 0");
- for (idx = 0; idx < length; idx++) {
- _playlist_item = (media_playlist_item_s*)g_list_nth_data(_playlist->item_list, idx);
- if (_playlist_item != NULL) {
- switch (_playlist_item->function) {
- case MEDIA_PLAYLIST_ADD:
- {
- ret = __media_playlist_insert_item_to_playlist(_playlist->playlist_id, _playlist_item->media_id);
- }
- break;
-
- case MEDIA_PLAYLIST_REMOVE:
- {
- ret = __media_playlist_remove_item_from_playlist(_playlist->playlist_id, _playlist_item->playlist_member_id);
- }
- break;
-
- case MEDIA_PLAYLIST_UPDATE_PLAYLIST_NAME:
- {
- ret = __media_playlist_update_playlist_name(_playlist->playlist_id, _playlist_item->playlist_name);
- }
- break;
-
- case MEDIA_PLAYLIST_UPDATE_THUMBNAIL_PATH:
- {
- ret = __media_playlist_update_thumbnail_path(_playlist->playlist_id, _playlist_item->thumbnail_path);
- }
- break;
-
- case MEDIA_PLAYLIST_UPDATE_PLAY_ORDER:
- {
- ret = __media_playlist_update_play_order(_playlist->playlist_id, _playlist_item->playlist_member_id, _playlist_item->play_order);
- }
- break;
-
- default:
- break;
- }
- }
- }
- ret = media_svc_send_query(tzplatform_getuid(TZ_USER_NAME));
+ g_list_foreach(_playlist->item_list, __media_playlist_foreach_request, &(_playlist->playlist_id));
+
+ ret = media_svc_send_query(_content_get_uid());
__media_playlist_item_release(_playlist);
- return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
+ return _content_error_capi(ret);
}
-int media_playlist_import_from_file(const char *path, const char *playlist_name, media_playlist_h *playlist)
+static int __media_playlist_get_media_id_by_path(const char *path, char **media_id)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
- char** import_item_list = NULL;
- int import_item_count = 0;
- int idx;
- char repl_path[MAX_QUERY_SIZE] = {0, };
+ char *query = NULL;
+ sqlite3_stmt *stmt = NULL;
- media_content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
- media_content_retvm_if(!STRING_VALID(playlist_name), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid playlist_name");
- memset(repl_path, 0, sizeof(repl_path));
- ret = _media_content_replace_path(path, repl_path);
- media_content_retvm_if(!STRING_VALID(repl_path), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed");
+ content_retip_if_fail(path);
+ content_retip_if_fail(media_id);
- ret = media_playlist_insert_to_db(playlist_name, playlist);
- media_content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "media_playlist_insert_to_db fail");
+#ifdef _USE_TVPD_MODE
+ query = sqlite3_mprintf("SELECT media_id FROM '%q' WHERE media_path='%q'", DB_VIEW_MEDIA, path);
+#else
+ query = sqlite3_mprintf("SELECT media_id FROM '%q' WHERE media_path='%q'", DB_TABLE_MEDIA, path);
+#endif
+ ret = _content_get_result(query, &stmt);
+ SQLITE3_SAFE_FREE(query);
+ content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "Failed to get media_id");
- ret = __media_playlist_import_item_from_file(repl_path, &import_item_list, &import_item_count);
- if (ret != MEDIA_CONTENT_ERROR_NONE) {
- __media_playlist_destroy_import_item(import_item_list, import_item_count);
- media_content_error("Fail to get playlist from file");
- return ret;
- }
+ if (sqlite3_step(stmt) == SQLITE_ROW)
+ *media_id = g_strdup((const char *)sqlite3_column_text(stmt, 0));
- if (import_item_count == 0)
- media_content_debug("The playlist from file is empty");
+ SQLITE3_FINALIZE(stmt);
- for (idx = 0; idx < import_item_count; idx++) {
- filter_h filter = NULL;
- char *media_id = NULL;
- char *condition = NULL;
+ return ret;
+}
- ret = media_filter_create(&filter);
- if (ret != MEDIA_CONTENT_ERROR_NONE) {
- __media_playlist_destroy_import_item(import_item_list, import_item_count);
- media_filter_destroy(filter);
- media_content_error("error media_filter_create");
- return ret;
- }
- condition = sqlite3_mprintf("path = '%q'", import_item_list[idx]);
- ret = media_filter_set_condition(filter, condition, MEDIA_CONTENT_COLLATE_DEFAULT);
- if (ret != MEDIA_CONTENT_ERROR_NONE) {
- __media_playlist_destroy_import_item(import_item_list, import_item_count);
- media_filter_destroy(filter);
- SQLITE3_SAFE_FREE(condition);
- media_content_error("error media_filter_set_condition");
- return ret;
- }
- ret = _media_db_get_group_item(NULL, filter, __media_playlist_media_info_cb, &media_id, MEDIA_GROUP_NONE);
- if (ret != MEDIA_CONTENT_ERROR_NONE) {
- __media_playlist_destroy_import_item(import_item_list, import_item_count);
- media_filter_destroy(filter);
- SAFE_FREE(media_id);
- SQLITE3_SAFE_FREE(condition);
- media_content_error("error media_info_foreach_media_from_db");
- return ret;
- }
- ret = media_playlist_add_media((media_playlist_h)*playlist, media_id);
- if (ret != MEDIA_CONTENT_ERROR_NONE) {
- __media_playlist_destroy_import_item(import_item_list, import_item_count);
- media_filter_destroy(filter);
- SAFE_FREE(media_id);
- SQLITE3_SAFE_FREE(condition);
- media_content_error("error media_playlist_add_media");
- return ret;
- }
- media_filter_destroy(filter);
- SAFE_FREE(media_id);
- SQLITE3_SAFE_FREE(condition);
+static void __media_playlist_foreach_item(gpointer item, gpointer user_data)
+{
+ int ret = MEDIA_CONTENT_ERROR_NONE;
+ char *path = (char *)item;
+ media_playlist_h *playlist = (media_playlist_h *)user_data;
+ char *media_id = NULL;
+
+ ret = __media_playlist_get_media_id_by_path(path, &media_id);
+ if (ret != MEDIA_CONTENT_ERROR_NONE) {
+ content_sec_error("Fail to get media_id [%s]", path);
+ return;
}
- ret = media_playlist_update_to_db(*playlist);
+ ret = media_playlist_add_media(*playlist, media_id);
+ g_free(media_id);
if (ret != MEDIA_CONTENT_ERROR_NONE) {
- __media_playlist_destroy_import_item(import_item_list, import_item_count);
- media_content_error("Fail to update playlist to db");
- return ret;
+ content_sec_error("Fail to add media [%s]", path);
+ return;
}
- __media_playlist_destroy_import_item(import_item_list, import_item_count);
+}
+
+int media_playlist_import_from_file(const char *path, const char *playlist_name, media_playlist_h *playlist)
+{
+ content_warn("DEPRECATION WARNING: media_playlist_import_from_file() is deprecated and will be removed from next release.");
+ int ret = MEDIA_CONTENT_ERROR_NONE;
+ GSList *item_list = NULL;
+
+ content_retip_if_fail(STRING_VALID(path));
+ content_retip_if_fail(STRING_VALID(playlist_name));
+
+ ret = media_playlist_insert_to_db(playlist_name, playlist);
+ content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "media_playlist_insert_to_db fail");
+
+ ret = __media_playlist_import_item_from_file(path, &item_list);
+ content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "Fail to get playlist from file");
+
+ g_slist_foreach(item_list, __media_playlist_foreach_item, playlist);
+
+ ret = media_playlist_update_to_db(*playlist);
+ g_slist_free_full(item_list, g_free);
return ret;
}
-int media_playlist_export_to_file(media_playlist_h playlist, const char* path)
+int media_playlist_export_to_file(media_playlist_h playlist, const char *path)
{
+ content_warn("DEPRECATION WARNING: media_playlist_export_to_file() is deprecated and will be removed from next release.");
int ret = MEDIA_CONTENT_ERROR_NONE;
- media_playlist_s *_playlist = (media_playlist_s*)playlist;
+ media_playlist_s *_playlist = (media_playlist_s *)playlist;
GList *item_list = NULL;
- unsigned int idx = 0;
- char repl_path[MAX_QUERY_SIZE] = {0, };
- char repl_item[MAX_QUERY_SIZE] = {0, };
+ GList *iter = NULL;
+ char *item = NULL;
- media_content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
- media_content_retvm_if(_playlist == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid playlist");
- media_content_retvm_if(_playlist->playlist_id <= 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid playlist_id");
- memset(repl_path, 0, sizeof(repl_path));
- ret = _media_content_replace_path(path, repl_path);
- media_content_retvm_if(!STRING_VALID(repl_path), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed");
+ content_retip_if_fail(STRING_VALID(path));
+ content_retip_if_fail(playlist);
+ content_retipm_if_fail(_playlist->playlist_id > 0, "%d", _playlist->playlist_id);
ret = _media_db_get_playlist_item(_playlist->playlist_id, NULL, __media_playlist_member_cb, &item_list);
- media_content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "_media_db_get_playlist_item fail");
+ content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "_media_db_get_playlist_item fail");
- ret = __media_playlist_reset_file(repl_path);
+ ret = __media_playlist_reset_file(path);
if (ret != MEDIA_CONTENT_ERROR_NONE) {
- g_list_free_full(item_list, __media_playlist_destroy_export_item);
- media_content_error("Fail to init playlist file");
- return ret;
+ content_error("Fail to init playlist file");
+ goto FINALIZE;
}
- for (idx = 0; idx < g_list_length(item_list); idx++) {
- char *item = g_list_nth_data(item_list, idx);
- memset(repl_item, 0, sizeof(repl_item));
- ret = _media_content_rollback_path(item, repl_item);
+ for (iter = item_list; iter; iter = g_list_next(iter)) {
+ item = (char *)iter->data;
+ if (!STRING_VALID(item))
+ continue;
- ret = __media_playlist_append_to_file(repl_path, repl_item);
+ ret = __media_playlist_append_to_file(path, item);
if (ret != MEDIA_CONTENT_ERROR_NONE) {
- g_list_free_full(item_list, __media_playlist_destroy_export_item);
- media_content_error("Fail to export paths into file");
- return ret;
+ content_error("Fail to export paths into file");
+ goto FINALIZE;
}
}
- g_list_free_full(item_list, __media_playlist_destroy_export_item);
+FINALIZE:
+ g_list_free_full(item_list, g_free);
+
+ return ret;
+}
+
+int media_playlist_create(media_playlist_h *playlist)
+{
+ content_warn("DEPRECATION WARNING: media_playlist_create() is deprecated and will be removed from next release.");
+ content_retip_if_fail(playlist);
+
+ media_playlist_s *_playlist = g_new0(media_playlist_s, 1);
+
+ _playlist->playlist_id = -1;
+ _playlist->name = NULL;
+ _playlist->thumbnail_path = NULL;
+ _playlist->item_list = NULL;
+
+ *playlist = (media_playlist_h)_playlist;
+
+ return MEDIA_CONTENT_ERROR_NONE;
+}
+
+int media_playlist_get_play_order_v2(int playlist_id, int playlist_member_id, int *play_order)
+{
+ content_warn("DEPRECATION WARNING: media_playlist_get_play_order_v2() is deprecated and will be removed from next release.");
+ int ret = MEDIA_CONTENT_ERROR_NONE;
+ sqlite3_stmt *stmt = NULL;
+ char *query = NULL;
+
+ content_retipm_if_fail(playlist_id >= 0, "%d", playlist_id);
+ content_retipm_if_fail(playlist_member_id >= 0, "%d", playlist_member_id);
+ content_retip_if_fail(play_order);
+
+ query = sqlite3_mprintf(SELECT_PLAY_ORDER_FROM_PLAYLIST_VIEW, playlist_id, playlist_member_id);
+
+ ret = _content_get_result(query, &stmt);
+ SQLITE3_SAFE_FREE(query);
+ content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
+
+ if (sqlite3_step(stmt) == SQLITE_ROW)
+ *play_order = sqlite3_column_int(stmt, 0);
+
+ SQLITE3_FINALIZE(stmt);
return ret;
}
+
+int media_playlist_insert_to_db_v2(media_playlist_h playlist)
+{
+ content_warn("DEPRECATION WARNING: media_playlist_insert_to_db_v2() is deprecated and will be removed from next release.");
+ int ret = MEDIA_CONTENT_ERROR_NONE;
+ media_playlist_s *_playlist = (media_playlist_s *)playlist;
+ int playlist_id = 0;
+
+ content_retip_if_fail(playlist);
+ content_retipm_if_fail(_playlist->playlist_id == -1, "%d", _playlist->playlist_id);
+
+ ret = __media_playlist_insert_playlist_record(_playlist->name, &playlist_id);
+ if (ret != MEDIA_CONTENT_ERROR_NONE) {
+ __media_playlist_item_release(_playlist);
+ content_error("Insert playlist Fail");
+ return ret;
+ }
+
+ _playlist->playlist_id = playlist_id;
+
+ return media_playlist_update_to_db(playlist);
+}
+
+int media_playlist_update_to_db_v2(int playlist_id, media_playlist_h playlist)
+{
+ content_warn("DEPRECATION WARNING: media_playlist_update_to_db_v2() is deprecated and will be removed from next release.");
+ media_playlist_s *_playlist = (media_playlist_s *)playlist;
+ content_retip_if_fail(playlist);
+
+ _playlist->playlist_id = playlist_id;
+
+ return media_playlist_update_to_db(playlist);
+}
+// LCOV_EXCL_STOP