summaryrefslogtreecommitdiff
path: root/src/include/mf-ug-fs-util.h
blob: b754d6565f4621fbc2e041c32ebc84a35b26a444 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
/*
 * myfile
 *
 * Copyright 2012  Samsung Electronics Co., Ltd
 *
 * Licensed under the Flora License, Version 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.tizenopensource.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.
 *
 */



#ifndef __DEF_MF_UG_FS_UTIL_H_
#define __DEF_MF_UG_FS_UTIL_H_

#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#include <dirent.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <linux/fs.h>
#include <Eina.h>

#include <Elementary.h>
#include <drm_client.h>
#include <drm_client_types.h>
#include <media_content.h>

#include "mf-ug-dlog.h"


/*	File system related value definition	*/
#define	FILE_EXT_LEN_MAX				8
#define MYFILE_DIR_PATH_LEN_MAX		4096
#define MYFILE_FILE_NAME_LEN_MAX		256
#define MYFILE_FILE_PATH_LEN_MAX		MYFILE_DIR_PATH_LEN_MAX + MYFILE_FILE_NAME_LEN_MAX


/*	File system related String definition	*/
#define PHONE_FOLDER		"/opt/media"
#define MEMORY_FOLDER		"/opt/storage/sdcard"
#define SOUNDS_FOLDER		"/opt/media/Sounds"
#define DEBUG_FOLDER		"SLP_debug"

#define MYFILE_NAME_PATTERN	"[\\:;*\"<>|?/]"

#define IMAGE_AND_VIDEO		"Images and videos"
#define SOUND_AND_MUSIC		"Sounds and music"
#define DOWNLOADS			"Downloads"
#define CAMERA_SHOTS		"Camera shots"


#define WALLPAPER			"Wallpapers"
#define MY_PHOTO_CLIPS		"My photo clips"
#define MY_ALBUM			"My album"	/*/_("IDS_MF_BODY_ACCESS_MORE_MY_ALBUM") */
#define MY_VIDEO_CLIPS		"My video clips"	/*/_("IDS_MF_BODY_MY_VIDEO_CLIPS") */

#define FM_RADIO			"FM Radio"	/*/dgettext("sys_string", "IDS_COM_HEADER_FMRADIO") */
#define MUSIC				"Music"	/*/_("IDS_MF_BODY_MUSIC") */
#define RINGTONES			"Ringtones"
#define VOICE_RECORDER		"Voice recorder"	/*/dgettext("sys_string", "IDS_COM_BODY_VOICE_RECORDER") */
#define ALERTS				"Alerts"
#define OTHERS				"Others"	/*/dgettext("sys_string","IDS_COM_BODY_OTHERS") */

/*	File system define default folder	*/

/*	compile option	*/
#define UG_DEBUG_FOLDER_OPTION

#ifndef UG_ICON_PATH
#define UG_ICON_PATH						"/opt/ug/res/images/ug-myfile-efl"
#endif

#ifndef UG_DEFAULT_ICON
#define UG_DEFAULT_ICON							UG_ICON_PATH"/myfile_icon_etc.png"
#endif

#define UG_ICON_FOLDER							UG_ICON_PATH"/myfile_icon_folder.png"
#define UG_ICON_FOLDER_OPEN						UG_ICON_PATH"/myfile_icon_folder_open.png"

