bool PasswordRecoveryDialog::run(NetworkAuthenticationManager &mgr) { std::string errorMessage; std::string email; while (true) { if (!runDialog(email, errorMessage)) { LogOutRunnable logout(mgr); logout.executeWithUI(); return false; } PasswordRecoveryRunnable recovery(mgr, email); recovery.executeWithUI(); if (recovery.hasErrors()) { errorMessage = recovery.errorMessage(); LogOutRunnable logout(mgr); logout.executeWithUI(); continue; } ZLResourceKey boxKey("recoverySuccessfulBox"); const std::string message = ZLStringUtil::printf(ZLDialogManager::dialogMessage(boxKey), email); ZLDialogManager::Instance().informationBox(boxKey, message); return true; } }
void NetworkBookBuyDirectlyAction::onAuthorised(ZLUserDataHolder &data, const std::string &error) { (void) data; if (!error.empty()) { // finished(error); return; } NetworkAuthenticationManager &mgr = *myBook.Link.authenticationManager(); if (!mgr.needPurchase(myBook)) { // finished(std::string()); return; } ZLResourceKey boxKey("purchaseConfirmBox"); const std::string message = ZLStringUtil::printf(ZLDialogManager::dialogMessage(boxKey), myBook.Title); const int code = ZLDialogManager::Instance().questionBox(boxKey, message, ZLResourceKey("buy"), ZLResourceKey("buyAndDownload"), ZLDialogManager::CANCEL_BUTTON); if (code == 2) { // finished(std::string()); return; } bool downloadBook = code == 1; if (mgr.needPurchase(myBook)) { ZLUserDataHolder *bookData = new ZLUserDataHolder; if (downloadBook) bookData->addUserData("downloadBook", new ZLUserData); // mgr.purchaseBook(myBook, ZLExecutionData::createListener(bookData, this, &NetworkBookBuyDirectlyAction::onPurchased)); } else if (downloadBook) { NetworkBookDownloadAction::run(); } }
void NetworkBookDeleteAction::run() { ZLResourceKey boxKey("deleteLocalCopyBox"); const std::string message = ZLStringUtil::printf(ZLDialogManager::dialogMessage(boxKey), myBook.Title); if (ZLDialogManager::Instance().questionBox(boxKey, message, ZLDialogManager::YES_BUTTON, ZLDialogManager::NO_BUTTON) != 0) { // finished(std::string()); return; } myBook.removeLocalFiles(); FBReader::Instance().refreshWindow(); // finished(std::string()); }
bool FBReader::createBook(const ZLFile &bookFile, shared_ptr<Book> &book) { shared_ptr<FormatPlugin> plugin = PluginCollection::Instance().plugin(bookFile, false); if (!plugin.isNull()) { std::string error = plugin->tryOpen(bookFile); if (!error.empty()) { ZLResourceKey boxKey("openBookErrorBox"); ZLDialogManager::Instance().errorBox( boxKey, ZLStringUtil::printf(ZLDialogManager::dialogMessage(boxKey), error) ); } else { book = BooksDBUtil::getBook(bookFile.path()); if (!book.isNull()) { BooksDB::Instance().insertIntoBookList(*book); } } return true; } if (!bookFile.isArchive()) { return false; } std::queue<std::string> archiveNames; archiveNames.push(bookFile.path()); std::vector<std::string> items; while (!archiveNames.empty()) { shared_ptr<ZLDir> archiveDir = ZLFile(archiveNames.front()).directory(); archiveNames.pop(); if (archiveDir.isNull()) { continue; } archiveDir->collectFiles(items, true); for (std::vector<std::string>::const_iterator it = items.begin(); it != items.end(); ++it) { const std::string itemName = archiveDir->itemPath(*it); ZLFile subFile(itemName); if (subFile.isArchive()) { archiveNames.push(itemName); } else if (createBook(subFile, book)) { return true; } } items.clear(); } return false; }
void NetworkBookDownloadAction::bookDownloaded(DownloadBookRunnable *downloader) { if (downloader->hasErrors()) { downloader->showErrorMessage(); // finished(downloader->errorMessage()); // setListener(0); return; } FBReader &fbreader = FBReader::Instance(); shared_ptr<Book> downloaderBook; const std::string fileName = downloader->fileName(); fbreader.createBook(ZLFile(fileName), downloaderBook); if (downloaderBook.isNull()) { ZLFile(fileName).remove(); ZLResourceKey boxKey("cantOpenDownloadedFile"); const std::string message = ZLStringUtil::printf(ZLDialogManager::dialogMessage(boxKey), myBook.Title); ZLDialogManager::Instance().errorBox(boxKey, message); fbreader.refreshWindow(); // finished(message); // setListener(0); return; } downloaderBook->removeAllAuthors(); for (std::vector<NetworkBookItem::AuthorData>::const_iterator it = myBook.Authors.begin(); it != myBook.Authors.end(); ++it) { downloaderBook->addAuthor(it->DisplayName, it->SortKey); } std::string bookTitle = myBook.Title; if (!myTag.empty()) { bookTitle += " (" + myTag + ")"; } downloaderBook->setTitle(bookTitle); downloaderBook->setLanguage(myBook.Language); for (std::vector<std::string>::const_iterator it = myBook.Tags.begin(); it != myBook.Tags.end(); ++it) { downloaderBook->addTag(*it); } if (!myTag.empty()) { downloaderBook->addTag(myTag); } Library::Instance().addBook(downloaderBook); fbreader.openBook(downloaderBook); fbreader.setMode(FBReader::BOOK_TEXT_MODE); fbreader.refreshWindow(); // finished(std::string()); // setListener(0); AppLog("bookDownloaded"); //myNode->close(); }
bool FBReader::createDescription(const std::string& fileName, BookDescriptionPtr &description) { ZLFile bookFile = ZLFile(fileName); FormatPlugin *plugin = PluginCollection::instance().plugin(ZLFile(fileName), false); if (plugin != 0) { std::string error = plugin->tryOpen(fileName); if (!error.empty()) { ZLResourceKey boxKey("openBookErrorBox"); ZLDialogManager::instance().errorBox( boxKey, ZLStringUtil::printf(ZLDialogManager::dialogMessage(boxKey), error) ); } else { BookList().addFileName(bookFile.path()); description = BookDescription::getDescription(bookFile.path()); } return true; } if (!bookFile.isArchive()) { return false; } std::queue<std::string> archiveNames; archiveNames.push(bookFile.path()); std::vector<std::string> items; while (!archiveNames.empty()) { shared_ptr<ZLDir> archiveDir = ZLFile(archiveNames.front()).directory(); archiveNames.pop(); if (archiveDir.isNull()) { continue; } archiveDir->collectFiles(items, true); for (std::vector<std::string>::const_iterator it = items.begin(); it != items.end(); ++it) { const std::string itemName = archiveDir->itemPath(*it); ZLFile subFile(itemName); if (subFile.isArchive()) { archiveNames.push(itemName); } else if (createDescription(itemName, description)) { return true; } } items.clear(); } return 0; }
void CollectionView::removeTag(const std::string &tag) { if (tag.empty()) { return; } ZLResourceKey boxKey("removeTagBox"); const std::string message = ZLStringUtil::printf(ZLDialogManager::dialogMessage(boxKey), tag); enum { REMOVE_TAG, REMOVE_SUBTREE, DONT_REMOVE } code = DONT_REMOVE; if (myCollection.hasSubtags(tag)) { if (myCollection.hasBooks(tag)) { switch (ZLDialogManager::instance().questionBox(boxKey, message, ZLResourceKey("thisOnly"), ZLResourceKey("withSubtags"), ZLDialogManager::CANCEL_BUTTON )) { case 0: code = REMOVE_TAG; break; case 1: code = REMOVE_SUBTREE; break; } } else { if (ZLDialogManager::instance().questionBox(boxKey, message, ZLResourceKey("withSubtags"), ZLDialogManager::CANCEL_BUTTON) == 0) { code = REMOVE_SUBTREE; } } } else { if (ZLDialogManager::instance().questionBox(boxKey, message, ZLDialogManager::YES_BUTTON, ZLDialogManager::CANCEL_BUTTON) == 0) { code = REMOVE_TAG; } } if (code != DONT_REMOVE) { collectionModel().removeAllMarks(); myCollection.removeTag(tag, code == REMOVE_SUBTREE); myCollection.rebuild(true); myDoUpdateModel = true; selectBook(mySelectedBook); application().refreshWindow(); } }
int BookRemoveAction::removeBookDialog() const { ZLResourceKey boxKey("removeBookBox"); const ZLResource &msgResource = ZLResource::resource("dialog")[boxKey]; switch (Library::Instance().canRemove(myBook)) { case Library::REMOVE_DONT_REMOVE: return Library::REMOVE_DONT_REMOVE; case Library::REMOVE_FROM_DISK: { ZLFile physFile(ZLFile(myBook->filePath()).physicalFilePath()); const std::string message = ZLStringUtil::printf(msgResource["deleteFile"].value(), physFile.name(false)); if (ZLDialogManager::Instance().questionBox(boxKey, message, ZLDialogManager::YES_BUTTON, ZLDialogManager::NO_BUTTON) == 0) { return Library::REMOVE_FROM_DISK; } return Library::REMOVE_DONT_REMOVE; } case Library::REMOVE_FROM_LIBRARY: { const std::string message = ZLStringUtil::printf(ZLDialogManager::dialogMessage(boxKey), myBook->title()); if (ZLDialogManager::Instance().questionBox(boxKey, message, ZLDialogManager::YES_BUTTON, ZLDialogManager::NO_BUTTON) == 0) { return Library::REMOVE_FROM_LIBRARY; } return Library::REMOVE_DONT_REMOVE; } case Library::REMOVE_FROM_LIBRARY_AND_DISK: { ZLResourceKey removeFileKey("removeFile"); ZLResourceKey removeLinkKey("removeLink"); const std::string message = ZLStringUtil::printf(ZLDialogManager::dialogMessage(boxKey), myBook->title()); switch(ZLDialogManager::Instance().questionBox(boxKey, message, removeLinkKey, removeFileKey, ZLDialogManager::CANCEL_BUTTON)) { case 0: return Library::REMOVE_FROM_LIBRARY; case 1: return Library::REMOVE_FROM_DISK; case 2: return Library::REMOVE_DONT_REMOVE; } } } return Library::REMOVE_DONT_REMOVE; }
void BookRemoveAction::run() { switch (removeBookDialog()) { case Library::REMOVE_FROM_DISK: { const std::string path = ZLFile(myBook->filePath()).physicalFilePath(); ZLFile physicalFile(path); if (!physicalFile.remove()) { ZLResourceKey boxKey("removeFileErrorBox"); const std::string message = ZLStringUtil::printf(ZLDialogManager::dialogMessage(boxKey), path); ZLDialogManager::Instance().errorBox(boxKey, message); } } // yes, we go through this label case Library::REMOVE_FROM_LIBRARY: Library::Instance().removeBook(myBook); FBReader::Instance().refreshWindow(); case Library::REMOVE_DONT_REMOVE: break; } }
void BooksUtil::removeTag(shared_ptr<Tag> tag) { ZLResourceKey boxKey("removeTagBox"); const std::string message = ZLStringUtil::printf(ZLDialogManager::dialogMessage(boxKey), tag->fullName()); enum { REMOVE_TAG, REMOVE_SUBTREE, DONT_REMOVE } code = DONT_REMOVE; Library &library = Library::Instance(); if (library.hasSubtags(tag)) { if (library.hasBooks(tag)) { switch (ZLDialogManager::Instance().questionBox(boxKey, message, ZLResourceKey("thisOnly"), ZLResourceKey("withSubtags"), ZLDialogManager::CANCEL_BUTTON )) { case 0: code = REMOVE_TAG; break; case 1: code = REMOVE_SUBTREE; break; } } else { if (ZLDialogManager::Instance().questionBox(boxKey, message, ZLResourceKey("withSubtags"), ZLDialogManager::CANCEL_BUTTON) == 0) { code = REMOVE_SUBTREE; } } } else { if (ZLDialogManager::Instance().questionBox(boxKey, message, ZLDialogManager::YES_BUTTON, ZLDialogManager::CANCEL_BUTTON) == 0) { code = REMOVE_TAG; } } if (code != DONT_REMOVE) { library.removeTag(tag, code == REMOVE_SUBTREE); // TODO: select current node (?) again FBReader::Instance().refreshWindow(); } }
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 FBReader::createBook(const std::string& fileName, shared_ptr<Book> &book) { ZLFile bookFile = ZLFile(fileName); // PB: return if physical file doesnt exists if (!bookFile.exists()) return false; // PB shared_ptr<FormatPlugin> plugin = PluginCollection::Instance().plugin(ZLFile(fileName), false); if (!plugin.isNull()) { std::string error = plugin->tryOpen(fileName); if (!error.empty()) { ZLResourceKey boxKey("openBookErrorBox"); ZLDialogManager::Instance().errorBox( boxKey, ZLStringUtil::printf(ZLDialogManager::dialogMessage(boxKey), error) ); } else { // PB: we dont like to load the book from the DB, just from file book = Book::loadFromFile(fileName /*bookFile.physicalFilePath()*/, FBReader::EncodingOverride); if (FBReader::LanguageOverride != "" && !book.isNull()) book->setLanguage(FBReader::LanguageOverride); //book = BooksDBUtil::getBook(bookFile.path()); //if (!book.isNull()) { // BooksDB::Instance().insertIntoBookList(*book); //} // PB } return true; } if (!bookFile.isArchive()) { return false; } std::queue<std::string> archiveNames; archiveNames.push(bookFile.path()); std::vector<std::string> items; while (!archiveNames.empty()) { shared_ptr<ZLDir> archiveDir = ZLFile(archiveNames.front()).directory(); archiveNames.pop(); if (archiveDir.isNull()) { continue; } archiveDir->collectFiles(items, true); for (std::vector<std::string>::const_iterator it = items.begin(); it != items.end(); ++it) { const std::string itemName = archiveDir->itemPath(*it); ZLFile subFile(itemName); if (subFile.isArchive()) { archiveNames.push(itemName); } else if (createBook(itemName, book)) { return true; } } items.clear(); } return false; }