rewritten to use wxTheMimeTypesManager

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5539 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2000-01-19 23:06:59 +00:00
parent d2a190fe37
commit 737255678c
3 changed files with 11 additions and 31 deletions

View File

@@ -19,7 +19,6 @@
#if (wxUSE_HTML || wxUSE_FS_INET || wxUSE_FS_ZIP) && wxUSE_STREAMS #if (wxUSE_HTML || wxUSE_FS_INET || wxUSE_FS_ZIP) && wxUSE_STREAMS
#include "wx/stream.h" #include "wx/stream.h"
#include "wx/mimetype.h"
#include "wx/url.h" #include "wx/url.h"
#include "wx/datetime.h" #include "wx/datetime.h"
@@ -128,17 +127,6 @@ class WXDLLEXPORT wxFileSystemHandler : public wxObject
wxString GetMimeTypeFromExt(const wxString& location); wxString GetMimeTypeFromExt(const wxString& location);
// Returns MIME type of the file - w/o need to open it // Returns MIME type of the file - w/o need to open it
// (default behaviour is that it returns type based on extension) // (default behaviour is that it returns type based on extension)
public:
static void CleanUpStatics();
// deletes static members (m_MimeMng). It can be called
// as many times as you wish because m_MimeMng is created
// on demand
private:
static wxMimeTypesManager *m_MimeMng;
// MIME manager
// (it's static and thus shared by all instances and derived classes)
}; };

View File

@@ -26,6 +26,10 @@
#include "wx/wfstream.h" #include "wx/wfstream.h"
#include "wx/module.h" #include "wx/module.h"
#include "wx/filesys.h" #include "wx/filesys.h"
#include "wx/mimetype.h"
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
// wxFileSystemHandler // wxFileSystemHandler
@@ -33,14 +37,6 @@
IMPLEMENT_ABSTRACT_CLASS(wxFileSystemHandler, wxObject) IMPLEMENT_ABSTRACT_CLASS(wxFileSystemHandler, wxObject)
wxMimeTypesManager *wxFileSystemHandler::m_MimeMng = NULL;
void wxFileSystemHandler::CleanUpStatics()
{
if (m_MimeMng) delete m_MimeMng;
m_MimeMng = NULL;
}
wxString wxFileSystemHandler::GetMimeTypeFromExt(const wxString& location) wxString wxFileSystemHandler::GetMimeTypeFromExt(const wxString& location)
{ {
@@ -58,9 +54,8 @@ wxString wxFileSystemHandler::GetMimeTypeFromExt(const wxString& location)
if ((c == wxT('/')) || (c == wxT('\\')) || (c == wxT(':'))) {return wxEmptyString;} if ((c == wxT('/')) || (c == wxT('\\')) || (c == wxT(':'))) {return wxEmptyString;}
} }
if (m_MimeMng == NULL) { static bool s_MinimalMimeEnsured = FALSE;
m_MimeMng = new wxMimeTypesManager; if (!s_MinimalMimeEnsured) {
static const wxFileTypeInfo fallbacks[] = static const wxFileTypeInfo fallbacks[] =
{ {
wxFileTypeInfo("image/jpeg", wxFileTypeInfo("image/jpeg",
@@ -93,10 +88,10 @@ wxString wxFileSystemHandler::GetMimeTypeFromExt(const wxString& location)
wxFileTypeInfo() wxFileTypeInfo()
}; };
m_MimeMng -> AddFallbacks(fallbacks); wxTheMimeTypesManager -> AddFallbacks(fallbacks);
} }
ft = m_MimeMng -> GetFileTypeFromExtension(ext); ft = wxTheMimeTypesManager -> GetFileTypeFromExtension(ext);
if (ft && (ft -> GetMimeType(&mime))) { if (ft && (ft -> GetMimeType(&mime))) {
delete ft; delete ft;
return mime; return mime;
@@ -412,7 +407,6 @@ class wxFileSystemModule : public wxModule
} }
virtual void OnExit() virtual void OnExit()
{ {
wxFileSystemHandler::CleanUpStatics();
wxFileSystem::CleanUpHandlers(); wxFileSystem::CleanUpHandlers();
} }
}; };

View File

@@ -84,7 +84,6 @@ class wxFileIconsTable
protected: protected:
wxImageList m_ImageList; wxImageList m_ImageList;
wxHashTable m_HashTable; wxHashTable m_HashTable;
wxMimeTypesManager m_Mime;
}; };
static wxFileIconsTable *g_IconsTable = NULL; static wxFileIconsTable *g_IconsTable = NULL;
@@ -95,8 +94,7 @@ static wxFileIconsTable *g_IconsTable = NULL;
wxFileIconsTable::wxFileIconsTable() : wxFileIconsTable::wxFileIconsTable() :
m_ImageList(16, 16), m_ImageList(16, 16),
m_HashTable(wxKEY_STRING), m_HashTable(wxKEY_STRING)
m_Mime()
{ {
m_HashTable.DeleteContents(TRUE); m_HashTable.DeleteContents(TRUE);
m_ImageList.Add(wxBitmap(folder_xpm)); // FI_FOLDER m_ImageList.Add(wxBitmap(folder_xpm)); // FI_FOLDER
@@ -172,8 +170,8 @@ int wxFileIconsTable::GetIconID(const wxString& extension, const wxString& mime)
} }
wxFileType *ft = (mime.IsEmpty()) ? wxFileType *ft = (mime.IsEmpty()) ?
m_Mime.GetFileTypeFromExtension(extension) : wxTheMimeTypesManager -> GetFileTypeFromExtension(extension) :
m_Mime.GetFileTypeFromMimeType(mime); wxTheMimeTypesManager -> GetFileTypeFromMimeType(mime);
wxIcon ic; wxIcon ic;
if (ft == NULL || (!ft -> GetIcon(&ic))) if (ft == NULL || (!ft -> GetIcon(&ic)))
{ {