Kgapi

calendarurl.cpp
1/*
2 * SPDX-FileCopyrightText: 2021 Daniel Vrátil <dvratil@kde.org>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only
5 * SPDX-License-Identifier: LGPL-3.0-only
6 * SPDX-License-Identifier: LicenseRef-KDE-Accepted-LGPL
7 */
8
9#include "calendarurl.h"
10
11#include "fieldmetadata.h"
12#include "peopleservice.h"
13
14#include <QJsonArray>
15#include <QJsonObject>
16#include <QJsonValue>
17#include <QSharedData>
18
19#include <algorithm>
20
21namespace KGAPI2::People
22{
23class CalendarUrl::Private : public QSharedData
24{
25public:
26 explicit Private() = default;
27 Private(const Private &) = default;
28 Private(Private &&) noexcept = delete;
29 Private &operator=(const Private &) = delete;
30 Private &operator=(Private &&) noexcept = delete;
31 ~Private() = default;
32
33 bool operator==(const Private &other) const
34 {
35 return url == other.url && metadata == other.metadata && type == other.type && formattedType == other.formattedType;
36 }
37
38 bool operator!=(const Private &other) const
39 {
40 return !(*this == other);
41 }
42
43 QString url{};
44 FieldMetadata metadata{};
45 QString type{};
46 QString formattedType{};
47};
48
50 : d(new Private)
51{
52}
53
54CalendarUrl::CalendarUrl(const CalendarUrl &) = default;
55CalendarUrl::CalendarUrl(CalendarUrl &&) noexcept = default;
56CalendarUrl &CalendarUrl::operator=(const CalendarUrl &) = default;
57CalendarUrl &CalendarUrl::operator=(CalendarUrl &&) noexcept = default;
58CalendarUrl::~CalendarUrl() = default;
59
60bool CalendarUrl::operator==(const CalendarUrl &other) const
61{
62 return *d == *other.d;
63}
64
65bool CalendarUrl::operator!=(const CalendarUrl &other) const
66{
67 return !(*this == other);
68}
69
71{
72 return d->url;
73}
74
75void CalendarUrl::setUrl(const QString &value)
76{
77 d->url = value;
78}
80{
81 return d->metadata;
82}
83
85{
86 d->metadata = value;
87}
89{
90 return d->type;
91}
92
93void CalendarUrl::setType(const QString &value)
94{
95 d->type = value;
96}
98{
99 return d->formattedType;
100}
101
102CalendarUrl CalendarUrl::fromJSON(const QJsonObject &obj)
103{
104 CalendarUrl calendarUrl;
105
106 if(!obj.isEmpty()) {
107 const auto metadata = obj.value(QStringLiteral("metadata")).toObject();
108 calendarUrl.d->metadata = FieldMetadata::fromJSON(metadata);
109 calendarUrl.d->url = obj.value(QStringLiteral("url")).toString();
110 calendarUrl.d->type = obj.value(QStringLiteral("type")).toString();
111 calendarUrl.d->formattedType = obj.value(QStringLiteral("formattedType")).toString();
112 }
113
114 return calendarUrl;
115}
116
117QList<CalendarUrl> CalendarUrl::fromJSONArray(const QJsonArray &data)
118{
119 QList<CalendarUrl> calendarUrls;
120
121 for(const auto &calendarUrl : data) {
122 if(calendarUrl.isObject()) {
123 const auto objectifiedCalendarUrl = calendarUrl.toObject();
124 calendarUrls.append(fromJSON(objectifiedCalendarUrl));
125 }
126 }
127
128 return calendarUrls;
129}
130
131QJsonValue CalendarUrl::toJSON() const
132{
133 QJsonObject obj;
134
135 PeopleUtils::addValueToJsonObjectIfValid(obj, "url", d->url);
136 // Skip, field metadata is only useful for receiving -> PeopleUtils::addValueToJsonObjectIfValid(obj, "metadata"}, d->metadata.toJSON());
137 PeopleUtils::addValueToJsonObjectIfValid(obj, "type", d->type);
138 // Output only -> PeopleUtils::addValueToJsonObjectIfValid(obj, "formattedType"}, d->formattedType);
139 return obj;
140}
141
142} // namespace KGAPI2::People
A person's calendar URL.
Definition calendarurl.h:34
void setUrl(const QString &value)
Sets value of the url property.
void setType(const QString &value)
Sets value of the type property.
void setMetadata(const FieldMetadata &value)
Sets value of the metadata property.
CalendarUrl()
Constructs a new CalendarUrl.
QString formattedType() const
Output only.
FieldMetadata metadata() const
Metadata about the calendar URL.
QString url() const
The calendar URL.
QString type() const
The type of the calendar URL.
Metadata about a field.
bool isEmpty() const const
QJsonValue value(QLatin1StringView key) const const
QJsonObject toObject() const const
QString toString() const const
void append(QList< T > &&value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 6 2024 12:11:00 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.