diff options
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/file-system/mf-ug-file-attr.c | 1319 | ||||
-rw-r--r-- | src/common/file-system/mf-ug-fs-oper.c | 1034 | ||||
-rw-r--r-- | src/common/mf-ug-cb.c | 1701 | ||||
-rw-r--r-- | src/common/mf-ug-fm-svc-wapper.c | 946 | ||||
-rw-r--r-- | src/common/mf-ug-inotify-handle.c | 349 | ||||
-rw-r--r-- | src/common/mf-ug-list-play.c | 1785 | ||||
-rw-r--r-- | src/common/mf-ug-search-internal.c | 882 | ||||
-rw-r--r-- | src/common/mf-ug-search.c | 125 | ||||
-rw-r--r-- | src/common/mf-ug-util.c | 858 |
9 files changed, 8999 insertions, 0 deletions
diff --git a/src/common/file-system/mf-ug-file-attr.c b/src/common/file-system/mf-ug-file-attr.c new file mode 100644 index 0000000..4376de2 --- /dev/null +++ b/src/common/file-system/mf-ug-file-attr.c @@ -0,0 +1,1319 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.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 <regex.h> +#include <sys/types.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; + mf_ug_fs_file_type ftype; +}; + +static struct _ug_ftype_by_mime mime_type[] = { + {"image/png", UG_FILE_TYPE_IMAGE}, + {"image/jpeg", UG_FILE_TYPE_IMAGE}, + {"image/gif", UG_FILE_TYPE_IMAGE}, + {"image/bmp", UG_FILE_TYPE_IMAGE}, + {"image/vnd.wap.wbmp", UG_FILE_TYPE_IMAGE}, + + {"video/x-msvideo", UG_FILE_TYPE_VIDEO}, + {"video/mp4", UG_FILE_TYPE_VIDEO}, + {"video/3gpp", UG_FILE_TYPE_VIDEO}, + {"video/x-ms-asf", UG_FILE_TYPE_VIDEO}, + {"video/x-ms-wmv", UG_FILE_TYPE_VIDEO}, + {"video/x-matroska", UG_FILE_TYPE_VIDEO}, + + {"audio/mpeg", UG_FILE_TYPE_MUSIC}, + {"audio/x-wav", UG_FILE_TYPE_MUSIC}, + {"application/x-smaf", UG_FILE_TYPE_MUSIC}, + {"audio/mxmf", UG_FILE_TYPE_MUSIC}, + {"audio/midi", UG_FILE_TYPE_MUSIC}, + {"audio/x-xmf", UG_FILE_TYPE_MUSIC}, + {"audio/x-ms-wma", UG_FILE_TYPE_MUSIC}, + {"audio/aac", UG_FILE_TYPE_MUSIC}, + {"audio/ac3", UG_FILE_TYPE_MUSIC}, + {"audio/ogg", UG_FILE_TYPE_MUSIC}, + {"audio/vorbis", UG_FILE_TYPE_MUSIC}, + {"audio/imelody", UG_FILE_TYPE_MUSIC}, + {"audio/iMelody", UG_FILE_TYPE_MUSIC}, + {"audio/x-rmf", UG_FILE_TYPE_MUSIC}, + {"application/vnd.smaf", UG_FILE_TYPE_MUSIC}, + {"audio/mobile-xmf", UG_FILE_TYPE_MUSIC}, + {"audio/mid", UG_FILE_TYPE_MUSIC}, + {"audio/vnd.ms-playready.media.pya", UG_FILE_TYPE_MUSIC}, + {"audio/imy", UG_FILE_TYPE_MUSIC}, + {"audio/m4a", UG_FILE_TYPE_MUSIC}, + {"audio/melody", UG_FILE_TYPE_MUSIC}, + {"audio/mmf", UG_FILE_TYPE_MUSIC}, + {"audio/mp3", UG_FILE_TYPE_MUSIC}, + {"audio/mp4", UG_FILE_TYPE_MUSIC}, + {"audio/MP4A-LATM", UG_FILE_TYPE_MUSIC}, + {"audio/mpeg3", UG_FILE_TYPE_MUSIC}, + {"audio/mpeg4", UG_FILE_TYPE_MUSIC}, + {"audio/mpg", UG_FILE_TYPE_MUSIC}, + {"audio/mpg3", UG_FILE_TYPE_MUSIC}, + {"audio/smaf", UG_FILE_TYPE_MUSIC}, + {"audio/sp-midi", UG_FILE_TYPE_MUSIC}, + {"audio/wav", UG_FILE_TYPE_MUSIC}, + {"audio/wave", UG_FILE_TYPE_MUSIC}, + {"audio/wma", UG_FILE_TYPE_MUSIC}, + {"audio/xmf", UG_FILE_TYPE_MUSIC}, + {"audio/x-mid", UG_FILE_TYPE_MUSIC}, + {"audio/x-midi", UG_FILE_TYPE_MUSIC}, + {"audio/x-mp3", UG_FILE_TYPE_MUSIC}, + {"audio/-mpeg", UG_FILE_TYPE_MUSIC}, + {"audio/x-mpeg", UG_FILE_TYPE_MUSIC}, + {"audio/x-mpegaudio", UG_FILE_TYPE_MUSIC}, + {"audio/x-mpg", UG_FILE_TYPE_MUSIC}, + {"audio/x-ms-asf", UG_FILE_TYPE_MUSIC}, + {"audio/x-wave", UG_FILE_TYPE_MUSIC}, + + {"application/pdf", UG_FILE_TYPE_PDF}, + + {"application/msword", UG_FILE_TYPE_DOC}, + {"application/vnd.openxmlformats-officedocument.wordprocessingml.document", UG_FILE_TYPE_DOC}, + + {"application/vnd.ms-powerpoint", UG_FILE_TYPE_PPT}, + {"application/vnd.openxmlformats-officedocument.presentationml.presentation", UG_FILE_TYPE_PPT}, + + {"application/vnd.ms-excel", UG_FILE_TYPE_EXCEL}, + {"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", UG_FILE_TYPE_EXCEL}, + + {"audio/AMR", UG_FILE_TYPE_VOICE}, + {"audio/AMR-WB", UG_FILE_TYPE_VOICE}, + {"audio/amr", UG_FILE_TYPE_VOICE}, + {"audio/amr-wb", UG_FILE_TYPE_VOICE}, + {"audio/x-amr", UG_FILE_TYPE_VOICE}, + + {"text/html", UG_FILE_TYPE_HTML}, + + {"application/x-shockwave-flash", UG_FILE_TYPE_FLASH}, + {"video/x-flv", UG_FILE_TYPE_FLASH}, + + {"text/plain", UG_FILE_TYPE_TXT}, + + {"text/x-opml+xml", UG_FILE_TYPE_RSS}, + + {"text/vnd.sun.j2me.app-descriptor", UG_FILE_TYPE_JAVA}, + {"application/x-java-archive", UG_FILE_TYPE_JAVA}, + + {NULL, UG_FILE_TYPE_ETC}, +}; + +static char *icon_array[UG_FILE_TYPE_MAX] = { + [UG_FILE_TYPE_DIR] = UG_ICON_FOLDER, + [UG_FILE_TYPE_IMAGE] = UG_ICON_IMAGE, + [UG_FILE_TYPE_VIDEO] = UG_ICON_VIDEO, + [UG_FILE_TYPE_MUSIC] = UG_ICON_MUSIC, + [UG_FILE_TYPE_SOUND] = UG_ICON_SOUND, + [UG_FILE_TYPE_PDF] = UG_ICON_PDF, + [UG_FILE_TYPE_DOC] = UG_ICON_DOC, + [UG_FILE_TYPE_PPT] = UG_ICON_PPT, + [UG_FILE_TYPE_EXCEL] = UG_ICON_EXCEL, + [UG_FILE_TYPE_VOICE] = UG_ICON_VOICE, + [UG_FILE_TYPE_HTML] = UG_ICON_HTML, + [UG_FILE_TYPE_FLASH] = UG_ICON_FLASH, + [UG_FILE_TYPE_TXT] = UG_ICON_TXT, + [UG_FILE_TYPE_VCONTACT] = UG_ICON_VCONTACT, + [UG_FILE_TYPE_VCALENDAR] = UG_ICON_VCALENDAR, + [UG_FILE_TYPE_VNOTE] = UG_ICON_VNOTE, + [UG_FILE_TYPE_RSS] = UG_ICON_RSS, + [UG_FILE_TYPE_JAVA] = UG_ICON_JAVA, +}; + +/********************* +**Function name: __mf_ug_file_attr_get_category_by_file_ext +**Parameter: const char* file_ext +**Return value: mf_ug_fs_file_type +** +**Action: +** Get file category by extention +** +*********************/ +static mf_ug_fs_file_type __mf_ug_file_attr_get_category_by_file_ext(const char *file_ext, const char *fullpath) +{ + int i = 0; + + if (file_ext == NULL) { + return UG_FILE_TYPE_ETC; + } + + if (file_ext[0] == '.') { + i = 1; + } + + switch (file_ext[i]) { + case 'a': + case 'A': + if (strcasecmp("ASF", &file_ext[i]) == 0) { + return UG_FILE_TYPE_VIDEO; + } + if (strcasecmp("AMR", &file_ext[i]) == 0) { + return UG_FILE_TYPE_VOICE; + } + if (strcasecmp("AWB", &file_ext[i]) == 0) { + return UG_FILE_TYPE_VOICE; + } + if (strcasecmp("AAC", &file_ext[i]) == 0) { + return UG_FILE_TYPE_MUSIC; + } + if (strcasecmp("AVI", &file_ext[i]) == 0) { + return UG_FILE_TYPE_VIDEO; + } + if (strcasecmp("AAC", &file_ext[i]) == 0) { + return UG_FILE_TYPE_MUSIC; + } + + break; + case 'b': + case 'B': + if (strcasecmp("BMP", &file_ext[i]) == 0) { + return UG_FILE_TYPE_IMAGE; + } + break; + case 'd': + case 'D': + if (strcasecmp("DOC", &file_ext[i]) == 0) { + return UG_FILE_TYPE_DOC; + } + if (strcasecmp("DOCX", &file_ext[i]) == 0) { + return UG_FILE_TYPE_DOC; + } + if (strcasecmp("DIVX", &file_ext[i]) == 0) { + 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': + case 'G': + if (strcasecmp("GIF", &file_ext[i]) == 0) { + return UG_FILE_TYPE_IMAGE; + } + if (strcasecmp("G72", &file_ext[i]) == 0) { + return UG_FILE_TYPE_MUSIC; + } + break; + case 'h': + case 'H': + if (strcasecmp("H263", &file_ext[i]) == 0) { + return UG_FILE_TYPE_MUSIC; + } + if (strcasecmp("HTML", &file_ext[i]) == 0) { + return UG_FILE_TYPE_HTML; + } + if (strcasecmp("HTM", &file_ext[i]) == 0) { + return UG_FILE_TYPE_HTML; + } + break; + case 'i': + case 'I': + if (strcasecmp("IMY", &file_ext[i]) == 0) { + return UG_FILE_TYPE_SOUND; + } + if (strcasecmp("IPK", &file_ext[i]) == 0) { + return UG_FILE_TYPE_APP; + } + if (strcasecmp("isma", &file_ext[i]) == 0) { + if (mf_ug_file_attr_is_drm_file(fullpath) == 0) { + return UG_FILE_TYPE_DRM; + } else { + return UG_FILE_TYPE_SOUND; + } + } + if (strcasecmp("ismv", &file_ext[i]) == 0) { + if (mf_ug_file_attr_is_drm_file(fullpath) == 0) { + return UG_FILE_TYPE_DRM; + } else { + return UG_FILE_TYPE_SOUND; + } + } + break; + case 'j': + case 'J': + if (strcasecmp("JAD", &file_ext[i]) == 0) { + return UG_FILE_TYPE_JAVA; + } + if (strcasecmp("JAR", &file_ext[i]) == 0) { + return UG_FILE_TYPE_JAVA; + } + + if (strcasecmp("JPG", &file_ext[i]) == 0) { + return UG_FILE_TYPE_IMAGE; + } + if (strcasecmp("JPEG", &file_ext[i]) == 0) { + return UG_FILE_TYPE_IMAGE; + } + if (strcasecmp("JPE", &file_ext[i]) == 0) { + return UG_FILE_TYPE_IMAGE; + } + break; + case 'm': + case 'M': + if (strcasecmp("MMF", &file_ext[i]) == 0) { + return UG_FILE_TYPE_SOUND; + } + if (strcasecmp("MP3", &file_ext[i]) == 0) { + return UG_FILE_TYPE_MUSIC; + } + if (strcasecmp("MID", &file_ext[i]) == 0) { + return UG_FILE_TYPE_SOUND; + } + if (strcasecmp("MIDI", &file_ext[i]) == 0) { + return UG_FILE_TYPE_SOUND; + } + if (strcasecmp("MP4", &file_ext[i]) == 0) { + return UG_FILE_TYPE_VIDEO; + } + if (strcasecmp("MPG", &file_ext[i]) == 0) { + return UG_FILE_TYPE_VIDEO; + } + if (strcasecmp("MPEG", &file_ext[i]) == 0) { + return UG_FILE_TYPE_VIDEO; + } + if (strcasecmp("M4A", &file_ext[i]) == 0) { + return UG_FILE_TYPE_MUSIC; + } + if (strcasecmp("M3G", &file_ext[i]) == 0) { + return UG_FILE_TYPE_FLASH; + } + if (strcasecmp("MXMF", &file_ext[i]) == 0) { + return UG_FILE_TYPE_SOUND; + } + if (strcasecmp("MKV", &file_ext[i]) == 0) { + return UG_FILE_TYPE_VIDEO; + } + if (strcasecmp("MKA", &file_ext[i]) == 0) { + return UG_FILE_TYPE_MUSIC; + } + break; + case 'o': + case 'O': + if (strcasecmp("opml", &file_ext[i]) == 0) { + return UG_FILE_TYPE_RSS; + } + break; + case 'p': + case 'P': + if (strcasecmp("PNG", &file_ext[i]) == 0) { + return UG_FILE_TYPE_IMAGE; + } + if (strcasecmp("PJPEG", &file_ext[i]) == 0) { + return UG_FILE_TYPE_IMAGE; + } + if (strcasecmp("PDF", &file_ext[i]) == 0) { + return UG_FILE_TYPE_PDF; + } + if (strcasecmp("PPT", &file_ext[i]) == 0) { + return UG_FILE_TYPE_PPT; + } + if (strcasecmp("PPTX", &file_ext[i]) == 0) { + return UG_FILE_TYPE_PPT; + } + if (strcasecmp("PEM", &file_ext[i]) == 0) { + return UG_FILE_TYPE_CERTIFICATION; + } + break; + case 'r': + case 'R': + break; + case 's': + case 'S': + if (strcasecmp("SDP", &file_ext[i]) == 0) { + return UG_FILE_TYPE_VIDEO; + } + if (strcasecmp("SPM", &file_ext[i]) == 0) { + return UG_FILE_TYPE_SOUND; + } + if (strcasecmp("SMP", &file_ext[i]) == 0) { + return UG_FILE_TYPE_SOUND; + } + if (strcasecmp("SPF", &file_ext[i]) == 0) { + return UG_FILE_TYPE_SOUND; + } + if (strcasecmp("SWF", &file_ext[i]) == 0) { + return UG_FILE_TYPE_FLASH; + } + if (strcasecmp("SCN", &file_ext[i]) == 0) { + return UG_FILE_TYPE_MOVIE_MAKER; + } + if (strcasecmp("SVG", &file_ext[i]) == 0) { + return UG_FILE_TYPE_SVG; + } + if (strcasecmp("SVGZ", &file_ext[i]) == 0) { + return UG_FILE_TYPE_SVG; + } + break; + case 't': + case 'T': + if (strcasecmp("TXT", &file_ext[i]) == 0) { + return UG_FILE_TYPE_TXT; + } + if (strcasecmp("THM", &file_ext[i]) == 0) { + return UG_FILE_TYPE_THEME; + } + break; + case 'v': + case 'V': + if (strcasecmp("VCF", &file_ext[i]) == 0) { + return UG_FILE_TYPE_VCONTACT; + } + if (strcasecmp("VCS", &file_ext[i]) == 0) { + return UG_FILE_TYPE_VCALENDAR; + } + if (strcasecmp("VNT", &file_ext[i]) == 0) { + return UG_FILE_TYPE_VNOTE; + } + if (strcasecmp("VBM", &file_ext[i]) == 0) { + return UG_FILE_TYPE_VBOOKMARK; + } + break; + case 'w': + case 'W': + if (strcasecmp("WAV", &file_ext[i]) == 0) { + return UG_FILE_TYPE_SOUND; + } + if (strcasecmp("WBMP", &file_ext[i]) == 0) { + return UG_FILE_TYPE_IMAGE; + } + if (strcasecmp("WGT", &file_ext[i]) == 0) { + return UG_FILE_TYPE_WGT; + } + if (strcasecmp("WMA", &file_ext[i]) == 0) { + return UG_FILE_TYPE_MUSIC; + } + if (strcasecmp("WMV", &file_ext[i]) == 0) { + return UG_FILE_TYPE_VIDEO; + } + break; + case 'x': + case 'X': + if (strcasecmp("XLS", &file_ext[i]) == 0) { + return UG_FILE_TYPE_EXCEL; + } + if (strcasecmp("XLSX", &file_ext[i]) == 0) { + return UG_FILE_TYPE_EXCEL; + } + if (strcasecmp("XMF", &file_ext[i]) == 0) { + return UG_FILE_TYPE_SOUND; + } + if (strcasecmp("XHTML", &file_ext[i]) == 0) { + return UG_FILE_TYPE_HTML; + } + break; + case '3': + if (strcasecmp("3GP", &file_ext[i]) == 0) { + return UG_FILE_TYPE_VIDEO; + } + if (strcasecmp("3GPP", &file_ext[i]) == 0) { + return UG_FILE_TYPE_VIDEO; + } + if (strcasecmp("3G2", &file_ext[i]) == 0) { + return UG_FILE_TYPE_VIDEO; + } + break; + } + + return UG_FILE_TYPE_ETC; +} + +/********************* +**Function name: mf_ug_file_attr_is_valid_name +**Parameter: +** const char *filename: the file/dir name we need to check +** +**Return value: +** -0x14 if the name is invalid +** 0 if the name is valid +** +**Action: +** check if the name is valid by file name +** +*********************/ +int mf_ug_file_attr_is_valid_name(const char *filename) +{ + char *pattern; + int ret, z, cflags = 0; + char ebuf[128]; + regex_t reg; + regmatch_t pm[1]; + const size_t nmatch = 1; + /*/ToDo: ignore the file star with . */ + if (strncmp(filename, ".", 1) == 0) { + return MYFILE_ERR_INVALID_FILE_NAME; + } + + pattern = MYFILE_NAME_PATTERN; + z = regcomp(®, pattern, cflags); + + if (z != 0) { + regerror(z, ®, ebuf, sizeof(ebuf)); + fprintf(stderr, "%s: pattern '%s' \n", ebuf, pattern); + return MYFILE_ERR_INVALID_FILE_NAME; + } + + z = regexec(®, filename, nmatch, pm, 0); + if (z == REG_NOMATCH) { + ret = MYFILE_ERR_NONE; + } else { + ret = MYFILE_ERR_INVALID_FILE_NAME; + } + regfree(®); + return ret; +} + + +/****************************** +** Prototype : __mf_ug_file_attr_default_icon_get_by_type +** Description : Samsung +** Input : mf_ug_fs_file_type ftype +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +static char *__mf_ug_file_attr_default_icon_get_by_type(mf_ug_fs_file_type ftype) +{ + char *icon_path = NULL; + + if (icon_array[ftype]) { + icon_path = strdup(icon_array[ftype]); + } else { + icon_path = strdup(UG_DEFAULT_ICON); + } + + return icon_path; +} + + +/****************************** +** Prototype : mf_ug_file_attr_get_parent_path +** Description : Samsung +** Input : const char* path +** char* parent_path +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +int mf_ug_file_attr_get_parent_path(const char *path, char **parent_path) +{ + ug_mf_retvm_if(path == NULL, MYFILE_ERR_INVALID_ARG, "path is NULL"); + ug_mf_retvm_if(parent_path == NULL, MYFILE_ERR_INVALID_ARG, "parent_path is NULL"); + ug_debug("Path :::: [%s]", path); + + *parent_path = g_strdup(path); + if (*parent_path == NULL) + return MYFILE_ERR_ALLOCATE_FAIL; + + const char *name = NULL; + name = ecore_file_file_get(path); + /* + ** input path and parent_path are check in the caller. + ** parent_path is full path must be like /opt/media/file.ext + ** name is file.ext + ** strlen(parent_path) should large than strlen(name) normally. + ** to take exception like input path is "", we add a if condition + */ + if (strlen(*parent_path) > strlen(name)) + (*parent_path)[strlen(*parent_path) - strlen(name) - 1] = '\0'; + + if (strlen(*parent_path) == 0) { + *parent_path = g_strdup("/"); + } + + return MYFILE_ERR_NONE; +} + + +/********************* +**Function name: mf_get_category +**Parameter: +** const char* filepath: file fullpath +** mf_ug_fs_file_type *category: output parameter of category +**Return value: +** error code +** +**Action: +** Get file category by file full path +** +*********************/ +int mf_ug_file_attr_get_file_category(const char *filepath, mf_ug_fs_file_type * category) +{ + int i = 0; + int flag = 0; + + if (mf_ug_file_attr_is_dir(filepath)) { + *category = UG_FILE_TYPE_DIR; + return MYFILE_ERR_NONE; + } + + const char *filename = NULL; + filename = ecore_file_file_get(filepath); + /*/return value ceck */ + if (filename == NULL) { + *category = UG_FILE_TYPE_NONE; + return MYFILE_ERR_SRC_ARG_INVALID; + } + char file_ext[FILE_EXT_LEN_MAX + 1] = { 0 }; + /*/ToDo: error file name like the last letter is "." */ + for (i = strlen(filename); i >= 0; i--) { + if (filename[i] == '.') { + strncpy(file_ext, &filename[i + 1], FILE_EXT_LEN_MAX); + ug_error("file_ext = %s\n",file_ext); + flag = 1; + break; + } + + if (filename[i] == '/') { + flag = 0; + break; + } + } + + if (flag == 1) { + *category = __mf_ug_file_attr_get_category_by_file_ext(file_ext, filepath); + return MYFILE_ERR_NONE; + } else { + *category = UG_FILE_TYPE_NONE; + return MYFILE_ERR_GET_CATEGORY_FAIL; + } +} + +/********************* +**Function name: mf_ug_file_attr_get_file_stat +**Parameter: +** const char* filename: file name +** ugFsNodeInfo **node: output parameter of what we need to refine +**Return value: +** error code +** +**Action: +** Get file size and last modified date by file path +** +*********************/ +int mf_ug_file_attr_get_file_stat(const char *filename, ugFsNodeInfo ** node) +{ + struct stat statbuf; + + ug_mf_retvm_if(filename == NULL, MYFILE_ERR_INVALID_ARG, "filename is null"); + ug_mf_retvm_if(node == NULL, MYFILE_ERR_INVALID_ARG, "node is null"); + + if (stat(filename, &statbuf) == -1) { + return MYFILE_ERR_GET_STAT_FAIL; + } + + (*node)->size = statbuf.st_size; + (*node)->date = statbuf.st_mtime; + + return MYFILE_ERR_NONE; +} + +/********************* +**Function name: mf_ug_file_attr_is_dir +**Parameter: +** const char* filename: file fullpath +**Return value: +** if path is a directory, return 1 +** else, return 0 +** +**Action: +** check if the file path is Directory +** +*********************/ +int mf_ug_file_attr_is_dir(const char *filepath) +{ + return ecore_file_is_dir(filepath); +} + +/********************* +**Function name: mf_ug_file_attr_get_store_type_by_full +**Parameter: +** const char* filepath: file full path +** mf_ug_storage_type *store_type: output parameter of storage type +**Return value: +** error code +** +**Action: +** Get file storage type by file path +** +*********************/ +int mf_ug_file_attr_get_store_type_by_full(const char *filepath, mf_ug_storage_type * store_type) +{ + if (filepath == NULL || store_type == NULL) { + return MYFILE_ERR_SRC_ARG_INVALID; + } + + if (strncmp(filepath, PHONE_FOLDER, strlen(PHONE_FOLDER)) == 0) { + *store_type = MF_UG_PHONE; + return MYFILE_ERR_NONE; + } else if (strncmp(filepath, MEMORY_FOLDER, strlen(MEMORY_FOLDER)) == 0) { + *store_type = MF_UG_MMC; + return MYFILE_ERR_NONE; + } else { + *store_type = MF_UG_NONE; + return MYFILE_ERR_STORAGE_TYPE_ERROR; + } +} + +/********************* +**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 +** char *file_ext: output parameter of file extension +** +**Return value: +** error code +** +**Action: +** get file extension by file full path +** +*********************/ +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); + + if (filename == NULL) { + return MYFILE_ERR_INVALID_FILE_NAME; + } + + char *pdot = strrchr(filename, '.'); + + if (!pdot) { + return MYFILE_ERR_EXT_GET_ERROR; + } else if (pdot != filepath) { + *file_ext = g_strdup(pdot + 1); + return MYFILE_ERR_NONE; + } else { + return MYFILE_ERR_EXT_GET_ERROR; + } +} + + + +/********************* +**Function name: mf_ug_file_attr_is_right_dir_path +**Parameter: +** const char *filename: the file/dir name we need to check +** +**Return value: +** error code +** +**Action: +** check if the dir path is correct +** +*********************/ +int mf_ug_file_attr_is_right_dir_path(const char *dir_path) +{ + int result = MYFILE_ERR_NONE; + int length = 0; + + length = strlen(dir_path); + if (length == 0) { + return MYFILE_ERR_INVALID_DIR_PATH; + } + + if (dir_path[length - 1] == '/' && length > 1) { + return MYFILE_ERR_INVALID_DIR_PATH; + } + + if (dir_path[0] != '/') { + return MYFILE_ERR_INVALID_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); + + if (result != MYFILE_ERR_NONE) { + ug_mf_error("Is NOT Valid dir path name"); + } + + return result; +} + +/********************* +**Function name: mf_ug_file_attr_is_right_file_path +**Parameter: +** const char *filename: the file/dir name we need to check +** +**Return value: +** error code +** +**Action: +** check if the file path is correct +** +*********************/ +int mf_ug_file_attr_is_right_file_path(const char *file_path) +{ + int result = MYFILE_ERR_NONE; + + if (strlen(file_path) == 0) { + return MYFILE_ERR_INVALID_FILE_PATH; + } + + if (file_path[0] != '/') { + return MYFILE_ERR_INVALID_DIR_PATH; + } + + const char *file_name = NULL; + file_name = ecore_file_file_get(file_path); + result = mf_ug_file_attr_is_valid_name(file_name); + if (result != MYFILE_ERR_NONE) { + ug_mf_error("Is NOT Valid dir path name"); + } + + return result; +} + + +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(tmp_filter); + tmp_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; + + media_info_get_thumbnail_path(media, &(tmp_data->thumbnail_path)); + + return false; +} + + + +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; + +} + +int 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; +} + +int mf_ug_file_attr_get_file_icon(const char *file_path, int *error_code, char **thumbnail) +{ + int index = 0; + char *icon_path = NULL; + mf_ug_fs_file_type ftype = UG_FILE_TYPE_NONE; + int thumbnail_type = MF_UG_THUMBNAIL_TYPE_DEFAULT; + const char *mime = NULL; + + ug_mf_retvm_if(file_path == NULL, MF_UG_THUMBNAIL_TYPE_DEFAULT, "file_path is NULL"); + + efreet_mime_init(); + mime = efreet_mime_type_get(file_path); + + if (mime == NULL) { + ug_mf_warnig("Fail to aul_get_mime_from_file(), set etc icon"); + efreet_mime_shutdown(); + return thumbnail_type; + } + + for (index = 0; mime_type[index].mime; index++) { + if (strncmp(mime, mime_type[index].mime, strlen(mime)) == 0) { + ftype = mime_type[index].ftype; + break; + } + } + + icon_path = __mf_ug_file_attr_default_icon_get_by_type(ftype); + ug_debug("ftype is [%d] icon_path is [%s]", ftype, icon_path); + + switch (ftype) { + case UG_FILE_TYPE_IMAGE: + case UG_FILE_TYPE_VIDEO: + { + int err = 0; + 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); + if (err == 0) { + icon_path = g_strdup(tmp_data.thumbnail_path); + thumbnail_type = MF_UG_THUMBNAIL_TYPE_THUMBNAIL; + } else { + icon_path = NULL; + if (error_code) + *error_code = err; + } + } + break; + default: + icon_path = __mf_ug_file_attr_default_icon_get_by_type(ftype); + thumbnail_type = MF_UG_THUMBNAIL_TYPE_DEFAULT; + break; + } + + ug_debug("mime [%s], file type [%d], icon_path [%s]", mime, ftype, icon_path); + *thumbnail = icon_path; + efreet_mime_shutdown(); + + return thumbnail_type; +} + +static int mf_ug_file_attr_get_path_level(const char *fullpath, int *level) +{ + if (fullpath == NULL) { + return MYFILE_ERR_SRC_ARG_INVALID; + } + + if (mf_ug_file_attr_is_right_dir_path(fullpath) != 0) { + return MYFILE_ERR_INVALID_PATH; + } + + mf_ug_storage_type storage_t = 0; + int start_level = 0; + int error_code = mf_ug_file_attr_get_store_type_by_full(fullpath, &storage_t); + if (error_code != 0) { + return error_code; + } + + if (storage_t == MF_UG_PHONE) { + start_level = MF_UG_PHONE_DEFAULT_LEVEL; + } else if (storage_t == MF_UG_MMC) { + start_level = MF_UG_MMC_DEFAULT_LEVEL; + } + + char *temp = strdup(fullpath); + if (temp == NULL) { + return MYFILE_ERR_UNKNOW_ERROR; + } + + int count = 0; + + gchar **result = NULL; + gchar **params = NULL; + result = g_strsplit(temp, "/", 0); + + if (result == NULL) { + free(temp); + temp = NULL; + return MYFILE_ERR_UNKNOW_ERROR; + } + + for (params = result; *params; params++) { + count++; + } + + g_strfreev(result); + *level = count - start_level - 1; + free(temp); + return MYFILE_ERR_NONE; + +} + + +int mf_ug_file_attr_is_in_system_folder(char *fullpath, int level, bool * result) +{ + if (fullpath == NULL) { + return MYFILE_ERR_SRC_ARG_INVALID; + } + + mf_ug_storage_type storage_t = 0; + int error_code = mf_ug_file_attr_get_store_type_by_full(fullpath, &storage_t); + if (error_code != 0) { + return error_code; + } + + const char *name = NULL; + name = ecore_file_file_get(fullpath); + char *parent_path = malloc(MYFILE_DIR_PATH_LEN_MAX + 1); + + if (parent_path == NULL) { + return MYFILE_ERR_ALLOCATE_FAIL; + } + memset(parent_path, 0, MYFILE_DIR_PATH_LEN_MAX + 1); + error_code = mf_ug_file_attr_get_parent_path(fullpath, &parent_path); + + if (error_code != 0) { + + free(parent_path); + parent_path = NULL; + return error_code; + } + + if (storage_t == MF_UG_PHONE || storage_t == MF_UG_MMC) { + if (level == 1) { + if ((strlen(name) == strlen(IMAGE_AND_VIDEO)) && strcmp(name, IMAGE_AND_VIDEO) == 0) { + *result = true; + } else if ((strlen(name) == strlen(SOUND_AND_MUSIC)) && strcmp(name, SOUND_AND_MUSIC) == 0) { + *result = true; + } else if ((strlen(name) == strlen(DOWNLOADS)) && strcmp(name, DOWNLOADS) == 0) { + *result = true; + } else if ((strlen(name) == strlen(CAMERA_SHOTS)) && strcmp(name, CAMERA_SHOTS) == 0) { + *result = true; + } else { + *result = false; + } + } else if (level == 2) { + const char *parent_name = NULL; + parent_name = ecore_file_file_get(parent_path); + if (storage_t == MF_UG_PHONE && (strlen(parent_name) == strlen(DOWNLOADS)) && strcmp(parent_name, DOWNLOADS) == 0) { + if ((strlen(name) == strlen(OTHERS)) && !strcmp(OTHERS, name)) { + *result = true; + } else { + *result = false; + } + } else if ((strlen(parent_name) == strlen(SOUND_AND_MUSIC)) && strcmp(parent_name, SOUND_AND_MUSIC) == 0) { + if ((strlen(name) == strlen(FM_RADIO)) && !strcmp(FM_RADIO, name)) { + *result = true; + } else if ((strlen(name) == strlen(MUSIC)) && !strcmp(MUSIC, name)) { + *result = true; + } else if ((strlen(name) == strlen(RINGTONES)) && !strcmp(RINGTONES, name)) { + *result = true; + } else if ((strlen(name) == strlen(ALERTS)) && !strcmp(ALERTS, name)) { + *result = true; + } else if ((strlen(name) == strlen(VOICE_RECORDER)) && !strcmp(VOICE_RECORDER, name)) { + *result = true; + } else { + *result = false; + } + } else if ((strlen(parent_name) == strlen(IMAGE_AND_VIDEO)) && strcmp(parent_name, IMAGE_AND_VIDEO) == 0) { + if ((strlen(name) == strlen(WALLPAPER)) && !strcmp(WALLPAPER, name)) { + *result = true; + } else if ((strlen(name) == strlen(MY_PHOTO_CLIPS)) && !strcmp(MY_PHOTO_CLIPS, name)) { + *result = true; + } else if ((strlen(name) == strlen(MY_ALBUM)) && !strcmp(MY_ALBUM, name)) { + *result = true; + } else if ((strlen(name) == strlen(MY_VIDEO_CLIPS)) && !strcmp(MY_VIDEO_CLIPS, name)) { + *result = true; + } else { + *result = false; + } + } else { + *result = false; + } + } else { + if (parent_path) { + free(parent_path); + parent_path = NULL; + } + return MYFILE_ERR_STORAGE_TYPE_ERROR; + } + } + + else { + if (parent_path) { + free(parent_path); + parent_path = NULL; + } + *result = false; + return MYFILE_ERR_STORAGE_TYPE_ERROR; + } + + if (parent_path) { + free(parent_path); + parent_path = NULL; + } + return MYFILE_ERR_NONE; +} + + +int mf_ug_file_attr_is_system_dir(char *fullpath, bool * result) +{ + if (fullpath == NULL) { + ug_debug("source argument invalid"); + return MYFILE_ERR_SRC_ARG_INVALID; + } + + if (mf_ug_file_attr_is_dir(fullpath) == 0) { + ug_debug("source is not exist"); + return MYFILE_ERR_SRC_NOT_EXIST; + } + + int level = 0; + int error_code = 0; + + error_code = mf_ug_file_attr_get_path_level(fullpath, &level); + if (error_code != 0) { + ug_debug("Fail to get path level"); + return error_code; + } + + if (level >= 3 || level <= 0) { + *result = false; + ug_debug("Path Level is wrong"); + return MYFILE_ERR_NONE; + } + error_code = mf_ug_file_attr_is_in_system_folder(fullpath, level, result); + + if (error_code != 0) { + ug_debug("Fail .. is in system folder err :: %d", error_code); + return error_code; + } + + return MYFILE_ERR_NONE; + +} + +mf_ug_fs_file_type mf_ug_file_attr_get_file_type_by_mime(const char *file_path) +{ + int index; + mf_ug_fs_file_type ftype = UG_FILE_TYPE_NONE; + const char *mime = NULL; + efreet_mime_init(); + mime = efreet_mime_type_get(file_path); + + if (mime == NULL) { + ug_debug("Fail to aul_get_mime_from_file(), set etc icon"); + efreet_mime_shutdown(); + return ftype; + } + + for (index = 0; mime_type[index].mime; index++) { + if (strncmp(mime, mime_type[index].mime, strlen(mime)) == 0) { + ftype = mime_type[index].ftype; + return ftype; + } + } + efreet_mime_shutdown(); + + 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; +} + diff --git a/src/common/file-system/mf-ug-fs-oper.c b/src/common/file-system/mf-ug-fs-oper.c new file mode 100644 index 0000000..ad1c556 --- /dev/null +++ b/src/common/file-system/mf-ug-fs-oper.c @@ -0,0 +1,1034 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.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 <libgen.h> +#include <glib.h> +#include "mf-ug-fs-util.h" +#include "mf-ug-util.h" + +static int __mf_ug_fs_oper_sort_by_date_cb_O2R(const void *d1, const void *d2); +static int __mf_ug_fs_oper_sort_by_name_cb_A2Z(const void *d1, const void *d2); +static int __mf_ug_fs_oper_sort_by_type_cb_A2Z(const void *d1, const void *d2); +static int __mf_ug_fs_oper_sort_by_size_cb_S2L(const void *d1, const void *d2); +static int __mf_ug_fs_oper_sort_by_name_cb_Z2A(const void *d1, const void *d2); +static int __mf_ug_fs_oper_sort_by_date_cb_R2O(const void *d1, const void *d2); +static int __mf_ug_fs_oper_sort_by_type_cb_Z2A(const void *d1, const void *d2); +static int __mf_ug_fs_oper_sort_by_size_cb_L2S(const void *d1, const void *d2); + +/********************* +**Function name: __mf_ug_fs_oper_file_system_error +**Parameter: +** const char* src: source path +** const char* dst: destination path +** int check_option: check option +** +**Return value: +** error code +** +**Action: +** input parameter checking +** +*********************/ +static const char *__mf_ug_fs_oper_get_file(const char *path) +{ + char *result = NULL; + + if (!path) { + return NULL; + } + if ((result = strrchr(path, '/'))) { + result++; + } else { + result = (char *)path; + } + return result; +} + + +static int __mf_ug_fs_oper_file_system_error(const char *src, const char *dst, int check_option) +{ + if ((check_option & MF_ERROR_CHECK_SRC_ARG_VALID) && (src == NULL)) { + return MYFILE_ERR_SRC_ARG_INVALID; + } + if ((check_option & MF_ERROR_CHECK_SRC_EXIST) && (!ecore_file_exists(src))) { + return MYFILE_ERR_SRC_NOT_EXIST; + } + + if (check_option & MF_ERROR_CHECK_SRC_PATH_VALID) { + if (!ecore_file_is_dir(src)) { + if (mf_ug_file_attr_is_right_file_path(src)) { + return MYFILE_ERR_INVALID_FILE_PATH; + } + } else { + if (mf_ug_file_attr_is_right_dir_path(src)) { + return MYFILE_ERR_INVALID_DIR_PATH; + } + } + } + + if (check_option & MF_ERROR_CHECK_DUPLICATED) { + char *parent_path = NULL; + + if (!mf_ug_file_attr_get_parent_path(dst, &parent_path)) { + if (mf_ug_file_attr_is_duplicated_name(parent_path, __mf_ug_fs_oper_get_file(dst))) { + UG_SAFE_FREE_CHAR(parent_path); + return MYFILE_ERR_DUPLICATED_NAME; + } + UG_SAFE_FREE_CHAR(parent_path); + } else { + UG_SAFE_FREE_CHAR(parent_path); + return MYFILE_ERR_GET_PARENT_PATH_FAIL; + } + } + return MYFILE_ERR_NONE; +} + +/********************* +**Function name: mf_ug_fs_oper_read_dir +**Parameter: +** char *path: path which we need to read +** Eina_List** dir_list: output parameter of dir list under specified path +** Eina_List** file_list: output parameter of file list under specified path +** +**Return value: +** error code +** +**Action: +** read element under the specified path +** +*********************/ +int mf_ug_fs_oper_read_dir(const char *path, Eina_List **dir_list, Eina_List **file_list) +{ + UG_TRACE_BEGIN; + DIR *pDir = NULL; + struct dirent *ent; + + ug_mf_retvm_if(path == NULL, MYFILE_ERR_INVALID_ARG, "path is null"); + ug_mf_retvm_if(dir_list == NULL, MYFILE_ERR_INVALID_ARG, "dir_list is null"); + ug_mf_retvm_if(file_list == NULL, MYFILE_ERR_INVALID_ARG, "file_list is null"); + + int option = MF_ERROR_CHECK_SRC_ARG_VALID | MF_ERROR_CHECK_SRC_EXIST | MF_ERROR_CHECK_SRC_PATH_VALID; + int ret = __mf_ug_fs_oper_file_system_error(path, NULL, option); + + if (ret != MYFILE_ERR_NONE) { + return ret; + } + + pDir = opendir(path); + + if (pDir == NULL) { + return MYFILE_ERR_DIR_OPEN_FAIL; + } + + while ((ent = readdir(pDir)) != NULL) { + GString *childpath = NULL; + ugFsNodeInfo *pNode = NULL; + + if (strncmp(ent->d_name, ".", 1) == 0 || strcmp(ent->d_name, "..") == 0) { + continue; + } + + if ((ent->d_type & DT_DIR) == 0 && (ent->d_type & DT_REG) == 0) { + continue; + } +#ifdef UG_DEBUG_FOLDER_OPTION + if ((ent->d_type & DT_DIR) != 0) { + if ((strlen(path) == strlen(PHONE_FOLDER)) && (strcmp(path, PHONE_FOLDER) == 0) + && (strlen(ent->d_name) == strlen(DEBUG_FOLDER)) && (strcmp(ent->d_name, DEBUG_FOLDER) == 0)) { + continue; + } + } +#endif + pNode = (ugFsNodeInfo *) malloc(sizeof(ugFsNodeInfo)); + + if (pNode == NULL) { + continue; + } + memset(pNode, 0, sizeof(ugFsNodeInfo)); + snprintf(pNode->path, sizeof(pNode->path), "%s", path); + snprintf(pNode->name, sizeof(pNode->name), "%s", ent->d_name); + if (ent->d_type & DT_DIR) { + pNode->type = UG_FILE_TYPE_DIR; + } else if (ent->d_type & DT_REG) { + mf_ug_file_attr_get_file_category(ent->d_name, &(pNode->type)); + } + childpath = g_string_new(path); + if (childpath == NULL) { + free(pNode); + pNode = NULL; + continue; + } + g_string_append_printf(childpath, "/%s", ent->d_name); + mf_ug_file_attr_get_file_stat(childpath->str, &pNode); + if (pNode->type == UG_FILE_TYPE_DIR) { + ug_mf_debug("dir append\n"); + *dir_list = eina_list_append(*dir_list, pNode); + } else { + ug_mf_debug("file append\n"); + ret = mf_ug_file_attr_get_file_ext(childpath->str, &pNode->ext); + if (ret != MYFILE_ERR_NONE) { + pNode->ext = NULL; + } + *file_list = eina_list_append(*file_list, pNode); + } + + g_string_free(childpath, TRUE); + } + closedir(pDir); + UG_TRACE_END; + + return MYFILE_ERR_NONE; +} + +/********************* +**Function name: __mf_ug_fs_oper_exec_filter +**Parameter: +** ugFsNodeInfo* pnode_info: the node we need to check for filter +** int option: filter +** +**Return value: +** error code +** +**Action: +** check if the node satisfied the filter option +*********************/ +static mf_ug_drm_file_mime_type __mf_ug_fs_oper_get_drm_file_type_by_mime(char *mime_type) +{ + gchar **result = NULL; + if (mime_type != NULL) { + result = g_strsplit(mime_type, "/", 0); + if (result && (*result)) { + ug_mf_debug("*result is [%s]", *result); + if (g_strcmp0(*result, "audio") == 0) { + g_strfreev(result); + return MF_UG_DRM_RINGTONE_FILE; + } else if (g_strcmp0(*result, "image") == 0) { + g_strfreev(result); + return MF_UG_DRM_IMAGE_FILE; + } else { + g_strfreev(result); + return MF_UG_DRM_UNKNOW_FILE; + } + } else { + g_strfreev(result); + return MF_UG_DRM_UNKNOW_FILE; + } + } else { + return MF_UG_DRM_UNKNOW_FILE; + } +} + +mf_ug_drm_file_mime_type mf_ug_fs_oper_get_drm_type(char *path) +{ + drm_result_e res = 0; + drm_content_info_s dcf_content_info; + + res = drm_get_content_info(path, &dcf_content_info); + + + if (res == DRM_RETURN_SUCCESS) { + mf_ug_drm_file_mime_type drm_mime_type = __mf_ug_fs_oper_get_drm_file_type_by_mime(dcf_content_info.mime_type); + return drm_mime_type; + } else { + return MF_UG_DRM_UNKNOW_FILE; + } +} + +int mf_ug_fs_oper_drm_is_action_allowed(const char *path, drm_action_type_e action, drm_setas_category_e category) +{ + drm_bool_type_e is_allowed = 0; + drm_action_allowed_data_s action_data; + + int ret = -1; + memset(&action_data,0x0,sizeof(drm_action_allowed_data_s)); + UG_SAFE_STRCPY(action_data.file_path, path); + + action_data.data = category; + + ret = drm_is_action_allowed(action,&action_data,&is_allowed); + if(DRM_RETURN_SUCCESS == ret && DRM_TRUE == is_allowed){ + return true; + }else{ + return false; + } +} + +bool mf_ug_fs_oper_drm_is_valid(const char *path, drm_permission_type_e perm_type) +{ + int res = DRM_RETURN_SUCCESS; + drm_license_status_e licence_status = DRM_LICENSE_STATUS_UNDEFINED; + if (path) { + res = drm_get_license_status(path, perm_type, &licence_status); + } + + ug_error("res is [%d] licence is [%d]", res, licence_status); + if (res == DRM_RETURN_SUCCESS && licence_status == DRM_LICENSE_STATUS_VALID) { + return true; + } else { + return false; + } + +} +static bool __mf_ug_fs_oper_exec_drm_filter(ugFsNodeInfo *pnode_info, int option) +{ + if (pnode_info == NULL) { + return FALSE; + } + + int result = -1; + char *fullpath = NULL; + drm_result_e res = DRM_RETURN_INTERNAL_ERROR; + if (option & MF_UG_FILTER_DRM_ALL) { + return TRUE; + } + + if (option & MF_UG_FILTER_DRM_WITHOUT_FL) { + fullpath = g_strconcat(pnode_info->path, "/", pnode_info->name, NULL); + res = mf_ug_fs_oper_drm_is_action_allowed(fullpath, DRM_IS_FORWARDING_ALLOWED, DRM_SETAS_NONE); + if (res == DRM_RETURN_SUCCESS) { + return FALSE; + } else { + return TRUE; + } + } + + if (option & MF_UG_FILTER_DRM_IMAGE) { + fullpath = g_strconcat(pnode_info->path, "/", pnode_info->name, NULL); + + result = mf_ug_fs_oper_drm_is_action_allowed(fullpath, DRM_HAS_VALID_SETAS_STATUS, DRM_SETAS_WALLPAPER); + if (result) { + mf_ug_drm_file_mime_type drm_mime_type = mf_ug_fs_oper_get_drm_type(fullpath); + if (drm_mime_type == MF_UG_DRM_IMAGE_FILE) + return TRUE; + else + return FALSE; + } else { + return FALSE; + } + } + + if (option & MF_UG_FILTER_DRM_RINGTONE) { + fullpath = g_strconcat(pnode_info->path, "/", pnode_info->name, NULL); + + result = mf_ug_fs_oper_drm_is_action_allowed(fullpath, DRM_HAS_VALID_SETAS_STATUS, DRM_SETAS_RINGTONE); + if (result) { + mf_ug_drm_file_mime_type drm_mime_type = mf_ug_fs_oper_get_drm_type(fullpath); + if (drm_mime_type == MF_UG_DRM_RINGTONE_FILE) + return TRUE; + else + return FALSE; + } else { + return FALSE; + } + + } + + return FALSE; +} + +static bool __mf_ug_fs_oper_exec_filter(ugFsNodeInfo *pnode_info, int option) +{ + if (pnode_info == NULL) { + return FALSE; + } + if (option & UG_FILTER_CATEGORY_IMAGE) { + if (pnode_info->type == UG_FILE_TYPE_IMAGE) { + return TRUE; + } + } + if (option & UG_FILTER_CATEGORY_VIDEO) { + if (pnode_info->type == UG_FILE_TYPE_VIDEO) { + return TRUE; + } + } + if (option & UG_FILTER_CATEGORY_SOUND) { + if (pnode_info->type == UG_FILE_TYPE_SOUND) { + return TRUE; + } + } + if (option & UG_FILTER_CATEGORY_VOICE) { + if (pnode_info->type == UG_FILE_TYPE_VOICE) { + return TRUE; + } + } + if (option & UG_FILTER_CATEGORY_MUSIC) { + if (pnode_info->type == UG_FILE_TYPE_MUSIC) { + return TRUE; + } + } + if (option & UG_FILTER_CATEGORY_HTML) { + if (pnode_info->type == UG_FILE_TYPE_HTML) { + return TRUE; + } + } + if (option & UG_FILTER_CATEGORY_FLASH) { + if (pnode_info->type == UG_FILE_TYPE_FLASH) { + return TRUE; + } + } + if (option & UG_FILTER_CATEGORY_GAME) { + if (pnode_info->type == UG_FILE_TYPE_GAME) { + return TRUE; + } + } + if (option & UG_FILTER_CATEGORY_APP) { + if (pnode_info->type == UG_FILE_TYPE_APP) { + return TRUE; + } + } + if (option & UG_FILTER_CATEGORY_THEME) { + if (pnode_info->type == UG_FILE_TYPE_THEME) { + return TRUE; + } + } + if (option & UG_FILTER_CATEGORY_DOC) { + if (pnode_info->type == UG_FILE_TYPE_DOC) { + return TRUE; + } + } + if (option & UG_FILTER_CATEGORY_EXCEL) { + if (pnode_info->type == UG_FILE_TYPE_EXCEL) { + return TRUE; + } + } + if (option & UG_FILTER_CATEGORY_PPT) { + if (pnode_info->type == UG_FILE_TYPE_PPT) { + return TRUE; + } + } + if (option & UG_FILTER_CATEGORY_PDF) { + if (pnode_info->type == UG_FILE_TYPE_PDF) { + return TRUE; + } + } + if (option & UG_FILTER_CATEGORY_TXT) { + if (pnode_info->type == UG_FILE_TYPE_TXT) { + return TRUE; + } + } + if (option & UG_FILTER_CATEGORY_VCONTACT) { + if (pnode_info->type == UG_FILE_TYPE_VCONTACT) { + return TRUE; + } + } + if (option & UG_FILTER_CATEGORY_VCALENDAR) { + if (pnode_info->type == UG_FILE_TYPE_VCALENDAR) { + return TRUE; + } + } + if (option & UG_FILTER_CATEGORY_VNOTE) { + if (pnode_info->type == UG_FILE_TYPE_VNOTE) { + return TRUE; + } + } + if (option & UG_FILTER_CATEGORY_VBOOKMARK) { + if (pnode_info->type == UG_FILE_TYPE_VBOOKMARK) { + return TRUE; + } + } + if (option & UG_FILTER_CATEGORY_VIDEO_PROJECT) { + if (pnode_info->type == UG_FILE_TYPE_VIDEO_PROJECT) { + return TRUE; + } + } + if (option & UG_FILTER_CATEGORY_SVG) { + if (pnode_info->type == UG_FILE_TYPE_SVG) { + return TRUE; + } + } + if (option & UG_FILTER_CATEGORY_RSS) { + if (pnode_info->type == UG_FILE_TYPE_RSS) { + return TRUE; + } + } + if (option & UG_FILTER_CATEGORY_ETC) { + if (pnode_info->type == UG_FILE_TYPE_ETC) { + return TRUE; + } + } + return FALSE; +} + +int mf_ug_fs_oper_list_filter(Eina_List *in_list, Eina_List **out_list, int option, int drm_opt) +{ + ug_mf_debug(); + if (in_list == NULL) { + return MYFILE_ERR_SRC_ARG_INVALID; + } + + if (out_list == NULL) { + return MYFILE_ERR_DST_ARG_INVALID; + } + + if (option == 0) { + *out_list = in_list; + return MYFILE_ERR_NONE; + } + + Eina_List *l = NULL; + ugFsNodeInfo *data = NULL; + EINA_LIST_FOREACH(in_list, l, data) { + if (data->type == UG_FILE_TYPE_DRM && __mf_ug_fs_oper_exec_drm_filter(data, drm_opt)) { + ug_debug("file [%s] is drm file", data->name); + *out_list = eina_list_append(*out_list, data); + } else if (__mf_ug_fs_oper_exec_filter(data, option)) { + *out_list = eina_list_append(*out_list, data); + } + } + return MYFILE_ERR_NONE; +} + +/****************************** +** Prototype : ug_mf_list_filter_by_extention +** Description : filter from list by extension +** Input : Eina_List *in_list +** Eina_List **out_list +** char* ext +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +int mf_ug_fs_oper_list_filter_by_extension(Eina_List *in_list, Eina_List **out_list, char *ext) +{ + if (in_list == NULL) { + return MYFILE_ERR_SRC_ARG_INVALID; + } + + if (out_list == NULL) { + return MYFILE_ERR_DST_ARG_INVALID; + } + + if (ext == NULL) { + *out_list = in_list; + return MYFILE_ERR_NONE; + } + + Eina_List *l = NULL; + ugFsNodeInfo *data = NULL; + + char *seps = ";"; + char *temp_ext = malloc(strlen(ext) + 1); + gchar **result = NULL; + gchar **params = NULL; + + EINA_LIST_FOREACH(in_list, l, data) { + memset(temp_ext, 0, strlen(ext) + 1); + strncpy(temp_ext, ext, strlen(ext)); + result = g_strsplit(temp_ext, seps, 0); + if (result == NULL) { + continue; + } + for (params = result; *params; params++) { + if (data->ext == NULL) + break; + if (strcasecmp(data->ext, *params) == 0) { + *out_list = eina_list_append(*out_list, data); + break; + } + } + + g_strfreev(result); + result = NULL; + } + free(temp_ext); + return MYFILE_ERR_NONE; +} + +static int __mf_ug_fs_oper_sort_by_priority(const void *d1, const void *d2, int sequence_type) +{ + int ret = 0; + switch(sequence_type) { + case MF_UG_SORT_BY_PRIORITY_TYPE_A2Z: + ret = __mf_ug_fs_oper_sort_by_date_cb_O2R(d1, d2); + if (ret == 0) { + ret = __mf_ug_fs_oper_sort_by_size_cb_S2L(d1, d2); + if (ret == 0) { + ret = __mf_ug_fs_oper_sort_by_name_cb_A2Z(d1, d2); + } + } + break; + case MF_UG_SORT_BY_PRIORITY_TYPE_Z2A: + ret = __mf_ug_fs_oper_sort_by_date_cb_R2O(d1, d2); + if (ret == 0) { + ret = __mf_ug_fs_oper_sort_by_size_cb_L2S(d1, d2); + if (ret == 0) { + ret = __mf_ug_fs_oper_sort_by_name_cb_Z2A(d1, d2); + } + } + break; + case MF_UG_SORT_BY_PRIORITY_DATE_O2R: + ret = __mf_ug_fs_oper_sort_by_size_cb_S2L(d1, d2); + if (ret == 0) { + ret = __mf_ug_fs_oper_sort_by_name_cb_A2Z(d1, d2); + } + break; + case MF_UG_SORT_BY_PRIORITY_DATE_R2O: + ret = __mf_ug_fs_oper_sort_by_size_cb_L2S(d1, d2); + if (ret == 0) { + ret = __mf_ug_fs_oper_sort_by_name_cb_Z2A(d1, d2); + } + break; + case MF_UG_SORT_BY_PRIORITY_SIZE_S2L: + ret = __mf_ug_fs_oper_sort_by_name_cb_A2Z(d1, d2); + break; + case MF_UG_SORT_BY_PRIORITY_SIZE_L2S: + ret = __mf_ug_fs_oper_sort_by_name_cb_Z2A(d1, d2); + break; + default: + break; + } + return ret; +} +/********************* +**Function name: __sort_by_name_cb +**Parameter: +** const void *d1: node1 to compare +** const void *d2: node2 to compare +** +**Return value: +** -1 if d1 > d2 +** 0 if d1 = d2 +** 1 if d1 > d2 +** +**Action: +** sort the list order by the Assic table + +** +*********************/ +static int __mf_ug_fs_oper_sort_by_name_cb_A2Z(const void *d1, const void *d2) +{ + ugFsNodeInfo *txt1 = (ugFsNodeInfo *) d1; + ugFsNodeInfo *txt2 = (ugFsNodeInfo *) d2; + gchar *name1 = NULL; + gchar *name2 = NULL; + int result = 0; + + if (!txt1) { + return (1); + } + if (!txt2) { + return (-1); + } + + name1 = g_ascii_strdown(txt1->name, strlen(txt1->name)); + if (name1 == NULL) { + return (-1); + } + name2 = g_ascii_strdown(txt2->name, strlen(txt2->name)); + if (name2 == NULL) { + g_free(name1); + name1 = NULL; + return (-1); + } + result = g_strcmp0(name1, name2); + + g_free(name1); + name1 = NULL; + g_free(name2); + name2 = NULL; + return result; + +} + +/********************* +**Function name: __sort_by_date_cb +**Parameter: +** const void *d1: node1 to compare +** const void *d2: node2 to compare +** +**Return value: +** -1 if d1 > d2 +** 0 if d1 = d2 +** 1 if d1 > d2 +** +**Action: +** sort the list order by the later created the later shown +*********************/ +static int __mf_ug_fs_oper_sort_by_date_cb_O2R(const void *d1, const void *d2) +{ + int ret = 0; + ugFsNodeInfo *time1 = (ugFsNodeInfo *) d1; + ugFsNodeInfo *time2 = (ugFsNodeInfo *) d2; + + if (!d1) { + return 1; + } + if (!d2) { + return -1; + } + + if (time1->date > time2->date) { + ret = 1; + } else if (time1->date < time2->date) { + ret = -1; + } else { + ret = 0; + } + + if (ret == 0) { + ret = __mf_ug_fs_oper_sort_by_priority(d1, d2, MF_UG_SORT_BY_PRIORITY_DATE_O2R); + } + return ret; +} + +/********************* +**Function name: __sort_by_type_cb +**Parameter: +** const void *d1: node1 to compare +** const void *d2: node2 to compare +** +**Return value: +** -1 if d1 < d2 +** 0 if d1 = d2 +** 1 if d1 > d2 +** +**Action: +** sort the list order by the category type value +*********************/ +static int __mf_ug_fs_oper_sort_by_type_cb_A2Z(const void *d1, const void *d2) +{ + ugFsNodeInfo *type1 = (ugFsNodeInfo *) d1; + ugFsNodeInfo *type2 = (ugFsNodeInfo *) d2; + gchar *ext1 = NULL; + gchar *ext2 = NULL; + int result = 0; + + if (type1 == NULL || type1->ext == NULL) { + return 1; + } + + if (type2 == NULL || type2->ext == NULL) { + return -1; + } + ext1 = g_ascii_strdown(type1->ext, strlen(type1->ext)); + if (ext1 == NULL) { + return (-1); + } + ext2 = g_ascii_strdown(type2->ext, strlen(type2->ext)); + if (ext2 == NULL) { + g_free(ext1); + ext1 = NULL; + return (-1); + } + result = g_strcmp0(ext1, ext2); + + g_free(ext1); + ext1 = NULL; + g_free(ext2); + ext2 = NULL; + + if (result == 0) { + result = __mf_ug_fs_oper_sort_by_priority(d1, d2, MF_UG_SORT_BY_PRIORITY_TYPE_A2Z); + } + + return result; +} + +/*order: the one with smaller size will be shown earlier*/ +/********************* +**Function name: __sort_by_name_cb +**Parameter: +** const void *d1: node1 to compare +** const void *d2: node2 to compare +** +**Return value: +** -1 if d1 > d2 +** 0 if d1 = d2 +** 1 if d1 > d2 +** +**Action: +** sort the list order by size, rule is the smaller the later shown +*********************/ +static int __mf_ug_fs_oper_sort_by_size_cb_S2L(const void *d1, const void *d2) +{ + int ret = 0; + ugFsNodeInfo *size1 = (ugFsNodeInfo *) d1; + ugFsNodeInfo *size2 = (ugFsNodeInfo *) d2; + + if (!d1) { + return 1; + } + + if (!d2) { + return -1; + } + + if (size1->size > size2->size) { + ret = 1; + } else if (size1->size < size2->size) { + ret = -1; + } else { + ret = 0; + } + + if (ret == 0) { + ret = __mf_ug_fs_oper_sort_by_priority(d1, d2, MF_UG_SORT_BY_PRIORITY_SIZE_S2L); + } + return ret; +} + +/********************* +**Function name: __mf_fs_oper_sort_by_name_cb_Z2A +**Parameter: +** const void *d1: node1 to compare +** const void *d2: node2 to compare +** +**Return value: +** 1 if d1 > d2 +** -1 if d1 <= d2 +** +**Action: +** sort the list order by the Assic table + +** +*********************/ +static int __mf_ug_fs_oper_sort_by_name_cb_Z2A(const void *d1, const void *d2) +{ + ugFsNodeInfo *txt1 = (ugFsNodeInfo *) d1; + ugFsNodeInfo *txt2 = (ugFsNodeInfo *) d2; + + int result = 0; + + if (!txt1) { + return (1); + } + if (!txt2) { + return (-1); + } + result = strcasecmp(txt1->name, txt2->name); + + if (result < 0) { + return (1); + } else { + return (-1); + } +} + +/********************* +**Function name: __sort_by_date_cb +**Parameter: +** const void *d1: node1 to compare +** const void *d2: node2 to compare +** +**Return value: +** -1 if d1 > d2 +** 0 if d1 = d2 +** 1 if d1 < d2 +** +**Action: +** sort the list order by the later created the later shown +*********************/ +static int __mf_ug_fs_oper_sort_by_date_cb_R2O(const void *d1, const void *d2) +{ + int ret = 0; + ugFsNodeInfo *time1 = (ugFsNodeInfo *) d1; + ugFsNodeInfo *time2 = (ugFsNodeInfo *) d2; + + if (!d1) { + return -1; + } + if (!d2) { + return 1; + } + if (time1->date > time2->date) { + ret = -1; + } else if (time1->date < time2->date) { + ret = 1; + } else { + ret = 0; + } + + if (ret == 0) { + ret = __mf_ug_fs_oper_sort_by_priority(d1, d2, MF_UG_SORT_BY_PRIORITY_DATE_R2O); + } + return ret; +} + +/********************* +**Function name: __sort_by_type_cb +**Parameter: +** const void *d1: node1 to compare +** const void *d2: node2 to compare +** +**Return value: +** -1 if d1 > d2 +** 0 if d1 = d2 +** 1 if d1 < d2 +** +**Action: +** sort the list order by the category type value +*********************/ +static int __mf_ug_fs_oper_sort_by_type_cb_Z2A(const void *d1, const void *d2) +{ + ugFsNodeInfo *type1 = (ugFsNodeInfo *) d1; + ugFsNodeInfo *type2 = (ugFsNodeInfo *) d2; + gchar *ext1 = NULL; + gchar *ext2 = NULL; + int result = 0; + + if (type1 == NULL || type1->ext == NULL) { + return -1; + } + + if (type2 == NULL || type2->ext == NULL) { + return 1; + } + + ext1 = g_ascii_strdown(type1->ext, strlen(type1->ext)); + if (ext1 == NULL) { + return (1); + } + ext2 = g_ascii_strdown(type2->ext, strlen(type2->ext)); + if (ext2 == NULL) { + g_free(ext1); + ext1 = NULL; + return (-1); + } + result = g_strcmp0(ext1, ext2); + g_free(ext1); + ext1 = NULL; + g_free(ext2); + ext2 = NULL; + if (result == 0) { + result = __mf_ug_fs_oper_sort_by_priority(d1, d2, MF_UG_SORT_BY_PRIORITY_TYPE_Z2A); + } + + return -result; +} + +/*order: the one with smaller size will be shown earlier*/ +/********************* +**Function name: __sort_by_name_cb +**Parameter: +** const void *d1: node1 to compare +** const void *d2: node2 to compare +** +**Return value: +** -1 if d1 > d2 +** 0 if d1 = d2 +** 1 if d1 < d2 +** +**Action: +** sort the list order by size, rule is the smaller the later shown +*********************/ +static int __mf_ug_fs_oper_sort_by_size_cb_L2S(const void *d1, const void *d2) +{ + int ret = 0; + ugFsNodeInfo *size1 = (ugFsNodeInfo *) d1; + ugFsNodeInfo *size2 = (ugFsNodeInfo *) d2; + + if (!d1) { + return -1; + } + + if (!d2) { + return 1; + } + + if (size1->size > size2->size) { + ret = -1; + } else if (size1->size < size2->size) { + ret = 1; + } else { + ret = 0; + } + + if (ret == 0) { + ret = __mf_ug_fs_oper_sort_by_priority(d1, d2, MF_UG_SORT_BY_PRIORITY_SIZE_L2S); + } + return ret; +} + +/********************* +**Function name: mf_fs_oper_sort_list +**Parameter: +** Eina_List **list: the list we need to sort +** int sort_opt: sort option +** +**Return value: +** void +** +**Action: +** sort the list order by sort option with the call back +*********************/ +void mf_ug_fs_oper_sort_list(Eina_List **list, int sort_opt) +{ + Eina_Compare_Cb sort_func = NULL; + if (!(*list)) { + return; + } + switch (sort_opt) { + case MF_UG_SORT_BY_NAME_A2Z: + sort_func = __mf_ug_fs_oper_sort_by_name_cb_A2Z; + break; + case MF_UG_SORT_BY_TYPE_A2Z: + sort_func = __mf_ug_fs_oper_sort_by_type_cb_A2Z; + break; + case MF_UG_SORT_BY_SIZE_S2L: + sort_func = __mf_ug_fs_oper_sort_by_size_cb_S2L; + break; + case MF_UG_SORT_BY_DATE_O2R: + sort_func = __mf_ug_fs_oper_sort_by_date_cb_O2R; + break; + case MF_UG_SORT_BY_NAME_Z2A: + sort_func = __mf_ug_fs_oper_sort_by_name_cb_Z2A; + break; + case MF_UG_SORT_BY_TYPE_Z2A: + sort_func = __mf_ug_fs_oper_sort_by_type_cb_Z2A; + break; + case MF_UG_SORT_BY_SIZE_L2S: + sort_func = __mf_ug_fs_oper_sort_by_size_cb_L2S; + break; + case MF_UG_SORT_BY_DATE_R2O: + sort_func = __mf_ug_fs_oper_sort_by_date_cb_R2O; + break; + default: + sort_func = __mf_ug_fs_oper_sort_by_type_cb_A2Z; + break; + } + *list = eina_list_sort(*list, eina_list_count(*list), sort_func); +} + +int mf_ug_fs_oper_create_dir(const char *dir) +{ + int option = MF_ERROR_CHECK_SRC_ARG_VALID | MF_ERROR_CHECK_DUPLICATED; + int ret = __mf_ug_fs_oper_file_system_error(dir, dir, option); + + if (ret != 0) { + return ret; + } + + ret = mf_ug_file_attr_is_right_dir_path(dir); + + if (ret != 0) { + return ret; + } + + mode_t default_mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; + + if (mkdir(dir, default_mode) < 0) { + return MYFILE_ERR_DIR_CREATE_FAIL; + } + return MYFILE_ERR_NONE; +} + diff --git a/src/common/mf-ug-cb.c b/src/common/mf-ug-cb.c new file mode 100644 index 0000000..f7ad1a5 --- /dev/null +++ b/src/common/mf-ug-cb.c @@ -0,0 +1,1701 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.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 <stdio.h> +#include <Elementary.h> +#include <vconf.h> +#include <vconf-keys.h> +#include <pthread.h> +#include <power.h> + +#include "mf-ug-main.h" +#include "mf-ug-util.h" +#include "mf-ug-inotify-handle.h" +#include "mf-ug-winset.h" +#include "mf-ug-fs-util.h" +#include "mf-ug-fm-svc-wrapper.h" +#include "mf-ug-resource.h" +#include "mf-ug-list-play.h" + +#define UG_MAX_LEN_VIB_DURATION 0.5 +#ifdef UG_OPERATION_SELECT_MODE +#define RESULT_KEY "http://tizen.org/appcontrol/data/selected" +#endif +/****************************** +** Prototype : mf_ug_cb_back_button_cb +** Description : +** Input : void *data +** Evas_Object *obj +** void *event_info +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ + +void mf_ug_cb_back_button_cb(void *data, Evas_Object *obj, void *event_info) +{ + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + ug_mf_retm_if(ugd == NULL, "ugData is NULL"); + + if (ugd->ug_Status.ug_bCancelDisableFlag) { + return; + } + if (0 != ugd->ug_ListPlay.ug_Player) { + mf_ug_list_play_destory_playing_file(ugd); + UG_SAFE_FREE_CHAR(ugd->ug_ListPlay.ug_pPlayFilePath); + } + if (ugd->ug_Status.ug_iMore == UG_MORE_SEARCH) { + + ugNaviBar *pNavi_s = mf_ug_navi_bar_get_in_use_navi(ugd); + ug_mf_retm_if(pNavi_s == NULL, "get navi failed"); + Evas_Object *playout = ugd->ug_MainWindow.ug_pNaviLayout; + ug_mf_retm_if(playout == NULL, "get conformant failed"); + Evas_Object *newContent = NULL; + + newContent = mf_ug_genlist_create_content_list_view(ugd); + + Evas_Object *unUsed = elm_object_part_content_unset(playout, "part1"); + evas_object_del(unUsed); + + elm_object_part_content_set(playout, "part1", newContent); + ugd->ug_Status.ug_iMore = UG_MORE_DEFAULT; + } else { + if (ugd->ug_Status.ug_bSettingEntry == true && ugd->ug_Status.ug_bInSettingView == false) { + Eina_List *l = NULL; + void *item = NULL; + ugNaviBar *pNavi_s = NULL; + ugNaviBar *pNavi_toshow = NULL; + GString *title = NULL; + + if (ugd->ug_ListPlay.ug_iPlayState == PLAY_STATE_PLAYING || ugd->ug_ListPlay.ug_iPlayState == PLAY_STATE_PAUSED) { + mf_ug_list_play_destory_playing_file(ugd); + UG_SAFE_FREE_CHAR(ugd->ug_ListPlay.ug_pPlayFilePath); + } + + EINA_LIST_FOREACH(ugd->ug_MainWindow.ug_pNaviBarList, l, item) { + pNavi_s = (ugNaviBar *)item; + if (pNavi_s == NULL) + return; + if (g_strcmp0(pNavi_s->ug_pNaviLabel, MF_UG_LABEL_PHONE) == 0) { + if (pNavi_s->ug_pCurrentPath != NULL) { + free(pNavi_s->ug_pCurrentPath); + pNavi_s->ug_pCurrentPath = NULL; + } + pNavi_s->ug_pCurrentPath = strdup(ugd->ug_Status.ug_pEntryPath); + pNavi_s->ug_bNaviFlagInUse = true; + pNavi_toshow = pNavi_s; + } else { + if (pNavi_s->ug_pCurrentPath != NULL) { + free(pNavi_s->ug_pCurrentPath); + pNavi_s->ug_pCurrentPath = NULL; + } + pNavi_s->ug_pCurrentPath = strdup(MEMORY_FOLDER); + pNavi_s->ug_bNaviFlagInUse = false; + } + + } + + if (pNavi_toshow == NULL) { + ug_debug("pNavi_toshow is NULL"); + return; + } + + if (ugd->ug_Status.ug_pPath) { + g_string_free(ugd->ug_Status.ug_pPath, TRUE); + ugd->ug_Status.ug_pPath = NULL; + } + + ugd->ug_Status.ug_bInSettingView = true; + + if (ugd->ug_Status.ug_pPath) { + g_string_free(ugd->ug_Status.ug_pPath, TRUE); + ugd->ug_Status.ug_pPath = NULL; + } + + pNavi_toshow->ug_pCurrentPath = strdup(ugd->ug_Status.ug_pEntryPath); + ugd->ug_Status.ug_pPath = g_string_new(pNavi_toshow->ug_pCurrentPath); + title = mf_ug_fm_svc_wapper_get_file_name(ugd->ug_Status.ug_pPath); + + if (title != NULL) { + pNavi_toshow->ug_pNaviTitle = g_strdup(title->str); + g_string_free(title, TRUE); + title = NULL; + } + ugd->ug_Status.ug_iViewType = mf_ug_view_normal; + mf_ug_navi_bar_create_default_view(ugd); + mf_ug_ctrl_bar_set_item_disable(ugd); + + elm_object_item_text_set(ugd->ug_MainWindow.ug_pNaviItem, pNavi_toshow->ug_pNaviTitle); + elm_naviframe_item_title_visible_set(ugd->ug_MainWindow.ug_pNaviItem, EINA_TRUE); + + } else { + ug_destroy_me(ugd->ug); + } + + } + UG_TRACE_END; + +} + +/****************************** +** Prototype : mf_ug_cb_add_button_cb +** Description : +** Input : void *data +** Evas_Object *obj +** void *event_info +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ + +void mf_ug_cb_add_button_cb(void *data, Evas_Object *obj, void *event_info) +{ + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + ug_mf_retm_if(ugd == NULL, "ugData is NULL"); + + service_h service; + + char *result = NULL; + + if (ugd->ug_Status.ug_b_NaviPushFlag) { + UG_TRACE_END; + return; + } + + if (ugd->ug_UiGadget.ug_iSelectMode == EXPORT_MODE || ugd->ug_UiGadget.ug_iSelectMode == SAVE_MODE) { + result = g_strdup(ugd->ug_Status.ug_pPath->str); + } else { + result = mf_ug_util_get_send_result(ugd); + } + if (ugd->ug_Status.ug_bRingtoneSet) { + ug_error("result is [%s]", result); + int ret = MYFILE_ERR_NONE; + ret = mf_ug_file_attr_is_drm_file(result); + ug_error("ret is [%d]", ret); + if (ret == MYFILE_ERR_NONE) { + ret = mf_ug_fs_oper_drm_is_valid(result, DRM_PERMISSION_TYPE_PLAY); + ug_error("ret is [%d]", ret); + if (ret == true) { + ret = mf_ug_fs_oper_drm_is_action_allowed(result, DRM_HAS_VALID_SETAS_STATUS, DRM_SETAS_RINGTONE); + ug_error("ret is [%d]", ret); + } + if (ret == false) { + mf_ug_popup_create(ugd, UG_POPMODE_TEXT, NULL, MF_UG_LABEL_DRM_UNABLE_SET, NULL, NULL, NULL, NULL, NULL); + return; + } + } + } + if (result) { + int ret = 0; + ret = service_create(&service); + if (ret == SERVICE_ERROR_NONE) { +#ifdef UG_OPERATION_SELECT_MODE + if (ugd->ug_UiGadget.ug_bOperationSelectFlag) { + service_add_extra_data(service, RESULT_KEY, result); + } else { + service_add_extra_data(service, "result", result); + } +#else + service_add_extra_data(service, "result", result); +#endif + ug_send_result(ugd->ug, service); + service_destroy(service); + } + ug_debug("result is [%s]", result); + UG_SAFE_FREE_CHAR(result); + } + + if (0 != ugd->ug_ListPlay.ug_Player) { + mf_ug_list_play_destory_playing_file(ugd); + UG_SAFE_FREE_CHAR(ugd->ug_ListPlay.ug_pPlayFilePath); + } + ug_destroy_me(ugd->ug); + UG_TRACE_END; +} + +void mf_ug_cb_list_by_response_cb(void *data) +{ + ugData *ugd = (ugData *)data; + assert(ugd); + + ugNaviBar *pNavi_s = mf_ug_navi_bar_get_in_use_navi(ugd); + ug_mf_retm_if(pNavi_s == NULL, "get navi failed"); + Evas_Object *playout = ugd->ug_MainWindow.ug_pNaviLayout; + ug_mf_retm_if(playout == NULL, "get conformant failed"); + Evas_Object *newContent = NULL; + + newContent = mf_ug_genlist_create_content_list_view(ugd); + + Evas_Object *unUsed = elm_object_part_content_unset(playout, "part1"); + evas_object_del(unUsed); + + elm_object_part_content_set(playout, "part1", newContent); + +} + + +void mf_ug_cb_list_by_button_callback(void *data, Evas_Object * obj, void *event_info) +{ + assert(data); + assert(obj); + ugData *ugd = (ugData *)data; + + Evas_Object *btn = (Evas_Object *)obj; + const char *label = elm_object_text_get(btn); + int iListBySortType = 0; + + if (g_strcmp0(label, MF_UG_LABEL_ASCENDING) == 0 ) { + switch(ugd->ug_Status.ug_iSelectedSortType) { + case 0: + iListBySortType = MF_UG_SORT_BY_NAME_Z2A; + break; + case 1: + iListBySortType = MF_UG_SORT_BY_DATE_R2O; + break; + + case 2: + iListBySortType = MF_UG_SORT_BY_SIZE_L2S; + break; + case 3: + iListBySortType = MF_UG_SORT_BY_TYPE_Z2A; + break; + default: + iListBySortType = MF_UG_SORT_BY_DATE_R2O; + break; + } + } else if(g_strcmp0(label, MF_UG_LABEL_DESCENDING) == 0 ) { + switch(ugd->ug_Status.ug_iSelectedSortType) { + case 0: + iListBySortType = MF_UG_SORT_BY_NAME_A2Z; + break; + case 1: + iListBySortType = MF_UG_SORT_BY_DATE_O2R; + break; + + case 2: + iListBySortType = MF_UG_SORT_BY_SIZE_S2L; + break; + case 3: + iListBySortType = MF_UG_SORT_BY_TYPE_A2Z; + break; + default: + iListBySortType = MF_UG_SORT_BY_DATE_O2R; + break; + } + + } + ugd->ug_Status.ug_iSortType = iListBySortType; + mf_ug_cb_list_by_response_cb(ugd); +} + + +void mf_ug_cb_popup_deleted_cb(void *data, Evas_Object * obj, void *event_info) +{ + ugData *ugd = (ugData *)data; + assert(ugd); + + mf_ug_cb_list_by_button_callback(data, obj, event_info); + + if (ugd->ug_MainWindow.ug_pNormalPopup != NULL) { + evas_object_del(ugd->ug_MainWindow.ug_pNormalPopup); + } + ugd->ug_MainWindow.ug_pNormalPopup = NULL; + +} + +void mf_ug_cb_sort_by_cb(void *data, Evas_Object *obj, void *event_info) +{ + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + ug_mf_retm_if(ugd == NULL, "ugData is NULL"); + + if (ugd->ug_Status.ug_b_NaviPushFlag) { + UG_TRACE_END; + return; + } + ugd->ug_MainWindow.ug_pNormalPopup = mf_ug_popup_create(ugd, UG_POPMODE_LIST_BY, MF_UG_LABEL_LIST_BY, + NULL, NULL, NULL, NULL, mf_ug_cb_popup_deleted_cb, ugd); + UG_TRACE_END; +} + +void mf_ug_cb_goto_myfile_button_cb(void *data, Evas_Object *obj, void *event_info) +{ + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + ug_mf_retm_if(ugd == NULL, "ugData is NULL"); + + if (ugd->ug_Status.ug_bCancelDisableFlag) { + ug_debug("ug_Status.ug_bCancelDisableFlag is true"); + return; + } + ugNaviBar *item = NULL; + Eina_List *l = NULL; + + ugNaviBar *pNavi_s = NULL; + ugNaviBar *pNavi_toshow = NULL; + + EINA_LIST_FOREACH(ugd->ug_MainWindow.ug_pNaviBarList, l, item) { + pNavi_s = (ugNaviBar *)item; + if (pNavi_s == NULL) + return; + if (g_strcmp0(pNavi_s->ug_pNaviLabel, MF_UG_LABEL_PHONE) == 0) { + if (pNavi_s->ug_pCurrentPath != NULL) { + free(pNavi_s->ug_pCurrentPath); + pNavi_s->ug_pCurrentPath = NULL; + } + pNavi_s->ug_pCurrentPath = strdup(PHONE_FOLDER); + pNavi_s->ug_bNaviFlagInUse = true; + pNavi_toshow = pNavi_s; + } else { + if (pNavi_s->ug_pCurrentPath != NULL) { + free(pNavi_s->ug_pCurrentPath); + pNavi_s->ug_pCurrentPath = NULL; + } + pNavi_s->ug_pCurrentPath = strdup(MEMORY_FOLDER); + pNavi_s->ug_bNaviFlagInUse = false; + } + + } + + + if (0 != ugd->ug_ListPlay.ug_Player) { + mf_ug_list_play_destory_playing_file(ugd); + UG_SAFE_FREE_CHAR(ugd->ug_ListPlay.ug_pPlayFilePath); + } + + if (ugd->ug_Status.ug_pPath) { + g_string_free(ugd->ug_Status.ug_pPath, TRUE); + ugd->ug_Status.ug_pPath = NULL; + } + ugd->ug_Status.ug_pPath = g_string_new(SOUNDS_FOLDER); + UG_SAFE_FREE_CHAR(pNavi_s->ug_pCurrentPath); + pNavi_s->ug_pCurrentPath = strdup(ugd->ug_Status.ug_pPath->str); + + ugd->ug_Status.ug_bInSettingView = false; + + mf_ug_navi_bar_create_default_view(ugd); + ugd->ug_Status.ug_bCancelDisableFlag = true; + mf_ug_ctrl_bar_set_item_disable(ugd); +} + + +/****************************** +** Prototype : _ug_popup_exit +** Description : Samsung +** Input : void *data +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ + +void mf_ug_cb_mass_storage_popup_cb(void *data) +{ + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + ug_mf_retm_if(ugd == NULL, "ugData is NULL"); + + mf_ug_cb_back_button_cb(ugd, NULL, NULL); + + if (ugd->ug_MainWindow.ug_pNormalPopup) { + evas_object_del(ugd->ug_MainWindow.ug_pNormalPopup); + ugd->ug_MainWindow.ug_pNormalPopup = NULL; + } + UG_TRACE_END; +} + +void mf_ug_cb_upper_button_pressed_cb(void *data, Evas_Object * obj, void *event_info) +{ + UG_TRACE_BEGIN; + ug_mf_retm_if(data == NULL, "data is NULL"); + + Evas_Object *upper_ic = (Evas_Object *)data; + elm_image_file_set(upper_ic, UG_TITLE_ICON_UPPER_PRESS, NULL); +} + +void mf_ug_cb_upper_button_unpressed_cb(void *data, Evas_Object * obj, void *event_info) +{ + UG_TRACE_BEGIN; + ug_mf_retm_if(data == NULL, "data is NULL"); + + Evas_Object *upper_ic = (Evas_Object *)data; + elm_image_file_set(upper_ic, UG_TITLE_ICON_UPPER, NULL); +} + + +/****************************** +** Prototype : mf_ug_cb_upper_click_cb +** Description : Samsung +** Input : void *data +** Evas_Object * obj +** void *event_info +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +void mf_ug_cb_upper_click_cb(void *data, Evas_Object * obj, void *event_info) +{ + UG_TRACE_BEGIN; + ug_mf_retm_if(data == NULL, "data is NULL"); + ugData *ugd = (ugData *)data; + ugNaviBar *pNavi_s = mf_ug_navi_bar_get_in_use_navi(ugd); + ug_mf_retm_if(pNavi_s == NULL, "pNavi_s is NULL"); + + if (ugd->ug_Status.ug_b_NaviPushFlag) { + UG_TRACE_END; + return; + } + + if (ugd->ug_Status.ug_pPath != NULL && pNavi_s->ug_pCurrentPath != NULL) { + if (g_strcmp0(pNavi_s->ug_pCurrentPath, MF_UG_LABEL_PHONE) == 0 + || g_strcmp0(pNavi_s->ug_pCurrentPath, MF_UG_LABEL_MMC) == 0) { + mf_ug_navi_bar_create_default_view(ugd); + return; + } + GString *new_path = NULL; + char *file_dir = ecore_file_dir_get(pNavi_s->ug_pCurrentPath); + if (file_dir) { + new_path = g_string_new(file_dir); + UG_SAFE_FREE_GSTRING(ugd->ug_Status.ug_pPath); + ugd->ug_Status.ug_pPath = new_path; + UG_SAFE_FREE_CHAR(pNavi_s->ug_pCurrentPath); + pNavi_s->ug_pCurrentPath = strdup(new_path->str); + free(file_dir); + file_dir = NULL; + } else { + ug_debug("file_dir is NULL"); + } + } else { + ugd->ug_Status.ug_pPath = g_string_new(MF_UG_LABEL_PHONE); + pNavi_s->ug_pCurrentPath = strdup(MF_UG_LABEL_PHONE); + } + mf_ug_navi_bar_create_default_view(ugd); + mf_ug_ctrl_bar_set_item_disable(ugd); + UG_TRACE_END; +} + +void mf_ug_cb_home_button_pressed_cb(void *data, Evas_Object * obj, void *event_info) +{ + UG_TRACE_BEGIN; + ug_mf_retm_if(data == NULL, "data is NULL"); + + Evas_Object *home_ic = (Evas_Object *)data; + elm_image_file_set(home_ic, UG_TITLE_ICON_HOME_PRESS, NULL); +} + +void mf_ug_cb_home_button_unpressed_cb(void *data, Evas_Object * obj, void *event_info) +{ + UG_TRACE_BEGIN; + ug_mf_retm_if(data == NULL, "data is NULL"); + + Evas_Object *home_ic = (Evas_Object *)data; + elm_image_file_set(home_ic, UG_TITLE_ICON_HOME, NULL); +} + +void mf_ug_cb_home_button_cb(void *data, Evas_Object * obj, void *event_info) +{ + UG_TRACE_BEGIN; + ug_mf_retm_if(data == NULL, "data is NULL"); + ugData *ugd = (ugData *)data; + ugNaviBar *pNavi_s = mf_ug_navi_bar_get_in_use_navi(ugd); + ug_mf_retm_if(pNavi_s == NULL, "pNavi_s is NULL"); + + if (ugd->ug_Status.ug_b_NaviPushFlag) { + UG_TRACE_END; + return; + } + + int storage = MF_UG_PHONE; + + storage = mf_ug_fm_svc_wapper_get_location(ugd->ug_Status.ug_pPath->str); + switch (storage) { + case MF_UG_PHONE: + UG_SAFE_FREE_GSTRING(ugd->ug_Status.ug_pPath); + ugd->ug_Status.ug_pPath = g_string_new(PHONE_FOLDER); + UG_SAFE_FREE_CHAR(pNavi_s->ug_pCurrentPath); + pNavi_s->ug_pCurrentPath = g_strdup(PHONE_FOLDER); + mf_ug_util_set_current_state(ugd, STATE_PHONE); + break; + case MF_UG_MMC: + UG_SAFE_FREE_GSTRING(ugd->ug_Status.ug_pPath); + ugd->ug_Status.ug_pPath = g_string_new(MEMORY_FOLDER); + UG_SAFE_FREE_CHAR(pNavi_s->ug_pCurrentPath); + pNavi_s->ug_pCurrentPath = g_strdup(MEMORY_FOLDER); + mf_ug_util_set_current_state(ugd, STATE_MEMORY); + break; + default: + return; + } + + mf_ug_navi_bar_create_default_view(ugd); + mf_ug_ctrl_bar_set_item_disable(ugd); + UG_TRACE_END; +} + +/****************************** +** Prototype : tab_callback +** Description : +** Input : void *data +** Evas_Object *obj +** void *event_info +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +void mf_ug_cb_tab_bar_cb(void *data, const char *path) +{ + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + ug_mf_retm_if(ugd == NULL, "ugd is NULL"); + + + const char *label = NULL; + Evas_Object *newContent = NULL; + Evas_Object *pNaviBar = NULL; + ugNaviBar *pNavi_s_toshow = NULL; + ugNaviBar *pNavi_s_inuse = NULL; + + if (ugd->ug_Status.ug_bSettingEntry == true && ugd->ug_Status.ug_bInSettingView == true) { + return; + } + + int optStorage = 0; + optStorage = mf_ug_fm_svc_wapper_get_location(path); + switch (optStorage) { + case MF_UG_PHONE: + label = MF_UG_LABEL_PHONE; + break; + case MF_UG_MMC: + label = MF_UG_LABEL_MMC; + break; + default: + break; + } + + + if (label != NULL) { + char *rootpath = NULL; + + /*0. set the previous navi to be out of use */ + pNavi_s_inuse = mf_ug_navi_bar_get_in_use_navi(ugd); + + if (pNavi_s_inuse == NULL || pNavi_s_inuse->ug_pNaviLabel == NULL) { + UG_TRACE_END; + return; + } + + pNavi_s_inuse->ug_bNaviFlagInUse = FALSE; + + if (0 != ugd->ug_ListPlay.ug_Player) { + mf_ug_list_play_destory_playing_file(ugd); + UG_SAFE_FREE_CHAR(ugd->ug_ListPlay.ug_pPlayFilePath); + } + + /*if the muisc is playing, destory the play */ + + /*1. get navi bar pointer by the label */ + pNaviBar = ugd->ug_MainWindow.ug_pNaviBar; + pNavi_s_toshow = ug_mf_navi_bar_get_navi_from_navilist(ugd->ug_MainWindow.ug_pNaviBarList, label); + + ug_debug("label is %s", label); + /*2. create navi bar if not created, otherwise get it by pNaviBar */ + if (pNavi_s_toshow == NULL) { + /*2.0 get root path by storage label */ + rootpath = mf_ug_fm_svc_wapper_get_root_path_by_tab_label(label); + if (rootpath == NULL) { + UG_TRACE_END; + return; + } + /*2.1 create the navi for the tab */ + pNavi_s_toshow = calloc(1, sizeof(ugNaviBar)); + if (pNavi_s_toshow == NULL) { + ug_debug("pNavi_s_toshow is NULL"); + free(rootpath); + rootpath = NULL; + return; + } + + pNavi_s_toshow->ug_bNaviFlagInUse = TRUE; + /*2.2 set path as root path of the storage */ + pNavi_s_toshow->ug_pCurrentPath = g_strdup(rootpath); + pNavi_s_toshow->ug_pNaviLabel = strdup(label); + free(rootpath); + rootpath = NULL; + /*2.3 insert phone navi into the navi_list */ + ugd->ug_MainWindow.ug_pNaviBarList = eina_list_append(ugd->ug_MainWindow.ug_pNaviBarList, pNavi_s_toshow); + + } else { + /*/2.1 get the navi of the tab */ + pNavi_s_toshow = mf_ug_navi_bar_get_navi_struct_by_label(ugd, label); + + pNavi_s_toshow->ug_bNaviFlagInUse = TRUE; + } + /*/2.2 set related status value. */ + if (ugd->ug_Status.ug_pPath != NULL) { + g_string_free(ugd->ug_Status.ug_pPath, TRUE); + ugd->ug_Status.ug_pPath = NULL; + } + ugd->ug_Status.ug_pPath = g_string_new(pNavi_s_toshow->ug_pCurrentPath); + ugd->ug_Status.ug_iViewType = mf_ug_view_normal; + mf_ug_navi_bar_create_default_view(ugd); + + mf_ug_ctrl_bar_set_item_disable(ugd); + } else { + ug_debug("Invalid argument: label is NULL\n"); + } + UG_TRACE_END; +} + + +void mf_ug_cb_ctrl_bar_button_cb(void *data, Evas_Object *obj, void *event_info) +{ + + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + ug_mf_retm_if(ugd == NULL, "ugd is NULL"); + ug_mf_retm_if(event_info == NULL, "event_info is NULL"); + const char *label = NULL; + + if (ugd->ug_Status.ug_b_NaviPushFlag) + return; + label = elm_object_item_text_get((Elm_Object_Item *)event_info); + ug_mf_retm_if(label == NULL, "label is NULL"); + + ugNaviBar *pNavi_s = mf_ug_navi_bar_get_in_use_navi(ugd); + if (g_strcmp0(label, MF_UG_LABEL_RINGTONES) == 0) { + if (g_strcmp0(ugd->ug_Status.ug_pPath->str, UG_RINGTION_PATH) != 0) { + UG_SAFE_FREE_GSTRING(ugd->ug_Status.ug_pPath); + ugd->ug_Status.ug_pPath = g_string_new(UG_RINGTION_PATH); + UG_SAFE_FREE_CHAR(pNavi_s->ug_pCurrentPath); + pNavi_s->ug_pCurrentPath = g_strdup(UG_RINGTION_PATH); + mf_ug_util_set_current_state(ugd, STATE_PHONE); + ugd->ug_Status.ug_iCtrlBarType = CTRL_BAR_MUSIC; + mf_ug_navi_bar_create_default_view(ugd); + } + } else if (g_strcmp0(label, MF_UG_LABEL_OTHER_MUSIC) == 0) { + if (g_strcmp0(ugd->ug_Status.ug_pPath->str, UG_MUSIC_PATH) != 0) { + UG_SAFE_FREE_GSTRING(ugd->ug_Status.ug_pPath); + ugd->ug_Status.ug_pPath = g_string_new(UG_MUSIC_PATH); + UG_SAFE_FREE_CHAR(pNavi_s->ug_pCurrentPath); + pNavi_s->ug_pCurrentPath = g_strdup(UG_MUSIC_PATH); + mf_ug_util_set_current_state(ugd, STATE_PHONE); + ugd->ug_Status.ug_iCtrlBarType = CTRL_BAR_RINGTONE; + mf_ug_navi_bar_create_default_view(ugd); + } + } + UG_TRACE_END; +} + +/****************************** +** Prototype : mf_ug_cb_list_play_cb +** Description : Samsung +** Input : ugListItemData *data +** Evas_Object *obj +** void *event_info +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +void mf_ug_cb_list_play_cb(ugListItemData *data, Evas_Object *obj, void *event_info) +{ + UG_TRACE_BEGIN; + ugListItemData *itemData = data; + ugData *ugd = NULL; + ug_mf_retm_if(itemData == NULL, "itemData is NULL"); + ug_mf_retm_if(itemData->ug_pData == NULL, "ug_pData is NULL"); + + ugd = itemData->ug_pData; + + if (itemData->ug_pData->ug_Status.ug_b_NaviPushFlag) + return; + + mf_ug_list_play_play_music_item(itemData); + + UG_TRACE_END; +} + +/****************************** +** Prototype : mf_ug_cb_select_info_show_cb +** Description : Samsung +** Input : void *data +** Evas *e +** Evas_Object *obj +** void *event_info +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +void mf_ug_cb_select_info_show_cb(void *data, Evas *e, Evas_Object *obj, void *event_info) +{ + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + ug_mf_retm_if(ugd == NULL, "ugd is NULL"); + edje_object_signal_emit(_EDJ(ugd->ug_MainWindow.ug_pMainLayout), "elm,state,show,default", "elm"); + UG_TRACE_END; + return; +} + +/****************************** +** Prototype : mf_ug_cb_select_info_hide_cb +** Description : Samsung +** Input : void *data +** Evas *e +** Evas_Object *obj +** void *event_info +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +void mf_ug_cb_select_info_hide_cb(void *data, Evas *e, Evas_Object *obj, void *event_info) +{ + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + ug_mf_retm_if(ugd == NULL, "ugd is NULL"); + edje_object_signal_emit(_EDJ(ugd->ug_MainWindow.ug_pMainLayout), "elm,state,hide,default", "elm"); + UG_TRACE_END; + return; +} + +/****************************** +** Prototype : mf_ug_cb_select_info_timeout_cb +** Description : Samsung +** Input : void *data +** Evas_Object *obj +** void *event_info +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +void mf_ug_cb_select_info_timeout_cb(void *data, Evas_Object *obj, void *event_info) +{ + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + ug_mf_retm_if(ugd == NULL, "ugd is NULL"); + edje_object_signal_emit(_EDJ(ugd->ug_MainWindow.ug_pMainLayout), "elm,state,hide,default", "elm"); + UG_TRACE_END; + return; +} + + +/****************************** +** Prototype : mf_ug_cb_mmc_changed_cb +** Description : Samsung +** Input : keynode_t *key +** void* data +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +static void __mf_ug_cb_mmc_remove_view_operation(void *data) +{ + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + ug_mf_retm_if(ugd == NULL, "ugd is NULL"); + + Evas_Object *parent = NULL; + const char *labelStorage = NULL; + parent = ugd->ug_MainWindow.ug_pNaviGenlist; + labelStorage = MEMORY_FOLDER; + + mf_ug_genlist_item_remove(parent, labelStorage); + +} + +void mf_ug_cb_mmc_changed_cb(keynode_t *key, void *data) +{ + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + ug_mf_retm_if(ugd == NULL, "ugd is NULL"); + ug_mf_retm_if(ugd->ug_Status.ug_pPath == NULL || ugd->ug_Status.ug_pPath->str == NULL, "ugd->ug_Status.ug_pPath is NULL"); + + int optStorage = MF_UG_NONE; + char *labelStorage = NULL; + + if (VCONF_TYPE_INT == vconf_keynode_get_type(key) + && VCONFKEY_SYSMAN_MMC_MOUNTED == vconf_keynode_get_int(key)) { + if (ugd->ug_Status.ug_bInSettingView && ugd->ug_Status.ug_bSettingEntry) { + ugd->ug_Status.ug_iMmcFlag = MMC_ON; + return; + } + ugd->ug_Status.ug_iMmcFlag = MMC_ON; + + mf_ug_util_storage_insert_action(ugd, MF_UG_LABEL_MMC); + } else { + ugNaviBar *pNaviInUseStruct = NULL; + + if (VCONFKEY_SYSMAN_MMC_REMOVED == vconf_keynode_get_int(key) + || VCONFKEY_SYSMAN_MMC_INSERTED_NOT_MOUNTED == vconf_keynode_get_int(key)) { + ug_debug("mmc removed"); + if (ugd->ug_Status.ug_bInSettingView && ugd->ug_Status.ug_bSettingEntry) { + ugd->ug_Status.ug_iMmcFlag = MMC_OFF; + return; + } + optStorage = MF_UG_MMC; + ugd->ug_Status.ug_iMmcFlag = MMC_OFF; + } + + if (optStorage == MF_UG_NONE) { + ug_debug("get removed storage failed"); + return; + } + + labelStorage = MF_UG_LABEL_MMC; + if (mf_ug_fm_svc_wapper_get_location(ugd->ug_Status.ug_pPath->str) == optStorage) { + if (0 != ugd->ug_ListPlay.ug_Player) { + mf_ug_list_play_destory_playing_file(ugd); + UG_SAFE_FREE_CHAR(ugd->ug_ListPlay.ug_pPlayFilePath); + } + + mf_ug_navi_bar_remove_navi_list_item_by_label(ugd, labelStorage); + pNaviInUseStruct = mf_ug_navi_bar_get_in_use_navi(ugd); + ug_debug("label is [%s]pNaviInUseStruct->ug_pCurrentPath is [%s]", pNaviInUseStruct->ug_pNaviLabel, pNaviInUseStruct->ug_pCurrentPath); + mf_ug_navi_bar_refresh_navibar_recovered_view(ugd, pNaviInUseStruct); + } + } + + if(mf_ug_fm_svc_wapper_is_root_path(ugd->ug_Status.ug_pPath)) + { + elm_naviframe_item_title_visible_set(ugd->ug_MainWindow.ug_pNaviItem, EINA_FALSE); + mf_ug_callback_tab_click(ugd); + } + else + { + mf_ug_navi_bar_title_set(ugd); + } + + UG_TRACE_END; + return; +} + +/****************************** +** Prototype : mf_ug_cb_dir_update_cb +** Description : Samsung +** Input : mf_ug_inotify_event event +** char *name +** void *data +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +void mf_ug_cb_dir_update_cb(mf_ug_inotify_event event, char *name, void *data) +{ + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + ug_mf_retm_if(ugd == NULL, "ugData is NULL"); + + ug_debug("event : %d, name : %s", event, name); + + ug_dir_event_t buffer; + + buffer.event = event; + buffer.name = strdup(name); + + ecore_pipe_write(ugd->ug_UiGadget.ug_pInotifyPipe, &buffer, sizeof(buffer)); + UG_TRACE_END; + + return; +} + +/****************************** +** Prototype : mf_ug_cb_dir_pipe_cb +** Description : Samsung +** Input : void *data +** void *buffer +** unsigned int nbyte +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +static GString *__mf_ug_cb_dir_pipe_get_parent(GString *path) +{ + + ug_mf_retvm_if(path == NULL, NULL, "path is NULL"); + ug_mf_retvm_if(path->str == NULL, NULL, "path->str is NULL"); + + if (ecore_file_exists(path->str)) { + return path; + } else if (mf_ug_fm_svc_wapper_is_root_path(path)) { + return path; + } else { + GString *parent = mf_ug_fm_svc_wrapper_get_file_parent_path(path); + UG_SAFE_FREE_GSTRING(path); + __mf_ug_cb_dir_pipe_get_parent(parent); + } + return path; +} + +void mf_ug_cb_dir_pipe_cb(void *data, void *buffer, unsigned int nbyte) +{ + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + ug_mf_retm_if(ugd == NULL, "ugd is NULL"); + + + if (ugd->ug_ListPlay.ug_iPlayState != PLAY_STATE_INIT) { + return; + } + + if (g_strcmp0(ugd->ug_Status.monitor_path, ugd->ug_Status.ug_pPath->str)) { + return; + } + if (buffer) { + ug_dir_event_t *msg = (ug_dir_event_t *) buffer; + ug_debug("event : %d, name : %s", msg->event, msg->name); + + Evas_Object *newContent = NULL; + ugListItemData *itemData = NULL; + Elm_Object_Item *it = NULL; + GString *parent = NULL; + char *path = NULL; + int count = 0; + + switch (msg->event) { + case UG_MF_INOTI_CREATE: + case UG_MF_INOTI_MOVE_IN: + /*/1 TODO: add new item to list */ + if(msg->name) { + path = g_strconcat(ugd->ug_Status.ug_pPath->str, "/", msg->name, NULL); + int file_type = 0; + if (mf_ug_file_attr_is_dir(path)) { + file_type = UG_FILE_TYPE_DIR; + } else { + file_type = UG_FILE_TYPE_FILE; + } + ugFsNodeInfo *pNode = mf_ug_util_generate_pnode(path, file_type); + if (ugd->ug_MainWindow.ug_pNaviGenlist == NULL) { + + Evas_Object *genlist = NULL; + genlist = elm_genlist_add(ugd->ug_MainWindow.ug_pNaviBar); + evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL); + + ugd->ug_MainWindow.ug_pNaviGenlist = genlist; + evas_object_smart_callback_add(genlist, "selected", mf_ug_genlist_selected_gl, ugd); + + evas_object_del(elm_object_part_content_unset(ugd->ug_MainWindow.ug_pNaviLayout, "part1")); + + elm_object_part_content_set(ugd->ug_MainWindow.ug_pNaviLayout, "part1", newContent); + elm_object_part_content_set(ugd->ug_MainWindow.ug_pNaviLayout, "part1", genlist); + } + if (file_type == UG_FILE_TYPE_DIR) { + if (ugd->ug_UiGadget.ug_iSelectMode == MULTI_FILE_MODE || + ugd->ug_UiGadget.ug_iSelectMode == SINGLE_FILE_MODE || + ugd->ug_UiGadget.ug_iSelectMode == IMPORT_MODE || + ugd->ug_UiGadget.ug_iSelectMode == IMPORT_PATH_SELECT_MODE || + ugd->ug_UiGadget.ug_iSelectMode == EXPORT_MODE || + ugd->ug_UiGadget.ug_iSelectMode == SAVE_MODE || + ugd->ug_UiGadget.ug_iSelectMode == IMPORT_SINGLE) { + + mf_ug_genlist_item_append(ugd->ug_MainWindow.ug_pNaviGenlist, pNode, ugd, 0, &ugd->ug_Status.ug_normalitc); + } else { + int groupValue = elm_genlist_items_count(ugd->ug_MainWindow.ug_pNaviGenlist); + mf_ug_genlist_item_append(ugd->ug_MainWindow.ug_pNaviGenlist, pNode, ugd, groupValue, &ugd->ug_Status.ug_itc); + } + } else { + if (ugd->ug_UiGadget.ug_iSelectMode == SINGLE_ALL_MODE || ugd->ug_UiGadget.ug_iSelectMode == SINGLE_FILE_MODE) { + int groupValue = elm_genlist_items_count(ugd->ug_MainWindow.ug_pNaviGenlist); + mf_ug_genlist_item_append(ugd->ug_MainWindow.ug_pNaviGenlist, pNode, ugd, groupValue, &ugd->ug_Status.ug_itc); + } else if (ugd->ug_UiGadget.ug_iSelectMode == EXPORT_MODE || ugd->ug_UiGadget.ug_iSelectMode == SAVE_MODE) { + mf_ug_genlist_item_append(ugd->ug_MainWindow.ug_pNaviGenlist, pNode, ugd, 0, &ugd->ug_Status.ug_normalitc); + } else { + mf_ug_genlist_item_append(ugd->ug_MainWindow.ug_pNaviGenlist, pNode, ugd, 0, &ugd->ug_Status.ug_itc); + } + + } + + if (pNode != NULL) { + UG_SAFE_FREE_CHAR(pNode->ext); + free(pNode); + pNode = NULL; + } + } + break; + case UG_MF_INOTI_DELETE: + case UG_MF_INOTI_MOVE_OUT: + /*/1 TODO: remove item from list */ + path = g_strconcat(ugd->ug_Status.ug_pPath->str, "/", msg->name, NULL); + it = elm_genlist_first_item_get(ugd->ug_MainWindow.ug_pNaviGenlist); + while (it) { + itemData = elm_object_item_data_get(it); + if (itemData->ug_pItemName == NULL || itemData->ug_pItemName->str == NULL) { + ug_debug(); + continue; + } + if (g_strcmp0(path, itemData->ug_pItemName->str) == 0) { + elm_object_item_del(it); + break; + } + + it = elm_genlist_item_next_get(it); + } + count = elm_genlist_items_count(ugd->ug_MainWindow.ug_pNaviGenlist); + ugd->ug_Status.ug_bNoContentFlag = !count; + + break; + case UG_MF_INOTI_MODIFY: + /*/1 TODO: update item in list */ + ugd->ug_MainWindow.ug_pNaviGenlist = newContent = mf_ug_genlist_create_content_list_view(ugd); + mf_ug_navi_bar_set_new_content(ugd->ug_MainWindow.ug_pNaviLayout, newContent); + break; + case UG_MF_INOTI_DELETE_SELF: + case UG_MF_INOTI_MOVE_SELF: + /*/1 TODO: watching directory is removed, change current directory. */ + { + GString *current = NULL; + current = g_string_new(ugd->ug_Status.ug_pPath->str); + parent = __mf_ug_cb_dir_pipe_get_parent(current); + + ugNaviBar *pNavi_s = mf_ug_navi_bar_get_in_use_navi(ugd); + + + g_string_free(ugd->ug_Status.ug_pPath, TRUE); + ugd->ug_Status.ug_pPath = NULL; + ugd->ug_Status.ug_pPath = parent; + + if (pNavi_s->ug_pCurrentPath != NULL) { + free(pNavi_s->ug_pCurrentPath); + pNavi_s->ug_pCurrentPath = NULL; + } + pNavi_s->ug_pCurrentPath = g_strdup(parent->str); + + + + mf_ug_navi_bar_create_default_view(ugd); + } + break; + default: + ug_mf_error("Unknown event"); + break; + } + mf_ug_ctrl_bar_set_item_disable(ugd); + if (msg->name) { + free(msg->name); + msg->name = NULL; + } + } + UG_TRACE_END; +} + + +#ifdef UG_THUMB_REAL_TIME_UPDATE +Eina_Bool mf_ug_cb_thumb_timer_cb(void *data) +{ + ugListItemData *itemData = (ugListItemData *)data; + ug_mf_retvm_if(itemData == NULL, EINA_FALSE, "input params is NULL"); + ugData *ugd = (ugData *)itemData->ug_pData; + ug_mf_retvm_if(ugd == NULL, EINA_FALSE, "ugd is NULL"); + + bool allright_flag = true; + Evas_Object *pContent = NULL; + + if (ugd->ug_Status.ug_pThumbUpdateTimer == NULL) { + return EINA_FALSE; + } + + /****read the realized part of the list****/ + if (itemData->ug_pItem) { + pContent = elm_object_item_widget_get(itemData->ug_pItem); + if (pContent == NULL) { + ugd->ug_Status.ug_pThumbUpdateTimer = NULL; + return EINA_FALSE; + } + } else { + ugd->ug_Status.ug_pThumbUpdateTimer = NULL; + return EINA_FALSE; + } + Eina_List *realized_list = elm_genlist_realized_items_get(pContent); + Eina_List *list = NULL; + Elm_Object_Item *it; + ugListItemData *item_data = NULL; + + if (realized_list == NULL) { + allright_flag = false; + } + + EINA_LIST_FOREACH(realized_list, list, it) { + item_data = (ugListItemData *)elm_object_item_data_get(it); + if (item_data == NULL) + continue; + + if (item_data->ug_bRealThumbFlag == false) { + ug_debug("Update item: %s", item_data->ug_pItemName->str); + if (ecore_file_is_dir(item_data->ug_pItemName->str) == true) { + item_data->ug_pThumbPath = strdup(UG_ICON_FOLDER); + item_data->ug_bRealThumbFlag = true; + elm_object_item_data_set(it, item_data); + elm_genlist_item_update(it); + + } else if (ecore_file_exists(item_data->ug_pItemName->str)) { + char *new_thumb = NULL; + int thumbnail_type = 0; + thumbnail_type = mf_ug_file_attr_get_file_icon(item_data->ug_pItemName->str, NULL, &new_thumb); + if (new_thumb) { + if (thumbnail_type == MF_UG_THUMBNAIL_TYPE_DEFAULT) { + if (item_data->ug_pThumbPath && g_strcmp0(new_thumb, item_data->ug_pThumbPath) == 0) { + allright_flag = FALSE; + } else { + if (item_data->ug_pThumbPath) { + free(item_data->ug_pThumbPath); + item_data->ug_pThumbPath = NULL; + } + item_data->ug_pThumbPath = strdup(new_thumb); + item_data->ug_bRealThumbFlag = TRUE; + elm_object_item_data_set(it, item_data); + elm_genlist_item_update(it); + free(new_thumb); + new_thumb = NULL; + } + + } else { + if (item_data->ug_pThumbPath) { + free(item_data->ug_pThumbPath); + item_data->ug_pThumbPath = NULL; + } + item_data->ug_pThumbPath = strdup(new_thumb); + item_data->ug_bRealThumbFlag = TRUE; + elm_object_item_data_set(it, item_data); + elm_genlist_item_update(it); + free(new_thumb); + new_thumb = NULL; + } + } else { + allright_flag = false; + } + } + } + } + + if (allright_flag == false) { + return EINA_TRUE; + } else { + ugd->ug_Status.ug_pThumbUpdateTimer = NULL; + return EINA_FALSE; + } +} +#endif + +void mf_ug_cb_create_new_folder(void *data, Evas_Object * obj, void *event_info) +{ + UG_TRACE_BEGIN; + ug_mf_retm_if(data == NULL, "data is NULL"); + + ugData *ugd = (ugData *)data; + UG_SAFE_FREE_OBJ(ugd->ug_MainWindow.ug_pContextPopup); + + if (ugd->ug_Status.ug_b_NaviPushFlag) { + UG_TRACE_END; + return; + } + + if (ugd->ug_Status.ug_iMore == UG_MORE_CREATE_FOLDER) + return; + + int ret = 0; + ugd->ug_Status.ug_iMore = UG_MORE_CREATE_FOLDER; + + ret = mf_ug_util_check_disk_space(ugd); + if (ret == MYFILE_ERR_NO_FREE_SPACE) { + ugd->ug_Status.ug_iMore = UG_MORE_DEFAULT; + return; + } +#ifdef UG_THUMB_REAL_TIME_UPDATE + if (ugd->ug_Status.ug_pThumbUpdateTimer != NULL) { + ecore_timer_del(ugd->ug_Status.ug_pThumbUpdateTimer); + ugd->ug_Status.ug_pThumbUpdateTimer = NULL; + } +#endif + ugd->ug_MainWindow.ug_pNewFolderPopup = mf_ug_popup_create_new_folder_popup(ugd, MF_UG_LABEL_CREATE); + +} + +void mf_ug_cb_warning_popup_cb(void *data, Evas_Object * obj, void *event_info) +{ + UG_TRACE_BEGIN; + ug_mf_retm_if(data == NULL, "data is NULL"); + ugData *ugd = (ugData *)data; + + Evas_Object *btn = (Evas_Object *)obj; + const char *label = elm_object_text_get(btn); + + if (g_strcmp0(label, MF_UG_LABEL_OK) == 0 ) { + evas_object_del(ugd->ug_MainWindow.ug_pNormalPopup); + ugd->ug_MainWindow.ug_pNormalPopup = NULL; + } +} + +void mf_ug_cb_reach_max_len_cb(void *data, Evas_Object * obj, void *event_info) +{ + UG_TRACE_BEGIN; + ug_mf_retm_if(data == NULL, "data is NULL"); + ugData *ugd = (ugData *)data; + mf_ug_popup_indicator_popup(MF_UG_LABEL_MAX_CHARACTER_REACHED); + + UG_TRACE_END; +} + +void mf_ug_cb_eraser_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source) +{ + elm_entry_entry_set(data, ""); +} + +void mf_ug_cb_cancel_new_folder_cb(void *data, Evas_Object * obj, void *event_info) +{ + UG_TRACE_BEGIN; + ug_mf_retm_if(data == NULL, "data is NULL"); + ugData *ugd = (ugData *)data; + + ugd->ug_Status.ug_iMore = UG_MORE_DEFAULT; + ecore_imf_context_input_panel_hide(elm_entry_imf_context_get(ugd->ug_MainWindow.ug_pEntry)); + evas_object_del(ugd->ug_MainWindow.ug_pEntry); + + UG_SAFE_FREE_OBJ(ugd->ug_MainWindow.ug_pNewFolderPopup); +} + +static int __mf_cb_imk_cancel_cb(void *data) +{ + UG_TRACE_BEGIN; + ug_mf_retvm_if(data == NULL, false, "data is NULL"); + ugData *ugd = (ugData *)data; + + mf_ug_cb_cancel_new_folder_cb(ugd, NULL, NULL); + ugd->ug_Status.popup_del_idler = NULL; + return 0; +} + + +static void __mf_ug_cb_illegal_char_popup_cb(void *data, Evas_Object * obj, void *event_info) +{ + UG_TRACE_BEGIN; + ug_mf_retm_if(data == NULL, "data is NULL"); + ugData *ugd = (ugData *)data; + + Evas_Object *btn = (Evas_Object *)obj; + const char *label = elm_object_text_get(btn); + + if (g_strcmp0(label, MF_UG_LABEL_YES) == 0 ) { + UG_SAFE_FREE_OBJ(ugd->ug_MainWindow.ug_pNormalPopup); + + Evas_Object *entry = ugd->ug_MainWindow.ug_pEntry; + if (entry != NULL) + elm_object_focus_set(entry, EINA_TRUE); + + } else if (g_strcmp0(label, MF_UG_LABEL_NO) == 0 ) { + UG_SAFE_FREE_OBJ(ugd->ug_MainWindow.ug_pNormalPopup); + ugd->ug_Status.popup_del_idler = ecore_idler_add((Ecore_Task_Cb) __mf_cb_imk_cancel_cb, ugd); + } + +} + +static int __mf_ug_cb_ime_mkdir_cb(void *data, char *fileName) +{ + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + + ug_mf_retvm_if(ugd == NULL, MYFILE_ERR_SRC_ARG_INVALID, "ugd is NULL"); + ug_mf_retvm_if(fileName == NULL, MYFILE_ERR_SRC_ARG_INVALID, "data is NULL"); + ug_mf_retvm_if(ugd->ug_Status.ug_pPath == NULL, MYFILE_ERR_SRC_ARG_INVALID, "ugd is NULL"); + ug_mf_retvm_if(ugd->ug_Status.ug_pPath->str == NULL, MYFILE_ERR_SRC_ARG_INVALID, "ugd is NULL"); + + + int ret = 0; + const char *message = NULL; + const char *left_label = NULL; + const char *right_label = NULL; + + left_label = MF_UG_LABEL_YES; + right_label = MF_UG_LABEL_NO; + if (strlen(fileName)) { + + GString *fullpathdir = g_string_new(ugd->ug_Status.ug_pPath->str); + + if (fullpathdir == NULL) { + mf_ug_util_operation_alloc_failed(ugd); + return MYFILE_ERR_ALLOCATE_MEMORY_FAIL; + } + GString *fullpathname = g_string_new(fileName); + + if (fullpathname == NULL) { + g_string_free(fullpathdir, TRUE); + fullpathdir = NULL; + mf_ug_util_operation_alloc_failed(ugd); + return MYFILE_ERR_ALLOCATE_MEMORY_FAIL; + } + /*check the space */ + gchar *test_space = g_strdup(fileName); + if (test_space == NULL) { + g_string_free(fullpathdir, TRUE); + fullpathdir = NULL; + g_string_free(fullpathname, TRUE); + fullpathname = NULL; + mf_ug_util_operation_alloc_failed(ugd); + return MYFILE_ERR_ALLOCATE_MEMORY_FAIL; + } + if (strlen(g_strchug(test_space)) == 0) { + message = MF_UG_LABEL_NAME_INVALID; /*TODO */ + ugd->ug_MainWindow.ug_pNormalPopup = mf_ug_popup_create(ugd, UG_POPMODE_TEXT_TWO_BTN, NULL, message, + left_label, right_label, NULL, + __mf_ug_cb_illegal_char_popup_cb, ugd); + + g_string_free(fullpathdir, TRUE); + fullpathdir = NULL; + g_string_free(fullpathname, TRUE); + fullpathname = NULL; + g_free(test_space); + test_space = NULL; + return MYFILE_ERR_DIR_CREATE_FAIL; + } + + g_free(test_space); + test_space = NULL; + + /*check if input name is valid */ + if (mf_ug_file_attr_is_valid_name(fullpathname->str) == MYFILE_ERR_INVALID_FILE_NAME) { + + message = MF_UG_LABEL_ILLEGAL_CHAR; + ugd->ug_MainWindow.ug_pNormalPopup = mf_ug_popup_create(ugd, UG_POPMODE_TEXT_TWO_BTN, NULL, message, + left_label, right_label, NULL, + __mf_ug_cb_illegal_char_popup_cb, ugd); + g_string_free(fullpathdir, TRUE); + fullpathdir = NULL; + g_string_free(fullpathname, TRUE); + fullpathname = NULL; + + return MYFILE_ERR_DIR_CREATE_FAIL; + } + + GString *fullpath = NULL; + char *temp_fullpath = g_strconcat(fullpathdir->str, "/", fullpathname->str, NULL); + if (temp_fullpath) { + fullpath = g_string_new(temp_fullpath); + + free(temp_fullpath); + temp_fullpath = NULL; + if (fullpath == NULL) { + g_string_free(fullpathdir, TRUE); + fullpathdir = NULL; + g_string_free(fullpathname, TRUE); + fullpathname = NULL; + mf_ug_util_operation_alloc_failed(ugd); + return MYFILE_ERR_ALLOCATE_MEMORY_FAIL; + } + } else { + g_string_free(fullpathdir, TRUE); + fullpathdir = NULL; + g_string_free(fullpathname, TRUE); + fullpathname = NULL; + return MYFILE_ERR_ALLOCATE_MEMORY_FAIL; + } + + /*check whether DIR name is override(DIR name has no extention) */ + /*check whether path length is override */ + if ((strlen(fullpathdir->str) + strlen(fullpathname->str)) > MYFILE_FILE_PATH_LEN_MAX) { + + message = MF_UG_LABEL_PATH_REACH_MAX_LEN; + ugd->ug_MainWindow.ug_pNormalPopup = mf_ug_popup_create(ugd, UG_POPMODE_TEXT_TWO_BTN, NULL, message, + left_label, right_label, NULL, + __mf_ug_cb_illegal_char_popup_cb, ugd); + g_string_free(fullpathdir, TRUE); + fullpathdir = NULL; + g_string_free(fullpathname, TRUE); + fullpathname = NULL; + ret = MYFILE_ERR_DIR_CREATE_FAIL; + } + /*check if duplicated name */ + else if (mf_ug_file_attr_is_duplicated_name(ugd->ug_Status.ug_pPath->str, fileName) == MYFILE_ERR_DUPLICATED_NAME) { + message = MF_UG_LABEL_DUP_NAME; + ugd->ug_MainWindow.ug_pNormalPopup = mf_ug_popup_create(ugd, UG_POPMODE_TEXT_TWO_BTN, NULL, message, + left_label, right_label, NULL, + __mf_ug_cb_illegal_char_popup_cb, ugd); + + g_string_free(fullpathdir, TRUE); + fullpathdir = NULL; + g_string_free(fullpathname, TRUE); + fullpathname = NULL; + ret = MYFILE_ERR_DIR_CREATE_FAIL; + } + /*check if DIR name is all spaces */ + else { + ret = mf_ug_fm_svc_wrapper_create_service(ugd, fullpath); + /*check whether operate on read only area */ + if (errno == EROFS) { + message = MF_UG_LABEL_OPER_READ_ONLY; + ugd->ug_MainWindow.ug_pNormalPopup = mf_ug_popup_create(ugd, UG_POPMODE_TEXT, NULL, message, NULL, NULL, NULL, NULL, NULL); + ret = MYFILE_ERR_DIR_CREATE_FAIL; + } else if (ret) { + message = MF_UG_LABEL_CREATE_DIR_FAILED; + ugd->ug_MainWindow.ug_pNormalPopup = mf_ug_popup_create(ugd, UG_POPMODE_TEXT, NULL, message, NULL, NULL, NULL, NULL, NULL); + } + + g_string_free(fullpathdir, TRUE); + fullpathdir = NULL; + g_string_free(fullpathname, TRUE); + fullpathname = NULL; + g_string_free(fullpath, TRUE); + fullpath = NULL; + + } + } else { + message = MF_UG_LABEL_EMPTY_FOLDER_NAME; + + ugd->ug_MainWindow.ug_pNormalPopup = mf_ug_popup_create(ugd, UG_POPMODE_TEXT_TWO_BTN, NULL, message, + left_label, right_label, NULL, + __mf_ug_cb_illegal_char_popup_cb, ugd); + ret = MYFILE_ERR_DIR_CREATE_FAIL; + } + return ret; +} + + +void mf_ug_cb_save_cb(void *data, Evas_Object *obj, void *event_info) +{ + UG_TRACE_BEGIN; + ug_mf_retm_if(data == NULL, "data is NULL"); + ugData *ugd = (ugData *)data; + + if (ugd->ug_Status.ug_b_NaviPushFlag) { + UG_TRACE_END; + return; + } + + int ret = 0; + const char *message = NULL; + const char *left_label = NULL; + const char *right_label = NULL; + + if (ugd->ug_Status.ug_iMore == UG_MORE_CREATE_FOLDER) { + const char *entry_data = NULL; + char *name = NULL; + + /*hide IMF*/ + if (ugd->ug_MainWindow.ug_pEntry != NULL) { + Ecore_IMF_Context *imf_context = elm_entry_imf_context_get(ugd->ug_MainWindow.ug_pEntry); + if (imf_context != NULL) + ecore_imf_context_hide(imf_context); + } + + entry_data = elm_entry_entry_get(ugd->ug_MainWindow.ug_pEntry); + + if (entry_data) { + name = elm_entry_markup_to_utf8(entry_data); + } else { + message = MF_UG_LABEL_GET_NAME_FAILED; + left_label = MF_UG_LABEL_YES; + right_label = MF_UG_LABEL_NO; + ugd->ug_MainWindow.ug_pNormalPopup = mf_ug_popup_create(ugd, UG_POPMODE_TEXT_TWO_BTN, NULL, message, + left_label, right_label, NULL, + __mf_ug_cb_illegal_char_popup_cb, ugd); + return; + } + + if (name == NULL) + return; + + ret = __mf_ug_cb_ime_mkdir_cb(ugd, name); + if (ret == 0) { + ugd->ug_Status.ug_iMore = UG_MORE_DEFAULT; + ecore_imf_context_input_panel_hide(elm_entry_imf_context_get(ugd->ug_MainWindow.ug_pEntry)); + evas_object_del(ugd->ug_MainWindow.ug_pEntry); + UG_SAFE_FREE_OBJ(ugd->ug_MainWindow.ug_pNewFolderPopup); + mf_ug_navi_bar_create_default_view(ugd); + } + + if (name != NULL) { + free(name); + name = NULL; + } + } +} + +void mf_ug_cb_lcd_state_changed_cb(power_state_e state, void *user_data) +{ + UG_TRACE_BEGIN; + + ug_mf_retm_if(user_data == NULL, "user_data is NULL"); + ugData *ugd = (ugData *)user_data; + + if(state == POWER_STATE_SCREEN_OFF){ + if (0 != ugd->ug_ListPlay.ug_Player) { + ug_debug("destory the playing file"); + mf_ug_list_play_destory_playing_file(ugd); + mf_ug_list_disable_play_itc(ugd, true); + UG_SAFE_FREE_CHAR(ugd->ug_ListPlay.ug_pPlayFilePath); + } + } + UG_TRACE_END; +} + + +Eina_Bool mf_ug_cb_popup_del_idler_cb(void *data) +{ + UG_TRACE_BEGIN; + ug_mf_retvm_if(data == NULL, ECORE_CALLBACK_CANCEL, "data is NULL"); + ugData *ugd = (ugData *)data; + + UG_SAFE_FREE_OBJ(ugd->ug_MainWindow.ug_pSearchPopup); + ugd->ug_Status.popup_del_idler = NULL; + + return ECORE_CALLBACK_CANCEL; +} + +void mf_ug_cb_entry_button_pressed_cb(void *data, Evas_Object * obj, void *event_info) +{ + UG_TRACE_BEGIN; + ug_mf_retm_if(data == NULL, "data is NULL"); + + Evas_Object *home_button_ic = (Evas_Object *)data; + elm_image_file_set(home_button_ic, UG_ICON_ENTRY_FOLDER_PRESS, NULL); +} + +void mf_ug_cb_entry_button_unpressed_cb(void *data, Evas_Object * obj, void *event_info) +{ + UG_TRACE_BEGIN; + ug_mf_retm_if(data == NULL, "data is NULL"); + + Evas_Object *home_button_ic = (Evas_Object *)data; + elm_image_file_set(home_button_ic, UG_ICON_ENTRY_FOLDER, NULL); +} + +void mf_ug_cb_play_button_pressed_cb(void *data, Evas_Object * obj, void *event_info) +{ + UG_TRACE_BEGIN; + ug_mf_retm_if(data == NULL, "data is NULL"); + ugData *ugd = (ugData *)data; + + const char *play_icon = NULL; + + Evas_Object *music_icon = elm_object_part_content_get(obj, "icon"); + if(ugd->ug_ListPlay.ug_iPlayState != PLAY_STATE_PLAYING) { + play_icon = UG_ICON_MUSIC_PLAY_WHITE_PRESS; + } else { + play_icon = UG_ICON_MUSIC_PAUSE_WHITE_PRESS; + } + + elm_image_file_set(music_icon, play_icon, NULL); +} + +void mf_ug_cb_play_button_unpressed_cb(void *data, Evas_Object * obj, void *event_info) +{ + UG_TRACE_BEGIN; + ug_mf_retm_if(data == NULL, "data is NULL"); + ugData *ugd = (ugData *)data; + + const char *play_icon = NULL; + + Evas_Object *music_icon = elm_object_part_content_get(obj, "icon"); + if(ugd->ug_ListPlay.ug_iPlayState != PLAY_STATE_PLAYING) { + play_icon = UG_ICON_MUSIC_PLAY_WHITE; + } else { + play_icon = UG_ICON_MUSIC_PAUSE_WHITE; + } + + elm_image_file_set(music_icon, play_icon, NULL); +} + +void mf_ug_cb_more_cb(void *data, Evas_Object * obj, void *event_info) +{ + UG_TRACE_BEGIN; + ug_mf_retm_if(data == NULL, "data is NULL"); + ugData *ugd = (ugData *)data; + + mf_ug_context_popup_create_more(ugd, obj); +} + + diff --git a/src/common/mf-ug-fm-svc-wapper.c b/src/common/mf-ug-fm-svc-wapper.c new file mode 100644 index 0000000..4cea7b6 --- /dev/null +++ b/src/common/mf-ug-fm-svc-wapper.c @@ -0,0 +1,946 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.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 <sys/statvfs.h> + +#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_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"); + + 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"); + } + UG_TRACE_END; + 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_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; + 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 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); + + 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) { + 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); + 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) +{ + GString *g_path = (GString *)data; + ug_mf_retvm_if(g_path == NULL, false, "g_path is NULL"); + + if (!strcmp(g_path->str, PHONE_FOLDER)) { + return true; + } else if (!strcmp(g_path->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(temp); + } + UG_SAFE_FREE_CHAR(utf8_string); + + } 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 = NULL; + gboolean ret = FALSE; + ret = g_utf8_validate(utf8_last, d_value, &end); + if (ret == TRUE) { + d_value = last_len - strlen(end); + utf8_last[d_value] = '\0'; + output = g_strconcat(output, sep, utf8_last, omit, NULL); + UG_SAFE_FREE_CHAR(temp); + } + } else { + output = g_strconcat(output, sep, utf8_last, NULL); + UG_SAFE_FREE_CHAR(temp); + } + } + else { + output = g_strdup(utf8_last); + UG_SAFE_FREE_CHAR(temp); + } + UG_SAFE_FREE_CHAR(utf8_last); + 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; + +} + +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) +{ + //mf_debug("%s %d\n", __func__, __LINE__); + 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); + } + //mf_debug("new_file_name [%s]", new_file_name); + //mf_debug("original_file_name [%s]", new_file_name); + UG_SAFE_FREE_CHAR(file_name_without_ext); + + ug_debug("new name is %s\n", new_file_name); + + 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); + //mf_debug("rename finished\n"); + error_code = MYFILE_ERR_NONE; + goto Exception; + } else { + //mf_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 || file_name->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; +} diff --git a/src/common/mf-ug-inotify-handle.c b/src/common/mf-ug-inotify-handle.c new file mode 100644 index 0000000..53734db --- /dev/null +++ b/src/common/mf-ug-inotify-handle.c @@ -0,0 +1,349 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.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 <stdio.h> +#include <glib.h> +#include <sys/inotify.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#include <stdint.h> +#include <fcntl.h> +#include <errno.h> +#include <pthread.h> + +#include "mf-ug-dlog.h" +#include "mf-ug-inotify-handle.h" + +#define MF_WATCH_FLAGS \ + IN_CREATE | IN_DELETE | IN_DELETE_SELF | IN_MOVE_SELF | IN_MOVED_FROM | IN_MOVED_TO | IN_CLOSE_WRITE + +#define MF_EVENT_SIZE (sizeof(struct inotify_event)) +/** reasonable guess as to size of 1024 events */ +#define MF_EVENT_BUF_LEN (1024 * (MF_EVENT_SIZE + 16)) +#define MF_U32_MAX 0xFFFFFFFF +typedef struct _mf_inotify_t { + int fd; + int wd; + gchar *path; + unsigned int prev_event; + pthread_t monitor; + mf_ug_inotify_cb callback; + void *u_data; +} mf_inotify_t; + +static pthread_mutex_t mf_noti_lock; +static mf_inotify_t *g_handle; + +static void __mf_ug_inotify_handle_free_handle(void) +{ + pthread_mutex_destroy(&mf_noti_lock); + + if (g_handle) { + if (g_handle->fd >= 0) { + close(g_handle->fd); + g_handle->fd = -1; + } + if (g_handle->path) { + g_free(g_handle->path); + g_handle->path = NULL; + } + g_free(g_handle); + g_handle = NULL; + } + + return; +} + +static mf_inotify_t *__mf_ug_inotify_handle_init_handle(void) +{ + __mf_ug_inotify_handle_free_handle(); + g_handle = g_new0(mf_inotify_t, 1); + + if (g_handle) { + g_handle->fd = -1; + pthread_mutex_init(&mf_noti_lock, NULL); + pthread_mutex_lock(&mf_noti_lock); + g_handle->wd = -1; + pthread_mutex_unlock(&mf_noti_lock); + } + + return g_handle; +} + +static void __mf_ug_inotify_handle_clean_up_thread(void *data) +{ + pthread_mutex_t *lock = (pthread_mutex_t *) data; + ug_mf_debug("Thread cancel Clean_up function"); + if (lock) { + pthread_mutex_unlock(lock); + } + return; +} + + +static gpointer __mf_ug_inotify_handle_watch_thread(gpointer user_data) +{ + mf_inotify_t *handle = (mf_inotify_t *) user_data; + int oldtype = 0; + + ug_mf_retvm_if(handle == NULL, NULL, "handle is NULL"); + ug_mf_debug("Create __mf_ug_inotify_handle_watch_thread!!! "); + + pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldtype); + + while (1) { + ssize_t len = 0; + uint32_t i = 0; + char event_buff[MF_EVENT_BUF_LEN] = { 0, }; + + if (handle->fd < 0) { + ug_mf_error("fd is not a vaild one"); + pthread_exit(NULL); + } + + len = read(handle->fd, event_buff, sizeof(event_buff) - 1); + if (len <= 0 || len > sizeof(event_buff) - 1) { + ug_mf_error("Fail to read() -fd : %d, len : %d", handle->fd, len); + continue; + } + + while (i < len) { + struct inotify_event *pevent = (struct inotify_event *)&event_buff[i]; + mf_ug_inotify_event s_event = UG_MF_INOTI_NONE; + ug_mf_error("mask=%x dir=%s len=%d name=%s", + pevent->mask, (pevent->mask & IN_ISDIR) ? "yes" : "no", pevent->len, (pevent->len) ? pevent->name : NULL); + + if (pevent->len && strncmp(pevent->name, ".", 1) == 0) { + s_event = UG_MF_INOTI_NONE; + } else if (pevent->mask & IN_ISDIR) { + if (pevent->mask & IN_DELETE_SELF) + s_event = UG_MF_INOTI_DELETE_SELF; + + if (pevent->mask & IN_MOVE_SELF) + s_event = UG_MF_INOTI_MOVE_SELF; + + if (pevent->mask & IN_CREATE) + s_event = UG_MF_INOTI_CREATE; + + if (pevent->mask & IN_DELETE) + s_event = UG_MF_INOTI_DELETE; + + if (pevent->mask & IN_MOVED_FROM) + s_event = UG_MF_INOTI_MOVE_OUT; + + if (pevent->mask & IN_MOVED_TO) + s_event = UG_MF_INOTI_MOVE_IN; + } else { + if (pevent->mask & IN_CREATE) { + s_event = UG_MF_INOTI_NONE; + handle->prev_event = IN_CREATE; + } + + if (pevent->mask & IN_CLOSE_WRITE) { + if (handle->prev_event == IN_CREATE) { + s_event = UG_MF_INOTI_CREATE; + } else { + s_event = UG_MF_INOTI_MODIFY; + } + handle->prev_event = 0; + } + + if (pevent->mask & IN_DELETE) + s_event = UG_MF_INOTI_DELETE; + + if (pevent->mask & IN_MOVED_FROM) + s_event = UG_MF_INOTI_MOVE_OUT; + + if (pevent->mask & IN_MOVED_TO) + s_event = UG_MF_INOTI_MOVE_IN; + } + + ug_mf_debug("s_event : %d, prev_event: %x, callback : %p", s_event, handle->prev_event, handle->callback); + if (s_event != UG_MF_INOTI_NONE) { + pthread_cleanup_push(__mf_ug_inotify_handle_clean_up_thread, (void *)&mf_noti_lock); + pthread_mutex_lock(&mf_noti_lock); + if (handle->callback) { + handle->callback(s_event, (pevent->len) ? pevent->name : NULL, handle->u_data); + } + pthread_mutex_unlock(&mf_noti_lock); + pthread_cleanup_pop(0); + } + + if ((MF_U32_MAX - pevent->len) >= MF_EVENT_SIZE) { + i += sizeof(struct inotify_event) + pevent->len; + } else { + break; + } + } + } + + ug_mf_debug("end __mf_ug_inotify_handle_watch_thread!!! "); + + return NULL; +} + +int mf_ug_inotify_handle_init_inotify(void) +{ + mf_inotify_t *handle = NULL; + handle = __mf_ug_inotify_handle_init_handle(); + ug_mf_retvm_if(handle == NULL, -1, "fail to __mf_ug_inotify_handle_init_handle()"); + + handle->fd = inotify_init(); + + if (handle->fd < 0) { + switch (errno) { + case EMFILE: + ug_mf_error("The user limit on the total number of inotify instances has been reached.\n"); + break; + case ENFILE: + ug_mf_error("The system limit on the total number of file descriptors has been reached.\n"); + break; + case ENOMEM: + ug_mf_error("Insufficient kernel memory is available.\n"); + break; + default: + ug_mf_error("Fail to inotify_init(), Unknown error.\n"); + break; + } + return -1; + } + pthread_create(&handle->monitor, NULL, __mf_ug_inotify_handle_watch_thread, handle); + return 0; +} + +int mf_ug_inotify_handle_add_inotify_watch(const char *path, mf_ug_inotify_cb callback, void *user_data) +{ + mf_inotify_t *handle = NULL; + handle = g_handle; + ug_mf_retvm_if(handle == NULL, -1, "handle is NULL"); + + if (handle->wd >= 0) { + ug_mf_warnig("The mf_notify module supports single instance, the watch descript [%d] is removed automatically\n", handle->wd); + mf_ug_inotify_handle_rm_inotify_watch(); + } + + pthread_mutex_lock(&mf_noti_lock); + handle->wd = inotify_add_watch(handle->fd, path, MF_WATCH_FLAGS); + + if (handle->wd < 0) { + switch (errno) { + case EACCES: + ug_mf_error("Read access to the given file is not permitted.\n"); + break; + case EBADF: + ug_mf_error("The given file descriptor is not valid.\n"); + handle->fd = -1; + break; + case EFAULT: + ug_mf_error("pathname points outside of the process's accessible address space.\n"); + break; + case EINVAL: + ug_mf_error("The given event mask contains no legal events; or fd is not an inotify file descriptor.\n"); + break; + case ENOMEM: + ug_mf_error("Insufficient kernel memory is available.\n"); + break; + case ENOSPC: + ug_mf_error("User limit on the total num of inotify watch was reached or the kernel failed to alloc a needed resource.\n"); + break; + default: + ug_mf_error("Fail to ug_ug_mf_inotify_add_watch(), Unknown error.\n"); + break; + } + pthread_mutex_unlock(&mf_noti_lock); + return -1; + } + + ug_mf_debug("start watching [%s] directory", path); + if (handle->path) { + g_free(handle->path); + handle->path = NULL; + } + handle->path = g_strdup(path); + handle->callback = callback; + handle->u_data = user_data; + pthread_mutex_unlock(&mf_noti_lock); + + return 0; +} + + + +int mf_ug_inotify_handle_rm_inotify_watch(void) +{ + int ret = -1; + mf_inotify_t *handle = NULL; + + handle = g_handle; + ug_mf_retvm_if(handle == NULL, -1, "handle is NULL"); + + if (handle->fd < 0 || handle->wd < 0) { + ug_mf_warnig("inotify is not initialized or has no watching dir - fd [%d] wd [%d]", handle->fd, handle->wd); + return 0; + } + + pthread_mutex_lock(&mf_noti_lock); + + ret = inotify_rm_watch(handle->fd, handle->wd); + if (ret < 0) { + switch (errno) { + case EBADF: + ug_mf_error("fd is not a valid file descriptor\n"); + handle->fd = -1; + break; + case EINVAL: + ug_mf_error("The watch descriptor wd is not valid; or fd is not an inotify file descriptor.\n"); + handle->wd = -1; + break; + default: + ug_mf_error("Fail to mf_ug_inotify_handle_add_inotify_watch(), Unknown error.\n"); + break; + } + pthread_mutex_unlock(&mf_noti_lock); + return -1; + } + ug_mf_debug("stop watching [%s] directory", handle->path); + if (handle->path) { + g_free(handle->path); + handle->path = NULL; + } + handle->callback = NULL; + handle->u_data = NULL; + handle->wd = -1; + pthread_mutex_unlock(&mf_noti_lock); + + return 0; +} + +void mf_ug_inotify_handle_finalize_inotify(void) +{ + mf_inotify_t *handle = NULL; + handle = g_handle; + + ug_mf_retm_if(handle == NULL, "handle is NULL"); + + if (handle->fd >= 0 && handle->wd >= 0) { + mf_ug_inotify_handle_rm_inotify_watch(); + } + + pthread_cancel(handle->monitor); + pthread_join(handle->monitor, NULL); + + __mf_ug_inotify_handle_free_handle(); + + return; +} diff --git a/src/common/mf-ug-list-play.c b/src/common/mf-ug-list-play.c new file mode 100644 index 0000000..74f46c6 --- /dev/null +++ b/src/common/mf-ug-list-play.c @@ -0,0 +1,1785 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.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 <stdio.h> +#include <Elementary.h> +#include <Ecore_X.h> +#include <vconf.h> +#include <stdbool.h> + + +#include "mf-ug-main.h" +#include "../../data/ug_edc_common.h" +#include "mf-ug-conf.h" +#include "mf-ug-cb.h" +#include "mf-ug-fm-svc-wrapper.h" +#include "mf-ug-util.h" +#include "mf-ug-winset.h" +#include "mf-ug-dlog.h" +#include "mf-ug-fs-util.h" +#include "mf-ug-resource.h" +#include "mf-ug-list-play.h" +static mf_player_cbs *g_player_cbs = NULL; +static Ecore_Pipe *g_player_pipe = NULL; + +static void __mf_ug_list_play_control_cb(void *data); +static bool __mf_ug_list_play_play_current_file(void *data); + + +/****************************** +** Prototype : __mf_ug_list_play_init_data +** Description : Samsung +** Input : void *data +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +static void __mf_ug_list_play_init_data(void *data) +{ + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + + ug_mf_retm_if(ugd == NULL, "ugd is NULL"); + + if (ugd->ug_ListPlay.ug_Player != 0) { + mf_ug_list_play_destory_playing_file(ugd); + ugd->ug_ListPlay.ug_Player = 0; + } + ugd->ug_ListPlay.ug_iPlayState = PLAY_STATE_INIT; + UG_SAFE_FREE_CHAR(ugd->ug_ListPlay.ug_pPlayFilePath); + UG_TRACE_END; +} + +/****************************** +** Prototype : __mf_ug_list_play_drm_has_valid_ro +** Description : Samsung +** Input : char *path +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +static bool __mf_ug_list_play_drm_has_valid_ro(char *path) +{ + UG_TRACE_BEGIN; + drm_result_e res = DRM_RETURN_INVALID_ARG; + drm_license_status_e licence_status; + + if (path) { + res = drm_get_license_status(path, DRM_PERMISSION_TYPE_PLAY, &licence_status); + } + + if (res == DRM_RETURN_SUCCESS && licence_status == DRM_LICENSE_STATUS_VALID) { + return true; + } else { + return false; + } +} + + +/****************************** +** Prototype : __mf_ug_list_play_check_drm_left_ro +** Description : Samsung +** Input : void *data +** char *path +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +static bool __mf_ug_list_play_check_drm_left_ro(void *data, char *path) +{ + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + ug_mf_retvm_if(ugd == NULL, false, "ugd is NULL"); + + + char left_ro_message[MAX_MESSAGE_LEN] = "\0"; + + bool ro_valid = false; + bool expired = false; + + + const char *title = ecore_file_file_get(path); + ugd->ug_ListPlay.ug_bDrmContentCanPlay = false; + + if (__mf_ug_list_play_drm_has_valid_ro(path)) + { + drm_constraint_info_s constraint; + memset(&constraint, 0x0, sizeof(drm_constraint_info_s)); + + int res = drm_get_constraint_info(path, DRM_PERMISSION_TYPE_PLAY, &constraint); + if (res == DRM_RETURN_SUCCESS) { + if (constraint.const_type.is_unlimited) { + ug_debug("UNLIMITED"); + ugd->ug_ListPlay.ug_bDrmContentCanPlay = TRUE; + return TRUE; + } + + if (constraint.const_type.is_count) { + int remain_count = constraint.remaining_count; + + if (remain_count == 1) { + snprintf(left_ro_message, sizeof(left_ro_message), "You can play \"%s\" just one more time", title); + ro_valid = true; + ugd->ug_ListPlay.ug_bDrmContentCanPlay = true; + } else if (remain_count == 0) { + snprintf(left_ro_message, sizeof(left_ro_message), "You can't play \"%s\" anymore", title); + ro_valid = false; + } else { + ro_valid = true; + ugd->ug_ListPlay.ug_bDrmContentCanPlay = true; + } + } + + if (constraint.const_type.is_datetime) { + ug_debug("DRM_DATETIME\n"); + snprintf(ugd->ug_ListPlay.ug_DrmInfo.validity, sizeof(ugd->ug_ListPlay.ug_DrmInfo.validity), + "%d.%d.%d %d:%d~%d.%d.%d %d:%d", + constraint.start_time.tm_mday, + constraint.start_time.tm_mon + 1, + constraint.start_time.tm_year + 109, + constraint.start_time.tm_hour, + constraint.start_time.tm_min, + constraint.end_time.tm_mday, + constraint.end_time.tm_mon + 1, + constraint.end_time.tm_year + 109, + constraint.end_time.tm_hour, + constraint.end_time.tm_min); + } + + if (constraint.const_type.is_interval) { + ug_debug("DRM_INTERVAL\n"); + snprintf(ugd->ug_ListPlay.ug_DrmInfo.validity, sizeof(ugd->ug_ListPlay.ug_DrmInfo.validity), + "until %d.%d.%d %d:%d", + constraint.interval_time.tm_mon, + constraint.interval_time.tm_mday, + constraint.interval_time.tm_year, + constraint.interval_time.tm_hour, + constraint.interval_time.tm_min); + } + + if (constraint.const_type.is_timedcount) { + int count = constraint.timed_remaining_count; + int time = constraint.timed_count_timer; + snprintf(ugd->ug_ListPlay.ug_DrmInfo.validity, sizeof(ugd->ug_ListPlay.ug_DrmInfo.validity), + "%d left (%d sec)", count, time); + ug_debug("DRM_TIMED_COUNT [%d]\n", count); + if (count == 1) + { + snprintf(left_ro_message, sizeof(left_ro_message), + "You can play \"%s\" just one more time", title); + ugd->ug_ListPlay.ug_bDrmContentCanPlay = TRUE; + } + else if (count == 0) + { + snprintf(left_ro_message, sizeof(left_ro_message), + "You can't play \"%s\" anymore", title); + } + } + + if (constraint.const_type.is_accumulated) { + int sec = constraint.accumulated_remaining_seconds; + int ndays = sec / ACCUMULATED_DATE; + ug_debug("DRM_ACCUMULATED [%d]\n", ndays); + snprintf(ugd->ug_ListPlay.ug_DrmInfo.validity, sizeof(ugd->ug_ListPlay.ug_DrmInfo.validity), + "%" UG_TIME_FORMAT " left", UG_TIME_ARGS(ndays)); + + if (ndays < ACCUMULATED_DATE) + { + snprintf(left_ro_message, sizeof(left_ro_message), + "You can play %s just one day", title); + + ugd->ug_ListPlay.ug_bDrmContentCanPlay = TRUE; + } + } + + if (constraint.const_type.is_individual) { + ug_debug("DRM_INDIVISUAL_ID [%s]", constraint.individual_id); + } + + if (constraint.const_type.is_system) { + ug_debug("DRM_SYSTEM [ID:%s, type:%d]", constraint.system_id, constraint.system_identity_type); + } + } + } else { + ug_debug("have no valid ro\n"); + snprintf(left_ro_message, sizeof(left_ro_message), "No valid RO for <br>\"%s\"", title); + ro_valid = false; + expired = true; + } + + + UG_TRACE_END; + + return true; +} + +/****************************** +** Prototype : __mf_ug_list_play_check_drm_forward +** Description : Samsung +** Input : void *data +** char *path +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +static drm_file_type_e __drm_get_file_type(void *path) +{ + drm_file_type_e type = DRM_TYPE_UNDEFINED; + drm_result_e res = -1; + + res = drm_get_file_type(path, &type); + if (res == DRM_RETURN_SUCCESS) { + return type; + } else { + return DRM_TYPE_UNDEFINED; + } +} +static bool __mf_ug_list_play_check_drm_forward(void *data, char *path) +{ + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + drm_file_type_e type = __drm_get_file_type(path); + + if (type == DRM_TYPE_OMA_V1 || type == DRM_TYPE_OMA_V2) { + + drm_file_info_s info; + memset(&info, 0x0, sizeof(drm_file_info_s)); + int ret = drm_get_file_info(path, &info); + if (ret == DRM_RETURN_SUCCESS) { + if (info.oma_info.method == DRM_METHOD_TYPE_FORWARD_LOCK) { + ugd->ug_ListPlay.ug_DrmInfo.forward = true; + return TRUE; + } + } + ugd->ug_ListPlay.ug_DrmInfo.forward = false; + return false; + } else if (type == DRM_TYPE_PLAYREADY) { + ug_debug("playready drm file"); + ugd->ug_ListPlay.ug_DrmInfo.forward = true; + } else { + ug_debug("Not supported drm type"); + UG_TRACE_END; + return false; + } + UG_TRACE_END; + return true; +} + +/****************************** +** Prototype : mf_ug_list_play_update_item_icon +** Description : +** Input : ugListItemData *data +** int state +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +static void __mf_ug_list_play_icon_hide(ugListItemData *itemData) +{ + ug_mf_retm_if(itemData == NULL, "itemData is NULL"); + ug_mf_retm_if(itemData->ug_pItem == NULL, "itemData->ug_pItem is NULL"); + + Evas_Object *btn = elm_object_item_part_content_unset(itemData->ug_pItem, "elm.icon.3"); + evas_object_hide(btn); + UG_SAFE_FREE_OBJ(btn); + itemData->ug_pPlaybtn = NULL; + +} +void mf_ug_list_disable_play_itc(void *data, bool disable) +{ + UG_TRACE_BEGIN; + + ugData *ugd = (ugData *)data; + ug_mf_retm_if(ugd == NULL, "ugd is NULL"); + + Elm_Object_Item *gl_item = NULL; + ugListItemData *itemData = NULL; + Evas_Object *pGenlist = NULL; + + if (ugd->ug_ListPlay.ug_pPlayFilePath == NULL || strlen(ugd->ug_ListPlay.ug_pPlayFilePath) == 0) { + + UG_TRACE_END; + return; + } + pGenlist = ugd->ug_MainWindow.ug_pNaviGenlist; + + gl_item = elm_genlist_first_item_get(pGenlist); + while (gl_item) { + itemData = elm_object_item_data_get(gl_item); + if (itemData && itemData->ug_pItemName) { + if (g_strcmp0(ugd->ug_ListPlay.ug_pPlayFilePath, itemData->ug_pItemName->str) == 0) { + if (disable) { + UG_SAFE_FREE_CHAR(ugd->ug_ListPlay.ug_pPlayFilePath); + elm_genlist_item_fields_update(itemData->ug_pItem, "elm.icon.3", ELM_GENLIST_ITEM_FIELD_CONTENT); + //elm_genlist_item_item_class_update(itemData->ug_pItem, &ugd->ug_Status.ug_noplayitc); + } else { + elm_genlist_item_fields_update(itemData->ug_pItem, "elm.icon.3", ELM_GENLIST_ITEM_FIELD_CONTENT); + } + UG_TRACE_END; + return; + } + } + gl_item = elm_genlist_item_next_get(gl_item); + } + + ug_debug("mf_ug_list_play_update_item_icon failed"); + UG_TRACE_END; +} + + +void mf_ug_list_paly_hide_play_icon(void *data) +{ + UG_TRACE_BEGIN; + + ugData *ugd = (ugData *)data; + ug_mf_retm_if(ugd == NULL, "ugd is NULL"); + + Elm_Object_Item *gl_item = NULL; + ugListItemData *itemData = NULL; + Evas_Object *pGenlist = NULL; + + if (ugd->ug_ListPlay.ug_pPlayFilePath == NULL || strlen(ugd->ug_ListPlay.ug_pPlayFilePath) == 0) { + + UG_TRACE_END; + return; + } + pGenlist = ugd->ug_MainWindow.ug_pNaviGenlist; + + gl_item = elm_genlist_first_item_get(pGenlist); + while (gl_item) { + itemData = elm_object_item_data_get(gl_item); + if (itemData && itemData->ug_pItemName) { + if (g_strcmp0(ugd->ug_ListPlay.ug_pPlayFilePath, itemData->ug_pItemName->str) == 0) { + __mf_ug_list_play_icon_hide(itemData); + UG_TRACE_END; + return; + } + } + gl_item = elm_genlist_item_next_get(gl_item); + } + + ug_debug("mf_ug_list_play_update_item_icon failed"); + UG_TRACE_END; +} +void mf_ug_list_play_update_play_icon(ugListItemData *itemData) +{ + ug_mf_retm_if(itemData == NULL, "itemData is NULL"); + ugData *ugd = (ugData *)itemData->ug_pData; + ug_mf_retm_if(ugd == NULL, "ugd is NULL"); + Evas_Object *btn = itemData->ug_pPlaybtn; + Evas_Object *music_icon = elm_object_part_content_get(btn, "icon"); + const char *play_icon = NULL; + const char *pause_icon = NULL; + if (ugd->ug_ListPlay.ug_pPlayFilePath) { + if (g_strcmp0(ugd->ug_ListPlay.ug_pPlayFilePath, itemData->ug_pItemName->str) == 0) { + if (ugd->ug_ListPlay.ug_iPlayState == PLAY_STATE_PLAYING) { + pause_icon = strdup(UG_ICON_MUSIC_PAUSE_WHITE); + elm_image_file_set(music_icon, pause_icon, NULL); + } else if (ugd->ug_ListPlay.ug_iPlayState == PLAY_STATE_PAUSED) { + play_icon = strdup(UG_ICON_MUSIC_PLAY_WHITE); + elm_image_file_set(music_icon, play_icon, NULL); + } else { + play_icon = strdup(UG_ICON_MUSIC_PLAY_WHITE); + elm_image_file_set(music_icon, play_icon, NULL); + } + } else { + play_icon = strdup(UG_ICON_MUSIC_PLAY_WHITE); + elm_image_file_set(music_icon, play_icon, NULL); + } + } else { + play_icon = strdup(UG_ICON_MUSIC_PLAY_WHITE); + elm_image_file_set(music_icon, play_icon, NULL); + } + +} + +void mf_ug_list_play_update_item_icon(void *data) +{ + UG_TRACE_BEGIN; + + ugData *ugd = (ugData *)data; + ug_mf_retm_if(ugd == NULL, "ugd is NULL"); + + Elm_Object_Item *gl_item = NULL; + ugListItemData *itemData = NULL; + Evas_Object *pGenlist = NULL; + + if (ugd->ug_ListPlay.ug_pPlayFilePath == NULL || strlen(ugd->ug_ListPlay.ug_pPlayFilePath) == 0) { + + UG_TRACE_END; + return; + } + pGenlist = ugd->ug_MainWindow.ug_pNaviGenlist; + + gl_item = elm_genlist_first_item_get(pGenlist); + while (gl_item) { + itemData = elm_object_item_data_get(gl_item); + if (itemData && itemData->ug_pItemName) { + if (g_strcmp0(ugd->ug_ListPlay.ug_pPlayFilePath, itemData->ug_pItemName->str) == 0) { + elm_genlist_item_fields_update(itemData->ug_pItem, "elm.icon.3", ELM_GENLIST_ITEM_FIELD_CONTENT); + //mf_ug_list_play_update_play_icon(itemData); + UG_TRACE_END; + return; + } + } + gl_item = elm_genlist_item_next_get(gl_item); + } + + ug_debug("mf_ug_list_play_update_item_icon failed"); + UG_TRACE_END; +} + + +/****************************** +** Prototype : __mf_ug_list_play_set_play_start_status +** Description : +** Input : ugListItemData *data +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +static void __mf_ug_list_play_set_play_start_status(void *data, char *path) +{ + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + ug_mf_retm_if(ugd == NULL, "ugd is NULL"); + + ugd->ug_ListPlay.ug_iPlayState = PLAY_STATE_PLAYING; + UG_TRACE_END; +} + +/****************************** +** Prototype : __mf_ug_list_play_set_play_resume_status +** Description : +** Input : ugListItemData *data +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +static void __mf_ug_list_play_set_play_resume_status(void *data) +{ + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + ug_mf_retm_if(ugd == NULL, "ugd is NULL"); + + ugd->ug_ListPlay.ug_iPlayState = PLAY_STATE_PLAYING; + UG_TRACE_END; +} + +/****************************** +** Prototype : __mf_ug_list_play_set_play_pause_status +** Description : +** Input : ugListItemData *data +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +static void __mf_ug_list_play_set_play_pause_status(ugData *data) +{ + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + ug_mf_retm_if(ugd == NULL, "ugd is NULL"); + + ugd->ug_ListPlay.ug_iPlayState = PLAY_STATE_PAUSED; + UG_TRACE_END; +} + +/****************************** +** Prototype : _mp_player_mgr_create +** Description : +** Input : void *data +** const gchar *path +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +static void __mf_player_mgr_callback_pipe_handler(void *data, void *buffer, unsigned int nbyte) +{ + UG_TRACE_BEGIN; + mf_player_cb_extra_data *extra_data = buffer; + ug_mf_retm_if(extra_data == NULL, "NULL"); + ug_mf_retm_if(g_player_cbs == NULL, "NULL"); + + switch (extra_data->cb_type) { + /*note: start callback and paused callback for player have been removed*/ + /*case MF_PLAYER_CB_TYPE_STARTED: + if (g_player_cbs->started_cb) + g_player_cbs->started_cb(g_player_cbs->user_data[MF_PLAYER_CB_TYPE_STARTED]); + break; + + case MF_PLAYER_CB_TYPE_PAUSED: + if (g_player_cbs->paused_cb) + g_player_cbs->paused_cb(g_player_cbs->user_data[MF_PLAYER_CB_TYPE_PAUSED]); + break;*/ + + case MF_PLAYER_CB_TYPE_COMPLETED: + if (g_player_cbs->completed_cb) + g_player_cbs->completed_cb(g_player_cbs->user_data[MF_PLAYER_CB_TYPE_COMPLETED]); + break; + + case MF_PLAYER_CB_TYPE_INTURRUPTED: + if (g_player_cbs->interrupted_cb) + g_player_cbs->interrupted_cb(extra_data->param.interrupted_code, g_player_cbs->user_data[MF_PLAYER_CB_TYPE_INTURRUPTED]); + break; + + case MF_PLAYER_CB_TYPE_ERROR: + if (g_player_cbs->error_cb) + g_player_cbs->error_cb(extra_data->param.error_code, g_player_cbs->user_data[MF_PLAYER_CB_TYPE_ERROR]); + break; + + case MF_PLAYER_CB_TYPE_BUFFERING: + if (g_player_cbs->buffering_cb) + g_player_cbs->buffering_cb(extra_data->param.percent ,g_player_cbs->user_data[MF_PLAYER_CB_TYPE_BUFFERING]); + break; + case MF_PLAYER_CB_TYPE_PREPARE: + if (g_player_cbs->prepare_cb) + g_player_cbs->prepare_cb(g_player_cbs->user_data[MF_PLAYER_CB_TYPE_PREPARE]); + break; + + default: + ug_debug("Not suppoted callback type [%d]", extra_data->cb_type); + } +} + + +static void +__mf_ug_list_play_mgr_completed_cb(void *userdata) +{ + UG_TRACE_BEGIN; + MF_CHECK(g_player_pipe); + + mf_player_cb_extra_data extra_data; + extra_data.cb_type = MF_PLAYER_CB_TYPE_COMPLETED; + + ecore_pipe_write(g_player_pipe, &extra_data, sizeof(mf_player_cb_extra_data)); +} + +static void +__mf_ug_list_play_mgr_interrupted_cb(player_interrupted_code_e code, void *userdata) +{ + UG_TRACE_BEGIN; + MF_CHECK(g_player_pipe); + + mf_player_cb_extra_data extra_data; + extra_data.cb_type = MF_PLAYER_CB_TYPE_INTURRUPTED; + extra_data.param.interrupted_code = code; + + ecore_pipe_write(g_player_pipe, &extra_data, sizeof(mf_player_cb_extra_data)); +} + + +static void +__mf_ug_list_play_mgr_error_cb(int error_code, void *userdata) +{ + UG_TRACE_BEGIN; + MF_CHECK(g_player_pipe); + + mf_player_cb_extra_data extra_data; + extra_data.cb_type = MF_PLAYER_CB_TYPE_ERROR; + extra_data.param.error_code = error_code; + + ecore_pipe_write(g_player_pipe, &extra_data, sizeof(mf_player_cb_extra_data)); +} + +static bool __mf_ug_list_play_set_uri(player_h player, const char *uri) +{ + UG_TRACE_BEGIN; + ug_mf_retvm_if(player == NULL, false, "player is NULL"); + ug_mf_retvm_if(uri == NULL, false, "uri is NULL"); + + int ret = 0; + ret = player_set_uri(player, uri); + //player_set_sound_type(ugd->ug_ListPlay.ug_Player, SOUND_TYPE_MEDIA); + if (ret != PLAYER_ERROR_NONE) { + ug_error(">>>>>>>>>>>>>g_err_name : %d\n", ret); + UG_TRACE_END; + return false; + } else { + UG_TRACE_END; + return true; + } + +} + +static bool __mf_ug_list_play_set_sound_type(player_h player, sound_type_e type) +{ + UG_TRACE_BEGIN; + ug_mf_retvm_if(player == NULL, false, "player is NULL"); + + int ret = 0; + ret = player_set_sound_type(player, type); + //player_set_sound_type(ugd->ug_ListPlay.ug_Player, SOUND_TYPE_MEDIA); + if (ret != PLAYER_ERROR_NONE) { + ug_error(">>>>>>>>>>>>>g_err_name : %d\n", ret); + UG_TRACE_END; + return false; + } else { + UG_TRACE_END; + return true; + } + +} + +static bool __mf_ug_list_play_create_player(player_h *player) +{ + UG_TRACE_BEGIN; + + int ret = 0; + ret = player_create(player); + //player_set_sound_type(ugd->ug_ListPlay.ug_Player, SOUND_TYPE_MEDIA); + if (ret != PLAYER_ERROR_NONE) { + ug_error(">>>>>>>>>>>>>g_err_name : %d\n", ret); + UG_TRACE_END; + return false; + } else { + UG_TRACE_END; + return true; + } + +} + +static bool __mf_ug_list_play_create_player_mgr(void *data, const char *path) +{ + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + ug_mf_retvm_if(ugd == NULL, false, "ugd is NULL"); + + int path_len = strlen(path); + char *g_err_name = NULL; + int ret = 0; + + if (path_len > 0 && path_len < MYFILE_DIR_PATH_LEN_MAX) { + if (ugd->ug_ListPlay.ug_Player == 0) { + ret = __mf_ug_list_play_create_player(&ugd->ug_ListPlay.ug_Player); + if (ret == false) { + UG_TRACE_END; + return false; + } + ug_debug("player is [%s]", ugd->ug_ListPlay.ug_Player); + /*avsysaudiosink volume table setting */ + + //ret = mm_player_set_attribute(ugd->ug_ListPlay.ug_Player, &g_err_name, "sound_volume_type", MM_SOUND_VOLUME_TYPE_MEDIA, + // "profile_uri", path, strlen(path), NULL); + ret = __mf_ug_list_play_set_uri(ugd->ug_ListPlay.ug_Player, path); + if (ret == false) { + UG_TRACE_END; + return false; + } + + ret = __mf_ug_list_play_set_sound_type(ugd->ug_ListPlay.ug_Player, SOUND_TYPE_MEDIA); + if (ret == false) { + ug_error("set sound type failed"); + } else { + ug_error("set sound type success"); + } + UG_SAFE_FREE_CHAR(g_player_cbs); + if (g_player_pipe) { + ecore_pipe_del(g_player_pipe); + g_player_pipe = NULL; + } + g_player_cbs = calloc(1, sizeof(mf_player_cbs)); + g_player_pipe = ecore_pipe_add(__mf_player_mgr_callback_pipe_handler, ugd); + + + player_set_completed_cb(ugd->ug_ListPlay.ug_Player, __mf_ug_list_play_mgr_completed_cb, NULL); + player_set_interrupted_cb(ugd->ug_ListPlay.ug_Player, __mf_ug_list_play_mgr_interrupted_cb, NULL); + player_set_error_cb(ugd->ug_ListPlay.ug_Player, __mf_ug_list_play_mgr_error_cb, NULL); + + } else { + ug_debug("player handle is exist"); + + ret = __mf_ug_list_play_set_uri(ugd->ug_ListPlay.ug_Player, path); + if (ret == false) { + UG_TRACE_END; + return false; + } + UG_TRACE_END; + return true; + } + } else { + ug_debug("the path_len is too long"); + UG_TRACE_END; + return false; + } + + //player_set_buffering_cb(ugd->ug_ListPlay.ug_Player, _mp_player_mgr_buffering_cb, NULL); + return true; + +} + +/****************************** +** Prototype : _mp_player_mgr_set_msg_callback +** Description : +** Input : MMMessageCallback cb +** gpointer user_data +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +static void __mf_ug_list_play_start(void *data) +{ + UG_TRACE_BEGIN; + ugListItemData *itemData = (ugListItemData *)data; + ug_mf_retm_if(itemData == NULL, "itemData is NULL"); + ugData *ugd = itemData->ug_pData; + ug_mf_retm_if(ugd == NULL, "ugd is NULL"); + int error_code = -1; + player_state_e state = PLAYER_STATE_NONE; + + error_code = player_get_state(ugd->ug_ListPlay.ug_Player, &state); + ug_debug("state is [%d]", state); + if (error_code == 0 && state == PLAYER_STATE_PLAYING) { + if (ugd->ug_ListPlay.ug_pPlayFilePath == NULL) { + ugd->ug_ListPlay.ug_pPlayFilePath = g_strdup(itemData->ug_pItemName->str); + } + __mf_ug_list_play_set_play_start_status(ugd, itemData->ug_pItemName->str); + } else if (ugd->ug_ListPlay.ug_iPlayState == PLAY_STATE_PAUSED) { + if (ugd->ug_ListPlay.ug_pPlayFilePath == NULL) { + ugd->ug_ListPlay.ug_pPlayFilePath = g_strdup(itemData->ug_pItemName->str); + } + __mf_ug_list_play_set_play_resume_status(ugd); + } + + UG_TRACE_END; +} + +static void __mf_ug_list_play_pauset(void *data) +{ + UG_TRACE_BEGIN; + + ugData *ugd = (ugData *)data; + ug_mf_retm_if(ugd == NULL, "ugd is NULL"); + + __mf_ug_list_play_set_play_pause_status(ugd); + UG_TRACE_END; +} + +static void __mf_ug_list_play_complete_cb(void *data) +{ + UG_TRACE_BEGIN; + + ugData *ugd = (ugData *)data; + ug_mf_retm_if(ugd == NULL, "ugd is NULL"); + + mf_ug_list_play_destory_playing_file(ugd); + mf_ug_list_disable_play_itc(ugd, true); + //mf_ug_list_play_update_item_icon(ugd); + UG_SAFE_FREE_CHAR(ugd->ug_ListPlay.ug_pPlayFilePath); + UG_TRACE_END; +} + +static void __mf_ug_list_play_interrupt_cb(player_interrupted_code_e code, void *data) +{ + UG_TRACE_BEGIN; + ugListItemData *itemData = data; + ug_mf_retm_if(itemData == NULL, "itemData is NULL"); + + ugData *ugd = (ugData *)itemData->ug_pData; + ug_mf_retm_if(ugd == NULL, "ugd is NULL"); + switch (code) { + case PLAYER_INTERRUPTED_BY_MEDIA: + ug_debug("Interrupt :: PLAYER_INTERRUPTED_BY_MEDIA"); + break; + case PLAYER_INTERRUPTED_BY_CALL: + ug_debug("Interrupt :: PLAYER_INTERRUPTED_BY_CALL_START"); + break; + case PLAYER_INTERRUPTED_BY_RESOURCE_CONFLICT: + ug_debug("Interrupt :: PLAYER_INTERRUPTED_BY_RESOURCE_CONFLICT"); + break; + case PLAYER_INTERRUPTED_BY_ALARM: + ug_debug("Interrupt :: PLAYER_INTERRUPTED_BY_ALARM_START"); + break; + case PLAYER_INTERRUPTED_BY_EARJACK_UNPLUG: + ug_debug("Interrupt :: PLAYER_INTERRUPTED_BY_EARJACK_UNPLUG"); + break; + case PLAYER_INTERRUPTED_COMPLETED: + ug_debug("PLAYER_INTERRUPTED_COMPLETED"); + /* ready to resume */ + ug_debug("ugd->ug_ListPlay.ug_iPlayState is [%d]", ugd->ug_ListPlay.ug_iPlayState); + if (ugd->ug_ListPlay.ug_iPlayState == PLAY_STATE_PAUSED) { + ug_debug(); + __mf_ug_list_play_control_cb(itemData); + } + return; + default: + break; + } + __mf_ug_list_play_set_play_pause_status(ugd); + mf_ug_list_play_update_item_icon(ugd); + UG_TRACE_END; + +} + +static void +__mf_list_play_control_prepare_cb(void *userdata) +{ + UG_TRACE_BEGIN; + + __mf_ug_list_play_play_current_file(userdata); +} + + +/****************************** +** Prototype : _mp_player_mgr_realize +** Description : +** Input : ugListItemData *data +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +static void +__mf_ug_list_play_prepare_cb(void *userdata) +{ + UG_TRACE_BEGIN; + MF_CHECK(g_player_pipe); + + mf_player_cb_extra_data extra_data; + memset(&extra_data, 0, sizeof(mf_player_cb_extra_data)); + extra_data.cb_type = MF_PLAYER_CB_TYPE_PREPARE; + + ecore_pipe_write(g_player_pipe, &extra_data, sizeof(mf_player_cb_extra_data)); +} + +static bool __mf_ug_list_play_realize_player_mgr(void *data) +{ + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + + ug_mf_retvm_if(ugd == NULL, false, "ugd is NULL"); + + int error_code = 0; + player_state_e state = PLAYER_STATE_NONE; + + if (ugd->ug_ListPlay.ug_Player != 0) { + error_code = player_get_state(ugd->ug_ListPlay.ug_Player, &state); + ug_debug("state is [%d]", state); + + if (0 == error_code && PLAYER_STATE_IDLE == state) { + ug_debug("player_prepare_async"); + if (player_prepare_async(ugd->ug_ListPlay.ug_Player, __mf_ug_list_play_prepare_cb, ugd) != PLAYER_ERROR_NONE) + { + ug_debug("Error when mp_player_mgr_realize\n"); + UG_TRACE_END; + return FALSE; + } else { + return true; + } + //ugd->ug_ListPlay.ug_iPlayState = PLAY_STATE_READY; + + } else { + UG_TRACE_END; + return false; + } + } + UG_TRACE_END; + + return false; +} + + +/****************************** +** Prototype : __mf_ug_list_play_ready_new_file_play +** Description : Samsung +** Input : void *data +** bool drm_check_flag +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +/*void mf_player_mgr_set_started_cb(player_started_cb callback, void *user_data) +{ + MF_CHECK(g_player_cbs); + + g_player_cbs->started_cb = callback; + g_player_cbs->user_data[MF_PLAYER_CB_TYPE_STARTED] = user_data; +} + +void mf_player_mgr_set_paused_cb(player_paused_cb callback, void *user_data) +{ + MF_CHECK(g_player_cbs); + + g_player_cbs->paused_cb = callback; + g_player_cbs->user_data[MF_PLAYER_CB_TYPE_PAUSED] = user_data; +}*/ + +void mf_player_mgr_set_completed_cb(player_completed_cb callback, void *user_data) +{ + + MF_CHECK(g_player_cbs); + + g_player_cbs->completed_cb = callback; + g_player_cbs->user_data[MF_PLAYER_CB_TYPE_COMPLETED] = user_data; +} + +void mf_player_mgr_set_interrupted_cb(player_interrupted_cb callback, void *user_data) +{ + + MF_CHECK(g_player_cbs); + + g_player_cbs->interrupted_cb = callback; + g_player_cbs->user_data[MF_PLAYER_CB_TYPE_INTURRUPTED] = user_data; +} + +void mf_player_mgr_set_error_cb(player_error_cb callback, void *user_data) +{ + + MF_CHECK(g_player_cbs); + + g_player_cbs->error_cb = callback; + g_player_cbs->user_data[MF_PLAYER_CB_TYPE_ERROR] = user_data; +} + +void mf_player_mgr_set_buffering_cb(player_buffering_cb callback, void *user_data) +{ + MF_CHECK(g_player_cbs); + + g_player_cbs->buffering_cb = callback; + g_player_cbs->user_data[MF_PLAYER_CB_TYPE_BUFFERING] = user_data; +} + +void mf_player_mgr_set_prepare_cb(player_prepared_cb callback, void *user_data) +{ + MF_CHECK(g_player_cbs); + + g_player_cbs->prepare_cb = callback; + g_player_cbs->user_data[MF_PLAYER_CB_TYPE_PREPARE] = user_data; +} + +static Eina_Bool __mf_play_control_error(void *data) +{ + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + ug_mf_retvm_if(ugd == NULL, false, "ugd is NULL"); + + mf_ug_list_play_destory_playing_file(ugd); + mf_ug_list_disable_play_itc(ugd, true); + UG_SAFE_FREE_CHAR(ugd->ug_ListPlay.ug_pPlayFilePath); + ugd->ug_ListPlay.playing_err_idler = NULL; + return EINA_FALSE; +} + +static void __mf_play_control_error_cb(int error_code, void *userdata) +{ + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)userdata; + ug_mf_retm_if(ugd == NULL, "ugd is NULL"); + + switch (error_code) + { + case PLAYER_ERROR_OUT_OF_MEMORY: + ug_error("PLAYER_ERROR_OUT_OF_MEMORY"); + break; + case PLAYER_ERROR_INVALID_PARAMETER: + ug_error("PLAYER_ERROR_INVALID_PARAMETER"); + //mp_widget_text_popup(ad, GET_STR("IDS_MUSIC_POP_UNABLE_TO_PLAY_ERROR_OCCURRED")); + break; + case PLAYER_ERROR_NOT_SUPPORTED_FILE: //can receive error msg while playing. + ug_error("receive MM_ERROR_PLAYER_CODEC_NOT_FOUND\n"); + ugd->ug_MainWindow.ug_pNormalPopup = mf_ug_popup_create(ugd, UG_POPMODE_TEXT, NULL, MF_UG_LABEL_UNSUPPORT_FILE_TYPE, NULL, NULL, NULL, NULL, NULL); + break; + case PLAYER_ERROR_CONNECTION_FAILED: + ug_error("MM_ERROR_PLAYER_STREAMING_CONNECTION_FAIL"); + + ugd->ug_MainWindow.ug_pNormalPopup = mf_ug_popup_create(ugd, UG_POPMODE_TEXT, NULL, MF_UG_LABEL_CONNECT_FAILED, NULL, NULL, NULL, NULL, NULL); + break; + default: + ugd->ug_MainWindow.ug_pNormalPopup = mf_ug_popup_create(ugd, UG_POPMODE_TEXT, NULL, MF_UG_LABEL_UNSUPPORT_FILE_TYPE, NULL, NULL, NULL, NULL, NULL); + ug_error("error_code: %d", error_code); + } + + if(!ugd->ug_ListPlay.playing_err_idler) { + ugd->ug_ListPlay.playing_err_idler = ecore_idler_add(__mf_play_control_error, ugd); + } +} + + +static bool __mf_ug_list_play_ready_new_file_play(void *data, bool drm_check_flag) +{ + + UG_TRACE_BEGIN; + ugListItemData *itemData = data; + ug_mf_retvm_if(itemData == NULL, false, "itemData is NULL"); + + ugData *ugd = (ugData *)itemData->ug_pData; + ug_mf_retvm_if(ugd == NULL, false, "ugd is NULL"); + + char *path = strdup(itemData->ug_pItemName->str); + + /*check if file is exist */ + if (path != NULL) { + if (!ecore_file_exists(path)) { + ug_debug("Error file %s is not exist\n", path); + free(path); + path = NULL; + UG_TRACE_END; + return false; + } + /*/check if file is drm file */ + if (mf_ug_file_attr_is_drm_file(path) == 0) { + if (!__mf_ug_list_play_check_drm_left_ro(ugd, path)) { + free(path); + path = NULL; + UG_TRACE_END; + return false; + } + + if (!__mf_ug_list_play_check_drm_forward(ugd, path)) { + free(path); + path = NULL; + UG_TRACE_END; + return false; + } + + ugd->ug_ListPlay.ug_bDrmconsumption = true; + } else { + ugd->ug_ListPlay.ug_bDrmconsumption = true; + } + + if (!__mf_ug_list_play_create_player_mgr(ugd, path)) { + free(path); + path = NULL; + ug_error("ERROR HERE !!!!!!!"); + ugd->ug_MainWindow.ug_pNormalPopup = mf_ug_popup_create(ugd, UG_POPMODE_TEXT, NULL, MF_UG_LABEL_UNABLE_TO_PLAY_ERROR_OCCURRED, NULL, NULL, NULL, NULL, NULL); + UG_TRACE_END; + return false; + } + + //mf_player_mgr_set_started_cb(__mf_ug_list_play_start_cb, itemData); + //mf_player_mgr_set_paused_cb(__mf_ug_list_play_pauset_cb, ugd); + mf_player_mgr_set_completed_cb(__mf_ug_list_play_complete_cb, ugd); + mf_player_mgr_set_interrupted_cb(__mf_ug_list_play_interrupt_cb, ugd); + mf_player_mgr_set_prepare_cb(__mf_list_play_control_prepare_cb, itemData); + mf_player_mgr_set_error_cb(__mf_play_control_error_cb, ugd); + //mf_player_mgr_set_buffering_cb(_mp_play_control_buffering_cb, ad); + + if (!__mf_ug_list_play_realize_player_mgr(ugd)) { + free(path); + path = NULL; + ug_error("ERROR HERE !!!!!!!"); + ugd->ug_MainWindow.ug_pNormalPopup = mf_ug_popup_create(ugd, UG_POPMODE_TEXT, NULL, MF_UG_LABEL_UNABLE_TO_PLAY_ERROR_OCCURRED, NULL, NULL, NULL, NULL, NULL); + UG_TRACE_END; + return false; + } + free(path); + path = NULL; + UG_TRACE_END; + return true; + } else { + return false; + } + +} + + +/****************************** +** Prototype : _mp_player_mgr_play +** Description : +** Input : ugListItemData *data +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +static bool __mf_ug_list_play_play(void *data) +{ + + UG_TRACE_BEGIN; + ugListItemData *itemData = data; + ug_mf_retvm_if(itemData == NULL, false, "itemData is NULL"); + ugData *ugd = itemData->ug_pData; + ug_mf_retvm_if(ugd == NULL, false, "ugd is NULL"); + + int err = 0; + int error_code = 0; + player_state_e state = PLAYER_STATE_NONE; + + if (ugd->ug_ListPlay.ug_Player != 0) { + error_code = player_get_state(ugd->ug_ListPlay.ug_Player, &state); + ug_debug("state is [%d]", state); + + if (0 == error_code && PLAYER_STATE_READY == state) { + err = player_start(ugd->ug_ListPlay.ug_Player); + if (err != PLAYER_ERROR_NONE) { + + if (err == PLAYER_ERROR_SOUND_POLICY) + { + ug_error("PLAYER_ERROR_SOUND_POLICY error"); + ugd->ug_MainWindow.ug_pNormalPopup = mf_ug_popup_create(ugd, UG_POPMODE_TEXT, NULL, MF_UG_LABEL_UNABLE_TO_PLAY_DURING_CALL, NULL, + NULL, NULL, NULL, NULL); + } + else + { + ug_error("error is [%d]", err); + ugd->ug_MainWindow.ug_pNormalPopup = mf_ug_popup_create(ugd, UG_POPMODE_TEXT, NULL, MF_UG_LABEL_UNABLE_TO_PLAY_ERROR_OCCURRED, NULL, + NULL, NULL, NULL, NULL); + } + ug_error("Error when _mp_player_mgr_play. err[%x]\n", err); + UG_TRACE_END; + return false; + } else { + __mf_ug_list_play_start(itemData); + mf_ug_list_disable_play_itc(ugd, false); + UG_TRACE_END; + return true; + } + } else { + UG_TRACE_END; + return false; + } + } else { + UG_TRACE_END; + return false; + } +} + +/****************************** +** Prototype : __mf_ug_list_play_stop +** Description : +** Input : void *data +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +static bool __mf_ug_list_play_stop(ugData *data) +{ + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + ug_mf_retvm_if(ugd == NULL, false, "ugd is NULL"); + + player_state_e state = PLAYER_STATE_NONE; + int error_code = 0; + + if (ugd->ug_ListPlay.ug_Player != 0) { + error_code = player_get_state(ugd->ug_ListPlay.ug_Player, &state); + ug_debug("state is [%d]", state); + + if (0 == error_code && (PLAYER_STATE_PLAYING == state || PLAYER_STATE_PAUSED == state)) { + if (player_stop(ugd->ug_ListPlay.ug_Player) != 0) { + ug_debug("Error when __mf_ug_list_play_stop\n"); + UG_TRACE_END; + return false; + } else { + + ugd->ug_ListPlay.ug_iPlayState = PLAY_STATE_STOP; + ugd->ug_ListPlay.ug_bDrmContentCanPlay = false; + UG_TRACE_END; + return true; + } + + } else { + UG_TRACE_END; + return false; + } + } + UG_TRACE_END; + return false; +} + +/****************************** +** Prototype : __mf_ug_list_play_unrealize +** Description : +** Input : void *data +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +static bool __mf_ug_list_play_unrealize(ugData *data) +{ + + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + ug_mf_retvm_if(ugd == NULL, false, "ugd is NULL"); + + if (ugd->ug_ListPlay.ug_Player != 0) { + /*/unrealize can be invoked at any state */ + int ret = player_unprepare(ugd->ug_ListPlay.ug_Player); + if (ret != 0) { + ug_error("Error when __mf_ug_list_play_unrealize %d", ret); + UG_TRACE_END; + return false; + } else { + UG_TRACE_END; + return true; + } + } + UG_TRACE_END; + return false; +} + +/****************************** +** Prototype : __mf_ug_list_play_destory +** Description : +** Input : void *data +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +static bool __mf_ug_list_play_destory(ugData *data) +{ + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + ug_mf_retvm_if(ugd == NULL, false, "ugd is NULL"); + + if (ugd->ug_ListPlay.ug_Player != 0) { + /*/destroy can be invoked at any state */ + if (player_destroy(ugd->ug_ListPlay.ug_Player) != 0) { + ug_debug("Error when __mf_ug_list_play_destory\n"); + UG_TRACE_END; + return false; + } else { + ugd->ug_ListPlay.ug_Player = 0; + ugd->ug_ListPlay.ug_iPlayState = PLAY_STATE_INIT; + UG_TRACE_END; + return true; + } + } + + UG_SAFE_FREE_CHAR(g_player_cbs); + if (g_player_pipe) { + ecore_pipe_del(g_player_pipe); + g_player_pipe = NULL; + } + UG_TRACE_END; + return false; +} + +/****************************** +** Prototype : __mf_ug_list_play_play_current_file +** Description : Samsung +** Input : ugData *data +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +static bool __mf_ug_list_play_play_current_file(void *data) +{ + + UG_TRACE_BEGIN; + ugListItemData *itemData = data; + ug_mf_retvm_if(itemData == NULL, false, "itemData is NULL"); + ugData *ugd = itemData->ug_pData; + ug_mf_retvm_if(ugd == NULL, false, "ugd is NULL"); + + int error_code = 0; + + player_state_e state = PLAYER_STATE_NONE; + error_code = player_get_state(ugd->ug_ListPlay.ug_Player, &state); + ug_debug("state is [%d]", state); + if (state != PLAYER_STATE_READY) { + UG_TRACE_END; + return false; + } + if (!__mf_ug_list_play_play(itemData)) { + mf_ug_list_play_destory_playing_file(ugd); + mf_ug_list_disable_play_itc(ugd, true); + UG_SAFE_FREE_CHAR(ugd->ug_ListPlay.ug_pPlayFilePath); + UG_TRACE_END; + return false; + } + + return true; +} + + +/****************************** +** Prototype : __mf_ug_list_play_resume +** Description : +** Input : ugListItemData *data +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +static bool __mf_ug_list_play_resume(void *data) +{ + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + ug_mf_retvm_if(ugd == NULL, false, "ugd is NULL"); + + player_state_e state = PLAYER_STATE_NONE; + int error_code = 0; + int err = -1; + + if (ugd->ug_ListPlay.ug_Player != 0) { + error_code = player_get_state(ugd->ug_ListPlay.ug_Player, &state); + ug_debug("state is [%d]", state); + + if (0 == error_code && PLAYER_STATE_PAUSED == state) { + err = player_start(ugd->ug_ListPlay.ug_Player); + + if (err != PLAYER_ERROR_NONE) { + + if (err == PLAYER_ERROR_SOUND_POLICY) + { + ug_error("ERROR HERE !!!!!!!"); + ugd->ug_MainWindow.ug_pNormalPopup = mf_ug_popup_create(ugd, UG_POPMODE_TEXT, NULL, MF_UG_LABEL_UNABLE_TO_PLAY_DURING_CALL, NULL, + NULL, NULL, NULL, NULL); + } + else + { + ug_error("ERROR HERE !!!!!!!"); + ugd->ug_MainWindow.ug_pNormalPopup = mf_ug_popup_create(ugd, UG_POPMODE_TEXT, NULL, MF_UG_LABEL_UNABLE_TO_PLAY_ERROR_OCCURRED, NULL, + NULL, NULL, NULL, NULL); + } + ug_error("Error when _mp_player_mgr_play. err[%x]\n", err); + UG_TRACE_END; + return false; + } else { + __mf_ug_list_play_set_play_start_status(ugd, ugd->ug_ListPlay.ug_pPlayFilePath); + mf_ug_list_disable_play_itc(ugd, false); + UG_TRACE_END; + return true; + } + } else { + UG_TRACE_END; + return false; + } + } + UG_TRACE_END; + return false; + +} + + +/****************************** +** Prototype : __mf_ug_list_play_pause +** Description : +** Input : ugListItemData *data +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +static bool __mf_ug_list_play_pause(void *data) +{ + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + ug_mf_retvm_if(ugd == NULL, false, "ugd is NULL"); + + int err = 0; + player_state_e state = PLAYER_STATE_NONE; + int error_code = 0; + + if (ugd->ug_ListPlay.ug_Player) { + error_code = player_get_state(ugd->ug_ListPlay.ug_Player, &state); + ug_debug("state is [%d]", state); + + if (0 == error_code && PLAYER_STATE_PLAYING == state) { + err = player_pause(ugd->ug_ListPlay.ug_Player); + if (err != 0) { + ug_debug("Error when _ug_player_mgr_pause. err[%x]\n", err); + UG_TRACE_END; + return false; + } else { + UG_TRACE_END; + return true; + } + } else { + UG_TRACE_END; + return false; + } + } + UG_TRACE_END; + return false; +} + + +/****************************** +** Prototype : mp_play_control_cb +** Description : +** Input : ugListItemData *data +** int state +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +void mf_ug_list_play_pause(void *data) +{ + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + ug_mf_retm_if(ugd == NULL, "ugd is NULL"); + int state = ugd->ug_ListPlay.ug_iPlayState; + + if (state == PLAY_STATE_PLAYING) { + if(__mf_ug_list_play_pause(ugd)) { + __mf_ug_list_play_pauset(ugd); + mf_ug_list_disable_play_itc(ugd, false); + } + } +} +static void __mf_ug_list_play_control_cb(void *data) +{ + UG_TRACE_BEGIN; + ugListItemData *itemData = data; + ug_mf_retm_if(itemData == NULL, "itemData is NULL"); + + ugData *ugd = (ugData *)itemData->ug_pData; + ug_mf_retm_if(ugd == NULL, "ugd is NULL"); + + int state = ugd->ug_ListPlay.ug_iPlayState; + + if (state == PLAY_STATE_PLAYING) { + if(__mf_ug_list_play_pause(ugd)) { + __mf_ug_list_play_pauset(ugd); + mf_ug_list_disable_play_itc(ugd, false); + } + } else { + if(__mf_ug_list_play_resume(ugd)) { + __mf_ug_list_play_start(itemData); + } + + } + UG_TRACE_END; +} + +static bool __mf_ug_list_play_play_new_file(ugListItemData *data, bool drm_check_flag) +{ + UG_TRACE_BEGIN; + ugListItemData *itemData = data; + ug_mf_retvm_if(itemData == NULL, false, "itemData is NULL"); + + ugData *ugd = (ugData *)itemData->ug_pData; + ug_mf_retvm_if(ugd == NULL, false, "ugd is NULL"); + + __mf_ug_list_play_init_data(ugd); + + if (!__mf_ug_list_play_ready_new_file_play(itemData, true)) { + UG_TRACE_END; + return false; + } + + if (!__mf_ug_list_play_play_current_file(itemData)) { + UG_TRACE_END; + return false; + } + UG_TRACE_END; + + return true; +} + + +/****************************** +** Prototype : _music_item_play +** Description : +** Input : ugListItemData *param +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +void mf_ug_list_play_play_music_item(ugListItemData *data) +{ + UG_TRACE_BEGIN; + ugListItemData *itemData = data; + ug_mf_retm_if(itemData == NULL, "itemData is NULL"); + ugData *ugd = itemData->ug_pData; + ug_mf_retm_if(ugd == NULL, "ugd is NULL"); + + int key = 0; + int error_code = 0; + error_code = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &key); + + ug_debug("key is [%d]", key); + ug_debug("ugd->ug_ListPlay.ug_iPlayState is [%d]", ugd->ug_ListPlay.ug_iPlayState); + + if (error_code == 0 && key <= VCONFKEY_SYSMAN_BAT_POWER_OFF) { + ugd->ug_MainWindow.ug_pNormalPopup = mf_ug_popup_create(ugd, UG_POPMODE_TEXT, NULL, ("Battery low, play failed!"), NULL, NULL, NULL, NULL, NULL); + } else if (error_code != 0) { + ugd->ug_MainWindow.ug_pNormalPopup = mf_ug_popup_create(ugd, UG_POPMODE_TEXT, NULL, ("Unkown error, play failed!"), NULL, NULL, NULL, NULL, NULL); + } else { + if (ugd->ug_ListPlay.ug_pPlayFilePath != NULL) { + ug_debug(); + if (g_strcmp0(ugd->ug_ListPlay.ug_pPlayFilePath, itemData->ug_pItemName->str) != 0) { + //mf_ug_list_play_destory_playing_file(ugd); + mf_ug_list_play_reset_playing_file(ugd); + mf_ug_list_disable_play_itc(ugd, true); + //mf_ug_list_play_update_item_icon(ugd); + __mf_ug_list_play_play_new_file(itemData, true); + } else { + ug_debug(); + /*/ playing the same file */ + __mf_ug_list_play_control_cb(itemData); + } + } else { + ug_debug(); + mf_ug_list_disable_play_itc(ugd, false); + __mf_ug_list_play_play_new_file(itemData, true); + } + } + UG_TRACE_END; + +} + +/****************************** +** Prototype : mf_ug_list_play_destory_playing_file +** Description : +** Input : ugListItemData *data +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +void mf_ug_list_play_reset_playing_file(void *data) +{ + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + ug_mf_retm_if(ugd == NULL, "ugd is NULL"); + __mf_ug_list_play_unrealize(ugd); + +} +void mf_ug_list_play_destory_playing_file(void *data) +{ + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + ug_mf_retm_if(ugd == NULL, "ugd is NULL"); + + __mf_ug_list_play_stop(ugd); + __mf_ug_list_play_unrealize(ugd); + __mf_ug_list_play_destory(ugd); + UG_TRACE_END; +} + + +static sound_type_e mf_ug_player_get_sound_type() +{ + UG_TRACE_BEGIN; + sound_type_e type = SOUND_TYPE_SYSTEM; + int ret = 0; + ret = sound_manager_get_current_sound_type(&type); + ug_error("ret is [%d]", ret); + UG_TRACE_END; + return type; +} + +static int mf_ug_player_get_volume(sound_type_e type) +{ + UG_TRACE_BEGIN; + int volume = 0; + int ret = 0; + ret = sound_manager_get_volume(SOUND_TYPE_MEDIA, &volume); + //ret = sound_manager_get_volume(type, &volume); + ug_error("ret is [%d]", ret); + UG_TRACE_END; + return volume; + +} + +static void mf_ug_player_set_volume(sound_type_e type, int volume) +{ + UG_TRACE_BEGIN; + int ret = 0; + ret = sound_manager_set_volume(type, volume); + ug_error("ret is [%d]", ret); + UG_TRACE_END; +} + + +static void mf_ug_player_vol_type_set(mf_player_volume_type type) +{ + UG_TRACE_BEGIN; + sound_type_e current_type; + int volume = 0; + current_type = mf_ug_player_get_sound_type(); + volume = mf_ug_player_get_volume(current_type); + ug_error("current type is [%d] volume is [%d] type is [%d]", current_type, volume, type); + sound_manager_set_volume_key_type(VOLUME_KEY_TYPE_MEDIA); + mf_ug_player_set_volume(SOUND_TYPE_MEDIA, volume); + UG_TRACE_END; + return; + switch (type) { + case MF_VOLUME_ALERT: + sound_manager_set_volume_key_type(VOLUME_KEY_TYPE_ALARM); + mf_ug_player_set_volume(SOUND_TYPE_ALARM, volume); + break; + case MF_VOLUME_NOTIFICATION: + sound_manager_set_volume_key_type(VOLUME_KEY_TYPE_NOTIFICATION); + mf_ug_player_set_volume(SOUND_TYPE_NOTIFICATION, volume); + break; + case MF_VOLUME_RINGTONE: + sound_manager_set_volume_key_type(VOLUME_KEY_TYPE_RINGTONE); + mf_ug_player_set_volume(SOUND_TYPE_RINGTONE, volume); + break; + default: + sound_manager_set_volume_key_type(VOLUME_KEY_TYPE_MEDIA); + mf_ug_player_set_volume(SOUND_TYPE_MEDIA, volume); + break; + } + UG_TRACE_END; +} + +void mf_ug_player_vol_set(const char *path) +{ + ug_mf_retm_if(path == NULL, "path is NULL"); + if (g_strcmp0(path, UG_SETTING_MSG_ALERTS_PATH) == 0) { + mf_ug_player_vol_type_set(MF_VOLUME_NOTIFICATION); + } else if (g_strcmp0(path, UG_SETTING_RINGTONE_PATH) == 0) { + mf_ug_player_vol_type_set(MF_VOLUME_RINGTONE); + } else if (g_strcmp0(path, UG_SETTING_ALERTS_PATH) == 0) { + mf_ug_player_vol_type_set(MF_VOLUME_ALERT); + } else { + mf_ug_player_vol_type_set(MF_VOLUME_NONE); + } +} + diff --git a/src/common/mf-ug-search-internal.c b/src/common/mf-ug-search-internal.c new file mode 100644 index 0000000..95e5c12 --- /dev/null +++ b/src/common/mf-ug-search-internal.c @@ -0,0 +1,882 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.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 <glib.h> +#include <stdio.h> +#include <errno.h> +#include <string.h> +#include <dirent.h> +#include <pthread.h> +#include <Ecore.h> + +#include "mf-ug-main.h" +#include "mf-ug-search.h" +#include "mf-ug-search-internal.h" +#include "mf-ug-fs-util.h" + +#define APPEND_SIZE 2 /* for null and slash */ +#define MF_ERR_BUF 256 + +#define NORMALIZE_OPTION G_NORMALIZE_NFD + +#ifdef CHECK_RESTRICTED_PATH +/* TODO + * This code should be revised. + * How to get restricted path information? + * I think this module should not depend on other lib(except glib and stdlib). +*/ +#define ROOT_UMS "/opt/usr/media" +#define ROOT_MMC "/opt/storage/sdcard" +#endif /* CHECK_RESTRICTED_PATH */ + +int flagSearchMsg = 1; +pthread_mutex_t gLockSearchMsg; +pthread_cond_t gCondSearchMsg; + +static void __mf_ug_search_tx_wait(); +static void __mf_ug_search_result_publish_msg(mf_search_pipe_msg_type type, void *result, void *user_data); + +inline static void __mf_ug_search_cmd_lock(ms_handle_t *handle) +{ + if (handle && handle->cmd_lock) { + g_mutex_lock(handle->cmd_lock); + } + return; +} + +inline static void __mf_ug_search_cmd_unlock(ms_handle_t *handle) +{ + if (handle && handle->cmd_lock) { + g_mutex_unlock(handle->cmd_lock); + } + return; +} + +inline static void __mf_ug_search_thread_lock(ms_handle_t *handle) +{ + if (handle && handle->thread_mutex) { + g_mutex_lock(handle->thread_mutex); + } + return; +} + +inline static void __mf_ug_search_thread_unlock(ms_handle_t *handle) +{ + if (handle && handle->thread_mutex) { + g_mutex_unlock(handle->thread_mutex); + } + return; +} + +inline static void __mf_ug_search_args_free(ms_args_t *args) +{ + if (args) { + if (args->root_path) { + g_list_foreach(args->root_path, (GFunc) g_free, NULL); + g_list_free(args->root_path); + args->root_path = NULL; + } + + if (args->needle) + g_free(args->needle); + + g_free(args); + } + return; +} + +inline static void __mf_ug_search_result_free(mf_search_result_t *result) +{ + if (result) { + if (result->current_dir) { + g_free(result->current_dir); + result->current_dir = NULL; + } + if (result->dir_list) { + g_list_foreach(result->dir_list, (GFunc) g_free, NULL); + g_list_free(result->dir_list); + result->dir_list = NULL; + } + if (result->file_list) { + g_list_foreach(result->file_list, (GFunc) g_free, NULL); + g_list_free(result->file_list); + result->file_list = NULL; + } + g_free(result); + } + return; +} + +#ifdef CHECK_RESTRICTED_PATH +gboolean __mf_ug_search_check_licet_path(const char *path) +{ + return (gboolean) (strstr(path, ROOT_UMS) || strstr(path, ROOT_MMC)); +} +#endif /*CHECK_RESTRICTED_PATH*/ + + + /*This function is for testing and should be revised for performance before applying*/ +static inline gboolean __mf_ug_search_has_nonspacing_mark(const char *nstr) +{ + if (nstr) { + const char *p_str = nstr; + while (p_str && *p_str) { + gunichar uc; + uc = g_utf8_get_char(p_str); + if (g_unichar_type(uc) == G_UNICODE_NON_SPACING_MARK) { + return TRUE; + } else { + p_str = g_utf8_next_char(p_str); + } + } + } + return FALSE; +} + +static gboolean __mf_ug_search_NFD_ext(const char *str, const char *needle) +{ + int s_len = 0; + int n_len = 0; + if (!str) { + return FALSE; + } + s_len = strlen(str); + + if (!needle) { + return FALSE; + } else { + n_len = strlen(needle); + if (n_len == 0) { + return FALSE; + } + } + if (s_len < n_len) + return FALSE; + char *pdot = strrchr(str, '.'); + + if (!pdot) { + return FALSE; + } else if (pdot != str) { + char *ext = NULL;; + ext = g_strdup(pdot+1); + if (g_strcmp0(ext, needle)== 0) { + g_free(ext); + ext = NULL; + return TRUE; + } + else { + g_free(ext); + ext = NULL; + return FALSE; + } + } else { + return FALSE; + } + +} +static gboolean __mf_ug_search_NFD_strstr(const char *str, const char *needle) +{ + int s_len = 0; + int n_len = 0; + + if (!str) { + return FALSE; + } + s_len = strlen(str); + + if (!needle) { + return FALSE; + } else { + n_len = strlen(needle); + if (n_len == 0) { + return FALSE; + } + } + + if (s_len < n_len) + return FALSE; + + if (__mf_ug_search_has_nonspacing_mark(str)) { + const char *p_str = str; + const char *end = p_str + s_len - n_len; + + while (p_str && p_str <= end && *p_str) { + const char *s = p_str; + const char *n = needle; + while (n && *n) { + if (s && *s) { + gunichar sc, nc; + sc = g_utf8_get_char(s); + nc = g_utf8_get_char(n); + if (g_unichar_type(sc) == G_UNICODE_NON_SPACING_MARK) { + if (g_unichar_type(nc) == G_UNICODE_NON_SPACING_MARK) { + if (sc != nc) { + goto next; + } else { + s = g_utf8_next_char(s); + n = g_utf8_next_char(n); + } + } else { + s = g_utf8_next_char(s); + } + } else if (sc != nc) { + goto next; + } else { + s = g_utf8_next_char(s); + n = g_utf8_next_char(n); + } + } else { + return FALSE; + } + } + + return TRUE; +next: + p_str = g_utf8_next_char(p_str); + } + } else { + return (gboolean) (!(!strstr(str, needle))); + } + return FALSE; +} + +static GList *__mf_ug_search_do_find(const char *root, const char *needle, mf_search_option option, ms_handle_t *handle) +{ + DIR *directory = NULL; + GList *candidate = NULL; + + char *up_needle = NULL; + char *up_name = NULL; + + if (!handle) { + ms_error("handle is NULL"); + return NULL; + } + + if (!handle->result) { + ms_error("handle->result is NULL"); + return NULL; + } + + if (!root || !needle) { + ms_error("invaild args"); + return NULL; + } + + if (!g_file_test(root, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) { + ms_error("invaild root_path : %s", root); + return NULL; + } + + directory = opendir(root); + if (directory) { + mf_search_result_t *result = NULL; + struct dirent *entry = NULL; + + result = handle->result; + __mf_ug_search_thread_lock(handle); + if (result->current_dir) { + g_free(result->current_dir); + } + result->current_dir = g_strdup(root); + __mf_ug_search_thread_unlock(handle); + while ((entry = readdir(directory)) != NULL) { + if (!(option & MF_SEARCH_OPT_HIDDEN) && (0 == strncmp(entry->d_name, ".", 1))) { + ms_debug("[%s] is hidden file. Skip it", entry->d_name); + continue; + } + + if (handle->is_stop == TRUE) { + ms_debug("break from do find"); + break; + } + + if (entry->d_type & DT_REG) { + if (option & MF_SEARCH_OPT_FILE) { + __mf_ug_search_thread_lock(handle); + result->total_count++; + __mf_ug_search_thread_unlock(handle); + + up_name = g_utf8_strup(entry->d_name, strlen(entry->d_name)); + up_needle = g_utf8_strup(needle, strlen(needle)); + + /*Todo:*/ + /* should we check the return value for further use? */ + gchar *nor_str = g_utf8_normalize(up_name, -1, NORMALIZE_OPTION); + if (__mf_ug_search_NFD_strstr(nor_str, up_needle)) + { + gchar *path = NULL; + gssize len = strlen(root) + strlen(entry->d_name) + APPEND_SIZE; /* for null and slash*/ + path = g_malloc(sizeof(gchar) * len); + if (path) { + g_snprintf(path, len, "%s/%s", root, entry->d_name); + + __mf_ug_search_thread_lock(handle); + result->file_list = g_list_append(result->file_list, (gpointer) path); + result->is_end = FALSE; + __mf_ug_search_thread_unlock(handle); + + __mf_ug_search_tx_wait(); + __mf_ug_search_result_publish_msg(MF_SEARCH_PIPE_MSG_RESULT_REPORT, result, + handle->args->user_data); + } + /*1 TODO: how can i handle else case?*/ + } + g_free(nor_str); + free(up_needle); + up_needle = NULL; + free(up_name); + up_name = NULL; + }else if (option & MF_SEARCH_OPT_EXT) { + __mf_ug_search_thread_lock(handle); + result->total_count++; + __mf_ug_search_thread_unlock(handle); + + up_name = g_utf8_strup(entry->d_name, strlen(entry->d_name)); + up_needle = g_utf8_strup(needle, strlen(needle)); + + /*Todo:*/ + /* should we check the return value for further use? */ + gchar *nor_str = g_utf8_normalize(up_name, -1, NORMALIZE_OPTION); + if (__mf_ug_search_NFD_ext(nor_str, up_needle)) + { + gchar *path = NULL; + gssize len = strlen(root) + strlen(entry->d_name) + APPEND_SIZE; /* for null and slash*/ + path = g_malloc(sizeof(gchar) * len); + if (path) { + g_snprintf(path, len, "%s/%s", root, entry->d_name); + + __mf_ug_search_thread_lock(handle); + result->file_list = g_list_append(result->file_list, (gpointer) path); + result->is_end = FALSE; + __mf_ug_search_thread_unlock(handle); + + __mf_ug_search_tx_wait(); + __mf_ug_search_result_publish_msg(MF_SEARCH_PIPE_MSG_RESULT_REPORT, result, + handle->args->user_data); + } + /*1 TODO: how can i handle else case?*/ + } + g_free(nor_str); + free(up_needle); + up_needle = NULL; + free(up_name); + up_name = NULL; + + } + } else if (entry->d_type & DT_DIR) { + gchar *path = NULL; + gssize len = 0; + + len = strlen(entry->d_name); + /*skip current and upper directory*/ + if (0 == strncmp(entry->d_name, ".", strlen(".")) || 0 == strncmp(entry->d_name, "..", strlen(".."))) { + continue; + } + /* we are not going to search /opt/media/SLP_Debug folder */ + if ((strlen(result->current_dir) == strlen(PHONE_FOLDER)) && (strcmp(result->current_dir, PHONE_FOLDER) == 0) + && (strlen(entry->d_name) == strlen(DEBUG_FOLDER)) && (strcmp(entry->d_name, DEBUG_FOLDER) == 0)) { + ms_debug("[%s] is hidden folder. Skip it", entry->d_name); + continue; + } + + len = strlen(root) + strlen(entry->d_name) + APPEND_SIZE; /* for null and slash */ + path = g_malloc(sizeof(gchar) * len); + if (path) { + g_snprintf(path, len, "%s/%s", root, entry->d_name); + candidate = g_list_append(candidate, (gpointer) path); + } + /*1 TODO: how can i handle else case?*/ + if (option & MF_SEARCH_OPT_DIR) { + __mf_ug_search_thread_lock(handle); + result->total_count++; + __mf_ug_search_thread_unlock(handle); + + up_name = g_utf8_strup(entry->d_name, strlen(entry->d_name)); + if (needle && strlen(needle)) { + up_needle = g_utf8_strup(needle, strlen(needle)); + gchar *nor_str = g_utf8_normalize(up_name, -1, NORMALIZE_OPTION); + if (__mf_ug_search_NFD_strstr(nor_str, up_needle)) + { + __mf_ug_search_thread_lock(handle); + result->dir_list = g_list_append(result->dir_list, (gpointer) g_strdup(path)); + result->is_end = FALSE; + __mf_ug_search_thread_unlock(handle); + __mf_ug_search_tx_wait(); + __mf_ug_search_result_publish_msg(MF_SEARCH_PIPE_MSG_RESULT_REPORT, result, handle->args->user_data); + } + g_free(nor_str); + free(up_name); + up_name = NULL; + + free(up_needle); + up_needle = NULL; + } else { + free(up_name); + up_name = NULL; + } + } + } + } + closedir(directory); + directory = NULL; + } + + return candidate; +} + +static gpointer __mf_ug_search_find_thread(gpointer data) +{ + ms_handle_t *handle = (ms_handle_t *) data; + if (handle) { + ms_args_t *args = NULL; + mf_search_result_t *result = NULL; + + result = handle->result; + args = handle->args; + + if (args && result) { + GList *root = NULL; + GList *candidate = NULL; /*use this list as stack*/ + root = args->root_path; + while (root) { + char *path = (char *)root->data; + if (path) { + /*push root paths to stack*/ + candidate = g_list_append(candidate, (gpointer) g_strdup(path)); + } + root = g_list_next(root); + } + + while (candidate) { + GList *new_list = NULL; + GList *list = NULL; + gchar *item = NULL; + + __mf_ug_search_thread_lock(handle); + if (handle->is_stop) { + __mf_ug_search_thread_unlock(handle); + result->is_end = TRUE; + goto MF_FIND_THREAD_EXIT; + } + __mf_ug_search_thread_unlock(handle); + + list = g_list_first(candidate); + /*pop one path from stack*/ + candidate = g_list_remove_link(candidate, list); + item = (gchar *) list->data; + if (item) { + ms_debug("current : %s", item); +#if 0 + __mf_ug_search_thread_lock(handle); + if (result->current_dir) { + g_free(result->current_dir); + } + result->current_dir = g_strdup(item); + __mf_ug_search_thread_unlock(handle); +#endif + /*publish root change message here*/ + __mf_ug_search_tx_wait(); + if (handle->is_stop) { + result->is_end = TRUE; + goto MF_FIND_THREAD_EXIT; + } + __mf_ug_search_result_publish_msg(MF_SEARCH_PIPE_MSG_ROOT_CHANGE, item, args->user_data); + new_list = __mf_ug_search_do_find(item, args->needle, args->option, handle); + g_free(item); + item = NULL; + g_list_free(list); + list = NULL; + } + /*push new paths to stack*/ + candidate = g_list_concat(new_list, candidate); + } + + __mf_ug_search_thread_lock(handle); + result->is_end = TRUE; + __mf_ug_search_thread_unlock(handle); + __mf_ug_search_tx_wait(); + __mf_ug_search_result_publish_msg(MF_SEARCH_PIPE_MSG_FINISHED, handle->result, args->user_data); +MF_FIND_THREAD_EXIT: + if (candidate) { + g_list_foreach(candidate, (GFunc) g_free, NULL); + g_list_free(candidate); + candidate = NULL; + } + } else { + ms_error("args : %p or result : %p is not allocated yet!!", handle->args, handle->result); + } + } + /*g_thread_exit(NULL);*/ + return NULL; +} + +int _mf_ug_search_init(ms_handle_t **handle) +{ + GMutex *lock = NULL; + ms_handle_t *ms_handle = NULL; + + ms_debug(""); + + if (!handle) { + return MF_SEARCH_ERROR_INVAL_P; + } + + ms_handle = g_malloc0(sizeof(ms_handle_t)); + if (ms_handle == NULL) { + ms_error("Fail to allocate memory for handle "); + *handle = NULL; + return MF_SEARCH_ERROR_ALLOC; + } + + ms_handle->state = MF_SEARCH_STATE_INIT; + ms_handle->is_stop = FALSE; + + lock = g_mutex_new(); + if (!lock) { + ms_error("Fail to create cmd_lock"); + g_free(ms_handle); + return MF_SEARCH_ERROR_ALLOC; + } + ms_handle->cmd_lock = lock; + + *handle = ms_handle; + + ms_info("Success to make search handle : %p", ms_handle); + return MF_SEARCH_ERROR_NONE; +} + +int _mf_ug_search_start(ms_handle_t *handle, const char **root_path, unsigned int path_num, const char *needle, mf_search_option option, void *user_data) +{ + ms_args_t *args = NULL; + mf_search_result_t *result = NULL; + mf_search_option l_opt = MF_SEARCH_OPT_NONE; + int ret = MF_SEARCH_ERROR_NONE; + int i = 0; + + if (!handle) { + ms_error("handle is NULL"); + return MF_SEARCH_ERROR_INVAL_P; + } + + if (handle->state != MF_SEARCH_STATE_INIT) { + ms_error("invaild state : %d", handle->state); + return MF_SEARCH_ERROR_INVAL_S; + } + + if (!root_path || !needle || path_num < 1) { + ms_error("invaild arguments - root[%p], path_num[%d], needle[%p]", root_path, path_num, needle); + return MF_SEARCH_ERROR_INVAL_P; + } + + __mf_ug_search_cmd_lock(handle); + + if (handle->args) { + __mf_ug_search_args_free(handle->args); + handle->args = NULL; + } + handle->args = args = g_malloc0(sizeof(ms_args_t)); + if (!args) { + ms_error("fail to alloc args"); + ret = MF_SEARCH_ERROR_ALLOC; + goto FAIL_FREE_MEM; + } + + if (option == MF_SEARCH_OPT_NONE) { + ms_warn("option is MF_SEARCH_OPT_NONE, set all option automatically "); + l_opt = MF_SEARCH_OPT_HIDDEN | MF_SEARCH_OPT_DIR | MF_SEARCH_OPT_FILE; + } else { + l_opt = option; + } + + for (i = 0; i < path_num; i++) { + const char *path = root_path[i]; + ms_debug("%d th root path is %s", i, path); +#ifdef CHECK_RESTRICTED_PATH + if (!__mf_ug_search_check_licet_path(path)) { + ms_error("%dth root path[%s] is invaild", i, path); + ret = MF_SEARCH_ERROR_INVAL_P; + goto FAIL_FREE_MEM; + } +#endif /*CHECK_RESTRICTED_PATH*/ + if (g_file_test(path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR) + && ((l_opt & MF_SEARCH_OPT_HIDDEN) || strncmp(path, ".", 1)) + && TRUE) { + gchar *new_path = NULL; + gssize len = strlen(path); + + if (path[len - 1] == '/') { + new_path = g_strndup(path, len - 1); + } else { + new_path = g_strndup(path, len); + } + args->root_path = g_list_append(args->root_path, (gpointer) new_path); + } else { + ms_error("Fail to test %dthe root path[%s]", i, path); + ret = MF_SEARCH_ERROR_INVAL_P; + goto FAIL_FREE_MEM; + } + } + args->user_data = user_data; + + + args->needle = g_utf8_normalize(needle, -1, NORMALIZE_OPTION); + if (!args->needle) { + ms_error("fail to alloc args->needle"); + goto FAIL_FREE_MEM; + } + + args->option = l_opt; + + if (handle->result) { + __mf_ug_search_result_free(handle->result); + handle->result = NULL; + } + handle->result = result = g_malloc0(sizeof(ms_args_t)); + if (!result) { + ms_error("fail to alloc result"); + ret = MF_SEARCH_ERROR_ALLOC; + goto FAIL_FREE_MEM; + } + + handle->thread_mutex = g_mutex_new(); + if (!handle->thread_mutex) { + ms_error("fail to alloc handle->thread_mutex"); + ret = MF_SEARCH_ERROR_ALLOC; + goto FAIL_FREE_MEM; + } + + handle->is_stop = FALSE; + handle->result->is_end = FALSE; + + /*create thread for find item.*/ + handle->thread_h = g_thread_create(__mf_ug_search_find_thread, handle, TRUE, NULL); + if (!handle->thread_h) { + ms_error("fail to create __mf_ug_search_find_thread"); + ret = MF_SEARCH_ERROR_INTERNAL; + goto FAIL_FREE_MEM; + } + /*create idler for reporting find result.*/ + handle->state = MF_SEARCH_STATE_SEARCH; + __mf_ug_search_cmd_unlock(handle); + return MF_SEARCH_ERROR_NONE; + +FAIL_FREE_MEM: + if (args) { + __mf_ug_search_args_free(args); + handle->args = NULL; + } + + if (result) { + __mf_ug_search_result_free(result); + handle->result = NULL; + } + + if (handle->thread_mutex) { + g_mutex_free(handle->thread_mutex); + handle->thread_mutex = NULL; + } + + if (handle->thread_h) { + __mf_ug_search_thread_lock(handle); + handle->is_stop = TRUE; + __mf_ug_search_thread_unlock(handle); + g_thread_join(handle->thread_h); + handle->thread_h = NULL; + } + __mf_ug_search_cmd_unlock(handle); + + return ret; +} + +int _mf_ug_search_stop(ms_handle_t *handle) +{ + ms_debug(""); + + if (!handle) { + ms_error("handle is NULL"); + return MF_SEARCH_ERROR_INVAL_P; + } + + if (handle->state != MF_SEARCH_STATE_SEARCH) { + ms_error("invaild state : %d", handle->state); + return MF_SEARCH_ERROR_INVAL_S; + } + + __mf_ug_search_cmd_lock(handle); + + __mf_ug_search_thread_lock(handle); + handle->is_stop = TRUE; + __mf_ug_search_thread_unlock(handle); + + pthread_mutex_lock(&gLockSearchMsg); + if (flagSearchMsg == 0) { + flagSearchMsg = 1; + pthread_cond_signal(&gCondSearchMsg); + } + pthread_mutex_unlock(&gLockSearchMsg); + + if (handle->thread_h) { + g_thread_join(handle->thread_h); + handle->thread_h = NULL; + } + + if (handle->thread_mutex) { + g_mutex_free(handle->thread_mutex); + handle->thread_mutex = NULL; + } + + if (handle->args) { + __mf_ug_search_args_free(handle->args); + handle->args = NULL; + } + if (handle->result) { + __mf_ug_search_result_free(handle->result); + handle->result = NULL; + } + + handle->state = MF_SEARCH_STATE_INIT; + handle->is_stop = FALSE; + + __mf_ug_search_cmd_unlock(handle); + + return MF_SEARCH_ERROR_NONE; +} + +void _mf_ug_search_finalize(ms_handle_t **handle) +{ + ms_handle_t *ms_handle = *handle; + + ms_debug(""); + + if (!ms_handle) { + ms_warn("invaild handle"); + return; + } + + if (ms_handle->state == MF_SEARCH_STATE_SEARCH) { + mf_ug_search_stop(ms_handle); + } +/* __mf_ug_search_cmd_lock(ms_handle); */ +/* __mf_ug_search_cmd_unlock(ms_handle); */ + + if (ms_handle->cmd_lock) { + g_mutex_free(ms_handle->cmd_lock); + ms_handle->cmd_lock = NULL; + } + g_free(ms_handle); + *handle = NULL; + + return; +} + +/*+++++++++++++++++++++++++ UTIL APIs ++++++++++++++++++++++++++++++ */ +static void __mf_ug_search_tx_wait() +{ + pthread_mutex_lock(&gLockSearchMsg); + while (flagSearchMsg == 0) { + pthread_cond_wait(&gCondSearchMsg, &gLockSearchMsg); + } + flagSearchMsg = 0; + pthread_mutex_unlock(&gLockSearchMsg); +} + +static void __mf_ug_search_result_publish_msg(mf_search_pipe_msg_type type, void *result, void *user_data) +{ + ugData *ugd = (ugData *)user_data; + /*generate message block*/ + mf_search_pipe_msg msg; + memset(&msg, 0, sizeof(mf_search_pipe_msg)); + + msg.mf_sp_msg_type = type; + if (msg.mf_sp_msg_type == MF_SEARCH_PIPE_MSG_RESULT_REPORT) { + msg.report_result = g_strdup((gchar *) result); + msg.current_path = NULL; + } else if (msg.mf_sp_msg_type == MF_SEARCH_PIPE_MSG_ROOT_CHANGE) { + msg.report_result = NULL; + msg.current_path = g_strdup((gchar *) result); + ms_debug("current path is %s", msg.current_path); + } else if (msg.mf_sp_msg_type == MF_SEARCH_PIPE_MSG_FINISHED) { + msg.report_result = result; + msg.current_path = NULL; + } else { + msg.report_result = NULL; + msg.current_path = NULL; + } + + /*write message to pipe*/ + ecore_pipe_write(ugd->ug_UiGadget.ug_pSyncPipe, &msg, sizeof(msg)); +} + +gchar *_mf_ug_search_result_dir_get(mf_search_result_t * result) +{ + gchar *name = NULL; + if (result) { + GList *list = NULL; + list = result->dir_list; + if (list && list->data) { + gchar *item = (gchar *) list->data; + result->dir_list = g_list_remove(list, item); + name = item; + } + } + return name; +} + +gchar *_mf_ug_search_result_file_get(mf_search_result_t * result) +{ + gchar *name = NULL; + if (result) { + GList *list = NULL; + list = result->file_list; + if (list && list->data) { + gchar *item = (gchar *) list->data; + result->file_list = g_list_remove(list, item); + name = item; + } + } + return name; +} + +gboolean _mf_ug_search_result_is_end(mf_search_result_t *result) +{ + gboolean end = FALSE; + if (result) { + end = result->is_end; + } + return end; +} + +guint _mf_ug_search_result_total_count_get(mf_search_result_t *result) +{ + guint count = 0; + if (result) { + count = result->total_count; + } + return count; +} + +gchar *_mf_ug_search_result_current_dir_get(mf_search_result_t * result) +{ + gchar *c_dir = NULL; + if (result) { + if (result->current_dir) { + c_dir = result->current_dir; + result->current_dir = NULL; + } + } + return c_dir; +} diff --git a/src/common/mf-ug-search.c b/src/common/mf-ug-search.c new file mode 100644 index 0000000..db2ca6e --- /dev/null +++ b/src/common/mf-ug-search.c @@ -0,0 +1,125 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.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 <stdio.h> +#include <dirent.h> +#include <sys/types.h> +#include <string.h> +#include <glib.h> + +#include "mf-ug-dlog.h" +#include "mf-ug-search.h" +#include "mf-ug-search-internal.h" + + +/*+++++++++++++++++++++++ APIs +++++++++++++++++++++++*/ + +int mf_ug_search_init(mf_search_handle *handle) +{ + int ret = 0; + ms_handle_t *ms_handle = NULL; + + if (!handle) { + return -1; + } + if (!g_thread_supported()) { + g_thread_init(NULL); + } + ret = _mf_ug_search_init(&ms_handle); + if (ret < 0) { + ms_error("Fail to init search handle "); + *handle = (mf_search_handle) 0; + return ret; + } + + *handle = (mf_search_handle) ms_handle; + + return MF_SEARCH_ERROR_NONE; +} + +int mf_ug_search_start(mf_search_handle handle, + const char **root_path, unsigned int path_num, const char *needle, mf_search_option option, void *user_data) +{ + int ret = 0; + if (!handle) { + return MF_SEARCH_ERROR_INVAL_P; + } + + if (!root_path || !needle || path_num < 1) { + return MF_SEARCH_ERROR_INVAL_P; + } + + ret = _mf_ug_search_start((ms_handle_t *) handle, root_path, path_num, needle, option, user_data); + + if (ret < 0) { + ms_error("Fail to start search "); + } + return ret; +} + +int mf_ug_search_stop(mf_search_handle handle) +{ + int ret = 0; + + ret = _mf_ug_search_stop((ms_handle_t *) handle); + if (ret < 0) { + ms_error("Fail to stop search "); + } + return ret; +} + +void mf_ug_search_finalize(mf_search_handle *handle) +{ + _mf_ug_search_finalize((ms_handle_t **) handle); + return; +} + +/*+++++++++++++++++++++++ UTIL APIs +++++++++++++++++++++++*/ + +char *mf_ug_search_result_dir_get(mf_search_result_t *result) +{ + return _mf_ug_search_result_dir_get(result); +} + +char *mf_ug_search_result_file_get(mf_search_result_t *result) +{ + return _mf_ug_search_result_file_get(result); +} + +int mf_ug_search_result_is_end(mf_search_result_t *result, int *is_end) +{ + if (result) { + *is_end = _mf_ug_search_result_is_end(result); + } else { + return MF_SEARCH_ERROR_INVAL_P; + } + return MF_SEARCH_ERROR_NONE; +} + +int mf_ug_search_result_total_count_get(mf_search_result_t *result, unsigned int *count) +{ + if (result) { + *count = _mf_ug_search_result_total_count_get(result); + } else { + return MF_SEARCH_ERROR_INVAL_P; + } + return MF_SEARCH_ERROR_NONE; +} + +char *mf_ug_search_result_current_dir_get(mf_search_result_t *result) +{ + return _mf_ug_search_result_current_dir_get(result); +} diff --git a/src/common/mf-ug-util.c b/src/common/mf-ug-util.c new file mode 100644 index 0000000..a9ea7b7 --- /dev/null +++ b/src/common/mf-ug-util.c @@ -0,0 +1,858 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.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 <pthread.h> +#include <vconf.h> + +#include "mf-ug-util.h" +#include "mf-ug-cb.h" +#include "mf-ug-winset.h" +#include "mf-ug-fm-svc-wrapper.h" +#include "mf-ug-fs-util.h" +#include "mf-ug-inotify-handle.h" +#include "mf-ug-resource.h" + +#define MF_UG_TIMER_INTERVAL_VIBRATION 0.5 +#define MF_UG_VIBRATION_DEVICE 0 +#define MF_UG_VIBRATION_DURATION 500 +#ifdef UG_OPERATION_SELECT_MODE +#define OPERATION_SEPERATOR ";" +#endif +#define NORMAL_SEPERATOR "?" + +/****************************** +** Prototype : ug_genlist_selected_state_get +** Description : +** Input : void *data +** Output : bool +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +bool mf_ug_util_is_genlist_selected(void *data) +{ + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + ug_mf_retvm_if(ugd == NULL, false, "ugd is NULL"); + + Elm_Object_Item *gli = NULL; + Elm_Object_Item *nli = NULL; + Evas_Object *genlist = NULL; + + ugNaviBar *pNavi_s = mf_ug_navi_bar_get_in_use_navi(ugd); + ug_mf_retvm_if(pNavi_s == NULL, false, "get navigation bar in use failed"); + + if (ugd->ug_MainWindow.ug_pNaviGenlist) { + genlist = ugd->ug_MainWindow.ug_pNaviGenlist; + gli = elm_genlist_first_item_get(genlist); + + while (gli) { + ugListItemData *itemData = (ugListItemData *)elm_object_item_data_get(gli); + ug_mf_retvm_if(itemData == NULL, false, "itemData is NULL"); + if (itemData->ug_bChecked == true) { + UG_TRACE_END; + return true; + } + nli = elm_genlist_item_next_get(gli); + gli = nli; + } + } + UG_TRACE_END; + return false; +} + +/****************************** +** Prototype : ug_parase_path_get +** Description : +** Input : GList *dest_list +** char *path_list +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +void mf_ug_util_get_params_path(Eina_List **dest_list, const char *path_list) +{ + UG_TRACE_BEGIN; + ug_mf_retm_if(dest_list == NULL, "dest_list is NULL"); + + gchar **result = NULL; + gchar **params = NULL; + result = g_strsplit(path_list, "?", 0); + + for (params = result; *params; params++) { + *dest_list = eina_list_append(*dest_list, strdup(*params)); + } + + g_strfreev(result); + UG_TRACE_END; +} + +/****************************** +** Prototype : mf_ug_util_free_eina_list_data +** Description : Samsung +** Input : Eina_List **list +** mf_ug_eina_list_node_type node_type +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +void mf_ug_util_free_eina_list_data(Eina_List **list, mf_ug_eina_list_node_type node_type) +{ + UG_TRACE_BEGIN; + ug_mf_retm_if(list == NULL, "list is NULL"); + ug_mf_retm_if(*list == NULL, "*list is NULL"); + + Eina_List *l = NULL; + void *pNode = NULL; + switch (node_type) { + case NODE_TYPE_CHAR: + case NODE_TYPE_PNODE: + EINA_LIST_FOREACH(*list, l, pNode) { + free(pNode); + pNode = NULL; + } + break; + case NODE_TYPE_GSTRING: + EINA_LIST_FOREACH(*list, l, pNode) { + if (pNode != NULL) { + g_string_free(pNode, TRUE); + pNode = NULL; + } + } + break; + default: + break; + } + + eina_list_free(*list); + *list = NULL; + UG_TRACE_END; +} + + +/****************************** +** Prototype : __mf_ug_util_get_marked_selected_items +** Description : +** Input : GList *list +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +static void __mf_ug_util_get_marked_selected_items(Eina_List *list, Eina_List **select_list) +{ + UG_TRACE_BEGIN; + ug_mf_retm_if(select_list == NULL, "select_list is NULL"); + ug_mf_retm_if(list == NULL, "list is NULL"); + + Eina_List *l = NULL; + void *pNode = NULL; + + EINA_LIST_FOREACH(list, l, pNode) { + if (pNode != NULL) { + *select_list = eina_list_append(*select_list, strdup(pNode)); + } + } + UG_TRACE_END; + +} + +/****************************** +** Prototype : __mf_ug_util_get_marked_off_selected_items +** Description : +** Input : void *data +** Evas_Object* content +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +static void __mf_ug_util_get_marked_off_selected_items(void *data, Eina_List **select_list) +{ + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + ug_mf_retm_if(ugd == NULL, "ugData is NULL"); + ug_mf_retm_if(select_list == NULL, "selected_list is NULL"); + ug_mf_retm_if(ugd->ug_MainWindow.ug_pNaviGenlist == NULL, "ugd->ug_MainWindow.ug_pNaviGenlist is NULL"); + + + Evas_Object *content = ugd->ug_MainWindow.ug_pNaviGenlist; + Elm_Object_Item *gli = elm_genlist_first_item_get(content); + int radio_id = 1; + Elm_Object_Item *nli = NULL; + + + while (gli) { + + ugListItemData *params = (ugListItemData *)elm_object_item_data_get(gli); + ug_mf_retm_if(params == NULL, "params is NULL"); + if (ugd->ug_UiGadget.ug_iSelectMode == SINGLE_ALL_MODE || ugd->ug_UiGadget.ug_iSelectMode == SINGLE_FILE_MODE) { + if (params->ug_pRadioBox) { + if (elm_radio_value_get(ugd->ug_MainWindow.ug_pRadioGroup) == radio_id) { + *select_list = eina_list_append(*select_list, strdup(params->ug_pItemName->str)); + break; + } + radio_id++; + } + } else if (ugd->ug_UiGadget.ug_iSelectMode == MULTI_ALL_MODE || + ugd->ug_UiGadget.ug_iSelectMode == MULTI_FILE_MODE || + ugd->ug_UiGadget.ug_iSelectMode == IMPORT_MODE || + ugd->ug_UiGadget.ug_iSelectMode == IMPORT_PATH_SELECT_MODE || + ugd->ug_UiGadget.ug_iSelectMode == IMPORT_SINGLE) { + if (params->ug_pCheckBox) { + if (params->ug_bChecked == true) { + *select_list = eina_list_append(*select_list, strdup(params->ug_pItemName->str)); + } + } + } + nli = elm_genlist_item_next_get(gli); + gli = nli; + } + UG_TRACE_END; +} + +/****************************** +** Prototype : mf_ug_util_get_send_result +** Description : +** Input : void *data +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +char *mf_ug_util_get_send_result(void *data) +{ + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + ug_mf_retvm_if(ugd == NULL, NULL, "ugData is NULL"); + + char *file_selected = NULL; + Eina_List *selected_list = NULL; + Eina_List *l = NULL; + char *pNode = NULL; + + if (ugd->ug_UiGadget.ug_iMarkedMode == MARKED_ON + && (ugd->ug_UiGadget.ug_iSelectMode == MULTI_FILE_MODE || ugd->ug_UiGadget.ug_iSelectMode == MULTI_ALL_MODE)) { + __mf_ug_util_get_marked_selected_items(ugd->ug_UiGadget.ug_pMultiSelectFileList, &selected_list); + } else { + __mf_ug_util_get_marked_off_selected_items(ugd, &selected_list); + } + + EINA_LIST_FOREACH(selected_list, l, pNode) { + if (pNode != NULL) { + if (file_selected == NULL) { + file_selected = g_strconcat(pNode, NULL); + } else { + char *temp = file_selected; +#ifdef UG_OPERATION_SELECT_MODE + if (ugd->ug_UiGadget.ug_bOperationSelectFlag) { + file_selected = g_strconcat(file_selected, OPERATION_SEPERATOR, pNode, NULL); + } else +#endif + file_selected = g_strconcat(file_selected, NORMAL_SEPERATOR, pNode, NULL); + free(temp); + } + } + } + mf_ug_util_free_eina_list_data(&selected_list, NODE_TYPE_CHAR); + UG_TRACE_END; + return file_selected; +} + + +/****************************** +** Prototype : _ug_mf_set_state_as +** Description : +** Input : struct ugmyfiledata* data +** int state +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +void mf_ug_util_set_current_state(void *data, int state) +{ + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + ug_mf_retm_if(ugd == NULL, "ugd is NULL"); + + ugd->ug_Status.ug_iState = state; + UG_TRACE_END; +} + + +/****************************** +** Prototype : mf_ug_util_get_mmc_state +** Description : +** Input : int* mmc_card +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +int mf_ug_util_get_mmc_state(int *mmc_card) +{ + UG_TRACE_BEGIN; + int data = UG_ERROR_RETURN; + int error_code = MYFILE_ERR_NONE; + + ug_mf_retvm_if(mmc_card == NULL, MYFILE_ERR_SRC_ARG_INVALID, "mmc_card is NULL"); + + *mmc_card = 0; + error_code = vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &data); + + if (error_code) { + UG_TRACE_END; + return MYFILE_ERR_GET_VCONF_FAIL; + } + + if (data != VCONFKEY_SYSMAN_MMC_MOUNTED) { + *mmc_card = MMC_OFF; + } else { + *mmc_card = MMC_ON; + } + UG_TRACE_END; + return error_code; +} + +/****************************** +** Prototype : mf_ug_util_create_dir_monitor +** Description : Samsung +** Input : void *data +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +int mf_ug_util_create_dir_monitor(void *data) +{ + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + ug_mf_retvm_if(ugd == NULL, UG_ERROR_RETURN, "ugData is NULL"); + + if (ugd->ug_UiGadget.ug_pInotifyPipe) { + ecore_pipe_del(ugd->ug_UiGadget.ug_pInotifyPipe); + ugd->ug_UiGadget.ug_pInotifyPipe = NULL; + } + ugd->ug_UiGadget.ug_pInotifyPipe = ecore_pipe_add(mf_ug_cb_dir_pipe_cb, (const void *)ugd); + UG_TRACE_END; + + return mf_ug_inotify_handle_init_inotify(); +} + + +/****************************** +** Prototype : mf_ug_util_add_dir_watch +** Description : Samsung +** Input : const char *path +** void *data +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +int mf_ug_util_add_dir_watch(const char *path, void *data) +{ + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + ug_mf_retvm_if(ugd == NULL, UG_ERROR_RETURN, "ugd is NULL"); + UG_SAFE_FREE_CHAR(ugd->ug_Status.monitor_path); + ugd->ug_Status.monitor_path = g_strdup(path); + return mf_ug_inotify_handle_add_inotify_watch(path, mf_ug_cb_dir_update_cb, data); +} + +int mf_ug_util_remove_dir_watch(void) +{ + return mf_ug_inotify_handle_rm_inotify_watch(); +} + +/****************************** +** Prototype : mf_ug_util_set_mmc_state_cb +** Description : Samsung +** Input : void *data +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +int mf_ug_util_set_mmc_state_cb(void *data) +{ + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + ug_mf_retvm_if(ugd == NULL, UG_ERROR_RETURN, "ugd is NULL"); + + int mmc_state = MMC_OFF; + mf_ug_util_get_mmc_state(&mmc_state); + ugd->ug_Status.ug_iMmcFlag = mmc_state; + + UG_TRACE_END; + return vconf_notify_key_changed(VCONFKEY_SYSMAN_MMC_STATUS, mf_ug_cb_mmc_changed_cb, ugd); +} + +/****************************** +** Prototype : mf_ug_util_destory_mmc_state_cb +** Description : Samsung +** Input : None +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +void mf_ug_util_destory_mmc_state_cb() +{ + UG_TRACE_BEGIN; + vconf_ignore_key_changed(VCONFKEY_SYSMAN_MMC_STATUS, mf_ug_cb_mmc_changed_cb); + UG_TRACE_END; +} + +/****************************** +** Prototype : mf_ug_util_destory_dir_monitor +** Description : Samsung +** Input : void *data +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +void mf_ug_util_destory_dir_monitor(void *data) +{ + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + ug_mf_retm_if(ugd == NULL, "ugd is NULL"); + + if (ugd->ug_UiGadget.ug_pInotifyPipe) { + ecore_pipe_del(ugd->ug_UiGadget.ug_pInotifyPipe); + ugd->ug_UiGadget.ug_pInotifyPipe = NULL; + } + + mf_ug_inotify_handle_finalize_inotify(); + UG_TRACE_END; + + return; +} + + +/****************************** +** Prototype : mf_ug_util_storage_insert_action +** Description : Samsung +** Input : void *data +** char* pItemLabel +** Output : None +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +void mf_ug_util_storage_insert_action(void *data, char *pItemLabel) +{ + UG_TRACE_BEGIN; + ugData *ugd = (ugData *)data; + ug_mf_retm_if(ugd == NULL, "ugd is NULL"); + + Elm_Object_Item *pItemPhone = NULL; + ugFsNodeInfo *pNode = NULL; + + if (ugd->ug_Status.ug_iMmcFlag) { + pNode = (ugFsNodeInfo *) malloc(sizeof(ugFsNodeInfo)); + memset(pNode, 0, sizeof(ugFsNodeInfo)); + /*set path */ + snprintf(pNode->path, sizeof(pNode->path), "%s", STORAGE_PARENT); + snprintf(pNode->name, sizeof(pNode->name), "%s", MMC_NAME); + pNode->type = UG_FILE_TYPE_DIR; + ugd->ug_UiGadget.ug_pDirList = eina_list_append(ugd->ug_UiGadget.ug_pDirList, pNode); + mf_ug_genlist_item_append(ugd->ug_MainWindow.ug_pNaviGenlist, pNode, ugd, 0, &ugd->ug_Status.ug_normalitc); + } + + UG_TRACE_END; +} + + + +/****************************** +** Prototype : mf_ug_util_get_file_launch_type +** Description : +** Input : char * path +** Output : UG_MYFILE_LAUNCH_TYPE +** Return Value : +** Calls : +** Called By : +** +** History : +** 1.Date : 2010/12/10 +** Author : Samsung +** Modification : Created function +** +******************************/ +mf_ug_launch_type mf_ug_util_get_file_launch_type(char *path) +{ + if (path == NULL) { + UG_TRACE_END; + return LAUNCH_TYPE_UNSUPPORT; + } + if (ecore_file_file_get(path) == NULL) { + UG_TRACE_END; + return LAUNCH_TYPE_UNSUPPORT; + } + if (ecore_file_is_dir(path) == 1) { + UG_TRACE_END; + return LAUNCH_TYPE_UNSUPPORT; + } + if (mf_ug_file_attr_is_drm_file(path) == 0) { + mf_ug_drm_file_mime_type drm_file_type = mf_ug_fs_oper_get_drm_type(path); + + if (drm_file_type == MF_UG_DRM_RINGTONE_FILE) { + UG_TRACE_END; + return LAUNCH_TYPE_MUSIC; + } else if (drm_file_type == MF_UG_DRM_IMAGE_FILE) { + UG_TRACE_END; + return LAUNCH_TYPE_IMAGE; + } else if (drm_file_type == MF_UG_DRM_VIDEO_FILE) { + UG_TRACE_END; + return LAUNCH_TYPE_VIDEO; + } else { + UG_TRACE_END; + return LAUNCH_TYPE_UNSUPPORT; + } + } else { + mf_ug_fs_file_type category_t = 0; + mf_ug_file_attr_get_file_category(path, &category_t); + if (category_t == UG_FILE_TYPE_MUSIC || category_t == UG_FILE_TYPE_SOUND || category_t == UG_FILE_TYPE_VOICE) { + UG_TRACE_END; + return LAUNCH_TYPE_MUSIC; + } else if (category_t == UG_FILE_TYPE_IMAGE) { + UG_TRACE_END; + return LAUNCH_TYPE_IMAGE; + } else { + UG_TRACE_END; + return LAUNCH_TYPE_UNSUPPORT; + } + } + UG_TRACE_END; +} + +mf_ug_theme_type mf_ug_util_get_theme(void) +{ + mf_ug_theme_type theme = UG_THEME_INVALID; + char *name; + + char *theme_name = vconf_get_str(VCONFKEY_SETAPPL_WIDGET_THEME_STR); + ug_debug("theme is [%s]", theme_name); + ug_mf_retvm_if(theme_name == NULL, UG_THEME_ERROR, "Failed to get vconf value"); /* file system exceptional handle */ + + name = strrchr(theme_name, '/'); + + if (!name) + name = theme_name; + else + ++name; + + ug_debug("name is [%s]", name); + //SETTING_TRACE("name:%s", name); + /* special theme process.. */ + if (0 == g_strcmp0("tizen-black.edj", name) || 0 == g_strcmp0("tizen-black-hd.edj", name)) { + theme = UG_THEME_NBEAT_BLACK; + } else if (0 == g_strcmp0("tizen.edj", name) || 0 == g_strcmp0("tizen-hd.edj", name) + || 0 == g_strcmp0("blue-hd.edj", name)) { + theme = UG_THEME_NBEAT; + } else { + theme = UG_THEME_ERROR; + } + free(theme_name); + theme_name = NULL; + ug_debug("theme is [%d]", theme); + return theme; +} + + +char *mf_ug_util_upper_folder_name_get(void *data, GString *fullpath) +{ + ug_mf_retvm_if(data == NULL, NULL, "data is NULL"); + ug_mf_retvm_if(fullpath == NULL, NULL, "fullpath is NULL"); + ug_mf_retvm_if(fullpath->str == NULL, NULL, "fullpath is NULL"); + + GString *parent_path = NULL; + GString *gName = NULL; + char *upper_name = NULL; + + parent_path = mf_ug_fm_svc_wrapper_get_file_parent_path(fullpath); + + ug_mf_retvm_if(parent_path == NULL, NULL, "fullpath is NULL"); + ug_mf_retvm_if(parent_path->str == NULL, NULL, "fullpath is NULL"); + + + if (!g_strcmp0(parent_path->str, PHONE_FOLDER)) { + upper_name = g_strdup(MF_UG_LABEL_PHONE); + } else if (!g_strcmp0(parent_path->str, MEMORY_FOLDER)) { + upper_name = g_strdup(MF_UG_LABEL_MMC); + } else { + gName = mf_ug_fm_svc_wapper_get_file_name(parent_path); + UG_GSTRING_CHECK_NULL_GOTO(gName, FAILED_EXIT); + upper_name = g_strdup(gName->str); + } + + UG_CHAR_CHECK_NULL_GOTO(upper_name, FAILED_EXIT); + UG_SAFE_FREE_GSTRING(parent_path); + UG_SAFE_FREE_GSTRING(gName); + return upper_name; + +FAILED_EXIT: + UG_SAFE_FREE_GSTRING(parent_path); + UG_SAFE_FREE_GSTRING(gName); + return NULL; + +} + +void mf_ug_util_sort_the_file_list(void *data) +{ + + UG_TRACE_BEGIN; + ug_mf_retm_if(data == NULL, "data is null"); + ugData *ugd = (ugData *)data; + + int iSortTypeValue = 0; + + iSortTypeValue = ugd->ug_Status.ug_iSortType; + + mf_ug_fs_oper_sort_list(&ugd->ug_UiGadget.ug_pFilterList, MF_UG_SORT_BY_NAME_A2Z); + mf_ug_fs_oper_sort_list(&ugd->ug_UiGadget.ug_pDirList, MF_UG_SORT_BY_NAME_A2Z); + +} + +int mf_ug_util_check_disk_space(void *data) +{ + UG_TRACE_BEGIN; + ug_mf_retvm_if(data == NULL, MYFILE_ERR_SRC_ARG_INVALID, "data is null"); + ugData *ugd = (ugData *)data; + + mf_ug_storage_type state = MF_UG_NONE; + unsigned long free_space = 0; + + if (ugd->ug_Status.ug_iMore == UG_MORE_CREATE_FOLDER) { + state = mf_ug_fm_svc_wapper_get_location(ugd->ug_Status.ug_pPath->str); + free_space = mf_ug_fm_svc_wrapper_get_free_space(state); + ug_debug("free size is %lu\n", free_space); + /* + ** in vfat fs type, sector size is 16K. + ** it is to say that the limited size of the free space should be 16K + ** or it will report space used up. + ** check free_space == 0 can make sure at least 16K is free on the disk + ** while every dir takes 4K + */ + if (free_space == 0) { + ugd->ug_MainWindow.ug_pNormalPopup = mf_ug_popup_create(ugd, UG_POPMODE_TEXT, NULL, + MF_UG_LABEL_NOT_ENOUGH_SPACE, MF_UG_LABEL_OK, + NULL, NULL, mf_ug_cb_warning_popup_cb, ugd); + return MYFILE_ERR_NO_FREE_SPACE; + } + } + + return MYFILE_ERR_NONE; +} + +void mf_ug_util_operation_alloc_failed(void *data) +{ + UG_TRACE_BEGIN; + ug_mf_retm_if(data == NULL, "data is null"); + ugData *ugd = (ugData *)data; + + ugd->ug_MainWindow.ug_pNormalPopup = mf_ug_popup_create(ugd, UG_POPMODE_TEXT, NULL, MF_UG_LABEL_MEMORY_NOT_ENOUGH, + NULL, NULL, NULL, (Evas_Smart_Cb) elm_exit, NULL); +} + +long mf_ug_util_character_count_get(const char *original) +{ + ug_mf_retvm_if(original == NULL, 0, "input string is NULL"); + long count = 0; + char *utf8_form = g_locale_to_utf8(original, -1, NULL, NULL, NULL); + if (utf8_form == NULL) + return count; + else { + count = g_utf8_strlen(utf8_form, -1); + free(utf8_form); + ug_debug("utf8 count is %ld", count); + return count; + } +} + +ugFsNodeInfo *mf_ug_util_generate_pnode(const char *path, int file_type) +{ + ug_mf_retvm_if(path == NULL, NULL, "path is NULL"); + ugFsNodeInfo *pNode = NULL; + int error = MYFILE_ERR_NONE; + + pNode = (ugFsNodeInfo *) malloc(sizeof(ugFsNodeInfo)); + if (pNode == NULL) { + return NULL; + } + memset(pNode, 0, sizeof(ugFsNodeInfo)); + char *parent = NULL; + error = mf_ug_file_attr_get_parent_path(path, &parent); + if (error == MYFILE_ERR_NONE) { + snprintf(pNode->path, sizeof(pNode->path), "%s", parent); + snprintf(pNode->name, sizeof(pNode->name), "%s", ecore_file_file_get(path)); + mf_ug_file_attr_get_file_stat(path, &pNode); + if (file_type == UG_FILE_TYPE_DIR) { + pNode->type = file_type; + } else { + mf_ug_file_attr_get_file_category(path, &(pNode->type)); + } + } else { + UG_SAFE_FREE_CHAR(pNode); + } + return pNode; +} + +void mf_util_generate_list(Eina_List **list, const char *path, int file_type) +{ + ug_mf_retm_if(list == NULL, "list is NULL"); + ug_mf_retm_if(path == NULL, "path is NULL"); + + ugFsNodeInfo *pNode = mf_ug_util_generate_pnode(path, file_type); + + if (pNode) + *list = eina_list_append(*list, pNode); +} + +void mf_util_remove_item_from_list_by_location(Eina_List **list, int location) +{ + ug_mf_retm_if(list == NULL, "list is NULL"); + + Eina_List *l = NULL; + ugFsNodeInfo *node = NULL; + + EINA_LIST_FOREACH(*list, l, node) { + if ((ugFsNodeInfo *)node != NULL && strlen(((ugFsNodeInfo *)node)->path) != 0) { + if (mf_ug_fm_svc_wapper_get_location(node->path) == location){ + UG_SAFE_FREE_CHAR(node->ext); + UG_SAFE_FREE_CHAR(node); + *list = eina_list_remove_list(*list, l); + } + } + } +} + +int mf_ug_util_generate_root_view_file_list(Eina_List **list, int storage_state) +{ + UG_TRACE_BEGIN; + + ugFsNodeInfo *pNode = NULL; + pNode = (ugFsNodeInfo *) malloc(sizeof(ugFsNodeInfo)); + memset(pNode, 0, sizeof(ugFsNodeInfo)); + /*set path */ + snprintf(pNode->path, sizeof(pNode->path), "%s", PHONE_PARENT); + snprintf(pNode->name, sizeof(pNode->name), "%s", PHONE_NAME); + pNode->type = UG_FILE_TYPE_DIR; + *list = eina_list_append(*list, pNode); + + if (storage_state == MMC_ON) { + pNode = (ugFsNodeInfo *) malloc(sizeof(ugFsNodeInfo)); + memset(pNode, 0, sizeof(ugFsNodeInfo)); + /*set path */ + snprintf(pNode->path, sizeof(pNode->path), "%s", STORAGE_PARENT); + snprintf(pNode->name, sizeof(pNode->name), "%s", MMC_NAME); + pNode->type = UG_FILE_TYPE_DIR; + *list = eina_list_append(*list, pNode); + } + + return 0; +} + + |