X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d39e2bbcf77228d8d81507d317c969d2dbf346d2..b22bb1a015c4cc734e55bdfcebabc99da24e185e:/src/unix/mimetype.cpp diff --git a/src/unix/mimetype.cpp b/src/unix/mimetype.cpp index 5c7ba44abb..1bce2f3121 100644 --- a/src/unix/mimetype.cpp +++ b/src/unix/mimetype.cpp @@ -16,7 +16,7 @@ #pragma hdrstop #endif -#if wxUSE_MIMETYPE && wxUSE_FILE && wxUSE_TEXTFILE +#if wxUSE_MIMETYPE && wxUSE_FILE #include "wx/unix/mimetype.h" @@ -32,7 +32,6 @@ #include "wx/confbase.h" #include "wx/ffile.h" -#include "wx/textfile.h" #include "wx/dir.h" #include "wx/tokenzr.h" #include "wx/iconloc.h" @@ -73,7 +72,7 @@ public: { wxString t = tok.GetNextToken(); t.MakeLower(); - if ((!!t) && (t.Find( "comment" ) != 0) && (t.Find( "generic" ) != 0)) + if ((!!t) && (t.Find( "comment" ) != 0) && (t.Find( "#" ) != 0) && (t.Find( "generic" ) != 0)) m_text.Add( t ); } return true; @@ -248,6 +247,28 @@ void wxMimeTypesManagerImpl::LoadXDGAppsFilesFromDir(const wxString& dirname) } +void wxMimeTypesManagerImpl::LoadXDGGlobs(const wxString& filename) +{ + wxLogTrace(TRACE_MIME, wxT("loading XDG globs file from %s"), filename.c_str()); + + wxMimeTextFile file(filename); + if ( !file.Open() ) + return; + + size_t i; + for (i = 0; i < file.GetLineCount(); i++) + { + wxStringTokenizer tok( file.GetLine(i), ":" ); + wxString mime = tok.GetNextToken(); + wxString ext = tok.GetNextToken(); + ext.Remove( 0, 2 ); + wxArrayString exts; + exts.Add( ext ); + + AddToMimeData(mime, wxEmptyString, NULL, exts, wxEmptyString, true ); + } +} + // ---------------------------------------------------------------------------- // wxFileTypeImpl (Unix) // ---------------------------------------------------------------------------- @@ -494,6 +515,8 @@ void wxMimeTypesManagerImpl::InitIfNeeded() } } + + // read system and user mailcaps and other files void wxMimeTypesManagerImpl::Initialize(int mailcapStyles, const wxString& sExtraDir) @@ -503,7 +526,11 @@ void wxMimeTypesManagerImpl::Initialize(int mailcapStyles, return; #endif - // Load desktop files for Gnome, and then override them with the Gnome defaults. + // Read MIME type - extension associations + LoadXDGGlobs( "/usr/share/mime/globs" ); + LoadXDGGlobs( "/usr/local/share/mime/globs" ); + + // Load desktop files for XDG, and then override them with the defaults. // We will override them one desktop file at a time, rather // than one mime type at a time, but it should be a reasonable // heuristic. @@ -815,6 +842,7 @@ wxFileType * wxMimeTypesManagerImpl::GetFileTypeFromMimeType(const wxString& mim // first look for an exact match int index = m_aTypes.Index(mimetype); + if ( index != wxNOT_FOUND ) { fileType = new wxFileType; @@ -973,4 +1001,4 @@ bool wxMimeTypesManagerImpl::Unassociate(wxFileType *ft) } #endif - // wxUSE_MIMETYPE && wxUSE_FILE && wxUSE_TEXTFILE + // wxUSE_MIMETYPE && wxUSE_FILE