presentation/DavAccountSettings.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | #include <QCoreApplication> | ||
| 3 | #include <QVariantMap> | ||
| 4 | #include <QList> | ||
| 5 | #include <functional> | ||
| 6 | #include <optional> | ||
| 7 | |||
| 8 | // DAV configuration admission and persistence, independent of any QML view. | ||
| 9 | // Credentials stay in the keyring; the injectable writer also makes successful | ||
| 10 | // and failed keyring completions testable without a desktop secret service. | ||
| 11 | class DavAccountSettings final { | ||
| 12 | 12 | Q_DECLARE_TR_FUNCTIONS(DavAccountSettings) | |
| 13 | public: | ||
| 14 | struct Account { | ||
| 15 | 96 | QString id; | |
| 16 | 96 | QString serverUrl; | |
| 17 | 95 | QString username; | |
| 18 | 95 | QStringList selectedBooks; | |
| 19 | 94 | bool requiresLocalAuthorization = false; | |
| 20 | 94 | QString credentialId; | |
| 21 | // Sprint 100 D-4: the mail account this DAV account belongs to ("" = | ||
| 22 | // its own entry). Local only: SettingsCollector never sends it (D-16). | ||
| 23 | 94 | QString mailAccountId; | |
| 24 |
9/14✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 96 times.
✓ Branch 6 → 7 taken 1 time.
✓ Branch 6 → 8 taken 95 times.
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 11 taken 95 times.
✓ Branch 12 → 13 taken 1 time.
✓ Branch 12 → 14 taken 94 times.
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 16 taken 94 times.
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 19 taken 94 times.
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 94 times.
|
96 | bool operator==(const Account &) const = default; |
| 25 | }; | ||
| 26 | using PasswordWriter = std::function<bool(const QString &, const QString &, const QString &, | ||
| 27 | const QByteArray &, QString *)>; | ||
| 28 | using AsyncSaveCallback = std::function<void(const QVariantMap &)>; | ||
| 29 | using AsyncPasswordWriter = std::function<void( | ||
| 30 | QObject *owner, const QString &key, const QByteArray &password, | ||
| 31 | std::function<void(bool, const QString &)> callback)>; | ||
| 32 | struct CalendarConfig { | ||
| 33 | 81 | QString accountId; | |
| 34 | 81 | QStringList selectedCalendars; | |
| 35 | 81 | QStringList readOnlyCalendars; | |
| 36 |
3/6✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 81 times.
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 81 times.
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 11 taken 81 times.
|
81 | bool operator==(const CalendarConfig &) const = default; |
| 37 | }; | ||
| 38 | static QList<Account> accounts(); | ||
| 39 | static QList<CalendarConfig> calendarConfigs(); | ||
| 40 | static bool storeAccounts(const QList<Account> &accounts); | ||
| 41 | static bool storeSelections(const Account &expected, const CalendarConfig &expectedCalendar, | ||
| 42 | const std::optional<QStringList> &books, | ||
| 43 | const std::optional<QStringList> &calendars); | ||
| 44 | static std::optional<Account> removeMetadata(const QString &id); | ||
| 45 | // Sprint 100 D-4: link a DAV account to a mail account, or unlink (""). | ||
| 46 | static bool setMailAccountLink(const QString &davAccountId, const QString &mailAccountId); | ||
| 47 | // S106-252: the id of the first DAV account linked to `mailAccountId` | ||
| 48 | // ("" when none) — a "use the mail login" save updates it. | ||
| 49 | static QString linkedTo(const QString &mailAccountId); | ||
| 50 | static QVariantMap save(const QVariantMap &fields, const PasswordWriter &passwordWriter = {}); | ||
| 51 | static QObject *saveAsync(QObject *owner, const QVariantMap &fields, | ||
| 52 | AsyncSaveCallback callback, | ||
| 53 | const AsyncPasswordWriter &passwordWriter = {}); | ||
| 54 | private: | ||
| 55 | static bool persist(const QList<Account> &accounts, const QList<CalendarConfig> &calendars); | ||
| 56 | }; | ||
| 57 |