2018-03-02 08:56:36 +00:00
|
|
|
#ifndef IMAGEPROVIDER_H
|
|
|
|
#define IMAGEPROVIDER_H
|
2019-01-04 12:17:26 +00:00
|
|
|
#pragma once
|
2018-03-02 08:56:36 +00:00
|
|
|
|
2019-01-04 12:17:26 +00:00
|
|
|
#include <QtQuick/QQuickAsyncImageProvider>
|
2019-02-28 11:20:26 +00:00
|
|
|
|
|
|
|
#include <connection.h>
|
|
|
|
#include <jobs/mediathumbnailjob.h>
|
|
|
|
|
2019-02-28 10:34:24 +00:00
|
|
|
#include <QtCore/QAtomicPointer>
|
2019-04-22 13:16:33 +00:00
|
|
|
#include <QtCore/QReadWriteLock>
|
2018-03-02 08:56:36 +00:00
|
|
|
|
2019-01-04 12:17:26 +00:00
|
|
|
namespace QMatrixClient {
|
|
|
|
class Connection;
|
|
|
|
}
|
2018-03-02 08:56:36 +00:00
|
|
|
|
2019-01-04 12:17:26 +00:00
|
|
|
class ThumbnailResponse : public QQuickImageResponse {
|
2019-02-28 10:34:24 +00:00
|
|
|
Q_OBJECT
|
2019-01-04 12:17:26 +00:00
|
|
|
public:
|
2019-04-22 13:16:33 +00:00
|
|
|
ThumbnailResponse(QMatrixClient::Connection* c,
|
|
|
|
QString mediaId,
|
2019-01-04 12:17:26 +00:00
|
|
|
const QSize& requestedSize);
|
|
|
|
~ThumbnailResponse() override = default;
|
|
|
|
|
2019-04-22 13:16:33 +00:00
|
|
|
private slots:
|
2019-01-04 12:17:26 +00:00
|
|
|
void startRequest();
|
2019-02-28 10:34:24 +00:00
|
|
|
void prepareResult();
|
|
|
|
void doCancel();
|
2019-01-04 12:17:26 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
QMatrixClient::Connection* c;
|
|
|
|
const QString mediaId;
|
|
|
|
const QSize requestedSize;
|
2019-04-22 13:16:33 +00:00
|
|
|
const QString localFile;
|
2019-01-04 12:17:26 +00:00
|
|
|
QMatrixClient::MediaThumbnailJob* job = nullptr;
|
|
|
|
|
|
|
|
QImage image;
|
|
|
|
QString errorStr;
|
2019-04-22 13:16:33 +00:00
|
|
|
mutable QReadWriteLock lock; // Guards ONLY these two members above
|
2019-01-04 12:17:26 +00:00
|
|
|
|
|
|
|
QQuickTextureFactory* textureFactory() const override;
|
|
|
|
QString errorString() const override;
|
|
|
|
void cancel() override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ImageProvider : public QObject, public QQuickAsyncImageProvider {
|
2018-09-07 05:50:06 +00:00
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(QMatrixClient::Connection* connection READ connection WRITE
|
|
|
|
setConnection NOTIFY connectionChanged)
|
2018-07-09 02:45:26 +00:00
|
|
|
public:
|
2019-02-28 10:34:24 +00:00
|
|
|
explicit ImageProvider() = default;
|
2018-03-02 08:56:36 +00:00
|
|
|
|
2019-01-04 12:17:26 +00:00
|
|
|
QQuickImageResponse* requestImageResponse(
|
2019-04-22 13:16:33 +00:00
|
|
|
const QString& id,
|
|
|
|
const QSize& requestedSize) override;
|
2018-03-02 08:56:36 +00:00
|
|
|
|
2018-09-07 05:50:06 +00:00
|
|
|
QMatrixClient::Connection* connection() { return m_connection; }
|
2019-01-04 12:17:26 +00:00
|
|
|
void setConnection(QMatrixClient::Connection* connection) {
|
|
|
|
m_connection.store(connection);
|
2019-02-28 10:34:24 +00:00
|
|
|
emit connectionChanged();
|
2018-09-07 05:50:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void connectionChanged();
|
2018-07-07 09:38:20 +00:00
|
|
|
|
2018-07-09 02:45:26 +00:00
|
|
|
private:
|
2019-01-04 12:17:26 +00:00
|
|
|
QAtomicPointer<QMatrixClient::Connection> m_connection;
|
2018-03-02 08:56:36 +00:00
|
|
|
};
|
|
|
|
|
2018-07-09 02:45:26 +00:00
|
|
|
#endif // IMAGEPROVIDER_H
|