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')
-rwxr-xr-xsrc/common/mf-ug-fm-svc-wapper.c547
1 files changed, 547 insertions, 0 deletions
diff --git a/src/common/mf-ug-fm-svc-wapper.c b/src/common/mf-ug-fm-svc-wapper.c
new file mode 100755
index 0000000..c7296e0
--- /dev/null
+++ b/src/common/mf-ug-fm-svc-wapper.c
@@ -0,0 +1,547 @@
+/*
+ * 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 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,
+ * 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 "mf-ug-util.h"
+#include "mf-ug-cb.h"
+#include "mf-ug-main.h"
+#include "mf-ug-fm-svc-wrapper.h"
+#include "mf-ug-fs-util.h"
+#include "mf-ug-resource.h"
+
+#define UG_FILTER_CATEGORY_ALL \
+UG_FILTER_CATEGORY_NONE | UG_FILTER_CATEGORY_IMAGE | UG_FILTER_CATEGORY_VIDEO \
+| UG_FILTER_CATEGORY_SOUND | UG_FILTER_CATEGORY_VOICE | UG_FILTER_CATEGORY_MUSIC \
+| UG_FILTER_CATEGORY_HTML | UG_FILTER_CATEGORY_FLASH | UG_FILTER_CATEGORY_GAME \
+| UG_FILTER_CATEGORY_APP | UG_FILTER_CATEGORY_THEME | UG_FILTER_CATEGORY_DOC \
+| UG_FILTER_CATEGORY_EXCEL | UG_FILTER_CATEGORY_PPT | UG_FILTER_CATEGORY_PDF \
+| UG_FILTER_CATEGORY_TXT | UG_FILTER_CATEGORY_VCONTACT | UG_FILTER_CATEGORY_VCALENDAR \
+| UG_FILTER_CATEGORY_VNOTE | UG_FILTER_CATEGORY_VBOOKMARK | UG_FILTER_CATEGORY_VIDEO_PROJECT\
+| UG_FILTER_CATEGORY_SVG | UG_FILTER_CATEGORY_ETC
+
+
+#define MF_UG_PATH_INFO_RETRENCH 128
+#define MF_UG_PATH_INFO_HEAD_LEN(x) strlen(x)
+#define MF_UG_PATH_INFO_TRANS_OMIT elm_entry_utf8_to_markup("..")
+#define MF_UG_PATH_INFO_LEVEL_BOUNDARY 3
+#define MF_UG_PATH_INFO_LEN_THRESHOLD 4
+#define MF_UG_PATH_INFO_SEP elm_entry_utf8_to_markup("/")
+typedef struct {
+ int len_orig;
+ int len_trans;
+ char *original;
+ char *transfer;
+ bool flag_trans;
+}ug_pNode;
+
+/*********************
+**Function name: __mf_ug_fm_svc_wapper_COMESFROM
+**Parameter:
+** GString* fullpath: fullpath to check the location
+**
+**Return value:
+** location of the path
+**
+**Action:
+** get storage type by fullpath
+*********************/
+static int __mf_ug_fm_svc_wapper_COMESFROM(char *fullpath)
+{
+ int len_phone = strlen(PHONE_FOLDER);
+ int len_memory = strlen(MEMORY_FOLDER);
+
+ if (strncmp(fullpath, PHONE_FOLDER, len_phone) == 0) {
+ return MF_UG_PHONE;
+ } else if (strncmp(fullpath, MEMORY_FOLDER, len_memory) == 0) {
+ return MF_UG_MMC;
+ } else {
+ return MYFILE_ERR_STORAGE_TYPE_ERROR;
+ }
+}
+
+/******************************
+** Prototype : _ug_mf_get_file_list
+** Description :
+** Input : struct ugmyfiledata *data
+** GString* folder_name
+** Eina_List** dir_list
+** Eina_List** file_list
+** Output : None
+** Return Value :
+** Calls :
+** Called By :
+**
+** History :
+** 1.Date : 2010/12/10
+** Author : Samsung
+** Modification : Created function
+**
+******************************/
+static int __mf_ug_fm_svc_wapper_get_file_list(GString *fullpath, Eina_List **dir_list, Eina_List **file_list)
+{
+ 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");
+
+ int error_code = 0;
+
+ error_code = mf_ug_fs_oper_read_dir(fullpath->str, dir_list, file_list);
+ if (error_code != 0) {
+ ug_debug("error_code is [%d]\n", error_code);
+ } else {
+ ug_debug("success get the file list\n");
+ }
+ return error_code;
+}
+
+
+/******************************
+** Prototype : mfUgGetFileListWithFormat
+** Description :
+** Input : struct ugmyfiledata *data
+** GString* folder_name
+** Eina_List** dir_list
+** Eina_List** file_list
+** Output : None
+** Return Value :
+** Calls :
+** Called By :
+**
+** History :
+** 1.Date : 2010/12/10
+** Author : Samsung
+** Modification : Created function
+**
+******************************/
+unsigned long mf_ug_fm_svc_wapper_get_file_filter(int file_filter_mode)
+{
+ unsigned long filter = 0;
+ switch (file_filter_mode) {
+ case SHOW_ALL_LIST:
+ filter |= UG_FILTER_CATEGORY_ALL;
+ ug_debug("show_all_list:::::::::::::::::::::::::::::::::: filter is [%d]", filter);
+ break;
+ case SHOW_IMAGE_LIST:
+ filter |= UG_FILTER_CATEGORY_IMAGE;
+ break;
+ case SHOW_SOUND_LIST:
+ filter |= UG_FILTER_CATEGORY_MUSIC | UG_FILTER_CATEGORY_SOUND | UG_FILTER_CATEGORY_VOICE;
+ break;
+ case SHOW_VIDEO_LIST:
+ filter |= UG_FILTER_CATEGORY_VIDEO;
+ break;
+ case SHOW_FLASH_LIST:
+ filter |= UG_FILTER_CATEGORY_FLASH;
+ break;
+ case SHOW_FOLDER_LIST:
+ break;
+ case SHOW_IMAGE_VIDEO_LIST:
+ filter |= UG_FILTER_CATEGORY_IMAGE | UG_FILTER_CATEGORY_VIDEO;
+ break;
+ case SHOW_IMAGE_SOUND_LIST:
+ filter |= UG_FILTER_CATEGORY_IMAGE | UG_FILTER_CATEGORY_SOUND | UG_FILTER_CATEGORY_MUSIC | UG_FILTER_CATEGORY_VOICE;
+ break;
+ case SHOW_VIDEO_SOUND_LIST:
+ filter |= UG_FILTER_CATEGORY_SOUND | UG_FILTER_CATEGORY_VIDEO | UG_FILTER_CATEGORY_MUSIC | UG_FILTER_CATEGORY_VOICE;
+ break;
+ default:
+ break;
+ }
+ return 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;
+ ug_mf_retvm_if(ugd == NULL, MYFILE_ERR_INVALID_ARG, "ugd is NULL");
+ 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");
+
+ int error_code = 0;
+ int filter_mode = 0;
+ int file_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;
+
+ ug_debug("fullpath is [%s]", fullpath->str);
+ error_code = __mf_ug_fm_svc_wapper_get_file_list(fullpath, dir_list, &file_list);
+
+ if (error_code == 0) {
+ ug_debug();
+ file_list_len = eina_list_count(file_list);
+
+ if (file_list_len > 0) {
+ 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);
+ } 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);
+ free(extension);
+ }
+ ug_debug("error is [%d]%s %d\n", error_code, __func__, __LINE__);
+ return error_code;
+ }
+ }
+ ug_debug("error is [%d]%s %d\n", error_code, __func__, __LINE__);
+ return error_code;
+}
+
+
+
+/******************************
+** Prototype : mfUgIsRootPath
+** Description :
+** Input : None
+** Output : None
+** Return Value :
+** Calls :
+** Called By :
+**
+** History :
+** 1.Date : 2010/12/10
+** Author : Samsung
+** Modification : Created function
+**
+******************************/
+bool mf_ug_fm_svc_wapper_is_root_path(void *data)
+{
+ ugData *ugd = (ugData *)data;
+ ug_mf_retvm_if(ugd == NULL, false, "ugd is NULL");
+
+ if (!strcmp(ugd->ug_Status.ug_pPath->str, PHONE_FOLDER)) {
+ return true;
+ } else if (!strcmp(ugd->ug_Status.ug_pPath->str, MEMORY_FOLDER)) {
+ return true;
+ } else {
+ return false;
+ }
+}
+
+
+/******************************
+** Prototype : mfUgGetFileName
+** Description :
+** Input : GString* path
+** Output : None
+** Return Value :
+** Calls :
+** Called By :
+**
+** History :
+** 1.Date : 2010/12/10
+** Author : Samsung
+** Modification : Created function
+**
+******************************/
+GString *mf_ug_fm_svc_wapper_get_file_name(GString *path)
+{
+ GString *ret = NULL;
+ if (ecore_file_exists(path->str)) {
+ ret = g_string_new(ecore_file_file_get(path->str));
+ } else {
+ ret = NULL;
+ }
+ return ret;
+}
+
+char *mf_ug_fm_svc_wapper_get_root_path_by_tab_label(const char *label)
+{
+ if (g_strcmp0(label, MF_UG_LABEL_PHONE) == 0) {
+ return g_strdup(PHONE_FOLDER);
+ } else if (g_strcmp0(label, MF_UG_LABEL_MMC) == 0) {
+ return g_strdup(MEMORY_FOLDER);
+ } else
+ return NULL;
+}
+
+/******************************
+** Prototype : mf_ug_fm_svc_wapper_get_location
+** Description : Samsung
+** Input : char* fullpath
+** Output : None
+** Return Value :
+** Calls :
+** Called By :
+**
+** History :
+** 1.Date : 2010/12/10
+** Author : Samsung
+** Modification : Created function
+**
+******************************/
+int mf_ug_fm_svc_wapper_get_location(char *fullpath)
+{
+ return __mf_ug_fm_svc_wapper_COMESFROM(fullpath);
+}
+
+gint mf_ug_fm_svc_wapper_get_folder_foldersystem(GString *path, bool * result)
+{
+
+ int error_code = 0;
+ error_code = mf_ug_file_attr_is_system_dir(path->str, result);
+ return error_code;
+
+}
+
+GString *mf_ug_fm_svc_wrapper_get_file_parent_path(GString *fullpath)
+{
+ GString *ret = NULL;
+ char *path = NULL;
+ int error_code = 0;
+
+ if (fullpath == NULL || fullpath->str == NULL) {
+ return NULL;
+ }
+ error_code = mf_ug_file_attr_get_parent_path(fullpath->str, &path);
+ if (error_code != 0) {
+ return NULL;
+ }
+
+ ret = g_string_new(path);
+ free(path);
+ path = NULL;
+ return ret;
+}
+
+char *mf_ug_fm_svc_path_info_retrench(const char *string)
+{
+ ug_mf_retvm_if(string == NULL, g_strdup(MF_UG_PATH_INFO_TRANS_OMIT), "input path is NULL");
+ char *retrench = NULL;
+ char *utf8_string = elm_entry_utf8_to_markup(string);
+ if (utf8_string && strlen (string) > MF_UG_PATH_INFO_LEN_THRESHOLD) {
+ if (g_utf8_strlen(utf8_string, -1) > 2) {
+ retrench = calloc(1, MF_UG_PATH_INFO_RETRENCH);
+ if (retrench) {
+ char *omit = MF_UG_PATH_INFO_TRANS_OMIT;
+ char *temp = g_utf8_strncpy(retrench, utf8_string, 2);
+ retrench = g_strconcat(temp, omit, NULL);
+ UG_SAFE_FREE_CHAR(omit);
+ UG_SAFE_FREE_CHAR(utf8_string);
+ UG_SAFE_FREE_CHAR(temp);
+ }
+
+ } else {
+ retrench = utf8_string;
+ }
+ return retrench;
+ } else {
+ return utf8_string;
+ }
+}
+
+static void __mf_ug_fm_svc_wrapper_path_info_node_free(Eina_List *list)
+{
+ ug_mf_retm_if(list == NULL, "list is NULL");
+ const Eina_List *l = NULL;
+ void *data = NULL;
+ EINA_LIST_FOREACH(list, l, data) {
+ ug_pNode *node = (ug_pNode *)data;
+ if (node != NULL) {
+ UG_SAFE_FREE_CHAR(node->original);
+ UG_SAFE_FREE_CHAR(node->transfer);
+ UG_SAFE_FREE_CHAR(node);
+ }
+ }
+ eina_list_free(list);
+}
+
+
+char *mf_ug_fm_svc_path_info_translate(char *path_info, int path_info_max_len)
+{
+
+ ug_mf_retvm_if(path_info == NULL, g_strdup(dgettext("sys_string", "IDS_COM_BODY_UNKNOWN")), "input path is NULL");
+
+ int top = 0;
+ bool flag = TRUE;
+ Eina_List *temp_list = NULL;
+ const Eina_List *l = NULL;
+ gchar **result = NULL;
+ gchar **params = NULL;
+ int count = 0;
+ int max_len = 0;
+ int total_len = 0;
+ int i = 0;
+ char *output = NULL;
+ void *pnode = NULL;
+ char *omit = MF_UG_PATH_INFO_TRANS_OMIT;
+
+ if (strlen(path_info) < path_info_max_len) {
+ UG_SAFE_FREE_CHAR(omit);
+ return path_info;
+ }
+
+ result = g_strsplit(path_info, "/", 0);
+ if (result == NULL) {
+ free(path_info);
+ path_info = NULL;
+ UG_SAFE_FREE_CHAR(omit);
+ return g_strdup(dgettext("sys_string", "IDS_COM_BODY_UNKNOWN"));
+ }
+
+ params = result;
+ count = g_strv_length(result);
+
+ if (count > MF_UG_PATH_INFO_LEVEL_BOUNDARY)
+ {
+ top = MF_UG_PATH_INFO_LEVEL_BOUNDARY;
+ flag = FALSE;
+ max_len = path_info_max_len - MF_UG_PATH_INFO_LEVEL_BOUNDARY - MF_UG_PATH_INFO_HEAD_LEN(omit);//(2 is length of ..) ../aa../bb../***
+ }
+ else
+ {
+ top = count;
+ flag = TRUE;
+ max_len = path_info_max_len - (count-1);
+ }
+
+ for(i = top; i > 1; i--)
+ {
+ ug_pNode *nodeB = calloc(sizeof(ug_pNode), 1);
+ nodeB->original = elm_entry_utf8_to_markup(params[count -i]);
+ nodeB->len_orig = strlen(params[count - i]);
+ nodeB->transfer = mf_ug_fm_svc_path_info_retrench(params[count-i]);
+ nodeB->len_trans = strlen(nodeB->transfer);
+ nodeB->flag_trans = FALSE;
+ total_len += nodeB->len_orig;
+
+ temp_list = eina_list_append(temp_list, nodeB);
+ }
+
+ total_len += strlen(params[count - 1]);
+
+ for (i = 0 ; i < eina_list_count(temp_list); i++)
+ {
+ if (total_len > max_len)
+ {
+ ug_pNode *data = NULL;
+ data = eina_list_nth(temp_list, i);
+ total_len -= (data->len_orig - data->len_trans);
+ data->flag_trans = TRUE;
+ }
+
+ if (total_len <= max_len)
+ break;
+ }
+
+
+ if (flag == FALSE)
+ {
+ output = elm_entry_utf8_to_markup("..");
+ }
+ char *temp = NULL;
+ char *sep = MF_UG_PATH_INFO_SEP;
+ EINA_LIST_FOREACH(temp_list, l, pnode)
+ {
+ ug_pNode *node = (ug_pNode *)pnode;
+ temp = output;
+ if(node->flag_trans == TRUE)
+ {
+ if (output != NULL)
+ output = g_strconcat(output, sep, node->transfer, NULL);
+ else
+ output = g_strdup(node->transfer);
+ }
+ else
+ {
+ if (output != NULL)
+ output = g_strconcat(output, sep ,node->original, NULL);
+ else
+ output = g_strdup(node->original);
+ }
+ UG_SAFE_FREE_CHAR(temp);
+ }
+ temp = output;
+ char *last_string = params[count - 1];
+ char *utf8_last = elm_entry_utf8_to_markup(last_string);
+
+ if (output != NULL) {
+ int last_len = strlen(last_string);
+ int output_len = strlen(output);
+ int d_value = path_info_max_len - output_len;
+ if ((last_len + output_len) > path_info_max_len) {
+ const char *end = (char *)calloc(1, d_value+1);
+ g_utf8_validate(utf8_last, d_value, &end);
+ d_value = last_len - strlen(end);
+ utf8_last[d_value] = '\0';
+ output = g_strconcat(output, sep, utf8_last, omit, NULL);
+ } else {
+ output = g_strconcat(output, sep, utf8_last, NULL);
+ }
+ }
+ else
+ output = g_strdup(utf8_last);
+ UG_SAFE_FREE_CHAR(utf8_last);
+
+ UG_SAFE_FREE_CHAR(temp);
+ UG_SAFE_FREE_CHAR(sep);
+ UG_SAFE_FREE_CHAR(omit);
+ UG_SAFE_FREE_CHAR(path_info);
+ __mf_ug_fm_svc_wrapper_path_info_node_free(temp_list);
+ temp_list = NULL;
+ g_strfreev(result);
+ result = NULL;
+ return output;
+}
+
+
+char *mf_ug_fm_svc_wrapper_translate_path(char *original_path)
+{
+ ug_mf_retvm_if(original_path == NULL, g_strdup(dgettext("sys_string", "IDS_COM_BODY_UNKNOWN")), "input path is NULL");
+
+ char *new_path = NULL;
+ int root_len = 0;
+
+ if (mf_ug_fm_svc_wapper_get_location(original_path) == MF_UG_PHONE) {
+ root_len = strlen(PHONE_FOLDER);
+ new_path = g_strconcat(MF_UG_LABEL_PHONE, original_path + root_len, "/", NULL);
+ } else if (mf_ug_fm_svc_wapper_get_location(original_path) == MF_UG_MMC) {
+ root_len = strlen(MEMORY_FOLDER);
+ new_path = g_strconcat(MF_UG_LABEL_MMC, original_path + root_len, "/", NULL);
+ } else {
+ new_path = g_strdup(original_path);
+ }
+
+ ug_debug("new path is %s", new_path);
+ return new_path;
+}
+
+char *mf_ug_fm_svc_wapper_path_info_get(char *original_path)
+{
+ ug_mf_retvm_if(original_path == NULL, g_strdup(dgettext("sys_string", "IDS_COM_BODY_UNKNOWN")), "input path is NULL");
+ char *path_info = NULL;
+ int len = 0;
+
+ path_info = mf_ug_fm_svc_wrapper_translate_path(original_path);
+ if (path_info) {
+ len = strlen(path_info);
+ if (len > 0 && path_info[len - 1] == '/') {
+ path_info[len - 1] = '\0';
+ }
+ }
+ return path_info;
+
+}
+