BibleTime
cswordbackend.h
Go to the documentation of this file.
1/*********
2*
3* In the name of the Father, and of the Son, and of the Holy Spirit.
4*
5* This file is part of BibleTime's source code, https://bibletime.info/
6*
7* Copyright 1999-2025 by the BibleTime developers.
8* The BibleTime source code is licensed under the GNU General Public License
9* version 2.0.
10*
11**********/
12
13#pragma once
14
15#include <memory>
16#include <QObject>
17#include <QString>
18#include <QStringList>
19#include <set>
20#include "../../util/btassert.h"
21#include "../bookshelfmodel/btbookshelfmodel.h"
22#include "../btglobal.h"
23#include "../drivers/cswordmoduleinfo.h"
24#include "../drivers/btconstmoduleset.h"
25#include "../filters/gbftohtml.h"
26#include "../filters/osistohtml.h"
27#include "../filters/plaintohtml.h"
28#include "../filters/teitohtml.h"
29#include "../filters/thmltohtml.h"
30#include "../language.h"
31
32// Sword includes:
33#pragma GCC diagnostic push
34#pragma GCC diagnostic ignored "-Wextra-semi"
35#pragma GCC diagnostic ignored "-Wunused-parameter"
36#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
37#include <swmgr.h>
38#pragma GCC diagnostic pop
39
40namespace sword {
41class Module;
42class Config;
43} // namespace sword
44
45/**
46 \brief The backend layer main class, a backend implementation of Sword.
47
48 This is the implementation of CBackend for Sword. It's additionally derived
49 from SWMgr to provide functions of Sword.
50
51 \note Mostly, only one instance of this class is used. This instance is
52 created by BibleTime::initBackends() and is destroyed by
53 BibleTimeApp::~BibleTimeApp(). Only when \ref BackendNotSingleton
54 "managing modules" separate backends are created.
55*/
56class CSwordBackend: public QObject {
57
58 Q_OBJECT
59
60public: // types:
61
62 /**
63 \brief The error codes which may be returned by the \ref Load() call.
64 \note These values exist to cast from the char return of SWMgr::Load().
65 */
71
72private: // types:
73
75 std::set<std::shared_ptr<Language const>>;
76
77public: // methods:
78
79 /**
80 \brief Creates the regular CSwordBackend instance.
81 \warning Should only be called once.
82 */
84
85 /**
86 \note Used by BtInstallBackend only.
87 \note Using augmentHome=false can mess up the system because it is true
88 elsewhere.
89 \param[in] path The path which is used to load modules.
90 \param[in] augmentHome Whether $HOME/.sword/ modules should be augmented
91 with the other modules.
92 */
93 CSwordBackend(const QString & path, const bool augmentHome = true);
94
95 ~CSwordBackend() override;
96
97 /** \returns the singleton instance. */
98 static CSwordBackend & instance() noexcept {
100 return *m_instance;
101 }
102
103 /**
104 \warning You have to call initModules() first.
105 \note This method is equivalent to model()->modules().
106 \returns The list of modules managed by this backend.
107 */
108 QList<CSwordModuleInfo*> const & moduleList() const
109 { return m_dataModel->moduleList(); }
110
111 std::shared_ptr<BtBookshelfModel> model() { return m_dataModel; }
112
114
115 std::shared_ptr<AvailableLanguagesCacheContainer const>
116 availableLanguages() noexcept;
117
118 /**
119 \brief Initializes the Sword modules.
120 \returns whether the initializiation was successful.
121 */
123
124 /**
125 \brief Deinitializes and frees the modules.
126 \returns whether the method succeeded.
127 */
128 void shutdownModules();
129
130 /**
131 \brief Sets the state of the given filter option.
132 \param[in] type The filter type whose state to set.
133 \param[in] state The new filter option state.
134 */
135 void setOption(CSwordModuleInfo::FilterOption const & type, const int state);
136
137 void setFilterOptions(const FilterOptions & options);
138
139 /** \returns the language for the international booknames of Sword. */
140 QString booknameLanguage() const;
141
142 /**
143 \brief Sets the language for the international booknames of Sword.
144 \param[in] langName The abbreviation string which should be used for the
145 Sword backend.
146 */
147 void setBooknameLanguage(QString const & langName);
148
149 /**
150 \brief Searches for a module with the given name.
151 \param[in] name The name of the desired module.
152 \returns a pointer to the desired module or NULL if not found.
153 */
154 CSwordModuleInfo * findModuleByName(const QString & name) const;
155
156 /**
157 \brief Searches for a module with the given sword module as module().
158 \param[in] swmodule The SWModule of the desired module.
159 \returns a pointer to the desired module or NULL if not found.
160 */
161 CSwordModuleInfo * findSwordModuleByPointer(const sword::SWModule * const swmodule) const;
162
163 /**
164 \returns The global config object containing the configs of all modules
165 merged together.
166 */
167 sword::SWConfig * getConfig() const { return m_manager.config; }
168
169 /**
170 \brief Reloads all Sword modules.
171 */
172 void reloadModules();
173
174 /**
175 \brief Uninstalls the given modules.
176 \param[in] modules The modules to uninstall.
177 */
178 void uninstallModules(BtConstModuleSet const & modules);
179
180 /**
181 \param[in] names The names of the modules to return.
182 \returns a list of pointers to modules, created from a list of module
183 names.
184 */
185 QList<CSwordModuleInfo*> getPointerList(const QStringList & names) const;
186
187 /**
188 \param[in] names The names of the modules to return.
189 \returns a list of pointers to const modules, created from a list of
190 module names.
191 */
192 BtConstModuleList getConstPointerList(const QStringList & names) const;
193
194 /**
195 \brief Sword prefix list.
196 \returns A list of all known Sword prefix dirs
197 */
198 QStringList swordDirList() const;
199
200 /**
201 Deletes all indices of modules where hasIndex() returns false (because of
202 wrong index version etc.) and deletes all orphaned indexes (no module
203 present) if autoDeleteOrphanedIndices is true.
204 */
206
207 QString prefixPath() const
208 { return QString::fromLatin1(m_manager.prefixPath); }
209
210 sword::SWMgr & raw() { return m_manager; }
211
212Q_SIGNALS:
213
215
216private: // fields:
217
218 struct Private: public sword::SWMgr {
219
220 // Methods:
221
222 using sword::SWMgr::SWMgr;
223
224 void shutdownModules();
225 void reloadConfig();
226 void addRenderFilters(sword::SWModule * module,
227 sword::ConfigEntMap & section) override;
228
229 // Fields:
230
236
238
239 std::shared_ptr<BtBookshelfModel> const m_dataModel;
240 std::shared_ptr<AvailableLanguagesCacheContainer const>
242
244
245};
#define BT_ASSERT(...)
Definition btassert.h:17
QList< CSwordModuleInfo const * > BtConstModuleList
The backend layer main class, a backend implementation of Sword.
void shutdownModules()
Deinitializes and frees the modules.
void setOption(CSwordModuleInfo::FilterOption const &type, const int state)
Sets the state of the given filter option.
CSwordBackend::LoadError initModules()
Initializes the Sword modules.
QStringList swordDirList() const
Sword prefix list.
std::set< std::shared_ptr< Language const > > AvailableLanguagesCacheContainer
static CSwordBackend * m_instance
std::shared_ptr< AvailableLanguagesCacheContainer const > availableLanguages() noexcept
sword::SWMgr & raw()
void reloadModules()
Reloads all Sword modules.
std::shared_ptr< BtBookshelfModel > const m_dataModel
QList< CSwordModuleInfo * > getPointerList(const QStringList &names) const
std::shared_ptr< BtBookshelfModel > model()
CSwordModuleInfo * findFirstAvailableModule(CSwordModuleInfo::ModuleType type)
CSwordBackend::Private m_manager
void deleteOrphanedIndices()
CSwordModuleInfo * findModuleByName(const QString &name) const
Searches for a module with the given name.
QString prefixPath() const
void uninstallModules(BtConstModuleSet const &modules)
Uninstalls the given modules.
void sigSwordSetupChanged()
CSwordBackend()
Creates the regular CSwordBackend instance.
BtConstModuleList getConstPointerList(const QStringList &names) const
LoadError
The error codes which may be returned by the Load() call.
static CSwordBackend & instance() noexcept
QList< CSwordModuleInfo * > const & moduleList() const
void setFilterOptions(const FilterOptions &options)
CSwordModuleInfo * findSwordModuleByPointer(const sword::SWModule *const swmodule) const
Searches for a module with the given sword module as module().
~CSwordBackend() override
void setBooknameLanguage(QString const &langName)
Sets the language for the international booknames of Sword.
std::shared_ptr< AvailableLanguagesCacheContainer const > m_availableLanguagesCache
sword::SWConfig * getConfig() const
QString booknameLanguage() const
GBF to HTML conversion filter.
Definition gbftohtml.h:43
OSIS to HTMl conversion filter.
Definition osistohtml.h:40
Plain text to HTML conversion filter.
Definition plaintohtml.h:33
TEI to HTML conversion filter.
Definition teitohtml.h:37
ThML to HTML conversion filter.
Definition thmltohtml.h:40
Filters::TeiToHtml m_teiFilter
Filters::ThmlToHtml m_thmlFilter
Filters::OsisToHtml m_osisFilter
Filters::GbfToHtml m_gbfFilter
void addRenderFilters(sword::SWModule *module, sword::ConfigEntMap &section) override
Filters::PlainToHtml m_plainFilter