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>
21 #include <media_content_type_product.h>
23 static char *g_src_path = NULL;
26 int media_folder_get_folder_count_from_db(filter_h filter, int *folder_count)
28 int ret = MEDIA_CONTENT_ERROR_NONE;
30 content_retip_if_fail(folder_count);
33 g_mutex_lock(_content_get_db_mutex());
36 ret = _media_db_get_group_count(filter, MEDIA_GROUP_FOLDER, folder_count);
39 g_mutex_unlock(_content_get_db_mutex());
46 int media_folder_foreach_folder_from_db(filter_h filter, media_folder_cb callback, void *user_data)
48 int ret = MEDIA_CONTENT_ERROR_NONE;
50 content_retip_if_fail(callback);
53 g_mutex_lock(_content_get_db_mutex());
56 ret = _media_db_get_folder(filter, callback, user_data);
59 g_mutex_unlock(_content_get_db_mutex());
65 int media_folder_get_media_count_from_db(const char *folder_id, filter_h filter, int *media_count)
67 int ret = MEDIA_CONTENT_ERROR_NONE;
69 content_retip_if_fail(STRING_VALID(folder_id));
70 content_retip_if_fail(media_count);
73 g_mutex_lock(_content_get_db_mutex());
76 ret = _media_db_get_group_item_count(folder_id, filter, MEDIA_GROUP_FOLDER, media_count);
79 g_mutex_unlock(_content_get_db_mutex());
85 int media_folder_foreach_media_from_db(const char *folder_id, filter_h filter, media_info_cb callback, void *user_data)
87 int ret = MEDIA_CONTENT_ERROR_NONE;
89 content_retip_if_fail(STRING_VALID(folder_id));
90 content_retip_if_fail(callback);
93 g_mutex_lock(_content_get_db_mutex());
96 ret = _media_db_get_group_item(folder_id, filter, callback, user_data, MEDIA_GROUP_FOLDER);
99 g_mutex_unlock(_content_get_db_mutex());
105 int media_folder_destroy(media_folder_h folder)
107 media_folder_s *_folder = (media_folder_s*)folder;
109 content_retip_if_fail(folder);
111 g_free(_folder->path);
112 g_free(_folder->name);
113 g_free(_folder->folder_id);
114 g_free(_folder->storage_uuid);
117 return MEDIA_CONTENT_ERROR_NONE;
119 int media_folder_clone(media_folder_h *dst, media_folder_h src)
121 media_folder_s *_src = (media_folder_s*)src;
123 content_retip_if_fail(dst);
124 content_retip_if_fail(src);
126 media_folder_s *_dst = g_new0(media_folder_s, 1);
128 _dst->folder_id = g_strdup(_src->folder_id);
129 _dst->name = g_strdup(_src->name);
130 _dst->path = g_strdup(_src->path);
131 _dst->storage_uuid = g_strdup(_src->storage_uuid);
133 *dst = (media_folder_h)_dst;
135 return MEDIA_CONTENT_ERROR_NONE;
138 int media_folder_get_folder_id(media_folder_h folder, char **folder_id)
140 media_folder_s *_folder = (media_folder_s*)folder;
142 content_retip_if_fail(folder);
143 content_retip_if_fail(folder_id);
145 *folder_id = g_strdup(_folder->folder_id);
147 return MEDIA_CONTENT_ERROR_NONE;
150 int media_folder_get_path(media_folder_h folder, char **path)
152 media_folder_s *_folder = (media_folder_s*)folder;
154 content_retip_if_fail(folder);
155 content_retip_if_fail(path);
157 *path = g_strdup(_folder->path);
159 return MEDIA_CONTENT_ERROR_NONE;
162 int media_folder_get_name(media_folder_h folder, char **name)
164 media_folder_s *_folder = (media_folder_s*)folder;
166 content_retip_if_fail(folder);
167 content_retip_if_fail(name);
169 *name = g_strdup(_folder->name);
171 return MEDIA_CONTENT_ERROR_NONE;
174 int media_folder_get_folder_from_db(const char *folder_id, media_folder_h *folder)
176 int ret = MEDIA_CONTENT_ERROR_NONE;
177 sqlite3_stmt *stmt = NULL;
178 char select_query[DEFAULT_QUERY_SIZE] = {0, };
179 media_folder_s *_folder = NULL;
181 content_retip_if_fail(STRING_VALID(folder_id));
182 content_retip_if_fail(folder);
184 snprintf(select_query, sizeof(select_query), SELECT_FOLDER_FROM_FOLDER, folder_id);
186 ret = _content_get_result(select_query, &stmt);
187 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
189 if (sqlite3_step(stmt) == SQLITE_ROW) {
190 _folder = g_new0(media_folder_s, 1);
192 _folder->folder_id = g_strdup(folder_id);
193 _folder->path = g_strdup((const char *)sqlite3_column_text(stmt, 0));
194 _folder->name = g_strdup((const char *)sqlite3_column_text(stmt, 1));
195 _folder->storage_uuid = g_strdup((const char *)sqlite3_column_text(stmt, 3));
197 *folder = (media_folder_h)_folder;
200 sqlite3_finalize(stmt);
204 #ifdef _USE_TVPD_MODE
205 int media_folder_update_to_db(media_folder_h folder)
207 int ret = MEDIA_CONTENT_ERROR_NONE;
208 content_warn("DEPRECATION WARNING: media_folder_update_to_db() is deprecated and will be removed from next release.");
209 media_folder_s *_folder = (media_folder_s*)folder;
211 content_retip_if_fail(folder);
212 content_retip_if_fail(STRING_VALID(_folder->folder_id));
217 ret = media_svc_rename_folder(_content_get_db_handle(), _folder->storage_uuid, g_src_path, _folder->path, _content_get_uid());
221 return _content_error_capi(ret);
224 int media_folder_set_name(media_folder_h folder, const char *name)
226 int ret = MEDIA_CONTENT_ERROR_NONE;
227 content_warn("DEPRECATION WARNING: media_folder_set_name() is deprecated and will be removed from next release.");
228 media_folder_s *_folder = (media_folder_s*)folder;
229 char *parent_folder_path = NULL;
231 content_retip_if_fail(folder);
232 content_retip_if_fail(STRING_VALID(name));
233 content_retip_if_fail(name[0] != '.');
234 content_retip_if_fail(STRING_VALID(_folder->path));
235 content_retip_if_fail(STRING_VALID(_folder->name));
238 g_free(_folder->name);
239 _folder->name = g_strdup(name);
243 g_src_path = g_strdup(_folder->path);
244 g_free(_folder->path);
246 parent_folder_path = g_path_get_dirname(g_src_path);
247 _folder->path = g_strdup_printf("%s/%s", parent_folder_path, name);
248 g_free(parent_folder_path);
250 content_sec_debug("Old[%s] New[%s]", g_src_path, _folder->path);
255 int media_folder_get_scan_status(const char *storage_uuid, char* path, media_folder_scan_status_e *scan_status)
257 int ret = MEDIA_CONTENT_ERROR_NONE;
258 int status = MEDIA_DIR_SCAN_NONE;
260 content_retip_if_fail(STRING_VALID(storage_uuid));
261 content_retip_if_fail(STRING_VALID(path));
262 content_retip_if_fail(scan_status);
264 ret = media_svc_get_folder_scan_status(_content_get_db_handle(), path, &status);
265 if (ret != MS_MEDIA_ERR_NONE) {
266 content_error("media_svc_get_folder_scan_status failed");
267 ret = _content_error_capi(ret);
269 *scan_status = status;
275 int media_folder_reset_scan_status(const char *storage_uuid, const char* path)
277 int ret = MEDIA_CONTENT_ERROR_NONE;
279 content_retip_if_fail(STRING_VALID(path));
281 ret = media_svc_set_folder_validity(FALSE, path, 0, TRUE, _content_get_uid());
282 if (ret != MS_MEDIA_ERR_NONE) {
283 content_error("set folder validity failed");
284 return _content_error_capi(ret);
287 ret = media_svc_set_folder_scan_status(storage_uuid, path, MEDIA_DIR_SCAN_NONE, false, _content_get_uid());
288 if (ret != MS_MEDIA_ERR_NONE) {
289 content_error("media_folder_reset_scan_status failed");
290 return _content_error_capi(ret);