File indexing completed on 2024-04-28 03:53:56

0001 /*
0002     SPDX-FileCopyrightText: 2009 Grégory Oestreicher <greg@kamago.net>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KDAV_DAVPROTOCOLBASE_H
0008 #define KDAV_DAVPROTOCOLBASE_H
0009 
0010 #include "kdav_export.h"
0011 
0012 #include "davcollection.h"
0013 
0014 #include <QDomDocument>
0015 #include <QMap>
0016 #include <QVariant>
0017 #include <memory>
0018 
0019 namespace KDAV
0020 {
0021 /**
0022  * @short Base class for XML query builders
0023  */
0024 class XMLQueryBuilder
0025 {
0026 public:
0027     typedef std::shared_ptr<XMLQueryBuilder> Ptr;
0028 
0029     virtual ~XMLQueryBuilder();
0030 
0031     virtual QDomDocument buildQuery() const = 0;
0032     virtual QString mimeType() const = 0;
0033 
0034     void setParameter(const QString &key, const QVariant &value);
0035     QVariant parameter(const QString &key) const;
0036 
0037 private:
0038     QMap<QString, QVariant> mParameters;
0039 };
0040 
0041 /**
0042  * @short Base class for various DAV groupware dialects.
0043  *
0044  * This class provides an interface to query the DAV dialect
0045  * specific features and abstract them.
0046  *
0047  * The functionality is implemented in:
0048  *   @li CaldavProtocol
0049  *   @li CarddavProtocol
0050  *   @li GroupdavProtocol
0051  */
0052 class DavProtocolBase
0053 {
0054 public:
0055     /**
0056      * Destroys the DAV protocol base.
0057      */
0058     virtual ~DavProtocolBase();
0059 
0060     /**
0061      * Returns whether the DAV protocol dialect supports principal
0062      * queries. If true, it must return the home set it provides
0063      * access to with principalHomeSet() and the home set namespace
0064      * with principalHomeSetNS();
0065      */
0066     virtual bool supportsPrincipals() const = 0;
0067 
0068     /**
0069      * Returns whether the DAV protocol dialect supports the REPORT
0070      * command to query all resources of a collection.
0071      * If not, PROPFIND command will be used instead.
0072      */
0073     virtual bool useReport() const = 0;
0074 
0075     /**
0076      * Returns whether the DAV protocol dialect supports the MULTIGET command.
0077      *
0078      * If MULTIGET is supported, the content of all DAV resources
0079      * can be fetched in Akonadi::ResourceBase::retrieveItems() already and
0080      * there is no need to call Akonadi::ResourceBase::retrieveItem() for every single
0081      * DAV resource.
0082      *
0083      * Protocols that have MULTIGET capabilities must inherit from
0084      * DavMultigetProtocol instead of this class.
0085      */
0086     virtual bool useMultiget() const = 0;
0087 
0088     /**
0089      * Returns the home set that this protocol supports.
0090      */
0091     virtual QString principalHomeSet() const;
0092 
0093     /**
0094      * Returns the namespace of the home set.
0095      */
0096     virtual QString principalHomeSetNS() const;
0097 
0098     /**
0099      * Returns the XML document that represents the DAV query to
0100      * list all available DAV collections.
0101      */
0102     virtual XMLQueryBuilder::Ptr collectionsQuery() const = 0;
0103 
0104     /**
0105      * Returns @c true if the given <prop> element of a multistatus response contains a
0106      * valid collection for this protocol.
0107      */
0108     virtual bool containsCollection(const QDomElement &propElem) const = 0;
0109 
0110     /**
0111      * Returns a list of XML documents that represent DAV queries to
0112      * list all available DAV resources inside a specific DAV collection.
0113      */
0114     virtual QList<XMLQueryBuilder::Ptr> itemsQueries() const = 0;
0115 
0116     /**
0117      * Returns the possible content types for the collection that
0118      * is described by the passed @p propstat element of a PROPFIND result.
0119      */
0120     virtual DavCollection::ContentTypes collectionContentTypes(const QDomElement &propstat) const = 0;
0121 };
0122 }
0123 
0124 #endif