20 #include <QKeySequence>
25 #include <type_traits>
27 #include "../../util/btassert.h"
28 #include "../../util/directory.h"
29 #include "../btglobal.h"
30 #include "../drivers/cswordmoduleinfo.h"
31 #include "../language.h"
32 #include "../managers/cswordbackend.h"
36 #pragma GCC diagnostic push
37 #pragma GCC diagnostic ignored "-Wextra-semi"
38 #pragma GCC diagnostic ignored "-Wsuggest-override"
39 #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
41 #pragma clang diagnostic push
42 #pragma clang diagnostic ignored "-Wsuggest-destructor-override"
49 #pragma clang diagnostic pop
51 #pragma GCC diagnostic pop
54 #define BTCONFIG_API_VERSION 1
74 std::make_shared<QSettings>(settingsFile, QSettings::IniFormat))
81 QStringLiteral(
"Gen - Mal"));
83 QStringLiteral(
"Gen - Deut"));
85 QStringLiteral(
"Jos - Est"));
87 QStringLiteral(
"Isa - Mal"));
89 QStringLiteral(
"Mat - Rev"));
91 QStringLiteral(
"Mat - Joh"));
93 QStringLiteral(
"Rom - Jude"));
95 QStringLiteral(
"Rom - Phile"));
99 const double minPointSize = 14.0;
101 if (pointSize < minPointSize)
107 for (
auto && sessionKey : sessionsConf.childGroups()) {
109 if (sessionKey.isEmpty())
113 sessionsConf.value<QString>(
114 sessionKey + QStringLiteral(
"/name"));
115 if (!sessionName.isEmpty())
117 std::move(sessionName));
134 tr(
"Default Session"));
145 + QStringLiteral(
"/bibletimerc");
146 bool confExisted = QFile::exists(confFileName);
181 QString key = QString::number(0u, 36);
186 key = QString::number(i, 36);
189 if (i == std::numeric_limits<std::size_t>::max()) {
191 keyPrefix.append(
'_');
225 setValue(QStringLiteral(
"Module keys/") + name, key);
230 return value<QString>(QStringLiteral(
"Module keys/") + name, QString());
235 auto shortcutsConf =
group(shortcutGroup);
236 for (QString
const & key : shortcutsConf.childKeys()) {
237 auto const variant = shortcutsConf.qVariantValue(key);
240 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
241 if (variant.type() == QVariant::List) {
243 auto const typeId = variant.typeId();
244 if (typeId == QMetaType::QVariantList) {
246 for (QVariant
const & shortcut : variant.toList())
247 shortcuts.append(shortcut.toString());
248 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
249 }
else if (variant.type() == QVariant::StringList
250 || variant.type() == QVariant::String)
252 }
else if (typeId == QMetaType::QStringList
253 || typeId == QMetaType::QString)
256 for (QString
const & shortcut : variant.toStringList())
257 shortcuts.append(shortcut);
262 allShortcuts.insert(key, shortcuts);
270 auto shortcutsConf =
group(shortcutGroup);
271 for (
auto it = shortcuts.begin(); it != shortcuts.end(); ++it) {
275 for (QKeySequence
const & shortcut : it.value())
276 varList.append(shortcut.toString());
278 if (!varList.empty())
279 shortcutsConf.setValue(it.key(), varList);
285 auto const subConf =
group.
group(QStringLiteral(
"presentation"));
286 os.
footnotes = subConf.value<
bool>(QStringLiteral(
"footnotes"),
true);
287 os.
strongNumbers = subConf.value<
bool>(QStringLiteral(
"strongNumbers"),
true);
288 os.
headings = subConf.value<
bool>(QStringLiteral(
"headings"),
true);
289 os.
morphTags = subConf.value<
bool>(QStringLiteral(
"morphTags"),
true);
290 os.
lemmas = subConf.value<
bool>(QStringLiteral(
"lemmas"),
true);
291 os.
redLetterWords = subConf.value<
bool>(QStringLiteral(
"redLetterWords"),
true);
292 os.
hebrewPoints = subConf.value<
bool>(QStringLiteral(
"hebrewPoints"),
true);
293 os.
hebrewCantillation = subConf.value<
bool>(QStringLiteral(
"hebrewCantillation"),
true);
294 os.
greekAccents = subConf.value<
bool>(QStringLiteral(
"greekAccents"),
true);
295 os.
textualVariants = subConf.value<
bool>(QStringLiteral(
"textualVariants"),
false);
297 os.
morphSegmentation = subConf.value<
bool>(QStringLiteral(
"morphSegmentation"),
true);
304 auto subConf =
group.
group(QStringLiteral(
"presentation"));
306 subConf.setValue(QStringLiteral(
"strongNumbers"),
static_cast<bool>(os.
strongNumbers));
307 subConf.setValue(QStringLiteral(
"headings"),
static_cast<bool>(os.
headings));
308 subConf.setValue(QStringLiteral(
"morphTags"),
static_cast<bool>(os.
morphTags));
309 subConf.setValue(QStringLiteral(
"lemmas"),
static_cast<bool>(os.
lemmas));
310 subConf.setValue(QStringLiteral(
"redLetterWords"),
static_cast<bool>(os.
redLetterWords));
311 subConf.setValue(QStringLiteral(
"hebrewPoints"),
static_cast<bool>(os.
hebrewPoints));
312 subConf.setValue(QStringLiteral(
"hebrewCantillation"),
static_cast<bool>(os.
hebrewCantillation));
313 subConf.setValue(QStringLiteral(
"greekAccents"),
static_cast<bool>(os.
greekAccents));
314 subConf.setValue(QStringLiteral(
"textualVariants"),
static_cast<bool>(os.
textualVariants));
315 subConf.setValue(QStringLiteral(
"scriptureReferences"),
static_cast<bool>(os.
scriptureReferences));
316 subConf.setValue(QStringLiteral(
"morphSegmentation"),
static_cast<bool>(os.
morphSegmentation));
322 auto const subConf =
group.
group(QStringLiteral(
"presentation"));
323 os.
lineBreaks = subConf.value<
bool>(QStringLiteral(
"lineBreaks"),
false);
324 os.
verseNumbers = subConf.value<
bool>(QStringLiteral(
"verseNumbers"),
true);
331 auto subConf =
group.
group(QStringLiteral(
"presentation"));
332 subConf.
setValue(QStringLiteral(
"lineBreaks"),
334 subConf.setValue(QStringLiteral(
"verseNumbers"),
341 auto fontAsString = fontSettings.second.toString();
343 const QString & englishName = language.
englishName();
347 setValue(QStringLiteral(
"fonts/") + englishName, fontAsString);
348 setValue(QStringLiteral(
"font standard settings/") + englishName,
351 auto const & abbrev = language.
abbrev();
355 setValue(QStringLiteral(
"fonts/") + abbrev, std::move(fontAsString));
356 setValue(QStringLiteral(
"font standard settings/") + abbrev,
373 const QString & englishName = language.
englishName();
375 auto const & abbrev = language.
abbrev();
379 qVariantValue(QStringLiteral(
"font standard settings/") + abbrev);
380 v.canConvert<
bool>())
382 fontSettings.first = v.value<
bool>();
386 QStringLiteral(
"font standard settings/") + englishName,
391 if (fontSettings.first) {
392 auto const v =
qVariantValue(QStringLiteral(
"fonts/") + abbrev);
394 v.canConvert<QString>()
396 : value<QString>(QStringLiteral(
"fonts/") + englishName,
398 if (!font.fromString(std::move(fontName))) {
404 fontSettings.second = font;
413 auto const storedMap =
414 value<BtConfig::StringMap>(
415 QStringLiteral(
"properties/searchScopes"),
420 for (
auto it = storedMap.cbegin(); it != storedMap.cend(); ++it) {
422 map.insert(tr(it.key().toUtf8()), it.value());
424 map.insert(it.key(), it.value());
429 static auto const separator = QStringLiteral(
"; ");
430 for (
auto & data : map) {
433 for (
int i = 0; i < list.getCount(); i++) {
434 data.append(QString::fromUtf8(list.getElement(i)->getRangeText()));
435 data.append(separator);
446 auto iter(searchScopes.begin());
447 while (iter != searchScopes.end()) {
448 QString &data = iter.value();
449 bool parsingWorked =
true;
452 for (
int i = 0; i < list.getCount(); i++) {
453 sword::VerseKey * verse(
dynamic_cast<sword::VerseKey *
>(list.getElement(i)));
455 if (verse !=
nullptr) {
456 verse->setLocale(
"en");
457 data.append(QString::fromUtf8(verse->getRangeText()));
460 parsingWorked =
false;
468 iter = searchScopes.erase(iter);
470 setValue(QStringLiteral(
"properties/searchScopes"), searchScopes);
474 static auto const key = QStringLiteral(
"GUI/booknameLanguage");
475 auto r = value<QString>(key, QLocale().name());
478 bool const updateConfig =
r.contains(
'_');
487 for (
auto const & moduleName : scopeModules) {
489 if (module ==
nullptr)
491 sword::VerseKey vk = module->
swordModule().getKey();
492 sword::ListKey list(vk.parseVerseList(data.toUtf8(),
"Genesis 1:1",
true));
493 if (list.getCount() > 0)
496 return sword::ListKey();
500 remove(QStringLiteral(
"properties/searchScopes"));
504 auto const moduleName =
505 value<QString>(QStringLiteral(
"settings/defaults/") + moduleType);
506 if (moduleName.isEmpty())
515 setValue(QStringLiteral(
"settings/defaults/") + moduleType,
516 module !=
nullptr ? module->
name() : QString());
#define BTCONFIG_API_VERSION
void remove(QString const &key)
removes a key (and its children) from the current group.
BtConfigCore group(Prefix &&prefix) const &
T value(QString const &key, T const &defaultValue=T()) const
Returns the settings value for the given global key.
void setValue(QString const &key, T const &value)
Sets a value for a key.
QVariant qVariantValue(QString const &key, QVariant const &defaultValue=QVariant()) const
Returns the settings value for the given global key as a QVariant.
QMap< QString, QString > StringMap
QString getModuleEncryptionKey(const QString &name)
Function to get a module decryption key.
static void storeFilterOptionsToGroup(FilterOptions const &options, BtConfigCore &group)
Saves the current filter options.
BtConfigCore session() const
static FilterOptions loadFilterOptionsFromGroup(BtConfigCore const &group)
void setFontForLanguage(Language const &language, FontSettingsPair const &fontSettings)
Set font for a language.
QPair< bool, QFont > FontSettingsPair
static DisplayOptions loadDisplayOptionsFromGroup(BtConfigCore const &group)
QHash< QString, QString > m_sessionNames
void setDefaultSwordModuleByType(const QString &moduleType, const CSwordModuleInfo *const module)
Sets the default sword module for a module type.
void setSearchScopesWithCurrentLocale(const QStringList &scopeModules, StringMap searchScopes)
QString m_currentSessionKey
QFont const & getDefaultFont() const
static InitState initBtConfig()
static void destroyInstance()
QString addSession(const QString &name)
Creates a new session with the given name.
void deleteSearchScopesWithCurrentLocale()
static void forceMigrate()
static sword::ListKey parseVerseListWithModules(const QString &data, const QStringList &scopeModules)
void setModuleEncryptionKey(const QString &name, const QString &key)
Function to set a module decryption key.
QHash< Language const *, FontSettingsPair > m_fontCache
a cache for the fonts saved in the configuration file for speed
void setShortcuts(QString const &shortcutGroup, ShortcutsMap const &shortcuts)
Sets the shortcuts for the given group.
static BtConfig * m_instance
singleton instance
QFont m_defaultFont
default font used when no special one is set
FontSettingsPair getFontForLanguage(Language const &language)
Get font for a language.
@ INIT_NEED_UNIMPLEMENTED_FORWARD_MIGRATE
@ INIT_NEED_UNIMPLEMENTED_BACKWARD_MIGRATE
void setCurrentSession(const QString &key)
Notifies the configuration system that the session settings should be read from and saved to the give...
void deleteSession(const QString &key)
Deletes the session with the given key.
QString booknameLanguage()
CSwordModuleInfo * getDefaultSwordModuleByType(const QString &moduleType)
Returns default sword module info class for a given module type.
ShortcutsMap getShortcuts(QString const &shortcutGroup)
Gets the shortcuts for the given group.
static void storeDisplayOptionsToGroup(DisplayOptions const &options, BtConfigCore &group)
Saves the current display options.
static StringMap m_defaultSearchScopes
static BtConfig & getInstance()
StringMap getSearchScopesForCurrentLocale(const QStringList &scopeModules)
CSwordModuleInfo * findModuleByName(const QString &name) const
Searches for a module with the given name.
static CSwordBackend & instance() noexcept
QString const & name() const
sword::SWModule & swordModule() const
QString const & englishName() const noexcept
QString const & abbrev() const
QStringList r(content.left(bodyIndex))
auto const KEY_SESSION_NAME
auto const BTCONFIG_API_VERSION_KEY
auto const GROUP_SESSIONS_PREFIX
auto const KEY_CURRENT_SESSION
auto const GROUP_SESSIONS
const QDir & getUserBaseDir()