//--------------------------------------------------------------------------------------- void BooksDlg::load_available_books() { Paths* pPaths = m_appScope.get_paths(); wxString sPath = pPaths->GetBooksPath(); wxString sPattern = "*.lmb"; wxString sRead = _("Please read the <a-1>Study guide</a-1> for information about \ the best way to use LenMus Phonascus and the books."); sRead.Replace("<a-1>", "<a href=\"lenmus#study-guide\">'"); sRead.Replace("</a-1>", "'</a>"); wxString sHeader = "<html><body>"; wxString sContent = sHeader + "<p>" + sRead + "</p>" "<h3>" + _("Available books:") + "</h3><ul>"; // wxLogMessage("[BooksDlg::load_available_books] Scanning path <%s>", sPath.wx_str()); wxDir dir(sPath); if ( !dir.IsOpened() ) { wxMessageBox( wxString::Format(_("Error when trying to move to folder %s"), sPath.wx_str() )); LOMSE_LOG_ERROR(str(boost::format("Error when trying to move to folder %s") % sPath.wx_str() )); return; } //Scan the books folder and load all books found wxString filename; bool fFound = dir.GetFirst(&filename, sPattern, wxDIR_FILES); while (fFound) { if ((filename != "TestingNewExercises.lmb" && filename != "L1_Dictation.lmb" && filename != "L3_MusicReading.lmb" ) || m_appScope.are_experimental_features_enabled() ) { wxFileName oFilename(sPath, filename, wxPATH_NATIVE); wxString name = get_book_name(oFilename); wxString link = wxString::Format("book-%s", filename.wx_str()); sContent += "<li><a href=\"lenmus#" + link + "\">" + name + "</a></li>"; } fFound = dir.GetNext(&filename); } sContent += "</ul></body></html>"; m_pHtmlWnd->SetPage(sContent); }
//--------------------------------------------------------------------------------------- void BooksDlg::OnLinkClicked(wxHtmlLinkEvent& event) { const wxHtmlLinkInfo& link = event.GetLinkInfo(); wxString sLocation = link.GetHref(); //study guide if (sLocation == "lenmus#study-guide") { HelpSystem* pHelp = m_appScope.get_help_controller(); pHelp->display_section(10101); //study-guide //show_html_document("study-guide.htm"); return; } //verify if it is a LenMus command link int iPos = sLocation.Find("lenmus#"); if (iPos == wxNOT_FOUND) { // external link ::wxLaunchDefaultBrowser(sLocation); } else { wxString filename = sLocation.substr(12); Paths* pPaths = m_appScope.get_paths(); wxString sPath = pPaths->GetBooksPath(); wxFileName oFile(sPath, filename, wxPATH_NATIVE); if (!oFile.FileExists()) { //try to use the english version sPath = pPaths->GetLocaleRootPath(); oFile.AssignDir(sPath); oFile.AppendDir("en"); oFile.AppendDir("books"); oFile.SetFullName(filename); if (!oFile.FileExists()) { wxMessageBox(_("Sorry: File not found!")); LOMSE_LOG_WARN(str(boost::format("File '%s' not found!") % oFile.GetFullPath().wx_str() )); return; } } m_fullName = oFile.GetFullPath(); EndModal(wxID_OK); } }