Clean up ImageLoaderManager

Unpointered NetworkAccessManager
Removed debug output
Removed unneeded includes
This commit is contained in:
Rasmus Karlsson 2017-10-08 15:30:55 +02:00
parent e7e4ab768b
commit 19630bf91b
3 changed files with 15 additions and 30 deletions

View file

@ -4,24 +4,17 @@
#include "windowmanager.hpp"
#include <QBuffer>
#include <QDebug>
#include <QEventLoop>
#include <QImageReader>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <sstream>
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);

View file

@ -1,15 +1,7 @@
#pragma once
#include <atomic>
#include <condition_variable>
#include <mutex>
#include <thread>
#include <vector>
#include <QEventLoop>
#include <QNetworkAccessManager>
#include <QThread>
#include <QTimerEvent>
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);
};

View file

@ -67,7 +67,6 @@ private:
void loadImage();
void gifUpdateTimout();
//static ImageLoaderManager imageLoader;
friend class ImageLoaderWorker;
};