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_retvm_if(!STRING_VALID(media_id), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid 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;
48 content_retvm_if(!STRING_VALID(media_id), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid parameter");
50 sql = sqlite3_mprintf(INSERT_BOOKMARK_TO_BOOKMARK, media_id, time, thumbnail_path, MEDIA_CONTENT_EMPTY_STRING);
51 ret = _content_query_sql(sql);
52 SQLITE3_SAFE_FREE(sql);
57 int media_bookmark_delete_from_db(int bookmark_id)
59 int ret = MEDIA_CONTENT_ERROR_NONE;
60 char *query_str = NULL;
61 content_retvm_if(bookmark_id < 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid parameter");
63 query_str = sqlite3_mprintf(DELETE_BOOKMARK_FROM_BOOKMARK, bookmark_id);
64 ret = _content_query_sql(query_str);
65 SQLITE3_SAFE_FREE(query_str);
70 int media_bookmark_get_bookmark_count_from_db(filter_h filter, int *bookmark_count)
72 content_retvm_if(!bookmark_count, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid parameter");
74 return _media_db_get_group_count(filter, MEDIA_GROUP_BOOKMARK, bookmark_count);
77 int media_bookmark_foreach_bookmark_from_db(filter_h filter, media_bookmark_cb callback, void *user_data)
79 content_retvm_if(!callback, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid paramter");
81 return _media_db_get_bookmark(NULL, filter, callback, user_data);
84 int media_bookmark_destroy(media_bookmark_h bookmark)
86 media_bookmark_s *_bookmark = (media_bookmark_s *)bookmark;
87 content_retvm_if(!_bookmark, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid paramter");
89 SAFE_FREE(_bookmark->media_id);
90 SAFE_FREE(_bookmark->thumbnail_path);
91 SAFE_FREE(_bookmark->name);
94 return MEDIA_CONTENT_ERROR_NONE;
96 int media_bookmark_clone(media_bookmark_h *dst, media_bookmark_h src)
98 media_bookmark_s *_src = (media_bookmark_s *)src;
99 content_retvm_if(!_src, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid source");
101 media_bookmark_s *_dst = (media_bookmark_s *)calloc(1, sizeof(media_bookmark_s));
102 content_retvm_if(!_dst, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
104 _dst->bookmark_id = _src->bookmark_id;
105 _dst->media_id = g_strdup(_src->media_id);
106 _dst->marked_time = _src->marked_time;
107 _dst->thumbnail_path = g_strdup(_src->thumbnail_path);
108 _dst->name = g_strdup(_src->name);
110 *dst = (media_bookmark_h)_dst;
112 return MEDIA_CONTENT_ERROR_NONE;
115 int media_bookmark_get_bookmark_id(media_bookmark_h bookmark, int *bookmark_id)
117 media_bookmark_s *_bookmark = (media_bookmark_s *)bookmark;
118 content_retvm_if(!_bookmark || !bookmark_id, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid parameter");
120 *bookmark_id = _bookmark->bookmark_id;
122 return MEDIA_CONTENT_ERROR_NONE;
125 int media_bookmark_get_marked_time(media_bookmark_h bookmark, time_t* marked_time)
127 media_bookmark_s *_bookmark = (media_bookmark_s *)bookmark;
128 content_retvm_if(!_bookmark || !marked_time, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid parameter");
130 *marked_time = _bookmark->marked_time;
132 return MEDIA_CONTENT_ERROR_NONE;
135 int media_bookmark_get_thumbnail_path(media_bookmark_h bookmark, char **path)
137 media_bookmark_s *_bookmark = (media_bookmark_s *)bookmark;
138 content_retvm_if(!_bookmark || !path, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid parameter");
140 *path = g_strdup(_bookmark->thumbnail_path);
142 return MEDIA_CONTENT_ERROR_NONE;
145 int media_bookmark_get_name(media_bookmark_h bookmark, char **name)
147 media_bookmark_s *_bookmark = (media_bookmark_s *)bookmark;
148 content_retvm_if(!_bookmark || !name, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid parameter");
150 *name = g_strdup(_bookmark->name);
152 return MEDIA_CONTENT_ERROR_NONE;
155 int media_bookmark_set_name(media_bookmark_h bookmark, const char *name)
157 media_bookmark_s *_bookmark = (media_bookmark_s *)bookmark;
158 content_retvm_if(!_bookmark, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid parameter");
160 _bookmark->name = g_strdup(STRING_VALID(name) ? name : MEDIA_CONTENT_EMPTY_STRING);
162 return MEDIA_CONTENT_ERROR_NONE;
165 int media_bookmark_update_to_db(media_bookmark_h bookmark)
167 int ret = MEDIA_CONTENT_ERROR_NONE;
168 media_bookmark_s *_bookmark = (media_bookmark_s *)bookmark;
170 content_retvm_if(!_bookmark, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid parameter");
172 sql = sqlite3_mprintf(UPDATE_BOOKMARK_FROM_BOOKMARK, _bookmark->name, _bookmark->bookmark_id);
173 ret = _content_query_sql(sql);
174 SQLITE3_SAFE_FREE(sql);
179 int media_bookmark_create(const char *media_id, time_t time, media_bookmark_h *bookmark)
181 int ret = MEDIA_CONTENT_ERROR_NONE;
183 content_retvm_if(!STRING_VALID(media_id), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid media_id");
184 content_retvm_if(!bookmark, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid bookmark");
186 ret = __media_bookmark_check_media_id(media_id);
187 content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "Not exist media_id");
189 media_bookmark_s *_bookmark = (media_bookmark_s *)calloc(1, sizeof(media_bookmark_s));
190 content_retvm_if(!_bookmark, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
192 _bookmark->media_id = g_strdup(media_id);
193 _bookmark->bookmark_id = -1;
194 _bookmark->marked_time = time;
196 *bookmark = (media_bookmark_h)_bookmark;
201 int media_bookmark_set_thumbnail_path(media_bookmark_h bookmark, const char *path)
203 media_bookmark_s *_bookmark = (media_bookmark_s *)bookmark;
204 content_retvm_if(!_bookmark, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid bookmark");
206 _bookmark->thumbnail_path = g_strdup(path);
208 return MEDIA_CONTENT_ERROR_NONE;
211 int media_bookmark_insert_to_db_v2(media_bookmark_h bookmark)
213 int ret = MEDIA_CONTENT_ERROR_NONE;
214 media_bookmark_s *_bookmark = (media_bookmark_s *)bookmark;
216 sqlite3_stmt *stmt = NULL;
217 int bookmark_id = -1;
219 content_retvm_if(!_bookmark, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid bookmark");
220 content_retvm_if(_bookmark->bookmark_id != -1, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid bookmark");
222 sql = sqlite3_mprintf(INSERT_BOOKMARK_TO_BOOKMARK,
223 _bookmark->media_id, _bookmark->marked_time, _bookmark->thumbnail_path, _bookmark->name);
225 ret = _content_query_sql(sql);
226 SQLITE3_SAFE_FREE(sql);
227 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
229 sql = sqlite3_mprintf(SELECT_BOOKMARK_ID_FROM_BOOKMARK, _bookmark->media_id, _bookmark->marked_time);
230 ret = _content_get_result(sql, &stmt);
231 SQLITE3_SAFE_FREE(sql);
232 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
234 if (sqlite3_step(stmt) == SQLITE_ROW)
235 bookmark_id = sqlite3_column_int(stmt, 0);
237 SQLITE3_FINALIZE(stmt);
239 _bookmark->bookmark_id = bookmark_id;