presentation/DavConnectionTest.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <QObject> | ||
| 4 | #include <QPointer> | ||
| 5 | #include <QString> | ||
| 6 | #include <QVariantMap> | ||
| 7 | #include <functional> | ||
| 8 | |||
| 9 | #include "data/DavCredentials.h" | ||
| 10 | |||
| 11 | class CalDavClient; | ||
| 12 | |||
| 13 | // Sprint 93 S93.6.3: "Test connection" of the DAV account form. Runs a | ||
| 14 | // CalDAV discovery with the entered address, user and password — or the | ||
| 15 | // stored password when the field is empty and the account exists — on a | ||
| 16 | // dedicated client (never the background sync's) and reports | ||
| 17 | // idle/testing/success/failed with a readable message: "Connection works: | ||
| 18 | // 11 calendars found." or the cause with a next step (password missing or | ||
| 19 | // rejected, server unreachable, TLS, timeout). | ||
| 20 | class DavConnectionTest final : public QObject { | ||
| 21 | 11 | Q_OBJECT | |
| 22 | Q_PROPERTY(QString state READ state NOTIFY stateChanged) | ||
| 23 | Q_PROPERTY(QString message READ message NOTIFY stateChanged) | ||
| 24 | // The account id the last run tested ("" = unsaved form values). | ||
| 25 | Q_PROPERTY(QString accountId READ accountId NOTIFY stateChanged) | ||
| 26 | public: | ||
| 27 | // Returns an unstarted client; the tester connects and starts it. | ||
| 28 | using ClientFactory = std::function<CalDavClient *(const QString &serverUrl, const QString &username, | ||
| 29 | const QByteArray &password)>; | ||
| 30 | using PasswordReader = std::function<void(QObject *owner, const QString &accountId, | ||
| 31 | const QString &serverUrl, const QString &username, | ||
| 32 | DavCredentials::PasswordCallback callback)>; | ||
| 33 | |||
| 34 | explicit DavConnectionTest(QObject *parent = nullptr); | ||
| 35 | ~DavConnectionTest() override; | ||
| 36 | |||
| 37 | // fields: {id, serverUrl, username, password}. | ||
| 38 | Q_INVOKABLE void start(const QVariantMap &fields); | ||
| 39 | Q_INVOKABLE void cancel(); | ||
| 40 | |||
| 41 | 32 | QString state() const { return m_state; } | |
| 42 | 6 | QString message() const { return m_message; } | |
| 43 | 1 | QString accountId() const { return m_accountId; } | |
| 44 | |||
| 45 | 4 | void setClientFactory(ClientFactory factory) { m_clientFactory = std::move(factory); } | |
| 46 | 2 | void setPasswordReader(PasswordReader reader) { m_passwordReader = std::move(reader); } | |
| 47 | void setTimeoutMs(int ms) { m_timeoutMs = ms; } | ||
| 48 | |||
| 49 | signals: | ||
| 50 | void stateChanged(); | ||
| 51 | |||
| 52 | private: | ||
| 53 | void probe(quint64 generation, const QString &serverUrl, const QString &username, QByteArray password); | ||
| 54 | void finish(const QString &state, const QString &message); | ||
| 55 |
2/4✓ Branch 3 → 4 taken 6 times.
✗ Branch 3 → 6 not taken.
✓ Branch 4 → 5 taken 6 times.
✗ Branch 4 → 6 not taken.
|
6 | bool current(quint64 generation) const { return m_run && m_generation == generation; } |
| 56 | |||
| 57 | QString m_state = QStringLiteral("idle"); | ||
| 58 | QString m_message; | ||
| 59 | QString m_accountId; | ||
| 60 | QPointer<QObject> m_run; | ||
| 61 | quint64 m_generation = 0; | ||
| 62 | int m_timeoutMs = 30000; | ||
| 63 | ClientFactory m_clientFactory; | ||
| 64 | PasswordReader m_passwordReader; | ||
| 65 | }; | ||
| 66 |