1#ifndef PICTURE_LOADER_WORKER_H
2#define PICTURE_LOADER_WORKER_H
5#include <QLoggingCategory>
13#include <qtmetamacros.h>
19class QNetworkAccessManager;
20class QNetworkDiskCache;
24#define REDIRECT_HEADER_NAME "redirects"
25#define REDIRECT_ORIGINAL_URL "original"
26#define REDIRECT_URL "redirect"
27#define REDIRECT_TIMESTAMP "timestamp"
28#define REDIRECT_CACHE_FILENAME "cache.ini"
140 void cacheRedirect(
const QUrl &originalUrl,
const QUrl &redirectUrl);
Handles searching for and loading card images from local and custom image folders.
Definition card_picture_loader_local.h:30
Handles downloading a single card image from network or local sources.
Definition card_picture_loader_worker_work.h:34
QQueue< QPair< QUrl, CardPictureLoaderWorkerWork * > > requestLoadQueue
Queue of pending network requests.
Definition card_picture_loader_worker.h:153
QNetworkDiskCache * cache
Disk cache for downloaded images.
Definition card_picture_loader_worker.h:148
void clearNetworkCache()
Clears the network cache and redirect cache.
Definition card_picture_loader_worker.cpp:557
void cleanStaleEntries()
Removes stale redirect entries older than TTL.
Definition card_picture_loader_worker.cpp:543
QHash< QString, int > hostRequestQuota
Sustained per-host request allowance.
Definition card_picture_loader_worker.h:157
void imageRequestQueued(const QUrl &url, const ExactCard &card, const QString &setName)
Emitted when a request is added to the network queue.
QTimer dispatchTimer
Timer pacing individual network requests.
Definition card_picture_loader_worker.h:156
void dispatchQueuedRequest()
Chooses a request from the queue and starts it, respecting the quota and pacing.
Definition card_picture_loader_worker.cpp:251
void saveRedirectCache() const
Saves redirect cache to disk.
Definition card_picture_loader_worker.cpp:528
bool isUnlockedHost(const QString &host) const
Whether a host may skip dispatch pacing and per-host allowance entirely.
Definition card_picture_loader_worker.cpp:422
void imageRequestSucceeded(const QUrl &url)
Emitted when a network request successfully completes.
QString cacheFilePath
Path to persistent redirect cache file.
Definition card_picture_loader_worker.h:150
static constexpr int MAX_REDIRECT_CHAIN_DEPTH
Bound on how many cached-redirect hops dispatch resolution will follow.
Definition card_picture_loader_worker.h:167
QSet< QString > currentlyLoading
Deduplication: contains pixmapCacheKey currently being loaded.
Definition card_picture_loader_worker.h:170
void resetRequestQuota()
Resets the request quota for rate-limiting.
Definition card_picture_loader_worker.cpp:210
void processQueuedRequests()
Ensures the pacing and quota-reset timers reflect the current queue and recovery state.
Definition card_picture_loader_worker.cpp:240
CardPictureLoaderLocal * localLoader
Loader for local images.
Definition card_picture_loader_worker.h:169
QUrl getCachedRedirect(const QUrl &originalUrl) const
Returns cached redirect URL for the given original URL, if available.
Definition card_picture_loader_worker.cpp:485
bool shutdownThread()
Stops the worker thread and reports whether it stopped.
Definition card_picture_loader_worker.cpp:110
void queueRequest(const QUrl &url, CardPictureLoaderWorkerWork *worker)
Queues a network request for a given URL and worker thread.
Definition card_picture_loader_worker.cpp:137
void onHostRateLimited(const QString &host)
Handles a server returning HTTP 429 by reducing that host's request quota.
Definition card_picture_loader_worker.cpp:427
QThread * pictureLoaderThread
Thread for executing worker tasks.
Definition card_picture_loader_worker.h:146
QHash< QString, int > hostQuotaRemaining
Per-host allowance left in the current second.
Definition card_picture_loader_worker.h:159
void updateTimerState()
Starts or stops the pacing and quota-reset timers to match the queue and recovery state.
Definition card_picture_loader_worker.cpp:310
QHash< QString, QDateTime > hostLast429
When each host was last rate limited.
Definition card_picture_loader_worker.h:160
bool picDownload
Whether downloading images from network is enabled.
Definition card_picture_loader_worker.h:152
void removedCachedUrl(const QUrl &url)
Removes a URL from the network cache.
Definition card_picture_loader_worker.cpp:480
QThread * workerThread() const
Returns the worker's QThread.
Definition card_picture_loader_worker.cpp:132
static constexpr int CacheTTLInDays
Time-to-live for redirect cache entries (days).
Definition card_picture_loader_worker.h:151
void imageLoadEnqueued(const ExactCard &card)
Emitted when an image load is enqueued.
bool processSingleRequest()
Processes a single queued request.
Definition card_picture_loader_worker.cpp:344
bool requestTouchesNetwork(const QUrl &url) const
Whether a request for this URL would actually touch the network, rather than being served from the di...
Definition card_picture_loader_worker.cpp:403
void cacheRedirect(const QUrl &originalUrl, const QUrl &redirectUrl)
Caches a redirect mapping between original and redirected URL.
Definition card_picture_loader_worker.cpp:474
static constexpr int MAX_IN_FLIGHT_PER_HOST
Maximum concurrent in-flight network replies per host.
Definition card_picture_loader_worker.h:164
void handleImageLoadEnqueued(const ExactCard &card)
Handles image load requests enqueued on this worker.
Definition card_picture_loader_worker.cpp:445
void networkCacheCleared()
Emitted after clearNetworkCache() has finished clearing both caches.
QHash< QString, int > hostRequestLimits
User-set per-host request allowances.
Definition card_picture_loader_worker.h:158
QTimer requestTimer
Timer to reset the request quota.
Definition card_picture_loader_worker.h:155
QNetworkAccessManager * networkManager
Network manager for HTTP requests.
Definition card_picture_loader_worker.h:147
void enqueueImageLoad(const ExactCard &card)
Enqueues an ExactCard for loading.
Definition card_picture_loader_worker.cpp:439
CardPictureLoaderWorker()
Constructs a CardPictureLoaderWorker.
Definition card_picture_loader_worker.cpp:45
int hostAllowanceCeiling(const QString &host) const
Effective per-host allowance ceiling for a host.
Definition card_picture_loader_worker.cpp:412
void loadRedirectCache()
Loads redirect cache from disk.
Definition card_picture_loader_worker.cpp:509
QUrl resolveCachedRedirect(const QUrl &url) const
Follows the cached-redirect chain to the URL that will actually be requested.
Definition card_picture_loader_worker.cpp:493
QHash< QUrl, QPair< QUrl, QDateTime > > redirectCache
Maps original URLs to redirects with timestamp.
Definition card_picture_loader_worker.h:149
QNetworkReply * makeRequest(const QUrl &url, CardPictureLoaderWorkerWork *workThread)
Makes a network request for the given URL using the specified worker.
Definition card_picture_loader_worker.cpp:158
QHash< QString, int > hostInFlight
Network replies currently in flight, per host.
Definition card_picture_loader_worker.h:161
void imageLoaded(const ExactCard &card, const QImage &image)
Emitted when an image has finished loading.
void handleImageLoaded(const ExactCard &card, const QImage &image)
Handles an image that has finished loading.
Definition card_picture_loader_worker.cpp:468
Represents a specific card instance, defined by its CardInfo and a particular printing.
Definition exact_card.h:24
Definition mana_curve_category_widget.h:11
Definition dlg_manage_sets.h:29
Q_LOGGING_CATEGORY(CrashReportLog, "crash_report")