BibleTime
Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
BtConfig Class Reference

#include <btconfig.h>

Inheritance diagram for BtConfig:

Public Types

using FontSettingsPair = QPair< bool, QFont >
 
using ShortcutsMap = QHash< QString, QList< QKeySequence > >
 
using StringMap = QMap< QString, QString >
 

Public Member Functions

QString addSession (const QString &name)
 Creates a new session with the given name. More...
 
QString booknameLanguage ()
 
QString const & currentSessionKey () const
 
QString currentSessionName () const
 
void deleteSearchScopesWithCurrentLocale ()
 
void deleteSession (const QString &key)
 Deletes the session with the given key. More...
 
QFont const & getDefaultFont () const
 
CSwordModuleInfogetDefaultSwordModuleByType (const QString &moduleType)
 Returns default sword module info class for a given module type. More...
 
DisplayOptions getDisplayOptions () const
 
FilterOptions getFilterOptions () const
 
FontSettingsPair getFontForLanguage (Language const &language)
 Get font for a language. More...
 
QString getModuleEncryptionKey (const QString &name)
 Function to get a module decryption key. More...
 
StringMap getSearchScopesForCurrentLocale (const QStringList &scopeModules)
 
ShortcutsMap getShortcuts (QString const &shortcutGroup)
 Gets the shortcuts for the given group. More...
 
BtConfigCore session () const
 
QHash< QString, QString > sessionNames () const
 
void setCurrentSession (const QString &key)
 Notifies the configuration system that the session settings should be read from and saved to the given session. More...
 
void setDefaultSwordModuleByType (const QString &moduleType, const CSwordModuleInfo *const module)
 Sets the default sword module for a module type. More...
 
void setFontForLanguage (Language const &language, FontSettingsPair const &fontSettings)
 Set font for a language. More...
 
void setModuleEncryptionKey (const QString &name, const QString &key)
 Function to set a module decryption key. More...
 
void setSearchScopesWithCurrentLocale (const QStringList &scopeModules, StringMap searchScopes)
 
void setShortcuts (QString const &shortcutGroup, ShortcutsMap const &shortcuts)
 Sets the shortcuts for the given group. More...
 
- Public Member Functions inherited from BtConfigCore
 BtConfigCore (BtConfigCore &&)=default
 
 BtConfigCore (BtConfigCore const &)=default
 
QStringList childGroups () const
 
QStringList childKeys () const
 
template<typename Prefix >
BtConfigCore group (Prefix &&prefix) &&
 
template<typename Prefix >
BtConfigCore group (Prefix &&prefix) const &
 
BtConfigCoreoperator= (BtConfigCore &&)=default
 
BtConfigCoreoperator= (BtConfigCore const &)=default
 
QVariant qVariantValue (QString const &key, QVariant const &defaultValue=QVariant()) const
 Returns the settings value for the given global key as a QVariant. More...
 
void remove (QString const &key)
 removes a key (and its children) from the current group. More...
 
template<typename T >
void setValue (QString const &key, T const &value)
 Sets a value for a key. More...
 
void sync ()
 Synchronizes the configuration to disk. More...
 
template<typename T >
T value (QString const &key, T const &defaultValue=T()) const
 Returns the settings value for the given global key. More...
 
 ~BtConfigCore ()
 

Static Public Member Functions

static BtConfiggetInstance ()
 
static DisplayOptions loadDisplayOptionsFromGroup (BtConfigCore const &group)
 
static FilterOptions loadFilterOptionsFromGroup (BtConfigCore const &group)
 
static sword::ListKey parseVerseListWithModules (const QString &data, const QStringList &scopeModules)
 
static void storeDisplayOptionsToGroup (DisplayOptions const &options, BtConfigCore &group)
 Saves the current display options. More...
 
static void storeFilterOptionsToGroup (FilterOptions const &options, BtConfigCore &group)
 Saves the current filter options. More...
 

Private Types

enum  InitState { INIT_NEED_UNIMPLEMENTED_BACKWARD_MIGRATE = -2 , INIT_OK = 0 , INIT_NEED_UNIMPLEMENTED_FORWARD_MIGRATE = 2 }
 

Private Member Functions

 BtConfig (const QString &settingsFile)
 

Static Private Member Functions

static void destroyInstance ()
 
static void forceMigrate ()
 
static InitState initBtConfig ()
 

Private Attributes

QString m_currentSessionKey
 
QFont m_defaultFont
 default font used when no special one is set More...
 
QHash< Language const *, FontSettingsPairm_fontCache
 a cache for the fonts saved in the configuration file for speed More...
 
QHash< QString, QString > m_sessionNames
 

Static Private Attributes

static StringMap m_defaultSearchScopes
 
static BtConfigm_instance = nullptr
 singleton instance More...
 

Friends

class BibleTimeApp
 

Detailed Description

Definition at line 35 of file btconfig.h.

Member Typedef Documentation

◆ FontSettingsPair

using BtConfig::FontSettingsPair = QPair<bool, QFont>

The first parameter indicates whether the custom font should be used or not. The second parameter is the custom font that has been set.

Definition at line 47 of file btconfig.h.

◆ ShortcutsMap

using BtConfig::ShortcutsMap = QHash<QString, QList<QKeySequence> >

Definition at line 49 of file btconfig.h.

◆ StringMap

using BtConfig::StringMap = QMap<QString, QString>

Definition at line 48 of file btconfig.h.

Member Enumeration Documentation

◆ InitState

enum BtConfig::InitState
private
Enumerator
INIT_NEED_UNIMPLEMENTED_BACKWARD_MIGRATE 
INIT_OK 
INIT_NEED_UNIMPLEMENTED_FORWARD_MIGRATE 

Definition at line 53 of file btconfig.h.

Constructor & Destructor Documentation

◆ BtConfig()

BtConfig::BtConfig ( const QString &  settingsFile)
explicitprivate

Member Function Documentation

◆ addSession()

QString BtConfig::addSession ( const QString &  name)

Creates a new session with the given name.

Precondition
The given name must not be an empty string.
Parameters
[in]namethe name of the session
Returns
the key of the created session.

Definition at line 177 of file btconfig.cpp.

References BT_ASSERT, anonymous_namespace{btconfig.cpp}::KEY_SESSION_NAME, m_sessionNames, and BtConfigCore::setValue().

Referenced by BibleTime::saveToNewProfile().

◆ booknameLanguage()

QString BtConfig::booknameLanguage ( )
Returns
the configured language code for book names.

Definition at line 473 of file btconfig.cpp.

References r(), and BtConfigCore::setValue().

Referenced by CDisplaySettingsPage::bookNameAbbreviationsTryVector().

◆ currentSessionKey()

QString const& BtConfig::currentSessionKey ( ) const
inline
Returns
the key of the current session.

Definition at line 66 of file btconfig.h.

References m_currentSessionKey.

Referenced by BibleTime::refreshProfileMenus().

◆ currentSessionName()

QString BtConfig::currentSessionName ( ) const
inline
Returns
the name of the current session.

Definition at line 71 of file btconfig.h.

References BT_ASSERT, m_currentSessionKey, and m_sessionNames.

◆ deleteSearchScopesWithCurrentLocale()

void BtConfig::deleteSearchScopesWithCurrentLocale ( )

Deletes the searchScopes given in the current locale.

Definition at line 499 of file btconfig.cpp.

References BtConfigCore::remove().

Referenced by Search::CRangeChooserDialog::initConnections().

◆ deleteSession()

void BtConfig::deleteSession ( const QString &  key)

Deletes the session with the given key.

Precondition
The session with the given key must exist.
The session with the given key must not be the current session.
Parameters
[in]keythe key of the session to delete.
Postcondition
The session with the given key and its settings are deleted.
Returns
whether deleting the session was successful.

