summary refs log tree commit diff
path: root/src/JdenticonProvider.h
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2021-12-21 15:06:34 +0100
committerNicolas Werner <nicolas.werner@hotmail.de>2021-12-21 15:06:34 +0100
commit8edc46dc16e2d3a5e5cbbd290a815d7e9d853003 (patch)
tree89d0074c350d31f9bd3c81212b99c63eb6abda9b /src/JdenticonProvider.h
parentCleanup blurhash formatting (diff)
downloadnheko-8edc46dc16e2d3a5e5cbbd290a815d7e9d853003.tar.xz
Cleanup jdenticon code in the same way as blurhashes
Diffstat (limited to 'src/JdenticonProvider.h')
-rw-r--r--src/JdenticonProvider.h52
1 files changed, 33 insertions, 19 deletions
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: