root/trunk/src/core/include/hydrogen/helpers/filesystem.h @ 2253

Revision 2253, 8.6 KB (checked in by jeremyz, 23 months ago)

Filesystem: drumkit_path=>drumkit_path_search, drumkit_location=>drumkit_dir_search + fix comments

Line 
1
2#ifndef H2C_FILESYSTEM_H
3#define H2C_FILESYSTEM_H
4
5#include <hydrogen/object.h>
6#include <QtCore/QString>
7
8namespace H2Core {
9
10/**
11 * Filesystem is a thin layer over QDir, QFile and QFileInfo
12 */
13class Filesystem : public H2Core::Object {
14        H2_OBJECT
15    public:
16        /** flags available for Filesystem::check_permissions */
17        enum file_perms {
18            is_dir =0x01,
19            is_file=0x02,
20            is_readable=0x04,
21            is_writable=0x08,
22            is_executable=0x10
23        };
24
25        /**
26         * check user and system filesystem usability
27         * \param logger is a pointer to the logger instance which will be used
28         */
29        static bool bootstrap( Logger* logger );
30
31        /** returns system data path */
32        static QString sys_data_path();
33        /** returns user data path */
34        static QString usr_data_path();
35
36        /** returns system core config path */
37        static QString sys_core_config();
38        /** returns user core config path */
39        static QString usr_core_config();
40        /** returns system gui config path */
41        static QString sys_gui_config();
42        /** returns user gui config path */
43        static QString usr_gui_config();
44        /** returns system empty sample file path */
45        static QString empty_sample();
46        /** returns system empty song file path */
47        static QString empty_song();
48        /** returns system click file path */
49        static QString click_file();
50        /** returns click file path from user directory if exists, otherwise from system */
51        static QString usr_click_file();
52        /** returns the path to the drumkit XSD (xml schema definition) file */
53        static QString drumkit_xsd( );
54        /** returns the path to the pattern XSD (xml schema definition) file */
55        static QString pattern_xsd( );
56
57        /** returns gui image path */
58        static QString img_dir();
59        /** returns documentation path */
60        static QString doc_dir();
61        /** returns internationalization path */
62        static QString i18n_dir();
63        /** returns user songs path */
64        static QString songs_dir();
65        /** returns user patterns path */
66        static QString patterns_dir();
67        /** returns system drumkits path */
68        static QString sys_drumkits_dir();
69        /** returns user drumkits path */
70        static QString usr_drumkits_dir();
71        /** returns user playlist path */
72        static QString playlists_dir();
73        /** returns system demos path */
74        static QString demos_dir();
75        /** returns system xsd path */
76        static QString xsd_dir();
77
78        /* DRUMKIT */
79        /** returns list of usable system drumkits ( see Filesystem::drumkits_list ) */
80        static QStringList sys_drumkits_list( );
81        /** returns list of usable user drumkits ( see Filesystem::drumkits_list ) */
82        static QStringList usr_drumkits_list( );
83        /**
84         * returns true if the drumkit exists within usable system or user drumkits
85         * \param dk_name the drumkit name
86         */
87        static bool drumkit_exists( const QString& dk_name );
88        /**
89         * returns path for a drumkit searching within user then system drumkits
90         * \param dk_name the drumkit name
91         */
92        static QString drumkit_path_search( const QString& dk_name );
93        /**
94         * returns the directory holding the named drumkit searching within user then system drumkits
95         * \param dk_name the drumkit name
96         */
97        static QString drumkit_dir_search( const QString& dk_name );
98        /**
99         * returns true if the path contains a usable drumkit
100         * \param dk_location the root drumkit location
101         */
102        static bool drumkit_valid( const QString& dk_path );
103        /**
104         * returns the path to the xml file within a suposed drumkit path
105         * \param dk_path the path to the drumkit
106         */
107        static QString drumkit_file( const QString& dk_path );
108
109        /* PATTERNS */
110        /** returns a list of existing patterns */
111        static QStringList patterns_list( );
112
113        /* SONGS */
114        /** returns a list of existing songs */
115        static QStringList songs_list( );
116        /**
117         * returns true if the song file exists
118         * \param sg_name the song name
119         */
120        static bool song_exists( const QString& sg_name );
121
122        /** send current settings information to logger with INFO severity */
123        static void info();
124
125        /**
126         * returns true if the given path is an existing regular file
127         * \param path the path to the file to check
128         * \param silent output not messages if set to true
129         */
130        static bool file_exists( const QString& path, bool silent=false );
131        /**
132         * returns true if the given path is an existing readable regular file
133         * \param path the path to the file to check
134         * \param silent output not messages if set to true
135         */
136        static bool file_readable( const QString& path, bool silent=false );
137        /**
138         * returns true if the given path is a possibly writable file (may exist or not)
139         * \param path the path to the file to check
140         * \param silent output not messages if set to true
141         */
142        static bool file_writable( const QString& path, bool silent=false );
143        /**
144         * returns true if the given path is an existing executable regular file
145         * \param path the path to the file to check
146         * \param silent output not messages if set to true
147         */
148        static bool file_executable( const QString& path, bool silent=false );
149        /**
150         * returns true if the given path is a readable regular directory
151         * \param path the path to the file to check
152         * \param silent output not messages if set to true
153         */
154        static bool dir_readable( const QString& path, bool silent=false );
155        /**
156         * returns true if the given path is a writable regular directory
157         * \param path the path to the file to check
158         * \param silent output not messages if set to true
159         */
160        static bool dir_writable( const QString& path, bool silent=false );
161        /**
162         * returns true if the path is a readable and writable regular directory, create if it not exists
163         * \param path the path to the file to check
164         * \param create will try to create path if not exists and set to true
165         * \param silent output not messages if set to true
166         */
167        static bool path_usable( const QString& path, bool create=true, bool silent=false );
168        /**
169         * writes to a file
170         * \param dst the destination path
171         * \param content then string to write
172         */
173        static bool write_to_file( const QString& dst, const QString& content );
174        /**
175         * copy a source file to a destination
176         * \param src source file path
177         * \param dsr destination file path
178         * \param overwrite allow to overwrite an existing file if set to true
179         */
180        static bool file_copy( const QString& src, const QString& dst, bool overwrite=false );
181        /**
182         * remove a path
183         * \param path the path to be removed
184         * \param recursive performe recursive removal if set to true
185         */
186        static bool rm( const QString& path, bool recursive=false );
187        /**
188         * create a path
189         * \param path the path to the directory to be created
190         */
191        static bool mkdir( const QString& path );
192
193    private:
194        static Logger* __logger;                    ///< a pointer to the logger
195        static bool check_sys_paths();              ///< returns true if the system path is consistent
196        static bool check_usr_paths();              ///< returns true if the user path is consistent
197        static bool rm_fr( const QString& path );   ///< recursively remove a path
198
199        /**
200         * returns a list of usable drumkits, which means having a readable drumkit.xml file
201         * \param path the path to search in for drumkits
202         */
203        static QStringList drumkits_list( const QString& path );
204        /**
205         * return true if all the asked permissions are ok
206         * \param path the path to the file to check
207         * \param perms bit mask of file_perms
208         * \param silent output not messages if set to true
209         */
210        static bool check_permissions( const QString& path, const int perms, bool silent );
211
212        static QString __sys_data_path;     ///< the path to the system files
213        static QString __usr_data_path;     ///< the path to the user files
214};
215
216};
217
218#endif  // H2C_FILESYSTEM_H
219
220/* vim: set softtabstop=4 expandtab: */
Note: See TracBrowser for help on using the browser.