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 static int __media_bookmark_check_media_id(const char *media_id)
23 int ret = MEDIA_CONTENT_ERROR_NONE;
24 char *query_str = NULL;
25 sqlite3_stmt *stmt = NULL;
28 content_retip_if_fail(STRING_VALID(media_id));
30 query_str = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_MEDIA_BY_ID, media_id);
31 ret = _content_get_result(query_str, &stmt);
32 sqlite3_free(query_str);
33 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
35 if (sqlite3_step(stmt) == SQLITE_ROW)
36 item_count = (int)sqlite3_column_int(stmt, 0);
38 sqlite3_finalize(stmt);
40 content_retvm_if(item_count == 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media_id");
42 return MEDIA_CONTENT_ERROR_NONE;
45 int media_bookmark_insert_to_db(const char *media_id, time_t time, const char *thumbnail_path)
47 content_warn("DEPRECATION WARNING: media_bookmark_insert_to_db() is deprecated and will be removed from next release.");
48 int ret = MEDIA_CONTENT_ERROR_NONE;
51 content_retip_if_fail(STRING_VALID(media_id));
53 sql = sqlite3_mprintf(INSERT_BOOKMARK_TO_BOOKMARK, media_id, time, thumbnail_path, "");
54 ret = _content_query_sql(sql);
60 int media_bookmark_delete_from_db(int bookmark_id)
62 content_warn("DEPRECATION WARNING: media_bookmark_delete_from_db() is deprecated and will be removed from next release.");
63 int ret = MEDIA_CONTENT_ERROR_NONE;
64 char *query_str = NULL;
66 content_retip_if_fail(bookmark_id >= 0);
68 query_str = sqlite3_mprintf(DELETE_BOOKMARK_FROM_BOOKMARK, bookmark_id);
69 ret = _content_query_sql(query_str);
70 sqlite3_free(query_str);
75 int media_bookmark_get_bookmark_count_from_db(filter_h filter, int *bookmark_count)
77 content_warn("DEPRECATION WARNING: media_bookmark_get_bookmark_count_from_db() is deprecated and will be removed from next release.");
78 content_retip_if_fail(bookmark_count);
80 return _media_db_get_group_count(filter, MEDIA_GROUP_BOOKMARK, bookmark_count);
83 int media_bookmark_foreach_bookmark_from_db(filter_h filter, media_bookmark_cb callback, void *user_data)
85 content_warn("DEPRECATION WARNING: media_bookmark_foreach_bookmark_from_db() is deprecated and will be removed from next release.");
86 content_retip_if_fail(callback);
88 return _media_db_get_bookmark(NULL, filter, callback, user_data);
91 int media_bookmark_destroy(media_bookmark_h bookmark)
93 content_warn("DEPRECATION WARNING: media_bookmark_destroy() is deprecated and will be removed from next release.");
94 media_bookmark_s *_bookmark = (media_bookmark_s *)bookmark;
96 content_retip_if_fail(bookmark);
98 g_free(_bookmark->media_id);
99 g_free(_bookmark->thumbnail_path);
100 g_free(_bookmark->name);
103 return MEDIA_CONTENT_ERROR_NONE;
105 int media_bookmark_clone(media_bookmark_h *dst, media_bookmark_h src)
107 content_warn("DEPRECATION WARNING: media_bookmark_clone() is deprecated and will be removed from next release.");
108 media_bookmark_s *_src = (media_bookmark_s *)src;
110 content_retip_if_fail(dst);
111 content_retip_if_fail(src);
113 media_bookmark_s *_dst = g_new0(media_bookmark_s, 1);
115 _dst->bookmark_id = _src->bookmark_id;
116 _dst->media_id = g_strdup(_src->media_id);
117 _dst->marked_time = _src->marked_time;
118 _dst->thumbnail_path = g_strdup(_src->thumbnail_path);
119 _dst->name = g_strdup(_src->name);
121 *dst = (media_bookmark_h)_dst;
123 return MEDIA_CONTENT_ERROR_NONE;
126 int media_bookmark_get_bookmark_id(media_bookmark_h bookmark, int *bookmark_id)
128 content_warn("DEPRECATION WARNING: media_bookmark_get_bookmark_id() is deprecated and will be removed from next release.");
129 media_bookmark_s *_bookmark = (media_bookmark_s *)bookmark;
131 content_retip_if_fail(bookmark);
132 content_retip_if_fail(bookmark_id);
134 *bookmark_id = _bookmark->bookmark_id;
136 return MEDIA_CONTENT_ERROR_NONE;
139 int media_bookmark_get_marked_time(media_bookmark_h bookmark, time_t* marked_time)
141 content_warn("DEPRECATION WARNING: media_bookmark_get_marked_time() is deprecated and will be removed from next release.");
142 media_bookmark_s *_bookmark = (media_bookmark_s *)bookmark;
144 content_retip_if_fail(bookmark);
145 content_retip_if_fail(marked_time);
147 *marked_time = _bookmark->marked_time;
149 return MEDIA_CONTENT_ERROR_NONE;
152 int media_bookmark_get_thumbnail_path(media_bookmark_h bookmark, char **path)
154 content_warn("DEPRECATION WARNING: media_bookmark_get_thumbnail_path() is deprecated and will be removed from next release.");
155 media_bookmark_s *_bookmark = (media_bookmark_s *)bookmark;
157 content_retip_if_fail(bookmark);
158 content_retip_if_fail(path);
160 *path = g_strdup(_bookmark->thumbnail_path);
162 return MEDIA_CONTENT_ERROR_NONE;
165 int media_bookmark_get_name(media_bookmark_h bookmark, char **name)
167 content_warn("DEPRECATION WARNING: media_bookmark_get_name() is deprecated and will be removed from next release.");
168 media_bookmark_s *_bookmark = (media_bookmark_s *)bookmark;
170 content_retip_if_fail(bookmark);
171 content_retip_if_fail(name);
173 *name = g_strdup(_bookmark->name);
175 return MEDIA_CONTENT_ERROR_NONE;
178 int media_bookmark_set_name(media_bookmark_h bookmark, const char *name)
180 content_warn("DEPRECATION WARNING: media_bookmark_set_name() is deprecated and will be removed from next release.");
181 media_bookmark_s *_bookmark = (media_bookmark_s *)bookmark;
183 content_retip_if_fail(bookmark);
185 g_free(_bookmark->name);
186 _bookmark->name = g_strdup(STRING_VALID(name) ? name : "");
188 return MEDIA_CONTENT_ERROR_NONE;
191 int media_bookmark_update_to_db(media_bookmark_h bookmark)
193 content_warn("DEPRECATION WARNING: media_bookmark_update_to_db() is deprecated and will be removed from next release.");
194 int ret = MEDIA_CONTENT_ERROR_NONE;
195 media_bookmark_s *_bookmark = (media_bookmark_s *)bookmark;
198 content_retip_if_fail(bookmark);
200 sql = sqlite3_mprintf(UPDATE_BOOKMARK_FROM_BOOKMARK, _bookmark->name, _bookmark->bookmark_id);
201 ret = _content_query_sql(sql);
207 int media_bookmark_create(const char *media_id, time_t time, media_bookmark_h *bookmark)
209 content_warn("DEPRECATION WARNING: media_bookmark_create() is deprecated and will be removed from next release.");
210 int ret = MEDIA_CONTENT_ERROR_NONE;
212 content_retip_if_fail(bookmark);
214 ret = __media_bookmark_check_media_id(media_id);
215 content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "Not exist media_id");
217 media_bookmark_s *_bookmark = g_new0(media_bookmark_s, 1);
219 _bookmark->media_id = g_strdup(media_id);
220 _bookmark->bookmark_id = -1;
221 _bookmark->marked_time = time;
223 *bookmark = (media_bookmark_h)_bookmark;
228 int media_bookmark_set_thumbnail_path(media_bookmark_h bookmark, const char *path)
230 content_warn("DEPRECATION WARNING: media_bookmark_set_thumbnail_path() is deprecated and will be removed from next release.");
231 media_bookmark_s *_bookmark = (media_bookmark_s *)bookmark;
233 content_retip_if_fail(bookmark);
235 g_free(_bookmark->thumbnail_path);
236 _bookmark->thumbnail_path = g_strdup(path);
238 return MEDIA_CONTENT_ERROR_NONE;
241 int media_bookmark_insert_to_db_v2(media_bookmark_h bookmark)
243 content_warn("DEPRECATION WARNING: media_bookmark_insert_to_db_v2() is deprecated and will be removed from next release.");
244 int ret = MEDIA_CONTENT_ERROR_NONE;
245 media_bookmark_s *_bookmark = (media_bookmark_s *)bookmark;
247 sqlite3_stmt *stmt = NULL;
248 int bookmark_id = -1;
250 content_retip_if_fail(bookmark);
251 content_retip_if_fail(_bookmark->bookmark_id == -1);
253 sql = sqlite3_mprintf(INSERT_BOOKMARK_TO_BOOKMARK,
254 _bookmark->media_id, _bookmark->marked_time, _bookmark->thumbnail_path, _bookmark->name);
256 ret = _content_query_sql(sql);
258 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
260 sql = sqlite3_mprintf(SELECT_BOOKMARK_ID_FROM_BOOKMARK, _bookmark->media_id, _bookmark->marked_time);
261 ret = _content_get_result(sql, &stmt);
263 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
265 if (sqlite3_step(stmt) == SQLITE_ROW)
266 bookmark_id = sqlite3_column_int(stmt, 0);
268 sqlite3_finalize(stmt);
270 _bookmark->bookmark_id = bookmark_id;