summaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/bookshelfmodel/btbookshelffiltermodel.cpp23
-rw-r--r--src/backend/bookshelfmodel/btbookshelffiltermodel.h2
-rw-r--r--src/backend/bookshelfmodel/btbookshelfmodel.cpp125
-rw-r--r--src/backend/bookshelfmodel/btbookshelfmodel.h110
-rw-r--r--src/backend/bookshelfmodel/btbookshelftreemodel.cpp79
-rw-r--r--src/backend/bookshelfmodel/btbookshelftreemodel.h64
-rw-r--r--src/backend/bookshelfmodel/categoryitem.cpp6
-rw-r--r--src/backend/bookshelfmodel/categoryitem.h2
-rw-r--r--src/backend/bookshelfmodel/indexingitem.cpp2
-rw-r--r--src/backend/bookshelfmodel/indexingitem.h2
-rw-r--r--src/backend/bookshelfmodel/item.cpp2
-rw-r--r--src/backend/bookshelfmodel/item.h2
-rw-r--r--src/backend/bookshelfmodel/languageitem.cpp4
-rw-r--r--src/backend/bookshelfmodel/languageitem.h2
-rw-r--r--src/backend/bookshelfmodel/moduleitem.cpp2
-rw-r--r--src/backend/bookshelfmodel/moduleitem.h8
-rw-r--r--src/backend/btinstallbackend.cpp301
-rw-r--r--src/backend/btinstallbackend.h71
-rw-r--r--src/backend/btmoduletreeitem.cpp7
-rw-r--r--src/backend/btmoduletreeitem.h42
-rw-r--r--src/backend/config/cbtconfig.cpp50
-rw-r--r--src/backend/config/cbtconfig.h19
-rw-r--r--src/backend/cswordmodulesearch.cpp101
-rw-r--r--src/backend/cswordmodulesearch.h99
-rw-r--r--src/backend/drivers/cswordbiblemoduleinfo.cpp190
-rw-r--r--src/backend/drivers/cswordbiblemoduleinfo.h140
-rw-r--r--src/backend/drivers/cswordbookmoduleinfo.cpp37
-rw-r--r--src/backend/drivers/cswordbookmoduleinfo.h64
-rw-r--r--src/backend/drivers/cswordcommentarymoduleinfo.cpp27
-rw-r--r--src/backend/drivers/cswordcommentarymoduleinfo.h46
-rw-r--r--src/backend/drivers/cswordlexiconmoduleinfo.cpp92
-rw-r--r--src/backend/drivers/cswordlexiconmoduleinfo.h73
-rw-r--r--src/backend/drivers/cswordmoduleinfo.cpp422
-rw-r--r--src/backend/drivers/cswordmoduleinfo.h275
-rw-r--r--src/backend/filters/bt_gbfhtml.h50
-rw-r--r--src/backend/filters/bt_osishtml.h70
-rw-r--r--src/backend/filters/bt_plainhtml.h34
-rw-r--r--src/backend/filters/bt_teihtml.h34
-rw-r--r--src/backend/filters/bt_thmlhtml.h54
-rw-r--r--src/backend/filters/bt_thmlplain.h30
-rw-r--r--src/backend/filters/gbftohtml.cpp (renamed from src/backend/filters/bt_gbfhtml.cpp)19
-rw-r--r--src/backend/filters/gbftohtml.h61
-rw-r--r--src/backend/filters/osismorphsegmentation.cpp4
-rw-r--r--src/backend/filters/osismorphsegmentation.h2
-rw-r--r--src/backend/filters/osistohtml.cpp (renamed from src/backend/filters/bt_osishtml.cpp)56
-rw-r--r--src/backend/filters/osistohtml.h75
-rw-r--r--src/backend/filters/plaintohtml.cpp (renamed from src/backend/filters/bt_plainhtml.cpp)8
-rw-r--r--src/backend/filters/plaintohtml.h40
-rw-r--r--src/backend/filters/teitohtml.cpp (renamed from src/backend/filters/bt_teihtml.cpp)25
-rw-r--r--src/backend/filters/teitohtml.h37
-rw-r--r--src/backend/filters/thmltohtml.cpp (renamed from src/backend/filters/bt_thmlhtml.cpp)25
-rw-r--r--src/backend/filters/thmltohtml.h62
-rw-r--r--src/backend/filters/thmltoplain.cpp (renamed from src/backend/filters/bt_thmlplain.cpp)24
-rw-r--r--src/backend/filters/thmltoplain.h33
-rw-r--r--src/backend/keys/cswordkey.cpp74
-rw-r--r--src/backend/keys/cswordkey.h91
-rw-r--r--src/backend/keys/cswordldkey.cpp40
-rw-r--r--src/backend/keys/cswordldkey.h36
-rw-r--r--src/backend/keys/cswordtreekey.cpp41
-rw-r--r--src/backend/keys/cswordtreekey.h35
-rw-r--r--src/backend/keys/cswordversekey.cpp112
-rw-r--r--src/backend/keys/cswordversekey.h55
-rw-r--r--src/backend/managers/btstringmgr.cpp2
-rw-r--r--src/backend/managers/btstringmgr.h2
-rw-r--r--src/backend/managers/cdisplaytemplatemgr.cpp69
-rw-r--r--src/backend/managers/cdisplaytemplatemgr.h119
-rw-r--r--src/backend/managers/clanguagemgr.cpp28
-rw-r--r--src/backend/managers/clanguagemgr.h57
-rw-r--r--src/backend/managers/cswordbackend.cpp197
-rw-r--r--src/backend/managers/cswordbackend.h173
-rw-r--r--src/backend/managers/referencemanager.cpp46
-rw-r--r--src/backend/managers/referencemanager.h17
-rw-r--r--src/backend/rendering/cbookdisplay.cpp32
-rw-r--r--src/backend/rendering/cbookdisplay.h39
-rw-r--r--src/backend/rendering/cchapterdisplay.cpp21
-rw-r--r--src/backend/rendering/cchapterdisplay.h29
-rw-r--r--src/backend/rendering/cdisplayrendering.cpp24
-rw-r--r--src/backend/rendering/cdisplayrendering.h10
-rw-r--r--src/backend/rendering/centrydisplay.cpp16
-rw-r--r--src/backend/rendering/centrydisplay.h27
-rw-r--r--src/backend/rendering/chtmlexportrendering.cpp85
-rw-r--r--src/backend/rendering/chtmlexportrendering.h18
-rw-r--r--src/backend/rendering/cplaintextexportrendering.cpp32
-rw-r--r--src/backend/rendering/cplaintextexportrendering.h10
-rw-r--r--src/backend/rendering/ctextrendering.cpp90
-rw-r--r--src/backend/rendering/ctextrendering.h49
86 files changed, 2719 insertions, 2191 deletions
diff --git a/src/backend/bookshelfmodel/btbookshelffiltermodel.cpp b/src/backend/bookshelfmodel/btbookshelffiltermodel.cpp
index b896556..182d337 100644
--- a/src/backend/bookshelfmodel/btbookshelffiltermodel.cpp
+++ b/src/backend/bookshelfmodel/btbookshelffiltermodel.cpp
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2009 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.
*
@@ -25,7 +25,7 @@ BtBookshelfFilterModel::BtBookshelfFilterModel(QObject *parent)
m_categoryFilterRole(BtBookshelfModel::ModuleCategoryRole),
m_categoryFilterColumn(0)
{
- // Intentionally empty
+ setDynamicSortFilter(true);
}
BtBookshelfFilterModel::~BtBookshelfFilterModel() {
@@ -125,16 +125,13 @@ bool BtBookshelfFilterModel::filterAcceptsRow(int row,
return true;
}
-bool BtBookshelfFilterModel::nameFilterAcceptsRow(int row, const QModelIndex &p)
- const
-{
- if (!m_enabled) return true;
+bool BtBookshelfFilterModel::nameFilterAcceptsRow(int row, const QModelIndex &parent) const {
if (m_nameFilter.isEmpty()) return true;
const QAbstractItemModel *m(sourceModel());
Q_ASSERT(m != 0);
- QModelIndex itemIndex(m->index(row, m_nameFilterColumn, p));
+ QModelIndex itemIndex(m->index(row, m_nameFilterColumn, parent));
int numChildren(m->rowCount(itemIndex));
if (numChildren == 0) {
QVariant data(m->data(itemIndex, m_nameFilterRole));
@@ -148,14 +145,14 @@ bool BtBookshelfFilterModel::nameFilterAcceptsRow(int row, const QModelIndex &p)
}
}
-bool BtBookshelfFilterModel::hiddenFilterAcceptsRow(int row,
- const QModelIndex &parent) const
+bool BtBookshelfFilterModel::hiddenFilterAcceptsRow(int row, const QModelIndex &parent) const
{
if (m_showHidden && m_showShown) return true;
typedef Qt::CheckState CS;
QAbstractItemModel *m(sourceModel());
+ Q_ASSERT(m != 0);
QModelIndex itemIndex(m->index(row, m_hiddenFilterColumn, parent));
int numChildren(m->rowCount(itemIndex));
@@ -181,17 +178,13 @@ bool BtBookshelfFilterModel::categoryFilterAcceptsRow(int row,
if (m_categoryFilter == CSwordModuleInfo::AllCategories) return true;
QAbstractItemModel *m(sourceModel());
+ Q_ASSERT(m != 0);
QModelIndex itemIndex(m->index(row, m_categoryFilterColumn, parent));
int numChildren(m->rowCount(itemIndex));
if (numChildren == 0) {
int cat = m->data(itemIndex, m_categoryFilterRole).toInt();
- if (m_categoryFilter.testFlag((CSwordModuleInfo::Category) cat)) {
- return true;
- }
- else {
- return false;
- }
+ return m_categoryFilter.testFlag((CSwordModuleInfo::Category) cat);
}
else {
for (int i(0); i < numChildren; i++) {
diff --git a/src/backend/bookshelfmodel/btbookshelffiltermodel.h b/src/backend/bookshelfmodel/btbookshelffiltermodel.h
index e440c69..55322ed 100644
--- a/src/backend/bookshelfmodel/btbookshelffiltermodel.h
+++ b/src/backend/bookshelfmodel/btbookshelffiltermodel.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2009 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.
*
diff --git a/src/backend/bookshelfmodel/btbookshelfmodel.cpp b/src/backend/bookshelfmodel/btbookshelfmodel.cpp
index ccbb5a5..c6aab1b 100644
--- a/src/backend/bookshelfmodel/btbookshelfmodel.cpp
+++ b/src/backend/bookshelfmodel/btbookshelfmodel.cpp
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2009 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.
*
@@ -12,9 +12,9 @@
#include "backend/bookshelfmodel/btbookshelfmodel.h"
+#include <QIcon>
#include <QSet>
-#include "util/cresmgr.h"
-#include "util/directory.h"
+#include "util/macros.h"
BtBookshelfModel::BtBookshelfModel(QObject *parent)
@@ -37,7 +37,7 @@ QVariant BtBookshelfModel::data(CSwordModuleInfo *module, int role) const {
case ModuleNameRole: // Qt::DisplayRole
return module->name();
case ModuleIconRole: // Qt::DecorationRole
- return moduleIcon(module);
+ return CSwordModuleInfo::moduleIcon(module);
case ModulePointerRole:
return qVariantFromValue((void*) module);
case ModuleCategoryRole:
@@ -52,6 +52,8 @@ QVariant BtBookshelfModel::data(CSwordModuleInfo *module, int role) const {
return module->hasIndex();
case ModuleIndexSizeRole:
return (qulonglong) module->indexSize();
+ case ModuleDescriptionRole:
+ return module->config(CSwordModuleInfo::Description);
default:
return QVariant();
}
@@ -93,107 +95,6 @@ bool BtBookshelfModel::setData(const QModelIndex &index, const QVariant &value,
return false;
}
-QIcon BtBookshelfModel::moduleIcon(const CSwordModuleInfo *m) {
- namespace DU = util::directory;
-
- /// \todo Make CSwordModuleInfo::isLocked() const and remove const_cast:
- CSwordModuleInfo *module(const_cast<CSwordModuleInfo*>(m));
-
- CSwordModuleInfo::Category cat(module->category());
- switch (cat) {
- case CSwordModuleInfo::Bibles:
- if (module->isLocked()) {
- return DU::getIcon(CResMgr::modules::bible::icon_locked);
- }
- else {
- return DU::getIcon(CResMgr::modules::bible::icon_unlocked);
- }
- case CSwordModuleInfo::Commentaries:
- if (module->isLocked()) {
- return DU::getIcon(CResMgr::modules::commentary::icon_locked);
- }
- else {
- return DU::getIcon(CResMgr::modules::commentary::icon_unlocked);
- }
- case CSwordModuleInfo::Lexicons:
- if (module->isLocked()) {
- return DU::getIcon(CResMgr::modules::lexicon::icon_locked);
- }
- else {
- return DU::getIcon(CResMgr::modules::lexicon::icon_unlocked);
- }
- case CSwordModuleInfo::Books:
- if (module->isLocked()) {
- return DU::getIcon(CResMgr::modules::book::icon_locked);
- }
- else {
- return DU::getIcon(CResMgr::modules::book::icon_unlocked);
- }
- case CSwordModuleInfo::Cult:
- case CSwordModuleInfo::Images:
- case CSwordModuleInfo::DailyDevotional:
- case CSwordModuleInfo::Glossary:
- case CSwordModuleInfo::UnknownCategory:
- default:
- return categoryIcon(cat);
- }
-}
-
-QIcon BtBookshelfModel::categoryIcon(const CSwordModuleInfo::Category &category) {
- namespace DU = util::directory;
-
- switch (category) {
- case CSwordModuleInfo::Bibles:
- return DU::getIcon(CResMgr::categories::bibles::icon);
- case CSwordModuleInfo::Commentaries:
- return DU::getIcon(CResMgr::categories::commentaries::icon);
- case CSwordModuleInfo::Books:
- return DU::getIcon(CResMgr::categories::books::icon);
- case CSwordModuleInfo::Cult:
- return DU::getIcon(CResMgr::categories::cults::icon);
- case CSwordModuleInfo::Images:
- return DU::getIcon(CResMgr::categories::images::icon);
- case CSwordModuleInfo::DailyDevotional:
- return DU::getIcon(CResMgr::categories::dailydevotional::icon);
- case CSwordModuleInfo::Lexicons:
- return DU::getIcon(CResMgr::categories::lexicons::icon);
- case CSwordModuleInfo::Glossary:
- return DU::getIcon(CResMgr::categories::glossary::icon);
- case CSwordModuleInfo::UnknownCategory:
- default:
- return QIcon();
- }
-}
-
-QString BtBookshelfModel::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");
- }
-}
-
-QString BtBookshelfModel::languageName(
- const CLanguageMgr::Language *language) {
- return language->translatedName();
-}
-
void BtBookshelfModel::clear(bool destroy) {
if (m_data.size() <= 0) return;
@@ -217,6 +118,8 @@ void BtBookshelfModel::addModule(CSwordModuleInfo * const module) {
this, SLOT(moduleHidden(bool)));
connect(module, SIGNAL(hasIndexChanged(bool)),
this, SLOT(moduleIndexed(bool)));
+ connect(module, SIGNAL(unlockedChanged(bool)),
+ this, SLOT(moduleUnlocked(bool)));
endInsertRows();
}
@@ -242,6 +145,8 @@ void BtBookshelfModel::addModules(const QSet<CSwordModuleInfo *> &modules) {
this, SLOT(moduleHidden(bool)));
connect(module, SIGNAL(hasIndexChanged(bool)),
this, SLOT(moduleIndexed(bool)));
+ connect(module, SIGNAL(unlockedChanged(bool)),
+ this, SLOT(moduleUnlocked(bool)));
}
endInsertRows();
}
@@ -256,6 +161,8 @@ void BtBookshelfModel::removeModule(CSwordModuleInfo * const module,
this, SLOT(moduleHidden(bool)));
disconnect(module, SIGNAL(hasIndexChanged(bool)),
this, SLOT(moduleIndexed(bool)));
+ disconnect(module, SIGNAL(unlockedChanged(bool)),
+ this, SLOT(moduleUnlocked(bool)));
m_data.removeAt(index);
endRemoveRows();
if (destroy) delete module;
@@ -276,7 +183,7 @@ void BtBookshelfModel::removeModules(const QSet<CSwordModuleInfo *> &modules,
CSwordModuleInfo* BtBookshelfModel::getModule(const QString &name) const {
Q_FOREACH(CSwordModuleInfo *module, m_data) {
- if (module->name() == name) return module;
+ if (UNLIKELY(module->name() == name)) return module;
}
return 0;
}
@@ -293,6 +200,12 @@ void BtBookshelfModel::moduleIndexed(bool) {
moduleDataChanged(static_cast<CSwordModuleInfo*>(sender()));
}
+void BtBookshelfModel::moduleUnlocked(bool) {
+ Q_ASSERT(qobject_cast<CSwordModuleInfo*>(sender()) != 0);
+
+ moduleDataChanged(static_cast<CSwordModuleInfo*>(sender()));
+}
+
void BtBookshelfModel::moduleDataChanged(CSwordModuleInfo *module) {
Q_ASSERT(m_data.count(module) == 1);
diff --git a/src/backend/bookshelfmodel/btbookshelfmodel.h b/src/backend/bookshelfmodel/btbookshelfmodel.h
index 735c655..20f2b3d 100644
--- a/src/backend/bookshelfmodel/btbookshelfmodel.h
+++ b/src/backend/bookshelfmodel/btbookshelfmodel.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2009 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.
*
@@ -18,6 +18,12 @@
#include "backend/drivers/cswordmoduleinfo.h"
+/**
+ Implements a simple list model projecting CSwordModuleInfo instances. This model is mostly
+ implemented to provide an interface the the underlying data and to provide notifications
+ when modules are added, removed or changed. If you want to use a model for widgets, the
+ BtBookshelfTreeModel might be a better choice, since it also provides sorting and grouping.
+*/
class BtBookshelfModel: public QAbstractListModel {
Q_OBJECT
public:
@@ -31,55 +37,135 @@ class BtBookshelfModel: public QAbstractListModel {
ModuleInstallPathRole = Qt::UserRole + 4,
ModuleHasIndexRole = Qt::UserRole + 5,
ModuleIndexSizeRole = Qt::UserRole + 6,
+ ModuleDescriptionRole = Qt::UserRole + 7,
UserRole = Qt::UserRole + 100
};
+ public:
BtBookshelfModel(QObject *parent = 0);
- virtual ~BtBookshelfModel();
+ ~BtBookshelfModel();
- virtual int rowCount(const QModelIndex &parent) const;
- virtual QVariant data(CSwordModuleInfo *module, int role) const;
- virtual QVariant data(const QModelIndex &index, int role) const;
- virtual QVariant headerData(int section, Qt::Orientation orientation,
+ // Virtual methods implemented from QAbstractListModel:
+ int rowCount(const QModelIndex &parent = QModelIndex()) const;
+ QVariant data(CSwordModuleInfo *module, int role) const;
+ QVariant data(const QModelIndex &index, int role) const;
+ QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const;
bool setData(const QModelIndex &index, const QVariant &value,
int role = ModuleHiddenRole);
+ /**
+ Given an index of this model, this method returns a pointer to the underlying
+ CSwordModuleInfo instance corresponding to the given index.
+ \param[in] index An index to this model.
+ */
inline CSwordModuleInfo *module(const QModelIndex &index) const {
return (CSwordModuleInfo *)
data(index, BtBookshelfModel::ModulePointerRole)
.value<void *>();
}
- static QIcon moduleIcon(const CSwordModuleInfo *module);
- static QIcon categoryIcon(const CSwordModuleInfo::Category &category);
- static QString categoryName(const CSwordModuleInfo::Category &category);
- static QString languageName(const CLanguageMgr::Language *language);
-
+ /**
+ Clears the data of the whole model by removing all items.
+ \param[in] destroy If true, all CSwordModuleInfo instances in this model are also
+ destroyed.
+ */
void clear(bool destroy = false);
+
+ /**
+ Appends the given module to this model.
+ \param[in] module Module to add.
+ */
void addModule(CSwordModuleInfo * const module);
+
+ /**
+ Appends the all the modules in the given set to this model.
+ \param[in] modules Set of modules to add.
+ */
void addModules(const QSet<CSwordModuleInfo *> &modules);
+
+ /**
+ Appends the all the modules in the given list to this model.
+ \param[in] modules Set of modules to add.
+ */
void addModules(const QList<CSwordModuleInfo *> &modules);
+
+ /**
+ Removes the given module from this model and optionally destroys it.
+ \param[in] module The module to remove from this model.
+ \param[in] destroy If true, the given CSwordModuleInfo instance is destroyed.
+ */
void removeModule(CSwordModuleInfo * const module,
bool destroy = false);
+
+ /**
+ Removes all modules from the given set from this model and optionally destroys
+ them.
+ \param[in] modules The set of modules to remove from this model.
+ \param[in] destroy If true, the given CSwordModuleInfo instances are destroyed.
+ */
void removeModules(const QSet<CSwordModuleInfo *> &modules,
bool destroy = false);
+
+ /**
+ Removes all modules from the given list from this model and optionally destroys
+ them.
+ \param[in] modules The list of modules to remove from this model.
+ \param[in] destroy If true, the given CSwordModuleInfo instances are destroyed.
+ */
void removeModules(const QList<CSwordModuleInfo *> &modules,
bool destroy = false);
+ /**
+ Returns the first module found with the given name.
+ \param[in] name Name of the module to find.
+ */
CSwordModuleInfo* getModule(const QString &name) const;
- inline const QList<CSwordModuleInfo *> &modules() const {
+
+ /**
+ Returns the list of handled modules as a list of CSwordModuleInfo* pointers.
+ */
+ inline const QList<CSwordModuleInfo *> &moduleList() const {
return m_data;
}
protected slots:
+ /**
+ Slot DIRECTLY called by CSwordModuleInfo when the hidden status of the respective
+ module changes.
+ \param[in] hidden True, if the module was hidden; false, if the module was shown.
+ */
void moduleHidden(bool hidden);
+
+ /**
+ Slot DIRECTLY called by CSwordModuleInfo when the indexed status of the respective
+ module changes.
+ \param[in] indexed True, if the module was indexed; false if the index was deleted.
+ */
void moduleIndexed(bool indexed);
+ /**
+ Slot DIRECTLY called by CSwordModuleInfo when the locked status of the respective
+ module changes.
+ \param[in] unlocked True, if the module was unlocked; false if the module was
+ locked.
+ */
+ void moduleUnlocked(bool unlocked);
+
protected:
+ /**
+ Called internally when module data changes. This method emits any neccessary
+ signals for this model.
+ \pre The givem module is handled by this model.
+ \param[in] module The module that changed status.
+ */
void moduleDataChanged(CSwordModuleInfo *module);
protected:
+ /**
+ The underlying data as a list of pointers to the respective CSwordModuleInfo
+ instances.
+ */
QList<CSwordModuleInfo *> m_data;
};
diff --git a/src/backend/bookshelfmodel/btbookshelftreemodel.cpp b/src/backend/bookshelfmodel/btbookshelftreemodel.cpp
index a2a988c..6444a81 100644
--- a/src/backend/bookshelfmodel/btbookshelftreemodel.cpp
+++ b/src/backend/bookshelfmodel/btbookshelftreemodel.cpp
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2009 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,24 +13,50 @@
#include "backend/bookshelfmodel/btbookshelftreemodel.h"
#include <QSet>
+#include <QSettings>
#include "backend/bookshelfmodel/categoryitem.h"
#include "backend/bookshelfmodel/indexingitem.h"
#include "backend/bookshelfmodel/languageitem.h"
#include "backend/bookshelfmodel/moduleitem.h"
+#include "backend/config/cbtconfig.h"
+#include "util/macros.h"
using namespace BookshelfModel;
+bool BtBookshelfTreeModel::Grouping::loadFrom(const QString &configKey) {
+ Q_ASSERT(!configKey.isNull());
+ QVariant v = CBTConfig::getConfig()->value(configKey);
+ (*this) = v.value<Grouping>();
+ return v.canConvert<Grouping>();
+}
+
+void BtBookshelfTreeModel::Grouping::saveTo(const QString &configKey) const {
+ Q_ASSERT(!configKey.isNull());
+ CBTConfig::getConfig()->setValue(configKey, QVariant::fromValue(*this));
+}
+
+
BtBookshelfTreeModel::BtBookshelfTreeModel(QObject *parent)
- : QAbstractItemModel(parent), m_sourceModel(0), m_rootItem(new RootItem),
- m_defaultChecked(MODULE_HIDDEN), m_checkable(false) {
- m_groupingOrder.push_back(GROUP_CATEGORY);
- m_groupingOrder.push_back(GROUP_LANGUAGE);
+ : QAbstractItemModel(parent), m_sourceModel(0), m_rootItem(new RootItem),
+ m_defaultChecked(MODULE_HIDDEN), m_checkable(false)
+{
+ // Intentionally empty
+}
+
+BtBookshelfTreeModel::BtBookshelfTreeModel(const QString &configKey,
+ QObject *parent)
+ : QAbstractItemModel(parent), m_sourceModel(0), m_rootItem(new RootItem),
+ m_groupingOrder(configKey), m_defaultChecked(MODULE_HIDDEN),
+ m_checkable(false)
+{
+ // Intentionally empty
}
BtBookshelfTreeModel::BtBookshelfTreeModel(const Grouping &g, QObject *parent)
: QAbstractItemModel(parent), m_sourceModel(0), m_rootItem(new RootItem),
- m_groupingOrder(g), m_defaultChecked(MODULE_HIDDEN), m_checkable(false) {
+ m_groupingOrder(g), m_defaultChecked(MODULE_HIDDEN), m_checkable(false)
+{
// Intentionally empty
}
@@ -123,13 +149,14 @@ QVariant BtBookshelfTreeModel::data(CSwordModuleInfo *module, int role) const {
bool BtBookshelfTreeModel::setData(const QModelIndex &itemIndex,
const QVariant &value,
int role) {
+ Q_ASSERT(itemIndex.isValid());
typedef QPair<Item *, QModelIndex> IP;
Qt::CheckState newState;
- if (role == Qt::CheckStateRole) {
+ if (LIKELY(role == Qt::CheckStateRole)) {
bool ok;
newState = (Qt::CheckState) value.toInt(&ok);
- if (!ok) return false;
+ if (UNLIKELY(!ok)) return false;
}
else {
return false;
@@ -262,7 +289,9 @@ void BtBookshelfTreeModel::setSourceModel(QAbstractItemModel *sourceModel) {
}
}
-void BtBookshelfTreeModel::setGroupingOrder(const Grouping &groupingOrder) {
+void BtBookshelfTreeModel::setGroupingOrder(const Grouping &groupingOrder,
+ bool emitSignal)
+{
if (m_groupingOrder == groupingOrder) return;
m_groupingOrder = groupingOrder;
@@ -291,6 +320,8 @@ void BtBookshelfTreeModel::setGroupingOrder(const Grouping &groupingOrder) {
addModule(module, checked.contains(module));
}
}
+
+ if (emitSignal) emit groupingOrderChanged(groupingOrder);
}
void BtBookshelfTreeModel::setCheckable(bool checkable) {
@@ -299,14 +330,29 @@ void BtBookshelfTreeModel::setCheckable(bool checkable) {
if (m_sourceModel == 0) return;
// Notify views that flags changed for all items:
+ resetData();
+}
+
+void BtBookshelfTreeModel::setCheckedModules(const QSet<CSwordModuleInfo*> &modules) {
+ typedef ModuleItemMap::const_iterator MIMCI;
+
+ for (MIMCI it(m_modules.constBegin()); it != m_modules.constEnd(); it++) {
+ if (modules.contains(it.key())) {
+ setData(getIndex(it.value()), Qt::Checked, Qt::CheckStateRole);
+ } else {
+ setData(getIndex(it.value()), Qt::Unchecked, Qt::CheckStateRole);
+ }
+ }
+}
+
+void BtBookshelfTreeModel::resetData() {
QModelIndexList queue;
queue.append(QModelIndex());
do {
QModelIndex parent(queue.takeFirst());
- int numChildren(rowCount(parent));
emit dataChanged(index(0, 0, parent),
- index(numChildren - 1, 0, parent));
- for (int i(0); i < numChildren; i++) {
+ index(rowCount(parent) - 1, columnCount() - 1, parent));
+ for (int i(0); i < rowCount(parent); i++) {
QModelIndex childIndex(index(i, 0, parent));
if (rowCount(childIndex) > 0) {
queue.append(childIndex);
@@ -402,7 +448,7 @@ void BtBookshelfTreeModel::removeModule(CSwordModuleInfo *module) {
}
Item *BtBookshelfTreeModel::getItem(const QModelIndex &index) const {
- if (index.isValid()) {
+ if (LIKELY(index.isValid())) {
Item *item(static_cast<Item*>(index.internalPointer()));
Q_ASSERT(item != 0);
return item;
@@ -504,8 +550,7 @@ void BtBookshelfTreeModel::moduleDataChanged(const QModelIndex &topLeft,
}
}
-void BtBookshelfTreeModel::moduleInserted(const QModelIndex &parent, int start,
- int end) {
+void BtBookshelfTreeModel::moduleInserted(const QModelIndex &parent, int start, int end) {
typedef BtBookshelfModel BM;
static const BM::ModuleRole PR(BM::ModulePointerRole);
static const BM::ModuleRole HR(BM::ModuleHiddenRole);
@@ -531,8 +576,7 @@ void BtBookshelfTreeModel::moduleInserted(const QModelIndex &parent, int start,
}
}
-void BtBookshelfTreeModel::moduleRemoved(const QModelIndex &parent, int start,
- int end) {
+void BtBookshelfTreeModel::moduleRemoved(const QModelIndex &parent, int start, int end) {
typedef BtBookshelfModel BM;
static const BM::ModuleRole PR(BM::ModulePointerRole);
@@ -557,6 +601,7 @@ QDataStream &operator<<(QDataStream &os, const BtBookshelfTreeModel::Grouping &o
QDataStream &operator>>(QDataStream &is, BtBookshelfTreeModel::Grouping &o) {
int s;
is >> s;
+ o.clear();
for (int i(0); i < s; i++) {
int g;
is >> g;
diff --git a/src/backend/bookshelfmodel/btbookshelftreemodel.h b/src/backend/bookshelfmodel/btbookshelftreemodel.h
index 47ce672..2a28dd8 100644
--- a/src/backend/bookshelfmodel/btbookshelftreemodel.h
+++ b/src/backend/bookshelfmodel/btbookshelftreemodel.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2009 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.
*
@@ -36,7 +36,7 @@ class BtBookshelfTreeModel: public QAbstractItemModel {
typedef QMap<CSwordModuleInfo*, BookshelfModel::ModuleItem*> ModuleItemMap;
typedef QMap<CSwordModuleInfo*, QPersistentModelIndex> SourceIndexMap;
- public:
+ public: /* Types: */
enum ModuleRole {
CheckStateRole = BtBookshelfModel::UserRole,
UserRole = BtBookshelfModel::UserRole + 100
@@ -52,9 +52,31 @@ class BtBookshelfTreeModel: public QAbstractItemModel {
MODULE_HIDDEN, /**< By default, check only added modules that are not hidden. */
MODULE_INDEXED /**< By default, check only added modules that are indexed. */
};
- typedef QList<Group> Grouping;
+ class Grouping: public QList<Group> {
+ public:
+ /**
+ \warning Be careful using this constructor!
+ */
+ explicit inline Grouping(bool empty = false) {
+ if (empty) return;
+ push_back(GROUP_CATEGORY);
+ push_back(GROUP_LANGUAGE);
+ }
+ explicit inline Grouping(Group group) { push_back(group); }
+ explicit inline Grouping(const QString &configKey) {
+ loadFrom(configKey);
+ }
+ inline Grouping(const Grouping &copy)
+ : QList<Group>(copy) {}
+
+ bool loadFrom(const QString &configKey);
+ void saveTo(const QString &configKey) const;
+ };
+
+ public: /* Methods: */
BtBookshelfTreeModel(QObject *parent = 0);
+ BtBookshelfTreeModel(const QString &configKey, QObject *parent = 0);
BtBookshelfTreeModel(const Grouping &grouping, QObject *parent = 0);
virtual ~BtBookshelfTreeModel();
@@ -75,30 +97,31 @@ class BtBookshelfTreeModel: public QAbstractItemModel {
virtual bool setData(const QModelIndex &index, const QVariant &value,
int role);
- void setSourceModel(QAbstractItemModel *sourceModel);
- inline QAbstractItemModel *sourceModel() const {
- return m_sourceModel;
- }
- void setGroupingOrder(const Grouping &groupingOrder);
- inline Grouping groupingOrder() const {
- return m_groupingOrder;
+ inline QAbstractItemModel *sourceModel() const { return m_sourceModel; }
+ inline const Grouping &groupingOrder() const { return m_groupingOrder; }
+ inline bool checkable() const { return m_checkable; }
+ inline CheckedBehavior defaultChecked() const { return m_defaultChecked; }
+ inline QList<CSwordModuleInfo*> modules() const { return m_modules.keys(); }
+ inline const QSet<CSwordModuleInfo*> &checkedModules() const {
+ return m_checkedModulesCache;
}
+
+ public slots:
+ void setSourceModel(QAbstractItemModel *sourceModel);
+ void setGroupingOrder(const BtBookshelfTreeModel::Grouping &groupingOrder,
+ bool emitSignal = true);
void setCheckable(bool checkable);
- inline bool checkable() const {
- return m_checkable;
- }
inline void setDefaultChecked(CheckedBehavior b) {
m_defaultChecked = b;
}
- inline CheckedBehavior defaultChecked() const {
- return m_defaultChecked;
- }
+ void setCheckedModules(const QSet<CSwordModuleInfo*> &modules);
- inline const QSet<CSwordModuleInfo*> &checkedModules() const {
- return m_checkedModulesCache;
- }
+ signals:
+ void groupingOrderChanged(BtBookshelfTreeModel::Grouping newGrouping);
+ void moduleChecked(CSwordModuleInfo *module, bool checked);
protected:
+ void resetData();
QVariant parentData(BookshelfModel::ModuleItem *item, int role) const;
void addModule(CSwordModuleInfo *module, bool checked);
void addModule(CSwordModuleInfo *module, QModelIndex parentIndex,
@@ -132,9 +155,6 @@ class BtBookshelfTreeModel: public QAbstractItemModel {
void moduleInserted(const QModelIndex &parent, int start, int end);
void moduleRemoved(const QModelIndex &parent, int start, int end);
- signals:
- void moduleChecked(CSwordModuleInfo *module, bool checked);
-
protected:
QAbstractItemModel *m_sourceModel;
BookshelfModel::Item *m_rootItem;
diff --git a/src/backend/bookshelfmodel/categoryitem.cpp b/src/backend/bookshelfmodel/categoryitem.cpp
index 46905d7..aaf5566 100644
--- a/src/backend/bookshelfmodel/categoryitem.cpp
+++ b/src/backend/bookshelfmodel/categoryitem.cpp
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2009 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.
*
@@ -23,9 +23,9 @@ CategoryItem::CategoryItem(CSwordModuleInfo *module)
QVariant CategoryItem::data(int role) const {
switch (role) {
case Qt::DisplayRole:
- return BtBookshelfModel::categoryName(m_category);
+ return CSwordModuleInfo::categoryName(m_category);
case Qt::DecorationRole:
- return BtBookshelfModel::categoryIcon(m_category);
+ return CSwordModuleInfo::categoryIcon(m_category);
default:
return Item::data(role);
}
diff --git a/src/backend/bookshelfmodel/categoryitem.h b/src/backend/bookshelfmodel/categoryitem.h
index 879895f..75d5a7c 100644
--- a/src/backend/bookshelfmodel/categoryitem.h
+++ b/src/backend/bookshelfmodel/categoryitem.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2009 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.
*
diff --git a/src/backend/bookshelfmodel/indexingitem.cpp b/src/backend/bookshelfmodel/indexingitem.cpp
index 898096f..5491ca5 100644
--- a/src/backend/bookshelfmodel/indexingitem.cpp
+++ b/src/backend/bookshelfmodel/indexingitem.cpp
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2009 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.
*
diff --git a/src/backend/bookshelfmodel/indexingitem.h b/src/backend/bookshelfmodel/indexingitem.h
index f30fb2d..a1eb812 100644
--- a/src/backend/bookshelfmodel/indexingitem.h
+++ b/src/backend/bookshelfmodel/indexingitem.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2009 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.
*
diff --git a/src/backend/bookshelfmodel/item.cpp b/src/backend/bookshelfmodel/item.cpp
index 809021b..02cd991 100644
--- a/src/backend/bookshelfmodel/item.cpp
+++ b/src/backend/bookshelfmodel/item.cpp
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2009 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.
*
diff --git a/src/backend/bookshelfmodel/item.h b/src/backend/bookshelfmodel/item.h
index f10da04..652120b 100644
--- a/src/backend/bookshelfmodel/item.h
+++ b/src/backend/bookshelfmodel/item.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2009 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.
*
diff --git a/src/backend/bookshelfmodel/languageitem.cpp b/src/backend/bookshelfmodel/languageitem.cpp
index 547c953..2fdab8b 100644
--- a/src/backend/bookshelfmodel/languageitem.cpp
+++ b/src/backend/bookshelfmodel/languageitem.cpp
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2009 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.
*
@@ -23,7 +23,7 @@ LanguageItem::LanguageItem(CSwordModuleInfo *module)
QVariant LanguageItem::data(int role) const {
switch (role) {
case Qt::DisplayRole:
- return BtBookshelfModel::languageName(m_language);
+ return m_language->translatedName();
case Qt::DecorationRole:
return util::directory::getIcon("flag.svg");
default:
diff --git a/src/backend/bookshelfmodel/languageitem.h b/src/backend/bookshelfmodel/languageitem.h
index c6e4417..03a9ce3 100644
--- a/src/backend/bookshelfmodel/languageitem.h
+++ b/src/backend/bookshelfmodel/languageitem.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2009 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.
*
diff --git a/src/backend/bookshelfmodel/moduleitem.cpp b/src/backend/bookshelfmodel/moduleitem.cpp
index e7aff92..ca9c3fb 100644
--- a/src/backend/bookshelfmodel/moduleitem.cpp
+++ b/src/backend/bookshelfmodel/moduleitem.cpp
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2009 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.
*
diff --git a/src/backend/bookshelfmodel/moduleitem.h b/src/backend/bookshelfmodel/moduleitem.h
index 006ae97..5e6e1ba 100644
--- a/src/backend/bookshelfmodel/moduleitem.h
+++ b/src/backend/bookshelfmodel/moduleitem.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2009 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.
*
@@ -28,10 +28,10 @@ class ModuleItem: public Item {
ModuleItem(CSwordModuleInfo *module, BtBookshelfTreeModel *parentModel);
/**
- Reimplementation of \ref Item::data which dispatches all requests to
- the \ref BtBookshelfTreeModel parent model.
+ Reimplementation of Item::data() which dispatches all
+ requests to the parent model (BtBookshelfTreeModel).
*/
- QVariant data(int role = Qt::DisplayRole) const;
+ virtual QVariant data(int role = Qt::DisplayRole) const;
inline CSwordModuleInfo *moduleInfo() const {
return m_moduleInfo;
diff --git a/src/backend/btinstallbackend.cpp b/src/backend/btinstallbackend.cpp
new file mode 100644
index 0000000..67f8945
--- /dev/null
+++ b/src/backend/btinstallbackend.cpp
@@ -0,0 +1,301 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2011 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "backend/btinstallbackend.h"
+
+#include <QDebug>
+#include <QDir>
+#include <QFile>
+#include <QFileInfo>
+#include "backend/managers/cswordbackend.h"
+#include "frontend/bookshelfmanager/btinstallmgr.h"
+#include "util/directory.h"
+#include "util/dialogutil.h"
+
+// Sword includes:
+#include <filemgr.h>
+#include <swconfig.h>
+#include <swbuf.h>
+
+
+using namespace sword;
+
+namespace BtInstallBackend {
+
+/** Adds the source described by Source to the backend. */
+bool addSource(sword::InstallSource& source) {
+ qDebug() << "backend::addSource";
+ SWConfig config(configFilename().toLatin1());
+ if (!strcmp(source.type, "FTP")) {
+ //make sure the path doesn't have a trailing slash, sword doesn't like it
+ if (source.directory[ source.directory.length()-1 ] == '/') {
+ source.directory--; //make one char shorter
+ }
+
+ config["Sources"].insert( std::make_pair(SWBuf("FTPSource"), source.getConfEnt()) );
+ }
+ else if (!strcmp(source.type, "DIR")) {
+ config["Sources"].insert( std::make_pair(SWBuf("DIRSource"), source.getConfEnt()) );
+ }
+ config.Save();
+ return true;
+}
+
+/** Returns the Source struct. */
+sword::InstallSource source(const QString &name) {
+ qDebug() << "backend::source";
+ BtInstallMgr mgr;
+ InstallSourceMap::iterator source = mgr.sources.find(name.toLatin1().data());
+ if (source != mgr.sources.end()) {
+ return *(source->second);
+ }
+ else { //not found in Sword, may be a local DIR source
+ SWConfig config(configFilename().toLatin1());
+ SectionMap::iterator sourcesSection = config.Sections.find("Sources");
+ if (sourcesSection != config.Sections.end()) {
+ ConfigEntMap::iterator sourceBegin =
+ sourcesSection->second.lower_bound("DIRSource");
+ ConfigEntMap::iterator sourceEnd =
+ sourcesSection->second.upper_bound("DIRSource");
+
+ while (sourceBegin != sourceEnd) {
+ InstallSource is("DIR", sourceBegin->second.c_str());
+ if (!strcmp(is.caption, name.toLatin1()) ) { //found local dir source
+ return is;
+ }
+
+ sourceBegin++;//next source
+ }
+ }
+ }
+
+ InstallSource is("EMPTY"); //default return value
+ is.caption = "unknown caption";
+ is.source = "unknown source";
+ is.directory = "unknown dir";
+ return is;
+}
+
+/** Deletes the source. */
+bool deleteSource(const QString &name) {
+ qDebug() << "backend::deleteSource";
+ sword::InstallSource is = source(name );
+
+ SWConfig config(configFilename().toLatin1());
+
+ //this code can probably be shortened by using the stl remove_if functionality
+ std::pair< ConfigEntMap::iterator, ConfigEntMap::iterator > range =
+ isRemote(is)
+ ? config["Sources"].equal_range("FTPSource")
+ : config["Sources"].equal_range("DIRSource");
+
+ ConfigEntMap::iterator it = range.first;
+ SWBuf sourceConfigEntry = is.getConfEnt();
+ bool notFound = true;
+ while (it != range.second) {
+ //SWORD lib gave us a "nice" surprise: getConfEnt() adds uid, so old sources added by BT are not recognized here
+ if (it->second == sourceConfigEntry) {
+ config["Sources"].erase(it);
+ notFound = false;
+ break;
+ }
+ ++it;
+ }
+ if (notFound) {
+ qDebug() << "source was not found, try without uid";
+ //try again without uid
+ QString sce(sourceConfigEntry.c_str());
+ QStringList l = sce.split('|');
+ l.removeLast();
+ sce = l.join("|").append("|");
+ it = range.first;
+ while (it != range.second) {
+ qDebug() << it->second;
+ if (it->second == sce) {
+ config["Sources"].erase(it);
+ break;
+ }
+ ++it;
+ }
+ }
+
+ config.Save();
+ return true; /// \todo dummy
+}
+
+/** Returns the moduleinfo list for the source. Delete the pointer after using. IS THIS POSSIBLE?*/
+QList<CSwordModuleInfo*> moduleList(QString /*name*/) {
+ QList<CSwordModuleInfo*> list; /// \todo dummy
+ return list;
+}
+
+bool isRemote(const sword::InstallSource& source) {
+ return !strcmp(source.type, "FTP");
+}
+
+QString configPath() {
+ return util::directory::getUserHomeSwordDir().absolutePath().append("/InstallMgr");
+}
+
+QString configFilename() {
+ return configPath().append("/InstallMgr.conf");
+}
+
+QStringList targetList() {
+ qDebug() << "backend::targetList";
+ QStringList names = CSwordBackend::instance()->swordDirList();
+ return names;
+}
+
+bool setTargetList( const QStringList& targets ) {
+ namespace DU = util::directory;
+
+ qDebug() << "backend::setTargetList";
+ //saves a new Sword config using the provided target list
+ //QString filename = KGlobal::dirs()->saveLocation("data", "bibletime/") + "sword.conf"; //default is to assume the real location isn't writable
+ //QString filename = util::DirectoryUtil::getUserBaseDir().canonicalPath().append("/.sword/sword.conf");
+ //bool directAccess = false;
+ QString filename = swordConfigFilename();
+ QFileInfo i(filename);
+ QFileInfo dirInfo(i.absolutePath());
+
+
+ if ( !i.exists() && dirInfo.isWritable() ) {
+ // if the file doesn't exist but the parent is writable, create it
+ qWarning() << "The Sword config file does not exist, it has to be created";
+ QFile f(filename);
+ f.open(QIODevice::WriteOnly);
+ f.close();
+ i.refresh();
+ }
+ if ( i.exists() && i.isWritable() ) { //we can write to the file ourself
+ qDebug() << "The Sword config file is writable";
+ }
+ else {
+ // There is no way to save to the file
+ qWarning() << "The Sword config file is not writable!";
+ util::showWarning(0, QObject::tr("Can't write file"), QObject::tr("The Sword config file can't be written!"));
+ return false;
+ }
+
+ filename = util::directory::convertDirSeparators(filename);
+ SWConfig conf(filename.toLocal8Bit());
+ conf.Sections.clear();
+
+#ifdef Q_WS_WIN
+ // On Windows, add the sword directory to the config file.
+ QString swordPath = DU::convertDirSeparators( DU::getApplicationSwordDir().absolutePath());
+ conf["Install"].insert(
+ std::make_pair( SWBuf("LocalePath"), swordPath.toLocal8Bit().data() )
+ );
+#endif
+
+ bool setDataPath = false;
+ for (QStringList::const_iterator it = targets.begin(); it != targets.end(); ++it) {
+ QString t = DU::convertDirSeparators(*it);
+#ifdef Q_WS_WIN
+ if (t.contains(DU::convertDirSeparators(DU::getUserHomeDir().canonicalPath().append("\\Sword")))) {
+#else
+ if (t.contains(DU::getUserHomeDir().canonicalPath().append("/.sword"))) {
+#endif
+ //we don't want $HOME/.sword in the config
+ continue;
+ }
+ else {
+ qDebug() << "Add path to the conf file" << filename << ":" << t;
+ conf["Install"].insert( std::make_pair(!setDataPath ? SWBuf("DataPath") : SWBuf("AugmentPath"), t.toLocal8Bit().data()) );
+ setDataPath = true;
+ }
+ }
+ qDebug() << "save the sword conf...";
+ conf.Save();
+ CSwordBackend::instance()->reloadModules(CSwordBackend::PathChanged);
+ return true;
+}
+
+QStringList sourceNameList() {
+ qDebug() << "backend::sourceList";
+ BtInstallMgr mgr;
+ Q_ASSERT(mgr.installConf);
+
+ QStringList names;
+
+ //add Sword remote sources
+ for (InstallSourceMap::iterator it = mgr.sources.begin(); it != mgr.sources.end(); it++) {
+ names << QString::fromLocal8Bit(it->second->caption);
+ }
+
+ // Add local directory sources
+ SWConfig config(configFilename().toLatin1());
+ sword::SectionMap::iterator sourcesSection = config.Sections.find("Sources");
+ if (sourcesSection != config.Sections.end()) {
+ sword::ConfigEntMap::iterator sourceBegin = sourcesSection->second.lower_bound("DIRSource");
+ sword::ConfigEntMap::iterator sourceEnd = sourcesSection->second.upper_bound("DIRSource");
+
+ while (sourceBegin != sourceEnd) {
+ InstallSource is("DIR", sourceBegin->second.c_str());
+ names << QString::fromLatin1(is.caption.c_str());
+
+ sourceBegin++;
+ }
+ }
+
+ return names;
+}
+
+
+void initPassiveFtpMode() {
+ qDebug() << "backend::initPassiveFtpMode";
+ SWConfig config(configFilename().toLatin1());
+ config["General"]["PassiveFTP"] = "true";
+ config.Save();
+}
+QString swordConfigFilename() {
+ namespace DU = util::directory;
+
+ qDebug() << "backend::swordConfigFilename";
+#ifdef Q_WS_WIN
+ qDebug() << DU::getUserHomeDir().absolutePath().append("/Sword/sword.conf");
+ return DU::getUserHomeDir().absolutePath().append("/Sword/sword.conf");
+// return DU::getApplicationDir().absolutePath().append("/sword.conf");
+#else
+ qDebug() << DU::getUserHomeDir().absolutePath().append("/.sword/sword.conf");
+ return DU::getUserHomeDir().absolutePath().append("/.sword/sword.conf");
+#endif
+}
+
+QDir swordDir() {
+ namespace DU = util::directory;
+
+#ifdef Q_WS_WIN
+ return QDir(DU::getUserHomeDir().absolutePath().append("/Sword/"));
+#else
+ return QDir(DU::getUserHomeDir().absolutePath().append("/.sword/"));
+#endif
+}
+
+CSwordBackend* backend( const sword::InstallSource& is) {
+ qDebug() << "backend::backend";
+ CSwordBackend* ret = 0;
+ /// \anchor BackendNotSingleton
+ if (isRemote(is)) {
+ ret = new CSwordBackend( QString(is.localShadow.c_str()), false );
+ }
+ else {
+ ret = new CSwordBackend( QString(is.directory.c_str()), false);
+ }
+
+ Q_ASSERT(ret);
+ if (ret) {
+ ret->initModules(CSwordBackend::OtherChange);
+ }
+ return ret;
+}
+
+} // namespace BtInstallBackend
diff --git a/src/backend/btinstallbackend.h b/src/backend/btinstallbackend.h
new file mode 100644
index 0000000..fc71697
--- /dev/null
+++ b/src/backend/btinstallbackend.h
@@ -0,0 +1,71 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2011 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef INSTBACKEND_H
+#define INSTBACKEND_H
+
+#include <QDir>
+#include <QString>
+#include "backend/managers/cswordbackend.h"
+
+// Sword includes:
+#include <installmgr.h>
+
+
+class CSwordModuleInfo;
+
+namespace BtInstallBackend {
+
+/** Adds the source to the backend. */
+bool addSource(sword::InstallSource& source);
+
+/** Returns the source struct. */
+sword::InstallSource source(const QString &name);
+
+/** Deletes the source. */
+bool deleteSource(const QString &name);
+
+/** Returns the moduleinfo list for the source. */
+QList<CSwordModuleInfo*> moduleList(const QString &name);
+
+/** Tells if the source is remote or local. */
+bool isRemote(const sword::InstallSource& source);
+
+/** Returns the list of available install target paths. */
+QStringList targetList();
+
+/** Saves the list of available install target paths to the sword config. Return success indicator.*/
+bool setTargetList( const QStringList& targets );
+
+QStringList sourceNameList();
+
+/** Returns the path of the sword installer configuration file. */
+QString configPath();
+
+/** Returns the name of the sword installer configuration file. */
+QString configFilename();
+
+/** Sets the passive mode for as default.
+* \todo see if we can en/disable this per source.
+*/
+void initPassiveFtpMode();
+
+/** Returns the file name for the Sword config file. */
+QString swordConfigFilename();
+
+/** Returns the Sword directory ($HOME/.sword/) as a QDir, created with absolute path (not canonical).
+*/
+QDir swordDir();
+
+/** Returns backend Sword manager for the source. */
+CSwordBackend* backend( const sword::InstallSource& is);
+
+} // namespace BtInstallBackend
+
+#endif
diff --git a/src/backend/btmoduletreeitem.cpp b/src/backend/btmoduletreeitem.cpp
index 01e4446..c57d094 100644
--- a/src/backend/btmoduletreeitem.cpp
+++ b/src/backend/btmoduletreeitem.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.
*
**********/
@@ -14,7 +14,6 @@
#include <QString>
#include "backend/drivers/cswordmoduleinfo.h"
#include "backend/managers/cswordbackend.h"
-#include "util/cpointers.h"
#include "util/cresmgr.h"
#include "util/tool.h"
@@ -30,7 +29,7 @@ BTModuleTreeItem::BTModuleTreeItem(QList<BTModuleTreeItem::Filter*>& filters, BT
m_originalModuleList = *modules;
}
else {
- m_originalModuleList = CPointers::backend()->moduleList();
+ m_originalModuleList = CSwordBackend::instance()->moduleList();
}
//populate the tree with groups/modules
create_tree(filters, grouping);
@@ -139,7 +138,7 @@ void BTModuleTreeItem::create_tree(QList<BTModuleTreeItem::Filter*>& filters, BT
map_initialized = true;
}
- //QList<CSwordModuleInfo*> originalInfoList = CPointers::backend()->moduleList();
+ //QList<CSwordModuleInfo*> originalInfoList = CSwordBackend::instance()()->moduleList();
foreach (CSwordModuleInfo* info, m_originalModuleList) {
bool included;
diff --git a/src/backend/btmoduletreeitem.h b/src/backend/btmoduletreeitem.h
index 5bcebf8..6ee6868 100644
--- a/src/backend/btmoduletreeitem.h
+++ b/src/backend/btmoduletreeitem.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.
*
**********/
@@ -27,21 +27,21 @@ different set of filters you have to create a new tree - it's not possible to mo
Example:
- ...
- QList<BTModuleTreeItem::Filter*> noFilters
- BTModuleTreeItem root(noFilters, BTModuleTreeItem::CatLangMod);
- add_to_view(&root, qtreewidget->invisibleRootItem());
- ...
- void add_to_view(BTModuleTreeItem* item, QTreeWidgetItem* widgetItem) {
- foreach (BTModuleTreeItem* i, item->children()) {
- add_to_view(i, new QTreeWidgetItem(widgetItem));
- }
- if (item->type() == BTModuleTreeItem::Category) prepare_category_item(widgetItem, item);
- ...
- }
-
-
- @author The BibleTime team <info@bibletime.info>
+ ...
+ QList<BTModuleTreeItem::Filter*> noFilters
+ BTModuleTreeItem root(noFilters, BTModuleTreeItem::CatLangMod);
+ add_to_view(&root, qtreewidget->invisibleRootItem());
+ ...
+ void add_to_view(BTModuleTreeItem* item, QTreeWidgetItem* widgetItem) {
+ foreach (BTModuleTreeItem* i, item->children()) {
+ add_to_view(i, new QTreeWidgetItem(widgetItem));
+ }
+ if (item->type() == BTModuleTreeItem::Category) prepare_category_item(widgetItem, item);
+ ...
+ }
+
+
+ @author The BibleTime team <info@bibletime.info>
*/
class BTModuleTreeItem {
public:
@@ -63,10 +63,10 @@ class BTModuleTreeItem {
* will stop with the first negative.
*
* Example:
- * QList<BTModuleTreeItem::Filter*> filters;
- * MyFilter filter; BTModuleTreeItem::HiddenOff hideFilter;
- * filters.append(&hideFilter); filters.append(&filter);
- * BTModuleTreeItem root(filters, BTModuleTreeItem::CatLangMod);
+ * QList<BTModuleTreeItem::Filter*> filters;
+ * MyFilter filter; BTModuleTreeItem::HiddenOff hideFilter;
+ * filters.append(&hideFilter); filters.append(&filter);
+ * BTModuleTreeItem root(filters, BTModuleTreeItem::CatLangMod);
*/
struct Filter {
virtual bool filter(CSwordModuleInfo*) = 0;
@@ -102,7 +102,7 @@ class BTModuleTreeItem {
* The root item is populated with the item tree.
* The constructor takes a list of filters (see Filter), grouping indicator (see Grouping)
* and optionally the module list from which the tree is constructed
- * (by default CPointers::backend()->moduleList() is used).
+ * (by default CSwordBackend::instance()()->moduleList() is used).
*/
BTModuleTreeItem(QList<BTModuleTreeItem::Filter*>& filters,
BTModuleTreeItem::Grouping grouping, QList<CSwordModuleInfo*>* modules = 0);
diff --git a/src/backend/config/cbtconfig.cpp b/src/backend/config/cbtconfig.cpp
index 39c3e0c..883f41f 100644
--- a/src/backend/config/cbtconfig.cpp
+++ b/src/backend/config/cbtconfig.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,9 +16,9 @@
#include <QWebSettings>
#include "backend/btmoduletreeitem.h"
#include "backend/managers/cdisplaytemplatemgr.h"
+#include "btglobal.h"
#include "frontend/displaywindow/btactioncollection.h"
#include "frontend/searchdialog/btsearchoptionsarea.h"
-#include "util/cpointers.h"
#include "util/directory.h"
// Sword includes:
@@ -91,6 +91,8 @@ QString getKey(const bools ID) {
return "autoTileHorizontal";
case autoTile:
return "autoTile";
+ case autoTabbed:
+ return "autoTabbed";
case autoCascade:
return "autoCascade";
@@ -112,18 +114,24 @@ QString getKey(const bools ID) {
return "bookshelfShowHidden";
case allowNetworkConnection:
return "allowNetworkConnection";
-
+
case showTextWindowHeaders:
return "showTextWindowHeaders";
case showTextWindowNavigator:
return "showTextWindowNavigator";
case showTextWindowModuleSelectorButtons:
return "showTextWindowModuleSelectorButtons";
+ case showFormatToolbarButtons:
+ return "showFormatToolbarButtons";
case showTextWindowToolButtons:
return "showTextWindowToolButtons";
+ case showToolbarsInEachWindow:
+ return "showToolbarsInEachWindow";
+ case showTipAtStartup:
+ return "showTipAtStartup";
}
Q_ASSERT(false);
- return false;
+ return QString::null;
}
QString getKey(const ints ID) {
@@ -188,6 +196,8 @@ QString getKey(const ints ID) {
return "configDialogHeight";
case configDialogWidth:
return "configDialogWidth";
+ case tipNumber:
+ return "tipNumber";
}
Q_ASSERT(false);
return QString::null;
@@ -249,7 +259,7 @@ QString IntListToString(const QList<int> intList) {
return intStrings.join(",");
}
-QList<int> StringToIntList(const QString intListString) {
+QList<int> StringToIntList(const QString &intListString) {
QList<int> intList;
if (!intListString.isEmpty() && intListString.contains(',')) {
foreach(QString intString, intListString.split(',')) {
@@ -268,13 +278,13 @@ QString getDefault(const strings ID) {
case displayStyle:
return CDisplayTemplateMgr::defaultTemplate();
case bookshelfCurrentItem:
- return QString();
+ return QString::null;
}
return QString::null;
}
QString getDefault(const modules ID) {
- // CSwordBackend *b = CPointers::backend();
+ // CSwordBackend *b = CSwordBackend::instance()();
switch (ID) {
case standardBible:
return "KJV";
@@ -318,6 +328,8 @@ bool getDefault(const bools ID) {
return false;
case autoTile:
return false;
+ case autoTabbed:
+ return false;
case autoCascade:
return false;
@@ -338,7 +350,7 @@ bool getDefault(const bools ID) {
return false;
case allowNetworkConnection:
return false;
-
+
case showTextWindowHeaders:
return true;
case showTextWindowNavigator:
@@ -347,6 +359,12 @@ bool getDefault(const bools ID) {
return true;
case showTextWindowToolButtons:
return true;
+ case showFormatToolbarButtons:
+ return true;
+ case showToolbarsInEachWindow:
+ return true;
+ case showTipAtStartup:
+ return true;
}
return false;
}
@@ -413,6 +431,8 @@ int getDefault(const ints ID) {
return 1;
case configDialogWidth:
return 1;
+ case tipNumber:
+ return 0;
}
return 0;
}
@@ -498,7 +518,7 @@ QString get(const strings ID) {
CSwordModuleInfo *get(const modules ID) {
getConfig()->beginGroup("modules");
- CSwordModuleInfo *result(CPointers::backend()->findModuleByName(
+ CSwordModuleInfo *result(CSwordBackend::instance()->findModuleByName(
getConfig()->value(getKey(ID), getDefault(ID)).toString()
));
getConfig()->endGroup();
@@ -603,7 +623,7 @@ FontSettingsPair get(const CLanguageMgr::Language * const language) {
return settings;
}
-void set(const strings ID, const QString value) {
+void set(const strings ID, const QString &value) {
// KConfigGroup cg = getConfig()->group("strings");
// cg.writeEntry(getKey(ID), value);
getConfig()->beginGroup("strings");
@@ -620,7 +640,7 @@ void set(const modules ID, CSwordModuleInfo * const value) {
}
void set(const modules ID, const QString& value) {
- CSwordModuleInfo *module(CPointers::backend()->findModuleByName(value));
+ CSwordModuleInfo *module(CSwordBackend::instance()->findModuleByName(value));
if (module) {
set(ID, module);
}
@@ -704,15 +724,15 @@ void set(const CLanguageMgr::Language * const language,
m_fontCache.remove(language);
}
-CSwordBackend::DisplayOptions getDisplayOptionDefaults() {
- CSwordBackend::DisplayOptions options;
+DisplayOptions getDisplayOptionDefaults() {
+ DisplayOptions options;
options.lineBreaks = get(lineBreaks);
options.verseNumbers = get(verseNumbers);
return options;
}
-CSwordBackend::FilterOptions getFilterOptionDefaults() {
- CSwordBackend::FilterOptions options;
+FilterOptions getFilterOptionDefaults() {
+ FilterOptions options;
options.footnotes = true; // Required for the info display
options.strongNumbers = true; // get(strongNumbers);
diff --git a/src/backend/config/cbtconfig.h b/src/backend/config/cbtconfig.h
index 9f3a850..ef618a2 100644
--- a/src/backend/config/cbtconfig.h
+++ b/src/backend/config/cbtconfig.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.
*
**********/
@@ -56,6 +56,7 @@ enum bools {
autoTileVertical,
autoTileHorizontal,
autoTile,
+ autoTabbed,
autoCascade,
lineBreaks,
@@ -73,7 +74,10 @@ enum bools {
showTextWindowHeaders,
showTextWindowNavigator,
showTextWindowToolButtons,
- showTextWindowModuleSelectorButtons
+ showTextWindowModuleSelectorButtons,
+ showFormatToolbarButtons,
+ showToolbarsInEachWindow,
+ showTipAtStartup
};
enum ints {
footnotes,
@@ -110,7 +114,8 @@ enum ints {
configDialogPosX,
configDialogPosY,
configDialogHeight,
- configDialogWidth
+ configDialogWidth,
+ tipNumber
};
enum intLists {
leftPaneSplitterSizes,
@@ -140,7 +145,7 @@ enum stringMaps {
};
QString IntListToString(const QList<int> intList);
-QList<int> StringToIntList(const QString intListString);
+QList<int> StringToIntList(const QString &intListString);
QString getDefault(const strings);
QString getDefault(const modules);
@@ -160,7 +165,7 @@ QStringList get(const stringLists);
StringMap get(const stringMaps);
FontSettingsPair get(const CLanguageMgr::Language * const);
-void set(const strings, const QString value);
+void set(const strings, const QString &value);
void set(const modules, CSwordModuleInfo * const module);
void set(const modules, const QString& moduleName);
void set(const bools, const bool value);
@@ -171,8 +176,8 @@ void set(const stringMaps, const StringMap value);
void set(const CLanguageMgr::Language * const language,
const FontSettingsPair &fontSettings);
-CSwordBackend::FilterOptions getFilterOptionDefaults();
-CSwordBackend::DisplayOptions getDisplayOptionDefaults();
+FilterOptions getFilterOptionDefaults();
+DisplayOptions getDisplayOptionDefaults();
void setupAccelSettings(const keys type,
BtActionCollection * const actionCollection);
diff --git a/src/backend/cswordmodulesearch.cpp b/src/backend/cswordmodulesearch.cpp
index 9348295..694151d 100644
--- a/src/backend/cswordmodulesearch.cpp
+++ b/src/backend/cswordmodulesearch.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,63 +10,32 @@
#include "backend/cswordmodulesearch.h"
#include "backend/config/cbtconfig.h"
-#include "backend/drivers/cswordmoduleinfo.h"
#include "backend/managers/cswordbackend.h"
+#include "btglobal.h"
-// Sword includes:
-#include <listkey.h>
-#include <swkey.h>
-#include <swmodule.h>
+void CSwordModuleSearch::startSearch() {
+ // Clear old search results:
+ m_results.clear();
+ m_foundItems = 0;
-CSwordModuleSearch* CSwordModuleSearch::searcher = 0;
+ /// \todo What is the purpose of the following statement?
+ CSwordBackend::instance()->setFilterOptions(CBTConfig::getFilterOptionDefaults());
-CSwordModuleSearch::CSwordModuleSearch()
- : m_searchedText(QString::null),
- m_searchOptions(0),
- m_foundItems(false) {
- searcher = this;
-}
-
-CSwordModuleSearch::~CSwordModuleSearch() {
- searcher = 0;
-}
-
-/** This function sets the modules which should be searched. */
-void CSwordModuleSearch::setModules( const QList<CSwordModuleInfo*>& list ) {
- m_moduleList = list;
-}
-
-/** Starts the search for the search text. */
-bool CSwordModuleSearch::startSearch() {
- backend()->setFilterOptions ( CBTConfig::getFilterOptionDefaults() );
- m_foundItems = false;
-
- bool foundItems = false;
-
- // for (m_moduleList.first(); m_moduleList.current() && !m_terminateSearch; m_moduleList.next()) {
- QList<CSwordModuleInfo*>::iterator end_it = m_moduleList.end();
-
- for (QList<CSwordModuleInfo*>::iterator it = m_moduleList.begin(); it != end_it; ++it) {
- if ( (*it)->searchIndexed(m_searchedText/*, m_searchOptions*/, m_searchScope) ) {
- foundItems = true;
+ // Search module-by-module:
+ Q_FOREACH(const CSwordModuleInfo *m, m_searchModules) {
+ sword::ListKey results;
+ int found = m->searchIndexed(m_searchText, m_searchScope, results);
+ if (found > 0) {
+ m_results.insert(m, results);
+ m_foundItems += found;
}
}
-
- m_foundItems = foundItems;
-
- //m_finishedSig.activate();
- emit finished();
- return true;
}
-/** Sets the text which should be search in the modules. */
-void CSwordModuleSearch::setSearchedText( const QString& text ) {
- m_searchedText = text;
-}
+void CSwordModuleSearch::setSearchScope(const sword::ListKey &scope) {
+ /// \todo Properly examine and document the inner workings of this method.
-/** Sets the search scope. */
-void CSwordModuleSearch::setSearchScope( const sword::ListKey& scope ) {
m_searchScope.copyFrom( scope );
if (!strlen(scope.getRangeText())) { //we can't search with an empty search scope, would crash
@@ -81,34 +50,14 @@ void CSwordModuleSearch::setSearchScope( const sword::ListKey& scope ) {
}
}
-/** Sets the search scope back. */
-void CSwordModuleSearch::resetSearchScope() {
- m_searchScope.ClearList();
-}
-
-/** Returns true if in the last search the searcher found items, if no items were found return false. */
-bool CSwordModuleSearch::foundItems() const {
- return m_foundItems;
-}
-
-/** Returns a copy of the used search scope. */
-const sword::ListKey& CSwordModuleSearch::searchScope() const {
- return m_searchScope;
-}
-
-void CSwordModuleSearch::connectFinished( QObject *receiver, const char *member ) {
- //m_finishedSig.connect(receiver, member);
- QObject::connect(this, SIGNAL(finished()), receiver, member);
-}
-
-bool CSwordModuleSearch::modulesHaveIndices( const QList<CSwordModuleInfo*>& modules ) {
- bool hasIndices = true;
- QList<CSwordModuleInfo*>::const_iterator end_it = modules.end();
- for ( QList<CSwordModuleInfo*>::const_iterator it = modules.begin(); it != end_it; ++it) {
- if (!(*it)->hasIndex()) {
- hasIndices = false;
- break;
+QList<const CSwordModuleInfo*> CSwordModuleSearch::unindexedModules(
+ const QList<const CSwordModuleInfo*> &modules)
+{
+ QList<const CSwordModuleInfo*> unindexed;
+ Q_FOREACH (const CSwordModuleInfo *m, modules) {
+ if (!m->hasIndex()) {
+ unindexed.append(m);
}
}
- return hasIndices;
+ return unindexed;
}
diff --git a/src/backend/cswordmodulesearch.h b/src/backend/cswordmodulesearch.h
index d40e9fa..bc0d37c 100644
--- a/src/backend/cswordmodulesearch.h
+++ b/src/backend/cswordmodulesearch.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.
*
**********/
@@ -11,8 +11,8 @@
#define CSWORDMODULESEARCH_H
#include <QObject>
-#include <QString>
-#include "util/cpointers.h"
+
+#include <QHash>
// Sword includes:
#include <listkey.h>
@@ -28,65 +28,86 @@ class CSwordModuleInfo;
* @version $Id: cswordmodulesearch.h,v 1.34 2006/08/08 19:32:48 joachim Exp $
*/
-class CSwordModuleSearch: public QObject, CPointers {
+class CSwordModuleSearch: public QObject {
Q_OBJECT
- public:
- CSwordModuleSearch();
+ public: /* Types: */
+ typedef QHash<const CSwordModuleInfo*, sword::ListKey> Results;
+
+ public: /* Methods: */
+ inline CSwordModuleSearch()
+ : m_foundItems(0) {}
+
/**
- * The destructor of this class. It cleans uop memory before it's deleted.
+ Sets the text which should be search in the modules.
+ \param[in] text the text to search.
*/
- virtual ~CSwordModuleSearch();
+ inline void setSearchedText(const QString &text) {
+ m_searchText = text;
+ }
+
/**
- * Sets the text which should be search in the modules.
+ Set the modules which should be searched.
+ \param[in] modules the modules to search in.
*/
- void setSearchedText( const QString& );
+ inline void setModules(const QList<const CSwordModuleInfo*> &modules) {
+ Q_ASSERT(!modules.empty());
+ Q_ASSERT(unindexedModules(modules).empty());
+ m_searchModules = modules;
+ }
+
/**
- * Starts the search for the search text.
+ Sets the search scope.
+ \param[in] scope the scope used for the search.
*/
- bool startSearch();
+ void setSearchScope(const sword::ListKey &scope);
+
/**
- * This function sets the modules which should be searched.
+ Resets the search scope.
*/
- void setModules( const QList<CSwordModuleInfo*>& );
+ inline void resetSearchScope() {
+ m_searchScope.ClearList();
+ }
+
/**
- * Sets the search scope.
+ \returns the search scope.
*/
- void setSearchScope( const sword::ListKey& scope );
+ const sword::ListKey &searchScope() const {
+ return m_searchScope;
+ }
+
/**
- * Sets the seaech scope back.
+ Starts the search for the search text.
*/
- void resetSearchScope();
+ void startSearch();
+
/**
- * @return "true" if in the last search the searcher found items, if no items were found return "false"
+ \returns the number of found items in the last search.
*/
- bool foundItems() const;
+ inline unsigned long foundItems() const {
+ return m_foundItems;
+ }
+
/**
- * Returns a copy of the used search scope.
+ \returns the results of the search.
*/
- const sword::ListKey& searchScope() const;
-
- void connectFinished( QObject * receiver, const char * member );
+ const Results &results() const {
+ return m_results;
+ }
/**
- * Returns true if all of the specified modules have indices already built.
+ \returns the list of unindexed modules in the given list.
*/
- bool modulesHaveIndices( const QList<CSwordModuleInfo*>& );
-
- protected:
- QString m_searchedText;
- sword::ListKey m_searchScope;
- QList<CSwordModuleInfo*> m_moduleList;
-
- int m_searchOptions;
-
- bool m_foundItems;
+ static QList<const CSwordModuleInfo*> unindexedModules(
+ const QList<const CSwordModuleInfo*> &modules);
- signals:
- void finished();
+ private: /* Fields: */
+ QString m_searchText;
+ sword::ListKey m_searchScope;
+ QList<const CSwordModuleInfo*> m_searchModules;
- private:
- static CSwordModuleSearch* searcher;
+ Results m_results;
+ unsigned long m_foundItems;
};
#endif
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 &copy) :
+ 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 &copy);
+
+ /* 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 &copy)
+ : 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 &copy)
+ : 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 &copy);
+
+ 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
diff --git a/src/backend/filters/bt_gbfhtml.h b/src/backend/filters/bt_gbfhtml.h
deleted file mode 100644
index 45e7e59..0000000
--- a/src/backend/filters/bt_gbfhtml.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*********
-*
-* 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.
-*
-**********/
-
-#ifndef BT_GBFHTML_H
-#define BT_GBFHTML_H
-
-// Sword includes:
-#include <gbfhtml.h>
-
-
-namespace Filters {
-
-/** GBF to HTML filter,
-* This filter converts GBF Text into HTML
-*/
-
-class BT_GBFHTML : public sword::GBFHTML { /*, protected CFilterTool */
-
- protected:
-
- class BT_UserData : public sword::GBFHTML::MyUserData {
-
- public:
- BT_UserData(const sword::SWModule *module, const sword::SWKey *key) : sword::GBFHTML::MyUserData(module, key) {
- swordFootnote = 1;
- hasFootnotePreTag = false;
- }
-
- short unsigned int swordFootnote;
- };
-
- virtual sword::BasicFilterUserData *createUserData(const sword::SWModule* module, const sword::SWKey* key) {
- return new BT_UserData(module, key);
- }
-
- public:
- BT_GBFHTML();
- virtual bool handleToken(sword::SWBuf &buf, const char *token, sword::BasicFilterUserData *userData);
- virtual char processText(sword::SWBuf& buf, const sword::SWKey*, const sword::SWModule * = 0);
-};
-
-}
-
-#endif
diff --git a/src/backend/filters/bt_osishtml.h b/src/backend/filters/bt_osishtml.h
deleted file mode 100644
index 83bf0a9..0000000
--- a/src/backend/filters/bt_osishtml.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/*********
-*
-* 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.
-*
-**********/
-
-#ifndef BT_OSISHTML_H
-#define BT_OSISHTML_H
-
-// Sword includes:
-#include <osishtmlhref.h>
-#include <swbuf.h>
-#include <swmodule.h>
-
-namespace Filters {
-
-/** BibleTime's OSIS to HTMl filter.
-* This filter works on OSIS tags and outputs HTML in the structure supported by BibleTime.
-*/
-
-class BT_OSISHTML : public sword::OSISHTMLHREF {
-
- protected:
-
- class BT_UserData : public sword::OSISHTMLHREF::MyUserData {
-
- public:
- BT_UserData(const sword::SWModule *module, const sword::SWKey *key) : sword::OSISHTMLHREF::MyUserData(module, key) {
- noteType = Unknown;
- swordFootnote = 1;
- inCrossrefNote = false;
- entryAttributes = module->getEntryAttributes();
- }
-
- unsigned short int swordFootnote;
- bool inCrossrefNote;
- sword::AttributeTypeList entryAttributes;
-
- enum NoteType {
- Unknown,
- Alternative,
- CrossReference,
- Footnote,
- StrongsMarkup
- } noteType;
-
- struct {
- sword::SWBuf who;
- }
-
- quote;
- };
-
- virtual sword::BasicFilterUserData *createUserData(const sword::SWModule* module, const sword::SWKey* key) {
- return new BT_UserData(module, key);
- }
-
- public:
- BT_OSISHTML();
- virtual bool handleToken(sword::SWBuf &buf, const char *token, sword::BasicFilterUserData *userData);
- private:
- void renderReference(const char *osisRef, sword::SWBuf &buf, sword::SWModule *myModule, BT_UserData *myUserData);
-};
-
-} //end of Filters namespace
-
-#endif
diff --git a/src/backend/filters/bt_plainhtml.h b/src/backend/filters/bt_plainhtml.h
deleted file mode 100644
index c228660..0000000
--- a/src/backend/filters/bt_plainhtml.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*********
-*
-* 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.
-*
-**********/
-
-#ifndef BT_PLAINHTML_H
-#define BT_PLAINHTML_H
-
-// Sword includes:
-#include <swbuf.h>
-#include <swfilter.h>
-
-
-class SWKey;
-class SWModule;
-
-namespace Filters {
-
-/** Plain to HTML filter,
-* This filter converts Plain Text into HTML
-*/
-class BT_PLAINHTML : public sword::SWFilter {
- protected:
- virtual char processText(sword::SWBuf& buf, const sword::SWKey*, const sword::SWModule * = 0);
- public:
- BT_PLAINHTML();
-};
-}
-
-#endif
diff --git a/src/backend/filters/bt_teihtml.h b/src/backend/filters/bt_teihtml.h
deleted file mode 100644
index 2160349..0000000
--- a/src/backend/filters/bt_teihtml.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*********
-*
-* 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.
-*
-**********/
-
-#ifndef BT_TEIHTML_H
-#define BT_TEIHTML_H
-
-// Sword includes:
-#include <teihtmlhref.h>
-#include <swbuf.h>
-
-namespace Filters {
-
-/** BibleTime's TEI to HTMl filter.
-* This filter works on TEI tags and outputs HTML in the structure supported by BibleTime.
-*/
-
-class BT_TEIHTML : public sword::TEIHTMLHREF {
-
- public:
- BT_TEIHTML();
- virtual bool handleToken(sword::SWBuf &buf, const char *token, sword::BasicFilterUserData *userData);
- private:
- void renderReference(const char *osisRef, sword::SWBuf &buf, sword::BasicFilterUserData *myUserData);
-};
-
-} //end of Filters namespace
-
-#endif
diff --git a/src/backend/filters/bt_thmlhtml.h b/src/backend/filters/bt_thmlhtml.h
deleted file mode 100644
index 6a220b6..0000000
--- a/src/backend/filters/bt_thmlhtml.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*********
-*
-* 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.
-*
-**********/
-
-#ifndef BT_THMLHTML_H
-#define BT_THMLHTML_H
-
-// Sword includes:
-#include <swbuf.h>
-#include <thmlhtml.h>
-
-
-namespace Filters {
-
-/** ThML to HTML filter.
-* This filter converts ThML text to HTML text
-*/
-
-class BT_ThMLHTML : public sword::ThMLHTML {
-
- protected:
-
- class BT_UserData : public sword::ThMLHTML::MyUserData {
-
- public:
- BT_UserData(const sword::SWModule *module, const sword::SWKey *key) : sword::ThMLHTML::MyUserData(module, key) {
- inscriptRef = false;
- swordFootnote = 1;
- inFootnoteTag = false;
- }
-
- bool inscriptRef;
- bool inFootnoteTag;
- unsigned short int swordFootnote;
- };
-
- virtual sword::BasicFilterUserData *createUserData(const sword::SWModule* module, const sword::SWKey* key) {
- return new BT_UserData(module, key);
- }
-
- public:
- BT_ThMLHTML ();
- virtual bool handleToken(sword::SWBuf& buf, const char *token, sword::BasicFilterUserData *userData);
- virtual char processText(sword::SWBuf& buf, const sword::SWKey*, const sword::SWModule* = 0);
-};
-
-}
-
-#endif
diff --git a/src/backend/filters/bt_thmlplain.h b/src/backend/filters/bt_thmlplain.h
deleted file mode 100644
index 92c2c33..0000000
--- a/src/backend/filters/bt_thmlplain.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/*********
-*
-* 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.
-*
-**********/
-
-#ifndef BT_THMLPLAIN_H
-#define BT_THMLPLAIN_H
-
-// Sword includes:
-#include <swbuf.h>
-#include <swfilter.h>
-
-
-namespace Filters {
-
-/** This filter converts ThML text to plain text
-*/
-class BT_ThMLPlain : public sword::SWFilter {
- protected:
- virtual char processText(sword::SWBuf &text, const sword::SWKey *key = 0, const sword::SWModule *module = 0);
- public:
- BT_ThMLPlain();
-};
-
-}
-#endif
diff --git a/src/backend/filters/bt_gbfhtml.cpp b/src/backend/filters/gbftohtml.cpp
index 8d6a36a..fac70ba 100644
--- a/src/backend/filters/bt_gbfhtml.cpp
+++ b/src/backend/filters/gbftohtml.cpp
@@ -2,24 +2,23 @@
*
* 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/filters/bt_gbfhtml.h"
+#include "backend/filters/gbftohtml.h"
#include <QRegExp>
#include <QString>
#include "backend/drivers/cswordmoduleinfo.h"
#include "backend/managers/cswordbackend.h"
-#include "util/cpointers.h"
// Sword includes:
#include <utilxml.h>
-Filters::BT_GBFHTML::BT_GBFHTML() : sword::GBFHTML() {
+Filters::GbfToHtml::GbfToHtml() : sword::GBFHTML() {
setEscapeStringCaseSensitive(true);
setPassThruUnknownEscapeString(true); //the HTML widget will render the HTML escape codes
@@ -72,14 +71,14 @@ Filters::BT_GBFHTML::BT_GBFHTML() : sword::GBFHTML() {
}
/** No descriptions */
-char Filters::BT_GBFHTML::processText(sword::SWBuf& buf, const sword::SWKey * key, const sword::SWModule * module) {
+char Filters::GbfToHtml::processText(sword::SWBuf& buf, const sword::SWKey * key, const sword::SWModule * module) {
GBFHTML::processText(buf, key, module);
if (!module->isProcessEntryAttributes()) {
return 1; //no processing should be done, may happen in a search
}
- CSwordModuleInfo* m = CPointers::backend()->findModuleByName( module->Name() );
+ CSwordModuleInfo* m = CSwordBackend::instance()->findModuleByName( module->Name() );
if (m && !(m->has(CSwordModuleInfo::lemmas) || m->has(CSwordModuleInfo::morphTags) || m->has(CSwordModuleInfo::strongNumbers))) { //only parse if the module has strongs or lemmas
return 1; //WARNING: Return alread here
@@ -227,13 +226,11 @@ char Filters::BT_GBFHTML::processText(sword::SWBuf& buf, const sword::SWKey * ke
return 1;
}
-bool Filters::BT_GBFHTML::handleToken(sword::SWBuf &buf, const char *token, sword::BasicFilterUserData *userData) {
+bool Filters::GbfToHtml::handleToken(sword::SWBuf &buf, const char *token, sword::BasicFilterUserData *userData) {
if (!substituteToken(buf, token)) { //more than a simple replace
const unsigned int tokenLength = strlen(token);
- unsigned long i;
- sword::SWBuf value;
- BT_UserData* myUserData = dynamic_cast<BT_UserData*>(userData);
+ UserData* myUserData = dynamic_cast<UserData*>(userData);
sword::SWModule* myModule = const_cast<sword::SWModule*>(myUserData->module); //hack to be able to call stuff like Lang()
if ( !strncmp(token, "WG", 2)
@@ -272,7 +269,7 @@ bool Filters::BT_GBFHTML::handleToken(sword::SWBuf &buf, const char *token, swor
else if (!strncmp(token, "FN", 2)) { //the end </font> tag is inserted in addTokenSubsitute
buf.append("<font face=\"");
- for (i = 2; i < tokenLength; i++) {
+ for (unsigned long i = 2; i < tokenLength; i++) {
if (token[i] != '\"') {
buf.append( token[i] );
}
diff --git a/src/backend/filters/gbftohtml.h b/src/backend/filters/gbftohtml.h
new file mode 100644
index 0000000..fbe5db2
--- /dev/null
+++ b/src/backend/filters/gbftohtml.h
@@ -0,0 +1,61 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2011 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef FILTERS_GBFTOHTML_H
+#define FILTERS_GBFTOHTML_H
+
+// Sword includes:
+#include <gbfhtml.h>
+
+
+namespace Filters {
+
+/**
+ \brief GBF to HTML conversion filter.
+*/
+class GbfToHtml: public sword::GBFHTML {
+ protected: /* Types: */
+ class UserData: public sword::GBFHTML::MyUserData {
+ public:
+ inline UserData(const sword::SWModule *module,
+ const sword::SWKey *key)
+ : sword::GBFHTML::MyUserData(module, key),
+ swordFootnote(1)
+ {
+ hasFootnotePreTag = false;
+ }
+
+ short unsigned int swordFootnote;
+ };
+
+ public: /* Methods: */
+ GbfToHtml();
+
+ /** Reimplemented from sword::OSISHTMLHREF. */
+ virtual bool handleToken(sword::SWBuf &buf,
+ const char *token,
+ sword::BasicFilterUserData *userData);
+
+ /** Reimplemented from sword::SWFilter. */
+ virtual char processText(sword::SWBuf &buf,
+ const sword::SWKey *key,
+ const sword::SWModule *module = 0);
+
+ protected: /* Methods: */
+ /** Reimplemented from sword::OSISHTMLHREF. */
+ virtual inline sword::BasicFilterUserData *createUserData(
+ const sword::SWModule *module, const sword::SWKey *key)
+ {
+ return new UserData(module, key);
+ }
+};
+
+} // namespace Filters
+
+#endif
diff --git a/src/backend/filters/osismorphsegmentation.cpp b/src/backend/filters/osismorphsegmentation.cpp
index 512fe2e..421b63e 100644
--- a/src/backend/filters/osismorphsegmentation.cpp
+++ b/src/backend/filters/osismorphsegmentation.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.
*
**********/
@@ -67,7 +67,7 @@ char Filters::OSISMorphSegmentation::processText(sword::SWBuf &text, const sword
text.append(token);
text.append('>');
- // hide = false; //not right, because there may be child tags in seg. Only /seg may disable the seg hiding.
+ // hide = false; //not right, because there may be child tags in seg. Only /seg may disable the seg hiding.
continue;
} //end of intoken part
diff --git a/src/backend/filters/osismorphsegmentation.h b/src/backend/filters/osismorphsegmentation.h
index c5bbb18..4843488 100644
--- a/src/backend/filters/osismorphsegmentation.h
+++ b/src/backend/filters/osismorphsegmentation.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.
*
**********/
diff --git a/src/backend/filters/bt_osishtml.cpp b/src/backend/filters/osistohtml.cpp
index 7525aca..c04c820 100644
--- a/src/backend/filters/bt_osishtml.cpp
+++ b/src/backend/filters/osistohtml.cpp
@@ -2,19 +2,18 @@
*
* 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/filters/bt_osishtml.h"
+#include "backend/filters/osistohtml.h"
#include <QString>
#include "backend/config/cbtconfig.h"
#include "backend/drivers/cswordmoduleinfo.h"
#include "backend/managers/clanguagemgr.h"
#include "backend/managers/referencemanager.h"
-#include "util/cpointers.h"
// Sword includes:
#include <swbuf.h>
@@ -22,7 +21,7 @@
#include <utilxml.h>
-Filters::BT_OSISHTML::BT_OSISHTML() : sword::OSISHTMLHREF() {
+Filters::OsisToHtml::OsisToHtml() : sword::OSISHTMLHREF() {
setPassThruUnknownEscapeString(true); //the HTML widget will render the HTML escape codes
addTokenSubstitute("inscription", "<span class=\"inscription\">");
@@ -31,12 +30,12 @@ Filters::BT_OSISHTML::BT_OSISHTML() : sword::OSISHTMLHREF() {
addTokenSubstitute("mentioned", "<span class=\"mentioned\">");
addTokenSubstitute("/mentioned", "</span>");
-// addTokenSubstitute("divineName", "<span class=\"name\"><span class=\"divine\">");
-// addTokenSubstitute("/divineName", "</span></span>");
+// addTokenSubstitute("divineName", "<span class=\"name\"><span class=\"divine\">");
+// addTokenSubstitute("/divineName", "</span></span>");
/// \todo Move that down to the real tag handling, segs without the type morph would generate incorrect markup, as the end span is always inserted
-// addTokenSubstitute("seg type=\"morph\"", "<span class=\"morphSegmentation\">");
-// addTokenSubstitute("/seg", "</span>");
+// addTokenSubstitute("seg type=\"morph\"", "<span class=\"morphSegmentation\">");
+// addTokenSubstitute("/seg", "</span>");
// OSIS tables
addTokenSubstitute("table", "<table>");
@@ -48,11 +47,11 @@ Filters::BT_OSISHTML::BT_OSISHTML() : sword::OSISHTMLHREF() {
}
-bool Filters::BT_OSISHTML::handleToken(sword::SWBuf &buf, const char *token, sword::BasicFilterUserData *userData) {
+bool Filters::OsisToHtml::handleToken(sword::SWBuf &buf, const char *token, sword::BasicFilterUserData *userData) {
// manually process if it wasn't a simple substitution
if (!substituteToken(buf, token)) {
- BT_UserData* myUserData = dynamic_cast<BT_UserData*>(userData);
+ UserData* myUserData = dynamic_cast<UserData*>(userData);
sword::SWModule* myModule = const_cast<sword::SWModule*>(myUserData->module); //hack
sword::XMLTag tag(token);
@@ -185,7 +184,7 @@ bool Filters::BT_OSISHTML::handleToken(sword::SWBuf &buf, const char *token, swo
}
//strongs is handled by BibleTime
/*else if (!strncmp("strongs", attrib, val-atrrib)) {
- attrValue.append( !strncmp(attrib, "x-", 2) ? attrib+2 : attrib );
+ attrValue.append( !strncmp(attrib, "x-", 2) ? attrib+2 : attrib );
}*/
else {
attrValue.append( !strncmp(attrib, "x-", 2) ? attrib + 2 : attrib );
@@ -224,7 +223,7 @@ bool Filters::BT_OSISHTML::handleToken(sword::SWBuf &buf, const char *token, swo
if (type == "crossReference") { //note containing cross references
myUserData->inCrossrefNote = true;
- myUserData->noteType = BT_UserData::CrossReference;
+ myUserData->noteType = UserData::CrossReference;
/*
* Do not count crossrefs as footnotes if they are displayed in the text. This will cause problems
@@ -251,7 +250,7 @@ bool Filters::BT_OSISHTML::handleToken(sword::SWBuf &buf, const char *token, swo
*/
myUserData->suspendTextPassThru = true;
- myUserData->noteType = BT_UserData::StrongsMarkup;
+ myUserData->noteType = UserData::StrongsMarkup;
}
else {
@@ -269,20 +268,20 @@ bool Filters::BT_OSISHTML::handleToken(sword::SWBuf &buf, const char *token, swo
buf.append( (n.length() > 0) ? n.c_str() : "*" );
buf.append("</span> ");
- myUserData->noteType = BT_UserData::Footnote;
+ myUserData->noteType = UserData::Footnote;
myUserData->suspendTextPassThru = true;
}
}
else { //if (tag.isEndTag()) {
- Q_ASSERT(myUserData->noteType != BT_UserData::Unknown);
+ Q_ASSERT(myUserData->noteType != UserData::Unknown);
- if (myUserData->noteType == BT_UserData::CrossReference) {
+ if (myUserData->noteType == UserData::CrossReference) {
buf.append("</span> ");
-// myUserData->suspendTextPassThru = false;
+// myUserData->suspendTextPassThru = false;
myUserData->inCrossrefNote = false;
}
- myUserData->noteType = BT_UserData::Unknown;
+ myUserData->noteType = UserData::Unknown;
myUserData->suspendTextPassThru = false;
}
}
@@ -425,15 +424,18 @@ bool Filters::BT_OSISHTML::handleToken(sword::SWBuf &buf, const char *token, swo
// <q> quote
else if (!strcmp(tag.getName(), "q")) {
- sword::SWBuf type = tag.getAttribute("type");
+ //sword::SWBuf type = tag.getAttribute("type");
sword::SWBuf who = tag.getAttribute("who");
const char *lev = tag.getAttribute("level");
int level = (lev) ? atoi(lev) : 1;
- const char* quoteMarker = tag.getAttribute("marker");
+ sword::SWBuf quoteMarker = tag.getAttribute("marker");
if ((!tag.isEndTag())) {
- myUserData->quote.who = who;
- if (quoteMarker) {
+ if (!tag.isEmpty()) {
+ myUserData->quote.who = who;
+ }
+
+ if (quoteMarker.size() > 0) {
buf.append(quoteMarker);
}
else if (osisQToTick) //alternate " and '
@@ -447,7 +449,7 @@ bool Filters::BT_OSISHTML::handleToken(sword::SWBuf &buf, const char *token, swo
if (myUserData->quote.who == "Jesus") {
buf.append("</span>");
}
- if (quoteMarker) {
+ if (quoteMarker.size() > 0) {
buf.append(quoteMarker);
}
else if (osisQToTick) { //alternate " and '
@@ -536,7 +538,7 @@ bool Filters::BT_OSISHTML::handleToken(sword::SWBuf &buf, const char *token, swo
return false;
}
-void Filters::BT_OSISHTML::renderReference(const char *osisRef, sword::SWBuf &buf, sword::SWModule *myModule, BT_UserData *myUserData) {
+void Filters::OsisToHtml::renderReference(const char *osisRef, sword::SWBuf &buf, sword::SWModule *myModule, UserData *myUserData) {
QString ref( osisRef );
QString hrefRef( ref );
//Q_ASSERT(!ref.isEmpty()); checked later
@@ -546,7 +548,7 @@ void Filters::BT_OSISHTML::renderReference(const char *osisRef, sword::SWBuf &bu
//If the osisRef is something like "ModuleID:key comes here" then the
// modulename is given, so we'll use that one
- CSwordModuleInfo* mod = CPointers::backend()->findSwordModuleByPointer(myModule);
+ CSwordModuleInfo* mod = CSwordBackend::instance()->findSwordModuleByPointer(myModule);
//Q_ASSERT(mod); checked later
if (!mod || (mod->type() != CSwordModuleInfo::Bible
&& mod->type() != CSwordModuleInfo::Commentary)) {
@@ -563,8 +565,8 @@ void Filters::BT_OSISHTML::renderReference(const char *osisRef, sword::SWBuf &bu
QString newModuleName = ref.left(pos);
hrefRef = ref.mid(pos + 1);
- if (CPointers::backend()->findModuleByName(newModuleName)) {
- mod = CPointers::backend()->findModuleByName(newModuleName);
+ if (CSwordBackend::instance()->findModuleByName(newModuleName)) {
+ mod = CSwordBackend::instance()->findModuleByName(newModuleName);
}
}
diff --git a/src/backend/filters/osistohtml.h b/src/backend/filters/osistohtml.h
new file mode 100644
index 0000000..ca36fe6
--- /dev/null
+++ b/src/backend/filters/osistohtml.h
@@ -0,0 +1,75 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2011 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef FILTERS_OSISTOHTML_H
+#define FILTERS_OSISTOHTML_H
+
+// Sword includes:
+#include <osishtmlhref.h>
+#include <swbuf.h>
+#include <swmodule.h>
+
+namespace Filters {
+
+/**
+ \brief OSIS to HTMl conversion filter.
+*/
+class OsisToHtml: public sword::OSISHTMLHREF {
+ protected: /* Types: */
+ class UserData: public sword::OSISHTMLHREF::MyUserData {
+ public:
+ inline UserData(const sword::SWModule *module,
+ const sword::SWKey *key)
+ : sword::OSISHTMLHREF::MyUserData(module, key),
+ swordFootnote(1), inCrossrefNote(false),
+ entryAttributes(module->getEntryAttributes()),
+ noteType(Unknown) {}
+
+ unsigned short int swordFootnote;
+ bool inCrossrefNote;
+ sword::AttributeTypeList entryAttributes;
+
+ enum NoteType {
+ Unknown,
+ Alternative,
+ CrossReference,
+ Footnote,
+ StrongsMarkup
+ } noteType;
+
+ struct {
+ sword::SWBuf who;
+ } quote;
+ };
+
+ public: /* Methods: */
+ OsisToHtml();
+
+ /** Reimplemented from sword::OSISHTMLHREF. */
+ virtual bool handleToken(sword::SWBuf &buf,
+ const char *token,
+ sword::BasicFilterUserData *userData);
+
+ protected: /* Methods: */
+ /** Reimplemented from sword::OSISHTMLHREF. */
+ virtual inline sword::BasicFilterUserData *createUserData(
+ const sword::SWModule *module,
+ const sword::SWKey *key)
+ {
+ return new UserData(module, key);
+ }
+
+ private: /* Methods: */
+ void renderReference(const char *osisRef, sword::SWBuf &buf,
+ sword::SWModule *myModule, UserData *myUserData);
+};
+
+} // namespace Filters
+
+#endif
diff --git a/src/backend/filters/bt_plainhtml.cpp b/src/backend/filters/plaintohtml.cpp
index c70db79..bc19440 100644
--- a/src/backend/filters/bt_plainhtml.cpp
+++ b/src/backend/filters/plaintohtml.cpp
@@ -2,19 +2,19 @@
*
* 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/filters/bt_plainhtml.h"
+#include "backend/filters/plaintohtml.h"
-Filters::BT_PLAINHTML::BT_PLAINHTML() : sword::SWFilter() {
+Filters::PlainToHtml::PlainToHtml() : sword::SWFilter() {
}
/** No descriptions */
-char Filters::BT_PLAINHTML::processText(sword::SWBuf& text, const sword::SWKey* /*key*/, const sword::SWModule* /*module*/) {
+char Filters::PlainToHtml::processText(sword::SWBuf& text, const sword::SWKey* /*key*/, const sword::SWModule* /*module*/) {
int count = 0;
sword::SWBuf orig = text;
diff --git a/src/backend/filters/plaintohtml.h b/src/backend/filters/plaintohtml.h
new file mode 100644
index 0000000..1093e2c
--- /dev/null
+++ b/src/backend/filters/plaintohtml.h
@@ -0,0 +1,40 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2011 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef FILTERS_PLAINTOHTML_H
+#define FILTERS_PLAINTOHTML_H
+
+// Sword includes:
+#include <swbuf.h>
+#include <swfilter.h>
+
+namespace sword {
+ class SWKey;
+ class SWModule;
+}
+
+namespace Filters {
+
+/**
+ \brief Plain text to HTML conversion filter.
+*/
+class PlainToHtml: public sword::SWFilter {
+ public: /* Methods: */
+ PlainToHtml();
+
+ protected: /* Methods: */
+ /** Reimplemented from sword::SWFilter. */
+ virtual char processText(sword::SWBuf &buf,
+ const sword::SWKey *key,
+ const sword::SWModule *module = 0);
+};
+
+} // namespace Filters
+
+#endif
diff --git a/src/backend/filters/bt_teihtml.cpp b/src/backend/filters/teitohtml.cpp
index b242f46..4b390d5 100644
--- a/src/backend/filters/bt_teihtml.cpp
+++ b/src/backend/filters/teitohtml.cpp
@@ -2,19 +2,18 @@
*
* 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/filters/bt_teihtml.h"
+#include "backend/filters/teitohtml.h"
#include <QString>
#include "backend/config/cbtconfig.h"
#include "backend/drivers/cswordmoduleinfo.h"
#include "backend/managers/clanguagemgr.h"
#include "backend/managers/referencemanager.h"
-#include "util/cpointers.h"
// Sword includes:
#include <swbuf.h>
@@ -22,12 +21,17 @@
#include <utilxml.h>
+namespace Filters {
-Filters::BT_TEIHTML::BT_TEIHTML() : sword::TEIHTMLHREF() {
- setPassThruUnknownEscapeString(true); //the HTML widget will render the HTML escape codes
+TeiToHtml::TeiToHtml()
+ : sword::TEIHTMLHREF()
+{
+ setPassThruUnknownEscapeString(true); // the HTML widget will render the HTML escape codes
}
-bool Filters::BT_TEIHTML::handleToken(sword::SWBuf &buf, const char *token, sword::BasicFilterUserData *userData) {
+bool TeiToHtml::handleToken(sword::SWBuf &buf, const char *token,
+ sword::BasicFilterUserData *userData)
+{
// manually process if it wasn't a simple substitution
if (!substituteToken(buf, token)) {
@@ -93,7 +97,9 @@ bool Filters::BT_TEIHTML::handleToken(sword::SWBuf &buf, const char *token, swor
return false;
}
-void Filters::BT_TEIHTML::renderReference(const char *osisRef, sword::SWBuf &buf, sword::BasicFilterUserData *myUserData) {
+void TeiToHtml::renderReference(const char *osisRef, sword::SWBuf &buf,
+ sword::BasicFilterUserData *myUserData)
+{
QString ref( osisRef );
QString hrefRef( ref );
@@ -113,8 +119,8 @@ void Filters::BT_TEIHTML::renderReference(const char *osisRef, sword::SWBuf &buf
QString newModuleName = ref.left(pos);
hrefRef = ref.mid(pos + 1);
- if (CPointers::backend()->findModuleByName(newModuleName)) {
- mod = CPointers::backend()->findModuleByName(newModuleName);
+ if (CSwordBackend::instance()->findModuleByName(newModuleName)) {
+ mod = CSwordBackend::instance()->findModuleByName(newModuleName);
}
}
@@ -141,3 +147,4 @@ void Filters::BT_TEIHTML::renderReference(const char *osisRef, sword::SWBuf &buf
}
}
+} // namespace Filters
diff --git a/src/backend/filters/teitohtml.h b/src/backend/filters/teitohtml.h
new file mode 100644
index 0000000..6fcc2c6
--- /dev/null
+++ b/src/backend/filters/teitohtml.h
@@ -0,0 +1,37 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2011 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef FILTERS_TEITOHTML_H
+#define FILTERS_TEITOHTML_H
+
+// Sword includes:
+#include <teihtmlhref.h>
+#include <swbuf.h>
+
+namespace Filters {
+
+/**
+ \brief TEI to HTML conversion filter.
+*/
+class TeiToHtml: public sword::TEIHTMLHREF {
+ public: /* Methods: */
+ TeiToHtml();
+
+ /** Reimplemented from sword::OSISHTMLHREF. */
+ virtual bool handleToken(sword::SWBuf &buf, const char *token,
+ sword::BasicFilterUserData *userData);
+
+ private: /* Methods: */
+ void renderReference(const char *osisRef, sword::SWBuf &buf,
+ sword::BasicFilterUserData *myUserData);
+};
+
+} // namespace Filters
+
+#endif
diff --git a/src/backend/filters/bt_thmlhtml.cpp b/src/backend/filters/thmltohtml.cpp
index 478339c..703b362 100644
--- a/src/backend/filters/bt_thmlhtml.cpp
+++ b/src/backend/filters/thmltohtml.cpp
@@ -2,12 +2,12 @@
*
* 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/filters/bt_thmlhtml.h"
+#include "backend/filters/thmltohtml.h"
#include <QString>
#include <QRegExp>
@@ -17,7 +17,6 @@
#include "backend/drivers/cswordmoduleinfo.h"
#include "backend/managers/clanguagemgr.h"
#include "backend/managers/referencemanager.h"
-#include "util/cpointers.h"
// Sword includes:
#include <swmodule.h>
@@ -26,7 +25,9 @@
#include <versekey.h>
-Filters::BT_ThMLHTML::BT_ThMLHTML() {
+namespace Filters {
+
+ThmlToHtml::ThmlToHtml() {
setEscapeStringCaseSensitive(true);
setPassThruUnknownEscapeString(true); //the HTML widget will render the HTML escape codes
@@ -40,10 +41,12 @@ Filters::BT_ThMLHTML::BT_ThMLHTML() {
removeTokenSubstitute("/note");
}
-char Filters::BT_ThMLHTML::processText(sword::SWBuf& buf, const sword::SWKey* key, const sword::SWModule* module) {
+char ThmlToHtml::processText(sword::SWBuf &buf, const sword::SWKey *key,
+ const sword::SWModule *module)
+{
sword::ThMLHTML::processText(buf, key, module);
- CSwordModuleInfo* m = CPointers::backend()->findModuleByName( module->Name() );
+ CSwordModuleInfo* m = CSwordBackend::instance()->findModuleByName( module->Name() );
if (m && !(m->has(CSwordModuleInfo::lemmas) || m->has(CSwordModuleInfo::strongNumbers))) { //only parse if the module has strongs or lemmas
return 1;
@@ -195,17 +198,19 @@ char Filters::BT_ThMLHTML::processText(sword::SWBuf& buf, const sword::SWKey* ke
}
-bool Filters::BT_ThMLHTML::handleToken(sword::SWBuf &buf, const char *token, sword::BasicFilterUserData *userData) {
+bool ThmlToHtml::handleToken(sword::SWBuf &buf, const char *token,
+ sword::BasicFilterUserData *userData)
+{
if (!substituteToken(buf, token) && !substituteEscapeString(buf, token)) {
sword::XMLTag tag(token);
- BT_UserData* myUserData = dynamic_cast<BT_UserData*>(userData);
+ UserData* myUserData = dynamic_cast<UserData*>(userData);
sword::SWModule* myModule = const_cast<sword::SWModule*>(myUserData->module); //hack to be able to call stuff like Lang()
if ( tag.getName() && !sword::stricmp(tag.getName(), "foreign") ) { // a text part in another language, we have to set the right font
if (tag.getAttribute("lang")) {
const char* abbrev = tag.getAttribute("lang");
- //const CLanguageMgr::Language* const language = CPointers::languageMgr()->languageForAbbrev( QString::fromLatin1(abbrev) );
+ //const CLanguageMgr::Language* const language = CLanguageMgr::instance()->languageForAbbrev( QString::fromLatin1(abbrev) );
buf.append("<span class=\"foreign\" lang=\"");
buf.append(abbrev);
@@ -383,3 +388,5 @@ bool Filters::BT_ThMLHTML::handleToken(sword::SWBuf &buf, const char *token, swo
return true;
}
+
+} // namespace Filtes
diff --git a/src/backend/filters/thmltohtml.h b/src/backend/filters/thmltohtml.h
new file mode 100644
index 0000000..99bbabb
--- /dev/null
+++ b/src/backend/filters/thmltohtml.h
@@ -0,0 +1,62 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2011 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef FILTERS_THMLTOHTML_H
+#define FILTERS_THMLTOHTML_H
+
+// Sword includes:
+#include <swbuf.h>
+#include <thmlhtml.h>
+
+
+namespace Filters {
+
+/**
+ \brief ThML to HTML conversion filter.
+*/
+class ThmlToHtml: public sword::ThMLHTML {
+ protected: /* Types: */
+ class UserData: public sword::ThMLHTML::MyUserData {
+ public:
+ inline UserData(const sword::SWModule *module,
+ const sword::SWKey *key)
+ : sword::ThMLHTML::MyUserData(module, key),
+ inscriptRef(false), inFootnoteTag(false),
+ swordFootnote(1) {}
+
+ bool inscriptRef;
+ bool inFootnoteTag;
+ unsigned short int swordFootnote;
+ };
+
+ public: /* Methods: */
+ ThmlToHtml();
+
+ /** Reimplemented from sword::OSISHTMLHREF. */
+ virtual bool handleToken(sword::SWBuf &buf,
+ const char *token,
+ sword::BasicFilterUserData *userData);
+
+ /** Reimplemented from sword::SWFilter. */
+ virtual char processText(sword::SWBuf &buf,
+ const sword::SWKey *key,
+ const sword::SWModule *module = 0);
+
+ protected: /* Methods: */
+ /** Reimplemented from sword::OSISHTMLHREF. */
+ virtual inline sword::BasicFilterUserData *createUserData(
+ const sword::SWModule *module, const sword::SWKey *key)
+ {
+ return new UserData(module, key);
+ }
+};
+
+} // namespace Filters
+
+#endif
diff --git a/src/backend/filters/bt_thmlplain.cpp b/src/backend/filters/thmltoplain.cpp
index ecd7bbd..42f383e 100644
--- a/src/backend/filters/bt_thmlplain.cpp
+++ b/src/backend/filters/thmltoplain.cpp
@@ -2,24 +2,25 @@
*
* 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.
*
**********/
-/******************************************************************************
- *
- * thmlplain - SWFilter descendant to strip out all ThML tags or convert to
- * ASCII rendered symbols.
- */
+#include "backend/filters/thmltoplain.h"
-#include "backend/filters/bt_thmlplain.h"
+#include <QtGlobal>
-Filters::BT_ThMLPlain::BT_ThMLPlain() {
-}
+namespace Filters {
+
+char ThmlToPlain::processText(sword::SWBuf &text,
+ const sword::SWKey *key,
+ const sword::SWModule *module)
+{
+ Q_UNUSED(key);
+ Q_UNUSED(module);
-char Filters::BT_ThMLPlain::processText(sword::SWBuf &text, const sword::SWKey* /*key*/, const sword::SWModule* /*module*/) {
char token[2048];
int tokpos = 0;
bool intoken = false;
@@ -197,7 +198,7 @@ char Filters::BT_ThMLPlain::processText(sword::SWBuf &text, const sword::SWKey*
token[tokpos++] = *from;
token[tokpos+2] = 0;
}
- else text += *from;
+ else text += *from;
}
orig = text;
@@ -218,3 +219,4 @@ char Filters::BT_ThMLPlain::processText(sword::SWBuf &text, const sword::SWKey*
return 0;
}
+} // namespace Filters
diff --git a/src/backend/filters/thmltoplain.h b/src/backend/filters/thmltoplain.h
new file mode 100644
index 0000000..77e2a2b
--- /dev/null
+++ b/src/backend/filters/thmltoplain.h
@@ -0,0 +1,33 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2011 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef FILTERS_THMLTOPLAIN_H
+#define FILTERS_THMLTOPLAIN_H
+
+// Sword includes:
+#include <swbuf.h>
+#include <swfilter.h>
+
+
+namespace Filters {
+
+/**
+ \brief ThML text to plain text conversion filter
+*/
+class ThmlToPlain: public sword::SWFilter {
+ protected: /* Methods: */
+ /** Reimplemented from sword::SWFilter. */
+ virtual char processText(sword::SWBuf &text,
+ const sword::SWKey *key = 0,
+ const sword::SWModule *module = 0);
+};
+
+} // namespace Filters
+
+#endif
diff --git a/src/backend/keys/cswordkey.cpp b/src/backend/keys/cswordkey.cpp
index 24f4909..9c5b25b 100644
--- a/src/backend/keys/cswordkey.cpp
+++ b/src/backend/keys/cswordkey.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,6 +16,7 @@
#include "backend/keys/cswordldkey.h"
#include "backend/keys/cswordtreekey.h"
#include "backend/keys/cswordversekey.h"
+#include "util/btsignal.h"
// Sword includes:
#include <swkey.h>
@@ -26,12 +27,21 @@
#include <versekey.h>
-CSwordKey::CSwordKey(CSwordModuleInfo* const module) : m_module(module) {}
+const QTextCodec *CSwordKey::m_cp1252Codec = QTextCodec::codecForName("Windows-1252");
-CSwordKey::CSwordKey(const CSwordKey& k) {
+CSwordKey::CSwordKey(const CSwordModuleInfo * const module)
+ : m_module(module),
+ m_signal(0) {}
+
+CSwordKey::CSwordKey(const CSwordKey& k)
+ : m_signal(0) {
m_module = k.m_module;
}
+CSwordKey::~CSwordKey() {
+ delete m_signal;
+}
+
QString CSwordKey::rawText() {
if (!m_module) return QString::null;
@@ -51,7 +61,6 @@ QString CSwordKey::renderedText( const CSwordKey::TextRenderType mode ) {
if (k) {
sword::VerseKey* vk_mod = dynamic_cast<sword::VerseKey*>(m_module->module()->getKey());
-
if (vk_mod) {
vk_mod->Headings(1);
}
@@ -74,25 +83,26 @@ QString CSwordKey::renderedText( const CSwordKey::TextRenderType mode ) {
//Q_ASSERT(!key().isNull());
if (!key().isNull()) { //we have valid text
- bool DoRender = (mode == ProcessEntryAttributesOnly) ? 0 : 1;
- QString text = QString::fromUtf8( m_module->module()->RenderText(0, -1, DoRender) );
- if (!DoRender) return QString::null;
+ bool DoRender = mode != ProcessEntryAttributesOnly;
+ QString text = QString::fromUtf8( m_module->module()->RenderText(0,-1, DoRender));
+ if (!DoRender)
+ return QString::null;
// This is yucky, but if we want strong lexicon refs we have to do it here.
if (m_module->type() == CSwordModuleInfo::Lexicon) {
QString t(text);
- QRegExp rx("(GREEK|HEBREW) for 0*([1-9]\\d*)"); // ignore 0's before number
+ QRegExp rx("(GREEK|HEBREW) for 0*([1-9]\\d*)"); // ignore 0's before number
int pos = 0;
while ( (pos = rx.indexIn(t, pos)) != -1 ) {
QString language = rx.cap(1);
- QString langcode = QString(language.at(0)); // "G" or "H"
+ QString langcode = QString(language.at(0)); // "G" or "H"
QString number = rx.cap(2);
- QString paddednumber = number.rightJustified(5, '0'); // Form 00123
+ QString paddednumber = number.rightJustified(5, '0'); // Form 00123
text.replace(
QRegExp( QString(
- "(>[^<>]+)" // Avoid replacing inside tags
- "\\b(0*%1)\\b").arg(number) ), // And span around 0's
+ "(>[^<>]+)" // Avoid replacing inside tags
+ "\\b(0*%1)\\b").arg(number) ), // And span around 0's
QString("\\1<span lemma=\"%1%2\"><a href=\"strongs://%3/%4\">\\2</a></span>")
.arg(langcode, paddednumber, language, paddednumber)
);
@@ -101,23 +111,22 @@ QString CSwordKey::renderedText( const CSwordKey::TextRenderType mode ) {
}
if (mode == HTMLEscaped) {
- //we have to encode all UTF-8 in HTML escapes
- // go though every character and write down the escaped HTML unicode entity
- // form is &#<decimal unicode value here>;
+ /*
+ Here we encode all non-latin1 characters as HTML unicode entities
+ in the form &#<decimal unicode value here>;
+ */
QString ret;
- QChar c;
- const unsigned int length = text.length();
- for (unsigned int i = 0; i < length; ++i) {
- c = text.at(i);
+ // Reserve characters to reduce number of memory allocations:
+ ret.reserve(text.size());
+
+ for (int i = 0; i < text.size(); ++i) {
+ const QChar c = text.at(i);
- if (c.toLatin1()) { //normal latin1 character
+ if (c.toLatin1()) {
ret.append(c);
- }
- else {//unicode character, needs to be escaped
- ret.append("&#")
- .append(c.unicode())
- .append(";");
+ } else {
+ ret.append("&#").append(c.unicode()).append(";");
}
}
@@ -144,14 +153,13 @@ QString CSwordKey::strippedText() {
return QString::fromUtf8( m_module->module()->StripText() );
}
-const QTextCodec* CSwordKey::cp1252Codec() {
- static QTextCodec * codec = QTextCodec::codecForName("Windows-1252");
- return codec;
+void CSwordKey::emitChanged() {
+ if (m_signal.isNull()) return;
+ m_signal->emitChanged();
}
-
/** This will create a proper key object from a given module */
-CSwordKey* CSwordKey::createInstance( CSwordModuleInfo* const module ) {
+CSwordKey *CSwordKey::createInstance(const CSwordModuleInfo *module) {
if (!module) {
return 0;
}
@@ -173,3 +181,9 @@ CSwordKey* CSwordKey::createInstance( CSwordModuleInfo* const module ) {
return 0;
}
}
+
+const BtSignal* CSwordKey::signaler() {
+ if (m_signal.isNull())
+ m_signal = new BtSignal();
+ return m_signal;
+}
diff --git a/src/backend/keys/cswordkey.h b/src/backend/keys/cswordkey.h
index d1924d6..48e511c 100644
--- a/src/backend/keys/cswordkey.h
+++ b/src/backend/keys/cswordkey.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.
*
**********/
@@ -10,89 +10,103 @@
#ifndef CSWORDKEY_H
#define CSWORDKEY_H
+#include <QPointer>
#include <QString>
class CSwordModuleInfo;
class QTextCodec;
+class BtSignal;
/** Base class for all keys.
* The base class for all Sword based keys.
* @author The BibleTime team
* @version $Id: cswordkey.h,v 1.27 2006/10/30 19:53:32 mgruner Exp $
*/
-
class CSwordKey {
-
protected:
- /** Constructor. May only be called from sublasses because this class contains pure virtual methods.
- * @param module The module which belongs to this key, may be NULL
- */
- CSwordKey(CSwordModuleInfo* const module = 0); //protected constructor, because CSwordKey shouldn't be used (it's an abstract base class).
- /** Copy constructor.
+ /**
+ \param module The module which belongs to this key, may be NULL
*/
- CSwordKey(const CSwordKey&); //copy constructor
+ CSwordKey(const CSwordModuleInfo * const module = 0);
+
+ CSwordKey(const CSwordKey &copy);
public:
enum TextRenderType {
Normal = 0,
HTMLEscaped = 1,
- ProcessEntryAttributesOnly = 2 // in this case, renderText() will not return text, but only cause EntryAttribute processing
+ ProcessEntryAttributesOnly = 2 // in this case, renderText() will not return text, but only cause EntryAttribute processing
};
- /** Destructor.
- * Public, not protected like the constructor, because CSwordKey pointers may be deleted by all others.
- */
- virtual ~CSwordKey() {};
- //pure virtual functions
+ virtual ~CSwordKey();
+
/** Returns the current key.
- * @return The current key which belongs to the current object.
+ * @return The key which belongs to the current object.
*/
virtual QString key() const = 0;
- /** Sets the current key. Sets the key using a utf8 enabled QString.
- * @param key The key which should be used to set the current one
- */
- virtual bool key(const QString& key) = 0;
- /** Set the key using a utf8-decoded c-string
- * @param key The key which should be used to set the current one
- */
- virtual bool key(const char* key) = 0;
+
+ /**
+ Sets the current key. Sets the key using a utf8 enabled QString.
+ \param key The key which should be used to set the current one.
+ */
+ virtual bool setKey(const QString &key) = 0;
+
+ /**
+ Set the key using a utf8-decoded c-string.
+ \param key The key which should be used to set the current one.
+ */
+ virtual bool setKey(const char *key) = 0;
+
/** Clone this object. Clone this current object and return it.
* @return A clone of the current object.
*/
virtual CSwordKey* copy() const = 0;
- //implemented functions
- /** Set/get the module. Set and get the module which belongs to this key.
- * @return The module which belongs to this key.
- */
- inline virtual CSwordModuleInfo* module(CSwordModuleInfo* const newModule = 0);
+ /**
+ \returns the module which belongs to this key.
+ */
+ inline const CSwordModuleInfo *module() const {
+ return m_module;
+ }
+
+ /**
+ Sets the module which belongs to this key.
+ \param[in] newModule the module to set.
+ */
+ virtual inline void setModule(const CSwordModuleInfo *newModule) {
+ m_module = newModule;
+ }
+
/** Returns the raw, unchanged text. Returns the text without any filter modifications,
* just in the way it comes out of the module.
*/
virtual QString rawText();
- /** Returns the rendered text. Returns the text of the current key after passign it through the
+ /** Returns the rendered text. Returns the text of the current key after passing it through the
* modules filters.
*/
virtual QString renderedText( const CSwordKey::TextRenderType mode = CSwordKey::Normal );
/** Stripped down text. Returns the text after removing all markup tags from it.
*/
virtual QString strippedText();
+
+ const BtSignal *signaler();
+
/**
* This returns a new object of the right CSwordKey* implementation
* (e.g. CSwordVerseKey or CSwordLDKey)
* The type is determined by the type of the module.
* @see CSwordModuleInfo, CSwordBibleModuleInfo, CSwordCommentaryModuleInfo, CSwordLexiconModukleInfo
*/
- static CSwordKey* createInstance(CSwordModuleInfo * const module);
+ static CSwordKey* createInstance(const CSwordModuleInfo *module);
protected:
/**
* Returns the encoded key appropriate for use directly with Sword.
*/
virtual const char * rawKey() const = 0;
- static const QTextCodec* cp1252Codec();
- CSwordModuleInfo* m_module; //module pointer used by all keys
+ static inline const QTextCodec *cp1252Codec() { return m_cp1252Codec; };
+ void emitChanged();
private:
/**
@@ -100,13 +114,10 @@ class CSwordKey {
*/
CSwordKey& operator= ( const CSwordKey & );
+ protected:
+ static const QTextCodec *m_cp1252Codec;
+ const CSwordModuleInfo *m_module;
+ QPointer<BtSignal> m_signal;
};
-inline CSwordModuleInfo* CSwordKey::module(CSwordModuleInfo* const newModule) {
- if (newModule) {
- m_module = newModule;
- }
- return m_module;
-}
-
#endif
diff --git a/src/backend/keys/cswordldkey.cpp b/src/backend/keys/cswordldkey.cpp
index bc1e2c1..ecde8b7 100644
--- a/src/backend/keys/cswordldkey.cpp
+++ b/src/backend/keys/cswordldkey.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.
*
**********/
@@ -18,8 +18,8 @@
#include <utilstr.h>
-CSwordLDKey::CSwordLDKey( CSwordModuleInfo* module ) {
- if ((m_module = dynamic_cast<CSwordLexiconModuleInfo*>(module))) {
+CSwordLDKey::CSwordLDKey(const CSwordModuleInfo *module) {
+ if ((m_module = dynamic_cast<const CSwordLexiconModuleInfo*>(module))) {
// *(m_module->module()) = TOP;
}
@@ -30,7 +30,11 @@ CSwordLDKey::CSwordLDKey( CSwordModuleInfo* module ) {
CSwordLDKey::CSwordLDKey( const CSwordLDKey &k ) : CSwordKey(k), SWKey((const char*)k) {}
/** No descriptions */
-CSwordLDKey::CSwordLDKey( const SWKey *k, CSwordModuleInfo* module) : CSwordKey(module), SWKey(*k) {}
+CSwordLDKey::CSwordLDKey(const SWKey *k, const CSwordModuleInfo *module)
+ : CSwordKey(module), SWKey(*k)
+{
+ // Intentionally empty
+}
/** Clones this object by copying the members. */
CSwordLDKey* CSwordLDKey::copy() const {
@@ -38,14 +42,14 @@ CSwordLDKey* CSwordLDKey::copy() const {
}
/** 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;
+void CSwordLDKey::setModule(const CSwordModuleInfo *newModule) {
+ Q_ASSERT(newModule);
+ if (m_module == newModule) return;
+ Q_ASSERT(newModule->type() == CSwordModuleInfo::Lexicon);
+
+ const QString oldKey = key();
+ m_module = newModule;
+ setKey(oldKey);
}
QString CSwordLDKey::key() const {
@@ -61,23 +65,23 @@ QString CSwordLDKey::key() const {
}
const char * CSwordLDKey::rawKey() const {
- return (const char*)*this;
+ return getText();
}
-bool CSwordLDKey::key( const QString& newKey ) {
+bool CSwordLDKey::setKey(const QString &newKey) {
Q_ASSERT(m_module);
if (m_module->isUnicode()) {
- return key(newKey.toUtf8().constData());
+ return setKey(newKey.toUtf8().constData());
}
else {
- return key((const char*)cp1252Codec()->fromUnicode(newKey));
+ return setKey((const char*)cp1252Codec()->fromUnicode(newKey));
}
}
/** Sets the key of this instance */
-bool CSwordLDKey::key( const char* newKey ) {
+bool CSwordLDKey::setKey(const char *newKey) {
Q_ASSERT(newKey);
if (newKey) {
@@ -98,7 +102,7 @@ CSwordLDKey* CSwordLDKey::NextEntry() {
( *( m_module->module() ) )++;
m_module->module()->setSkipConsecutiveLinks(false);
- key(m_module->module()->KeyText());
+ setKey(m_module->module()->KeyText());
SWKey::operator = (m_module->module()->KeyText());
return this;
diff --git a/src/backend/keys/cswordldkey.h b/src/backend/keys/cswordldkey.h
index 2e460d7..ed43ce7 100644
--- a/src/backend/keys/cswordldkey.h
+++ b/src/backend/keys/cswordldkey.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.
*
**********/
@@ -52,19 +52,19 @@ class CSwordLDKey : public CSwordKey, public sword::SWKey {
public:
/**
- * Constructor of CSwordLDKey
+ \todo Document param
*/
- CSwordLDKey( CSwordModuleInfo* module );
- /**
- * Copy constructor for this key class.
- */
- CSwordLDKey( const CSwordLDKey &k );
+ CSwordLDKey(const CSwordModuleInfo *module);
+
+ CSwordLDKey(const CSwordLDKey &copy);
+
/**
- * Copy constructor for this key class.
+ \todo Document params
*/
- CSwordLDKey( const sword::SWKey *k, CSwordModuleInfo* module);
+ CSwordLDKey(const sword::SWKey *k, const CSwordModuleInfo *module);
+
/**
- * Clones this object by copying the members.
+ Reimplementation of CSwordKey::copy()
*/
virtual CSwordLDKey* copy() const;
/**
@@ -75,22 +75,26 @@ class CSwordLDKey : public CSwordKey, public sword::SWKey {
* Uses the parameter to returns the previous entry afer this key.
*/
CSwordLDKey* PreviousEntry( void );
+
/**
- * Sets the module of this key.
+ Sets the module of this key.
*/
- virtual CSwordModuleInfo* module( CSwordModuleInfo* const module = 0 );
+ virtual void setModule(const CSwordModuleInfo *module);
+
/**
* Returns the current key as a QString
*/
virtual QString key() const;
+
/**
- * Set the current key using unicode decoded QString.
+ Reimplemented from CSwordKey::setKey(const QString &key).
*/
- virtual bool key( const QString& newKey );
+ virtual bool setKey(const QString &newKey);
+
/**
- * Set the current key from char*. To avoid encoding problems use key(QString) instead.
+ Reimplemented from CSwordKey::setKey(const char *key).
*/
- virtual bool key( const char* );
+ virtual bool setKey(const char *key);
protected:
/**
diff --git a/src/backend/keys/cswordtreekey.cpp b/src/backend/keys/cswordtreekey.cpp
index e1ac9c3..4ea624f 100644
--- a/src/backend/keys/cswordtreekey.cpp
+++ b/src/backend/keys/cswordtreekey.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,7 +16,12 @@
CSwordTreeKey::CSwordTreeKey( const CSwordTreeKey& k ) : CSwordKey(k), TreeKeyIdx(k) {}
-CSwordTreeKey::CSwordTreeKey( const TreeKeyIdx *k, CSwordModuleInfo* module ) : CSwordKey(module), TreeKeyIdx(*k) {}
+CSwordTreeKey::CSwordTreeKey(const TreeKeyIdx *k,
+ const CSwordModuleInfo *module)
+ : CSwordKey(module), TreeKeyIdx(*k)
+{
+ // Intentionally empty
+}
CSwordTreeKey* CSwordTreeKey::copy() const {
return new CSwordTreeKey(*this);
@@ -38,19 +43,19 @@ const char * CSwordTreeKey::rawKey() const {
return getText();
}
-bool CSwordTreeKey::key( const QString& newKey ) {
+bool CSwordTreeKey::setKey(const QString &newKey) {
//return key( newKey.toLocal8Bit().constData() );
//return key(m_module->getTextCodec()->fromUnicode(newKey).constData());
Q_ASSERT(m_module);
if (m_module->isUnicode()) {
- return key(newKey.toUtf8().constData());
+ return setKey(newKey.toUtf8().constData());
}
else {
- return key((const char*)cp1252Codec()->fromUnicode(newKey));
+ return setKey((const char*)cp1252Codec()->fromUnicode(newKey));
}
}
-bool CSwordTreeKey::key( const char* newKey ) {
+bool CSwordTreeKey::setKey(const char *newKey) {
Q_ASSERT(newKey);
if (newKey) {
@@ -75,21 +80,21 @@ QString CSwordTreeKey::getLocalNameUnicode() {
}
}
-CSwordModuleInfo* CSwordTreeKey::module( CSwordModuleInfo* const newModule ) {
- if (newModule && (newModule != m_module) && (newModule->type() == CSwordModuleInfo::GenericBook) ) {
- m_module = newModule;
+void CSwordTreeKey::setModule(const CSwordModuleInfo *newModule) {
+ Q_ASSERT(newModule);
+ if (m_module == newModule) return;
+ Q_ASSERT(newModule->type() == CSwordModuleInfo::GenericBook);
- const QString oldKey = key();
+ m_module = newModule;
- CSwordBookModuleInfo* newBook = dynamic_cast<CSwordBookModuleInfo*>(newModule);
- copyFrom( *(newBook->tree()) );
+ const QString oldKey = key();
- key(oldKey); //try to restore our old key
+ const CSwordBookModuleInfo *newBook = dynamic_cast<const CSwordBookModuleInfo*>(newModule);
+ copyFrom( *(newBook->tree()) );
- //set the key to the root node
- root();
- firstChild();
- }
+ setKey(oldKey); //try to restore our old key
- return m_module;
+ //set the key to the root node
+ root();
+ firstChild();
}
diff --git a/src/backend/keys/cswordtreekey.h b/src/backend/keys/cswordtreekey.h
index 9a60d5b..d6eb5ec 100644
--- a/src/backend/keys/cswordtreekey.h
+++ b/src/backend/keys/cswordtreekey.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.
*
**********/
@@ -26,18 +26,20 @@ class CSwordModuleInfo;
class CSwordTreeKey : public CSwordKey, public sword::TreeKeyIdx {
public:
- /** Constructor of this CSwordKey implementation.
- * @param k The Sword tree key which belongs to this key
- * @param module The module which belongs to this key
- */
- CSwordTreeKey( const sword::TreeKeyIdx *k, CSwordModuleInfo* module );
- /** Copy constructor.
+ /**
+ \param k The Sword tree key which belongs to this key
+ \param module The module which belongs to this key
*/
+ CSwordTreeKey(const sword::TreeKeyIdx *k,
+ const CSwordModuleInfo *module);
+
CSwordTreeKey( const CSwordTreeKey& k );
- /** The module which belongs to this key.
- * @return The module.
- */
- virtual CSwordModuleInfo* module( CSwordModuleInfo* const newModule );
+
+ /**
+ Reimplemented from CSwordKey.
+ */
+ virtual void setModule(const CSwordModuleInfo *newModule);
+
/** Copy method.
* @return A new copy of this object.
*/
@@ -53,15 +55,16 @@ class CSwordTreeKey : public CSwordKey, public sword::TreeKeyIdx {
* Returns the current key as unicode decoded QString.
*/
virtual QString key() const;
+
/**
- * Set the key. If the parameter is empty or null, the key will be set to "/"
+ Reimplemented from CSwordKey::setKey(const QString &key).
*/
- virtual bool key( const QString& key );
+ virtual bool setKey(const QString &key);
+
/**
- * Set the key from char* To avoid encoding problems use key(QString instead),
- * otherwise it is caller's responsibility to ensure the correct encoding (utf8/latin1).
+ Reimplemented from CSwordKey::setKey(const char *key).
*/
- virtual bool key( const char* key );
+ virtual bool setKey(const char *key);
protected:
/**
diff --git a/src/backend/keys/cswordversekey.cpp b/src/backend/keys/cswordversekey.cpp
index a7e16c5..5ea1455 100644
--- a/src/backend/keys/cswordversekey.cpp
+++ b/src/backend/keys/cswordversekey.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.
*
**********/
@@ -14,19 +14,22 @@
#include "backend/drivers/cswordbiblemoduleinfo.h"
#include "backend/drivers/cswordcommentarymoduleinfo.h"
+#include "util/btsignal.h"
// Sword includes:
#include <swmodule.h>
#include <localemgr.h>
-CSwordVerseKey::CSwordVerseKey( CSwordModuleInfo* const module ) :
- CSwordKey(module) {
- if ( CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(module) ) {
+CSwordVerseKey::CSwordVerseKey(const CSwordModuleInfo *module)
+ : CSwordKey(module)
+{
+ typedef CSwordBibleModuleInfo CSBMI;
+ if (const CSBMI *bible = dynamic_cast<const CSBMI*>(module) ) {
// Copy important settings like versification system
copyFrom((sword::VerseKey*) bible->module()->getKey());
- key( bible->lowerBound().key() );
+ setKey( bible->lowerBound().key() );
}
this->VerseKey::setAutoNormalize(true);
}
@@ -35,7 +38,12 @@ CSwordVerseKey::CSwordVerseKey( const CSwordVerseKey& k ) : CSwordKey(k), VerseK
this->VerseKey::setAutoNormalize(true);
}
-CSwordVerseKey::CSwordVerseKey( const VerseKey* const k, CSwordModuleInfo* const module ) : CSwordKey(module), VerseKey(*k) {}
+CSwordVerseKey::CSwordVerseKey(const VerseKey *k,
+ const CSwordModuleInfo *module)
+ : CSwordKey(module), VerseKey(*k)
+{
+ // Intentionally empty
+}
/** Clones this object. */
CSwordKey* CSwordVerseKey::copy() const {
@@ -43,33 +51,38 @@ CSwordKey* CSwordVerseKey::copy() const {
}
/** Sets the module for this key */
-CSwordModuleInfo* CSwordVerseKey::module( CSwordModuleInfo* const newModule ) {
- if (newModule && ((newModule->type() == CSwordModuleInfo::Bible) || (newModule->type() == CSwordModuleInfo::Commentary) ) ) {
- m_module = newModule;
+void CSwordVerseKey::setModule(const CSwordModuleInfo *newModule) {
+ typedef CSwordBibleModuleInfo CSBMI;
- //check if the module contains the key we present
- CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(newModule);
+ Q_ASSERT(newModule);
+ if (m_module == newModule) return;
+ Q_ASSERT(newModule->type() == CSwordModuleInfo::Bible
+ || newModule->type() == CSwordModuleInfo::Commentary);
- if (_compare(bible->lowerBound()) < 0) {
- key( bible->lowerBound() );
- }
+ m_module = newModule;
- if (_compare(bible->upperBound()) > 0) {
- key( bible->upperBound() );
- }
+ //check if the module contains the key we present
+ const CSBMI* bible = dynamic_cast<const CSBMI*>(newModule);
+
+ if (_compare(bible->lowerBound()) < 0) {
+ setKey(bible->lowerBound());
}
- return dynamic_cast<CSwordBibleModuleInfo*>(m_module);
+ if (_compare(bible->upperBound()) > 0) {
+ setKey(bible->upperBound());
+ }
}
/** Returns the current book as Text, not as integer. */
QString CSwordVerseKey::book( const QString& newBook ) {
+ typedef CSwordBibleModuleInfo CSBMI;
int min = 0;
int max = 1;
- if (CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(module())) {
- const bool hasOT = bible->hasTestament(CSwordBibleModuleInfo::OldTestament);
- const bool hasNT = bible->hasTestament(CSwordBibleModuleInfo::NewTestament);
+ const CSBMI *bible = dynamic_cast<const CSBMI*>(module());
+ if (bible != 0) {
+ const bool hasOT = bible->hasTestament(CSBMI::OldTestament);
+ const bool hasNT = bible->hasTestament(CSBMI::NewTestament);
if (hasOT && hasNT) {
min = 0;
@@ -110,26 +123,37 @@ const char * CSwordVerseKey::rawKey() const {
return getText();
}
-bool CSwordVerseKey::key( const QString& newKey ) {
- return key( newKey.toUtf8().constData() );
+bool CSwordVerseKey::setKey(const QString &newKey) {
+ return setKey(newKey.toUtf8().constData());
}
-bool CSwordVerseKey::key( const char* newKey ) {
- if (newKey && (strlen(newKey) > 0) ) {
- VerseKey::operator = (newKey);
- }
- else if (newKey && !strlen(newKey)) {
- CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(module());
-
- if ( bible ) {
- VerseKey::operator = (bible->lowerBound().key().toUtf8().constData());
+bool CSwordVerseKey::setKey(const char *newKey) {
+ typedef CSwordBibleModuleInfo CSBMI;
+
+ /// \todo Is this check necessary?
+ if (newKey) {
+ /// \todo Is this check necessary?
+ // Check if empty string:
+ if (*newKey != '\0') {
+ positionFrom(newKey);
+ } else {
+ const CSwordModuleInfo *m = module();
+ if (m->type() == CSwordModuleInfo::Bible) {
+ Q_ASSERT(dynamic_cast<const CSBMI*>(m) != 0);
+ const CSBMI *bible = static_cast<const CSBMI*>(m);
+ positionFrom(bible->lowerBound().key().toUtf8().constData());
+ }
}
}
+ /// \todo Do we ALWAYS need to emit this signal and check for errors?
+ emitChanged();
return !Error();
}
bool CSwordVerseKey::next( const JumpType type ) {
+ typedef CSwordBibleModuleInfo CSBMI;
+
Error(); //clear Error status
bool ret = true;
@@ -174,7 +198,7 @@ bool CSwordVerseKey::next( const JumpType type ) {
m_module->module()->setSkipConsecutiveLinks(oldStatus);
if (!m_module->module()->Error()) {
- key( QString::fromUtf8(m_module->module()->KeyText()) );
+ setKey(QString::fromUtf8(m_module->module()->KeyText()));
}
else {
// Verse(Verse()+1);
@@ -196,27 +220,32 @@ bool CSwordVerseKey::next( const JumpType type ) {
return false;
}
- if ( CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(module()) ) {
+ const CSBMI *bible = dynamic_cast<const CSBMI*>(module());
+ if (bible != 0) {
if (_compare(bible->lowerBound()) < 0 ) {
- key( bible->lowerBound() );
+ setKey(bible->lowerBound());
ret = false;
}
if (_compare(bible->upperBound()) > 0 ) {
- key( bible->upperBound() );
+ setKey(bible->upperBound());
ret = false;
}
+ emitChanged();
return ret;
}
else if (Error()) { //we have no module, so take care of VerseKey::Error()
return false;
}
+ emitChanged();
return ret;
}
bool CSwordVerseKey::previous( const JumpType type ) {
+ typedef CSwordBibleModuleInfo CSBMI;
+
bool ret = true;
switch (type) {
@@ -256,7 +285,7 @@ bool CSwordVerseKey::previous( const JumpType type ) {
m_module->module()->setSkipConsecutiveLinks(oldStatus);
if (!m_module->module()->Error()) {
- key( QString::fromUtf8(m_module->module()->KeyText()) );//don't use fromUtf8
+ setKey(QString::fromUtf8(m_module->module()->KeyText()));//don't use fromUtf8
}
else {
ret = false;
@@ -275,22 +304,25 @@ bool CSwordVerseKey::previous( const JumpType type ) {
return false;
}
- if ( CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(module()) ) {
+ const CSBMI *bible = dynamic_cast<const CSBMI*>(module());
+ if (bible != 0) {
if (_compare(bible->lowerBound()) < 0 ) {
- key( bible->lowerBound() );
+ setKey(bible->lowerBound());
ret = false;
}
if (_compare(bible->upperBound()) > 0 ) {
- key( bible->upperBound() );
+ setKey(bible->upperBound());
ret = false;
}
+ emitChanged();
return ret;
}
else if (Error()) {
return false;
}
+ emitChanged();
return ret;
}
diff --git a/src/backend/keys/cswordversekey.h b/src/backend/keys/cswordversekey.h
index bfbfa25..2769cbf 100644
--- a/src/backend/keys/cswordversekey.h
+++ b/src/backend/keys/cswordversekey.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.
*
**********/
@@ -35,8 +35,8 @@ class CSwordModuleInfo;
* @see NextVerse()
* @see PreviousVerse().
*
- * Call the constructor only with a valid verse based modules, otherwise this key will be invalid
- * and the application will probably crash.
+ * Call the constructor only with valid verse based modules, otherwise this key
+ * will be invalid and the application will probably crash.
*
* @version $Id: cswordversekey.h,v 1.26 2006/02/25 11:38:15 joachim Exp $
* @short CSwordKey implementation for Sword's VerseKey.
@@ -53,39 +53,43 @@ class CSwordVerseKey : public CSwordKey, public sword::VerseKey {
};
/**
- * Constructor of this class.
- *
- * This function will construct a versekey with the current module position
- * and it will setup the m_module members.
- *
- */
- CSwordVerseKey( CSwordModuleInfo* const module );
- /**
- * Copy constructor.
+ Constructs a versekey with the current module position and setups
+ the m_module members.
*/
- CSwordVerseKey( const CSwordVerseKey& k );
+ CSwordVerseKey(const CSwordModuleInfo *module);
+
+ CSwordVerseKey(const CSwordVerseKey &copy);
+
/**
- * VerseKey based constructor.
- */
- CSwordVerseKey( const sword::VerseKey* const k, CSwordModuleInfo* const module );
+ * Constructs a CSwordVerseKey using the given module at the position given
+ * by the versekey.
+ *
+ * \param[in] k Position to use.
+ * \param[in] module Module to use.
+ */
+ CSwordVerseKey(const sword::VerseKey *k,
+ const CSwordModuleInfo *module);
+
/**
- * Clones this object.
+ Reimplementation of CSwordKey::copy().
*/
virtual CSwordKey* copy() const;
+
/**
* Set/get the key. If the parameter is not set (means equal to QString::null)
* the used key is returned. Otherwise the key is set and the new on ei returned.
*/
virtual QString key() const;
+
/**
- * Set the current key.
+ Reimplemented from CSwordKey::setKey(const QString &key).
*/
- virtual bool key( const QString& );
+ virtual bool setKey(const QString &key);
+
/**
- * Set/get the key. If the parameter is not set (means equal to QString::null)
- * the used key is returned. Otherwise the key is set and the new on ei returned.
+ Reimplemented from CSwordKey::setKey(const char *key).
*/
- virtual bool key( const char* key );
+ virtual bool setKey(const char *key);
/**
* Jumps to the next entry of the given type
@@ -102,10 +106,11 @@ class CSwordVerseKey : public CSwordKey, public sword::VerseKey {
* @return The name of the current book
*/
QString book(const QString& newBook = QString::null);
+
/**
- * Sets the module for this key
+ Sets the module for this key.
*/
- virtual CSwordModuleInfo* module( CSwordModuleInfo* const newModule = 0 );
+ virtual void setModule(const CSwordModuleInfo *newModule);
protected:
/**
@@ -114,7 +119,7 @@ class CSwordVerseKey : public CSwordKey, public sword::VerseKey {
virtual const char * rawKey() const;
private:
- /** Disable assignment operator */
+ /** Disable assignment operator */
CSwordVerseKey& operator= (const CSwordVerseKey&);
/** Disable from base class to prevent compiler warnings */
inline virtual CSwordVerseKey& operator= (const sword::VerseKey&) {
diff --git a/src/backend/managers/btstringmgr.cpp b/src/backend/managers/btstringmgr.cpp
index a2abc7f..ad1fb3e 100644
--- a/src/backend/managers/btstringmgr.cpp
+++ b/src/backend/managers/btstringmgr.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.
*
**********/
diff --git a/src/backend/managers/btstringmgr.h b/src/backend/managers/btstringmgr.h
index 7f44df8..1cf7170 100644
--- a/src/backend/managers/btstringmgr.h
+++ b/src/backend/managers/btstringmgr.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.
*
**********/
diff --git a/src/backend/managers/cdisplaytemplatemgr.cpp b/src/backend/managers/cdisplaytemplatemgr.cpp
index 11d2a59..b3def8c 100644
--- a/src/backend/managers/cdisplaytemplatemgr.cpp
+++ b/src/backend/managers/cdisplaytemplatemgr.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.
*
**********/
@@ -17,15 +17,38 @@
#include "backend/config/cbtconfig.h"
#include "backend/drivers/cswordmoduleinfo.h"
#include "backend/managers/clanguagemgr.h"
-#include "util/cpointers.h"
#include "util/directory.h"
-CDisplayTemplateMgr::CDisplayTemplateMgr() {
- loadTemplates();
-}
+CDisplayTemplateMgr *CDisplayTemplateMgr::m_instance = 0;
+
+CDisplayTemplateMgr::CDisplayTemplateMgr(QString &errorMessage) {
+ Q_ASSERT(m_instance == 0);
-CDisplayTemplateMgr::~CDisplayTemplateMgr() {
+ m_instance = this;
+ namespace DU = util::directory;
+
+ QStringList filter("*.tmpl");
+
+ // Preload global display templates from disk:
+ QDir td = DU::getDisplayTemplatesDir();
+ Q_FOREACH(QString file, td.entryList(filter, QDir::Files | QDir::Readable))
+ loadTemplate(td.canonicalPath() + "/" + file);
+
+ /*
+ Preload user display templates from disk, overriding any global templates
+ with the same file name:
+ */
+ QDir utd = DU::getUserDisplayTemplatesDir();
+ Q_FOREACH(QString file, utd.entryList(filter, QDir::Files | QDir::Readable))
+ loadTemplate(utd.canonicalPath() + "/" + file);
+
+ if (m_templateMap.contains(defaultTemplate())) {
+ errorMessage = QString::null;
+ } else {
+ errorMessage = QObject::tr("Default template \"%1\" not found!")
+ .arg(defaultTemplate());
+ }
}
const QString CDisplayTemplateMgr::fillTemplate( const QString& name, const QString& content, Settings& settings ) {
@@ -70,9 +93,9 @@ const QString CDisplayTemplateMgr::fillTemplate( const QString& name, const QStr
qDebug() << "There were more than 1 module, create headers";
QString header;
- QList<CSwordModuleInfo*>::iterator end_it = settings.modules.end();
+ QList<const CSwordModuleInfo*>::iterator end_it = settings.modules.end();
- for (QList<CSwordModuleInfo*>::iterator it(settings.modules.begin()); it != end_it; ++it) {
+ for (QList<const CSwordModuleInfo*>::iterator it(settings.modules.begin()); it != end_it; ++it) {
header.append("<th style=\"width:")
.append(QString::number(int( 100.0 / (float)moduleCount )))
.append("%;\">")
@@ -88,7 +111,7 @@ const QString CDisplayTemplateMgr::fillTemplate( const QString& name, const QStr
}
QString langCSS;
- CLanguageMgr::LangMap langMap = CPointers::languageMgr()->availableLanguages();
+ CLanguageMgr::LangMap langMap = CLanguageMgr::instance()->availableLanguages();
qDebug() << "langMap length:" << langMap.count();
qDebug() << "loop through langMap";
@@ -118,7 +141,7 @@ const QString CDisplayTemplateMgr::fillTemplate( const QString& name, const QStr
//at first append the font standard settings for all languages without configured font
// Create a dummy language (the langmap may be empty)
- CLanguageMgr::Language lang_v(QString("en"), QString("English"), QString());
+ CLanguageMgr::Language lang_v(QString("en"), QString("English"), QString::null);
CLanguageMgr::Language* lang = &lang_v;
if (lang && !lang->abbrev().isEmpty()/*&& lang->isValid()*/) {
@@ -132,7 +155,7 @@ const QString CDisplayTemplateMgr::fillTemplate( const QString& name, const QStr
);
}
-// qWarning("Outputing unformated text");
+// qWarning("Outputing unformated text");
const QString t = QString(m_templateMap[ templateName ]) //don't change the map's content directly, use a copy
.replace("#TITLE#", settings.title)
.replace("#LANG_ABBREV#", settings.langAbbrev.isEmpty() ? QString("en") : settings.langAbbrev)
@@ -144,25 +167,13 @@ const QString CDisplayTemplateMgr::fillTemplate( const QString& name, const QStr
return t;
}
-void CDisplayTemplateMgr::loadTemplates() {
- namespace DU = util::directory;
-
- QStringList files;
- foreach (QString file, DU::getDisplayTemplatesDir().entryList(QStringList("*.tmpl"))) {
- files += DU::getDisplayTemplatesDir().canonicalPath() + "/" + file;
- }
- foreach (QString file, DU::getUserDisplayTemplatesDir().entryList(QStringList("*.tmpl"))) {
- files += DU::getUserDisplayTemplatesDir().canonicalPath() + "/" + file;
- }
-
- foreach (QString file, files) {
- QFile f(file);
- if (f.exists() && f.open( QIODevice::ReadOnly )) {
- QString fileContent = QTextStream( &f ).readAll();
+void CDisplayTemplateMgr::loadTemplate(const QString &filename) {
+ QFile f(filename);
+ if (f.open(QIODevice::ReadOnly)) {
+ QString fileContent = QTextStream(&f).readAll();
- if (!fileContent.isEmpty()) {
- m_templateMap[ QFileInfo(file).fileName() ] = fileContent;
- }
+ if (!fileContent.isEmpty()) {
+ m_templateMap[QFileInfo(f).fileName()] = fileContent;
}
}
}
diff --git a/src/backend/managers/cdisplaytemplatemgr.h b/src/backend/managers/cdisplaytemplatemgr.h
index 16725a5..9b96e8b 100644
--- a/src/backend/managers/cdisplaytemplatemgr.h
+++ b/src/backend/managers/cdisplaytemplatemgr.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.
*
**********/
@@ -18,71 +18,82 @@
class CSwordModuleInfo;
/**
- * Manages the display templates used in the filters and display classes.
- * @author The BibleTime team
+ Manages the display templates used in the filters and display classes.
+ \note This is a singleton.
*/
class CDisplayTemplateMgr {
- public:
- /** Settings which are used to fill the content into the template.
+ public: /* Types: */
+ /**
+ Settings which are used to fill the content into the template.
*/
-
struct Settings {
- /** Constructor. Constructs the new settings object. The default values are empty.
- */
- Settings() {
- title = QString::null;
- langAbbrev = QString::null;
- pageCSS_ID = QString::null;
- pageDirection = QString("ltr");
- };
-
- QList<CSwordModuleInfo*> modules; /**< the list of modules */
- QString title; /**< the title which is used for the new processed HTML page */
- QString langAbbrev; /**< the language for the HTML page. */
- QString pageDirection; /**< the language for the HTML page. */
- QString pageCSS_ID; /**< the CSS ID which is used in the content part of the page */
+ Settings() : pageDirection("ltr") {}
+
+ /** The list of modules */
+ QList<const CSwordModuleInfo*> modules;
+
+ /** The title which is used for the new processed HTML page */
+ QString title;
+
+ /** The language for the HTML page. */
+ QString langAbbrev;
+
+ /** The language direction for the HTML page. */
+ QString pageDirection;
+
+ /** The CSS ID which is used in the content part of the page */
+ QString pageCSS_ID;
};
- /** Available templates.
- * @return The list of templates, which are available.
+ public: /* Methods: */
+
+ /**
+ \param[out] errorMessage Set to error string on error, otherwise set
+ to QString::null.
*/
- inline const QStringList availableTemplates();
- /** Fill template. Fill rendered content into the template given by the name.
- * @param name The name of the template
- * @param content The content which should be filled into the template
- * @param settings The settings which are used to process the templating process
- * @return The full HTML template HTML code including the CSS data.
+ explicit CDisplayTemplateMgr(QString &errorMessage);
+
+ /**
+ \returns the list of available templates.
*/
- const QString fillTemplate( const QString& name, const QString& content, Settings& settings);
- /** Default template.
- * @return The i18n'ed name of the default template
+ inline const QStringList availableTemplates() const {
+ return m_templateMap.keys();
+ }
+
+ /**
+ \brief Fills the template.
+
+ Fills rendered content into the template given by the name.
+
+ \param name The name of the template to fill.
+ \param content The content which should be filled into the template.
+ \param settings The settings which are used to process the templating
+ process.
+
+ \returns The full HTML template HTML code including the CSS data.
*/
- inline static const QString defaultTemplate();
-
- protected:
- friend class CPointers;
- /** Display template manager constructor. Protected to just allow CPointers to create objects. */
- CDisplayTemplateMgr();
- /** Destructor. */
- ~CDisplayTemplateMgr();
- /** Does the actual work of loading templates from disk */
- void loadTemplates();
-
- private:
- QMap<QString, QString> m_templateMap;
-};
+ const QString fillTemplate( const QString& name, const QString& content, Settings& settings);
-inline const QString CDisplayTemplateMgr::defaultTemplate() {
- return QString("Blue.tmpl");
-}
+ /**
+ \returns the name of the default template.
+ */
+ inline static const char *defaultTemplate() { return "Blue.tmpl"; }
-/**
- * CDisplayTemplateMgr::availableTemplates()
- */
-inline const QStringList CDisplayTemplateMgr::availableTemplates() {
- return m_templateMap.keys();
-}
+ /**
+ \returns The singleton instance of the instance of this class.
+ */
+ static inline CDisplayTemplateMgr *instance() {
+ Q_ASSERT(m_instance != 0);
+ return m_instance;
+ };
+ private: /* Methods: */
+ /** Preloads a single template from disk: */
+ void loadTemplate(const QString &filename);
+ private: /* Fields: */
+ QMap<QString, QString> m_templateMap;
+ static CDisplayTemplateMgr *m_instance;
+};
#endif
diff --git a/src/backend/managers/clanguagemgr.cpp b/src/backend/managers/clanguagemgr.cpp
index 5c44405..a8d4e1f 100644
--- a/src/backend/managers/clanguagemgr.cpp
+++ b/src/backend/managers/clanguagemgr.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.
*
**********/
@@ -11,7 +11,6 @@
#include "backend/drivers/cswordmoduleinfo.h"
#include "backend/managers/cswordbackend.h"
-#include "util/cpointers.h"
CLanguageMgr::Language::Language() {}
@@ -37,6 +36,22 @@ CLanguageMgr::Language::~Language() {
/****************************************************/
/******************** CLanguageMgr ******************/
/****************************************************/
+
+CLanguageMgr *CLanguageMgr::m_instance = 0;
+
+void CLanguageMgr::destroyInstance() {
+ delete m_instance;
+ m_instance = 0;
+}
+
+CLanguageMgr *CLanguageMgr::instance() {
+ if (m_instance == 0) {
+ m_instance = new CLanguageMgr();
+ }
+
+ return m_instance;
+}
+
CLanguageMgr::CLanguageMgr() : m_langMap() {
m_availableModulesCache.moduleCount = 0;
init();
@@ -50,7 +65,7 @@ CLanguageMgr::~CLanguageMgr() {
}
const CLanguageMgr::LangMap& CLanguageMgr::availableLanguages() {
- QList<CSwordModuleInfo*> mods = CPointers::backend()->moduleList();
+ QList<CSwordModuleInfo*> mods = CSwordBackend::instance()->moduleList();
if ( m_availableModulesCache.moduleCount != (unsigned int)mods.count() ) { //we have to refill the cached map
m_availableModulesCache.availableLanguages.clear();
@@ -98,13 +113,6 @@ const CLanguageMgr::Language* CLanguageMgr::languageForAbbrev( const QString& ab
return newLang;
}
-const CLanguageMgr::Language* CLanguageMgr::languageForName( const QString& name ) const {
- foreach ( const Language* lang, m_langList ) {
- if (lang->name() == name) return lang;
- }
- return &m_defaultLanguage;//invalid language
-}
-
const CLanguageMgr::Language* CLanguageMgr::languageForTranslatedName( const QString& name ) const {
foreach ( const Language* lang, m_langList ) {
if (lang->translatedName() == name) return lang;
diff --git a/src/backend/managers/clanguagemgr.h b/src/backend/managers/clanguagemgr.h
index de716c0..cbe70e9 100644
--- a/src/backend/managers/clanguagemgr.h
+++ b/src/backend/managers/clanguagemgr.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,9 +16,10 @@
#include <QStringList>
-/** Manages the languages of BibleTime and provides functions to work with them.
- * @author The BibleTime team
- */
+/**
+ \brief Manages the languages and provides functions to work with them.
+ \note This is a singleton.
+*/
class CLanguageMgr {
public:
@@ -27,21 +28,21 @@ class CLanguageMgr {
*/
class Language {
public:
- /** Default constructor of a language object.
- * Uses the abbreviation parameter to lookup the
- * language name and to be able to return the name, flag etc.
- * Possible values for abbrev are de, en, fr, it etc.
+ /**
+ Uses the abbreviation parameter to lookup the language name
+ and to be able to return the name, flag etc. Possible values
+ for abbrev are de, en, fr, it etc.
*/
Language();
- /** Copy constructor.
- */
- Language(const Language&);
- /** Constructor which takes all necessary data.
- */
- Language(const QString& abbrev, const QString& englishName, const QString& translatedName, const QStringList& altAbbrevs = QStringList());
- /** Destructor.
- */
+
+ Language(const Language &copy);
+
+ Language(const QString &abbrev, const QString &englishName,
+ const QString &translatedName,
+ const QStringList &altAbbrevs = QStringList());
+
~Language();
+
/** Returns the abbreviation.
* @return The abbreviation of the chosen language.
*/
@@ -88,12 +89,17 @@ class CLanguageMgr {
typedef QHash<QString, const Language*> LangMap;
typedef QHash<QString, const Language*>::const_iterator LangMapIterator;
- /** Constructor.
- */
+
+ /** Returns the singleton instance, creating it if one does not exist. */
+ static CLanguageMgr *instance();
+
+ /** Destroys the singleton instance, if one exists. */
+ static void destroyInstance();
+
CLanguageMgr();
- /** Destructor
- */
+
virtual ~CLanguageMgr();
+
/**
* Returns the standard languages available as standard. Does nothing for Sword.
* @return A LangMap map which contains all known languages
@@ -111,11 +117,7 @@ class CLanguageMgr {
* @return Pointer to a language for the given string abbreviation.
*/
const CLanguageMgr::Language* languageForAbbrev( const QString& abbrev ) const;
- /** Language for english name.
- * @param abbrev The english language name.
- * @return Pointer to a language for the given name
- */
- const CLanguageMgr::Language* languageForName( const QString& language ) const;
+
/** Language for translated language name.
* @param abbrev The translated language name
* @return Pointer to a language for the given translated language name
@@ -142,8 +144,9 @@ class CLanguageMgr {
struct ModuleCache {
unsigned int moduleCount;
LangMap availableLanguages;
- }
- m_availableModulesCache;
+ } m_availableModulesCache;
+
+ static CLanguageMgr *m_instance;
};
#endif
diff --git a/src/backend/managers/cswordbackend.cpp b/src/backend/managers/cswordbackend.cpp
index 4596a61..b5c109f 100644
--- a/src/backend/managers/cswordbackend.cpp
+++ b/src/backend/managers/cswordbackend.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.
*
**********/
@@ -20,16 +20,9 @@
#include "backend/drivers/cswordbookmoduleinfo.h"
#include "backend/drivers/cswordcommentarymoduleinfo.h"
#include "backend/drivers/cswordlexiconmoduleinfo.h"
-#include "backend/filters/bt_gbfhtml.h"
-#include "backend/filters/bt_osishtml.h"
-#include "backend/filters/bt_teihtml.h"
-#include "backend/filters/bt_plainhtml.h"
-#include "backend/filters/bt_thmlhtml.h"
-#include "backend/filters/bt_thmlplain.h"
+#include "backend/filters/thmltoplain.h"
#include "backend/filters/osismorphsegmentation.h"
-#include "backend/rendering/cbookdisplay.h"
-#include "backend/rendering/cchapterdisplay.h"
-#include "backend/rendering/centrydisplay.h"
+#include "btglobal.h"
#include "util/directory.h"
// Sword includes:
@@ -42,52 +35,25 @@
#include <utilstr.h>
-using namespace Filters;
using namespace Rendering;
-CSwordBackend::CSwordBackend()
- : sword::SWMgr(0, 0, false, new sword::EncodingFilterMgr( sword::ENC_UTF8 ), true),
- m_dataModel(this) {
- m_filters.gbf = new BT_GBFHTML();
- m_filters.plain = new BT_PLAINHTML();
- m_filters.thml = new BT_ThMLHTML();
- m_filters.osis = new BT_OSISHTML();
- m_filters.tei = new BT_TEIHTML();
-
- m_displays.entry = new CEntryDisplay();
- m_displays.chapter = new CChapterDisplay();
- m_displays.book = new CBookDisplay();
+CSwordBackend *CSwordBackend::m_instance = 0;
+CSwordBackend::CSwordBackend()
+ : sword::SWMgr(0, 0, false,
+ new sword::EncodingFilterMgr(sword::ENC_UTF8), true),
+ m_dataModel(this)
+{
filterInit();
}
CSwordBackend::CSwordBackend(const QString& path, const bool augmentHome)
: sword::SWMgr(!path.isEmpty() ? path.toLocal8Bit().constData() : 0, false, new sword::EncodingFilterMgr( sword::ENC_UTF8 ), false, augmentHome) { // don't allow module renaming, because we load from a path
- m_filters.gbf = new BT_GBFHTML();
- m_filters.plain = new BT_PLAINHTML();
- m_filters.thml = new BT_ThMLHTML();
- m_filters.osis = new BT_OSISHTML();
- m_filters.tei = new BT_TEIHTML();
-
- m_displays.entry = new CEntryDisplay();
- m_displays.chapter = new CChapterDisplay();
- m_displays.book = new CBookDisplay();
-
filterInit();
}
CSwordBackend::~CSwordBackend() {
shutdownModules();
-
- delete m_filters.gbf;
- delete m_filters.plain;
- delete m_filters.thml;
- delete m_filters.osis;
- delete m_filters.tei;
-
- delete m_displays.book;
- delete m_displays.chapter;
- delete m_displays.entry;
}
void CSwordBackend::filterInit() {
@@ -97,7 +63,7 @@ void CSwordBackend::filterInit() {
optionFilters.erase("OSISMorphSegmentation");
delete filter;
}
- sword::SWOptionFilter* tmpFilter = new OSISMorphSegmentation();
+ sword::SWOptionFilter *tmpFilter = new Filters::OSISMorphSegmentation();
optionFilters.insert(sword::OptionFilterMap::value_type("OSISMorphSegmentation", tmpFilter));
cleanupFilters.push_back(tmpFilter);
@@ -105,7 +71,7 @@ void CSwordBackend::filterInit() {
//remove this hack as soon as Sword is fixed
cleanupFilters.remove(thmlplain);
delete thmlplain;
- thmlplain = new BT_ThMLPlain();
+ thmlplain = new Filters::ThmlToPlain();
cleanupFilters.push_back(thmlplain);
}
@@ -125,10 +91,23 @@ QList<CSwordModuleInfo*> CSwordBackend::takeModulesFromList(QStringList names) {
return list;
}
-QList<CSwordModuleInfo*> CSwordBackend::getPointerList(QStringList names) {
+QList<CSwordModuleInfo*> CSwordBackend::getPointerList(const QStringList &names) {
QList<CSwordModuleInfo*> list;
- foreach(QString name, names) {
- CSwordModuleInfo* mInfo = findModuleByName(name);
+ Q_FOREACH (const QString &name, names) {
+ CSwordModuleInfo *mInfo = findModuleByName(name);
+ if (mInfo) {
+ list.append(mInfo);
+ }
+ }
+ return list;
+}
+
+QList<const CSwordModuleInfo*> CSwordBackend::getConstPointerList(
+ const QStringList &names)
+{
+ QList<const CSwordModuleInfo*> list;
+ Q_FOREACH (const QString &name, names) {
+ const CSwordModuleInfo *mInfo = findModuleByName(name);
if (mInfo) {
list.append(mInfo);
}
@@ -154,19 +133,19 @@ CSwordBackend::LoadError CSwordBackend::initModules(SetupChangedReason reason) {
if (!strcmp(curMod->Type(), "Biblical Texts")) {
newModule = new CSwordBibleModuleInfo(curMod, this);
- newModule->module()->Disp(m_displays.chapter);
+ newModule->module()->Disp(&m_chapterDisplay);
}
else if (!strcmp(curMod->Type(), "Commentaries")) {
newModule = new CSwordCommentaryModuleInfo(curMod, this);
- newModule->module()->Disp(m_displays.entry);
+ newModule->module()->Disp(&m_entryDisplay);
}
else if (!strcmp(curMod->Type(), "Lexicons / Dictionaries")) {
newModule = new CSwordLexiconModuleInfo(curMod, this);
- newModule->module()->Disp(m_displays.entry);
+ newModule->module()->Disp(&m_entryDisplay);
}
else if (!strcmp(curMod->Type(), "Generic Books")) {
newModule = new CSwordBookModuleInfo(curMod, this);
- newModule->module()->Disp(m_displays.book);
+ newModule->module()->Disp(&m_bookDisplay);
}
if (newModule) {
@@ -181,8 +160,7 @@ CSwordBackend::LoadError CSwordBackend::initModules(SetupChangedReason reason) {
}
}
- Q_FOREACH(CSwordModuleInfo* mod, m_dataModel.modules()) {
- m_moduleDescriptionMap.insert( mod->config(CSwordModuleInfo::Description), mod->name() );
+ Q_FOREACH(CSwordModuleInfo* mod, m_dataModel.moduleList()) {
//unlock modules if keys are present
if ( mod->isEncrypted() ) {
const QString unlockKey = CBTConfig::getModuleEncryptionKey( mod->name() );
@@ -206,29 +184,29 @@ void CSwordBackend::AddRenderFilters(sword::SWModule *module, sword::ConfigEntMa
moduleDriver = ((entry = section.find("ModDrv")) != section.end()) ? (*entry).second : (sword::SWBuf) "";
if (sourceformat == "OSIS") {
- module->AddRenderFilter(m_filters.osis);
+ module->AddRenderFilter(&m_osisFilter);
noDriver = false;
}
else if (sourceformat == "ThML") {
- module->AddRenderFilter(m_filters.thml);
+ module->AddRenderFilter(&m_thmlFilter);
noDriver = false;
}
else if (sourceformat == "TEI") {
- module->AddRenderFilter(m_filters.tei);
+ module->AddRenderFilter(&m_teiFilter);
noDriver = false;
}
else if (sourceformat == "GBF") {
- module->AddRenderFilter(m_filters.gbf);
+ module->AddRenderFilter(&m_gbfFilter);
noDriver = false;
}
else if (sourceformat == "PLAIN") {
- module->AddRenderFilter(m_filters.plain);
+ module->AddRenderFilter(&m_plainFilter);
noDriver = false;
}
if (noDriver) { //no driver found
if ( (moduleDriver == "RawCom") || (moduleDriver == "RawLD") ) {
- module->AddRenderFilter(m_filters.plain);
+ module->AddRenderFilter(&m_plainFilter);
noDriver = false;
}
}
@@ -284,7 +262,7 @@ void CSwordBackend::setOption( const CSwordModuleInfo::FilterTypes type, const i
setGlobalOption(optionName(type).toUtf8().constData(), value.c_str());
}
-void CSwordBackend::setFilterOptions( const CSwordBackend::FilterOptions options) {
+void CSwordBackend::setFilterOptions(const FilterOptions &options) {
setOption( CSwordModuleInfo::footnotes, options.footnotes );
setOption( CSwordModuleInfo::strongNumbers, options.strongNumbers );
setOption( CSwordModuleInfo::headings, options.headings );
@@ -302,93 +280,27 @@ void CSwordBackend::setFilterOptions( const CSwordBackend::FilterOptions options
/** This function searches for a module with the specified description */
CSwordModuleInfo* CSwordBackend::findModuleByDescription(const QString& description) {
- Q_FOREACH (CSwordModuleInfo *mod, m_dataModel.modules()) {
+ Q_FOREACH (CSwordModuleInfo *mod, m_dataModel.moduleList()) {
if (mod->config(CSwordModuleInfo::Description) == description) return mod;
}
return 0;
}
-/** This function searches for a module with the specified description */
-const QString CSwordBackend::findModuleNameByDescription(const QString& description) {
- if (m_moduleDescriptionMap.contains(description)) {
- return m_moduleDescriptionMap[description];
- }
- return QString::null;
-}
-
/** This function searches for a module with the specified name */
CSwordModuleInfo* CSwordBackend::findModuleByName(const QString& name) {
- Q_FOREACH (CSwordModuleInfo *mod, m_dataModel.modules()) {
+ Q_FOREACH (CSwordModuleInfo *mod, m_dataModel.moduleList()) {
if (mod->name() == name) return mod;
}
return 0;
}
CSwordModuleInfo* CSwordBackend::findSwordModuleByPointer(const sword::SWModule* const swmodule) {
- Q_FOREACH (CSwordModuleInfo *mod, m_dataModel.modules()) {
+ Q_FOREACH (CSwordModuleInfo *mod, m_dataModel.moduleList()) {
if (mod->module() == swmodule ) return mod;
}
return 0;
}
-CSwordModuleInfo* CSwordBackend::findModuleByPointer(const CSwordModuleInfo* const module) {
- Q_FOREACH (CSwordModuleInfo *mod, m_dataModel.modules()) {
- if (mod == module) return mod;
- }
- return 0;
-}
-
-/** Returns our local config object to store the cipher keys etc. locally for each user. The values of the config are merged with the global config. */
-bool CSwordBackend::moduleConfig(const QString& module, sword::SWConfig& moduleConfig) {
-
- sword::SectionMap::iterator section;
- QDir dir(QString::fromUtf8(configPath));
- bool foundConfig = false;
-
- QFileInfoList list = dir.entryInfoList();
- if (dir.isReadable()) {
- for (int i = 0; i < list.size(); ++i) {
- QFileInfo fileInfo = list.at(i);
-
- moduleConfig = sword::SWConfig( fileInfo.absoluteFilePath().toLocal8Bit().constData() );
- section = moduleConfig.Sections.find( module.toLocal8Bit().constData() );
- foundConfig = ( section != moduleConfig.Sections.end() );
- }
- }
- else { //try to read mods.conf
- moduleConfig = sword::SWConfig("");//global config
- section = config->Sections.find( module.toLocal8Bit().constData() );
- foundConfig = ( section != config->Sections.end() );
-
- sword::ConfigEntMap::iterator entry;
-
- if (foundConfig) { //copy module section
-
- for (entry = section->second.begin(); entry != section->second.end(); entry++) {
- moduleConfig.Sections[section->first].insert(sword::ConfigEntMap::value_type(entry->first, entry->second));
- }
- }
- }
-
- if (!foundConfig && configType != 2) { //search in $HOME/.sword/
-
- QString myPath = util::directory::getUserHomeSwordModsDir().absolutePath();
- dir.setPath(myPath);
-
- QFileInfoList list = dir.entryInfoList();
- if (dir.isReadable()) {
- for (int i = 0; i < list.size(); ++i) {
- QFileInfo fileInfo = list.at(i);
- moduleConfig = sword::SWConfig( fileInfo.absoluteFilePath().toLocal8Bit().constData() );
- section = moduleConfig.Sections.find( module.toLocal8Bit().constData() );
- foundConfig = ( section != moduleConfig.Sections.end() );
- }
- }
- }
-
- return foundConfig;
-}
-
/** Returns the text used for the option given as parameter. */
const QString CSwordBackend::optionName( const CSwordModuleInfo::FilterTypes option ) {
switch (option) {
@@ -490,7 +402,7 @@ const QString CSwordBackend::booknameLanguage( const QString& language ) {
//use what sword returns, language may be different
QString newLocaleName( sword::LocaleMgr::getSystemLocaleMgr()->getDefaultLocaleName() );
- Q_FOREACH (CSwordModuleInfo *mod, m_dataModel.modules()) {
+ Q_FOREACH (CSwordModuleInfo *mod, m_dataModel.moduleList()) {
if ( (mod->type() == CSwordModuleInfo::Bible) || (mod->type() == CSwordModuleInfo::Commentary) ) {
//Create a new key, it will get the default bookname language
((sword::VerseKey*)(mod->module()->getKey()))->setLocale( newLocaleName.toUtf8().constData() );
@@ -609,3 +521,26 @@ QStringList CSwordBackend::swordDirList() const {
return swordDirSet.values();
}
+
+void CSwordBackend::deleteOrphanedIndices() {
+ QDir dir(CSwordModuleInfo::getGlobalBaseIndexLocation());
+ dir.setFilter(QDir::Dirs);
+ CSwordModuleInfo* module;
+
+ for (unsigned int i = 0; i < dir.count(); i++) {
+ if (dir[i] != "." && dir[i] != "..") {
+ if ( (module = this->findModuleByName(dir[i])) ) { //mod exists
+ if (!module->hasIndex()) { //index files found, but wrong version etc.
+ qDebug() << "deleting outdated index for module" << dir[i];
+ CSwordModuleInfo::deleteIndexForModule( dir[i] );
+ }
+ }
+ else { //no module exists
+ if (CBTConfig::get( CBTConfig::autoDeleteOrphanedIndices ) ) {
+ qDebug() << "deleting orphaned index in directory" << dir[i];
+ CSwordModuleInfo::deleteIndexForModule( dir[i] );
+ }
+ }
+ }
+ }
+}
diff --git a/src/backend/managers/cswordbackend.h b/src/backend/managers/cswordbackend.h
index c8b4f77..68be102 100644
--- a/src/backend/managers/cswordbackend.h
+++ b/src/backend/managers/cswordbackend.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,6 +16,14 @@
#include <QStringList>
#include "backend/drivers/cswordmoduleinfo.h"
#include "backend/bookshelfmodel/btbookshelfmodel.h"
+#include "backend/filters/gbftohtml.h"
+#include "backend/filters/osistohtml.h"
+#include "backend/filters/plaintohtml.h"
+#include "backend/filters/teitohtml.h"
+#include "backend/filters/thmltohtml.h"
+#include "backend/rendering/cbookdisplay.h"
+#include "backend/rendering/cchapterdisplay.h"
+#include "backend/rendering/centrydisplay.h"
// Sword includes:
#include <swmgr.h>
@@ -25,20 +33,17 @@
#include <localemgr.h>
#include <utilstr.h>
-namespace Rendering {
-class CEntryDisplay;
-class CChapterDisplay;
-class CBookDisplay;
-}
+/**
+ \brief The backend layer main class, a backend implementation of Sword.
+
+ This is the implementation of CBackend for Sword. It's additionally derived
+ from SWMgr to provide functions of Sword.
-/** The backend layer main class.
- * This is the implementation of CBackend for Sword. It's additionally derived from SWMgr
- * to provide functions of Sword.
- *
- * @short The backend implementation of Sword
- * @author The BibleTime team
- * @version $Id: cswordbackend.h,v 1.58 2007/03/14 21:32:47 joachim Exp $
- */
+ \note Mostly, only one instance of this class is used. This instance is
+ created by BibleTime::initBackends() and is destroyed by
+ BibleTimeApp::~BibleTimeApp(). Only when \ref BackendNotSingleton
+ "managing modules" separate backends are created.
+*/
class CSwordBackend : public QObject, public sword::SWMgr {
Q_OBJECT
public:
@@ -52,32 +57,6 @@ class CSwordBackend : public QObject, public sword::SWMgr {
OtherChange = 16
};
- /** Filter options. Filter options to
- * control the text display of modules. Uses int and not bool because not all
- * options have just two toggle values.
- */
- struct FilterOptions {
- int footnotes; /**< 0 for disabled, 1 for enabled */
- int strongNumbers; /**< 0 for disabled, 1 for enabled */
- int headings; /**< 0 for disabled, 1 for enabled */
- int morphTags; /**< 0 for disabled, 1 for enabled */
- int lemmas; /**< 0 for disabled, 1 for enabled */
- int hebrewPoints; /**< 0 for disabled, 1 for enabled */
- int hebrewCantillation; /**< 0 for disabled, 1 for enabled */
- int greekAccents; /**< 0 for disabled, 1 for enabled */
- int textualVariants; /**< Number n to enabled the n-th variant */
- int redLetterWords; /**< 0 for disabled, 1 for enabled */
- int scriptureReferences; /**< 0 for disabled, 1 for enabled */
- int morphSegmentation; /**< 0 for disabled, 1 for enabled */
- };
-
- /** Control the display of a text.
- */
- struct DisplayOptions {
- int lineBreaks;
- int verseNumbers;
- };
-
/** The error codes which may be returned by the @ref Load() call.
*/
enum LoadError { // the values exist to cast from the char return of SWMgr::Load
@@ -86,12 +65,6 @@ class CSwordBackend : public QObject, public sword::SWMgr {
NoModules = 1
};
/**
- * The constructor of the Sword backend.
- * It creates the SWModule objects using SWMgr's methods, it adds the necessary
- * filters for the module format.
- */
- CSwordBackend();
- /**
* The constructor of the Sword backend. This is actually used nowhere.
* Notice that using augmentHome=false can mess up the system because it is true elsewhere.
* @param path The path which is used to load modules
@@ -104,6 +77,19 @@ class CSwordBackend : public QObject, public sword::SWMgr {
*/
~CSwordBackend();
+ /** Creates and returns the instance. */
+ static inline CSwordBackend *createInstance() {
+ Q_ASSERT(m_instance == 0);
+ m_instance = new CSwordBackend();
+ return m_instance;
+ }
+
+ /** Returns the singleton instance, creating it if one does not exist. */
+ static inline CSwordBackend *instance() { return m_instance; }
+
+ /** Destroys the singleton instance, if one exists. */
+ static void destroyInstance() { delete m_instance; }
+
/**
* This function returns the list of available modules managed by this
* backend. You have to call initModules() first; This method is
@@ -134,8 +120,8 @@ class CSwordBackend : public QObject, public sword::SWMgr {
* @param enable If this is true the option will be enabled, otherwise it will be disabled.
*/
void setOption( const CSwordModuleInfo::FilterTypes type, const int state );
- /** */
- void setFilterOptions( const CSwordBackend::FilterOptions options );
+
+ void setFilterOptions(const FilterOptions &options);
/**
* Sets the language for the international booknames of Sword.
* @param langName The abbreviation string which should be used for the Sword backend
@@ -147,12 +133,7 @@ class CSwordBackend : public QObject, public sword::SWMgr {
* @return pointer to the desired module; null if no module has the specified description
*/
CSwordModuleInfo* findModuleByDescription(const QString& description);
- /**
- * This function searches for a module with the specified description
- * @param description The description of the desired module
- * @return pointer to the desired module; null if no module has the specified description
- */
- const QString findModuleNameByDescription(const QString& description);
+
/**
* This function searches for a module with the specified name
* @param name The name of the desired module
@@ -165,21 +146,12 @@ class CSwordBackend : public QObject, public sword::SWMgr {
* @return pointer to the desired module; null if no module has the specified name
*/
CSwordModuleInfo* findSwordModuleByPointer(const sword::SWModule* const swmodule);
- /**
- * This function searches for a module which is the same as the passed module.
- * @param module The module which should be used for searching the new one. May be child of a different backend.
- * @return Pointer to the desired module; null if no module has the specified name
- */
- CSwordModuleInfo* findModuleByPointer(const CSwordModuleInfo* const module);
+
/**
* @return Our global config object which contains the configs of all modules merged together.
*/
inline sword::SWConfig* getConfig() const;
- /**
- * Tries to find the config object for the module. The second paramter will be the found config.
- * @return True if the config was found, false if not. If false is returned the moduleConfig object is in undefined/unknwon state.
- */
- bool moduleConfig(const QString& module, sword::SWConfig& moduleConfig );
+
/**
* Returns the text used for the option given as parameter.
* @param The paramter enum
@@ -195,11 +167,7 @@ class CSwordBackend : public QObject, public sword::SWMgr {
* @param The translated option name
*/
static const QString translatedOptionName(const CSwordModuleInfo::FilterTypes option );
- /**
- * Returns the version of the Sword library.
- * @return The version used by this backend
- */
- inline const sword::SWVersion Version();
+
/**
* Reload all Sword modules.
*/
@@ -212,22 +180,39 @@ class CSwordBackend : public QObject, public sword::SWMgr {
QList<CSwordModuleInfo*> takeModulesFromList(QStringList names);
/**
- * Returns a list of pointers to modules, created from a list of module names.
+ \returns a list of pointers to modules, created from a list of module
+ names.
+ */
+ QList<CSwordModuleInfo*> getPointerList(const QStringList &names);
+
+ /**
+ \returns a list of pointers to const modules, created from a list of
+ module names.
*/
- QList<CSwordModuleInfo*> getPointerList(QStringList names);
+ QList<const CSwordModuleInfo*> getConstPointerList(const QStringList &names);
/** Sword prefix list.
* @return A list of all known Sword prefix dirs
*/
QStringList swordDirList() const;
+ /**
+ * delete all orphaned indexes (no module present) if autoDeleteOrphanedIndices is true
+ * delete all indices of modules where hasIndex() returns false (because of wrong index version etc.)
+ */
+ void deleteOrphanedIndices();
signals:
void sigSwordSetupChanged(CSwordBackend::SetupChangedReason reason);
protected:
/**
- * Adds a render filter to the module.
- * This is used to apply our own render filters to our modules instead of the sword filters
+ Creates the SWModule objects using SWMgr's methods, it adds the
+ necessary filters for the module format.
+ */
+ CSwordBackend();
+
+ /**
+ * Reimplemented from sword::SWMgr.
*/
void AddRenderFilters(sword::SWModule *module, sword::ConfigEntMap &section);
/**
@@ -239,32 +224,27 @@ class CSwordBackend : public QObject, public sword::SWMgr {
QString getPrivateSwordConfigPath() const;
QString getPrivateSwordConfigFile() const;
- private:
- // Filters
- struct Filters {
- sword::SWFilter* gbf;
- sword::SWFilter* plain;
- sword::SWFilter* thml;
- sword::SWFilter* osis;
- sword::SWFilter* tei;
- } m_filters;
-
- struct Displays {
- Rendering::CChapterDisplay* chapter;
- Rendering::CEntryDisplay* entry;
- Rendering::CBookDisplay* book;
- } m_displays;
+ private: /* Fields: */
+ // Filters:
+ Filters::GbfToHtml m_gbfFilter;
+ Filters::OsisToHtml m_osisFilter;
+ Filters::PlainToHtml m_plainFilter;
+ Filters::TeiToHtml m_teiFilter;
+ Filters::ThmlToHtml m_thmlFilter;
+
+ // Displays:
+ Rendering::CChapterDisplay m_chapterDisplay;
+ Rendering::CEntryDisplay m_entryDisplay;
+ Rendering::CBookDisplay m_bookDisplay;
BtBookshelfModel m_dataModel;
- QMap<QString, QString> m_moduleDescriptionMap;
-};
-Q_DECLARE_METATYPE(CSwordBackend::FilterOptions)
-Q_DECLARE_METATYPE(CSwordBackend::DisplayOptions)
+ static CSwordBackend *m_instance;
+};
/**Returns The list of modules managed by this backend*/
inline const QList<CSwordModuleInfo*> &CSwordBackend::moduleList() const {
- return m_dataModel.modules();
+ return m_dataModel.moduleList();
}
inline BtBookshelfModel *CSwordBackend::model() {
@@ -276,9 +256,4 @@ inline sword::SWConfig* CSwordBackend::getConfig() const {
return config;
}
-/** Returns the version of the Sword library. */
-inline const sword::SWVersion CSwordBackend::Version() {
- return sword::SWVersion::currentVersion;
-}
-
#endif
diff --git a/src/backend/managers/referencemanager.cpp b/src/backend/managers/referencemanager.cpp
index 4fc5e53..de41af2 100644
--- a/src/backend/managers/referencemanager.cpp
+++ b/src/backend/managers/referencemanager.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,12 +10,10 @@
#include "backend/managers/referencemanager.h"
#include <algorithm>
-
#include <QRegExp>
#include <QDebug>
#include "backend/config/cbtconfig.h"
#include "backend/keys/cswordversekey.h"
-#include "util/cpointers.h"
/** Returns a hyperlink used to be imbedded in the display windows. At the moment the format is sword://module/key */
@@ -87,15 +85,15 @@ const QString ReferenceManager::encodeHyperlink( const QString moduleName, const
case Bible: //bibles or commentary keys need parsing
case Commentary: {
- /* CSwordModuleInfo* mod = CPointers::backend()->findModuleByName(moduleName);
+ /* CSwordModuleInfo* mod = CSwordBackend::instance()()->findModuleByName(moduleName);
- ParseOptions options;
- options.refDestinationModule = mod->name();
- options.refBase =
- options.sourceLanguage = mod->module()->Lang();
- options.destinationLanguage = "en";
+ ParseOptions options;
+ options.refDestinationModule = mod->name();
+ options.refBase =
+ options.sourceLanguage = mod->module()->Lang();
+ options.destinationLanguage = "en";
- ret.append( parseVerseReference(key, options) ); //we add the english key, so drag and drop will work in all cases*/
+ ret.append( parseVerseReference(key, options) ); //we add the english key, so drag and drop will work in all cases*/
ret.append(key);
break;
}
@@ -237,20 +235,6 @@ bool ReferenceManager::decodeHyperlink( const QString& hyperlink, QString& modul
return true;
}
-const QString ReferenceManager::encodeReference(const QString &module, const QString &reference) {
- //return QString("(%1)%2").arg(module).arg(reference);
- return QString("(").append(module).append(")").append(reference);
-}
-
-void ReferenceManager::decodeReference(QString &dragreference, QString &module, QString &reference) {
- const int pos = dragreference.indexOf(")");
- const QString fallbackModule = dragreference.mid( 1, pos - 1);
- dragreference = dragreference.mid(pos + 1);
-
- module = fallbackModule;
- reference = dragreference;
-}
-
/** Returns true if the parameter is a hyperlink. */
bool ReferenceManager::isHyperlink( const QString& hyperlink ) {
return ( hyperlink.left(8) == "sword://")
@@ -341,7 +325,7 @@ ReferenceManager::Type ReferenceManager::typeFromModule( const CSwordModuleInfo:
/** Parses the given verse references using the given language and the module.*/
const QString ReferenceManager::parseVerseReference( const QString& ref, const ReferenceManager::ParseOptions& options) {
- CSwordModuleInfo* const mod = CPointers::backend()->findModuleByName(options.refDestinationModule);
+ CSwordModuleInfo* const mod = CSwordBackend::instance()->findModuleByName(options.refDestinationModule);
//Q_ASSERT(mod); tested later
if (!mod) {
@@ -371,19 +355,19 @@ const QString ReferenceManager::parseVerseReference( const QString& ref, const R
CSwordVerseKey baseKey(0);
baseKey.setLocale( sourceLanguage.toUtf8().constData() );
- baseKey.key( options.refBase ); //probably in the sourceLanguage
+ baseKey.setKey(options.refBase); //probably in the sourceLanguage
baseKey.setLocale( "en_US" ); //english works in all environments as base
-// CSwordVerseKey dummy(0);
+// CSwordVerseKey dummy(0);
//HACK: We have to workaround a Sword bug, we have to set the default locale to the same as the sourceLanguage !
- const QString oldLocaleName = CPointers::backend()->booknameLanguage();
- CPointers::backend()->booknameLanguage(sourceLanguage);
+ const QString oldLocaleName = CSwordBackend::instance()->booknameLanguage();
+ CSwordBackend::instance()->booknameLanguage(sourceLanguage);
sword::VerseKey dummy;
dummy.setLocale( sourceLanguage.toUtf8().constData() );
Q_ASSERT( !strcmp(dummy.getLocale(), sourceLanguage.toUtf8().constData()) );
-// qDebug("Parsing '%s' in '%s' using '%s' as base, source lang '%s', dest lang '%s'", ref.latin1(), options.refDestinationModule.latin1(), baseKey.key().latin1(), sourceLanguage.latin1(), destinationLanguage.latin1());
+// qDebug("Parsing '%s' in '%s' using '%s' as base, source lang '%s', dest lang '%s'", ref.latin1(), options.refDestinationModule.latin1(), baseKey.key().latin1(), sourceLanguage.latin1(), destinationLanguage.latin1());
for (QStringList::iterator it = refList.begin(); it != refList.end(); it++) {
//The listkey may contain more than one item, because a ref lik "Gen 1:3,5" is parsed into two single refs
@@ -416,6 +400,6 @@ const QString ReferenceManager::parseVerseReference( const QString& ref, const R
}
- CPointers::backend()->booknameLanguage(oldLocaleName);
+ CSwordBackend::instance()->booknameLanguage(oldLocaleName);
return ret;
}
diff --git a/src/backend/managers/referencemanager.h b/src/backend/managers/referencemanager.h
index fdef8b2..a07b480 100644
--- a/src/backend/managers/referencemanager.h
+++ b/src/backend/managers/referencemanager.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.
*
**********/
@@ -47,20 +47,7 @@ bool decodeHyperlink( const QString& hyperlink, QString& module, QString& key, T
* @return The encoded hyperlink
*/
const QString encodeHyperlink( const QString module, const QString key, const Type type);
-/**
-* Puts a module Name and a Reference together in the 'draggable' form
-* (module)reference
-* @param module The name of the module
-* @param reference The key reference as text
-* @return The encoded reference using module and reference
-* @author Martin Gruner
-*/
-const QString encodeReference(const QString &module, const QString &reference);
-/**
-* decodes a 'draggable' reference into a modulename and a reference
-* @author Martin Gruner
-*/
-void decodeReference(QString &dragreference, QString &module, QString &reference);
+
/**
* Returns true if the parameter is a hyperlink.
* @param hyperlink The string which is tested
diff --git a/src/backend/rendering/cbookdisplay.cpp b/src/backend/rendering/cbookdisplay.cpp
index 9da57f2..259e904 100644
--- a/src/backend/rendering/cbookdisplay.cpp
+++ b/src/backend/rendering/cbookdisplay.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/rendering/cbookdisplay.h"
-#include <boost/scoped_ptr.hpp>
+#include <QSharedPointer>
#include <QtAlgorithms>
#include "backend/drivers/cswordbookmoduleinfo.h"
@@ -17,12 +17,18 @@
#include "backend/rendering/cdisplayrendering.h"
-/** Returns the rendered text using the modules in the list and using the key parameter. The displayoptions and filter options are used, too. */
-const QString Rendering::CBookDisplay::text( const QList<CSwordModuleInfo*>& modules, const QString& keyName, const CSwordBackend::DisplayOptions displayOptions, const CSwordBackend::FilterOptions filterOptions ) {
- CSwordBookModuleInfo* book = dynamic_cast<CSwordBookModuleInfo*>(modules.first());
+const QString Rendering::CBookDisplay::text(
+ const QList<const CSwordModuleInfo*> &modules,
+ const QString &keyName,
+ const DisplayOptions &displayOptions,
+ const FilterOptions &filterOptions)
+{
+ typedef CSwordBookModuleInfo CSBMI;
+
+ const CSBMI* book = dynamic_cast<const CSBMI*>(modules.first());
Q_ASSERT(book);
- CSwordBackend::DisplayOptions dOpts = displayOptions;
+ DisplayOptions dOpts = displayOptions;
dOpts.lineBreaks = true; //books should render with blocks, not with inlined sections
CDisplayRendering render(dOpts, filterOptions);
@@ -32,10 +38,10 @@ const QString Rendering::CBookDisplay::text( const QList<CSwordModuleInfo*>& mod
// the number of levels which should be display together, 1 means display no entries together
int displayLevel = book->config( CSwordModuleInfo::DisplayLevel ).toInt();
- boost::scoped_ptr<CSwordTreeKey> key (
+ QSharedPointer<CSwordTreeKey> key (
dynamic_cast<CSwordTreeKey*>( CSwordKey::createInstance(book) )
);
- key->key(keyName); //set the key to position we'd like to get
+ key->setKey(keyName); //set the key to position we'd like to get
const unsigned long offset = key->getOffset();
@@ -60,7 +66,7 @@ const QString Rendering::CBookDisplay::text( const QList<CSwordModuleInfo*>& mod
int possibleLevels = 1; //we start with the default value of displayLevel, which means no entries together
- while ( key->parent() && (key->key() != "/") && !key->key().isEmpty() ) {//add parents
+ while ( key->sword::TreeKeyIdx::parent() && (key->key() != "/") && !key->key().isEmpty() ) {//add parents
++possibleLevels;
};
@@ -90,7 +96,7 @@ const QString Rendering::CBookDisplay::text( const QList<CSwordModuleInfo*>& mod
// at the moment we're at the lowest level, so we only have to go up!
for (int currentLevel = 1; currentLevel < displayLevel; ++currentLevel) { //we start again with 1 == standard of displayLevel
- if ( !key->parent() ) { //something went wrong although we checked before! Be safe and return entry's text
+ if ( !key->sword::TreeKeyIdx::parent() ) { //something went wrong although we checked before! Be safe and return entry's text
tree.append( new CDisplayRendering::KeyTreeItem( key->key(), modules, itemSettings ) );
const QString renderedText = render.renderKeyTree(tree);
@@ -108,7 +114,7 @@ const QString Rendering::CBookDisplay::text( const QList<CSwordModuleInfo*>& mod
//const bool hasToplevelText = !key->strippedText().isEmpty();
key->firstChild(); //go to the first sibling on the same level
- setupRenderTree(key.get(), &tree, keyName);
+ setupRenderTree(key.data(), &tree, keyName);
const QString renderedText = render.renderKeyTree(tree);
@@ -126,7 +132,9 @@ void Rendering::CBookDisplay::setupRenderTree(CSwordTreeKey * swordTree, CTextRe
CTextRendering::KeyTreeItem::Settings settings;
settings.highlight = (key == highlightKey);
- CTextRendering::KeyTreeItem* item = new CTextRendering::KeyTreeItem(key, swordTree->module(0), settings );
+ /// \todo Check whether this is correct:
+ CTextRendering::KeyTreeItem *item = new CTextRendering::KeyTreeItem(
+ key, swordTree->module(), settings);
renderTree->append( item );
if (swordTree->hasChildren()) { //print tree for the child items
diff --git a/src/backend/rendering/cbookdisplay.h b/src/backend/rendering/cbookdisplay.h
index 832249f..be5ec9b 100644
--- a/src/backend/rendering/cbookdisplay.h
+++ b/src/backend/rendering/cbookdisplay.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.
*
**********/
@@ -20,26 +20,27 @@ class CSwordTreeKey;
namespace Rendering {
/**
-* A CEntryDisplay implementation which works on tree-based GenBook modules
-* of Sword.
-* @short CEntryDisplay implementation for GenBook modules,
-* @author The BibleTime team
-*/
-
-class CBookDisplay : public CEntryDisplay {
- public: // Public methods
- virtual ~CBookDisplay() {}
+* \brief CEntryDisplay implementation for GenBook modules,
- /**
- * Returns the rendered text using the modules in the list and using the key parameter.
- * The displayoptions and filter options are used, too.
- */
- virtual const QString text( const QList<CSwordModuleInfo*>& modules, const QString& key, const CSwordBackend::DisplayOptions displayOptions, const CSwordBackend::FilterOptions filterOptions);
-
- protected:
- void setupRenderTree(CSwordTreeKey* swordTree, CTextRendering::KeyTree* renderTree, const QString& highlightKey);
+ A CEntryDisplay implementation which works on tree-based GenBook modules of
+ Sword.
+*/
+class CBookDisplay: public CEntryDisplay {
+ public: /* Methods: */
+ virtual inline ~CBookDisplay() {}
+
+ /** Reimplemented from CEntryDisplay. */
+ virtual const QString text(const QList<const CSwordModuleInfo*> &modules,
+ const QString &key,
+ const DisplayOptions &displayOptions,
+ const FilterOptions &filterOptions);
+
+ protected: /* Methods: */
+ void setupRenderTree(CSwordTreeKey *swordTree,
+ CTextRendering::KeyTree *renderTree,
+ const QString &highlightKey);
};
-}
+} // namespace Rendering
#endif
diff --git a/src/backend/rendering/cchapterdisplay.cpp b/src/backend/rendering/cchapterdisplay.cpp
index 74063cf..31b56b8 100644
--- a/src/backend/rendering/cchapterdisplay.cpp
+++ b/src/backend/rendering/cchapterdisplay.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.
*
**********/
@@ -14,11 +14,18 @@
#include "backend/rendering/cdisplayrendering.h"
-const QString Rendering::CChapterDisplay::text( const QList<CSwordModuleInfo*>& modules, const QString& keyName, const CSwordBackend::DisplayOptions displayOptions, const CSwordBackend::FilterOptions filterOptions ) {
+const QString Rendering::CChapterDisplay::text(
+ const QList<const CSwordModuleInfo*> &modules,
+ const QString &keyName,
+ const DisplayOptions &displayOptions,
+ const FilterOptions &filterOptions)
+{
+ typedef CSwordBibleModuleInfo CSBMI;
+
Q_ASSERT( modules.count() >= 1 );
Q_ASSERT( !keyName.isEmpty() );
- CSwordModuleInfo* module = modules.first();
+ const CSwordModuleInfo *module = modules.first();
if (modules.count() == 1) module->module()->setSkipConsecutiveLinks( true ); //skip empty, linked verses
@@ -37,14 +44,14 @@ const QString Rendering::CChapterDisplay::text( const QList<CSwordModuleInfo*>&
if (module->type() == CSwordModuleInfo::Bible) {
((sword::VerseKey*)(module->module()->getKey()))->Headings(1); //HACK: enable headings for VerseKeys
- CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(module);
- Q_ASSERT(bible);
+ Q_ASSERT(dynamic_cast<const CSBMI*>(module) != 0);
+ const CSBMI *bible = static_cast<const CSBMI*>(module);
CSwordVerseKey k1(module);
k1.Headings(1);
- k1.key(keyName);
+ k1.setKey(keyName);
- if (k1.Chapter() == 1) k1.Chapter(0); //Chapter 1, start with 0:0, otherwise X:0
+ if (k1.Chapter() == 1) k1.Chapter(0); //Chapter 1, start with 0:0, otherwise X:0
k1.Verse(0);
diff --git a/src/backend/rendering/cchapterdisplay.h b/src/backend/rendering/cchapterdisplay.h
index 3b3d363..a13ebc3 100644
--- a/src/backend/rendering/cchapterdisplay.h
+++ b/src/backend/rendering/cchapterdisplay.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.
*
**********/
@@ -15,24 +15,25 @@
namespace Rendering {
-/** Chapter rendering.
-* A CEntryDisplay implementation mde for Bibles to display whole chapters
-* at once.
-* @author The BibleTime team
-*/
-
-class CChapterDisplay : public CEntryDisplay {
+/**
+ \brief CEntryDisplay implementation for whole chapters.
- public: // Public methods
- virtual ~CChapterDisplay() {}
+ A CEntryDisplay implementation made for Bibles to display whole chapters at
+ once.
+*/
+class CChapterDisplay: public CEntryDisplay {
+ public: /* Methods: */
+ virtual inline ~CChapterDisplay() {}
/**
- * Returns the rendered text using the modules in the list and using the key parameter.
- * The displayoptions and filter options are used, too.
+ Reimplemented from CEntryDisplay.
*/
- virtual const QString text( const QList<CSwordModuleInfo*>& modules, const QString& key, const CSwordBackend::DisplayOptions displayOptions, const CSwordBackend::FilterOptions filterOptions);
+ virtual const QString text(const QList<const CSwordModuleInfo*> &modules,
+ const QString &key,
+ const DisplayOptions &displayOptions,
+ const FilterOptions &filterOptions);
};
-}
+} // namespace Rendering
#endif
diff --git a/src/backend/rendering/cdisplayrendering.cpp b/src/backend/rendering/cdisplayrendering.cpp
index cc3f7c9..c79cfdf 100644
--- a/src/backend/rendering/cdisplayrendering.cpp
+++ b/src/backend/rendering/cdisplayrendering.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,15 +16,21 @@
#include "backend/keys/cswordversekey.h"
#include "backend/managers/cdisplaytemplatemgr.h"
#include "backend/managers/referencemanager.h"
-#include "util/cpointers.h"
namespace Rendering {
-CDisplayRendering::CDisplayRendering(CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions)
- : CHTMLExportRendering(CHTMLExportRendering::Settings(true), displayOptions, filterOptions) {}
+CDisplayRendering::CDisplayRendering(const DisplayOptions &displayOptions,
+ const FilterOptions &filterOptions)
+ : CHTMLExportRendering(CHTMLExportRendering::Settings(true),
+ displayOptions, filterOptions)
+{
+ // Intentionally empty
+}
-const QString CDisplayRendering::entryLink( const KeyTreeItem& item, CSwordModuleInfo* module ) {
+const QString CDisplayRendering::entryLink(const KeyTreeItem &item,
+ const CSwordModuleInfo *module)
+{
QString linkText;
const bool isBible = module && (module->type() == CSwordModuleInfo::Bible);
@@ -32,7 +38,7 @@ const QString CDisplayRendering::entryLink( const KeyTreeItem& item, CSwordModul
vk.Headings(true);
if (isBible) {
- vk.key(item.key());
+ vk.setKey(item.key());
}
if (isBible && (vk.Verse() == 0)) {
@@ -105,7 +111,7 @@ const QString CDisplayRendering::keyToHTMLAnchor(const QString& key) {
}
const QString CDisplayRendering::finishText( const QString& oldText, KeyTree& tree ) {
- QList<CSwordModuleInfo*> modules = collectModules(&tree);
+ QList<const CSwordModuleInfo*> modules = collectModules(&tree);
qDebug() << "CDisplayRendering::finishText";
//marking words is very slow, we have to find a better solution
@@ -139,9 +145,9 @@ const QString CDisplayRendering::finishText( const QString& oldText, KeyTree& tr
const CLanguageMgr::Language* const lang =
(modules.count() >= 1)
? modules.first()->language()
- : CPointers::languageMgr()->defaultLanguage();
+ : CLanguageMgr::instance()->defaultLanguage();
- CDisplayTemplateMgr* tMgr = CPointers::displayTemplateManager();
+ CDisplayTemplateMgr *tMgr = CDisplayTemplateMgr::instance();
//Q_ASSERT(modules.count() >= 1);
diff --git a/src/backend/rendering/cdisplayrendering.h b/src/backend/rendering/cdisplayrendering.h
index f66e556..8b222ac 100644
--- a/src/backend/rendering/cdisplayrendering.h
+++ b/src/backend/rendering/cdisplayrendering.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.
*
**********/
@@ -25,12 +25,14 @@ class CDisplayRendering : public CHTMLExportRendering {
static const QString keyToHTMLAnchor(const QString& key);
CDisplayRendering(
- CSwordBackend::DisplayOptions displayOptions = CBTConfig::getDisplayOptionDefaults(),
- CSwordBackend::FilterOptions filterOptions = CBTConfig::getFilterOptionDefaults()
+ const DisplayOptions &displayOptions = CBTConfig::getDisplayOptionDefaults(),
+ const FilterOptions &filterOptions = CBTConfig::getFilterOptionDefaults()
);
protected:
- virtual const QString entryLink( const KeyTreeItem& item, CSwordModuleInfo* const module );
+ virtual const QString entryLink(const KeyTreeItem &item,
+ const CSwordModuleInfo *module);
+
virtual const QString finishText( const QString&, KeyTree& tree );
};
diff --git a/src/backend/rendering/centrydisplay.cpp b/src/backend/rendering/centrydisplay.cpp
index b6c7a27..d1b2a34 100644
--- a/src/backend/rendering/centrydisplay.cpp
+++ b/src/backend/rendering/centrydisplay.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.
*
**********/
@@ -24,15 +24,17 @@
using namespace Rendering;
-/** Returns the rendered text using the modules in the list and using the key parameter.
- * The displayoptions and filter options are used, too.
- */
-const QString CEntryDisplay::text( const QList<CSwordModuleInfo*>& modules, const QString& keyName, const CSwordBackend::DisplayOptions displayOptions, const CSwordBackend::FilterOptions filterOptions ) {
+const QString CEntryDisplay::text(
+ const QList<const CSwordModuleInfo*> &modules,
+ const QString &keyName,
+ const DisplayOptions &displayOptions,
+ const FilterOptions &filterOptions)
+{
CDisplayRendering render(displayOptions, filterOptions);
//no highlighted key and no extra key link in the text
CTextRendering::KeyTreeItem::Settings normal_settings(false, CTextRendering::KeyTreeItem::Settings::CompleteShort);
- CSwordModuleInfo* module = modules.first();
+ const CSwordModuleInfo *module = modules.first();
Rendering::CTextRendering::KeyTree tree;
@@ -42,7 +44,7 @@ const QString CEntryDisplay::text( const QList<CSwordModuleInfo*>& modules, cons
CSwordVerseKey k1(module);
k1.Headings(1);
- k1.key(keyName);
+ k1.setKey(keyName);
// don't print the key
CTextRendering::KeyTreeItem::Settings preverse_settings(false, CTextRendering::KeyTreeItem::Settings::NoKey);
diff --git a/src/backend/rendering/centrydisplay.h b/src/backend/rendering/centrydisplay.h
index 5f410a5..08a55c4 100644
--- a/src/backend/rendering/centrydisplay.h
+++ b/src/backend/rendering/centrydisplay.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.
*
**********/
@@ -10,35 +10,28 @@
#ifndef CENTRYDISPLAY_H
#define CENTRYDISPLAY_H
-#include "util/cpointers.h"
-
#include <QString>
-#include "backend/managers/cswordbackend.h"
// Sword includes:
#include <swdisp.h>
class CSwordModuleInfo;
+struct DisplayOptions;
+struct FilterOptions;
namespace Rendering {
-/**
-* The reimplementation of SWDisplay to fit our needs.
-* @short Display implementation
-* @author The BibleTime team
-*/
-
-class CEntryDisplay : public sword::SWDisplay, public CPointers {
-
+class CEntryDisplay: public sword::SWDisplay {
public:
- virtual ~CEntryDisplay() {}
-
/**
- * Returns the rendered text using the modules in the list and using the key parameter.
- * The displayoptions and filter options are used, too.
+ \returns the rendered text using the modules in the list and using the
+ key parameter.
*/
- virtual const QString text( const QList<CSwordModuleInfo*>& modules, const QString& key, const CSwordBackend::DisplayOptions displayOptions, const CSwordBackend::FilterOptions filterOptions);
+ virtual const QString text(const QList<const CSwordModuleInfo*> &modules,
+ const QString &key,
+ const DisplayOptions &displayOptions,
+ const FilterOptions &filterOptions);
};
diff --git a/src/backend/rendering/chtmlexportrendering.cpp b/src/backend/rendering/chtmlexportrendering.cpp
index 6a571c6..3d82602 100644
--- a/src/backend/rendering/chtmlexportrendering.cpp
+++ b/src/backend/rendering/chtmlexportrendering.cpp
@@ -2,15 +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/rendering/chtmlexportrendering.h"
-#include <boost/scoped_ptr.hpp>
-#include <iostream>
+#include <QSharedPointer>
#include <QDebug>
#include "backend/drivers/cswordmoduleinfo.h"
@@ -18,42 +17,43 @@
#include "backend/keys/cswordversekey.h"
#include "backend/managers/cdisplaytemplatemgr.h"
#include "backend/managers/clanguagemgr.h"
-#include "util/cpointers.h"
+#ifdef BT_DEBUG
namespace {
-/*
- * Helper function to dump a verse with all its enty attributes
- */
-
+/** Helper function to dump a verse with all its enty attributes. */
void dumpEntryAttributes(sword::SWModule *module) {
- std::cout << "Attributes for key: " << module->getKeyText() << std::endl;
+ qDebug() << "Attributes for key: " << module->getKeyText();
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";
+ qDebug() << "[ " << i1->first << " ]";
for (i2 = i1->second.begin(); i2 != i1->second.end(); i2++) {
- std::cout << "\t[ " << i2->first << " ]\n";
+ qDebug() << "\t[ " << i2->first << " ]";
for (i3 = i2->second.begin(); i3 != i2->second.end(); i3++) {
- std::cout << "\t\t" << i3->first << " = " << i3->second << "\n";
+ qDebug() << "\t\t" << i3->first << " = " << i3->second;
}
}
}
- std::cout << std::endl;
}
-}
+} // anonymous namespace
+#endif
namespace Rendering {
-CHTMLExportRendering::CHTMLExportRendering(const CHTMLExportRendering::Settings& settings, CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions)
+CHTMLExportRendering::CHTMLExportRendering(
+ const CHTMLExportRendering::Settings &settings,
+ const DisplayOptions &displayOptions,
+ const FilterOptions &filterOptions)
: m_displayOptions(displayOptions),
- m_filterOptions(filterOptions),
- m_settings(settings) {}
-
-CHTMLExportRendering::~CHTMLExportRendering() {}
+ m_filterOptions(filterOptions),
+ m_settings(settings)
+{
+ // Intentionally empty
+}
const QString CHTMLExportRendering::renderEntry( const KeyTreeItem& i, CSwordKey* k) {
@@ -62,13 +62,13 @@ const QString CHTMLExportRendering::renderEntry( const KeyTreeItem& i, CSwordKey
ret.append(i.getAlternativeContent());
// Q_ASSERT(i.hasChildItems());
-
+
if (!i.childList()->isEmpty()) {
KeyTree * const tree = i.childList();
- const QList<CSwordModuleInfo*> modules = collectModules(tree);
+ const QList<const CSwordModuleInfo*> modules = collectModules(tree);
- if (modules.count() == 1) { //insert the direction into the sorrounding div
+ if (modules.count() == 1) { //insert the direction into the surrounding div
ret.insert( 5, QString("dir=\"%1\" ").arg((modules.first()->textDirection() == CSwordModuleInfo::LeftToRight) ? "ltr" : "rtl" ));
}
@@ -82,13 +82,13 @@ const QString CHTMLExportRendering::renderEntry( const KeyTreeItem& i, CSwordKey
}
- const QList<CSwordModuleInfo*>& modules( i.modules() );
+ const QList<const CSwordModuleInfo*> &modules(i.modules());
if (modules.count() == 0) {
return QString(""); //no module present for rendering
}
- boost::scoped_ptr<CSwordKey> scoped_key( !k ? CSwordKey::createInstance(modules.first()) : 0 );
- CSwordKey* key = k ? k : scoped_key.get();
+ QSharedPointer<CSwordKey> scoped_key( !k ? CSwordKey::createInstance(modules.first()) : 0 );
+ CSwordKey* key = k ? k : scoped_key.data();
Q_ASSERT(key);
CSwordVerseKey* myVK = dynamic_cast<CSwordVerseKey*>(key);
@@ -100,19 +100,17 @@ const QString CHTMLExportRendering::renderEntry( const KeyTreeItem& i, CSwordKey
//declarations out of the loop for optimization
QString entry;
- QString keyText;
bool isRTL;
QString preverseHeading;
QString langAttr;
QString key_renderedText;
- QList<CSwordModuleInfo*>::const_iterator end_modItr = modules.end();
+ QList<const CSwordModuleInfo*>::const_iterator end_modItr = modules.end();
- for (QList<CSwordModuleInfo*>::const_iterator mod_Itr(modules.begin()); mod_Itr != end_modItr; ++mod_Itr) {
- key->module(*mod_Itr);
- key->key( i.key() );
+ for (QList<const CSwordModuleInfo*>::const_iterator mod_Itr(modules.begin()); mod_Itr != end_modItr; ++mod_Itr) {
+ key->setModule(*mod_Itr);
+ key->setKey(i.key());
- keyText = key->key();
isRTL = ((*mod_Itr)->textDirection() == CSwordModuleInfo::RightToLeft);
entry = QString::null;
@@ -144,7 +142,16 @@ const QString CHTMLExportRendering::renderEntry( const KeyTreeItem& i, CSwordKey
(*mod_Itr)->module()->getEntryAttributes()["Heading"]["Preverse"].end();
for (; it != end; ++it) {
- preverseHeading = QString::fromUtf8(it->second.c_str());
+ QString unfiltered = it->second.c_str();
+
+ /// \todo This is only a preliminary workaround to strip the tags:
+ QRegExp filter("<title>(.*)</title>");
+ if (unfiltered.indexOf(filter) >= 0) {
+ preverseHeading = filter.cap(1);
+ } else {
+ preverseHeading = unfiltered;
+ }
+
/// \todo Take care of the heading type!
if (!preverseHeading.isEmpty()) {
entry.append("<div ")
@@ -207,16 +214,16 @@ const QString CHTMLExportRendering::renderEntry( const KeyTreeItem& i, CSwordKey
}
void CHTMLExportRendering::initRendering() {
- //CPointers::backend()->setDisplayOptions( m_displayOptions );
- CPointers::backend()->setFilterOptions( m_filterOptions );
+ //CSwordBackend::instance()()->setDisplayOptions( m_displayOptions );
+ CSwordBackend::instance()->setFilterOptions( m_filterOptions );
}
const QString CHTMLExportRendering::finishText( const QString& text, KeyTree& tree ) {
- const QList<CSwordModuleInfo*> modules = collectModules(&tree);
+ const QList<const CSwordModuleInfo*> modules = collectModules(&tree);
const CLanguageMgr::Language* const lang = modules.first()->language();
- CDisplayTemplateMgr* tMgr = CPointers::displayTemplateManager();
+ CDisplayTemplateMgr *tMgr = CDisplayTemplateMgr::instance();
CDisplayTemplateMgr::Settings settings;
settings.modules = modules;
settings.langAbbrev = ((modules.count() == 1) && lang->isValid()) ? lang->abbrev() : "unknown";
@@ -231,7 +238,11 @@ const QString CHTMLExportRendering::finishText( const QString& text, KeyTree& tr
/*!
\fn CHTMLExportRendering::entryLink( KeyTreeItem& item )
*/
-const QString CHTMLExportRendering::entryLink( const KeyTreeItem& item, CSwordModuleInfo* ) {
+const QString CHTMLExportRendering::entryLink(const KeyTreeItem& item,
+ const CSwordModuleInfo *module)
+{
+ Q_UNUSED(module);
+
return item.key();
}
diff --git a/src/backend/rendering/chtmlexportrendering.h b/src/backend/rendering/chtmlexportrendering.h
index 065bb85..97e632d 100644
--- a/src/backend/rendering/chtmlexportrendering.h
+++ b/src/backend/rendering/chtmlexportrendering.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.
*
**********/
@@ -14,6 +14,7 @@
#include "backend/config/cbtconfig.h"
#include "backend/managers/cswordbackend.h"
+#include "btglobal.h"
namespace Rendering {
@@ -37,20 +38,21 @@ class CHTMLExportRendering : public CTextRendering {
};
CHTMLExportRendering(
- const Settings& settings,
- CSwordBackend::DisplayOptions displayOptions = CBTConfig::getDisplayOptionDefaults(),
- CSwordBackend::FilterOptions filterOptions = CBTConfig::getFilterOptionDefaults()
+ const Settings &settings,
+ const DisplayOptions &displayOptions = CBTConfig::getDisplayOptionDefaults(),
+ const FilterOptions &filterOptions = CBTConfig::getFilterOptionDefaults()
);
- virtual ~CHTMLExportRendering();
+ virtual inline ~CHTMLExportRendering() {};
protected:
virtual const QString renderEntry( const KeyTreeItem&, CSwordKey* = 0 );
virtual const QString finishText( const QString&, KeyTree& tree );
- virtual const QString entryLink( const KeyTreeItem& item, CSwordModuleInfo* module );
+ virtual const QString entryLink(const KeyTreeItem &item,
+ const CSwordModuleInfo *module);
virtual void initRendering();
- CSwordBackend::DisplayOptions m_displayOptions;
- CSwordBackend::FilterOptions m_filterOptions;
+ DisplayOptions m_displayOptions;
+ FilterOptions m_filterOptions;
Settings m_settings;
};
diff --git a/src/backend/rendering/cplaintextexportrendering.cpp b/src/backend/rendering/cplaintextexportrendering.cpp
index fdbf78d..cad5eb9 100644
--- a/src/backend/rendering/cplaintextexportrendering.cpp
+++ b/src/backend/rendering/cplaintextexportrendering.cpp
@@ -2,40 +2,48 @@
*
* 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/rendering/cplaintextexportrendering.h"
-#include <boost/scoped_ptr.hpp>
+#include <QSharedPointer>
#include "backend/keys/cswordkey.h"
namespace Rendering {
-CPlainTextExportRendering::CPlainTextExportRendering(const CPlainTextExportRendering::Settings& settings, CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions)
- : CHTMLExportRendering(settings, displayOptions, filterOptions) {}
+CPlainTextExportRendering::CPlainTextExportRendering(
+ const CPlainTextExportRendering::Settings &settings,
+ const DisplayOptions &displayOptions,
+ const FilterOptions &filterOptions)
+ : CHTMLExportRendering(settings, displayOptions, filterOptions)
+{
+ // Intentionally empty
+}
-CPlainTextExportRendering::~CPlainTextExportRendering() {}
+const QString CPlainTextExportRendering::renderEntry(const KeyTreeItem &i,
+ CSwordKey *k)
+{
+ Q_UNUSED(k);
-const QString CPlainTextExportRendering::renderEntry( const KeyTreeItem& i, CSwordKey* ) {
if (!m_settings.addText) {
return QString(i.key()).append("\n");
}
- QList<CSwordModuleInfo*> modules = i.modules();
- boost::scoped_ptr<CSwordKey> key( CSwordKey::createInstance(modules.first()) );
+ QList<const CSwordModuleInfo*> modules = i.modules();
+ QSharedPointer<CSwordKey> key( CSwordKey::createInstance(modules.first()) );
QString renderedText = QString(i.key()).append(":\n");
QString entry;
// for (CSwordModuleInfo* m = modules.first(); m; m = modules.next()) {
- QList<CSwordModuleInfo*>::iterator end_it = modules.end();
+ QList<const CSwordModuleInfo*>::iterator end_it = modules.end();
- for (QList<CSwordModuleInfo*>::iterator it(modules.begin()); it != end_it; ++it) {
- key->module(*it);
- key->key( i.key() );
+ for (QList<const CSwordModuleInfo*>::iterator it(modules.begin()); it != end_it; ++it) {
+ key->setModule(*it);
+ key->setKey(i.key());
/// \todo Check this code
entry.append(key->strippedText()).append("\n");
diff --git a/src/backend/rendering/cplaintextexportrendering.h b/src/backend/rendering/cplaintextexportrendering.h
index 5ebbb24..d14192e 100644
--- a/src/backend/rendering/cplaintextexportrendering.h
+++ b/src/backend/rendering/cplaintextexportrendering.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.
*
**********/
@@ -25,11 +25,11 @@ class CPlainTextExportRendering : public CHTMLExportRendering {
public:
CPlainTextExportRendering(
- const Settings& settings,
- CSwordBackend::DisplayOptions displayOptions = CBTConfig::getDisplayOptionDefaults(),
- CSwordBackend::FilterOptions filterOptions = CBTConfig::getFilterOptionDefaults()
+ const Settings &settings,
+ const DisplayOptions &displayOptions = CBTConfig::getDisplayOptionDefaults(),
+ const FilterOptions &filterOptions = CBTConfig::getFilterOptionDefaults()
);
- virtual ~CPlainTextExportRendering();
+ virtual inline ~CPlainTextExportRendering() {};
protected:
virtual const QString renderEntry( const KeyTreeItem&, CSwordKey* = 0 );
diff --git a/src/backend/rendering/ctextrendering.cpp b/src/backend/rendering/ctextrendering.cpp
index 645b5d6..586d11e 100644
--- a/src/backend/rendering/ctextrendering.cpp
+++ b/src/backend/rendering/ctextrendering.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/rendering/ctextrendering.h"
-#include <boost/scoped_ptr.hpp>
+#include <QSharedPointer>
#include <QRegExp>
#include <QtAlgorithms>
@@ -26,17 +26,20 @@
using namespace Rendering;
-CTextRendering::KeyTreeItem::KeyTreeItem(const QString& key, CSwordModuleInfo const * mod, const Settings settings )
- : m_settings( settings ),
+CTextRendering::KeyTreeItem::KeyTreeItem(const QString &key,
+ const CSwordModuleInfo *module,
+ const Settings &settings)
+ : m_settings(settings),
m_moduleList(),
m_key( key ),
m_childList(),
m_stopKey( QString::null ),
m_alternativeContent( QString::null ) {
- m_moduleList.append( const_cast<CSwordModuleInfo*>(mod) ); //BAD CODE
+ m_moduleList.append( const_cast<CSwordModuleInfo*>(module) ); //BAD CODE
}
-CTextRendering::KeyTreeItem::KeyTreeItem(const QString& content, const Settings settings )
+CTextRendering::KeyTreeItem::KeyTreeItem(const QString &content,
+ const Settings &settings)
: m_settings( settings ),
m_moduleList(),
m_key( QString::null ),
@@ -45,7 +48,9 @@ CTextRendering::KeyTreeItem::KeyTreeItem(const QString& content, const Settings
m_alternativeContent( content ) {
}
-CTextRendering::KeyTreeItem::KeyTreeItem(const QString& key, const QList<CSwordModuleInfo*>& mods, const Settings settings )
+CTextRendering::KeyTreeItem::KeyTreeItem(const QString &key,
+ const QList<const CSwordModuleInfo*> &mods,
+ const Settings &settings)
: m_settings( settings ),
m_moduleList( mods ),
m_key( key ),
@@ -76,11 +81,10 @@ CTextRendering::KeyTreeItem::KeyTreeItem(const KeyTreeItem& i)
}
-CTextRendering::KeyTreeItem::~KeyTreeItem() {
- qDeleteAll(m_childList);
-}
-
-CTextRendering::KeyTreeItem::KeyTreeItem(const QString& startKey, const QString& stopKey, CSwordModuleInfo* module, const Settings settings)
+CTextRendering::KeyTreeItem::KeyTreeItem(const QString &startKey,
+ const QString &stopKey,
+ const CSwordModuleInfo *module,
+ const Settings &settings)
: m_settings( settings ),
m_moduleList(),
m_key( startKey ),
@@ -94,10 +98,10 @@ CTextRendering::KeyTreeItem::KeyTreeItem(const QString& startKey, const QString&
if (module->type() == CSwordModuleInfo::Bible) {
CSwordVerseKey start(module);
- start.key(startKey);
+ start.setKey(startKey);
CSwordVerseKey stop(module);
- stop.key(stopKey);
+ stop.setKey(stopKey);
if (!m_key.isEmpty() && !m_stopKey.isEmpty()) { //we have a range of keys
bool ok = true;
@@ -154,13 +158,13 @@ const QString& CTextRendering::KeyTreeItem::getAlternativeContent() const {
return m_alternativeContent;
}
-const QList<CSwordModuleInfo*> CTextRendering::collectModules(KeyTree* const tree) const {
+const QList<const CSwordModuleInfo*> CTextRendering::collectModules(KeyTree* const tree) const {
//collect all modules which are available and used by child items
- QList<CSwordModuleInfo*> modules;
+ QList<const CSwordModuleInfo*> modules;
foreach (KeyTreeItem* c, (*tree)) {
Q_ASSERT(c);
- foreach (CSwordModuleInfo* mod, c->modules()) {
+ foreach (const CSwordModuleInfo* mod, c->modules()) {
if (!modules.contains(mod)) {
modules.append(mod);
}
@@ -172,20 +176,22 @@ const QList<CSwordModuleInfo*> CTextRendering::collectModules(KeyTree* const tre
const QString CTextRendering::renderKeyTree( KeyTree& tree ) {
initRendering();
- QList<CSwordModuleInfo*> modules = collectModules(&tree);
+ QList<const CSwordModuleInfo*> modules = collectModules(&tree);
QString t;
//optimization for entries with the same key
- boost::scoped_ptr<CSwordKey> key(
+ QSharedPointer<CSwordKey> key(
(modules.count() == 1) ? CSwordKey::createInstance(modules.first()) : 0
);
- foreach (KeyTreeItem* c, tree) {
- if (modules.count() == 1) { //this optimizes the rendering, only one key created for all items
- key->key( c->key() );
- t.append( renderEntry( *c, key.get()) );
+ if (modules.count() == 1) { //this optimizes the rendering, only one key created for all items
+ foreach (KeyTreeItem* c, tree) {
+ key->setKey(c->key());
+ t.append( renderEntry( *c, key.data()) );
}
- else {
+ }
+ else {
+ foreach (KeyTreeItem* c, tree) {
t.append( renderEntry( *c ) );
}
}
@@ -193,19 +199,25 @@ const QString CTextRendering::renderKeyTree( KeyTree& tree ) {
return finishText(t, tree);
}
-const QString CTextRendering::renderKeyRange( const QString& start, const QString& stop, const QList<CSwordModuleInfo*>& modules, const QString& highlightKey, const KeyTreeItem::Settings& keySettings ) {
+const QString CTextRendering::renderKeyRange(
+ const QString &start,
+ const QString &stop,
+ const QList<const CSwordModuleInfo*> &modules,
+ const QString &highlightKey,
+ const KeyTreeItem::Settings &keySettings)
+{
- CSwordModuleInfo* module = modules.first();
+ const CSwordModuleInfo *module = modules.first();
//qWarning( "renderKeyRange start %s stop %s \n", start.latin1(), stop.latin1() );
- boost::scoped_ptr<CSwordKey> lowerBound( CSwordKey::createInstance(module) );
- lowerBound->key(start);
+ QSharedPointer<CSwordKey> lowerBound( CSwordKey::createInstance(module) );
+ lowerBound->setKey(start);
- boost::scoped_ptr<CSwordKey> upperBound( CSwordKey::createInstance(module) );
- upperBound->key(stop);
+ QSharedPointer<CSwordKey> upperBound( CSwordKey::createInstance(module) );
+ upperBound->setKey(stop);
- sword::SWKey* sw_start = dynamic_cast<sword::SWKey*>(lowerBound.get());
- sword::SWKey* sw_stop = dynamic_cast<sword::SWKey*>(upperBound.get());
+ sword::SWKey* sw_start = dynamic_cast<sword::SWKey*>(lowerBound.data());
+ sword::SWKey* sw_stop = dynamic_cast<sword::SWKey*>(upperBound.data());
Q_ASSERT((*sw_start == *sw_stop) || (*sw_start < *sw_stop));
@@ -216,10 +228,10 @@ const QString CTextRendering::renderKeyRange( const QString& start, const QStrin
KeyTree tree;
KeyTreeItem::Settings settings = keySettings;
- CSwordVerseKey* vk_start = dynamic_cast<CSwordVerseKey*>(lowerBound.get());
+ CSwordVerseKey* vk_start = dynamic_cast<CSwordVerseKey*>(lowerBound.data());
Q_ASSERT(vk_start);
- CSwordVerseKey* vk_stop = dynamic_cast<CSwordVerseKey*>(upperBound.get());
+ CSwordVerseKey* vk_stop = dynamic_cast<CSwordVerseKey*>(upperBound.data());
Q_ASSERT(vk_stop);
bool ok = true;
@@ -250,13 +262,15 @@ const QString CTextRendering::renderKeyRange( const QString& start, const QStrin
return QString::null;
}
-const QString CTextRendering::renderSingleKey( const QString& key, const QList<CSwordModuleInfo*>& moduleList, const KeyTreeItem::Settings& settings ) {
+const QString CTextRendering::renderSingleKey(
+ const QString &key,
+ const QList<const CSwordModuleInfo*> &modules,
+ const KeyTreeItem::Settings &settings)
+{
KeyTree tree;
- tree.append( new KeyTreeItem(key, moduleList, settings) );
+ tree.append( new KeyTreeItem(key, modules, settings) );
const QString renderedText = renderKeyTree(tree);
qDeleteAll(tree);
return renderedText;
}
-
-
diff --git a/src/backend/rendering/ctextrendering.h b/src/backend/rendering/ctextrendering.h
index b6dd5e1..c6b187a 100644
--- a/src/backend/rendering/ctextrendering.h
+++ b/src/backend/rendering/ctextrendering.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.
*
**********/
@@ -53,13 +53,26 @@ class CTextRendering {
KeyRenderingFace keyRenderingFace;
};
- KeyTreeItem(const QString& key, CSwordModuleInfo const * module, const Settings settings);
- KeyTreeItem(const QString& key, const QList<CSwordModuleInfo*>& modules, const Settings settings);
- KeyTreeItem(const QString& startKey, const QString& stopKey, CSwordModuleInfo* module, const Settings settings);
- KeyTreeItem(const QString& content, const Settings settings);
- KeyTreeItem(const KeyTreeItem& i);
+ KeyTreeItem(const QString &key,
+ const CSwordModuleInfo *module,
+ const Settings &settings);
- virtual ~KeyTreeItem();
+ KeyTreeItem(const QString &key,
+ const QList<const CSwordModuleInfo*> &modules,
+ const Settings &settings);
+
+ KeyTreeItem(const QString &startKey,
+ const QString &stopKey,
+ const CSwordModuleInfo *module,
+ const Settings &settings);
+
+ KeyTreeItem(const QString &content, const Settings &settings);
+
+ KeyTreeItem(const KeyTreeItem &i);
+
+ virtual inline ~KeyTreeItem() {
+ qDeleteAll(m_childList);
+ }
const QString& getAlternativeContent() const;
inline void setAlternativeContent(const QString& newContent) {
@@ -70,7 +83,7 @@ class CTextRendering {
return !m_alternativeContent.isNull();
};
- inline const QList<CSwordModuleInfo*>& modules() const {
+ inline const QList<const CSwordModuleInfo*>& modules() const {
return m_moduleList;
};
@@ -83,13 +96,13 @@ class CTextRendering {
};
inline KeyTree* childList() const;
-// inline const bool hasChildItems() const;
+// inline const bool hasChildItems() const;
protected:
KeyTreeItem();
Settings m_settings;
- QList<CSwordModuleInfo*> m_moduleList;
+ QList<const CSwordModuleInfo*> m_moduleList;
QString m_key;
mutable KeyTree m_childList;
@@ -101,12 +114,20 @@ class CTextRendering {
const QString renderKeyTree( KeyTree& );
- const QString renderKeyRange( const QString& start, const QString& stop, const QList<CSwordModuleInfo*>& modules, const QString& hightlightKey = QString::null, const KeyTreeItem::Settings& settings = KeyTreeItem::Settings() );
+ const QString renderKeyRange(
+ const QString &start,
+ const QString &stop,
+ const QList<const CSwordModuleInfo*> &modules,
+ const QString &hightlightKey = QString::null,
+ const KeyTreeItem::Settings &settings = KeyTreeItem::Settings());
- const QString renderSingleKey( const QString& key, const QList<CSwordModuleInfo*>&, const KeyTreeItem::Settings& settings = KeyTreeItem::Settings() );
+ const QString renderSingleKey(
+ const QString &key,
+ const QList<const CSwordModuleInfo*> &modules,
+ const KeyTreeItem::Settings &settings = KeyTreeItem::Settings());
protected:
- const QList<CSwordModuleInfo*> collectModules(KeyTree* const tree) const;
+ const QList<const CSwordModuleInfo*> collectModules(KeyTree* const tree) const;
virtual const QString renderEntry( const KeyTreeItem&, CSwordKey* = 0 ) = 0;
virtual const QString finishText( const QString&, KeyTree& tree ) = 0;
virtual void initRendering() = 0;
@@ -117,7 +138,7 @@ inline CTextRendering::KeyTree* CTextRendering::KeyTreeItem::childList() const {
}
//
//inline const bool CTextRendering::KeyTreeItem::hasChildItems() const {
-// return !m_childList.isEmpty();
+// return !m_childList.isEmpty();
//}
}