\docparam{location}{The full location (aka filename) of the file}
-\docparam{mimetype}{MIME type of this file. Mime type is either extension-based or HTTP Content-Type}
+\docparam{mimetype}{MIME type of this file. It may be left empty, in which
+case the type will be determined from file's extension (\arg{location} must
+not be empty in this case).}
\docparam{anchor}{Anchor. See \helpref{GetAnchor()}{wxfsfilegetanchor} for details.}
{
m_Stream = stream;
m_Location = loc;
- m_MimeType = mimetype; m_MimeType.MakeLower();
+ m_MimeType = mimetype.Lower();
m_Anchor = anchor;
#if wxUSE_DATETIME
m_Modif = modif;
}
// returns file's mime type
- const wxString& GetMimeType() const { return m_MimeType; }
+ const wxString& GetMimeType() const;
// returns the original location (aka filename) of the file
const wxString& GetLocation() const { return m_Location; }
virtual wxString FindFirst(const wxString& spec, int flags = 0);
virtual wxString FindNext();
+ // Returns MIME type of the file - w/o need to open it
+ // (default behaviour is that it returns type based on extension)
+ static wxString GetMimeTypeFromExt(const wxString& location);
+
protected:
// returns protocol ("file", "http", "tar" etc.) The last (most right)
// protocol is used:
// {it returns "tar" for "file:subdir/archive.tar.gz#tar:/README.txt"}
- wxString GetProtocol(const wxString& location) const;
+ static wxString GetProtocol(const wxString& location);
// returns left part of address:
// {it returns "file:subdir/archive.tar.gz" for "file:subdir/archive.tar.gz#tar:/README.txt"}
- wxString GetLeftLocation(const wxString& location) const;
+ static wxString GetLeftLocation(const wxString& location);
// returns anchor part of address:
// {it returns "anchor" for "file:subdir/archive.tar.gz#tar:/README.txt#anchor"}
// NOTE: anchor is NOT a part of GetLeftLocation()'s return value
- wxString GetAnchor(const wxString& location) const;
+ static wxString GetAnchor(const wxString& location);
// returns right part of address:
// {it returns "/README.txt" for "file:subdir/archive.tar.gz#tar:/README.txt"}
- wxString GetRightLocation(const wxString& location) const;
-
- // Returns MIME type of the file - w/o need to open it
- // (default behaviour is that it returns type based on extension)
- wxString GetMimeTypeFromExt(const wxString& location);
+ static wxString GetRightLocation(const wxString& location);
DECLARE_ABSTRACT_CLASS(wxFileSystemHandler)
};
#include "wx/tokenzr.h"
#include "wx/private/fileback.h"
+// ----------------------------------------------------------------------------
+// wxFSFile
+// ----------------------------------------------------------------------------
-//--------------------------------------------------------------------------------
+const wxString& wxFSFile::GetMimeType() const
+{
+ if ( m_MimeType.empty() && !m_Location.empty() )
+ {
+ wxConstCast(this, wxFSFile)->m_MimeType =
+ wxFileSystemHandler::GetMimeTypeFromExt(m_Location);
+ }
+
+ return m_MimeType;
+}
+
+// ----------------------------------------------------------------------------
// wxFileSystemHandler
-//--------------------------------------------------------------------------------
+// ----------------------------------------------------------------------------
IMPLEMENT_ABSTRACT_CLASS(wxFileSystemHandler, wxObject)
+/* static */
wxString wxFileSystemHandler::GetMimeTypeFromExt(const wxString& location)
{
wxString ext, mime;
-wxString wxFileSystemHandler::GetProtocol(const wxString& location) const
+/* static */
+wxString wxFileSystemHandler::GetProtocol(const wxString& location)
{
wxString s = wxEmptyString;
int i, l = location.length();
}
-wxString wxFileSystemHandler::GetLeftLocation(const wxString& location) const
+/* static */
+wxString wxFileSystemHandler::GetLeftLocation(const wxString& location)
{
int i;
bool fnd = false;
return wxEmptyString;
}
-wxString wxFileSystemHandler::GetRightLocation(const wxString& location) const
+/* static */
+wxString wxFileSystemHandler::GetRightLocation(const wxString& location)
{
int i, l = location.length();
int l2 = l + 1;
else return location.Mid(i + 1, l2 - i - 2);
}
-wxString wxFileSystemHandler::GetAnchor(const wxString& location) const
+/* static */
+wxString wxFileSystemHandler::GetAnchor(const wxString& location)
{
wxChar c;
int l = location.length();
return new wxFSFile(is,
right,
- GetMimeTypeFromExt(location),
+ wxEmptyString,
GetAnchor(location)
#if wxUSE_DATETIME
,wxDateTime(wxFileModificationTime(fullpath))
return new wxFSFile(s,
key + right,
- GetMimeTypeFromExt(location),
+ wxEmptyString,
GetAnchor(location)
#if wxUSE_DATETIME
, entry->GetDateTime()
{
wxInputStream *s = url.GetInputStream();
wxString content = url.GetProtocol().GetContentType();
- if (content == wxEmptyString) content = GetMimeTypeFromExt(location);
if (s)
{
wxString tmpfile =
if (obj == NULL) return NULL;
else return new wxFSFile(new wxMemoryInputStream(obj -> m_Data, obj -> m_Len),
location,
- GetMimeTypeFromExt(location),
+ wxEmptyString,
GetAnchor(location)
#if wxUSE_DATETIME
, obj -> m_Time
// Open a stream to read the content of the chm-file
s = new wxChmInputStream(leftFilename.GetFullPath(), right, true);
- wxString mime = GetMimeTypeFromExt(location);
-
if ( s )
{
return new wxFSFile(s,
left + _T("#chm:") + right,
- mime,
+ wxEmptyString,
GetAnchor(location),
wxDateTime(wxFileModificationTime(left)));
}