1 | // SPDX-FileCopyrightText: 2018 Kitsune Ral <Kitsune-Ral@users.sf.net> |
2 | // SPDX-License-Identifier: LGPL-2.1-or-later |
3 | |
4 | #include "mediathumbnailjob.h" |
5 | |
6 | #include "../logging_categories_p.h" |
7 | |
8 | using namespace Quotient; |
9 | |
10 | QUrl MediaThumbnailJob::makeRequestUrl(QUrl baseUrl, const QUrl& mxcUri, |
11 | QSize requestedSize) |
12 | { |
13 | return makeRequestUrl(baseUrl: std::move(baseUrl), serverName: mxcUri.authority(), |
14 | mediaId: mxcUri.path().mid(position: 1), width: requestedSize.width(), |
15 | height: requestedSize.height()); |
16 | } |
17 | |
18 | MediaThumbnailJob::MediaThumbnailJob(const QString& serverName, |
19 | const QString& mediaId, QSize requestedSize) |
20 | : GetContentThumbnailJob(serverName, mediaId, requestedSize.width(), |
21 | requestedSize.height(), "scale"_ls ) |
22 | { |
23 | setLoggingCategory(THUMBNAILJOB); |
24 | } |
25 | |
26 | MediaThumbnailJob::MediaThumbnailJob(const QUrl& mxcUri, QSize requestedSize) |
27 | : MediaThumbnailJob(mxcUri.authority(), |
28 | mxcUri.path().mid(position: 1), // sans leading '/' |
29 | requestedSize) |
30 | { |
31 | setLoggingCategory(THUMBNAILJOB); |
32 | } |
33 | |
34 | QImage MediaThumbnailJob::thumbnail() const { return _thumbnail; } |
35 | |
36 | QImage MediaThumbnailJob::scaledThumbnail(QSize toSize) const |
37 | { |
38 | return _thumbnail.scaled(s: toSize, aspectMode: Qt::KeepAspectRatio, |
39 | mode: Qt::SmoothTransformation); |
40 | } |
41 | |
42 | BaseJob::Status MediaThumbnailJob::prepareResult() |
43 | { |
44 | if (_thumbnail.loadFromData(data: data()->readAll())) |
45 | return Success; |
46 | |
47 | return { IncorrectResponse, QStringLiteral("Could not read image data" ) }; |
48 | } |
49 | |