X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2b813b73cd79cfb4d275e9628811f379e8c5ee39..5d5da6f610400c6a6a7886b154adeb8a69772f98:/src/unix/mimetype.cpp diff --git a/src/unix/mimetype.cpp b/src/unix/mimetype.cpp index 62487d68ea..4913cd53d5 100644 --- a/src/unix/mimetype.cpp +++ b/src/unix/mimetype.cpp @@ -51,7 +51,7 @@ #include "wx/defs.h" #endif -#if wxUSE_FILE && wxUSE_TEXTFILE +#if wxUSE_MIMETYPE && wxUSE_FILE && wxUSE_TEXTFILE #ifndef WX_PRECOMP #include "wx/string.h" @@ -79,6 +79,11 @@ // other standard headers #include +#ifdef __VMS +/* silence warnings for comparing unsigned int's <0 */ +# pragma message disable unscomzer +#endif + // this is a class to extend wxArrayString... class wxMimeArrayString : public wxArrayString { @@ -114,7 +119,6 @@ public: wxString GetVerb (size_t i) { - if (i < 0) return wxEmptyString; if (i > GetCount() ) return wxEmptyString; wxString sTmp = Item(i).BeforeFirst(wxT('=')); return sTmp; @@ -122,7 +126,6 @@ public: wxString GetCmd (size_t i) { - if (i < 0) return wxEmptyString; if (i > GetCount() ) return wxEmptyString; wxString sTmp = Item(i).AfterFirst(wxT('=')); return sTmp; @@ -192,7 +195,6 @@ public: wxString GetVerb (size_t i) { - if (i < 0) return wxEmptyString; if (i > GetLineCount() ) return wxEmptyString; wxString sTmp = GetLine(i).BeforeFirst(wxT('=')); return sTmp; @@ -200,7 +202,6 @@ public: wxString GetCmd (size_t i) { - if (i < 0) return wxEmptyString; if (i > GetLineCount() ) return wxEmptyString; wxString sTmp = GetLine(i).AfterFirst(wxT('=')); return sTmp; @@ -294,10 +295,13 @@ static bool IsKnownUnimportantField(const wxString& field); // a) for "brief" format: // // b) for "expanded" format: -// type= \ -// desc="" \ +// type= BACKSLASH +// desc="" BACKSLASH // exts="" // +// (where BACKSLASH is a literal '\\' which we can't put here because cpp +// misinterprets it) +// // We try to autodetect the format of mime.types: if a non-comment line starts // with "type=" we assume the second format, otherwise the first one. @@ -1105,17 +1109,19 @@ 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(wxIcon *icon, + wxString *iconFile /*= NULL */, + int *iconIndex /*= NULL*/) const { +#if wxUSE_GUI wxString sTmp; size_t i = 0; while ( (i < m_index.GetCount() ) && sTmp.IsEmpty() ) - { - sTmp = m_manager->m_aIcons[m_index[i]]; - i ++; - } + { + sTmp = m_manager->m_aIcons[m_index[i]]; + i ++; + } if ( sTmp.IsEmpty () ) return FALSE; wxIcon icn; @@ -1126,14 +1132,16 @@ bool wxFileTypeImpl::GetIcon(wxIcon *icon, wxString *iconFile /*= NULL */, icn = wxIcon(sTmp, wxBITMAP_TYPE_ANY); if ( icn.Ok() ) - { - *icon = icn; - if (iconFile) *iconFile = sTmp; - if (iconIndex) *iconIndex = 0; - return TRUE; - } - return FALSE; + { + *icon = icn; + if (iconFile) *iconFile = sTmp; + if (iconIndex) *iconIndex = 0; + return TRUE; } +#endif // wxUSE_GUI + + return FALSE; +} bool @@ -1291,7 +1299,8 @@ void wxMimeTypesManagerImpl::Initialize(int mailcapStyles, const wxString& sExtraDir) { // read mimecap amd mime.types - if ( (mailcapStyles & wxMAILCAP_NETSCAPE) || (mailcapStyles & wxMAILCAP_BASE) ) + if ( (mailcapStyles & wxMAILCAP_NETSCAPE) || + (mailcapStyles & wxMAILCAP_STANDARD) ) GetMimeInfo(sExtraDir); // read GNOME tables @@ -1348,12 +1357,12 @@ void wxMimeTypesManagerImpl::GetMimeInfo (const wxString& sExtraDir) wxString strHome = wxGetenv(wxT("HOME")); wxArrayString dirs; + dirs.Add ( strHome + wxT("/.") ); dirs.Add ( wxT("/etc/") ); dirs.Add ( wxT("/usr/etc/") ); dirs.Add ( wxT("/usr/local/etc/") ); dirs.Add ( wxT("/etc/mail/") ); dirs.Add ( wxT("/usr/public/lib/") ); - dirs.Add ( strHome + wxT("/.") ); if (!sExtraDir.IsEmpty()) dirs.Add ( sExtraDir + wxT("/") ); size_t nDirs = dirs.GetCount(); @@ -1375,7 +1384,7 @@ void wxMimeTypesManagerImpl::GetMimeInfo (const wxString& sExtraDir) bool wxMimeTypesManagerImpl::WriteToMimeTypes (int index, bool delete_index) { // check we have the right manager - if (! ( m_mailcapStylesInited & wxMAILCAP_BASE) ) + if (! ( m_mailcapStylesInited & wxMAILCAP_STANDARD) ) return FALSE; bool bTemp; @@ -1517,7 +1526,7 @@ bool wxMimeTypesManagerImpl::WriteToMailCap (int index, bool delete_index) { //check we have the right managers if ( !( ( m_mailcapStylesInited & wxMAILCAP_NETSCAPE) || - ( m_mailcapStylesInited & wxMAILCAP_BASE) ) ) + ( m_mailcapStylesInited & wxMAILCAP_STANDARD) ) ) return FALSE; bool bTemp; @@ -1568,7 +1577,7 @@ bool wxMimeTypesManagerImpl::WriteToMailCap (int index, bool delete_index) sTmp = sTmp + wxT(";") + sCmd ; //includes wxT(" %s "); // write it in the format that Netscape uses (default) - if (! ( m_mailcapStylesInited & wxMAILCAP_BASE ) ) + if (! ( m_mailcapStylesInited & wxMAILCAP_STANDARD ) ) { if (! delete_index) file.InsertLine (sTmp, nIndex); nIndex ++; @@ -1712,7 +1721,7 @@ bool wxMimeTypesManagerImpl::WriteMimeInfo(int nIndex, bool delete_mime ) { bool ok = TRUE; - if ( m_mailcapStylesInited & wxMAILCAP_BASE ) + if ( m_mailcapStylesInited & wxMAILCAP_STANDARD ) { // write in metamail format; if (WriteToMimeTypes (nIndex, delete_mime) ) @@ -2108,8 +2117,13 @@ bool wxMimeTypesManagerImpl::ReadMimeTypes(const wxString& strFileName) strExtensions = strRHS; } else { - wxLogWarning(_("Unknown field in file %s, line %d: '%s'."), - strFileName.c_str(), nLine + 1, strLHS.c_str()); + // 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()); + } } if ( !entryEnded ) { @@ -2193,7 +2207,7 @@ bool wxMimeTypesManagerImpl::ReadMailcap(const wxString& strFileName, // the flags and field values on the current line bool needsterminal = FALSE, copiousoutput = FALSE; - wxMimeArrayString *entry; + wxMimeArrayString *entry = NULL; // suppress compiler warning wxString strType, strOpenCmd, @@ -2518,11 +2532,11 @@ bool wxMimeTypesManagerImpl::Unassociate(wxFileType *ft) else { WriteMimeInfo(nIndex, TRUE ); - m_aTypes.Remove (nIndex); - m_aEntries.Remove (nIndex); - m_aExtensions.Remove (nIndex); - m_aDescriptions.Remove (nIndex); - m_aIcons.Remove (nIndex); + m_aTypes.RemoveAt(nIndex); + m_aEntries.RemoveAt(nIndex); + m_aExtensions.RemoveAt(nIndex); + m_aDescriptions.RemoveAt(nIndex); + m_aIcons.RemoveAt(nIndex); } } // check data integrity @@ -2558,5 +2572,5 @@ static bool IsKnownUnimportantField(const wxString& fieldAll) } #endif - // wxUSE_FILE && wxUSE_TEXTFILE + // wxUSE_MIMETYPE && wxUSE_FILE && wxUSE_TEXTFILE