diff options
author | Your Name <you@example.com> | 2022-04-21 10:51:07 -0400 |
---|---|---|
committer | Your Name <you@example.com> | 2022-04-21 10:51:07 -0400 |
commit | b96fa27adbcdedee9e0a2c788bc5604fbaaa60d8 (patch) | |
tree | 592397f5e75b086450afbe65e5dfca63bc8f16e5 /src/readerview.cc | |
parent | 97f3b9c202ad675fbcc2af8f0719f3652557453b (diff) | |
download | biblereader-b96fa27adbcdedee9e0a2c788bc5604fbaaa60d8.tar.gz biblereader-b96fa27adbcdedee9e0a2c788bc5604fbaaa60d8.tar.bz2 biblereader-b96fa27adbcdedee9e0a2c788bc5604fbaaa60d8.zip |
Code simplifications
Diffstat (limited to 'src/readerview.cc')
-rw-r--r-- | src/readerview.cc | 73 |
1 files changed, 26 insertions, 47 deletions
diff --git a/src/readerview.cc b/src/readerview.cc index d008be6..9eace05 100644 --- a/src/readerview.cc +++ b/src/readerview.cc @@ -1,10 +1,13 @@ #include "readerview.h" -#include <libbible.h> #include <gdkmm/rgba.h> #include <algorithm> +#include <libbible.h> +#include <iostream> using namespace std; +std::vector<libbible::passage> conf; + std::string getCurrMod() { auto mods = libbible::getModuleNames(); std::string currMod = libbible::settingsRead("biblereader::currMod"); @@ -24,28 +27,9 @@ std::string getCurrMod() { return currMod; } -void updateConfig(string book, int chapter, struct config *conf) { - string currMod = getCurrMod(); - if(currMod.empty()) { - conf->chapter = 0; - conf->book = ""; - conf->bookFull = ""; - conf->maxChapter = 0; - conf->version = ""; - } else { - auto passages = libbible::getPassages(currMod, book); - conf->chapter = chapter; - conf->book = passages[0].bookShort; - conf->bookFull = passages[0].book; - conf->maxChapter = passages.back().chapterStart; - conf->version = currMod; - } -} - ReaderView::ReaderView() : text() { - this->conf = new struct config; text.set_editable(false); text.set_cursor_visible(false); text.set_wrap_mode(Gtk::WrapMode::WRAP_WORD_CHAR); @@ -55,42 +39,42 @@ ReaderView::ReaderView() scroll->add(text); add(*scroll); // Open the passage we had last time - std::string book = libbible::settingsRead("book"); - int chapter = libbible::settingsReadInt("chapter"); - if(book.empty() || chapter == 0) { - book = "Genesis"; - chapter = 1; + setBook(libbible::settingsRead("book")); + if(libbible::settingsRead("book").empty() || getChapter() == 0) { + setBook("Genesis"); } - updateConfig(book, chapter, conf); refresh(); } ReaderView::~ReaderView() {} -void ReaderView::setChapter(int chapter) { - conf->chapter = chapter; - refresh(); +void ReaderView::setChapter(unsigned int chapter) { + libbible::settingsWriteInt("chapter", chapter); } -int ReaderView::getChapter() { - return conf->chapter; +unsigned int ReaderView::getChapter() { + if(conf.empty()) return 0; + return libbible::settingsReadInt("chapter"); } -int ReaderView::getChapterMax() { - return conf->maxChapter; +unsigned int ReaderView::getChapterMax() { + if(conf.empty()) return 0; + return conf.back().chapterEnd; } void ReaderView::setBook(std::string book) { - conf->book = book; - refresh(); + libbible::settingsWrite("book", book); + conf = libbible::getPassages(getCurrMod(), book); } std::string ReaderView::getBook() { - return conf->book; + if(conf.empty()) return ""; + return conf[0].bookShort; } std::string ReaderView::getBookFull() { - return conf->bookFull; + if(conf.empty()) return ""; + return conf[0].book; } std::vector<std::string> ReaderView::getAllBooks() { @@ -101,17 +85,8 @@ std::vector<std::string> ReaderView::getAllBooks() { return libbible::getBooks(currMod); } -std::string ReaderView::getVersion() { - return conf->version; -} - void ReaderView::refresh() { auto buf = text.get_buffer(); - libbible::settingsWrite("book", conf->book); - libbible::settingsWriteInt("chapter", conf->chapter); - updateConfig(conf->book, conf->chapter, conf); - // Get passage back - string ref = conf->book + " " + std::to_string(conf->chapter); buf->set_text(""); // Clear contents string currMod = getCurrMod(); @@ -124,7 +99,11 @@ void ReaderView::refresh() { return; } - auto texts = libbible::getText(libbible::getPassage(currMod, ref)); + conf = libbible::getPassages(getCurrMod(), getBook()); + if(getChapter() > conf.size()) { + setChapter(1); + } + auto texts = libbible::getText(conf[getChapter()-1]); auto iter = buf->get_iter_at_offset(0); |