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>
20 static int __media_bookmark_check_media_id(const char *media_id)
22 int ret = MEDIA_CONTENT_ERROR_NONE;
23 char *query_str = NULL;
24 sqlite3_stmt *stmt = NULL;
27 content_retip_if_fail(STRING_VALID(media_id));
29 query_str = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_MEDIA_BY_ID, media_id);
30 ret = _content_get_result(query_str, &stmt);
31 SQLITE3_SAFE_FREE(query_str);
32 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
34 if (sqlite3_step(stmt) == SQLITE_ROW)
35 item_count = (int)sqlite3_column_int(stmt, 0);
37 SQLITE3_FINALIZE(stmt);
39 content_retvm_if(item_count == 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media_id");
41 return MEDIA_CONTENT_ERROR_NONE;
44 int media_bookmark_insert_to_db(const char *media_id, time_t time, const char *thumbnail_path)
46 int ret = MEDIA_CONTENT_ERROR_NONE;
49 content_retip_if_fail(STRING_VALID(media_id));
51 sql = sqlite3_mprintf(INSERT_BOOKMARK_TO_BOOKMARK, media_id, time, thumbnail_path, MEDIA_CONTENT_EMPTY_STRING);
52 ret = _content_query_sql(sql);
53 SQLITE3_SAFE_FREE(sql);
58 int media_bookmark_delete_from_db(int bookmark_id)
60 int ret = MEDIA_CONTENT_ERROR_NONE;
61 char *query_str = NULL;
63 content_retip_if_fail(bookmark_id >= 0);
65 query_str = sqlite3_mprintf(DELETE_BOOKMARK_FROM_BOOKMARK, bookmark_id);
66 ret = _content_query_sql(query_str);
67 SQLITE3_SAFE_FREE(query_str);
72 int media_bookmark_get_bookmark_count_from_db(filter_h filter, int *bookmark_count)
74 content_retip_if_fail(bookmark_count);
76 return _media_db_get_group_count(filter, MEDIA_GROUP_BOOKMARK, bookmark_count);
79 int media_bookmark_foreach_bookmark_from_db(filter_h filter, media_bookmark_cb callback, void *user_data)
81 content_retip_if_fail(callback);
83 return _media_db_get_bookmark(NULL, filter, callback, user_data);
86 int media_bookmark_destroy(media_bookmark_h bookmark)
88 media_bookmark_s *_bookmark = (media_bookmark_s *)bookmark;
90 content_retip_if_fail(bookmark);
92 g_free(_bookmark->media_id);
93 g_free(_bookmark->thumbnail_path);
94 g_free(_bookmark->name);
97 return MEDIA_CONTENT_ERROR_NONE;
99 int media_bookmark_clone(media_bookmark_h *dst, media_bookmark_h src)
101 media_bookmark_s *_src = (media_bookmark_s *)src;
103 content_retip_if_fail(dst);
104 content_retip_if_fail(src);
106 media_bookmark_s *_dst = g_new0(media_bookmark_s, 1);
108 _dst->bookmark_id = _src->bookmark_id;
109 _dst->media_id = g_strdup(_src->media_id);
110 _dst->marked_time = _src->marked_time;
111 _dst->thumbnail_path = g_strdup(_src->thumbnail_path);
112 _dst->name = g_strdup(_src->name);
114 *dst = (media_bookmark_h)_dst;
116 return MEDIA_CONTENT_ERROR_NONE;
119 int media_bookmark_get_bookmark_id(media_bookmark_h bookmark, int *bookmark_id)
121 media_bookmark_s *_bookmark = (media_bookmark_s *)bookmark;
123 content_retip_if_fail(bookmark);
124 content_retip_if_fail(bookmark_id);
126 *bookmark_id = _bookmark->bookmark_id;
128 return MEDIA_CONTENT_ERROR_NONE;
131 int media_bookmark_get_marked_time(media_bookmark_h bookmark, time_t* marked_time)
133 media_bookmark_s *_bookmark = (media_bookmark_s *)bookmark;
135 content_retip_if_fail(bookmark);
136 content_retip_if_fail(marked_time);
138 *marked_time = _bookmark->marked_time;
140 return MEDIA_CONTENT_ERROR_NONE;
143 int media_bookmark_get_thumbnail_path(media_bookmark_h bookmark, char **path)
145 media_bookmark_s *_bookmark = (media_bookmark_s *)bookmark;
147 content_retip_if_fail(bookmark);
148 content_retip_if_fail(path);
150 *path = g_strdup(_bookmark->thumbnail_path);
152 return MEDIA_CONTENT_ERROR_NONE;
155 int media_bookmark_get_name(media_bookmark_h bookmark, char **name)
157 media_bookmark_s *_bookmark = (media_bookmark_s *)bookmark;
159 content_retip_if_fail(bookmark);
160 content_retip_if_fail(name);
162 *name = g_strdup(_bookmark->name);
164 return MEDIA_CONTENT_ERROR_NONE;
167 int media_bookmark_set_name(media_bookmark_h bookmark, const char *name)
169 media_bookmark_s *_bookmark = (media_bookmark_s *)bookmark;
171 content_retip_if_fail(bookmark);
173 g_free(_bookmark->name);
174 _bookmark->name = g_strdup(STRING_VALID(name) ? name : MEDIA_CONTENT_EMPTY_STRING);
176 return MEDIA_CONTENT_ERROR_NONE;
179 int media_bookmark_update_to_db(media_bookmark_h bookmark)
181 int ret = MEDIA_CONTENT_ERROR_NONE;
182 media_bookmark_s *_bookmark = (media_bookmark_s *)bookmark;
185 content_retip_if_fail(bookmark);
187 sql = sqlite3_mprintf(UPDATE_BOOKMARK_FROM_BOOKMARK, _bookmark->name, _bookmark->bookmark_id);
188 ret = _content_query_sql(sql);
189 SQLITE3_SAFE_FREE(sql);
194 int media_bookmark_create(const char *media_id, time_t time, media_bookmark_h *bookmark)
196 int ret = MEDIA_CONTENT_ERROR_NONE;
198 content_retip_if_fail(bookmark);
200 ret = __media_bookmark_check_media_id(media_id);
201 content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "Not exist media_id");
203 media_bookmark_s *_bookmark = g_new0(media_bookmark_s, 1);
205 _bookmark->media_id = g_strdup(media_id);
206 _bookmark->bookmark_id = -1;
207 _bookmark->marked_time = time;
209 *bookmark = (media_bookmark_h)_bookmark;
214 int media_bookmark_set_thumbnail_path(media_bookmark_h bookmark, const char *path)
216 media_bookmark_s *_bookmark = (media_bookmark_s *)bookmark;
218 content_retip_if_fail(bookmark);
220 g_free(_bookmark->thumbnail_path);
221 _bookmark->thumbnail_path = g_strdup(path);
223 return MEDIA_CONTENT_ERROR_NONE;
226 int media_bookmark_insert_to_db_v2(media_bookmark_h bookmark)
228 int ret = MEDIA_CONTENT_ERROR_NONE;
229 media_bookmark_s *_bookmark = (media_bookmark_s *)bookmark;
231 sqlite3_stmt *stmt = NULL;
232 int bookmark_id = -1;
234 content_retip_if_fail(bookmark);
235 content_retip_if_fail(_bookmark->bookmark_id == -1);
237 sql = sqlite3_mprintf(INSERT_BOOKMARK_TO_BOOKMARK,
238 _bookmark->media_id, _bookmark->marked_time, _bookmark->thumbnail_path, _bookmark->name);
240 ret = _content_query_sql(sql);
241 SQLITE3_SAFE_FREE(sql);
242 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
244 sql = sqlite3_mprintf(SELECT_BOOKMARK_ID_FROM_BOOKMARK, _bookmark->media_id, _bookmark->marked_time);
245 ret = _content_get_result(sql, &stmt);
246 SQLITE3_SAFE_FREE(sql);
247 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
249 if (sqlite3_step(stmt) == SQLITE_ROW)
250 bookmark_id = sqlite3_column_int(stmt, 0);
252 SQLITE3_FINALIZE(stmt);
254 _bookmark->bookmark_id = bookmark_id;