#define UG_ICON_IMAGE							UG_ICON_PATH"/myfile_icon_images.png"
#define UG_ICON_VIDEO							UG_ICON_PATH"/myfile_icon_video.png"
#define UG_ICON_MUSIC							UG_ICON_PATH"/myfile_icon_music.png"
#define UG_ICON_SOUND							UG_ICON_PATH"/myfile_icon_music.png"
#define UG_ICON_PDF							UG_ICON_PATH"/myfile_icon_pdf.png"
#define UG_ICON_DOC							UG_ICON_PATH"/myfile_icon_word.png"
#define UG_ICON_PPT							UG_ICON_PATH"/myfile_icon_ppt.png"
#define UG_ICON_EXCEL							UG_ICON_PATH"/myfile_icon_excel.png"
#define UG_ICON_VOICE							UG_ICON_PATH"/myfile_icon_music.png"
#define UG_ICON_HTML							UG_ICON_PATH"/myfile_icon_html.png"
#define UG_ICON_FLASH							UG_ICON_PATH"/myfile_icon_swf.png"
#define UG_ICON_TXT							UG_ICON_PATH"/myfile_icon_text.png"
#define UG_ICON_VCONTACT						UG_ICON_PATH"/myfile_icon_svg.png"
#define UG_ICON_VCALENDAR						UG_ICON_PATH"/myfile_icon_svg.png"
#define UG_ICON_VNOTE							UG_ICON_PATH"/myfile_icon_text.png"
#define UG_ICON_RSS							UG_ICON_PATH"/myfile_icon_rss.png"
#define UG_ICON_JAVA							UG_ICON_PATH"/myfile_icon_java.png"
#define UG_ICON_MEMORY_SUB						UG_ICON_PATH"/myfile_icon_mmc_sub.png"
#define UG_ICON_MUSIC_PLAY						UG_ICON_PATH"/myfile_icon_control_play.png"
#define UG_ICON_MUSIC_PAUSE						UG_ICON_PATH"/myfile_icon_control_pause.png"
#define UG_ICON_MUSIC_PLAY_WHITE					UG_ICON_PATH"/myfile_icon_play_focus.png"
#define UG_ICON_MUSIC_PAUSE_WHITE					UG_ICON_PATH"/myfile_icon_pause_focus.png"

#define	UG_ICON_BLACK_THEME_UPPER					UG_ICON_PATH"/myfile_icon_upper_folder_black_theme.png"
#define	UG_ICON_WHITE_THEME_UPPER					UG_ICON_PATH"/myfile_icon_upper_folder_white_theme.png"

#define UG_ICON_PHONE							UG_ICON_PATH"/myfile_icon_phone.png"
#define UG_ICON_MEMORY							UG_ICON_PATH"/myfile_icon_mmc.png"
#define UG_ICON_VIDEO_PLAY						UG_ICON_PATH"/myfile_icon_video_play.png"

typedef enum _mf_ug_fs_file_type mf_ug_fs_file_type;

enum _mf_ug_fs_file_type {
	UG_FILE_TYPE_NONE = 0,
	UG_FILE_TYPE_DIR,			   /**< Folder category */
	UG_FILE_TYPE_FILE,			   /**< File category */
	UG_FILE_TYPE_IMAGE,	      /**< Image category */
	UG_FILE_TYPE_VIDEO,	      /**< Video category */
	UG_FILE_TYPE_MUSIC,	      /**< Music category */
	UG_FILE_TYPE_SOUND,	      /**< Sound category */
	UG_FILE_TYPE_PDF,	      /**< Pdf category */
	UG_FILE_TYPE_DOC,	      /**< Word category */
	UG_FILE_TYPE_PPT,	      /**< Powerpoint category */
	UG_FILE_TYPE_EXCEL,	      /**< Excel category */
	UG_FILE_TYPE_VOICE,	      /**< Voice category */
	UG_FILE_TYPE_HTML,	      /**< Html category */
	UG_FILE_TYPE_FLASH,	      /**< Flash category */
	UG_FILE_TYPE_GAME,	      /**< Game category */
	UG_FILE_TYPE_APP,	      /**< Application category */
	UG_FILE_TYPE_THEME,	      /**< Theme category */
	UG_FILE_TYPE_TXT,	      /**< Txt category */
	UG_FILE_TYPE_VCONTACT,	      /**< Vcontact category */
	UG_FILE_TYPE_VCALENDAR,	      /**< Vcalendar category */
	UG_FILE_TYPE_VNOTE,	      /**< Vnote category */
	UG_FILE_TYPE_VBOOKMARK,	      /**< Vbookmark category */
	UG_FILE_TYPE_VIDEO_PROJECT,   /**< Video editor project category */
	UG_FILE_TYPE_RADIO_RECORDED,  /**< radio recorded clips category */
	UG_FILE_TYPE_MOVIE_MAKER,     /**< Movie maker project category */
	UG_FILE_TYPE_SVG,	      /**< Svg category */
	UG_FILE_TYPE_RSS,	      /**< Rss reader file, *.opml */
	UG_FILE_TYPE_CERTIFICATION,   /**< certification file, *.pem */
	UG_FILE_TYPE_JAVA,	      /**< java file, *.jad, *.jar */
	UG_FILE_TYPE_WGT,	      /**< wrt , *.wgt, *.wgt */
	UG_FILE_TYPE_DRM,				/**< drm file , *.dcf */
	UG_FILE_TYPE_ETC,	      /**< Other files category */
	UG_FILE_TYPE_MAX
};

