Spectral/src/imageprovider.h

62 lines
1.6 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 <jobs/mediathumbnailjob.h>
#include <QThreadPool>
#include <QtCore/QAtomicPointer>
2018-07-09 02:45:26 +00:00
#include <QtCore/QReadWriteLock>
2019-01-04 12:17:26 +00:00
#include <QtQuick/QQuickAsyncImageProvider>
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 {
public:
ThumbnailResponse(QMatrixClient::Connection* c, QString mediaId,
const QSize& requestedSize);
~ThumbnailResponse() override = default;
void startRequest();
private:
QMatrixClient::Connection* c;
const QString mediaId;
const QSize requestedSize;
QMatrixClient::MediaThumbnailJob* job = nullptr;
QImage image;
QString errorStr;
mutable QReadWriteLock lock;
void prepareResult();
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-01-04 12:17:26 +00:00
explicit ImageProvider() : QObject(), QQuickAsyncImageProvider() {}
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);
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