summaryrefslogtreecommitdiff
path: root/src/backend/keys/cswordldkey.cpp
blob: bc1e2c15bb62e21e16a0466a3050edbca6f8f6e1 (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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*********
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
* Copyright 1999-2008 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/

#include "backend/keys/cswordldkey.h"

#include <QTextCodec>
#include "backend/drivers/cswordlexiconmoduleinfo.h"

// Sword includes:
#include <swmodule.h>
#include <swld.h>
#include <utilstr.h>


CSwordLDKey::CSwordLDKey( CSwordModuleInfo* module ) {
    if ((m_module = dynamic_cast<CSwordLexiconModuleInfo*>(module))) {
        //    *(m_module->module()) = TOP;
    }

    SWKey::operator= (" ");
}

/** No descriptions */
CSwordLDKey::CSwordLDKey( const CSwordLDKey &k ) : CSwordKey(k), SWKey((const char*)k) {}

/** No descriptions */
CSwordLDKey::CSwordLDKey( const SWKey *k, CSwordModuleInfo* module) : CSwordKey(module), SWKey(*k) {}

/** Clones this object by copying the members. */
CSwordLDKey* CSwordLDKey::copy() const {
    return new CSwordLDKey(*this);
}

/** Sets the module of this key. */
CSwordModuleInfo* CSwordLDKey::module(CSwordModuleInfo* const newModule) {
    if (newModule && newModule->type() == CSwordModuleInfo::Lexicon) {
        const QString oldKey = key();
        m_module = newModule;
        key(oldKey);
    }

    return m_module;
}

QString CSwordLDKey::key() const {
    //return QString::fromUtf8((const char*)*this);
    Q_ASSERT(m_module);

    if (m_module->isUnicode()) {
        return QString::fromUtf8((const char*)*this);
    }
    else {
        return cp1252Codec()->toUnicode((const char*)*this);
    }
}

const char * CSwordLDKey::rawKey() const {
    return (const char*)*this;
}

bool CSwordLDKey::key( const QString& newKey ) {
    Q_ASSERT(m_module);

    if (m_module->isUnicode()) {
        return key(newKey.toUtf8().constData());
    }
    else {
        return key((const char*)cp1252Codec()->fromUnicode(newKey));
    }
}


/** Sets the key of this instance */
bool CSwordLDKey::key( const char* newKey ) {
    Q_ASSERT(newKey);

    if (newKey) {
        SWKey::operator = (newKey); //set the key
        m_module->module()->SetKey(this);
        m_module->snap();
    }

    return !Error();
}

/** Uses the parameter to returns the next entry afer this key. */
CSwordLDKey* CSwordLDKey::NextEntry() {
    m_module->module()->SetKey(this); //use this key as base for the next one!
    //   m_module->module()->getKey()->setText( (const char*)key().utf8() );

    m_module->module()->setSkipConsecutiveLinks(true);
    ( *( m_module->module() ) )++;
    m_module->module()->setSkipConsecutiveLinks(false);

    key(m_module->module()->KeyText());
    SWKey::operator = (m_module->module()->KeyText());

    return this;
}

/** Uses the parameter to returns the next entry afer this key. */
CSwordLDKey* CSwordLDKey::PreviousEntry() {
    m_module->module()->SetKey(this); //use this key as base for the next one!
    //   m_module->module()->getKey()->setText( (const char*)key().utf8() );

    m_module->module()->setSkipConsecutiveLinks(true);
    ( *( m_module->module() ) )--;
    m_module->module()->setSkipConsecutiveLinks(false);

    SWKey::operator = (m_module->module()->KeyText());

    return this;
}