diff options
Diffstat (limited to 'src/common/file-system/mf-ug-file-attr.c')
-rw-r--r--[-rwxr-xr-x] | src/common/file-system/mf-ug-file-attr.c | 308 |
1 files changed, 267 insertions, 41 deletions
diff --git a/src/common/file-system/mf-ug-file-attr.c b/src/common/file-system/mf-ug-file-attr.c index 082e394..58ef220 100755..100644 --- a/src/common/file-system/mf-ug-file-attr.c +++ b/src/common/file-system/mf-ug-file-attr.c @@ -1,17 +1,20 @@ /* + * myfile + * * Copyright 2012 Samsung Electronics Co., Ltd * * Licensed under the Flora License, Version 1.0 (the "License"); - * - * You may not use this file except in compliance with 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.tizenopensource.org/license * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an "AS IS" BASIS, + * 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. * - * See the License for the specific language governing permissions and limitations under the License. */ @@ -19,13 +22,35 @@ #include <regex.h> #include <sys/types.h> -#include <aul.h> -#include <visual-svc.h> -#include <media-svc.h> +#include <media_content.h> +#include <drm_client.h> +#include <drm_client_types.h> #include "mf-ug-fs-util.h" +#include "mf-ug-util.h" #define MF_UG_PHONE_DEFAULT_LEVEL 2 /*the phone path is /opt/media, it consists of opt and media two parts*/ #define MF_UG_MMC_DEFAULT_LEVEL 3 /*the mmc path is /opt/storage/sdcard, it consists of opt and storage and sdcard three parts*/ +#define CONDITION_LENGTH 200 +#define UG_CONDITION_IMAGE_VIDEO "(MEDIA_TYPE=0 OR MEDIA_TYPE=1)" + +typedef struct __ug_filter_s ug_filter_s; +struct __ug_filter_s { + char *cond; /*set media type or favorite type, or other query statement*/ + media_content_collation_e collate_type; /*collate type*/ + media_content_order_e sort_type; /*sort type*/ + char *sort_keyword; /*sort keyword*/ + int offset; /*offset*/ + int count; /*count*/ + bool with_meta; /*whether get image or video info*/ +}; + +typedef struct __ug_transfer_data_s ug_transfer_data_s; + +struct __ug_transfer_data_s { + const char *file_path; + char *thumbnail_path; +}; + struct _ug_ftype_by_mime { const char *mime; @@ -203,7 +228,14 @@ static mf_ug_fs_file_type __mf_ug_file_attr_get_category_by_file_ext(const char return UG_FILE_TYPE_DOC; } if (strcasecmp("DIVX", &file_ext[i]) == 0) { - return UG_FILE_TYPE_VIDEO; + if (mf_ug_file_attr_is_drm_file(fullpath) == 0) { + return UG_FILE_TYPE_DRM; + } else { + return UG_FILE_TYPE_VIDEO; + } + } + if (strcasecmp("DCF", &file_ext[i]) == 0) { + return UG_FILE_TYPE_DRM; } break; case 'g': @@ -425,7 +457,7 @@ static mf_ug_fs_file_type __mf_ug_file_attr_get_category_by_file_ext(const char } /********************* -**Function name: __mf_ug_file_attr_is_valid_name +**Function name: mf_ug_file_attr_is_valid_name **Parameter: ** const char *filename: the file/dir name we need to check ** @@ -437,7 +469,7 @@ static mf_ug_fs_file_type __mf_ug_file_attr_get_category_by_file_ext(const char ** check if the name is valid by file name ** *********************/ -static int __mf_ug_file_attr_is_valid_name(const char *filename) +int mf_ug_file_attr_is_valid_name(const char *filename) { char *pattern; int ret, z, cflags = 0; @@ -675,6 +707,33 @@ int mf_ug_file_attr_get_store_type_by_full(const char *filepath, mf_ug_storage_t } /********************* +**Function name: mf_ug_file_attr_is_drm_file +**Parameter: +** const char* filepath: file full path +** +**Return value: +** true if it is a DRM file +** false if it is not a DRM file +** +**Action: +** check if file is drm file +** +*********************/ +int mf_ug_file_attr_is_drm_file(const char *file_fullpath) +{ + if (file_fullpath == NULL) + return MYFILE_ERR_DRM_PERMISSION_DENY; + drm_bool_type_e drmFlag = DRM_FALSE; + int res = 0; + res = drm_is_drm_file(file_fullpath, &drmFlag); + + if (res == DRM_RETURN_SUCCESS && drmFlag == DRM_TRUE) + return 0; + else + return MYFILE_ERR_DRM_PERMISSION_DENY; +} + +/********************* **Function name: mf_ug_file_attr_get_file_ext **Parameter: ** const char* filepath: file full path @@ -687,8 +746,11 @@ int mf_ug_file_attr_get_store_type_by_full(const char *filepath, mf_ug_storage_t ** get file extension by file full path ** *********************/ -int mf_ug_file_attr_get_file_ext(const char *filepath, char *file_ext) +int mf_ug_file_attr_get_file_ext(const char *filepath, char **file_ext) { + ug_mf_retvm_if(filepath == NULL, MYFILE_ERR_INVALID_FILE_NAME, "filepath is NULL"); + ug_mf_retvm_if(file_ext == NULL, MYFILE_ERR_INVALID_FILE_NAME, "file_ext is NULL"); + const char *filename = NULL; filename = ecore_file_file_get(filepath); @@ -701,7 +763,7 @@ int mf_ug_file_attr_get_file_ext(const char *filepath, char *file_ext) if (!pdot) { return MYFILE_ERR_EXT_GET_ERROR; } else if (pdot != filepath) { - memcpy(file_ext, pdot + 1, strlen(pdot) - 1); + *file_ext = g_strdup(pdot + 1); return MYFILE_ERR_NONE; } else { return MYFILE_ERR_EXT_GET_ERROR; @@ -742,7 +804,7 @@ int mf_ug_file_attr_is_right_dir_path(const char *dir_path) const char *file_name = NULL; file_name = ecore_file_file_get(dir_path); - result = __mf_ug_file_attr_is_valid_name(file_name); + result = mf_ug_file_attr_is_valid_name(file_name); if (result != MYFILE_ERR_NONE) { ug_mf_error("Is NOT Valid dir path name"); @@ -777,7 +839,7 @@ int mf_ug_file_attr_is_right_file_path(const char *file_path) const char *file_name = NULL; file_name = ecore_file_file_get(file_path); - result = __mf_ug_file_attr_is_valid_name(file_name); + result = mf_ug_file_attr_is_valid_name(file_name); if (result != MYFILE_ERR_NONE) { ug_mf_error("Is NOT Valid dir path name"); } @@ -786,8 +848,136 @@ int mf_ug_file_attr_is_right_file_path(const char *file_path) } +static int __mf_ug_create_filter(filter_h *filter, ug_filter_s *condition) +{ + ug_mf_retvm_if(filter == NULL, -1, "filter is NULL"); + ug_mf_retvm_if(condition == NULL, -1, "condition is NULL"); + + int ret = MEDIA_CONTENT_ERROR_NONE; + filter_h tmp_filter = NULL; + ret = media_filter_create(&tmp_filter); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + ug_debug("Fail to create filter"); + return ret; + } + if (condition->cond) { + ret = media_filter_set_condition(tmp_filter, condition->cond, + condition->collate_type); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + ug_debug("Fail to set condition"); + goto ERROR; + } + } + + if (condition->sort_keyword) { + ret = media_filter_set_order(tmp_filter, condition->sort_type, + condition->sort_keyword, + condition->collate_type); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + ug_debug("Fail to set order"); + goto ERROR; + } + } + + ug_debug("offset is %d, count is %d", condition->offset, condition->count); + if (condition->offset != -1 && condition->count != -1 && + condition->count > condition->offset) { + ret = media_filter_set_offset(tmp_filter, condition->offset, + condition->count); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + ug_debug("Fail to set offset"); + goto ERROR; + } + } + *filter = tmp_filter; + return ret; + ERROR: + if (tmp_filter) { + media_filter_destroy(*filter); + tmp_filter = NULL; + *filter = NULL; + } + return ret; +} + +static int __mf_ug_destroy_filter(filter_h filter) +{ + ug_mf_retvm_if(filter == NULL, -1, "filter is NULL"); + int ret = MEDIA_CONTENT_ERROR_NONE; + ret = media_filter_destroy(filter); + + return ret; +} + +static bool __mf_ug_local_data_get_media_thumbnail_cb(media_info_h media, void *data) +{ + ug_mf_retvm_if(data == NULL, -1, "filter is NULL"); + ug_transfer_data_s *tmp_data = (ug_transfer_data_s *)data; + + char *file_path = NULL; + char *thumbnail_path = NULL; + + media_info_get_thumbnail_path(media, &(tmp_data->thumbnail_path)); + + return false; +} + + -char *mf_ug_file_attr_get_file_icon(MediaSvcHandle *handle, const char *file_path, int *error_code) +int static __mf_ug_local_thumbnail_get(void *data, ug_filter_s *condition) +{ + + int ret = -1; + filter_h filter = NULL; + ret = __mf_ug_create_filter(&filter, condition); + if (ret != 0) { + ug_debug("Create filter failed"); + return ret; + } + + + ret = media_info_foreach_media_from_db(filter, + __mf_ug_local_data_get_media_thumbnail_cb, + data); + if (ret != 0) { + ug_debug("media_info_foreach_media_from_db failed: %d", ret); + } else { + ug_debug("media_info_foreach_media_from_db success!", ret); + } + __mf_ug_destroy_filter(filter); + + return ret; + +} + +const char *mf_ug_file_attr_get_thumbnail(void *data) +{ + ug_mf_retvm_if(data == NULL, -1, "data is NULL"); + + ug_transfer_data_s *mp_data = (ug_transfer_data_s *)data; + ug_filter_s filter; + int ret = -1; + + memset(&filter, 0, sizeof(ug_filter_s)); + + char *condition = NULL; + condition = g_strdup_printf("%s and MEDIA_PATH=\"%s\"", UG_CONDITION_IMAGE_VIDEO, mp_data->file_path); + ug_debug("condition [%s]", condition); + filter.cond = condition; + filter.collate_type = MEDIA_CONTENT_COLLATE_DEFAULT; + filter.sort_type = MEDIA_CONTENT_ORDER_DESC; + filter.sort_keyword = MEDIA_MODIFIED_TIME; + filter.with_meta = true; + + ret = __mf_ug_local_thumbnail_get(data, &filter); + UG_SAFE_FREE_CHAR(condition); + + + + return ret; +} + +char *mf_ug_file_attr_get_file_icon(const char *file_path, int *error_code) { int index = 0; char *icon_path = NULL; @@ -812,35 +1002,15 @@ char *mf_ug_file_attr_get_file_icon(MediaSvcHandle *handle, const char *file_pat switch (ftype) { case UG_FILE_TYPE_IMAGE: - { - int err = 0; - thumbnail_path = calloc(1, (MYFILE_FILE_PATH_LEN_MAX + 1)); - if (thumbnail_path == NULL) { - return NULL; - } - - err = minfo_get_thumb_path(handle, file_path, thumbnail_path, MYFILE_FILE_PATH_LEN_MAX); - if (err == 0) { - icon_path = thumbnail_path; - } else { - icon_path = NULL; - if (error_code) - *error_code = err; - } - } - break; case UG_FILE_TYPE_VIDEO: { int err = 0; - thumbnail_path = calloc(1, (MYFILE_FILE_PATH_LEN_MAX + 1)); - if (thumbnail_path == NULL) { - return NULL; - } - - err = minfo_get_thumb_path_for_video(handle, file_path, thumbnail_path, MYFILE_FILE_PATH_LEN_MAX); - + ug_transfer_data_s tmp_data; + memset(&tmp_data,0x00,sizeof(ug_transfer_data_s)); + tmp_data.file_path = file_path; + err = mf_ug_file_attr_get_thumbnail(&tmp_data);//minfo_get_thumb_path(handle, file_path, image_thumb, sizeof(image_thumb)); if (err == 0) { - icon_path = thumbnail_path; + icon_path = g_strdup(tmp_data.thumbnail_path); } else { icon_path = NULL; if (error_code) @@ -1070,3 +1240,59 @@ mf_ug_fs_file_type mf_ug_file_attr_get_file_type_by_mime(const char *file_path) return ftype; } + +int mf_ug_file_attr_is_duplicated_name(const char *dir, const char *name) +{ + + char *file_path = g_strconcat(dir, "/", name, NULL); + if (ecore_file_exists(file_path)) { + UG_SAFE_FREE_CHAR(file_path); + return MYFILE_ERR_DUPLICATED_NAME; + } else { + UG_SAFE_FREE_CHAR(file_path); + return MYFILE_ERR_NONE; + } +} + +int mf_ug_file_attr_get_logical_path_by_full(const char *full_path, char **path) +{ + ug_mf_retvm_if(full_path == NULL, MYFILE_ERR_INVALID_FILE_PATH, "fullpath is NULL"); + ug_mf_retvm_if(path == NULL, MYFILE_ERR_INVALID_FILE_PATH, "path is NULL"); + + mf_ug_storage_type store_type = 0; + int root_len = 0; + int error_code = 0; + + error_code = mf_ug_file_attr_get_store_type_by_full(full_path, &store_type); + + *path = g_strdup(full_path); + if (*path == NULL) { + return MYFILE_ERR_ALLOCATE_MEMORY_FAIL; + } + + memset(*path, 0, strlen(*path)); + switch (store_type) { + case MF_UG_PHONE: + root_len = strlen(PHONE_FOLDER); + break; + case MF_UG_MMC: + root_len = strlen(MEMORY_FOLDER); + break; + default: + return MYFILE_ERR_STORAGE_TYPE_ERROR; + } + + /* + ** *path has the same length with full_path + ** strlen(*path) is 0 since the memset called + ** we use length of full_path to reprecent the *path's + */ + g_strlcpy(*path, full_path + root_len, strlen(full_path)); + if (strlen(*path) == 0) { + UG_SAFE_FREE_CHAR(*path); + *path = g_strdup("/"); + } + + return MYFILE_ERR_NONE; +} + |