presentation/AccountServiceCheck.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | #include "service/MailLoginProbe.h" | ||
| 3 | #include <QObject> | ||
| 4 | #include <QPointer> | ||
| 5 | #include <QVariantMap> | ||
| 6 | #include <functional> | ||
| 7 | |||
| 8 | class AccountSession; | ||
| 9 | |||
| 10 | // Sprint 100 S100.4.2 (D-25, SF-15, SF-16): "Save = test" of the account | ||
| 11 | // editors. check() signs in to the incoming and then the outgoing server | ||
| 12 | // with the passwords typed in the editor — or, when a field is empty, the | ||
| 13 | // stored ones — and reports one Diagnosis per service. Nothing is saved | ||
| 14 | // here; the editor saves after a successful check (or "Save anyway"). | ||
| 15 | class AccountServiceCheck final : public QObject { | ||
| 16 | 2 | Q_OBJECT | |
| 17 | Q_PROPERTY(bool running READ running NOTIFY changed) | ||
| 18 | // The service being checked: "imap", "smtp" or "". | ||
| 19 | Q_PROPERTY(QString step READ step NOTIFY changed) | ||
| 20 | public: | ||
| 21 | // Reads a stored secret ("imap"/"smtp") of a saved account. | ||
| 22 | using SecretReader = std::function<void(QObject *owner, const QString &service, const QString &accountId, | ||
| 23 | std::function<void(QByteArray)>)>; | ||
| 24 | explicit AccountServiceCheck(AccountSession *accounts, QObject *parent = nullptr); | ||
| 25 | 1 | void setSecretReader(SecretReader reader) { m_secretReader = std::move(reader); } | |
| 26 | 2 | void setSslConfiguration(const QSslConfiguration &configuration) { m_ssl = configuration; m_customSsl = true; } | |
| 27 | 7 | bool running() const { return !m_step.isEmpty(); } | |
| 28 | 6 | QString step() const { return m_step; } | |
| 29 | // fields: the editor map (id, email, imapHost/Port/Security/Username/ | ||
| 30 | // Password, smtpHost/Port/Security/Username/Password, smtpLogin) and | ||
| 31 | // checkIncoming/checkOutgoing (default true). Returns a request id; | ||
| 32 | // finished(requestId, {ok, incoming, outgoing}) follows. | ||
| 33 | Q_INVOKABLE QString check(const QVariantMap &fields); | ||
| 34 | Q_INVOKABLE void cancel(); | ||
| 35 | signals: | ||
| 36 | void changed(); | ||
| 37 | void finished(const QString &requestId, const QVariantMap &result); | ||
| 38 | private: | ||
| 39 | void readPassword(const QString &service, std::function<void(QByteArray)> done); | ||
| 40 | void runIncoming(); | ||
| 41 | void runOutgoing(); | ||
| 42 | void complete(); | ||
| 43 | MailLoginProbe::Request request(const QString &service, const QByteArray &password) const; | ||
| 44 | AccountSession *m_accounts; | ||
| 45 | SecretReader m_secretReader; | ||
| 46 | QSslConfiguration m_ssl; | ||
| 47 | bool m_customSsl = false; | ||
| 48 | QVariantMap m_fields; | ||
| 49 | QString m_requestId; | ||
| 50 | QString m_step; | ||
| 51 | QVariantMap m_incoming, m_outgoing; | ||
| 52 | QPointer<MailLoginProbe> m_probe; | ||
| 53 | QPointer<QObject> m_run; | ||
| 54 | }; | ||
| 55 |