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