File indexing completed on 2024-06-16 04:52:28
0001 /* 0002 Copyright (c) 2011 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 #ifndef KDAV2_DAVPRINCIPALSEARCHJOB_H 0020 #define KDAV2_DAVPRINCIPALSEARCHJOB_H 0021 0022 #include "kpimkdav2_export.h" 0023 0024 #include "davjobbase.h" 0025 #include "davurl.h" 0026 0027 #include <QtCore/QList> 0028 #include <QtCore/QPair> 0029 #include <QtCore/QString> 0030 0031 #include <KCoreAddons/KJob> 0032 0033 class QDomDocument; 0034 0035 namespace KDAV2 0036 { 0037 0038 /** 0039 * @short A job that search a DAV principal on a server 0040 * 0041 * This job is used to search a principal on a server 0042 * that implement the dav-property-search REPORT (RFC3744). 0043 * 0044 * The properties to fetch are set with @ref fetchProperty(). 0045 */ 0046 class KPIMKDAV2_EXPORT DavPrincipalSearchJob : public DavJobBase 0047 { 0048 Q_OBJECT 0049 0050 public: 0051 /** 0052 * Types of search that are supported by this job. 0053 * DisplayName will match on the DAV displayname property. 0054 * EmailAddress will match on the CalDav calendar-user-address-set property. 0055 */ 0056 enum FilterType { 0057 DisplayName, 0058 EmailAddress 0059 }; 0060 0061 /** 0062 * Simple struct to hold the search job results 0063 */ 0064 struct Result { 0065 QString propertyNamespace; 0066 QString property; 0067 QString value; 0068 }; 0069 0070 /** 0071 * Creates a new dav principal search job 0072 * 0073 * @param url The URL to use in the REPORT query. 0074 * @param type The type that the filter will match. 0075 * @param filter The filter that will be used to match the displayname attribute. 0076 * @param parent The parent object. 0077 */ 0078 explicit DavPrincipalSearchJob(const DavUrl &url, FilterType type, const QString &filter, QObject *parent = nullptr); 0079 0080 /** 0081 * Add a new property to fetch from the server. 0082 * 0083 * @param name The name of the property. 0084 * @param ns The namespace of this property, defaults to 'DAV:'. 0085 */ 0086 void fetchProperty(const QString &name, const QString &ns = QString()); 0087 0088 /** 0089 * Starts the job 0090 */ 0091 void start() Q_DECL_OVERRIDE; 0092 0093 /** 0094 * Return the DavUrl used by this job 0095 */ 0096 DavUrl davUrl() const; 0097 0098 /** 0099 * Get the job results. 0100 */ 0101 QList<Result> results() const; 0102 0103 private Q_SLOTS: 0104 void principalCollectionSetSearchFinished(KJob *job); 0105 void principalPropertySearchFinished(KJob *job); 0106 0107 private: 0108 void buildReportQuery(QDomDocument &query); 0109 0110 private: 0111 DavUrl mUrl; 0112 FilterType mType; 0113 QString mFilter; 0114 int mPrincipalPropertySearchSubJobCount; 0115 bool mPrincipalPropertySearchSubJobSuccessful; 0116 QList< QPair<QString, QString> > mFetchProperties; 0117 QList<Result> mResults; 0118 }; 0119 0120 } 0121 0122 #endif