]> git.saurik.com Git - wxWidgets.git/blame - include/wx/filesys.h
Add exemple for redirecting cout
[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$
5526e819
VS
7// Licence: wxWindows Licence
8/////////////////////////////////////////////////////////////////////////////
9
10#ifndef __FILESYS_H__
11#define __FILESYS_H__
12
13#ifdef __GNUG__
14#pragma interface
15#endif
16
d30e0edd
RR
17#include "wx/setup.h"
18
f22e0c3c 19#if (wxUSE_HTML || wxUSE_FS_INET || wxUSE_FS_ZIP) && wxUSE_STREAMS
d30e0edd
RR
20
21#include "wx/stream.h"
d30e0edd 22#include "wx/url.h"
6ee654e6 23#include "wx/datetime.h"
5526e819
VS
24
25class wxFSFile;
26class wxFileSystemHandler;
27class wxFileSystem;
28
29//--------------------------------------------------------------------------------
30// wxFSFile
31// This class is a file opened using wxFileSystem. It consists of
32// input stream, location, mime type & optional anchor
33// (in 'index.htm#chapter2', 'chapter2' is anchor)
34//--------------------------------------------------------------------------------
35
36class WXDLLEXPORT wxFSFile : public wxObject
37{
38 private:
39 wxInputStream *m_Stream;
40 wxString m_Location;
41 wxString m_MimeType;
42 wxString m_Anchor;
6ee654e6 43 wxDateTime m_Modif;
5526e819
VS
44
45 public:
6ee654e6
VS
46 wxFSFile(wxInputStream *stream, const wxString& loc,
47 const wxString& mimetype, const wxString& anchor,
48 wxDateTime modif)
5526e819
VS
49 {
50 m_Stream = stream;
51 m_Location = loc;
52 m_MimeType = mimetype; m_MimeType.MakeLower();
53 m_Anchor = anchor;
6ee654e6 54 m_Modif = modif;
5526e819
VS
55 }
56 virtual ~wxFSFile()
57 {
58 if (m_Stream) delete m_Stream;
59 }
60
61 wxInputStream *GetStream() const {return m_Stream;}
62 // returns stream. This doesn't _create_ stream, it only returns
63 // pointer to it!!
64
65 const wxString& GetMimeType() const {return m_MimeType;}
66 // returns file's mime type
67
68 const wxString& GetLocation() const {return m_Location;}
69 // returns the original location (aka filename) of the file
70
71 const wxString& GetAnchor() const {return m_Anchor;}
6ee654e6
VS
72
73 wxDateTime GetModificationTime() const {return m_Modif;}
5526e819
VS
74};
75
76
77
78
79
80//--------------------------------------------------------------------------------
81// wxFileSystemHandler
82// This class is FS handler for wxFileSystem. It provides
83// interface to access certain
84// kinds of files (HTPP, FTP, local, tar.gz etc..)
85//--------------------------------------------------------------------------------
86
87class WXDLLEXPORT wxFileSystemHandler : public wxObject
88{
89 DECLARE_ABSTRACT_CLASS(wxFileSystemHandler)
90
91 public:
92 wxFileSystemHandler() : wxObject() {}
93
94 virtual bool CanOpen(const wxString& location) = 0;
95 // returns TRUE if this handler is able to open given location
96
97 virtual wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location) = 0;
98 // opens given file and returns pointer to input stream.
99 // Returns NULL if opening failed.
100 // The location is always absolute path.
101
aaa66113
VS
102 virtual wxString FindFirst(const wxString& spec, int flags = 0);
103 virtual wxString FindNext();
104 // Finds first/next file that matches spec wildcard. flags can be wxDIR for restricting
105 // the query to directories or wxFILE for files only or 0 for either.
106 // Returns filename or empty string if no more matching file exists
107
5526e819
VS
108 protected:
109 wxString GetProtocol(const wxString& location) const;
110 // returns protocol ("file", "http", "tar" etc.) The last (most right)
111 // protocol is used:
112 // {it returns "tar" for "file:subdir/archive.tar.gz#tar:/README.txt"}
113
114 wxString GetLeftLocation(const wxString& location) const;
115 // returns left part of address:
116 // {it returns "file:subdir/archive.tar.gz" for "file:subdir/archive.tar.gz#tar:/README.txt"}
117
118 wxString GetAnchor(const wxString& location) const;
119 // returns anchor part of address:
120 // {it returns "anchor" for "file:subdir/archive.tar.gz#tar:/README.txt#anchor"}
121 // NOTE: anchor is NOT a part of GetLeftLocation()'s return value
122
123 wxString GetRightLocation(const wxString& location) const;
124 // returns right part of address:
125 // {it returns "/README.txt" for "file:subdir/archive.tar.gz#tar:/README.txt"}
126
127 wxString GetMimeTypeFromExt(const wxString& location);
128 // Returns MIME type of the file - w/o need to open it
129 // (default behaviour is that it returns type based on extension)
5526e819
VS
130};
131
132
133
134
135//--------------------------------------------------------------------------------
136// wxFileSystem
137// This class provides simple interface for opening various
138// kinds of files (HTPP, FTP, local, tar.gz etc..)
139//--------------------------------------------------------------------------------
140
141class WXDLLEXPORT wxFileSystem : public wxObject
142{
143 DECLARE_DYNAMIC_CLASS(wxFileSystem)
144
5526e819 145 public:
aaa66113 146 wxFileSystem() : wxObject() {m_Path = m_LastName = wxEmptyString; m_Handlers.DeleteContents(TRUE); m_FindFileHandler = NULL;}
5526e819
VS
147
148 void ChangePathTo(const wxString& location, bool is_dir = FALSE);
149 // sets the current location. Every call to OpenFile is
150 // relative to this location.
151 // NOTE !!
152 // unless is_dir = TRUE 'location' is *not* the directory but
153 // file contained in this directory
154 // (so ChangePathTo("dir/subdir/xh.htm") sets m_Path to "dir/subdir/")
269e8200 155
f22e0c3c 156 wxString GetPath() const {return m_Path;}
5526e819
VS
157
158 wxFSFile* OpenFile(const wxString& location);
159 // opens given file and returns pointer to input stream.
160 // Returns NULL if opening failed.
161 // It first tries to open the file in relative scope
162 // (based on ChangePathTo()'s value) and then as an absolute
163 // path.
aaa66113
VS
164
165 wxString FindFirst(const wxString& spec, int flags = 0);
166 wxString FindNext();
167 // Finds first/next file that matches spec wildcard. flags can be wxDIR for restricting
168 // the query to directories or wxFILE for files only or 0 for either.
169 // Returns filename or empty string if no more matching file exists
170
5526e819
VS
171
172 static void AddHandler(wxFileSystemHandler *handler);
173 // Adds FS handler.
174 // In fact, this class is only front-end to the FS hanlers :-)
269e8200
RD
175
176 static void CleanUpHandlers();
177 // remove all items from the m_Handlers list
aaa66113
VS
178
179 private:
180 wxString m_Path;
181 // the path (location) we are currently in
182 // this is path, not file!
183 // (so if you opened test/demo.htm, it is
184 // "test/", not "test/demo.htm")
185 wxString m_LastName;
186 // name of last opened file (full path)
187 static wxList m_Handlers;
188 // list of FS handlers
189 wxFileSystemHandler *m_FindFileHandler;
190 // handler that succeed in FindFirst query
5526e819
VS
191};
192
193
194/*
195
196'location' syntax:
197
198To determine FS type, we're using standard KDE notation:
199file:/absolute/path/file.htm
200file:relative_path/xxxxx.html
201/some/path/x.file ('file:' is default)
202http://www.gnome.org
203file:subdir/archive.tar.gz#tar:/README.txt
204
205special characters :
206 ':' - FS identificator is before this char
207 '#' - separator. It can be either HTML anchor ("index.html#news")
208 (in case there is no ':' in the string to the right from it)
209 or FS separator
210 (example : http://www.wxhtml.org/wxhtml-0.1.tar.gz#tar:/include/wxhtml/filesys.h"
211 this would access tgz archive stored on web)
212 '/' - directory (path) separator. It is used to determine upper-level path.
213 HEY! Don't use \ even if you're on Windows!
214
215*/
216
d30e0edd
RR
217#endif
218 // (wxUSE_FS_INET || wxUSE_FS_ZIP) && wxUSE_STREAMS
219
269e8200 220#endif
d30e0edd 221 // __FILESYS_H__