File indexing completed on 2024-05-26 05:17:02
0001 /* 0002 Copyright (c) 2009 Grégory Oestreicher <greg@kamago.net> 0003 0004 This program is free software; you can redistribute it and/or modify 0005 it under the terms of the GNU General Public License as published by 0006 the Free Software Foundation; either version 2 of the License, or 0007 (at your option) any later version. 0008 0009 This program is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0012 GNU General Public License for more details. 0013 0014 You should have received a copy of the GNU General Public License 0015 along with this program; if not, write to the Free Software 0016 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0017 */ 0018 0019 #include "groupdavprotocol.h" 0020 0021 #include "common/utils.h" 0022 0023 #include <QtCore/QVariant> 0024 #include <QtXml/QDomDocument> 0025 0026 using namespace KDAV2; 0027 0028 class GroupdavCollectionQueryBuilder : public XMLQueryBuilder 0029 { 0030 public: 0031 QDomDocument buildQuery() const Q_DECL_OVERRIDE 0032 { 0033 QDomDocument document; 0034 0035 QDomElement propfindElement = document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("propfind")); 0036 document.appendChild(propfindElement); 0037 0038 QDomElement propElement = document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("prop")); 0039 propfindElement.appendChild(propElement); 0040 0041 propElement.appendChild(document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("displayname"))); 0042 propElement.appendChild(document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("resourcetype"))); 0043 0044 return document; 0045 } 0046 0047 QString mimeType() const Q_DECL_OVERRIDE 0048 { 0049 return QString(); 0050 } 0051 }; 0052 0053 class GroupdavItemQueryBuilder : public XMLQueryBuilder 0054 { 0055 public: 0056 QDomDocument buildQuery() const Q_DECL_OVERRIDE 0057 { 0058 QDomDocument document; 0059 0060 QDomElement propfindElement = document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("propfind")); 0061 document.appendChild(propfindElement); 0062 0063 QDomElement propElement = document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("prop")); 0064 propfindElement.appendChild(propElement); 0065 0066 propElement.appendChild(document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("displayname"))); 0067 propElement.appendChild(document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("resourcetype"))); 0068 propElement.appendChild(document.createElementNS(QStringLiteral("DAV:"), QStringLiteral("getetag"))); 0069 0070 return document; 0071 } 0072 0073 QString mimeType() const Q_DECL_OVERRIDE 0074 { 0075 return QString(); 0076 } 0077 }; 0078 0079 GroupdavProtocol::GroupdavProtocol() 0080 { 0081 } 0082 0083 bool GroupdavProtocol::supportsPrincipals() const 0084 { 0085 return false; 0086 } 0087 0088 bool GroupdavProtocol::supportsCTags() const 0089 { 0090 return false; 0091 } 0092 0093 bool GroupdavProtocol::useReport() const 0094 { 0095 return false; 0096 } 0097 0098 bool GroupdavProtocol::useMultiget() const 0099 { 0100 return false; 0101 } 0102 0103 XMLQueryBuilder::Ptr GroupdavProtocol::collectionsQuery() const 0104 { 0105 return XMLQueryBuilder::Ptr(new GroupdavCollectionQueryBuilder()); 0106 } 0107 0108 QString GroupdavProtocol::collectionsXQuery() const 0109 { 0110 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:']")); 0111 0112 return query; 0113 } 0114 0115 QVector<XMLQueryBuilder::Ptr> GroupdavProtocol::itemsQueries() const 0116 { 0117 QVector<XMLQueryBuilder::Ptr> ret; 0118 ret << XMLQueryBuilder::Ptr(new GroupdavItemQueryBuilder()); 0119 return ret; 0120 } 0121 0122 DavCollection::ContentTypes GroupdavProtocol::collectionContentTypes(const QDomElement &propstatElement) const 0123 { 0124 /* 0125 * Extract the content type information from a propstat like the following 0126 * 0127 * <propstat> 0128 * <status>HTTP/1.1 200 OK</status> 0129 * <prop> 0130 * <displayname>Tasks</displayname> 0131 * <resourcetype> 0132 * <collection/> 0133 * <G:vtodo-collection xmlns:G="http://groupdav.org/"/> 0134 * </resourcetype> 0135 * <getlastmodified>Sat, 30 Jan 2010 17:52:41 -0100</getlastmodified> 0136 * </prop> 0137 * </propstat> 0138 */ 0139 0140 const QDomElement propElement = Utils::firstChildElementNS(propstatElement, QStringLiteral("DAV:"), QStringLiteral("prop")); 0141 const QDomElement resourcetypeElement = Utils::firstChildElementNS(propElement, QStringLiteral("DAV:"), QStringLiteral("resourcetype")); 0142 0143 DavCollection::ContentTypes contentTypes; 0144 0145 if (!Utils::firstChildElementNS(resourcetypeElement, QStringLiteral("http://groupdav.org/"), QStringLiteral("vevent-collection")).isNull()) { 0146 contentTypes |= DavCollection::Events; 0147 } 0148 0149 if (!Utils::firstChildElementNS(resourcetypeElement, QStringLiteral("http://groupdav.org/"), QStringLiteral("vtodo-collection")).isNull()) { 0150 contentTypes |= DavCollection::Todos; 0151 } 0152 0153 if (!Utils::firstChildElementNS(resourcetypeElement, QStringLiteral("http://groupdav.org/"), QStringLiteral("vcard-collection")).isNull()) { 0154 contentTypes |= DavCollection::Contacts; 0155 } 0156 0157 return contentTypes; 0158 }