From 8edc46dc16e2d3a5e5cbbd290a815d7e9d853003 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Tue, 21 Dec 2021 15:06:34 +0100 Subject: Cleanup jdenticon code in the same way as blurhashes --- src/JdenticonProvider.h | 52 +++++++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 19 deletions(-) (limited to 'src/JdenticonProvider.h') diff --git a/src/JdenticonProvider.h b/src/JdenticonProvider.h index 95f3db78..b387b3c1 100644 --- a/src/JdenticonProvider.h +++ b/src/JdenticonProvider.h @@ -13,31 +13,47 @@ #include "jdenticoninterface.h" -namespace Jdenticon { -JdenticonInterface * -getJdenticonInterface(); -} - -class JdenticonResponse - : public QQuickImageResponse +class JdenticonRunnable + : public QObject , public QRunnable { + Q_OBJECT public: - JdenticonResponse(const QString &key, bool crop, double radius, const QSize &requestedSize); - - QQuickTextureFactory *textureFactory() const override - { - return QQuickTextureFactory::textureFactoryForImage(m_pixmap.toImage()); - } + JdenticonRunnable(const QString &key, bool crop, double radius, const QSize &requestedSize); void run() override; +signals: + void done(QImage img); + +private: QString m_key; bool m_crop; double m_radius; QSize m_requestedSize; - QPixmap m_pixmap; - JdenticonInterface *jdenticonInterface_ = nullptr; +}; + +class JdenticonResponse : public QQuickImageResponse +{ +public: + JdenticonResponse(const QString &key, + bool crop, + double radius, + const QSize &requestedSize, + QThreadPool *pool); + + QQuickTextureFactory *textureFactory() const override + { + return QQuickTextureFactory::textureFactoryForImage(m_pixmap); + } + + void handleDone(QImage img) + { + m_pixmap = std::move(img); + emit finished(); + } + + QImage m_pixmap; }; class JdenticonProvider @@ -47,7 +63,7 @@ class JdenticonProvider Q_OBJECT public: - static bool isAvailable() { return Jdenticon::getJdenticonInterface() != nullptr; } + static bool isAvailable(); public slots: QQuickImageResponse * @@ -70,9 +86,7 @@ public slots: } } - JdenticonResponse *response = new JdenticonResponse(id_, crop, radius, requestedSize); - pool.start(response); - return response; + return new JdenticonResponse(id_, crop, radius, requestedSize, &pool); } private: -- cgit 1.5.1