]> git.saurik.com Git - wxWidgets.git/blame - interface/filesys.h
More initial reviews of d* interface headers.
[wxWidgets.git] / interface / filesys.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: filesys.h
e54c96f1 3// Purpose: interface of wxFileSystem
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
9/**
10 @class wxFileSystem
11 @wxheader{filesys.h}
7c913512 12
23324ae1
FM
13 This class provides an interface for opening files on different
14 file systems. It can handle absolute and/or local filenames.
e54c96f1 15 It uses a system of handlers() to
23324ae1 16 provide access to user-defined virtual file systems.
7c913512 17
23324ae1
FM
18 @library{wxbase}
19 @category{vfs}
7c913512 20
e54c96f1 21 @see wxFileSystemHandler, wxFSFile, Overview()
23324ae1
FM
22*/
23class wxFileSystem : public wxObject
24{
25public:
26 /**
27 Constructor.
28 */
29 wxFileSystem();
30
31 /**
7c913512 32 This static function adds new handler into the list of
e54c96f1 33 handlers() which provide access to virtual FS.
23324ae1
FM
34 Note that if two handlers for the same protocol are added, the last one added
35 takes precedence.
36 */
37 static void AddHandler(wxFileSystemHandler handler);
38
39 /**
4cc4bfaf 40 Sets the current location. @a location parameter passed to
23324ae1 41 OpenFile() is relative to this path.
4cc4bfaf 42 @b Caution! Unless @a is_dir is @true the @a location parameter
23324ae1
FM
43 is not the directory name but the name of the file in this directory. All these
44 commands change the path to "dir/subdir/":
3c4f71cc 45
7c913512 46 @param location
4cc4bfaf 47 the new location. Its meaning depends on the value of is_dir
7c913512 48 @param is_dir
4cc4bfaf
FM
49 if @true location is new directory. If @false (default)
50 location is file in the new directory.
23324ae1 51 */
4cc4bfaf 52 void ChangePathTo(const wxString& location, bool is_dir = false);
23324ae1
FM
53
54 /**
55 Converts filename into URL.
3c4f71cc 56
4cc4bfaf 57 @see URLToFileName(), wxFileName
23324ae1
FM
58 */
59 static wxString FileNameToURL(wxFileName filename);
60
61 /**
4cc4bfaf 62 Looks for the file with the given name @a file in a colon or semi-colon
23324ae1
FM
63 (depending on the current platform) separated list of directories in
64 @e path. If the file is found in any directory, returns @true and the full
7c913512 65 path of the file in @e str, otherwise returns @false and doesn't modify
23324ae1 66 @e str.
3c4f71cc 67
7c913512 68 @param str
4cc4bfaf 69 Receives the full path of the file, must not be @NULL
7c913512 70 @param path
4cc4bfaf 71 wxPATH_SEP-separated list of directories
7c913512 72 @param file
4cc4bfaf 73 the name of the file to look for
23324ae1
FM
74 */
75 bool FindFileInPath(wxString str, const wxString& path,
76 const wxString& file);
77
78 /**
e54c96f1 79 Works like wxFindFirstFile(). Returns name of the first
4cc4bfaf 80 filename (within filesystem's current path) that matches @e wildcard. @a flags
23324ae1
FM
81 may be one of
82 wxFILE (only files), wxDIR (only directories) or 0 (both).
83 */
84 wxString FindFirst(const wxString& wildcard, int flags = 0);
85
86 /**
87 Returns the next filename that matches parameters passed to FindFirst().
88 */
89 wxString FindNext();
90
91 /**
92 Returns actual path (set by wxFileSystem::ChangePathTo).
93 */
94 wxString GetPath();
95
96 /**
97 This static function returns @true if there is a registered handler which can
98 open the given
99 location.
100 */
4cc4bfaf 101 static bool HasHandlerForPath(const wxString& location);
23324ae1
FM
102
103 /**
104 Opens the file and returns a pointer to a wxFSFile object
105 or @NULL if failed. It first tries to open the file in relative scope
106 (based on value passed to ChangePathTo() method) and then as an
107 absolute path. Note that the user is responsible for deleting the returned
7c913512 108 wxFSFile.
4cc4bfaf 109 @a flags can be one or more of the following bit values ored together:
3c4f71cc 110
23324ae1
FM
111 A stream opened with just the default @e wxFS_READ flag may
112 or may not be seekable depending on the underlying source.
4cc4bfaf 113 Passing @e wxFS_READ | wxFS_SEEKABLE for @a flags will
23324ae1
FM
114 back a stream that is not natively seekable with memory or a file
115 and return a stream that is always seekable.
116 */
117 wxFSFile* OpenFile(const wxString& location,
118 int flags = wxFS_READ);
119
120 /**
7c913512 121 Converts URL into a well-formed filename. The URL must use the @c file
23324ae1
FM
122 protocol.
123 */
124 static wxFileName URLToFileName(const wxString& url);
125};
126
127
e54c96f1 128
23324ae1
FM
129/**
130 @class wxFSFile
131 @wxheader{filesys.h}
7c913512 132
23324ae1 133 This class represents a single file opened by wxFileSystem.
7c913512 134 It provides more information than wxWindow's input stream
23324ae1 135 (stream, filename, mime type, anchor).
7c913512 136
cdbcf4c2 137 @note Any pointer returned by a method of wxFSFile is valid
23324ae1
FM
138 only as long as the wxFSFile object exists. For example a call to GetStream()
139 doesn't @e create the stream but only returns the pointer to it. In
140 other words after 10 calls to GetStream() you will have obtained ten identical
141 pointers.
7c913512 142
23324ae1
FM
143 @library{wxbase}
144 @category{vfs}
7c913512 145
e54c96f1 146 @see wxFileSystemHandler, wxFileSystem, Overview()
23324ae1
FM
147*/
148class wxFSFile : public wxObject
149{
150public:
151 /**
152 Constructor. You probably won't use it. See Notes for details.
3c4f71cc 153
7c913512 154 @param stream
4cc4bfaf 155 The input stream that will be used to access data
7c913512 156 @param location
4cc4bfaf 157 The full location (aka filename) of the file
7c913512 158 @param mimetype
4cc4bfaf
FM
159 MIME type of this file. It may be left empty, in which
160 case the type will be determined from file's extension (location must
161 not be empty in this case).
7c913512 162 @param anchor
4cc4bfaf 163 Anchor. See GetAnchor() for details.
23324ae1
FM
164 */
165 wxFSFile(wxInputStream stream, const wxString& loc,
166 const wxString& mimetype,
167 const wxString& anchor, wxDateTime modif);
168
169 /**
170 Detaches the stream from the wxFSFile object. That is, the
171 stream obtained with @c GetStream() will continue its existance
172 after the wxFSFile object is deleted. You will have to delete
173 the stream yourself.
174 */
175 void DetachStream();
176
177 /**
178 Returns anchor (if present). The term of @b anchor can be easily
179 explained using few examples:
3c4f71cc 180
23324ae1
FM
181 Usually an anchor is presented only if the MIME type is 'text/html'.
182 But it may have some meaning with other files;
183 for example myanim.avi#200 may refer to position in animation
184 or reality.wrl#MyView may refer to a predefined view in VRML.
185 */
328f5751 186 const wxString GetAnchor() const;
23324ae1
FM
187
188 /**
7c913512 189 Returns full location of the file, including path and protocol.
23324ae1
FM
190 Examples :
191 */
328f5751 192 const wxString GetLocation() const;
23324ae1
FM
193
194 /**
195 Returns the MIME type of the content of this file. It is either
196 extension-based (see wxMimeTypesManager) or extracted from
197 HTTP protocol Content-Type header.
198 */
328f5751 199 const wxString GetMimeType() const;
23324ae1
FM
200
201 /**
202 Returns time when this file was modified.
203 */
328f5751 204 wxDateTime GetModificationTime() const;
23324ae1
FM
205
206 /**
207 Returns pointer to the stream. You can use the returned
208 stream to directly access data. You may suppose
209 that the stream provide Seek and GetSize functionality
210 (even in the case of the HTTP protocol which doesn't provide
211 this by default. wxHtml uses local cache to work around
212 this and to speed up the connection).
213 */
328f5751 214 wxInputStream* GetStream() const;
23324ae1
FM
215};
216
217
e54c96f1 218
23324ae1
FM
219/**
220 @class wxFileSystemHandler
221 @wxheader{filesys.h}
7c913512 222
23324ae1
FM
223 Classes derived from wxFileSystemHandler are used
224 to access virtual file systems. Its public interface consists
7c913512
FM
225 of two methods: wxFileSystemHandler::CanOpen
226 and wxFileSystemHandler::OpenFile.
23324ae1
FM
227 It provides additional protected methods to simplify the process
228 of opening the file: GetProtocol, GetLeftLocation, GetRightLocation,
229 GetAnchor, GetMimeTypeFromExt.
7c913512 230
e54c96f1 231 Please have a look at overview() if you don't know how locations
23324ae1 232 are constructed.
7c913512 233
23324ae1 234 Also consult @ref overview_fs "list of available handlers".
7c913512 235
23324ae1
FM
236 @b wxPerl note: In wxPerl, you need to derive your file system handler class
237 from Wx::PlFileSystemHandler.
7c913512 238
23324ae1
FM
239 @library{wxbase}
240 @category{vfs}
7c913512 241
e54c96f1 242 @see wxFileSystem, wxFSFile, Overview()
23324ae1
FM
243*/
244class wxFileSystemHandler : public wxObject
245{
246public:
247 /**
248 Constructor.
249 */
250 wxFileSystemHandler();
251
252 /**
253 Returns @true if the handler is able to open this file. This function doesn't
254 check whether the file exists or not, it only checks if it knows the protocol.
255 Example:
3c4f71cc 256
23324ae1
FM
257 Must be overridden in derived handlers.
258 */
259 virtual bool CanOpen(const wxString& location);
260
261 /**
e54c96f1 262 Works like wxFindFirstFile(). Returns name of the first
4cc4bfaf 263 filename (within filesystem's current path) that matches @e wildcard. @a flags
23324ae1
FM
264 may be one of
265 wxFILE (only files), wxDIR (only directories) or 0 (both).
23324ae1
FM
266 This method is only called if CanOpen() returns @true.
267 */
268 virtual wxString FindFirst(const wxString& wildcard,
269 int flags = 0);
270
271 /**
272 Returns next filename that matches parameters passed to wxFileSystem::FindFirst.
23324ae1
FM
273 This method is only called if CanOpen() returns @true and FindFirst
274 returned a non-empty string.
275 */
276 virtual wxString FindNext();
277
278 /**
279 Returns the anchor if present in the location.
280 See @ref wxFSFile::getanchor wxFSFile for details.
23324ae1 281 Example: GetAnchor("index.htm#chapter2") == "chapter2"
cdbcf4c2 282 @note the anchor is NOT part of the left location.
23324ae1 283 */
328f5751 284 wxString GetAnchor(const wxString& location) const;
23324ae1
FM
285
286 /**
7c913512 287 Returns the left location string extracted from @e location.
23324ae1
FM
288 Example: GetLeftLocation("file:myzipfile.zip#zip:index.htm") ==
289 "file:myzipfile.zip"
290 */
328f5751 291 wxString GetLeftLocation(const wxString& location) const;
23324ae1
FM
292
293 /**
294 Returns the MIME type based on @b extension of @e location. (While
295 wxFSFile::GetMimeType
296 returns real MIME type - either extension-based or queried from HTTP.)
23324ae1
FM
297 Example : GetMimeTypeFromExt("index.htm") == "text/html"
298 */
299 wxString GetMimeTypeFromExt(const wxString& location);
300
301 /**
7c913512 302 Returns the protocol string extracted from @e location.
23324ae1
FM
303 Example: GetProtocol("file:myzipfile.zip#zip:index.htm") == "zip"
304 */
328f5751 305 wxString GetProtocol(const wxString& location) const;
23324ae1
FM
306
307 /**
7c913512 308 Returns the right location string extracted from @e location.
23324ae1
FM
309 Example : GetRightLocation("file:myzipfile.zip#zip:index.htm") == "index.htm"
310 */
328f5751 311 wxString GetRightLocation(const wxString& location) const;
23324ae1
FM
312
313 /**
314 Opens the file and returns wxFSFile pointer or @NULL if failed.
23324ae1 315 Must be overridden in derived handlers.
3c4f71cc 316
7c913512 317 @param fs
4cc4bfaf
FM
318 Parent FS (the FS from that OpenFile was called). See ZIP handler
319 for details of how to use it.
7c913512 320 @param location
4cc4bfaf 321 The absolute location of file.
23324ae1
FM
322 */
323 virtual wxFSFile* OpenFile(wxFileSystem& fs,
324 const wxString& location);
325};
e54c96f1 326