KDAV

groupdavprotocol.cpp
1/*
2 SPDX-FileCopyrightText: 2009 Grégory Oestreicher <greg@kamago.net>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "groupdavprotocol_p.h"
8
9#include "common/utils_p.h"
10
11#include <QDomDocument>
12
13using namespace KDAV;
14
15class GroupdavCollectionQueryBuilder : 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
31 return document;
32 }
33
34 QString mimeType() const override
35 {
36 return QString();
37 }
38};
39
40class GroupdavItemQueryBuilder : public XMLQueryBuilder
41{
42public:
43 QDomDocument buildQuery() const override
44 {
45 QDomDocument document;
46
47 QDomElement propfindElement = document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("propfind"));
48 document.appendChild(propfindElement);
49
50 QDomElement propElement = document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("prop"));
51 propfindElement.appendChild(propElement);
52
53 propElement.appendChild(document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("displayname")));
54 propElement.appendChild(document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("resourcetype")));
55 propElement.appendChild(document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("getetag")));
56
57 return document;
58 }
59
60 QString mimeType() const override
61 {
62 return QString();
63 }
64};
65
66GroupdavProtocol::GroupdavProtocol()
67{
68}
69
70bool GroupdavProtocol::supportsPrincipals() const
71{
72 return false;
73}
74
75bool GroupdavProtocol::useReport() const
76{
77 return false;
78}
79
80bool GroupdavProtocol::useMultiget() const
81{
82 return false;
83}
84
85XMLQueryBuilder::Ptr GroupdavProtocol::collectionsQuery() const
86{
87 return XMLQueryBuilder::Ptr(new GroupdavCollectionQueryBuilder());
88}
89
90bool GroupdavProtocol::containsCollection(const QDomElement &propElem) const
91{
92 return !propElem.elementsByTagNameNS(QStringLiteral("http://groupdav.org/"), QStringLiteral("vevent-collection")).isEmpty()
93 || !propElem.elementsByTagNameNS(QStringLiteral("http://groupdav.org/"), QStringLiteral("vtodo-collection")).isEmpty()
94 || !propElem.elementsByTagNameNS(QStringLiteral("http://groupdav.org/"), QStringLiteral("vcard-collection")).isEmpty();
95}
96
97QList<XMLQueryBuilder::Ptr> GroupdavProtocol::itemsQueries() const
98{
100 ret << XMLQueryBuilder::Ptr(new GroupdavItemQueryBuilder());
101 return ret;
102}
103
104DavCollection::ContentTypes GroupdavProtocol::collectionContentTypes(const QDomElement &propstatElement) const
105{
106 /*
107 * Extract the content type information from a propstat like the following
108 *
109 * <propstat>
110 * <status>HTTP/1.1 200 OK</status>
111 * <prop>
112 * <displayname>Tasks</displayname>
113 * <resourcetype>
114 * <collection/>
115 * <G:vtodo-collection xmlns:G="http://groupdav.org/"/>
116 * </resourcetype>
117 * <getlastmodified>Sat, 30 Jan 2010 17:52:41 -0100</getlastmodified>
118 * </prop>
119 * </propstat>
120 */
121
122 const QDomElement propElement = Utils::firstChildElementNS(propstatElement, QStringLiteral("DAV:"), QStringLiteral("prop"));
123 const QDomElement resourcetypeElement = Utils::firstChildElementNS(propElement, QStringLiteral("DAV:"), QStringLiteral("resourcetype"));
124
125 DavCollection::ContentTypes contentTypes;
126
127 if (!Utils::firstChildElementNS(resourcetypeElement, QStringLiteral("http://groupdav.org/"), QStringLiteral("vevent-collection")).isNull()) {
128 contentTypes |= DavCollection::Events;
129 }
130
131 if (!Utils::firstChildElementNS(resourcetypeElement, QStringLiteral("http://groupdav.org/"), QStringLiteral("vtodo-collection")).isNull()) {
132 contentTypes |= DavCollection::Todos;
133 }
134
135 if (!Utils::firstChildElementNS(resourcetypeElement, QStringLiteral("http://groupdav.org/"), QStringLiteral("vcard-collection")).isNull()) {
136 contentTypes |= DavCollection::Contacts;
137 }
138
139 return contentTypes;
140}
@ Todos
The collection can contain todo DAV resources.
@ Events
The collection can contain event DAV resources.
@ Contacts
The collection can contain contact DAV resources.
The KDAV namespace.
QDomElement createElementNS(const QString &nsURI, const QString &qName)
QDomNodeList elementsByTagNameNS(const QString &nsURI, const QString &localName) const const
QDomNode appendChild(const QDomNode &newChild)
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:05:53 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.