2 * Copyright 2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <sys/types.h>
22 #include <media_content.h>
27 #include "mf-fs-util.h"
32 #include "mf-media-content.h"
34 #define MF_UDATE_NUM 1000
35 #define MF_PHONE_DEFAULT_LEVEL 3 /*the phone path is /opt/usr/media, it consists of opt and media two parts*/
36 #define MF_MMC_DEFAULT_LEVEL 3 /*the mmc path is /opt/storage/sdcard, it consists of opt and storage and sdcard three parts*/
37 typedef struct __mf_filter_s mf_filter_s;
38 struct __mf_filter_s {
39 char *cond; /*set media type or favorite type, or other query statement*/
40 media_content_collation_e collate_type; /*collate type*/
41 media_content_order_e sort_type; /*sort type*/
42 char *sort_keyword; /*sort keyword*/
43 int offset; /*offset*/
45 bool with_meta; /*whether get image or video info*/
47 #define CONDITION_LENGTH 200
48 #define MF_CONDITION_IMAGE_VIDEO "(MEDIA_TYPE=0 OR MEDIA_TYPE=1)"
50 struct _ftype_by_mime {
55 static struct _ftype_by_mime mime_type[] = {
56 {"image/png", FILE_TYPE_IMAGE},
57 {"image/jpeg", FILE_TYPE_IMAGE},
58 {"image/gif", FILE_TYPE_IMAGE},
59 {"image/bmp", FILE_TYPE_IMAGE},
60 {"image/vnd.wap.wbmp", FILE_TYPE_IMAGE},
63 {"video/x-msvideo", FILE_TYPE_VIDEO},
64 {"video/mp4", FILE_TYPE_VIDEO},
65 {"video/3gpp", FILE_TYPE_VIDEO},
66 {"video/x-ms-asf", FILE_TYPE_VIDEO},
67 {"video/x-ms-wmv", FILE_TYPE_VIDEO},
68 {"video/x-matroska", FILE_TYPE_VIDEO},
71 {"audio/mpeg", FILE_TYPE_MUSIC},
72 {"audio/x-wav", FILE_TYPE_MUSIC},
73 {"application/x-smaf", FILE_TYPE_MUSIC},
74 {"audio/mxmf", FILE_TYPE_MUSIC},
75 {"audio/midi", FILE_TYPE_MUSIC},
76 {"audio/x-xmf", FILE_TYPE_MUSIC},
77 {"audio/x-ms-wma", FILE_TYPE_MUSIC},
78 {"audio/aac", FILE_TYPE_MUSIC},
79 {"audio/ac3", FILE_TYPE_MUSIC},
80 {"audio/ogg", FILE_TYPE_MUSIC},
81 {"audio/vorbis", FILE_TYPE_MUSIC},
82 {"audio/imelody", FILE_TYPE_MUSIC},
83 {"audio/iMelody", FILE_TYPE_MUSIC},
84 {"audio/x-rmf", FILE_TYPE_MUSIC},
85 {"application/vnd.smaf", FILE_TYPE_MUSIC},
86 {"audio/mobile-xmf", FILE_TYPE_MUSIC},
87 {"audio/mid", FILE_TYPE_MUSIC},
88 {"audio/vnd.ms-playready.media.pya", FILE_TYPE_MUSIC},
89 {"audio/imy", FILE_TYPE_MUSIC},
90 {"audio/m4a", FILE_TYPE_MUSIC},
91 {"audio/melody", FILE_TYPE_MUSIC},
92 {"audio/mmf", FILE_TYPE_MUSIC},
93 {"audio/mp3", FILE_TYPE_MUSIC},
94 {"audio/mp4", FILE_TYPE_MUSIC},
95 {"audio/MP4A-LATM", FILE_TYPE_MUSIC},
96 {"audio/mpeg3", FILE_TYPE_MUSIC},
97 {"audio/mpeg4", FILE_TYPE_MUSIC},
98 {"audio/mpg", FILE_TYPE_MUSIC},
99 {"audio/mpg3", FILE_TYPE_MUSIC},
100 {"audio/smaf", FILE_TYPE_MUSIC},
101 {"audio/sp-midi", FILE_TYPE_MUSIC},
102 {"audio/wav", FILE_TYPE_MUSIC},
103 {"audio/wave", FILE_TYPE_MUSIC},
104 {"audio/wma", FILE_TYPE_MUSIC},
105 {"audio/xmf", FILE_TYPE_MUSIC},
106 {"audio/x-mid", FILE_TYPE_MUSIC},
107 {"audio/x-midi", FILE_TYPE_MUSIC},
108 {"audio/x-mp3", FILE_TYPE_MUSIC},
109 {"audio/-mpeg", FILE_TYPE_MUSIC},
110 {"audio/x-mpeg", FILE_TYPE_MUSIC},
111 {"audio/x-mpegaudio", FILE_TYPE_MUSIC},
112 {"audio/x-mpg", FILE_TYPE_MUSIC},
113 {"audio/x-ms-asf", FILE_TYPE_MUSIC},
114 {"audio/x-wave", FILE_TYPE_MUSIC},
117 {"application/pdf", FILE_TYPE_PDF},
120 {"application/msword", FILE_TYPE_DOC},
121 {"application/vnd.openxmlformats-officedocument.wordprocessingml.document", FILE_TYPE_DOC},
124 {"application/vnd.ms-powerpoint", FILE_TYPE_PPT},
125 {"application/vnd.openxmlformats-officedocument.presentationml.presentation", FILE_TYPE_PPT},
128 {"application/vnd.ms-excel", FILE_TYPE_EXCEL},
129 {"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", FILE_TYPE_EXCEL},
132 {"audio/AMR", FILE_TYPE_VOICE},
133 {"audio/AMR-WB", FILE_TYPE_VOICE},
134 {"audio/amr", FILE_TYPE_VOICE},
135 {"audio/amr-wb", FILE_TYPE_VOICE},
136 {"audio/x-amr", FILE_TYPE_VOICE},
139 {"text/html", FILE_TYPE_HTML},
142 {"application/x-shockwave-flash", FILE_TYPE_FLASH},
143 {"video/x-flv", FILE_TYPE_FLASH},
146 {"text/plain", FILE_TYPE_TXT},
149 {"text/x-opml+xml", FILE_TYPE_RSS},
152 {"text/vnd.sun.j2me.app-descriptor", FILE_TYPE_JAVA},
153 {"application/x-java-archive", FILE_TYPE_JAVA},
156 {NULL, FILE_TYPE_ETC},
159 static char *icon_array[FILE_TYPE_MAX] = {
160 [FILE_TYPE_DIR] = MF_ICON_FOLDER,
161 [FILE_TYPE_IMAGE] = MF_ICON_IMAGE,
162 [FILE_TYPE_VIDEO] = MF_ICON_VIDEO,
163 [FILE_TYPE_MUSIC] = MF_ICON_MUSIC,
164 [FILE_TYPE_SOUND] = MF_ICON_SOUND,
165 [FILE_TYPE_PDF] = MF_ICON_PDF,
166 [FILE_TYPE_DOC] = MF_ICON_DOC,
167 [FILE_TYPE_PPT] = MF_ICON_PPT,
168 [FILE_TYPE_EXCEL] = MF_ICON_EXCEL,
169 [FILE_TYPE_VOICE] = MF_ICON_VOICE,
170 [FILE_TYPE_HTML] = MF_ICON_HTML,
171 [FILE_TYPE_FLASH] = MF_ICON_FLASH,
172 [FILE_TYPE_TXT] = MF_ICON_TXT,
173 [FILE_TYPE_VCONTACT] = MF_ICON_VCONTACT,
174 [FILE_TYPE_VCALENDAR] = MF_ICON_VCALENDAR,
175 [FILE_TYPE_VNOTE] = MF_ICON_VNOTE,
176 [FILE_TYPE_RSS] = MF_ICON_RSS,
177 [FILE_TYPE_JAVA] = MF_ICON_JAVA,
180 static char *thumbnail_array[FILE_TYPE_MAX] = {
181 [FILE_TYPE_DIR] = MF_ICON_THUMBNAIL_FOLDER,
182 [FILE_TYPE_IMAGE] = MF_ICON_IMAGE,
183 [FILE_TYPE_VIDEO] = MF_ICON_THUMBNAIL_VIDEO,
184 [FILE_TYPE_MUSIC] = MF_ICON_THUMBNAIL_MUSIC,
185 [FILE_TYPE_SOUND] = MF_ICON_THUMBNAIL_RINGTONE,
186 [FILE_TYPE_PDF] = MF_ICON_THUMBNAIL_PDF,
187 [FILE_TYPE_DOC] = MF_ICON_THUMBNAIL_DOC,
188 [FILE_TYPE_PPT] = MF_ICON_THUMBNAIL_PPT,
189 [FILE_TYPE_EXCEL] = MF_ICON_THUMBNAIL_EXCEL,
190 [FILE_TYPE_VOICE] = MF_ICON_VOICE,
191 [FILE_TYPE_HTML] = MF_ICON_THUMBNAIL_HTML,
192 [FILE_TYPE_FLASH] = MF_ICON_THUMBNAIL_FLASH,
193 [FILE_TYPE_TXT] = MF_ICON_THUMBNAIL_TXT,
194 [FILE_TYPE_VCONTACT] = MF_ICON_VCONTACT,
195 [FILE_TYPE_VCALENDAR] = MF_ICON_VCALENDAR,
196 [FILE_TYPE_VNOTE] = MF_ICON_VNOTE,
197 [FILE_TYPE_RSS] = MF_ICON_THUMBNAIL_RSS,
198 [FILE_TYPE_JAVA] = MF_ICON_JAVA,
201 /*********************
202 **Function name: __mf_file_attr_get_category_by_file_ext
203 **Parameter: const char* file_ext
204 **Return value: fsFileType
207 ** Get file category by extention
209 *********************/
210 static fsFileType __mf_file_attr_get_category_by_file_ext(const char *file_ext, const char *fullpath)
214 if (file_ext == NULL) {
215 return FILE_TYPE_ETC;
218 if (file_ext[0] == '.') {
222 switch (file_ext[i]) {
225 if (strcasecmp("ASF", &file_ext[i]) == 0) {
226 return FILE_TYPE_VIDEO;
228 if (strcasecmp("AMR", &file_ext[i]) == 0) {
229 return FILE_TYPE_VOICE;
231 if (strcasecmp("AWB", &file_ext[i]) == 0) {
232 return FILE_TYPE_VOICE;
234 if (strcasecmp("AAC", &file_ext[i]) == 0) {
235 return FILE_TYPE_MUSIC;
237 if (strcasecmp("AVI", &file_ext[i]) == 0) {
238 return FILE_TYPE_VIDEO;
240 if (strcasecmp("AAC", &file_ext[i]) == 0) {
241 return FILE_TYPE_MUSIC;
247 if (strcasecmp("BMP", &file_ext[i]) == 0) {
248 return FILE_TYPE_IMAGE;
253 if (strcasecmp("DOC", &file_ext[i]) == 0) {
254 return FILE_TYPE_DOC;
256 if (strcasecmp("DOCX", &file_ext[i]) == 0) {
257 return FILE_TYPE_DOC;
259 if (strcasecmp("DIVX", &file_ext[i]) == 0) {
260 if (mf_drm_is_drm_file(fullpath) == 0) {
261 return FILE_TYPE_DRM;
263 return FILE_TYPE_VIDEO;
266 if (strcasecmp("DCF", &file_ext[i]) == 0) {
267 return FILE_TYPE_DRM;
272 if (strcasecmp("GIF", &file_ext[i]) == 0) {
273 return FILE_TYPE_IMAGE;
275 if (strcasecmp("G72", &file_ext[i]) == 0) {
276 return FILE_TYPE_MUSIC;
281 if (strcasecmp("H263", &file_ext[i]) == 0) {
282 return FILE_TYPE_MUSIC;
284 if (strcasecmp("HTML", &file_ext[i]) == 0) {
285 return FILE_TYPE_HTML;
287 if (strcasecmp("HTM", &file_ext[i]) == 0) {
288 return FILE_TYPE_HTML;
293 if (strcasecmp("IMY", &file_ext[i]) == 0) {
294 return FILE_TYPE_SOUND;
296 if (strcasecmp("IPK", &file_ext[i]) == 0) {
297 return FILE_TYPE_APP;
302 if (strcasecmp("JAD", &file_ext[i]) == 0) {
303 return FILE_TYPE_JAVA;
305 if (strcasecmp("JAR", &file_ext[i]) == 0) {
306 return FILE_TYPE_JAVA;
309 if (strcasecmp("JPG", &file_ext[i]) == 0) {
310 return FILE_TYPE_IMAGE;
312 if (strcasecmp("JPEG", &file_ext[i]) == 0) {
313 return FILE_TYPE_IMAGE;
315 if (strcasecmp("JPE", &file_ext[i]) == 0) {
316 return FILE_TYPE_IMAGE;
321 if (strcasecmp("MMF", &file_ext[i]) == 0) {
322 return FILE_TYPE_SOUND;
324 if (strcasecmp("MP3", &file_ext[i]) == 0) {
325 return FILE_TYPE_MUSIC;
327 if (strcasecmp("MID", &file_ext[i]) == 0) {
328 return FILE_TYPE_SOUND;
330 if (strcasecmp("MIDI", &file_ext[i]) == 0) {
331 return FILE_TYPE_SOUND;
333 if (strcasecmp("MP4", &file_ext[i]) == 0) {
334 return FILE_TYPE_VIDEO;
336 if (strcasecmp("MPG", &file_ext[i]) == 0) {
337 return FILE_TYPE_VIDEO;
339 if (strcasecmp("MPEG", &file_ext[i]) == 0) {
340 return FILE_TYPE_VIDEO;
342 if (strcasecmp("M4A", &file_ext[i]) == 0) {
343 return FILE_TYPE_MUSIC;
345 if (strcasecmp("M3G", &file_ext[i]) == 0) {
346 return FILE_TYPE_FLASH;
348 if (strcasecmp("MXMF", &file_ext[i]) == 0) {
349 return FILE_TYPE_SOUND;
351 if (strcasecmp("MKV", &file_ext[i]) == 0) {
352 return FILE_TYPE_VIDEO;
354 if (strcasecmp("MKA", &file_ext[i]) == 0) {
355 return FILE_TYPE_MUSIC;
360 if (strcasecmp("opml", &file_ext[i]) == 0) {
361 return FILE_TYPE_RSS;
366 if (strcasecmp("PNG", &file_ext[i]) == 0) {
367 return FILE_TYPE_IMAGE;
369 if (strcasecmp("PJPEG", &file_ext[i]) == 0) {
370 return FILE_TYPE_IMAGE;
372 if (strcasecmp("PDF", &file_ext[i]) == 0) {
373 return FILE_TYPE_PDF;
375 if (strcasecmp("PPT", &file_ext[i]) == 0) {
376 return FILE_TYPE_PPT;
378 if (strcasecmp("PPTX", &file_ext[i]) == 0) {
379 return FILE_TYPE_PPT;
381 if (strcasecmp("PEM", &file_ext[i]) == 0) {
382 return FILE_TYPE_CERTIFICATION;
390 if (strcasecmp("SDP", &file_ext[i]) == 0) {
391 return FILE_TYPE_VIDEO;
393 if (strcasecmp("SPM", &file_ext[i]) == 0) {
394 return FILE_TYPE_SOUND;
396 if (strcasecmp("SMP", &file_ext[i]) == 0) {
397 return FILE_TYPE_SOUND;
399 if (strcasecmp("SPF", &file_ext[i]) == 0) {
400 return FILE_TYPE_SOUND;
402 if (strcasecmp("SWF", &file_ext[i]) == 0) {
403 return FILE_TYPE_FLASH;
405 if (strcasecmp("SCN", &file_ext[i]) == 0) {
406 return FILE_TYPE_MOVIE_MAKER;
408 if (strcasecmp("SVG", &file_ext[i]) == 0) {
409 return FILE_TYPE_SVG;
411 if (strcasecmp("SVGZ", &file_ext[i]) == 0) {
412 return FILE_TYPE_SVG;
417 if (strcasecmp("TXT", &file_ext[i]) == 0) {
418 return FILE_TYPE_TXT;
420 if (strcasecmp("THM", &file_ext[i]) == 0) {
421 return FILE_TYPE_THEME;
426 if (strcasecmp("VCF", &file_ext[i]) == 0) {
427 return FILE_TYPE_VCONTACT;
429 if (strcasecmp("VCS", &file_ext[i]) == 0) {
430 return FILE_TYPE_VCALENDAR;
432 if (strcasecmp("VNT", &file_ext[i]) == 0) {
433 return FILE_TYPE_VNOTE;
435 if (strcasecmp("VBM", &file_ext[i]) == 0) {
436 return FILE_TYPE_VBOOKMARK;
441 if (strcasecmp("WAV", &file_ext[i]) == 0) {
442 return FILE_TYPE_SOUND;
444 if (strcasecmp("WBMP", &file_ext[i]) == 0) {
445 return FILE_TYPE_IMAGE;
447 if (strcasecmp("WGT", &file_ext[i]) == 0) {
448 return FILE_TYPE_WGT;
450 if (strcasecmp("WMA", &file_ext[i]) == 0) {
451 return FILE_TYPE_MUSIC;
453 if (strcasecmp("WMV", &file_ext[i]) == 0) {
454 return FILE_TYPE_VIDEO;
459 if (strcasecmp("XLS", &file_ext[i]) == 0) {
460 return FILE_TYPE_EXCEL;
462 if (strcasecmp("XLSX", &file_ext[i]) == 0) {
463 return FILE_TYPE_EXCEL;
465 if (strcasecmp("XMF", &file_ext[i]) == 0) {
466 return FILE_TYPE_SOUND;
468 if (strcasecmp("XHTML", &file_ext[i]) == 0) {
469 return FILE_TYPE_HTML;
473 if (strcasecmp("3GP", &file_ext[i]) == 0) {
474 return FILE_TYPE_VIDEO;
476 if (strcasecmp("3GPP", &file_ext[i]) == 0) {
477 return FILE_TYPE_VIDEO;
479 if (strcasecmp("3G2", &file_ext[i]) == 0) {
480 return FILE_TYPE_VIDEO;
485 return FILE_TYPE_ETC;
488 /*********************
489 **Function name: mf_get_category
491 ** const char* filepath: file fullpath
492 ** fsFileType *category: output parameter of category
497 ** Get file category by file full path
499 *********************/
500 int mf_file_attr_get_file_category(const char *filepath, fsFileType * category)
505 if (mf_file_attr_is_dir(filepath)) {
506 *category = FILE_TYPE_DIR;
507 return MYFILE_ERR_NONE;
510 const char *filename = NULL;
511 filename = ecore_file_file_get(filepath);
512 if (filename == NULL) {
513 *category = FILE_TYPE_NONE;
514 return MYFILE_ERR_SRC_ARG_INVALID;
516 char *file_ext = NULL;
517 /*ToDo: error file name like the last letter is "." */
518 for (i = strlen(filename); i >= 0; i--) {
519 if (filename[i] == '.') {
520 file_ext = g_strdup(&filename[i + 1]);
525 if (filename[i] == '/') {
532 *category = __mf_file_attr_get_category_by_file_ext(file_ext, filepath);
533 SAFE_FREE_CHAR(file_ext);
534 return MYFILE_ERR_NONE;
536 *category = FILE_TYPE_NONE;
537 SAFE_FREE_CHAR(file_ext);
538 return MYFILE_ERR_GET_CATEGORY_FAIL;
542 /*********************
543 **Function name: mf_file_attr_get_file_stat
545 ** const char* filename: file name
546 ** fsNodeInfo **node: output parameter of what we need to refine
551 ** Get file size and last modified date by file path
553 *********************/
554 int mf_file_attr_get_file_stat(const char *filename, fsNodeInfo **node)
558 mf_retvm_if(filename == NULL, MYFILE_ERR_INVALID_ARG, "filename is null");
559 mf_retvm_if(node == NULL, MYFILE_ERR_INVALID_ARG, "node is null");
561 if (stat(filename, &statbuf) == -1) {
562 return MYFILE_ERR_GET_STAT_FAIL;
564 time_t tempdate = statbuf.st_mtime;
565 (*node)->size = statbuf.st_size;
566 (*node)->date = (UDate) tempdate * MF_UDATE_NUM;
568 return MYFILE_ERR_NONE;
571 /*********************
572 **Function name: mf_file_attr_is_dir
574 ** const char* filename: file fullpath
576 ** if path is a directory, return 1
580 ** check if the file path is Directory
582 *********************/
583 int mf_file_attr_is_dir(const char *filepath)
585 return ecore_file_is_dir(filepath);
588 /*********************
589 **Function name: mf_file_attr_get_store_type_by_full
591 ** const char* filepath: file full path
592 ** MF_STORAGE *store_type: output parameter of storage type
597 ** Get file storage type by file path
599 *********************/
600 int mf_file_attr_get_store_type_by_full(const char *filepath, MF_STORAGE * store_type)
602 if (filepath == NULL || store_type == NULL) {
603 return MYFILE_ERR_SRC_ARG_INVALID;
606 if (strncmp(filepath, PHONE_FOLDER, strlen(PHONE_FOLDER)) == 0) {
607 *store_type = MYFILE_PHONE;
608 return MYFILE_ERR_NONE;
609 } else if (strncmp(filepath, MEMORY_FOLDER, strlen(MEMORY_FOLDER)) == 0) {
610 *store_type = MYFILE_MMC;
611 return MYFILE_ERR_NONE;
613 *store_type = MYFILE_NONE;
614 return MYFILE_ERR_STORAGE_TYPE_ERROR;
619 /*********************
620 **Function name: mf_file_attr_get_file_ext
622 ** const char* filepath: file full path
623 ** char *file_ext: output parameter of file extension
629 ** get file extension by file full path
631 *********************/
632 int mf_file_attr_get_file_ext(const char *filepath, char **file_ext)
636 const char *filename = NULL;
637 filename = ecore_file_file_get(filepath);
639 if (filename == NULL) {
640 return MYFILE_ERR_INVALID_FILE_NAME;
643 char *pdot = strrchr(filename, '.');
646 return MYFILE_ERR_EXT_GET_ERROR;
647 } else if (pdot != filepath) {
648 *file_ext = g_strdup(pdot + 1);
649 return MYFILE_ERR_NONE;
651 return MYFILE_ERR_EXT_GET_ERROR;
655 /*********************
656 **Function name: mf_file_attr_is_duplicated_name
658 ** const char* dir: dir which we need to check
659 ** const char *name: the file/dir name we need to check
662 ** -23 if the name is already existed
663 ** 0 if the name is not existed
666 ** check if the name is existed in the specified dir
668 *********************/
669 int mf_file_attr_is_duplicated_name(const char *dir, const char *name)
672 char *file_path = g_strconcat(dir, "/", name, NULL);
673 if (ecore_file_exists(file_path)) {
674 SAFE_FREE_CHAR(file_path);
675 return MYFILE_ERR_DUPLICATED_NAME;
677 SAFE_FREE_CHAR(file_path);
678 return MYFILE_ERR_NONE;
682 /*********************
683 **Function name: mf_file_attr_is_valid_name
685 ** const char *filename: the file/dir name we need to check
688 ** -0x14 if the name is invalid
689 ** 0 if the name is valid
692 ** check if the name is valid by file name
694 *********************/
695 int mf_file_attr_is_valid_name(const char *filename)
698 int ret, z, cflags = 0;
702 const size_t nmatch = 1;
703 /*ToDo: ignore the file star with . */
704 if (strncmp(filename, ".", 1) == 0) {
705 return MYFILE_ERR_INVALID_FILE_NAME;
708 pattern = MYFILE_NAME_PATTERN;
709 z = regcomp(®, pattern, cflags);
712 regerror(z, ®, ebuf, sizeof(ebuf));
713 fprintf(stderr, "%s: pattern '%s' \n", ebuf, pattern);
714 return MYFILE_ERR_INVALID_FILE_NAME;
717 z = regexec(®, filename, nmatch, pm, 0);
718 if (z == REG_NOMATCH) {
719 ret = MYFILE_ERR_NONE;
721 ret = MYFILE_ERR_INVALID_FILE_NAME;
727 /*********************
728 **Function name: mf_file_attr_is_right_dir_path
730 ** const char *filename: the file/dir name we need to check
736 ** check if the dir path is correct
738 *********************/
739 int mf_file_attr_is_right_dir_path(const char *dir_path)
741 int result = MYFILE_ERR_NONE;
744 length = strlen(dir_path);
746 return MYFILE_ERR_INVALID_DIR_PATH;
749 if (dir_path[length - 1] == '/' && length > 1) {
750 return MYFILE_ERR_INVALID_DIR_PATH;
753 if (dir_path[0] != '/') {
754 return MYFILE_ERR_INVALID_DIR_PATH;
757 const char *file_name = NULL;
758 file_name = ecore_file_file_get(dir_path);
759 result = mf_file_attr_is_valid_name(file_name);
761 if (result != MYFILE_ERR_NONE) {
762 mf_error("Is NOT Valid dir path name");
768 /*********************
769 **Function name: mf_file_attr_is_right_file_path
771 ** const char *filename: the file/dir name we need to check
777 ** check if the file path is correct
779 *********************/
780 int mf_file_attr_is_right_file_path(const char *file_path)
782 int result = MYFILE_ERR_NONE;
784 if (strlen(file_path) == 0) {
785 return MYFILE_ERR_INVALID_FILE_PATH;
788 if (file_path[0] != '/') {
789 return MYFILE_ERR_INVALID_DIR_PATH;
792 const char *file_name = NULL;
793 file_name = ecore_file_file_get(file_path);
794 result = mf_file_attr_is_valid_name(file_name);
795 if (result != MYFILE_ERR_NONE) {
796 mf_error("Is NOT Valid dir path name");
802 /*********************
803 **Function name: mf_file_attr_is_right_dir_path
805 ** const char *filename: the file/dir name we need to check
811 ** check if the dir path is correct
813 *********************/
814 int mf_file_attr_get_parent_path(const char *path, char **parent_path)
818 mf_debug("Path :::: [%s]", path);
820 *parent_path = g_strdup(path);
821 if (*parent_path == NULL)
822 return MYFILE_ERR_ALLOCATE_MEMORY_FAIL;
824 const char *name = NULL;
825 name = ecore_file_file_get(path);
827 ** input path and parent_path are check in the caller.
828 ** parent_path is full path must be like /opt/media/file.ext
830 ** strlen(parent_path) should large than strlen(name) normally.
831 ** to take exception like input path is "", we add a if condition
833 if (strlen(*parent_path) > strlen(name))
834 (*parent_path)[strlen(*parent_path) - strlen(name) - 1] = '\0';
836 if (strlen(*parent_path) == 0) {
837 *parent_path = g_strdup("/");
840 return MYFILE_ERR_NONE;
843 /*********************
844 **Function name: mf_file_attr_get_logical_path_by_full
846 ** const char *full_path: the full path
847 ** char* path: logic path of output parameter
853 ** get logic path by full path
855 *********************/
856 int mf_file_attr_get_logical_path_by_full(const char *full_path, char **path)
860 MF_STORAGE store_type = 0;
864 error_code = mf_file_attr_get_store_type_by_full(full_path, &store_type);
866 *path = g_strdup(full_path);
868 return MYFILE_ERR_ALLOCATE_MEMORY_FAIL;
871 memset(*path, 0, strlen(*path));
872 switch (store_type) {
874 root_len = strlen(PHONE_FOLDER);
877 root_len = strlen(MEMORY_FOLDER);
880 return MYFILE_ERR_STORAGE_TYPE_ERROR;
884 ** *path has the same length with full_path
885 ** strlen(*path) is 0 since the memset called
886 ** we use length of full_path to reprecent the *path's
888 g_strlcpy(*path, full_path + root_len, strlen(full_path));
889 if (strlen(*path) == 0) {
890 SAFE_FREE_CHAR(*path);
891 *path = g_strdup("/");
894 return MYFILE_ERR_NONE;
898 typedef struct __mf_transfer_data_s mf_transfer_data_s;
900 struct __mf_transfer_data_s {
901 const char *file_path;
902 char *thumbnail_path;
906 static bool __mf_local_data_get_media_thumbnail_cb(media_info_h media, void *data)
908 mf_retvm_if(data == NULL, -1, "filter is NULL");
909 mf_transfer_data_s *tmp_data = (mf_transfer_data_s *)data;
912 media_info_clone(tmp_data->media, media);
913 media_info_get_thumbnail_path(media, &(tmp_data->thumbnail_path));
918 int mf_file_attr_get_file_icon(const char *file_path, int *error_code, int view_type, const char **thumbnail, media_info_h *media_info)
921 const char *icon_path = DEFAULT_ICON;
922 fsFileType ftype = FILE_TYPE_NONE;
923 const char *mime = NULL;
924 int thumbnail_type = MF_THUMBNAIL_TYPE_DEFAULT;
925 mf_retvm_if(file_path == NULL, thumbnail_type, "file_path is NULL");
927 mime = efreet_mime_type_get(file_path);
929 mf_warnig("Fail to efreet_mime_type_get(), set etc icon");
931 return thumbnail_type;
934 for (index = 0; mime_type[index].mime; index++) {
935 if (strncmp(mime, mime_type[index].mime, strlen(mime)) == 0) {
936 ftype = mime_type[index].ftype;
941 if (view_type == 0) {
942 icon_path = mf_file_attr_get_default_icon_by_type(ftype);
943 thumbnail_type = MF_THUMBNAIL_TYPE_DEFAULT;
945 icon_path = mf_file_attr_get_default_thumbnail_by_type(ftype);
946 thumbnail_type = MF_THUMBNAIL_TYPE_DEFAULT;
950 case FILE_TYPE_IMAGE:
951 case FILE_TYPE_VIDEO:
955 mf_transfer_data_s tmp_data;
956 memset(&tmp_data,0x00,sizeof(mf_transfer_data_s));
957 tmp_data.file_path = file_path;
958 tmp_data.media = media_info;
959 //err = mf_file_attr_get_thumbnail(&tmp_data);
960 char *condition = NULL;
961 condition = g_strdup_printf("%s and MEDIA_PATH=\"%s\"", MF_CONDITION_IMAGE_VIDEO, tmp_data.file_path);
962 err = mf_media_content_data_get(&tmp_data, condition, __mf_local_data_get_media_thumbnail_cb);
964 icon_path = g_strdup(tmp_data.thumbnail_path);
965 thumbnail_type = MF_THUMBNAIL_TYPE_THUMBNAIL;
971 SAFE_FREE_CHAR(tmp_data.thumbnail_path);
978 *thumbnail = icon_path;
979 return thumbnail_type;
982 fsFileType mf_file_attr_get_file_type(const char *mime)
985 fsFileType ftype = FILE_TYPE_NONE;
986 for (index = 0; mime_type[index].mime; index++) {
987 if (strncmp(mime, mime_type[index].mime, strlen(mime)) == 0) {
988 ftype = mime_type[index].ftype;
995 fsFileType mf_file_attr_get_file_type_by_mime(const char *file_path)
998 fsFileType ftype = FILE_TYPE_NONE;
999 const char *mime = NULL;
1001 mime = efreet_mime_type_get(file_path);
1003 mf_warnig("Fail to efreet_mime_type_get(), set etc icon");
1008 for (index = 0; mime_type[index].mime; index++) {
1009 if (strncmp(mime, mime_type[index].mime, strlen(mime)) == 0) {
1010 ftype = mime_type[index].ftype;
1019 const char *mf_file_attr_get_default_icon_by_type(fsFileType ftype)
1021 const char *icon_path = DEFAULT_ICON;
1023 if (icon_array[ftype]) {
1024 icon_path = icon_array[ftype];
1026 icon_path = DEFAULT_ICON;
1032 const char *mf_file_attr_get_default_thumbnail_by_type(fsFileType ftype)
1035 const char *thumbnail_path = DEFAULT_ICON;
1037 if (thumbnail_array[ftype]) {
1038 thumbnail_path = thumbnail_array[ftype];
1040 thumbnail_path = DEFAULT_ICON;
1043 return thumbnail_path;
1045 /*********************
1046 **Function name: mf_file_attr_get_path_level
1048 ** const char *file_fullpath: the full path
1049 ** int* level: level which the specified path under(this is output parameter)
1055 ** get level of specified path under
1057 *********************/
1058 int mf_file_attr_get_path_level(const char *fullpath, int *level)
1060 if (fullpath == NULL) {
1061 return MYFILE_ERR_SRC_ARG_INVALID;
1064 if (mf_file_attr_is_right_dir_path(fullpath) != 0) {
1065 return MYFILE_ERR_INVALID_PATH;
1068 MF_STORAGE storage_t = 0;
1069 int start_level = 0;
1070 int error_code = mf_file_attr_get_store_type_by_full(fullpath, &storage_t);
1071 if (error_code != 0) {
1075 if (storage_t == MYFILE_PHONE) {
1076 start_level = MF_PHONE_DEFAULT_LEVEL;
1077 } else if (storage_t == MYFILE_MMC) {
1078 start_level = MF_MMC_DEFAULT_LEVEL;
1081 char *temp = strdup(fullpath);
1083 return MYFILE_ERR_UNKNOWN_ERROR;
1087 gchar **result = NULL;
1088 gchar **params = NULL;
1089 result = g_strsplit(temp, "/", 0);
1090 if (result == NULL) {
1093 return MYFILE_ERR_UNKNOWN_ERROR;
1095 for (params = result; *params; params++) {
1096 mf_debug("*params is [%s]", *params);
1101 *level = count - start_level - 1;
1102 mf_debug("cout is [%d] start level is [%d]", count, start_level);
1104 return MYFILE_ERR_NONE;
1108 /*********************
1109 **Function name: mf_file_attr_is_in_system_folder
1111 ** const char *file_fullpath: the full path
1112 ** int* level: level which the specified path under
1113 ** bool* result: output parameter for the result
1119 ** check if the specified path is under system folder
1121 *********************/
1122 int mf_file_attr_is_in_system_folder(char *fullpath, int level, bool * result)
1124 if (fullpath == NULL) {
1125 return MYFILE_ERR_SRC_ARG_INVALID;
1128 MF_STORAGE storage_t = 0;
1129 int error_code = mf_file_attr_get_store_type_by_full(fullpath, &storage_t);
1130 if (error_code != 0) {
1134 const char *name = NULL;
1135 name = ecore_file_file_get(fullpath);
1136 char *parent_path = NULL;
1137 error_code = mf_file_attr_get_parent_path(fullpath, &parent_path);
1139 if (error_code != 0) {
1143 if (storage_t == MYFILE_PHONE || storage_t == MYFILE_MMC) {
1145 if ((strlen(name) == strlen(DEFAULT_FOLDER_CAMERA_SHOTS)) && strcmp(name, DEFAULT_FOLDER_CAMERA_SHOTS) == 0) {
1147 } else if ((strlen(name) == strlen(DEFAULT_FOLDER_IMAGE)) && strcmp(name, DEFAULT_FOLDER_IMAGE) == 0) {
1149 } else if ((strlen(name) == strlen(DEFAULT_FOLDER_VIDEO)) && strcmp(name, DEFAULT_FOLDER_VIDEO) == 0) {
1151 } else if ((strlen(name) == strlen(DEFAULT_FOLDER_MUSIC)) && strcmp(name, DEFAULT_FOLDER_MUSIC) == 0) {
1153 } else if ((strlen(name) == strlen(DEFAULT_FOLDER_DOWNLOADS)) && strcmp(name, DEFAULT_FOLDER_DOWNLOADS) == 0) {
1156 if (storage_t == MYFILE_PHONE) {
1157 if ((strlen(name) == strlen(DEFAULT_FOLDER_ALERTS_AND_RINGTONES)) && strcmp(name, DEFAULT_FOLDER_ALERTS_AND_RINGTONES) == 0) {
1159 } else if ((strlen(name) == strlen(DEFAULT_FOLDER_BOOKMARK)) && strcmp(name, DEFAULT_FOLDER_BOOKMARK) == 0) {
1161 } else if ((strlen(name) == strlen(DEFAULT_FOLDER_RSS)) && strcmp(name, DEFAULT_FOLDER_RSS) == 0) {
1171 } else if (level == 2) {
1172 const char *parent_name = NULL;
1173 parent_name = ecore_file_file_get(parent_path);
1174 if (storage_t == MYFILE_PHONE) {
1175 if (!g_strcmp0(parent_name, DEFAULT_FOLDER_IMAGE) && !g_strcmp0(name, SUB_FODER_WALLPAPER)) {
1177 } else if (!g_strcmp0(parent_name, DEFAULT_FOLDER_ALERTS_AND_RINGTONES)
1178 && (!g_strcmp0(name, SUB_FODER_ALERTS) || !g_strcmp0(name, SUB_FODER_RINGTONES))) {
1180 } else if (!g_strcmp0(parent_name, DEFAULT_FOLDER_MUSIC)
1181 && (!g_strcmp0(name, SUB_FODER_FM) || !g_strcmp0(name, SUB_FODER_VOICE_RECORD))) {
1194 return MYFILE_ERR_STORAGE_TYPE_ERROR;
1204 return MYFILE_ERR_STORAGE_TYPE_ERROR;
1210 return MYFILE_ERR_NONE;
1213 /*********************
1214 **Function name: mf_file_attr_is_system_dir
1216 ** const char *file_fullpath: the full path
1217 ** bool* result: output parameter for the result
1223 ** check if the specified path is system folder
1225 *********************/
1226 int mf_file_attr_is_system_dir(char *fullpath, bool * result)
1228 if (fullpath == NULL) {
1229 mf_error("source argument invalid");
1230 return MYFILE_ERR_SRC_ARG_INVALID;
1233 if (mf_file_attr_is_dir(fullpath) == 0) {
1234 mf_error("source is not exist");
1235 return MYFILE_ERR_SRC_NOT_EXIST;
1241 error_code = mf_file_attr_get_path_level(fullpath, &level);
1242 if (error_code != 0) {
1243 mf_error("Fail to get path level");
1247 if (level >= 3 || level <= 0) {
1249 mf_error("Path Level is wrong");
1250 return MYFILE_ERR_NONE;
1252 error_code = mf_file_attr_is_in_system_folder(fullpath, level, result);
1254 if (error_code != 0) {
1255 mf_error("Fail .. is in system folder err :: %d", error_code);
1259 return MYFILE_ERR_NONE;
1262 #ifdef MYFILE_USB_OTG
1263 int mf_file_attr_is_disk_link(const char *fullpath, bool *result)
1265 if (fullpath == NULL) {
1266 mf_error("source argument invalid");
1267 return MYFILE_ERR_SRC_ARG_INVALID;
1270 if (mf_file_attr_is_dir(fullpath) == 0) {
1271 mf_error("source is not exist");
1272 return MYFILE_ERR_SRC_NOT_EXIST;
1276 char *parent_path = NULL;
1278 error_code = mf_file_attr_get_parent_path(fullpath, &parent_path);
1280 if(error_code == 0){
1281 if(g_strcmp0(parent_path, OTG_FOLDER) == 0)
1286 SAFE_FREE_CHAR(parent_path);
1291 #define MF_ROUND_D(x, dig) (floor((x)*pow(10, dig+1)+0.5)/pow(10, dig+1))
1292 void mf_file_attr_get_file_size_info(char **file_size, fsNodeInfo *pNode)
1295 mf_retm_if(file_size == NULL, "file_size is NULL");
1296 mf_retm_if(pNode == NULL, "pNode is NULL");
1297 unsigned long long original_size = 0;
1302 original_size = pNode->size;
1303 size = (double)original_size;
1305 while (size >= MYFILE_BASIC_SIZE) {
1306 size /= MYFILE_BASIC_SIZE;
1310 if (index == SIZE_BYTE) {
1311 snprintf(NULL, 0, "%llu B%n", original_size, &len);
1313 size = MF_ROUND_D(size, 1);
1314 snprintf(NULL, 0, "%0.1lf XB%n", size, &len);
1322 *file_size = (char *)calloc(len, sizeof(char));
1323 if (*file_size == NULL) {
1328 if (index == SIZE_BYTE) {
1329 snprintf(*file_size, len, "%llu B", original_size);
1331 if (index == SIZE_KB) {
1332 snprintf(*file_size, len, "%0.1lf KB", size);
1333 } else if (index == SIZE_MB) {
1334 snprintf(*file_size, len, "%0.1lf MB", size);
1335 } else if (index == SIZE_GB) {
1336 snprintf(*file_size, len, "%0.1lf GB", size);