aboutsummaryrefslogtreecommitdiff
path: root/readerview.cc
blob: aef003daf574d11dba47aaf409df0b96a3b20ba6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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();
}