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