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

0001 /*
0002     SPDX-FileCopyrightText: 2011 Grégory Oestreicher <greg@kamago.net>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KDAV_DAVPRINCIPALSEARCHJOB_H
0008 #define KDAV_DAVPRINCIPALSEARCHJOB_H
0009 
0010 #include "kdav_export.h"
0011 
0012 #include "davjobbase.h"
0013 #include "davurl.h"
0014 
0015 #include <QString>
0016 
0017 namespace KDAV
0018 {
0019 class DavPrincipalSearchJobPrivate;
0020 
0021 /**
0022  * @class DavPrincipalSearchJob davprincipalsearchjob.h <KDAV/DavPrincipalSearchJob>
0023  *
0024  * @short A job that search a DAV principal on a server
0025  *
0026  * This job is used to search a principal on a server
0027  * that implement the dav-property-search REPORT (RFC3744).
0028  *
0029  * The properties to fetch are set with @ref fetchProperty().
0030  */
0031 class KDAV_EXPORT DavPrincipalSearchJob : public DavJobBase
0032 {
0033     Q_OBJECT
0034 
0035 public:
0036     /**
0037      * Types of search that are supported by this job.
0038      * DisplayName will match on the DAV displayname property.
0039      * EmailAddress will match on the CalDav calendar-user-address-set property.
0040      */
0041     enum FilterType {
0042         DisplayName,
0043         EmailAddress,
0044     };
0045 
0046     /**
0047      * Simple struct to hold the search job results
0048      */
0049     struct Result {
0050         QString propertyNamespace;
0051         QString property;
0052         QString value;
0053     };
0054 
0055     /**
0056      * Creates a new DAV principal search job
0057      *
0058      * @param url The URL to use in the REPORT query.
0059      * @param type The type that the filter will match.
0060      * @param filter The filter that will be used to match the displayname attribute.
0061      * @param parent The parent object.
0062      */
0063     explicit DavPrincipalSearchJob(const DavUrl &url, FilterType type, const QString &filter, QObject *parent = nullptr);
0064 
0065     /**
0066      * Add a new property to fetch from the server.
0067      *
0068      * @param name The name of the property.
0069      * @param ns The namespace of this property, defaults to 'DAV:'.
0070      */
0071     void fetchProperty(const QString &name, const QString &ns = QString());
0072 
0073     /**
0074      * Starts the job
0075      */
0076     void start() override;
0077 
0078     /**
0079      * Return the DavUrl used by this job
0080      */
0081     Q_REQUIRED_RESULT DavUrl davUrl() const;
0082 
0083     /**
0084      * Get the job results.
0085      */
0086     Q_REQUIRED_RESULT QList<Result> results() const;
0087 
0088 private:
0089     Q_DECLARE_PRIVATE(DavPrincipalSearchJob)
0090 };
0091 }
0092 
0093 Q_DECLARE_TYPEINFO(KDAV::DavPrincipalSearchJob::Result, Q_RELOCATABLE_TYPE);
0094 #endif