MailJDTourDownloadDocsQualityTestsCoverage

Which source lines and branches the tests execute. Lines 91.5 %, branches 75.0 % (minimum 85 % and 72 %). main @ 399ffe3d · 21 October 2026 · pipeline 7238.

GCC Code Coverage Report


Directory: src/
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 87.3% 165 / 0 / 189
Functions: 100.0% 17 / 0 / 17
Branches: 72.3% 211 / 0 / 292

presentation/ContactPhotoProvider.cpp
Line Branch Exec Source
1 #include "ContactPhotoProvider.h"
2
3 #include "data/ContactQueries.h"
4 #include "data/ContactStore.h"
5 #include "data/VCardCodec.h"
6 #include "util/RasterImageFormat.h"
7
8 #include <QBuffer>
9 #include <QCoreApplication>
10 #include <QImageReader>
11 #include <QLoggingCategory>
12 #include <QMutexLocker>
13 #include <QPainter>
14 #include <QPainterPath>
15 #include <QUrl>
16
17
4/7
✓ Branch 2 → 3 taken 5 times.
✓ Branch 2 → 8 taken 9 times.
✓ Branch 4 → 5 taken 5 times.
✗ Branch 4 → 8 not taken.
✓ Branch 5 → 6 taken 5 times.
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 12 not taken.
14 Q_LOGGING_CATEGORY(lcContactPhoto, "mailjd.contacts.photo")
18
19 namespace {
20
21 class PhotoResponse final : public QQuickImageResponse {
22 public:
23 2300 QQuickTextureFactory *textureFactory() const override { return QQuickTextureFactory::textureFactoryForImage(m_image); }
24 2497 void finish(const QImage &image) {
25 2497 m_image = image;
26 2497 emit finished();
27 2497 }
28
29 private:
30 QImage m_image;
31 };
32
33 2497 int sideFor(const QSize &requested) {
34 2497 const int side = qMax(requested.width(), requested.height());
35
1/2
✓ Branch 5 → 6 taken 2497 times.
✗ Branch 5 → 8 not taken.
2497 return side > 0 ? qMin(side, 512) : 128;
36 }
37
38 } // namespace
39
40
1/1
✓ Branch 5 → 6 taken 765 times.
765 ContactPhotoProvider::ContactPhotoProvider(QString databasePath) : m_databasePath(std::move(databasePath)) {
41
1/1
✓ Branch 8 → 9 taken 765 times.
765 m_pool.setMaxThreadCount(1);
42 765 }
43
44 1530 ContactPhotoProvider::~ContactPhotoProvider() { m_pool.waitForDone(); }
45
46 451 QImage ContactPhotoProvider::decode(const QByteArray &bytes, int side) {
47
1/1
✓ Branch 2 → 3 taken 451 times.
451 QBuffer buffer;
48
1/1
✓ Branch 3 → 4 taken 451 times.
451 buffer.setData(bytes);
49
1/1
✓ Branch 5 → 6 taken 451 times.
451 QImageReader reader(&buffer);
50
1/1
✓ Branch 7 → 8 taken 451 times.
451 reader.setAllocationLimit(AllocationLimitMiB);
51
3/3
✓ Branch 8 → 9 taken 451 times.
✓ Branch 9 → 10 taken 5 times.
✓ Branch 9 → 24 taken 446 times.
451 if (!RasterImageFormat::accept(reader)) {
52
7/7
✓ Branch 10 → 11 taken 5 times.
✓ Branch 14 → 15 taken 5 times.
✓ Branch 15 → 16 taken 5 times.
✓ Branch 16 → 17 taken 5 times.
✓ Branch 17 → 18 taken 5 times.
✓ Branch 22 → 12 taken 5 times.
✓ Branch 22 → 23 taken 5 times.
10 qCInfo(lcContactPhoto) << "Photo refused: format" << reader.format();
53 5 return {};
54 }
55
1/1
✓ Branch 24 → 25 taken 446 times.
446 const QSize size = reader.size();
56
6/8
✓ Branch 26 → 27 taken 446 times.
✗ Branch 26 → 31 not taken.
✓ Branch 28 → 29 taken 445 times.
✓ Branch 28 → 31 taken 1 time.
✗ Branch 30 → 31 not taken.
✓ Branch 30 → 32 taken 445 times.
✓ Branch 33 → 34 taken 1 time.
✓ Branch 33 → 53 taken 445 times.
446 if (!size.isValid() || size.width() > MaxDimension || size.height() > MaxDimension) {
57
9/9
✓ Branch 34 → 35 taken 1 time.
✓ Branch 38 → 39 taken 1 time.
✓ Branch 39 → 40 taken 1 time.
✓ Branch 41 → 42 taken 1 time.
✓ Branch 42 → 43 taken 1 time.
✓ Branch 43 → 44 taken 1 time.
✓ Branch 44 → 45 taken 1 time.
✓ Branch 51 → 36 taken 1 time.
✓ Branch 51 → 52 taken 1 time.
2 qCInfo(lcContactPhoto) << "Photo refused: size" << size << "format" << reader.format();
58 1 return {};
59 }
60 // Scale the shorter edge to `side` — only ever down (S106-309: scaling up
61 // with KeepAspectRatioByExpanding turned a 4096×1 image into 2097152×512,
62 // about 4 GiB) — then the centre square, scaled to side×side.
63 445 side = qBound(1, side, MaxDimension);
64 445 const QSize scaled = size.scaled(side, side, Qt::KeepAspectRatioByExpanding);
65
5/6
✓ Branch 57 → 58 taken 441 times.
✓ Branch 57 → 62 taken 4 times.
✓ Branch 60 → 61 taken 441 times.
✗ Branch 60 → 62 not taken.
✓ Branch 63 → 64 taken 441 times.
✓ Branch 63 → 65 taken 4 times.
445 if (scaled.width() <= size.width() && scaled.height() <= size.height())
66
1/1
✓ Branch 64 → 65 taken 441 times.
441 reader.setScaledSize(scaled);
67
1/1
✓ Branch 65 → 66 taken 445 times.
445 const QImage image = reader.read();
68
2/3
✓ Branch 66 → 67 taken 445 times.
✗ Branch 67 → 68 not taken.
✓ Branch 67 → 82 taken 445 times.
445 if (image.isNull()) {
69 ✗ qCInfo(lcContactPhoto) << "Photo not decodable:" << reader.errorString();
70 ✗ return {};
71 }
72
2/2
✓ Branch 82 → 83 taken 445 times.
✓ Branch 83 → 84 taken 445 times.
445 const int edge = qMin(image.width(), image.height());
73
3/3
✓ Branch 85 → 86 taken 445 times.
✓ Branch 86 → 87 taken 445 times.
✓ Branch 87 → 88 taken 445 times.
445 QImage centre = image.copy((image.width() - edge) / 2, (image.height() - edge) / 2, edge, edge);
74
2/2
✓ Branch 88 → 89 taken 4 times.
✓ Branch 88 → 93 taken 441 times.
445 if (edge != side)
75
1/1
✓ Branch 89 → 90 taken 4 times.
4 centre = centre.scaled(side, side, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
76 // Clipped to a circle (transparent corners), so QML needs no mask effect.
77
1/1
✓ Branch 93 → 94 taken 445 times.
445 QImage round(side, side, QImage::Format_ARGB32_Premultiplied);
78
1/1
✓ Branch 94 → 95 taken 445 times.
445 round.fill(Qt::transparent);
79
1/1
✓ Branch 95 → 96 taken 445 times.
445 QPainter painter(&round);
80
1/1
✓ Branch 96 → 97 taken 445 times.
445 painter.setRenderHint(QPainter::Antialiasing);
81 445 QPainterPath circle;
82
1/1
✓ Branch 99 → 100 taken 445 times.
445 circle.addEllipse(QRectF(0, 0, side, side));
83
1/1
✓ Branch 100 → 101 taken 445 times.
445 painter.setClipPath(circle);
84
1/1
✓ Branch 102 → 103 taken 445 times.
445 painter.drawImage(QPoint(0, 0), centre);
85 445 return round;
86 451 }
87
88 namespace {
89
90 // The upright image of `bytes` within the limits, scaled to fit `maxSide`
91 // (0 = full size).
92 10 QImage readUpright(const QByteArray &bytes, int maxSide, QString *error) {
93
1/1
✓ Branch 2 → 3 taken 10 times.
10 QBuffer buffer;
94
1/1
✓ Branch 3 → 4 taken 10 times.
10 buffer.setData(bytes);
95
1/1
✓ Branch 5 → 6 taken 10 times.
10 QImageReader reader(&buffer);
96
1/1
✓ Branch 7 → 8 taken 10 times.
10 reader.setAllocationLimit(ContactPhotoProvider::AllocationLimitMiB);
97
1/1
✓ Branch 8 → 9 taken 10 times.
10 reader.setAutoTransform(true);
98
3/3
✓ Branch 9 → 10 taken 10 times.
✓ Branch 10 → 11 taken 1 time.
✓ Branch 10 → 17 taken 9 times.
10 if (!RasterImageFormat::accept(reader)) {
99
1/2
✓ Branch 11 → 12 taken 1 time.
✗ Branch 11 → 16 not taken.
1 if (error)
100
1/1
✓ Branch 12 → 13 taken 1 time.
1 *error = QCoreApplication::translate("ContactPhotoProvider", "This file is not a picture MailJD can read.");
101 1 return {};
102 }
103
1/1
✓ Branch 17 → 18 taken 9 times.
9 const QSize size = reader.size();
104
4/8
✓ Branch 19 → 20 taken 9 times.
✗ Branch 19 → 24 not taken.
✓ Branch 21 → 22 taken 9 times.
✗ Branch 21 → 24 not taken.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 25 taken 9 times.
✗ Branch 26 → 27 not taken.
✓ Branch 26 → 33 taken 9 times.
18 if (!size.isValid() || size.width() > ContactPhotoProvider::MaxDimension ||
105 9 size.height() > ContactPhotoProvider::MaxDimension) {
106 ✗ if (error)
107 ✗ *error = QCoreApplication::translate("ContactPhotoProvider", "Choose a picture of at most 4096 × 4096 pixels.");
108 ✗ return {};
109 }
110
6/6
✓ Branch 33 → 34 taken 4 times.
✓ Branch 33 → 39 taken 5 times.
✓ Branch 37 → 38 taken 1 time.
✓ Branch 37 → 39 taken 3 times.
✓ Branch 40 → 41 taken 1 time.
✓ Branch 40 → 44 taken 8 times.
9 if (maxSide > 0 && qMax(size.width(), size.height()) > maxSide)
111
1/1
✓ Branch 42 → 43 taken 1 time.
1 reader.setScaledSize(size.scaled(maxSide, maxSide, Qt::KeepAspectRatio));
112
1/1
✓ Branch 44 → 45 taken 9 times.
9 QImage image = reader.read();
113
3/7
✓ Branch 45 → 46 taken 9 times.
✗ Branch 46 → 47 not taken.
✓ Branch 46 → 49 taken 9 times.
✗ Branch 47 → 48 not taken.
✗ Branch 47 → 49 not taken.
✗ Branch 50 → 51 not taken.
✓ Branch 50 → 55 taken 9 times.
9 if (image.isNull() && error)
114 ✗ *error = QCoreApplication::translate("ContactPhotoProvider", "This file is not a picture MailJD can read.");
115 9 return image;
116 10 }
117
118 // At most CardJpegBytes: lower quality first, then (S106-311: a noise image
119 // stays above the limit at quality 40) a smaller square; empty when even a
120 // small one does not fit.
121 8 QByteArray cardJpeg(const QImage &square) {
122 8 constexpr qsizetype CardJpegBytes = 64 * 1024;
123
1/1
✓ Branch 2 → 3 taken 8 times.
8 QImage current = square;
124
2/3
✓ Branch 30 → 31 taken 8 times.
✓ Branch 31 → 4 taken 8 times.
✗ Branch 31 → 32 not taken.
8 while (current.width() >= 32) {
125
1/2
✓ Branch 23 → 5 taken 8 times.
✗ Branch 23 → 24 not taken.
8 for (int quality = 85; quality >= 40; quality -= 15) {
126 ✗ QByteArray jpeg;
127
1/1
✓ Branch 5 → 6 taken 8 times.
8 QBuffer out(&jpeg);
128
1/1
✓ Branch 7 → 8 taken 8 times.
8 out.open(QIODevice::WriteOnly);
129
1/1
✓ Branch 8 → 9 taken 8 times.
8 current.save(&out, "JPEG", quality);
130
1/2
✓ Branch 10 → 11 taken 8 times.
✗ Branch 10 → 12 not taken.
8 if (jpeg.size() <= CardJpegBytes)
131 8 return jpeg;
132 8 }
133 ✗ current = current.scaled(current.width() / 2, current.height() / 2, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
134 }
135 ✗ qCWarning(lcContactPhoto) << "Photo refused: no JPEG of at most 64 KiB";
136 ✗ return {};
137 8 }
138
139 } // namespace
140
141 7 QByteArray ContactPhotoProvider::prepareForCard(const QByteArray &bytes, QString *error) {
142
1/1
✓ Branch 2 → 3 taken 7 times.
7 QBuffer buffer;
143
1/1
✓ Branch 3 → 4 taken 7 times.
7 buffer.setData(bytes);
144
1/1
✓ Branch 5 → 6 taken 7 times.
7 QImageReader reader(&buffer);
145
1/1
✓ Branch 7 → 8 taken 7 times.
7 reader.setAllocationLimit(AllocationLimitMiB);
146
1/1
✓ Branch 8 → 9 taken 7 times.
7 reader.setAutoTransform(true);
147
3/3
✓ Branch 9 → 10 taken 7 times.
✓ Branch 10 → 11 taken 4 times.
✓ Branch 10 → 17 taken 3 times.
7 if (!RasterImageFormat::accept(reader)) {
148
1/2
✓ Branch 11 → 12 taken 4 times.
✗ Branch 11 → 16 not taken.
4 if (error)
149
1/1
✓ Branch 12 → 13 taken 4 times.
4 *error = QCoreApplication::translate("ContactPhotoProvider", "This file is not a picture MailJD can read.");
150 4 return {};
151 }
152
1/1
✓ Branch 17 → 18 taken 3 times.
3 const QSize size = reader.size();
153
4/8
✓ Branch 19 → 20 taken 3 times.
✗ Branch 19 → 24 not taken.
✓ Branch 21 → 22 taken 3 times.
✗ Branch 21 → 24 not taken.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 25 taken 3 times.
✗ Branch 26 → 27 not taken.
✓ Branch 26 → 33 taken 3 times.
3 if (!size.isValid() || size.width() > MaxDimension || size.height() > MaxDimension) {
154 ✗ if (error)
155 ✗ *error = QCoreApplication::translate("ContactPhotoProvider", "Choose a picture of at most 4096 × 4096 pixels.");
156 ✗ return {};
157 }
158 3 const int side = qMin(256, qMin(size.width(), size.height()));
159
1/1
✓ Branch 38 → 39 taken 3 times.
3 reader.setScaledSize(size.scaled(side, side, Qt::KeepAspectRatioByExpanding));
160
1/1
✓ Branch 39 → 40 taken 3 times.
3 const QImage image = reader.read();
161
2/3
✓ Branch 40 → 41 taken 3 times.
✗ Branch 41 → 42 not taken.
✓ Branch 41 → 48 taken 3 times.
3 if (image.isNull()) {
162 ✗ if (error)
163 ✗ *error = QCoreApplication::translate("ContactPhotoProvider", "This file is not a picture MailJD can read.");
164 ✗ return {};
165 }
166
3/3
✓ Branch 48 → 49 taken 3 times.
✓ Branch 49 → 50 taken 3 times.
✓ Branch 50 → 51 taken 3 times.
3 const QImage square = image.copy((image.width() - side) / 2, (image.height() - side) / 2, side, side)
167
1/1
✓ Branch 52 → 53 taken 3 times.
3 .convertToFormat(QImage::Format_RGB32);
168
1/1
✓ Branch 54 → 55 taken 3 times.
3 const QByteArray jpeg = cardJpeg(square);
169
2/6
✗ Branch 56 → 57 not taken.
✓ Branch 56 → 59 taken 3 times.
✗ Branch 57 → 58 not taken.
✗ Branch 57 → 59 not taken.
✗ Branch 60 → 61 not taken.
✓ Branch 60 → 65 taken 3 times.
3 if (jpeg.isEmpty() && error)
170 ✗ *error = QCoreApplication::translate("ContactPhotoProvider", "This image cannot be used.");
171
9/9
✓ Branch 65 → 66 taken 3 times.
✓ Branch 69 → 70 taken 3 times.
✓ Branch 70 → 71 taken 3 times.
✓ Branch 71 → 72 taken 3 times.
✓ Branch 72 → 73 taken 3 times.
✓ Branch 74 → 75 taken 3 times.
✓ Branch 75 → 76 taken 3 times.
✓ Branch 79 → 67 taken 3 times.
✓ Branch 79 → 80 taken 3 times.
6 qCInfo(lcContactPhoto) << "Photo prepared:" << side << "px," << jpeg.size() << "bytes";
172 3 return jpeg;
173 7 }
174
175
176 4 QImage ContactPhotoProvider::preview(const QByteArray &bytes, int maxSide, QString *error) {
177 4 return readUpright(bytes, maxSide, error);
178 }
179
180 6 QByteArray ContactPhotoProvider::cropForCard(const QByteArray &bytes, const QRectF &crop, QString *error) {
181
1/1
✓ Branch 2 → 3 taken 6 times.
6 const QImage image = readUpright(bytes, 0, error);
182
3/3
✓ Branch 3 → 4 taken 6 times.
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 6 taken 5 times.
6 if (image.isNull())
183 1 return {};
184 // The framer's square in pixels of the upright image, kept inside it.
185
2/2
✓ Branch 13 → 14 taken 5 times.
✓ Branch 16 → 17 taken 5 times.
10 QRect area(qRound(crop.x() * image.width()), qRound(crop.y() * image.height()),
186
2/2
✓ Branch 7 → 8 taken 5 times.
✓ Branch 10 → 11 taken 5 times.
15 qRound(crop.width() * image.width()), qRound(crop.height() * image.height()));
187
1/1
✓ Branch 19 → 20 taken 5 times.
5 area = area.intersected(image.rect());
188 5 const int side = qMin(area.width(), area.height());
189
1/2
✗ Branch 24 → 25 not taken.
✓ Branch 24 → 31 taken 5 times.
5 if (side < 8) {
190 ✗ if (error)
191 ✗ *error = QCoreApplication::translate("ContactPhotoProvider", "This image cannot be used.");
192 ✗ return {};
193 }
194
1/1
✓ Branch 33 → 34 taken 5 times.
5 const QImage square = image.copy(area.x(), area.y(), side, side)
195
1/1
✓ Branch 36 → 37 taken 5 times.
10 .scaled(qMin(256, side), qMin(256, side), Qt::IgnoreAspectRatio, Qt::SmoothTransformation)
196
1/1
✓ Branch 38 → 39 taken 5 times.
5 .convertToFormat(QImage::Format_RGB32);
197
1/1
✓ Branch 41 → 42 taken 5 times.
5 const QByteArray jpeg = cardJpeg(square);
198
2/6
✗ Branch 43 → 44 not taken.
✓ Branch 43 → 46 taken 5 times.
✗ Branch 44 → 45 not taken.
✗ Branch 44 → 46 not taken.
✗ Branch 47 → 48 not taken.
✓ Branch 47 → 52 taken 5 times.
5 if (jpeg.isEmpty() && error)
199 ✗ *error = QCoreApplication::translate("ContactPhotoProvider", "This image cannot be used.");
200
10/10
✓ Branch 52 → 53 taken 5 times.
✓ Branch 56 → 57 taken 5 times.
✓ Branch 57 → 58 taken 5 times.
✓ Branch 58 → 59 taken 5 times.
✓ Branch 59 → 60 taken 5 times.
✓ Branch 60 → 61 taken 5 times.
✓ Branch 62 → 63 taken 5 times.
✓ Branch 63 → 64 taken 5 times.
✓ Branch 67 → 54 taken 5 times.
✓ Branch 67 → 68 taken 5 times.
10 qCInfo(lcContactPhoto) << "Photo framed:" << square.width() << "px," << jpeg.size() << "bytes";
201 5 return jpeg;
202 6 }
203
204 486 QImage ContactPhotoProvider::load(const QString &databasePath, const QString &cardKey, int side) {
205 486 qint64 bookId = 0;
206 486 QString uid;
207
3/3
✓ Branch 2 → 3 taken 486 times.
✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 5 taken 485 times.
486 if (!ContactQueries::splitKey(cardKey, &bookId, &uid))
208 1 return {};
209
1/1
✓ Branch 5 → 6 taken 485 times.
485 ContactStore store;
210
2/3
✓ Branch 6 → 7 taken 485 times.
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 485 times.
485 if (!store.open(databasePath))
211 ✗ return {};
212
1/1
✓ Branch 9 → 10 taken 485 times.
485 const auto stored = store.card(bookId, uid);
213
1/2
✗ Branch 11 → 12 not taken.
✓ Branch 11 → 13 taken 485 times.
485 if (!stored)
214 ✗ return {};
215
1/1
✓ Branch 13 → 14 taken 485 times.
485 ContactCard card;
216
2/3
✓ Branch 15 → 16 taken 485 times.
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 485 times.
485 if (!VCardCodec::parse(stored->raw, &card))
217 ✗ return {};
218 // D-15: a URI photo is shown only once ContactPhotoFetch fetched it from
219 // the book's own origin.
220
2/2
✓ Branch 18 → 19 taken 2 times.
✓ Branch 18 → 24 taken 483 times.
485 if (card.photo.kind == ContactPhoto::Kind::Uri)
221
2/2
✓ Branch 19 → 20 taken 2 times.
✓ Branch 20 → 21 taken 2 times.
2 return decode(store.fetchedPhoto(bookId, uid), side);
222
3/3
✓ Branch 24 → 25 taken 440 times.
✓ Branch 24 → 26 taken 43 times.
✓ Branch 25 → 27 taken 440 times.
483 return card.photo.kind == ContactPhoto::Kind::Inline ? decode(card.photo.data, side) : QImage();
223 486 }
224
225 2497 QQuickImageResponse *ContactPhotoProvider::requestImageResponse(const QString &encodedId, const QSize &requestedSize) {
226 // QML passes "<encodeURIComponent(cardKey)>/<encoded photo tag>": UIDs
227 // may contain any character; the tag changes with the photo.
228 2497 const int tagAt = encodedId.indexOf(QLatin1Char('/'));
229
3/3
✓ Branch 5 → 6 taken 2497 times.
✓ Branch 6 → 7 taken 2497 times.
✓ Branch 7 → 8 taken 2497 times.
2497 const QString id = QUrl::fromPercentEncoding(encodedId.left(tagAt).toUtf8());
230
2/3
✓ Branch 10 → 11 taken 2497 times.
✗ Branch 10 → 12 not taken.
✓ Branch 11 → 13 taken 2497 times.
2497 const QString tag = tagAt >= 0 ? encodedId.mid(tagAt + 1) : QString();
231
3/6
✓ Branch 13 → 14 taken 2497 times.
✓ Branch 14 → 15 taken 2497 times.
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 17 taken 2497 times.
✗ Branch 63 → 64 not taken.
✗ Branch 63 → 65 not taken.
2497 auto *response = new PhotoResponse;
232
1/1
✓ Branch 17 → 18 taken 2497 times.
2497 const int side = sideFor(requestedSize);
233
5/5
✓ Branch 20 → 21 taken 2497 times.
✓ Branch 23 → 24 taken 2497 times.
✓ Branch 24 → 25 taken 2497 times.
✓ Branch 25 → 26 taken 2497 times.
✓ Branch 26 → 27 taken 2497 times.
2497 const QString cacheKey = id + QLatin1Char('@') + QString::number(side) + QLatin1Char('#') + tag;
234 {
235 2497 QMutexLocker lock(&m_mutex);
236
2/2
✓ Branch 33 → 34 taken 2016 times.
✓ Branch 33 → 40 taken 481 times.
2497 if (const QImage *cached = m_cache.object(cacheKey)) {
237
1/1
✓ Branch 34 → 35 taken 2016 times.
2016 const QImage image = *cached;
238
2/2
✓ Branch 35 → 36 taken 2016 times.
✓ Branch 36 → 37 taken 2016 times.
4032 QMetaObject::invokeMethod(response, [response, image] { response->finish(image); }, Qt::QueuedConnection);
239 2016 return response;
240 2016 }
241 2497 }
242 // Qt's image-response pattern: the engine keeps the response alive until
243 // finished() (emitted from the worker; the engine's connection is queued).
244 481 const QString path = m_databasePath;
245
1/5
✓ Branch 48 → 50 taken 481 times.
✗ Branch 93 → 94 not taken.
✗ Branch 93 → 95 not taken.
✗ Branch 96 → 97 not taken.
✗ Branch 96 → 98 not taken.
481 m_pool.start([this, response, path, id, side, cacheKey] {
246
1/1
✓ Branch 2 → 3 taken 481 times.
481 const QImage image = load(path, id, side);
247 {
248 481 QMutexLocker lock(&m_mutex);
249
4/7
✓ Branch 4 → 5 taken 481 times.
✓ Branch 5 → 6 taken 481 times.
✓ Branch 6 → 7 taken 481 times.
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 481 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 15 not taken.
481 m_cache.insert(cacheKey, new QImage(image));
250 481 }
251
1/1
✓ Branch 10 → 11 taken 481 times.
481 response->finish(image);
252 481 });
253 481 return response;
254 2497 }
255
256 42 void ContactPhotoProvider::invalidate(const QStringList &cardKeys) {
257 42 QMutexLocker lock(&m_mutex);
258
5/5
✓ Branch 3 → 4 taken 42 times.
✓ Branch 4 → 5 taken 42 times.
✓ Branch 5 → 6 taken 42 times.
✓ Branch 23 → 7 taken 327 times.
✓ Branch 23 → 24 taken 42 times.
369 for (const QString &key : m_cache.keys())
259
2/2
✓ Branch 20 → 10 taken 327 times.
✓ Branch 20 → 21 taken 327 times.
654 for (const QString &card : cardKeys)
260
4/4
✓ Branch 13 → 14 taken 327 times.
✓ Branch 14 → 15 taken 327 times.
✓ Branch 16 → 17 taken 22 times.
✓ Branch 16 → 18 taken 305 times.
327 if (key.startsWith(card + QLatin1Char('@')))
261 64 m_cache.remove(key);
262 42 }
263