summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2021-12-07 23:58:17 +0100
committerNicolas Werner <nicolas.werner@hotmail.de>2021-12-08 02:43:03 +0100
commit30791f7890bb1ab4504a1b6b7101d9b050c786be (patch)
tree84f488cf6ffc8dc5e763967af75628117535e547 /src
parentAllow swiping between views in single page mode (diff)
downloadnheko-30791f7890bb1ab4504a1b6b7101d9b050c786be.tar.xz
Get rid of threadpool for images
Diffstat (limited to 'src')
-rw-r--r--src/BlurhashProvider.h1
-rw-r--r--src/MxcImageProvider.cpp12
-rw-r--r--src/MxcImageProvider.h56
3 files changed, 48 insertions, 21 deletions
diff --git a/src/BlurhashProvider.h b/src/BlurhashProvider.h

index 08693673..39d63d3c 100644 --- a/src/BlurhashProvider.h +++ b/src/BlurhashProvider.h
@@ -16,7 +16,6 @@ class BlurhashResponse { public: BlurhashResponse(const QString &id, const QSize &requestedSize) - : m_id(id) , m_requestedSize(requestedSize) { diff --git a/src/MxcImageProvider.cpp b/src/MxcImageProvider.cpp
index 5d0ee0be..35bc0586 100644 --- a/src/MxcImageProvider.cpp +++ b/src/MxcImageProvider.cpp
@@ -43,9 +43,7 @@ MxcImageProvider::requestImageResponse(const QString &id, const QSize &requested } } - MxcImageResponse *response = new MxcImageResponse(id_, crop, radius, requestedSize); - pool.start(response); - return response; + return new MxcImageResponse(id_, crop, radius, requestedSize); } void @@ -54,18 +52,18 @@ MxcImageProvider::addEncryptionInfo(mtx::crypto::EncryptedFile info) infos.insert(QString::fromStdString(info.url), info); } void -MxcImageResponse::run() +MxcImageRunnable::run() { MxcImageProvider::download( m_id, m_requestedSize, [this](QString, QSize, QImage image, QString) { if (image.isNull()) { - m_error = "Failed to download image."; + emit error("Failed to download image."); } else { - m_image = image; + emit done(image); } - emit finished(); + this->deleteLater(); }, m_crop, m_radius); diff --git a/src/MxcImageProvider.h b/src/MxcImageProvider.h
index 5d5b9c77..3d61c2ab 100644 --- a/src/MxcImageProvider.h +++ b/src/MxcImageProvider.h
@@ -8,24 +8,59 @@ #include <QQuickImageResponse> #include <QImage> -#include <QThreadPool> +//#include <QThreadPool> #include <functional> #include <mtx/common.hpp> -class MxcImageResponse - : public QQuickImageResponse - , public QRunnable +class MxcImageRunnable + : public QObject { + Q_OBJECT + +signals: + void done(QImage image); + void error(QString error); + public: - MxcImageResponse(const QString &id, bool crop, double radius, const QSize &requestedSize) + MxcImageRunnable(const QString &id, bool crop, double radius, const QSize &requestedSize) : m_id(id) , m_requestedSize(requestedSize) , m_crop(crop) , m_radius(radius) { - setAutoDelete(false); + } + + void run(); + + QString m_id; + QSize m_requestedSize; + bool m_crop; + double m_radius; +}; +class MxcImageResponse + : public QQuickImageResponse +{ +public: + MxcImageResponse(const QString &id, bool crop, double radius, const QSize &requestedSize) + + { + auto runnable = new MxcImageRunnable(id, crop, radius, requestedSize); + connect(runnable, &MxcImageRunnable::done, this, &MxcImageResponse::handleDone); + connect(runnable, &MxcImageRunnable::error, this, &MxcImageResponse::handleError); + runnable->run(); + } + + void handleDone(QImage image) + { + m_image = image; + emit finished(); + } + void handleError(QString error) + { + m_error = error; + emit finished(); } QQuickTextureFactory *textureFactory() const override @@ -34,13 +69,8 @@ public: } QString errorString() const override { return m_error; } - void run() override; - - QString m_id, m_error; - QSize m_requestedSize; + QString m_error; QImage m_image; - bool m_crop; - double m_radius; }; class MxcImageProvider @@ -60,5 +90,5 @@ public slots: double radius = 0); private: - QThreadPool pool; + // QThreadPool pool; };