mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 01:23:24 -08:00
Format picture-loader changes using project style
This commit is contained in:
parent
5d7ddf69b8
commit
c28acf8ba6
4 changed files with 26 additions and 30 deletions
|
|
@ -4,9 +4,9 @@
|
|||
#include <QBuffer>
|
||||
#include <QByteArray>
|
||||
#include <QByteArrayList>
|
||||
#include <QIODevice>
|
||||
#include <QImage>
|
||||
#include <QImageReader>
|
||||
#include <QIODevice>
|
||||
#include <QMovie>
|
||||
#include <QString>
|
||||
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@
|
|||
#include "card_picture_loader_local.h"
|
||||
#include "card_picture_loader_worker_work.h"
|
||||
#include "card_picture_to_load.h"
|
||||
#include "redirect_chain.h"
|
||||
#include "libcockatrice/card/printing/exact_card.h"
|
||||
#include "libcockatrice/utility/server_rate_limiter.h"
|
||||
#include "redirect_chain.h"
|
||||
|
||||
#include <QAbstractNetworkCache>
|
||||
#include <QByteArray>
|
||||
|
|
@ -102,23 +102,22 @@ CardPictureLoaderWorker::CardPictureLoaderWorker()
|
|||
|
||||
connect(&SettingsCache::instance().downloads(), &DownloadSettings::hostRequestLimitsChanged, this,
|
||||
[this] { hostRequestLimits = SettingsCache::instance().downloads().getHostRequestLimits(); });
|
||||
connect(&SettingsCache::instance().downloads(), &DownloadSettings::picDownloadChanged, this,
|
||||
[this] {
|
||||
picDownload = SettingsCache::instance().downloads().getPicDownload();
|
||||
if (!picDownload) {
|
||||
// Waiting for network quota or 429 recovery cannot help a cache-only lookup.
|
||||
// Retire cancelled status entries just as the normal dispatcher does.
|
||||
while (!requestLoadQueue.isEmpty()) {
|
||||
const auto entry = requestLoadQueue.takeFirst();
|
||||
if (entry.second) {
|
||||
makeRequest(entry.first, entry.second);
|
||||
} else {
|
||||
emit imageRequestSucceeded(entry.first);
|
||||
}
|
||||
}
|
||||
updateTimerState();
|
||||
connect(&SettingsCache::instance().downloads(), &DownloadSettings::picDownloadChanged, this, [this] {
|
||||
picDownload = SettingsCache::instance().downloads().getPicDownload();
|
||||
if (!picDownload) {
|
||||
// Waiting for network quota or 429 recovery cannot help a cache-only lookup.
|
||||
// Retire cancelled status entries just as the normal dispatcher does.
|
||||
while (!requestLoadQueue.isEmpty()) {
|
||||
const auto entry = requestLoadQueue.takeFirst();
|
||||
if (entry.second) {
|
||||
makeRequest(entry.first, entry.second);
|
||||
} else {
|
||||
emit imageRequestSucceeded(entry.first);
|
||||
}
|
||||
});
|
||||
}
|
||||
updateTimerState();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
CardPictureLoaderWorker::~CardPictureLoaderWorker()
|
||||
|
|
@ -157,9 +156,9 @@ void CardPictureLoaderWorker::queueRequest(const QUrl &url, CardPictureLoaderWor
|
|||
{
|
||||
const QUrl resolvedUrl = resolveCachedRedirect(url);
|
||||
if (!picDownload || (static_cast<CardPictureLoaderCacheMethod::CacheMethod>(
|
||||
SettingsCache::instance().cacheStorage().getCardPictureLoaderCacheMethod()) ==
|
||||
CardPictureLoaderCacheMethod::CacheMethod::NETWORK_CACHE &&
|
||||
cache->metaData(resolvedUrl).isValid() && !worker->shouldBypassCache(resolvedUrl))) {
|
||||
SettingsCache::instance().cacheStorage().getCardPictureLoaderCacheMethod()) ==
|
||||
CardPictureLoaderCacheMethod::CacheMethod::NETWORK_CACHE &&
|
||||
cache->metaData(resolvedUrl).isValid() && !worker->shouldBypassCache(resolvedUrl))) {
|
||||
// A request that will be served from the disk cache never touches the network and therefore
|
||||
// doesn't use up any of the rate limit, so it gets to skip the queue.
|
||||
// Every reply retires a status, including online cache hits and deferred
|
||||
|
|
@ -180,9 +179,8 @@ QNetworkReply *CardPictureLoaderWorker::makeRequest(const QUrl &url, CardPicture
|
|||
const QUrl resolvedUrl = resolveCachedRedirect(url);
|
||||
if (resolvedUrl != url) {
|
||||
emit imageRequestSucceeded(url);
|
||||
if (requestTouchesNetwork(resolvedUrl, worker) &&
|
||||
CardPictureLoaderWorkerWork::rateLimiter().isRateLimited(resolvedUrl.host(),
|
||||
QDateTime::currentDateTime())) {
|
||||
if (requestTouchesNetwork(resolvedUrl, worker) && CardPictureLoaderWorkerWork::rateLimiter().isRateLimited(
|
||||
resolvedUrl.host(), QDateTime::currentDateTime())) {
|
||||
worker->scheduleDeferredRetry(resolvedUrl.host());
|
||||
return nullptr;
|
||||
}
|
||||
|
|
@ -443,8 +441,7 @@ bool CardPictureLoaderWorker::processSingleRequest()
|
|||
return false;
|
||||
}
|
||||
|
||||
bool CardPictureLoaderWorker::requestTouchesNetwork(const QUrl &url,
|
||||
const CardPictureLoaderWorkerWork *worker) const
|
||||
bool CardPictureLoaderWorker::requestTouchesNetwork(const QUrl &url, const CardPictureLoaderWorkerWork *worker) const
|
||||
{
|
||||
if (!picDownload) {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -263,8 +263,7 @@ void CardPictureLoaderWorkerWork::handleSuccessfulReply(QNetworkReply *reply)
|
|||
int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
if (statusCode == 301 || statusCode == 302 || statusCode == 303 || statusCode == 305 || statusCode == 307 ||
|
||||
statusCode == 308) {
|
||||
QUrl redirectUrl = reply->url().resolved(
|
||||
reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl());
|
||||
QUrl redirectUrl = reply->url().resolved(reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl());
|
||||
qCDebug(CardPictureLoaderWorkerWorkLog).nospace()
|
||||
<< "PictureLoader: [card: " << cardToDownload.getCard().getName() << " set: " << cardToDownload.getSetName()
|
||||
<< "]: following " << (isFromCache ? "cached redirect" : "redirect") << " to "
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@
|
|||
#include <QImage>
|
||||
#include <QLoggingCategory>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QSet>
|
||||
#include <QString>
|
||||
#include <QTimer>
|
||||
#include <QUrl>
|
||||
#include <qtmetamacros.h>
|
||||
|
|
@ -80,7 +80,7 @@ public slots:
|
|||
void handleNetworkReply(QNetworkReply *reply);
|
||||
|
||||
private:
|
||||
bool picDownload; ///< Whether network downloading is enabled
|
||||
bool picDownload; ///< Whether network downloading is enabled
|
||||
QTimer *deferredRetry = nullptr; ///< Owned retry, cancellable when downloads are disabled
|
||||
QSet<QUrl> retriedCacheUrls;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue