20#include <QKeySequence>
26#include "../../util/btassert.h"
27#include "../../util/directory.h"
28#include "../btglobal.h"
29#include "../drivers/cswordmoduleinfo.h"
30#include "../language.h"
31#include "../managers/cswordbackend.h"
35#pragma GCC diagnostic push
36#pragma GCC diagnostic ignored "-Wextra-semi"
37#pragma GCC diagnostic ignored "-Wsuggest-override"
38#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
40#pragma clang diagnostic push
41#pragma clang diagnostic ignored "-Wsuggest-destructor-override"
48#pragma clang diagnostic pop
50#pragma GCC diagnostic pop
53#define BTCONFIG_API_VERSION 1
73 std::make_shared<QSettings>(settingsFile, QSettings::IniFormat))
80 QStringLiteral(
"Gen - Mal"));
82 QStringLiteral(
"Gen - Deut"));
84 QStringLiteral(
"Jos - Est"));
86 QStringLiteral(
"Isa - Mal"));
88 QStringLiteral(
"Mat - Rev"));
90 QStringLiteral(
"Mat - Joh"));
92 QStringLiteral(
"Rom - Jude"));
94 QStringLiteral(
"Rom - Phile"));
98 const double minPointSize = 14.0;
100 if (pointSize < minPointSize)
105 auto sessionsConf =
group(GROUP_SESSIONS);
106 for (
auto && sessionKey : sessionsConf.childGroups()) {
108 if (sessionKey.isEmpty())
112 sessionsConf.value<QString>(
113 sessionKey + QStringLiteral(
"/name"));
114 if (!sessionName.isEmpty())
116 std::move(sessionName));
133 tr(
"Default Session"));
144 + QStringLiteral(
"/bibletimerc");
145 bool confExisted = QFile::exists(confFileName);
152 int btConfigOldApi =
m_instance->
value<
int>(BTCONFIG_API_VERSION_KEY, 0);
180 QString key = QString::number(0u, 36);
185 key = QString::number(i, 36);
188 if (i == std::numeric_limits<std::size_t>::max()) {
190 keyPrefix.append(
'_');
199 setValue(KEY_SESSION_NAME.arg(key), name);
209 remove(GROUP_SESSIONS_PREFIX + key);
224 setValue(QStringLiteral(
"Module keys/") + name, key);
229 return value<QString>(QStringLiteral(
"Module keys/") + name, QString());
234 auto shortcutsConf =
group(shortcutGroup);
235 for (QString
const & key : shortcutsConf.childKeys()) {
236 auto const variant = shortcutsConf.qVariantValue(key);
238 QList<QKeySequence> shortcuts;
239 auto const typeId = variant.typeId();
240 if (typeId == QMetaType::QVariantList) {
241 for (QVariant
const & shortcut : variant.toList())
242 shortcuts.append(shortcut.toString());
243 }
else if (typeId == QMetaType::QStringList
244 || typeId == QMetaType::QString)
246 for (QString
const & shortcut : variant.toStringList())
247 shortcuts.append(shortcut);
252 allShortcuts.insert(key, shortcuts);
260 auto shortcutsConf =
group(shortcutGroup);
261 for (
auto it = shortcuts.begin(); it != shortcuts.end(); ++it) {
265 for (QKeySequence
const & shortcut : it.value())
266 varList.append(shortcut.toString());
268 if (!varList.empty())
269 shortcutsConf.setValue(it.key(), varList);
275 auto const subConf =
group.
group(QStringLiteral(
"presentation"));
276 os.
footnotes = subConf.value<
bool>(QStringLiteral(
"footnotes"),
true);
277 os.
strongNumbers = subConf.value<
bool>(QStringLiteral(
"strongNumbers"),
true);
278 os.
headings = subConf.value<
bool>(QStringLiteral(
"headings"),
true);
279 os.
morphTags = subConf.value<
bool>(QStringLiteral(
"morphTags"),
true);
280 os.
lemmas = subConf.value<
bool>(QStringLiteral(
"lemmas"),
true);
281 os.
redLetterWords = subConf.value<
bool>(QStringLiteral(
"redLetterWords"),
true);
282 os.
hebrewPoints = subConf.value<
bool>(QStringLiteral(
"hebrewPoints"),
true);
283 os.
hebrewCantillation = subConf.value<
bool>(QStringLiteral(
"hebrewCantillation"),
true);
284 os.
greekAccents = subConf.value<
bool>(QStringLiteral(
"greekAccents"),
true);
285 os.
textualVariants = subConf.value<
bool>(QStringLiteral(
"textualVariants"),
false);
287 os.
morphSegmentation = subConf.value<
bool>(QStringLiteral(
"morphSegmentation"),
true);
294 auto subConf =
group.
group(QStringLiteral(
"presentation"));
296 subConf.setValue(QStringLiteral(
"strongNumbers"),
static_cast<bool>(os.
strongNumbers));
297 subConf.setValue(QStringLiteral(
"headings"),
static_cast<bool>(os.
headings));
298 subConf.setValue(QStringLiteral(
"morphTags"),
static_cast<bool>(os.
morphTags));
299 subConf.setValue(QStringLiteral(
"lemmas"),
static_cast<bool>(os.
lemmas));
300 subConf.setValue(QStringLiteral(
"redLetterWords"),
static_cast<bool>(os.
redLetterWords));
301 subConf.setValue(QStringLiteral(
"hebrewPoints"),
static_cast<bool>(os.
hebrewPoints));
302 subConf.setValue(QStringLiteral(
"hebrewCantillation"),
static_cast<bool>(os.
hebrewCantillation));
303 subConf.setValue(QStringLiteral(
"greekAccents"),
static_cast<bool>(os.
greekAccents));
304 subConf.setValue(QStringLiteral(
"textualVariants"),
static_cast<bool>(os.
textualVariants));
305 subConf.setValue(QStringLiteral(
"scriptureReferences"),
static_cast<bool>(os.
scriptureReferences));
306 subConf.setValue(QStringLiteral(
"morphSegmentation"),
static_cast<bool>(os.
morphSegmentation));
312 auto const subConf =
group.
group(QStringLiteral(
"presentation"));
313 os.
lineBreaks = subConf.value<
bool>(QStringLiteral(
"lineBreaks"),
false);
314 os.
verseNumbers = subConf.value<
bool>(QStringLiteral(
"verseNumbers"),
true);
321 auto subConf =
group.
group(QStringLiteral(
"presentation"));
322 subConf.
setValue(QStringLiteral(
"lineBreaks"),
324 subConf.setValue(QStringLiteral(
"verseNumbers"),
331 auto fontAsString = fontSettings.second.toString();
333 const QString & englishName = language.
englishName();
337 setValue(QStringLiteral(
"fonts/") + englishName, fontAsString);
338 setValue(QStringLiteral(
"font standard settings/") + englishName,
341 auto const & abbrev = language.
abbrev();
345 setValue(QStringLiteral(
"fonts/") + abbrev, std::move(fontAsString));
346 setValue(QStringLiteral(
"font standard settings/") + abbrev,
363 const QString & englishName = language.
englishName();
365 auto const & abbrev = language.
abbrev();
369 qVariantValue(QStringLiteral(
"font standard settings/") + abbrev);
370 v.canConvert<
bool>())
372 fontSettings.first = v.value<
bool>();
376 QStringLiteral(
"font standard settings/") + englishName,
381 if (fontSettings.first) {
382 auto const v =
qVariantValue(QStringLiteral(
"fonts/") + abbrev);
384 v.canConvert<QString>()
386 : value<QString>(QStringLiteral(
"fonts/") + englishName,
388 if (!font.fromString(std::move(fontName))) {
394 fontSettings.second = font;
403 auto const storedMap =
404 value<BtConfig::StringMap>(
405 QStringLiteral(
"properties/searchScopes"),
410 for (
auto it = storedMap.cbegin(); it != storedMap.cend(); ++it) {
412 map.insert(tr(it.key().toUtf8()), it.value());
414 map.insert(it.key(), it.value());
419 static auto const separator = QStringLiteral(
"; ");
420 for (
auto & data : map) {
423 for (
int i = 0; i < list.getCount(); i++) {
424 data.append(QString::fromUtf8(list.getElement(i)->getRangeText()));
425 data.append(separator);
436 auto iter(searchScopes.begin());
437 while (iter != searchScopes.end()) {
438 QString &data = iter.value();
439 bool parsingWorked =
true;
442 for (
int i = 0; i < list.getCount(); i++) {
443 sword::VerseKey * verse(
dynamic_cast<sword::VerseKey *
>(list.getElement(i)));
445 if (verse !=
nullptr) {
446 verse->setLocale(
"en");
447 data.append(QString::fromUtf8(verse->getRangeText()));
450 parsingWorked =
false;
458 iter = searchScopes.erase(iter);
460 setValue(QStringLiteral(
"properties/searchScopes"), searchScopes);
464 static auto const key = QStringLiteral(
"GUI/booknameLanguage");
465 auto r = value<QString>(key, QLocale().name());
468 bool const updateConfig =
r.contains(
'_');
477 for (
auto const & moduleName : scopeModules) {
478 auto module = CSwordBackend::instance().findModuleByName(moduleName);
479 if (module ==
nullptr)
481 sword::VerseKey vk =
module->swordModule().getKey();
482 sword::ListKey list(vk.parseVerseList(data.toUtf8(),
"Genesis 1:1",
true));
483 if (list.getCount() > 0)
486 return sword::ListKey();
490 remove(QStringLiteral(
"properties/searchScopes"));
494 auto const moduleName =
495 value<QString>(QStringLiteral(
"settings/defaults/") + moduleType);
496 if (moduleName.isEmpty())
505 setValue(QStringLiteral(
"settings/defaults/") + moduleType,
506 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()