Messagelib

contactpreference.cpp
1/*
2 SPDX-FileCopyrightText: 2022 Sandro Knauß <sknauss@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "contactpreference.h"
8
9#include <KContacts/Addressee>
10
11using namespace MessageComposer;
12
13ContactPreference::ContactPreference() = default;
14
15void ContactPreference::fillFromAddressee(const KContacts::Addressee &contact)
16{
17 const QString encryptPref = contact.custom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("CRYPTOENCRYPTPREF"));
18 encryptionPreference = Kleo::stringToEncryptionPreference(encryptPref);
19 const QString signPref = contact.custom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("CRYPTOSIGNPREF"));
20 signingPreference = Kleo::stringToSigningPreference(signPref);
21 const QString cryptoFormats = contact.custom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("CRYPTOPROTOPREF"));
22 cryptoMessageFormat = Kleo::stringToCryptoMessageFormat(cryptoFormats);
23 pgpKeyFingerprints = contact.custom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("OPENPGPFP")).split(QLatin1Char(','), Qt::SkipEmptyParts);
24 smimeCertFingerprints = contact.custom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("SMIMEFP")).split(QLatin1Char(','), Qt::SkipEmptyParts);
25}
26
27void ContactPreference::fillAddressee(KContacts::Addressee &contact) const
28{
29 contact.insertCustom(QStringLiteral("KADDRESSBOOK"),
30 QStringLiteral("CRYPTOENCRYPTPREF"),
31 QLatin1StringView(Kleo::encryptionPreferenceToString(encryptionPreference)));
32 contact.insertCustom(QStringLiteral("KADDRESSBOOK"),
33 QStringLiteral("CRYPTOSIGNPREF"),
34 QLatin1StringView(Kleo::signingPreferenceToString(signingPreference)));
35 contact.insertCustom(QStringLiteral("KADDRESSBOOK"),
36 QStringLiteral("CRYPTOPROTOPREF"),
37 QLatin1StringView(cryptoMessageFormatToString(cryptoMessageFormat)));
38 contact.insertCustom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("OPENPGPFP"), pgpKeyFingerprints.join(QLatin1Char(',')));
39 contact.insertCustom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("SMIMEFP"), smimeCertFingerprints.join(QLatin1Char(',')));
40}
void insertCustom(const QString &app, const QString &name, const QString &value)
QString custom(const QString &app, const QString &name) const
Simple interface that both EncryptJob and SignEncryptJob implement so the composer can extract some e...
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
QString join(QChar separator) const const
SkipEmptyParts
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:07:24 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.