~ubuntu-branches/ubuntu/jaunty/bibletime/jaunty

« back to all changes in this revision

Viewing changes to bibletime/backend/cswordldkey.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Ralph Janke
  • Date: 2008-05-10 15:18:16 UTC
  • mfrom: (1.1.6 upstream) (3.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080510151816-bqp8y1to705zd0fm
Tags: 1.6.5.1-1
* New upstream version (Closes: #441161, #271502)
* fixes for new autotools and gcc 4.3 (Closes: #407291)
* added poxml to Build-Depends
* No DFSG necessary anymore since biblestudy howto has 
  now Commons Licence 
* Added libclucene-dev to dev-depends (Closes: #436677)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*********
 
2
*
 
3
* This file is part of BibleTime's source code, http://www.bibletime.info/.
 
4
*
 
5
* Copyright 1999-2007 by the BibleTime developers.
 
6
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
 
7
*
 
8
**********/
 
9
 
 
10
 
 
11
 
 
12
//BibleTime includes
 
13
#include "cswordldkey.h"
 
14
#include "cswordlexiconmoduleinfo.h"
 
15
 
 
16
//Qt includes
 
17
#include <qtextcodec.h>
 
18
 
 
19
//Sword includes
 
20
#include <swmodule.h>
 
21
#include <swld.h>
 
22
#include <utilstr.h>
 
23
 
 
24
 
 
25
CSwordLDKey::CSwordLDKey( CSwordModuleInfo* module ) {
 
26
        if ((m_module = dynamic_cast<CSwordLexiconModuleInfo*>(module))) {
 
27
                //    *(m_module->module()) = TOP;
 
28
        }
 
29
 
 
30
        SWKey::operator = (" ");
 
31
}
 
32
 
 
33
/** No descriptions */
 
34
CSwordLDKey::CSwordLDKey( const CSwordLDKey &k ) : CSwordKey(k), SWKey((const char*)k) {}
 
35
 
 
36
/** No descriptions */
 
37
CSwordLDKey::CSwordLDKey( const SWKey *k, CSwordModuleInfo* module) : CSwordKey(module), SWKey(*k) {}
 
38
 
 
39
/** Clones this object by copying the members. */
 
40
CSwordLDKey* CSwordLDKey::copy() const {
 
41
        return new CSwordLDKey(*this);
 
42
}
 
43
 
 
44
/** Sets the module of this key. */
 
45
CSwordModuleInfo* const CSwordLDKey::module(CSwordModuleInfo* const newModule) {
 
46
        if (newModule && newModule->type() == CSwordModuleInfo::Lexicon) {
 
47
                const QString oldKey = key();
 
48
                m_module = newModule;
 
49
                key(oldKey);
 
50
        }
 
51
 
 
52
        return m_module;
 
53
}
 
54
 
 
55
/** Sets the key of this instance */
 
56
const QString CSwordLDKey::key() const {
 
57
        
 
58
        if (!m_module || m_module->isUnicode()) {
 
59
                return QString::fromUtf8((const char*)*this);
 
60
        } else {
 
61
                QTextCodec *codec = QTextCodec::codecForName("CP1252");
 
62
                return codec->toUnicode((const char*)*this);
 
63
        }
 
64
}
 
65
 
 
66
const char * CSwordLDKey::rawKey() const {
 
67
        return (const char*)*this;
 
68
}
 
69
 
 
70
const bool CSwordLDKey::key( const QString& newKey ) {
 
71
        
 
72
        Q_ASSERT(m_module);
 
73
 
 
74
        if (!m_module || m_module->isUnicode()) {
 
75
                return key((const char*)newKey.utf8());
 
76
        } else {
 
77
                QTextCodec *codec = QTextCodec::codecForName("CP1252");
 
78
                return key((const char*)codec->fromUnicode(newKey));
 
79
        }
 
80
}
 
81
 
 
82
 
 
83
/** Sets the key of this instance */
 
84
const bool CSwordLDKey::key( const char* newKey ) {
 
85
        Q_ASSERT(newKey);
 
86
 
 
87
        if (newKey) {
 
88
                SWKey::operator = (newKey); //set the key
 
89
 
 
90
                m_module->module()->SetKey(this);
 
91
                //   m_module->module()->getKey()->setText( (const char*)key().utf8() );
 
92
                m_module->snap();
 
93
                //   SWKey::operator = (m_module->module()->KeyText());
 
94
        }
 
95
 
 
96
        return !Error();
 
97
}
 
98
 
 
99
/** Uses the parameter to returns the next entry afer this key. */
 
100
CSwordLDKey* CSwordLDKey::NextEntry() {
 
101
        m_module->module()->SetKey(this); //use this key as base for the next one!
 
102
 
 
103
        m_module->module()->setSkipConsecutiveLinks(true);
 
104
        ( *( m_module->module() ) )++;
 
105
        m_module->module()->setSkipConsecutiveLinks(false);
 
106
 
 
107
        key(m_module->module()->KeyText());
 
108
        SWKey::operator = (m_module->module()->KeyText());
 
109
 
 
110
        return this;
 
111
}
 
112
 
 
113
/** Uses the parameter to returns the next entry afer this key. */
 
114
CSwordLDKey* CSwordLDKey::PreviousEntry() {
 
115
        m_module->module()->SetKey(this); //use this key as base for the next one!
 
116
 
 
117
        m_module->module()->setSkipConsecutiveLinks(true);
 
118
        ( *( m_module->module() ) )--;
 
119
        m_module->module()->setSkipConsecutiveLinks(false);
 
120
 
 
121
        SWKey::operator = (m_module->module()->KeyText());
 
122
 
 
123
        return this;
 
124
}
 
125
 
 
126
/** Assignment operator for more ease of use of this class. */
 
127
CSwordLDKey& CSwordLDKey::operator = (const QString& keyname ) {
 
128
         key(keyname);
 
129
         return *this;
 
130
}