mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-12 17:14:52 -07:00
[PictureLoader] Use thread pool instead of creating new thread (#6072)
* delete threads * Run reply processing in thread pool
This commit is contained in:
parent
38f76d449a
commit
1649f30389
3 changed files with 14 additions and 13 deletions
|
|
@ -94,7 +94,7 @@ QNetworkReply *PictureLoaderWorker::makeRequest(const QUrl &url, PictureLoaderWo
|
|||
QNetworkReply *reply = networkManager->get(req);
|
||||
|
||||
// Connect reply handling
|
||||
connect(reply, &QNetworkReply::finished, worker, [reply, worker] { worker->handleNetworkReply(reply); });
|
||||
connect(reply, &QNetworkReply::finished, worker, [reply, worker] { worker->acceptNetworkReply(reply); });
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
#include <QNetworkDiskCache>
|
||||
#include <QNetworkReply>
|
||||
#include <QThread>
|
||||
#include <QThreadPool>
|
||||
|
||||
// Card back returned by gatherer when card is not found
|
||||
static const QStringList MD5_BLACKLIST = {"db0c48db407a907c16ade38de048a441"};
|
||||
|
|
@ -28,16 +29,7 @@ PictureLoaderWorkerWork::PictureLoaderWorkerWork(const PictureLoaderWorker *work
|
|||
// Hook up signals to settings
|
||||
connect(&SettingsCache::instance(), SIGNAL(picDownloadChanged()), this, SLOT(picDownloadChanged()));
|
||||
|
||||
pictureLoaderThread = new QThread;
|
||||
moveToThread(pictureLoaderThread);
|
||||
|
||||
connect(pictureLoaderThread, &QThread::started, this, &PictureLoaderWorkerWork::startNextPicDownload);
|
||||
|
||||
// clean up threads once loading finishes
|
||||
connect(this, &QObject::destroyed, pictureLoaderThread, &QThread::quit);
|
||||
connect(pictureLoaderThread, &QThread::finished, pictureLoaderThread, &QObject::deleteLater);
|
||||
|
||||
pictureLoaderThread->start(QThread::LowPriority);
|
||||
startNextPicDownload();
|
||||
}
|
||||
|
||||
void PictureLoaderWorkerWork::startNextPicDownload()
|
||||
|
|
@ -78,6 +70,15 @@ void PictureLoaderWorkerWork::picDownloadFailed()
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the reply in another thread.
|
||||
* @param reply The finished reply. Takes ownership of the object
|
||||
*/
|
||||
void PictureLoaderWorkerWork::acceptNetworkReply(QNetworkReply *reply)
|
||||
{
|
||||
QThreadPool::globalInstance()->start([this, reply] { handleNetworkReply(reply); });
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param reply The reply. Takes ownership of the object
|
||||
|
|
|
|||
|
|
@ -30,14 +30,14 @@ public:
|
|||
PictureToLoad cardToDownload;
|
||||
|
||||
public slots:
|
||||
void handleNetworkReply(QNetworkReply *reply);
|
||||
void acceptNetworkReply(QNetworkReply *reply);
|
||||
|
||||
private:
|
||||
QThread *pictureLoaderThread;
|
||||
bool picDownload;
|
||||
|
||||
void startNextPicDownload();
|
||||
void picDownloadFailed();
|
||||
void handleNetworkReply(QNetworkReply *reply);
|
||||
void handleFailedReply(const QNetworkReply *reply);
|
||||
void handleSuccessfulReply(QNetworkReply *reply);
|
||||
QImage tryLoadImageFromReply(QNetworkReply *reply);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue