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

KDE's Doxygen guidelines are available online.