/* * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #ifdef _USE_TVPD_MODE #include static char *g_src_path = NULL; #endif int media_folder_get_folder_count_from_db(filter_h filter, int *folder_count) { int ret = MEDIA_CONTENT_ERROR_NONE; content_retip_if_fail(folder_count); #ifdef _USE_TVPD_MODE g_mutex_lock(_content_get_db_mutex()); #endif ret = _media_db_get_group_count(filter, MEDIA_GROUP_FOLDER, folder_count); #ifdef _USE_TVPD_MODE g_mutex_unlock(_content_get_db_mutex()); #endif return ret; } int media_folder_foreach_folder_from_db(filter_h filter, media_folder_cb callback, void *user_data) { int ret = MEDIA_CONTENT_ERROR_NONE; content_retip_if_fail(callback); #ifdef _USE_TVPD_MODE g_mutex_lock(_content_get_db_mutex()); #endif ret = _media_db_get_folder(filter, callback, user_data); #ifdef _USE_TVPD_MODE g_mutex_unlock(_content_get_db_mutex()); #endif return ret; } int media_folder_get_media_count_from_db(const char *folder_id, filter_h filter, int *media_count) { int ret = MEDIA_CONTENT_ERROR_NONE; content_retip_if_fail(STRING_VALID(folder_id)); content_retip_if_fail(media_count); #ifdef _USE_TVPD_MODE g_mutex_lock(_content_get_db_mutex()); #endif ret = _media_db_get_group_item_count(folder_id, filter, MEDIA_GROUP_FOLDER, media_count); #ifdef _USE_TVPD_MODE g_mutex_unlock(_content_get_db_mutex()); #endif return ret; } int media_folder_foreach_media_from_db(const char *folder_id, filter_h filter, media_info_cb callback, void *user_data) { int ret = MEDIA_CONTENT_ERROR_NONE; content_retip_if_fail(STRING_VALID(folder_id)); content_retip_if_fail(callback); #ifdef _USE_TVPD_MODE g_mutex_lock(_content_get_db_mutex()); #endif ret = _media_db_get_group_item(folder_id, filter, callback, user_data, MEDIA_GROUP_FOLDER); #ifdef _USE_TVPD_MODE g_mutex_unlock(_content_get_db_mutex()); #endif return ret; } int media_folder_destroy(media_folder_h folder) { media_folder_s *_folder = (media_folder_s*)folder; content_retip_if_fail(folder); g_free(_folder->path); g_free(_folder->name); g_free(_folder->folder_id); g_free(_folder->storage_uuid); g_free(_folder); return MEDIA_CONTENT_ERROR_NONE; } int media_folder_clone(media_folder_h *dst, media_folder_h src) { media_folder_s *_src = (media_folder_s*)src; content_retip_if_fail(dst); content_retip_if_fail(src); media_folder_s *_dst = g_new0(media_folder_s, 1); _dst->folder_id = g_strdup(_src->folder_id); _dst->name = g_strdup(_src->name); _dst->path = g_strdup(_src->path); _dst->storage_uuid = g_strdup(_src->storage_uuid); *dst = (media_folder_h)_dst; return MEDIA_CONTENT_ERROR_NONE; } int media_folder_get_folder_id(media_folder_h folder, char **folder_id) { media_folder_s *_folder = (media_folder_s*)folder; content_retip_if_fail(folder); content_retip_if_fail(folder_id); *folder_id = g_strdup(_folder->folder_id); return MEDIA_CONTENT_ERROR_NONE; } int media_folder_get_path(media_folder_h folder, char **path) { media_folder_s *_folder = (media_folder_s*)folder; content_retip_if_fail(folder); content_retip_if_fail(path); *path = g_strdup(_folder->path); return MEDIA_CONTENT_ERROR_NONE; } int media_folder_get_name(media_folder_h folder, char **name) { media_folder_s *_folder = (media_folder_s*)folder; content_retip_if_fail(folder); content_retip_if_fail(name); *name = g_strdup(_folder->name); return MEDIA_CONTENT_ERROR_NONE; } int media_folder_get_folder_from_db(const char *folder_id, media_folder_h *folder) { int ret = MEDIA_CONTENT_ERROR_NONE; sqlite3_stmt *stmt = NULL; char select_query[DEFAULT_QUERY_SIZE] = {0, }; media_folder_s *_folder = NULL; content_retip_if_fail(STRING_VALID(folder_id)); content_retip_if_fail(folder); snprintf(select_query, sizeof(select_query), SELECT_FOLDER_FROM_FOLDER, folder_id); ret = _content_get_result(select_query, &stmt); content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); if (sqlite3_step(stmt) == SQLITE_ROW) { _folder = g_new0(media_folder_s, 1); _folder->folder_id = g_strdup(folder_id); _folder->path = g_strdup((const char *)sqlite3_column_text(stmt, 0)); _folder->name = g_strdup((const char *)sqlite3_column_text(stmt, 1)); _folder->storage_uuid = g_strdup((const char *)sqlite3_column_text(stmt, 3)); *folder = (media_folder_h)_folder; } sqlite3_finalize(stmt); return ret; } #ifdef _USE_TVPD_MODE int media_folder_update_to_db(media_folder_h folder) { int ret = MEDIA_CONTENT_ERROR_NONE; content_warn("DEPRECATION WARNING: media_folder_update_to_db() is deprecated and will be removed from next release."); media_folder_s *_folder = (media_folder_s*)folder; content_retip_if_fail(folder); content_retip_if_fail(STRING_VALID(_folder->folder_id)); if (!g_src_path) return ret; ret = media_svc_rename_folder(_content_get_db_handle(), _folder->storage_uuid, g_src_path, _folder->path, _content_get_uid()); g_free(g_src_path); g_src_path = NULL; return _content_error_capi(ret); } int media_folder_set_name(media_folder_h folder, const char *name) { int ret = MEDIA_CONTENT_ERROR_NONE; content_warn("DEPRECATION WARNING: media_folder_set_name() is deprecated and will be removed from next release."); media_folder_s *_folder = (media_folder_s*)folder; char *parent_folder_path = NULL; content_retip_if_fail(folder); content_retip_if_fail(STRING_VALID(name)); content_retip_if_fail(name[0] != '.'); content_retip_if_fail(STRING_VALID(_folder->path)); content_retip_if_fail(STRING_VALID(_folder->name)); // Change name.. g_free(_folder->name); _folder->name = g_strdup(name); // Change path.. g_free(g_src_path); g_src_path = g_strdup(_folder->path); g_free(_folder->path); parent_folder_path = g_path_get_dirname(g_src_path); _folder->path = g_strdup_printf("%s/%s", parent_folder_path, name); g_free(parent_folder_path); content_sec_debug("Old[%s] New[%s]", g_src_path, _folder->path); return ret; } int media_folder_get_scan_status(const char *storage_uuid, char* path, media_folder_scan_status_e *scan_status) { int ret = MEDIA_CONTENT_ERROR_NONE; int status = MEDIA_DIR_SCAN_NONE; content_retip_if_fail(STRING_VALID(storage_uuid)); content_retip_if_fail(STRING_VALID(path)); content_retip_if_fail(scan_status); ret = media_svc_get_folder_scan_status(_content_get_db_handle(), path, &status); if (ret != MS_MEDIA_ERR_NONE) { content_error("media_svc_get_folder_scan_status failed"); ret = _content_error_capi(ret); } else { *scan_status = status; } return ret; } int media_folder_reset_scan_status(const char *storage_uuid, const char* path) { int ret = MEDIA_CONTENT_ERROR_NONE; content_retip_if_fail(STRING_VALID(path)); ret = media_svc_set_folder_validity(FALSE, path, 0, TRUE, _content_get_uid()); if (ret != MS_MEDIA_ERR_NONE) { content_error("set folder validity failed"); return _content_error_capi(ret); } ret = media_svc_set_folder_scan_status(storage_uuid, path, MEDIA_DIR_SCAN_NONE, false, _content_get_uid()); if (ret != MS_MEDIA_ERR_NONE) { content_error("media_folder_reset_scan_status failed"); return _content_error_capi(ret); } return ret; } #endif