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