aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/header.cc7
-rw-r--r--src/readerview.cc73
-rw-r--r--src/readerview.h17
3 files changed, 32 insertions, 65 deletions
diff --git a/src/header.cc b/src/header.cc
index d018ad5..b05e0dd 100644
--- a/src/header.cc
+++ b/src/header.cc
@@ -44,6 +44,7 @@ Header::Header(ReaderView *reader, Gtk::Window *window)
Header::~Header() {}
void Header::updateButtons() {
+ reader->refresh();
back.set_sensitive(reader->getChapter() > 1);
forward.set_sensitive(reader->getChapter() < reader->getChapterMax());
if(reader->getBook() == "") {
@@ -96,7 +97,7 @@ void Header::updateMenus() {
swr->add(*boxr);
swr->set_propagate_natural_width(true);
swr->set_min_content_height(300);
- for(int chapter = 1; chapter <= reader->getChapterMax(); chapter++) {
+ for(unsigned int chapter = 1; chapter <= reader->getChapterMax(); chapter++) {
Gtk::Button *item = Gtk::manage(new Gtk::Button(std::to_string(chapter)));
item->set_relief(Gtk::ReliefStyle::RELIEF_NONE);
item->signal_clicked().connect([chapter, this]() {
@@ -159,7 +160,6 @@ void Header::updateMenus() {
item->signal_clicked().connect([version, this]() {
menuMenu.popdown();
libbible::settingsWrite("biblereader::currMod", version);
- this->reader->refresh();
updateButtons();
updateMenus();
showText();
@@ -170,7 +170,6 @@ void Header::updateMenus() {
delVersion->signal_clicked().connect([version, this]() {
menuMenu.popdown();
libbible::uninstallMod(version);
- reader->refresh();
updateButtons();
updateMenus();
});
@@ -180,7 +179,7 @@ void Header::updateMenus() {
hbox->add(*item);
hbox->add(*delVersion);
versionBox->add(*hbox);
- item->set_sensitive(version != reader->getVersion());
+ item->set_sensitive(version != libbible::settingsRead("biblereader::currMod"));
}
Gtk::Button *add = Gtk::manage(new Gtk::Button);
add->set_image_from_icon_name("list-add-symbolic");
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);
diff --git a/src/readerview.h b/src/readerview.h
index 7c0436b..51fc48d 100644
--- a/src/readerview.h
+++ b/src/readerview.h
@@ -7,27 +7,16 @@ class ReaderView : public Gtk::Frame
ReaderView();
virtual ~ReaderView();
- void setChapter(int chapter);
- int getChapter(void);
- int getChapterMax(void);
+ void setChapter(unsigned int chapter);
+ unsigned int getChapter(void);
+ unsigned int getChapterMax(void);
void setBook(std::string book);
std::string getBook(void);
std::string getBookFull(void);
std::vector<std::string> getAllBooks(void);
-
- std::string getVersion(void);
void refresh(void);
protected:
Gtk::TextView text;
- struct config *conf;
-};
-
-struct config {
- int chapter;
- std::string book;
- std::string bookFull;
- int maxChapter;
- std::string version;
};