]> git.saurik.com Git - wxWidgets.git/blob - src/common/fs_filter.cpp
No changes, just fix a typo in a comment in docview event handling code.
[wxWidgets.git] / src / common / fs_filter.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/fs_filter.cpp
3 // Purpose: wxFilter file system handler
4 // Author: Mike Wetherell
5 // Copyright: (c) 2006 Mike Wetherell
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
8
9 #include "wx/wxprec.h"
10
11 #ifdef __BORLANDC__
12 #pragma hdrstop
13 #endif
14
15 #if wxUSE_FILESYSTEM
16
17 #include "wx/fs_filter.h"
18
19 #ifndef WX_PRECOMP
20 #endif
21
22 #include "wx/scopedptr.h"
23
24 wxDEFINE_SCOPED_PTR_TYPE(wxFSFile)
25 wxDEFINE_SCOPED_PTR_TYPE(wxInputStream)
26
27 //----------------------------------------------------------------------------
28 // wxFilterFSHandler
29 //----------------------------------------------------------------------------
30
31 bool wxFilterFSHandler::CanOpen(const wxString& location)
32 {
33 return wxFilterClassFactory::Find(GetProtocol(location)) != NULL;
34 }
35
36 wxFSFile* wxFilterFSHandler::OpenFile(
37 wxFileSystem& fs,
38 const wxString& location)
39 {
40 wxString right = GetRightLocation(location);
41 if (!right.empty())
42 return NULL;
43
44 wxString protocol = GetProtocol(location);
45 const wxFilterClassFactory *factory = wxFilterClassFactory::Find(protocol);
46 if (!factory)
47 return NULL;
48
49 wxString left = GetLeftLocation(location);
50 wxFSFilePtr leftFile(fs.OpenFile(left));
51 if (!leftFile.get())
52 return NULL;
53
54 wxInputStreamPtr leftStream(leftFile->DetachStream());
55 if (!leftStream.get() || !leftStream->IsOk())
56 return NULL;
57
58 wxInputStreamPtr stream(factory->NewStream(leftStream.release()));
59
60 // The way compressed streams are supposed to be served is e.g.:
61 // Content-type: application/postscript
62 // Content-encoding: gzip
63 // So the mime type should be just the mime type of the lhs. However check
64 // whether the mime type is that of this compression format (e.g.
65 // application/gzip). If so pop any extension and try GetMimeTypeFromExt,
66 // e.g. if it were '.ps.gz' pop the '.gz' and try looking up '.ps'
67 wxString mime = leftFile->GetMimeType();
68 if (factory->CanHandle(mime, wxSTREAM_MIMETYPE))
69 mime = GetMimeTypeFromExt(factory->PopExtension(left));
70
71 return new wxFSFile(stream.release(),
72 left + wxT("#") + protocol + wxT(":") + right,
73 mime,
74 GetAnchor(location)
75 #if wxUSE_DATETIME
76 , leftFile->GetModificationTime()
77 #endif // wxUSE_DATETIME
78 );
79 }
80
81 wxString wxFilterFSHandler::FindFirst(const wxString& WXUNUSED(spec), int WXUNUSED(flags))
82 {
83 return wxEmptyString;
84 }
85
86 wxString wxFilterFSHandler::FindNext()
87 {
88 return wxEmptyString;
89 }
90
91 #endif //wxUSE_FILESYSTEM