AusweisApp2/src/settings/GeneralSettings.cpp

313 lines
8.0 KiB
C++
Raw Normal View History

2017-07-03 09:30:10 +02:00
/*!
* \brief Contains the method definitions of the GeneralSettings class.
*
2018-03-28 15:10:51 +02:00
* \copyright Copyright (c) 2014-2018 Governikus GmbH & Co. KG, Germany
2017-07-03 09:30:10 +02:00
*/
#include "GeneralSettings.h"
2017-12-20 14:54:05 +01:00
#include "AutoStart.h"
2017-07-03 09:30:10 +02:00
#include <QCoreApplication>
2018-03-28 15:10:51 +02:00
#include <QLoggingCategory>
2017-07-03 09:30:10 +02:00
#include <QtConcurrent/QtConcurrentRun>
using namespace governikus;
2018-03-28 15:10:51 +02:00
Q_DECLARE_LOGGING_CATEGORY(settings)
2017-12-20 14:54:05 +01:00
namespace
{
SETTINGS_NAME(SETTINGS_NAME_PERSISTENT_SETTINGS_VERSION, "persistentSettingsVersion")
SETTINGS_NAME(SETTINGS_NAME_SKIP_VERSION, "skipVersion")
SETTINGS_NAME(SETTINGS_NAME_AUTO_CLOSE_WINDOW, "autoCloseWindow")
SETTINGS_NAME(SETTINGS_NAME_SHOW_SETUP_ASSISTANT, "showSetupAssistant")
SETTINGS_NAME(SETTINGS_NAME_REMIND_USER_TO_CLOSE, "remindToClose")
SETTINGS_NAME(SETTINGS_NAME_TRANSPORT_PIN_REMINDER, "transportPinReminder")
SETTINGS_NAME(SETTINGS_NAME_DEVELOPER_MODE, "developerMode")
SETTINGS_NAME(SETTINGS_NAME_USE_SELF_AUTH_TEST_URI, "selfauthTestUri")
SETTINGS_NAME(SETTINGS_NAME_LANGUAGE, "language")
SETTINGS_NAME(SETTINGS_GROUP_NAME_COMMON, "common")
SETTINGS_NAME(SETTINGS_NAME_AUTO, "autoUpdateCheck")
SETTINGS_NAME(SETTINGS_NAME_KEYLESS_PASSWORD, "keylessPassword")
2018-03-28 15:10:51 +02:00
SETTINGS_NAME(SETTINGS_NAME_LAST_READER_PLUGIN_TYPE, "lastTechnology")
2017-12-20 14:54:05 +01:00
}
2017-07-03 09:30:10 +02:00
GeneralSettings::GeneralSettings()
: AbstractSettings()
2017-12-20 14:54:05 +01:00
, mStoreGeneral(getStore())
, mStoreCommon(getStore())
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
{
// With 1.14.0 the reader and provider are no longer stored in the settings
mStoreCommon->beginGroup(QStringLiteral("readers"));
mStoreCommon->remove(QString()); // remove the whole group
mStoreCommon->endGroup();
mStoreCommon->beginGroup(QStringLiteral("providers"));
mStoreCommon->remove(QString()); // remove the whole group
mStoreCommon->endGroup();
}
mStoreCommon->beginGroup(SETTINGS_GROUP_NAME_COMMON());
2017-07-03 09:30:10 +02:00
// QFuture.result() crashes under linux and win if uninitalized
mAutoStart = QtConcurrent::run([] {
2017-12-20 14:54:05 +01:00
return !GENERAL_SETTINGS_DEFAULT_AUTOSTART;
2017-07-03 09:33:28 +02:00
});
2017-07-03 09:30:10 +02:00
mAutoStart.waitForFinished();
// Check if the key "autoCloseWindow" (introduced in changeset 199210b0b20c)
// does not yet exist to detect a new installation. This key was the first one
// in the settings general group.
2017-12-20 14:54:05 +01:00
const bool isNewInstallation = !mStoreGeneral->allKeys().contains(SETTINGS_NAME_AUTO_CLOSE_WINDOW());
2017-07-03 09:30:10 +02:00
if (isNewInstallation)
{
2017-12-20 14:54:05 +01:00
mStoreGeneral->setValue(SETTINGS_NAME_AUTO_CLOSE_WINDOW(), true);
2017-07-03 09:30:10 +02:00
setAutoStart(GENERAL_SETTINGS_DEFAULT_AUTOSTART);
2017-12-20 14:54:05 +01:00
setTransportPinReminder(true);
mStoreGeneral->sync();
2017-07-03 09:30:10 +02:00
}
2017-12-20 14:54:05 +01:00
#ifdef QT_NO_DEBUG
// Iterate autostart entries in order to remove broken login items on macos.
// This process might take up to 15s per entry.
mAutoStart = QtConcurrent::run(AutoStart::enabled);
2017-07-03 09:30:10 +02:00
#endif
}
2017-12-20 14:54:05 +01:00
GeneralSettings::~GeneralSettings()
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
mAutoStart.waitForFinished();
2017-07-03 09:30:10 +02:00
}
void GeneralSettings::save()
{
2017-12-20 14:54:05 +01:00
mStoreGeneral->setValue(SETTINGS_NAME_PERSISTENT_SETTINGS_VERSION(), QCoreApplication::applicationVersion());
2017-07-03 09:30:10 +02:00
2017-12-20 14:54:05 +01:00
mStoreGeneral->sync();
mStoreCommon->sync();
2017-07-03 09:30:10 +02:00
}
2017-12-20 14:54:05 +01:00
bool GeneralSettings::isAutoStart() const
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
return mAutoStart;
2017-07-03 09:30:10 +02:00
}
2017-12-20 14:54:05 +01:00
void GeneralSettings::setAutoStart(bool pAutoStart)
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
if (pAutoStart != mAutoStart)
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
#ifdef QT_NO_DEBUG
AutoStart::set(pAutoStart);
#endif
mAutoStart.waitForFinished();
mAutoStart = QtConcurrent::run([pAutoStart] {
return pAutoStart;
});
Q_EMIT fireSettingsChanged();
2017-07-03 09:30:10 +02:00
}
}
2017-12-20 14:54:05 +01:00
const QString GeneralSettings::getPersistentSettingsVersion() const
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
return mStoreGeneral->value(SETTINGS_NAME_PERSISTENT_SETTINGS_VERSION(), QString()).toString();
2017-07-03 09:30:10 +02:00
}
2017-12-20 14:54:05 +01:00
QString GeneralSettings::getSkipVersion()
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
return mStoreGeneral->value(SETTINGS_NAME_SKIP_VERSION(), QString()).toString();
}
2017-07-03 09:30:10 +02:00
2017-12-20 14:54:05 +01:00
void GeneralSettings::skipVersion(const QString& pVersion)
{
mStoreGeneral->setValue(SETTINGS_NAME_SKIP_VERSION(), pVersion);
2017-07-03 09:30:10 +02:00
}
bool GeneralSettings::isAutoCloseWindowAfterAuthentication() const
{
2017-12-20 14:54:05 +01:00
return mStoreGeneral->value(SETTINGS_NAME_AUTO_CLOSE_WINDOW(), true).toBool();
2017-07-03 09:30:10 +02:00
}
void GeneralSettings::setAutoCloseWindowAfterAuthentication(bool pAutoClose)
{
2017-12-20 14:54:05 +01:00
if (pAutoClose != isAutoCloseWindowAfterAuthentication())
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
mStoreGeneral->setValue(SETTINGS_NAME_AUTO_CLOSE_WINDOW(), pAutoClose);
2017-07-03 09:30:10 +02:00
Q_EMIT fireSettingsChanged();
}
}
2017-12-20 14:54:05 +01:00
bool GeneralSettings::isShowSetupAssistant() const
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
return mStoreGeneral->value(SETTINGS_NAME_SHOW_SETUP_ASSISTANT(), true).toBool();
2017-07-03 09:30:10 +02:00
}
2017-12-20 14:54:05 +01:00
void GeneralSettings::setShowSetupAssistant(bool pShowSetupAssistant)
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
if (pShowSetupAssistant != isShowSetupAssistant())
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
mStoreGeneral->setValue(SETTINGS_NAME_SHOW_SETUP_ASSISTANT(), pShowSetupAssistant);
2017-07-03 09:30:10 +02:00
Q_EMIT fireSettingsChanged();
}
}
2017-12-20 14:54:05 +01:00
bool GeneralSettings::isRemindUserToClose() const
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
return mStoreGeneral->value(SETTINGS_NAME_REMIND_USER_TO_CLOSE(), true).toBool();
2017-07-03 09:30:10 +02:00
}
2017-12-20 14:54:05 +01:00
void GeneralSettings::setRemindUserToClose(bool pRemindUser)
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
if (pRemindUser != isRemindUserToClose())
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
mStoreGeneral->setValue(SETTINGS_NAME_REMIND_USER_TO_CLOSE(), pRemindUser);
2017-07-03 09:30:10 +02:00
Q_EMIT fireSettingsChanged();
}
}
2017-12-20 14:54:05 +01:00
bool GeneralSettings::isTransportPinReminder() const
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
// The standard value should be true but we need to set it to false for backwards
// compatibility. It is set to true in the constructor if we have a new
// installation. The the standard value used in this function will only be
// used if the user upgrades from AusweisApp 1.6.3 or an older version.
return mStoreGeneral->value(SETTINGS_NAME_TRANSPORT_PIN_REMINDER(), false).toBool();
2017-07-03 09:30:10 +02:00
}
2017-12-20 14:54:05 +01:00
void GeneralSettings::setTransportPinReminder(bool pTransportPinReminder)
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
if (pTransportPinReminder != isTransportPinReminder())
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
mStoreGeneral->setValue(SETTINGS_NAME_TRANSPORT_PIN_REMINDER(), pTransportPinReminder);
2017-07-03 09:30:10 +02:00
Q_EMIT fireSettingsChanged();
}
}
2017-12-20 14:54:05 +01:00
bool GeneralSettings::isDeveloperMode() const
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
const bool developerMode = mStoreGeneral->value(SETTINGS_NAME_DEVELOPER_MODE(), false).toBool();
if (developerMode && appIsBackgroundService())
2017-07-03 09:30:10 +02:00
{
2018-03-28 15:10:51 +02:00
qCDebug(settings) << "Running as a background service. Developer mode is disallowed.";
2017-12-20 14:54:05 +01:00
return false;
2017-07-03 09:30:10 +02:00
}
2017-12-20 14:54:05 +01:00
return developerMode;
2017-07-03 09:30:10 +02:00
}
2017-12-20 14:54:05 +01:00
void GeneralSettings::setDeveloperMode(bool pEnabled)
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
if (pEnabled != isDeveloperMode())
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
mStoreGeneral->setValue(SETTINGS_NAME_DEVELOPER_MODE(), pEnabled);
2017-07-03 09:30:10 +02:00
Q_EMIT fireSettingsChanged();
}
}
2017-12-20 14:54:05 +01:00
bool GeneralSettings::useSelfAuthTestUri() const
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
return mStoreGeneral->value(SETTINGS_NAME_USE_SELF_AUTH_TEST_URI(), false).toBool();
2017-07-03 09:30:10 +02:00
}
2017-12-20 14:54:05 +01:00
void GeneralSettings::setUseSelfauthenticationTestUri(bool pUse)
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
if (pUse != useSelfAuthTestUri())
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
mStoreGeneral->setValue(SETTINGS_NAME_USE_SELF_AUTH_TEST_URI(), pUse);
2017-07-03 09:30:10 +02:00
Q_EMIT fireSettingsChanged();
}
}
2017-12-20 14:54:05 +01:00
QLocale::Language GeneralSettings::getLanguage() const
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
const QString loadedLanguage = mStoreGeneral->value(SETTINGS_NAME_LANGUAGE(), QString()).toString();
if (loadedLanguage.isEmpty())
2017-07-03 09:33:28 +02:00
{
2017-12-20 14:54:05 +01:00
return QLocale::C;
2017-07-03 09:33:28 +02:00
}
2017-12-20 14:54:05 +01:00
return QLocale(loadedLanguage).language();
2017-07-03 09:30:10 +02:00
}
2017-12-20 14:54:05 +01:00
void GeneralSettings::setLanguage(const QLocale::Language pLanguage)
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
if (pLanguage != getLanguage())
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
mStoreGeneral->setValue(SETTINGS_NAME_LANGUAGE(), pLanguage == QLocale::C ? QString() : QLocale(pLanguage).bcp47Name());
2017-07-03 09:30:10 +02:00
Q_EMIT fireSettingsChanged();
}
}
2017-12-20 14:54:05 +01:00
bool GeneralSettings::isAutoUpdateCheck() const
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
return mStoreCommon->value(SETTINGS_NAME_AUTO(), true).toBool();
2017-07-03 09:30:10 +02:00
}
2017-12-20 14:54:05 +01:00
void GeneralSettings::setAutoUpdateCheck(bool pAutoCheck)
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
if (pAutoCheck != isAutoUpdateCheck())
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
mStoreCommon->setValue(SETTINGS_NAME_AUTO(), pAutoCheck);
2017-07-03 09:30:10 +02:00
Q_EMIT fireSettingsChanged();
}
}
2017-07-03 09:33:28 +02:00
2017-12-20 14:54:05 +01:00
bool GeneralSettings::isUseScreenKeyboard() const
2017-07-03 09:33:28 +02:00
{
2017-12-20 14:54:05 +01:00
return mStoreCommon->value(SETTINGS_NAME_KEYLESS_PASSWORD(), false).toBool();
2017-07-03 09:33:28 +02:00
}
2017-12-20 14:54:05 +01:00
void GeneralSettings::setUseScreenKeyboard(bool pKeylessPassword)
2017-07-03 09:33:28 +02:00
{
2017-12-20 14:54:05 +01:00
if (pKeylessPassword != isUseScreenKeyboard())
{
mStoreCommon->setValue(SETTINGS_NAME_KEYLESS_PASSWORD(), pKeylessPassword);
Q_EMIT fireSettingsChanged();
}
2017-07-03 09:33:28 +02:00
}
2018-03-28 15:10:51 +02:00
QString GeneralSettings::getLastReaderPluginType() const
{
return mStoreGeneral->value(SETTINGS_NAME_LAST_READER_PLUGIN_TYPE(), QString()).toString();
}
void GeneralSettings::setLastReaderPluginType(const QString& pLastReaderPluginType)
{
if (pLastReaderPluginType != getLastReaderPluginType())
{
mStoreGeneral->setValue(SETTINGS_NAME_LAST_READER_PLUGIN_TYPE(), pLastReaderPluginType);
Q_EMIT fireSettingsChanged();
}
}