1/*
2 This file is part of the KContacts framework.
3 SPDX-FileCopyrightText: 2015-2019 Laurent Montel <montel@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#include "calendarurl.h"
9#include "parametermap_p.h"
10
11#include <QDataStream>
12#include <QStringList>
13#include <QUrl>
14
15using namespace KContacts;
16
17class Q_DECL_HIDDEN CalendarUrl::Private : public QSharedData
18{
19public:
20 Private()
21 {
22 }
23
24 Private(const Private &other)
25 : QSharedData(other)
26 {
27 mParamMap = other.mParamMap;
28 type = other.type;
29 url = other.url;
30 }
31
32 static QString typeToString(CalendarUrl::CalendarType type);
33
34 ParameterMap mParamMap;
35 QUrl url;
36 CalendarUrl::CalendarType type;
37};
38
39QString CalendarUrl::Private::typeToString(CalendarUrl::CalendarType type)
40{
41 QString ret;
42 switch (type) {
43 case Unknown:
44 case EndCalendarType:
45 ret = QStringLiteral("Unknown");
46 break;
47 case FBUrl:
48 ret = QStringLiteral("FreeBusy");
49 break;
50 case CALUri:
51 ret = QStringLiteral("CalUri");
52 break;
53 case CALADRUri:
54 ret = QStringLiteral("Caladruri");
55 break;
56 }
57 return ret;
58}
59
60CalendarUrl::CalendarUrl()
61 : d(new Private)
62{
63 d->type = Unknown;
64}
65
66CalendarUrl::CalendarUrl(CalendarUrl::CalendarType type)
67 : d(new Private)
68{
69 d->type = type;
70}
71
72CalendarUrl::CalendarUrl(const CalendarUrl &other)
73 : d(other.d)
74{
75}
76
77CalendarUrl::~CalendarUrl()
78{
79}
80
81bool CalendarUrl::operator==(const CalendarUrl &other) const
82{
83 return (d->mParamMap == other.d->mParamMap) && (d->type == other.type()) && (d->url == other.url());
84}
85
86bool CalendarUrl::operator!=(const CalendarUrl &other) const
87{
88 return !(other == *this);
89}
90
91CalendarUrl &CalendarUrl::operator=(const CalendarUrl &other)
92{
93 if (this != &other) {
94 d = other.d;
95 }
96
97 return *this;
98}
99
100QString CalendarUrl::toString() const
101{
102 QString str = QLatin1String("CalendarUrl {\n");
103 str += QStringLiteral(" url: %1\n").arg(a: d->url.toString());
104 str += QStringLiteral(" type: %1\n").arg(a: CalendarUrl::Private::typeToString(type: d->type));
105 str += d->mParamMap.toString();
106 str += QLatin1String("}\n");
107 return str;
108}
109
110void CalendarUrl::setParams(const ParameterMap &params)
111{
112 d->mParamMap = params;
113}
114
115ParameterMap CalendarUrl::params() const
116{
117 return d->mParamMap;
118}
119
120bool CalendarUrl::isValid() const
121{
122 return (d->type != Unknown) && (d->url.isValid());
123}
124
125void CalendarUrl::setType(CalendarUrl::CalendarType type)
126{
127 d->type = type;
128}
129
130CalendarUrl::CalendarType CalendarUrl::type() const
131{
132 return d->type;
133}
134
135void CalendarUrl::setUrl(const QUrl &url)
136{
137 d->url = url;
138}
139
140QUrl CalendarUrl::url() const
141{
142 return d->url;
143}
144
145QDataStream &KContacts::operator<<(QDataStream &s, const CalendarUrl &calUrl)
146{
147 return s << calUrl.d->mParamMap << static_cast<uint>(calUrl.d->type) << calUrl.d->url;
148}
149
150QDataStream &KContacts::operator>>(QDataStream &s, CalendarUrl &calUrl)
151{
152 uint type;
153 s >> calUrl.d->mParamMap >> type >> calUrl.d->url;
154 calUrl.d->type = static_cast<CalendarUrl::CalendarType>(type);
155 return s;
156}
157

source code of kcontacts/src/calendarurl.cpp