app/core/CalendarFreeBusy.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include "service/CalDavXml.h" | ||
| 4 | |||
| 5 | #include <QDateTime> | ||
| 6 | #include <QHash> | ||
| 7 | #include <QObject> | ||
| 8 | #include <QString> | ||
| 9 | #include <QStringList> | ||
| 10 | #include <functional> | ||
| 11 | |||
| 12 | class CalDavClient; | ||
| 13 | |||
| 14 | // Sprint 108 S108.8.5 (D-25): attendees' busy times through the RFC 6638 | ||
| 15 | // schedule outbox of a DAV account — one VFREEBUSY POST per question, an | ||
| 16 | // answer within 5 s or "no information", answers kept for 10 minutes. No | ||
| 17 | // public free/busy URLs are fetched. GUI thread; owned by the calendar | ||
| 18 | // coordinator, which supplies an authenticated client per question. | ||
| 19 | class CalendarFreeBusy : public QObject { | ||
| 20 | Q_OBJECT | ||
| 21 | public: | ||
| 22 | using Done = std::function<void(const QList<CalDavXml::FreeBusy> &)>; | ||
| 23 | using ClientFor = std::function<CalDavClient *(const QString &accountId)>; | ||
| 24 | static constexpr int TimeoutMs = 5000; | ||
| 25 | static constexpr qint64 CacheSeconds = 600; | ||
| 26 | |||
| 27 | 948 | explicit CalendarFreeBusy(ClientFor clientFor, QObject *parent = nullptr) | |
| 28 | 948 | : QObject(parent), m_clientFor(std::move(clientFor)) {} | |
| 29 | |||
| 30 | // `done` runs exactly once with one entry per attendee (known = false | ||
| 31 | // when the server could not tell, did not answer in time or the account | ||
| 32 | // has no schedule outbox); cached answers return at once. | ||
| 33 | void request(const QString &accountId, const QString &outboxUrl, const QString &organizer, | ||
| 34 | const QStringList &attendees, const QDateTime &from, const QDateTime &to, Done done); | ||
| 35 | 1 | void setClock(std::function<QDateTime()> clock) { m_clock = std::move(clock); } | |
| 36 | |||
| 37 | private: | ||
| 38 | struct Cached { | ||
| 39 | CalDavXml::FreeBusy answer; | ||
| 40 | QDateTime fetched; | ||
| 41 | }; | ||
| 42 | ClientFor m_clientFor; | ||
| 43 | 10 | std::function<QDateTime()> m_clock = [] { return QDateTime::currentDateTimeUtc(); }; | |
| 44 | QHash<QString, Cached> m_cache; // accountId|attendee|from|to | ||
| 45 | static QString cacheKey(const QString &accountId, const QString &attendee, const QDateTime &from, | ||
| 46 | const QDateTime &to); | ||
| 47 | }; | ||
| 48 |