1 /*
2     SPDX-FileCopyrightText: 2010 Volker Krause <vkrause@kde.org>
3     Based in kmail/recipientseditor.h/cpp
4     SPDX-FileCopyrightText: 2004 Cornelius Schumacher <schumacher@kde.org>
5 
6     SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
7 */
8 
9 #include "recipient.h"
10 
11 #include <KLocalizedString>
12 
13 using namespace KPIM;
14 using namespace MessageComposer;
15 
16 class MessageComposer::RecipientPrivate
17 {
18 public:
RecipientPrivate(const QString & email,Recipient::Type type)19     RecipientPrivate(const QString &email, Recipient::Type type)
20         : mType(type)
21         , mEmail(email)
22     {
23     }
24 
25     Kleo::Action mEncryptionAction = Kleo::Impossible;
26     MessageComposer::Recipient::Type mType;
27     QString mEmail;
28     QString mName;
29     GpgME::Key mKey;
30 };
31 
Recipient(const QString & email,Recipient::Type type)32 Recipient::Recipient(const QString &email, Recipient::Type type)
33     : d(new MessageComposer::RecipientPrivate(email, type))
34 {
35 }
36 
37 Recipient::~Recipient() = default;
38 
setType(Type type)39 void Recipient::setType(Type type)
40 {
41     d->mType = type;
42 }
43 
type() const44 Recipient::Type Recipient::type() const
45 {
46     return d->mType;
47 }
48 
setEmail(const QString & email)49 void Recipient::setEmail(const QString &email)
50 {
51     d->mEmail = email;
52 }
53 
email() const54 QString Recipient::email() const
55 {
56     return d->mEmail;
57 }
58 
setName(const QString & name)59 void Recipient::setName(const QString &name)
60 {
61     d->mName = name;
62 }
63 
name() const64 QString Recipient::name() const
65 {
66     return d->mName;
67 }
68 
isEmpty() const69 bool Recipient::isEmpty() const
70 {
71     return d->mEmail.isEmpty();
72 }
73 
clear()74 void Recipient::clear()
75 {
76     d->mEmail.clear();
77     d->mType = Recipient::To;
78 }
79 
typeToId(Recipient::Type type)80 int Recipient::typeToId(Recipient::Type type)
81 {
82     return static_cast<int>(type);
83 }
84 
idToType(int id)85 Recipient::Type Recipient::idToType(int id)
86 {
87     return static_cast<Type>(id);
88 }
89 
typeLabel() const90 QString Recipient::typeLabel() const
91 {
92     return typeLabel(d->mType);
93 }
94 
typeLabel(Recipient::Type type)95 QString Recipient::typeLabel(Recipient::Type type)
96 {
97     switch (type) {
98     case To:
99         return i18nc("@label:listbox Recipient of an email message.", "To");
100     case Cc:
101         return i18nc("@label:listbox Carbon Copy recipient of an email message.", "CC");
102     case Bcc:
103         return i18nc("@label:listbox Blind carbon copy recipient of an email message.", "BCC");
104     case ReplyTo:
105         return i18nc("@label:listbox Reply-To recipient of an email message.", "Reply-To");
106     case Undefined:
107         break;
108     }
109 
110     return xi18nc("@label:listbox", "<placeholder>Undefined Recipient Type</placeholder>");
111 }
112 
allTypeLabels()113 QStringList Recipient::allTypeLabels()
114 {
115     QStringList types;
116     types.append(typeLabel(To));
117     types.append(typeLabel(Cc));
118     types.append(typeLabel(Bcc));
119     types.append(typeLabel(ReplyTo));
120     return types;
121 }
122 
key() const123 GpgME::Key Recipient::key() const
124 {
125     return d->mKey;
126 }
127 
setKey(const GpgME::Key & key)128 void Recipient::setKey(const GpgME::Key &key)
129 {
130     d->mKey = key;
131 }
132 
encryptionAction() const133 Kleo::Action MessageComposer::Recipient::encryptionAction() const
134 {
135     return d->mEncryptionAction;
136 }
137 
setEncryptionAction(const Kleo::Action action)138 void MessageComposer::Recipient::setEncryptionAction(const Kleo::Action action)
139 {
140     d->mEncryptionAction = action;
141 }
142