diff options
Diffstat (limited to 'src/backend/drivers')
-rw-r--r-- | src/backend/drivers/cswordbiblemoduleinfo.cpp | 190 | ||||
-rw-r--r-- | src/backend/drivers/cswordbiblemoduleinfo.h | 140 | ||||
-rw-r--r-- | src/backend/drivers/cswordbookmoduleinfo.cpp | 37 | ||||
-rw-r--r-- | src/backend/drivers/cswordbookmoduleinfo.h | 64 | ||||
-rw-r--r-- | src/backend/drivers/cswordcommentarymoduleinfo.cpp | 27 | ||||
-rw-r--r-- | src/backend/drivers/cswordcommentarymoduleinfo.h | 46 | ||||
-rw-r--r-- | src/backend/drivers/cswordlexiconmoduleinfo.cpp | 92 | ||||
-rw-r--r-- | src/backend/drivers/cswordlexiconmoduleinfo.h | 73 | ||||
-rw-r--r-- | src/backend/drivers/cswordmoduleinfo.cpp | 422 | ||||
-rw-r--r-- | src/backend/drivers/cswordmoduleinfo.h | 275 |
10 files changed, 676 insertions, 690 deletions
diff --git a/src/backend/drivers/cswordbiblemoduleinfo.cpp b/src/backend/drivers/cswordbiblemoduleinfo.cpp index 4a65c4d..a81430f 100644 --- a/src/backend/drivers/cswordbiblemoduleinfo.cpp +++ b/src/backend/drivers/cswordbiblemoduleinfo.cpp @@ -2,14 +2,14 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2008 by the BibleTime developers. +* Copyright 1999-2011 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ #include "backend/drivers/cswordbiblemoduleinfo.h" -#include <boost/scoped_ptr.hpp> +#include <QSharedPointer> #include <QFile> #include "backend/managers/cswordbackend.h" #include "backend/keys/cswordversekey.h" @@ -18,65 +18,55 @@ #include <versekey.h> -CSwordBibleModuleInfo::CSwordBibleModuleInfo( sword::SWModule* module, CSwordBackend* const usedBackend ) - : CSwordModuleInfo(module, usedBackend), +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"), - m_hasOT(-1), - m_hasNT(-1) {} + m_cachedLocale("unknown") +{ + initBounds(); +} -CSwordBibleModuleInfo::CSwordBibleModuleInfo( const CSwordBibleModuleInfo& m ) : - CSwordModuleInfo(m), +CSwordBibleModuleInfo::CSwordBibleModuleInfo(const CSwordBibleModuleInfo ©) : + CSwordModuleInfo(copy), m_lowerBound(0), m_upperBound(0), - m_bookList(0) { - if (m.m_bookList) { + 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 = *m.m_bookList; + *m_bookList = *copy.m_bookList; } - - m_hasOT = m.m_hasOT; - m_hasNT = m.m_hasNT; - m_cachedLocale = m.m_cachedLocale; -} - -CSwordModuleInfo* CSwordBibleModuleInfo::clone() { - return new CSwordBibleModuleInfo(*this); -} - -CSwordBibleModuleInfo::~CSwordBibleModuleInfo() { - delete m_bookList; + initBounds(); } void CSwordBibleModuleInfo::initBounds() { - if (m_hasOT == -1) { - m_hasOT = hasTestament(OldTestament); - } + const bool oldStatus = module()->getSkipConsecutiveLinks(); + module()->setSkipConsecutiveLinks(true); - if (m_hasNT == -1) { - m_hasNT = hasTestament(NewTestament); - } + module()->setPosition(sword::TOP); // position to first entry + sword::VerseKey key(module()->KeyText()); + m_hasOT = (key.Testament() == 1); - if (m_hasOT) { - m_lowerBound.key("Genesis 1:1"); - } - else { - m_lowerBound.key("Matthew 1:1"); - } + module()->setPosition(sword::BOTTOM); + key = module()->KeyText(); + m_hasNT = (key.Testament() == 2); - if (!m_hasNT) { - m_upperBound.key("Malachi 4:6"); - } - else { - m_upperBound.key("Revelation of John 22:21"); - } + module()->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"); } /** Returns the books available in this module */ -QStringList* CSwordBibleModuleInfo::books() { +QStringList *CSwordBibleModuleInfo::books() const { if (m_cachedLocale != backend()->booknameLanguage()) { //if the locale has changed delete m_bookList; m_bookList = 0; @@ -85,34 +75,33 @@ QStringList* CSwordBibleModuleInfo::books() { if (!m_bookList) { m_bookList = new QStringList(); - initBounds(); - int min = 0; - int max = 1; + 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 > 0 && m_hasNT > 0) { //both - min = 0; - max = 1; - } - else if (m_hasOT > 0 && !m_hasNT) { //only OT - min = 0; - max = 0; + if (m_hasOT && m_hasNT) { //both + min = 1; + max = 2; } - else if (!m_hasOT && m_hasNT > 0) { //only NT + 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 = 0; - max = -1; + min = 1; + max = 0; } - boost::scoped_ptr<sword::VerseKey> key((sword::VerseKey *)module()->CreateKey()); - (*key) = sword::TOP; + QSharedPointer<sword::VerseKey> key((sword::VerseKey *)module()->CreateKey()); + key->setPosition(sword::TOP); - for (key->Testament(min + 1); !key->Error() && (key->Testament() - 1) <= max; key->Book(key->Book() + 1)) { + for (key->setTestament(min); !key->Error() && key->getTestament() <= max; key->Book(key->Book() + 1)) { m_bookList->append( QString::fromUtf8(key->getBookName()) ); } @@ -122,101 +111,58 @@ QStringList* CSwordBibleModuleInfo::books() { return m_bookList; } -/** Returns the number of chapters for the given book. */ -unsigned int CSwordBibleModuleInfo::chapterCount(const unsigned int book) { +unsigned int CSwordBibleModuleInfo::chapterCount(const unsigned int book) const { int result = 0; - boost::scoped_ptr<sword::VerseKey> key((sword::VerseKey *)module()->CreateKey()); - (*key) = sword::TOP; + QSharedPointer<sword::VerseKey> key((sword::VerseKey *)module()->CreateKey()); + key->setPosition(sword::TOP); // works for old and new versions key->Book(book); - (*key) = sword::MAXCHAPTER; + key->setPosition(sword::MAXCHAPTER); result = key->Chapter(); return result; } -unsigned int CSwordBibleModuleInfo::chapterCount(const QString& book) { - return chapterCount( bookNumber(book) ); +unsigned int CSwordBibleModuleInfo::chapterCount(const QString &book) const { + return chapterCount(bookNumber(book)); } /** Returns the number of verses for the given chapter. */ -unsigned int CSwordBibleModuleInfo::verseCount( const unsigned int book, const unsigned int chapter ) { +unsigned int CSwordBibleModuleInfo::verseCount(const unsigned int book, + const unsigned int chapter) const +{ unsigned int result = 0; - boost::scoped_ptr<sword::VerseKey> key((sword::VerseKey *)module()->CreateKey()); - (*key) = sword::TOP; + QSharedPointer<sword::VerseKey> key((sword::VerseKey *)module()->CreateKey()); + key->setPosition(sword::TOP); // works for old and new versions key->Book(book); key->Chapter(chapter); - (*key) = sword::MAXVERSE; + key->setPosition(sword::MAXVERSE); result = key->Verse(); return result; } -unsigned int CSwordBibleModuleInfo::verseCount( const QString& book, const unsigned int chapter ) { - return verseCount( bookNumber(book), chapter ); +unsigned int CSwordBibleModuleInfo::verseCount(const QString &book, + const unsigned int chapter) const +{ + return verseCount(bookNumber(book), chapter); } -unsigned int CSwordBibleModuleInfo::bookNumber(const QString &book) { +unsigned int CSwordBibleModuleInfo::bookNumber(const QString &book) const { unsigned int bookNumber = 0; - //find out if we have ot and nt, only ot or only nt - initBounds(); - - boost::scoped_ptr<sword::VerseKey> key((sword::VerseKey *)module()->CreateKey()); - (*key) = sword::TOP; + QSharedPointer<sword::VerseKey> key((sword::VerseKey *)module()->CreateKey()); + key->setPosition(sword::TOP); key->setBookName(book.toUtf8().constData()); - bookNumber = ((key->Testament() > 1) ? key->BMAX[0] : 0) + key->Book(); + bookNumber = ((key->getTestament() > 1) ? key->BMAX[0] : 0) + key->Book(); return bookNumber; } - -/** Returns true if his module has the text of desired type of testament */ -bool CSwordBibleModuleInfo::hasTestament( CSwordBibleModuleInfo::Testament type ) { - if (m_hasOT == -1 || m_hasNT == -1) { - const bool oldStatus = module()->getSkipConsecutiveLinks(); - module()->setSkipConsecutiveLinks(true); - - *module() = sword::TOP; //position to first entry - sword::VerseKey key( module()->KeyText() ); - - if (key.Testament() == 1) { // OT && NT - m_hasOT = 1; - } - else if (key.Testament() == 2) { //no OT - m_hasOT = 0; - } - - *module() = sword::BOTTOM; - key = module()->KeyText(); - - if (key.Testament() == 1) { // only OT, no NT - m_hasNT = 0; - } - else if (key.Testament() == 2) { //has NT - m_hasNT = 1; - } - - module()->setSkipConsecutiveLinks(oldStatus); - } - - switch (type) { - - case OldTestament: - return m_hasOT > 0; - - case NewTestament: - return m_hasNT > 0; - - default: - return false; - } -} - diff --git a/src/backend/drivers/cswordbiblemoduleinfo.h b/src/backend/drivers/cswordbiblemoduleinfo.h index 2780558..40ec8cb 100644 --- a/src/backend/drivers/cswordbiblemoduleinfo.h +++ b/src/backend/drivers/cswordbiblemoduleinfo.h @@ -2,7 +2,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2008 by the BibleTime developers. +* Copyright 1999-2011 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ @@ -17,110 +17,102 @@ /** - * This is the CModuleInfo imlementation for Bible modules managed by Sword. - * - * @short Implementation for Sword Bibles - * @author The BibleTime team - * @version $Id: cswordbiblemoduleinfo.h,v 1.18 2006/02/25 11:38:15 joachim Exp $ - */ + \brief Implementation for Sword Bibles. -class CSwordBibleModuleInfo : public CSwordModuleInfo { + This is the CModuleInfo imlementation for Bible modules managed by Sword. +*/ +class CSwordBibleModuleInfo: public CSwordModuleInfo { + Q_OBJECT - public: + public: /* Types: */ enum Testament { OldTestament = 1, NewTestament = 2 }; + public: /* Methods: */ + CSwordBibleModuleInfo(sword::SWModule *module, CSwordBackend * const, + ModuleType type = Bible); + CSwordBibleModuleInfo(const CSwordBibleModuleInfo ©); + + /* Reimplementation of CSwordModuleInfo::clone(). */ + virtual inline CSwordModuleInfo *clone() const { + return new CSwordBibleModuleInfo(*this); + } + + inline ~CSwordBibleModuleInfo() { + delete m_bookList; + } + /** - * The constructor of this class + \returns the number of avalable verses for the given chapter and book. + \param book The number book we should use + \param chapter The chapter we should use */ - CSwordBibleModuleInfo( sword::SWModule* module, CSwordBackend* const ); - /** The copy constructor for this Bible module. - */ - CSwordBibleModuleInfo( const CSwordBibleModuleInfo& m ); + unsigned int verseCount(const unsigned int book, + const unsigned int chapter) const; + /** - * The destructor of this class + \returns the number of avalable verses for the given chapter and book. + \param book The name of the book we use + \param chapter The number of the chapter we use */ - ~CSwordBibleModuleInfo(); + unsigned int verseCount(const QString &book, + const unsigned int chapter) const; + /** - * Returns the number of avalable verses for the given chapter and book. - * - * @param book The number book we should use - * @param chapter The chapter we should use - * @return The number of verses for the given book and chapter + \returns the number of available chapters in the given book. */ - virtual unsigned int verseCount( const unsigned int book, const unsigned int chapter ); + unsigned int chapterCount(const unsigned int book) const; + /** - * Returns the number of avalable verses for the given chapter and book. - * - * @param book The name of the book we use - * @param chapter The number of the chapter we use - * @return The number of verses for the given book and chapter - */ - virtual unsigned int verseCount( const QString& book, const unsigned int chapter ); - /** Information about the chapters in a book. - * @return The number of available chapters of the given book. - * @return The number of chapters for the given book - */ - virtual unsigned int chapterCount( const unsigned int book ); - /** Information about the chapters in a book. - * @return The number of available chapters of the given book. + \returns the number of available chapters in the given book. */ - virtual unsigned int chapterCount( const QString& book ); - /** Return all book of this module. - * @return A QStringList containing the books which are available in this module. - */ - virtual QStringList* books(); + unsigned int chapterCount(const QString &book) const; + /** - * Reimplementation, Returns the type + \returns a QStringList containing the books available in this module. */ - virtual CSwordModuleInfo::ModuleType type() const; + QStringList *books() const; + /** - * @return the book number, values starting with 1; 0 if not found + \returns the index of the book given by its name. + \retval 0 if a book with the given name was not found. */ - unsigned int bookNumber(const QString &book); + unsigned int bookNumber(const QString &book) const; + /** - * Returns true if his module has the text of desired type of testament + \returns whether this module has the text of desired type of testament */ - bool hasTestament( CSwordBibleModuleInfo::Testament ); - /** Reimplementation to clone this object. */ - virtual CSwordModuleInfo* clone(); + bool hasTestament(CSwordBibleModuleInfo::Testament type) const { + return type == OldTestament ? m_hasOT : m_hasNT; + } + /** - * Returns the key which represents the lower bound of this module. + \returns the key which represents the lower bound of this module. */ - inline const CSwordVerseKey& lowerBound(); + inline const CSwordVerseKey &lowerBound() const { + return m_lowerBound; + } + /** - * Returns the key which represents the upper bound of this module. + \returns the key which represents the upper bound of this module. */ - inline const CSwordVerseKey& upperBound(); + inline const CSwordVerseKey &upperBound() const { + return m_upperBound; + } - private: + private: /* Methods: */ void initBounds(); + private: CSwordVerseKey m_lowerBound; CSwordVerseKey m_upperBound; - QStringList* m_bookList; //This booklist is cached - QString m_cachedLocale; - short int m_hasOT; - short int m_hasNT; + mutable QStringList *m_bookList; //This booklist is cached + mutable QString m_cachedLocale; + bool m_hasOT; + bool m_hasNT; }; -inline CSwordModuleInfo::ModuleType CSwordBibleModuleInfo::type() const { - return CSwordModuleInfo::Bible; -} - -/** Returns the key which represents the lower bound of this module. */ -inline const CSwordVerseKey& CSwordBibleModuleInfo::lowerBound() { - initBounds(); - return m_lowerBound; -} - -/** Returns the key which represents the lower bound of this module. */ -inline const CSwordVerseKey& CSwordBibleModuleInfo::upperBound() { - initBounds(); - return m_upperBound; -} - #endif diff --git a/src/backend/drivers/cswordbookmoduleinfo.cpp b/src/backend/drivers/cswordbookmoduleinfo.cpp index 6371de1..8c6b8b1 100644 --- a/src/backend/drivers/cswordbookmoduleinfo.cpp +++ b/src/backend/drivers/cswordbookmoduleinfo.cpp @@ -2,7 +2,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2008 by the BibleTime developers. +* Copyright 1999-2011 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ @@ -16,33 +16,22 @@ #include <treekeyidx.h> -CSwordBookModuleInfo::CSwordBookModuleInfo( sword::SWModule* module, CSwordBackend* const usedBackend ) - : CSwordModuleInfo(module, usedBackend), - m_depth(-1) {} - -CSwordBookModuleInfo::CSwordBookModuleInfo( const CSwordBookModuleInfo& module ) - : CSwordModuleInfo(module) { - m_depth = module.m_depth; -} - -CSwordBookModuleInfo::~CSwordBookModuleInfo() {} - -int CSwordBookModuleInfo::depth() { - if (m_depth == -1) { - sword::TreeKeyIdx* key = tree(); - - if (key) { - key->root(); - computeDepth(key, 0); - } +CSwordBookModuleInfo::CSwordBookModuleInfo(sword::SWModule *module, + CSwordBackend * const usedBackend) + : CSwordModuleInfo(module, usedBackend, + CSwordModuleInfo::GenericBook), + m_depth(-1) +{ + sword::TreeKeyIdx *key = tree(); + if (key) { + key->root(); + computeDepth(key, 0); } - - return m_depth; } -void CSwordBookModuleInfo::computeDepth(sword::TreeKeyIdx* key, int level ) { +void CSwordBookModuleInfo::computeDepth(sword::TreeKeyIdx *key, int level) { std::string savedKey; - // savedKey = key->getFullName(); //sword 1.5.8 + // savedKey = key->getFullName(); //sword 1.5.8 savedKey = key->getText(); if (level > m_depth) { diff --git a/src/backend/drivers/cswordbookmoduleinfo.h b/src/backend/drivers/cswordbookmoduleinfo.h index 77adb29..12a3d01 100644 --- a/src/backend/drivers/cswordbookmoduleinfo.h +++ b/src/backend/drivers/cswordbookmoduleinfo.h @@ -2,7 +2,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2008 by the BibleTime developers. +* Copyright 1999-2011 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ @@ -16,50 +16,48 @@ #include <treekeyidx.h> -/** Class for generic book support - * @author The BibleTime team - */ +/** + \brief Class for generic book support +*/ +class CSwordBookModuleInfo: public CSwordModuleInfo { + Q_OBJECT -class CSwordBookModuleInfo : public CSwordModuleInfo { - - public: - /** Constructor. - * @param module The module which belongs to this object - * @param backend The parent backend for this book module. - */ - CSwordBookModuleInfo( sword::SWModule* module, CSwordBackend* const backend ); - /** Copy constructor. - * Copy constructor to copy the passed parameter. - * @param module The module which should be copied. - */ - CSwordBookModuleInfo( const CSwordBookModuleInfo& module ); - /** Destructor. - */ - ~CSwordBookModuleInfo(); + public: /* Methods: */ /** - * Returns the type of the module. + \param module The module which belongs to this object + \param backend The parent backend for this book module. */ - virtual CSwordModuleInfo::ModuleType type() const; + CSwordBookModuleInfo(sword::SWModule *module, + CSwordBackend * const usedBackend); + + inline CSwordBookModuleInfo(const CSwordBookModuleInfo ©) + : CSwordModuleInfo(copy), m_depth(copy.m_depth) {} + + /* Reimplementation of CSwordModuleInfo::clone(). */ + virtual inline CSwordModuleInfo *clone() const { + return new CSwordBookModuleInfo(*this); + } + /** - * Returns the maximal depth of sections and subsections. + \returns the maximal depth of sections and subsections. */ - int depth(); + inline int depth() const { return m_depth; } + /** - * @return A treekey filled with the structure of this module. Don't delete the returned key because it's casted from the module object. + \returns A treekey filled with the structure of this module. Don't + delete the returned key because it's casted from the module + object. */ - sword::TreeKeyIdx* tree() const; + sword::TreeKeyIdx *tree() const; - private: + private: /* Methods: */ /** * A recursive helper function to help computng the module depth! */ - void computeDepth(sword::TreeKeyIdx* key, int level = 0 ); + void computeDepth(sword::TreeKeyIdx *key, int level = 0); + + private: /* Fields: */ int m_depth; }; -inline CSwordBookModuleInfo::ModuleType CSwordBookModuleInfo::type() const { - return CSwordModuleInfo::GenericBook; -} - - #endif diff --git a/src/backend/drivers/cswordcommentarymoduleinfo.cpp b/src/backend/drivers/cswordcommentarymoduleinfo.cpp index 8b74ffa..07e09d2 100644 --- a/src/backend/drivers/cswordcommentarymoduleinfo.cpp +++ b/src/backend/drivers/cswordcommentarymoduleinfo.cpp @@ -2,7 +2,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2008 by the BibleTime developers. +* Copyright 1999-2011 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ @@ -10,24 +10,11 @@ #include "backend/drivers/cswordcommentarymoduleinfo.h" -CSwordCommentaryModuleInfo::CSwordCommentaryModuleInfo( sword::SWModule* module, CSwordBackend* const usedBackend) - : CSwordBibleModuleInfo(module, usedBackend) {} - -CSwordCommentaryModuleInfo::~CSwordCommentaryModuleInfo() {} - -/** No descriptions */ -CSwordModuleInfo* CSwordCommentaryModuleInfo::clone() { - return new CSwordCommentaryModuleInfo(*this); -} - -/** Returns true if this module may be written by the write display windows. */ bool CSwordCommentaryModuleInfo::isWritable() const { - // qWarning(module()->getConfigEntry("ModDrv")); - //a module is only writable if it's a RawFiles module with writable returning true - - if ( (std::string(module()->getConfigEntry("ModDrv")) == std::string("RawFiles")) && module()->isWritable()) { - return true; - }; - - return false; + /* + A module is only writable if it's a RawFiles module with writable + returning true. + */ + return std::string(module()->getConfigEntry("ModDrv")) == "RawFiles" + && module()->isWritable(); } diff --git a/src/backend/drivers/cswordcommentarymoduleinfo.h b/src/backend/drivers/cswordcommentarymoduleinfo.h index a297538..60640a2 100644 --- a/src/backend/drivers/cswordcommentarymoduleinfo.h +++ b/src/backend/drivers/cswordcommentarymoduleinfo.h @@ -2,7 +2,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2008 by the BibleTime developers. +* Copyright 1999-2011 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ @@ -13,31 +13,27 @@ #include "backend/drivers/cswordbiblemoduleinfo.h" -/** Commentary module implementation. - * This CSwordModule implementation provides access to Sword's commentary modules. - * @author The BibleTime team - * @version $Id: cswordcommentarymoduleinfo.h,v 1.13 2006/02/25 11:38:15 joachim Exp $ - */ - -class CSwordCommentaryModuleInfo : public CSwordBibleModuleInfo { - - public: - CSwordCommentaryModuleInfo( sword::SWModule* module, CSwordBackend* const ); - ~CSwordCommentaryModuleInfo(); - /** Reimplementation to return the commentary type. - */ - virtual CSwordModuleInfo::ModuleType type() const; - /** Reimplementation to clone the current object. - */ - virtual CSwordModuleInfo* clone(); - /** - * Returns true if this module may be written by the write display windows. - */ +/** + \brief Commentary module implementation. + + This CSwordModule implementation provides access to Sword's commentary modules. +*/ +class CSwordCommentaryModuleInfo: public CSwordBibleModuleInfo { + Q_OBJECT + + public: /* Methods: */ + inline CSwordCommentaryModuleInfo(sword::SWModule *module, + CSwordBackend * const usedBackend) + : CSwordBibleModuleInfo(module, usedBackend, + CSwordModuleInfo::Commentary) {} + + /* Reimplementation of CSwordModuleInfo::clone(). */ + virtual inline CSwordModuleInfo* clone() const { + return new CSwordCommentaryModuleInfo(*this); + } + + /* Reimplementation of CSwordModuleInfo::isWritable(). */ virtual bool isWritable() const; }; -inline CSwordModuleInfo::ModuleType CSwordCommentaryModuleInfo::type() const { - return CSwordModuleInfo::Commentary; -} - #endif diff --git a/src/backend/drivers/cswordlexiconmoduleinfo.cpp b/src/backend/drivers/cswordlexiconmoduleinfo.cpp index c4a04de..d6515be 100644 --- a/src/backend/drivers/cswordlexiconmoduleinfo.cpp +++ b/src/backend/drivers/cswordlexiconmoduleinfo.cpp @@ -2,14 +2,13 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2008 by the BibleTime developers. +* Copyright 1999-2011 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ #include "backend/drivers/cswordlexiconmoduleinfo.h" -#include <algorithm> #include <QFile> #include <QDataStream> #include <QTextCodec> @@ -24,45 +23,23 @@ //Change it once the format changed to make all systems rebuild their caches #define CACHE_FORMAT "3" -CSwordLexiconModuleInfo::CSwordLexiconModuleInfo( sword::SWModule* module, CSwordBackend* const backend ) : CSwordModuleInfo(module, backend) { - m_entryList = 0; -} - -CSwordLexiconModuleInfo::CSwordLexiconModuleInfo( const CSwordLexiconModuleInfo& m ) : CSwordModuleInfo(m) { - delete m_entryList; - m_entryList = 0; - - if (m.m_entryList) { - m_entryList = new QStringList(); - *m_entryList = *m.m_entryList;//copy list items - } -} - -CSwordLexiconModuleInfo::~CSwordLexiconModuleInfo() { - delete m_entryList; - m_entryList = 0; -} - -/** Returns the entries of the module. */ -QStringList* CSwordLexiconModuleInfo::entries() { +const QStringList &CSwordLexiconModuleInfo::entries() const { namespace DU = util::directory; - if (!module()) { - return 0; + // If cache is ok, just return it: + if (!m_entries.empty()) { + return m_entries; } - if (m_entryList) return m_entryList; - - m_entryList = new QStringList(); - + // Initialize cache: //Check for buggy modules! They will not be loaded any more. if ( name() == QString("ZhEnglish")) { qWarning() << "Module ZhEnglish is buggy and will not be loaded."; - return m_entryList; + return m_entries; } if ( name() == QString("EReo_en")) { qWarning() << "Module EReo_en is buggy and will not be loaded."; - return m_entryList; + return m_entries; } QString dir(DU::getUserCacheDir().absolutePath()); @@ -88,11 +65,11 @@ QStringList* CSwordLexiconModuleInfo::entries() { if (ModuleVersion == config(CSwordModuleInfo::ModuleVersion) && CacheVersion == CACHE_FORMAT && QDataStreamVersion == QString::number(s.version())) { - s >> *m_entryList; + s >> m_entries; f1.close(); - qDebug() << "Read" << m_entryList->count() << "entries from lexicon cache for module" << name(); - return m_entryList; + qDebug() << "Read" << m_entries.count() << "entries from lexicon cache for module" << name(); + return m_entries; } f1.close(); @@ -103,40 +80,37 @@ QStringList* CSwordLexiconModuleInfo::entries() { */ qDebug() << "Read all entries of lexicon" << name(); - sword::SWModule* my_module = module(); - my_module->setSkipConsecutiveLinks(true); - (*my_module) = sword::TOP; + module()->setSkipConsecutiveLinks(true); + module()->setPosition(sword::TOP); snap(); //snap to top entry do { if ( isUnicode() ) { - m_entryList->append(QString::fromUtf8(my_module->KeyText())); + m_entries.append(QString::fromUtf8(module()->KeyText())); } else { //for latin1 modules use fromLatin1 because of speed QTextCodec* codec = QTextCodec::codecForName("Windows-1252"); - m_entryList->append(codec->toUnicode(my_module->KeyText())); + m_entries.append(codec->toUnicode(module()->KeyText())); } - (*my_module)++; - } - while ( !my_module->Error() ); - - (*my_module) = sword::TOP; //back to the first entry + module()->increment(); + } while (!module()->Error()); - my_module->setSkipConsecutiveLinks(false); + module()->setPosition(sword::TOP); // back to the first entry + module()->setSkipConsecutiveLinks(false); - if (m_entryList->count()) { - m_entryList->first().simplified(); + if (m_entries.count()) { + m_entries.first().simplified(); - if (m_entryList->first().trimmed().isEmpty()) { - m_entryList->erase( m_entryList->begin() ); + if (m_entries.first().trimmed().isEmpty()) { + m_entries.erase( m_entries.begin() ); } } qDebug() << "Writing cache file for lexicon module" << name(); - if (m_entryList->count()) { + if (m_entries.count()) { //create cache QString dir(DU::getUserCacheDir().absolutePath()); QFile f2( QString(dir).append("/").append(name()) ); @@ -146,24 +120,10 @@ QStringList* CSwordLexiconModuleInfo::entries() { s << config(CSwordModuleInfo::ModuleVersion) //store module version << QString(CACHE_FORMAT) //store BT version -- format may change << QString::number(s.version()) //store QDataStream version -- format may change - << *m_entryList; + << m_entries; f2.close(); } } - return m_entryList; -} - -/** Jumps to the closest entry in the module. */ -bool CSwordLexiconModuleInfo::snap() { - if (module()->getRawEntry()) { // Snap to the current entry - return true; - } - - return false; -} - -/** No descriptions */ -CSwordModuleInfo* CSwordLexiconModuleInfo::clone() { - return new CSwordLexiconModuleInfo(*this); + return m_entries; } diff --git a/src/backend/drivers/cswordlexiconmoduleinfo.h b/src/backend/drivers/cswordlexiconmoduleinfo.h index 36d30fb..d75e106 100644 --- a/src/backend/drivers/cswordlexiconmoduleinfo.h +++ b/src/backend/drivers/cswordlexiconmoduleinfo.h @@ -2,7 +2,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2008 by the BibleTime developers. +* Copyright 1999-2011 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ @@ -16,55 +16,46 @@ /** - * The implementation of CModuleInfo for the Sword lexiccons and citionaries. - * @author The BibleTime team - * @version $Id: cswordlexiconmoduleinfo.h,v 1.12 2006/02/25 11:38:15 joachim Exp $ - */ + The implementation of CModuleInfo for the Sword lexiccons and citionaries. +*/ +class CSwordLexiconModuleInfo: public CSwordModuleInfo { + Q_OBJECT -class CSwordLexiconModuleInfo : public CSwordModuleInfo { + public: /* Methods: */ + inline CSwordLexiconModuleInfo(sword::SWModule *module, + CSwordBackend * const backend) + : CSwordModuleInfo(module, backend, Lexicon) {} + + inline CSwordLexiconModuleInfo(const CSwordLexiconModuleInfo ©) + : CSwordModuleInfo(copy), m_entries(copy.m_entries) {} + + /* Reimplementation of CSwordModuleInfo::clone(). */ + virtual inline CSwordModuleInfo *clone() const { + return new CSwordLexiconModuleInfo(*this); + } - public: - /** - * The standard constructor fot this object. - * A default constructor doesn't exist. Use this one. - */ - CSwordLexiconModuleInfo( sword::SWModule* module, CSwordBackend* const ); - /** - * The copy constructor - */ - CSwordLexiconModuleInfo( const CSwordLexiconModuleInfo& m ); - /** Reimplementation to return a valid clone. - */ - virtual CSwordModuleInfo* clone(); - /** Destructor. - */ - virtual ~CSwordLexiconModuleInfo(); - /** - * Returns the entries of the module. - * This function returns the entries of the modules represented by this object. - * If this function is called for the first time the list is load from disk and stored in a list which cahes it. - * If the function is called again, the cached list is returned so we have a major speed improvement. - * @return The list of lexicon entries - */ - QStringList* entries(); /** - * Reimplementation, to return the right type for this lexicon. + This method returns the entries of the modules represented by this + object. If this function is called for the first time the list is load + from disk and stored in a list which cahes it. If the function is + called again, the cached list is returned so we have a major speed + improvement. + \returns the list of lexicon entries in the module. */ - virtual CSwordModuleInfo::ModuleType type() const; + const QStringList &entries() const; + /** - * Jumps to the closest entry in the module. + Jumps to the closest entry in the module. */ - bool snap(); + virtual inline bool snap() const { + return module()->getRawEntry(); + } - private: + private: /* Fields: */ /** - * This is the list which caches the entres of the module. + This is the list which caches the entres of the module. */ - QStringList* m_entryList; + mutable QStringList m_entries; }; -inline CSwordModuleInfo::ModuleType CSwordLexiconModuleInfo::type() const { - return CSwordModuleInfo::Lexicon; -} - #endif diff --git a/src/backend/drivers/cswordmoduleinfo.cpp b/src/backend/drivers/cswordmoduleinfo.cpp index 6096af2..b1e646f 100644 --- a/src/backend/drivers/cswordmoduleinfo.cpp +++ b/src/backend/drivers/cswordmoduleinfo.cpp @@ -2,14 +2,14 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2008 by the BibleTime developers. +* Copyright 1999-2011 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ #include "backend/drivers/cswordmoduleinfo.h" -#include <boost/scoped_ptr.hpp> +#include <QSharedPointer> #include <CLucene.h> #include <CLucene/util/Misc.h> #include <CLucene/util/Reader.h> @@ -28,8 +28,9 @@ #include "backend/managers/cswordbackend.h" #include "backend/rendering/centrydisplay.h" #include "backend/cswordmodulesearch.h" +#include "btglobal.h" +#include "util/cresmgr.h" #include "util/directory.h" -#include "util/cpointers.h" #include "util/exceptions.h" #include "util/dialogutil.h" @@ -42,6 +43,29 @@ #include <versekey.h> +#ifdef BT_DEBUG +namespace { + +/** HELPER Method to dump all current EntryAttributes of a module. */ +void dumpEntryAttributes(sword::SWModule *m) { + qDebug() << "Attributes for key: " << m->getKeyText(); + sword::AttributeTypeList::iterator i1; + sword::AttributeList::iterator i2; + sword::AttributeValue::iterator i3; + for (i1 = m->getEntryAttributes().begin(); i1 != m->getEntryAttributes().end(); i1++) { + qDebug() << "[ " << i1->first << " ]"; + for (i2 = i1->second.begin(); i2 != i1->second.end(); i2++) { + qDebug() << "\t[ " << i2->first << " ]"; + for (i3 = i2->second.begin(); i3 != i2->second.end(); i3++) { + qDebug() << "\t\t" << i3->first << " = " << i3->second; + } + } + } +} + +} // anonymous namespace +#endif + //Increment this, if the index format changes //Then indices on the user's systems will be rebuilt const unsigned int INDEX_VERSION = 7; @@ -50,69 +74,76 @@ const unsigned int INDEX_VERSION = 7; //Lucene default is too small const unsigned long BT_MAX_LUCENE_FIELD_LENGTH = 1024 * 1024; -CSwordModuleInfo::CSwordModuleInfo(sword::SWModule * module, CSwordBackend * const usedBackend) { - m_module = module; - Q_ASSERT(module); +CSwordModuleInfo::CSwordModuleInfo(sword::SWModule *module, + CSwordBackend * const usedBackend, + ModuleType type) + : m_module(module), + m_backend(usedBackend ? usedBackend : CSwordBackend::instance()), + m_type(type), + m_cancelIndexing(false), + m_cachedName(QString::fromUtf8(module->Name())), + m_cachedHasVersion(!QString((*m_backend->getConfig())[module->Name()]["Version"]).isEmpty()) +{ + Q_ASSERT(module != 0); + Q_ASSERT(usedBackend != 0); + + initCachedCategory(); + initCachedLanguage(); - m_cancelIndexing = false; - m_searchResult.ClearList(); - m_backend = usedBackend ? usedBackend : CPointers::backend(); - m_dataCache.name = module ? QString(module->Name()) : QString::null; - m_dataCache.isUnicode = module ? module->isUnicode() : false; - m_dataCache.category = UnknownCategory; - m_dataCache.language = 0; - m_dataCache.hasVersion = !QString((*m_backend->getConfig())[module->Name()]["Version"]).isEmpty(); m_hidden = CBTConfig::get(CBTConfig::hiddenModules).contains(name()); if (backend()) { if (hasVersion() && (minimumSwordVersion() > sword::SWVersion::currentVersion)) { qWarning("The module \"%s\" requires a newer Sword library. Please update to \"Sword %s\".", name().toUtf8().constData(), (const char *)minimumSwordVersion()); + + /// \todo if this is the case, can we use the module at all? } } } -CSwordModuleInfo::CSwordModuleInfo(const CSwordModuleInfo & m) : QObject() { - m_module = m.m_module; - m_backend = m.m_backend; - m_dataCache = m.m_dataCache; - m_searchResult = m.m_searchResult; - m_hidden = m.m_hidden; - m_cancelIndexing = m.m_cancelIndexing; +CSwordModuleInfo::CSwordModuleInfo(const CSwordModuleInfo &o) + : QObject(0), m_module(o.m_module), m_backend(o.m_backend), + m_type(o.m_type), m_hidden(o.m_hidden), + m_cancelIndexing(o.m_cancelIndexing), m_cachedName(o.m_cachedName), + m_cachedCategory(o.m_cachedCategory), + m_cachedLanguage(o.m_cachedLanguage), + m_cachedHasVersion(o.m_cachedHasVersion) +{ + // Intentionally empty } -/** No descriptions */ -CSwordModuleInfo *CSwordModuleInfo::clone() { - return new CSwordModuleInfo(*this); -} - -CSwordModuleInfo::~CSwordModuleInfo() { - m_searchResult.ClearList(); - m_module = 0; //the Sword module object is deleted by the backend -} - -/** Sets the unlock key of the modules and writes the key into the cofig file.*/ bool CSwordModuleInfo::unlock(const QString & unlockKey) { if (!isEncrypted()) { return false; } + bool unlocked = unlockKeyIsValid(); + CBTConfig::setModuleEncryptionKey(name(), unlockKey); + + /// \todo remove this comment once it is no longer needed + /* There is currently a deficiency in sword 1.6.1 in that backend->setCipherKey() does + * not work correctly for modules from which data was already fetched. Therefore we have to + * reload the modules in bibletime.cpp + */ backend()->setCipherKey(m_module->Name(), unlockKey.toUtf8().constData()); + /// \todo write to Sword config as well + if (unlockKeyIsValid() != unlocked) { + emit unlockedChanged(!unlocked); + } return true; } -/** This function returns true if this module is locked, otherwise return false. */ -bool CSwordModuleInfo::isLocked() { +bool CSwordModuleInfo::isLocked() const { //still works, but the cipherkey is stored in CBTConfig. //Works because it is set in sword on program startup. return isEncrypted() && !unlockKeyIsValid(); } -/** This functions returns true if this module is encrypted (locked or unlocked). */ bool CSwordModuleInfo::isEncrypted() const { /** * If we have the CipherKey entry the module @@ -120,22 +151,18 @@ bool CSwordModuleInfo::isEncrypted() const { */ //This code is still right, though we do no longer write to the module config files any more - sword::ConfigEntMap config = backend()->getConfig()->Sections.find(name().toUtf8().constData())->second; + std::map < sword::SWBuf, sword::ConfigEntMap, std::less < sword::SWBuf > >::iterator SectionMapIter; + SectionMapIter = backend()->getConfig()->Sections.find(name().toUtf8().constData()); + if (SectionMapIter == backend()->getConfig()->Sections.end()) + return false; + sword::ConfigEntMap config = SectionMapIter->second; sword::ConfigEntMap::iterator it = config.find("CipherKey"); return it != config.end(); } -/** This function makes an estimate if a module was properly unlocked. -* It returns true if the first entry of the module is not empty and -* contains only printable characters (for the first 100 chars or so). -* If that is the case, we can safely assume that a) the module was properly -* unlocked and b) no buffer overflows will occur, which can happen when -* Sword filters process garbage text which was not properly decrypted. -*/ -bool CSwordModuleInfo::unlockKeyIsValid() { - - (*m_module) = sword::TOP; +bool CSwordModuleInfo::unlockKeyIsValid() const { + m_module->setPosition(sword::TOP); // This needs to use ::fromLatin1 because if the text is still locked, // a lot of garbage will show up. It will also work with properly decrypted @@ -146,18 +173,15 @@ bool CSwordModuleInfo::unlockKeyIsValid() { : QString::fromLatin1( m_module->getRawEntryBuf().c_str() ); if (test.isEmpty()) { - qWarning() << "Unlock key of module" << name() << "is NOT valid!"; return false; } for (int i = 0; i <= test.length() && i < 100; i++) { if ( !test[i].isPrint() && !test[i].isNull() ) { - qWarning() << "Unlock key of module" << name() << "is NOT valid!"; return false; } } - qDebug() << "Unlock key of module" << name() << "is valid"; return true; } @@ -173,7 +197,7 @@ QString CSwordModuleInfo::getModuleStandardIndexLocation() const { //this for no return getModuleBaseIndexLocation() + QString("/standard"); } -bool CSwordModuleInfo::hasIndex() { +bool CSwordModuleInfo::hasIndex() const { //this will return true only //if the index exists and has correct version information for both index and module QDir d; @@ -199,25 +223,6 @@ bool CSwordModuleInfo::hasIndex() { return lucene::index::IndexReader::indexExists(getModuleStandardIndexLocation().toAscii().constData()); } -// HELPER Method: this dumps all current EntryAttributes of a module -//#include <iostream> -//void dumpEntryAttributes(sword::SWModule *module) { -// std::cout << "Attributes for key: " << module->getKeyText() << std::endl; -// sword::AttributeTypeList::iterator i1; -// sword::AttributeList::iterator i2; -// sword::AttributeValue::iterator i3; -// for (i1 = module->getEntryAttributes().begin(); i1 != module->getEntryAttributes().end(); i1++) { -// std::cout << "[ " << i1->first << " ]\n"; -// for (i2 = i1->second.begin(); i2 != i1->second.end(); i2++) { -// std::cout << "\t[ " << i2->first << " ]\n"; -// for (i3 = i2->second.begin(); i3 != i2->second.end(); i3++) { -// std::cout << "\t\t" << i3->first << " = " << i3->second << "\n"; -// } -// } -// } -// std::cout << std::endl; -//} - void CSwordModuleInfo::buildIndex() { m_cancelIndexing = false; @@ -252,14 +257,14 @@ void CSwordModuleInfo::buildIndex() { } } - boost::scoped_ptr<lucene::index::IndexWriter> writer( new lucene::index::IndexWriter(index.toAscii().constData(), &an, true) ); //always create a new index + QSharedPointer<lucene::index::IndexWriter> writer( new lucene::index::IndexWriter(index.toAscii().constData(), &an, true) ); //always create a new index writer->setMaxFieldLength(BT_MAX_LUCENE_FIELD_LENGTH); writer->setUseCompoundFile(true); //merge segments into a single file writer->setMinMergeDocs(1000); - *m_module = sword::TOP; + m_module->setPosition(sword::TOP); unsigned long verseLowIndex = m_module->Index(); - *m_module = sword::BOTTOM; + m_module->setPosition(sword::BOTTOM); unsigned long verseHighIndex = m_module->Index(); //verseLowIndex is not 0 in all cases (i.e. NT-only modules) @@ -271,7 +276,7 @@ void CSwordModuleInfo::buildIndex() { if (type() == CSwordModuleInfo::Lexicon) { verseIndex = 0; verseLowIndex = 0; - verseSpan = ((CSwordLexiconModuleInfo*)this)->entries()->size(); + verseSpan = ((CSwordLexiconModuleInfo*)this)->entries().size(); } emit indexingProgress(0); @@ -296,14 +301,15 @@ void CSwordModuleInfo::buildIndex() { wchar_t wcharBuffer[BT_MAX_LUCENE_FIELD_LENGTH + 1]; - for (*m_module = sword::TOP; !(m_module->Error()) && !m_cancelIndexing; (*m_module)++) { + m_module->setPosition(sword::TOP); + while (!(m_module->Error()) && !m_cancelIndexing) { // Also index Chapter 0 and Verse 0, because they might have information in the entry attributes // We used to just put their content into the textBuffer and continue to the next verse, but // with entry attributes this doesn't work any more. // Hits in the search dialog will show up as 1:1 (instead of 0) - boost::scoped_ptr<lucene::document::Document> doc(new lucene::document::Document()); + QSharedPointer<lucene::document::Document> doc(new lucene::document::Document()); //index the key lucene_utf8towcs(wcharBuffer, key->getText(), BT_MAX_LUCENE_FIELD_LENGTH); @@ -357,7 +363,7 @@ void CSwordModuleInfo::buildIndex() { } } // for attListI - writer->addDocument(doc.get()); + writer->addDocument(doc.data()); //Index() is not implemented properly for lexicons, so we use a //workaround. if (type() == CSwordModuleInfo::Lexicon) { @@ -380,7 +386,9 @@ void CSwordModuleInfo::buildIndex() { //m_indexingProgress.activate(); emit indexingProgress(indexingProgressValue); } - } + + m_module->increment(); + } // while (!(m_module->Error()) && !m_cancelIndexing) if (!m_cancelIndexing) { writer->optimize(); @@ -421,20 +429,23 @@ unsigned long CSwordModuleInfo::indexSize() const { } -bool CSwordModuleInfo::searchIndexed(const QString& searchedText, sword::ListKey& scope) { +int CSwordModuleInfo::searchIndexed(const QString &searchedText, + const sword::ListKey &scope, + sword::ListKey &results) const +{ char utfBuffer[BT_MAX_LUCENE_FIELD_LENGTH + 1]; wchar_t wcharBuffer[BT_MAX_LUCENE_FIELD_LENGTH + 1]; // work around Swords thread insafety for Bibles and Commentaries - boost::scoped_ptr < CSwordKey > key(CSwordKey::createInstance(this)); - sword::SWKey* s = dynamic_cast < sword::SWKey * >(key.get()); + QSharedPointer < CSwordKey > key(CSwordKey::createInstance(this)); + sword::SWKey* s = dynamic_cast < sword::SWKey * >(key.data()); QList<sword::VerseKey*> list; if (s) { m_module->SetKey(*s); } - m_searchResult.ClearList(); + results.ClearList(); try { // do not use any stop words @@ -442,15 +453,16 @@ bool CSwordModuleInfo::searchIndexed(const QString& searchedText, sword::ListKey lucene::analysis::standard::StandardAnalyzer analyzer( stop_words ); lucene::search::IndexSearcher searcher(getModuleStandardIndexLocation().toAscii().constData()); lucene_utf8towcs(wcharBuffer, searchedText.toUtf8().constData(), BT_MAX_LUCENE_FIELD_LENGTH); - boost::scoped_ptr<lucene::search::Query> q( lucene::queryParser::QueryParser::parse((const TCHAR*)wcharBuffer, (const TCHAR*)_T("content"), &analyzer) ); + QSharedPointer<lucene::search::Query> q( lucene::queryParser::QueryParser::parse((const TCHAR*)wcharBuffer, (const TCHAR*)_T("content"), &analyzer) ); - boost::scoped_ptr<lucene::search::Hits> h( searcher.search(q.get(), lucene::search::Sort::INDEXORDER) ); + QSharedPointer<lucene::search::Hits> h( searcher.search(q.data(), lucene::search::Sort::INDEXORDER) ); - const bool useScope = (scope.Count() > 0); -// const bool isVerseModule = (type() == CSwordModuleInfo::Bible) || (type() == CSwordModuleInfo::Commentary); + /// \warning This is a workaround for Sword constness + const bool useScope = (const_cast<sword::ListKey&>(scope).Count() > 0); +// const bool isVerseModule = (type() == CSwordModuleInfo::Bible) || (type() == CSwordModuleInfo::Commentary); lucene::document::Document* doc = 0; - boost::scoped_ptr<sword::SWKey> swKey( module()->CreateKey() ); + QSharedPointer<sword::SWKey> swKey( module()->CreateKey() ); for (int i = 0; i < h->length(); ++i) { @@ -462,46 +474,34 @@ bool CSwordModuleInfo::searchIndexed(const QString& searchedText, sword::ListKey // limit results based on scope //if (searchOptions & CSwordModuleSearch::useScope && scope.Count() > 0){ if (useScope) { - for (int j = 0; j < scope.Count(); j++) { - sword::VerseKey* vkey = dynamic_cast<sword::VerseKey*>(scope.getElement(j)); + /// \warning This is a workaround for sword constness + for (int j = 0; j < const_cast<sword::ListKey&>(scope).Count(); j++) { + /// \warning This is a workaround for sword constness + sword::ListKey &scope2 = const_cast<sword::ListKey&>(scope); + sword::VerseKey* vkey = dynamic_cast<sword::VerseKey*>(scope2.getElement(j)); if (vkey->LowerBound().compare(*swKey) <= 0 && vkey->UpperBound().compare(*swKey) >= 0) { - m_searchResult.add(*swKey); + results.add(*swKey); } } } else { // no scope, give me all buffers - m_searchResult.add(*swKey); + results.add(*swKey); } } } catch (...) { qWarning("CLucene exception occurred"); util::showWarning(0, QCoreApplication::tr("Search aborted"), QCoreApplication::tr("An internal error occurred while executing your search.")); - return false; + return 0; } qDeleteAll(list); list.clear(); - return (m_searchResult.Count() > 0); -} - -/** Returns the last search result for this module. */ -sword::ListKey & CSwordModuleInfo::searchResult(const sword::ListKey * newResult) { - if (newResult) { - m_searchResult.copyFrom(*newResult); - } - - return m_searchResult; -} - -/** Clears the last search result. */ -void CSwordModuleInfo::clearSearchResult() { - m_searchResult.ClearList(); + return results.Count(); } -/** Returns the required Sword version for this module. Returns -1 if no special Sword version is required. */ -sword::SWVersion CSwordModuleInfo::minimumSwordVersion() { +sword::SWVersion CSwordModuleInfo::minimumSwordVersion() const { return sword::SWVersion(config(CSwordModuleInfo::MinimumSwordVersion).toUtf8().constData()); } @@ -634,12 +634,11 @@ QString CSwordModuleInfo::config(const CSwordModuleInfo::ConfigEntry entry) cons } } -/** Returns true if the module supports the feature given as parameter. */ bool CSwordModuleInfo::has(const CSwordModuleInfo::Feature feature) const { switch (feature) { - // case StrongsNumbers: - // return m_module->getConfig().has("Feature", "StrongsNumber"); + // case StrongsNumbers: + // return m_module->getConfig().has("Feature", "StrongsNumber"); case GreekDef: return m_module->getConfig().has("Feature", "GreekDef"); @@ -684,25 +683,20 @@ bool CSwordModuleInfo::has(const CSwordModuleInfo::FilterTypes option) const { return false; } -/** Returns the text direction of the module's text., */ -CSwordModuleInfo::TextDirection CSwordModuleInfo::textDirection() { - if (config(TextDir) == "RtoL") { +CSwordModuleInfo::TextDirection CSwordModuleInfo::textDirection() const { + if (config(TextDir) == "RtoL") return CSwordModuleInfo::RightToLeft; - } - else { - return CSwordModuleInfo::LeftToRight; - } + + return CSwordModuleInfo::LeftToRight; } -/** Writes the new text at the given position into the module. This does only work for writable modules. */ -void CSwordModuleInfo::write(CSwordKey * key, const QString & newText) { +void CSwordModuleInfo::write(CSwordKey *key, const QString &newText) { module()->KeyText(key->key().toUtf8().constData()); //don't store a pointer to the const char* value somewhere because QCString doesn't keep the value of it module()->setEntry(isUnicode() ? newText.toUtf8().constData() : newText.toLocal8Bit().constData()); } -/** Deletes the current entry and removes it from the module. */ bool CSwordModuleInfo::deleteEntry(CSwordKey * const key) { module()->KeyText(isUnicode() ? key->key().toUtf8().constData() : key->key().toLocal8Bit().constData()); @@ -714,43 +708,48 @@ bool CSwordModuleInfo::deleteEntry(CSwordKey * const key) { return false; } -/** Returns the category of this module. See CSwordModuleInfo::Category for possible values. */ -CSwordModuleInfo::Category CSwordModuleInfo::category() const { - //qDebug() << "CSwordModuleInfo::category"; - if (m_dataCache.category == CSwordModuleInfo::UnknownCategory) { - const QString cat(m_module->getConfigEntry("Category")); - //qDebug() << "the category was unknown, add a category "<< cat << "for module" << m_module->Name(); +void CSwordModuleInfo::initCachedCategory() { + /// \todo Maybe we can use raw string comparsion instead of QString? + const QString cat(m_module->getConfigEntry("Category")); - if (cat == "Cults / Unorthodox / Questionable Material") { - m_dataCache.category = Cult; - } - else if (cat == "Daily Devotional" || m_module->getConfig().has("Feature", "DailyDevotion")) { - m_dataCache.category = DailyDevotional; - } - else if (cat == "Glossaries" || m_module->getConfig().has("Feature", "Glossary")) { //allow both - m_dataCache.category = Glossary; - } - else if (cat == "Images" || cat == "Maps") { - m_dataCache.category = Images; - } - else if (type() == Commentary) { - m_dataCache.category = Commentaries; - } - else if (type() == Bible) { - m_dataCache.category = Bibles; - } - else if (type() == Lexicon) { - m_dataCache.category = Lexicons; - } - else if (type() == GenericBook) { - m_dataCache.category = Books; + /// \warning cat has to be checked before type() !!! + if (cat == "Cults / Unorthodox / Questionable Material") { + m_cachedCategory = Cult; + } else if (cat == "Daily Devotional" + || m_module->getConfig().has("Feature","DailyDevotion")) + { + m_cachedCategory = DailyDevotional; + } else if (cat == "Glossaries" + || m_module->getConfig().has("Feature", "Glossary")) + { + m_cachedCategory = Glossary; + } else if (cat == "Images" || cat == "Maps") { + m_cachedCategory = Images; + } else { + switch (type()) { + case Bible: m_cachedCategory = Bibles; break; + case Commentary: m_cachedCategory = Commentaries; break; + case Lexicon: m_cachedCategory = Lexicons; break; + case GenericBook: m_cachedCategory = Books; break; + case Unknown: // Fall thru + default: m_cachedCategory = UnknownCategory; break; } } - //qDebug() << "assigned category: " << m_dataCache.category; - return m_dataCache.category; } -/** Returns the display object for this module. */ +void CSwordModuleInfo::initCachedLanguage() { + CLanguageMgr *lm = CLanguageMgr::instance(); + if (category() == Glossary) { + /* + Special handling for glossaries, we use the "from language" as + language for the module. + */ + m_cachedLanguage = lm->languageForAbbrev(config(GlossaryFrom)); + } else { + m_cachedLanguage = lm->languageForAbbrev(m_module->Lang()); + } +} + Rendering::CEntryDisplay * CSwordModuleInfo::getDisplay() const { return dynamic_cast < Rendering::CEntryDisplay * >(m_module->Disp()); } @@ -873,30 +872,114 @@ QString CSwordModuleInfo::aboutText() const { return text; } -/** Returns the language of the module. */ -const CLanguageMgr::Language* CSwordModuleInfo::language() const { - if (!m_dataCache.language) { - if (module()) { - if (category() == Glossary) { - //special handling for glossaries, we use the "from language" as language for the module - m_dataCache.language = (CPointers::languageMgr())->languageForAbbrev(config(GlossaryFrom)); +QIcon CSwordModuleInfo::moduleIcon(const CSwordModuleInfo *module) { + const QString &filename = moduleIconFilename(module); + if (filename.isEmpty()) return QIcon(); + return util::directory::getIcon(filename); +} + +const QString &CSwordModuleInfo::moduleIconFilename( + const CSwordModuleInfo *module) +{ + const CSwordModuleInfo::Category cat(module->category()); + switch (cat) { + case CSwordModuleInfo::Bibles: + if (module->isLocked()) { + return CResMgr::modules::bible::icon_locked; } else { - m_dataCache.language = (CPointers::languageMgr())->languageForAbbrev(module()->Lang()); + return CResMgr::modules::bible::icon_unlocked; } - } - else { - m_dataCache.language = (CPointers::languageMgr())->defaultLanguage(); //default language - } + case CSwordModuleInfo::Commentaries: + if (module->isLocked()) { + return CResMgr::modules::commentary::icon_locked; + } + else { + return CResMgr::modules::commentary::icon_unlocked; + } + case CSwordModuleInfo::Lexicons: + if (module->isLocked()) { + return CResMgr::modules::lexicon::icon_locked; + } + else { + return CResMgr::modules::lexicon::icon_unlocked; + } + case CSwordModuleInfo::Books: + if (module->isLocked()) { + return CResMgr::modules::book::icon_locked; + } + else { + return CResMgr::modules::book::icon_unlocked; + } + case CSwordModuleInfo::Cult: + case CSwordModuleInfo::Images: + case CSwordModuleInfo::DailyDevotional: + case CSwordModuleInfo::Glossary: + case CSwordModuleInfo::UnknownCategory: + default: + return categoryIconFilename(cat); } +} - return m_dataCache.language; +QIcon CSwordModuleInfo::categoryIcon(const CSwordModuleInfo::Category &category) +{ + QString filename = categoryIconFilename(category); + if (filename.isEmpty()) return QIcon(); + return util::directory::getIcon(filename); +} + +const QString &CSwordModuleInfo::categoryIconFilename( + const CSwordModuleInfo::Category &category) +{ + static const QString noFilename; + + switch (category) { + case CSwordModuleInfo::Bibles: + return CResMgr::categories::bibles::icon; + case CSwordModuleInfo::Commentaries: + return CResMgr::categories::commentaries::icon; + case CSwordModuleInfo::Books: + return CResMgr::categories::books::icon; + case CSwordModuleInfo::Cult: + return CResMgr::categories::cults::icon; + case CSwordModuleInfo::Images: + return CResMgr::categories::images::icon; + case CSwordModuleInfo::DailyDevotional: + return CResMgr::categories::dailydevotional::icon; + case CSwordModuleInfo::Lexicons: + return CResMgr::categories::lexicons::icon; + case CSwordModuleInfo::Glossary: + return CResMgr::categories::glossary::icon; + case CSwordModuleInfo::UnknownCategory: + default: + return noFilename; + } } +QString CSwordModuleInfo::categoryName( + const CSwordModuleInfo::Category &category) { + switch (category) { + case CSwordModuleInfo::Bibles: + return tr("Bibles"); + case CSwordModuleInfo::Commentaries: + return tr("Commentaries"); + case CSwordModuleInfo::Books: + return tr("Books"); + case CSwordModuleInfo::Cult: + return tr("Cults/Unorthodox"); + case CSwordModuleInfo::Images: + return tr("Maps and Images"); + case CSwordModuleInfo::DailyDevotional: + return tr("Daily Devotionals"); + case CSwordModuleInfo::Lexicons: + return tr("Lexicons and Dictionaries"); + case CSwordModuleInfo::Glossary: + return tr("Glossaries"); + default: + return tr("Unknown"); + } +} -/*! - \fn CSwordModuleInfo::getSimpleConfigEntry(char* name) -*/ QString CSwordModuleInfo::getSimpleConfigEntry(const QString& name) const { QString ret = isUnicode() ? QString::fromUtf8(m_module->getConfigEntry(name.toUtf8().constData())) @@ -933,3 +1016,4 @@ bool CSwordModuleInfo::setHidden(bool hide) { emit hiddenChanged(hide); return true; } + diff --git a/src/backend/drivers/cswordmoduleinfo.h b/src/backend/drivers/cswordmoduleinfo.h index a767c41..d7397de 100644 --- a/src/backend/drivers/cswordmoduleinfo.h +++ b/src/backend/drivers/cswordmoduleinfo.h @@ -2,7 +2,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2008 by the BibleTime developers. +* Copyright 1999-2011 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ @@ -162,25 +162,28 @@ class CSwordModuleInfo: public QObject { */ QString config( const CSwordModuleInfo::ConfigEntry entry ) const; - CSwordModuleInfo( sword::SWModule* module, CSwordBackend* const = 0 ); - /** Copy constructor to copy the passed parameter. - * @param m The module to be copied - */ - CSwordModuleInfo( const CSwordModuleInfo& m ); - /** Reimplementation to return a valid clone. - */ - virtual CSwordModuleInfo* clone(); - /** Destructor. - */ - virtual ~CSwordModuleInfo(); + CSwordModuleInfo(sword::SWModule *module, + CSwordBackend * const = 0, + ModuleType type = Unknown); + + CSwordModuleInfo(const CSwordModuleInfo ©); + + virtual CSwordModuleInfo *clone() const = 0; + + virtual inline ~CSwordModuleInfo() {} + /** * Returns the module object so all objects can access the original Sword module. */ - sword::SWModule* module() const; + inline sword::SWModule *module() const { + return m_module; + } + /** - * Sets the unlock key of the modules and writes the key into the cofig file. - * @return True if the unlock process was succesful, if the key was wrong, or if the config file was write protected return false. + * Sets the unlock key of the modules and writes the key into the config file. + * @return True if the unlock process was succesful, if the key was +wrong, or if the config file was write protected return false. */ bool unlock( const QString& unlockKey ); /** @@ -200,99 +203,130 @@ class CSwordModuleInfo: public QObject { /** * This function returns true if this module is locked (encrypted + correct cipher key), * otherwise return false. - * \todo Make CSwordModuleInfo::isLocked() const. * @return True if this module is locked, i.e. encrypted but without a key set */ - bool isLocked(); + bool isLocked() const; - bool unlockKeyIsValid(); - /** The module version. - * @return true if this module has a version number and false if it doesn't have one. + /** + This function makes an estimate if a module was properly unlocked. It + returns true if the first entry of the module is not empty and + contains only printable characters (for the first 100 chars or so). If + that is the case, we can safely assume that a) the module was properly + unlocked and b) no buffer overflows will occur, which can happen when + Sword filters process garbage text which was not properly decrypted. */ - inline bool hasVersion() const; + bool unlockKeyIsValid() const; /** - * Returns true if the module's index has been built. + \retval true if this module has a version number + \retval false if it doesn't have a version number */ - virtual bool hasIndex(); + inline bool hasVersion() const { + return m_cachedHasVersion; + } + /** - * Returns the path to this module's index base dir + \returns true if the module's index has been built. */ - virtual QString getModuleBaseIndexLocation() const; + bool hasIndex() const; + /** - * Returns the path to this module's standard index + \returns the path to this module's index base dir */ - virtual QString getModuleStandardIndexLocation() const; - /** - * Builds a search index for this module - */ - virtual void buildIndex(); + QString getModuleBaseIndexLocation() const; + /** - * Returns index size + \returns the path to this module's standard index */ - virtual unsigned long indexSize() const; + QString getModuleStandardIndexLocation() const; + /** - * Returns true if something was found, otherwise return false. - * This function uses CLucene to perform and index based search. It also - * overwrites the variable containing the last search result. + Builds a search index for this module */ - virtual bool searchIndexed(const QString& searchedText, sword::ListKey& scope); + void buildIndex(); + /** - * Returns the last search result for this module. - * The last result is cleared by @ref search + \returns index size */ - virtual sword::ListKey& searchResult( const sword::ListKey* newResult = 0 ); + unsigned long indexSize() const; + /** - * Clears the last search result. - * This does immediately clean the last search result, - * no matter if search is in progress or not. + This function uses CLucene to perform and index based search. It also + overwrites the variable containing the last search result. + \returns the number of results found */ - void clearSearchResult(); + int searchIndexed(const QString &searchedText, + const sword::ListKey &scope, + sword::ListKey &results) const; + /** - * Returns the type of the module. + \returns the type of the module. */ - virtual CSwordModuleInfo::ModuleType type() const; + inline ModuleType type() const { + return m_type; + } + /** * Returns the required Sword version for this module. * Returns -1 if no special Sword version is required. */ - sword::SWVersion minimumSwordVersion(); + sword::SWVersion minimumSwordVersion() const; + /** - * Returns the name of the module. - * @return The name of this module. + \note The Sword library takes care of the duplicate names: _n is added + after each duplicate. + \returns The name of this module. */ - QString name() const; + inline const QString &name() const { + return m_cachedName; + } + /** * Snaps to the closest entry in the module if the current key is * not present in the data files. */ - virtual bool snap() { + virtual inline bool snap() const { return false; } - bool has( const CSwordModuleInfo::Feature ) const; - bool has( const CSwordModuleInfo::FilterTypes ) const; /** - * Returns the text direction of the module's text., + \returns whether the module supports the feature given as parameter. + */ + bool has(const CSwordModuleInfo::Feature) const; + + bool has(const CSwordModuleInfo::FilterTypes ) const; + + /** + \returns the text direction of the module's text. */ - virtual CSwordModuleInfo::TextDirection textDirection(); + CSwordModuleInfo::TextDirection textDirection() const; + /** - * Writes the new text at the given position into the module. This does only work for writabe modules. + Writes the new text at the given position into the module. This does + only work for writabe modules. */ - virtual void write( CSwordKey* key, const QString& newText ); + void write(CSwordKey *key, const QString &newText); + /** - * Deletes the current entry and removes it from the module. + Deletes the current entry and removes it from the module. */ - bool deleteEntry( CSwordKey* const key ); + bool deleteEntry(CSwordKey * const key); + /** - * Returns the language of the module. + \returns the language of the module. */ - const CLanguageMgr::Language* language() const; + inline const CLanguageMgr::Language *language() const { + return m_cachedLanguage; + } + /** - * Returns true if this module may be written by the write display windows. + \returns whether this module may be written to. */ - inline virtual bool isWritable() const; + inline virtual bool isWritable() const { + return false; + } + /** * Returns true if this module is hidden (not to be shown with other modules in certain views). */ @@ -308,9 +342,12 @@ class CSwordModuleInfo: public QObject { bool setHidden(bool hide); /** - * Returns the category of this module. See CSwordModuleInfo::Category for possible values. + \returns the category of this module. */ - CSwordModuleInfo::Category category() const; + inline CSwordModuleInfo::Category category() const { + return m_cachedCategory; + } + /** * The about text which belongs to this module. */ @@ -320,9 +357,39 @@ class CSwordModuleInfo: public QObject { * Protected because it should not be used outside of the CSword*ModuleInfo classes. */ inline bool isUnicode() const { - return m_dataCache.isUnicode; + return m_module->isUnicode(); } + /** + Returns an icon for the given module. + \param[in] module The module whose icon to return. + */ + static QIcon moduleIcon(const CSwordModuleInfo *module); + + /** + Returns the icon filename for the given module. + \param[in] module The module whose icon filename to return. + */ + static const QString &moduleIconFilename(const CSwordModuleInfo *module); + + /** + Returns an icon for the category of given module. + \param[in] module The module whose category icon to return. + */ + static QIcon categoryIcon(const CSwordModuleInfo::Category &category); + + /** + Returns the icon filename for the category of given module. + \param[in] module The module whose category icon filename to return. + */ + static const QString &categoryIconFilename(const CSwordModuleInfo::Category &category); + + /** + Returns a translated name for the given category. + \param[in] module The category whose translated name to return. + */ + static QString categoryName(const CSwordModuleInfo::Category &category); + public slots: inline void cancelIndexing() { m_cancelIndexing = true; @@ -344,66 +411,42 @@ class CSwordModuleInfo: public QObject { QString getSimpleConfigEntry(const QString& name) const; QString getFormattedConfigEntry(const QString& name) const; + private: /* Methods: */ + /** + Initializes CSwordModuleInfo::m_cachedCategory. + \pre m_module must be set + */ + void initCachedCategory(); + + /** + Initializes CSwordModuleInfo::m_cachedLanguage. + \pre CSwordModuleInfo::m_module must be set + \pre CSwordModuleInfo::m_cachedLanguage must be set + */ + void initCachedLanguage(); + signals: - void hasIndexChanged(bool); - void hiddenChanged(bool); + void hasIndexChanged(bool hasIndex); + void hiddenChanged(bool hidden); + void unlockedChanged(bool unlocked); void indexingFinished(); void indexingProgress(int); private: - sword::SWModule* m_module; - sword::ListKey m_searchResult; - - mutable struct DataCache { - DataCache() { - language = 0; - } - - QString name; - bool isUnicode; - CSwordModuleInfo::Category category; - const CLanguageMgr::Language* language; - bool hasVersion; - } - - m_dataCache; - - CSwordBackend* m_backend; - + sword::SWModule * const m_module; + CSwordBackend *m_backend; + ModuleType m_type; bool m_hidden; - bool m_cancelIndexing; + + // Cached data: + const QString m_cachedName; + CSwordModuleInfo::Category m_cachedCategory; + const CLanguageMgr::Language *m_cachedLanguage; + bool m_cachedHasVersion; }; Q_DECLARE_METATYPE(CSwordModuleInfo::Category); Q_DECLARE_OPERATORS_FOR_FLAGS(CSwordModuleInfo::Categories) -inline CSwordModuleInfo::ModuleType CSwordModuleInfo::type() const { - return CSwordModuleInfo::Unknown; -} - -inline sword::SWModule* CSwordModuleInfo::module() const { - return m_module; -} - -inline bool CSwordModuleInfo::hasVersion() const { - return m_dataCache.hasVersion; -} - - -/** -* Returns the name of the module. -* The Sword library takes care of the duplicate names: _n is added after each duplicate. -*/ -inline QString CSwordModuleInfo::name() const { - return m_dataCache.name; -} - -/** Returns true if this module may be written by the write display windows. */ -inline bool CSwordModuleInfo::isWritable() const { - return false; -} - -//#include "util/cpointers.h" - #endif |