void ContentsView::setModel(const TextModel *model, const std::string &name) { TextView::setModel(model, name); const std::string &group = fileName(); moveStartCursor( ZLIntegerOption(ZLOption::STATE_CATEGORY, group, PARAGRAPH_OPTION_NAME, 0).value(), ZLIntegerOption(ZLOption::STATE_CATEGORY, group, WORD_OPTION_NAME, 0).value(), ZLIntegerOption(ZLOption::STATE_CATEGORY, group, CHAR_OPTION_NAME, 0).value() ); }
void ContentsView::saveState() { const WordCursor &cursor = startCursor(); if (!cursor.isNull()) { const std::string &group = fileName(); ZLIntegerOption(ZLOption::STATE_CATEGORY, group, PARAGRAPH_OPTION_NAME, 0).setValue(cursor.paragraphCursor().index()); ZLIntegerOption(ZLOption::STATE_CATEGORY, group, WORD_OPTION_NAME, 0).setValue(cursor.wordNumber()); ZLIntegerOption(ZLOption::STATE_CATEGORY, group, CHAR_OPTION_NAME, 0).setValue(cursor.charNumber()); } }
void BookTextView::readBookState(const Book &book) { ReadingState state; if (ZLBooleanOption(ZLCategoryKey::STATE, LAST_STATE_GROUP, STATE_VALID, false).value()) { state.Paragraph = ZLIntegerOption(ZLCategoryKey::STATE, LAST_STATE_GROUP, PARAGRAPH_OPTION_NAME, 0).value(); state.Word = ZLIntegerOption(ZLCategoryKey::STATE, LAST_STATE_GROUP, WORD_OPTION_NAME, 0).value(); state.Character = ZLIntegerOption(ZLCategoryKey::STATE, LAST_STATE_GROUP, CHAR_OPTION_NAME, 0).value(); } else { BooksDB::Instance().loadBookState(book, state); } gotoPosition(state.Paragraph, state.Word, state.Character); }
void BookDescriptionUtil::listZipEntries(const ZLFile &zipFile, std::vector<std::string> &entries) { int entriesNumber = ZLIntegerOption(FBCategoryKey::BOOKS, zipFile.path(), ENTRIES_NUMBER, -1).value(); if (entriesNumber == -1) { resetZipInfo(zipFile.path()); entriesNumber = ZLIntegerOption(FBCategoryKey::BOOKS, zipFile.path(), ENTRIES_NUMBER, -1).value(); } for (int i = 0; i < entriesNumber; ++i) { std::string optionName = ENTRY; ZLStringUtil::appendNumber(optionName, i); std::string entry = ZLStringOption(FBCategoryKey::BOOKS, zipFile.path(), optionName, "").value(); if (!entry.empty()) { entries.push_back(entry); } } }
int BookTextView::readStackPos(const Book &book) { if (ZLBooleanOption(ZLCategoryKey::STATE, LAST_STATE_GROUP, STATE_VALID, false).value()) { return ZLIntegerOption(ZLCategoryKey::STATE, LAST_STATE_GROUP, POSITION_IN_BUFFER, 0).value(); } else { return BooksDB::Instance().loadStackPos(book); } }
void BookTextView::saveState() { const ZLTextWordCursor &cursor = textArea().startCursor(); if (myBook.isNull()) { return; } if (!cursor.isNull()) { ZLIntegerOption(ZLCategoryKey::STATE, LAST_STATE_GROUP, PARAGRAPH_OPTION_NAME, 0).setValue(cursor.paragraphCursor().index()); ZLIntegerOption(ZLCategoryKey::STATE, LAST_STATE_GROUP, WORD_OPTION_NAME, 0).setValue(cursor.elementIndex()); ZLIntegerOption(ZLCategoryKey::STATE, LAST_STATE_GROUP, CHAR_OPTION_NAME, 0).setValue(cursor.charIndex()); ZLIntegerOption(ZLCategoryKey::STATE, LAST_STATE_GROUP, POSITION_IN_BUFFER, 0).setValue(myCurrentPointInStack); ZLBooleanOption(ZLCategoryKey::STATE, LAST_STATE_GROUP, STATE_VALID, false).setValue(true); if (myStackChanged) { BooksDB::Instance().saveBookStateStack(*myBook, myPositionStack); myStackChanged = false; } } }
static void changeActionNames(const std::map<std::string,std::string> &map, const std::string &group) { const int length = ZLIntegerOption(ZLCategoryKey::CONFIG, group, "Number", 0).value(); for (int i = 0; i < length; ++i) { std::string optionName = "Action"; ZLStringUtil::appendNumber(optionName, i); ZLStringOption option(ZLCategoryKey::CONFIG, group, optionName, ""); std::string value = option.value(); std::map<std::string,std::string>::const_iterator it = map.find(value); if (it != map.end()) { option.setValue(it->second); } } }
void BookTextView::saveBookState(const Book &book) { const ReadingState state( ZLIntegerOption(ZLCategoryKey::STATE, LAST_STATE_GROUP, PARAGRAPH_OPTION_NAME, 0).value(), ZLIntegerOption(ZLCategoryKey::STATE, LAST_STATE_GROUP, WORD_OPTION_NAME, 0).value(), ZLIntegerOption(ZLCategoryKey::STATE, LAST_STATE_GROUP, CHAR_OPTION_NAME, 0).value() ); const int stackPos = ZLIntegerOption(ZLCategoryKey::STATE, LAST_STATE_GROUP, POSITION_IN_BUFFER, 0).value(); BooksDB::Instance().setBookState(book, state); BooksDB::Instance().setStackPos(book, stackPos); ZLIntegerOption(ZLCategoryKey::STATE, LAST_STATE_GROUP, PARAGRAPH_OPTION_NAME, 0).setValue(0); ZLIntegerOption(ZLCategoryKey::STATE, LAST_STATE_GROUP, WORD_OPTION_NAME, 0).setValue(0); ZLIntegerOption(ZLCategoryKey::STATE, LAST_STATE_GROUP, CHAR_OPTION_NAME, 0).setValue(0); ZLIntegerOption(ZLCategoryKey::STATE, LAST_STATE_GROUP, POSITION_IN_BUFFER, 0).setValue(0); ZLBooleanOption(ZLCategoryKey::STATE, LAST_STATE_GROUP, STATE_VALID, false).setValue(false); }
void BookDescriptionUtil::resetZipInfo(const ZLFile &zipFile) { ZLOption::clearGroup(zipFile.path()); shared_ptr<ZLDir> zipDir = zipFile.directory(); if (!zipDir.isNull()) { std::string zipPrefix = zipFile.path() + ':'; std::vector<std::string> entries; int counter = 0; zipDir->collectFiles(entries, false); for (std::vector<std::string>::iterator zit = entries.begin(); zit != entries.end(); ++zit) { std::string optionName = ENTRY; ZLStringUtil::appendNumber(optionName, counter); std::string fullName = zipPrefix + *zit; ZLStringOption(FBCategoryKey::BOOKS, zipFile.path(), optionName, "").setValue(fullName); BookInfo(fullName).reset(); ++counter; } ZLIntegerOption(FBCategoryKey::BOOKS, zipFile.path(), ENTRIES_NUMBER, -1).setValue(counter); } }
void BookTextView::saveState() { const ZLTextWordCursor &cursor = startCursor(); if (!cursor.isNull()) { ZLIntegerOption(ZLCategoryKey::STATE, myFileName, PARAGRAPH_OPTION_NAME, 0).setValue(cursor.paragraphCursor().index()); ZLIntegerOption(ZLCategoryKey::STATE, myFileName, WORD_OPTION_NAME, 0).setValue(cursor.wordNumber()); ZLIntegerOption(ZLCategoryKey::STATE, myFileName, CHAR_OPTION_NAME, 0).setValue(cursor.charNumber()); ZLIntegerOption(ZLCategoryKey::STATE, myFileName, BUFFER_SIZE, 0).setValue(myPositionStack.size()); ZLIntegerOption(ZLCategoryKey::STATE, myFileName, POSITION_IN_BUFFER, 0).setValue(myCurrentPointInStack); for (unsigned int i = 0; i < myPositionStack.size(); ++i) { std::string bufferParagraph = BUFFER_PARAGRAPH_PREFIX; std::string bufferWord = BUFFER_WORD_PREFIX; ZLStringUtil::appendNumber(bufferParagraph, i); ZLStringUtil::appendNumber(bufferWord, i); ZLIntegerOption(ZLCategoryKey::STATE, myFileName, bufferParagraph, -1).setValue(myPositionStack[i].first); ZLIntegerOption(ZLCategoryKey::STATE, myFileName, bufferWord, -1).setValue(myPositionStack[i].second); } } }
void BookTextView::setModel(shared_ptr<ZLTextModel> model, const std::string &fileName) { FBView::setModel(model); myFileName = fileName; gotoPosition( ZLIntegerOption(ZLCategoryKey::STATE, fileName, PARAGRAPH_OPTION_NAME, 0).value(), ZLIntegerOption(ZLCategoryKey::STATE, fileName, WORD_OPTION_NAME, 0).value(), ZLIntegerOption(ZLCategoryKey::STATE, fileName, CHAR_OPTION_NAME, 0).value() ); myPositionStack.clear(); myCurrentPointInStack = 0; int stackSize = ZLIntegerOption(ZLCategoryKey::STATE, fileName, BUFFER_SIZE, 0).value(); if (stackSize > 0) { if (stackSize > (int)myMaxStackSize) { stackSize = myMaxStackSize; } int pointInStack = ZLIntegerOption(ZLCategoryKey::STATE, fileName, POSITION_IN_BUFFER, 0).value(); if ((pointInStack < 0) || (pointInStack > stackSize)) { pointInStack = stackSize; } myCurrentPointInStack = pointInStack; for (int i = 0; i < stackSize; ++i) { std::string bufferParagraph = BUFFER_PARAGRAPH_PREFIX; std::string bufferWord = BUFFER_WORD_PREFIX; ZLStringUtil::appendNumber(bufferParagraph, i); ZLStringUtil::appendNumber(bufferWord, i); Position pos; pos.first = ZLIntegerOption(ZLCategoryKey::STATE, fileName, bufferParagraph, -1).value(); pos.second = ZLIntegerOption(ZLCategoryKey::STATE, fileName, bufferWord, -1).value(); myPositionStack.push_back(pos); } } }
void BookDescriptionUtil::saveInfo(const ZLFile &file) { ZLIntegerOption(FBCategoryKey::BOOKS, file.path(), SIZE, -1).setValue(file.size()); }
bool BookDescriptionUtil::checkInfo(const ZLFile &file) { return (ZLIntegerOption(FBCategoryKey::BOOKS, file.path(), SIZE, -1).value() == (int)file.size()); }