File indexing completed on 2024-10-13 12:46:07

0001 // SPDX-FileCopyrightText: 2018-2019 Black Hat <bhat@encom.eu.org>
0002 // SPDX-FileCopyrightText: 2019 Kitsune Ral <kitsune-ral@users.sf.net>
0003 // SPDX-License-Identifier: GPL-3.0-only
0004 
0005 #pragma once
0006 
0007 #include <QQuickAsyncImageProvider>
0008 
0009 #include <Quotient/jobs/mediathumbnailjob.h>
0010 
0011 #include <QReadWriteLock>
0012 
0013 namespace Quotient
0014 {
0015 class Connection;
0016 }
0017 
0018 /**
0019  * @class ThumbnailResponse
0020  *
0021  * A QQuickImageResponse for an mxc image.
0022  *
0023  * @sa QQuickImageResponse
0024  */
0025 class ThumbnailResponse : public QQuickImageResponse
0026 {
0027     Q_OBJECT
0028 public:
0029     explicit ThumbnailResponse(QString mediaId, QSize requestedSize);
0030     ~ThumbnailResponse() override = default;
0031 
0032 private Q_SLOTS:
0033     void startRequest();
0034     void prepareResult();
0035 
0036 private:
0037     QString mediaId;
0038     QSize requestedSize;
0039     const QString localFile;
0040     Quotient::MediaThumbnailJob *job = nullptr;
0041 
0042     QImage image;
0043     QString errorStr;
0044     mutable QReadWriteLock lock; // Guards ONLY these two members above
0045 
0046     QQuickTextureFactory *textureFactory() const override;
0047     QString errorString() const override;
0048 };
0049 
0050 /**
0051  * @class MatrixImageProvider
0052  *
0053  * A QQuickAsyncImageProvider for mxc images.
0054  *
0055  * @sa QQuickAsyncImageProvider
0056  */
0057 class MatrixImageProvider : public QQuickAsyncImageProvider
0058 {
0059 public:
0060     /**
0061      * @brief Return a job to provide the image with the given ID.
0062      *
0063      * @sa QQuickAsyncImageProvider::requestImageResponse
0064      */
0065     QQuickImageResponse *requestImageResponse(const QString &id, const QSize &requestedSize) override;
0066 };