typedef enum _mf_ug_iter_category_filter_t mf_ug_iter_category_filter_t;
enum _mf_ug_iter_category_filter_t {
	UG_FILTER_CATEGORY_NONE = 0x00000000,				/**< Default */
	UG_FILTER_CATEGORY_IMAGE = 0x00000001,					/**< Image category */
	UG_FILTER_CATEGORY_VIDEO = 0x00000002,					/**< Video category */
	UG_FILTER_CATEGORY_SOUND = 0x00000004,					/**< Sound category */
	UG_FILTER_CATEGORY_VOICE = 0x00000008,					/**< Voice category */
	UG_FILTER_CATEGORY_MUSIC = 0x00000010,					/**< Music category */
	UG_FILTER_CATEGORY_HTML = 0x00000020,				/**< Html category */
	UG_FILTER_CATEGORY_FLASH = 0x00000040,					/**< Flash category */
	UG_FILTER_CATEGORY_GAME = 0x00000080,				/**< Game category */
	UG_FILTER_CATEGORY_APP = 0x00000100,				/**< Application category */
	UG_FILTER_CATEGORY_THEME = 0x00000200,					/**< Theme category */
	UG_FILTER_CATEGORY_DOC = 0x00000400,				/**< Word category */
	UG_FILTER_CATEGORY_EXCEL = 0x00000800,					/**< Excel category */
	UG_FILTER_CATEGORY_PPT = 0x00001000,				/**< Powerpoint category */
	UG_FILTER_CATEGORY_PDF = 0x00002000,				/**< Pdf category */
	UG_FILTER_CATEGORY_TXT = 0x00004000,				/**< Txt category */
	UG_FILTER_CATEGORY_VCONTACT = 0x00008000,			/**< Vcontact category */
	UG_FILTER_CATEGORY_VCALENDAR = 0x00010000,			/**< Vcalendar category */
	UG_FILTER_CATEGORY_VNOTE = 0x00020000,					/**< Vnote category */
	UG_FILTER_CATEGORY_VBOOKMARK = 0x00040000,			/**< Vbookmark category */
	UG_FILTER_CATEGORY_VIDEO_PROJECT = 0x00080000,		/**< Video editor project category */
	UG_FILTER_CATEGORY_SVG = 0x00100000,				/**< SVG category */
	UG_FILTER_CATEGORY_RSS = 0x00200000,				/**< RSS category */
	UG_FILTER_CATEGORY_ETC = 0x00400000,				/**< Other files category */

};

typedef enum _mf_ug_drm_filter mf_ug_drm_filter;
enum _mf_ug_drm_filter {
	MF_UG_FILTER_DRM_NONE = 0x00000000,				/**< Default */
	MF_UG_FILTER_DRM_ALL = 0x00000001,
	MF_UG_FILTER_DRM_WITHOUT_FL = 0x00000002,
	MF_UG_FILTER_DRM_IMAGE = 0x00000004,
	MF_UG_FILTER_DRM_RINGTONE = 0x00000008,
};

typedef enum _mf_ug_storage_type mf_ug_storage_type;
enum _mf_ug_storage_type {
	MF_UG_NONE,
	MF_UG_PHONE,
	MF_UG_MMC,
	MF_UG_MAX
};



typedef enum _mf_ug_drm_file_mime_type mf_ug_drm_file_mime_type;
enum _mf_ug_drm_file_mime_type {
	MF_UG_DRM_UNKNOW_FILE = 0,
	MF_UG_DRM_IMAGE_FILE,
	MF_UG_DRM_RINGTONE_FILE,
	MF_UG_DRM_VIDEO_FILE,
	MF_UG_DRM_FILE_MAX
};

typedef enum _mf_ug_sort_option mf_ug_sort_option;

enum _mf_ug_sort_option {
	MF_UG_SORT_BY_NONE = 0,		 /**< Sort by default */
	MF_UG_SORT_BY_NAME_A2Z,		 /**< Sort by file name ascending */
	MF_UG_SORT_BY_SIZE_S2L,		 /**< Sort by file size ascending */
	MF_UG_SORT_BY_DATE_O2R,		 /**< Sort by file date ascending */
	MF_UG_SORT_BY_TYPE_A2Z,				 /**< Sort by file type ascending */
	MF_UG_SORT_BY_NAME_Z2A,		 /**< Sort by file name descending */
	MF_UG_SORT_BY_SIZE_L2S,		 /**< Sort by file size descending */
	MF_UG_SORT_BY_DATE_R2O,		 /**< Sort by file date descending */
	MF_UG_SORT_BY_TYPE_Z2A,				 /**< Sort by file type descending */
	MF_UG_SORT_BY_MAX
} ;

typedef enum __MF_UG_SORT_BY_PRIORITY_SEQUENCE MF_UG_SORT_BY_PRIORITY_SEQUENCE;
enum __MF_UG_SORT_BY_PRIORITY_SEQUENCE {
	MF_UG_SORT_BY_PRIORITY_TYPE_A2Z,
	MF_UG_SORT_BY_PRIORITY_TYPE_Z2A,
	MF_UG_SORT_BY_PRIORITY_DATE_O2R,
	MF_UG_SORT_BY_PRIORITY_DATE_R2O,
	MF_UG_SORT_BY_PRIORITY_SIZE_S2L,
	MF_UG_SORT_BY_PRIORITY_SIZE_L2S,
};

/*	File operation error check options definition		*/
#define	MF_ERROR_CHECK_SRC_ARG_VALID		0x0001
#define	MF_ERROR_CHECK_SRC_EXIST			0x0002
#define MF_ERROR_CHECK_SRC_PATH_VALID		0x0004
#define	MF_ERROR_CHECK_DUPLICATED		0x0008

/*	File system error definition	*/
#define MF_ERROR_MASKL16       0xFFFF

#define MF_ERROR_SET(X)        (X & MF_ERROR_MASKL16)

#define MID_CONTENTS_MGR_ERROR  0

#define MYFILE_ERR_NONE   (MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x00))	   /**< No error */

