KDAV

carddavprotocol.cpp
1/*
2 SPDX-FileCopyrightText: 2010 Tobias Koenig <tokoe@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "carddavprotocol_p.h"
8
9#include <QDomDocument>
10#include <QStringList>
11#include <QUrl>
12
13using namespace KDAV;
14
15class CarddavCollectionQueryBuilder : public XMLQueryBuilder
16{
17public:
18 QDomDocument buildQuery() const override
19 {
20 QDomDocument document;
21
22 QDomElement propfindElement = document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("propfind"));
23 document.appendChild(propfindElement);
24
25 QDomElement propElement = document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("prop"));
26 propfindElement.appendChild(propElement);
27
28 propElement.appendChild(document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("displayname")));
29 propElement.appendChild(document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("resourcetype")));
30 propElement.appendChild(document.createElementNS(QStringLiteral("http://calendarserver.org/ns/"), QStringLiteral("getctag")));
31
32 return document;
33 }
34
35 QString mimeType() const override
36 {
37 return QString();
38 }
39};
40
41class CarddavListItemsQueryBuilder : public XMLQueryBuilder
42{
43public:
44 QDomDocument buildQuery() const override
45 {
46 QDomDocument document;
47
48 QDomElement propfindElement = document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("propfind"));
49 document.appendChild(propfindElement);
50
51 QDomElement propElement = document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("prop"));
52 propfindElement.appendChild(propElement);
53
54 propElement.appendChild(document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("displayname")));
55 propElement.appendChild(document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("resourcetype")));
56 propElement.appendChild(document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("getetag")));
57
58 return document;
59 }
60
61 QString mimeType() const override
62 {
63 return QStringLiteral("text/directory");
64 }
65};
66
67class CarddavMultigetQueryBuilder : public XMLQueryBuilder
68{
69public:
70 QDomDocument buildQuery() const override
71 {
72 QDomDocument document;
73 const QStringList urls = parameter(QStringLiteral("urls")).toStringList();
74 if (urls.isEmpty()) {
75 return document;
76 }
77
78 QDomElement multigetElement = document.createElementNS(QStringLiteral("urn:ietf:params:xml:ns:carddav"), QStringLiteral("addressbook-multiget"));
79 document.appendChild(multigetElement);
80
81 QDomElement propElement = document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("prop"));
82 multigetElement.appendChild(propElement);
83
84 propElement.appendChild(document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("getetag")));
85 QDomElement addressDataElement = document.createElementNS(QStringLiteral("urn:ietf:params:xml:ns:carddav"), QStringLiteral("address-data"));
86 addressDataElement.appendChild(document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("allprop")));
87 propElement.appendChild(addressDataElement);
88
89 for (const QString &url : urls) {
90 QDomElement hrefElement = document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("href"));
91 const QUrl pathUrl = QUrl::fromUserInput(url);
92 const QDomText textNode = document.createTextNode(pathUrl.toString());
93 hrefElement.appendChild(textNode);
94
95 multigetElement.appendChild(hrefElement);
96 }
97
98 return document;
99 }
100
101 QString mimeType() const override
102 {
103 return QString();
104 }
105};
106
107CarddavProtocol::CarddavProtocol()
108{
109}
110
111bool CarddavProtocol::supportsPrincipals() const
112{
113 return true;
114}
115
116bool CarddavProtocol::useReport() const
117{
118 return false;
119}
120
121bool CarddavProtocol::useMultiget() const
122{
123 return true;
124}
125
126QString CarddavProtocol::principalHomeSet() const
127{
128 return QStringLiteral("addressbook-home-set");
129}
130
131QString CarddavProtocol::principalHomeSetNS() const
132{
133 return QStringLiteral("urn:ietf:params:xml:ns:carddav");
134}
135
136XMLQueryBuilder::Ptr CarddavProtocol::collectionsQuery() const
137{
138 return XMLQueryBuilder::Ptr(new CarddavCollectionQueryBuilder());
139}
140
141bool CarddavProtocol::containsCollection(const QDomElement &propElem) const
142{
143 return !propElem.elementsByTagNameNS(QStringLiteral("urn:ietf:params:xml:ns:carddav"), QStringLiteral("addressbook")).isEmpty();
144}
145
146QList<XMLQueryBuilder::Ptr> CarddavProtocol::itemsQueries() const
147{
149 ret << XMLQueryBuilder::Ptr(new CarddavListItemsQueryBuilder());
150 return ret;
151}
152
153XMLQueryBuilder::Ptr CarddavProtocol::itemsReportQuery(const QStringList &urls) const
154{
155 XMLQueryBuilder::Ptr ret(new CarddavMultigetQueryBuilder());
156 ret->setParameter(QStringLiteral("urls"), urls);
157 return ret;
158}
159
160QString CarddavProtocol::responseNamespace() const
161{
162 return QStringLiteral("urn:ietf:params:xml:ns:carddav");
163}
164
165QString CarddavProtocol::dataTagName() const
166{
167 return QStringLiteral("address-data");
168}
169
170DavCollection::ContentTypes CarddavProtocol::collectionContentTypes(const QDomElement &) const
171{
173}
@ Contacts
The collection can contain contact DAV resources.
The KDAV namespace.
QDomElement createElementNS(const QString &nsURI, const QString &qName)
QDomText createTextNode(const QString &value)
QDomNodeList elementsByTagNameNS(const QString &nsURI, const QString &localName) const const
QDomNode appendChild(const QDomNode &newChild)
bool isEmpty() const const
bool isEmpty() const const
QUrl fromUserInput(const QString &userInput, const QString &workingDirectory, UserInputResolutionOptions options)
QString toString(FormattingOptions options) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:02:02 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.