Cockatrice 2026-09-01-Development-3.1.0-beta.10
A virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
CardDatabaseLoader Class Reference

Handles loading card databases from disk and saving custom tokens. More...

#include <card_database_loader.h>

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

Public Slots

LoadStatus loadCardDatabases ()
 Loads all configured card databases.
LoadStatus loadCardDatabase (const QString &path, CardDatabaseData &data)
 Loads a single card database file into the given snapshot.
bool saveCustomTokensToFile ()
 Saves custom tokens to the user-defined custom database path.

Signals

void loadingStarted ()
 Emitted when loading starts.
void loadingFinished ()
 Emitted when loading finishes successfully.
void loadingFailed ()
 Emitted when loading fails.
void databaseDataReady (CardDatabaseData data)
 Emitted with the fully-built snapshot once background loading completes. The receiver swaps it into the live database.
void newSetsFound (int numSets, const QStringList &setNames)
 Emitted when new sets are discovered during loading.
void allNewSetsEnabled ()
 Emitted when all newly discovered sets have been enabled.

Public Member Functions

 CardDatabaseLoader (QObject *parent, CardDatabase *db, ICardDatabasePathProvider *pathProvider, ICardPreferenceProvider *preferenceProvider, ICardSetPriorityController *_priorityController)
 Constructs a CardDatabaseLoader.
 ~CardDatabaseLoader () override
 Destructor cleans up allocated parsers.

Private Member Functions

LoadStatus loadFromFile (const QString &fileName, CardDatabaseData &data)
 Parses a single file into the given snapshot using the available parsers.
LoadStatus doLoadCardDatabases ()
 Performs the actual load work synchronously on the calling thread.
QStringList collectCustomDatabasePaths () const
 Collects custom card database paths recursively.
QByteArray computeSourceHash (const QStringList &customPaths) const
 Computes a hash identifying the current set of input database files.
QString cachePath () const
 Path of the binary cache file derived from the main card database path.
bool loadFromCache (CardDatabaseData &data, const QByteArray &sourceHash)
 Attempts to populate the snapshot from the binary cache.
bool saveToCache (const CardDatabaseData &data, const QByteArray &sourceHash)
 Writes the snapshot to the binary cache for the current inputs.

Private Attributes

CardDatabasedatabase
ICardDatabasePathProviderpathProvider
ICardSetPriorityControllerpriorityController
QList< ICardDatabaseParser * > availableParsers
QBasicMutex * loadFromFileMutex = new QBasicMutex()
QBasicMutex * reloadDatabaseMutex = new QBasicMutex()
bool initialLoadComplete = false

Detailed Description

Handles loading card databases from disk and saving custom tokens.

This class is responsible for:

  • Discovering configured card database paths.
  • Loading main, token, spoiler, and custom databases.
  • Populating a CardDatabase instance using connected parsers.
  • Emitting signals about loading progress and new sets.

Constructor & Destructor Documentation

◆ CardDatabaseLoader()

CardDatabaseLoader::CardDatabaseLoader ( QObject * parent,
CardDatabase * db,
ICardDatabasePathProvider * pathProvider,
ICardPreferenceProvider * preferenceProvider,
ICardSetPriorityController * _priorityController )
explicit

Constructs a CardDatabaseLoader.

Parameters
parentQObject parent.
dbPointer to the CardDatabase to populate (non-owning).
pathProviderProvider for card database file paths.
preferenceProviderOptional card preference provider for pinned printings.
Here is the call graph for this function:

◆ ~CardDatabaseLoader()

CardDatabaseLoader::~CardDatabaseLoader ( )
override

Destructor cleans up allocated parsers.

Member Function Documentation

◆ allNewSetsEnabled

void CardDatabaseLoader::allNewSetsEnabled ( )
signal

Emitted when all newly discovered sets have been enabled.

Here is the caller graph for this function:

◆ cachePath()

QString CardDatabaseLoader::cachePath ( ) const
nodiscardprivate

Path of the binary cache file derived from the main card database path.

Returns
Cache file path.
Here is the caller graph for this function:

◆ collectCustomDatabasePaths()

QStringList CardDatabaseLoader::collectCustomDatabasePaths ( ) const
nodiscardprivate

Collects custom card database paths recursively.

Returns
Sorted list of file paths to custom databases.
Here is the caller graph for this function:

◆ computeSourceHash()

QByteArray CardDatabaseLoader::computeSourceHash ( const QStringList & customPaths) const
nodiscardprivate

Computes a hash identifying the current set of input database files.

Returns
Hash over the paths, sizes and modification times of all inputs.
Here is the caller graph for this function:

◆ databaseDataReady

void CardDatabaseLoader::databaseDataReady ( CardDatabaseData data)
signal

Emitted with the fully-built snapshot once background loading completes. The receiver swaps it into the live database.

Here is the caller graph for this function:

◆ doLoadCardDatabases()

LoadStatus CardDatabaseLoader::doLoadCardDatabases ( )
private

Performs the actual load work synchronously on the calling thread.

Returns
Status of the main database load.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadCardDatabase

LoadStatus CardDatabaseLoader::loadCardDatabase ( const QString & path,
CardDatabaseData & data )
slot

Loads a single card database file into the given snapshot.

Parameters
pathPath to the database file.
dataSnapshot to populate.
Returns
LoadStatus indicating success or failure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadCardDatabases

LoadStatus CardDatabaseLoader::loadCardDatabases ( )
slot

Loads all configured card databases.

Runs synchronously on the calling thread. The caller should ensure that any signal receivers are already connected before invoking this.

Returns
Status of the main database load.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadFromCache()

bool CardDatabaseLoader::loadFromCache ( CardDatabaseData & data,
const QByteArray & sourceHash )
private

Attempts to populate the snapshot from the binary cache.

Parameters
dataSnapshot to populate.
sourceHashPre-computed hash identifying the current input files.
Returns
True if a valid, up-to-date cache was read.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadFromFile()

LoadStatus CardDatabaseLoader::loadFromFile ( const QString & fileName,
CardDatabaseData & data )
private

Parses a single file into the given snapshot using the available parsers.

Parameters
fileNamePath to the database file.
dataSnapshot to populate.
Returns
LoadStatus indicating success or failure.
Here is the caller graph for this function:

◆ loadingFailed

void CardDatabaseLoader::loadingFailed ( )
signal

Emitted when loading fails.

Here is the caller graph for this function:

◆ loadingFinished

void CardDatabaseLoader::loadingFinished ( )
signal

Emitted when loading finishes successfully.

Here is the caller graph for this function:

◆ loadingStarted

void CardDatabaseLoader::loadingStarted ( )
signal

Emitted when loading starts.

Here is the caller graph for this function:

◆ newSetsFound

void CardDatabaseLoader::newSetsFound ( int numSets,
const QStringList & setNames )
signal

Emitted when new sets are discovered during loading.

Parameters
numSetsNumber of new sets.
setNamesNames of the discovered sets.
Here is the caller graph for this function:

◆ saveCustomTokensToFile

bool CardDatabaseLoader::saveCustomTokensToFile ( )
slot

Saves custom tokens to the user-defined custom database path.

Returns
True if the save was successful.

◆ saveToCache()

bool CardDatabaseLoader::saveToCache ( const CardDatabaseData & data,
const QByteArray & sourceHash )
private

Writes the snapshot to the binary cache for the current inputs.

Parameters
dataSnapshot to serialize.
sourceHashPre-computed hash identifying the current input files.
Returns
True if the cache was written successfully.
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ availableParsers

QList<ICardDatabaseParser *> CardDatabaseLoader::availableParsers
private

List of available parsers for different formats.

◆ database

CardDatabase* CardDatabaseLoader::database
private

Non-owning pointer to the target CardDatabase.

◆ initialLoadComplete

bool CardDatabaseLoader::initialLoadComplete = false
private

Set after the first successful load.

◆ loadFromFileMutex

QBasicMutex* CardDatabaseLoader::loadFromFileMutex = new QBasicMutex()
private

Mutex for single-file loading.

◆ pathProvider

ICardDatabasePathProvider* CardDatabaseLoader::pathProvider
private

Pointer to the path provider.

◆ priorityController

ICardSetPriorityController* CardDatabaseLoader::priorityController
private

Controller for reconstructing set state.

◆ reloadDatabaseMutex

QBasicMutex* CardDatabaseLoader::reloadDatabaseMutex = new QBasicMutex()
private

Mutex for reloading entire database.


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