BibleTime
Classes | Public Types | Signals | Public Member Functions | Static Public Member Functions | Private Types | Private Attributes | Static Private Attributes | List of all members
CSwordBackend Class Reference

The backend layer main class, a backend implementation of Sword. More...

#include <cswordbackend.h>

Inheritance diagram for CSwordBackend:

Classes

struct  Private
 

Public Types

enum  LoadError { NoSwordConfig = -1 , NoError = 0 , NoModules = 1 }
 The error codes which may be returned by the Load() call. More...
 

Signals

void sigSwordSetupChanged ()
 

Public Member Functions

std::shared_ptr< AvailableLanguagesCacheContainer const > availableLanguages () noexcept
 
QString booknameLanguage () const
 
 CSwordBackend ()
 Creates the regular CSwordBackend instance. More...
 
 CSwordBackend (const QString &path, const bool augmentHome=true)
 
void deleteOrphanedIndices ()
 
CSwordModuleInfofindFirstAvailableModule (CSwordModuleInfo::ModuleType type)
 
CSwordModuleInfofindModuleByName (const QString &name) const
 Searches for a module with the given name. More...
 
CSwordModuleInfofindSwordModuleByPointer (const sword::SWModule *const swmodule) const
 Searches for a module with the given sword module as module(). More...
 
sword::SWConfig * getConfig () const
 
BtConstModuleList getConstPointerList (const QStringList &names) const
 
QList< CSwordModuleInfo * > getPointerList (const QStringList &names) const
 
CSwordBackend::LoadError initModules ()
 Initializes the Sword modules. More...
 
std::shared_ptr< BtBookshelfModelmodel ()
 
QList< CSwordModuleInfo * > const & moduleList () const
 
QString prefixPath () const
 
sword::SWMgr & raw ()
 
void reloadModules ()
 Reloads all Sword modules. More...
 
void setBooknameLanguage (QString const &langName)
 Sets the language for the international booknames of Sword. More...
 
void setFilterOptions (const FilterOptions &options)
 
void setOption (CSwordModuleInfo::FilterOption const &type, const int state)
 Sets the state of the given filter option. More...
 
void shutdownModules ()
 Deinitializes and frees the modules. More...
 
QStringList swordDirList () const
 Sword prefix list. More...
 
void uninstallModules (BtConstModuleSet const &modules)
 Uninstalls the given modules. More...
 
 ~CSwordBackend () override
 

Static Public Member Functions

static CSwordBackendinstance () noexcept
 

Private Types

using AvailableLanguagesCacheContainer = std::set< std::shared_ptr< Language const > >
 

Private Attributes

std::shared_ptr< AvailableLanguagesCacheContainer const > m_availableLanguagesCache
 
std::shared_ptr< BtBookshelfModel > const m_dataModel
 
CSwordBackend::Private m_manager
 

Static Private Attributes

static CSwordBackendm_instance = nullptr
 

Detailed Description

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.

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 managing modules separate backends are created.

Definition at line 56 of file cswordbackend.h.

Member Typedef Documentation

◆ AvailableLanguagesCacheContainer

using CSwordBackend::AvailableLanguagesCacheContainer = std::set<std::shared_ptr<Language const> >
private

Definition at line 74 of file cswordbackend.h.

Member Enumeration Documentation

◆ LoadError

The error codes which may be returned by the Load() call.

Note
These values exist to cast from the char return of SWMgr::Load().
Enumerator
NoSwordConfig 
NoError 
NoModules 

Definition at line 66 of file cswordbackend.h.

Constructor & Destructor Documentation

◆ CSwordBackend() [1/2]

CSwordBackend::CSwordBackend ( )

Creates the regular CSwordBackend instance.

Warning
Should only be called once.

Definition at line 58 of file cswordbackend.cpp.

References booknameLanguage(), BT_ASSERT, BT_CONNECT, btConfig(), deleteOrphanedIndices(), initModules(), m_availableLanguagesCache, m_dataModel, m_instance, and setBooknameLanguage().

◆ CSwordBackend() [2/2]

CSwordBackend::CSwordBackend ( const QString &  path,
const bool  augmentHome = true 
)
Note
Used by BtInstallBackend only.
Using augmentHome=false can mess up the system because it is true elsewhere.
Parameters
[in]pathThe path which is used to load modules.
[in]augmentHomeWhether $HOME/.sword/ modules should be augmented with the other modules.

Definition at line 83 of file cswordbackend.cpp.

◆ ~CSwordBackend()

CSwordBackend::~CSwordBackend ( )
override

Definition at line 90 of file cswordbackend.cpp.

References shutdownModules().

Member Function Documentation

◆ availableLanguages()

std::shared_ptr< CSwordBackend::AvailableLanguagesCacheContainer const > CSwordBackend::availableLanguages ( )
noexcept

◆ booknameLanguage()

QString CSwordBackend::booknameLanguage ( ) const
Returns
the language for the international booknames of Sword.

Definition at line 338 of file cswordbackend.cpp.

References BtLocaleMgr::defaultLocaleName().

