Libkdav2

groupdavprotocol.cpp
1/*
2 Copyright (c) 2009 Grégory Oestreicher <greg@kamago.net>
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 "groupdavprotocol.h"
20
21#include "common/utils.h"
22
23#include <QtCore/QVariant>
24#include <QtXml/QDomDocument>
25
26using namespace KDAV2;
27
28class GroupdavCollectionQueryBuilder : 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
44 return document;
45 }
46
47 QString mimeType() const Q_DECL_OVERRIDE
48 {
49 return QString();
50 }
51};
52
53class GroupdavItemQueryBuilder : public XMLQueryBuilder
54{
55public:
56 QDomDocument buildQuery() const Q_DECL_OVERRIDE
57 {
58 QDomDocument document;
59
60 QDomElement propfindElement = document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("propfind"));
61 document.appendChild(propfindElement);
62
63 QDomElement propElement = document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("prop"));
64 propfindElement.appendChild(propElement);
65
66 propElement.appendChild(document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("displayname")));
67 propElement.appendChild(document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("resourcetype")));
68 propElement.appendChild(document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("getetag")));
69
70 return document;
71 }
72
73 QString mimeType() const Q_DECL_OVERRIDE
74 {
75 return QString();
76 }
77};
78
79GroupdavProtocol::GroupdavProtocol()
80{
81}
82
83bool GroupdavProtocol::supportsPrincipals() const
84{
85 return false;
86}
87
88bool GroupdavProtocol::supportsCTags() const
89{
90 return false;
91}
92
93bool GroupdavProtocol::useReport() const
94{
95 return false;
96}
97
98bool GroupdavProtocol::useMultiget() const
99{
100 return false;
101}
102
103XMLQueryBuilder::Ptr GroupdavProtocol::collectionsQuery() const
104{
105 return XMLQueryBuilder::Ptr(new GroupdavCollectionQueryBuilder());
106}
107
108QString GroupdavProtocol::collectionsXQuery() const
109{
110 const QString query(QStringLiteral("//*[(local-name()='vevent-collection' or local-name()='vtodo-collection' or local-name()='vcard-collection') and namespace-uri()='http://groupdav.org/']/ancestor::*[local-name()='response' and namespace-uri()='DAV:']"));
111
112 return query;
113}
114
115QVector<XMLQueryBuilder::Ptr> GroupdavProtocol::itemsQueries() const
116{
118 ret << XMLQueryBuilder::Ptr(new GroupdavItemQueryBuilder());
119 return ret;
120}
121
122DavCollection::ContentTypes GroupdavProtocol::collectionContentTypes(const QDomElement &propstatElement) const
123{
124 /*
125 * Extract the content type information from a propstat like the following
126 *
127 * <propstat>
128 * <status>HTTP/1.1 200 OK</status>
129 * <prop>
130 * <displayname>Tasks</displayname>
131 * <resourcetype>
132 * <collection/>
133 * <G:vtodo-collection xmlns:G="http://groupdav.org/"/>
134 * </resourcetype>
135 * <getlastmodified>Sat, 30 Jan 2010 17:52:41 -0100</getlastmodified>
136 * </prop>
137 * </propstat>
138 */
139
140 const QDomElement propElement = Utils::firstChildElementNS(propstatElement, QStringLiteral("DAV:"), QStringLiteral("prop"));
141 const QDomElement resourcetypeElement = Utils::firstChildElementNS(propElement, QStringLiteral("DAV:"), QStringLiteral("resourcetype"));
142
143 DavCollection::ContentTypes contentTypes;
144
145 if (!Utils::firstChildElementNS(resourcetypeElement, QStringLiteral("http://groupdav.org/"), QStringLiteral("vevent-collection")).isNull()) {
146 contentTypes |= DavCollection::Events;
147 }
148
149 if (!Utils::firstChildElementNS(resourcetypeElement, QStringLiteral("http://groupdav.org/"), QStringLiteral("vtodo-collection")).isNull()) {
150 contentTypes |= DavCollection::Todos;
151 }
152
153 if (!Utils::firstChildElementNS(resourcetypeElement, QStringLiteral("http://groupdav.org/"), QStringLiteral("vcard-collection")).isNull()) {
154 contentTypes |= DavCollection::Contacts;
155 }
156
157 return contentTypes;
158}
@ Contacts
The collection can contain contact DAV resources.
@ Todos
The collection can contain todo DAV resources.
@ Events
The collection can contain event DAV resources.
Base class for XML query builders.
KSERVICE_EXPORT KService::List query(FilterFunc filterFunc)
QDomElement KPIMKDAV2_EXPORT firstChildElementNS(const QDomElement &parent, const QString &namespaceUri, const QString &tagName)
Returns the first child element of parent that has the given tagName and is part of the namespaceUri.
Definition utils.cpp:37
QDomElement createElementNS(const QString &nsURI, const QString &qName)
QDomNode appendChild(const QDomNode &newChild)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:13:28 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.