wxFileType * wxMimeTypesManagerImpl::GetFileTypeFromExtension(const wxString& ext) { if (ext.empty() ) return NULL; InitIfNeeded(); size_t count = m_aExtensions.GetCount(); for ( size_t n = 0; n < count; n++ ) { wxStringTokenizer tk(m_aExtensions[n], wxT(' ')); while ( tk.HasMoreTokens() ) { // consider extensions as not being case-sensitive if ( tk.GetNextToken().IsSameAs(ext, false /* no case */) ) { // found wxFileType *fileType = new wxFileType; fileType->m_impl->Init(this, n); return fileType; } } } return NULL; }
bool wxMimeTypesManagerImpl::Unassociate(wxFileType *ft) { InitIfNeeded(); wxArrayString sMimeTypes; ft->GetMimeTypes(sMimeTypes); size_t i; size_t nCount = sMimeTypes.GetCount(); for (i = 0; i < nCount; i ++) { const wxString &sMime = sMimeTypes.Item(i); int nIndex = m_aTypes.Index(sMime); if ( nIndex == wxNOT_FOUND) { // error if we get here ?? return false; } else { m_aTypes.RemoveAt(nIndex); m_aEntries.RemoveAt(nIndex); m_aExtensions.RemoveAt(nIndex); m_aDescriptions.RemoveAt(nIndex); m_aIcons.RemoveAt(nIndex); } } // check data integrity wxASSERT( m_aTypes.GetCount() == m_aEntries.GetCount() && m_aTypes.GetCount() == m_aExtensions.GetCount() && m_aTypes.GetCount() == m_aIcons.GetCount() && m_aTypes.GetCount() == m_aDescriptions.GetCount() ); return true; }
size_t wxMimeTypesManagerImpl::EnumAllFileTypes(wxArrayString& mimetypes) { InitIfNeeded(); mimetypes.Empty(); size_t count = m_aTypes.GetCount(); #if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */ # pragma ivdep # pragma swp # pragma unroll # pragma prefetch # if 0 # pragma simd noassert # endif #endif /* VDM auto patch */ for ( size_t n = 0; n < count; n++ ) { // don't return template types from here (i.e. anything containg '*') const wxString &type = m_aTypes[n]; if ( type.Find(wxT('*')) == wxNOT_FOUND ) { mimetypes.Add(type); } } return mimetypes.GetCount(); }
void wxMimeTypesManagerImpl::AddFallback(const wxFileTypeInfo& filetype) { InitIfNeeded(); wxString extensions; const wxArrayString& exts = filetype.GetExtensions(); size_t nExts = exts.GetCount(); #if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */ # pragma ivdep # pragma swp # pragma unroll # pragma prefetch # if 0 # pragma simd noassert # endif #endif /* VDM auto patch */ for ( size_t nExt = 0; nExt < nExts; nExt++ ) { if ( nExt > 0 ) extensions += wxT(' '); extensions += exts[nExt]; } AddMimeTypeInfo(filetype.GetMimeType(), extensions, filetype.GetDescription()); }
wxFileType * wxMimeTypesManagerImpl::Associate(const wxFileTypeInfo& ftInfo) { InitIfNeeded(); wxString strType = ftInfo.GetMimeType(); wxString strDesc = ftInfo.GetDescription(); wxString strIcon = ftInfo.GetIconFile(); wxMimeTypeCommands *entry = new wxMimeTypeCommands(); if ( ! ftInfo.GetOpenCommand().empty()) entry->Add(wxT("open=") + ftInfo.GetOpenCommand() + wxT(" %s ")); if ( ! ftInfo.GetPrintCommand().empty()) entry->Add(wxT("print=") + ftInfo.GetPrintCommand() + wxT(" %s ")); // now find where these extensions are in the data store and remove them wxArrayString sA_Exts = ftInfo.GetExtensions(); wxString sExt, sExtStore; size_t i, nIndex; size_t nExtCount = sA_Exts.GetCount(); #if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */ # pragma ivdep # pragma swp # pragma unroll # pragma prefetch # if 0 # pragma simd noassert # endif #endif /* VDM auto patch */ for (i=0; i < nExtCount; i++) { sExt = sA_Exts.Item(i); // clean up to just a space before and after sExt.Trim().Trim(false); sExt = wxT(' ') + sExt + wxT(' '); size_t nCount = m_aExtensions.GetCount(); #if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */ # pragma ivdep # pragma swp # pragma unroll # pragma prefetch # if 0 # pragma simd noassert # endif #endif /* VDM auto patch */ for (nIndex = 0; nIndex < nCount; nIndex++) { sExtStore = m_aExtensions.Item(nIndex); if (sExtStore.Replace(sExt, wxT(" ") ) > 0) m_aExtensions.Item(nIndex) = sExtStore; } } if ( !DoAssociation(strType, strIcon, entry, sA_Exts, strDesc) ) return NULL; return GetFileTypeFromMimeType(strType); }
wxFileType * wxMimeTypesManagerImpl::GetFileTypeFromMimeType(const wxString& mimeType) { InitIfNeeded(); wxFileType * fileType = NULL; // mime types are not case-sensitive wxString mimetype(mimeType); mimetype.MakeLower(); // first look for an exact match int index = m_aTypes.Index(mimetype); if ( index != wxNOT_FOUND ) { fileType = new wxFileType; fileType->m_impl->Init(this, index); } // then try to find "text/*" as match for "text/plain" (for example) // NB: if mimeType doesn't contain '/' at all, BeforeFirst() will return // the whole string - ok. index = wxNOT_FOUND; wxString strCategory = mimetype.BeforeFirst(wxT('/')); size_t nCount = m_aTypes.GetCount(); #if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */ # pragma ivdep # pragma swp # pragma unroll # pragma prefetch # if 0 # pragma simd noassert # endif #endif /* VDM auto patch */ for ( size_t n = 0; n < nCount; n++ ) { if ( (m_aTypes[n].BeforeFirst(wxT('/')) == strCategory ) && m_aTypes[n].AfterFirst(wxT('/')) == wxT("*") ) { index = n; break; } } if ( index != wxNOT_FOUND ) { // don't throw away fileType that was already found if (!fileType) fileType = new wxFileType; fileType->m_impl->Init(this, index); } return fileType; }
bool wxMimeTypesManagerImpl::Unassociate(wxFileType *ft) { InitIfNeeded(); wxArrayString sMimeTypes; ft->GetMimeTypes(sMimeTypes); size_t i; size_t nCount = sMimeTypes.GetCount(); #if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */ # pragma ivdep # pragma swp # pragma unroll # pragma prefetch # if 0 # pragma simd noassert # endif #endif /* VDM auto patch */ for (i = 0; i < nCount; i ++) { const wxString &sMime = sMimeTypes.Item(i); int nIndex = m_aTypes.Index(sMime); if ( nIndex == wxNOT_FOUND) { // error if we get here ?? return false; } else { m_aTypes.RemoveAt(nIndex); m_aEntries.RemoveAt(nIndex); m_aExtensions.RemoveAt(nIndex); m_aDescriptions.RemoveAt(nIndex); m_aIcons.RemoveAt(nIndex); } } // check data integrity wxASSERT( m_aTypes.GetCount() == m_aEntries.GetCount() && m_aTypes.GetCount() == m_aExtensions.GetCount() && m_aTypes.GetCount() == m_aIcons.GetCount() && m_aTypes.GetCount() == m_aDescriptions.GetCount() ); return true; }
size_t wxMimeTypesManagerImpl::EnumAllFileTypes(wxArrayString& mimetypes) { InitIfNeeded(); mimetypes.Empty(); size_t count = m_aTypes.GetCount(); for ( size_t n = 0; n < count; n++ ) { // don't return template types from here (i.e. anything containg '*') const wxString &type = m_aTypes[n]; if ( type.Find(wxT('*')) == wxNOT_FOUND ) { mimetypes.Add(type); } } return mimetypes.GetCount(); }
void wxMimeTypesManagerImpl::AddFallback(const wxFileTypeInfo& filetype) { InitIfNeeded(); wxString extensions; const wxArrayString& exts = filetype.GetExtensions(); size_t nExts = exts.GetCount(); for ( size_t nExt = 0; nExt < nExts; nExt++ ) { if ( nExt > 0 ) extensions += wxT(' '); extensions += exts[nExt]; } AddMimeTypeInfo(filetype.GetMimeType(), extensions, filetype.GetDescription()); }
int wxMimeTypesManagerImpl::AddToMimeData(const wxString& strType, const wxString& strIcon, wxMimeTypeCommands *entry, const wxArrayString& strExtensions, const wxString& strDesc, bool replaceExisting) { InitIfNeeded(); // ensure mimetype is always lower case wxString mimeType = strType.Lower(); // is this a known MIME type? int nIndex = m_aTypes.Index(mimeType); if ( nIndex == wxNOT_FOUND ) { // 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; 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 { if ( replaceExisting ) { // if new description change it if ( !strDesc.empty()) m_aDescriptions[nIndex] = strDesc; // if new icon change it if ( !strIcon.empty()) m_aIcons[nIndex] = strIcon; if ( entry ) { delete m_aEntries[nIndex]; m_aEntries[nIndex] = entry; } } else // add data we don't already have ... { // if new description add only if none if ( m_aDescriptions[nIndex].empty() ) m_aDescriptions[nIndex] = strDesc; // if new icon and no existing icon if ( m_aIcons[nIndex].empty() ) m_aIcons[nIndex] = strIcon; // add any new entries... if ( entry ) { wxMimeTypeCommands *entryOld = m_aEntries[nIndex]; size_t count = entry->GetCount(); for ( size_t i = 0; i < count; i++ ) { const wxString& verb = entry->GetVerb(i); if ( !entryOld->HasVerb(verb) ) { 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; } } } // always add the extensions to this mimetype wxString& exts = m_aExtensions[nIndex]; // add all extensions we don't have yet wxString ext; size_t count = strExtensions.GetCount(); for ( size_t i = 0; i < count; i++ ) { ext = strExtensions[i]; ext += wxT(' '); if ( exts.Find(ext) == wxNOT_FOUND ) { exts += ext; } } // check data integrity wxASSERT( m_aTypes.GetCount() == m_aEntries.GetCount() && m_aTypes.GetCount() == m_aExtensions.GetCount() && m_aTypes.GetCount() == m_aIcons.GetCount() && m_aTypes.GetCount() == m_aDescriptions.GetCount() ); return nIndex; }
wxFileType * wxMimeTypesManagerImpl::GetFileTypeFromExtension(const wxString& ext) { if (ext.empty() ) return NULL; InitIfNeeded(); wxFileType* fileTypeFallback = NULL; size_t count = m_aExtensions.GetCount(); #if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */ # pragma ivdep # pragma swp # pragma unroll # pragma prefetch # if 0 # pragma simd noassert # endif #endif /* VDM auto patch */ for ( size_t n = 0; n < count; n++ ) { wxStringTokenizer tk(m_aExtensions[n], wxT(' ')); #if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */ # pragma ivdep # pragma swp # pragma unroll # pragma prefetch # if 0 # pragma simd noassert # endif #endif /* VDM auto patch */ while ( tk.HasMoreTokens() ) { // consider extensions as not being case-sensitive if ( tk.GetNextToken().IsSameAs(ext, false /* no case */) ) { // found wxFileType *fileType = new wxFileType; fileType->m_impl->Init(this, n); // See if this one has a known open-command. If not, keep // looking for another one that does, as a file that can't be // opened is not very useful, but store this one as a fallback. wxString type, desc, open; fileType->GetMimeType(&type); fileType->GetDescription(&desc); wxFileType::MessageParameters params("filename."+ext, type); if ( fileType->GetOpenCommand(&open, params) ) { delete fileTypeFallback; return fileType; } else { // Override the previous fallback, if any, with the new // one: we consider that later entries have priority. delete fileTypeFallback; fileTypeFallback = fileType; } } } } // If we couldn't find a filetype with a known open-command, return any // without one return fileTypeFallback; }