X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/70687b638d5860a91a53aecec2a43d838d925372..e0c749a72f391a5180b84911be22132652aa5374:/src/unix/mimetype.cpp diff --git a/src/unix/mimetype.cpp b/src/unix/mimetype.cpp index 4b6378e1d6..d5f4415784 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 @@ -40,7 +40,7 @@ // headers // ---------------------------------------------------------------------------- -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "mimetype.h" #endif @@ -59,10 +59,6 @@ #ifndef WX_PRECOMP #include "wx/string.h" - #if wxUSE_GUI - #include "wx/icon.h" - - #endif #endif //WX_PRECOMP @@ -77,6 +73,7 @@ #include "wx/dir.h" #include "wx/utils.h" #include "wx/tokenzr.h" +#include "wx/iconloc.h" #include "wx/unix/mimetype.h" @@ -643,14 +640,12 @@ void wxMimeTypesManagerImpl::LoadGnomeDataFromKeyFile(const wxString& filename, void wxMimeTypesManagerImpl::LoadGnomeMimeTypesFromMimeFile(const wxString& filename) { wxTextFile textfile(filename); -#if defined(__WXGTK20__) && wxUSE_UNICODE - if ( !textfile.Open( wxConvUTF8) ) -#else if ( !textfile.Open() ) -#endif return; - wxLogTrace(TRACE_MIME, wxT("--- Opened Gnome file %s ---"), - filename.c_str()); + + wxLogTrace(TRACE_MIME, + wxT("--- Opened Gnome file %s ---"), + filename.c_str()); // values for the entry being parsed wxString curMimeType, curExtList; @@ -679,8 +674,9 @@ void wxMimeTypesManagerImpl::LoadGnomeMimeTypesFromMimeFile(const wxString& file // end of the entry if ( !!curMimeType && !!curExtList ) { - wxLogTrace(TRACE_MIME, wxT("--- At end of Gnome file finding mimetype %s ---"), - curMimeType.c_str()); + wxLogTrace(TRACE_MIME, + wxT("--- At end of Gnome file finding mimetype %s ---"), + curMimeType.c_str()); AddMimeTypeInfo(curMimeType, curExtList, wxEmptyString); } @@ -702,20 +698,20 @@ void wxMimeTypesManagerImpl::LoadGnomeMimeTypesFromMimeFile(const wxString& file // this is a field=value ling pc++; // skip leading TAB - static const int lenField = 4; // strlen("ext:") - if ( wxStrncmp(pc, wxT("ext:"), lenField) == 0 ) + static const int lenField = 5; // strlen("ext: ") + if ( wxStrncmp(pc, wxT("ext: "), lenField) == 0 ) { - // skip ' ' which follows and take everything left until the end - // of line - curExtList = pc + lenField + 1; + // skip it and take everything left until the end of line + curExtList = pc + lenField; } //else: some other field, we don't care } else { // this is the start of the new section - wxLogTrace(TRACE_MIME, wxT("--- In Gnome file finding mimetype %s ---"), - curMimeType.c_str()); + wxLogTrace(TRACE_MIME, + wxT("--- In Gnome file finding mimetype %s ---"), + curMimeType.c_str()); if (! curMimeType.empty()) AddMimeTypeInfo(curMimeType, curExtList, wxEmptyString); @@ -1172,12 +1168,9 @@ wxString wxFileTypeImpl::GetExpandedCommand(const wxString & verb, const wxFileT return wxFileType::ExpandCommand(sTmp, params); } -bool wxFileTypeImpl::GetIcon(wxIcon *icon, - wxString *iconFile /*= NULL */, - int *iconIndex /*= NULL*/) const +bool wxFileTypeImpl::GetIcon(wxIconLocation *iconLoc) const { -#if wxUSE_GUI wxString sTmp; size_t i = 0; while ( (i < m_index.GetCount() ) && sTmp.empty() ) @@ -1185,25 +1178,15 @@ bool wxFileTypeImpl::GetIcon(wxIcon *icon, sTmp = m_manager->m_aIcons[m_index[i]]; i ++; } - if ( sTmp.empty () ) return FALSE; - - wxIcon icn; - - if (sTmp.Right(4).MakeUpper() == _T(".XPM")) - icn = wxIcon(sTmp); - else - icn = wxIcon(sTmp, wxBITMAP_TYPE_ANY); + if ( sTmp.empty () ) + return FALSE; - if ( icn.Ok() ) + if ( iconLoc ) { - *icon = icn; - if (iconFile) *iconFile = sTmp; - if (iconIndex) *iconIndex = 0; - return TRUE; + iconLoc->SetFileName(sTmp); } -#endif // wxUSE_GUI - return FALSE; + return TRUE; } @@ -1833,7 +1816,8 @@ int wxMimeTypesManagerImpl::AddToMimeData(const wxString& strType, m_aEntries.Add(entry ? entry : new wxMimeTypeCommands); // change nIndex so we can use it below to add the extensions - nIndex = m_aExtensions.Add(wxEmptyString); + m_aExtensions.Add(wxEmptyString); + nIndex = m_aExtensions.size() - 1; m_aDescriptions.Add(strDesc); } @@ -1879,6 +1863,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; } } } @@ -2185,7 +2173,7 @@ bool wxMimeTypesManagerImpl::ReadMimeTypes(const wxString& strFileName) else if ( strLHS == wxT("exts") ) { strExtensions = strRHS; } - else if ( strLHS != _T("icon") ) + else if ( strLHS == _T("icon") ) { // this one is simply ignored: it usually refers to Netscape // built in icons which are useless for us anyhow