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