Refactor Config.

Replaces all string configuration options with enum types
that can be checked by the compiler. This prevents spelling
errors, in-place configuration definitions, and inconsistent
default values. The default value config getter signature was
removed in favour of consistently and centrally default-initialised
configuration values.

Individual default values were adjusted for better security,
such as the default password length, which was increased from
16 characters to 32.

The already existing config option deprecation map was extended
by a general migration procedure using configuration versioning.

Settings were split into Roaming and Local settings, which
go to their respective AppData locations on Windows.

Fixes #2574
Fixes #2193
This commit is contained in:
Janek Bevendorff 2020-04-26 01:31:38 +02:00
parent 5add01243d
commit 596d2cf425
45 changed files with 1002 additions and 638 deletions

View file

@ -34,62 +34,62 @@ BrowserSettings* BrowserSettings::instance()
bool BrowserSettings::isEnabled()
{
return config()->get("Browser/Enabled", false).toBool();
return config()->get(Config::Browser_Enabled).toBool();
}
void BrowserSettings::setEnabled(bool enabled)
{
config()->set("Browser/Enabled", enabled);
config()->set(Config::Browser_Enabled, enabled);
}
bool BrowserSettings::showNotification()
{
return config()->get("Browser/ShowNotification", true).toBool();
return config()->get(Config::Browser_ShowNotification).toBool();
}
void BrowserSettings::setShowNotification(bool showNotification)
{
config()->set("Browser/ShowNotification", showNotification);
config()->set(Config::Browser_ShowNotification, showNotification);
}
bool BrowserSettings::bestMatchOnly()
{
return config()->get("Browser/BestMatchOnly", false).toBool();
return config()->get(Config::Browser_BestMatchOnly).toBool();
}
void BrowserSettings::setBestMatchOnly(bool bestMatchOnly)
{
config()->set("Browser/BestMatchOnly", bestMatchOnly);
config()->set(Config::Browser_BestMatchOnly, bestMatchOnly);
}
bool BrowserSettings::unlockDatabase()
{
return config()->get("Browser/UnlockDatabase", true).toBool();
return config()->get(Config::Browser_UnlockDatabase).toBool();
}
void BrowserSettings::setUnlockDatabase(bool unlockDatabase)
{
config()->set("Browser/UnlockDatabase", unlockDatabase);
config()->set(Config::Browser_UnlockDatabase, unlockDatabase);
}
bool BrowserSettings::matchUrlScheme()
{
return config()->get("Browser/MatchUrlScheme", true).toBool();
return config()->get(Config::Browser_MatchUrlScheme).toBool();
}
void BrowserSettings::setMatchUrlScheme(bool matchUrlScheme)
{
config()->set("Browser/MatchUrlScheme", matchUrlScheme);
config()->set(Config::Browser_MatchUrlScheme, matchUrlScheme);
}
bool BrowserSettings::sortByUsername()
{
return config()->get("Browser/SortByUsername", false).toBool();
return config()->get(Config::Browser_SortByUsername).toBool();
}
void BrowserSettings::setSortByUsername(bool sortByUsername)
{
config()->set("Browser/SortByUsername", sortByUsername);
config()->set(Config::Browser_SortByUsername, sortByUsername);
}
bool BrowserSettings::sortByTitle()
@ -104,82 +104,82 @@ void BrowserSettings::setSortByTitle(bool sortByUsertitle)
bool BrowserSettings::alwaysAllowAccess()
{
return config()->get("Browser/AlwaysAllowAccess", false).toBool();
return config()->get(Config::Browser_AlwaysAllowAccess).toBool();
}
void BrowserSettings::setAlwaysAllowAccess(bool alwaysAllowAccess)
{
config()->set("Browser/AlwaysAllowAccess", alwaysAllowAccess);
config()->set(Config::Browser_AlwaysAllowAccess, alwaysAllowAccess);
}
bool BrowserSettings::alwaysAllowUpdate()
{
return config()->get("Browser/AlwaysAllowUpdate", false).toBool();
return config()->get(Config::Browser_AlwaysAllowUpdate).toBool();
}
void BrowserSettings::setAlwaysAllowUpdate(bool alwaysAllowUpdate)
{
config()->set("Browser/AlwaysAllowUpdate", alwaysAllowUpdate);
config()->set(Config::Browser_AlwaysAllowUpdate, alwaysAllowUpdate);
}
bool BrowserSettings::httpAuthPermission()
{
return config()->get("Browser/HttpAuthPermission", false).toBool();
return config()->get(Config::Browser_HttpAuthPermission).toBool();
}
void BrowserSettings::setHttpAuthPermission(bool httpAuthPermission)
{
config()->set("Browser/HttpAuthPermission", httpAuthPermission);
config()->set(Config::Browser_HttpAuthPermission, httpAuthPermission);
}
bool BrowserSettings::searchInAllDatabases()
{
return config()->get("Browser/SearchInAllDatabases", false).toBool();
return config()->get(Config::Browser_SearchInAllDatabases).toBool();
}
void BrowserSettings::setSearchInAllDatabases(bool searchInAllDatabases)
{
config()->set("Browser/SearchInAllDatabases", searchInAllDatabases);
config()->set(Config::Browser_SearchInAllDatabases, searchInAllDatabases);
}
bool BrowserSettings::supportKphFields()
{
return config()->get("Browser/SupportKphFields", true).toBool();
return config()->get(Config::Browser_SupportKphFields).toBool();
}
void BrowserSettings::setSupportKphFields(bool supportKphFields)
{
config()->set("Browser/SupportKphFields", supportKphFields);
config()->set(Config::Browser_SupportKphFields, supportKphFields);
}
bool BrowserSettings::noMigrationPrompt()
{
return config()->get("Browser/NoMigrationPrompt", false).toBool();
return config()->get(Config::Browser_NoMigrationPrompt).toBool();
}
void BrowserSettings::setNoMigrationPrompt(bool prompt)
{
config()->set("Browser/NoMigrationPrompt", prompt);
config()->set(Config::Browser_NoMigrationPrompt, prompt);
}
bool BrowserSettings::supportBrowserProxy()
{
return config()->get("Browser/SupportBrowserProxy", true).toBool();
return config()->get(Config::Browser_SupportBrowserProxy).toBool();
}
void BrowserSettings::setSupportBrowserProxy(bool enabled)
{
config()->set("Browser/SupportBrowserProxy", enabled);
config()->set(Config::Browser_SupportBrowserProxy, enabled);
}
bool BrowserSettings::useCustomProxy()
{
return config()->get("Browser/UseCustomProxy", false).toBool();
return config()->get(Config::Browser_UseCustomProxy).toBool();
}
void BrowserSettings::setUseCustomProxy(bool enabled)
{
config()->set("Browser/UseCustomProxy", enabled);
config()->set(Config::Browser_UseCustomProxy, enabled);
}
QString BrowserSettings::customProxyLocation()
@ -187,32 +187,32 @@ QString BrowserSettings::customProxyLocation()
if (!useCustomProxy()) {
return QString();
}
return config()->get("Browser/CustomProxyLocation", "").toString();
return config()->get(Config::Browser_CustomProxyLocation).toString();
}
void BrowserSettings::setCustomProxyLocation(const QString& location)
{
config()->set("Browser/CustomProxyLocation", location);
config()->set(Config::Browser_CustomProxyLocation, location);
}
bool BrowserSettings::updateBinaryPath()
{
return config()->get("Browser/UpdateBinaryPath", true).toBool();
return config()->get(Config::Browser_UpdateBinaryPath).toBool();
}
void BrowserSettings::setUpdateBinaryPath(bool enabled)
{
config()->set("Browser/UpdateBinaryPath", enabled);
config()->set(Config::Browser_UpdateBinaryPath, enabled);
}
bool BrowserSettings::allowExpiredCredentials()
{
return config()->get("Browser/AllowExpiredCredentials", false).toBool();
return config()->get(Config::Browser_AllowExpiredCredentials).toBool();
}
void BrowserSettings::setAllowExpiredCredentials(bool enabled)
{
config()->set("Browser/AllowExpiredCredentials", enabled);
config()->set(Config::Browser_AllowExpiredCredentials, enabled);
}
bool BrowserSettings::chromeSupport()
@ -294,202 +294,202 @@ void BrowserSettings::setEdgeSupport(bool enabled)
bool BrowserSettings::passwordUseNumbers()
{
return config()->get("generator/Numbers", PasswordGenerator::DefaultNumbers).toBool();
return config()->get(Config::PasswordGenerator_Numbers).toBool();
}
void BrowserSettings::setPasswordUseNumbers(bool useNumbers)
{
config()->set("generator/Numbers", useNumbers);
config()->set(Config::PasswordGenerator_Numbers, useNumbers);
}
bool BrowserSettings::passwordUseLowercase()
{
return config()->get("generator/LowerCase", PasswordGenerator::DefaultLower).toBool();
return config()->get(Config::PasswordGenerator_LowerCase).toBool();
}
void BrowserSettings::setPasswordUseLowercase(bool useLowercase)
{
config()->set("generator/LowerCase", useLowercase);
config()->set(Config::PasswordGenerator_LowerCase, useLowercase);
}
bool BrowserSettings::passwordUseUppercase()
{
return config()->get("generator/UpperCase", PasswordGenerator::DefaultUpper).toBool();
return config()->get(Config::PasswordGenerator_UpperCase).toBool();
}
void BrowserSettings::setPasswordUseUppercase(bool useUppercase)
{
config()->set("generator/UpperCase", useUppercase);
config()->set(Config::PasswordGenerator_UpperCase, useUppercase);
}
bool BrowserSettings::passwordUseSpecial()
{
return config()->get("generator/SpecialChars", PasswordGenerator::DefaultSpecial).toBool();
return config()->get(Config::PasswordGenerator_SpecialChars).toBool();
}
void BrowserSettings::setPasswordUseSpecial(bool useSpecial)
{
config()->set("generator/SpecialChars", useSpecial);
config()->set(Config::PasswordGenerator_SpecialChars, useSpecial);
}
bool BrowserSettings::passwordUseBraces()
{
return config()->get("generator/Braces", PasswordGenerator::DefaultBraces).toBool();
return config()->get(Config::PasswordGenerator_Braces).toBool();
}
void BrowserSettings::setPasswordUseBraces(bool useBraces)
{
config()->set("generator/Braces", useBraces);
config()->set(Config::PasswordGenerator_Braces, useBraces);
}
bool BrowserSettings::passwordUsePunctuation()
{
return config()->get("generator/Punctuation", PasswordGenerator::DefaultQuotes).toBool();
return config()->get(Config::PasswordGenerator_Punctuation).toBool();
}
void BrowserSettings::setPasswordUsePunctuation(bool usePunctuation)
{
config()->set("generator/Punctuation", usePunctuation);
config()->set(Config::PasswordGenerator_Punctuation, usePunctuation);
}
bool BrowserSettings::passwordUseQuotes()
{
return config()->get("generator/Quotes", PasswordGenerator::DefaultQuotes).toBool();
return config()->get(Config::PasswordGenerator_Quotes).toBool();
}
void BrowserSettings::setPasswordUseQuotes(bool useQuotes)
{
config()->set("generator/Quotes", useQuotes);
config()->set(Config::PasswordGenerator_Quotes, useQuotes);
}
bool BrowserSettings::passwordUseDashes()
{
return config()->get("generator/Dashes", PasswordGenerator::DefaultDashes).toBool();
return config()->get(Config::PasswordGenerator_Dashes).toBool();
}
void BrowserSettings::setPasswordUseDashes(bool useDashes)
{
config()->set("generator/Dashes", useDashes);
config()->set(Config::PasswordGenerator_Dashes, useDashes);
}
bool BrowserSettings::passwordUseMath()
{
return config()->get("generator/Math", PasswordGenerator::DefaultMath).toBool();
return config()->get(Config::PasswordGenerator_Math).toBool();
}
void BrowserSettings::setPasswordUseMath(bool useMath)
{
config()->set("generator/Math", useMath);
config()->set(Config::PasswordGenerator_Math, useMath);
}
bool BrowserSettings::passwordUseLogograms()
{
return config()->get("generator/Logograms", PasswordGenerator::DefaultLogograms).toBool();
return config()->get(Config::PasswordGenerator_Logograms).toBool();
}
void BrowserSettings::setPasswordUseLogograms(bool useLogograms)
{
config()->set("generator/Logograms", useLogograms);
config()->set(Config::PasswordGenerator_Logograms, useLogograms);
}
bool BrowserSettings::passwordUseEASCII()
{
return config()->get("generator/EASCII", PasswordGenerator::DefaultEASCII).toBool();
return config()->get(Config::PasswordGenerator_EASCII).toBool();
}
void BrowserSettings::setPasswordUseEASCII(bool useEASCII)
{
config()->set("generator/EASCII", useEASCII);
config()->set(Config::PasswordGenerator_EASCII, useEASCII);
}
bool BrowserSettings::advancedMode()
{
return config()->get("generator/AdvancedMode", PasswordGenerator::DefaultAdvancedMode).toBool();
return config()->get(Config::PasswordGenerator_AdvancedMode).toBool();
}
void BrowserSettings::setAdvancedMode(bool advancedMode)
{
config()->set("generator/AdvancedMode", advancedMode);
config()->set(Config::PasswordGenerator_AdvancedMode, advancedMode);
}
QString BrowserSettings::passwordAdditionalChars()
{
return config()->get("generator/AdditionalChars", PasswordGenerator::DefaultAdditionalChars).toString();
return config()->get(Config::PasswordGenerator_AdditionalChars).toString();
}
void BrowserSettings::setPasswordAdditionalChars(const QString& chars)
{
config()->set("generator/AdditionalChars", chars);
config()->set(Config::PasswordGenerator_AdditionalChars, chars);
}
QString BrowserSettings::passwordExcludedChars()
{
return config()->get("generator/ExcludedChars", PasswordGenerator::DefaultExcludedChars).toString();
return config()->get(Config::PasswordGenerator_ExcludedChars).toString();
}
void BrowserSettings::setPasswordExcludedChars(const QString& chars)
{
config()->set("generator/ExcludedChars", chars);
config()->set(Config::PasswordGenerator_ExcludedChars, chars);
}
int BrowserSettings::passPhraseWordCount()
{
return config()->get("generator/WordCount", PassphraseGenerator::DefaultWordCount).toInt();
return config()->get(Config::PasswordGenerator_WordCount).toInt();
}
void BrowserSettings::setPassPhraseWordCount(int wordCount)
{
config()->set("generator/WordCount", wordCount);
config()->set(Config::PasswordGenerator_WordCount, wordCount);
}
QString BrowserSettings::passPhraseWordSeparator()
{
return config()->get("generator/WordSeparator", PassphraseGenerator::DefaultSeparator).toString();
return config()->get(Config::PasswordGenerator_WordSeparator).toString();
}
void BrowserSettings::setPassPhraseWordSeparator(const QString& separator)
{
config()->set("generator/WordSeparator", separator);
config()->set(Config::PasswordGenerator_WordSeparator, separator);
}
int BrowserSettings::generatorType()
{
return config()->get("generator/Type", 0).toInt();
return config()->get(Config::PasswordGenerator_Type).toInt();
}
void BrowserSettings::setGeneratorType(int type)
{
config()->set("generator/Type", type);
config()->set(Config::PasswordGenerator_Type, type);
}
bool BrowserSettings::passwordEveryGroup()
{
return config()->get("generator/EnsureEvery", PasswordGenerator::DefaultFromEveryGroup).toBool();
return config()->get(Config::PasswordGenerator_EnsureEvery).toBool();
}
void BrowserSettings::setPasswordEveryGroup(bool everyGroup)
{
config()->get("generator/EnsureEvery", everyGroup);
config()->set(Config::PasswordGenerator_EnsureEvery, everyGroup);
}
bool BrowserSettings::passwordExcludeAlike()
{
return config()->get("generator/ExcludeAlike", PasswordGenerator::DefaultLookAlike).toBool();
return config()->get(Config::PasswordGenerator_ExcludeAlike).toBool();
}
void BrowserSettings::setPasswordExcludeAlike(bool excludeAlike)
{
config()->set("generator/ExcludeAlike", excludeAlike);
config()->set(Config::PasswordGenerator_ExcludeAlike, excludeAlike);
}
int BrowserSettings::passwordLength()
{
return config()->get("generator/Length", PasswordGenerator::DefaultLength).toInt();
return config()->get(Config::PasswordGenerator_Length).toInt();
}
void BrowserSettings::setPasswordLength(int length)
{
config()->set("generator/Length", length);
config()->set(Config::PasswordGenerator_Length, length);
m_passwordGenerator.setLength(length);
}