Referenced by CSwordBibleModuleInfo::books(), and CSwordBackend().

◆ deleteOrphanedIndices()

void CSwordBackend::deleteOrphanedIndices ( )

Deletes all indices of modules where hasIndex() returns false (because of wrong index version etc.) and deletes all orphaned indexes (no module present) if autoDeleteOrphanedIndices is true.

Definition at line 478 of file cswordbackend.cpp.

References btConfig(), CSwordModuleInfo::deleteIndexForModule(), findModuleByName(), and CSwordModuleInfo::getGlobalBaseIndexLocation().

Referenced by CSwordBackend().

◆ findFirstAvailableModule()

CSwordModuleInfo * CSwordBackend::findFirstAvailableModule ( CSwordModuleInfo::ModuleType  type)

◆ findModuleByName()

CSwordModuleInfo * CSwordBackend::findModuleByName ( const QString &  name) const

◆ findSwordModuleByPointer()

CSwordModuleInfo * CSwordBackend::findSwordModuleByPointer ( const sword::SWModule *const  swmodule) const

Searches for a module with the given sword module as module().

Parameters
[in]swmoduleThe SWModule of the desired module.
Returns
a pointer to the desired module or NULL if not found.

Definition at line 331 of file cswordbackend.cpp.

References m_dataModel.

Referenced by anonymous_namespace{osistohtml.cpp}::renderReference().

◆ getConfig()

sword::SWConfig* CSwordBackend::getConfig ( ) const
inline
Returns
The global config object containing the configs of all modules merged together.

Definition at line 167 of file cswordbackend.h.

References m_manager.

Referenced by CSwordModuleInfo::isEncrypted().

◆ getConstPointerList()

BtConstModuleList CSwordBackend::getConstPointerList ( const QStringList &  names) const
Parameters
[in]namesThe names of the modules to return.
Returns
a list of pointers to const modules, created from a list of module names.

Definition at line 185 of file cswordbackend.cpp.

References findModuleByName().

◆ getPointerList()

QList< CSwordModuleInfo * > CSwordBackend::getPointerList ( const QStringList &  names) const
Parameters
[in]namesThe names of the modules to return.
Returns
a list of pointers to modules, created from a list of module names.

Definition at line 177 of file cswordbackend.cpp.

References findModuleByName().

◆ initModules()

CSwordBackend::LoadError CSwordBackend::initModules ( )

Initializes the Sword modules.

Returns
whether the initializiation was successful.
Todo:
Refactor data model to use shared_ptr to contain works

Definition at line 193 of file cswordbackend.cpp.

References BT_ASSERT, btConfig(), m_dataModel, m_manager, shutdownModules(), and sigSwordSetupChanged().

Referenced by CSwordBackend(), and reloadModules().

◆ instance()

static CSwordBackend& CSwordBackend::instance ( )
inlinestaticnoexcept
Returns
the singleton instance.

Definition at line 98 of file cswordbackend.h.

References BT_ASSERT, and m_instance.

Referenced by Search::CModuleResultView::activeModule(), BtBookshelfDockWidget::BtBookshelfDockWidget(), BtBookshelfWorksPage::BtBookshelfWorksPage(), BtFontSettingsPage::BtFontSettingsPage(), BtIndexDialog::BtIndexDialog(), BtModelViewReadDisplay::BtModelViewReadDisplay(), BtOpenWorkAction::BtOpenWorkAction(), BtSearchModuleChooserDialog::BtSearchModuleChooserDialog(), CDisplayWindow::CDisplayWindow(), BtIndexDialog::createIndices(), BtInstallPageModel::data(), anonymous_namespace{btinforendering.cpp}::decodeCrossReference(), anonymous_namespace{btinforendering.cpp}::decodeFootnote(), ReferenceManager::decodeHyperlink(), anonymous_namespace{btinforendering.cpp}::decodeMorph(), anonymous_namespace{btinforendering.cpp}::decodeSwordReference(), BtIndexDialog::deleteIndices(), BtQuickWidget::dragEnterEvent(), CBookmarkIndex::dropEvent(), Search::CModuleResultView::executed(), CDisplayTemplateMgr::fillTemplate(), anonymous_namespace{btbookshelfworkspage.cpp}::filter(), BtConfig::getDefaultSwordModuleByType(), anonymous_namespace{btinforendering.cpp}::getFirstAvailableStrongsModule(), BtQmlInterface::getFontsFromSettings(), CSwordModuleInfo::getFormattedConfigEntry(), BtQmlInterface::getRawText(), Filters::ThmlToHtml::handleToken(), Search::BtSearchOptionsArea::initConnections(), Search::CRangeChooserDialog::initConnections(), BtBookshelfRemoveFinalPage::initializePage(), CDisplayWindow::lookupKey(), main(), BtQmlInterface::moduleIsWritable(), BibleTime::moduleUnlock(), BtTextBrowser::mouseMoveEvent(), BtConfig::parseVerseListWithModules(), ReferenceManager::parseVerseReference(), BtIndexDialog::populateModuleList(), Filters::GbfToHtml::processText(), Filters::ThmlToHtml::processText(), CDisplayWindow::reload(), CBibleReadWindow::reload(), CCommentaryReadWindow::reload(), BtModuleTextModel::reloadModules(), BibleTime::reloadProfile(), BtInstallThread::removeModule(), Rendering::CTextRendering::renderKeyTree(), anonymous_namespace{osistohtml.cpp}::renderReference(), Filters::TeiToHtml::renderReference(), Filters::TeiToHtml::renderTargetReference(), CSwordModuleSearch::search(), BtBookshelfWorksPage::slotInitPathCombo(), BibleTime::slotSettingsOptions(), BtBookshelfInstallFinalPage::slotThreadFinished(), anonymous_namespace{btmodulechoosermenu.cpp}::SortModel::SortModel(), BtModelViewReadDisplay::text(), BtBookshelfTaskPage::timeToUpdate(), and anonymous_namespace{btbookmarksmodel.cpp}::BookmarkItem::toolTip().

