#include "readerview.h" #include "sword.h" #include #include ReaderView::ReaderView() : text() { this->sword = new Sword(); this->conf = new struct config; text.set_editable(false); text.set_cursor_visible(false); text.set_wrap_mode(Gtk::WrapMode::WRAP_WORD_CHAR); //text.override_background_color(*(new Gdk::RGBA("#1d1f21"))); //text.override_color(*(new Gdk::RGBA("#c5c8c6"))); auto scroll = new Gtk::ScrolledWindow(); scroll->add(text); add(*scroll); // Open the passage we had last time string book = libbible::settingsRead("book"); int chapter = libbible::settingsReadInt("chapter"); if(book.empty() || chapter == 0) { book = "Genesis"; chapter = 1; } sword->getConfig(book, chapter, conf); refresh(); } ReaderView::~ReaderView() {} // Returns all new mods std::vector ReaderView::modsUpdated() { auto oldMods = getAllVersions(); std::sort(oldMods.begin(), oldMods.end()); sword = new Sword(); auto newMods = getAllVersions(); std::sort(newMods.begin(), newMods.end()); std::vector justNew; std::set_difference(newMods.begin(), newMods.end(), oldMods.begin(), oldMods.end(), std::back_inserter(justNew)); refresh(); return justNew; } void ReaderView::refresh() { auto textBuffer = text.get_buffer(); libbible::settingsWrite("book", conf->book); libbible::settingsWriteInt("chapter", conf->chapter); sword->getConfig(conf->book, conf->chapter, conf); // Get passage back string passage = conf->book + " " + std::to_string(conf->chapter); textBuffer->set_text(""); // Clear contents //auto iter = textBuffer->get_iter_at_offset(0); sword->fillBuffer(passage, textBuffer); } void ReaderView::setChapter(int chapter) { conf->chapter = chapter; refresh(); } int ReaderView::getChapter() { return conf->chapter; } int ReaderView::getChapterMax() { return conf->maxChapter; } void ReaderView::setBook(std::string book) { conf->book = book; refresh(); } std::string ReaderView::getBook() { return conf->book; } std::string ReaderView::getBookFull() { return conf->bookFull; } std::vector ReaderView::getAllBooks() { return sword->getBooks(); } void ReaderView::setVersion(std::string version) { sword->setModule(version); refresh(); } std::string ReaderView::getVersion() { return conf->version; } std::vector ReaderView::getAllVersions() { return sword->getModules(); }