From 69cce151786fff258571659c6c5ef1b50a64ec58 Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Sun, 17 Jun 2007 10:59:01 +0000 Subject: [PATCH] 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 --- docs/latex/wx/fsfile.tex | 4 +++- include/wx/filesys.h | 20 ++++++++++---------- src/common/filesys.cpp | 33 ++++++++++++++++++++++++++------- src/common/fs_arc.cpp | 2 +- src/common/fs_inet.cpp | 1 - src/common/fs_mem.cpp | 2 +- src/html/chm.cpp | 4 +--- 7 files changed, 42 insertions(+), 24 deletions(-) diff --git a/docs/latex/wx/fsfile.tex b/docs/latex/wx/fsfile.tex index 50b13411d4..0f24e1a37b 100644 --- a/docs/latex/wx/fsfile.tex +++ b/docs/latex/wx/fsfile.tex @@ -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{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.} diff --git a/include/wx/filesys.h b/include/wx/filesys.h index 69d4ffd284..686c64ac0c 100644 --- a/include/wx/filesys.h +++ b/include/wx/filesys.h @@ -50,7 +50,7 @@ public: { 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; @@ -78,7 +78,7 @@ public: } // 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; } @@ -132,28 +132,28 @@ public: 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) }; diff --git a/src/common/filesys.cpp b/src/common/filesys.cpp index f3ef6a7209..8488c57702 100644 --- a/src/common/filesys.cpp +++ b/src/common/filesys.cpp @@ -29,14 +29,29 @@ #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; @@ -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; 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; bool fnd = false; @@ -150,7 +167,8 @@ wxString wxFileSystemHandler::GetLeftLocation(const wxString& location) const 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; @@ -166,7 +184,8 @@ wxString wxFileSystemHandler::GetRightLocation(const wxString& location) const 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(); @@ -230,7 +249,7 @@ wxFSFile* wxLocalFSHandler::OpenFile(wxFileSystem& WXUNUSED(fs), const wxString& return new wxFSFile(is, right, - GetMimeTypeFromExt(location), + wxEmptyString, GetAnchor(location) #if wxUSE_DATETIME ,wxDateTime(wxFileModificationTime(fullpath)) diff --git a/src/common/fs_arc.cpp b/src/common/fs_arc.cpp index 0a16addb22..ff639417dd 100644 --- a/src/common/fs_arc.cpp +++ b/src/common/fs_arc.cpp @@ -413,7 +413,7 @@ wxFSFile* wxArchiveFSHandler::OpenFile( return new wxFSFile(s, key + right, - GetMimeTypeFromExt(location), + wxEmptyString, GetAnchor(location) #if wxUSE_DATETIME , entry->GetDateTime() diff --git a/src/common/fs_inet.cpp b/src/common/fs_inet.cpp index ce26c59f8c..835cf15a7e 100644 --- a/src/common/fs_inet.cpp +++ b/src/common/fs_inet.cpp @@ -107,7 +107,6 @@ wxFSFile* wxInternetFSHandler::OpenFile(wxFileSystem& WXUNUSED(fs), { wxInputStream *s = url.GetInputStream(); wxString content = url.GetProtocol().GetContentType(); - if (content == wxEmptyString) content = GetMimeTypeFromExt(location); if (s) { wxString tmpfile = diff --git a/src/common/fs_mem.cpp b/src/common/fs_mem.cpp index 52fbc0649e..aed198aa5a 100644 --- a/src/common/fs_mem.cpp +++ b/src/common/fs_mem.cpp @@ -122,7 +122,7 @@ wxFSFile* wxMemoryFSHandlerBase::OpenFile(wxFileSystem& WXUNUSED(fs), const wxSt 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 diff --git a/src/html/chm.cpp b/src/html/chm.cpp index 70dbf61886..b8f65ab9c0 100644 --- a/src/html/chm.cpp +++ b/src/html/chm.cpp @@ -825,13 +825,11 @@ wxFSFile* wxChmFSHandler::OpenFile(wxFileSystem& WXUNUSED(fs), // 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))); } -- 2.45.2