KContacts

calendarurl.cpp
1 /*
2  This file is part of the KContacts framework.
3  SPDX-FileCopyrightText: 2015-2019 Laurent Montel <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #include "calendarurl.h"
9 
10 #include <QMap>
11 #include <QUrl>
12 #include <QDataStream>
13 #include <QStringList>
14 
15 using namespace KContacts;
16 
17 class Q_DECL_HIDDEN CalendarUrl::Private : public QSharedData
18 {
19 public:
20  Private()
21  {
22  }
23 
24  Private(const Private &other)
25  : QSharedData(other)
26  {
27  parameters = other.parameters;
28  type = other.type;
29  url = other.url;
30  }
31 
32  static QString typeToString(CalendarUrl::CalendarType type);
33  QMap<QString, QStringList> parameters;
34  QUrl url;
35  CalendarUrl::CalendarType type;
36 };
37 
38 QString CalendarUrl::Private::typeToString(CalendarUrl::CalendarType type)
39 {
40  QString ret;
41  switch (type) {
42  case Unknown:
43  case EndCalendarType:
44  ret = QStringLiteral("Unknown");
45  break;
46  case FBUrl:
47  ret = QStringLiteral("FreeBusy");
48  break;
49  case CALUri:
50  ret = QStringLiteral("CalUri");
51  break;
52  case CALADRUri:
53  ret = QStringLiteral("Caladruri");
54  break;
55  }
56  return ret;
57 }
58 
59 CalendarUrl::CalendarUrl()
60  : d(new Private)
61 {
62  d->type = Unknown;
63 }
64 
65 CalendarUrl::CalendarUrl(CalendarUrl::CalendarType type)
66  : d(new Private)
67 {
68  d->type = type;
69 }
70 
71 CalendarUrl::CalendarUrl(const CalendarUrl &other)
72  : d(other.d)
73 {
74 }
75 
76 CalendarUrl::~CalendarUrl()
77 {
78 }
79 
80 QMap<QString, QStringList> CalendarUrl::parameters() const
81 {
82  return d->parameters;
83 }
84 
85 bool CalendarUrl::operator==(const CalendarUrl &other) const
86 {
87  return (d->parameters == other.parameters()) && (d->type == other.type()) && (d->url == other.url());
88 }
89 
90 bool CalendarUrl::operator!=(const CalendarUrl &other) const
91 {
92  return !(other == *this);
93 }
94 
95 CalendarUrl &CalendarUrl::operator=(const CalendarUrl &other)
96 {
97  if (this != &other) {
98  d = other.d;
99  }
100 
101  return *this;
102 }
103 
104 QString CalendarUrl::toString() const
105 {
106  QString str = QLatin1String("CalendarUrl {\n");
107  str += QStringLiteral(" url: %1\n").arg(d->url.toString());
108  str += QStringLiteral(" type: %1\n").arg(CalendarUrl::Private::typeToString(d->type));
109  if (!d->parameters.isEmpty()) {
110  QMap<QString, QStringList>::const_iterator it = d->parameters.constBegin();
111  const QMap<QString, QStringList>::const_iterator end = d->parameters.constEnd();
112  QString param;
113  while (it != end) {
114  param += QStringLiteral("%1 %2").arg(it.key(), it.value().join(QLatin1Char(',')));
115  ++it;
116  }
117  str += QStringLiteral(" parameters: %1\n").arg(param);
118  }
119  str += QLatin1String("}\n");
120  return str;
121 }
122 
123 void CalendarUrl::setParameters(const QMap<QString, QStringList> &params)
124 {
125  d->parameters = params;
126 }
127 
128 bool CalendarUrl::isValid() const
129 {
130  return (d->type != Unknown) && (d->url.isValid());
131 }
132 
133 void CalendarUrl::setType(CalendarUrl::CalendarType type)
134 {
135  d->type = type;
136 }
137 
138 CalendarUrl::CalendarType CalendarUrl::type() const
139 {
140  return d->type;
141 }
142 
143 void CalendarUrl::setUrl(const QUrl &url)
144 {
145  d->url = url;
146 }
147 
148 QUrl CalendarUrl::url() const
149 {
150  return d->url;
151 }
152 
153 QDataStream &KContacts::operator<<(QDataStream &s, const CalendarUrl &calUrl)
154 {
155  return s << calUrl.d->parameters << static_cast<uint>(calUrl.d->type) << calUrl.d->url;
156 }
157 
158 QDataStream &KContacts::operator>>(QDataStream &s, CalendarUrl &calUrl)
159 {
160  uint type;
161  s >> calUrl.d->parameters >> type >> calUrl.d->url;
162  calUrl.d->type = static_cast<CalendarUrl::CalendarType>(type);
163  return s;
164 }
Class that holds a Calendar Url (FBURL/CALADRURI/CALURI)
Definition: calendarurl.h:21
Type type(const QSqlDatabase &db)
QString typeToString(Type type)
const Key key(const T &value, const Key &defaultKey) const const
const QList< QKeySequence > & end()
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
const T value(const Key &key, const T &defaultValue) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat Jul 11 2020 22:54:17 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.