determine wxFSFile's MIME type when wxFSFile::GetMimeType() is called instead of creating it; this dramatically improves startup times of XRC applications on Unix

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@46503 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík 2007-06-17 10:59:01 +00:00
parent 81c882b613
commit 69cce15178
7 changed files with 42 additions and 24 deletions

View File

@ -43,7 +43,9 @@ Constructor. You probably won't use it. See Notes for details.
\docparam{location}{The full location (aka filename) of the file} \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.} \docparam{anchor}{Anchor. See \helpref{GetAnchor()}{wxfsfilegetanchor} for details.}

View File

@ -50,7 +50,7 @@ public:
{ {
m_Stream = stream; m_Stream = stream;
m_Location = loc; m_Location = loc;
m_MimeType = mimetype; m_MimeType.MakeLower(); m_MimeType = mimetype.Lower();
m_Anchor = anchor; m_Anchor = anchor;
#if wxUSE_DATETIME #if wxUSE_DATETIME
m_Modif = modif; m_Modif = modif;
@ -78,7 +78,7 @@ public:
} }
// returns file's mime type // 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 // returns the original location (aka filename) of the file
const wxString& GetLocation() const { return m_Location; } const wxString& GetLocation() const { return m_Location; }
@ -132,28 +132,28 @@ public:
virtual wxString FindFirst(const wxString& spec, int flags = 0); virtual wxString FindFirst(const wxString& spec, int flags = 0);
virtual wxString FindNext(); 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: protected:
// returns protocol ("file", "http", "tar" etc.) The last (most right) // returns protocol ("file", "http", "tar" etc.) The last (most right)
// protocol is used: // protocol is used:
// {it returns "tar" for "file:subdir/archive.tar.gz#tar:/README.txt"} // {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: // returns left part of address:
// {it returns "file:subdir/archive.tar.gz" for "file:subdir/archive.tar.gz#tar:/README.txt"} // {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: // returns anchor part of address:
// {it returns "anchor" for "file:subdir/archive.tar.gz#tar:/README.txt#anchor"} // {it returns "anchor" for "file:subdir/archive.tar.gz#tar:/README.txt#anchor"}
// NOTE: anchor is NOT a part of GetLeftLocation()'s return value // 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: // returns right part of address:
// {it returns "/README.txt" for "file:subdir/archive.tar.gz#tar:/README.txt"} // {it returns "/README.txt" for "file:subdir/archive.tar.gz#tar:/README.txt"}
wxString GetRightLocation(const wxString& location) const; static wxString GetRightLocation(const wxString& location);
// 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);
DECLARE_ABSTRACT_CLASS(wxFileSystemHandler) DECLARE_ABSTRACT_CLASS(wxFileSystemHandler)
}; };

View File