◆ model()

std::shared_ptr<BtBookshelfModel> CSwordBackend::model ( )
inline

Definition at line 111 of file cswordbackend.h.

References m_dataModel.

Referenced by availableLanguages().

◆ moduleList()

QList<CSwordModuleInfo*> const& CSwordBackend::moduleList ( ) const
inline
Warning
You have to call initModules() first.
Note
This method is equivalent to model()->modules().
Returns
The list of modules managed by this backend.

Definition at line 108 of file cswordbackend.h.

References m_dataModel.

Referenced by findFirstAvailableModule(), and main().

◆ prefixPath()

QString CSwordBackend::prefixPath ( ) const
inline

◆ raw()

sword::SWMgr& CSwordBackend::raw ( )
inline

Definition at line 210 of file cswordbackend.h.

References m_manager.

Referenced by CSwordModuleInfo::unlock().

◆ reloadModules()

void CSwordBackend::reloadModules ( )

◆ setBooknameLanguage()

void CSwordBackend::setBooknameLanguage ( QString const &  langName)

Sets the language for the international booknames of Sword.

Parameters
[in]langNameThe abbreviation string which should be used for the Sword backend.

Definition at line 341 of file cswordbackend.cpp.

References BtLocaleMgr::defaultLocaleName(), m_dataModel, and BtLocaleMgr::setDefaultLocaleName().

Referenced by CSwordBackend(), and BibleTime::slotSettingsOptions().

◆ setFilterOptions()

void CSwordBackend::setFilterOptions ( const FilterOptions options)

◆ setOption()

void CSwordBackend::setOption ( CSwordModuleInfo::FilterOption const &  type,
const int  state 
)

Sets the state of the given filter option.

Parameters
[in]typeThe filter type whose state to set.
[in]stateThe new filter option state.

Definition at line 304 of file cswordbackend.cpp.

References m_manager, CSwordModuleInfo::FilterOption::optionName, and CSwordModuleInfo::FilterOption::valueToString.

Referenced by CSwordModuleInfo::buildIndex(), setFilterOptions(), and CSwordModuleInfo::setImportantFilterOptions().

◆ shutdownModules()

void CSwordBackend::shutdownModules ( )

Deinitializes and frees the modules.

Returns
whether the method succeeded.

Definition at line 282 of file cswordbackend.cpp.

References m_dataModel, m_manager, and CSwordBackend::Private::shutdownModules().

Referenced by initModules(), reloadModules(), and ~CSwordBackend().

◆ sigSwordSetupChanged

void CSwordBackend::sigSwordSetupChanged ( )
signal

◆ swordDirList()

QStringList CSwordBackend::swordDirList ( ) const

Sword prefix list.

Returns
A list of all known Sword prefix dirs

Definition at line 383 of file cswordbackend.cpp.

References util::directory::getUserHomeSwordDir(), and m_manager.

◆ uninstallModules()

void CSwordBackend::uninstallModules ( BtConstModuleSet const &  modules)

Uninstalls the given modules.

Parameters
[in]modulesThe modules to uninstall.

Definition at line 134 of file cswordbackend.cpp.

References CSwordModuleInfo::AbsoluteDataPath, CSwordModuleInfo::DataPath, m_dataModel, prefixPath(), and sigSwordSetupChanged().

Referenced by BtBookshelfRemoveFinalPage::initializePage().

Member Data Documentation

◆ m_availableLanguagesCache

std::shared_ptr<AvailableLanguagesCacheContainer const> CSwordBackend::m_availableLanguagesCache
private

Definition at line 241 of file cswordbackend.h.

Referenced by availableLanguages(), and CSwordBackend().

◆ m_dataModel

std::shared_ptr<BtBookshelfModel> const CSwordBackend::m_dataModel
private

◆ m_instance

CSwordBackend * CSwordBackend::m_instance = nullptr
staticprivate

Definition at line 243 of file cswordbackend.h.

Referenced by CSwordBackend(), and instance().

◆ m_manager

CSwordBackend::Private CSwordBackend::m_manager
private

The documentation for this class was generated from the following files: