/** * @brief Sets specified value. * * Method sets the value for the provided chapter and its key. * * @param chapter The chapter name of the value. * @param key The key name. * @param value The value to set. */ void condor2nav::CFileParserINI::Value(const std::string &chapter, const std::string &key, std::string value) { if(key == "") throw EOperationFailed{"ERROR: Cannot set value for empty key in INI file!!!"}; CValuesMap &map = (chapter != "") ? Chapter(chapter).valuesMap : _valuesMap; map[key] = std::move(value); }
/** * @brief Returns requested value. * * Method returns the value specified by the chapter and key name. To search in * global scope (no chapters) "" should be provided for @p chapter. * * @param chapter The chapter name to find ("" means to look in global scope). * @param key The key name o find. * * @exception std Thrown when value not found. * * @return Requested value. */ const std::string &condor2nav::CFileParserINI::Value(const std::string &chapter, const std::string &key) const { const CValuesMap &map = (chapter != "") ? Chapter(chapter).valuesMap : _valuesMap; auto it = map.find(key); if(it == map.end()) throw EOperationFailed{"ERROR: Entry '" + key + "' not found in '" + Path().string() + "' INI file!!!"}; return it->second; }
bool CSwordVerseKey::previous( const JumpType type ) { bool ret = true; switch (type) { case UseBook: { if ( (Book() == 1) && (Testament() == 1) ) { //Genesis return false; } else if ( (Book() == 1) && (Testament() == 2) ) { //Matthew Testament(1); Book(BMAX[0]); } else { Book( Book() - 1 ); } break; } case UseChapter: { Chapter(Chapter() - 1); break; } case UseVerse: { if (m_module && m_module->module()) { const bool useHeaders = 1; //(Verse() == 0); const bool oldHeadingsStatus = ((VerseKey*)(m_module->module()->getKey()))->Headings( useHeaders ); m_module->module()->getKey()->setText( key().toUtf8().constData() ); const bool oldStatus = m_module->module()->getSkipConsecutiveLinks(); m_module->module()->setSkipConsecutiveLinks(true); ( *( m_module->module() ) )--; ((VerseKey*)(m_module->module()->getKey()))->Headings( oldHeadingsStatus ); m_module->module()->setSkipConsecutiveLinks(oldStatus); if (!m_module->module()->Error()) { key( QString::fromUtf8(m_module->module()->KeyText()) );//don't use fromUtf8 } else { ret = false; // Verse(Verse()-1); m_module->module()->getKey()->setText( key().toUtf8().constData() ); //restore module's key } } else { Verse(Verse() - 1); } break; } default: return false; } if ( CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(module()) ) { if (_compare(bible->lowerBound()) < 0 ) { key( bible->lowerBound() ); ret = false; } if (_compare(bible->upperBound()) > 0 ) { key( bible->upperBound() ); ret = false; } return ret; } else if (Error()) { return false; } return ret; }
bool CSwordVerseKey::next( const JumpType type ) { Error(); //clear Error status bool ret = true; switch (type) { case UseBook: { const int currentTestament = Testament(); const int currentBook = Book(); if ((currentTestament == 2) && (currentBook >= BMAX[currentTestament-1])) { //Revelation, i.e. end of navigation return false; } else if ((currentTestament == 1) && (currentBook >= BMAX[currentTestament-1])) { //Malachi, switch to the NT Testament(currentTestament + 1); Book(1); } else { Book(Book() + 1); } break; } case UseChapter: { Chapter(Chapter() + 1); break; } case UseVerse: { if (m_module && m_module->module()) { const bool oldStatus = m_module->module()->getSkipConsecutiveLinks(); m_module->module()->setSkipConsecutiveLinks(true); //disable headings for next verse const bool useHeaders = 1; //(Verse() == 0); const bool oldHeadingsStatus = ((VerseKey*)(m_module->module()->getKey()))->Headings( useHeaders ); //don't use setKey(), that would create a new key without Headings set m_module->module()->getKey()->setText( key().toUtf8().constData() ); (*(m_module->module()) )++; ((VerseKey*)(m_module->module()->getKey()))->Headings(oldHeadingsStatus); m_module->module()->setSkipConsecutiveLinks(oldStatus); if (!m_module->module()->Error()) { key( QString::fromUtf8(m_module->module()->KeyText()) ); } else { // Verse(Verse()+1); //don't change the key, restore the module's position m_module->module()->getKey()->setText( key().toUtf8().constData() ); ret = false; break; } } else { Verse(Verse() + 1); } break; } default: return false; } if ( CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(module()) ) { if (_compare(bible->lowerBound()) < 0 ) { key( bible->lowerBound() ); ret = false; } if (_compare(bible->upperBound()) > 0 ) { key( bible->upperBound() ); ret = false; } return ret; } else if (Error()) { //we have no module, so take care of VerseKey::Error() return false; } return ret; }
void Manga::downloadInformation() { sf::Http web(MangaHost); sf::Http::Request request(m_uri); sf::Http::Response response = web.sendRequest(request); sf::Http::Response::Status status = response.getStatus(); if (status == sf::Http::Response::Ok) { //std::cout<<"Link is valid\n"; std::string body(response.getBody()); //Erase all of the \n eraseN(body); if (testing) { if (!directoryExists("test")) createDirectory("test"); FILE* f = fopen("test/body.html", "w"); fwrite(body.c_str(), sizeof(char), body.size(), f); fclose(f); std::cout<<"Html page output to file: test/body.html\n"; } //Start parsing m_name = getParse(body, parseMangaName); //Supress all white spaces at the end of the name!! for (int i(m_name.size()-1); i>=0; --i) { if (m_name[i] == ' ') m_name.resize(i); else break; } std::string last_chapter(getParse(body, parseChapters)); sscanf(last_chapter.c_str(), "%u", &m_num_chapters); if (testing) std::cout<<"Name parsed: "<<m_name<<".\nChapter count parsed: "<<last_chapter<<"\n"; if (!testing) { if (!directoryExists("mangas")) createDirectory("mangas"); if (!directoryExists("mangas/" + m_name)) createDirectory("mangas/" + m_name); } if (m_cover != NULL) delete m_cover; m_cover = new Image(getParse(body, parseCover), "mangas/" + m_name + "/"); if (!testing) m_cover->thDownload(); else std::cout<<"Cover parsed: "<<m_cover->getUrl()<<"\n"; m_loaded = true; //Fill list of chapters sf::Clock clock; size_t first(0); std::string chapter_web_list(getParse(body, parseChapterList)); //erase all the \n!! eraseN(chapter_web_list); if (testing) { FILE* f = fopen("test/chapter_list.html", "w"); fwrite(chapter_web_list.c_str(), sizeof(char), chapter_web_list.size(), f); fclose(f); std::cout<<"Html page output to file: test/chapter_list.html\n"; } unsigned int chapter_i(1); while(true) { first = chapter_web_list.find(parseChapterListElement.begin[0], first); if (first == chapter_web_list.npos) break; else first += parseChapterListElement.begin[0].size(); std::string chapter_url, chapter_name(getParse(chapter_web_list.substr(first), Manga::parseChapterListName)); switch (Manga::chapterPath) { case URL_uri: chapter_url = getParse(chapter_web_list.substr(first), parseChapterListUri); break; case URL_absolute: //std::cout<<getParse(chapter_web_list.substr(first), parseChapterListUri)<<" tachan!\n"; chapter_url = getUri(getParse(chapter_web_list.substr(first), parseChapterListUri)); break; case URL_relative: chapter_url = getWorkingDirectory(m_uri) + getParse(chapter_web_list.substr(first), parseChapterListUri); break; default: break; } m_chapters.push_back(Chapter(chapter_url, this, chapter_i, chapter_name)); //std::cout<<"Added chapter: "<<m_chapters.back()<<"\n"; ++chapter_i; } if (Manga::chapterListReversed) // reverse the chapter list { m_chapters.reverse(); chapter_i = 1; for (std::list<Chapter>::iterator it(m_chapters.begin()); it != m_chapters.end(); ++it) { it->setChapter(chapter_i); ++chapter_i; } } if (testing) { std::cout<<m_chapters.size()<<" chapters were parsed\n"; for (std::list<Chapter>::iterator it(m_chapters.begin()); it != m_chapters.end(); ++it) std::cout<<"Chapter "<<it->m_num_chapter<<" parsed: "<<it->m_name<<" at "<<it->m_uri<<"\n"; } //std::cout<<"Chapter list created in: "<<clock.getElapsedTime().asSeconds()<<" sec\n"; } else std::cout<<"Error downloading manga info: "<<status<<"\n"; }