@ -29,14 +29,29 @@
#include "wx/tokenzr.h" #include "wx/tokenzr.h"
#include "wx/private/fileback.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 // wxFileSystemHandler
//-------------------------------------------------------------------------------- // ----------------------------------------------------------------------------
IMPLEMENT_ABSTRACT_CLASS(wxFileSystemHandler, wxObject) IMPLEMENT_ABSTRACT_CLASS(wxFileSystemHandler, wxObject)
/* static */
wxString wxFileSystemHandler::GetMimeTypeFromExt(const wxString& location) wxString wxFileSystemHandler::GetMimeTypeFromExt(const wxString& location)
{ {
wxString ext, mime; wxString ext, mime;
@ -123,7 +138,8 @@ wxString wxFileSystemHandler::GetMimeTypeFromExt(const wxString& location)
wxString wxFileSystemHandler::GetProtocol(const wxString& location) const /* static */
wxString wxFileSystemHandler::GetProtocol(const wxString& location)
{ {
wxString s = wxEmptyString; wxString s = wxEmptyString;
int i, l = location.length(); int i, l = location.length();
@ -138,7 +154,8 @@ wxString wxFileSystemHandler::GetProtocol(const wxString& location) const
} }
wxString wxFileSystemHandler::GetLeftLocation(const wxString& location) const /* static */
wxString wxFileSystemHandler::GetLeftLocation(const wxString& location)
{ {
int i; int i;
bool fnd = false; bool fnd = false;
@ -150,7 +167,8 @@ wxString wxFileSystemHandler::GetLeftLocation(const wxString& location) const
return wxEmptyString; return wxEmptyString;
} }
wxString wxFileSystemHandler::GetRightLocation(const wxString& location) const /* static */
wxString wxFileSystemHandler::GetRightLocation(const wxString& location)
{ {
int i, l = location.length(); int i, l = location.length();
int l2 = l + 1; int l2 = l + 1;
@ -166,7 +184,8 @@ wxString wxFileSystemHandler::GetRightLocation(const wxString& location) const
else return location.Mid(i + 1, l2 - i - 2); 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; wxChar c;
int l = location.length(); int l = location.length();
@ -230,7 +249,7 @@ wxFSFile* wxLocalFSHandler::OpenFile(wxFileSystem& WXUNUSED(fs), const wxString&
return new wxFSFile(is, return new wxFSFile(is,
right, right,
GetMimeTypeFromExt(location), wxEmptyString,
GetAnchor(location) GetAnchor(location)
#if wxUSE_DATETIME #if wxUSE_DATETIME
,wxDateTime(wxFileModificationTime(fullpath)) ,wxDateTime(wxFileModificationTime(fullpath))

View File

@ -413,7 +413,7 @@ wxFSFile* wxArchiveFSHandler::OpenFile(
return new wxFSFile(s, return new wxFSFile(s,
key + right, key + right,
GetMimeTypeFromExt(location), wxEmptyString,
GetAnchor(location) GetAnchor(location)
#if wxUSE_DATETIME #if wxUSE_DATETIME
, entry->GetDateTime() , entry->GetDateTime()

View File

@ -107,7 +107,6 @@ wxFSFile* wxInternetFSHandler::OpenFile(wxFileSystem& WXUNUSED(fs),
{ {
wxInputStream *s = url.GetInputStream(); wxInputStream *s = url.GetInputStream();
wxString content = url.GetProtocol().GetContentType(); wxString content = url.GetProtocol().GetContentType();
if (content == wxEmptyString) content = GetMimeTypeFromExt(location);
if (s) if (s)
{ {
wxString tmpfile = wxString tmpfile =

View File

@ -122,7 +122,7 @@ wxFSFile* wxMemoryFSHandlerBase::OpenFile(wxFileSystem& WXUNUSED(fs), const wxSt
if (obj == NULL) return NULL; if (obj == NULL) return NULL;
else return new wxFSFile(new wxMemoryInputStream(obj -> m_Data, obj -> m_Len), else return new wxFSFile(new wxMemoryInputStream(obj -> m_Data, obj -> m_Len),
location, location,
GetMimeTypeFromExt(location), wxEmptyString,
GetAnchor(location) GetAnchor(location)
#if wxUSE_DATETIME #if wxUSE_DATETIME
, obj -> m_Time , obj -> m_Time

View File

@ -825,13 +825,11 @@ wxFSFile* wxChmFSHandler::OpenFile(wxFileSystem& WXUNUSED(fs),
// Open a stream to read the content of the chm-file // Open a stream to read the content of the chm-file
s = new wxChmInputStream(leftFilename.GetFullPath(), right, true); s = new wxChmInputStream(leftFilename.GetFullPath(), right, true);
wxString mime = GetMimeTypeFromExt(location);
if ( s ) if ( s )
{ {
return new wxFSFile(s, return new wxFSFile(s,
left + _T("#chm:") + right, left + _T("#chm:") + right,
mime, wxEmptyString,
GetAnchor(location), GetAnchor(location),
wxDateTime(wxFileModificationTime(left))); wxDateTime(wxFileModificationTime(left)));
} }