]> git.saurik.com Git - wxWidgets.git/blame - include/wx/filesys.h
Added GetBitmap, GetIcon to wxImageList
[wxWidgets.git] / include / wx / filesys.h
CommitLineData
5526e819
VS
1/////////////////////////////////////////////////////////////////////////////
2// Name: filesys.h
3// Purpose: class for opening files - virtual file system
4// Author: Vaclav Slavik
5// Copyright: (c) 1999 Vaclav Slavik
aaa66113 6// RCS-ID: $Id$
65571936 7// Licence: wxWindows licence
5526e819
VS
8/////////////////////////////////////////////////////////////////////////////
9
10#ifndef __FILESYS_H__
11#define __FILESYS_H__
12
12028905 13#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
af49c4b8 14#pragma interface "filesys.h"
5526e819
VS
15#endif
16
d30e0edd
RR
17#include "wx/setup.h"
18
24528b0c
VS
19#if !wxUSE_STREAMS
20#error You cannot compile virtual file systems without wxUSE_STREAMS
21#endif
22
23#if wxUSE_HTML && !wxUSE_FILESYSTEM
24#error You cannot compile wxHTML without virtual file systems
25#endif
26
27#if wxUSE_FILESYSTEM
d30e0edd
RR
28
29#include "wx/stream.h"
6ee654e6 30#include "wx/datetime.h"
9548c49a 31#include "wx/filename.h"
5526e819 32
446e5259
VS
33class WXDLLIMPEXP_BASE wxFSFile;
34class WXDLLIMPEXP_BASE wxFileSystemHandler;
35class WXDLLIMPEXP_BASE wxFileSystem;
5526e819
VS
36
37//--------------------------------------------------------------------------------
38// wxFSFile
39// This class is a file opened using wxFileSystem. It consists of
40// input stream, location, mime type & optional anchor
41// (in 'index.htm#chapter2', 'chapter2' is anchor)
42//--------------------------------------------------------------------------------
43
bddd7a8d 44class WXDLLIMPEXP_BASE wxFSFile : public wxObject
5526e819 45{
19008b7b 46public:
46837272 47 wxFSFile(wxInputStream *stream, const wxString& loc,
e2b87f38
VZ
48 const wxString& mimetype, const wxString& anchor
49#if wxUSE_DATETIME
50 , wxDateTime modif
51#endif // wxUSE_DATETIME
52 )
19008b7b
VS
53 {
54 m_Stream = stream;
55 m_Location = loc;
56 m_MimeType = mimetype; m_MimeType.MakeLower();
57 m_Anchor = anchor;
e2b87f38 58#if wxUSE_DATETIME
19008b7b 59 m_Modif = modif;
e2b87f38 60#endif // wxUSE_DATETIME
19008b7b 61 }
e2b87f38 62
19008b7b
VS
63 virtual ~wxFSFile() { if (m_Stream) delete m_Stream; }
64
65 // returns stream. This doesn't _create_ stream, it only returns
ae500232 66 // pointer to it.
19008b7b
VS
67 wxInputStream *GetStream() const {return m_Stream;}
68
69 // returns file's mime type
70 const wxString& GetMimeType() const {return m_MimeType;}
71
72 // returns the original location (aka filename) of the file
73 const wxString& GetLocation() const {return m_Location;}
74
75 const wxString& GetAnchor() const {return m_Anchor;}
76
e2b87f38 77#if wxUSE_DATETIME
19008b7b 78 wxDateTime GetModificationTime() const {return m_Modif;}
e2b87f38 79#endif // wxUSE_DATETIME
19008b7b
VS
80
81private:
82 wxInputStream *m_Stream;
83 wxString m_Location;
84 wxString m_MimeType;
85 wxString m_Anchor;
e2b87f38 86#if wxUSE_DATETIME
19008b7b 87 wxDateTime m_Modif;
e2b87f38 88#endif // wxUSE_DATETIME
46837272
RD
89
90 DECLARE_ABSTRACT_CLASS(wxFSFile)
22f3361e 91 DECLARE_NO_COPY_CLASS(wxFSFile)
5526e819
VS
92};
93
94
95
96
97
98//--------------------------------------------------------------------------------
99// wxFileSystemHandler
100// This class is FS handler for wxFileSystem. It provides
101// interface to access certain
102// kinds of files (HTPP, FTP, local, tar.gz etc..)
103//--------------------------------------------------------------------------------
104
bddd7a8d 105class WXDLLIMPEXP_BASE wxFileSystemHandler : public wxObject
5526e819 106{
19008b7b
VS
107public:
108 wxFileSystemHandler() : wxObject() {}
109
a62848fd 110 // returns true if this handler is able to open given location
19008b7b
VS
111 virtual bool CanOpen(const wxString& location) = 0;
112
113 // opens given file and returns pointer to input stream.
114 // Returns NULL if opening failed.
115 // The location is always absolute path.
116 virtual wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location) = 0;
117
118 // Finds first/next file that matches spec wildcard. flags can be wxDIR for restricting
119 // the query to directories or wxFILE for files only or 0 for either.
120 // Returns filename or empty string if no more matching file exists
121 virtual wxString FindFirst(const wxString& spec, int flags = 0);
122 virtual wxString FindNext();
123
124protected:
125 // returns protocol ("file", "http", "tar" etc.) The last (most right)
126 // protocol is used:
127 // {it returns "tar" for "file:subdir/archive.tar.gz#tar:/README.txt"}
128 wxString GetProtocol(const wxString& location) const;
129
130 // returns left part of address:
131 // {it returns "file:subdir/archive.tar.gz" for "file:subdir/archive.tar.gz#tar:/README.txt"}
132 wxString GetLeftLocation(const wxString& location) const;
133
134 // returns anchor part of address:
135 // {it returns "anchor" for "file:subdir/archive.tar.gz#tar:/README.txt#anchor"}
136 // NOTE: anchor is NOT a part of GetLeftLocation()'s return value
137 wxString GetAnchor(const wxString& location) const;
138
139 // returns right part of address:
140 // {it returns "/README.txt" for "file:subdir/archive.tar.gz#tar:/README.txt"}
141 wxString GetRightLocation(const wxString& location) const;
142
143 // Returns MIME type of the file - w/o need to open it
144 // (default behaviour is that it returns type based on extension)
145 wxString GetMimeTypeFromExt(const wxString& location);
5526e819 146
19008b7b 147 DECLARE_ABSTRACT_CLASS(wxFileSystemHandler)
5526e819
VS
148};
149
150
151
152
153//--------------------------------------------------------------------------------
154// wxFileSystem
155// This class provides simple interface for opening various
156// kinds of files (HTPP, FTP, local, tar.gz etc..)
157//--------------------------------------------------------------------------------
158
bddd7a8d 159class WXDLLIMPEXP_BASE wxFileSystem : public wxObject
5526e819 160{
19008b7b 161public:
bf07249c
VZ
162 wxFileSystem() : wxObject() { m_FindFileHandler = NULL;}
163 virtual ~wxFileSystem() { }
19008b7b
VS
164
165 // sets the current location. Every call to OpenFile is
166 // relative to this location.
167 // NOTE !!
a62848fd 168 // unless is_dir = true 'location' is *not* the directory but
19008b7b
VS
169 // file contained in this directory
170 // (so ChangePathTo("dir/subdir/xh.htm") sets m_Path to "dir/subdir/")
a62848fd 171 void ChangePathTo(const wxString& location, bool is_dir = false);
19008b7b
VS
172
173 wxString GetPath() const {return m_Path;}
174
175 // opens given file and returns pointer to input stream.
176 // Returns NULL if opening failed.
177 // It first tries to open the file in relative scope
178 // (based on ChangePathTo()'s value) and then as an absolute
179 // path.
180 wxFSFile* OpenFile(const wxString& location);
181
182 // Finds first/next file that matches spec wildcard. flags can be wxDIR for restricting
183 // the query to directories or wxFILE for files only or 0 for either.
184 // Returns filename or empty string if no more matching file exists
185 wxString FindFirst(const wxString& spec, int flags = 0);
186 wxString FindNext();
187
188 // Adds FS handler.
189 // In fact, this class is only front-end to the FS hanlers :-)
190 static void AddHandler(wxFileSystemHandler *handler);
191
192 // remove all items from the m_Handlers list
193 static void CleanUpHandlers();
194
2b5f62a0 195 // Returns the native path for a file URL
9548c49a 196 static wxFileName URLToFileName(const wxString& url);
2b5f62a0
VZ
197
198 // Returns the file URL for a native path
9548c49a 199 static wxString FileNameToURL(const wxFileName& filename);
2b5f62a0
VZ
200
201
19008b7b
VS
202protected:
203 wxString m_Path;
204 // the path (location) we are currently in
205 // this is path, not file!
206 // (so if you opened test/demo.htm, it is
207 // "test/", not "test/demo.htm")
208 wxString m_LastName;
209 // name of last opened file (full path)
210 static wxList m_Handlers;
211 // list of FS handlers
212 wxFileSystemHandler *m_FindFileHandler;
213 // handler that succeed in FindFirst query
5526e819 214
19008b7b 215 DECLARE_DYNAMIC_CLASS(wxFileSystem)
22f3361e 216 DECLARE_NO_COPY_CLASS(wxFileSystem)
5526e819
VS
217};
218
219
220/*
221
222'location' syntax:
223
224To determine FS type, we're using standard KDE notation:
225file:/absolute/path/file.htm
226file:relative_path/xxxxx.html
227/some/path/x.file ('file:' is default)
228http://www.gnome.org
229file:subdir/archive.tar.gz#tar:/README.txt
230
231special characters :
232 ':' - FS identificator is before this char
233 '#' - separator. It can be either HTML anchor ("index.html#news")
234 (in case there is no ':' in the string to the right from it)
235 or FS separator
236 (example : http://www.wxhtml.org/wxhtml-0.1.tar.gz#tar:/include/wxhtml/filesys.h"
237 this would access tgz archive stored on web)
238 '/' - directory (path) separator. It is used to determine upper-level path.
239 HEY! Don't use \ even if you're on Windows!
240
241*/
242
19008b7b 243
bddd7a8d 244class WXDLLIMPEXP_BASE wxLocalFSHandler : public wxFileSystemHandler
19008b7b
VS
245{
246public:
247 virtual bool CanOpen(const wxString& location);
248 virtual wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
249 virtual wxString FindFirst(const wxString& spec, int flags = 0);
250 virtual wxString FindNext();
46837272 251
19008b7b
VS
252 // wxLocalFSHandler will prefix all filenames with 'root' before accessing
253 // files on disk. This effectively makes 'root' the top-level directory
46837272 254 // and prevents access to files outside this directory.
19008b7b
VS
255 // (This is similar to Unix command 'chroot'.)
256 static void Chroot(const wxString& root) { ms_root = root; }
46837272 257
19008b7b
VS
258protected:
259 static wxString ms_root;
260};
261
262
263
d30e0edd 264#endif
24528b0c 265 // wxUSE_FILESYSTEM
d30e0edd 266
269e8200 267#endif
d30e0edd 268 // __FILESYS_H__