]>
Commit | Line | Data |
---|---|---|
37671b82 | 1 | ///////////////////////////////////////////////////////////////////////////// |
8aa3cd14 | 2 | // Name: src/common/fs_filter.cpp |
37671b82 MW |
3 | // Purpose: wxFilter file system handler |
4 | // Author: Mike Wetherell | |
5 | // Copyright: (c) 2006 Mike Wetherell | |
37671b82 MW |
6 | // Licence: wxWindows licence |
7 | ///////////////////////////////////////////////////////////////////////////// | |
8 | ||
9 | #include "wx/wxprec.h" | |
10 | ||
11 | #ifdef __BORLANDC__ | |
8aa3cd14 | 12 | #pragma hdrstop |
37671b82 MW |
13 | #endif |
14 | ||
15 | #if wxUSE_FILESYSTEM | |
16 | ||
17 | #include "wx/fs_filter.h" | |
18 | ||
b4f4d3dd | 19 | #ifndef WX_PRECOMP |
37671b82 MW |
20 | #endif |
21 | ||
664e1314 | 22 | #include "wx/scopedptr.h" |
37671b82 MW |
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; | |
8aa3cd14 | 43 | |
37671b82 MW |
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 | ||
34eeb223 | 58 | wxInputStreamPtr stream(factory->NewStream(leftStream.release())); |
37671b82 MW |
59 | |
60 | // The way compressed streams are supposed to be served is e.g.: | |
8aa3cd14 WS |
61 | // Content-type: application/postscript |
62 | // Content-encoding: gzip | |
37671b82 MW |
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 | ||
8aa3cd14 | 81 | wxString wxFilterFSHandler::FindFirst(const wxString& WXUNUSED(spec), int WXUNUSED(flags)) |
37671b82 MW |
82 | { |
83 | return wxEmptyString; | |
84 | } | |
85 | ||
86 | wxString wxFilterFSHandler::FindNext() | |
87 | { | |
88 | return wxEmptyString; | |
89 | } | |
90 | ||
91 | #endif //wxUSE_FILESYSTEM |