3
* This file is part of BibleTime's source code, http://www.bibletime.info/.
5
* Copyright 1999-2007 by the BibleTime developers.
6
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
12
#include "cswordtreekey.h"
13
#include "cswordbookmoduleinfo.h"
15
#include <qtextcodec.h>
17
CSwordTreeKey::CSwordTreeKey( const CSwordTreeKey& k ) : CSwordKey(k), TreeKeyIdx(k) {}
19
CSwordTreeKey::CSwordTreeKey( const TreeKeyIdx *k, CSwordModuleInfo* module ) : CSwordKey(module), TreeKeyIdx(*k) {}
21
CSwordTreeKey* CSwordTreeKey::copy() const {
22
return new CSwordTreeKey(*this);
25
const QString CSwordTreeKey::getLocalNameUnicode() const
28
CSwordTreeKey* nonconst_this = const_cast<CSwordTreeKey*>(this);
29
if (!m_module || m_module->isUnicode()) {
30
return QString::fromUtf8(nonconst_this->getLocalName());
32
QTextCodec *codec = QTextCodec::codecForName("CP1252");
33
return codec->toUnicode(nonconst_this->getLocalName());
37
/** Returns the key of this instance */
38
const QString CSwordTreeKey::key() const {
40
if (!m_module || m_module->isUnicode()) {
41
return QString::fromUtf8(getText());
43
QTextCodec *codec = QTextCodec::codecForName("CP1252");
44
return codec->toUnicode(getText());
48
/** Returns the raw key for use by Sword */
49
const char* CSwordTreeKey::rawKey() const {
53
const bool CSwordTreeKey::key( const QString& newKey ) {
55
if (!m_module || m_module->isUnicode()) {
56
return key((const char*)newKey.utf8());
58
QTextCodec *codec = QTextCodec::codecForName("CP1252");
59
return key((const char*)codec->fromUnicode(newKey));
63
const bool CSwordTreeKey::key( const char* newKey ) {
67
TreeKeyIdx::operator = (newKey);
76
CSwordModuleInfo* const CSwordTreeKey::module( CSwordModuleInfo* const newModule ) {
77
if (newModule && (newModule != m_module) && (newModule->type() == CSwordModuleInfo::GenericBook) ) {
80
const QString oldKey = key();
82
CSwordBookModuleInfo* newBook = dynamic_cast<CSwordBookModuleInfo*>(newModule);
83
copyFrom( *(newBook->tree()) );
85
key(oldKey); //try to restore our old key
87
//set the key to the root node
95
/** Assignment operator. */
96
CSwordTreeKey& CSwordTreeKey::operator = (const QString& keyname ) {