#include <media_info_private.h>
-#include <media_util_private.h>
+static int __media_bookmark_check_media_id(const char *media_id);
+
+static int __media_bookmark_check_media_id(const char *media_id)
+{
+ int ret = MEDIA_CONTENT_ERROR_NONE;
+ char *query_str = NULL;
+ sqlite3_stmt *stmt = NULL;
+ int item_count = 0;
+
+ media_content_retvm_if(!STRING_VALID(media_id), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid media_id");
+
+ query_str = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_MEDIA_BY_ID, media_id);
+ ret = _content_query_prepare(&stmt, query_str, NULL, NULL);
+ SQLITE3_SAFE_FREE(query_str);
+ media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
+
+ while (sqlite3_step(stmt) == SQLITE_ROW)
+ item_count = (int)sqlite3_column_int(stmt, 0);
+
+ SQLITE3_FINALIZE(stmt);
+
+ media_content_retvm_if(item_count == 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media_id");
+
+ return MEDIA_CONTENT_ERROR_NONE;
+}
int media_bookmark_insert_to_db(const char *media_id, time_t time, const char *thumbnail_path)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
char *sql = NULL;
- char repl_path[MAX_QUERY_SIZE] = {0, };
if (STRING_VALID(media_id)) {
- if (STRING_VALID(thumbnail_path)) {
- memset(repl_path, 0, sizeof(repl_path));
- ret = _media_content_replace_path(thumbnail_path, repl_path);
- sql = sqlite3_mprintf(INSERT_BOOKMARK_TO_BOOKMARK, media_id, time, repl_path);
- } else {
- sql = sqlite3_mprintf(INSERT_BOOKMARK_TO_BOOKMARK, media_id, time, thumbnail_path);
- }
+ sql = sqlite3_mprintf(INSERT_BOOKMARK_TO_BOOKMARK, media_id, time, thumbnail_path, MEDIA_CONTENT_EMPTY_STRING);
ret = _content_query_sql(sql);
SQLITE3_SAFE_FREE(sql);
} else {
if (_bookmark) {
SAFE_FREE(_bookmark->media_id);
SAFE_FREE(_bookmark->thumbnail_path);
+ SAFE_FREE(_bookmark->name);
free(_bookmark);
ret = MEDIA_CONTENT_ERROR_NONE;
} else {
}
}
+ if (STRING_VALID(_src->name)) {
+ _dst->name = (char*)strdup(_src->name);
+ if (_dst->name == NULL) {
+ media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
+ media_bookmark_destroy((media_bookmark_h)_dst);
+ return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
+ }
+ }
+
*dst = (media_bookmark_h)_dst;
ret = MEDIA_CONTENT_ERROR_NONE;
return ret;
}
+
+int media_bookmark_get_name(media_bookmark_h bookmark, char **name)
+{
+ int ret = MEDIA_CONTENT_ERROR_NONE;
+ media_bookmark_s *_bookmark = (media_bookmark_s*)bookmark;
+
+ if (_bookmark) {
+ *name = g_strdup(_bookmark->name);
+ media_content_retvm_if(*name == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
+ } else {
+ media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
+ ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
+ }
+
+ return ret;
+}
+
+int media_bookmark_set_name(media_bookmark_h bookmark, const char *name)
+{
+ int ret = MEDIA_CONTENT_ERROR_NONE;
+ media_bookmark_s *_bookmark = (media_bookmark_s*)bookmark;
+
+ if (_bookmark != NULL) {
+ if (STRING_VALID(name))
+ _bookmark->name = g_strdup(name);
+ else
+ _bookmark->name = g_strdup(MEDIA_CONTENT_EMPTY_STRING);
+
+ media_content_retvm_if(_bookmark->name == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
+ } else {
+ media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
+ ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
+ }
+
+ return ret;
+}
+
+int media_bookmark_update_to_db(media_bookmark_h bookmark)
+{
+ int ret = MEDIA_CONTENT_ERROR_NONE;
+ media_bookmark_s *_bookmark = (media_bookmark_s*)bookmark;
+ char *sql = NULL;
+
+ if (_bookmark != NULL) {
+ sql = sqlite3_mprintf(UPDATE_BOOKMARK_FROM_BOOKMARK, _bookmark->name, _bookmark->bookmark_id);
+ ret = _content_query_sql(sql);
+ SQLITE3_SAFE_FREE(sql);
+ } else {
+ media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
+ ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
+ }
+
+ return ret;
+}
+
+int media_bookmark_create(const char *media_id, time_t time, media_bookmark_h *bookmark)
+{
+ int ret = MEDIA_CONTENT_ERROR_NONE;
+
+ media_content_retvm_if(!STRING_VALID(media_id), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid media_id");
+ media_content_retvm_if(bookmark == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid bookmark");
+
+ ret = __media_bookmark_check_media_id(media_id);
+ media_content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Not exist media_id");
+
+ media_bookmark_s *_bookmark = (media_bookmark_s*)calloc(1, sizeof(media_bookmark_s));
+ media_content_retvm_if(_bookmark == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
+
+ _bookmark->media_id = g_strdup(media_id);
+ if (!STRING_VALID(_bookmark->media_id)) {
+ media_content_error("MEDIA_CONTENT_ERROR_OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
+ SAFE_FREE(_bookmark->media_id);
+ SAFE_FREE(_bookmark);
+ return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
+ }
+
+ _bookmark->bookmark_id = -1;
+ _bookmark->marked_time = time;
+
+ *bookmark = (media_bookmark_h)_bookmark;
+
+ return ret;
+}
+
+int media_bookmark_set_thumbnail_path(media_bookmark_h bookmark, const char *path)
+{
+ int ret = MEDIA_CONTENT_ERROR_NONE;
+ media_bookmark_s *_bookmark = (media_bookmark_s*)bookmark;
+
+ media_content_retvm_if(_bookmark == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid bookmark");
+
+ if (STRING_VALID(path))
+ _bookmark->thumbnail_path = g_strdup(path);
+ else
+ _bookmark->thumbnail_path = g_strdup(MEDIA_CONTENT_EMPTY_STRING);
+
+ media_content_retvm_if(_bookmark->thumbnail_path == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
+
+ return ret;
+}
+
+int media_bookmark_insert_to_db_v2(media_bookmark_h bookmark)
+{
+ int ret = MEDIA_CONTENT_ERROR_NONE;
+ media_bookmark_s *_bookmark = (media_bookmark_s*)bookmark;
+ char *sql = NULL;
+ char *select_query = NULL;
+ sqlite3_stmt *stmt = NULL;
+ int bookmark_id = -1;
+
+ media_content_retvm_if(_bookmark == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid bookmark");
+ media_content_retvm_if(_bookmark->bookmark_id != -1, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid bookmark insert");
+
+ sql = sqlite3_mprintf(INSERT_BOOKMARK_TO_BOOKMARK, _bookmark->media_id, _bookmark->marked_time, _bookmark->thumbnail_path, _bookmark->name);
+ ret = _content_query_sql(sql);
+ SQLITE3_SAFE_FREE(sql);
+
+ select_query = sqlite3_mprintf(SELECT_BOOKMARK_ID_FROM_BOOKMARK, _bookmark->media_id, _bookmark->marked_time);
+
+ ret = _content_query_prepare(&stmt, select_query, NULL, NULL);
+ SQLITE3_SAFE_FREE(select_query);
+ media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
+
+ while (sqlite3_step(stmt) == SQLITE_ROW)
+ bookmark_id = (int)sqlite3_column_int(stmt, 0);
+
+ SQLITE3_FINALIZE(stmt);
+
+ _bookmark->bookmark_id = bookmark_id;
+
+ return ret;
+}