Messagelib

recipient.cpp
1 /*
2  SPDX-FileCopyrightText: 2010 Volker Krause <[email protected]>
3  Based in kmail/recipientseditor.h/cpp
4  SPDX-FileCopyrightText: 2004 Cornelius Schumacher <[email protected]>
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:
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 
32 Recipient::Recipient(const QString &email, Recipient::Type type)
33  : d(new MessageComposer::RecipientPrivate(email, type))
34 {
35 }
36 
37 Recipient::~Recipient() = default;
38 
39 void Recipient::setType(Type type)
40 {
41  d->mType = type;
42 }
43 
44 Recipient::Type Recipient::type() const
45 {
46  return d->mType;
47 }
48 
49 void Recipient::setEmail(const QString &email)
50 {
51  d->mEmail = email;
52 }
53 
54 QString Recipient::email() const
55 {
56  return d->mEmail;
57 }
58 
59 void Recipient::setName(const QString &name)
60 {
61  d->mName = name;
62 }
63 
64 QString Recipient::name() const
65 {
66  return d->mName;
67 }
68 
69 bool Recipient::isEmpty() const
70 {
71  return d->mEmail.isEmpty();
72 }
73 
74 void Recipient::clear()
75 {
76  d->mEmail.clear();
77  d->mType = Recipient::To;
78 }
79 
80 int Recipient::typeToId(Recipient::Type type)
81 {
82  return static_cast<int>(type);
83 }
84 
85 Recipient::Type Recipient::idToType(int id)
86 {
87  return static_cast<Type>(id);
88 }
89 
90 QString Recipient::typeLabel() const
91 {
92  return typeLabel(d->mType);
93 }
94 
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 
113 QStringList Recipient::allTypeLabels()
114 {
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 
123 GpgME::Key Recipient::key() const
124 {
125  return d->mKey;
126 }
127 
128 void Recipient::setKey(const GpgME::Key &key)
129 {
130  d->mKey = key;
131 }
132 
133 Kleo::Action MessageComposer::Recipient::encryptionAction() const
134 {
135  return d->mEncryptionAction;
136 }
137 
138 void MessageComposer::Recipient::setEncryptionAction(const Kleo::Action action)
139 {
140  d->mEncryptionAction = action;
141 }
void append(const T &value)
QString xi18nc(const char *context, const char *text, const TYPE &arg...)
Simple interface that both EncryptJob and SignEncryptJob implement so the composer can extract some e...
QStringList types(Mode mode=Writing)
bool isEmpty() const const
const char * name(StandardAction id)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Mar 27 2023 04:08:18 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.