20#include <QKeySequence>
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)
106 auto sessionsConf =
group(GROUP_SESSIONS);
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);
153 int btConfigOldApi =
m_instance->
value<
int>(BTCONFIG_API_VERSION_KEY, 0);
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(
'_');
200 setValue(KEY_SESSION_NAME.arg(key), name);
210 remove(GROUP_SESSIONS_PREFIX + key);
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);
239 QList<QKeySequence> shortcuts;
240 auto const typeId = variant.typeId();
241 if (typeId == QMetaType::QVariantList) {
242 for (QVariant
const & shortcut : variant.toList())
243 shortcuts.append(shortcut.toString());
244 }
else if (typeId == QMetaType::QStringList
245 || typeId == QMetaType::QString)
247 for (QString
const & shortcut : variant.toStringList())
248 shortcuts.append(shortcut);
253 allShortcuts.insert(key, shortcuts);
261 auto shortcutsConf =
group(shortcutGroup);
262 for (
auto it = shortcuts.begin(); it != shortcuts.end(); ++it) {
266 for (QKeySequence
const & shortcut : it.value())
267 varList.append(shortcut.toString());
269 if (!varList.empty())
270 shortcutsConf.setValue(it.key(), varList);
276 auto const subConf =
group.
group(QStringLiteral(
"presentation"));
277 os.
footnotes = subConf.value<
bool>(QStringLiteral(
"footnotes"),
true);
278 os.
strongNumbers = subConf.value<
bool>(QStringLiteral(
"strongNumbers"),
true);
279 os.
headings = subConf.value<
bool>(QStringLiteral(
"headings"),
true);
280 os.
morphTags = subConf.value<
bool>(QStringLiteral(
"morphTags"),
true);
281 os.
lemmas = subConf.value<
bool>(QStringLiteral(
"lemmas"),
true);
282 os.
redLetterWords = subConf.value<
bool>(QStringLiteral(
"redLetterWords"),
true);
283 os.
hebrewPoints = subConf.value<
bool>(QStringLiteral(
"hebrewPoints"),
true);
284 os.
hebrewCantillation = subConf.value<
bool>(QStringLiteral(
"hebrewCantillation"),
true);
285 os.
greekAccents = subConf.value<
bool>(QStringLiteral(
"greekAccents"),
true);
286 os.
textualVariants = subConf.value<
bool>(QStringLiteral(
"textualVariants"),
false);
288 os.
morphSegmentation = subConf.value<
bool>(QStringLiteral(
"morphSegmentation"),
true);
295 auto subConf =
group.
group(QStringLiteral(
"presentation"));
297 subConf.setValue(QStringLiteral(
"strongNumbers"),
static_cast<bool>(os.
strongNumbers));
298 subConf.setValue(QStringLiteral(
"headings"),
static_cast<bool>(os.
headings));
299 subConf.setValue(QStringLiteral(
"morphTags"),
static_cast<bool>(os.
morphTags));
300 subConf.setValue(QStringLiteral(
"lemmas"),
static_cast<bool>(os.
lemmas));
301 subConf.setValue(QStringLiteral(
"redLetterWords"),
static_cast<bool>(os.
redLetterWords));
302 subConf.setValue(QStringLiteral(
"hebrewPoints"),
static_cast<bool>(os.
hebrewPoints));
303 subConf.setValue(QStringLiteral(
"hebrewCantillation"),
static_cast<bool>(os.
hebrewCantillation));
304 subConf.setValue(QStringLiteral(
"greekAccents"),
static_cast<bool>(os.
greekAccents));
305 subConf.setValue(QStringLiteral(
"textualVariants"),
static_cast<bool>(os.
textualVariants));
306 subConf.setValue(QStringLiteral(
"scriptureReferences"),
static_cast<bool>(os.
scriptureReferences));
307 subConf.setValue(QStringLiteral(
"morphSegmentation"),
static_cast<bool>(os.
morphSegmentation));
313 auto const subConf =
group.
group(QStringLiteral(
"presentation"));
314 os.
lineBreaks = subConf.value<
bool>(QStringLiteral(
"lineBreaks"),
false);
315 os.
verseNumbers = subConf.value<
bool>(QStringLiteral(
"verseNumbers"),
true);
322 auto subConf =
group.
group(QStringLiteral(
"presentation"));
323 subConf.
setValue(QStringLiteral(
"lineBreaks"),
325 subConf.setValue(QStringLiteral(
"verseNumbers"),
332 auto fontAsString = fontSettings.second.toString();
334 const QString & englishName = language.
englishName();
338 setValue(QStringLiteral(
"fonts/") + englishName, fontAsString);
339 setValue(QStringLiteral(
"font standard settings/") + englishName,
342 auto const & abbrev = language.
abbrev();
346 setValue(QStringLiteral(
"fonts/") + abbrev, std::move(fontAsString));
347 setValue(QStringLiteral(
"font standard settings/") + abbrev,
364 const QString & englishName = language.
englishName();
366 auto const & abbrev = language.
abbrev();
370 qVariantValue(QStringLiteral(
"font standard settings/") + abbrev);
371 v.canConvert<
bool>())
373 fontSettings.first = v.value<
bool>();
377 QStringLiteral(
"font standard settings/") + englishName,
382 if (fontSettings.first) {
383 auto const v =
qVariantValue(QStringLiteral(
"fonts/") + abbrev);
385 v.canConvert<QString>()
387 : value<QString>(QStringLiteral(
"fonts/") + englishName,
389 if (!font.fromString(std::move(fontName))) {
395 fontSettings.second = font;
404 auto const storedMap =
405 value<BtConfig::StringMap>(
406 QStringLiteral(
"properties/searchScopes"),
411 for (
auto it = storedMap.cbegin(); it != storedMap.cend(); ++it) {
413 map.insert(tr(it.key().toUtf8()), it.value());
415 map.insert(it.key(), it.value());
420 static auto const separator = QStringLiteral(
"; ");
421 for (
auto & data : map) {
424 for (
int i = 0; i < list.getCount(); i++) {
425 data.append(QString::fromUtf8(list.getElement(i)->getRangeText()));
426 data.append(separator);
437 auto iter(searchScopes.begin());
438 while (iter != searchScopes.end()) {
439 QString &data = iter.value();
440 bool parsingWorked =
true;
443 for (
int i = 0; i < list.getCount(); i++) {
444 sword::VerseKey * verse(
dynamic_cast<sword::VerseKey *
>(list.getElement(i)));
446 if (verse !=
nullptr) {
447 verse->setLocale(
"en");
448 data.append(QString::fromUtf8(verse->getRangeText()));
451 parsingWorked =
false;
459 iter = searchScopes.erase(iter);
461 setValue(QStringLiteral(
"properties/searchScopes"), searchScopes);
465 static auto const key = QStringLiteral(
"GUI/booknameLanguage");
466 auto r = value<QString>(key, QLocale().name());
469 bool const updateConfig =
r.contains(
'_');
478 for (
auto const & moduleName : scopeModules) {
479 auto module = CSwordBackend::instance().findModuleByName(moduleName);
480 if (module ==
nullptr)
482 sword::VerseKey vk =
module->swordModule().getKey();
483 sword::ListKey list(vk.parseVerseList(data.toUtf8(),
"Genesis 1:1",
true));
484 if (list.getCount() > 0)
487 return sword::ListKey();
491 remove(QStringLiteral(
"properties/searchScopes"));
495 auto const moduleName =
496 value<QString>(QStringLiteral(
"settings/defaults/") + moduleType);
497 if (moduleName.isEmpty())
506 setValue(QStringLiteral(
"settings/defaults/") + moduleType,
507 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)
QFont const & getDefaultFont() const
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
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
QString const & abbrev() const
QString const & englishName() const noexcept
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()