update usages

This commit is contained in:
RickyRister 2025-12-06 23:12:46 -08:00
parent d5a29d1421
commit 3ef0f806b8
9 changed files with 42 additions and 51 deletions

View file

@ -259,7 +259,7 @@ void DeckViewContainer::loadLocalDeck()
void DeckViewContainer::loadDeckFromFile(const QString &filePath) void DeckViewContainer::loadDeckFromFile(const QString &filePath)
{ {
DeckLoader::FileFormat fmt = DeckLoader::getFormatFromName(filePath); LoadedDeck::FileFormat fmt = LoadedDeck::getFormatFromName(filePath);
DeckLoader deck(this); DeckLoader deck(this);
bool success = deck.loadFromFile(filePath, fmt, true); bool success = deck.loadFromFile(filePath, fmt, true);

View file

@ -33,7 +33,7 @@ DeckLoader::DeckLoader(QObject *parent, DeckList *_deckList) : QObject(parent),
{ {
} }
bool DeckLoader::loadFromFile(const QString &fileName, FileFormat fmt, bool userRequest) bool DeckLoader::loadFromFile(const QString &fileName, LoadedDeck::FileFormat fmt, bool userRequest)
{ {
QFile file(fileName); QFile file(fileName);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
@ -42,17 +42,17 @@ bool DeckLoader::loadFromFile(const QString &fileName, FileFormat fmt, bool user
bool result = false; bool result = false;
switch (fmt) { switch (fmt) {
case PlainTextFormat: case LoadedDeck::PlainTextFormat:
result = deckList->loadFromFile_Plain(&file); result = deckList->loadFromFile_Plain(&file);
break; break;
case CockatriceFormat: { case LoadedDeck::CockatriceFormat: {
result = deckList->loadFromFile_Native(&file); result = deckList->loadFromFile_Native(&file);
qCInfo(DeckLoaderLog) << "Loaded from" << fileName << "-" << result; qCInfo(DeckLoaderLog) << "Loaded from" << fileName << "-" << result;
if (!result) { if (!result) {
qCInfo(DeckLoaderLog) << "Retrying as plain format"; qCInfo(DeckLoaderLog) << "Retrying as plain format";
file.seek(0); file.seek(0);
result = deckList->loadFromFile_Plain(&file); result = deckList->loadFromFile_Plain(&file);
fmt = PlainTextFormat; fmt = LoadedDeck::PlainTextFormat;
} }
break; break;
} }
@ -77,7 +77,7 @@ bool DeckLoader::loadFromFile(const QString &fileName, FileFormat fmt, bool user
return result; return result;
} }
bool DeckLoader::loadFromFileAsync(const QString &fileName, FileFormat fmt, bool userRequest) bool DeckLoader::loadFromFileAsync(const QString &fileName, LoadedDeck::FileFormat fmt, bool userRequest)
{ {
auto *watcher = new QFutureWatcher<bool>(this); auto *watcher = new QFutureWatcher<bool>(this);
@ -106,9 +106,9 @@ bool DeckLoader::loadFromFileAsync(const QString &fileName, FileFormat fmt, bool
} }
switch (fmt) { switch (fmt) {
case PlainTextFormat: case LoadedDeck::PlainTextFormat:
return deckList->loadFromFile_Plain(&file); return deckList->loadFromFile_Plain(&file);
case CockatriceFormat: { case LoadedDeck::CockatriceFormat: {
bool result = false; bool result = false;
result = deckList->loadFromFile_Native(&file); result = deckList->loadFromFile_Native(&file);
if (!result) { if (!result) {
@ -140,7 +140,7 @@ bool DeckLoader::loadFromRemote(const QString &nativeString, int remoteDeckId)
return result; return result;
} }
bool DeckLoader::saveToFile(const QString &fileName, FileFormat fmt) bool DeckLoader::saveToFile(const QString &fileName, LoadedDeck::FileFormat fmt)
{ {
QFile file(fileName); QFile file(fileName);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
@ -149,10 +149,10 @@ bool DeckLoader::saveToFile(const QString &fileName, FileFormat fmt)
bool result = false; bool result = false;
switch (fmt) { switch (fmt) {
case PlainTextFormat: case LoadedDeck::PlainTextFormat:
result = deckList->saveToFile_Plain(&file); result = deckList->saveToFile_Plain(&file);
break; break;
case CockatriceFormat: case LoadedDeck::CockatriceFormat:
result = deckList->saveToFile_Native(&file); result = deckList->saveToFile_Native(&file);
qCInfo(DeckLoaderLog) << "Saving to " << fileName << "-" << result; qCInfo(DeckLoaderLog) << "Saving to " << fileName << "-" << result;
break; break;
@ -172,7 +172,7 @@ bool DeckLoader::saveToFile(const QString &fileName, FileFormat fmt)
return result; return result;
} }
bool DeckLoader::updateLastLoadedTimestamp(const QString &fileName, FileFormat fmt) bool DeckLoader::updateLastLoadedTimestamp(const QString &fileName, LoadedDeck::FileFormat fmt)
{ {
QFileInfo fileInfo(fileName); QFileInfo fileInfo(fileName);
if (!fileInfo.exists()) { if (!fileInfo.exists()) {
@ -193,10 +193,10 @@ bool DeckLoader::updateLastLoadedTimestamp(const QString &fileName, FileFormat f
// Perform file modifications // Perform file modifications
switch (fmt) { switch (fmt) {
case PlainTextFormat: case LoadedDeck::PlainTextFormat:
result = deckList->saveToFile_Plain(&file); result = deckList->saveToFile_Plain(&file);
break; break;
case CockatriceFormat: case LoadedDeck::CockatriceFormat:
deckList->setLastLoadedTimestamp(QDateTime::currentDateTime().toString()); deckList->setLastLoadedTimestamp(QDateTime::currentDateTime().toString());
result = deckList->saveToFile_Native(&file); result = deckList->saveToFile_Native(&file);
break; break;
@ -414,14 +414,6 @@ void DeckLoader::clearSetNamesAndNumbers(const DeckList *deckList)
deckList->forEachCard(clearSetNameAndNumber); deckList->forEachCard(clearSetNameAndNumber);
} }
DeckLoader::FileFormat DeckLoader::getFormatFromName(const QString &fileName)
{
if (fileName.endsWith(".cod", Qt::CaseInsensitive)) {
return CockatriceFormat;
}
return PlainTextFormat;
}
void DeckLoader::saveToClipboard(const DeckList *deckList, bool addComments, bool addSetNameAndNumber) void DeckLoader::saveToClipboard(const DeckList *deckList, bool addComments, bool addSetNameAndNumber)
{ {
QString buffer; QString buffer;
@ -564,12 +556,12 @@ bool DeckLoader::convertToCockatriceFormat(QString fileName)
bool result = false; bool result = false;
// Perform file modifications based on the detected format // Perform file modifications based on the detected format
switch (getFormatFromName(fileName)) { switch (LoadedDeck::getFormatFromName(fileName)) {
case PlainTextFormat: case LoadedDeck::PlainTextFormat:
// Save in Cockatrice's native format // Save in Cockatrice's native format
result = deckList->saveToFile_Native(&file); result = deckList->saveToFile_Native(&file);
break; break;
case CockatriceFormat: case LoadedDeck::CockatriceFormat:
qCInfo(DeckLoaderLog) << "File is already in Cockatrice format. No conversion needed."; qCInfo(DeckLoaderLog) << "File is already in Cockatrice format. No conversion needed.";
result = true; result = true;
break; break;
@ -590,7 +582,7 @@ bool DeckLoader::convertToCockatriceFormat(QString fileName)
} }
lastLoadInfo = { lastLoadInfo = {
.fileName = newFileName, .fileName = newFileName,
.fileFormat = CockatriceFormat, .fileFormat = LoadedDeck::CockatriceFormat,
}; };
} }

View file

@ -42,7 +42,7 @@ public:
private: private:
DeckList *deckList; DeckList *deckList;
LoadInfo lastLoadInfo; LoadedDeck::LoadInfo lastLoadInfo;
public: public:
DeckLoader(QObject *parent); DeckLoader(QObject *parent);
@ -50,29 +50,28 @@ public:
DeckLoader(const DeckLoader &) = delete; DeckLoader(const DeckLoader &) = delete;
DeckLoader &operator=(const DeckLoader &) = delete; DeckLoader &operator=(const DeckLoader &) = delete;
const LoadInfo &getLastLoadInfo() const const LoadedDeck::LoadInfo &getLastLoadInfo() const
{ {
return lastLoadInfo; return lastLoadInfo;
} }
void setLastLoadInfo(const LoadInfo &info) void setLastLoadInfo(const LoadedDeck::LoadInfo &info)
{ {
lastLoadInfo = info; lastLoadInfo = info;
} }
[[nodiscard]] bool hasNotBeenLoaded() const [[nodiscard]] bool hasNotBeenLoaded() const
{ {
return lastLoadInfo.fileName.isEmpty() && lastLoadInfo.remoteDeckId == LoadInfo::NON_REMOTE_ID; return lastLoadInfo.isEmpty();
} }
static void clearSetNamesAndNumbers(const DeckList *deckList); static void clearSetNamesAndNumbers(const DeckList *deckList);
static FileFormat getFormatFromName(const QString &fileName);
bool loadFromFile(const QString &fileName, FileFormat fmt, bool userRequest = false); bool loadFromFile(const QString &fileName, LoadedDeck::FileFormat fmt, bool userRequest = false);
bool loadFromFileAsync(const QString &fileName, FileFormat fmt, bool userRequest); bool loadFromFileAsync(const QString &fileName, LoadedDeck::FileFormat fmt, bool userRequest);
bool loadFromRemote(const QString &nativeString, int remoteDeckId); bool loadFromRemote(const QString &nativeString, int remoteDeckId);
bool saveToFile(const QString &fileName, FileFormat fmt); bool saveToFile(const QString &fileName, LoadedDeck::FileFormat fmt);
bool updateLastLoadedTimestamp(const QString &fileName, FileFormat fmt); bool updateLastLoadedTimestamp(const QString &fileName, LoadedDeck::FileFormat fmt);
static QString exportDeckToDecklist(const DeckList *deckList, DecklistWebsite website); static QString exportDeckToDecklist(const DeckList *deckList, DecklistWebsite website);

View file

@ -23,7 +23,7 @@ HomeWidget::HomeWidget(QWidget *parent, TabSupervisor *_tabSupervisor)
backgroundSourceDeck = new DeckLoader(this); backgroundSourceDeck = new DeckLoader(this);
backgroundSourceDeck->loadFromFile(SettingsCache::instance().getDeckPath() + "background.cod", backgroundSourceDeck->loadFromFile(SettingsCache::instance().getDeckPath() + "background.cod",
DeckLoader::CockatriceFormat, false); LoadedDeck::CockatriceFormat, false);
gradientColors = extractDominantColors(background); gradientColors = extractDominantColors(background);
@ -73,7 +73,7 @@ void HomeWidget::initializeBackgroundFromSource()
break; break;
case BackgroundSources::DeckFileArt: case BackgroundSources::DeckFileArt:
backgroundSourceDeck->loadFromFile(SettingsCache::instance().getDeckPath() + "background.cod", backgroundSourceDeck->loadFromFile(SettingsCache::instance().getDeckPath() + "background.cod",
DeckLoader::CockatriceFormat, false); LoadedDeck::CockatriceFormat, false);
cardChangeTimer->start(SettingsCache::instance().getHomeTabBackgroundShuffleFrequency() * 1000); cardChangeTimer->start(SettingsCache::instance().getHomeTabBackgroundShuffleFrequency() * 1000);
break; break;
} }

View file

@ -380,7 +380,7 @@ void AbstractTabDeckEditor::actOpenRecent(const QString &fileName)
*/ */
void AbstractTabDeckEditor::openDeckFromFile(const QString &fileName, DeckOpenLocation deckOpenLocation) void AbstractTabDeckEditor::openDeckFromFile(const QString &fileName, DeckOpenLocation deckOpenLocation)
{ {
DeckLoader::FileFormat fmt = DeckLoader::getFormatFromName(fileName); LoadedDeck::FileFormat fmt = LoadedDeck::getFormatFromName(fileName);
auto *l = new DeckLoader(this); auto *l = new DeckLoader(this);
if (l->loadFromFile(fileName, fmt, true)) { if (l->loadFromFile(fileName, fmt, true)) {
@ -406,7 +406,7 @@ void AbstractTabDeckEditor::openDeckFromFile(const QString &fileName, DeckOpenLo
bool AbstractTabDeckEditor::actSaveDeck() bool AbstractTabDeckEditor::actSaveDeck()
{ {
DeckLoader *const deck = getDeckLoader(); DeckLoader *const deck = getDeckLoader();
if (deck->getLastLoadInfo().remoteDeckId != DeckLoader::LoadInfo::NON_REMOTE_ID) { if (deck->getLastLoadInfo().remoteDeckId != LoadedDeck::LoadInfo::NON_REMOTE_ID) {
QString deckString = deck->getDeckList()->writeToString_Native(); QString deckString = deck->getDeckList()->writeToString_Native();
if (deckString.length() > MAX_FILE_LENGTH) { if (deckString.length() > MAX_FILE_LENGTH) {
QMessageBox::critical(this, tr("Error"), tr("Could not save remote deck")); QMessageBox::critical(this, tr("Error"), tr("Could not save remote deck"));
@ -452,7 +452,7 @@ bool AbstractTabDeckEditor::actSaveDeckAs()
return false; return false;
QString fileName = dialog.selectedFiles().at(0); QString fileName = dialog.selectedFiles().at(0);
DeckLoader::FileFormat fmt = DeckLoader::getFormatFromName(fileName); LoadedDeck::FileFormat fmt = LoadedDeck::getFormatFromName(fileName);
if (!getDeckLoader()->saveToFile(fileName, fmt)) { if (!getDeckLoader()->saveToFile(fileName, fmt)) {
QMessageBox::critical( QMessageBox::critical(

View file

@ -242,7 +242,7 @@ void TabDeckStorage::actOpenLocalDeck()
QString filePath = localDirModel->filePath(curLeft); QString filePath = localDirModel->filePath(curLeft);
auto deckLoader = new DeckLoader(this); auto deckLoader = new DeckLoader(this);
if (!deckLoader->loadFromFile(filePath, DeckLoader::CockatriceFormat, true)) if (!deckLoader->loadFromFile(filePath, LoadedDeck::CockatriceFormat, true))
continue; continue;
emit openDeckEditor(deckLoader); emit openDeckEditor(deckLoader);
@ -308,7 +308,7 @@ void TabDeckStorage::uploadDeck(const QString &filePath, const QString &targetPa
QFileInfo deckFileInfo(deckFile); QFileInfo deckFileInfo(deckFile);
DeckLoader deck(this); DeckLoader deck(this);
if (!deck.loadFromFile(filePath, DeckLoader::CockatriceFormat)) { if (!deck.loadFromFile(filePath, LoadedDeck::CockatriceFormat)) {
QMessageBox::critical(this, tr("Error"), tr("Invalid deck file")); QMessageBox::critical(this, tr("Error"), tr("Invalid deck file"));
return; return;
} }
@ -493,7 +493,7 @@ void TabDeckStorage::downloadFinished(const Response &r,
QString filePath = extraData.toString(); QString filePath = extraData.toString();
DeckLoader deck(this, new DeckList(QString::fromStdString(resp.deck()))); DeckLoader deck(this, new DeckList(QString::fromStdString(resp.deck())));
deck.saveToFile(filePath, DeckLoader::CockatriceFormat); deck.saveToFile(filePath, LoadedDeck::CockatriceFormat);
} }
void TabDeckStorage::actNewFolder() void TabDeckStorage::actNewFolder()

View file

@ -25,7 +25,7 @@ TabDeckStorageVisual::TabDeckStorageVisual(TabSupervisor *_tabSupervisor)
void TabDeckStorageVisual::actOpenLocalDeck(const QString &filePath) void TabDeckStorageVisual::actOpenLocalDeck(const QString &filePath)
{ {
auto deckLoader = new DeckLoader(this); auto deckLoader = new DeckLoader(this);
if (!deckLoader->loadFromFile(filePath, DeckLoader::getFormatFromName(filePath), true)) { if (!deckLoader->loadFromFile(filePath, LoadedDeck::getFormatFromName(filePath), true)) {
QMessageBox::critical(this, tr("Error"), tr("Could not open deck at %1").arg(filePath)); QMessageBox::critical(this, tr("Error"), tr("Could not open deck at %1").arg(filePath));
return; return;
} }

View file

@ -79,7 +79,7 @@ static QStringList findAllKnownTags()
QStringList knownTags; QStringList knownTags;
auto loader = DeckLoader(nullptr); auto loader = DeckLoader(nullptr);
for (const QString &file : allFiles) { for (const QString &file : allFiles) {
loader.loadFromFile(file, DeckLoader::getFormatFromName(file), false); loader.loadFromFile(file, LoadedDeck::getFormatFromName(file), false);
QStringList tags = loader.getDeckList()->getTags(); QStringList tags = loader.getDeckList()->getTags();
knownTags.append(tags); knownTags.append(tags);
knownTags.removeDuplicates(); knownTags.removeDuplicates();
@ -136,7 +136,7 @@ static void convertFileToCockatriceFormat(DeckPreviewWidget *deckPreviewWidget)
*/ */
bool DeckPreviewDeckTagsDisplayWidget::promptFileConversionIfRequired(DeckPreviewWidget *deckPreviewWidget) bool DeckPreviewDeckTagsDisplayWidget::promptFileConversionIfRequired(DeckPreviewWidget *deckPreviewWidget)
{ {
if (DeckLoader::getFormatFromName(deckPreviewWidget->filePath) == DeckLoader::CockatriceFormat) { if (LoadedDeck::getFormatFromName(deckPreviewWidget->filePath) == LoadedDeck::CockatriceFormat) {
return true; return true;
} }

View file

@ -32,7 +32,7 @@ DeckPreviewWidget::DeckPreviewWidget(QWidget *_parent,
many deck loads have finished already and if we've loaded all decks and THEN load all the tags at once. */ many deck loads have finished already and if we've loaded all decks and THEN load all the tags at once. */
connect(deckLoader, &DeckLoader::loadFinished, visualDeckStorageWidget->tagFilterWidget, connect(deckLoader, &DeckLoader::loadFinished, visualDeckStorageWidget->tagFilterWidget,
&VisualDeckStorageTagFilterWidget::refreshTags); &VisualDeckStorageTagFilterWidget::refreshTags);
deckLoader->loadFromFileAsync(filePath, DeckLoader::getFormatFromName(filePath), false); deckLoader->loadFromFileAsync(filePath, LoadedDeck::getFormatFromName(filePath), false);
bannerCardDisplayWidget = bannerCardDisplayWidget =
new DeckPreviewCardPictureWidget(this, false, visualDeckStorageWidget->deckPreviewSelectionAnimationEnabled); new DeckPreviewCardPictureWidget(this, false, visualDeckStorageWidget->deckPreviewSelectionAnimationEnabled);
@ -288,7 +288,7 @@ void DeckPreviewWidget::setBannerCard(int /* changedIndex */)
auto [name, id] = bannerCardComboBox->currentData().value<QPair<QString, QString>>(); auto [name, id] = bannerCardComboBox->currentData().value<QPair<QString, QString>>();
CardRef cardRef = {name, id}; CardRef cardRef = {name, id};
deckLoader->getDeckList()->setBannerCard(cardRef); deckLoader->getDeckList()->setBannerCard(cardRef);
deckLoader->saveToFile(filePath, DeckLoader::getFormatFromName(filePath)); deckLoader->saveToFile(filePath, LoadedDeck::getFormatFromName(filePath));
bannerCardDisplayWidget->setCard(CardDatabaseManager::query()->getCard(cardRef)); bannerCardDisplayWidget->setCard(CardDatabaseManager::query()->getCard(cardRef));
} }
@ -311,7 +311,7 @@ void DeckPreviewWidget::imageDoubleClickedEvent(QMouseEvent *event, DeckPreviewC
void DeckPreviewWidget::setTags(const QStringList &tags) void DeckPreviewWidget::setTags(const QStringList &tags)
{ {
deckLoader->getDeckList()->setTags(tags); deckLoader->getDeckList()->setTags(tags);
deckLoader->saveToFile(filePath, DeckLoader::CockatriceFormat); deckLoader->saveToFile(filePath, LoadedDeck::CockatriceFormat);
} }
QMenu *DeckPreviewWidget::createRightClickMenu() QMenu *DeckPreviewWidget::createRightClickMenu()
@ -386,7 +386,7 @@ void DeckPreviewWidget::actRenameDeck()
// write change // write change
deckLoader->getDeckList()->setName(newName); deckLoader->getDeckList()->setName(newName);
deckLoader->saveToFile(filePath, DeckLoader::getFormatFromName(filePath)); deckLoader->saveToFile(filePath, LoadedDeck::getFormatFromName(filePath));
// update VDS // update VDS
refreshBannerCardText(); refreshBannerCardText();
@ -416,7 +416,7 @@ void DeckPreviewWidget::actRenameFile()
return; return;
} }
DeckLoader::LoadInfo lastLoadInfo = deckLoader->getLastLoadInfo(); LoadedDeck::LoadInfo lastLoadInfo = deckLoader->getLastLoadInfo();
lastLoadInfo.fileName = newFilePath; lastLoadInfo.fileName = newFilePath;
deckLoader->setLastLoadInfo(lastLoadInfo); deckLoader->setLastLoadInfo(lastLoadInfo);