From 9873a31d83d9404644b32253d2c10230f653867a Mon Sep 17 00:00:00 2001 From: "yujie.cheng" Date: Thu, 17 Jan 2019 17:10:23 +0800 Subject: [PATCH] app need to rename folder in tv Change-Id: Ice0c4ca31ad1eba07376f53112df9927a8c7745e --- include_product/media_content_product.h | 49 +++++++++++++++++++++ src/media_folder.c | 75 +++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+) diff --git a/include_product/media_content_product.h b/include_product/media_content_product.h index 4278699..7eafc89 100755 --- a/include_product/media_content_product.h +++ b/include_product/media_content_product.h @@ -167,6 +167,55 @@ int media_folder_foreach_media_from_db_by_union_select(const char* folder_id, fi int media_folder_get_scan_status(const char *storage_uuid, char* path, media_folder_scan_status_e *scan_status); /** + * @brief Sets the folder name. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * + * @param[in] folder The handle to the media folder + * @param[in] name The name of the media folder + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_INVALID_OPERATION Invalid operation + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + */ +int media_folder_set_name(media_folder_h folder, const char *name); + +/** + * @brief Updates the media folder to the media database. + * + * @details The function updates the given media folder in the media database. The function should be called after any change in folder attributes, to be updated to the media + * database. + * + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * + * @privlevel public + * @privilege %http://tizen.org/privilege/content.write + * + * @param[in] folder The handle to the media folder + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_INVALID_OPERATION Invalid operation + * @retval #MEDIA_CONTENT_ERROR_DB_FAILED DB Operation failed + * @retval #MEDIA_CONTENT_ERROR_DB_BUSY DB Operation busy + * @retval #MEDIA_CONTENT_ERROR_NETWORK Network fail + * @retval #MEDIA_CONTENT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre This function requires opened connection to content service by media_content_connect(). + * + * @see media_content_connect() + * @see media_folder_destroy() + */ +int media_folder_update_to_db(media_folder_h folder); + +/** * @brief insert media folder into database by folder path * @since_tizen 4.0 * diff --git a/src/media_folder.c b/src/media_folder.c index 49f3ded..f14d4a5 100755 --- a/src/media_folder.c +++ b/src/media_folder.c @@ -21,6 +21,10 @@ #include #endif +#ifdef _USE_TVPD_MODE +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; @@ -349,6 +353,77 @@ int media_folder_get_folder_from_db(const char *folder_id, media_folder_h *folde return ret; } #ifdef _USE_TVPD_MODE +int media_folder_update_to_db(media_folder_h folder) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_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; + char repl_path[MAX_PATH_LEN] = {0, }; + + if ((_folder == NULL) || (_folder->folder_id == NULL)) { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + if (STRING_VALID(_folder->folder_id) && g_src_path) { + ret = _media_content_replace_path(_folder->path, repl_path); + if (ret != MEDIA_CONTENT_ERROR_NONE) { + SAFE_FREE(g_src_path); + return ret; + } + ret = media_svc_rename_folder(_content_get_db_handle(), _folder->storage_uuid, g_src_path, repl_path, _content_get_uid()); + SAFE_FREE(g_src_path); + + return _content_error_capi(MEDIA_CONTENT_TYPE, ret); + } + + return ret; +} + +int media_folder_set_name(media_folder_h folder, const char *name) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_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; + + if (_folder != NULL && STRING_VALID(name) && name[0] != '.') { + if (STRING_VALID(_folder->path) && STRING_VALID(_folder->name)) { + char *folder_path = NULL; + char new_folder_path[MAX_PATH_LEN] = {0,}; + char repl_path[MAX_PATH_LEN] = {0, }; + + memset(repl_path, 0, sizeof(repl_path)); + ret = _media_content_replace_path(_folder->path, repl_path); + media_content_retvm_if(!STRING_VALID(repl_path), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed"); + + folder_path = g_path_get_dirname(repl_path); + media_content_sec_debug("Existed Folder Path : %s", repl_path); + snprintf(new_folder_path, sizeof(new_folder_path), "%s/%s", folder_path, name); + media_content_sec_debug("New Path : %s", new_folder_path); + + SAFE_FREE(g_src_path); + g_src_path = strdup(repl_path); + + SAFE_FREE(_folder->path); + SAFE_FREE(_folder->name); + SAFE_FREE(folder_path); + + _folder->path = strdup(new_folder_path); + media_content_retvm_if(_folder->path == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); + _folder->name = strdup(name); + media_content_retvm_if(_folder->name == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); + } else { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + } else { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + int media_folder_insert_to_db(const char *path) { char repl_path[MAX_PATH_LEN] = {0, }; -- 2.7.4