Example #1
0
void FBReader::openBookInternal(BookDescriptionPtr description) {
	if (!description.isNull()) {
		BookTextView &bookTextView = (BookTextView&)*myBookTextView;
		ContentsView &contentsView = (ContentsView&)*myContentsView;
		FootnoteView &footnoteView = (FootnoteView&)*myFootnoteView;
		RecentBooksView &recentBooksView = (RecentBooksView&)*myRecentBooksView;

		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());
		ZLTextHyphenator::instance().load(description->language());
		bookTextView.setModel(myModel->bookTextModel(), description->fileName());
		bookTextView.setCaption(description->title());
		bookTextView.setContentsModel(myModel->contentsModel());
		footnoteView.setModel(0);
		footnoteView.setCaption(description->title());
		contentsView.setModel(myModel->contentsModel());
		contentsView.setCaption(description->title());

		recentBooksView.lastBooks().addBook(description->fileName());
	}
}
Example #2
0
void CollectionView::editBookInfo(BookDescriptionPtr book) {
	if (!book.isNull() && BookInfoDialog(myCollection, book->fileName()).dialog().run()) {
		myCollection.rebuild(false);
		myDoUpdateModel = true;
		selectBook(book);
		application().refreshWindow();
	}
}
Example #3
0
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());
    }
}
Example #4
0
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);
	}
}