presentation/ComposeThumbnailProvider.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "ComposeThumbnailProvider.h" | ||
| 2 | #include "ComposeLog.h" | ||
| 3 | |||
| 4 | #include <QDir> | ||
| 5 | #include <QFileInfo> | ||
| 6 | #include <QImageReader> | ||
| 7 | #include <QUrl> | ||
| 8 | |||
| 9 | namespace { | ||
| 10 | constexpr int MaximumEdge = 256; | ||
| 11 | } | ||
| 12 | |||
| 13 | 12 | QString ComposeThumbnailProvider::draftPath(const QString &id) { | |
| 14 |
2/2✓ Branch 2 → 3 taken 12 times.
✓ Branch 3 → 4 taken 12 times.
|
12 | const QString path = QUrl::fromPercentEncoding(id.toUtf8()); |
| 15 |
1/1✓ Branch 5 → 6 taken 12 times.
|
12 | const QFileInfo info(path); |
| 16 |
6/7✓ Branch 7 → 8 taken 12 times.
✗ Branch 7 → 10 not taken.
✓ Branch 8 → 9 taken 12 times.
✓ Branch 9 → 10 taken 1 time.
✓ Branch 9 → 11 taken 11 times.
✓ Branch 12 → 13 taken 1 time.
✓ Branch 12 → 14 taken 11 times.
|
12 | if (path.isEmpty() || !info.isAbsolute()) return {}; |
| 17 |
1/1✓ Branch 14 → 15 taken 11 times.
|
11 | const QString canonical = info.canonicalFilePath(); |
| 18 |
6/12✓ Branch 16 → 17 taken 11 times.
✗ Branch 16 → 20 not taken.
✓ Branch 17 → 18 taken 11 times.
✓ Branch 18 → 19 taken 11 times.
✗ Branch 19 → 20 not taken.
✓ Branch 19 → 21 taken 11 times.
✓ Branch 22 → 23 taken 11 times.
✗ Branch 22 → 24 not taken.
✗ Branch 24 → 25 not taken.
✓ Branch 24 → 26 taken 11 times.
✗ Branch 54 → 55 not taken.
✗ Branch 54 → 56 not taken.
|
11 | if (canonical.isEmpty() || !QFileInfo(canonical).isFile()) return {}; |
| 19 | // The file must sit below a directory named "compose-drafts" (symlinks | ||
| 20 | // resolved, so "../" or a link cannot leave the store). | ||
| 21 |
6/6✓ Branch 26 → 27 taken 11 times.
✓ Branch 27 → 28 taken 11 times.
✓ Branch 37 → 38 taken 31 times.
✓ Branch 38 → 39 taken 42 times.
✓ Branch 39 → 30 taken 39 times.
✓ Branch 39 → 40 taken 3 times.
|
42 | for (QDir dir = QFileInfo(canonical).dir(); !dir.isRoot(); dir.cdUp()) |
| 22 |
5/5✓ Branch 31 → 32 taken 39 times.
✓ Branch 34 → 35 taken 8 times.
✓ Branch 34 → 37 taken 31 times.
✓ Branch 42 → 43 taken 3 times.
✓ Branch 42 → 45 taken 8 times.
|
42 | if (dir.dirName() == QLatin1String("compose-drafts")) return canonical; |
| 23 | 3 | return {}; | |
| 24 | 12 | } | |
| 25 | |||
| 26 | 8 | QImage ComposeThumbnailProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize) { | |
| 27 |
1/1✓ Branch 2 → 3 taken 8 times.
|
8 | const QString path = draftPath(id); |
| 28 |
2/2✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 16 taken 7 times.
|
8 | if (path.isEmpty()) { |
| 29 |
5/5✓ Branch 5 → 6 taken 1 time.
✓ Branch 9 → 10 taken 1 time.
✓ Branch 10 → 11 taken 1 time.
✓ Branch 14 → 7 taken 1 time.
✓ Branch 14 → 15 taken 1 time.
|
2 | qCWarning(lcCompose) << "thumbnail refused outside the draft store"; |
| 30 | 1 | return {}; | |
| 31 | } | ||
| 32 |
1/1✓ Branch 17 → 18 taken 7 times.
|
7 | QImageReader reader(path); |
| 33 |
1/1✓ Branch 19 → 20 taken 7 times.
|
7 | reader.setAutoTransform(true); |
| 34 |
1/1✓ Branch 20 → 21 taken 7 times.
|
7 | QSize source = reader.size(); |
| 35 |
1/1✓ Branch 24 → 25 taken 7 times.
|
7 | const int edge = qBound(16, qMax(requestedSize.width(), requestedSize.height()), MaximumEdge); |
| 36 |
3/3✓ Branch 26 → 27 taken 6 times.
✓ Branch 26 → 30 taken 1 time.
✓ Branch 28 → 29 taken 6 times.
|
7 | if (source.isValid()) reader.setScaledSize(source.scaled(edge, edge, Qt::KeepAspectRatio)); |
| 37 |
1/1✓ Branch 30 → 31 taken 7 times.
|
7 | QImage image = reader.read(); |
| 38 |
3/3✓ Branch 31 → 32 taken 7 times.
✓ Branch 32 → 33 taken 1 time.
✓ Branch 32 → 34 taken 6 times.
|
7 | if (image.isNull()) return {}; |
| 39 |
5/8✓ Branch 34 → 35 taken 6 times.
✓ Branch 35 → 36 taken 6 times.
✗ Branch 35 → 38 not taken.
✓ Branch 36 → 37 taken 6 times.
✗ Branch 37 → 38 not taken.
✓ Branch 37 → 39 taken 6 times.
✗ Branch 40 → 41 not taken.
✓ Branch 40 → 45 taken 6 times.
|
6 | if (image.width() > MaximumEdge || image.height() > MaximumEdge) |
| 40 | ✗ | image = image.scaled(MaximumEdge, MaximumEdge, Qt::KeepAspectRatio, Qt::SmoothTransformation); | |
| 41 |
2/3✓ Branch 45 → 46 taken 6 times.
✗ Branch 45 → 47 not taken.
✓ Branch 46 → 47 taken 6 times.
|
6 | if (size) *size = image.size(); |
| 42 | 6 | return image; | |
| 43 | 8 | } | |
| 44 |