diff options
Diffstat (limited to 'src/backend')
45 files changed, 832 insertions, 823 deletions
diff --git a/src/backend/bookshelfmodel/btbookshelfmodel.cpp b/src/backend/bookshelfmodel/btbookshelfmodel.cpp index c6aab1b..322b22a 100644 --- a/src/backend/bookshelfmodel/btbookshelfmodel.cpp +++ b/src/backend/bookshelfmodel/btbookshelfmodel.cpp @@ -54,6 +54,10 @@ QVariant BtBookshelfModel::data(CSwordModuleInfo *module, int role) const { return (qulonglong) module->indexSize(); case ModuleDescriptionRole: return module->config(CSwordModuleInfo::Description); + case Qt::ToolTipRole: + return QString("<b>%1:</b><br/>%2") + .arg(module->name()) + .arg(module->config(CSwordModuleInfo::Description)); default: return QVariant(); } diff --git a/src/backend/bookshelfmodel/btbookshelftreemodel.cpp b/src/backend/bookshelfmodel/btbookshelftreemodel.cpp index 6444a81..3d6008f 100644 --- a/src/backend/bookshelfmodel/btbookshelftreemodel.cpp +++ b/src/backend/bookshelfmodel/btbookshelftreemodel.cpp @@ -27,8 +27,11 @@ using namespace BookshelfModel; bool BtBookshelfTreeModel::Grouping::loadFrom(const QString &configKey) { Q_ASSERT(!configKey.isNull()); QVariant v = CBTConfig::getConfig()->value(configKey); + if (!v.canConvert<Grouping>()) + return false; + (*this) = v.value<Grouping>(); - return v.canConvert<Grouping>(); + return true; } void BtBookshelfTreeModel::Grouping::saveTo(const QString &configKey) const { diff --git a/src/backend/bookshelfmodel/btbookshelftreemodel.h b/src/backend/bookshelfmodel/btbookshelftreemodel.h index 2a28dd8..085095d 100644 --- a/src/backend/bookshelfmodel/btbookshelftreemodel.h +++ b/src/backend/bookshelfmodel/btbookshelftreemodel.h @@ -59,13 +59,17 @@ class BtBookshelfTreeModel: public QAbstractItemModel { \warning Be careful using this constructor! */ explicit inline Grouping(bool empty = false) { - if (empty) return; + 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); + if (loadFrom(configKey)) + return; + push_back(GROUP_CATEGORY); + push_back(GROUP_LANGUAGE); } inline Grouping(const Grouping ©) : QList<Group>(copy) {} diff --git a/src/backend/btinstallbackend.cpp b/src/backend/btinstallbackend.cpp index 67f8945..c1136bf 100644 --- a/src/backend/btinstallbackend.cpp +++ b/src/backend/btinstallbackend.cpp @@ -30,7 +30,6 @@ 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 @@ -49,7 +48,6 @@ bool addSource(sword::InstallSource& source) { /** 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()) { @@ -84,7 +82,6 @@ sword::InstallSource source(const QString &name) { /** Deletes the source. */ bool deleteSource(const QString &name) { - qDebug() << "backend::deleteSource"; sword::InstallSource is = source(name ); SWConfig config(configFilename().toLatin1()); @@ -108,7 +105,7 @@ bool deleteSource(const QString &name) { ++it; } if (notFound) { - qDebug() << "source was not found, try without uid"; + qDebug() << "source was not found, trying without uid"; //try again without uid QString sce(sourceConfigEntry.c_str()); QStringList l = sce.split('|'); @@ -116,7 +113,6 @@ bool deleteSource(const QString &name) { sce = l.join("|").append("|"); it = range.first; while (it != range.second) { - qDebug() << it->second; if (it->second == sce) { config["Sources"].erase(it); break; @@ -148,7 +144,6 @@ QString configFilename() { } QStringList targetList() { - qDebug() << "backend::targetList"; QStringList names = CSwordBackend::instance()->swordDirList(); return names; } @@ -156,7 +151,6 @@ QStringList targetList() { 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"); @@ -174,10 +168,7 @@ bool setTargetList( const QStringList& targets ) { f.close(); i.refresh(); } - if ( i.exists() && i.isWritable() ) { //we can write to the file ourself - qDebug() << "The Sword config file is writable"; - } - else { + if (!i.exists() || !i.isWritable()) { // 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!")); @@ -213,14 +204,13 @@ bool setTargetList( const QStringList& targets ) { setDataPath = true; } } - qDebug() << "save the sword conf..."; + qDebug() << "Saving Sword configuration ..."; conf.Save(); CSwordBackend::instance()->reloadModules(CSwordBackend::PathChanged); return true; } QStringList sourceNameList() { - qDebug() << "backend::sourceList"; BtInstallMgr mgr; Q_ASSERT(mgr.installConf); @@ -251,7 +241,6 @@ QStringList sourceNameList() { void initPassiveFtpMode() { - qDebug() << "backend::initPassiveFtpMode"; SWConfig config(configFilename().toLatin1()); config["General"]["PassiveFTP"] = "true"; config.Save(); @@ -259,13 +248,13 @@ void initPassiveFtpMode() { QString swordConfigFilename() { namespace DU = util::directory; - qDebug() << "backend::swordConfigFilename"; + qDebug() << "Sword config:" #ifdef Q_WS_WIN - qDebug() << DU::getUserHomeDir().absolutePath().append("/Sword/sword.conf"); + << 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"); + << DU::getUserHomeDir().absolutePath().append("/.sword/sword.conf"); return DU::getUserHomeDir().absolutePath().append("/.sword/sword.conf"); #endif } @@ -281,7 +270,6 @@ QDir swordDir() { } CSwordBackend* backend( const sword::InstallSource& is) { - qDebug() << "backend::backend"; CSwordBackend* ret = 0; /// \anchor BackendNotSingleton if (isRemote(is)) { diff --git a/src/backend/btmoduletreeitem.cpp b/src/backend/btmoduletreeitem.cpp index c57d094..4c16231 100644 --- a/src/backend/btmoduletreeitem.cpp +++ b/src/backend/btmoduletreeitem.cpp @@ -9,7 +9,6 @@ #include "backend/btmoduletreeitem.h" -#include <QDebug> #include <QList> #include <QString> #include "backend/drivers/cswordmoduleinfo.h" @@ -24,7 +23,8 @@ BTModuleTreeItem::BTModuleTreeItem(QList<BTModuleTreeItem::Filter*>& filters, BT m_firstChild(0), m_next(0), m_type(BTModuleTreeItem::Root), - m_category(CSwordModuleInfo::UnknownCategory) { + m_category(CSwordModuleInfo::UnknownCategory), + m_grouping (grouping) { if (modules) { m_originalModuleList = *modules; } @@ -32,7 +32,7 @@ BTModuleTreeItem::BTModuleTreeItem(QList<BTModuleTreeItem::Filter*>& filters, BT m_originalModuleList = CSwordBackend::instance()->moduleList(); } //populate the tree with groups/modules - create_tree(filters, grouping); + create_tree(filters); } /** @@ -64,12 +64,10 @@ BTModuleTreeItem::~BTModuleTreeItem() { } QList<BTModuleTreeItem*> BTModuleTreeItem::children() const { - //qDebug() << "BTModuleTreeItem::children"; QList<BTModuleTreeItem*> childList; if (m_firstChild) { BTModuleTreeItem* child = m_firstChild; while (child) { - //qDebug() << "child:" << child->text(); childList.append(child); child = child->m_next; } @@ -120,26 +118,26 @@ QString BTModuleTreeItem::iconName() const { return QString::null; } - -void BTModuleTreeItem::create_tree(QList<BTModuleTreeItem::Filter*>& filters, BTModuleTreeItem::Grouping grouping) { - qDebug() << "BTModuleTreeItem::create_tree"; - static bool map_initialized = false; - static QMap<CSwordModuleInfo::Category, QString> CategoryNamesMap; - if (!map_initialized) { - CategoryNamesMap.insert(CSwordModuleInfo::Commentaries, QObject::tr("Commentaries")); - CategoryNamesMap.insert(CSwordModuleInfo::Cult, QObject::tr("Cults/Unorthodox")); - CategoryNamesMap.insert(CSwordModuleInfo::Images, QObject::tr("Maps and Images")); - CategoryNamesMap.insert(CSwordModuleInfo::DailyDevotional, QObject::tr("Daily Devotionals")); - CategoryNamesMap.insert(CSwordModuleInfo::Lexicons, QObject::tr("Lexicons and Dictionaries")); - CategoryNamesMap.insert(CSwordModuleInfo::Bibles, QObject::tr("Bibles")); - CategoryNamesMap.insert(CSwordModuleInfo::Glossary, QObject::tr("Glossaries")); - CategoryNamesMap.insert(CSwordModuleInfo::Books, QObject::tr("Books")); - - map_initialized = true; +bool BTModuleTreeItem::m_map_initialized = false; +QMap<CSwordModuleInfo::Category, QString> BTModuleTreeItem::m_CategoryNamesMap; + +void BTModuleTreeItem::create_tree(QList<BTModuleTreeItem::Filter*>& filters) { + if (!m_map_initialized) { + m_CategoryNamesMap.insert(CSwordModuleInfo::Commentaries, QObject::tr("Commentaries")); + m_CategoryNamesMap.insert(CSwordModuleInfo::Cult, QObject::tr("Cults/Unorthodox")); + m_CategoryNamesMap.insert(CSwordModuleInfo::Images, QObject::tr("Maps and Images")); + m_CategoryNamesMap.insert(CSwordModuleInfo::DailyDevotional, QObject::tr("Daily Devotionals")); + m_CategoryNamesMap.insert(CSwordModuleInfo::Lexicons, QObject::tr("Lexicons and Dictionaries")); + m_CategoryNamesMap.insert(CSwordModuleInfo::Bibles, QObject::tr("Bibles")); + m_CategoryNamesMap.insert(CSwordModuleInfo::Glossary, QObject::tr("Glossaries")); + m_CategoryNamesMap.insert(CSwordModuleInfo::Books, QObject::tr("Books")); + + m_map_initialized = true; } + add_items(filters); +} - //QList<CSwordModuleInfo*> originalInfoList = CSwordBackend::instance()()->moduleList(); - +void BTModuleTreeItem::add_items(QList<BTModuleTreeItem::Filter*>& filters) { foreach (CSwordModuleInfo* info, m_originalModuleList) { bool included; included = true; @@ -150,39 +148,37 @@ void BTModuleTreeItem::create_tree(QList<BTModuleTreeItem::Filter*>& filters, BT } } if (included) { - //qDebug() << "a module will be included: " << info->name(); - BTModuleTreeItem* parentGroupForModule = this; BTModuleTreeItem* parentGroupForLanguage = this; BTModuleTreeItem* parentGroupForCategory = this; //the order of if(grouping...) clauses is important - if (grouping == BTModuleTreeItem::LangMod || grouping == BTModuleTreeItem::LangCatMod) { + if (m_grouping == BTModuleTreeItem::LangMod || m_grouping == BTModuleTreeItem::LangCatMod) { BTModuleTreeItem* langItem = create_parent_item(parentGroupForLanguage, info->language()->translatedName(), BTModuleTreeItem::Language); - if (grouping == BTModuleTreeItem::LangMod) + if (m_grouping == BTModuleTreeItem::LangMod) parentGroupForModule = langItem; else parentGroupForCategory = langItem; } - if (grouping == BTModuleTreeItem::CatMod || grouping == BTModuleTreeItem::CatLangMod) { - BTModuleTreeItem* catItem = create_parent_item(parentGroupForCategory, CategoryNamesMap.value(info->category()), BTModuleTreeItem::Category, info->category()); + if (m_grouping == BTModuleTreeItem::CatMod || m_grouping == BTModuleTreeItem::CatLangMod) { + BTModuleTreeItem* catItem = create_parent_item(parentGroupForCategory, m_CategoryNamesMap.value(info->category()), BTModuleTreeItem::Category, info->category()); - if (grouping == BTModuleTreeItem::CatMod) + if (m_grouping == BTModuleTreeItem::CatMod) parentGroupForModule = catItem; else parentGroupForLanguage = catItem; } - if (grouping == BTModuleTreeItem::CatLangMod) { + if (m_grouping == BTModuleTreeItem::CatLangMod) { // category is there already, create language and make it the parent for the module parentGroupForModule = create_parent_item(parentGroupForLanguage, info->language()->translatedName(), BTModuleTreeItem::Language); } - if (grouping == BTModuleTreeItem::LangCatMod) { + if (m_grouping == BTModuleTreeItem::LangCatMod) { //language is there already, create category and make it the parent for the module - parentGroupForModule = create_parent_item(parentGroupForCategory, CategoryNamesMap.value(info->category()), BTModuleTreeItem::Category, info->category()); + parentGroupForModule = create_parent_item(parentGroupForCategory, m_CategoryNamesMap.value(info->category()), BTModuleTreeItem::Category, info->category()); } // the parent group for module has been set above, now just add the module to it @@ -214,8 +210,6 @@ BTModuleTreeItem* BTModuleTreeItem::create_parent_item( } void BTModuleTreeItem::sort_children(BTModuleTreeItem* parent) { - //qDebug() << "BTModuleTreeItem::sort_children"; - // sort each child recursively depth-first foreach(BTModuleTreeItem* item, parent->children()) { sort_children(item); @@ -259,3 +253,15 @@ bool BTModuleTreeItem::localeAwareLessThan(BTModuleTreeItem* first, BTModuleTree } return (QString::localeAwareCompare(first->text(), second->text()) < 0 ); } + +QDataStream &operator<<(QDataStream &out, const BTModuleTreeItem::Grouping &grouping) { + out << (qint8) grouping; + return out; +} + +QDataStream &operator>>(QDataStream &in, BTModuleTreeItem::Grouping &grouping) { + qint8 i; + in >> i; + grouping = (BTModuleTreeItem::Grouping) i; + return in; +} diff --git a/src/backend/btmoduletreeitem.h b/src/backend/btmoduletreeitem.h index 6ee6868..008bfb2 100644 --- a/src/backend/btmoduletreeitem.h +++ b/src/backend/btmoduletreeitem.h @@ -10,6 +10,7 @@ #ifndef BTMODULETREEITEM_H #define BTMODULETREEITEM_H +#include <QMap> #include <QString> #include "backend/drivers/cswordmoduleinfo.h" @@ -70,7 +71,6 @@ class BTModuleTreeItem { */ struct Filter { virtual bool filter(CSwordModuleInfo*) = 0; - inline virtual ~Filter() {}; }; /** @@ -81,7 +81,6 @@ class BTModuleTreeItem { inline bool filter(CSwordModuleInfo* mi) { return !mi->isHidden(); } - inline virtual ~HiddenOff() {}; }; /** @@ -94,7 +93,13 @@ class BTModuleTreeItem { * CatLangMod: first category, second language, third module. Mod: don't use * Category or Language at all, Module is toplevel and tree is flat. */ - enum Grouping {CatLangMod, CatMod, LangCatMod, LangMod, Mod}; + enum Grouping { + CatLangMod = 0, + CatMod = 1, + LangCatMod = 2, + LangMod = 3, + Mod = 4 + }; /** @@ -110,6 +115,9 @@ class BTModuleTreeItem { /** When the root item is deleted the whole tree is deleted. */ ~BTModuleTreeItem(); + /** Adds filtered items to the tree */ + void add_items(QList<BTModuleTreeItem::Filter*>& filters); + /** * Returns the item type. */ @@ -154,12 +162,16 @@ class BTModuleTreeItem { BTModuleTreeItem(); /** Creates the tree under this root item (called only from root ctor). */ - void create_tree(QList<BTModuleTreeItem::Filter*>& filters, BTModuleTreeItem::Grouping grouping); + void create_tree(QList<BTModuleTreeItem::Filter*>& filters); /** Sorts recursively the children of of the given item. */ void sort_children(BTModuleTreeItem* parent); /** Helper function for creating a group item while creating the tree. */ BTModuleTreeItem* create_parent_item(BTModuleTreeItem* parent, const QString& text, BTModuleTreeItem::Type type, CSwordModuleInfo::Category category = CSwordModuleInfo::UnknownCategory); + static bool m_map_initialized; + static QMap<CSwordModuleInfo::Category, QString> m_CategoryNamesMap; + + CSwordModuleInfo* m_moduleInfo; QString m_text; BTModuleTreeItem* m_firstChild; @@ -167,6 +179,11 @@ class BTModuleTreeItem { Type m_type; CSwordModuleInfo::Category m_category; QList<CSwordModuleInfo*> m_originalModuleList; + Grouping m_grouping; }; +QDataStream &operator<<(QDataStream &out, const BTModuleTreeItem::Grouping &grouping); +QDataStream &operator>>(QDataStream &in, BTModuleTreeItem::Grouping &grouping); +Q_DECLARE_METATYPE(BTModuleTreeItem::Grouping) + #endif diff --git a/src/backend/config/cbtconfig.cpp b/src/backend/config/cbtconfig.cpp index 883f41f..d82fc7d 100644 --- a/src/backend/config/cbtconfig.cpp +++ b/src/backend/config/cbtconfig.cpp @@ -44,7 +44,6 @@ QString getKey(const strings ID) { case bookshelfCurrentItem: return "bookshelfCurrentItem"; } - Q_ASSERT(false); return QString::null; } @@ -67,7 +66,6 @@ QString getKey(const modules ID) { case standardGreekMorphLexicon: return "standardGreekMorphLexicon"; } - Q_ASSERT(false); return QString::null; } @@ -78,8 +76,8 @@ QString getKey(const bools ID) { case readOldBookmarks: return "readOldBookmarks"; - case toolbar: - return "toolbar"; + case showMainWindowToolbar: + return "showMainWindowToolbar"; case mainIndex: return "mainIndex"; case infoDisplay: @@ -129,9 +127,10 @@ QString getKey(const bools ID) { return "showToolbarsInEachWindow"; case showTipAtStartup: return "showTipAtStartup"; + default: + Q_ASSERT(false); + return QString::null; } - Q_ASSERT(false); - return QString::null; } QString getKey(const ints ID) { @@ -198,9 +197,10 @@ QString getKey(const ints ID) { return "configDialogWidth"; case tipNumber: return "tipNumber"; + default: + Q_ASSERT(false); + return QString::null; } - Q_ASSERT(false); - return QString::null; } QString getKey(const intLists ID) { @@ -214,7 +214,6 @@ QString getKey(const intLists ID) { case searchResultSplitterSizes: return "searchResultSplitterSizes"; } - Q_ASSERT(false); return QString::null; } @@ -230,18 +229,15 @@ QString getKey(const stringLists ID) { return "bookshelfOpenGroups"; case hiddenModules: return "hiddenModules"; + default: + Q_ASSERT(false); + return QString::null; } - Q_ASSERT(false); - return QString::null; } QString getKey(const stringMaps ID) { - switch (ID) { - case searchScopes: - return "SearchScopes"; - }; - Q_ASSERT(false); - return QString::null; + Q_ASSERT(ID == searchScopes); + return "SearchScopes"; } QString getKey(const CLanguageMgr::Language * const language) { @@ -251,19 +247,36 @@ QString getKey(const CLanguageMgr::Language * const language) { } // anonymous namespace -QString IntListToString(const QList<int> intList) { +QString IntListToString(const QList<int> &intList) { QStringList intStrings; - foreach(int i, intList) { + Q_FOREACH (int i, intList) { intStrings << QString::number(i); } return intStrings.join(","); } -QList<int> StringToIntList(const QString &intListString) { +QList<int> StringToIntList(const QString &intListString, + bool *ok, + QString::SplitBehavior splitBehavior) +{ QList<int> intList; - if (!intListString.isEmpty() && intListString.contains(',')) { - foreach(QString intString, intListString.split(',')) { - intList << intString.trimmed().toInt(); + if (ok != 0) { + *ok = true; + + if (!intListString.isEmpty()) { + Q_FOREACH (const QString &intString, intListString.split(',', splitBehavior)) { + int i = intString.trimmed().toInt(ok); + if (!(*ok)) + break; + + intList << i; + } + } + } else { + if (!intListString.isEmpty()) { + Q_FOREACH (const QString &intString, intListString.split(',', splitBehavior)) { + intList << intString.trimmed().toInt(); + } } } return intList; @@ -276,15 +289,14 @@ QString getDefault(const strings ID) { case language: return QLocale::system().name(); case displayStyle: - return CDisplayTemplateMgr::defaultTemplate(); + return CDisplayTemplateMgr::defaultTemplateName(); case bookshelfCurrentItem: + default: return QString::null; } - return QString::null; } QString getDefault(const modules ID) { - // CSwordBackend *b = CSwordBackend::instance()(); switch (ID) { case standardBible: return "KJV"; @@ -303,171 +315,103 @@ QString getDefault(const modules ID) { return "StrongsHebrew"; case standardGreekMorphLexicon: return "StrongsGreek"; + default: + return QString::null; } - - return QString::null; } bool getDefault(const bools ID) { switch (ID) { case firstSearchDialog: - return true; - case readOldBookmarks: - return false; - - case toolbar: - return true; + case showMainWindowToolbar: case mainIndex: - return true; case infoDisplay: - return true; - case autoTileVertical: - return true; - case autoTileHorizontal: - return false; - case autoTile: - return false; - case autoTabbed: - return false; - case autoCascade: - return false; - - case lineBreaks: - return false; case verseNumbers: - return true; - case logo: - return true; case autoDeleteOrphanedIndices: - return true; - case crashedLastTime: - return false; - case crashedTwoTimes: - return false; - case bookshelfShowHidden: - return false; - case allowNetworkConnection: - return false; - case showTextWindowHeaders: - return true; case showTextWindowNavigator: - return true; case showTextWindowModuleSelectorButtons: - return true; case showTextWindowToolButtons: - return true; case showFormatToolbarButtons: - return true; case showToolbarsInEachWindow: - return true; case showTipAtStartup: return true; + case readOldBookmarks: + case autoTileHorizontal: + case autoTile: + case autoTabbed: + case autoCascade: + case lineBreaks: + case crashedLastTime: + case crashedTwoTimes: + case bookshelfShowHidden: + case allowNetworkConnection: + default: + return false; } - return false; } int getDefault(const ints ID) { switch (ID) { + case bookshelfGrouping: + return BTModuleTreeItem::CatLangMod; + case searchType: + return Search::BtSearchOptionsArea::AndType; + case searchDialogHeight: + case magDelay: + return 400; + case searchDialogWidth: + case searchDialogX: + case searchDialogY: + return 200; case footnotes: - return int(true); case strongNumbers: - return int(true); case headings: - return int(true); case morphTags: - return int(true); case lemmas: - return int(true); case hebrewPoints: - return int(true); case hebrewCantillation: - return int(true); case greekAccents: - return int(true); - case textualVariants: - return int(false); case scriptureReferences: - return int(true); case morphSegmentation: - return int(true); - case bookshelfContentsX: - return 0; - case bookshelfContentsY: - return 0; - case magDelay: - return 400; - case bookshelfGrouping: - return BTModuleTreeItem::CatLangMod; - case searchDialogWidth: - return 200; - case searchDialogHeight: - return 400; - case searchDialogX: - return 200; - case searchDialogY: - return 200; - case searchType: - return Search::BtSearchOptionsArea::AndType; - case mainindexActiveTab: - return 0; - case installPathIndex: - return 0; case bookshelfPosX: - return 1; case bookshelfPosY: - return 1; case bookshelfHeight: - return 1; case bookshelfWidth: - return 1; case configDialogPosX: - return 1; case configDialogPosY: - return 1; case configDialogHeight: - return 1; case configDialogWidth: return 1; + case textualVariants: + case bookshelfContentsX: + case bookshelfContentsY: + case mainindexActiveTab: + case installPathIndex: case tipNumber: + default: return 0; } - return 0; } QList<int> getDefault(const intLists /*ID*/) { - QList<int> result; - /*switch ( ID ) { - case leftPaneSplitterSizes: break; - case mainSplitterSizes: break; - case searchMainSplitterSizes: break; - case searchResultSplitterSizes: break;*/ - return result; + return QList<int>(); } QStringList getDefault(const stringLists ID) { - switch (ID) { - case searchTexts: { - QStringList list; - list.append(QString::null); - return list; - } - case searchCompletionTexts: - return QStringList(); - case bookshelfOpenGroups: - return QStringList(); - case hiddenModules: - return QStringList(); - case searchModulesHistory: - return QStringList(); + if (ID == searchTexts) { + QStringList list; + list.append(QString::null); + return list; + } else { + return QStringList(); } - return QStringList(); } StringMap getDefault(const stringMaps ID) { - if (ID != searchScopes) return StringMap(); + Q_ASSERT(ID == searchScopes); StringMap map; map.insert(QObject::tr("Old testament"), QString("Gen - Mal")); @@ -487,7 +431,7 @@ StringMap getDefault(const stringMaps ID) { sword::ListKey list(vk.ParseVerseList(it.value().toLocal8Bit(), "Genesis 1:1", true)); QString data; for (int i(0); i < list.Count(); i++) { - data.append(QString::fromUtf8(list.GetElement(i)->getRangeText())); + data.append(QString::fromUtf8(list.getElement(i)->getRangeText())); data.append("; "); } map[it.key()] = data; @@ -498,186 +442,170 @@ StringMap getDefault(const stringMaps ID) { QFont &getDefault(const CLanguageMgr::Language * const) { // Language specific lookup of the font name - if (m_defaultFont) return *m_defaultFont; + if (m_defaultFont) + return *m_defaultFont; /// \todo make the font name and size a configuration option - // int fontSize = QWebSettings::globalSettings()->fontSize(QWebSettings::DefaultFontSize); - int fontSize(12); - QString fontName(QWebSettings::globalSettings()->fontFamily(QWebSettings::StandardFont)); - m_defaultFont = new QFont(fontName, fontSize); /// \todo there may be a mem leak here! + m_defaultFont = new QFont(); + m_defaultFont->setPointSize(12); return *m_defaultFont; } QString get(const strings ID) { - getConfig()->beginGroup("strings"); - QString result(getConfig()->value(getKey(ID), getDefault(ID)).toString()); - getConfig()->endGroup(); - return result; + QVariant v = getConfig()->value("strings/" + getKey(ID)); + if (v.isValid()) + return v.toString(); + + return getDefault(ID); } CSwordModuleInfo *get(const modules ID) { - getConfig()->beginGroup("modules"); - CSwordModuleInfo *result(CSwordBackend::instance()->findModuleByName( - getConfig()->value(getKey(ID), getDefault(ID)).toString() - )); - getConfig()->endGroup(); - return result; + QVariant v = getConfig()->value("modules/" + getKey(ID)); + CSwordBackend *b = CSwordBackend::instance(); + if (v.isValid()) + return b->findModuleByName(v.toString()); + + return b->findModuleByName(getDefault(ID)); } bool get(const bools ID) { - getConfig()->beginGroup("bools"); - bool result(getConfig()->value(getKey(ID), getDefault(ID)).toBool()); - getConfig()->endGroup(); - return result; + QVariant v = getConfig()->value("bools/" + getKey(ID)); + if (v.isValid()) + return v.toBool(); + + return getDefault(ID); } int get(const ints ID) { - getConfig()->beginGroup("ints"); - int result(getConfig()->value(getKey(ID), getDefault(ID)).toInt()); - getConfig()->endGroup(); - return result; + QVariant v = getConfig()->value("ints/" + getKey(ID)); + if (v.isValid()) + return v.toInt(); + + return getDefault(ID); } QList<int> get(const intLists ID) { - getConfig()->beginGroup("intlists"); - QList<int> result(StringToIntList( - getConfig()->value(getKey(ID), IntListToString(getDefault(ID))) - .toString() - )); - getConfig()->endGroup(); - return result; + QVariant v = getConfig()->value("intlists/" + getKey(ID)); + if (v.isValid()) { + bool ok; + QList<int> r = StringToIntList(v.toString(), &ok); + if (ok) + return r; + } + return getDefault(ID); } QStringList get(const stringLists ID) { - getConfig()->beginGroup("stringlists"); - QStringList result( - getConfig()->value(getKey(ID), getDefault(ID)).toStringList() - ); - getConfig()->endGroup(); - return result; + QVariant v = getConfig()->value("stringlists/" + getKey(ID)); + if (v.isValid()) + return v.toStringList(); + + return getDefault(ID); } StringMap get(const stringMaps ID) { + Q_ASSERT(ID == searchScopes); + + QSettings *s = getConfig(); + s->beginGroup(getKey(ID)); + const QStringList keys = s->childKeys(); + + if (keys.isEmpty()) { + s->endGroup(); + return getDefault(ID); + } + + /** + Make sure we return the scopes in the chosen language. saved + keys are in english. + */ StringMap map; + sword::VerseKey vk; + Q_FOREACH (const QString &key, keys) { + if (key.isEmpty()) + continue; - getConfig()->beginGroup(getKey(ID)); - QStringList keys(getConfig()->childKeys()); - - if (!keys.isEmpty()) { - switch (ID) { - case searchScopes: { - /** - Make sure we return the scopes in the chosen language. saved - keys are in english. - */ - sword::VerseKey vk; - foreach (QString key, keys) { - Q_ASSERT(!key.isEmpty()); - QByteArray b(getConfig()->value(key).toString().toUtf8()); - sword::ListKey list(vk.ParseVerseList(b, "Genesis 1:1", true)); - QString data; - for (int i(0); i < list.Count(); i++) { - data.append(QString::fromUtf8(list.GetElement(i)->getRangeText())); - data.append("; "); - } - map[key] = data; // Set the new data - } - } - default: - break; + QByteArray b = s->value(key).toString().toUtf8(); + sword::ListKey list(vk.ParseVerseList(b, "Genesis 1:1", true)); + QString data; + for (int i = 0; i < list.Count(); i++) { + data.append(QString::fromUtf8(list.getElement(i)->getRangeText())); + data.append("; "); } + map[key] = data; // Set the new data } - else { - map = getDefault(ID); - } - getConfig()->endGroup(); + s->endGroup(); return map; } FontSettingsPair get(const CLanguageMgr::Language * const language) { // Check the cache first: - FontCacheMap::const_iterator it(m_fontCache.find(language)); - if (it != m_fontCache.end()) return *it; - - FontSettingsPair settings; - - getConfig()->beginGroup("font standard settings"); - settings.first = getConfig()->value(getKey(language), false).toBool(); - getConfig()->endGroup(); - - getConfig()->beginGroup("fonts"); - QFont font; - if (settings.first) { - font.fromString(getConfig()->value(getKey(language), getDefault(language)).toString()); - } - else { - font = getDefault(language); + FontCacheMap::const_iterator it = m_fontCache.find(language); + if (it != m_fontCache.end()) + return *it; + + QSettings *s = getConfig(); + FontSettingsPair fontSettings; + fontSettings.first = s->value("font standard settings/" + getKey(language), false).toBool(); + + if (fontSettings.first) { + QVariant v = s->value("fonts/" + getKey(language)); + if (v.isValid()) { + fontSettings.second.fromString(v.toString()); + } else { + fontSettings.second = getDefault(language); + } + } else { + fontSettings.second = getDefault(language); } - settings.second = font; - getConfig()->endGroup(); // Cache the value: - m_fontCache.insert(language, settings); + m_fontCache.insert(language, fontSettings); - return settings; + return fontSettings; } void set(const strings ID, const QString &value) { -// KConfigGroup cg = getConfig()->group("strings"); -// cg.writeEntry(getKey(ID), value); - getConfig()->beginGroup("strings"); - getConfig()->setValue(getKey(ID), value); - getConfig()->endGroup(); + getConfig()->setValue("strings/" + getKey(ID), value); } void set(const modules ID, CSwordModuleInfo * const value) { -// KConfigGroup cg = getConfig()->group("modules"); -// cg.writeEntry(getKey(ID), value ? value->name() : QString::null); - getConfig()->beginGroup("modules"); - getConfig()->setValue(getKey(ID), value ? value->name() : QString::null); - getConfig()->endGroup(); + getConfig()->setValue("modules/" + getKey(ID), value ? value->name() : QString::null); } -void set(const modules ID, const QString& value) { +void set(const modules ID, const QString &value) { CSwordModuleInfo *module(CSwordBackend::instance()->findModuleByName(value)); if (module) { set(ID, module); } } -void set(const bools ID, const bool value) { - getConfig()->beginGroup("bools"); - getConfig()->setValue(getKey(ID), value); - getConfig()->endGroup(); +void set(const bools ID, const bool value) { + getConfig()->setValue("bools/" + getKey(ID), value); } void set(const ints ID, const int value) { - getConfig()->beginGroup("ints"); - getConfig()->setValue(getKey(ID), value); - getConfig()->endGroup(); + getConfig()->setValue("ints/" + getKey(ID), value); } -void set(const intLists ID, const QList<int> value) { - getConfig()->beginGroup("intlists"); - getConfig()->setValue(getKey(ID), IntListToString(value)); - getConfig()->endGroup(); +void set(const intLists ID, const QList<int> &value) { + getConfig()->setValue("intlists/" + getKey(ID), IntListToString(value)); } -void set(const stringLists ID, const QStringList value) { - getConfig()->beginGroup("stringlists"); - getConfig()->setValue(getKey(ID), value); - getConfig()->endGroup(); +void set(const stringLists ID, const QStringList &value) { + getConfig()->setValue("stringlists/" + getKey(ID), value); } -void set(const stringMaps ID, const StringMap value) { +void set(const stringMaps ID, const StringMap &value) { typedef StringMap::ConstIterator SMCI; using namespace sword; - getConfig()->beginGroup(getKey(ID)); + QSettings *s = getConfig(); + s->beginGroup(getKey(ID)); // Clear all entries of this group to make sure old stuff gets removed: - getConfig()->remove(""); + s->remove(""); switch (ID) { case searchScopes: { @@ -690,35 +618,34 @@ void set(const stringMaps ID, const StringMap value) { QString data; ListKey list(vk.ParseVerseList(it.value().toUtf8(), "Genesis 1:1", true)); for (int i(0); i < list.Count(); i++) { - VerseKey *range(dynamic_cast<VerseKey*>(list.GetElement(i))); + VerseKey *range(dynamic_cast<VerseKey*>(list.getElement(i))); if (range) { range->setLocale("en"); data.append(QString::fromUtf8( range->getRangeText() )); data.append(";"); } } - getConfig()->setValue(it.key(), data); + s->setValue(it.key(), data); } break; } default: { for (SMCI it(value.begin()); it != value.end(); it++) { - getConfig()->setValue(it.key(), it.value()); + s->setValue(it.key(), it.value()); } break; } } - getConfig()->endGroup(); + s->endGroup(); } void set(const CLanguageMgr::Language * const language, - const FontSettingsPair& value) { - getConfig()->beginGroup("fonts"); - getConfig()->setValue(getKey(language), value.second.toString()); - getConfig()->endGroup(); - getConfig()->beginGroup("font standard settings"); - getConfig()->setValue(getKey(language), value.first); - getConfig()->endGroup(); + const FontSettingsPair& value) +{ + QSettings *s = getConfig(); + QString lang = getKey(language); + s->setValue("fonts/" + lang, value.second.toString()); + s->setValue("font standard settings/" + lang, value.first); // Remove language from the cache: m_fontCache.remove(language); @@ -751,9 +678,9 @@ FilterOptions getFilterOptionDefaults() { } void setupAccelSettings(const keys type, - BtActionCollection * const actionCollection) { - qDebug() << "CBTConfig::setupAccelSettings begin"; - QString groupName; + BtActionCollection * const actionCollection) +{ + const char *groupName =""; switch (type) { case allWindows: groupName = "Displaywindow shortcuts"; @@ -780,18 +707,15 @@ void setupAccelSettings(const keys type, groupName = "Application shortcuts"; break; } - qDebug() << groupName; - Q_ASSERT(getConfig()); actionCollection->setConfigGroup(groupName); actionCollection->readSettings(); - qDebug() << "CBTConfig::setupAccelSettings end"; } void saveAccelSettings(const keys type, - BtActionCollection * const actionCollection) { - qDebug() << "CBTConfig::saveAccelSettings begin"; - QString groupName; + BtActionCollection * const actionCollection) +{ + const char *groupName =""; switch (type) { case allWindows: groupName = "Displaywindow shortcuts"; @@ -821,22 +745,22 @@ void saveAccelSettings(const keys type, actionCollection->setConfigGroup(groupName); actionCollection->writeSettings(); - qDebug() << "CBTConfig::saveAccelSettings end"; } QString getModuleEncryptionKey(const QString &module) { Q_ASSERT(!module.isEmpty()); - getConfig()->beginGroup("Module keys"); - QString result(getConfig()->value(module, QVariant(QString::null)).toString()); - getConfig()->endGroup(); - return result; + static const QString nullString; + + QVariant v = getConfig()->value("Module keys/" + module); + if (v.isValid()) + return v.toString(); + + return nullString; } void setModuleEncryptionKey(const QString &module, const QString &key) { - getConfig()->beginGroup("Module keys"); - getConfig()->setValue(module, key); - getConfig()->endGroup(); + getConfig()->setValue("Module keys/" + module, key); } QSettings *getConfig() { diff --git a/src/backend/config/cbtconfig.h b/src/backend/config/cbtconfig.h index ef618a2..f3fa042 100644 --- a/src/backend/config/cbtconfig.h +++ b/src/backend/config/cbtconfig.h @@ -49,7 +49,7 @@ enum bools { firstSearchDialog, readOldBookmarks, - toolbar, + showMainWindowToolbar, mainIndex, infoDisplay, @@ -144,8 +144,10 @@ enum stringMaps { searchScopes }; -QString IntListToString(const QList<int> intList); -QList<int> StringToIntList(const QString &intListString); +QString IntListToString(const QList<int> &intList); +QList<int> StringToIntList(const QString &intListString, + bool *ok = 0, + QString::SplitBehavior splitBehavior = QString::KeepEmptyParts); QString getDefault(const strings); QString getDefault(const modules); @@ -167,12 +169,12 @@ FontSettingsPair get(const CLanguageMgr::Language * const); void set(const strings, const QString &value); void set(const modules, CSwordModuleInfo * const module); -void set(const modules, const QString& moduleName); +void set(const modules, const QString &moduleName); void set(const bools, const bool value); void set(const ints, const int value); -void set(const intLists, const QList<int> value); -void set(const stringLists, const QStringList value); -void set(const stringMaps, const StringMap value); +void set(const intLists, const QList<int> &value); +void set(const stringLists, const QStringList &value); +void set(const stringMaps, const StringMap &value); void set(const CLanguageMgr::Language * const language, const FontSettingsPair &fontSettings); diff --git a/src/backend/cswordmodulesearch.h b/src/backend/cswordmodulesearch.h index bc0d37c..aa864b0 100644 --- a/src/backend/cswordmodulesearch.h +++ b/src/backend/cswordmodulesearch.h @@ -66,7 +66,7 @@ class CSwordModuleSearch: public QObject { Resets the search scope. */ inline void resetSearchScope() { - m_searchScope.ClearList(); + m_searchScope.clear(); } /** diff --git a/src/backend/drivers/cswordbiblemoduleinfo.cpp b/src/backend/drivers/cswordbiblemoduleinfo.cpp index a81430f..e87fea2 100644 --- a/src/backend/drivers/cswordbiblemoduleinfo.cpp +++ b/src/backend/drivers/cswordbiblemoduleinfo.cpp @@ -12,7 +12,6 @@ #include <QSharedPointer> #include <QFile> #include "backend/managers/cswordbackend.h" -#include "backend/keys/cswordversekey.h" // Sword includes: #include <versekey.h> @@ -21,53 +20,46 @@ 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") + : CSwordModuleInfo(module, usedBackend, type) + , m_boundsInitialized(false) + , m_lowerBound(0) + , m_upperBound(0) + , m_bookList(0) { - initBounds(); + // Intentionally empty } -CSwordBibleModuleInfo::CSwordBibleModuleInfo(const CSwordBibleModuleInfo ©) : - CSwordModuleInfo(copy), - m_lowerBound(0), - m_upperBound(0), - 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 = *copy.m_bookList; - } - initBounds(); -} +void CSwordBibleModuleInfo::initBounds() const { + /// \todo The fields calculated by this method could be cached to disk. -void CSwordBibleModuleInfo::initBounds() { - const bool oldStatus = module()->getSkipConsecutiveLinks(); - module()->setSkipConsecutiveLinks(true); + Q_ASSERT(!m_boundsInitialized); - module()->setPosition(sword::TOP); // position to first entry - sword::VerseKey key(module()->KeyText()); - m_hasOT = (key.Testament() == 1); + sword::SWModule *m = module(); + const bool oldStatus = m->getSkipConsecutiveLinks(); + m->setSkipConsecutiveLinks(true); - module()->setPosition(sword::BOTTOM); - key = module()->KeyText(); - m_hasNT = (key.Testament() == 2); + m->setPosition(sword::TOP); // position to first entry + sword::VerseKey key(module()->getKeyText()); + m_hasOT = (key.getTestament() == 1); - module()->setSkipConsecutiveLinks(oldStatus); + m->setPosition(sword::BOTTOM); + key = module()->getKeyText(); + m_hasNT = (key.getTestament() == 2); + + m->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"); + + m_boundsInitialized = true; } /** Returns the books available in this module */ QStringList *CSwordBibleModuleInfo::books() const { - if (m_cachedLocale != backend()->booknameLanguage()) { //if the locale has changed + if (m_cachedLocale != backend()->booknameLanguage()) { + // Reset the booklist because the locale has changed + m_cachedLocale = backend()->booknameLanguage(); delete m_bookList; m_bookList = 0; } @@ -75,37 +67,29 @@ QStringList *CSwordBibleModuleInfo::books() const { if (!m_bookList) { m_bookList = new QStringList(); + // Initialize m_hasOT and m_hasNT + if (!m_boundsInitialized) + initBounds(); + 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) + min++; // min == 2 - if (m_hasOT && m_hasNT) { //both - min = 1; - max = 2; - } - 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 = 1; - max = 0; - } + if (!m_hasNT) + max--; // max == 1 - QSharedPointer<sword::VerseKey> key((sword::VerseKey *)module()->CreateKey()); - key->setPosition(sword::TOP); + if (min > max) { + qWarning("CSwordBibleModuleInfo (%s) no OT and not NT! Check your config!", module()->Name()); + } else { + QSharedPointer<sword::VerseKey> key((sword::VerseKey *)module()->CreateKey()); + key->setPosition(sword::TOP); - for (key->setTestament(min); !key->Error() && key->getTestament() <= max; key->Book(key->Book() + 1)) { - m_bookList->append( QString::fromUtf8(key->getBookName()) ); + for (key->setTestament(min); !key->Error() && key->getTestament() <= max; key->setBook(key->getBook() + 1)) { + m_bookList->append( QString::fromUtf8(key->getBookName()) ); + } } - - m_cachedLocale = backend()->booknameLanguage(); } return m_bookList; @@ -118,9 +102,9 @@ unsigned int CSwordBibleModuleInfo::chapterCount(const unsigned int book) const key->setPosition(sword::TOP); // works for old and new versions - key->Book(book); + key->setBook(book); key->setPosition(sword::MAXCHAPTER); - result = key->Chapter(); + result = key->getChapter(); return result; } @@ -140,10 +124,10 @@ unsigned int CSwordBibleModuleInfo::verseCount(const unsigned int book, key->setPosition(sword::TOP); // works for old and new versions - key->Book(book); - key->Chapter(chapter); + key->setBook(book); + key->setChapter(chapter); key->setPosition(sword::MAXVERSE); - result = key->Verse(); + result = key->getVerse(); return result; } @@ -162,7 +146,7 @@ unsigned int CSwordBibleModuleInfo::bookNumber(const QString &book) const { key->setBookName(book.toUtf8().constData()); - bookNumber = ((key->getTestament() > 1) ? key->BMAX[0] : 0) + key->Book(); + bookNumber = ((key->getTestament() > 1) ? key->BMAX[0] : 0) + key->getBook(); return bookNumber; } diff --git a/src/backend/drivers/cswordbiblemoduleinfo.h b/src/backend/drivers/cswordbiblemoduleinfo.h index 40ec8cb..49606e3 100644 --- a/src/backend/drivers/cswordbiblemoduleinfo.h +++ b/src/backend/drivers/cswordbiblemoduleinfo.h @@ -24,21 +24,9 @@ class CSwordBibleModuleInfo: public CSwordModuleInfo { Q_OBJECT - public: /* Types: */ - enum Testament { - OldTestament = 1, - NewTestament = 2 - }; - public: /* Methods: */ CSwordBibleModuleInfo(sword::SWModule *module, CSwordBackend * const, ModuleType type = Bible); - CSwordBibleModuleInfo(const CSwordBibleModuleInfo ©); - - /* Reimplementation of CSwordModuleInfo::clone(). */ - virtual inline CSwordModuleInfo *clone() const { - return new CSwordBibleModuleInfo(*this); - } inline ~CSwordBibleModuleInfo() { delete m_bookList; @@ -82,16 +70,29 @@ class CSwordBibleModuleInfo: public CSwordModuleInfo { unsigned int bookNumber(const QString &book) const; /** - \returns whether this module has the text of desired type of testament + \returns whether this module has the Old Testament texts. */ - bool hasTestament(CSwordBibleModuleInfo::Testament type) const { - return type == OldTestament ? m_hasOT : m_hasNT; + inline bool hasOldTestament() const { + if (!m_boundsInitialized) + initBounds(); + return m_hasOT; + } + + /** + \returns whether this module has the New Testament texts. + */ + inline bool hasNewTestament() const { + if (!m_boundsInitialized) + initBounds(); + return m_hasNT; } /** \returns the key which represents the lower bound of this module. */ inline const CSwordVerseKey &lowerBound() const { + if (!m_boundsInitialized) + initBounds(); return m_lowerBound; } @@ -99,20 +100,25 @@ class CSwordBibleModuleInfo: public CSwordModuleInfo { \returns the key which represents the upper bound of this module. */ inline const CSwordVerseKey &upperBound() const { + if (!m_boundsInitialized) + initBounds(); return m_upperBound; } private: /* Methods: */ - void initBounds(); - private: - CSwordVerseKey m_lowerBound; - CSwordVerseKey m_upperBound; + void initBounds() const; + + private: /* Fields: */ + + mutable bool m_boundsInitialized; + mutable CSwordVerseKey m_lowerBound; + mutable CSwordVerseKey m_upperBound; + mutable bool m_hasOT; + mutable bool m_hasNT; mutable QStringList *m_bookList; //This booklist is cached mutable QString m_cachedLocale; - bool m_hasOT; - bool m_hasNT; }; #endif diff --git a/src/backend/drivers/cswordbookmoduleinfo.h b/src/backend/drivers/cswordbookmoduleinfo.h index 12a3d01..c6b0494 100644 --- a/src/backend/drivers/cswordbookmoduleinfo.h +++ b/src/backend/drivers/cswordbookmoduleinfo.h @@ -33,11 +33,6 @@ class CSwordBookModuleInfo: public CSwordModuleInfo { inline CSwordBookModuleInfo(const CSwordBookModuleInfo ©) : CSwordModuleInfo(copy), m_depth(copy.m_depth) {} - /* Reimplementation of CSwordModuleInfo::clone(). */ - virtual inline CSwordModuleInfo *clone() const { - return new CSwordBookModuleInfo(*this); - } - /** \returns the maximal depth of sections and subsections. */ diff --git a/src/backend/drivers/cswordcommentarymoduleinfo.h b/src/backend/drivers/cswordcommentarymoduleinfo.h index 60640a2..3c42d99 100644 --- a/src/backend/drivers/cswordcommentarymoduleinfo.h +++ b/src/backend/drivers/cswordcommentarymoduleinfo.h @@ -27,11 +27,6 @@ class CSwordCommentaryModuleInfo: public CSwordBibleModuleInfo { : 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; }; diff --git a/src/backend/drivers/cswordlexiconmoduleinfo.cpp b/src/backend/drivers/cswordlexiconmoduleinfo.cpp index d6515be..4e53361 100644 --- a/src/backend/drivers/cswordlexiconmoduleinfo.cpp +++ b/src/backend/drivers/cswordlexiconmoduleinfo.cpp @@ -86,12 +86,12 @@ const QStringList &CSwordLexiconModuleInfo::entries() const { do { if ( isUnicode() ) { - m_entries.append(QString::fromUtf8(module()->KeyText())); + m_entries.append(QString::fromUtf8(module()->getKeyText())); } else { //for latin1 modules use fromLatin1 because of speed QTextCodec* codec = QTextCodec::codecForName("Windows-1252"); - m_entries.append(codec->toUnicode(module()->KeyText())); + m_entries.append(codec->toUnicode(module()->getKeyText())); } module()->increment(); diff --git a/src/backend/drivers/cswordlexiconmoduleinfo.h b/src/backend/drivers/cswordlexiconmoduleinfo.h index d75e106..1789b9b 100644 --- a/src/backend/drivers/cswordlexiconmoduleinfo.h +++ b/src/backend/drivers/cswordlexiconmoduleinfo.h @@ -29,11 +29,6 @@ class CSwordLexiconModuleInfo: public CSwordModuleInfo { inline CSwordLexiconModuleInfo(const CSwordLexiconModuleInfo ©) : CSwordModuleInfo(copy), m_entries(copy.m_entries) {} - /* Reimplementation of CSwordModuleInfo::clone(). */ - virtual inline CSwordModuleInfo *clone() const { - return new CSwordLexiconModuleInfo(*this); - } - /** 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 diff --git a/src/backend/drivers/cswordmoduleinfo.cpp b/src/backend/drivers/cswordmoduleinfo.cpp index b1e646f..a7ceca9 100644 --- a/src/backend/drivers/cswordmoduleinfo.cpp +++ b/src/backend/drivers/cswordmoduleinfo.cpp @@ -11,8 +11,6 @@ #include <QSharedPointer> #include <CLucene.h> -#include <CLucene/util/Misc.h> -#include <CLucene/util/Reader.h> #include <QByteArray> #include <QCoreApplication> #include <QDebug> @@ -43,7 +41,7 @@ #include <versekey.h> -#ifdef BT_DEBUG +#if 0 namespace { /** HELPER Method to dump all current EntryAttributes of a module. */ @@ -223,7 +221,7 @@ bool CSwordModuleInfo::hasIndex() const { return lucene::index::IndexReader::indexExists(getModuleStandardIndexLocation().toAscii().constData()); } -void CSwordModuleInfo::buildIndex() { +bool CSwordModuleInfo::buildIndex() { m_cancelIndexing = false; @@ -260,7 +258,6 @@ void CSwordModuleInfo::buildIndex() { 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->setPosition(sword::TOP); unsigned long verseLowIndex = m_module->Index(); @@ -406,12 +403,22 @@ void CSwordModuleInfo::buildIndex() { emit hasIndexChanged(true); } } + catch (CLuceneError &e) { + qWarning() << "CLucene exception occurred while indexing:" << e.what(); + util::showWarning(0, QCoreApplication::tr("Indexing aborted"), QCoreApplication::tr("An internal error occurred while building the index: %1").arg(e.what())); + deleteIndex(); + m_cancelIndexing = false; + return false; + } catch (...) { qWarning("CLucene exception occurred while indexing"); util::showWarning(0, QCoreApplication::tr("Indexing aborted"), QCoreApplication::tr("An internal error occurred while building the index.")); deleteIndex(); m_cancelIndexing = false; + return false; } + + return true; } void CSwordModuleInfo::deleteIndex() { @@ -442,10 +449,10 @@ int CSwordModuleInfo::searchIndexed(const QString &searchedText, QList<sword::VerseKey*> list; if (s) { - m_module->SetKey(*s); + m_module->setKey(*s); } - results.ClearList(); + results.clear(); try { // do not use any stop words @@ -455,7 +462,11 @@ int CSwordModuleInfo::searchIndexed(const QString &searchedText, lucene_utf8towcs(wcharBuffer, searchedText.toUtf8().constData(), BT_MAX_LUCENE_FIELD_LENGTH); QSharedPointer<lucene::search::Query> q( lucene::queryParser::QueryParser::parse((const TCHAR*)wcharBuffer, (const TCHAR*)_T("content"), &analyzer) ); +#ifdef CLUCENE2 + QSharedPointer<lucene::search::Hits> h( searcher.search(q.data(), lucene::search::Sort::INDEXORDER()) ); +#else QSharedPointer<lucene::search::Hits> h( searcher.search(q.data(), lucene::search::Sort::INDEXORDER) ); +#endif /// \warning This is a workaround for Sword constness const bool useScope = (const_cast<sword::ListKey&>(scope).Count() > 0); @@ -465,7 +476,11 @@ int CSwordModuleInfo::searchIndexed(const QString &searchedText, QSharedPointer<sword::SWKey> swKey( module()->CreateKey() ); - for (int i = 0; i < h->length(); ++i) { +#ifdef CLUCENE2 + for (unsigned int i = 0; i < h->length(); ++i) { +#else + for (int i = 0; i < h->length(); ++i) { +#endif doc = &h->doc(i); lucene_wcstoutf8(utfBuffer, (const wchar_t*)doc->get((const TCHAR*)_T("key")), BT_MAX_LUCENE_FIELD_LENGTH); @@ -691,14 +706,14 @@ CSwordModuleInfo::TextDirection CSwordModuleInfo::textDirection() const { } void CSwordModuleInfo::write(CSwordKey *key, const QString &newText) { - module()->KeyText(key->key().toUtf8().constData()); + module()->setKey(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()); } bool CSwordModuleInfo::deleteEntry(CSwordKey * const key) { - module()->KeyText(isUnicode() ? key->key().toUtf8().constData() : key->key().toLocal8Bit().constData()); + module()->setKey(isUnicode() ? key->key().toUtf8().constData() : key->key().toLocal8Bit().constData()); if (module()) { module()->deleteEntry(); @@ -751,7 +766,7 @@ void CSwordModuleInfo::initCachedLanguage() { } Rendering::CEntryDisplay * CSwordModuleInfo::getDisplay() const { - return dynamic_cast < Rendering::CEntryDisplay * >(m_module->Disp()); + return dynamic_cast<Rendering::CEntryDisplay *>(m_module->getDisplay()); } QString CSwordModuleInfo::aboutText() const { diff --git a/src/backend/drivers/cswordmoduleinfo.h b/src/backend/drivers/cswordmoduleinfo.h index d7397de..3c59f9d 100644 --- a/src/backend/drivers/cswordmoduleinfo.h +++ b/src/backend/drivers/cswordmoduleinfo.h @@ -23,6 +23,11 @@ #include <swsearchable.h> #include <swversion.h> +#ifdef CLUCENE2 +// CLucene no longer lists the following functions in its headers +extern size_t lucene_utf8towcs(wchar_t *, const char *, size_t maxslen); +extern size_t lucene_wcstoutf8 (char *, const wchar_t *, size_t maxslen); +#endif class CSwordBackend; class CSwordKey; @@ -138,7 +143,7 @@ class CSwordModuleInfo: public QObject { Cult = 0x80, /**< Cult / sect / questionable module. */ AllCategories = 0xff }; - Q_DECLARE_FLAGS(Categories, Category); + Q_DECLARE_FLAGS(Categories, Category) /** * Returns the base directory for search indices @@ -168,11 +173,6 @@ class CSwordModuleInfo: public QObject { CSwordModuleInfo(const CSwordModuleInfo ©); - virtual CSwordModuleInfo *clone() const = 0; - - virtual inline ~CSwordModuleInfo() {} - - /** * Returns the module object so all objects can access the original Sword module. */ @@ -243,8 +243,9 @@ wrong, or if the config file was write protected return false. /** Builds a search index for this module + \returns Whether indexing this module was successful. */ - void buildIndex(); + bool buildIndex(); /** \returns index size @@ -396,7 +397,6 @@ wrong, or if the config file was write protected return false. } protected: - friend class CSwordBackend; inline CSwordBackend* backend() const { return m_backend; diff --git a/src/backend/filters/osismorphsegmentation.cpp b/src/backend/filters/osismorphsegmentation.cpp index 421b63e..981ce89 100644 --- a/src/backend/filters/osismorphsegmentation.cpp +++ b/src/backend/filters/osismorphsegmentation.cpp @@ -24,8 +24,6 @@ Filters::OSISMorphSegmentation::OSISMorphSegmentation() : sword::SWOptionFilter( setOptionValue("Off"); } -Filters::OSISMorphSegmentation::~OSISMorphSegmentation() {} - char Filters::OSISMorphSegmentation::processText(sword::SWBuf &text, const sword::SWKey * /*key*/, const sword::SWModule * /*module*/) { sword::SWBuf token; bool intoken = false; diff --git a/src/backend/filters/osismorphsegmentation.h b/src/backend/filters/osismorphsegmentation.h index 4843488..8d5a4ab 100644 --- a/src/backend/filters/osismorphsegmentation.h +++ b/src/backend/filters/osismorphsegmentation.h @@ -28,7 +28,6 @@ class OSISMorphSegmentation : public sword::SWOptionFilter { public: OSISMorphSegmentation(); - virtual ~OSISMorphSegmentation(); virtual char processText(sword::SWBuf &text, const sword::SWKey *key = 0, const sword::SWModule *module = 0); }; diff --git a/src/backend/filters/plaintohtml.cpp b/src/backend/filters/plaintohtml.cpp index bc19440..70df723 100644 --- a/src/backend/filters/plaintohtml.cpp +++ b/src/backend/filters/plaintohtml.cpp @@ -9,61 +9,90 @@ #include "backend/filters/plaintohtml.h" +#include <QDebug> -Filters::PlainToHtml::PlainToHtml() : sword::SWFilter() { -} +// Sword includes: +#include <swbuf.h> -/** No descriptions */ -char Filters::PlainToHtml::processText(sword::SWBuf& text, const sword::SWKey* /*key*/, const sword::SWModule* /*module*/) { - int count = 0; +char Filters::PlainToHtml::processText(sword::SWBuf &text, + const sword::SWKey * /*key*/, + const sword::SWModule * /*module*/) +{ sword::SWBuf orig = text; - const char *from = orig.c_str(); - for (text = ""; *from; from++) { - if ((*from == '\n') && (from[1] == '\n')) { // two newlinea are a paragraph - text += "<P>"; - from++; - continue; - } - //This is a special case: Newlines in the plaintext editor are stored as <br />, not as \n - //we need to let them through - else if ((*from == '<') && (from[1] == 'b') && (from[2] == 'r') && (from[3] == ' ') && (from[4] == '/') && (from[5] == '>')) { - text += "<br />"; - from += 5; - continue; - } - else if ((*from == '\n')) { // only one new line - text += "<br/>"; - continue; - } - else if (*from == '<') { - text += "<"; - continue; - } - else if (*from == '>') { + const char * from = orig.c_str(); + bool inFootNote = false; + + for (text = "<p>"; *from; from++) { + switch (*from) { + + case '\n': + if (text.size() > 3) { // ignore leading newlines + if (from[1] == '\n') { // two or more newlines denote a new paragraph + text += "</p><p>"; + do { + from++; + } while (from[1] == '\n'); + } else { // only one new line + text += "<br/>"; + } + } + break; + + case '<': + // This is a special case: Newlines in the plaintext editor are stored as <br />, not as \n + // we need to let them through + /// \todo is this quirk necessary? + if ((from[1] == 'b') + && (from[2] == 'r') + && (from[3] == ' ') + && (from[4] == '/') + && (from[5] == '>')) + { + text += "<br/>"; + from += 5; + } else { + text += "<"; + } + break; + + case '>': text += ">"; - continue; - } - else if (*from == '&') { + break; + + case '&': text += "&"; - continue; - } - else if (*from == '{') { //footnote start - text += "<font color=\"#800000\"><small> ("; /// \bug Possible color conflict - continue; - } - else if (*from == '}') { //footnote end - text += ") </small></font>"; - continue; - } - else if ((*from == ' ') && (count > 5000)) { - text += "<wbr/>"; - count = 0; - continue; + break; + + case '{': // footnote start + if (inFootNote) { + text += *from; + } else { + text += "<span class=\"footnote\">"; + inFootNote = true; + } + break; + + case '}': // footnote end + if (inFootNote) { + text += "</span>"; + inFootNote = false; + } + // fall through: + + default: + text += *from; + break; + } + } - text += *from; - count++; + // Handle missing footnode end: + if (inFootNote) { + qWarning() << "PlainToHtml filter detected missing footnote end."; + text += "</span>"; } + + text += "</p>"; return 0; } diff --git a/src/backend/filters/plaintohtml.h b/src/backend/filters/plaintohtml.h index 1093e2c..b327ecc 100644 --- a/src/backend/filters/plaintohtml.h +++ b/src/backend/filters/plaintohtml.h @@ -11,9 +11,9 @@ #define FILTERS_PLAINTOHTML_H // Sword includes: -#include <swbuf.h> #include <swfilter.h> + namespace sword { class SWKey; class SWModule; @@ -25,14 +25,14 @@ 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 diff --git a/src/backend/filters/thmltohtml.cpp b/src/backend/filters/thmltohtml.cpp index 703b362..12f42bf 100644 --- a/src/backend/filters/thmltohtml.cpp +++ b/src/backend/filters/thmltohtml.cpp @@ -62,7 +62,7 @@ char ThmlToHtml::processText(sword::SWBuf &buf, const sword::SWKey *key, int pos = tag.indexIn(t, 0); if (pos == -1) { //no strong or morph code found in this text - return 1; //WARNING: Return alread here + return 1; //WARNING: Return already here } while (pos != -1) { diff --git a/src/backend/keys/cswordkey.cpp b/src/backend/keys/cswordkey.cpp index 9c5b25b..a685b27 100644 --- a/src/backend/keys/cswordkey.cpp +++ b/src/backend/keys/cswordkey.cpp @@ -153,8 +153,15 @@ QString CSwordKey::strippedText() { return QString::fromUtf8( m_module->module()->StripText() ); } +void CSwordKey::emitBeforeChanged() { + if (m_signal.isNull()) + return; + m_signal->emitBeforeChanged(); +} + void CSwordKey::emitChanged() { - if (m_signal.isNull()) return; + if (m_signal.isNull()) + return; m_signal->emitChanged(); } diff --git a/src/backend/keys/cswordkey.h b/src/backend/keys/cswordkey.h index 48e511c..9b043b7 100644 --- a/src/backend/keys/cswordkey.h +++ b/src/backend/keys/cswordkey.h @@ -81,14 +81,14 @@ class CSwordKey { /** 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(); + QString rawText(); /** 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 ); + QString renderedText( const CSwordKey::TextRenderType mode = CSwordKey::Normal ); /** Stripped down text. Returns the text after removing all markup tags from it. */ - virtual QString strippedText(); + QString strippedText(); const BtSignal *signaler(); @@ -100,13 +100,21 @@ class CSwordKey { */ static CSwordKey* createInstance(const CSwordModuleInfo *module); + /** + * This is called before a key change to emit a signal + * */ + void emitBeforeChanged(); + /** + * This is called after a key change to emit a signal + * */ + void emitChanged(); + protected: /** * Returns the encoded key appropriate for use directly with Sword. */ virtual const char * rawKey() const = 0; static inline const QTextCodec *cp1252Codec() { return m_cp1252Codec; }; - void emitChanged(); private: /** diff --git a/src/backend/keys/cswordldkey.cpp b/src/backend/keys/cswordldkey.cpp index ecde8b7..822da8c 100644 --- a/src/backend/keys/cswordldkey.cpp +++ b/src/backend/keys/cswordldkey.cpp @@ -86,7 +86,7 @@ bool CSwordLDKey::setKey(const char *newKey) { if (newKey) { SWKey::operator = (newKey); //set the key - m_module->module()->SetKey(this); + m_module->module()->setKey(this); m_module->snap(); } @@ -95,29 +95,29 @@ bool CSwordLDKey::setKey(const char *newKey) { /** Uses the parameter to returns the next entry afer this key. */ CSwordLDKey* CSwordLDKey::NextEntry() { - m_module->module()->SetKey(this); //use this key as base for the next one! + m_module->module()->setKey(this); // use this key as base for the next one! // m_module->module()->getKey()->setText( (const char*)key().utf8() ); m_module->module()->setSkipConsecutiveLinks(true); ( *( m_module->module() ) )++; m_module->module()->setSkipConsecutiveLinks(false); - setKey(m_module->module()->KeyText()); - SWKey::operator = (m_module->module()->KeyText()); + setKey(m_module->module()->getKeyText()); + setText(m_module->module()->getKeyText()); return this; } /** Uses the parameter to returns the next entry afer this key. */ CSwordLDKey* CSwordLDKey::PreviousEntry() { - m_module->module()->SetKey(this); //use this key as base for the next one! + m_module->module()->setKey(this); // use this key as base for the next one! // m_module->module()->getKey()->setText( (const char*)key().utf8() ); m_module->module()->setSkipConsecutiveLinks(true); ( *( m_module->module() ) )--; m_module->module()->setSkipConsecutiveLinks(false); - SWKey::operator = (m_module->module()->KeyText()); + setText(m_module->module()->getKeyText()); return this; } diff --git a/src/backend/keys/cswordversekey.cpp b/src/backend/keys/cswordversekey.cpp index 5ea1455..de4fd0e 100644 --- a/src/backend/keys/cswordversekey.cpp +++ b/src/backend/keys/cswordversekey.cpp @@ -81,8 +81,8 @@ QString CSwordVerseKey::book( const QString& newBook ) { 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); + const bool hasOT = bible->hasOldTestament(); + const bool hasNT = bible->hasNewTestament(); if (hasOT && hasNT) { min = 0; @@ -106,7 +106,7 @@ QString CSwordVerseKey::book( const QString& newBook ) { setBookName(newBook.toUtf8().constData()); } - if ( (Testament() >= min + 1) && (Testament() <= max + 1) && (Book() <= BMAX[min]) ) { + if ((getTestament() >= min + 1) && (getTestament() <= max + 1) && (getBook() <= BMAX[min])) { return QString::fromUtf8( getBookName() ); } @@ -135,12 +135,15 @@ bool CSwordVerseKey::setKey(const char *newKey) { /// \todo Is this check necessary? // Check if empty string: if (*newKey != '\0') { + QString newKeyStr = newKey; + emitBeforeChanged(); 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); + emitBeforeChanged(); positionFrom(bible->lowerBound().key().toUtf8().constData()); } } @@ -160,24 +163,24 @@ bool CSwordVerseKey::next( const JumpType type ) { switch (type) { case UseBook: { - const int currentTestament = Testament(); - const int currentBook = Book(); + const int currentTestament = getTestament(); + const int currentBook = getBook(); if ((currentTestament == 2) && (currentBook >= BMAX[currentTestament-1])) { //Revelation, i.e. end of navigation return false; } else if ((currentTestament == 1) && (currentBook >= BMAX[currentTestament-1])) { //Malachi, switch to the NT - Testament(currentTestament + 1); - Book(1); + setTestament(currentTestament + 1); + setBook(1); } else { - Book(Book() + 1); + setBook(getBook() + 1); } break; } case UseChapter: { - Chapter(Chapter() + 1); + setChapter(getChapter() + 1); break; } @@ -198,7 +201,7 @@ bool CSwordVerseKey::next( const JumpType type ) { m_module->module()->setSkipConsecutiveLinks(oldStatus); if (!m_module->module()->Error()) { - setKey(QString::fromUtf8(m_module->module()->KeyText())); + setKey(QString::fromUtf8(m_module->module()->getKeyText())); } else { // Verse(Verse()+1); @@ -210,7 +213,7 @@ bool CSwordVerseKey::next( const JumpType type ) { } else { - Verse(Verse() + 1); + setVerse(getVerse() + 1); } break; @@ -223,11 +226,13 @@ bool CSwordVerseKey::next( const JumpType type ) { const CSBMI *bible = dynamic_cast<const CSBMI*>(module()); if (bible != 0) { if (_compare(bible->lowerBound()) < 0 ) { + emitBeforeChanged(); setKey(bible->lowerBound()); ret = false; } if (_compare(bible->upperBound()) > 0 ) { + emitBeforeChanged(); setKey(bible->upperBound()); ret = false; } @@ -251,22 +256,22 @@ bool CSwordVerseKey::previous( const JumpType type ) { switch (type) { case UseBook: { - if ( (Book() == 1) && (Testament() == 1) ) { //Genesis + if ((getBook() == 1) && (getTestament() == 1)) { //Genesis return false; } - else if ( (Book() == 1) && (Testament() == 2) ) { //Matthew - Testament(1); - Book(BMAX[0]); + else if ((getBook() == 1) && (getTestament() == 2)) { //Matthew + setTestament(1); + setBook(BMAX[0]); } else { - Book( Book() - 1 ); + setBook(getBook() - 1); } break; } case UseChapter: { - Chapter(Chapter() - 1); + setChapter(getChapter() - 1); break; } @@ -285,7 +290,7 @@ bool CSwordVerseKey::previous( const JumpType type ) { m_module->module()->setSkipConsecutiveLinks(oldStatus); if (!m_module->module()->Error()) { - setKey(QString::fromUtf8(m_module->module()->KeyText()));//don't use fromUtf8 + setKey(QString::fromUtf8(m_module->module()->getKeyText())); // don't use fromUtf8 } else { ret = false; @@ -294,7 +299,7 @@ bool CSwordVerseKey::previous( const JumpType type ) { } } else { - Verse(Verse() - 1); + setVerse(getVerse() - 1); } break; @@ -307,11 +312,13 @@ bool CSwordVerseKey::previous( const JumpType type ) { const CSBMI *bible = dynamic_cast<const CSBMI*>(module()); if (bible != 0) { if (_compare(bible->lowerBound()) < 0 ) { + emitBeforeChanged(); setKey(bible->lowerBound()); ret = false; } if (_compare(bible->upperBound()) > 0 ) { + emitBeforeChanged(); setKey(bible->upperBound()); ret = false; } diff --git a/src/backend/managers/cdisplaytemplatemgr.cpp b/src/backend/managers/cdisplaytemplatemgr.cpp index b3def8c..b433dd7 100644 --- a/src/backend/managers/cdisplaytemplatemgr.cpp +++ b/src/backend/managers/cdisplaytemplatemgr.cpp @@ -29,37 +29,45 @@ CDisplayTemplateMgr::CDisplayTemplateMgr(QString &errorMessage) { namespace DU = util::directory; QStringList filter("*.tmpl"); + QStringList cssfilter("*.css"); // Preload global display templates from disk: QDir td = DU::getDisplayTemplatesDir(); - Q_FOREACH(QString file, td.entryList(filter, QDir::Files | QDir::Readable)) + Q_FOREACH(const QString &file, td.entryList(filter, QDir::Files | QDir::Readable)) loadTemplate(td.canonicalPath() + "/" + file); + + // Load app stylesheets + Q_FOREACH(const QString &file, td.entryList(cssfilter, QDir::Files | QDir::Readable)) + loadCSSTemplate(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)) + Q_FOREACH(const QString &file, utd.entryList(filter, QDir::Files | QDir::Readable)) loadTemplate(utd.canonicalPath() + "/" + file); - if (m_templateMap.contains(defaultTemplate())) { + if (m_cssMap.contains(defaultTemplateName())) { errorMessage = QString::null; } else { errorMessage = QObject::tr("Default template \"%1\" not found!") - .arg(defaultTemplate()); + .arg(defaultTemplateName()); } } -const QString CDisplayTemplateMgr::fillTemplate( const QString& name, const QString& content, Settings& settings ) { - qDebug() << "CDisplayTemplateMgr::fillTemplate"; - - const QString templateName = m_templateMap.contains(name) ? name : defaultTemplate(); +QString CDisplayTemplateMgr::fillTemplate(const QString &name, + const QString &content, + const Settings &settings) +{ + const QString templateName = m_cssMap.contains(name) ? name : defaultTemplateName(); QString displayTypeString; + QString moduleName; if (!settings.pageCSS_ID.isEmpty()) { displayTypeString = settings.pageCSS_ID; + moduleName = ""; } else { if (settings.modules.count()) { @@ -79,9 +87,11 @@ const QString CDisplayTemplateMgr::fillTemplate( const QString& name, const QStr displayTypeString = "singleentry"; break; }; + moduleName = settings.modules.first()->name(); } else { //use bible as default type if no modules are set displayTypeString = "bible"; + moduleName = ""; }; } @@ -93,13 +103,11 @@ const QString CDisplayTemplateMgr::fillTemplate( const QString& name, const QStr qDebug() << "There were more than 1 module, create headers"; QString header; - QList<const CSwordModuleInfo*>::iterator end_it = settings.modules.end(); - - for (QList<const CSwordModuleInfo*>::iterator it(settings.modules.begin()); it != end_it; ++it) { + Q_FOREACH(const CSwordModuleInfo *mi, settings.modules) { header.append("<th style=\"width:") .append(QString::number(int( 100.0 / (float)moduleCount ))) .append("%;\">") - .append((*it)->name()) + .append(mi->name()) .append("</th>"); } @@ -113,12 +121,8 @@ const QString CDisplayTemplateMgr::fillTemplate( const QString& name, const QStr QString langCSS; CLanguageMgr::LangMap langMap = CLanguageMgr::instance()->availableLanguages(); - qDebug() << "langMap length:" << langMap.count(); - qDebug() << "loop through langMap"; foreach(const CLanguageMgr::Language* lang, langMap) { //const CLanguageMgr::Language* lang = *it; - //qDebug() << "foreach, lang: "; - //qDebug() << lang; //if (lang->isValid() && CBTConfig::get(lang).first) { if (!lang->abbrev().isEmpty() && CBTConfig::get(lang).first) { @@ -154,19 +158,34 @@ const QString CDisplayTemplateMgr::fillTemplate( const QString& name, const QStr .arg(standardFont.italic() ? "italic" : "normal") ); } + + // Template stylesheet + // qWarning("Outputing unformated text"); - const QString t = QString(m_templateMap[ templateName ]) //don't change the map's content directly, use a copy + const QString t = QString(m_templateMap[ "Basic.tmpl" ]) //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) .replace("#DISPLAYTYPE#", displayTypeString) .replace("#LANG_CSS#", langCSS) .replace("#PAGE_DIRECTION#", settings.pageDirection) - .replace("#CONTENT#", newContent); + .replace("#CONTENT#", newContent) + .replace("#THEME_STYLE#", m_cssMap[ templateName ]) + .replace("#MODTYPE#", displayTypeString) + .replace("#MODNAME#", moduleName) + .replace("#MODULE_STYLESHEET#", QString("")); // Let's fix this! return t; } +QString CDisplayTemplateMgr::activeTemplateName() { + const QString tn = CBTConfig::get(CBTConfig::displayStyle); + if (tn.isEmpty()) + return defaultTemplateName(); + + return tn; +} + void CDisplayTemplateMgr::loadTemplate(const QString &filename) { QFile f(filename); if (f.open(QIODevice::ReadOnly)) { @@ -177,3 +196,8 @@ void CDisplayTemplateMgr::loadTemplate(const QString &filename) { } } } + +void CDisplayTemplateMgr::loadCSSTemplate(const QString &filename) { + QFile f(filename); + m_cssMap[QFileInfo(f).fileName()] = QString("file://") + filename; +} diff --git a/src/backend/managers/cdisplaytemplatemgr.h b/src/backend/managers/cdisplaytemplatemgr.h index 9b96e8b..a7b49e5 100644 --- a/src/backend/managers/cdisplaytemplatemgr.h +++ b/src/backend/managers/cdisplaytemplatemgr.h @@ -22,12 +22,15 @@ class CSwordModuleInfo; \note This is a singleton. */ class CDisplayTemplateMgr { + public: /* Types: */ + /** Settings which are used to fill the content into the template. */ struct Settings { - Settings() : pageDirection("ltr") {} + + inline Settings() : pageDirection("ltr") {} /** The list of modules */ QList<const CSwordModuleInfo*> modules; @@ -43,6 +46,7 @@ class CDisplayTemplateMgr { /** The CSS ID which is used in the content part of the page */ QString pageCSS_ID; + }; public: /* Methods: */ @@ -57,7 +61,7 @@ class CDisplayTemplateMgr { \returns the list of available templates. */ inline const QStringList availableTemplates() const { - return m_templateMap.keys(); + return m_cssMap.keys(); } /** @@ -72,12 +76,18 @@ class CDisplayTemplateMgr { \returns The full HTML template HTML code including the CSS data. */ - const QString fillTemplate( const QString& name, const QString& content, Settings& settings); + QString fillTemplate(const QString &name, const QString &content, + const Settings &settings); /** \returns the name of the default template. */ - inline static const char *defaultTemplate() { return "Blue.tmpl"; } + static inline const char * defaultTemplateName() { return "Blue.css"; } + + /** + \returns the name of the active template. + */ + static QString activeTemplateName(); /** \returns The singleton instance of the instance of this class. @@ -85,15 +95,20 @@ class CDisplayTemplateMgr { 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); + void loadCSSTemplate(const QString &filename); private: /* Fields: */ + QMap<QString, QString> m_templateMap; + QMap<QString, QString> m_cssMap; static CDisplayTemplateMgr *m_instance; + }; #endif diff --git a/src/backend/managers/cswordbackend.cpp b/src/backend/managers/cswordbackend.cpp index b5c109f..b5f4bff 100644 --- a/src/backend/managers/cswordbackend.cpp +++ b/src/backend/managers/cswordbackend.cpp @@ -75,23 +75,21 @@ void CSwordBackend::filterInit() { cleanupFilters.push_back(thmlplain); } -QList<CSwordModuleInfo*> CSwordBackend::takeModulesFromList(QStringList names) { - int numberOfRemoved = 0; +QList<CSwordModuleInfo*> CSwordBackend::takeModulesFromList(const QStringList &names) { QList<CSwordModuleInfo*> list; - foreach(QString name, names) { + Q_FOREACH (const QString &name, names) { CSwordModuleInfo* mInfo = findModuleByName(name); if (mInfo) { m_dataModel.removeModule(mInfo); - ++numberOfRemoved; list.append(mInfo); } } - if (numberOfRemoved > 0) + if (!list.isEmpty()) emit sigSwordSetupChanged(RemovedModules); return list; } -QList<CSwordModuleInfo*> CSwordBackend::getPointerList(const QStringList &names) { +QList<CSwordModuleInfo*> CSwordBackend::getPointerList(const QStringList &names) const { QList<CSwordModuleInfo*> list; Q_FOREACH (const QString &name, names) { CSwordModuleInfo *mInfo = findModuleByName(name); @@ -103,7 +101,7 @@ QList<CSwordModuleInfo*> CSwordBackend::getPointerList(const QStringList &names) } QList<const CSwordModuleInfo*> CSwordBackend::getConstPointerList( - const QStringList &names) + const QStringList &names) const { QList<const CSwordModuleInfo*> list; Q_FOREACH (const QString &name, names) { @@ -133,19 +131,19 @@ CSwordBackend::LoadError CSwordBackend::initModules(SetupChangedReason reason) { if (!strcmp(curMod->Type(), "Biblical Texts")) { newModule = new CSwordBibleModuleInfo(curMod, this); - newModule->module()->Disp(&m_chapterDisplay); + newModule->module()->setDisplay(&m_chapterDisplay); } else if (!strcmp(curMod->Type(), "Commentaries")) { newModule = new CSwordCommentaryModuleInfo(curMod, this); - newModule->module()->Disp(&m_entryDisplay); + newModule->module()->setDisplay(&m_entryDisplay); } else if (!strcmp(curMod->Type(), "Lexicons / Dictionaries")) { newModule = new CSwordLexiconModuleInfo(curMod, this); - newModule->module()->Disp(&m_entryDisplay); + newModule->module()->setDisplay(&m_entryDisplay); } else if (!strcmp(curMod->Type(), "Generic Books")) { newModule = new CSwordBookModuleInfo(curMod, this); - newModule->module()->Disp(&m_bookDisplay); + newModule->module()->setDisplay(&m_bookDisplay); } if (newModule) { @@ -279,7 +277,7 @@ void CSwordBackend::setFilterOptions(const FilterOptions &options) { } /** This function searches for a module with the specified description */ -CSwordModuleInfo* CSwordBackend::findModuleByDescription(const QString& description) { +CSwordModuleInfo* CSwordBackend::findModuleByDescription(const QString &description) const { Q_FOREACH (CSwordModuleInfo *mod, m_dataModel.moduleList()) { if (mod->config(CSwordModuleInfo::Description) == description) return mod; } @@ -287,16 +285,16 @@ CSwordModuleInfo* CSwordBackend::findModuleByDescription(const QString& descript } /** This function searches for a module with the specified name */ -CSwordModuleInfo* CSwordBackend::findModuleByName(const QString& name) { +CSwordModuleInfo* CSwordBackend::findModuleByName(const QString &name) const { Q_FOREACH (CSwordModuleInfo *mod, m_dataModel.moduleList()) { if (mod->name() == name) return mod; } return 0; } -CSwordModuleInfo* CSwordBackend::findSwordModuleByPointer(const sword::SWModule* const swmodule) { +CSwordModuleInfo* CSwordBackend::findSwordModuleByPointer(const sword::SWModule * const swmodule) const { Q_FOREACH (CSwordModuleInfo *mod, m_dataModel.moduleList()) { - if (mod->module() == swmodule ) return mod; + if (mod->module() == swmodule) return mod; } return 0; } diff --git a/src/backend/managers/cswordbackend.h b/src/backend/managers/cswordbackend.h index 68be102..764d6d5 100644 --- a/src/backend/managers/cswordbackend.h +++ b/src/backend/managers/cswordbackend.h @@ -65,7 +65,7 @@ class CSwordBackend : public QObject, public sword::SWMgr { NoModules = 1 }; /** - * The constructor of the Sword backend. This is actually used nowhere. + * The constructor of the Sword backend. Used by BtInstallBackend only. * 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 * @param augmentHome True if the $HOME/.sword/ modules should be augmented with the other modules @@ -132,20 +132,20 @@ class CSwordBackend : public QObject, public sword::SWMgr { * @param description The description of the desired module * @return pointer to the desired module; null if no module has the specified description */ - CSwordModuleInfo* findModuleByDescription(const QString& description); + CSwordModuleInfo* findModuleByDescription(const QString &description) const; /** * This function searches for a module with the specified name * @param name The name of the desired module * @return Pointer to the desired module; null if no module has the specified name */ - CSwordModuleInfo* findModuleByName(const QString& name); + CSwordModuleInfo* findModuleByName(const QString &name) const; /** * This function searches for a module with the specified sword module as module() object! * @param swmodule to a Sword module * @return pointer to the desired module; null if no module has the specified name */ - CSwordModuleInfo* findSwordModuleByPointer(const sword::SWModule* const swmodule); + CSwordModuleInfo* findSwordModuleByPointer(const sword::SWModule * const swmodule) const; /** * @return Our global config object which contains the configs of all modules merged together. @@ -177,19 +177,19 @@ class CSwordBackend : public QObject, public sword::SWMgr { * Takes off the given modules from the list and returns them. * User must take care of the deletion of the returned CSwordModuleInfo pointers. */ - QList<CSwordModuleInfo*> takeModulesFromList(QStringList names); + QList<CSwordModuleInfo*> takeModulesFromList(const QStringList &names); /** \returns a list of pointers to modules, created from a list of module names. */ - QList<CSwordModuleInfo*> getPointerList(const QStringList &names); + QList<CSwordModuleInfo*> getPointerList(const QStringList &names) const; /** \returns a list of pointers to const modules, created from a list of module names. */ - QList<const CSwordModuleInfo*> getConstPointerList(const QStringList &names); + QList<const CSwordModuleInfo*> getConstPointerList(const QStringList &names) const; /** Sword prefix list. * @return A list of all known Sword prefix dirs diff --git a/src/backend/managers/referencemanager.cpp b/src/backend/managers/referencemanager.cpp index de41af2..0a17645 100644 --- a/src/backend/managers/referencemanager.cpp +++ b/src/backend/managers/referencemanager.cpp @@ -250,51 +250,35 @@ const QString ReferenceManager::preferredModule( const ReferenceManager::Type ty switch (type) { case ReferenceManager::Bible: - - module = CBTConfig::get - ( CBTConfig::standardBible ); - + module = CBTConfig::get(CBTConfig::standardBible); break; case ReferenceManager::Commentary: - module = CBTConfig::get - ( CBTConfig::standardCommentary ); - + module = CBTConfig::get(CBTConfig::standardCommentary); break; case ReferenceManager::Lexicon: - module = CBTConfig::get - ( CBTConfig::standardLexicon ); - + module = CBTConfig::get(CBTConfig::standardLexicon); break; case ReferenceManager::StrongsHebrew: - module = CBTConfig::get - ( CBTConfig::standardHebrewStrongsLexicon ); - + module = CBTConfig::get(CBTConfig::standardHebrewStrongsLexicon); break; case ReferenceManager::StrongsGreek: - module = CBTConfig::get - ( CBTConfig::standardGreekStrongsLexicon ); - + module = CBTConfig::get(CBTConfig::standardGreekStrongsLexicon); break; case ReferenceManager::MorphHebrew: - module = CBTConfig::get - ( CBTConfig::standardHebrewMorphLexicon ); - + module = CBTConfig::get(CBTConfig::standardHebrewMorphLexicon); break; case ReferenceManager::MorphGreek: - module = CBTConfig::get - ( CBTConfig::standardGreekMorphLexicon ); - + module = CBTConfig::get(CBTConfig::standardGreekMorphLexicon); break; default: module = 0; - break; } diff --git a/src/backend/rendering/cbookdisplay.cpp b/src/backend/rendering/cbookdisplay.cpp index 259e904..6589e99 100644 --- a/src/backend/rendering/cbookdisplay.cpp +++ b/src/backend/rendering/cbookdisplay.cpp @@ -53,8 +53,6 @@ const QString Rendering::CBookDisplay::text( const QString renderedText = render.renderKeyTree(tree); key->setOffset( offset ); - - qDeleteAll(tree); // Dispose of the heap allocated objects pointed to in tree. return renderedText; }; @@ -84,7 +82,6 @@ const QString Rendering::CBookDisplay::text( const QString renderedText = render.renderKeyTree(tree); key->setOffset( offset ); - qDeleteAll(tree); // Dispose of the heap allocated objects pointed to in tree. return renderedText; }; @@ -101,7 +98,6 @@ const QString Rendering::CBookDisplay::text( const QString renderedText = render.renderKeyTree(tree); key->setOffset( offset ); - qDeleteAll(tree); // Dispose of the heap allocated objects pointed to in tree. return renderedText; }; }; @@ -119,8 +115,6 @@ const QString Rendering::CBookDisplay::text( const QString renderedText = render.renderKeyTree(tree); key->setOffset( offset ); //restore key - - qDeleteAll(tree); // Dispose of the heap allocated objects pointed to in tree. return renderedText; } diff --git a/src/backend/rendering/cbookdisplay.h b/src/backend/rendering/cbookdisplay.h index be5ec9b..4bd5c22 100644 --- a/src/backend/rendering/cbookdisplay.h +++ b/src/backend/rendering/cbookdisplay.h @@ -26,21 +26,22 @@ namespace Rendering { 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 +}; /* class CBookDisplay */ + +} /* namespace Rendering */ #endif diff --git a/src/backend/rendering/cchapterdisplay.cpp b/src/backend/rendering/cchapterdisplay.cpp index 31b56b8..eea2a72 100644 --- a/src/backend/rendering/cchapterdisplay.cpp +++ b/src/backend/rendering/cchapterdisplay.cpp @@ -51,14 +51,17 @@ const QString Rendering::CChapterDisplay::text( k1.Headings(1); k1.setKey(keyName); - if (k1.Chapter() == 1) k1.Chapter(0); //Chapter 1, start with 0:0, otherwise X:0 + if (k1.getChapter() == 1) + k1.setChapter(0); // Chapter 1, start with 0:0, otherwise X:0 - k1.Verse(0); + k1.setVerse(0); startKey = k1.key(); - if (k1.Chapter() == 0) k1.Chapter(1); - k1.Verse(bible->verseCount(k1.book(), k1.Chapter())); + if (k1.getChapter() == 0) + k1.setChapter(1); + + k1.setVerse(bible->verseCount(k1.book(), k1.getChapter())); endKey = k1.key(); } diff --git a/src/backend/rendering/cchapterdisplay.h b/src/backend/rendering/cchapterdisplay.h index a13ebc3..c245c57 100644 --- a/src/backend/rendering/cchapterdisplay.h +++ b/src/backend/rendering/cchapterdisplay.h @@ -22,18 +22,16 @@ namespace Rendering { once. */ class CChapterDisplay: public CEntryDisplay { + public: /* Methods: */ - virtual inline ~CChapterDisplay() {} - /** - Reimplemented from CEntryDisplay. - */ virtual const QString text(const QList<const CSwordModuleInfo*> &modules, const QString &key, const DisplayOptions &displayOptions, const FilterOptions &filterOptions); -}; -} // namespace Rendering +}; /* class CChapterDisplay */ + +} /* namespace Rendering */ #endif diff --git a/src/backend/rendering/cdisplayrendering.cpp b/src/backend/rendering/cdisplayrendering.cpp index c79cfdf..175cf4e 100644 --- a/src/backend/rendering/cdisplayrendering.cpp +++ b/src/backend/rendering/cdisplayrendering.cpp @@ -11,7 +11,6 @@ #include <QString> #include <QRegExp> -#include <QDebug> #include "backend/keys/cswordkey.h" #include "backend/keys/cswordversekey.h" #include "backend/managers/cdisplaytemplatemgr.h" @@ -22,14 +21,13 @@ namespace Rendering { CDisplayRendering::CDisplayRendering(const DisplayOptions &displayOptions, const FilterOptions &filterOptions) - : CHTMLExportRendering(CHTMLExportRendering::Settings(true), - displayOptions, filterOptions) + : CHTMLExportRendering(true, displayOptions, filterOptions) { // Intentionally empty } -const QString CDisplayRendering::entryLink(const KeyTreeItem &item, - const CSwordModuleInfo *module) +QString CDisplayRendering::entryLink(const KeyTreeItem &item, + const CSwordModuleInfo * module) { QString linkText; @@ -41,7 +39,7 @@ const QString CDisplayRendering::entryLink(const KeyTreeItem &item, vk.setKey(item.key()); } - if (isBible && (vk.Verse() == 0)) { + if (isBible && (vk.getVerse() == 0)) { return QString::null; //Warning: return already here } @@ -72,7 +70,7 @@ const QString CDisplayRendering::entryLink(const KeyTreeItem &item, case KeyTreeItem::Settings::SimpleKey: { if (isBible) { - linkText = QString::number(vk.Verse()); + linkText = QString::number(vk.getVerse()); break; } @@ -101,18 +99,14 @@ const QString CDisplayRendering::entryLink(const KeyTreeItem &item, return QString::null; } -const QString CDisplayRendering::keyToHTMLAnchor(const QString& key) { - QString ret = key; +QString CDisplayRendering::keyToHTMLAnchor(const QString& key) { // Be careful not to remove non-ASCII characters, this causes problems // with many languages. - ret = ret.trimmed().remove(QRegExp("\\s")).replace(QString(":"), QString("_")); - - return ret; + return key.trimmed().remove(QRegExp("\\s")).replace(QString(":"), QString("_")); } -const QString CDisplayRendering::finishText( const QString& oldText, KeyTree& tree ) { - QList<const CSwordModuleInfo*> modules = collectModules(&tree); - qDebug() << "CDisplayRendering::finishText"; +QString CDisplayRendering::finishText(const QString &text, const KeyTree &tree) { + QList<const CSwordModuleInfo*> modules = collectModules(tree); //marking words is very slow, we have to find a better solution @@ -160,6 +154,6 @@ const QString CDisplayRendering::finishText( const QString& oldText, KeyTree& tr else settings.pageDirection = QString::null; - return tMgr->fillTemplate(CBTConfig::get(CBTConfig::displayStyle), oldText, settings); + return tMgr->fillTemplate(CDisplayTemplateMgr::activeTemplateName(), text, settings); } } diff --git a/src/backend/rendering/cdisplayrendering.h b/src/backend/rendering/cdisplayrendering.h index 8b222ac..362fc2a 100644 --- a/src/backend/rendering/cdisplayrendering.h +++ b/src/backend/rendering/cdisplayrendering.h @@ -21,21 +21,24 @@ namespace Rendering { */ class CDisplayRendering : public CHTMLExportRendering { - public: - static const QString keyToHTMLAnchor(const QString& key); + + public: /* Methods: */ + + static QString keyToHTMLAnchor(const QString &key); CDisplayRendering( const DisplayOptions &displayOptions = CBTConfig::getDisplayOptionDefaults(), - const FilterOptions &filterOptions = CBTConfig::getFilterOptionDefaults() - ); + const FilterOptions &filterOptions = CBTConfig::getFilterOptionDefaults()); + + protected: /* Methods: */ + + virtual QString entryLink(const KeyTreeItem &item, + const CSwordModuleInfo * module); - protected: - virtual const QString entryLink(const KeyTreeItem &item, - const CSwordModuleInfo *module); + virtual QString finishText(const QString &text, const KeyTree &tree); - virtual const QString finishText( const QString&, KeyTree& tree ); -}; +}; /* class CDisplayRendering */ -} +} /* namespace Rendering */ #endif diff --git a/src/backend/rendering/centrydisplay.cpp b/src/backend/rendering/centrydisplay.cpp index d1b2a34..7415eda 100644 --- a/src/backend/rendering/centrydisplay.cpp +++ b/src/backend/rendering/centrydisplay.cpp @@ -49,23 +49,21 @@ const QString CEntryDisplay::text( // don't print the key CTextRendering::KeyTreeItem::Settings preverse_settings(false, CTextRendering::KeyTreeItem::Settings::NoKey); - if (k1.Verse() == 1) { //X:1, prepend X:0 - if (k1.Chapter() == 1) { //1:1, also prepend 0:0 before that - k1.Chapter(0); - k1.Verse(0); + if (k1.getVerse() == 1) { // X:1, prepend X:0 + if (k1.getChapter() == 1) { // 1:1, also prepend 0:0 before that + k1.setChapter(0); + k1.setVerse(0); if ( k1.rawText().length() > 0 ) { tree.append( new Rendering::CTextRendering::KeyTreeItem(k1.key(), modules, preverse_settings) ); } - k1.Chapter(1); + k1.setChapter(1); } - k1.Verse(0); + k1.setVerse(0); if ( k1.rawText().length() > 0 ) { tree.append( new Rendering::CTextRendering::KeyTreeItem(k1.key(), modules, preverse_settings) ); } } } tree.append( new Rendering::CTextRendering::KeyTreeItem(keyName, modules, normal_settings) ); - QString result(render.renderKeyTree(tree)); - qDeleteAll(tree); - return result; + return render.renderKeyTree(tree); } diff --git a/src/backend/rendering/centrydisplay.h b/src/backend/rendering/centrydisplay.h index 08a55c4..50b6447 100644 --- a/src/backend/rendering/centrydisplay.h +++ b/src/backend/rendering/centrydisplay.h @@ -23,7 +23,9 @@ struct FilterOptions; namespace Rendering { class CEntryDisplay: public sword::SWDisplay { - public: + + public: /* Methods: */ + /** \returns the rendered text using the modules in the list and using the key parameter. @@ -32,9 +34,9 @@ class CEntryDisplay: public sword::SWDisplay { const QString &key, const DisplayOptions &displayOptions, const FilterOptions &filterOptions); -}; +}; /* class CEntryDisplay */ -} +} /* namespace Rendering */ #endif diff --git a/src/backend/rendering/chtmlexportrendering.cpp b/src/backend/rendering/chtmlexportrendering.cpp index 3d82602..66897b5 100644 --- a/src/backend/rendering/chtmlexportrendering.cpp +++ b/src/backend/rendering/chtmlexportrendering.cpp @@ -10,7 +10,6 @@ #include "backend/rendering/chtmlexportrendering.h" #include <QSharedPointer> -#include <QDebug> #include "backend/drivers/cswordmoduleinfo.h" #include "backend/keys/cswordkey.h" @@ -19,7 +18,9 @@ #include "backend/managers/clanguagemgr.h" -#ifdef BT_DEBUG +#if 0 +#include <QDebug> + namespace { /** Helper function to dump a verse with all its enty attributes. */ @@ -45,26 +46,28 @@ void dumpEntryAttributes(sword::SWModule *module) { namespace Rendering { CHTMLExportRendering::CHTMLExportRendering( - const CHTMLExportRendering::Settings &settings, + bool addText, const DisplayOptions &displayOptions, const FilterOptions &filterOptions) - : m_displayOptions(displayOptions), - m_filterOptions(filterOptions), - m_settings(settings) + : m_displayOptions(displayOptions) + , m_filterOptions(filterOptions) + , m_addText(addText) { // Intentionally empty } -const QString CHTMLExportRendering::renderEntry( const KeyTreeItem& i, CSwordKey* k) { +QString CHTMLExportRendering::renderEntry(const KeyTreeItem& i, CSwordKey* k) { if (i.hasAlternativeContent()) { - QString ret = QString(i.settings().highlight ? "<div class=\"currententry\">" : "<div class=\"entry\">"); + QString ret = i.settings().highlight + ? "<div class=\"currententry\">" + : "<div class=\"entry\">"; ret.append(i.getAlternativeContent()); // Q_ASSERT(i.hasChildItems()); if (!i.childList()->isEmpty()) { - KeyTree * const tree = i.childList(); + const KeyTree & tree = *i.childList(); const QList<const CSwordModuleInfo*> modules = collectModules(tree); @@ -72,8 +75,8 @@ const QString CHTMLExportRendering::renderEntry( const KeyTreeItem& i, CSwordKey ret.insert( 5, QString("dir=\"%1\" ").arg((modules.first()->textDirection() == CSwordModuleInfo::LeftToRight) ? "ltr" : "rtl" )); } - foreach ( KeyTreeItem* c, (*tree) ) { - ret.append( renderEntry( *c ) ); + Q_FOREACH (const KeyTreeItem * const item, tree) { + ret.append(renderEntry(*item)); } } @@ -83,8 +86,8 @@ const QString CHTMLExportRendering::renderEntry( const KeyTreeItem& i, CSwordKey const QList<const CSwordModuleInfo*> &modules(i.modules()); - if (modules.count() == 0) { - return QString(""); //no module present for rendering + if (modules.isEmpty()) { + return ""; //no module present for rendering } QSharedPointer<CSwordKey> scoped_key( !k ? CSwordKey::createInstance(modules.first()) : 0 ); @@ -93,7 +96,9 @@ const QString CHTMLExportRendering::renderEntry( const KeyTreeItem& i, CSwordKey CSwordVerseKey* myVK = dynamic_cast<CSwordVerseKey*>(key); - if ( myVK ) myVK->Headings(1); + if (myVK) { + myVK->Headings(1); + } QString renderedText( (modules.count() > 1) ? "\n\t\t<tr>\n" : "\n" ); // Only insert the table stuff if we are displaying parallel. @@ -142,7 +147,7 @@ const QString CHTMLExportRendering::renderEntry( const KeyTreeItem& i, CSwordKey (*mod_Itr)->module()->getEntryAttributes()["Heading"]["Preverse"].end(); for (; it != end; ++it) { - QString unfiltered = it->second.c_str(); + QString unfiltered = QString::fromUtf8(it->second.c_str()); /// \todo This is only a preliminary workaround to strip the tags: QRegExp filter("<title>(.*)</title>"); @@ -169,12 +174,12 @@ const QString CHTMLExportRendering::renderEntry( const KeyTreeItem& i, CSwordKey entry.append( i.settings().highlight ? "class=\"currententry\" " : "class=\"entry\" " ); } - entry.append(langAttr).append(isRTL ? " dir=\"rtl\"" : " dir=\"ltr\"").append(">"); + entry.append(langAttr).append(isRTL ? " dir=\"rtl\">" : " dir=\"ltr\">"); //keys should normally be left-to-right, but this doesn't apply in all cases entry.append("<span class=\"entryname\" dir=\"ltr\">").append(entryLink(i, *mod_Itr)).append("</span>"); - if (m_settings.addText) { + if (m_addText) { //entry.append( QString::fromLatin1("<span %1>%2</span>").arg(langAttr).arg(key_renderedText) ); entry.append( key_renderedText ); } @@ -182,7 +187,7 @@ const QString CHTMLExportRendering::renderEntry( const KeyTreeItem& i, CSwordKey if (!i.childList()->isEmpty()) { KeyTree* tree(i.childList()); - foreach (KeyTreeItem* c, (*tree)) { + Q_FOREACH (const KeyTreeItem * const c, *tree) { entry.append( renderEntry(*c) ); } } @@ -218,28 +223,31 @@ void CHTMLExportRendering::initRendering() { CSwordBackend::instance()->setFilterOptions( m_filterOptions ); } -const QString CHTMLExportRendering::finishText( const QString& text, KeyTree& tree ) { - const QList<const CSwordModuleInfo*> modules = collectModules(&tree); - - const CLanguageMgr::Language* const lang = modules.first()->language(); - - CDisplayTemplateMgr *tMgr = CDisplayTemplateMgr::instance(); - CDisplayTemplateMgr::Settings settings; - settings.modules = modules; - settings.langAbbrev = ((modules.count() == 1) && lang->isValid()) ? lang->abbrev() : "unknown"; - if (modules.count() == 1) - settings.pageDirection = ((modules.first()->textDirection() == CSwordModuleInfo::LeftToRight) ? "ltr" : "rtl"); - else +QString CHTMLExportRendering::finishText(const QString &text, const KeyTree &tree) { + typedef CDisplayTemplateMgr CDTM; + + CDTM::Settings settings; + settings.modules = collectModules(tree); + if (settings.modules.count() == 1) { + const CSwordModuleInfo * const firstModule = settings.modules.first(); + const CLanguageMgr::Language * const lang = firstModule->language(); + settings.langAbbrev = lang->isValid() ? lang->abbrev() : "unknown"; + if (firstModule->textDirection() == CSwordModuleInfo::RightToLeft) { + settings.pageDirection = "rtl"; + } + } else { + settings.langAbbrev = "unknown"; settings.pageDirection = QString::null; + } - return tMgr->fillTemplate(QObject::tr("Export"), text, settings); + return CDTM::instance()->fillTemplate(QObject::tr("Export"), text, settings); } /*! \fn CHTMLExportRendering::entryLink( KeyTreeItem& item ) */ -const QString CHTMLExportRendering::entryLink(const KeyTreeItem& item, - const CSwordModuleInfo *module) +QString CHTMLExportRendering::entryLink(const KeyTreeItem &item, + const CSwordModuleInfo * module) { Q_UNUSED(module); diff --git a/src/backend/rendering/chtmlexportrendering.h b/src/backend/rendering/chtmlexportrendering.h index 97e632d..db90707 100644 --- a/src/backend/rendering/chtmlexportrendering.h +++ b/src/backend/rendering/chtmlexportrendering.h @@ -25,37 +25,31 @@ namespace Rendering { * @short HTML rendering for export. * @author The BibleTime team */ +class CHTMLExportRendering: public CTextRendering { -class CHTMLExportRendering : public CTextRendering { - - public: - struct Settings { - Settings(const bool text = true) { - addText = text; - }; - - bool addText; - }; + public: /* Methods: */ CHTMLExportRendering( - const Settings &settings, + bool addText, const DisplayOptions &displayOptions = CBTConfig::getDisplayOptionDefaults(), - const FilterOptions &filterOptions = CBTConfig::getFilterOptionDefaults() - ); - 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, - const CSwordModuleInfo *module); + const FilterOptions &filterOptions = CBTConfig::getFilterOptionDefaults()); + + protected: /* Methods: */ + + virtual QString renderEntry(const KeyTreeItem &item, CSwordKey * key = 0); + virtual QString finishText(const QString &text, const KeyTree &tree); + virtual QString entryLink(const KeyTreeItem &item, + const CSwordModuleInfo *module); virtual void initRendering(); + protected: /* Fields: */ + DisplayOptions m_displayOptions; FilterOptions m_filterOptions; - Settings m_settings; -}; + bool m_addText; + +}; /* class CHTMLExportRendering */ -} +} /* namespace Rendering */ #endif diff --git a/src/backend/rendering/cplaintextexportrendering.cpp b/src/backend/rendering/cplaintextexportrendering.cpp index cad5eb9..4bff025 100644 --- a/src/backend/rendering/cplaintextexportrendering.cpp +++ b/src/backend/rendering/cplaintextexportrendering.cpp @@ -16,33 +16,29 @@ namespace Rendering { CPlainTextExportRendering::CPlainTextExportRendering( - const CPlainTextExportRendering::Settings &settings, + bool addText, const DisplayOptions &displayOptions, const FilterOptions &filterOptions) - : CHTMLExportRendering(settings, displayOptions, filterOptions) + : CHTMLExportRendering(addText, displayOptions, filterOptions) { // Intentionally empty } -const QString CPlainTextExportRendering::renderEntry(const KeyTreeItem &i, - CSwordKey *k) +QString CPlainTextExportRendering::renderEntry(const KeyTreeItem &i, + CSwordKey * k) { Q_UNUSED(k); - if (!m_settings.addText) { + if (!m_addText) return QString(i.key()).append("\n"); - } - QList<const CSwordModuleInfo*> modules = i.modules(); - QSharedPointer<CSwordKey> key( CSwordKey::createInstance(modules.first()) ); + const QList<const CSwordModuleInfo*> modules = i.modules(); + 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<const CSwordModuleInfo*>::iterator end_it = modules.end(); - - for (QList<const CSwordModuleInfo*>::iterator it(modules.begin()); it != end_it; ++it) { - key->setModule(*it); + Q_FOREACH(const CSwordModuleInfo * module, modules) { + key->setModule(module); key->setKey(i.key()); /// \todo Check this code @@ -50,11 +46,13 @@ const QString CPlainTextExportRendering::renderEntry(const KeyTreeItem &i, renderedText.append( entry ); } + delete key; return renderedText; } -const QString CPlainTextExportRendering::finishText( const QString& oldText, KeyTree& ) { - return oldText; +QString CPlainTextExportRendering::finishText(const QString &text, const KeyTree &tree) { + Q_UNUSED(tree); + return text; } } diff --git a/src/backend/rendering/cplaintextexportrendering.h b/src/backend/rendering/cplaintextexportrendering.h index d14192e..9360474 100644 --- a/src/backend/rendering/cplaintextexportrendering.h +++ b/src/backend/rendering/cplaintextexportrendering.h @@ -20,22 +20,22 @@ namespace Rendering { * @short Text rendering as plain text. * @author The BibleTime team */ +class CPlainTextExportRendering: public CHTMLExportRendering { -class CPlainTextExportRendering : public CHTMLExportRendering { + public: /* Methods: */ - public: CPlainTextExportRendering( - const Settings &settings, + bool addText, const DisplayOptions &displayOptions = CBTConfig::getDisplayOptionDefaults(), - const FilterOptions &filterOptions = CBTConfig::getFilterOptionDefaults() - ); - virtual inline ~CPlainTextExportRendering() {}; + const FilterOptions &filterOptions = CBTConfig::getFilterOptionDefaults()); - protected: - virtual const QString renderEntry( const KeyTreeItem&, CSwordKey* = 0 ); - virtual const QString finishText( const QString&, KeyTree& tree ); -}; + protected: /* Methods: */ -} + virtual QString renderEntry(const KeyTreeItem &item, CSwordKey * key = 0); + virtual QString finishText(const QString &text, const KeyTree &tree); + +}; /* class CPlainTextExportRendering */ + +} /* namespace Rendering */ #endif diff --git a/src/backend/rendering/ctextrendering.cpp b/src/backend/rendering/ctextrendering.cpp index 586d11e..72e4e12 100644 --- a/src/backend/rendering/ctextrendering.cpp +++ b/src/backend/rendering/ctextrendering.cpp @@ -74,8 +74,10 @@ CTextRendering::KeyTreeItem::KeyTreeItem(const KeyTreeItem& i) m_key( i.m_key ), m_childList(), m_stopKey( i.m_stopKey ), - m_alternativeContent( i.m_alternativeContent ) { - foreach(KeyTreeItem* item, (*i.childList())) { + m_alternativeContent( i.m_alternativeContent ) +{ + const KeyTree &tree = *i.childList(); + Q_FOREACH (const KeyTreeItem * const item, tree) { m_childList.append(new KeyTreeItem((*item))); //deep copy } @@ -134,19 +136,19 @@ CTextRendering::KeyTreeItem::KeyTreeItem(const QString &startKey, else { sword::VerseKey vk(startKey.toUtf8().constData(), stopKey.toUtf8().constData()); - if (vk.LowerBound().Book() != vk.UpperBound().Book()) { + if (vk.LowerBound().getBook() != vk.UpperBound().getBook()) { m_alternativeContent = QString::fromUtf8(vk.getRangeText()); } - else if (vk.LowerBound().Chapter() != vk.UpperBound().Chapter()) { + else if (vk.LowerBound().getChapter() != vk.UpperBound().getChapter()) { m_alternativeContent = QString("%1 - %2:%3") .arg(QString::fromUtf8(vk.LowerBound().getText())) - .arg(vk.UpperBound().Chapter()) - .arg(vk.UpperBound().Verse()); + .arg(vk.UpperBound().getChapter()) + .arg(vk.UpperBound().getVerse()); } else { //only verses differ (same book, same chapter) m_alternativeContent = QString("%1 - %2") .arg(QString::fromUtf8(vk.LowerBound().getText())) - .arg(vk.UpperBound().Verse()); + .arg(vk.UpperBound().getVerse()); } } @@ -154,29 +156,24 @@ CTextRendering::KeyTreeItem::KeyTreeItem(const QString &startKey, m_alternativeContent.prepend("<div class=\"rangeheading\" dir=\"ltr\">").append("</div>"); //insert the right tags } -const QString& CTextRendering::KeyTreeItem::getAlternativeContent() const { - return m_alternativeContent; -} - -const QList<const CSwordModuleInfo*> CTextRendering::collectModules(KeyTree* const tree) const { +QList<const CSwordModuleInfo*> CTextRendering::collectModules(const KeyTree &tree) const { //collect all modules which are available and used by child items QList<const CSwordModuleInfo*> modules; - foreach (KeyTreeItem* c, (*tree)) { - Q_ASSERT(c); - foreach (const CSwordModuleInfo* mod, c->modules()) { - if (!modules.contains(mod)) { + Q_FOREACH (const KeyTreeItem * const c, tree) { + Q_ASSERT(c != 0); + Q_FOREACH (const CSwordModuleInfo * const mod, c->modules()) { + if (!modules.contains(mod)) modules.append(mod); - } } } return modules; } -const QString CTextRendering::renderKeyTree( KeyTree& tree ) { +const QString CTextRendering::renderKeyTree(const KeyTree &tree) { initRendering(); - QList<const CSwordModuleInfo*> modules = collectModules(&tree); + const QList<const CSwordModuleInfo*> modules = collectModules(tree); QString t; //optimization for entries with the same key @@ -185,13 +182,13 @@ const QString CTextRendering::renderKeyTree( KeyTree& tree ) { ); if (modules.count() == 1) { //this optimizes the rendering, only one key created for all items - foreach (KeyTreeItem* c, tree) { + Q_FOREACH (const KeyTreeItem * const c, tree) { key->setKey(c->key()); t.append( renderEntry( *c, key.data()) ); } } else { - foreach (KeyTreeItem* c, tree) { + Q_FOREACH (const KeyTreeItem * const c, tree) { t.append( renderEntry( *c ) ); } } @@ -245,18 +242,16 @@ const QString CTextRendering::renderKeyRange( it should be displayed as one entry with the caption 1-5. */ - if (vk_start->Chapter() == 0) { //range was 0:0-1:x, render 0:0 first and jump to 1:0 - vk_start->Verse(0); + if (vk_start->getChapter() == 0) { // range was 0:0-1:x, render 0:0 first and jump to 1:0 + vk_start->setVerse(0); tree.append( new KeyTreeItem(vk_start->key(), modules, settings) ); - vk_start->Chapter(1); - vk_start->Verse(0); + vk_start->setChapter(1); + vk_start->setVerse(0); } tree.append( new KeyTreeItem(vk_start->key(), modules, settings) ); ok = vk_start->next(CSwordVerseKey::UseVerse); } - const QString renderedText = renderKeyTree(tree); - qDeleteAll(tree); - return renderedText; + return renderKeyTree(tree); } return QString::null; @@ -270,7 +265,5 @@ const QString CTextRendering::renderSingleKey( KeyTree tree; tree.append( new KeyTreeItem(key, modules, settings) ); - const QString renderedText = renderKeyTree(tree); - qDeleteAll(tree); - return renderedText; + return renderKeyTree(tree); } diff --git a/src/backend/rendering/ctextrendering.h b/src/backend/rendering/ctextrendering.h index c6b187a..161deef 100644 --- a/src/backend/rendering/ctextrendering.h +++ b/src/backend/rendering/ctextrendering.h @@ -11,12 +11,15 @@ #define CTEXTRENDERING_H #include <QList> +#include <QSharedPointer> #include <QString> class CSwordKey; class CSwordModuleInfo; +namespace Rendering { + /** * CTextRendering is BibleTime's place where the actual rendering takes place. * It provides several methods to convert an abstract tree of items @@ -26,20 +29,28 @@ class CSwordModuleInfo; * @short Text rendering based on trees * @author The BibleTime team */ - -namespace Rendering { - class CTextRendering { - public: + public: /* Types: */ class KeyTreeItem; - typedef QList<KeyTreeItem*> KeyTree; - class KeyTreeItem { + class KeyTreeSharedPointer: public QSharedPointer<KeyTreeItem> { public: + inline KeyTreeSharedPointer(KeyTreeItem * i) + : QSharedPointer<KeyTreeItem>(i) {} + + inline operator const KeyTreeItem * () const { return data(); } + }; + + typedef QList<KeyTreeSharedPointer> KeyTree; + + class KeyTreeItem { + + public: /* Types: */ struct Settings { + enum KeyRenderingFace { NoKey, //< means no key shown at all SimpleKey, //< means only versenumber or only lexicon entry name @@ -47,11 +58,18 @@ class CTextRendering { CompleteLong //< means "Genesis 1:1" }; - Settings(const bool highlight = false, KeyRenderingFace keyRendering = SimpleKey) : highlight(highlight), keyRenderingFace(keyRendering) {} + Settings(const bool highlight = false, + KeyRenderingFace keyRendering = SimpleKey) + : highlight(highlight) + , keyRenderingFace(keyRendering) + {} bool highlight; KeyRenderingFace keyRenderingFace; - }; + + }; /* struct Settings */ + + public: /* Methods: */ KeyTreeItem(const QString &key, const CSwordModuleInfo *module, @@ -70,37 +88,40 @@ class CTextRendering { KeyTreeItem(const KeyTreeItem &i); - virtual inline ~KeyTreeItem() { - qDeleteAll(m_childList); + inline const QString &getAlternativeContent() const { + return m_alternativeContent; } - const QString& getAlternativeContent() const; inline void setAlternativeContent(const QString& newContent) { m_alternativeContent = newContent; - }; + } inline bool hasAlternativeContent() const { return !m_alternativeContent.isNull(); - }; + } inline const QList<const CSwordModuleInfo*>& modules() const { return m_moduleList; - }; + } inline const QString& key() const { return m_key; - }; + } inline const Settings& settings() const { return m_settings; - }; + } - inline KeyTree* childList() const; -// inline const bool hasChildItems() const; + inline KeyTree* childList() const { + return &m_childList; + } + + protected: /* Methods: */ - protected: KeyTreeItem(); + private: /* Fields: */ + Settings m_settings; QList<const CSwordModuleInfo*> m_moduleList; QString m_key; @@ -108,11 +129,12 @@ class CTextRendering { QString m_stopKey; QString m_alternativeContent; - }; - virtual ~CTextRendering() {} + }; /* class KeyTreeItem */ + + public: /* Methods: */ - const QString renderKeyTree( KeyTree& ); + const QString renderKeyTree(const KeyTree &tree); const QString renderKeyRange( const QString &start, @@ -126,21 +148,15 @@ class CTextRendering { const QList<const CSwordModuleInfo*> &modules, const KeyTreeItem::Settings &settings = KeyTreeItem::Settings()); - protected: - 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; + protected: /* Methods: */ + + QList<const CSwordModuleInfo*> collectModules(const KeyTree &tree) const; + virtual QString renderEntry(const KeyTreeItem &item, CSwordKey * key = 0) = 0; + virtual QString finishText(const QString &text, const KeyTree &tree) = 0; virtual void initRendering() = 0; -}; -inline CTextRendering::KeyTree* CTextRendering::KeyTreeItem::childList() const { - return &m_childList; -} -// -//inline const bool CTextRendering::KeyTreeItem::hasChildItems() const { -// return !m_childList.isEmpty(); -//} +}; /* class CTextRendering */ -} +} /* namespace Rendering */ #endif |