X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/341c92a8b4c813cbfb606687937dcdf5d8c3c2fe..ac91b9d22aea519059b3f64adfba506d43aba639:/src/common/mimetype.cpp diff --git a/src/common/mimetype.cpp b/src/common/mimetype.cpp index 9f7cd6b0bf..8e068c6f0f 100644 --- a/src/common/mimetype.cpp +++ b/src/common/mimetype.cpp @@ -285,7 +285,7 @@ public: bool GetExtensions(wxArrayString& extensions); bool GetMimeType(wxString *mimeType) const { *mimeType = m_manager->m_aTypes[m_index]; return TRUE; } - bool GetIcon(wxIcon *icon) const + bool GetIcon(wxIcon * WXUNUSED(icon)) const { return FALSE; } // @@ maybe with Gnome/KDE integration... bool GetDescription(wxString *desc) const { *desc = m_manager->m_aDescriptions[m_index]; return TRUE; } @@ -448,6 +448,28 @@ wxFileType::GetPrintCommand(wxString *printCmd, // wxMimeTypesManager // ---------------------------------------------------------------------------- +bool wxMimeTypesManager::IsOfType(const wxString& mimeType, + const wxString& wildcard) +{ + wxASSERT_MSG( mimeType.Find('*') == wxNOT_FOUND, + "first MIME type can't contain wildcards" ); + + // all comparaisons are case insensitive (2nd arg of IsSameAs() is FALSE) + if ( wildcard.BeforeFirst('/').IsSameAs(mimeType.BeforeFirst('/'), FALSE) ) + { + wxString strSubtype = wildcard.AfterFirst('/'); + + if ( strSubtype == '*' || + strSubtype.IsSameAs(mimeType.AfterFirst('/'), FALSE) ) + { + // matches (either exactly or it's a wildcard) + return TRUE; + } + } + + return FALSE; +} + wxMimeTypesManager::wxMimeTypesManager() { m_impl = new wxMimeTypesManagerImpl; @@ -971,6 +993,16 @@ void wxMimeTypesManagerImpl::ReadMimeTypes(const wxString& strFileName) } } + // although it doesn't seem to be covered by RFCs, some programs + // (notably Netscape) create their entries with several comma + // separated extensions (RFC mention the spaces only) + strExtensions.Replace(",", " "); + + // also deal with the leading dot + if ( !strExtensions.IsEmpty() && strExtensions[0] == '.' ) { + strExtensions.erase(0, 1); + } + int index = m_aTypes.Index(strMimeType); if ( index == wxNOT_FOUND ) { // add a new entry @@ -1031,8 +1063,8 @@ void wxMimeTypesManagerImpl::ReadMailcap(const wxString& strFileName) } currentToken = Field_Type; // the flags and field values on the current line - bool needsterminal = false, - copiousoutput = false; + bool needsterminal = FALSE, + copiousoutput = FALSE; wxString strType, strOpenCmd, strPrintCmd, @@ -1148,9 +1180,9 @@ void wxMimeTypesManagerImpl::ReadMailcap(const wxString& strFileName) // programmer wxLogDebug ( - _("Mailcap file %s, line %d: unknown " - "field '%s' for the MIME type " - "'%s' ignored."), + "Mailcap file %s, line %d: unknown " + "field '%s' for the MIME type " + "'%s' ignored.", strFileName.c_str(), nLine + 1, curField.c_str(),