[Amis-vcs] SF.net SVN: amis: [2179] branches/amis3
Brought to you by:
julienq,
marisademeglio
From: <mar...@us...> - 2007-09-27 13:51:22
|
Revision: 2179 http://amis.svn.sourceforge.net/amis/?rev=2179&view=rev Author: marisademeglio Date: 2007-09-27 06:51:22 -0700 (Thu, 27 Sep 2007) Log Message: ----------- If the key doesn't work for the protected book, then the book is played as normal. To test: other cases where opening a book fails (see if the last-read book is loaded instead) Also fixed: a bug in ResolveSmilDataVisitor Modified Paths: -------------- branches/amis3/AmisCore/src/dtb/Dtb.cpp branches/amis3/AmisCore/src/dtb/DtbFileSet.cpp branches/amis3/AmisCore/src/dtb/nav/NavVisitor.cpp branches/amis3/AmisGuiMFC2/include/gui/AmisGuiMFC2.h branches/amis3/AmisGuiMFC2/src/gui/AmisGuiMFC2.cpp branches/amis3/AmisGuiMFC2/src/pdtb.cpp Modified: branches/amis3/AmisCore/src/dtb/Dtb.cpp =================================================================== --- branches/amis3/AmisCore/src/dtb/Dtb.cpp 2007-09-27 12:15:02 UTC (rev 2178) +++ branches/amis3/AmisCore/src/dtb/Dtb.cpp 2007-09-27 13:51:22 UTC (rev 2179) @@ -220,8 +220,6 @@ if (checkForCopyProtection(mpMetadata)) { mbIsProtected = true; - if (mpNavModel) delete mpNavModel; - if (mpCustomTests) delete mpCustomTests; if (mpCallbackForPreprocessingBookKey != NULL) { @@ -233,12 +231,16 @@ //reparse the ncc.pdtb file if (!ncc_file_reader.readFromFile(getFileSet()->getProtectedNavFilepath())) return false; + if (mpNavModel) delete mpNavModel; + if (mpCustomTests) delete mpCustomTests; mpNavModel = ncc_file_reader.getNavModel(); mpCustomTests = ncc_file_reader.getCustomTests(); } - else return false; //TODO error message } - else return false; //TODO error message + /* if: 1. no function registered to handle protected books or + 2. that function failed + then: playback of NCC.html continues and it will say "this book is protected... " + */ } mpSpine = spine_visitor.getSpine(mpNavModel, this->getFileSet()->getBookDirectory()); Modified: branches/amis3/AmisCore/src/dtb/DtbFileSet.cpp =================================================================== --- branches/amis3/AmisCore/src/dtb/DtbFileSet.cpp 2007-09-27 12:15:02 UTC (rev 2178) +++ branches/amis3/AmisCore/src/dtb/DtbFileSet.cpp 2007-09-27 13:51:22 UTC (rev 2179) @@ -160,7 +160,7 @@ //is this an opf file? bool amis::dtb::DtbFileSet::isOpfFile(const ambulant::net::url* filepath) { - string file_ext = amis::util::FilePathTools::getFileName(filepath->get_path()); + string file_ext = amis::util::FilePathTools::getExtension(filepath->get_path()); //convert the string to lower case before doing a comparison std::transform(file_ext.begin(), file_ext.end(), file_ext.begin(), (int(*)(int))tolower); @@ -202,6 +202,8 @@ else if(safe_filename[i] == ':') safe_filename.replace(i, 1, "__"); + else if(safe_filename[i] == ' ') + safe_filename.replace(i, 1, "__"); } safe_filename.append(".bmk"); Modified: branches/amis3/AmisCore/src/dtb/nav/NavVisitor.cpp =================================================================== --- branches/amis3/AmisCore/src/dtb/nav/NavVisitor.cpp 2007-09-27 12:15:02 UTC (rev 2178) +++ branches/amis3/AmisCore/src/dtb/nav/NavVisitor.cpp 2007-09-27 13:51:22 UTC (rev 2179) @@ -66,7 +66,12 @@ return; mpPreviousNavNode = NULL; + //this is the map of NavNodes to smil ids (one id to many nodes) + //an id in section 1.1 is in section 1.1 and not in section 1 + //an id in any section may also be referenced by a page node mpMap = new NodeRefMap; + + //a map of text ids and the smil files they occur in mpTextMap = new StringMap; unsigned int i = 0; @@ -79,12 +84,19 @@ //have their audio data filled in (this data isn't built into the NCC files) if (resolveNavNodeAudioData == true) { + //who = which nav nodes WhoRefersToThisSmilFile who_visitor; p_nav_nodes = who_visitor.findOut(pModel, pSpine->getSmilFilePath(i)); } - const ambulant::net::url* smilfile = pSpine->getSmilFilePath(i);//->join_to_base(*bookDir); + const ambulant::net::url* smilfile = pSpine->getSmilFilePath(i); amis::io::QuickDataSmilFileReader quick_reader; + //get all the ids and text src's from this smil file. also fill in the audio data for the nav nodes. + //big id list is a list of all SMIL element IDs + //text map is a map of the smilfile name and the text src in it + //p_nav_nodes is a list of pointers to nav nodes that refer to this smil file quick_reader.readFromFile(smilfile, &mBigIdList, mpTextMap, p_nav_nodes); + + //this deletes a pointer to a list of pointers, not the nodes themselves if (p_nav_nodes != NULL) delete p_nav_nodes; } @@ -183,7 +195,7 @@ else { //look for the end of the range - for (it_b = it_a + 1; it_b <= mBigIdList.end(); it_b++) + for (it_b = it_a; it_b < mBigIdList.end(); it_b++) { if ((*it_b).compare(b) == 0) { Modified: branches/amis3/AmisGuiMFC2/include/gui/AmisGuiMFC2.h =================================================================== --- branches/amis3/AmisGuiMFC2/include/gui/AmisGuiMFC2.h 2007-09-27 12:15:02 UTC (rev 2178) +++ branches/amis3/AmisGuiMFC2/include/gui/AmisGuiMFC2.h 2007-09-27 13:51:22 UTC (rev 2179) @@ -88,6 +88,8 @@ private: void initPathsAndFiles(); + void openBook(const ambulant::net::url*); + void openLastReadBook(); std::string mAppPath; std::string mLocalizationDll; ambulant::net::url mURL; Modified: branches/amis3/AmisGuiMFC2/src/gui/AmisGuiMFC2.cpp =================================================================== --- branches/amis3/AmisGuiMFC2/src/gui/AmisGuiMFC2.cpp 2007-09-27 12:15:02 UTC (rev 2178) +++ branches/amis3/AmisGuiMFC2/src/gui/AmisGuiMFC2.cpp 2007-09-27 13:51:22 UTC (rev 2179) @@ -105,6 +105,9 @@ BOOL CAmisGuiMFC2App::InitInstance() { + //this says "use the registry instead of ini files" (for windows-specific app preferences). we use it for UAKs + SetRegistryKey(_T("Amis")); + // InitCommonControls() is required on Windows XP if an application // manifest specifies use of ComCtl32.dll version 6 or later to enable // visual styles. Otherwise, any window creation will fail. @@ -248,34 +251,61 @@ return mpRecentBooks; } +void CAmisGuiMFC2App::openBook(const ambulant::net::url* filename) +{ + bool b_a_book_was_open = false; + //close the open book + if (mbBookIsOpen == true) + { + b_a_book_was_open = true; + OnFileClose(); + } + + if (!filename->is_empty_path()) + { + if (amis::dtb::DtbWithHooks::Instance()->open(filename, &very_temporary_bookmarks_dir)) + { + mbBookIsOpen = true; + amis::dtb::DtbWithHooks::Instance()->startReading(true); + } + else + { + //TODO localize these messages + CString message1 = _T("Error opening book"); + CString message2 = _T("Error opening book. Reloading previous book."); + + if (b_a_book_was_open) + { + AfxMessageBox(message2); + openLastReadBook(); + } + else AfxMessageBox(message1); + } + } +} +void CAmisGuiMFC2App::openLastReadBook() +{ + //close any open book + OnFileClose(); + + if (mpRecentBooks->getLastRead()) + openBook(&mpRecentBooks->getLastRead()->mPath); +} + void CAmisGuiMFC2App::OnFileOpen() { amis::gui::dialogs::AmisFileDialog* p_dlg = new amis::gui::dialogs::AmisFileDialog(amis::gui::dialogs::AmisFileDialog::getFileOpenFilter()); string filename = p_dlg->showOpen(); - //the user is able to open UAK files through AMIS if (isUserKeyFile(filename)) { importUserKeysIntoRegistry(filename); } - - //else it's a book else { - ambulant::net::url filename_url = ambulant::net::url::from_filename(filename); - if (!filename_url.is_empty_path()) - { - if (amis::dtb::DtbWithHooks::Instance()->open(&filename_url, &very_temporary_bookmarks_dir)) - { - mbBookIsOpen = true; - amis::dtb::DtbWithHooks::Instance()->startReading(true); - } - else - { - //TODO give an error that book could not be opened - } - } + ambulant::net::url book_path = ambulant::net::url::from_filename(filename); + openBook(&book_path); } } @@ -320,11 +350,7 @@ amis::RecentBookEntry* p_book = NULL; p_book = mpRecentBooks->getEntry(selection); - if (amis::dtb::DtbWithHooks::Instance()->open(&p_book->mPath, &very_temporary_bookmarks_dir)) - { - amis::dtb::DtbWithHooks::Instance()->startReading(true); - } - + openBook(&p_book->mPath); } void CAmisGuiMFC2App::OnNavNextSection() @@ -360,6 +386,7 @@ MainWndParts::Instance()->mpMmView->OnDestroy(); amis::dtb::DtbWithHooks::Instance()->DestroyInstance(); amis::gui::MainWndParts::Instance()->mpSidebar->m_wndDlg.clearAll(); + amis::gui::MenuManip::Instance()->setupMenusNothingOpen(); mbBookIsOpen = false; } } @@ -392,15 +419,7 @@ { str_url = T2A(dlg.getUrl()); ambulant::net::url book_url = ambulant::net::url::from_url(str_url); - if (amis::dtb::DtbWithHooks::Instance()->open(&book_url, &very_temporary_bookmarks_dir)) - { - amis::dtb::DtbWithHooks::Instance()->startReading(true); - } - else - { - //TODO: localize this - AfxMessageBox(_T("Error opening book")); - } + openBook(&book_url); } } @@ -456,4 +475,5 @@ void CAmisGuiMFC2App::OnResetFontSize() { TextRenderBrain::Instance()->resetFontSize(); -} \ No newline at end of file +} + Modified: branches/amis3/AmisGuiMFC2/src/pdtb.cpp =================================================================== --- branches/amis3/AmisGuiMFC2/src/pdtb.cpp 2007-09-27 12:15:02 UTC (rev 2178) +++ branches/amis3/AmisGuiMFC2/src/pdtb.cpp 2007-09-27 13:51:22 UTC (rev 2179) @@ -1,10 +1,12 @@ #include "pdtb.h" #include "stdafx.h" +//for string transformations +#include <algorithm> //stupid hack .. for now #define WITH_PROTECTED_BOOK_SUPPORT 1 -//#ifdef WITH_PROTECTED_BOOK_SUPPORT +#ifdef WITH_PROTECTED_BOOK_SUPPORT #include "ambulant/common/plugin_engine.h" #include "../../ambulant-private/pdtbplugin/pdtbplugin.h" @@ -64,10 +66,12 @@ return false; } -bool isUserKeyFile(std::string filename) +bool isUserKeyFile(string filename) { - string ext = amis::util::FilePathTools::getExtension(filename); - if (ext == "uak" || ext == "UAK") return true; + string file_ext = amis::util::FilePathTools::getExtension(filename); + //convert the string to lower case before doing a comparison + std::transform(file_ext.begin(), file_ext.end(), file_ext.begin(), (int(*)(int))tolower); + if (file_ext == "uak") return true; else return false; } -//#endif \ No newline at end of file +#endif \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |