mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-21 09:05:10 -07:00
[PictureLoader] Address review comments
- Make deleteAllLocalOverrides static; it does not touch instance state - Drop the now-unused hasCustomArt dead code - Rename the override install methods to installPrintingOverride / installPrintingOverrideOnLoad
This commit is contained in:
parent
c70ef49bcf
commit
8053fe34a8
2 changed files with 13 additions and 45 deletions
|
|
@ -8,7 +8,7 @@
|
|||
#include <QApplication>
|
||||
#include <QBuffer>
|
||||
#include <QDebug>
|
||||
#include <QDirIterator>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QMainWindow>
|
||||
#include <QMovie>
|
||||
|
|
@ -334,8 +334,7 @@ void CardPictureLoader::saveCardImageToLocalStorage(const ExactCard &card,
|
|||
}
|
||||
}
|
||||
|
||||
void CardPictureLoader::overridePrintingConnectLocalSaveAndEnqueue(const ExactCard &originalCard,
|
||||
const ExactCard &overrideCard)
|
||||
void CardPictureLoader::installPrintingOverrideOnLoad(const ExactCard &originalCard, const ExactCard &overrideCard)
|
||||
{
|
||||
// Overriding a card with itself is the reset case, not a real override: every code path below
|
||||
// would re-enter itself through emitPixmapUpdated(). Reject it outright.
|
||||
|
|
@ -391,10 +390,9 @@ void CardPictureLoader::overridePrintingConnectLocalSaveAndEnqueue(const ExactCa
|
|||
CardPictureLoader::getInstance().worker->enqueueImageLoad(overrideCard);
|
||||
}
|
||||
|
||||
void CardPictureLoader::overridePrintingEnsurePixmapExistsAndSaveLocally(const ExactCard &originalCard,
|
||||
const ExactCard &overrideCard)
|
||||
void CardPictureLoader::installPrintingOverride(const ExactCard &originalCard, const ExactCard &overrideCard)
|
||||
{
|
||||
// Same guard as overridePrintingConnectLocalSaveAndEnqueue: self-override is the reset case.
|
||||
// Same guard as installPrintingOverrideOnLoad: self-override is the reset case.
|
||||
if (originalCard == overrideCard) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -409,7 +407,7 @@ void CardPictureLoader::overridePrintingEnsurePixmapExistsAndSaveLocally(const E
|
|||
}
|
||||
|
||||
// Cache miss or previously failed load — enqueue load and wait for the signal.
|
||||
overridePrintingConnectLocalSaveAndEnqueue(originalCard, overrideCard);
|
||||
installPrintingOverrideOnLoad(originalCard, overrideCard);
|
||||
}
|
||||
|
||||
bool CardPictureLoader::hasLocalOverrides(const ExactCard &card)
|
||||
|
|
@ -499,32 +497,3 @@ void CardPictureLoader::cardLangChanged()
|
|||
QPixmapCache::clear();
|
||||
failedAt.clear();
|
||||
}
|
||||
|
||||
bool CardPictureLoader::hasCustomArt()
|
||||
{
|
||||
auto picsPath = SettingsCache::instance().paths().getPicsPath();
|
||||
QDirIterator it(picsPath, QDir::Dirs | QDir::NoDotAndDotDot);
|
||||
|
||||
// Check if there is at least one non-directory file in the pics path, other
|
||||
// than in the "downloadedPics" subdirectory.
|
||||
while (it.hasNext()) {
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 3, 0))
|
||||
QFileInfo dir(it.nextFileInfo());
|
||||
#else
|
||||
// nextFileInfo() is only available in Qt 6.3+, for previous versions, we build
|
||||
// the QFileInfo from a QString which requires more system calls.
|
||||
QFileInfo dir(it.next());
|
||||
#endif
|
||||
|
||||
if (it.fileName() == "downloadedPics") {
|
||||
continue;
|
||||
}
|
||||
|
||||
QDirIterator subIt(it.filePath(), QDir::Files, QDirIterator::Subdirectories | QDirIterator::FollowSymlinks);
|
||||
if (subIt.hasNext()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,12 +96,6 @@ public:
|
|||
*/
|
||||
static void cacheCardPixmaps(const QList<ExactCard> &cards);
|
||||
|
||||
/**
|
||||
* @brief Check if the user has custom card art in the picsPath directory.
|
||||
* @return True if any custom art exists.
|
||||
*/
|
||||
static bool hasCustomArt();
|
||||
|
||||
/**
|
||||
* @brief Check if a local override image already exists for the card.
|
||||
* @param card The card to check.
|
||||
|
|
@ -109,6 +103,12 @@ public:
|
|||
*/
|
||||
static bool hasLocalOverrides(const ExactCard &card);
|
||||
|
||||
/**
|
||||
* @brief Removes all locally stored override images for the card.
|
||||
* @param card The card to remove the override images of.
|
||||
*/
|
||||
static void deleteAllLocalOverrides(const ExactCard &card);
|
||||
|
||||
/**
|
||||
* @brief Clears the in-memory QPixmap cache for all cards.
|
||||
*/
|
||||
|
|
@ -127,10 +127,9 @@ public slots:
|
|||
* @param image Loaded QImage.
|
||||
*/
|
||||
void imageLoaded(const ExactCard &card, const QImage &image);
|
||||
void deleteAllLocalOverrides(const ExactCard &card);
|
||||
void saveCardImageToLocalStorage(const ExactCard &card, const QPixmap &pixmap, bool allowOverwrite = false);
|
||||
void overridePrintingConnectLocalSaveAndEnqueue(const ExactCard &originalCard, const ExactCard &overrideCard);
|
||||
void overridePrintingEnsurePixmapExistsAndSaveLocally(const ExactCard &originalCard, const ExactCard &overrideCard);
|
||||
void installPrintingOverride(const ExactCard &originalCard, const ExactCard &overrideCard);
|
||||
void installPrintingOverrideOnLoad(const ExactCard &originalCard, const ExactCard &overrideCard);
|
||||
|
||||
private slots:
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue