diff options
Diffstat (limited to 'src/backend/config/cbtconfig.cpp')
-rw-r--r-- | src/backend/config/cbtconfig.cpp | 478 |
1 files changed, 201 insertions, 277 deletions
diff --git a/src/backend/config/cbtconfig.cpp b/src/backend/config/cbtconfig.cpp index 883f41f..d82fc7d 100644 --- a/src/backend/config/cbtconfig.cpp +++ b/src/backend/config/cbtconfig.cpp @@ -44,7 +44,6 @@ QString getKey(const strings ID) { case bookshelfCurrentItem: return "bookshelfCurrentItem"; } - Q_ASSERT(false); return QString::null; } @@ -67,7 +66,6 @@ QString getKey(const modules ID) { case standardGreekMorphLexicon: return "standardGreekMorphLexicon"; } - Q_ASSERT(false); return QString::null; } @@ -78,8 +76,8 @@ QString getKey(const bools ID) { case readOldBookmarks: return "readOldBookmarks"; - case toolbar: - return "toolbar"; + case showMainWindowToolbar: + return "showMainWindowToolbar"; case mainIndex: return "mainIndex"; case infoDisplay: @@ -129,9 +127,10 @@ QString getKey(const bools ID) { return "showToolbarsInEachWindow"; case showTipAtStartup: return "showTipAtStartup"; + default: + Q_ASSERT(false); + return QString::null; } - Q_ASSERT(false); - return QString::null; } QString getKey(const ints ID) { @@ -198,9 +197,10 @@ QString getKey(const ints ID) { return "configDialogWidth"; case tipNumber: return "tipNumber"; + default: + Q_ASSERT(false); + return QString::null; } - Q_ASSERT(false); - return QString::null; } QString getKey(const intLists ID) { @@ -214,7 +214,6 @@ QString getKey(const intLists ID) { case searchResultSplitterSizes: return "searchResultSplitterSizes"; } - Q_ASSERT(false); return QString::null; } @@ -230,18 +229,15 @@ QString getKey(const stringLists ID) { return "bookshelfOpenGroups"; case hiddenModules: return "hiddenModules"; + default: + Q_ASSERT(false); + return QString::null; } - Q_ASSERT(false); - return QString::null; } QString getKey(const stringMaps ID) { - switch (ID) { - case searchScopes: - return "SearchScopes"; - }; - Q_ASSERT(false); - return QString::null; + Q_ASSERT(ID == searchScopes); + return "SearchScopes"; } QString getKey(const CLanguageMgr::Language * const language) { @@ -251,19 +247,36 @@ QString getKey(const CLanguageMgr::Language * const language) { } // anonymous namespace -QString IntListToString(const QList<int> intList) { +QString IntListToString(const QList<int> &intList) { QStringList intStrings; - foreach(int i, intList) { + Q_FOREACH (int i, intList) { intStrings << QString::number(i); } return intStrings.join(","); } -QList<int> StringToIntList(const QString &intListString) { +QList<int> StringToIntList(const QString &intListString, + bool *ok, + QString::SplitBehavior splitBehavior) +{ QList<int> intList; - if (!intListString.isEmpty() && intListString.contains(',')) { - foreach(QString intString, intListString.split(',')) { - intList << intString.trimmed().toInt(); + if (ok != 0) { + *ok = true; + + if (!intListString.isEmpty()) { + Q_FOREACH (const QString &intString, intListString.split(',', splitBehavior)) { + int i = intString.trimmed().toInt(ok); + if (!(*ok)) + break; + + intList << i; + } + } + } else { + if (!intListString.isEmpty()) { + Q_FOREACH (const QString &intString, intListString.split(',', splitBehavior)) { + intList << intString.trimmed().toInt(); + } } } return intList; @@ -276,15 +289,14 @@ QString getDefault(const strings ID) { case language: return QLocale::system().name(); case displayStyle: - return CDisplayTemplateMgr::defaultTemplate(); + return CDisplayTemplateMgr::defaultTemplateName(); case bookshelfCurrentItem: + default: return QString::null; } - return QString::null; } QString getDefault(const modules ID) { - // CSwordBackend *b = CSwordBackend::instance()(); switch (ID) { case standardBible: return "KJV"; @@ -303,171 +315,103 @@ QString getDefault(const modules ID) { return "StrongsHebrew"; case standardGreekMorphLexicon: return "StrongsGreek"; + default: + return QString::null; } - - return QString::null; } bool getDefault(const bools ID) { switch (ID) { case firstSearchDialog: - return true; - case readOldBookmarks: - return false; - - case toolbar: - return true; + case showMainWindowToolbar: case mainIndex: - return true; case infoDisplay: - return true; - case autoTileVertical: - return true; - case autoTileHorizontal: - return false; - case autoTile: - return false; - case autoTabbed: - return false; - case autoCascade: - return false; - - case lineBreaks: - return false; case verseNumbers: - return true; - case logo: - return true; case autoDeleteOrphanedIndices: - return true; - case crashedLastTime: - return false; - case crashedTwoTimes: - return false; - case bookshelfShowHidden: - return false; - case allowNetworkConnection: - return false; - case showTextWindowHeaders: - return true; case showTextWindowNavigator: - return true; case showTextWindowModuleSelectorButtons: - return true; case showTextWindowToolButtons: - return true; case showFormatToolbarButtons: - return true; case showToolbarsInEachWindow: - return true; case showTipAtStartup: return true; + case readOldBookmarks: + case autoTileHorizontal: + case autoTile: + case autoTabbed: + case autoCascade: + case lineBreaks: + case crashedLastTime: + case crashedTwoTimes: + case bookshelfShowHidden: + case allowNetworkConnection: + default: + return false; } - return false; } int getDefault(const ints ID) { switch (ID) { + case bookshelfGrouping: + return BTModuleTreeItem::CatLangMod; + case searchType: + return Search::BtSearchOptionsArea::AndType; + case searchDialogHeight: + case magDelay: + return 400; + case searchDialogWidth: + case searchDialogX: + case searchDialogY: + return 200; case footnotes: - return int(true); case strongNumbers: - return int(true); case headings: - return int(true); case morphTags: - return int(true); case lemmas: - return int(true); case hebrewPoints: - return int(true); case hebrewCantillation: - return int(true); case greekAccents: - return int(true); - case textualVariants: - return int(false); case scriptureReferences: - return int(true); case morphSegmentation: - return int(true); - case bookshelfContentsX: - return 0; - case bookshelfContentsY: - return 0; - case magDelay: - return 400; - case bookshelfGrouping: - return BTModuleTreeItem::CatLangMod; - case searchDialogWidth: - return 200; - case searchDialogHeight: - return 400; - case searchDialogX: - return 200; - case searchDialogY: - return 200; - case searchType: - return Search::BtSearchOptionsArea::AndType; - case mainindexActiveTab: - return 0; - case installPathIndex: - return 0; case bookshelfPosX: - return 1; case bookshelfPosY: - return 1; case bookshelfHeight: - return 1; case bookshelfWidth: - return 1; case configDialogPosX: - return 1; case configDialogPosY: - return 1; case configDialogHeight: - return 1; case configDialogWidth: return 1; + case textualVariants: + case bookshelfContentsX: + case bookshelfContentsY: + case mainindexActiveTab: + case installPathIndex: case tipNumber: + default: return 0; } - return 0; } QList<int> getDefault(const intLists /*ID*/) { - QList<int> result; - /*switch ( ID ) { - case leftPaneSplitterSizes: break; - case mainSplitterSizes: break; - case searchMainSplitterSizes: break; - case searchResultSplitterSizes: break;*/ - return result; + return QList<int>(); } QStringList getDefault(const stringLists ID) { - switch (ID) { - case searchTexts: { - QStringList list; - list.append(QString::null); - return list; - } - case searchCompletionTexts: - return QStringList(); - case bookshelfOpenGroups: - return QStringList(); - case hiddenModules: - return QStringList(); - case searchModulesHistory: - return QStringList(); + if (ID == searchTexts) { + QStringList list; + list.append(QString::null); + return list; + } else { + return QStringList(); } - return QStringList(); } StringMap getDefault(const stringMaps ID) { - if (ID != searchScopes) return StringMap(); + Q_ASSERT(ID == searchScopes); StringMap map; map.insert(QObject::tr("Old testament"), QString("Gen - Mal")); @@ -487,7 +431,7 @@ StringMap getDefault(const stringMaps ID) { sword::ListKey list(vk.ParseVerseList(it.value().toLocal8Bit(), "Genesis 1:1", true)); QString data; for (int i(0); i < list.Count(); i++) { - data.append(QString::fromUtf8(list.GetElement(i)->getRangeText())); + data.append(QString::fromUtf8(list.getElement(i)->getRangeText())); data.append("; "); } map[it.key()] = data; @@ -498,186 +442,170 @@ StringMap getDefault(const stringMaps ID) { QFont &getDefault(const CLanguageMgr::Language * const) { // Language specific lookup of the font name - if (m_defaultFont) return *m_defaultFont; + if (m_defaultFont) + return *m_defaultFont; /// \todo make the font name and size a configuration option - // int fontSize = QWebSettings::globalSettings()->fontSize(QWebSettings::DefaultFontSize); - int fontSize(12); - QString fontName(QWebSettings::globalSettings()->fontFamily(QWebSettings::StandardFont)); - m_defaultFont = new QFont(fontName, fontSize); /// \todo there may be a mem leak here! + m_defaultFont = new QFont(); + m_defaultFont->setPointSize(12); return *m_defaultFont; } QString get(const strings ID) { - getConfig()->beginGroup("strings"); - QString result(getConfig()->value(getKey(ID), getDefault(ID)).toString()); - getConfig()->endGroup(); - return result; + QVariant v = getConfig()->value("strings/" + getKey(ID)); + if (v.isValid()) + return v.toString(); + + return getDefault(ID); } CSwordModuleInfo *get(const modules ID) { - getConfig()->beginGroup("modules"); - CSwordModuleInfo *result(CSwordBackend::instance()->findModuleByName( - getConfig()->value(getKey(ID), getDefault(ID)).toString() - )); - getConfig()->endGroup(); - return result; + QVariant v = getConfig()->value("modules/" + getKey(ID)); + CSwordBackend *b = CSwordBackend::instance(); + if (v.isValid()) + return b->findModuleByName(v.toString()); + + return b->findModuleByName(getDefault(ID)); } bool get(const bools ID) { - getConfig()->beginGroup("bools"); - bool result(getConfig()->value(getKey(ID), getDefault(ID)).toBool()); - getConfig()->endGroup(); - return result; + QVariant v = getConfig()->value("bools/" + getKey(ID)); + if (v.isValid()) + return v.toBool(); + + return getDefault(ID); } int get(const ints ID) { - getConfig()->beginGroup("ints"); - int result(getConfig()->value(getKey(ID), getDefault(ID)).toInt()); - getConfig()->endGroup(); - return result; + QVariant v = getConfig()->value("ints/" + getKey(ID)); + if (v.isValid()) + return v.toInt(); + + return getDefault(ID); } QList<int> get(const intLists ID) { - getConfig()->beginGroup("intlists"); - QList<int> result(StringToIntList( - getConfig()->value(getKey(ID), IntListToString(getDefault(ID))) - .toString() - )); - getConfig()->endGroup(); - return result; + QVariant v = getConfig()->value("intlists/" + getKey(ID)); + if (v.isValid()) { + bool ok; + QList<int> r = StringToIntList(v.toString(), &ok); + if (ok) + return r; + } + return getDefault(ID); } QStringList get(const stringLists ID) { - getConfig()->beginGroup("stringlists"); - QStringList result( - getConfig()->value(getKey(ID), getDefault(ID)).toStringList() - ); - getConfig()->endGroup(); - return result; + QVariant v = getConfig()->value("stringlists/" + getKey(ID)); + if (v.isValid()) + return v.toStringList(); + + return getDefault(ID); } StringMap get(const stringMaps ID) { + Q_ASSERT(ID == searchScopes); + + QSettings *s = getConfig(); + s->beginGroup(getKey(ID)); + const QStringList keys = s->childKeys(); + + if (keys.isEmpty()) { + s->endGroup(); + return getDefault(ID); + } + + /** + Make sure we return the scopes in the chosen language. saved + keys are in english. + */ StringMap map; + sword::VerseKey vk; + Q_FOREACH (const QString &key, keys) { + if (key.isEmpty()) + continue; - getConfig()->beginGroup(getKey(ID)); - QStringList keys(getConfig()->childKeys()); - - if (!keys.isEmpty()) { - switch (ID) { - case searchScopes: { - /** - Make sure we return the scopes in the chosen language. saved - keys are in english. - */ - sword::VerseKey vk; - foreach (QString key, keys) { - Q_ASSERT(!key.isEmpty()); - QByteArray b(getConfig()->value(key).toString().toUtf8()); - sword::ListKey list(vk.ParseVerseList(b, "Genesis 1:1", true)); - QString data; - for (int i(0); i < list.Count(); i++) { - data.append(QString::fromUtf8(list.GetElement(i)->getRangeText())); - data.append("; "); - } - map[key] = data; // Set the new data - } - } - default: - break; + QByteArray b = s->value(key).toString().toUtf8(); + sword::ListKey list(vk.ParseVerseList(b, "Genesis 1:1", true)); + QString data; + for (int i = 0; i < list.Count(); i++) { + data.append(QString::fromUtf8(list.getElement(i)->getRangeText())); + data.append("; "); } + map[key] = data; // Set the new data } - else { - map = getDefault(ID); - } - getConfig()->endGroup(); + s->endGroup(); return map; } FontSettingsPair get(const CLanguageMgr::Language * const language) { // Check the cache first: - FontCacheMap::const_iterator it(m_fontCache.find(language)); - if (it != m_fontCache.end()) return *it; - - FontSettingsPair settings; - - getConfig()->beginGroup("font standard settings"); - settings.first = getConfig()->value(getKey(language), false).toBool(); - getConfig()->endGroup(); - - getConfig()->beginGroup("fonts"); - QFont font; - if (settings.first) { - font.fromString(getConfig()->value(getKey(language), getDefault(language)).toString()); - } - else { - font = getDefault(language); + FontCacheMap::const_iterator it = m_fontCache.find(language); + if (it != m_fontCache.end()) + return *it; + + QSettings *s = getConfig(); + FontSettingsPair fontSettings; + fontSettings.first = s->value("font standard settings/" + getKey(language), false).toBool(); + + if (fontSettings.first) { + QVariant v = s->value("fonts/" + getKey(language)); + if (v.isValid()) { + fontSettings.second.fromString(v.toString()); + } else { + fontSettings.second = getDefault(language); + } + } else { + fontSettings.second = getDefault(language); } - settings.second = font; - getConfig()->endGroup(); // Cache the value: - m_fontCache.insert(language, settings); + m_fontCache.insert(language, fontSettings); - return settings; + return fontSettings; } void set(const strings ID, const QString &value) { -// KConfigGroup cg = getConfig()->group("strings"); -// cg.writeEntry(getKey(ID), value); - getConfig()->beginGroup("strings"); - getConfig()->setValue(getKey(ID), value); - getConfig()->endGroup(); + getConfig()->setValue("strings/" + getKey(ID), value); } void set(const modules ID, CSwordModuleInfo * const value) { -// KConfigGroup cg = getConfig()->group("modules"); -// cg.writeEntry(getKey(ID), value ? value->name() : QString::null); - getConfig()->beginGroup("modules"); - getConfig()->setValue(getKey(ID), value ? value->name() : QString::null); - getConfig()->endGroup(); + getConfig()->setValue("modules/" + getKey(ID), value ? value->name() : QString::null); } -void set(const modules ID, const QString& value) { +void set(const modules ID, const QString &value) { CSwordModuleInfo *module(CSwordBackend::instance()->findModuleByName(value)); if (module) { set(ID, module); } } -void set(const bools ID, const bool value) { - getConfig()->beginGroup("bools"); - getConfig()->setValue(getKey(ID), value); - getConfig()->endGroup(); +void set(const bools ID, const bool value) { + getConfig()->setValue("bools/" + getKey(ID), value); } void set(const ints ID, const int value) { - getConfig()->beginGroup("ints"); - getConfig()->setValue(getKey(ID), value); - getConfig()->endGroup(); + getConfig()->setValue("ints/" + getKey(ID), value); } -void set(const intLists ID, const QList<int> value) { - getConfig()->beginGroup("intlists"); - getConfig()->setValue(getKey(ID), IntListToString(value)); - getConfig()->endGroup(); +void set(const intLists ID, const QList<int> &value) { + getConfig()->setValue("intlists/" + getKey(ID), IntListToString(value)); } -void set(const stringLists ID, const QStringList value) { - getConfig()->beginGroup("stringlists"); - getConfig()->setValue(getKey(ID), value); - getConfig()->endGroup(); +void set(const stringLists ID, const QStringList &value) { + getConfig()->setValue("stringlists/" + getKey(ID), value); } -void set(const stringMaps ID, const StringMap value) { +void set(const stringMaps ID, const StringMap &value) { typedef StringMap::ConstIterator SMCI; using namespace sword; - getConfig()->beginGroup(getKey(ID)); + QSettings *s = getConfig(); + s->beginGroup(getKey(ID)); // Clear all entries of this group to make sure old stuff gets removed: - getConfig()->remove(""); + s->remove(""); switch (ID) { case searchScopes: { @@ -690,35 +618,34 @@ void set(const stringMaps ID, const StringMap value) { QString data; ListKey list(vk.ParseVerseList(it.value().toUtf8(), "Genesis 1:1", true)); for (int i(0); i < list.Count(); i++) { - VerseKey *range(dynamic_cast<VerseKey*>(list.GetElement(i))); + VerseKey *range(dynamic_cast<VerseKey*>(list.getElement(i))); if (range) { range->setLocale("en"); data.append(QString::fromUtf8( range->getRangeText() )); data.append(";"); } } - getConfig()->setValue(it.key(), data); + s->setValue(it.key(), data); } break; } default: { for (SMCI it(value.begin()); it != value.end(); it++) { - getConfig()->setValue(it.key(), it.value()); + s->setValue(it.key(), it.value()); } break; } } - getConfig()->endGroup(); + s->endGroup(); } void set(const CLanguageMgr::Language * const language, - const FontSettingsPair& value) { - getConfig()->beginGroup("fonts"); - getConfig()->setValue(getKey(language), value.second.toString()); - getConfig()->endGroup(); - getConfig()->beginGroup("font standard settings"); - getConfig()->setValue(getKey(language), value.first); - getConfig()->endGroup(); + const FontSettingsPair& value) +{ + QSettings *s = getConfig(); + QString lang = getKey(language); + s->setValue("fonts/" + lang, value.second.toString()); + s->setValue("font standard settings/" + lang, value.first); // Remove language from the cache: m_fontCache.remove(language); @@ -751,9 +678,9 @@ FilterOptions getFilterOptionDefaults() { } void setupAccelSettings(const keys type, - BtActionCollection * const actionCollection) { - qDebug() << "CBTConfig::setupAccelSettings begin"; - QString groupName; + BtActionCollection * const actionCollection) +{ + const char *groupName =""; switch (type) { case allWindows: groupName = "Displaywindow shortcuts"; @@ -780,18 +707,15 @@ void setupAccelSettings(const keys type, groupName = "Application shortcuts"; break; } - qDebug() << groupName; - Q_ASSERT(getConfig()); actionCollection->setConfigGroup(groupName); actionCollection->readSettings(); - qDebug() << "CBTConfig::setupAccelSettings end"; } void saveAccelSettings(const keys type, - BtActionCollection * const actionCollection) { - qDebug() << "CBTConfig::saveAccelSettings begin"; - QString groupName; + BtActionCollection * const actionCollection) +{ + const char *groupName =""; switch (type) { case allWindows: groupName = "Displaywindow shortcuts"; @@ -821,22 +745,22 @@ void saveAccelSettings(const keys type, actionCollection->setConfigGroup(groupName); actionCollection->writeSettings(); - qDebug() << "CBTConfig::saveAccelSettings end"; } QString getModuleEncryptionKey(const QString &module) { Q_ASSERT(!module.isEmpty()); - getConfig()->beginGroup("Module keys"); - QString result(getConfig()->value(module, QVariant(QString::null)).toString()); - getConfig()->endGroup(); - return result; + static const QString nullString; + + QVariant v = getConfig()->value("Module keys/" + module); + if (v.isValid()) + return v.toString(); + + return nullString; } void setModuleEncryptionKey(const QString &module, const QString &key) { - getConfig()->beginGroup("Module keys"); - getConfig()->setValue(module, key); - getConfig()->endGroup(); + getConfig()->setValue("Module keys/" + module, key); } QSettings *getConfig() { |