void PGM_BASE::WritePdfBrowserInfos() { wxASSERT( m_common_settings ); m_common_settings->Write( wxT( "PdfBrowserName" ), GetPdfBrowserName() ); m_common_settings->Write( wxT( "UseSystemBrowser" ), m_use_system_pdf_browser ); } // Mime type extensions (PDF files are not considered here) static wxMimeTypesManager* mimeDatabase; static const wxFileTypeInfo EDAfallbacks[] = { wxFileTypeInfo( wxT( "text/html" ), wxT( "wxhtml %s" ), wxT( "wxhtml %s" ), wxT( "html document (from KiCad)" ), wxT( "htm" ), wxT( "html" ),wxNullPtr ), wxFileTypeInfo( wxT( "application/sch" ), wxT( "eeschema %s" ), wxT( "eeschema -p %s" ), wxT( "sch document (from KiCad)" ), wxT( "sch" ), wxT( "SCH" ), wxNullPtr ), // must terminate the table with this! wxFileTypeInfo() };
void MyApp::DoMIMEDemo(wxCommandEvent& WXUNUSED(event)) { static wxString s_defaultExt = _T("xyz"); wxString ext = wxGetTextFromUser(_T("Enter a file extension: "), _T("MIME database test"), s_defaultExt); if ( !!ext ) { s_defaultExt = ext; // init MIME database if not done yet if ( !m_mimeDatabase ) { m_mimeDatabase = new wxMimeTypesManager; static const wxFileTypeInfo fallbacks[] = { wxFileTypeInfo(_T("application/xyz"), _T("XyZ %s"), _T("XyZ -p %s"), _T("The one and only XYZ format file"), _T("xyz"), _T("123"), NULL), wxFileTypeInfo(_T("text/html"), _T("lynx %s"), _T("lynx -dump %s | lpr"), _T("HTML document (from fallback)"), _T("htm"), _T("html"), NULL), // must terminate the table with this! wxFileTypeInfo() }; m_mimeDatabase->AddFallbacks(fallbacks); } wxTextCtrl& textCtrl = * GetTextCtrl(); wxFileType *filetype = m_mimeDatabase->GetFileTypeFromExtension(ext); if ( !filetype ) { textCtrl << _T("Unknown extension '") << ext << _T("'\n"); } else { wxString type, desc, open; filetype->GetMimeType(&type); filetype->GetDescription(&desc); wxString filename = _T("filename"); filename << _T(".") << ext; wxFileType::MessageParameters params(filename, type); filetype->GetOpenCommand(&open, params); textCtrl << _T("MIME information about extension '") << ext << _T('\n') << _T("\tMIME type: ") << ( !type ? wxT("unknown") : type.c_str() ) << _T('\n') << _T("\tDescription: ") << ( !desc ? wxEmptyString : desc.c_str() ) << _T('\n') << _T("\tCommand to open: ") << ( !open ? wxT("no") : open.c_str() ) << _T('\n'); delete filetype; } } //else: cancelled by user }
wxString wxFileSystemHandler::GetMimeTypeFromExt(const wxString& location) { wxString ext, mime; wxString loc = GetRightLocation(location); wxChar c; int l = loc.length(), l2; l2 = l; for (int i = l-1; i >= 0; i--) { c = loc[(unsigned int) i]; if ( c == wxT('#') ) l2 = i + 1; if ( c == wxT('.') ) { ext = loc.Right(l2-i-1); break; } if ( (c == wxT('/')) || (c == wxT('\\')) || (c == wxT(':')) ) return wxEmptyString; } #if wxUSE_MIMETYPE static bool s_MinimalMimeEnsured = false; if (!s_MinimalMimeEnsured) { static const wxFileTypeInfo fallbacks[] = { wxFileTypeInfo(_T("image/jpeg"), wxEmptyString, wxEmptyString, _T("JPEG image (from fallback)"), _T("jpg"), _T("jpeg"), _T("JPG"), _T("JPEG"), NULL), wxFileTypeInfo(_T("image/gif"), wxEmptyString, wxEmptyString, _T("GIF image (from fallback)"), _T("gif"), _T("GIF"), NULL), wxFileTypeInfo(_T("image/png"), wxEmptyString, wxEmptyString, _T("PNG image (from fallback)"), _T("png"), _T("PNG"), NULL), wxFileTypeInfo(_T("image/bmp"), wxEmptyString, wxEmptyString, _T("windows bitmap image (from fallback)"), _T("bmp"), _T("BMP"), NULL), wxFileTypeInfo(_T("text/html"), wxEmptyString, wxEmptyString, _T("HTML document (from fallback)"), _T("htm"), _T("html"), _T("HTM"), _T("HTML"), NULL), // must terminate the table with this! wxFileTypeInfo() }; wxTheMimeTypesManager->AddFallbacks(fallbacks); s_MinimalMimeEnsured = true; } wxFileType *ft = wxTheMimeTypesManager->GetFileTypeFromExtension(ext); if ( !ft || !ft -> GetMimeType(&mime) ) { mime = wxEmptyString; } delete ft; return mime; #else if ( ext.IsSameAs(wxT("htm"), false) || ext.IsSameAs(_T("html"), false) ) return wxT("text/html"); if ( ext.IsSameAs(wxT("jpg"), false) || ext.IsSameAs(_T("jpeg"), false) ) return wxT("image/jpeg"); if ( ext.IsSameAs(wxT("gif"), false) ) return wxT("image/gif"); if ( ext.IsSameAs(wxT("png"), false) ) return wxT("image/png"); if ( ext.IsSameAs(wxT("bmp"), false) ) return wxT("image/bmp"); return wxEmptyString; #endif }
/* static */ wxString wxFileSystemHandler::GetMimeTypeFromExt(const wxString& location) { wxString ext, mime; wxString loc = GetRightLocation(location); wxChar c; int l = loc.length(), l2; l2 = l; for (int i = l-1; i >= 0; i--) { c = loc[(unsigned int) i]; if ( c == wxT('#') ) l2 = i + 1; if ( c == wxT('.') ) { ext = loc.Right(l2-i-1); break; } if ( (c == wxT('/')) || (c == wxT('\\')) || (c == wxT(':')) ) return wxEmptyString; } #if wxUSE_MIMETYPE static bool s_MinimalMimeEnsured = false; // Don't use mime types manager if the application doesn't need it and it would be // cause an unacceptable delay, especially on startup. #if wxUSE_SYSTEM_OPTIONS if ( !wxSystemOptions::GetOptionInt(wxT("filesys.no-mimetypesmanager")) ) #endif { if (!s_MinimalMimeEnsured) { static const wxFileTypeInfo fallbacks[] = { wxFileTypeInfo(wxT("image/jpeg"), wxEmptyString, wxEmptyString, wxT("JPEG image (from fallback)"), wxT("jpg"), wxT("jpeg"), wxT("JPG"), wxT("JPEG"), wxNullPtr), wxFileTypeInfo(wxT("image/gif"), wxEmptyString, wxEmptyString, wxT("GIF image (from fallback)"), wxT("gif"), wxT("GIF"), wxNullPtr), wxFileTypeInfo(wxT("image/png"), wxEmptyString, wxEmptyString, wxT("PNG image (from fallback)"), wxT("png"), wxT("PNG"), wxNullPtr), wxFileTypeInfo(wxT("image/bmp"), wxEmptyString, wxEmptyString, wxT("windows bitmap image (from fallback)"), wxT("bmp"), wxT("BMP"), wxNullPtr), wxFileTypeInfo(wxT("text/html"), wxEmptyString, wxEmptyString, wxT("HTML document (from fallback)"), wxT("htm"), wxT("html"), wxT("HTM"), wxT("HTML"), wxNullPtr), // must terminate the table with this! wxFileTypeInfo() }; wxTheMimeTypesManager->AddFallbacks(fallbacks); s_MinimalMimeEnsured = true; } wxFileType *ft = wxTheMimeTypesManager->GetFileTypeFromExtension(ext); if ( !ft || !ft -> GetMimeType(&mime) ) { mime = wxEmptyString; } delete ft; return mime; } else #endif { if ( ext.IsSameAs(wxT("htm"), false) || ext.IsSameAs(wxT("html"), false) ) return wxT("text/html"); if ( ext.IsSameAs(wxT("jpg"), false) || ext.IsSameAs(wxT("jpeg"), false) ) return wxT("image/jpeg"); if ( ext.IsSameAs(wxT("gif"), false) ) return wxT("image/gif"); if ( ext.IsSameAs(wxT("png"), false) ) return wxT("image/png"); if ( ext.IsSameAs(wxT("bmp"), false) ) return wxT("image/bmp"); return wxEmptyString; } }
void MyApp::DoMIMEDemo(wxCommandEvent& WXUNUSED(event)) { static wxString s_defaultExt = "xyz"; wxString ext = wxGetTextFromUser("Enter a file extension: ", "MIME database test", s_defaultExt); if ( !!ext ) { s_defaultExt = ext; // init MIME database if not done yet if ( !m_mimeDatabase ) { m_mimeDatabase = new wxMimeTypesManager; static const wxFileTypeInfo fallbacks[] = { wxFileTypeInfo("application/xyz", "XyZ %s", "XyZ -p %s", "The one and only XYZ format file", "xyz", "123", wxNullPtr), wxFileTypeInfo("text/html", "lynx %s", "lynx -dump %s | lpr", "HTML document (from fallback)", "htm", "html", wxNullPtr), // must terminate the table with this! wxFileTypeInfo() }; m_mimeDatabase->AddFallbacks(fallbacks); } wxTextCtrl& textCtrl = * GetTextCtrl(); wxFileType *filetype = m_mimeDatabase->GetFileTypeFromExtension(ext); if ( !filetype ) { textCtrl << "Unknown extension '" << ext << "'\n"; } else { wxString type, desc, open; wxIconLocation loc; filetype->GetMimeType(&type); filetype->GetDescription(&desc); filetype->GetIcon(&loc); wxString filename = "filename"; filename << "." << ext; wxFileType::MessageParameters params(filename, type); filetype->GetOpenCommand(&open, params); textCtrl << "MIME information about extension '" << ext << '\n' << "\tMIME type: " << ( !type ? wxString("unknown") : type ) << '\n' << "\tDescription: " << ( !desc ? wxString(wxEmptyString) : desc ) << '\n' << "\tCommand to open: " << ( !open ? wxString("no") : open ) << '\n' << "\tIcon: " << ( loc.IsOk() ? loc.GetFileName() : wxString("no") ) << '\n'; delete filetype; } } //else: cancelled by user }