diff options
author | Teus Benschop <teusjannette@gmail.com> | 2017-10-06 12:24:31 +0200 |
---|---|---|
committer | Teus Benschop <teusjannette@gmail.com> | 2017-10-06 12:24:31 +0200 |
commit | 90d2181239761f8950b95768d3b037843e9e8b50 (patch) | |
tree | 6cc667ab420cc04029de2de7e361d2305e214595 /src/backend/config | |
parent | 1ea03c0fce8066c1e22188447b4a6ca4dcef1201 (diff) |
New upstream version 2.11.0
Diffstat (limited to 'src/backend/config')
-rw-r--r-- | src/backend/config/btconfig.cpp | 107 | ||||
-rw-r--r-- | src/backend/config/btconfig.h | 36 | ||||
-rw-r--r-- | src/backend/config/btconfigcore.cpp | 19 | ||||
-rw-r--r-- | src/backend/config/btconfigcore.h | 22 |
4 files changed, 86 insertions, 98 deletions
diff --git a/src/backend/config/btconfig.cpp b/src/backend/config/btconfig.cpp index e76b246..98db556 100644 --- a/src/backend/config/btconfig.cpp +++ b/src/backend/config/btconfig.cpp @@ -2,7 +2,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2014 by the BibleTime developers. +* Copyright 1999-2016 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ @@ -11,13 +11,13 @@ #include <QDebug> #include <QLocale> -#include "backend/btmoduletreeitem.h" -#include "backend/managers/cdisplaytemplatemgr.h" -#include "frontend/messagedialog.h" -#include "util/directory.h" // DU::getUserBaseDir() +#include "../../util/btassert.h" +#include "../../util/directory.h" // DU::getUserBaseDir() +#include "../btmoduletreeitem.h" +#include "../managers/cdisplaytemplatemgr.h" +#include "../managers/cswordbackend.h" // Sword includes: -#include <backend/managers/cswordbackend.h> #include <versekey.h> // For search scope configuration @@ -31,7 +31,7 @@ const QString BTCONFIG_API_VERSION_KEY = "btconfig_api_version"; * set the instance variable initially to 0, so it can be safely checked * whether the variable has been initialized yet. */ -BtConfig * BtConfig::m_instance = NULL; +BtConfig * BtConfig::m_instance = nullptr; BtConfig::StringMap BtConfig::m_defaultSearchScopes; @@ -39,7 +39,7 @@ BtConfig::StringMap BtConfig::m_defaultSearchScopes; BtConfig::BtConfig(const QString & settingsFile) : BtConfigCore(settingsFile) { - Q_ASSERT_X(!m_instance, "BtConfig", "Already initialized!"); + BT_ASSERT(!m_instance && "BtConfig already initialized!"); m_instance = this; if (m_defaultSearchScopes.isEmpty()) { @@ -52,10 +52,17 @@ BtConfig::BtConfig(const QString & settingsFile) m_defaultSearchScopes.insert(tr("Letters/Epistles"), QString("Rom - Jude")); m_defaultSearchScopes.insert(tr("Paul's Epistles"), QString("Rom - Phile")); } + +#ifdef Q_OS_WIN + const double minPointSize = 14.0; + double pointSize = m_defaultFont.pointSizeF(); + if (pointSize < minPointSize) + m_defaultFont.setPointSizeF(minPointSize); +#endif } -bool BtConfig::initBtConfig() { - Q_ASSERT(!m_instance); +BtConfig::InitState BtConfig::initBtConfig() { + BT_ASSERT(!m_instance); const QString confFileName = util::directory::getUserBaseDir().absolutePath() + "/bibletimerc"; @@ -63,83 +70,57 @@ bool BtConfig::initBtConfig() { m_instance = new BtConfig(confFileName); if (!confExisted) { m_instance->setValue<int>(BTCONFIG_API_VERSION_KEY, BTCONFIG_API_VERSION); - return true; + return INIT_OK; } int btConfigOldApi = m_instance->value<int>(BTCONFIG_API_VERSION_KEY, 0); if (btConfigOldApi == BTCONFIG_API_VERSION) - return true; - - bool cont; - if (btConfigOldApi < BTCONFIG_API_VERSION) { - /// \todo Migrate from btConfigOldApi to BTCONFIG_API_VERSION - qWarning() << "BibleTime configuration migration is not yet implemented!!!"; - cont = message::showWarning( - 0, "Warning!", - "Migration to the new configuration system is not yet " - "implemented. Proceeding might result in <b>loss of data" - "</b>. Please backup your configuration files before you " - "continue!<br/><br/>Do you want to continue? Press \"No\" " - "to quit BibleTime immediately.", - QMessageBox::Yes | QMessageBox::No, - QMessageBox::No) == QMessageBox::Yes; - } else { - Q_ASSERT(btConfigOldApi > BTCONFIG_API_VERSION); - cont = message::showWarning( - 0, tr("Error loading configuration!"), - tr("Failed to load BibleTime's configuration, because it " - "appears that the configuration file corresponds to a " - "newer version of BibleTime. This is likely caused by " - "BibleTime being downgraded. Loading the new " - "configuration file may result in <b>loss of data</b>." - "<br/><br/>Do you still want to try to load the new " - "configuration file? Press \"No\" to quit BibleTime " - "immediately."), - QMessageBox::Yes | QMessageBox::No, - QMessageBox::No) == QMessageBox::Yes; - } - if (cont) - m_instance->setValue<int>(BTCONFIG_API_VERSION_KEY, BTCONFIG_API_VERSION); - return cont; + return INIT_OK; + return (btConfigOldApi < BTCONFIG_API_VERSION) + ? INIT_NEED_UNIMPLEMENTED_FORWARD_MIGRATE + : INIT_NEED_UNIMPLEMENTED_BACKWARD_MIGRATE; } +void BtConfig::forceMigrate() +{ m_instance->setValue<int>(BTCONFIG_API_VERSION_KEY, BTCONFIG_API_VERSION); } + BtConfig& BtConfig::getInstance() { - Q_ASSERT_X(m_instance, "BtConfig", "Not yet initialized!"); + BT_ASSERT(m_instance && "BtConfig not yet initialized!"); return *m_instance; } void BtConfig::destroyInstance() { delete m_instance; - m_instance = NULL; + m_instance = nullptr; } void BtConfig::setModuleEncryptionKey(const QString & name, const QString & key) { - Q_ASSERT(!name.isEmpty()); + BT_ASSERT(!name.isEmpty()); setValue("Module keys/" + name, key); } QString BtConfig::getModuleEncryptionKey(const QString & name) { - Q_ASSERT(!name.isEmpty()); + BT_ASSERT(!name.isEmpty()); return value<QString>("Module keys/" + name, QString::null); } -QHash<QString, QList<QKeySequence> > BtConfig::getShortcuts(const QString & shortcutGroup) { +BtConfig::ShortcutsMap BtConfig::getShortcuts(QString const & shortcutGroup) { beginGroup(shortcutGroup); - QHash<QString, QList<QKeySequence> > allShortcuts; - Q_FOREACH (const QString & key, childKeys()) { + ShortcutsMap allShortcuts; + for (QString const & key : childKeys()) { QVariant variant = qVariantValue(key); QList<QKeySequence> shortcuts; if (variant.type() == QVariant::List) { // For BibleTime before 2.9 - Q_FOREACH (const QVariant & shortcut, variant.toList()) + for (QVariant const & shortcut : variant.toList()) shortcuts.append(shortcut.toString()); } else if (variant.type() == QVariant::StringList || variant.type() == QVariant::String) { // a StringList with one element is recognized as a QVariant::String - Q_FOREACH (const QString & shortcut, variant.toStringList()) + for (QString const & shortcut : variant.toStringList()) shortcuts.append(shortcut); } else { // it's something we don't know, skip it continue; @@ -151,17 +132,15 @@ QHash<QString, QList<QKeySequence> > BtConfig::getShortcuts(const QString & shor return allShortcuts; } -void BtConfig::setShortcuts(const QString & shortcutGroup, - const QHash<QString, QList<QKeySequence> > & shortcuts) +void BtConfig::setShortcuts(QString const & shortcutGroup, + ShortcutsMap const & shortcuts) { - typedef QHash<QString, QList<QKeySequence> >::const_iterator SHMCI; - beginGroup(shortcutGroup); - for (SHMCI it = shortcuts.begin(); it != shortcuts.end(); ++it) { + for (auto it = shortcuts.begin(); it != shortcuts.end(); ++it) { // Write beautiful string lists (since 2.9): /// \note saving QKeySequences directly doesn't appear to work! QStringList varList; - Q_FOREACH (const QKeySequence & shortcut, it.value()) + for (QKeySequence const & shortcut : it.value()) varList.append(shortcut.toString()); if (!varList.empty()) @@ -226,7 +205,7 @@ void BtConfig::setFontForLanguage(const CLanguageMgr::Language & language, const FontSettingsPair & fontSettings) { const QString & englishName = language.englishName(); - Q_ASSERT(!englishName.isEmpty()); + BT_ASSERT(!englishName.isEmpty()); QMutexLocker lock(&this->m_mutex); // write the language to the settings @@ -241,7 +220,7 @@ BtConfig::FontSettingsPair BtConfig::getFontForLanguage( const CLanguageMgr::Language & language) { const QString & englishName = language.englishName(); - Q_ASSERT(!englishName.isEmpty()); + BT_ASSERT(!englishName.isEmpty()); QMutexLocker lock(&this->m_mutex); // Check the cache first: @@ -302,7 +281,7 @@ void BtConfig::setSearchScopesWithCurrentLocale(StringMap searchScopes) { for (int i = 0; i < list.getCount(); i++) { sword::VerseKey * verse(dynamic_cast<sword::VerseKey *>(list.getElement(i))); - if (verse != 0) { + if (verse != nullptr) { verse->setLocale("en"); data.append(QString::fromUtf8(verse->getRangeText())); data.append(";"); @@ -327,7 +306,7 @@ void BtConfig::deleteSearchScopesWithCurrentLocale() { CSwordModuleInfo *BtConfig::getDefaultSwordModuleByType(const QString & moduleType) { const QString moduleName = value<QString>("settings/defaults/" + moduleType, QString()); if (moduleName.isEmpty()) - return 0; + return nullptr; return CSwordBackend::instance()->findModuleByName(moduleName); } @@ -336,7 +315,7 @@ void BtConfig::setDefaultSwordModuleByType(const QString &moduleType, const CSwordModuleInfo * const module) { setValue("settings/defaults/" + moduleType, - module != 0 ? module->name() : QString::null); + module != nullptr ? module->name() : QString::null); } /** diff --git a/src/backend/config/btconfig.h b/src/backend/config/btconfig.h index be19d41..785a89f 100644 --- a/src/backend/config/btconfig.h +++ b/src/backend/config/btconfig.h @@ -4,7 +4,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2014 by the BibleTime developers. +* Copyright 1999-2016 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ @@ -22,20 +22,16 @@ #include <QString> #include <QStringList> #include <QVariant> - -#include "backend/config/btconfigcore.h" - -#include "backend/btmoduletreeitem.h" // for BTModuleTreeItem::Grouping -#include "backend/drivers/cswordmoduleinfo.h" -#include "btglobal.h" +#include "../btglobal.h" +#include "../btmoduletreeitem.h" // for BTModuleTreeItem::Grouping +#include "../drivers/cswordmoduleinfo.h" +#include "btconfigcore.h" class BibleTimeApp; class BtConfig: public BtConfigCore { - Q_DISABLE_COPY(BtConfig) - friend class BibleTimeApp; public: /* Types: */ @@ -44,12 +40,19 @@ public: /* Types: */ * The first parameter indicates whether the custom font should be used or not. * The second parameter is the custom font that has been set. */ - typedef QPair<bool, QFont> FontSettingsPair; - typedef QMap<QString, QString> StringMap; + using FontSettingsPair = QPair<bool, QFont>; + using StringMap = QMap<QString, QString>; + using ShortcutsMap = QHash<QString, QList<QKeySequence> >; private: /* Types: */ - typedef QHash<const CLanguageMgr::Language *, FontSettingsPair> FontCacheMap; + using FontCacheMap = QHash<const CLanguageMgr::Language *, FontSettingsPair>; + + enum InitState { + INIT_NEED_UNIMPLEMENTED_BACKWARD_MIGRATE = -2, + INIT_OK = 0, + INIT_NEED_UNIMPLEMENTED_FORWARD_MIGRATE = 2, + }; public: /* Methods: */ @@ -86,7 +89,7 @@ public: /* Methods: */ * \param[in] shortcutGroup The group to retrieve shortcuts for. * \returns Hash of strings and lists of shortcuts. */ - QHash<QString, QList<QKeySequence> > getShortcuts(const QString & shortcutGroup); + ShortcutsMap getShortcuts(QString const & shortcutGroup); /*! * \brief Sets the shortcuts for the given group. @@ -96,8 +99,8 @@ public: /* Methods: */ * \param[in] shortcutGroup The group to retrieve shortcuts for. * \param[in] Hash of strings and lists of shortcuts to write. */ - void setShortcuts(const QString & shortcutGroup, - const QHash<QString, QList<QKeySequence> > & shortcuts); + void setShortcuts(QString const & shortcutGroup, + ShortcutsMap const & shortcuts); /*! * \brief Returns current filter options. @@ -218,7 +221,8 @@ private: /* Methods: */ explicit BtConfig(const QString & settingsFile); - static bool initBtConfig(); + static InitState initBtConfig(); + static void forceMigrate(); static void destroyInstance(); diff --git a/src/backend/config/btconfigcore.cpp b/src/backend/config/btconfigcore.cpp index 0914508..b290e2d 100644 --- a/src/backend/config/btconfigcore.cpp +++ b/src/backend/config/btconfigcore.cpp @@ -2,7 +2,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2014 by the BibleTime developers. +* Copyright 1999-2016 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ @@ -55,7 +55,8 @@ BtConfigCore::BtConfigCore(const QString & settingsFile) || !m_sessionNames.contains(m_currentSessionKey)) { if (m_sessionNames.isEmpty()) { - const QString &newSessionName = QString::number((qulonglong) 0u, 36); + QString const & newSessionName = + QString::number(static_cast<qulonglong>(0u), 36); m_currentSessionKey = newSessionName; m_settings.setValue(KEY_CURRENT_SESSION, newSessionName); m_settings.setValue(KEY_SESSION_NAME.arg(newSessionName), @@ -68,10 +69,10 @@ BtConfigCore::BtConfigCore(const QString & settingsFile) } void BtConfigCore::setCurrentSession(const QString & key) { - Q_ASSERT(!key.isEmpty()); + BT_ASSERT(!key.isEmpty()); QMutexLocker lock(&m_mutex); - Q_ASSERT(m_sessionNames.contains(key)); + BT_ASSERT(m_sessionNames.contains(key)); m_currentSessionKey = key; m_cachedCurrentSessionGroup = GROUP_SESSION.arg(key); @@ -80,7 +81,7 @@ void BtConfigCore::setCurrentSession(const QString & key) { } QString BtConfigCore::addSession(const QString & name) { - Q_ASSERT(!name.isEmpty()); + BT_ASSERT(!name.isEmpty()); // Generate a new session key: QString key = QString::number(0u, 36); @@ -100,7 +101,7 @@ QString BtConfigCore::addSession(const QString & name) { } }; } - Q_ASSERT(!m_sessionNames.contains(key)); + BT_ASSERT(!m_sessionNames.contains(key)); m_sessionNames.insert(key, name); m_settings.setValue(KEY_SESSION_NAME.arg(key), name); @@ -111,8 +112,8 @@ QString BtConfigCore::addSession(const QString & name) { void BtConfigCore::deleteSession(const QString & key) { QMutexLocker lock(&m_mutex); - Q_ASSERT(m_sessionNames.contains(key)); - Q_ASSERT(key != m_currentSessionKey); + BT_ASSERT(m_sessionNames.contains(key)); + BT_ASSERT(key != m_currentSessionKey); m_sessionNames.remove(key); m_settings.remove(GROUP_SESSIONS + key); @@ -121,7 +122,7 @@ void BtConfigCore::deleteSession(const QString & key) { QStringList BtConfigCore::childKeys() { QMutexLocker lock(&m_mutex); - return childGroups__(); + return childKeys__(); } QStringList BtConfigCore::childKeys__() { diff --git a/src/backend/config/btconfigcore.h b/src/backend/config/btconfigcore.h index 5c24b4f..257295d 100644 --- a/src/backend/config/btconfigcore.h +++ b/src/backend/config/btconfigcore.h @@ -4,7 +4,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2014 by the BibleTime developers. +* Copyright 1999-2016 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ @@ -18,6 +18,7 @@ #include <QHash> #include <QMutex> #include <QStringList> +#include "../../util/btassert.h" /** @@ -27,15 +28,17 @@ */ class BtConfigCore { - Q_DISABLE_COPY(BtConfigCore) Q_DECLARE_TR_FUNCTIONS(BtConfigCore) public: /* Types: */ - typedef QHash<QString, QString> SessionNamesHashMap; + using SessionNamesHashMap = QHash<QString, QString>; public: /* Methods: */ + BtConfigCore(BtConfigCore const &) = delete; + BtConfigCore & operator=(BtConfigCore const &) = delete; + /** \param[in] settingsFile The filename of the settings file. */ @@ -57,9 +60,9 @@ public: /* Methods: */ */ inline const QString & currentSessionName() const { QMutexLocker lock(&m_mutex); - typedef QHash<QString, QString>::const_iterator SSHCI; + using SSHCI = QHash<QString, QString>::const_iterator; SSHCI it = m_sessionNames.constFind(m_currentSessionKey); - Q_ASSERT(it != m_sessionNames.constEnd()); + BT_ASSERT(it != m_sessionNames.constEnd()); return it.value(); } @@ -239,13 +242,13 @@ public: /* Methods: */ \param[in] prefix the prefix to append */ inline void beginGroup(QString prefix) { - Q_ASSERT(!prefix.isEmpty()); + BT_ASSERT(!prefix.isEmpty()); while (prefix.startsWith('/')) prefix.remove(0, 1); - Q_ASSERT(!prefix.isEmpty()); + BT_ASSERT(!prefix.isEmpty()); while (prefix.endsWith('/')) prefix.chop(1); - Q_ASSERT(!prefix.isEmpty()); + BT_ASSERT(!prefix.isEmpty()); m_mutex.lock(); m_groups.append(prefix); @@ -262,7 +265,8 @@ public: /* Methods: */ \warning Locks the object (recursively) until endGroup(). */ inline void endGroup() { - Q_ASSERT_X(!m_groups.isEmpty(), "BtConfig", "endGroup() called, but no beginGroup() active."); + BT_ASSERT(!m_groups.isEmpty() + && "BtConfig::endGroup() called, but no beginGroup() active"); m_groups.removeLast(); m_cachedGroup = QString(); m_mutex.unlock(); |