cancel bug fix
[apps/home/ug-myfile-efl.git] / src / include / mf-ug-fs-util.h
1 /*
2  * myfile
3  *
4  * Copyright 2012  Samsung Electronics Co., Ltd
5  *
6  * Licensed under the Flora License, Version 1.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.tizenopensource.org/license
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20
21
22 #ifndef __DEF_MF_UG_FS_UTIL_H_
23 #define __DEF_MF_UG_FS_UTIL_H_
24
25 #include <stdio.h>
26 #include <stdbool.h>
27 #include <string.h>
28 #include <stdlib.h>
29 #include <dirent.h>
30 #include <sys/stat.h>
31 #include <unistd.h>
32 #include <sys/types.h>
33 #include <sys/stat.h>
34 #include <linux/fs.h>
35 #include <Eina.h>
36
37 #include <Elementary.h>
38 #include <drm_client.h>
39 #include <drm_client_types.h>
40 #include <media_content.h>
41
42 #include "mf-ug-dlog.h"
43
44
45 /*      File system related value definition    */
46 #define FILE_EXT_LEN_MAX                                8
47 #define MYFILE_DIR_PATH_LEN_MAX         4096
48 #define MYFILE_FILE_NAME_LEN_MAX                255
49 #define MYFILE_FILE_PATH_LEN_MAX                MYFILE_DIR_PATH_LEN_MAX + MYFILE_FILE_NAME_LEN_MAX
50
51
52 /*      File system related String definition   */
53 #define PHONE_FOLDER            "/opt/media"
54 #define MEMORY_FOLDER           "/opt/storage/sdcard"
55 #define SOUNDS_FOLDER           "/opt/media/Sounds"
56 #define DEBUG_FOLDER            "SLP_debug"
57
58 #define MYFILE_NAME_PATTERN     "[\\:;*\"<>|?/]"
59
60 #define IMAGE_AND_VIDEO         "Images and videos"
61 #define SOUND_AND_MUSIC         "Sounds and music"
62 #define DOWNLOADS                       "Downloads"
63 #define CAMERA_SHOTS            "Camera shots"
64
65
66 #define WALLPAPER                       "Wallpapers"
67 #define MY_PHOTO_CLIPS          "My photo clips"
68 #define MY_ALBUM                        "My album"      /*/_("IDS_MF_BODY_ACCESS_MORE_MY_ALBUM") */
69 #define MY_VIDEO_CLIPS          "My video clips"        /*/_("IDS_MF_BODY_MY_VIDEO_CLIPS") */
70
71 #define FM_RADIO                        "FM Radio"      /*/dgettext("sys_string", "IDS_COM_HEADER_FMRADIO") */
72 #define MUSIC                           "Music" /*/_("IDS_MF_BODY_MUSIC") */
73 #define RINGTONES                       "Ringtones"
74 #define VOICE_RECORDER          "Voice recorder"        /*/dgettext("sys_string", "IDS_COM_BODY_VOICE_RECORDER") */
75 #define ALERTS                          "Alerts"
76 #define OTHERS                          "Others"        /*/dgettext("sys_string","IDS_COM_BODY_OTHERS") */
77
78 /*      File system define default folder       */
79
80 /*      compile option  */
81 #define UG_DEBUG_FOLDER_OPTION
82
83 #ifndef UG_ICON_PATH
84 #define UG_ICON_PATH                                            "/opt/ug/res/images/ug-myfile-efl"
85 #endif
86
87 #ifndef UG_DEFAULT_ICON
88 #define UG_DEFAULT_ICON                                                 UG_ICON_PATH"/myfile_icon_etc.png"
89 #endif
90
91 #define UG_ICON_FOLDER                                                  UG_ICON_PATH"/myfile_icon_folder.png"
92 #define UG_ICON_FOLDER_OPEN                                             UG_ICON_PATH"/myfile_icon_folder_open.png"
93
94 #define UG_ICON_IMAGE                                                   UG_ICON_PATH"/myfile_icon_images.png"
95 #define UG_ICON_VIDEO                                                   UG_ICON_PATH"/myfile_icon_video.png"
96 #define UG_ICON_MUSIC                                                   UG_ICON_PATH"/myfile_icon_music.png"
97 #define UG_ICON_SOUND                                                   UG_ICON_PATH"/myfile_icon_music.png"
98 #define UG_ICON_PDF                                                     UG_ICON_PATH"/myfile_icon_pdf.png"
99 #define UG_ICON_DOC                                                     UG_ICON_PATH"/myfile_icon_word.png"
100 #define UG_ICON_PPT                                                     UG_ICON_PATH"/myfile_icon_ppt.png"
101 #define UG_ICON_EXCEL                                                   UG_ICON_PATH"/myfile_icon_excel.png"
102 #define UG_ICON_VOICE                                                   UG_ICON_PATH"/myfile_icon_music.png"
103 #define UG_ICON_HTML                                                    UG_ICON_PATH"/myfile_icon_html.png"
104 #define UG_ICON_FLASH                                                   UG_ICON_PATH"/myfile_icon_swf.png"
105 #define UG_ICON_TXT                                                     UG_ICON_PATH"/myfile_icon_text.png"
106 #define UG_ICON_VCONTACT                                                UG_ICON_PATH"/myfile_icon_svg.png"
107 #define UG_ICON_VCALENDAR                                               UG_ICON_PATH"/myfile_icon_svg.png"
108 #define UG_ICON_VNOTE                                                   UG_ICON_PATH"/myfile_icon_text.png"
109 #define UG_ICON_RSS                                                     UG_ICON_PATH"/myfile_icon_rss.png"
110 #define UG_ICON_JAVA                                                    UG_ICON_PATH"/myfile_icon_java.png"
111 #define UG_ICON_MEMORY_SUB                                              UG_ICON_PATH"/myfile_icon_mmc_sub.png"
112 #define UG_ICON_MUSIC_PLAY                                              UG_ICON_PATH"/myfile_icon_control_play.png"
113 #define UG_ICON_MUSIC_PAUSE                                             UG_ICON_PATH"/myfile_icon_control_pause.png"
114 #define UG_ICON_MUSIC_PLAY_WHITE                                        UG_ICON_PATH"/myfile_icon_play_focus.png"
115 #define UG_ICON_MUSIC_PAUSE_WHITE                                       UG_ICON_PATH"/myfile_icon_pause_focus.png"
116
117 #define UG_ICON_BLACK_THEME_UPPER                                       UG_ICON_PATH"/myfile_icon_upper_folder_black_theme.png"
118 #define UG_ICON_WHITE_THEME_UPPER                                       UG_ICON_PATH"/myfile_icon_upper_folder_white_theme.png"
119
120 #define UG_ICON_PHONE                                                   UG_ICON_PATH"/myfile_icon_phone.png"
121 #define UG_ICON_MEMORY                                                  UG_ICON_PATH"/myfile_icon_mmc.png"
122 #define UG_ICON_VIDEO_PLAY                                              UG_ICON_PATH"/myfile_icon_video_play.png"
123
124 typedef enum _mf_ug_fs_file_type mf_ug_fs_file_type;
125
126 enum _mf_ug_fs_file_type {
127         UG_FILE_TYPE_NONE = 0,
128         UG_FILE_TYPE_DIR,                          /**< Folder category */
129         UG_FILE_TYPE_FILE,                         /**< File category */
130         UG_FILE_TYPE_IMAGE,           /**< Image category */
131         UG_FILE_TYPE_VIDEO,           /**< Video category */
132         UG_FILE_TYPE_MUSIC,           /**< Music category */
133         UG_FILE_TYPE_SOUND,           /**< Sound category */
134         UG_FILE_TYPE_PDF,             /**< Pdf category */
135         UG_FILE_TYPE_DOC,             /**< Word category */
136         UG_FILE_TYPE_PPT,             /**< Powerpoint category */
137         UG_FILE_TYPE_EXCEL,           /**< Excel category */
138         UG_FILE_TYPE_VOICE,           /**< Voice category */
139         UG_FILE_TYPE_HTML,            /**< Html category */
140         UG_FILE_TYPE_FLASH,           /**< Flash category */
141         UG_FILE_TYPE_GAME,            /**< Game category */
142         UG_FILE_TYPE_APP,             /**< Application category */
143         UG_FILE_TYPE_THEME,           /**< Theme category */
144         UG_FILE_TYPE_TXT,             /**< Txt category */
145         UG_FILE_TYPE_VCONTACT,        /**< Vcontact category */
146         UG_FILE_TYPE_VCALENDAR,       /**< Vcalendar category */
147         UG_FILE_TYPE_VNOTE,           /**< Vnote category */
148         UG_FILE_TYPE_VBOOKMARK,       /**< Vbookmark category */
149         UG_FILE_TYPE_VIDEO_PROJECT,   /**< Video editor project category */
150         UG_FILE_TYPE_RADIO_RECORDED,  /**< radio recorded clips category */
151         UG_FILE_TYPE_MOVIE_MAKER,     /**< Movie maker project category */
152         UG_FILE_TYPE_SVG,             /**< Svg category */
153         UG_FILE_TYPE_RSS,             /**< Rss reader file, *.opml */
154         UG_FILE_TYPE_CERTIFICATION,   /**< certification file, *.pem */
155         UG_FILE_TYPE_JAVA,            /**< java file, *.jad, *.jar */
156         UG_FILE_TYPE_WGT,             /**< wrt , *.wgt, *.wgt */
157         UG_FILE_TYPE_DRM,                               /**< drm file , *.dcf */
158         UG_FILE_TYPE_ETC,             /**< Other files category */
159         UG_FILE_TYPE_MAX
160 };
161
162 typedef enum _mf_ug_iter_category_filter_t mf_ug_iter_category_filter_t;
163 enum _mf_ug_iter_category_filter_t {
164         UG_FILTER_CATEGORY_NONE = 0x00000000,                           /**< Default */
165         UG_FILTER_CATEGORY_IMAGE = 0x00000001,                                  /**< Image category */
166         UG_FILTER_CATEGORY_VIDEO = 0x00000002,                                  /**< Video category */
167         UG_FILTER_CATEGORY_SOUND = 0x00000004,                                  /**< Sound category */
168         UG_FILTER_CATEGORY_VOICE = 0x00000008,                                  /**< Voice category */
169         UG_FILTER_CATEGORY_MUSIC = 0x00000010,                                  /**< Music category */
170         UG_FILTER_CATEGORY_HTML = 0x00000020,                           /**< Html category */
171         UG_FILTER_CATEGORY_FLASH = 0x00000040,                                  /**< Flash category */
172         UG_FILTER_CATEGORY_GAME = 0x00000080,                           /**< Game category */
173         UG_FILTER_CATEGORY_APP = 0x00000100,                            /**< Application category */
174         UG_FILTER_CATEGORY_THEME = 0x00000200,                                  /**< Theme category */
175         UG_FILTER_CATEGORY_DOC = 0x00000400,                            /**< Word category */
176         UG_FILTER_CATEGORY_EXCEL = 0x00000800,                                  /**< Excel category */
177         UG_FILTER_CATEGORY_PPT = 0x00001000,                            /**< Powerpoint category */
178         UG_FILTER_CATEGORY_PDF = 0x00002000,                            /**< Pdf category */
179         UG_FILTER_CATEGORY_TXT = 0x00004000,                            /**< Txt category */
180         UG_FILTER_CATEGORY_VCONTACT = 0x00008000,                       /**< Vcontact category */
181         UG_FILTER_CATEGORY_VCALENDAR = 0x00010000,                      /**< Vcalendar category */
182         UG_FILTER_CATEGORY_VNOTE = 0x00020000,                                  /**< Vnote category */
183         UG_FILTER_CATEGORY_VBOOKMARK = 0x00040000,                      /**< Vbookmark category */
184         UG_FILTER_CATEGORY_VIDEO_PROJECT = 0x00080000,          /**< Video editor project category */
185         UG_FILTER_CATEGORY_SVG = 0x00100000,                            /**< SVG category */
186         UG_FILTER_CATEGORY_RSS = 0x00200000,                            /**< RSS category */
187         UG_FILTER_CATEGORY_ETC = 0x00400000,                            /**< Other files category */
188
189 };
190
191 typedef enum _mf_ug_drm_filter mf_ug_drm_filter;
192 enum _mf_ug_drm_filter {
193         MF_UG_FILTER_DRM_NONE = 0x00000000,                             /**< Default */
194         MF_UG_FILTER_DRM_ALL = 0x00000001,
195         MF_UG_FILTER_DRM_WITHOUT_FL = 0x00000002,
196         MF_UG_FILTER_DRM_IMAGE = 0x00000004,
197         MF_UG_FILTER_DRM_RINGTONE = 0x00000008,
198 };
199
200 typedef enum _mf_ug_storage_type mf_ug_storage_type;
201 enum _mf_ug_storage_type {
202         MF_UG_NONE,
203         MF_UG_PHONE,
204         MF_UG_MMC,
205         MF_UG_MAX
206 };
207
208
209
210 typedef enum _mf_ug_drm_file_mime_type mf_ug_drm_file_mime_type;
211 enum _mf_ug_drm_file_mime_type {
212         MF_UG_DRM_UNKNOW_FILE = 0,
213         MF_UG_DRM_IMAGE_FILE,
214         MF_UG_DRM_RINGTONE_FILE,
215         MF_UG_DRM_VIDEO_FILE,
216         MF_UG_DRM_FILE_MAX
217 };
218
219 typedef enum _mf_ug_sort_option mf_ug_sort_option;
220
221 enum _mf_ug_sort_option {
222         MF_UG_SORT_BY_NONE = 0,          /**< Sort by default */
223         MF_UG_SORT_BY_NAME_A2Z,          /**< Sort by file name ascending */
224         MF_UG_SORT_BY_SIZE_S2L,          /**< Sort by file size ascending */
225         MF_UG_SORT_BY_DATE_O2R,          /**< Sort by file date ascending */
226         MF_UG_SORT_BY_TYPE_A2Z,                          /**< Sort by file type ascending */
227         MF_UG_SORT_BY_NAME_Z2A,          /**< Sort by file name descending */
228         MF_UG_SORT_BY_SIZE_L2S,          /**< Sort by file size descending */
229         MF_UG_SORT_BY_DATE_R2O,          /**< Sort by file date descending */
230         MF_UG_SORT_BY_TYPE_Z2A,                          /**< Sort by file type descending */
231         MF_UG_SORT_BY_MAX
232 } ;
233
234 typedef enum __MF_UG_SORT_BY_PRIORITY_SEQUENCE MF_UG_SORT_BY_PRIORITY_SEQUENCE;
235 enum __MF_UG_SORT_BY_PRIORITY_SEQUENCE {
236         MF_UG_SORT_BY_PRIORITY_TYPE_A2Z,
237         MF_UG_SORT_BY_PRIORITY_TYPE_Z2A,
238         MF_UG_SORT_BY_PRIORITY_DATE_O2R,
239         MF_UG_SORT_BY_PRIORITY_DATE_R2O,
240         MF_UG_SORT_BY_PRIORITY_SIZE_S2L,
241         MF_UG_SORT_BY_PRIORITY_SIZE_L2S,
242 };
243
244 /*      File operation error check options definition           */
245 #define MF_ERROR_CHECK_SRC_ARG_VALID            0x0001
246 #define MF_ERROR_CHECK_SRC_EXIST                        0x0002
247 #define MF_ERROR_CHECK_SRC_PATH_VALID           0x0004
248 #define MF_ERROR_CHECK_DUPLICATED               0x0008
249
250 /*      File system error definition    */
251 #define MF_ERROR_MASKL16       0xFFFF
252
253 #define MF_ERROR_SET(X)        (X & MF_ERROR_MASKL16)
254
255 #define MID_CONTENTS_MGR_ERROR  0
256
257 #define MYFILE_ERR_NONE   (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x00))    /**< No error */
258
259 /*/1-10*/
260 #define MYFILE_ERR_SRC_ARG_INVALID                      (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x01))      /**< invalid src argument */
261 #define MYFILE_ERR_DST_ARG_INVALID                      (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x02))      /**< invalid dst argument */
262 #define MYFILE_ERR_DIR_OPEN_FAIL                        (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x03))      /**< exception of dir open*/
263 #define MYFILE_ERR_INVALID_DIR_PATH                     (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x04))      /**< exception of invalid dir path */
264 #define MYFILE_ERR_INVALID_FILE_NAME                    (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x05))      /**< exception of invalid file name */
265 #define MYFILE_ERR_INVALID_FILE_PATH                    (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x06))      /**< exception of invalid file path */
266 #define MYFILE_ERR_DRM_PERMISSION_DENY                  (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x07))          /**< can't copy/move drm file because of permission */
267 #define MYFILE_ERR_SRC_NOT_EXIST                        (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x08))          /**< source not found */
268 #define MYFILE_ERR_STORAGE_TYPE_ERROR                   (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x09))          /**< storage type error */
269 #define MYFILE_ERR_EXT_GET_ERROR                        (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x0a))          /**< get ext type failed */
270 #define MYFILE_ERR_GET_STAT_FAIL                        (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x0b))          /**< get stat failed */
271 #define MYFILE_ERR_GET_CATEGORY_FAIL                    (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x0c))          /**< get file category failed */
272 #define MYFILE_ERR_GET_VCONF_FAIL                       (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x0d))          /**< get vconf value failed */
273 #define MYFILE_ERR_INVALID_ARG                          (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x0e))          /**< argument of function is not valid */
274 #define MYFILE_ERR_ALLOCATE_FAIL                        (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x0f))
275 #define MYFILE_ERR_LIST_PLAY_FAIL                       (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x10))
276 #define MYFILE_ERR_INVALID_PATH                         (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x11))      /**< invalid path string */
277 #define MYFILE_ERR_GET_THUMBNAIL_FAILED                 (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x12))           /**<get thumbnail failed */
278 #define MYFILE_ERR_UNKNOW_ERROR                         (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x13))           /**<unknow error */
279 #define MYFILE_ERR_NO_FREE_SPACE                        (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x14))          /**< get free space failed */
280 #define MYFILE_ERR_DUPLICATED_NAME                      (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x15))    /**< exception of duplicated dir name*/
281 #define MYFILE_ERR_ALLOCATE_MEMORY_FAIL                 (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x16))   /**< exception of memory allocation */
282 #define MYFILE_ERR_GET_LOGIC_PATH_FAIL                  (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x17))   /**< get logical path failed */
283 #define MYFILE_ERR_GENERATE_NAME_FAIL                   (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x18))   /**< generate name failed */
284 #define MYFILE_ERR_DIR_CREATE_FAIL                      (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x19))   /**< exception of create dir */
285 #define MYFILE_ERR_GET_PARENT_PATH_FAIL                 (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x1a))   /**< get parent path failed */
286
287 /*      File system related callback definition */
288
289 typedef struct _ugFsNodeInfo ugFsNodeInfo;
290 struct _ugFsNodeInfo {
291         char path[MYFILE_DIR_PATH_LEN_MAX];
292         char name[MYFILE_FILE_NAME_LEN_MAX];
293         time_t date;
294         mf_ug_fs_file_type type;
295         char *ext;
296         unsigned int size;
297 };
298
299
300 /**********                     File Attribute Related                  **********/
301 int mf_ug_file_attr_get_file_stat(const char *filename, ugFsNodeInfo ** node);
302
303 int mf_ug_file_attr_get_file_category(const char *filepath, mf_ug_fs_file_type * category);
304 int mf_ug_file_attr_is_dir(const char *filepath);
305 int mf_ug_file_attr_get_store_type_by_full(const char *filepath, mf_ug_storage_type * store_type);
306 int mf_ug_file_attr_is_drm_file(const char *file_fullpath);
307 int mf_ug_file_attr_get_file_ext(const char *filepath, char **file_ext);
308 int mf_ug_file_attr_is_right_dir_path(const char *dir_path);
309 int mf_ug_file_attr_is_right_file_path(const char *file_path);
310 int mf_ug_file_attr_is_duplicated_name(const char *dir, const char *name);
311 int mf_ug_file_attr_get_logical_path_by_full(const char *full_path, char **path);
312 int mf_ug_file_attr_is_valid_name(const char *filename);
313
314 /**********                     File Operation Related                  **********/
315 int mf_ug_fs_oper_read_dir(const char *path, Eina_List **dir_list, Eina_List **file_list);
316 int mf_ug_fs_oper_list_filter(Eina_List *in_list, Eina_List **out_list, int option, int drm_opt);
317 int mf_ug_fs_oper_list_filter_by_extension(Eina_List *in_list, Eina_List **out_list, char *ext);
318 int mf_ug_file_attr_get_file_icon(const char *file_path, int *error_code, char **thumbnail);
319 mf_ug_drm_file_mime_type mf_ug_fs_oper_get_drm_type(char *path);
320 int mf_ug_file_attr_is_system_dir(char *fullpath, bool * result);
321 mf_ug_fs_file_type mf_ug_file_attr_get_file_type_by_mime(const char *file_path);
322 int mf_ug_fs_oper_create_dir(const char *dir);
323 void mf_ug_fs_oper_sort_list(Eina_List **list, int sort_opt);
324
325 #endif