10#include "emailaddress.h"
12#include "fieldmetadata.h"
13#include "peopleservice.h"
20#include <KContacts/Email>
24namespace KGAPI2::People
26class EmailAddress::Private :
public QSharedData
29 explicit Private() =
default;
30 Private(
const Private &) =
default;
31 Private(Private &&) noexcept = delete;
32 Private &operator=(const Private &) = delete;
33 Private &operator=(Private &&) noexcept = delete;
36 bool operator==(const Private &other)
const
38 return value == other.value && metadata == other.metadata && type == other.type && displayName == other.displayName
39 && formattedType == other.formattedType;
42 bool operator!=(
const Private &other)
const
44 return !(*
this == other);
48 FieldMetadata metadata{};
50 QString displayName{};
51 QString formattedType{};
67 return *d == *other.d;
70bool EmailAddress::operator!=(
const EmailAddress &other)
const
72 return !(*
this == other);
104 return d->displayName;
109 d->displayName =
value;
113 return d->formattedType;
122 emailAddress.d->metadata = FieldMetadata::fromJSON(
metadata);
123 emailAddress.d->value = obj.
value(QStringLiteral(
"value")).
toString();
124 emailAddress.d->type = obj.
value(QStringLiteral(
"type")).
toString();
125 emailAddress.d->formattedType = obj.
value(QStringLiteral(
"formattedType")).
toString();
126 emailAddress.d->displayName = obj.
value(QStringLiteral(
"displayName")).
toString();
136 for(
const auto &emailAddress : data) {
137 if(emailAddress.isObject()) {
138 const auto objectifiedEmailAddress = emailAddress.toObject();
139 emailAddresses.
append(fromJSON(objectifiedEmailAddress));
143 return emailAddresses;
147QJsonValue EmailAddress::toJSON()
const
151 PeopleUtils::addValueToJsonObjectIfValid(obj,
"value", d->value);
153 PeopleUtils::addValueToJsonObjectIfValid(obj,
"type", d->type);
154 PeopleUtils::addValueToJsonObjectIfValid(obj,
"displayName", d->displayName);
159KContacts::Email EmailAddress::toKContactsEmail()
const
161 KContacts::Email convertedEmail;
162 convertedEmail.setEmail(
value());
164 const auto emailType =
type();
174 return convertedEmail;
177EmailAddress EmailAddress::fromKContactsEmail(
const KContacts::Email &email)
180 convertedEmail.setValue(email.mail());
182 switch(email.
type()) {
184 convertedEmail.setType(QStringLiteral(
"home"));
187 convertedEmail.setType(QStringLiteral(
"work"));
191 convertedEmail.setType(QStringLiteral(
"other"));
195 return convertedEmail;
198QList<EmailAddress> EmailAddress::fromKContactsEmailList(
const QList<KContacts::Email> &emailList)
200 QList<EmailAddress> convertedEmails;
201 std::transform(emailList.
cbegin(),
203 std::back_inserter(convertedEmails),
204 [](
const KContacts::Email &email) {
205 return EmailAddress::fromKContactsEmail(email);
207 return convertedEmails;
A person's email address.
QString displayName() const
The display name of the email.
QString type() const
The type of the email address.
void setDisplayName(const QString &value)
Sets value of the displayName property.
void setValue(const QString &value)
Sets value of the value property.
void setMetadata(const FieldMetadata &value)
Sets value of the metadata property.
QString formattedType() const
Output only.
FieldMetadata metadata() const
Metadata about the email address.
void setType(const QString &value)
Sets value of the type property.
EmailAddress()
Constructs a new EmailAddress.
QString value() const
The email address.
bool isEmpty() const const
QJsonValue value(QLatin1StringView key) const const
QJsonObject toObject() const const
QString toString() const const
void append(QList< T > &&value)
const_iterator cbegin() const const
const_iterator cend() const const
int compare(QLatin1StringView s1, const QString &s2, Qt::CaseSensitivity cs)