X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2b5f62a0b2db198609b45dec622a018dae37008e..ce51dc7507f31a6baadb8709ac4b807cd2dad421:/src/unix/mimetype.cpp diff --git a/src/unix/mimetype.cpp b/src/unix/mimetype.cpp index 23c23a983e..5f6157c61e 100644 --- a/src/unix/mimetype.cpp +++ b/src/unix/mimetype.cpp @@ -6,7 +6,7 @@ // Created: 23.09.98 // RCS-ID: $Id$ // Copyright: (c) 1998 Vadim Zeitlin -// Licence: wxWindows license (part of wxExtra library) +// Licence: wxWindows licence (part of wxExtra library) ///////////////////////////////////////////////////////////////////////////// // known bugs; there may be others!! chris elliott, biol75@york.ac.uk 27 Mar 01 @@ -529,7 +529,8 @@ bool wxMimeTypesManagerImpl::WriteGnomeMimeFile(int index, bool delete_index) } -void wxMimeTypesManagerImpl::LoadGnomeDataFromKeyFile(const wxString& filename) +void wxMimeTypesManagerImpl::LoadGnomeDataFromKeyFile(const wxString& filename, + const wxArrayString& dirs) { wxTextFile textfile(filename); #if defined(__WXGTK20__) && wxUSE_UNICODE @@ -564,10 +565,29 @@ void wxMimeTypesManagerImpl::LoadGnomeDataFromKeyFile(const wxString& filename) wxString sTmp(pc); if (sTmp.Contains(wxT("=")) ) { + // GNOME 1: if (sTmp.Contains( wxT("icon-filename=") ) ) { curIconFile = sTmp.AfterFirst(wxT('=')); } + // GNOME 2: + else if (sTmp.Contains( wxT("icon_filename=") ) ) + { + curIconFile = sTmp.AfterFirst(wxT('=')); + if (!wxFileExists(curIconFile)) + { + size_t nDirs = dirs.GetCount(); + for (size_t nDir = 0; nDir < nDirs; nDir++) + { + wxString newFile; + newFile.Printf(wxT("%s/pixmaps/document-icons/%s.png"), + dirs[nDir].c_str(), + curIconFile.c_str()); + if (wxFileExists(newFile)) + curIconFile = newFile; + } + } + } else //: some other field, { //may contain lines like this (RH7) @@ -711,7 +731,8 @@ void wxMimeTypesManagerImpl::LoadGnomeMimeTypesFromMimeFile(const wxString& file } -void wxMimeTypesManagerImpl::LoadGnomeMimeFilesFromDir(const wxString& dirbase) +void wxMimeTypesManagerImpl::LoadGnomeMimeFilesFromDir( + const wxString& dirbase, const wxArrayString& dirs) { wxASSERT_MSG( !!dirbase && !wxEndsWithPathSeparator(dirbase), _T("base directory shouldn't end with a slash") ); @@ -741,7 +762,7 @@ void wxMimeTypesManagerImpl::LoadGnomeMimeFilesFromDir(const wxString& dirbase) cont = dir.GetFirst(&filename, _T("*.keys"), wxDIR_FILES); while ( cont ) { - LoadGnomeDataFromKeyFile(dirname + filename); + LoadGnomeDataFromKeyFile(dirname + filename, dirs); cont = dir.GetNext(&filename); } @@ -752,7 +773,6 @@ void wxMimeTypesManagerImpl::LoadGnomeMimeFilesFromDir(const wxString& dirbase) void wxMimeTypesManagerImpl::GetGnomeMimeInfo(const wxString& sExtraDir) { - wxArrayString dirs; dirs.Add(wxT("/usr/share")); dirs.Add(wxT("/usr/local/share")); @@ -766,7 +786,7 @@ void wxMimeTypesManagerImpl::GetGnomeMimeInfo(const wxString& sExtraDir) size_t nDirs = dirs.GetCount(); for ( size_t nDir = 0; nDir < nDirs; nDir++ ) { - LoadGnomeMimeFilesFromDir(dirs[nDir]); + LoadGnomeMimeFilesFromDir(dirs[nDir], dirs); } } @@ -921,6 +941,9 @@ void wxMimeTypesManagerImpl::LoadKDELinksForMimeSubtype(const wxString& dirbase, wxMimeTextFile file; if ( !file.Open(dirbase + filename) ) return; + wxLogTrace(TRACE_MIME, wxT("loading KDE file %s"), + (dirbase+filename).c_str()); + wxMimeTypeCommands * entry = new wxMimeTypeCommands; wxArrayString sExts; wxString mimetype, mime_desc, strIcon; @@ -991,6 +1014,7 @@ void wxMimeTypesManagerImpl::LoadKDELinksForMimeSubtype(const wxString& dirbase, if ( nIndex != wxNOT_FOUND ) { strIcon = file.GetCmd(nIndex); + wxLogTrace(TRACE_MIME, wxT(" icon %s"), strIcon.c_str()); //it could be the real path, but more often a short name if (!wxFileExists(strIcon)) { @@ -1004,6 +1028,7 @@ void wxMimeTypesManagerImpl::LoadKDELinksForMimeSubtype(const wxString& dirbase, if (wxFileExists(icondirs[nDir] + strIcon)) { strIcon.Prepend(icondirs[nDir]); + wxLogTrace(TRACE_MIME, wxT(" iconfile %s"), strIcon.c_str()); break; } } @@ -1042,6 +1067,9 @@ void wxMimeTypesManagerImpl::LoadKDELinksForMimeType(const wxString& dirbase, if ( !dir.IsOpened() ) return; + wxLogTrace(TRACE_MIME, wxT("--- Loading from KDE directory %s ---"), + dirname.c_str()); + dirname += _T('/'); wxString filename; @@ -1851,6 +1879,10 @@ int wxMimeTypesManagerImpl::AddToMimeData(const wxString& strType, entryOld->AddOrReplaceVerb(verb, entry->GetCmd(i)); } } + + // as we don't store it anywhere, it won't be deleted later as + // usual -- do it immediately instead + delete entry; } } } @@ -2157,14 +2189,19 @@ bool wxMimeTypesManagerImpl::ReadMimeTypes(const wxString& strFileName) else if ( strLHS == wxT("exts") ) { strExtensions = strRHS; } - else { + else if ( strLHS != _T("icon") ) + { // this one is simply ignored: it usually refers to Netscape // built in icons which are useless for us anyhow - if ( strLHS != _T("icon") ) - { - wxLogWarning(_("Unknown field in file %s, line %d: '%s'."), - strFileName.c_str(), nLine + 1, strLHS.c_str()); - } + } + else if ( !strLHS.StartsWith(_T("x-")) ) + { + // we suppose that all fields starting with "X-" are + // unregistered extensions according to the standard practice, + // but it may be worth telling the user about other junk in + // his mime.types file + wxLogWarning(_("Unknown field in file %s, line %d: '%s'."), + strFileName.c_str(), nLine + 1, strLHS.c_str()); } if ( !entryEnded ) {