10#include "phonenumber.h"
12#include "fieldmetadata.h"
13#include "peopleservice.h"
20#include <KContacts/PhoneNumber>
24namespace KGAPI2::People
26class PhoneNumber::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 && formattedType == other.formattedType && canonicalForm == other.canonicalForm && type == other.type
39 && metadata == other.metadata;
42 bool operator!=(
const Private &other)
const
44 return !(*
this == other);
48 QString formattedType{};
49 QString canonicalForm{};
51 FieldMetadata metadata{};
67 return *d == *other.d;
70bool PhoneNumber::operator!=(
const PhoneNumber &other)
const
72 return !(*
this == other);
86 return d->formattedType;
90 return d->canonicalForm;
117 phoneNumber.d->metadata = FieldMetadata::fromJSON(
metadata);
118 phoneNumber.d->value = obj.
value(QStringLiteral(
"value")).
toString();
119 phoneNumber.d->canonicalForm = obj.
value(QStringLiteral(
"canonicalForm")).
toString();
120 phoneNumber.d->type = obj.
value(QStringLiteral(
"type")).
toString();
121 phoneNumber.d->formattedType = obj.
value(QStringLiteral(
"formattedType")).
toString();
131 for(
const auto &phoneNumber : data) {
132 if(phoneNumber.isObject()) {
133 const auto objectifiedPhoneNumber = phoneNumber.toObject();
134 phoneNumbers.
append(fromJSON(objectifiedPhoneNumber));
141QJsonValue PhoneNumber::toJSON()
const
145 PeopleUtils::addValueToJsonObjectIfValid(obj,
"value", d->value);
148 PeopleUtils::addValueToJsonObjectIfValid(obj,
"type", d->type);
153PhoneNumber PhoneNumber::fromKContactsPhoneNumber(
const KContacts::PhoneNumber &phoneNumber)
156 convertedPhoneNumber.setValue(phoneNumber.
number());
158 switch(phoneNumber.
type()) {
160 convertedPhoneNumber.setType(QStringLiteral(
"home"));
163 convertedPhoneNumber.setType(QStringLiteral(
"work"));
166 convertedPhoneNumber.setType(QStringLiteral(
"mobile"));
169 convertedPhoneNumber.setType(QStringLiteral(
"otherFax"));
172 convertedPhoneNumber.setType(QStringLiteral(
"pager"));
175 convertedPhoneNumber.setType(QStringLiteral(
"main"));
182 return convertedPhoneNumber;
185QList<PhoneNumber> PhoneNumber::fromKContactsPhoneNumberList(
const QList<KContacts::PhoneNumber> &phoneNumberList)
187 QList<PhoneNumber> convertedPhoneNumbers;
188 std::transform(phoneNumberList.
cbegin(),
189 phoneNumberList.
cend(),
190 std::back_inserter(convertedPhoneNumbers),
191 [](
const KContacts::PhoneNumber &phoneNumber) {
192 return PhoneNumber::fromKContactsPhoneNumber(phoneNumber);
194 return convertedPhoneNumbers;
197KContacts::PhoneNumber PhoneNumber::toKContactsPhoneNumber()
const
199 KContacts::PhoneNumber convertedPhoneNumber;
222 return convertedPhoneNumber;
QString formattedType() const
Output only.
PhoneNumber()
Constructs a new PhoneNumber.
void setValue(const QString &value)
Sets value of the value property.
QString type() const
The type of the phone number.
FieldMetadata metadata() const
Metadata about the phone number.
QString value() const
The phone number.
void setType(const QString &value)
Sets value of the type property.
void setMetadata(const FieldMetadata &value)
Sets value of the metadata property.
QString canonicalForm() const
Output only.
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)