File indexing completed on 2024-06-23 05:18:36

0001 /*
0002     SPDX-FileCopyrightText: 2010 Volker Krause <vkrause@kde.org>
0003     Based in kmail/recipientseditor.h/cpp
0004     SPDX-FileCopyrightText: 2004 Cornelius Schumacher <schumacher@kde.org>
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
0007 */
0008 
0009 #include "recipient.h"
0010 
0011 #include <KLocalizedString>
0012 
0013 using namespace KPIM;
0014 using namespace MessageComposer;
0015 
0016 class MessageComposer::RecipientPrivate
0017 {
0018 public:
0019     RecipientPrivate(const QString &email, Recipient::Type type)
0020         : mType(type)
0021         , mEmail(email)
0022     {
0023     }
0024 
0025     Kleo::Action mEncryptionAction = Kleo::Impossible;
0026     MessageComposer::Recipient::Type mType;
0027     QString mEmail;
0028     QString mName;
0029     GpgME::Key mKey;
0030 };
0031 
0032 Recipient::Recipient(const QString &email, Recipient::Type type)
0033     : d(new MessageComposer::RecipientPrivate(email, type))
0034 {
0035 }
0036 
0037 Recipient::~Recipient() = default;
0038 
0039 void Recipient::setType(Type type)
0040 {
0041     d->mType = type;
0042 }
0043 
0044 Recipient::Type Recipient::type() const
0045 {
0046     return d->mType;
0047 }
0048 
0049 void Recipient::setEmail(const QString &email)
0050 {
0051     d->mEmail = email;
0052 }
0053 
0054 QString Recipient::email() const
0055 {
0056     return d->mEmail;
0057 }
0058 
0059 void Recipient::setName(const QString &name)
0060 {
0061     d->mName = name;
0062 }
0063 
0064 QString Recipient::name() const
0065 {
0066     return d->mName;
0067 }
0068 
0069 bool Recipient::isEmpty() const
0070 {
0071     return d->mEmail.isEmpty();
0072 }
0073 
0074 void Recipient::clear()
0075 {
0076     d->mEmail.clear();
0077     d->mType = Recipient::To;
0078 }
0079 
0080 int Recipient::typeToId(Recipient::Type type)
0081 {
0082     return static_cast<int>(type);
0083 }
0084 
0085 Recipient::Type Recipient::idToType(int id)
0086 {
0087     return static_cast<Type>(id);
0088 }
0089 
0090 QString Recipient::typeLabel() const
0091 {
0092     return typeLabel(d->mType);
0093 }
0094 
0095 QString Recipient::typeLabel(Recipient::Type type)
0096 {
0097     switch (type) {
0098     case To:
0099         return i18nc("@label:listbox Recipient of an email message.", "To");
0100     case Cc:
0101         return i18nc("@label:listbox Carbon Copy recipient of an email message.", "CC");
0102     case Bcc:
0103         return i18nc("@label:listbox Blind carbon copy recipient of an email message.", "BCC");
0104     case ReplyTo:
0105         return i18nc("@label:listbox Reply-To recipient of an email message.", "Reply-To");
0106     case Undefined:
0107         break;
0108     }
0109 
0110     return xi18nc("@label:listbox", "<placeholder>Undefined Recipient Type</placeholder>");
0111 }
0112 
0113 QStringList Recipient::allTypeLabels()
0114 {
0115     QStringList types;
0116     types.append(typeLabel(To));
0117     types.append(typeLabel(Cc));
0118     types.append(typeLabel(Bcc));
0119     types.append(typeLabel(ReplyTo));
0120     return types;
0121 }
0122 
0123 GpgME::Key Recipient::key() const
0124 {
0125     return d->mKey;
0126 }
0127 
0128 void Recipient::setKey(const GpgME::Key &key)
0129 {
0130     d->mKey = key;
0131 }
0132 
0133 Kleo::Action MessageComposer::Recipient::encryptionAction() const
0134 {
0135     return d->mEncryptionAction;
0136 }
0137 
0138 void MessageComposer::Recipient::setEncryptionAction(const Kleo::Action action)
0139 {
0140     d->mEncryptionAction = action;
0141 }