/*/1-10*/
#define MYFILE_ERR_SRC_ARG_INVALID			(MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x01))	   /**< invalid src argument */
#define MYFILE_ERR_DST_ARG_INVALID			(MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x02))	   /**< invalid dst argument */
#define MYFILE_ERR_DIR_OPEN_FAIL			(MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x03))	   /**< exception of dir open*/
#define MYFILE_ERR_INVALID_DIR_PATH			(MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x04))	   /**< exception of invalid dir path */
#define MYFILE_ERR_INVALID_FILE_NAME			(MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x05))	   /**< exception of invalid file name */
#define MYFILE_ERR_INVALID_FILE_PATH			(MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x06))	   /**< exception of invalid file path */
#define MYFILE_ERR_DRM_PERMISSION_DENY			(MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x07))	       /**< can't copy/move drm file because of permission */
#define MYFILE_ERR_SRC_NOT_EXIST			(MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x08))	       /**< source not found */
#define MYFILE_ERR_STORAGE_TYPE_ERROR			(MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x09))	       /**< storage type error */
#define MYFILE_ERR_EXT_GET_ERROR			(MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x0a))	       /**< get ext type failed */
#define MYFILE_ERR_GET_STAT_FAIL			(MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x0b))	       /**< get stat failed */
#define MYFILE_ERR_GET_CATEGORY_FAIL			(MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x0c))	       /**< get file category failed */
#define MYFILE_ERR_GET_VCONF_FAIL			(MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x0d))	       /**< get vconf value failed */
#define MYFILE_ERR_INVALID_ARG				(MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x0e))	       /**< argument of function is not valid */
#define MYFILE_ERR_ALLOCATE_FAIL			(MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x0f))
#define MYFILE_ERR_LIST_PLAY_FAIL			(MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x10))
#define MYFILE_ERR_INVALID_PATH				(MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x11))	   /**< invalid path string */
#define MYFILE_ERR_GET_THUMBNAIL_FAILED			(MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x12))		/**<get thumbnail failed */
#define MYFILE_ERR_UNKNOW_ERROR				(MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x13))		/**<unknow error */
#define MYFILE_ERR_NO_FREE_SPACE			(MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x14))	       /**< get free space failed */
#define MYFILE_ERR_DUPLICATED_NAME			(MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x15))    /**< exception of duplicated dir name*/
#define MYFILE_ERR_ALLOCATE_MEMORY_FAIL			(MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x16))	/**< exception of memory allocation */
#define MYFILE_ERR_GET_LOGIC_PATH_FAIL			(MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x17))	/**< get logical path failed */
#define MYFILE_ERR_GENERATE_NAME_FAIL			(MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x18))	/**< generate name failed */
#define MYFILE_ERR_DIR_CREATE_FAIL			(MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x19))	/**< exception of create dir */
#define MYFILE_ERR_GET_PARENT_PATH_FAIL			(MID_CONTENTS_MGR_ERROR - MF_ERROR_SET(0x1a))	/**< get parent path failed */

/*	File system related callback definition	*/

typedef struct _ugFsNodeInfo ugFsNodeInfo;
struct _ugFsNodeInfo {
	char path[MYFILE_DIR_PATH_LEN_MAX];
	char name[MYFILE_FILE_NAME_LEN_MAX];
	time_t date;
	mf_ug_fs_file_type type;
	char *ext;
	unsigned int size;
};


/**********			File Attribute Related			**********/
int mf_ug_file_attr_get_file_stat(const char *filename, ugFsNodeInfo ** node);

int mf_ug_file_attr_get_file_category(const char *filepath, mf_ug_fs_file_type * category);
int mf_ug_file_attr_is_dir(const char *filepath);
int mf_ug_file_attr_get_store_type_by_full(const char *filepath, mf_ug_storage_type * store_type);
int mf_ug_file_attr_is_drm_file(const char *file_fullpath);
int mf_ug_file_attr_get_file_ext(const char *filepath, char **file_ext);
int mf_ug_file_attr_is_right_dir_path(const char *dir_path);
int mf_ug_file_attr_is_right_file_path(const char *file_path);
int mf_ug_file_attr_is_duplicated_name(const char *dir, const char *name);
int mf_ug_file_attr_get_logical_path_by_full(const char *full_path, char **path);
int mf_ug_file_attr_is_valid_name(const char *filename);

/**********			File Operation Related			**********/
int mf_ug_fs_oper_read_dir(const char *path, Eina_List **dir_list, Eina_List **file_list);
int mf_ug_fs_oper_list_filter(Eina_List *in_list, Eina_List **out_list, int option, int drm_opt);
int mf_ug_fs_oper_list_filter_by_extension(Eina_List *in_list, Eina_List **out_list, char *ext);
char *mf_ug_file_attr_get_file_icon(const char *file_path, int *error_code);
mf_ug_drm_file_mime_type mf_ug_fs_oper_get_drm_type(char *path);
int mf_ug_file_attr_is_system_dir(char *fullpath, bool * result);
mf_ug_fs_file_type mf_ug_file_attr_get_file_type_by_mime(const char *file_path);
int mf_ug_fs_oper_create_dir(const char *dir);
void mf_ug_fs_oper_sort_list(Eina_List **list, int sort_opt);

#endif