Definition at line 205 of file btconfig.cpp.

References BT_ASSERT, anonymous_namespace{btconfig.cpp}::GROUP_SESSIONS_PREFIX, m_currentSessionKey, m_sessionNames, and BtConfigCore::remove().

Referenced by BibleTime::deleteProfile().

◆ destroyInstance()

void BtConfig::destroyInstance ( )
staticprivate

Definition at line 216 of file btconfig.cpp.

References m_instance.

Referenced by BibleTimeApp::~BibleTimeApp().

◆ forceMigrate()

void BtConfig::forceMigrate ( )
staticprivate

◆ getDefaultFont()

QFont const& BtConfig::getDefaultFont ( ) const
inline

Returns a default font that is suitable for the current language.

Returns
QFont suitable for current language.

Definition at line 192 of file btconfig.h.

References m_defaultFont.

Referenced by CDisplayTemplateMgr::fillTemplate(), and getFontForLanguage().

◆ getDefaultSwordModuleByType()

CSwordModuleInfo * BtConfig::getDefaultSwordModuleByType ( const QString &  moduleType)

Returns default sword module info class for a given module type.

This is basically a convenience function for getting the respective "settings/defaults/ *" variable and searching that module manually. If module is not installed 0 will be returned.

Parameters
[in]moduleTypemodule type to return the default sword module info for
Returns
sword module info pointer or 0

Definition at line 503 of file btconfig.cpp.

References CSwordBackend::findModuleByName(), and CSwordBackend::instance().

Referenced by anonymous_namespace{btinforendering.cpp}::decodeCrossReference(), ReferenceManager::decodeHyperlink(), anonymous_namespace{btinforendering.cpp}::decodeMorph(), anonymous_namespace{btinforendering.cpp}::getStrongsModule(), Filters::ThmlToHtml::handleToken(), BibleTime::processCommandline(), anonymous_namespace{osistohtml.cpp}::renderReference(), Filters::TeiToHtml::renderReference(), and CDisplayWindow::setBibleReference().

◆ getDisplayOptions()

DisplayOptions BtConfig::getDisplayOptions ( ) const
inline

◆ getFilterOptions()

FilterOptions BtConfig::getFilterOptions ( ) const
inline

◆ getFontForLanguage()

BtConfig::FontSettingsPair BtConfig::getFontForLanguage ( Language const &  language)

Get font for a language.

Gets a FontSettingsPair for the language given. If no font has been saved a default font is returned.

Parameters
[in]languagepointer to a language to get the font for.
Returns
FontSettingsPair for given language
Todo:

Definition at line 364 of file btconfig.cpp.

References Language::abbrev(), BT_ASSERT, Language::englishName(), getDefaultFont(), m_fontCache, and BtConfigCore::qVariantValue().

Referenced by CBookKeyChooser::adjustFont(), BtFontSettingsPage::BtFontSettingsPage(), CDisplayTemplateMgr::fillTemplate(), and BtQmlInterface::getFontsFromSettings().

◆ getInstance()

BtConfig & BtConfig::getInstance ( )
static

Definition at line 164 of file btconfig.cpp.

References BT_ASSERT, and m_instance.

Referenced by btConfig().

◆ getModuleEncryptionKey()

QString BtConfig::getModuleEncryptionKey ( const QString &  name)

Function to get a module decryption key.

This helper function will retrieve a previously set module decryption key from the configuration. If the key is not set it will return a null string.

Parameters
[in]nameName of module to retrieve the key for
Returns
Decryption key as a string

Definition at line 228 of file btconfig.cpp.

References BT_ASSERT.

Referenced by CSwordModuleInfo::config().

◆ getSearchScopesForCurrentLocale()

BtConfig::StringMap BtConfig::getSearchScopesForCurrentLocale ( const QStringList &  scopeModules)
Todo:
: unit test these functions

Returns the searchScopes for the current locale.

This function retrieves the search scopes of the "properties/searchScopes" property and converts them to the current locale.

Returns
Search scopes in current locale.

Definition at line 412 of file btconfig.cpp.

References m_defaultSearchScopes, and parseVerseListWithModules().

Referenced by Search::CRangeChooserDialog::CRangeChooserDialog(), and Search::BtSearchOptionsArea::searchScope().

◆ getShortcuts()

BtConfig::ShortcutsMap BtConfig::getShortcuts ( QString const &  shortcutGroup)

Gets the shortcuts for the given group.

Returns a hash of shortcuts for strings for the respective shortcut group.

Parameters
[in]shortcutGroupThe group to retrieve shortcuts for.
Returns
Hash of strings and lists of shortcuts.

Definition at line 233 of file btconfig.cpp.

References BtConfigCore::group().

Referenced by BtActionCollection::readShortcuts().

◆ initBtConfig()

BtConfig::InitState BtConfig::initBtConfig ( )
staticprivate

◆ loadDisplayOptionsFromGroup()

DisplayOptions BtConfig::loadDisplayOptionsFromGroup ( BtConfigCore const &  group)
static
Returns
DisplayOptions structure containing display settings.

Definition at line 320 of file btconfig.cpp.

References BtConfigCore::group(), DisplayOptions::lineBreaks, and DisplayOptions::verseNumbers.

Referenced by CBibleReadWindow::applyProfileSettings(), and getDisplayOptions().

◆ loadFilterOptionsFromGroup()

FilterOptions BtConfig::loadFilterOptionsFromGroup ( BtConfigCore const &  group)
static

◆ parseVerseListWithModules()

sword::ListKey BtConfig::parseVerseListWithModules ( const QString &  data,
const QStringList &  scopeModules 
)
static

◆ session()

BtConfigCore BtConfig::session ( ) const

◆ sessionNames()

QHash<QString, QString> BtConfig::sessionNames ( ) const
inline
Returns
a hashmap with the keys and printable names of the sessions.

Definition at line 78 of file btconfig.h.

References m_sessionNames.

Referenced by BibleTime::refreshProfileMenus(), and BibleTime::saveToNewProfile().

◆ setCurrentSession()

void BtConfig::setCurrentSession ( const QString &  key)

Notifies the configuration system that the session settings should be read from and saved to the given session.

Precondition
The session with the given key must exist.
Parameters
[in]keythe key of the session to switch to.
Postcondition
the sessionValue() and value() methods will work with the settings of the given session.

Definition at line 169 of file btconfig.cpp.

References BT_ASSERT, anonymous_namespace{btconfig.cpp}::KEY_CURRENT_SESSION, m_currentSessionKey, m_sessionNames, and BtConfigCore::setValue().

Referenced by BibleTime::saveToNewProfile().

◆ setDefaultSwordModuleByType()

void BtConfig::setDefaultSwordModuleByType ( const QString &  moduleType,
const CSwordModuleInfo *const  module 
)

Sets the default sword module for a module type.

This is basically a convenience function for setting the "settings/defaults/ *" variables to the module->name() string manually. 0 is allowed as the module, then the default module will be unset.

Parameters
[in]moduleTypemodule type to set
[in]modulethe sword module info to set as default module

Definition at line 512 of file btconfig.cpp.

References CSwordModuleInfo::name(), and BtConfigCore::setValue().

◆ setFontForLanguage()

void BtConfig::setFontForLanguage ( Language const &  language,
FontSettingsPair const &  fontSettings 
)

Set font for a language.

Todo:
: put FontSettingsPair in QVariant directly

Sets a FontSettingsPair for the language given.

Parameters
[in]languagepointer to a language to set the font for
[in]fontSettingsFontSettingsPair to set

Definition at line 338 of file btconfig.cpp.

