Cockatrice 2025-11-30-Development-2.11.0-beta.38
A cross-platform virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
CardPictureLoaderWorker Class Reference

Handles asynchronous loading of card images, both locally and via network. More...

#include <card_picture_loader_worker.h>

Inheritance diagram for CardPictureLoaderWorker:
[legend]
Collaboration diagram for CardPictureLoaderWorker:
[legend]

Public Slots

QNetworkReply * makeRequest (const QUrl &url, CardPictureLoaderWorkerWork *workThread)
 Makes a network request for the given URL using the specified worker.
void processQueuedRequests ()
 Processes all queued requests respecting the request quota.
bool processSingleRequest ()
 Processes a single queued request.
void handleImageLoaded (const ExactCard &card, const QImage &image)
 Handles an image that has finished loading.
void cacheRedirect (const QUrl &originalUrl, const QUrl &redirectUrl)
 Caches a redirect mapping between original and redirected URL.
void removedCachedUrl (const QUrl &url)
 Removes a URL from the network cache.

Signals

void imageLoadEnqueued (const ExactCard &card)
 Emitted when an image load is enqueued.
void imageLoaded (const ExactCard &card, const QImage &image)
 Emitted when an image has finished loading.
void imageRequestQueued (const QUrl &url, const ExactCard &card, const QString &setName)
 Emitted when a request is added to the network queue.
void imageRequestSucceeded (const QUrl &url)
 Emitted when a network request successfully completes.

Public Member Functions

 CardPictureLoaderWorker ()
 Constructs a CardPictureLoaderWorker.
 ~CardPictureLoaderWorker () override
void enqueueImageLoad (const ExactCard &card)
 Enqueues an ExactCard for loading.
void queueRequest (const QUrl &url, CardPictureLoaderWorkerWork *worker)
 Queues a network request for a given URL and worker thread.
void clearNetworkCache ()
 Clears the network cache and redirect cache.

Private Slots

void resetRequestQuota ()
 Resets the request quota for rate-limiting.
void handleImageLoadEnqueued (const ExactCard &card)
 Handles image load requests enqueued on this worker.

Private Member Functions

QUrl getCachedRedirect (const QUrl &originalUrl) const
 Returns cached redirect URL for the given original URL, if available.
void loadRedirectCache ()
 Loads redirect cache from disk.
void saveRedirectCache () const
 Saves redirect cache to disk.
void cleanStaleEntries ()
 Removes stale redirect entries older than TTL.

Private Attributes

QThread * pictureLoaderThread
 Thread for executing worker tasks.
QNetworkAccessManager * networkManager
 Network manager for HTTP requests.
QNetworkDiskCache * cache
 Disk cache for downloaded images.
QHash< QUrl, QPair< QUrl, QDateTime > > redirectCache
 Maps original URLs to redirects with timestamp.
QString cacheFilePath
 Path to persistent redirect cache file.
bool picDownload
 Whether downloading images from network is enabled.
QQueue< QPair< QUrl, CardPictureLoaderWorkerWork * > > requestLoadQueue
 Queue of pending network requests.
int requestQuota
 Remaining requests allowed per second.
QTimer requestTimer
 Timer to reset the request quota.
CardPictureLoaderLocallocalLoader
 Loader for local images.
QSet< QString > currentlyLoading
 Deduplication: contains pixmapCacheKey currently being loaded.

Static Private Attributes

static constexpr int CacheTTLInDays = 30
 Time-to-live for redirect cache entries (days)

Detailed Description

Handles asynchronous loading of card images, both locally and via network.

Responsibilities:

  • Maintain a queue of network image requests with rate-limiting.
  • Load images from local cache first via CardPictureLoaderLocal.
  • Handle network redirects and persistent caching of redirects.
  • Deduplicate simultaneous requests for the same card.
  • Emit signals for status updates and loaded images.

Constructor & Destructor Documentation

◆ CardPictureLoaderWorker()

CardPictureLoaderWorker::CardPictureLoaderWorker ( )
explicit

Constructs a CardPictureLoaderWorker.

Initializes network manager, cache, redirect cache, local loader, and request quota timer.

Here is the call graph for this function:

◆ ~CardPictureLoaderWorker()

CardPictureLoaderWorker::~CardPictureLoaderWorker ( )
override
Here is the call graph for this function:

Member Function Documentation

◆ cacheRedirect

void CardPictureLoaderWorker::cacheRedirect ( const QUrl & originalUrl,
const QUrl & redirectUrl )
slot

Caches a redirect mapping between original and redirected URL.

Here is the caller graph for this function:

◆ cleanStaleEntries()

void CardPictureLoaderWorker::cleanStaleEntries ( )
private

Removes stale redirect entries older than TTL.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clearNetworkCache()

void CardPictureLoaderWorker::clearNetworkCache ( )

Clears the network cache and redirect cache.

Here is the caller graph for this function:

◆ enqueueImageLoad()

void CardPictureLoaderWorker::enqueueImageLoad ( const ExactCard & card)

Enqueues an ExactCard for loading.

Parameters
cardExactCard to load

This will first try to load the image locally; if that fails, it will enqueue a network request.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCachedRedirect()

QUrl CardPictureLoaderWorker::getCachedRedirect ( const QUrl & originalUrl) const
nodiscardprivate

Returns cached redirect URL for the given original URL, if available.

Here is the caller graph for this function:

◆ handleImageLoaded

void CardPictureLoaderWorker::handleImageLoaded ( const ExactCard & card,
const QImage & image )
slot

Handles an image that has finished loading.

Parameters
cardThe ExactCard that was loaded
imageThe loaded QImage; empty if loading failed

Called when image loading is done. Failures are indicated by an empty QImage.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleImageLoadEnqueued

void CardPictureLoaderWorker::handleImageLoadEnqueued ( const ExactCard & card)
privateslot

Handles image load requests enqueued on this worker.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ imageLoaded

void CardPictureLoaderWorker::imageLoaded ( const ExactCard & card,
const QImage & image )
signal

Emitted when an image has finished loading.

Here is the caller graph for this function:

◆ imageLoadEnqueued

void CardPictureLoaderWorker::imageLoadEnqueued ( const ExactCard & card)
signal

Emitted when an image load is enqueued.

Here is the caller graph for this function:

◆ imageRequestQueued

void CardPictureLoaderWorker::imageRequestQueued ( const QUrl & url,
const ExactCard & card,
const QString & setName )
signal

Emitted when a request is added to the network queue.

Here is the caller graph for this function:

◆ imageRequestSucceeded

void CardPictureLoaderWorker::imageRequestSucceeded ( const QUrl & url)
signal

Emitted when a network request successfully completes.

Here is the caller graph for this function:

◆ loadRedirectCache()

void CardPictureLoaderWorker::loadRedirectCache ( )
private

Loads redirect cache from disk.

Here is the caller graph for this function:

◆ makeRequest

QNetworkReply * CardPictureLoaderWorker::makeRequest ( const QUrl & url,
CardPictureLoaderWorkerWork * workThread )
slot

Makes a network request for the given URL using the specified worker.

Parameters
urlURL to load
workThreadWorker handling the request
Returns
The QNetworkReply object representing the request
Here is the call graph for this function:
Here is the caller graph for this function:

◆ processQueuedRequests

void CardPictureLoaderWorker::processQueuedRequests ( )
slot

Processes all queued requests respecting the request quota.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ processSingleRequest

bool CardPictureLoaderWorker::processSingleRequest ( )
slot

Processes a single queued request.

Returns
true if a request was processed, false if queue is empty.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ queueRequest()

void CardPictureLoaderWorker::queueRequest ( const QUrl & url,
CardPictureLoaderWorkerWork * worker )

Queues a network request for a given URL and worker thread.

Parameters
urlURL to load
workerWorker handling this request
Here is the call graph for this function:
Here is the caller graph for this function:

◆ removedCachedUrl

void CardPictureLoaderWorker::removedCachedUrl ( const QUrl & url)
slot

Removes a URL from the network cache.

Here is the caller graph for this function:

◆ resetRequestQuota

void CardPictureLoaderWorker::resetRequestQuota ( )
privateslot

Resets the request quota for rate-limiting.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ saveRedirectCache()

void CardPictureLoaderWorker::saveRedirectCache ( ) const
private

Saves redirect cache to disk.

Here is the caller graph for this function:

Member Data Documentation

◆ cache

QNetworkDiskCache* CardPictureLoaderWorker::cache
private

Disk cache for downloaded images.

◆ cacheFilePath

QString CardPictureLoaderWorker::cacheFilePath
private

Path to persistent redirect cache file.

◆ CacheTTLInDays

int CardPictureLoaderWorker::CacheTTLInDays = 30
staticconstexprprivate

Time-to-live for redirect cache entries (days)

◆ currentlyLoading

QSet<QString> CardPictureLoaderWorker::currentlyLoading
private

Deduplication: contains pixmapCacheKey currently being loaded.

◆ localLoader

CardPictureLoaderLocal* CardPictureLoaderWorker::localLoader
private

Loader for local images.

◆ networkManager

QNetworkAccessManager* CardPictureLoaderWorker::networkManager
private

Network manager for HTTP requests.

◆ picDownload

bool CardPictureLoaderWorker::picDownload
private

Whether downloading images from network is enabled.

◆ pictureLoaderThread

QThread* CardPictureLoaderWorker::pictureLoaderThread
private

Thread for executing worker tasks.

◆ redirectCache

QHash<QUrl, QPair<QUrl, QDateTime> > CardPictureLoaderWorker::redirectCache
private

Maps original URLs to redirects with timestamp.

◆ requestLoadQueue

QQueue<QPair<QUrl, CardPictureLoaderWorkerWork *> > CardPictureLoaderWorker::requestLoadQueue
private

Queue of pending network requests.

◆ requestQuota

int CardPictureLoaderWorker::requestQuota
private

Remaining requests allowed per second.

◆ requestTimer

QTimer CardPictureLoaderWorker::requestTimer
private

Timer to reset the request quota.


The documentation for this class was generated from the following files: