10
#include "cswordversekey.h"
10
#include "backend/keys/cswordversekey.h"
12
#include <QStringList>
11
15
#include "backend/drivers/cswordbiblemoduleinfo.h"
12
16
#include "backend/drivers/cswordcommentarymoduleinfo.h"
15
#include <QStringList>
18
19
#include <swmodule.h>
19
20
#include <localemgr.h>
21
23
CSwordVerseKey::CSwordVerseKey( CSwordModuleInfo* const module ) :
24
if ( CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(module) ) {
25
// Copy important settings like versification system
26
copyFrom((sword::VerseKey*) bible->module()->getKey());
28
key( bible->lowerBound().key() );
32
CSwordVerseKey::CSwordVerseKey( const CSwordVerseKey& k ) : CSwordKey(k), VerseKey(k) {}
25
if ( CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(module) ) {
26
// Copy important settings like versification system
27
copyFrom((sword::VerseKey*) bible->module()->getKey());
29
key( bible->lowerBound().key() );
31
this->VerseKey::setAutoNormalize(true);
34
CSwordVerseKey::CSwordVerseKey( const CSwordVerseKey& k ) : CSwordKey(k), VerseKey(k) {
35
this->VerseKey::setAutoNormalize(true);
34
38
CSwordVerseKey::CSwordVerseKey( const VerseKey* const k, CSwordModuleInfo* const module ) : CSwordKey(module), VerseKey(*k) {}
36
40
/** Clones this object. */
37
41
CSwordKey* CSwordVerseKey::copy() const {
38
return new CSwordVerseKey(*this);
42
return new CSwordVerseKey(*this);
41
45
/** Sets the module for this key */
42
46
CSwordModuleInfo* CSwordVerseKey::module( CSwordModuleInfo* const newModule ) {
43
if (newModule && ((newModule->type() == CSwordModuleInfo::Bible) || (newModule->type() == CSwordModuleInfo::Commentary) ) ) {
46
//check if the module contains the key we present
47
CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(newModule);
49
if (_compare(bible->lowerBound()) < 0) {
50
key( bible->lowerBound() );
53
if (_compare(bible->upperBound()) > 0) {
54
key( bible->upperBound() );
58
return dynamic_cast<CSwordBibleModuleInfo*>(m_module);
47
if (newModule && ((newModule->type() == CSwordModuleInfo::Bible) || (newModule->type() == CSwordModuleInfo::Commentary) ) ) {
50
//check if the module contains the key we present
51
CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(newModule);
53
if (_compare(bible->lowerBound()) < 0) {
54
key( bible->lowerBound() );
57
if (_compare(bible->upperBound()) > 0) {
58
key( bible->upperBound() );
62
return dynamic_cast<CSwordBibleModuleInfo*>(m_module);
61
65
/** Returns the current book as Text, not as integer. */
62
66
QString CSwordVerseKey::book( const QString& newBook ) {
66
if (CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(module())) {
67
const bool hasOT = bible->hasTestament(CSwordBibleModuleInfo::OldTestament);
68
const bool hasNT = bible->hasTestament(CSwordBibleModuleInfo::NewTestament);
74
else if (hasOT && !hasNT) {
78
else if (!hasOT && hasNT) {
82
else if (!hasOT && !hasNT) {
88
if (!newBook.isEmpty()) {
89
setBookName(newBook.toUtf8().constData());
92
if ( (Testament() >= min+1) && (Testament() <= max+1) && (Book() <= BMAX[min]) ) {
93
return QString::fromUtf8( getBookName() );
96
//return QString::fromUtf8( books[min][0].name ); //return the first book, i.e. Genesis
70
if (CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(module())) {
71
const bool hasOT = bible->hasTestament(CSwordBibleModuleInfo::OldTestament);
72
const bool hasNT = bible->hasTestament(CSwordBibleModuleInfo::NewTestament);
78
else if (hasOT && !hasNT) {
82
else if (!hasOT && hasNT) {
86
else if (!hasOT && !hasNT) {
92
if (!newBook.isEmpty()) {
93
setBookName(newBook.toUtf8().constData());
96
if ( (Testament() >= min + 1) && (Testament() <= max + 1) && (Book() <= BMAX[min]) ) {
97
return QString::fromUtf8( getBookName() );
100
//return QString::fromUtf8( books[min][0].name ); //return the first book, i.e. Genesis
101
return QString::null;
100
104
/** Sets the key we use to the parameter. */
101
105
QString CSwordVerseKey::key() const {
102
return QString::fromUtf8(getText());
106
return QString::fromUtf8(getText());
105
109
const char * CSwordVerseKey::rawKey() const {
109
113
bool CSwordVerseKey::key( const QString& newKey ) {
110
return key( newKey.toUtf8().constData() );
114
return key( newKey.toUtf8().constData() );
113
117
bool CSwordVerseKey::key( const char* newKey ) {
114
if (newKey && (strlen(newKey)>0) ) {
115
VerseKey::operator = (newKey);
117
else if (newKey && !strlen(newKey)) {
118
CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(module());
121
VerseKey::operator = (bible->lowerBound().key().toUtf8().constData());
118
if (newKey && (strlen(newKey) > 0) ) {
119
VerseKey::operator = (newKey);
121
else if (newKey && !strlen(newKey)) {
122
CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(module());
125
VerseKey::operator = (bible->lowerBound().key().toUtf8().constData());
128
132
bool CSwordVerseKey::next( const JumpType type ) {
129
Error(); //clear Error status
135
const int currentTestament = Testament();
136
const int currentBook = Book();
138
if ((currentTestament == 2) && (currentBook >= BMAX[currentTestament-1])) { //Revelation, i.e. end of navigation
141
else if ((currentTestament == 1) && (currentBook >= BMAX[currentTestament-1])) { //Malachi, switch to the NT
142
Testament(currentTestament+1);
152
Chapter(Chapter()+1);
157
if (m_module && m_module->module()) {
158
const bool oldStatus = m_module->module()->getSkipConsecutiveLinks();
159
m_module->module()->setSkipConsecutiveLinks(true);
161
//disable headings for next verse
162
const bool useHeaders = (Verse() == 0);
163
const bool oldHeadingsStatus = ((VerseKey*)(m_module->module()->getKey()))->Headings( useHeaders );
164
//don't use setKey(), that would create a new key without Headings set
165
m_module->module()->getKey()->setText( key().toUtf8().constData() );
167
(*(m_module->module()) )++;
169
((VerseKey*)(m_module->module()->getKey()))->Headings(oldHeadingsStatus);
170
m_module->module()->setSkipConsecutiveLinks(oldStatus);
172
if (!m_module->module()->Error()) {
173
key( QString::fromUtf8(m_module->module()->KeyText()) );
177
//don't change the key, restore the module's position
178
m_module->module()->getKey()->setText( key().toUtf8().constData() );
195
if ( CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(module()) ) {
196
if (_compare(bible->lowerBound()) < 0 ) {
197
key( bible->lowerBound() );
201
if (_compare(bible->upperBound()) > 0 ) {
202
key( bible->upperBound() );
208
else if (Error()) { //we have no module, so take care of VerseKey::Error()
133
Error(); //clear Error status
139
const int currentTestament = Testament();
140
const int currentBook = Book();
142
if ((currentTestament == 2) && (currentBook >= BMAX[currentTestament-1])) { //Revelation, i.e. end of navigation
145
else if ((currentTestament == 1) && (currentBook >= BMAX[currentTestament-1])) { //Malachi, switch to the NT
146
Testament(currentTestament + 1);
156
Chapter(Chapter() + 1);
161
if (m_module && m_module->module()) {
162
const bool oldStatus = m_module->module()->getSkipConsecutiveLinks();
163
m_module->module()->setSkipConsecutiveLinks(true);
165
//disable headings for next verse
166
const bool useHeaders = (Verse() == 0);
167
const bool oldHeadingsStatus = ((VerseKey*)(m_module->module()->getKey()))->Headings( useHeaders );
168
//don't use setKey(), that would create a new key without Headings set
169
m_module->module()->getKey()->setText( key().toUtf8().constData() );
171
(*(m_module->module()) )++;
173
((VerseKey*)(m_module->module()->getKey()))->Headings(oldHeadingsStatus);
174
m_module->module()->setSkipConsecutiveLinks(oldStatus);
176
if (!m_module->module()->Error()) {
177
key( QString::fromUtf8(m_module->module()->KeyText()) );
181
//don't change the key, restore the module's position
182
m_module->module()->getKey()->setText( key().toUtf8().constData() );
199
if ( CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(module()) ) {
200
if (_compare(bible->lowerBound()) < 0 ) {
201
key( bible->lowerBound() );
205
if (_compare(bible->upperBound()) > 0 ) {
206
key( bible->upperBound() );
212
else if (Error()) { //we have no module, so take care of VerseKey::Error()
215
219
bool CSwordVerseKey::previous( const JumpType type ) {
221
if ( (Book() == 1) && (Testament() == 1) ) { //Genesis
224
else if ( (Book() == 1) && (Testament() == 2) ){ //Matthew
236
Chapter(Chapter()-1);
241
if (m_module && m_module->module()) {
242
const bool useHeaders = (Verse() == 0);
243
const bool oldHeadingsStatus = ((VerseKey*)(m_module->module()->getKey()))->Headings( useHeaders );
245
m_module->module()->getKey()->setText( key().toUtf8().constData() );
247
const bool oldStatus = m_module->module()->getSkipConsecutiveLinks();
248
m_module->module()->setSkipConsecutiveLinks(true);
249
( *( m_module->module() ) )--;
251
((VerseKey*)(m_module->module()->getKey()))->Headings( oldHeadingsStatus );
252
m_module->module()->setSkipConsecutiveLinks(oldStatus);
254
if (!m_module->module()->Error()) {
255
key( QString::fromUtf8(m_module->module()->KeyText()) );//don't use fromUtf8
260
m_module->module()->getKey()->setText( key().toUtf8().constData() ); //restore module's key
274
if ( CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(module()) ) {
275
if (_compare(bible->lowerBound()) < 0 ) {
276
key( bible->lowerBound() );
280
if (_compare(bible->upperBound()) > 0 ) {
281
key( bible->upperBound() );
225
if ( (Book() == 1) && (Testament() == 1) ) { //Genesis
228
else if ( (Book() == 1) && (Testament() == 2) ) { //Matthew
240
Chapter(Chapter() - 1);
245
if (m_module && m_module->module()) {
246
const bool useHeaders = (Verse() == 0);
247
const bool oldHeadingsStatus = ((VerseKey*)(m_module->module()->getKey()))->Headings( useHeaders );
249
m_module->module()->getKey()->setText( key().toUtf8().constData() );
251
const bool oldStatus = m_module->module()->getSkipConsecutiveLinks();
252
m_module->module()->setSkipConsecutiveLinks(true);
253
( *( m_module->module() ) )--;
255
((VerseKey*)(m_module->module()->getKey()))->Headings( oldHeadingsStatus );
256
m_module->module()->setSkipConsecutiveLinks(oldStatus);
258
if (!m_module->module()->Error()) {
259
key( QString::fromUtf8(m_module->module()->KeyText()) );//don't use fromUtf8
264
m_module->module()->getKey()->setText( key().toUtf8().constData() ); //restore module's key
278
if ( CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(module()) ) {
279
if (_compare(bible->lowerBound()) < 0 ) {
280
key( bible->lowerBound() );
284
if (_compare(bible->upperBound()) > 0 ) {
285
key( bible->upperBound() );