Commit 2b3ac5d9 authored by Sandro Knauß's avatar Sandro Knauß 🐝
Browse files

Add more properties to identity.

We nned these additinal properties to have a overwride feature.
parent f25ca3f3
# SPDX-FileCopyrightText: none
# SPDX-License-Identifier: BSD-3-Clause
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
set(PIM_VERSION "5.21.40")
set(PIM_VERSION "5.21.41")
project(KIdentityManagement VERSION ${PIM_VERSION})
......
......@@ -40,6 +40,11 @@ bool IdentityTester::compareIdentities(const Identity &actual, const Identity &e
QCOMPARE(actual.smimeEncryptionKey(), expected.smimeEncryptionKey());
QCOMPARE(actual.smimeSigningKey(), expected.smimeSigningKey());
QCOMPARE(actual.preferredCryptoMessageFormat(), expected.preferredCryptoMessageFormat());
QCOMPARE(actual.autocryptEnabled(), expected.autocryptEnabled());
QCOMPARE(actual.autocryptPrefer(), expected.autocryptPrefer());
QCOMPARE(actual.encryptionOverride(), expected.encryptionOverride());
QCOMPARE(actual.warnNotEncrypt(), expected.warnNotEncrypt());
QCOMPARE(actual.warnNotSign(), expected.warnNotSign());
QCOMPARE(actual.emailAliases(), expected.emailAliases());
QCOMPARE(actual.primaryEmailAddress(), expected.primaryEmailAddress());
QCOMPARE(actual.vCardFile(), expected.vCardFile());
......@@ -127,6 +132,23 @@ void IdentityTester::test_Identity()
QVERIFY(!identity.autocryptEnabled());
identity.setAutocryptEnabled(true);
QVERIFY(identity.autocryptEnabled());
QVERIFY(!identity.autocryptPrefer());
identity.setAutocryptPrefer(true);
QVERIFY(identity.autocryptPrefer());
QVERIFY(!identity.encryptionOverride());
identity.setEncryptionOverride(true);
QVERIFY(identity.encryptionOverride());
QVERIFY(!identity.warnNotEncrypt());
identity.setWarnNotEncrypt(true);
QVERIFY(identity.warnNotEncrypt());
QVERIFY(!identity.warnNotSign());
identity.setWarnNotSign(true);
QVERIFY(identity.warnNotSign());
identity.setDefaultDomainName(QStringLiteral("kde.org"));
QCOMPARE(identity.defaultDomainName(), QStringLiteral("kde.org"));
Signature sig;
......@@ -240,3 +262,44 @@ void IdentityTester::test_toMimeData()
QCOMPARE(identity.fullName(), identity2.fullName());
}
void IdentityTester::test_migration()
{
Identity identity(QStringLiteral("Test1"));
identity.setFullName(QStringLiteral("name"));
QVERIFY(!identity.encryptionOverride());
{
KConfig config(QStringLiteral("test"));
QVERIFY(config.isConfigWritable(true));
KConfigGroup cg(&config, QStringLiteral("test"));
identity.writeConfig(cg);
config.sync();
}
{ // Generate a config that triggers the migration code
KConfig config(QStringLiteral("test_old"));
QVERIFY(config.isConfigWritable(true));
KConfigGroup cg(&config, QStringLiteral("test"));
identity.writeConfig(cg);
cg.deleteEntry(s_encryptionOverride);
cg.deleteEntry(s_warnnotencrypt);
cg.deleteEntry(s_warnnotsign);
config.sync();
}
{ // The migration is not triggerd
KConfig config(QStringLiteral("test"));
KConfigGroup cg(&config, QStringLiteral("test"));
Identity i2;
i2.readConfig(cg);
QVERIFY(compareIdentities(i2, identity));
}
{ // The migration is triggered
// for old config files (< v5.21.41)
KConfig config(QStringLiteral("test_old"));
KConfigGroup cg(&config, QStringLiteral("test"));
Identity i2;
i2.readConfig(cg);
QVERIFY(i2.encryptionOverride());
i2.setEncryptionOverride(false);
QVERIFY(compareIdentities(i2, identity));
}
}
......@@ -26,4 +26,5 @@ private Q_SLOTS:
void test_NullIdentity();
void test_Aliases();
void test_toMimeData();
void test_migration();
};
......@@ -95,6 +95,14 @@ void Identity::readConfig(const KConfigGroup &config)
}
++i;
}
// needs to update to v5.21.41
// Check if we update to to encryption override mode
// before we had only auto_encrypt and auto_sign and no global setting
if (!mPropertiesMap.contains(QLatin1String(s_encryptionOverride))
&& !mPropertiesMap.contains(QLatin1String(s_warnnotencrypt))
&& !mPropertiesMap.contains(QLatin1String(s_warnnotsign))) {
setEncryptionOverride(true);
}
mSignature.readConfig(config);
}
......@@ -107,6 +115,10 @@ void Identity::writeConfig(KConfigGroup &config) const
qCDebug(KIDENTITYMANAGEMENT_LOG) << "Store:" << i.key() << ":" << i.value();
++i;
}
if (!mPropertiesMap.contains(QLatin1String(s_encryptionOverride))) {
config.writeEntry(QLatin1String(s_encryptionOverride), false);
qCDebug(KIDENTITYMANAGEMENT_LOG) << "Add" << s_encryptionOverride << ":" << false;
}
mSignature.writeConfig(config);
}
......@@ -166,8 +178,10 @@ QDataStream &KIdentityManagement::operator<<(QDataStream &stream, const KIdentit
<< i.mPropertiesMap[QLatin1String(s_prefcrypt)] << i.mPropertiesMap[QLatin1String(s_cc)] << i.mPropertiesMap[QLatin1String(s_attachVcard)]
<< i.mPropertiesMap[QLatin1String(s_autocorrectionLanguage)] << i.mPropertiesMap[QLatin1String(s_disabledFcc)]
<< i.mPropertiesMap[QLatin1String(s_defaultDomainName)]
<< i.mPropertiesMap[QLatin1String(s_autocryptEnabled)]
<< i.mPropertiesMap[QLatin1String(s_pgpautosign)] << i.mPropertiesMap[QLatin1String(s_pgpautoencrypt)];
<< i.mPropertiesMap[QLatin1String(s_autocryptEnabled)] << i.mPropertiesMap[QLatin1String(s_autocryptPrefer)]
<< i.mPropertiesMap[QLatin1String(s_encryptionOverride)]
<< i.mPropertiesMap[QLatin1String(s_pgpautosign)] << i.mPropertiesMap[QLatin1String(s_pgpautoencrypt)]
<< i.mPropertiesMap[QLatin1String(s_warnnotencrypt)] << i.mPropertiesMap[QLatin1String(s_warnnotsign)];
}
QDataStream &KIdentityManagement::operator>>(QDataStream &stream, KIdentityManagement::Identity &i)
......@@ -185,8 +199,10 @@ QDataStream &KIdentityManagement::operator>>(QDataStream &stream, KIdentityManag
>> i.mPropertiesMap[QLatin1String(s_prefcrypt)] >> i.mPropertiesMap[QLatin1String(s_cc)] >> i.mPropertiesMap[QLatin1String(s_attachVcard)]
>> i.mPropertiesMap[QLatin1String(s_autocorrectionLanguage)] >> i.mPropertiesMap[QLatin1String(s_disabledFcc)]
>> i.mPropertiesMap[QLatin1String(s_defaultDomainName)]
>> i.mPropertiesMap[QLatin1String(s_autocryptEnabled)]
>> i.mPropertiesMap[QLatin1String(s_pgpautosign)] >> i.mPropertiesMap[QLatin1String(s_pgpautoencrypt)];
>> i.mPropertiesMap[QLatin1String(s_autocryptEnabled)] >> i.mPropertiesMap[QLatin1String(s_autocryptPrefer)]
>> i.mPropertiesMap[QLatin1String(s_encryptionOverride)]
>> i.mPropertiesMap[QLatin1String(s_pgpautosign)] >> i.mPropertiesMap[QLatin1String(s_pgpautoencrypt)]
>> i.mPropertiesMap[QLatin1String(s_warnnotencrypt)] >> i.mPropertiesMap[QLatin1String(s_warnnotsign)];
i.setProperty(QLatin1String(s_uoid), uoid);
return stream;
......@@ -738,6 +754,66 @@ void Identity::setAutocryptEnabled(const bool on)
setProperty(QLatin1String(s_autocryptEnabled), on);
}
bool KIdentityManagement::Identity::autocryptPrefer() const
{
const auto var = property(QLatin1String(s_autocryptPrefer));
if (var.isNull()) {
return false;
} else {
return var.toBool();
}
}
void Identity::setAutocryptPrefer(const bool on)
{
setProperty(QLatin1String(s_autocryptPrefer), on);
}
bool KIdentityManagement::Identity::encryptionOverride() const
{
const auto var = property(QLatin1String(s_encryptionOverride));
if (var.isNull()) {
return false;
} else {
return var.toBool();
}
}
void Identity::setEncryptionOverride(const bool on)
{
setProperty(QLatin1String(s_encryptionOverride), on);
}
bool KIdentityManagement::Identity::warnNotEncrypt() const
{
const auto var = property(QLatin1String(s_warnnotencrypt));
if (var.isNull()) {
return false;
} else {
return var.toBool();
}
}
void Identity::setWarnNotEncrypt(const bool on)
{
setProperty(QLatin1String(s_warnnotencrypt), on);
}
bool KIdentityManagement::Identity::warnNotSign() const
{
const auto var = property(QLatin1String(s_warnnotsign));
if (var.isNull()) {
return false;
} else {
return var.toBool();
}
}
void Identity::setWarnNotSign(const bool on)
{
setProperty(QLatin1String(s_warnnotsign), on);
}
QString Identity::defaultDomainName() const
{
return property(QLatin1String(s_defaultDomainName)).toString();
......
......@@ -55,10 +55,14 @@ static const char s_emailAliases[] = "Email Aliases";
static const char s_attachVcard[] = "Attach Vcard";
static const char s_autocorrectionLanguage[] = "Autocorrection Language";
static const char s_disabledFcc[] = "Disable Fcc";
static const char s_encryptionOverride[] = "Override Encryption Defaults";
static const char s_pgpautosign[] = "Pgp Auto Sign";
static const char s_pgpautoencrypt[] = "Pgp Auto Encrypt";
static const char s_warnnotsign[] = "Warn not Sign";
static const char s_warnnotencrypt[] = "Warn not Encrypt";
static const char s_defaultDomainName[] = "Default Domain";
static const char s_autocryptEnabled[] = "Autocrypt";
static const char s_autocryptPrefer[] = "Autocrypt Prefer";
KIDENTITYMANAGEMENT_EXPORT QDataStream &operator<<(QDataStream &stream, const KIdentityManagement::Identity &ident);
KIDENTITYMANAGEMENT_EXPORT QDataStream &operator>>(QDataStream &stream, KIdentityManagement::Identity &ident);
......@@ -229,6 +233,30 @@ public:
Q_REQUIRED_RESULT bool autocryptEnabled() const;
void setAutocryptEnabled(const bool);
/**
* @since 5.22
*/
Q_REQUIRED_RESULT bool autocryptPrefer() const;
void setAutocryptPrefer(const bool);
/**
* @since 5.22
*/
Q_REQUIRED_RESULT bool encryptionOverride() const;
void setEncryptionOverride(const bool);
/**
* @since 5.22
*/
Q_REQUIRED_RESULT bool warnNotSign() const;
void setWarnNotSign(const bool);
/**
* @since 5.22
*/
Q_REQUIRED_RESULT bool warnNotEncrypt() const;
void setWarnNotEncrypt(const bool);
/**
* @since 4.14
*/
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment