Initialize Tizen 2.3
[apps/home/ug-myfile-efl.git] / src / include / mf-ug-fs-util.h
1 /*
2  * Copyright 2012          Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.1 (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
7  *
8  *  http://floralicense.org/license/
9  *
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.
15  */
16
17 #ifndef __DEF_MF_UG_FS_UTIL_H_
18 #define __DEF_MF_UG_FS_UTIL_H_
19
20 #include <stdio.h>
21 #include <stdbool.h>
22 #include <string.h>
23 #include <stdlib.h>
24 #include <dirent.h>
25 #include <sys/stat.h>
26 #include <unistd.h>
27 #include <sys/types.h>
28 #include <sys/stat.h>
29 #include <linux/fs.h>
30 #include <Eina.h>
31
32 #include <Elementary.h>
33 #include <drm_client.h>
34 #include <drm_client_types.h>
35 #include <media_content.h>
36
37 #include "mf-ug-dlog.h"
38
39
40 /*  File system related value definition    */
41 #define FILE_EXT_LEN_MAX                8
42 #define MYFILE_DIR_PATH_LEN_MAX     4096
43 #define MYFILE_FILE_NAME_LEN_MAX        255
44 #define MYFILE_FILE_PATH_LEN_MAX        MYFILE_DIR_PATH_LEN_MAX + MYFILE_FILE_NAME_LEN_MAX
45
46
47 /*  File system related String definition   */
48 #define PHONE_FOLDER        "/opt/usr/media"
49 #define MEMORY_FOLDER       "/opt/storage/sdcard"
50 #define PHONE_PARENT        "/opt/usr"
51 #define PHONE_NAME      "media"
52 #define STORAGE_PARENT      "/opt/storage"
53 #define MMC_NAME        "sdcard"
54
55 #define SOUNDS_FOLDER       "/opt/usr/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                        "/usr/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_WHITE                    UG_ICON_PATH"/myfile_icon_control_play.png"
113 #define UG_ICON_MUSIC_PAUSE_WHITE                   UG_ICON_PATH"/myfile_icon_control_pause.png"
114 #define UG_ICON_MUSIC_PLAY_WHITE_PRESS                  UG_ICON_PATH"/myfile_icon_control_play_press.png"
115 #define UG_ICON_MUSIC_PAUSE_WHITE_PRESS                 UG_ICON_PATH"/myfile_icon_control_pause_press.png"
116 #define UG_ICON_ENTRY_FOLDER                        UG_ICON_PATH"/myfile_icon_entry_folder.png"
117 #define UG_ICON_ENTRY_FOLDER_PRESS                  UG_ICON_PATH"/myfile_icon_entry_folder_press.png"
118
119 #define UG_ICON_BLACK_THEME_UPPER                   UG_ICON_PATH"/myfile_icon_upper_folder_black_theme.png"
120 #define UG_ICON_WHITE_THEME_UPPER                   UG_ICON_PATH"/myfile_icon_upper_folder_white_theme.png"
121
122 #define UG_ICON_PHONE                           UG_ICON_PATH"/myfile_icon_phone.png"
123 #define UG_ICON_MEMORY                          UG_ICON_PATH"/myfile_icon_mmc.png"
124 #define UG_ICON_VIDEO_PLAY                      UG_ICON_PATH"/myfile_icon_video_play.png"
125
126 #define UG_ICON_ITEM_PHONE                      UG_ICON_PATH"/U01_1st_icon_phone.png"
127 #define UG_ICON_ITEM_MMC                        UG_ICON_PATH"/U01_1st_icon_memory_card.png"
128 typedef enum _mf_ug_fs_file_type mf_ug_fs_file_type;
129
130 enum _mf_ug_fs_file_type {
131     UG_FILE_TYPE_NONE = 0,
132     UG_FILE_TYPE_DIR,              /**< Folder category */
133     UG_FILE_TYPE_FILE,             /**< File category */
134     UG_FILE_TYPE_IMAGE,       /**< Image category */
135     UG_FILE_TYPE_VIDEO,       /**< Video category */
136     UG_FILE_TYPE_MUSIC,       /**< Music category */
137     UG_FILE_TYPE_SOUND,       /**< Sound category */
138     UG_FILE_TYPE_PDF,         /**< Pdf category */
139     UG_FILE_TYPE_DOC,         /**< Word category */
140     UG_FILE_TYPE_PPT,         /**< Powerpoint category */
141     UG_FILE_TYPE_EXCEL,       /**< Excel category */
142     UG_FILE_TYPE_VOICE,       /**< Voice category */
143     UG_FILE_TYPE_HTML,        /**< Html category */
144     UG_FILE_TYPE_FLASH,       /**< Flash category */
145     UG_FILE_TYPE_GAME,        /**< Game category */
146     UG_FILE_TYPE_APP,         /**< Application category */
147     UG_FILE_TYPE_THEME,       /**< Theme category */
148     UG_FILE_TYPE_TXT,         /**< Txt category */
149     UG_FILE_TYPE_VCONTACT,        /**< Vcontact category */
150     UG_FILE_TYPE_VCALENDAR,       /**< Vcalendar category */
151     UG_FILE_TYPE_VNOTE,       /**< Vnote category */
152     UG_FILE_TYPE_VBOOKMARK,       /**< Vbookmark category */
153     UG_FILE_TYPE_VIDEO_PROJECT,   /**< Video editor project category */
154     UG_FILE_TYPE_RADIO_RECORDED,  /**< radio recorded clips category */
155     UG_FILE_TYPE_MOVIE_MAKER,     /**< Movie maker project category */
156     UG_FILE_TYPE_SVG,         /**< Svg category */
157     UG_FILE_TYPE_RSS,         /**< Rss reader file, *.opml */
158     UG_FILE_TYPE_CERTIFICATION,   /**< certification file, *.pem */
159     UG_FILE_TYPE_JAVA,        /**< java file, *.jad, *.jar */
160     UG_FILE_TYPE_WGT,         /**< wrt , *.wgt, *.wgt */
161     UG_FILE_TYPE_DRM,               /**< drm file , *.dcf */
162     UG_FILE_TYPE_ETC,         /**< Other files category */
163     UG_FILE_TYPE_MAX
164 };
165
166 typedef enum _mf_ug_iter_category_filter_t mf_ug_iter_category_filter_t;
167 enum _mf_ug_iter_category_filter_t {
168     UG_FILTER_CATEGORY_NONE = 0x00000000,               /**< Default */
169     UG_FILTER_CATEGORY_IMAGE = 0x00000001,                  /**< Image category */
170     UG_FILTER_CATEGORY_VIDEO = 0x00000002,                  /**< Video category */
171     UG_FILTER_CATEGORY_SOUND = 0x00000004,                  /**< Sound category */
172     UG_FILTER_CATEGORY_VOICE = 0x00000008,                  /**< Voice category */
173     UG_FILTER_CATEGORY_MUSIC = 0x00000010,                  /**< Music category */
174     UG_FILTER_CATEGORY_HTML = 0x00000020,               /**< Html category */
175     UG_FILTER_CATEGORY_FLASH = 0x00000040,                  /**< Flash category */
176     UG_FILTER_CATEGORY_GAME = 0x00000080,               /**< Game category */
177     UG_FILTER_CATEGORY_APP = 0x00000100,                /**< Application category */
178     UG_FILTER_CATEGORY_THEME = 0x00000200,                  /**< Theme category */
179     UG_FILTER_CATEGORY_DOC = 0x00000400,                /**< Word category */
180     UG_FILTER_CATEGORY_EXCEL = 0x00000800,                  /**< Excel category */
181     UG_FILTER_CATEGORY_PPT = 0x00001000,                /**< Powerpoint category */
182     UG_FILTER_CATEGORY_PDF = 0x00002000,                /**< Pdf category */
183     UG_FILTER_CATEGORY_TXT = 0x00004000,                /**< Txt category */
184     UG_FILTER_CATEGORY_VCONTACT = 0x00008000,           /**< Vcontact category */
185     UG_FILTER_CATEGORY_VCALENDAR = 0x00010000,          /**< Vcalendar category */
186     UG_FILTER_CATEGORY_VNOTE = 0x00020000,                  /**< Vnote category */
187     UG_FILTER_CATEGORY_VBOOKMARK = 0x00040000,          /**< Vbookmark category */
188     UG_FILTER_CATEGORY_VIDEO_PROJECT = 0x00080000,      /**< Video editor project category */
189     UG_FILTER_CATEGORY_SVG = 0x00100000,                /**< SVG category */
190     UG_FILTER_CATEGORY_RSS = 0x00200000,                /**< RSS category */
191     UG_FILTER_CATEGORY_ETC = 0x00400000,                /**< Other files category */
192
193 };
194
195 typedef enum _mf_ug_drm_filter mf_ug_drm_filter;
196 enum _mf_ug_drm_filter {
197     MF_UG_FILTER_DRM_NONE = 0x00000000,             /**< Default */
198     MF_UG_FILTER_DRM_ALL = 0x00000001,
199     MF_UG_FILTER_DRM_WITHOUT_FL = 0x00000002,
200     MF_UG_FILTER_DRM_IMAGE = 0x00000004,
201     MF_UG_FILTER_DRM_RINGTONE = 0x00000008,
202 };
203
204 typedef enum _mf_ug_storage_type mf_ug_storage_type;
205 enum _mf_ug_storage_type {
206     MF_UG_NONE,
207     MF_UG_PHONE,
208     MF_UG_MMC,
209     MF_UG_MAX
210 };
211
212
213
214 typedef enum _mf_ug_drm_file_mime_type mf_ug_drm_file_mime_type;
215 enum _mf_ug_drm_file_mime_type {
216     MF_UG_DRM_UNKNOW_FILE = 0,
217     MF_UG_DRM_IMAGE_FILE,
218     MF_UG_DRM_RINGTONE_FILE,
219     MF_UG_DRM_VIDEO_FILE,
220     MF_UG_DRM_FILE_MAX
221 };
222
223 typedef enum _mf_ug_sort_option mf_ug_sort_option;
224
225 enum _mf_ug_sort_option {
226     MF_UG_SORT_BY_NONE = 0,      /**< Sort by default */
227     MF_UG_SORT_BY_NAME_A2Z,      /**< Sort by file name ascending */
228     MF_UG_SORT_BY_SIZE_S2L,      /**< Sort by file size ascending */
229     MF_UG_SORT_BY_DATE_O2R,      /**< Sort by file date ascending */
230     MF_UG_SORT_BY_TYPE_A2Z,              /**< Sort by file type ascending */
231     MF_UG_SORT_BY_NAME_Z2A,      /**< Sort by file name descending */
232     MF_UG_SORT_BY_SIZE_L2S,      /**< Sort by file size descending */
233     MF_UG_SORT_BY_DATE_R2O,      /**< Sort by file date descending */
234     MF_UG_SORT_BY_TYPE_Z2A,              /**< Sort by file type descending */
235     MF_UG_SORT_BY_MAX
236 } ;
237
238 typedef enum __MF_UG_SORT_BY_PRIORITY_SEQUENCE MF_UG_SORT_BY_PRIORITY_SEQUENCE;
239 enum __MF_UG_SORT_BY_PRIORITY_SEQUENCE {
240     MF_UG_SORT_BY_PRIORITY_TYPE_A2Z,
241     MF_UG_SORT_BY_PRIORITY_TYPE_Z2A,
242     MF_UG_SORT_BY_PRIORITY_DATE_O2R,
243     MF_UG_SORT_BY_PRIORITY_DATE_R2O,
244     MF_UG_SORT_BY_PRIORITY_SIZE_S2L,
245     MF_UG_SORT_BY_PRIORITY_SIZE_L2S,
246 };
247
248 /*  File operation error check options definition       */
249 #define MF_ERROR_CHECK_SRC_ARG_VALID        0x0001
250 #define MF_ERROR_CHECK_SRC_EXIST            0x0002
251 #define MF_ERROR_CHECK_SRC_PATH_VALID       0x0004
252 #define MF_ERROR_CHECK_DUPLICATED       0x0008
253
254 /*  File system error definition    */
255 #define MF_ERROR_MASKL16       0xFFFF
256
257 #define MF_ERROR_SET(X)        (X & MF_ERROR_MASKL16)
258
259 #define MID_CONTENTS_MGR_ERROR  0
260
261 #define MYFILE_ERR_NONE   (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x00))    /**< No error */
262
263 /*/1-10*/
264 #define MYFILE_ERR_SRC_ARG_INVALID          (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x01))      /**< invalid src argument */
265 #define MYFILE_ERR_DST_ARG_INVALID          (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x02))      /**< invalid dst argument */
266 #define MYFILE_ERR_DIR_OPEN_FAIL            (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x03))      /**< exception of dir open*/
267 #define MYFILE_ERR_INVALID_DIR_PATH         (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x04))      /**< exception of invalid dir path */
268 #define MYFILE_ERR_INVALID_FILE_NAME            (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x05))      /**< exception of invalid file name */
269 #define MYFILE_ERR_INVALID_FILE_PATH            (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x06))      /**< exception of invalid file path */
270 #define MYFILE_ERR_DRM_PERMISSION_DENY          (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x07))          /**< can't copy/move drm file because of permission */
271 #define MYFILE_ERR_SRC_NOT_EXIST            (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x08))          /**< source not found */
272 #define MYFILE_ERR_STORAGE_TYPE_ERROR           (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x09))          /**< storage type error */
273 #define MYFILE_ERR_EXT_GET_ERROR            (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x0a))          /**< get ext type failed */
274 #define MYFILE_ERR_GET_STAT_FAIL            (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x0b))          /**< get stat failed */
275 #define MYFILE_ERR_GET_CATEGORY_FAIL            (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x0c))          /**< get file category failed */
276 #define MYFILE_ERR_GET_VCONF_FAIL           (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x0d))          /**< get vconf value failed */
277 #define MYFILE_ERR_INVALID_ARG              (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x0e))          /**< argument of function is not valid */
278 #define MYFILE_ERR_ALLOCATE_FAIL            (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x0f))
279 #define MYFILE_ERR_LIST_PLAY_FAIL           (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x10))
280 #define MYFILE_ERR_INVALID_PATH             (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x11))      /**< invalid path string */
281 #define MYFILE_ERR_GET_THUMBNAIL_FAILED         (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x12))       /**<get thumbnail failed */
282 #define MYFILE_ERR_UNKNOW_ERROR             (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x13))       /**<unknow error */
283 #define MYFILE_ERR_NO_FREE_SPACE            (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x14))          /**< get free space failed */
284 #define MYFILE_ERR_DUPLICATED_NAME          (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x15))    /**< exception of duplicated dir name*/
285 #define MYFILE_ERR_ALLOCATE_MEMORY_FAIL         (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x16))   /**< exception of memory allocation */
286 #define MYFILE_ERR_GET_LOGIC_PATH_FAIL          (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x17))   /**< get logical path failed */
287 #define MYFILE_ERR_GENERATE_NAME_FAIL           (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x18))   /**< generate name failed */
288 #define MYFILE_ERR_DIR_CREATE_FAIL          (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x19))   /**< exception of create dir */
289 #define MYFILE_ERR_GET_PARENT_PATH_FAIL         (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x1a))   /**< get parent path failed */
290 #define MYFILE_ERR_EXCEED_MAX_LENGTH            (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x1b))       /**< length of file/dir path exceeds maximum length*/
291
292 /*  File system related callback definition */
293
294 typedef struct _ugFsNodeInfo ugFsNodeInfo;
295 struct _ugFsNodeInfo {
296     char path[MYFILE_DIR_PATH_LEN_MAX];
297     char name[MYFILE_FILE_NAME_LEN_MAX];
298     time_t date;
299     mf_ug_fs_file_type type;
300     char *ext;
301     unsigned int size;
302 };
303
304
305 /**********         File Attribute Related          **********/
306 int mf_ug_file_attr_get_file_stat(const char *filename, ugFsNodeInfo ** node);
307
308 int mf_ug_file_attr_get_file_category(const char *filepath, mf_ug_fs_file_type * category);
309 int mf_ug_file_attr_is_dir(const char *filepath);
310 int mf_ug_file_attr_get_store_type_by_full(const char *filepath, mf_ug_storage_type * store_type);
311 int mf_ug_file_attr_is_drm_file(const char *file_fullpath);
312 int mf_ug_file_attr_get_file_ext(const char *filepath, char **file_ext);
313 int mf_ug_file_attr_is_right_dir_path(const char *dir_path);
314 int mf_ug_file_attr_is_right_file_path(const char *file_path);
315 int mf_ug_file_attr_is_duplicated_name(const char *dir, const char *name);
316 int mf_ug_file_attr_get_logical_path_by_full(const char *full_path, char **path);
317 int mf_ug_file_attr_is_valid_name(const char *filename);
318
319 /**********         File Operation Related          **********/
320 int mf_ug_fs_oper_read_dir(const char *path, Eina_List **dir_list, Eina_List **file_list);
321 int mf_ug_fs_oper_list_filter(Eina_List *in_list, Eina_List **out_list, int option, int drm_opt);
322 int mf_ug_fs_oper_list_filter_by_extension(Eina_List *in_list, Eina_List **out_list, char *ext);
323 int mf_ug_file_attr_get_file_icon(const char *file_path, int *error_code, char **thumbnail);
324 mf_ug_drm_file_mime_type mf_ug_fs_oper_get_drm_type(char *path);
325 int mf_ug_file_attr_is_system_dir(char *fullpath, bool * result);
326 mf_ug_fs_file_type mf_ug_file_attr_get_file_type_by_mime(const char *file_path);
327 int mf_ug_fs_oper_create_dir(const char *dir);
328 void mf_ug_fs_oper_sort_list(Eina_List **list, int sort_opt);
329 int mf_ug_fs_oper_drm_is_action_allowed(const char *path, drm_action_type_e action, drm_setas_category_e category);
330 bool mf_ug_fs_oper_drm_is_valid(const char *path, drm_permission_type_e perm_type);
331
332 #endif