Libkdav2

carddavprotocol.cpp
1/*
2 Copyright (c) 2010 Tobias Koenig <tokoe@kde.org>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17*/
18
19#include "carddavprotocol.h"
20
21#include <QtCore/QStringList>
22#include <QtCore/QUrl>
23#include <QtCore/QVariant>
24#include <QtXml/QDomDocument>
25
26using namespace KDAV2;
27
28class CarddavCollectionQueryBuilder : public XMLQueryBuilder
29{
30public:
31 QDomDocument buildQuery() const Q_DECL_OVERRIDE
32 {
33 QDomDocument document;
34
35 QDomElement propfindElement = document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("propfind"));
36 document.appendChild(propfindElement);
37
38 QDomElement propElement = document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("prop"));
39 propfindElement.appendChild(propElement);
40
41 propElement.appendChild(document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("displayname")));
42 propElement.appendChild(document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("resourcetype")));
43 propElement.appendChild(document.createElementNS(QStringLiteral("http://calendarserver.org/ns/"), QStringLiteral("getctag")));
44
45 return document;
46 }
47
48 QString mimeType() const Q_DECL_OVERRIDE
49 {
50 return QString();
51 }
52};
53
54class CarddavListItemsQueryBuilder : public XMLQueryBuilder
55{
56public:
57 QDomDocument buildQuery() const Q_DECL_OVERRIDE
58 {
59 QDomDocument document;
60
61 QDomElement propfindElement = document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("propfind"));
62 document.appendChild(propfindElement);
63
64 QDomElement propElement = document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("prop"));
65 propfindElement.appendChild(propElement);
66
67 propElement.appendChild(document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("displayname")));
68 propElement.appendChild(document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("resourcetype")));
69 propElement.appendChild(document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("getetag")));
70
71 return document;
72 }
73
74 QString mimeType() const Q_DECL_OVERRIDE
75 {
76 return QStringLiteral("text/directory");
77 }
78};
79
80class CarddavMultigetQueryBuilder : public XMLQueryBuilder
81{
82public:
83 QDomDocument buildQuery() const Q_DECL_OVERRIDE
84 {
85 QDomDocument document;
86 const QStringList urls = parameter(QStringLiteral("urls")).toStringList();
87 if (urls.isEmpty()) {
88 return document;
89 }
90
91 QDomElement multigetElement = document.createElementNS(QStringLiteral("urn:ietf:params:xml:ns:carddav"), QStringLiteral("addressbook-multiget"));
92 document.appendChild(multigetElement);
93
94 QDomElement propElement = document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("prop"));
95 multigetElement.appendChild(propElement);
96
97 propElement.appendChild(document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("getetag")));
98 QDomElement addressDataElement = document.createElementNS(QStringLiteral("urn:ietf:params:xml:ns:carddav"), QStringLiteral("address-data"));
99 addressDataElement.appendChild(document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("allprop")));
100 propElement.appendChild(addressDataElement);
101
102 for (const QString &url : urls) {
103 QDomElement hrefElement = document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("href"));
104 const QUrl pathUrl = QUrl::fromUserInput(url);
105 const QDomText textNode = document.createTextNode(pathUrl.toString());
106 hrefElement.appendChild(textNode);
107
108 multigetElement.appendChild(hrefElement);
109 }
110
111 return document;
112 }
113
114 QString mimeType() const Q_DECL_OVERRIDE
115 {
116 return QString();
117 }
118};
119
120CarddavProtocol::CarddavProtocol()
121{
122}
123
124bool CarddavProtocol::supportsPrincipals() const
125{
126 return true;
127}
128
129bool CarddavProtocol::supportsCTags() const
130{
131 return true;
132}
133
134bool CarddavProtocol::useReport() const
135{
136 return false;
137}
138
139bool CarddavProtocol::useMultiget() const
140{
141 return true;
142}
143
144QString CarddavProtocol::principalHomeSet() const
145{
146 return QStringLiteral("addressbook-home-set");
147}
148
149QString CarddavProtocol::principalHomeSetNS() const
150{
151 return QStringLiteral("urn:ietf:params:xml:ns:carddav");
152}
153
154XMLQueryBuilder::Ptr CarddavProtocol::collectionsQuery() const
155{
156 return XMLQueryBuilder::Ptr(new CarddavCollectionQueryBuilder());
157}
158
159QString CarddavProtocol::collectionsXQuery() const
160{
161 const QString query(QStringLiteral("//*[local-name()='addressbook' and namespace-uri()='urn:ietf:params:xml:ns:carddav']/ancestor::*[local-name()='response' and namespace-uri()='DAV:']"));
162
163 return query;
164}
165
166QVector<XMLQueryBuilder::Ptr> CarddavProtocol::itemsQueries() const
167{
169 ret << XMLQueryBuilder::Ptr(new CarddavListItemsQueryBuilder());
170 return ret;
171}
172
173XMLQueryBuilder::Ptr CarddavProtocol::itemsReportQuery(const QStringList &urls) const
174{
175 XMLQueryBuilder::Ptr ret(new CarddavMultigetQueryBuilder());
176 ret->setParameter(QStringLiteral("urls"), urls);
177 return ret;
178}
179
180QString CarddavProtocol::responseNamespace() const
181{
182 return QStringLiteral("urn:ietf:params:xml:ns:carddav");
183}
184
185QString CarddavProtocol::dataTagName() const
186{
187 return QStringLiteral("address-data");
188}
189
190DavCollection::ContentTypes CarddavProtocol::collectionContentTypes(const QDomElement &) const
191{
193}
@ Contacts
The collection can contain contact DAV resources.
Base class for XML query builders.
std::optional< QSqlQuery > query(const QString &queryStatement)
QDomElement createElementNS(const QString &nsURI, const QString &qName)
QDomText createTextNode(const QString &value)
QDomNode appendChild(const QDomNode &newChild)
bool isEmpty() const const
QUrl fromUserInput(const QString &userInput, const QString &workingDirectory, UserInputResolutionOptions options)
QString toString(FormattingOptions options) const const
QStringList toStringList() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:05 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.