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