void FBReader::openBookInternal(BookDescriptionPtr description) { if (!description.isNull()) { BookTextView &bookTextView = (BookTextView&)*myBookTextView; ContentsView &contentsView = (ContentsView&)*myContentsView; FootnoteView &footnoteView = (FootnoteView&)*myFootnoteView; bookTextView.saveState(); bookTextView.setModel(0, "", ""); bookTextView.setContentsModel(0); contentsView.setModel(0, ""); if (myModel != 0) { delete myModel; } myModel = new BookModel(description); ZLStringOption(ZLCategoryKey::STATE, STATE, BOOK, std::string()).setValue(myModel->fileName()); const std::string &lang = description->language(); ZLTextHyphenator::instance().load(lang); bookTextView.setModel(myModel->bookTextModel(), lang, description->fileName()); bookTextView.setCaption(description->title()); bookTextView.setContentsModel(myModel->contentsModel()); footnoteView.setModel(0, lang); footnoteView.setCaption(description->title()); contentsView.setModel(myModel->contentsModel(), lang); contentsView.setCaption(description->title()); myRecentBooks.addBook(description); ((RecentBooksPopupData&)*myRecentBooksPopupData).updateId(); } }
void FBReader::openBookInternal(BookDescriptionPtr description) { if (description) { BookTextView &bookTextView = (BookTextView&)*myBookTextView; ContentsView &contentsView = (ContentsView&)*myContentsView; FootnoteView &footnoteView = (FootnoteView&)*myFootnoteView; bookTextView.saveState(); bookTextView.setModel(shared_ptr<ZLTextModel>(), "", ""); bookTextView.setContentsModel(shared_ptr<ZLTextModel>()); contentsView.setModel(shared_ptr<ZLTextModel>(), ""); if (myModel != 0) { delete myModel; } myModel = new BookModel(description); bookOpened = true; // If it's DRM content, check if it's valid to open if(myModel->drm() && BookModel::OPEN_NORMAL != myModel->openStatus()) { if (sys::SysStatus::instance().isSystemBusy()) { sys::SysStatus::instance().setSystemBusy(false); } ui::MessageDialog dialog(QMessageBox::Critical, QCoreApplication::tr("Failed!"), QCoreApplication::tr("Failed opening the " "book! The book is damaged or you do " "not have permission to open it."), QMessageBox::Yes); dialog.exec(); bookOpened = false; return; } ZLStringOption(ZLCategoryKey::STATE, STATE, BOOK, std::string()).setValue(myModel->fileName()); const std::string &lang = description->language(); ZLTextHyphenator::instance().load(lang); bookTextView.setModel(myModel->bookTextModel(), lang, description->fileName()); bookTextView.setCaption(description->title()); bookTextView.setContentsModel(myModel->contentsModel()); footnoteView.setModel(shared_ptr<ZLTextModel>(), lang); footnoteView.setCaption(description->title()); contentsView.setModel(myModel->contentsModel(), lang); contentsView.setCaption(description->title()); } }
void CollectionView::removeBook(BookDescriptionPtr book) { if (book.isNull()) { return; } if (book == mySelectedBook) { mySelectedBook = 0; } CollectionModel &cModel = collectionModel(); ZLResourceKey boxKey("removeBookBox"); const std::string message = ZLStringUtil::printf(ZLDialogManager::dialogMessage(boxKey), book->title()); if (ZLDialogManager::instance().questionBox(boxKey, message, ZLDialogManager::YES_BUTTON, ZLDialogManager::NO_BUTTON) == 0) { cModel.removeAllMarks(); BookList().removeFileName(book->fileName()); cModel.removeBook(book); if (cModel.paragraphsNumber() == 0) { setStartCursor(0); } else { size_t index = startCursor().paragraphCursor().index(); if (index >= cModel.paragraphsNumber()) { index = cModel.paragraphsNumber() - 1; } while (!((ZLTextTreeParagraph*)cModel[index])->parent()->isOpen()) { --index; } gotoParagraph(index); } rebuildPaintInfo(true); selectBook(mySelectedBook); application().refreshWindow(); myCollection.rebuild(false); } }
bool DescriptionComparator::operator() (const BookDescriptionPtr d1, const BookDescriptionPtr d2) { return d1->title() < d2->title(); }