X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4d2976ad6b56ff1650e15f2b949c10ec92385309..0a1c1e6214827e1d9dc9f6ca2c39567cb2d35ebc:/src/unix/mimetype.cpp diff --git a/src/unix/mimetype.cpp b/src/unix/mimetype.cpp index 8130ffda6e..1b8cf25097 100644 --- a/src/unix/mimetype.cpp +++ b/src/unix/mimetype.cpp @@ -9,8 +9,16 @@ // Licence: wxWindows license (part of wxExtra library) ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ -#pragma implementation "mimetype.h" +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +#ifdef __GNUG__ + #pragma implementation "mimetype.h" #endif // for compilers that support precompilation, includes "wx.h". @@ -24,7 +32,7 @@ #include "wx/defs.h" #endif -#if (wxUSE_FILE && wxUSE_TEXTFILE) || defined(__WXMSW__) +#if wxUSE_FILE && wxUSE_TEXTFILE #ifndef WX_PRECOMP #include "wx/string.h" @@ -54,6 +62,22 @@ // in case we're compiling in non-GUI mode class WXDLLEXPORT wxIcon; +// ---------------------------------------------------------------------------- +// constants +// ---------------------------------------------------------------------------- + +// MIME code tracing mask +#define TRACE_MIME _T("mime") + +// ---------------------------------------------------------------------------- +// private functions +// ---------------------------------------------------------------------------- + +// there are some fields which we don't understand but for which we don't give +// warnings as we know that they're not important - this function is used to +// test for them +static bool IsKnownUnimportantField(const wxString& field); + // ---------------------------------------------------------------------------- // private classes // ---------------------------------------------------------------------------- @@ -138,6 +162,11 @@ public: { m_next = NULL; } + + ~MailCapEntry() + { + if (m_next) delete m_next; + } // accessors const wxString& GetOpenCmd() const { return m_openCmd; } @@ -560,8 +589,14 @@ void wxGNOMEIconHandler::GetMimeInfoRecords(wxMimeTypesManagerImpl *manager) } } +#if wxUSE_GUI + #define WXUNUSED_UNLESS_GUI(p) p +#else + #define WXUNUSED_UNLESS_GUI(p) +#endif -bool wxGNOMEIconHandler::GetIcon(const wxString& mimetype, wxIcon *icon) +bool wxGNOMEIconHandler::GetIcon(const wxString& mimetype, + wxIcon * WXUNUSED_UNLESS_GUI(icon)) { if ( !m_inited ) { @@ -581,8 +616,11 @@ bool wxGNOMEIconHandler::GetIcon(const wxString& mimetype, wxIcon *icon) icn = wxIcon(iconname); else icn = wxIcon(iconname, wxBITMAP_TYPE_ANY); - if (icn.Ok()) *icon = icn; - else return FALSE; + if ( !icn.Ok() ) + return FALSE; + + if ( icon ) + *icon = icn; #else // helpful for testing in console mode wxLogDebug(_T("Found GNOME icon for '%s': '%s'\n"), @@ -789,6 +827,7 @@ void wxKDEIconHandler::Init() dirs.Add(_T("/usr/share")); dirs.Add(_T("/opt/kde/share")); icondirs.Add(_T("/usr/share/icons/")); + icondirs.Add(_T("/usr/X11R6/share/icons/")); // Debian/Corel linux icondirs.Add(_T("/opt/kde/share/icons/")); } @@ -801,7 +840,8 @@ void wxKDEIconHandler::Init() m_inited = TRUE; } -bool wxKDEIconHandler::GetIcon(const wxString& mimetype, wxIcon *icon) +bool wxKDEIconHandler::GetIcon(const wxString& mimetype, + wxIcon * WXUNUSED_UNLESS_GUI(icon)) { if ( !m_inited ) { @@ -821,8 +861,12 @@ bool wxKDEIconHandler::GetIcon(const wxString& mimetype, wxIcon *icon) icn = wxIcon(iconname); else icn = wxIcon(iconname, wxBITMAP_TYPE_ANY); - if (icn.Ok()) *icon = icn; - else return FALSE; + + if ( !icn.Ok() ) + return FALSE; + + if ( icon ) + *icon = icn; #else // helpful for testing in console mode wxLogDebug(_T("Found KDE icon for '%s': '%s'\n"), @@ -856,15 +900,21 @@ wxFileTypeImpl::GetEntry(const wxFileType::MessageParameters& params) const // notice that an empty command would always succeed (it's ok) command = wxFileType::ExpandCommand(entry->GetTestCmd(), params); - if ( command.IsEmpty() || (wxSystem(command) == 0) ) { - // ok, passed - wxLogTrace(wxT("Test '%s' for mime type '%s' succeeded."), - command.c_str(), params.GetMimeType().c_str()); - break; - } - else { - wxLogTrace(wxT("Test '%s' for mime type '%s' failed."), - command.c_str(), params.GetMimeType().c_str()); + // suppress the command output + if ( !command.IsEmpty() ) + { + if ( wxSystem(command) == 0 ) { + // ok, passed + wxLogTrace(TRACE_MIME, + wxT("Test '%s' for mime type '%s' succeeded."), + command.c_str(), params.GetMimeType().c_str()); + break; + } + else { + wxLogTrace(TRACE_MIME, + wxT("Test '%s' for mime type '%s' failed."), + command.c_str(), params.GetMimeType().c_str()); + } } entry = entry->GetNext(); @@ -1026,6 +1076,14 @@ wxMimeTypesManagerImpl::wxMimeTypesManagerImpl() handlers[hn]->GetMimeInfoRecords(this); } + +wxMimeTypesManagerImpl::~wxMimeTypesManagerImpl() +{ + size_t cnt = m_aEntries.GetCount(); + for (size_t i = 0; i < cnt; i++) delete m_aEntries[i]; +} + + wxFileType * wxMimeTypesManagerImpl::GetFileTypeFromExtension(const wxString& ext) { @@ -1161,7 +1219,8 @@ void wxMimeTypesManagerImpl::AddMailcapInfo(const wxString& strType, bool wxMimeTypesManagerImpl::ReadMimeTypes(const wxString& strFileName) { - wxLogTrace(wxT("--- Parsing mime.types file '%s' ---"), strFileName.c_str()); + wxLogTrace(TRACE_MIME, wxT("--- Parsing mime.types file '%s' ---"), + strFileName.c_str()); wxTextFile file(strFileName); if ( !file.Open() ) @@ -1236,8 +1295,9 @@ bool wxMimeTypesManagerImpl::ReadMimeTypes(const wxString& strFileName) } } else { - // unquoted string ends at the first space - for ( pEnd = pc; !wxIsspace(*pEnd); pEnd++ ) + // unquoted string ends at the first space or at the end of + // line + for ( pEnd = pc; *pEnd && !wxIsspace(*pEnd); pEnd++ ) ; } @@ -1316,7 +1376,8 @@ bool wxMimeTypesManagerImpl::ReadMimeTypes(const wxString& strFileName) bool wxMimeTypesManagerImpl::ReadMailcap(const wxString& strFileName, bool fallback) { - wxLogTrace(wxT("--- Parsing mailcap file '%s' ---"), strFileName.c_str()); + wxLogTrace(TRACE_MIME, wxT("--- Parsing mailcap file '%s' ---"), + strFileName.c_str()); wxTextFile file(strFileName); if ( !file.Open() ) @@ -1466,10 +1527,7 @@ bool wxMimeTypesManagerImpl::ReadMailcap(const wxString& strFileName, if ( !ok ) { - // we don't understand this field, but - // Netscape stores info in it, so don't warn - // about it - if ( curField.Left(16u) != "x-mozilla-flags=" ) + if ( !IsKnownUnimportantField(curField) ) { // don't flood the user with error // messages if we don't understand @@ -1609,6 +1667,29 @@ size_t wxMimeTypesManagerImpl::EnumAllFileTypes(wxArrayString& mimetypes) return mimetypes.GetCount(); } +// ---------------------------------------------------------------------------- +// private functions +// ---------------------------------------------------------------------------- + +static bool IsKnownUnimportantField(const wxString& fieldAll) +{ + static const wxChar *knownFields[] = + { + _T("x-mozilla-flags"), + _T("nametemplate"), + _T("textualnewlines"), + }; + + wxString field = fieldAll.BeforeFirst(_T('=')); + for ( size_t n = 0; n < WXSIZEOF(knownFields); n++ ) + { + if ( field.CmpNoCase(knownFields[n]) == 0 ) + return TRUE; + } + + return FALSE; +} + #endif // wxUSE_FILE && wxUSE_TEXTFILE