File indexing completed on 2024-12-22 04:56:56
0001 /* 0002 SPDX-FileCopyrightText: 2011 Grégory Oestreicher <greg@kamago.net> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <KCalendarCore/FreeBusy> 0010 0011 #include <QMap> 0012 #include <QObject> 0013 #include <QString> 0014 0015 class QDateTime; 0016 class KJob; 0017 0018 /** 0019 * @short The class that will manage DAV free-busy requests 0020 */ 0021 class DavFreeBusyHandler : public QObject 0022 { 0023 Q_OBJECT 0024 0025 public: 0026 /** 0027 * Constructs a new DavFreeBusyHandler 0028 */ 0029 explicit DavFreeBusyHandler(QObject *parent = nullptr); 0030 0031 /** 0032 * Checks if the free-busy info for @p email can be handled 0033 * 0034 * @param email The email address of the contact. 0035 */ 0036 void canHandleFreeBusy(const QString &email); 0037 0038 /** 0039 * Retrieve the free-busy info for @p email between @p start and @p end 0040 * 0041 * @param email The email address to retrieve the free-busy for 0042 * @param start The start of the free-busy period to report 0043 * @param end The end of the free-busy period to report 0044 */ 0045 void retrieveFreeBusy(const QString &email, const QDateTime &start, const QDateTime &end); 0046 0047 Q_SIGNALS: 0048 /** 0049 * Emitted once we know if the free-busy info for @p email 0050 * can be handled or not. 0051 */ 0052 void handlesFreeBusy(const QString &email, bool handles); 0053 0054 /** 0055 * Emitted once the free-busy has been retrieved 0056 */ 0057 void freeBusyRetrieved(const QString &email, const QString &freeBusy, bool success, const QString &errorText); 0058 0059 private: 0060 void onPrincipalSearchJobFinished(KJob *job); 0061 void onRetrieveFreeBusyJobFinished(KJob *job); 0062 /** 0063 * Simple struct to track the state of requests 0064 */ 0065 struct RequestTracker { 0066 RequestTracker() = default; 0067 0068 int handlingJobCount = 0; 0069 bool handlingJobSuccessful = false; 0070 int retrievalJobCount = 0; 0071 bool retrievalJobSuccessful = false; 0072 QMap<uint, KCalendarCore::FreeBusy::Ptr> resultingFreeBusy; 0073 }; 0074 0075 QMap<QString, RequestTracker> mRequestsTracker; 0076 QMap<QString, QStringList> mPrincipalScheduleOutbox; 0077 uint mNextRequestId = 0; 0078 };