presentation/MailSelectionSummary.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "MailSelectionSummary.h" | ||
| 2 | |||
| 3 | #include "service/MailSelectionService.h" | ||
| 4 | #include "ui/MailListModel.h" | ||
| 5 | #include <QLoggingCategory> | ||
| 6 | #include <QPointer> | ||
| 7 | #include <algorithm> | ||
| 8 | |||
| 9 | Q_DECLARE_LOGGING_CATEGORY(lcQuickBackend) | ||
| 10 | |||
| 11 | 795 | MailSelectionSummary::MailSelectionSummary(HeaderLookup headers, QObject *parent) | |
| 12 | 795 | : QObject(parent), m_headers(std::move(headers)) {} | |
| 13 | |||
| 14 | 2841 | void MailSelectionSummary::update(const std::shared_ptr<const MailSelectionSnapshot> &snapshot, qint64 count) { | |
| 15 |
2/2✓ Branch 2 → 3 taken 88 times.
✓ Branch 2 → 4 taken 2753 times.
|
2841 | const qint64 shown = count > 1 ? count : 0; |
| 16 |
6/6✓ Branch 6 → 7 taken 2794 times.
✓ Branch 6 → 9 taken 47 times.
✓ Branch 7 → 8 taken 2782 times.
✓ Branch 7 → 9 taken 12 times.
✓ Branch 10 → 11 taken 2782 times.
✓ Branch 10 → 12 taken 59 times.
|
2866 | if (snapshot == m_snapshot && shown == m_count) return; |
| 17 |
3/4✓ Branch 13 → 14 taken 34 times.
✓ Branch 13 → 17 taken 25 times.
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 17 taken 34 times.
|
59 | const bool sameSnapshot = snapshot && snapshot == m_snapshot; |
| 18 | 59 | m_snapshot = snapshot; | |
| 19 | 59 | m_count = shown; | |
| 20 | 59 | const quint64 generation = ++m_generation; | |
| 21 |
2/2✓ Branch 19 → 20 taken 59 times.
✓ Branch 20 → 21 taken 59 times.
|
59 | MailSelectionService::shared()->cancel(this); |
| 22 | // The previous rows stay until the new ones arrive (no flicker while a | ||
| 23 | // Shift range grows); nothing is listed without a selection. | ||
| 24 |
7/7✓ Branch 21 → 22 taken 41 times.
✓ Branch 21 → 24 taken 18 times.
✓ Branch 23 → 24 taken 7 times.
✓ Branch 23 → 25 taken 34 times.
✓ Branch 26 → 27 taken 25 times.
✓ Branch 26 → 28 taken 34 times.
✓ Branch 27 → 28 taken 25 times.
|
59 | if (shown == 0 || !snapshot) m_mails.clear(); |
| 25 |
1/1✓ Branch 28 → 29 taken 59 times.
|
59 | emit changed(); |
| 26 |
7/8✓ Branch 29 → 30 taken 41 times.
✓ Branch 29 → 33 taken 18 times.
✓ Branch 31 → 32 taken 34 times.
✓ Branch 31 → 33 taken 7 times.
✗ Branch 32 → 33 not taken.
✓ Branch 32 → 34 taken 34 times.
✓ Branch 35 → 36 taken 25 times.
✓ Branch 35 → 37 taken 34 times.
|
59 | if (shown == 0 || !snapshot || sameSnapshot) return; |
| 27 |
1/1✓ Branch 37 → 38 taken 34 times.
|
34 | const QPointer<MailSelectionSummary> guard(this); |
| 28 |
2/2✓ Branch 38 → 39 taken 34 times.
✓ Branch 43 → 44 taken 34 times.
|
68 | MailSelectionService::shared()->page(this, snapshot, 0, MaxMails, |
| 29 |
1/3✓ Branch 41 → 42 taken 34 times.
✗ Branch 58 → 59 not taken.
✗ Branch 58 → 60 not taken.
|
68 | [guard, generation, snapshot](MailSelectionResult result) { |
| 30 |
3/6✓ Branch 3 → 4 taken 34 times.
✗ Branch 3 → 6 not taken.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 34 times.
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 34 times.
|
34 | if (!guard || generation != guard->m_generation) return; |
| 31 |
1/2✗ Branch 10 → 11 not taken.
✓ Branch 10 → 23 taken 34 times.
|
34 | if (result.outcome != MailSelectionResult::Outcome::Ready) { |
| 32 | ✗ | qCWarning(lcQuickBackend) << "selection page failed" << result.error; | |
| 33 | ✗ | return; | |
| 34 | } | ||
| 35 | 34 | QList<MailId> ids; | |
| 36 |
2/2✓ Branch 34 → 26 taken 152 times.
✓ Branch 34 → 35 taken 34 times.
|
186 | for (const qint64 uid : std::as_const(result.uids)) ids.append({snapshot->accountId, snapshot->folderId, uid}); |
| 37 |
2/3✓ Branch 37 → 38 taken 34 times.
✗ Branch 37 → 40 not taken.
✓ Branch 39 → 41 taken 34 times.
|
34 | QList<MailHeader> headers = guard->m_headers ? guard->m_headers(ids) : QList<MailHeader>{}; |
| 38 |
3/3✓ Branch 41 → 42 taken 34 times.
✓ Branch 42 → 43 taken 34 times.
✓ Branch 43 → 44 taken 34 times.
|
152 | std::sort(headers.begin(), headers.end(), [](const MailHeader &a, const MailHeader &b) { return a.date > b.date; }); |
| 39 | 34 | QVariantList mails; | |
| 40 |
2/2✓ Branch 92 → 47 taken 152 times.
✓ Branch 92 → 93 taken 34 times.
|
186 | for (const auto &header : std::as_const(headers)) |
| 41 |
1/1✓ Branch 73 → 74 taken 152 times.
|
456 | mails.append(QVariantMap{{QStringLiteral("subject"), header.subject}, |
| 42 | 304 | {QStringLiteral("sender"), header.from}, | |
| 43 |
1/1✓ Branch 59 → 60 taken 152 times.
|
304 | {QStringLiteral("date"), MailListModel::formatDate(header.date)}, |
| 44 | 304 | {QStringLiteral("unread"), !header.isSeen()}, | |
| 45 |
2/4✓ Branch 77 → 78 taken 760 times.
✓ Branch 77 → 79 taken 152 times.
✗ Branch 135 → 136 not taken.
✗ Branch 135 → 137 not taken.
|
1216 | {QStringLiteral("starred"), header.isFlagged()}}); |
| 46 | 34 | guard->m_mails = mails; | |
| 47 |
8/8✓ Branch 95 → 96 taken 34 times.
✓ Branch 99 → 100 taken 34 times.
✓ Branch 100 → 101 taken 34 times.
✓ Branch 102 → 103 taken 34 times.
✓ Branch 103 → 104 taken 34 times.
✓ Branch 105 → 106 taken 34 times.
✓ Branch 109 → 97 taken 34 times.
✓ Branch 109 → 110 taken 34 times.
|
68 | qCDebug(lcQuickBackend) << "summary of" << guard->m_count << "mails shows" << mails.size(); |
| 48 |
1/1✓ Branch 111 → 112 taken 34 times.
|
34 | emit guard->changed(); |
| 49 |
2/8✓ Branch 30 → 31 taken 152 times.
✓ Branch 71 → 72 taken 152 times.
✗ Branch 125 → 126 not taken.
✗ Branch 125 → 127 not taken.
✗ Branch 173 → 174 not taken.
✗ Branch 173 → 177 not taken.
✗ Branch 175 → 176 not taken.
✗ Branch 175 → 177 not taken.
|
1098 | }); |
| 50 | 34 | } | |
| 51 |