References Language::abbrev(), BT_ASSERT, Language::englishName(), m_fontCache, and BtConfigCore::setValue().

Referenced by BtFontSettingsPage::save().

◆ setModuleEncryptionKey()

void BtConfig::setModuleEncryptionKey ( const QString &  name,
const QString &  key 
)

Function to set a module decryption key.

This helper function will set a module decryption key in the configuration. Any previous key will be overwritten.

Parameters
[in]nameName of module to set the key for
[in]keyDecryption key to set as string

Definition at line 221 of file btconfig.cpp.

References BT_ASSERT, and BtConfigCore::setValue().

Referenced by CSwordModuleInfo::unlock().

◆ setSearchScopesWithCurrentLocale()

void BtConfig::setSearchScopesWithCurrentLocale ( const QStringList &  scopeModules,
StringMap  searchScopes 
)

Sets the searchScopes given in the current locale.

This function sets the search scopes of the "properties/searchScopes" property, the scopes are converted to the english locale before saving them.

Parameters
[in]searchScopesSearch scopes in any locale.

We want to make sure that the search scopes are saved with english key names so loading them will always work with each locale set.

Definition at line 441 of file btconfig.cpp.

References parseVerseListWithModules(), and BtConfigCore::setValue().

Referenced by Search::CRangeChooserDialog::accept().

◆ setShortcuts()

void BtConfig::setShortcuts ( QString const &  shortcutGroup,
ShortcutsMap const &  shortcuts 
)

Sets the shortcuts for the given group.

Writes a hash of shortcuts for strings for the respective shortcut group.

Parameters
[in]shortcutGroupThe group to retrieve shortcuts for.
[in]Hashof strings and lists of shortcuts to write.
Note
saving QKeySequences directly doesn't appear to work!

Definition at line 267 of file btconfig.cpp.

References BtConfigCore::group().

Referenced by BtActionCollection::writeShortcuts().

◆ storeDisplayOptionsToGroup()

void BtConfig::storeDisplayOptionsToGroup ( DisplayOptions const &  options,
BtConfigCore group 
)
static

Saves the current display options.

Parameters
[in]optionsThe display options to save.

Definition at line 328 of file btconfig.cpp.

References BtConfigCore::group(), DisplayOptions::lineBreaks, BtConfigCore::setValue(), and DisplayOptions::verseNumbers.

Referenced by CBibleReadWindow::storeProfileSettings().

◆ storeFilterOptionsToGroup()

void BtConfig::storeFilterOptionsToGroup ( FilterOptions const &  options,
BtConfigCore group 
)
static

Friends And Related Function Documentation

◆ BibleTimeApp

friend class BibleTimeApp
friend

Definition at line 39 of file btconfig.h.

Member Data Documentation

◆ m_currentSessionKey

QString BtConfig::m_currentSessionKey
private

◆ m_defaultFont

QFont BtConfig::m_defaultFont
private

default font used when no special one is set

Definition at line 287 of file btconfig.h.

Referenced by BtConfig(), and getDefaultFont().

◆ m_defaultSearchScopes

BtConfig::StringMap BtConfig::m_defaultSearchScopes
staticprivate

Definition at line 290 of file btconfig.h.

Referenced by BtConfig(), and getSearchScopesForCurrentLocale().

◆ m_fontCache

QHash<Language const *, FontSettingsPair> BtConfig::m_fontCache
private

a cache for the fonts saved in the configuration file for speed

Definition at line 288 of file btconfig.h.

Referenced by getFontForLanguage(), and setFontForLanguage().

◆ m_instance

BtConfig * BtConfig::m_instance = nullptr
staticprivate

singleton instance

Definition at line 285 of file btconfig.h.

Referenced by BtConfig(), destroyInstance(), forceMigrate(), getInstance(), initBtConfig(), and BibleTimeApp::~BibleTimeApp().

◆ m_sessionNames

QHash<QString, QString> BtConfig::m_sessionNames
private

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