aboutsummaryrefslogtreecommitdiff
path: root/src/readerview.cc
diff options
context:
space:
mode:
authorYour Name <you@example.com>2022-02-19 10:54:35 -0500
committerYour Name <you@example.com>2022-02-19 10:54:35 -0500
commit4f26d55e01f9424ba5660cb27076eafba4c88b21 (patch)
tree41131c34e6610cd1b3c52b2b771ef550134a725d /src/readerview.cc
parenta5cdc506789ac6aeb6f4256b892fedf046fff06c (diff)
downloadbiblereader-4f26d55e01f9424ba5660cb27076eafba4c88b21.tar.gz
biblereader-4f26d55e01f9424ba5660cb27076eafba4c88b21.tar.bz2
biblereader-4f26d55e01f9424ba5660cb27076eafba4c88b21.zip
Reorganized sources
Diffstat (limited to 'src/readerview.cc')
-rw-r--r--src/readerview.cc98
1 files changed, 98 insertions, 0 deletions
diff --git a/src/readerview.cc b/src/readerview.cc
new file mode 100644
index 0000000..aef003d
--- /dev/null
+++ b/src/readerview.cc
@@ -0,0 +1,98 @@
+#include "readerview.h"
+#include "sword.h"
+#include <libbible.h>
+#include <gdkmm/rgba.h>
+
+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<std::string> 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<std::string> 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<std::string> ReaderView::getAllBooks() {
+ return sword->getBooks();
+}
+
+void ReaderView::setVersion(std::string version) {
+ sword->setModule(version);
+ refresh();
+}
+
+std::string ReaderView::getVersion() {
+ return conf->version;
+}
+
+std::vector<std::string> ReaderView::getAllVersions() {
+ return sword->getModules();
+}