summaryrefslogtreecommitdiff
path: root/src/backend/managers/cswordbackend.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/managers/cswordbackend.h')
-rw-r--r--src/backend/managers/cswordbackend.h173
1 files changed, 74 insertions, 99 deletions
diff --git a/src/backend/managers/cswordbackend.h b/src/backend/managers/cswordbackend.h
index c8b4f77..68be102 100644
--- a/src/backend/managers/cswordbackend.h
+++ b/src/backend/managers/cswordbackend.h
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2008 by the BibleTime developers.
+* Copyright 1999-2011 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -16,6 +16,14 @@
#include <QStringList>
#include "backend/drivers/cswordmoduleinfo.h"
#include "backend/bookshelfmodel/btbookshelfmodel.h"
+#include "backend/filters/gbftohtml.h"
+#include "backend/filters/osistohtml.h"
+#include "backend/filters/plaintohtml.h"
+#include "backend/filters/teitohtml.h"
+#include "backend/filters/thmltohtml.h"
+#include "backend/rendering/cbookdisplay.h"
+#include "backend/rendering/cchapterdisplay.h"
+#include "backend/rendering/centrydisplay.h"
// Sword includes:
#include <swmgr.h>
@@ -25,20 +33,17 @@
#include <localemgr.h>
#include <utilstr.h>
-namespace Rendering {
-class CEntryDisplay;
-class CChapterDisplay;
-class CBookDisplay;
-}
+/**
+ \brief The backend layer main class, a backend implementation of Sword.
+
+ This is the implementation of CBackend for Sword. It's additionally derived
+ from SWMgr to provide functions of Sword.
-/** The backend layer main class.
- * This is the implementation of CBackend for Sword. It's additionally derived from SWMgr
- * to provide functions of Sword.
- *
- * @short The backend implementation of Sword
- * @author The BibleTime team
- * @version $Id: cswordbackend.h,v 1.58 2007/03/14 21:32:47 joachim Exp $
- */
+ \note Mostly, only one instance of this class is used. This instance is
+ created by BibleTime::initBackends() and is destroyed by
+ BibleTimeApp::~BibleTimeApp(). Only when \ref BackendNotSingleton
+ "managing modules" separate backends are created.
+*/
class CSwordBackend : public QObject, public sword::SWMgr {
Q_OBJECT
public:
@@ -52,32 +57,6 @@ class CSwordBackend : public QObject, public sword::SWMgr {
OtherChange = 16
};
- /** Filter options. Filter options to
- * control the text display of modules. Uses int and not bool because not all
- * options have just two toggle values.
- */
- struct FilterOptions {
- int footnotes; /**< 0 for disabled, 1 for enabled */
- int strongNumbers; /**< 0 for disabled, 1 for enabled */
- int headings; /**< 0 for disabled, 1 for enabled */
- int morphTags; /**< 0 for disabled, 1 for enabled */
- int lemmas; /**< 0 for disabled, 1 for enabled */
- int hebrewPoints; /**< 0 for disabled, 1 for enabled */
- int hebrewCantillation; /**< 0 for disabled, 1 for enabled */
- int greekAccents; /**< 0 for disabled, 1 for enabled */
- int textualVariants; /**< Number n to enabled the n-th variant */
- int redLetterWords; /**< 0 for disabled, 1 for enabled */
- int scriptureReferences; /**< 0 for disabled, 1 for enabled */
- int morphSegmentation; /**< 0 for disabled, 1 for enabled */
- };
-
- /** Control the display of a text.
- */
- struct DisplayOptions {
- int lineBreaks;
- int verseNumbers;
- };
-
/** The error codes which may be returned by the @ref Load() call.
*/
enum LoadError { // the values exist to cast from the char return of SWMgr::Load
@@ -86,12 +65,6 @@ class CSwordBackend : public QObject, public sword::SWMgr {
NoModules = 1
};
/**
- * The constructor of the Sword backend.
- * It creates the SWModule objects using SWMgr's methods, it adds the necessary
- * filters for the module format.
- */
- CSwordBackend();
- /**
* The constructor of the Sword backend. This is actually used nowhere.
* Notice that using augmentHome=false can mess up the system because it is true elsewhere.
* @param path The path which is used to load modules
@@ -104,6 +77,19 @@ class CSwordBackend : public QObject, public sword::SWMgr {
*/
~CSwordBackend();
+ /** Creates and returns the instance. */
+ static inline CSwordBackend *createInstance() {
+ Q_ASSERT(m_instance == 0);
+ m_instance = new CSwordBackend();
+ return m_instance;
+ }
+
+ /** Returns the singleton instance, creating it if one does not exist. */
+ static inline CSwordBackend *instance() { return m_instance; }
+
+ /** Destroys the singleton instance, if one exists. */
+ static void destroyInstance() { delete m_instance; }
+
/**
* This function returns the list of available modules managed by this
* backend. You have to call initModules() first; This method is
@@ -134,8 +120,8 @@ class CSwordBackend : public QObject, public sword::SWMgr {
* @param enable If this is true the option will be enabled, otherwise it will be disabled.
*/
void setOption( const CSwordModuleInfo::FilterTypes type, const int state );
- /** */
- void setFilterOptions( const CSwordBackend::FilterOptions options );
+
+ void setFilterOptions(const FilterOptions &options);
/**
* Sets the language for the international booknames of Sword.
* @param langName The abbreviation string which should be used for the Sword backend
@@ -147,12 +133,7 @@ class CSwordBackend : public QObject, public sword::SWMgr {
* @return pointer to the desired module; null if no module has the specified description
*/
CSwordModuleInfo* findModuleByDescription(const QString& description);
- /**
- * This function searches for a module with the specified description
- * @param description The description of the desired module
- * @return pointer to the desired module; null if no module has the specified description
- */
- const QString findModuleNameByDescription(const QString& description);
+
/**
* This function searches for a module with the specified name
* @param name The name of the desired module
@@ -165,21 +146,12 @@ class CSwordBackend : public QObject, public sword::SWMgr {
* @return pointer to the desired module; null if no module has the specified name
*/
CSwordModuleInfo* findSwordModuleByPointer(const sword::SWModule* const swmodule);
- /**
- * This function searches for a module which is the same as the passed module.
- * @param module The module which should be used for searching the new one. May be child of a different backend.
- * @return Pointer to the desired module; null if no module has the specified name
- */
- CSwordModuleInfo* findModuleByPointer(const CSwordModuleInfo* const module);
+
/**
* @return Our global config object which contains the configs of all modules merged together.
*/
inline sword::SWConfig* getConfig() const;
- /**
- * Tries to find the config object for the module. The second paramter will be the found config.
- * @return True if the config was found, false if not. If false is returned the moduleConfig object is in undefined/unknwon state.
- */
- bool moduleConfig(const QString& module, sword::SWConfig& moduleConfig );
+
/**
* Returns the text used for the option given as parameter.
* @param The paramter enum
@@ -195,11 +167,7 @@ class CSwordBackend : public QObject, public sword::SWMgr {
* @param The translated option name
*/
static const QString translatedOptionName(const CSwordModuleInfo::FilterTypes option );
- /**
- * Returns the version of the Sword library.
- * @return The version used by this backend
- */
- inline const sword::SWVersion Version();
+
/**
* Reload all Sword modules.
*/
@@ -212,22 +180,39 @@ class CSwordBackend : public QObject, public sword::SWMgr {
QList<CSwordModuleInfo*> takeModulesFromList(QStringList names);
/**
- * Returns a list of pointers to modules, created from a list of module names.
+ \returns a list of pointers to modules, created from a list of module
+ names.
+ */
+ QList<CSwordModuleInfo*> getPointerList(const QStringList &names);
+
+ /**
+ \returns a list of pointers to const modules, created from a list of
+ module names.
*/
- QList<CSwordModuleInfo*> getPointerList(QStringList names);
+ QList<const CSwordModuleInfo*> getConstPointerList(const QStringList &names);
/** Sword prefix list.
* @return A list of all known Sword prefix dirs
*/
QStringList swordDirList() const;
+ /**
+ * delete all orphaned indexes (no module present) if autoDeleteOrphanedIndices is true
+ * delete all indices of modules where hasIndex() returns false (because of wrong index version etc.)
+ */
+ void deleteOrphanedIndices();
signals:
void sigSwordSetupChanged(CSwordBackend::SetupChangedReason reason);
protected:
/**
- * Adds a render filter to the module.
- * This is used to apply our own render filters to our modules instead of the sword filters
+ Creates the SWModule objects using SWMgr's methods, it adds the
+ necessary filters for the module format.
+ */
+ CSwordBackend();
+
+ /**
+ * Reimplemented from sword::SWMgr.
*/
void AddRenderFilters(sword::SWModule *module, sword::ConfigEntMap &section);
/**
@@ -239,32 +224,27 @@ class CSwordBackend : public QObject, public sword::SWMgr {
QString getPrivateSwordConfigPath() const;
QString getPrivateSwordConfigFile() const;
- private:
- // Filters
- struct Filters {
- sword::SWFilter* gbf;
- sword::SWFilter* plain;
- sword::SWFilter* thml;
- sword::SWFilter* osis;
- sword::SWFilter* tei;
- } m_filters;
-
- struct Displays {
- Rendering::CChapterDisplay* chapter;
- Rendering::CEntryDisplay* entry;
- Rendering::CBookDisplay* book;
- } m_displays;
+ private: /* Fields: */
+ // Filters:
+ Filters::GbfToHtml m_gbfFilter;
+ Filters::OsisToHtml m_osisFilter;
+ Filters::PlainToHtml m_plainFilter;
+ Filters::TeiToHtml m_teiFilter;
+ Filters::ThmlToHtml m_thmlFilter;
+
+ // Displays:
+ Rendering::CChapterDisplay m_chapterDisplay;
+ Rendering::CEntryDisplay m_entryDisplay;
+ Rendering::CBookDisplay m_bookDisplay;
BtBookshelfModel m_dataModel;
- QMap<QString, QString> m_moduleDescriptionMap;
-};
-Q_DECLARE_METATYPE(CSwordBackend::FilterOptions)
-Q_DECLARE_METATYPE(CSwordBackend::DisplayOptions)
+ static CSwordBackend *m_instance;
+};
/**Returns The list of modules managed by this backend*/
inline const QList<CSwordModuleInfo*> &CSwordBackend::moduleList() const {
- return m_dataModel.modules();
+ return m_dataModel.moduleList();
}
inline BtBookshelfModel *CSwordBackend::model() {
@@ -276,9 +256,4 @@ inline sword::SWConfig* CSwordBackend::getConfig() const {
return config;
}
-/** Returns the version of the Sword library. */
-inline const sword::SWVersion CSwordBackend::Version() {
- return sword::SWVersion::currentVersion;
-}
-
#endif