X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e675d6d86e992a9f27bcb5ce9a0cae7e972fa35b..6ba718d7aee2f519d9146b90424ccec9e2243479:/src/unix/mimetype.cpp diff --git a/src/unix/mimetype.cpp b/src/unix/mimetype.cpp index 5675516b4c..265f86aae0 100644 --- a/src/unix/mimetype.cpp +++ b/src/unix/mimetype.cpp @@ -4,7 +4,6 @@ // Author: Vadim Zeitlin // Modified by: // Created: 23.09.98 -// RCS-ID: $Id$ // Copyright: (c) 1998 Vadim Zeitlin // Licence: wxWindows licence (part of wxExtra library) ///////////////////////////////////////////////////////////////////////////// @@ -161,7 +160,7 @@ void wxMimeTypesManagerImpl::LoadXDGApp(const wxString& filename) #if wxUSE_INTL // try "Name[locale name]" first wxLocale *locale = wxGetLocale(); if ( locale ) - nIndex = file.pIndexOf(_T("Name[")+locale->GetName()+_T("]=")); + nIndex = file.pIndexOf(wxT("Name[")+locale->GetName()+wxT("]=")); #endif // wxUSE_INTL if(nIndex == wxNOT_FOUND) nIndex = file.pIndexOf( wxT("Name=") ); @@ -173,7 +172,7 @@ void wxMimeTypesManagerImpl::LoadXDGApp(const wxString& filename) nIndex = wxNOT_FOUND; #if wxUSE_INTL // try "Icon[locale name]" first if ( locale ) - nIndex = file.pIndexOf(_T("Icon[")+locale->GetName()+_T("]=")); + nIndex = file.pIndexOf(wxT("Icon[")+locale->GetName()+wxT("]=")); #endif // wxUSE_INTL if(nIndex == wxNOT_FOUND) nIndex = file.pIndexOf( wxT("Icon=") ); @@ -198,7 +197,7 @@ void wxMimeTypesManagerImpl::LoadXDGApp(const wxString& filename) sCmd.Replace(wxT("%i"), nameicon); sCmd.Replace(wxT("%m"), namemini); - wxStringTokenizer tokenizer(mimetypes, _T(";")); + wxStringTokenizer tokenizer(mimetypes, wxT(";")); while(tokenizer.HasMoreTokens()) { wxString mimetype = tokenizer.GetNextToken().Lower(); nIndex = m_aTypes.Index(mimetype); @@ -222,7 +221,7 @@ void wxMimeTypesManagerImpl::LoadXDGAppsFilesFromDir(const wxString& dirname) wxString filename; // Look into .desktop files - bool cont = dir.GetFirst(&filename, _T("*.desktop"), wxDIR_FILES); + bool cont = dir.GetFirst(&filename, wxT("*.desktop"), wxDIR_FILES); while (cont) { wxFileName p(dirname, filename); @@ -268,8 +267,7 @@ void wxMimeTypesManagerImpl::LoadXDGGlobs(const wxString& filename) wxArrayString exts; exts.Add( ext ); - if (mime.Find( "application" ) != 0) - AddToMimeData(mime, wxEmptyString, NULL, exts, wxEmptyString, true ); + AddToMimeData(mime, wxEmptyString, NULL, exts, wxEmptyString, true ); } } @@ -508,14 +506,19 @@ void wxMimeTypesManagerImpl::InitIfNeeded() // set the flag first to prevent recursion m_initialized = true; - wxString wm = wxTheApp->GetTraits()->GetDesktopEnvironment(); + int mailcapStyles = wxMAILCAP_ALL; + if ( wxAppTraits * const traits = wxApp::GetTraitsIfExists() ) + { + wxString wm = traits->GetDesktopEnvironment(); - if (wm == wxT("KDE")) - Initialize( wxMAILCAP_KDE ); - else if (wm == wxT("GNOME")) - Initialize( wxMAILCAP_GNOME ); - else - Initialize(); + if ( wm == "KDE" ) + mailcapStyles = wxMAILCAP_KDE; + else if ( wm == "GNOME" ) + mailcapStyles = wxMAILCAP_GNOME; + //else: unknown, use the default + } + + Initialize(mailcapStyles); } } @@ -719,16 +722,35 @@ int wxMimeTypesManagerImpl::AddToMimeData(const wxString& strType, int nIndex = m_aTypes.Index(mimeType); if ( nIndex == wxNOT_FOUND ) { - // new file type - m_aTypes.Add(mimeType); - m_aIcons.Add(strIcon); - m_aEntries.Add(entry ? entry : new wxMimeTypeCommands); + // We put MIME types containing "application" at the end, so that + // if the MIME type for the extension "htm" is searched for, it will + // rather find "text/html" than "application/x-mozilla-bookmarks". + if (mimeType.Find( "application" ) == 0) + { + // new file type + m_aTypes.Add(mimeType); + m_aIcons.Add(strIcon); + m_aEntries.Add(entry ? entry : new wxMimeTypeCommands); - // change nIndex so we can use it below to add the extensions - m_aExtensions.Add(wxEmptyString); - nIndex = m_aExtensions.size() - 1; + // change nIndex so we can use it below to add the extensions + m_aExtensions.Add(wxEmptyString); + nIndex = m_aExtensions.size() - 1; - m_aDescriptions.Add(strDesc); + m_aDescriptions.Add(strDesc); + } + else + { + // new file type + m_aTypes.Insert(mimeType,0); + m_aIcons.Insert(strIcon,0); + m_aEntries.Insert(entry ? entry : new wxMimeTypeCommands,0); + + // change nIndex so we can use it below to add the extensions + m_aExtensions.Insert(wxEmptyString,0); + nIndex = 0; + + m_aDescriptions.Insert(strDesc,0); + } } else // yes, we already have it {