void FBReader::initWindow() { ZLApplication::initWindow(); trackStylus(true); MigrationRunnable migration; if (migration.shouldMigrate()) { ZLDialogManager::Instance().wait(ZLResourceKey("migrate"), migration); } if (!myBookAlreadyOpen) { shared_ptr<Book> book; if (!myBookToOpen.empty()) { createBook(ZLFile(myBookToOpen), book); } if (book.isNull()) { const BookList &books = Library::Instance().recentBooks(); if (!books.empty()) { book = books[0]; } } if (book.isNull()) { book = BooksDBUtil::getBook(helpFileName(ZLibrary::Language())); } if (book.isNull()) { book = BooksDBUtil::getBook(helpFileName("en")); } openBook(book); } refreshWindow(); ZLTimeManager::Instance().addTask(new TimeUpdater(), 1000); }
void FBReader::tryShowFootnoteView(const std::string &id, const std::string &type) { if (type == "external") { openLinkInBrowser(id); } else if (type == "internal") { if (myMode == BOOK_TEXT_MODE && !myModel.isNull()) { BookModel::Label label = myModel->label(id); if (!label.Model.isNull()) { if (label.Model == myModel->bookTextModel()) { bookTextView().gotoParagraph(label.ParagraphNumber); } else { FootnoteView &view = ((FootnoteView&)*myFootnoteView); view.setModel(label.Model); setMode(FOOTNOTE_MODE); view.gotoParagraph(label.ParagraphNumber); } setHyperlinkCursor(false); refreshWindow(); } } } else if (type == "book") { DownloadBookRunnable downloader(id); downloader.executeWithUI(); if (downloader.hasErrors()) { downloader.showErrorMessage(); } else { shared_ptr<Book> book; createBook(downloader.fileName(), book); if (!book.isNull()) { Library::Instance().addBook(book); openBook(book); refreshWindow(); } } } }
void BalloonServer::init() { try { svrSem = new ONSem(BALL_SEM); } catch(OVioException ex) { throw OPMException(SERVER_RUNNING, 0); } Buffer = &pipeMessage; if (!beginPiping(BALL_PIPE)) throw OPMException(PIPE_FAILED, 0); Pages.add(&firstPage); Pages.add(&secondPage); Pages.add(&thirdPage); try { createBook("Balloons Server", 270, 170, NB_STANDARD); } catch(OPMException err) { err.viewError(); throw err; } showFrame(); }
void FBReader::openFile(const std::string &filePath) { shared_ptr<Book> book; createBook(filePath, book); if (!book.isNull()) { openBook(book); refreshWindow(); } }
void FBReader::openFile(const ZLFile &file) { shared_ptr<Book> book; createBook(file, book); if (!book.isNull()) { openBook(book); refreshWindow(); } }
shared_ptr<Book> Book::loadFromJavaBook(JNIEnv *env, jobject javaBook) { jobject javaFile = AndroidUtil::Field_Book_File->value(javaBook); const std::string path = AndroidUtil::Method_ZLFile_getPath->callForCppString(javaFile); env->DeleteLocalRef(javaFile); const std::string title = AndroidUtil::Method_Book_getTitle->callForCppString(javaBook); const std::string language = AndroidUtil::Method_Book_getLanguage->callForCppString(javaBook); const std::string encoding = AndroidUtil::Method_Book_getEncodingNoDetection->callForCppString(javaBook); return createBook(ZLFile(path), 0, encoding, language, title); }
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; }
shared_ptr<Book> Book::loadFromBookInfo(const ZLFile &file) { BookInfo info(file.path()); shared_ptr<Book> book = createBook( file, 0, info.EncodingOption.value(), info.LanguageOption.value(), info.TitleOption.value() ); book->setSeries( info.SeriesTitleOption.value(), Number(info.IndexInSeriesOption.value()) ); if (book->language().empty()) { book->setLanguage(PluginCollection::Instance().DefaultLanguageOption.value()); } const std::string &tagList = info.TagsOption.value(); if (!tagList.empty()) { std::size_t index = 0; do { std::size_t newIndex = tagList.find(',', index); book->addTag(Tag::getTagByFullName(tagList.substr(index, newIndex - index))); index = newIndex + 1; } while (index != 0); } const std::string &authorList = info.AuthorDisplayNameOption.value(); if (!authorList.empty()) { std::size_t index = 0; do { std::size_t newIndex = authorList.find(',', index); book->addAuthor(authorList.substr(index, newIndex - index)); index = newIndex + 1; } while (index != 0); } return book; }
int main(int argc, char const *argv[]) { if (argc == 1) { printf("ERROR: the program takes one argument\n"); return 0; } argv[1]; FILE *input = fopen(argv[1], "r"); Book *book = createBook(); readBookFromFile(input, book); fclose(input); sh_fileName = argv[1]; sh_book = book; signal(SIGINT, signal_handler); char command[10]; char *name = NULL; //(char *) malloc(sizeof(char)*80); char *number = NULL; // (char *) malloc(sizeof(char)*80); char *str = NULL; //(char *) malloc(80); bool corName; bool corNumber; while (true) { corName = true; corNumber = true; scanf("%s", command); if(!strcmp(command, "debprint")) { fullPrint(book); } else if(!strcmp(command, "print")) { printBook(stdout, book); } else if(!strcmp(command, "find")) { str = read(stdin); printFound(stdout, book, str); free(str); } else if(!strcmp(command, "create")) { name = read(stdin); number = read(stdin); corName = correctName(name); corNumber = correctNumber(number); if (correctName && correctNumber) { appendBook(book, name, number); } free(name); free(number); } else if(!strcmp(command, "delete")) { int id; scanf("%d", &id); removeContact(book, id); } else if(!strcmp(command, "change")) { int id; scanf("%d%s", &id, command); str = read(stdin); if(!strcmp(command, "number")) { corName = correctName(str); if (corName) changeNumber(book, id, str); } else if (!strcmp(command, "name")) { corNumber = correctNumber(str); if (corNumber) changeName(book, id, str); } else { printf("ERROR: Expected \"name\" or \"number\" after id in the command change\n"); } free(str); } else if(!strcmp(command, "exit")) { FILE* output = fopen(argv[1], "w"); printBook(output, book); fclose(output); deleteBook(book); break; } else { printf("ERROR: Unknown command %s\n", command); } if (!corName) { printf("ERROR: Invalid name\n"); } if (!corNumber) { printf("ERROR: Invalid number\n"); } } return 0; }
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; }