summaryrefslogtreecommitdiff
path: root/src/common/mf-ug-fm-svc-wapper.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/mf-ug-fm-svc-wapper.c')
-rw-r--r--[-rwxr-xr-x]src/common/mf-ug-fm-svc-wapper.c420
1 files changed, 413 insertions, 7 deletions
diff --git a/src/common/mf-ug-fm-svc-wapper.c b/src/common/mf-ug-fm-svc-wapper.c
index c7296e0..f4eb7f9 100755..100644
--- a/src/common/mf-ug-fm-svc-wapper.c
+++ b/src/common/mf-ug-fm-svc-wapper.c
@@ -1,22 +1,25 @@
/*
+ * 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.
*/
-
+#include <sys/statvfs.h>
#include "mf-ug-util.h"
#include "mf-ug-cb.h"
@@ -95,6 +98,7 @@ static int __mf_ug_fm_svc_wapper_COMESFROM(char *fullpath)
******************************/
static int __mf_ug_fm_svc_wapper_get_file_list(GString *fullpath, Eina_List **dir_list, Eina_List **file_list)
{
+ UG_TRACE_BEGIN;
ug_mf_retvm_if(fullpath == NULL, MYFILE_ERR_INVALID_ARG, "fullpath is NULL");
ug_mf_retvm_if(fullpath->str == NULL, MYFILE_ERR_INVALID_ARG, "fullpath->str is NULL");
ug_mf_retvm_if(fullpath->len == 0, MYFILE_ERR_INVALID_ARG, "fullpath->len is 0");
@@ -107,6 +111,7 @@ static int __mf_ug_fm_svc_wapper_get_file_list(GString *fullpath, Eina_List **di
} else {
ug_debug("success get the file list\n");
}
+ UG_TRACE_END;
return error_code;
}
@@ -166,6 +171,54 @@ unsigned long mf_ug_fm_svc_wapper_get_file_filter(int file_filter_mode)
return filter;
}
+int mf_ug_fm_svc_wapper_get_drm_filter(int drm_filter_mode, unsigned long file_filter)
+{
+ int drm_filter = 0;
+ unsigned long filter = file_filter;
+ unsigned long all = (unsigned long)(UG_FILTER_CATEGORY_ALL);
+
+ switch (drm_filter_mode) {
+ case DRM_FILTER_ALL:
+ if (filter == all) {
+ ug_debug("drm_filter is ALL");
+ drm_filter |= MF_UG_FILTER_DRM_ALL;
+ } else {
+ if (filter & UG_FILTER_CATEGORY_IMAGE) {
+ ug_debug("drm_filter is IMAGE");
+ drm_filter |= MF_UG_FILTER_DRM_IMAGE;
+ }
+ if (filter & UG_FILTER_CATEGORY_SOUND) {
+ ug_debug("drm_filter is SOUND");
+ drm_filter |= MF_UG_FILTER_DRM_RINGTONE;
+ }
+ if (filter & UG_FILTER_CATEGORY_MUSIC) {
+ ug_debug("drm_filter is MUSIC");
+ drm_filter |= MF_UG_FILTER_DRM_RINGTONE;
+ }
+ }
+ break;
+ case DRM_FILTER_WITHOUT_FL:
+ drm_filter |= MF_UG_FILTER_DRM_WITHOUT_FL;
+ if (filter == all) {
+ drm_filter |= MF_UG_FILTER_DRM_ALL;
+ } else {
+ if (filter & UG_FILTER_CATEGORY_IMAGE) {
+ drm_filter |= MF_UG_FILTER_DRM_IMAGE;
+ }
+ if (filter & UG_FILTER_CATEGORY_SOUND) {
+ drm_filter |= MF_UG_FILTER_DRM_RINGTONE;
+ }
+ if (filter & UG_FILTER_CATEGORY_MUSIC) {
+ drm_filter |= MF_UG_FILTER_DRM_RINGTONE;
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ return drm_filter;
+}
+
int mf_ug_fm_svc_wapper_get_file_list_by_filter(ugData *data, GString *fullpath, Eina_List **dir_list, Eina_List **filter_list)
{
ugData *ugd = data;
@@ -177,12 +230,14 @@ int mf_ug_fm_svc_wapper_get_file_list_by_filter(ugData *data, GString *fullpath,
int error_code = 0;
int filter_mode = 0;
int file_filter = 0;
+ int drm_filter = 0;
int file_list_len = 0;
Eina_List *file_list = NULL;
char *extension = NULL;
filter_mode = ugd->ug_UiGadget.ug_iFilterMode;
file_filter = ugd->ug_UiGadget.ug_iFileFilter;
+ drm_filter = ugd->ug_UiGadget.ug_iDrmFilter;
ug_debug("fullpath is [%s]", fullpath->str);
error_code = __mf_ug_fm_svc_wapper_get_file_list(fullpath, dir_list, &file_list);
@@ -195,7 +250,8 @@ int mf_ug_fm_svc_wapper_get_file_list_by_filter(ugData *data, GString *fullpath,
ug_debug("file_filter is [%d]\n", filter_mode);
if (filter_mode != SHOW_BY_EXTENSION) {
- error_code = mf_ug_fs_oper_list_filter(file_list, filter_list, file_filter);
+ ug_debug("file_filter is [%d] drm_filter is [%d]", file_filter, drm_filter);
+ error_code = mf_ug_fs_oper_list_filter(file_list, filter_list, file_filter, drm_filter);
} else if (ugd->ug_UiGadget.ug_pExtension != NULL) {
extension = strdup(ugd->ug_UiGadget.ug_pExtension);
error_code = mf_ug_fs_oper_list_filter_by_extension(file_list, filter_list, extension);
@@ -545,3 +601,353 @@ char *mf_ug_fm_svc_wapper_path_info_get(char *original_path)
}
+unsigned long mf_ug_fm_svc_wrapper_get_free_space(int state)
+{
+ struct statvfs info;
+ char *path = NULL;
+
+ if (state == MF_UG_PHONE) {
+ path = PHONE_FOLDER;
+ } else if (state == MF_UG_MMC) {
+ path = MEMORY_FOLDER;
+ } else {
+ return -1;
+ }
+
+ if (-1 == statvfs(path, &info)) {
+ return -2;
+ }
+ return (info.f_bsize) * info.f_bfree;
+}
+
+bool mf_ug_fm_svc_wrapper_detect_duplication(GString *to)
+{
+ int existing = MYFILE_ERR_NONE;
+ if (to == NULL) {
+ return false;
+ }
+ GString *parent_path = mf_ug_fm_svc_wrapper_get_file_parent_path(to);
+ GString *file_name = mf_ug_fm_svc_wapper_get_file_name(to);
+
+ ug_debug("full path and file name %s", to->str);
+ if (file_name == NULL || parent_path == NULL || file_name->len == 0) {
+ return false;
+ }
+
+ if (parent_path->str != NULL) {
+ ug_debug("parent_path->str is %s", parent_path->str);
+ }
+ if (file_name->str != NULL) {
+ ug_debug("file_name->str is %s", file_name->str);
+ }
+
+ existing = mf_ug_file_attr_is_duplicated_name(parent_path->str, file_name->str);
+
+ ug_debug("EXIST result is %d", existing);
+
+ if (parent_path != NULL) {
+ g_string_free(parent_path, TRUE);
+ }
+ parent_path = NULL;
+
+ if (file_name != NULL) {
+ g_string_free(file_name, TRUE);
+ }
+ file_name = NULL;
+
+ if (existing == MYFILE_ERR_NONE) {
+ return false;
+ } else {
+ return true;
+ }
+}
+
+static int __mf_ug_fm_svc_wrapper_get_next_number(char *file_name_without_ext, int file_name_type)
+{
+ int nCount = 0;
+ int nLength = 0;
+ int nUnderline = 0;
+ bool bAllDigits = true;
+ int i;
+
+ /* check _02d format */
+ nLength = strlen(file_name_without_ext);
+
+ if (file_name_type == FILE_NAME_WITH_UNDERLINE) {
+ if (nLength < 3) { /*4 means the # of minimum characters (*_n) */
+ return 1; /*doesn't match */
+ } else { /* input is more than 3 bytes */
+ /* find '_' */
+ for (nUnderline = nLength - 1; nUnderline >= 0; nUnderline--) {
+ if (file_name_without_ext[nUnderline] == '_') {
+ break;
+ }
+ }
+
+ if (nUnderline == 0 && file_name_without_ext[0] != '_') {
+ return 1; /* doesn't match */
+ }
+ /* check the right characters are all digits */
+ for (i = nUnderline + 1; i < nLength; i++) {
+ if (file_name_without_ext[i] < '0' || file_name_without_ext[i] > '9') {
+ bAllDigits = false;
+ break;
+ }
+ }
+
+ if (bAllDigits) {
+ for (i = nUnderline + 1; i < nLength; i++) {
+ nCount *= 10;
+ nCount += file_name_without_ext[i] - '0';
+ }
+
+ file_name_without_ext[nUnderline] = '\0'; /* truncate the last '_dd' */
+ }
+ }
+ } else {
+
+ if (nLength < 5) { /* 5 means the # of minimum characters (*_(n)) */
+ return 1; /*doesn't match */
+ } else { /* input is more than 3 bytes */
+ /* find '_' */
+ for (nUnderline = nLength - 1; nUnderline >= 0; nUnderline--) {
+ if (file_name_without_ext[nUnderline] == '(') {
+ break;
+ }
+ }
+
+ if (nUnderline == 0 && file_name_without_ext[0] != '(') {
+ return 1; /* doesn't match */
+ }
+ /* check the right characters are all digits */
+ for (i = nUnderline + 1; i < nLength - 1; i++) {
+ if (file_name_without_ext[i] < '0' || file_name_without_ext[i] > '9') {
+ bAllDigits = false;
+ break;
+ }
+ }
+
+ /* and more than 2 columns. */
+ if (bAllDigits) {
+ for (i = nUnderline + 1; i < nLength - 1; i++) {
+ nCount *= 10;
+ nCount += file_name_without_ext[i] - '0';
+ }
+
+ file_name_without_ext[nUnderline] = '\0'; /* truncate the last '_dd' */
+ }
+ }
+ }
+
+ /* increase nCount by 1 */
+ nCount++;
+
+ return nCount;
+}
+
+
+static int __mf_ug_fm_svc_wrapper_get_unique_name(const char *default_dir_full_path, char *original_file_name, char **unique_file_name,
+ int file_name_type, void *data)
+{
+ ug_mf_retvm_if(unique_file_name == NULL, MYFILE_ERR_SRC_ARG_INVALID, "unique_file_name is NULL");
+ ug_mf_retvm_if(data == NULL, MYFILE_ERR_SRC_ARG_INVALID, "data is NULL");
+
+ char *file_name_without_ext = NULL;
+ char *file_ext = NULL;
+ char *new_file_name = NULL;
+ bool result = false;
+ char *dir_rel_path = NULL;
+ int slash = 1;
+ int nCount = 0;
+ bool bExt = false;
+ int error_code = 0;
+
+ if (default_dir_full_path == NULL || original_file_name == NULL) {
+ ug_debug("default_dir_full_path == NULL || \
+ original_file_name == NULL || \
+ unique_file_name == NULL || \
+ error_code == NULL ");
+ error_code = MYFILE_ERR_SRC_ARG_INVALID;
+ goto Exception;
+ }
+ result = mf_ug_file_attr_get_logical_path_by_full(default_dir_full_path, &dir_rel_path);
+
+ if (result) {
+ error_code = MYFILE_ERR_GET_LOGIC_PATH_FAIL;
+ goto Exception;
+ }
+
+ if (strncmp(dir_rel_path, "/", strlen(dir_rel_path)) == 0) {
+ slash = 0;
+ }
+
+ error_code = mf_ug_file_attr_is_duplicated_name(default_dir_full_path, original_file_name);
+ if (error_code == 0) {
+ ug_debug("unique_file_name [%s]", *unique_file_name);
+ ug_debug("original_file_name [%s]", new_file_name);
+ *unique_file_name = g_strdup(original_file_name);
+ ug_debug("unique_file_name [%s]", *unique_file_name);
+ }
+
+ while (error_code < 0) {
+ error_code = 0;
+ bExt = mf_ug_file_attr_get_file_ext(original_file_name, &file_ext);
+ file_name_without_ext = g_strdup(original_file_name);
+
+ if (file_name_without_ext == NULL) {
+ error_code = MYFILE_ERR_ALLOCATE_MEMORY_FAIL;
+ goto Exception;
+ }
+
+ /* add a condition, whether extention is or not. */
+ if (bExt == 0) {
+ file_name_without_ext[strlen(file_name_without_ext) - strlen(file_ext) - 1] = '\0';
+ }
+
+ nCount = __mf_ug_fm_svc_wrapper_get_next_number(file_name_without_ext, file_name_type);
+ if (nCount == 1 && file_name_type == FILE_NAME_WITH_BRACKETS) {
+ char *file_name_with_space = g_strconcat(file_name_without_ext, " ", NULL);
+ if (file_name_with_space) {
+ UG_SAFE_FREE_CHAR(file_name_without_ext);
+ file_name_without_ext = file_name_with_space;
+ file_name_with_space = NULL;
+ }
+ }
+
+ if (bExt == 0) {
+ if (file_name_type == FILE_NAME_WITH_BRACKETS)
+ new_file_name = g_strdup_printf("%s(%d).%s", file_name_without_ext, nCount, file_ext);
+ else
+ new_file_name = g_strdup_printf("%s_%d.%s", file_name_without_ext, nCount, file_ext);
+ } else {
+
+ if (file_name_type == FILE_NAME_WITH_BRACKETS)
+ new_file_name = g_strdup_printf("%s(%d)", file_name_without_ext, nCount);
+ else
+ new_file_name = g_strdup_printf("%s_%d", file_name_without_ext, nCount);
+ }
+ UG_SAFE_FREE_CHAR(file_name_without_ext);
+
+ ug_debug("new name is %s\n", new_file_name);
+
+ if (error_code != 0) {
+ original_file_name = g_strdup(new_file_name);
+ error_code = MYFILE_ERR_DUPLICATED_NAME;
+ UG_SAFE_FREE_CHAR(new_file_name);
+ UG_SAFE_FREE_CHAR(file_ext);
+ continue;
+ } else {
+ error_code = mf_ug_file_attr_is_duplicated_name(default_dir_full_path, new_file_name);
+ if (error_code == 0) {
+ *unique_file_name = g_strdup(new_file_name);
+ //ug_debug("rename finished\n");
+ error_code = MYFILE_ERR_NONE;
+ goto Exception;
+ } else {
+ //ug_debug("rename continue\n");
+ original_file_name = g_strdup(new_file_name);
+ UG_SAFE_FREE_CHAR(new_file_name);
+ }
+ }
+ UG_SAFE_FREE_CHAR(file_ext);
+ }
+
+ return MYFILE_ERR_NONE;
+
+Exception:
+ UG_SAFE_FREE_CHAR(dir_rel_path);
+ UG_SAFE_FREE_CHAR(file_ext);
+ UG_SAFE_FREE_CHAR(new_file_name);
+ return error_code;
+}
+
+int mf_ug_fm_svc_wrapper_file_auto_rename(void *data, GString *fullpath, int file_name_type, GString **filename)
+{
+ ug_mf_retvm_if(data == NULL, MYFILE_ERR_SRC_ARG_INVALID, "data is NULL");
+ ugData *ugd = (ugData *)data;
+
+ GString *parent_path = mf_ug_fm_svc_wrapper_get_file_parent_path(fullpath);
+ GString *file_name = mf_ug_fm_svc_wapper_get_file_name(fullpath);
+
+ if (parent_path == NULL || file_name == NULL) {
+ return MYFILE_ERR_GENERATE_NAME_FAIL;
+ }
+ if (parent_path->str == NULL || parent_path->str == NULL) {
+ g_string_free(parent_path, TRUE);
+ parent_path = NULL;
+ g_string_free(file_name, TRUE);
+ file_name = NULL;
+ return MYFILE_ERR_GENERATE_NAME_FAIL;
+ }
+
+ char *name = NULL;
+ int error_code = 0;
+
+ if (parent_path->str != NULL) {
+ //mf_debug("parent_full_path is [%s]", parent_path->str);
+ }
+
+ if (file_name->str != NULL) {
+ //mf_debug("original_file_name is [%s]", file_name->str);
+ }
+ error_code = __mf_ug_fm_svc_wrapper_get_unique_name(parent_path->str, file_name->str, &name, file_name_type, ugd);
+ if (error_code) {
+ UG_SAFE_FREE_CHAR(name);
+ return MYFILE_ERR_GENERATE_NAME_FAIL;
+ }
+ g_string_append_printf(parent_path, "/%s", name);
+ ug_debug("After gstring append, PATH ::: [%s]", parent_path->str);
+
+ if (file_name != NULL) {
+ g_string_free(file_name, TRUE);
+ }
+
+ file_name = NULL;
+ if (name != NULL) {
+ free(name);
+ name = NULL;
+ }
+
+ *filename = parent_path;
+ return MYFILE_ERR_NONE;
+}
+
+int mf_ug_fm_svc_wrapper_create_service(void *data, GString *fullpath)
+{
+ int error_code;
+
+ mf_ug_util_remove_dir_watch();
+ error_code = mf_ug_fs_oper_create_dir(fullpath->str);
+
+ if (error_code != 0) {
+ ug_debug("Make DIR error\n");
+ }
+
+ return error_code;
+}
+
+int mf_ug_fm_svc_wrapper_create_p(const char *fullpath)
+{
+ UG_TRACE_BEGIN;
+
+ ug_debug("path is [%s]", fullpath);
+ int error_code = MYFILE_ERR_NONE;
+
+ char *parent = NULL;
+ error_code = mf_ug_file_attr_get_parent_path(fullpath, &parent);
+
+ goto_if(error_code != MYFILE_ERR_NONE, EXIT);
+
+ if (ecore_file_exists(parent) == false) {
+ error_code = mf_ug_fm_svc_wrapper_create_p(parent);
+ goto_if(error_code != MYFILE_ERR_NONE, EXIT);
+
+ }
+
+ ug_debug("create [%s]", fullpath);
+ error_code = mf_ug_fs_oper_create_dir(fullpath);
+ goto_if(error_code != MYFILE_ERR_NONE, EXIT);
+
+EXIT:
+ return error_code;
+}