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>
19 #include <media_util_private.h>
22 int media_bookmark_insert_to_db(const char *media_id, time_t time, const char *thumbnail_path)
24 int ret = MEDIA_CONTENT_ERROR_NONE;
26 char repl_path[MAX_QUERY_SIZE] = {0, };
28 if (STRING_VALID(media_id)) {
29 memset(repl_path, 0, sizeof(repl_path));
30 ret = _media_content_replace_path(thumbnail_path, repl_path);
31 sql = sqlite3_mprintf(INSERT_BOOKMARK_TO_BOOKMARK, media_id, time, repl_path);
32 ret = _content_query_sql(sql);
33 SQLITE3_SAFE_FREE(sql);
35 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
36 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
42 int media_bookmark_delete_from_db(int bookmark_id)
44 int ret = MEDIA_CONTENT_ERROR_NONE;
45 char *query_str = NULL;
47 if (bookmark_id < 0) {
48 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
49 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
52 query_str = sqlite3_mprintf(DELETE_BOOKMARK_FROM_BOOKMARK, bookmark_id);
54 ret = _content_query_sql(query_str);
56 SQLITE3_SAFE_FREE(query_str);
61 int media_bookmark_get_bookmark_count_from_db(filter_h filter, int *bookmark_count)
63 int ret = MEDIA_CONTENT_ERROR_NONE;
65 if (bookmark_count == NULL) {
66 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
67 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
70 ret = _media_db_get_group_count(filter, MEDIA_GROUP_BOOKMARK, bookmark_count);
75 int media_bookmark_destroy(media_bookmark_h bookmark)
77 int ret = MEDIA_CONTENT_ERROR_NONE;
78 media_bookmark_s *_bookmark = (media_bookmark_s*)bookmark;
81 SAFE_FREE(_bookmark->media_id);
82 SAFE_FREE(_bookmark->thumbnail_path);
84 ret = MEDIA_CONTENT_ERROR_NONE;
86 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
87 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
92 int media_bookmark_clone(media_bookmark_h *dst, media_bookmark_h src)
94 int ret = MEDIA_CONTENT_ERROR_NONE;
97 media_bookmark_s *_src = (media_bookmark_s*)src;
98 media_bookmark_s *_dst = (media_bookmark_s*)calloc(1, sizeof(media_bookmark_s));
99 media_content_retvm_if(_dst == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
101 _dst->bookmark_id = _src->bookmark_id;
103 if (STRING_VALID(_src->media_id)) {
104 _dst->media_id = (char *)strdup(_src->media_id);
105 if (_dst->media_id == NULL) {
106 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
107 media_bookmark_destroy((media_bookmark_h)_dst);
108 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
112 _dst->marked_time = _src->marked_time;
114 if (STRING_VALID(_src->thumbnail_path)) {
115 _dst->thumbnail_path = (char*)strdup(_src->thumbnail_path);
116 if (_dst->thumbnail_path == NULL) {
117 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
118 media_bookmark_destroy((media_bookmark_h)_dst);
119 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
123 *dst = (media_bookmark_h)_dst;
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_bookmark_get_bookmark_id(media_bookmark_h bookmark, int *bookmark_id)
136 int ret = MEDIA_CONTENT_ERROR_NONE;
137 media_bookmark_s *_bookmark = (media_bookmark_s*)bookmark;
140 *bookmark_id = _bookmark->bookmark_id;
141 ret = MEDIA_CONTENT_ERROR_NONE;
143 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
144 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
150 int media_bookmark_get_marked_time(media_bookmark_h bookmark, time_t* marked_time)
152 int ret = MEDIA_CONTENT_ERROR_NONE;
153 media_bookmark_s *_bookmark = (media_bookmark_s*)bookmark;
156 *marked_time = _bookmark->marked_time;
157 ret = MEDIA_CONTENT_ERROR_NONE;
159 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
160 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
166 int media_bookmark_get_thumbnail_path(media_bookmark_h bookmark, char **path)
168 int ret = MEDIA_CONTENT_ERROR_NONE;
169 media_bookmark_s *_bookmark = (media_bookmark_s*)bookmark;
172 if (STRING_VALID(_bookmark->thumbnail_path)) {
173 *path = strdup(_bookmark->thumbnail_path);
174 media_content_retvm_if(*path == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
179 ret = MEDIA_CONTENT_ERROR_NONE;
181 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
182 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;