Kgapi

contactgroupmetadata.cpp
1/*
2 * SPDX-FileCopyrightText: 2021 Daniel Vrátil <dvratil@kde.org>
3 * SPDX-FileCopyrightText: 2022 Claudio Cambra <claudio.cambra@kde.org>
4 *
5 * SPDX-License-Identifier: LGPL-2.1-only
6 * SPDX-License-Identifier: LGPL-3.0-only
7 * SPDX-License-Identifier: LicenseRef-KDE-Accepted-LGPL
8 */
9
10#include "contactgroupmetadata.h"
11#include "peopleservice.h"
12
13#include <QJsonArray>
14#include <QJsonObject>
15#include <QJsonValue>
16#include <QSharedData>
17#include <QDateTime>
18
19#include <algorithm>
20
21namespace KGAPI2::People
22{
23class ContactGroupMetadata::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 updateTime == other.updateTime && deleted == other.deleted;
36 }
37
38 bool operator!=(const Private &other) const
39 {
40 return !(*this == other);
41 }
42
43 QDateTime updateTime{};
44 bool deleted{};
45};
46
48 : d(new Private)
49{
50}
51
55ContactGroupMetadata &ContactGroupMetadata::operator=(ContactGroupMetadata &&) noexcept = default;
57
58bool ContactGroupMetadata::operator==(const ContactGroupMetadata &other) const
59{
60 return *d == *other.d;
61}
62
63bool ContactGroupMetadata::operator!=(const ContactGroupMetadata &other) const
64{
65 return !(*this == other);
66}
67
69{
70 return d->updateTime;
71}
73{
74 return d->deleted;
75}
76
77ContactGroupMetadata ContactGroupMetadata::fromJSON(const QJsonObject &obj)
78{
79 ContactGroupMetadata contactGroupMetadata;
80
81 if (!obj.isEmpty()) {
82 contactGroupMetadata.d->updateTime = obj.value(QStringLiteral("updateTime")).toVariant().toDateTime();
83 contactGroupMetadata.d->deleted = obj.value(QStringLiteral("deleted")).toBool();
84 }
85
86 return contactGroupMetadata;
87}
88
89QJsonValue ContactGroupMetadata::toJSON() const
90{
91 QJsonObject obj;
92
93 PeopleUtils::addValueToJsonObjectIfValid(obj, "updateTime", d->updateTime.toString(Qt::ISODate));
94 PeopleUtils::addValueToJsonObjectIfValid(obj, "deleted", d->deleted);
95 return obj;
96}
97
98} // namespace KGAPI2::People
The metadata about a contact group.
ContactGroupMetadata()
Constructs a new ContactGroupMetadata.
QDateTime updateTime() const
Output only.
bool isEmpty() const const
QJsonValue value(QLatin1StringView key) const const
bool toBool(bool defaultValue) const const
QVariant toVariant() const const
QDateTime toDateTime() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:36:13 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.