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