Spectral/src/imageprovider.h

71 lines
1.7 KiB
C
Raw Normal View History

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>
#include <QtCore/QAtomicPointer>
#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 {
Q_OBJECT
2019-01-04 12:17:26 +00:00
public:
ThumbnailResponse(QMatrixClient::Connection* c,
QString mediaId,
2019-01-04 12:17:26 +00:00
const QSize& requestedSize);
~ThumbnailResponse() override = default;
private slots:
2019-01-04 12:17:26 +00:00
void startRequest();
void prepareResult();
void doCancel();
2019-01-04 12:17:26 +00:00
private:
QMatrixClient::Connection* c;
const QString mediaId;
const QSize requestedSize;
const QString localFile;
2019-01-04 12:17:26 +00:00
QMatrixClient::MediaThumbnailJob* job = nullptr;
QImage image;
QString errorStr;
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:
explicit ImageProvider() = default;
2018-03-02 08:56:36 +00:00
2019-01-04 12:17:26 +00:00
QQuickImageResponse* requestImageResponse(
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);
emit connectionChanged();
2018-09-07 05:50:06 +00:00
}
signals:
void connectionChanged();
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