AusweisApp2/src/settings/PreVerificationSettings.cpp

100 lines
2.2 KiB
C++
Raw Normal View History

2017-07-03 09:30:10 +02:00
/*!
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 "PreVerificationSettings.h"
using namespace governikus;
2017-12-20 14:54:05 +01:00
namespace
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
SETTINGS_NAME(SETTINGS_GROUP_NAME_PREVERIFICATION, "preverification")
SETTINGS_NAME(SETTINGS_NAME_ENABLED, "enabled")
SETTINGS_NAME(SETTINGS_NAME_LINKCERTIFICATES, "linkcertificates")
SETTINGS_NAME(SETTINGS_NAME_LINKCERTIFICATE, "linkcertificate")
2017-07-03 09:30:10 +02:00
}
2017-12-20 14:54:05 +01:00
PreVerificationSettings::PreVerificationSettings()
: AbstractSettings()
, mStore(getStore())
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
mStore->beginGroup(SETTINGS_GROUP_NAME_PREVERIFICATION());
2017-07-03 09:30:10 +02:00
}
2017-12-20 14:54:05 +01:00
void PreVerificationSettings::updateLinkCertificates(const QByteArrayList& pLinkCertificates)
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
mStore->beginGroup(SETTINGS_NAME_LINKCERTIFICATES());
mStore->remove(QString());
mStore->endGroup();
2017-07-03 09:30:10 +02:00
2017-12-20 14:54:05 +01:00
mStore->beginWriteArray(SETTINGS_NAME_LINKCERTIFICATES());
for (int i = 0; i < pLinkCertificates.size(); ++i)
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
mStore->setArrayIndex(i);
mStore->setValue(SETTINGS_NAME_LINKCERTIFICATE(), pLinkCertificates.at(i));
2017-07-03 09:30:10 +02:00
}
2017-12-20 14:54:05 +01:00
mStore->endArray();
2017-07-03 09:30:10 +02:00
}
2017-12-20 14:54:05 +01:00
PreVerificationSettings::~PreVerificationSettings()
2017-07-03 09:30:10 +02:00
{
}
void PreVerificationSettings::save()
{
2017-12-20 14:54:05 +01:00
mStore->sync();
2017-07-03 09:30:10 +02:00
}
bool PreVerificationSettings::isEnabled() const
{
2017-12-20 14:54:05 +01:00
return mStore->value(SETTINGS_NAME_ENABLED(), true).toBool();
2017-07-03 09:30:10 +02:00
}
void PreVerificationSettings::setEnabled(bool pEnabled)
{
2017-12-20 14:54:05 +01:00
mStore->setValue(SETTINGS_NAME_ENABLED(), pEnabled);
2017-07-03 09:30:10 +02:00
}
2017-12-20 14:54:05 +01:00
QByteArrayList PreVerificationSettings::getLinkCertificates() const
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
const int itemCount = mStore->beginReadArray(SETTINGS_NAME_LINKCERTIFICATES());
QByteArrayList linkCertificates;
linkCertificates.reserve(itemCount);
for (int i = 0; i < itemCount; ++i)
{
mStore->setArrayIndex(i);
linkCertificates += mStore->value(SETTINGS_NAME_LINKCERTIFICATE()).toByteArray();
}
mStore->endArray();
return linkCertificates;
2017-07-03 09:30:10 +02:00
}
2017-12-20 14:54:05 +01:00
void PreVerificationSettings::removeLinkCertificate(const QByteArray& pCert)
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
auto linkCertificates = getLinkCertificates();
if (linkCertificates.removeAll(pCert) > 0)
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
updateLinkCertificates(linkCertificates);
2017-07-03 09:30:10 +02:00
}
}
2017-12-20 14:54:05 +01:00
void PreVerificationSettings::addLinkCertificate(const QByteArray& pCert)
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
auto linkCertificates = getLinkCertificates();
if (!linkCertificates.contains(pCert))
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
linkCertificates += pCert;
updateLinkCertificates(linkCertificates);
2017-07-03 09:30:10 +02:00
}
}