summaryrefslogtreecommitdiff
path: root/src/backend/drivers/cswordbiblemoduleinfo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/drivers/cswordbiblemoduleinfo.cpp')
-rw-r--r--src/backend/drivers/cswordbiblemoduleinfo.cpp110
1 files changed, 47 insertions, 63 deletions
diff --git a/src/backend/drivers/cswordbiblemoduleinfo.cpp b/src/backend/drivers/cswordbiblemoduleinfo.cpp
index a81430f..e87fea2 100644
--- a/src/backend/drivers/cswordbiblemoduleinfo.cpp
+++ b/src/backend/drivers/cswordbiblemoduleinfo.cpp
@@ -12,7 +12,6 @@
#include <QSharedPointer>
#include <QFile>
#include "backend/managers/cswordbackend.h"
-#include "backend/keys/cswordversekey.h"
// Sword includes:
#include <versekey.h>
@@ -21,53 +20,46 @@
CSwordBibleModuleInfo::CSwordBibleModuleInfo(sword::SWModule *module,
CSwordBackend * const usedBackend,
ModuleType type)
- : CSwordModuleInfo(module, usedBackend, type),
- m_lowerBound(0),
- m_upperBound(0),
- m_bookList(0),
- m_cachedLocale("unknown")
+ : CSwordModuleInfo(module, usedBackend, type)
+ , m_boundsInitialized(false)
+ , m_lowerBound(0)
+ , m_upperBound(0)
+ , m_bookList(0)
{
- initBounds();
+ // Intentionally empty
}
-CSwordBibleModuleInfo::CSwordBibleModuleInfo(const CSwordBibleModuleInfo &copy) :
- CSwordModuleInfo(copy),
- m_lowerBound(0),
- m_upperBound(0),
- m_bookList(0),
- m_cachedLocale(copy.m_cachedLocale),
- m_hasOT(copy.m_hasOT),
- m_hasNT(copy.m_hasNT)
-{
- if (copy.m_bookList) {
- m_bookList = new QStringList();
- *m_bookList = *copy.m_bookList;
- }
- initBounds();
-}
+void CSwordBibleModuleInfo::initBounds() const {
+ /// \todo The fields calculated by this method could be cached to disk.
-void CSwordBibleModuleInfo::initBounds() {
- const bool oldStatus = module()->getSkipConsecutiveLinks();
- module()->setSkipConsecutiveLinks(true);
+ Q_ASSERT(!m_boundsInitialized);
- module()->setPosition(sword::TOP); // position to first entry
- sword::VerseKey key(module()->KeyText());
- m_hasOT = (key.Testament() == 1);
+ sword::SWModule *m = module();
+ const bool oldStatus = m->getSkipConsecutiveLinks();
+ m->setSkipConsecutiveLinks(true);
- module()->setPosition(sword::BOTTOM);
- key = module()->KeyText();
- m_hasNT = (key.Testament() == 2);
+ m->setPosition(sword::TOP); // position to first entry
+ sword::VerseKey key(module()->getKeyText());
+ m_hasOT = (key.getTestament() == 1);
- module()->setSkipConsecutiveLinks(oldStatus);
+ m->setPosition(sword::BOTTOM);
+ key = module()->getKeyText();
+ m_hasNT = (key.getTestament() == 2);
+
+ m->setSkipConsecutiveLinks(oldStatus);
m_lowerBound.setKey(m_hasOT ? "Genesis 1:1" : "Matthew 1:1");
m_upperBound.setKey(!m_hasNT ? "Malachi 4:6" : "Revelation of John 22:21");
+
+ m_boundsInitialized = true;
}
/** Returns the books available in this module */
QStringList *CSwordBibleModuleInfo::books() const {
- if (m_cachedLocale != backend()->booknameLanguage()) { //if the locale has changed
+ if (m_cachedLocale != backend()->booknameLanguage()) {
+ // Reset the booklist because the locale has changed
+ m_cachedLocale = backend()->booknameLanguage();
delete m_bookList;
m_bookList = 0;
}
@@ -75,37 +67,29 @@ QStringList *CSwordBibleModuleInfo::books() const {
if (!m_bookList) {
m_bookList = new QStringList();
+ // Initialize m_hasOT and m_hasNT
+ if (!m_boundsInitialized)
+ initBounds();
+
int min = 1; // 1 = OT
int max = 2; // 2 = NT
- //find out if we have ot and nt, only ot or only nt
+ if (!m_hasOT)
+ min++; // min == 2
- if (m_hasOT && m_hasNT) { //both
- min = 1;
- max = 2;
- }
- else if (m_hasOT && !m_hasNT) { //only OT
- min = 1;
- max = 1;
- }
- else if (!m_hasOT && m_hasNT) { //only NT
- min = 2;
- max = 2;
- }
- else if (!m_hasOT && !m_hasNT) { //somethings wrong here! - no OT and no NT
- qWarning("CSwordBibleModuleInfo (%s) no OT and not NT! Check your config!", module()->Name());
- min = 1;
- max = 0;
- }
+ if (!m_hasNT)
+ max--; // max == 1
- QSharedPointer<sword::VerseKey> key((sword::VerseKey *)module()->CreateKey());
- key->setPosition(sword::TOP);
+ if (min > max) {
+ qWarning("CSwordBibleModuleInfo (%s) no OT and not NT! Check your config!", module()->Name());
+ } else {
+ QSharedPointer<sword::VerseKey> key((sword::VerseKey *)module()->CreateKey());
+ key->setPosition(sword::TOP);
- for (key->setTestament(min); !key->Error() && key->getTestament() <= max; key->Book(key->Book() + 1)) {
- m_bookList->append( QString::fromUtf8(key->getBookName()) );
+ for (key->setTestament(min); !key->Error() && key->getTestament() <= max; key->setBook(key->getBook() + 1)) {
+ m_bookList->append( QString::fromUtf8(key->getBookName()) );
+ }
}
-
- m_cachedLocale = backend()->booknameLanguage();
}
return m_bookList;
@@ -118,9 +102,9 @@ unsigned int CSwordBibleModuleInfo::chapterCount(const unsigned int book) const
key->setPosition(sword::TOP);
// works for old and new versions
- key->Book(book);
+ key->setBook(book);
key->setPosition(sword::MAXCHAPTER);
- result = key->Chapter();
+ result = key->getChapter();
return result;
}
@@ -140,10 +124,10 @@ unsigned int CSwordBibleModuleInfo::verseCount(const unsigned int book,
key->setPosition(sword::TOP);
// works for old and new versions
- key->Book(book);
- key->Chapter(chapter);
+ key->setBook(book);
+ key->setChapter(chapter);
key->setPosition(sword::MAXVERSE);
- result = key->Verse();
+ result = key->getVerse();
return result;
}
@@ -162,7 +146,7 @@ unsigned int CSwordBibleModuleInfo::bookNumber(const QString &book) const {
key->setBookName(book.toUtf8().constData());
- bookNumber = ((key->getTestament() > 1) ? key->BMAX[0] : 0) + key->Book();
+ bookNumber = ((key->getTestament() > 1) ? key->BMAX[0] : 0) + key->getBook();
return bookNumber;
}