diff --git a/src/messages/imageloadermanager.cpp b/src/messages/imageloadermanager.cpp index a1ed63d13..edfc2f125 100644 --- a/src/messages/imageloadermanager.cpp +++ b/src/messages/imageloadermanager.cpp @@ -4,24 +4,17 @@ #include "windowmanager.hpp" #include -#include -#include #include #include #include #include -#include - namespace chatterino { namespace messages { ImageLoaderManager::ImageLoaderManager() - : NaM(new QNetworkAccessManager) { - qDebug() << "imageloaderthread" << QThread::currentThread(); - qDebug() << "workerthread: " << &this->workerThread; - this->NaM->moveToThread(&this->workerThread); + this->NaM.moveToThread(&this->workerThread); this->workerThread.start(); } @@ -33,30 +26,28 @@ ImageLoaderManager::~ImageLoaderManager() void ImageLoaderWorker::handleRequest(LazyLoadedImage *lli, QNetworkAccessManager *nam) { - QNetworkRequest request; - request.setUrl(QUrl(lli->getUrl())); - qDebug() << "handleRequest: " << lli->getUrl(); + QNetworkRequest request(QUrl(lli->getUrl())); QNetworkReply *reply = nam->get(request); + QObject::connect(reply, &QNetworkReply::finished, [lli, reply, this]() { this->handleLoad(lli, reply); }); - } void ImageLoaderManager::queue(chatterino::messages::LazyLoadedImage *lli) { ImageLoaderRequester requester; - ImageLoaderWorker *workerer = new ImageLoaderWorker; - workerer->moveToThread(&this->workerThread); - QObject::connect(&requester, &ImageLoaderRequester::request, workerer, + ImageLoaderWorker *worker = new ImageLoaderWorker; + + worker->moveToThread(&this->workerThread); + + QObject::connect(&requester, &ImageLoaderRequester::request, worker, &ImageLoaderWorker::handleRequest); - emit requester.request(lli, this->NaM); - qDebug() << lli->getUrl(); + + emit requester.request(lli, &this->NaM); } void ImageLoaderWorker::handleLoad(chatterino::messages::LazyLoadedImage *lli, QNetworkReply *reply) { - qDebug() << "Received emote " << lli->url; - qDebug() << QThread::currentThread(); QByteArray array = reply->readAll(); QBuffer buffer(&array); buffer.open(QIODevice::ReadOnly); diff --git a/src/messages/imageloadermanager.hpp b/src/messages/imageloadermanager.hpp index 6024cade3..9f0f0250a 100644 --- a/src/messages/imageloadermanager.hpp +++ b/src/messages/imageloadermanager.hpp @@ -1,15 +1,7 @@ #pragma once -#include -#include -#include -#include -#include - -#include #include #include -#include namespace chatterino { namespace messages { @@ -19,7 +11,7 @@ class LazyLoadedImage; class ImageLoaderWorker : public QObject { Q_OBJECT -public: + public slots: void handleRequest(chatterino::messages::LazyLoadedImage *lli, QNetworkAccessManager *nam); void handleLoad(LazyLoadedImage *lli, QNetworkReply *reply); @@ -28,6 +20,7 @@ public slots: class ImageLoaderRequester : public QObject { Q_OBJECT + signals: void request(chatterino::messages::LazyLoadedImage *lli, QNetworkAccessManager *nam); }; @@ -35,12 +28,14 @@ signals: class ImageLoaderManager : public QObject { Q_OBJECT + QThread workerThread; - QNetworkAccessManager *NaM; + QNetworkAccessManager NaM; public: ImageLoaderManager(); ~ImageLoaderManager(); + void queue(chatterino::messages::LazyLoadedImage *lli); }; diff --git a/src/messages/lazyloadedimage.hpp b/src/messages/lazyloadedimage.hpp index 59e8cc410..50c544589 100644 --- a/src/messages/lazyloadedimage.hpp +++ b/src/messages/lazyloadedimage.hpp @@ -67,7 +67,6 @@ private: void loadImage(); void gifUpdateTimout(); - //static ImageLoaderManager imageLoader; friend class ImageLoaderWorker; };