void FBReader::initWindow() { ZLApplication::initWindow(); trackStylus(true); MigrationRunnable migration; if (migration.shouldMigrate()) { ZLDialogManager::instance().wait(ZLResourceKey("migrate"), migration); } if (!myBookAlreadyOpen) { BookDescriptionPtr description; if (!myBookToOpen.empty()) { createDescription(myBookToOpen, description); } if (description.isNull()) { ZLStringOption bookName(ZLCategoryKey::STATE, STATE, BOOK, ""); description = BookDescription::getDescription(bookName.value()); } if (description.isNull()) { description = BookDescription::getDescription(helpFileName(ZLibrary::Language())); } if (description.isNull()) { description = BookDescription::getDescription(helpFileName("en")); } openBook(description); } refreshWindow(); // ZLTimeManager::instance().addTask(new TimeUpdater(*this), 1000); }
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 BookCollection::addDescription(BookDescriptionPtr description) { if (description.isNull()) { return; } AuthorPtr author = description->author(); const std::string &displayName = author->displayName(); const std::string &sortKey = author->sortKey(); std::map<AuthorPtr,Books>::iterator it = myCollection.begin(); for (; it != myCollection.end(); ++it) { AuthorPtr author1 = (*it).first; if ((author1->sortKey() == sortKey) && (author1->displayName() == displayName)) { break; } } if (it != myCollection.end()) { (*it).second.push_back(description); } else { Books books; books.push_back(description); myCollection.insert(std::pair<AuthorPtr,Books>(author, books)); myAuthors.push_back(author); } }
void CollectionView::editBookInfo(BookDescriptionPtr book) { if (!book.isNull() && BookInfoDialog(myCollection, book->fileName()).dialog().run()) { myCollection.rebuild(false); myDoUpdateModel = true; selectBook(book); application().refreshWindow(); } }
void FBReader::openFile(const std::string &fileName) { BookDescriptionPtr description; createDescription(fileName, description); if (!description.isNull()) { openBook(description); refreshWindow(); } }
void LastOpenedBooks::addBook(const std::string &fileName) { for (Books::iterator it = myBooks.begin(); it != myBooks.end(); ++it) { if ((*it)->fileName() == fileName) { myBooks.erase(it); break; } } BookDescriptionPtr description = BookDescription::getDescription(fileName); if (!description.isNull()) { myBooks.insert(myBooks.begin(), description); } const size_t maxSize = MaxListSizeOption.value(); if (myBooks.size() > maxSize) { myBooks.erase(myBooks.begin() + maxSize, myBooks.end()); } }
LastOpenedBooks::LastOpenedBooks() : MaxListSizeOption(ZLCategoryKey::STATE, GROUP, "MaxSize", 1, 100, 10) { const int size = MaxListSizeOption.value(); for (int i = 0; i < size; ++i) { std::string num = BOOK; ZLStringUtil::appendNumber(num, i); std::string name = ZLStringOption(ZLCategoryKey::STATE, GROUP, num, "").value(); if (!name.empty()) { BookDescriptionPtr description = BookDescription::getDescription(name); if (!description.isNull()) { myBooks.push_back(description); } } } }
bool CollectionView::_onStylusPress(int x, int y) { fbreader().setHyperlinkCursor(false); const ZLTextElementArea *imageArea = elementByCoordinates(x, y); if ((imageArea != 0) && (imageArea->Kind == ZLTextElement::IMAGE_ELEMENT)) { ZLTextWordCursor cursor = startCursor(); cursor.moveToParagraph(imageArea->ParagraphIndex); cursor.moveTo(imageArea->ElementIndex, 0); const ZLTextElement &element = cursor.element(); if (element.kind() != ZLTextElement::IMAGE_ELEMENT) { return false; } const ZLTextImageElement &imageElement = (ZLTextImageElement&)element; const std::string &id = imageElement.id(); if (id == CollectionModel::BookInfoImageId) { editBookInfo(collectionModel().bookByParagraphIndex(imageArea->ParagraphIndex)); return true; } else if (id == CollectionModel::RemoveBookImageId) { removeBook(collectionModel().bookByParagraphIndex(imageArea->ParagraphIndex)); return true; } else if (id == CollectionModel::RemoveTagImageId) { removeTag(collectionModel().tagByParagraphIndex(imageArea->ParagraphIndex)); return true; } else if (id == CollectionModel::TagInfoImageId) { editTagInfo(collectionModel().tagByParagraphIndex(imageArea->ParagraphIndex)); return true; } else { return false; } } int index = paragraphIndexByCoordinates(x, y); if (index == -1) { return false; } BookDescriptionPtr book = collectionModel().bookByParagraphIndex(index); if (!book.isNull()) { fbreader().openBook(book); fbreader().showBookTextView(); return true; } return false; }
bool CollectionView::_onStylusMove(int x, int y) { const ZLTextElementArea *imageArea = elementByCoordinates(x, y); if ((imageArea != 0) && (imageArea->Kind == ZLTextElement::IMAGE_ELEMENT)) { fbreader().setHyperlinkCursor(true); return true; } int index = paragraphIndexByCoordinates(x, y); if (index != -1) { BookDescriptionPtr book = collectionModel().bookByParagraphIndex(index); if (!book.isNull()) { fbreader().setHyperlinkCursor(true); return true; } } fbreader().setHyperlinkCursor(false); return false; }
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); } }
void CollectionView::selectBook(BookDescriptionPtr book) { mySelectedBook = book; if (myDoUpdateModel) { shared_ptr<ZLTextModel> oldModel = model(); setModel(0, ""); ((CollectionModel&)*oldModel).update(); setModel(oldModel, ""); myDoUpdateModel = false; } if (!book.isNull()) { collectionModel().removeAllMarks(); const std::vector<int> &toSelect = collectionModel().paragraphIndicesByBook(book); for (std::vector<int>::const_iterator it = toSelect.begin(); it != toSelect.end(); ++it) { highlightParagraph(*it); } if (!toSelect.empty()) { preparePaintInfo(); gotoParagraph(toSelect[toSelect.size() - 1]); scrollPage(false, ZLTextView::SCROLL_PERCENTAGE, 40); } } }