Move enum to separate namespace

This commit is contained in:
RickyRister 2025-12-07 04:59:30 -08:00
parent 3ef0f806b8
commit 6cbb438256
14 changed files with 182 additions and 154 deletions

View file

@ -19,6 +19,7 @@ set(cockatrice_SOURCES
src/client/settings/card_counter_settings.cpp src/client/settings/card_counter_settings.cpp
src/client/settings/shortcut_treeview.cpp src/client/settings/shortcut_treeview.cpp
src/client/settings/shortcuts_settings.cpp src/client/settings/shortcuts_settings.cpp
src/interface/deck_loader/deck_file_format.cpp
src/interface/deck_loader/deck_loader.cpp src/interface/deck_loader/deck_loader.cpp
src/interface/deck_loader/loaded_deck.cpp src/interface/deck_loader/loaded_deck.cpp
src/interface/widgets/dialogs/dlg_connect.cpp src/interface/widgets/dialogs/dlg_connect.cpp
@ -288,7 +289,7 @@ set(cockatrice_SOURCES
add_subdirectory(sounds) add_subdirectory(sounds)
add_subdirectory(themes) add_subdirectory(themes)
configure_file( configure_file(
${CMAKE_SOURCE_DIR}/cockatrice/resources/config/qtlogging.ini ${CMAKE_BINARY_DIR}/cockatrice/qtlogging.ini COPYONLY ${CMAKE_SOURCE_DIR}/cockatrice/resources/config/qtlogging.ini ${CMAKE_BINARY_DIR}/cockatrice/qtlogging.ini COPYONLY
) )
set(cockatrice_RESOURCES cockatrice.qrc) set(cockatrice_RESOURCES cockatrice.qrc)
@ -296,12 +297,12 @@ set(cockatrice_RESOURCES cockatrice.qrc)
if(UPDATE_TRANSLATIONS) if(UPDATE_TRANSLATIONS)
# Cockatrice main sources # Cockatrice main sources
file(GLOB_RECURSE translate_cockatrice_SRCS ${CMAKE_SOURCE_DIR}/cockatrice/src/*.cpp file(GLOB_RECURSE translate_cockatrice_SRCS ${CMAKE_SOURCE_DIR}/cockatrice/src/*.cpp
${CMAKE_SOURCE_DIR}/cockatrice/src/*.h ${CMAKE_SOURCE_DIR}/cockatrice/src/*.h
) )
# All libcockatrice_* libraries (recursively) # All libcockatrice_* libraries (recursively)
file(GLOB_RECURSE translate_lib_SRCS ${CMAKE_SOURCE_DIR}/libcockatrice_*/**/*.cpp file(GLOB_RECURSE translate_lib_SRCS ${CMAKE_SOURCE_DIR}/libcockatrice_*/**/*.cpp
${CMAKE_SOURCE_DIR}/libcockatrice_*/**/*.h ${CMAKE_SOURCE_DIR}/libcockatrice_*/**/*.h
) )
# Combine all sources for translation # Combine all sources for translation
@ -319,7 +320,7 @@ endif(WIN32)
if(APPLE) if(APPLE)
set(MACOSX_BUNDLE_ICON_FILE appicon.icns) set(MACOSX_BUNDLE_ICON_FILE appicon.icns)
set_source_files_properties( set_source_files_properties(
${CMAKE_CURRENT_SOURCE_DIR}/resources/appicon.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources ${CMAKE_CURRENT_SOURCE_DIR}/resources/appicon.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources
) )
set(cockatrice_SOURCES ${cockatrice_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/resources/appicon.icns) set(cockatrice_SOURCES ${cockatrice_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/resources/appicon.icns)
endif(APPLE) endif(APPLE)
@ -346,13 +347,13 @@ set(COCKATRICE_WIN32_QM_INSTALL_DIR "translations")
if(Qt6_FOUND) if(Qt6_FOUND)
qt6_add_executable( qt6_add_executable(
cockatrice cockatrice
WIN32 WIN32
MACOSX_BUNDLE MACOSX_BUNDLE
${cockatrice_SOURCES} ${cockatrice_SOURCES}
${cockatrice_RESOURCES_RCC} ${cockatrice_RESOURCES_RCC}
${cockatrice_MOC_SRCS} ${cockatrice_MOC_SRCS}
MANUAL_FINALIZATION MANUAL_FINALIZATION
) )
elseif(Qt5_FOUND) elseif(Qt5_FOUND)
# Qt5 Translations need to be linked at executable creation time # Qt5 Translations need to be linked at executable creation time
@ -364,8 +365,8 @@ elseif(Qt5_FOUND)
endif() endif()
endif() endif()
add_executable( add_executable(
cockatrice WIN32 MACOSX_BUNDLE ${cockatrice_MOC_SRCS} ${cockatrice_QM} ${cockatrice_RESOURCES_RCC} cockatrice WIN32 MACOSX_BUNDLE ${cockatrice_MOC_SRCS} ${cockatrice_QM} ${cockatrice_RESOURCES_RCC}
${cockatrice_SOURCES} ${cockatrice_SOURCES}
) )
if(UNIX) if(UNIX)
if(APPLE) if(APPLE)
@ -380,29 +381,29 @@ endif()
if(Qt5_FOUND) if(Qt5_FOUND)
target_link_libraries( target_link_libraries(
cockatrice cockatrice
libcockatrice_card libcockatrice_card
libcockatrice_deck_list libcockatrice_deck_list
libcockatrice_filters libcockatrice_filters
libcockatrice_utility libcockatrice_utility
libcockatrice_network libcockatrice_network
libcockatrice_models libcockatrice_models
libcockatrice_rng libcockatrice_rng
libcockatrice_settings libcockatrice_settings
${COCKATRICE_QT_MODULES} ${COCKATRICE_QT_MODULES}
) )
else() else()
target_link_libraries( target_link_libraries(
cockatrice cockatrice
PUBLIC libcockatrice_card PUBLIC libcockatrice_card
libcockatrice_deck_list libcockatrice_deck_list
libcockatrice_filters libcockatrice_filters
libcockatrice_utility libcockatrice_utility
libcockatrice_network libcockatrice_network
libcockatrice_models libcockatrice_models
libcockatrice_rng libcockatrice_rng
libcockatrice_settings libcockatrice_settings
${COCKATRICE_QT_MODULES} ${COCKATRICE_QT_MODULES}
) )
endif() endif()
@ -436,48 +437,48 @@ if(APPLE)
# Qt plugins: audio (Qt5), iconengines, imageformats, multimedia (Qt6), platforms, printsupport (Qt5), styles, tls (Qt6) # Qt plugins: audio (Qt5), iconengines, imageformats, multimedia (Qt6), platforms, printsupport (Qt5), styles, tls (Qt6)
install( install(
DIRECTORY "${QT_PLUGINS_DIR}/" DIRECTORY "${QT_PLUGINS_DIR}/"
DESTINATION ${plugin_dest_dir} DESTINATION ${plugin_dest_dir}
COMPONENT Runtime COMPONENT Runtime
FILES_MATCHING FILES_MATCHING
PATTERN "*.dSYM" EXCLUDE PATTERN "*.dSYM" EXCLUDE
PATTERN "*_debug.dylib" EXCLUDE PATTERN "*_debug.dylib" EXCLUDE
PATTERN "audio/*.dylib" PATTERN "audio/*.dylib"
PATTERN "iconengines/*.dylib" PATTERN "iconengines/*.dylib"
PATTERN "imageformats/*.dylib" PATTERN "imageformats/*.dylib"
PATTERN "multimedia/*.dylib" PATTERN "multimedia/*.dylib"
PATTERN "platforms/*.dylib" PATTERN "platforms/*.dylib"
PATTERN "printsupport/*.dylib" PATTERN "printsupport/*.dylib"
PATTERN "styles/*.dylib" PATTERN "styles/*.dylib"
PATTERN "tls/*.dylib" PATTERN "tls/*.dylib"
) )
install( install(
DIRECTORY "${CMAKE_BINARY_DIR}/cockatrice/" DIRECTORY "${CMAKE_BINARY_DIR}/cockatrice/"
DESTINATION ${qtconf_dest_dir}/ DESTINATION ${qtconf_dest_dir}/
FILES_MATCHING FILES_MATCHING
PATTERN "*.ini" PATTERN "*.ini"
) )
install( install(
CODE " CODE "
file(WRITE \"\${CMAKE_INSTALL_PREFIX}/${qtconf_dest_dir}/qt.conf\" \"[Paths] file(WRITE \"\${CMAKE_INSTALL_PREFIX}/${qtconf_dest_dir}/qt.conf\" \"[Paths]
Plugins = Plugins Plugins = Plugins
Translations = Resources/translations Translations = Resources/translations
Data = Resources\") Data = Resources\")
" "
COMPONENT Runtime COMPONENT Runtime
) )
install( install(
CODE " CODE "
file(GLOB_RECURSE QTPLUGINS file(GLOB_RECURSE QTPLUGINS
\"\${CMAKE_INSTALL_PREFIX}/${plugin_dest_dir}/*.dylib\") \"\${CMAKE_INSTALL_PREFIX}/${plugin_dest_dir}/*.dylib\")
set(BU_CHMOD_BUNDLE_ITEMS ON) set(BU_CHMOD_BUNDLE_ITEMS ON)
include(BundleUtilities) include(BundleUtilities)
fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/cockatrice.app\" \"\${QTPLUGINS}\" \"${QT_LIBRARY_DIR}\") fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/cockatrice.app\" \"\${QTPLUGINS}\" \"${QT_LIBRARY_DIR}\")
" "
COMPONENT Runtime COMPONENT Runtime
) )
endif() endif()
@ -487,65 +488,65 @@ if(WIN32)
set(qtconf_dest_dir .) set(qtconf_dest_dir .)
install( install(
DIRECTORY "${CMAKE_BINARY_DIR}/${PROJECT_NAME}/${CMAKE_BUILD_TYPE}/" DIRECTORY "${CMAKE_BINARY_DIR}/${PROJECT_NAME}/${CMAKE_BUILD_TYPE}/"
DESTINATION ./ DESTINATION ./
FILES_MATCHING FILES_MATCHING
PATTERN "*.dll" PATTERN "*.dll"
) )
install( install(
DIRECTORY "${CMAKE_BINARY_DIR}/cockatrice/" DIRECTORY "${CMAKE_BINARY_DIR}/cockatrice/"
DESTINATION ./ DESTINATION ./
FILES_MATCHING FILES_MATCHING
PATTERN "*.ini" PATTERN "*.ini"
) )
# Qt plugins: audio (Qt5), iconengines, imageformats, multimedia (Qt6) platforms, printsupport (Qt5), styles, tls (Qt6) # Qt plugins: audio (Qt5), iconengines, imageformats, multimedia (Qt6) platforms, printsupport (Qt5), styles, tls (Qt6)
install( install(
DIRECTORY "${QT_PLUGINS_DIR}/" DIRECTORY "${QT_PLUGINS_DIR}/"
DESTINATION ${plugin_dest_dir} DESTINATION ${plugin_dest_dir}
COMPONENT Runtime COMPONENT Runtime
FILES_MATCHING FILES_MATCHING
PATTERN "audio/qtaudio_wasapi.dll" PATTERN "audio/qtaudio_wasapi.dll"
PATTERN "audio/qtaudio_windows.dll" PATTERN "audio/qtaudio_windows.dll"
PATTERN "iconengines/qsvgicon.dll" PATTERN "iconengines/qsvgicon.dll"
PATTERN "imageformats/*.dll" PATTERN "imageformats/*.dll"
PATTERN "mediaservice/dsengine.dll" PATTERN "mediaservice/dsengine.dll"
PATTERN "mediaservice/wmfengine.dll" PATTERN "mediaservice/wmfengine.dll"
PATTERN "multimedia/*.dll" PATTERN "multimedia/*.dll"
PATTERN "platforms/qdirect2d.dll" PATTERN "platforms/qdirect2d.dll"
PATTERN "platforms/qminimal.dll" PATTERN "platforms/qminimal.dll"
PATTERN "platforms/qoffscreen.dll" PATTERN "platforms/qoffscreen.dll"
PATTERN "platforms/qwindows.dll" PATTERN "platforms/qwindows.dll"
PATTERN "printsupport/windowsprintersupport.dll" PATTERN "printsupport/windowsprintersupport.dll"
PATTERN "styles/qcertonlybackend.dll" PATTERN "styles/qcertonlybackend.dll"
PATTERN "styles/qopensslbackend.dll" PATTERN "styles/qopensslbackend.dll"
PATTERN "styles/qschannelbackend.dll" PATTERN "styles/qschannelbackend.dll"
PATTERN "styles/qwindowsvistastyle.dll" PATTERN "styles/qwindowsvistastyle.dll"
PATTERN "tls/qcertonlybackend.dll" PATTERN "tls/qcertonlybackend.dll"
PATTERN "tls/qopensslbackend.dll" PATTERN "tls/qopensslbackend.dll"
PATTERN "tls/qschannelbackend.dll" PATTERN "tls/qschannelbackend.dll"
) )
install( install(
CODE " CODE "
file(WRITE \"\${CMAKE_INSTALL_PREFIX}/${qtconf_dest_dir}/qt.conf\" \"[Paths] file(WRITE \"\${CMAKE_INSTALL_PREFIX}/${qtconf_dest_dir}/qt.conf\" \"[Paths]
Plugins = Plugins Plugins = Plugins
Translations = Resources/translations Translations = Resources/translations
Data = Resources\") Data = Resources\")
" "
COMPONENT Runtime COMPONENT Runtime
) )
install( install(
CODE " CODE "
file(GLOB_RECURSE QTPLUGINS file(GLOB_RECURSE QTPLUGINS
\"\${CMAKE_INSTALL_PREFIX}/${plugin_dest_dir}/*.dll\") \"\${CMAKE_INSTALL_PREFIX}/${plugin_dest_dir}/*.dll\")
set(BU_CHMOD_BUNDLE_ITEMS ON) set(BU_CHMOD_BUNDLE_ITEMS ON)
include(BundleUtilities) include(BundleUtilities)
fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/Cockatrice.exe\" \"\${QTPLUGINS}\" \"${QT_LIBRARY_DIR}\") fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/Cockatrice.exe\" \"\${QTPLUGINS}\" \"${QT_LIBRARY_DIR}\")
" "
COMPONENT Runtime COMPONENT Runtime
) )
if(OPENSSL_FOUND) if(OPENSSL_FOUND)
@ -557,13 +558,13 @@ if(Qt6_FOUND AND Qt6LinguistTools_FOUND)
#Qt6 Translations happen after the executable is built up #Qt6 Translations happen after the executable is built up
if(UPDATE_TRANSLATIONS) if(UPDATE_TRANSLATIONS)
qt6_add_translations( qt6_add_translations(
cockatrice cockatrice
TS_FILES TS_FILES
${cockatrice_TS} ${cockatrice_TS}
SOURCES SOURCES
${translate_SRCS} ${translate_SRCS}
QM_FILES_OUTPUT_VARIABLE QM_FILES_OUTPUT_VARIABLE
cockatrice_QM cockatrice_QM
) )
else() else()
qt6_add_translations(cockatrice TS_FILES ${cockatrice_TS} QM_FILES_OUTPUT_VARIABLE cockatrice_QM) qt6_add_translations(cockatrice TS_FILES ${cockatrice_TS} QM_FILES_OUTPUT_VARIABLE cockatrice_QM)

View file

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

View file

@ -0,0 +1,9 @@
#include "deck_file_format.h"
DeckFileFormat::Format DeckFileFormat::getFormatFromName(const QString &fileName)
{
if (fileName.endsWith(".cod", Qt::CaseInsensitive)) {
return Cockatrice;
}
return PlainText;
}

View file

@ -0,0 +1,36 @@
#ifndef COCKATRICE_DECK_FILE_FORMAT_H
#define COCKATRICE_DECK_FILE_FORMAT_H
#include <QString>
namespace DeckFileFormat
{
/**
* The deck file formats that Cockatrice supports.
*/
enum Format
{
/**
* Plaintext deck files, a format that is intended to be widely supported among different programs.
* This format does not support Cockatrice specific features such as banner cards or tags.
*/
PlainText,
/**
* This is cockatrice's native deck file format, and supports deck metadata such as banner cards and tags.
* Stored as .cod files.
*/
Cockatrice
};
/**
* Determines what deck file format the given filename corresponds to.
*
* @param fileName The filename
* @return The deck format
*/
Format getFormatFromName(const QString &fileName);
} // namespace DeckFileFormat
#endif // COCKATRICE_DECK_FILE_FORMAT_H

View file

@ -33,7 +33,7 @@ DeckLoader::DeckLoader(QObject *parent, DeckList *_deckList) : QObject(parent),
{ {
} }
bool DeckLoader::loadFromFile(const QString &fileName, LoadedDeck::FileFormat fmt, bool userRequest) bool DeckLoader::loadFromFile(const QString &fileName, DeckFileFormat::Format 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, LoadedDeck::FileFormat fm
bool result = false; bool result = false;
switch (fmt) { switch (fmt) {
case LoadedDeck::PlainTextFormat: case DeckFileFormat::PlainText:
result = deckList->loadFromFile_Plain(&file); result = deckList->loadFromFile_Plain(&file);
break; break;
case LoadedDeck::CockatriceFormat: { case DeckFileFormat::Cockatrice: {
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 = LoadedDeck::PlainTextFormat; fmt = DeckFileFormat::PlainText;
} }
break; break;
} }
@ -77,7 +77,7 @@ bool DeckLoader::loadFromFile(const QString &fileName, LoadedDeck::FileFormat fm
return result; return result;
} }
bool DeckLoader::loadFromFileAsync(const QString &fileName, LoadedDeck::FileFormat fmt, bool userRequest) bool DeckLoader::loadFromFileAsync(const QString &fileName, DeckFileFormat::Format 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, LoadedDeck::FileForm
} }
switch (fmt) { switch (fmt) {
case LoadedDeck::PlainTextFormat: case DeckFileFormat::PlainText:
return deckList->loadFromFile_Plain(&file); return deckList->loadFromFile_Plain(&file);
case LoadedDeck::CockatriceFormat: { case DeckFileFormat::Cockatrice: {
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, LoadedDeck::FileFormat fmt) bool DeckLoader::saveToFile(const QString &fileName, DeckFileFormat::Format 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, LoadedDeck::FileFormat fmt)
bool result = false; bool result = false;
switch (fmt) { switch (fmt) {
case LoadedDeck::PlainTextFormat: case DeckFileFormat::PlainText:
result = deckList->saveToFile_Plain(&file); result = deckList->saveToFile_Plain(&file);
break; break;
case LoadedDeck::CockatriceFormat: case DeckFileFormat::Cockatrice:
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, LoadedDeck::FileFormat fmt)
return result; return result;
} }
bool DeckLoader::updateLastLoadedTimestamp(const QString &fileName, LoadedDeck::FileFormat fmt) bool DeckLoader::updateLastLoadedTimestamp(const QString &fileName, DeckFileFormat::Format fmt)
{ {
QFileInfo fileInfo(fileName); QFileInfo fileInfo(fileName);
if (!fileInfo.exists()) { if (!fileInfo.exists()) {
@ -193,10 +193,10 @@ bool DeckLoader::updateLastLoadedTimestamp(const QString &fileName, LoadedDeck::
// Perform file modifications // Perform file modifications
switch (fmt) { switch (fmt) {
case LoadedDeck::PlainTextFormat: case DeckFileFormat::PlainText:
result = deckList->saveToFile_Plain(&file); result = deckList->saveToFile_Plain(&file);
break; break;
case LoadedDeck::CockatriceFormat: case DeckFileFormat::Cockatrice:
deckList->setLastLoadedTimestamp(QDateTime::currentDateTime().toString()); deckList->setLastLoadedTimestamp(QDateTime::currentDateTime().toString());
result = deckList->saveToFile_Native(&file); result = deckList->saveToFile_Native(&file);
break; break;
@ -556,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 (LoadedDeck::getFormatFromName(fileName)) { switch (DeckFileFormat::getFormatFromName(fileName)) {
case LoadedDeck::PlainTextFormat: case DeckFileFormat::PlainText:
// 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 LoadedDeck::CockatriceFormat: case DeckFileFormat::Cockatrice:
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;
@ -582,7 +582,7 @@ bool DeckLoader::convertToCockatriceFormat(QString fileName)
} }
lastLoadInfo = { lastLoadInfo = {
.fileName = newFileName, .fileName = newFileName,
.fileFormat = LoadedDeck::CockatriceFormat, .fileFormat = DeckFileFormat::Cockatrice,
}; };
} }

View file

@ -67,11 +67,11 @@ public:
static void clearSetNamesAndNumbers(const DeckList *deckList); static void clearSetNamesAndNumbers(const DeckList *deckList);
bool loadFromFile(const QString &fileName, LoadedDeck::FileFormat fmt, bool userRequest = false); bool loadFromFile(const QString &fileName, DeckFileFormat::Format fmt, bool userRequest = false);
bool loadFromFileAsync(const QString &fileName, LoadedDeck::FileFormat fmt, bool userRequest); bool loadFromFileAsync(const QString &fileName, DeckFileFormat::Format fmt, bool userRequest);
bool loadFromRemote(const QString &nativeString, int remoteDeckId); bool loadFromRemote(const QString &nativeString, int remoteDeckId);
bool saveToFile(const QString &fileName, LoadedDeck::FileFormat fmt); bool saveToFile(const QString &fileName, DeckFileFormat::Format fmt);
bool updateLastLoadedTimestamp(const QString &fileName, LoadedDeck::FileFormat fmt); bool updateLastLoadedTimestamp(const QString &fileName, DeckFileFormat::Format fmt);
static QString exportDeckToDecklist(const DeckList *deckList, DecklistWebsite website); static QString exportDeckToDecklist(const DeckList *deckList, DecklistWebsite website);

View file

@ -1,12 +1,5 @@
#include "loaded_deck.h" #include "loaded_deck.h"
LoadedDeck::FileFormat LoadedDeck::getFormatFromName(const QString &fileName)
{
if (fileName.endsWith(".cod", Qt::CaseInsensitive)) {
return CockatriceFormat;
}
return PlainTextFormat;
}
bool LoadedDeck::LoadInfo::isEmpty() const bool LoadedDeck::LoadInfo::isEmpty() const
{ {

View file

@ -1,5 +1,7 @@
#ifndef COCKATRICE_LOADED_DECK_H #ifndef COCKATRICE_LOADED_DECK_H
#define COCKATRICE_LOADED_DECK_H #define COCKATRICE_LOADED_DECK_H
#include "deck_file_format.h"
#include "libcockatrice/deck_list/deck_list.h" #include "libcockatrice/deck_list/deck_list.h"
#include <QString> #include <QString>
@ -10,19 +12,6 @@
*/ */
struct LoadedDeck struct LoadedDeck
{ {
enum FileFormat
{
PlainTextFormat,
CockatriceFormat
};
/**
* Determines what deck file format the given filename corresponds to.
*
* @param fileName The filename
* @return The deck format
*/
static FileFormat getFormatFromName(const QString &fileName);
/** /**
* @brief Information about where the deck was loaded from. * @brief Information about where the deck was loaded from.
@ -35,7 +24,7 @@ struct LoadedDeck
static constexpr int NON_REMOTE_ID = -1; static constexpr int NON_REMOTE_ID = -1;
QString fileName = ""; QString fileName = "";
FileFormat fileFormat = CockatriceFormat; DeckFileFormat::Format fileFormat = DeckFileFormat::Cockatrice;
int remoteDeckId = NON_REMOTE_ID; int remoteDeckId = NON_REMOTE_ID;
bool isEmpty() const; bool isEmpty() const;

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",
LoadedDeck::CockatriceFormat, false); DeckFileFormat::Cockatrice, 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",
LoadedDeck::CockatriceFormat, false); DeckFileFormat::Cockatrice, 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)
{ {
LoadedDeck::FileFormat fmt = LoadedDeck::getFormatFromName(fileName); DeckFileFormat::Format fmt = DeckFileFormat::getFormatFromName(fileName);
auto *l = new DeckLoader(this); auto *l = new DeckLoader(this);
if (l->loadFromFile(fileName, fmt, true)) { if (l->loadFromFile(fileName, fmt, true)) {
@ -452,7 +452,7 @@ bool AbstractTabDeckEditor::actSaveDeckAs()
return false; return false;
QString fileName = dialog.selectedFiles().at(0); QString fileName = dialog.selectedFiles().at(0);
LoadedDeck::FileFormat fmt = LoadedDeck::getFormatFromName(fileName); DeckFileFormat::Format fmt = DeckFileFormat::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, LoadedDeck::CockatriceFormat, true)) if (!deckLoader->loadFromFile(filePath, DeckFileFormat::Cockatrice, 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, LoadedDeck::CockatriceFormat)) { if (!deck.loadFromFile(filePath, DeckFileFormat::Cockatrice)) {
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, LoadedDeck::CockatriceFormat); deck.saveToFile(filePath, DeckFileFormat::Cockatrice);
} }
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, LoadedDeck::getFormatFromName(filePath), true)) { if (!deckLoader->loadFromFile(filePath, DeckFileFormat::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, LoadedDeck::getFormatFromName(file), false); loader.loadFromFile(file, DeckFileFormat::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 (LoadedDeck::getFormatFromName(deckPreviewWidget->filePath) == LoadedDeck::CockatriceFormat) { if (DeckFileFormat::getFormatFromName(deckPreviewWidget->filePath) == DeckFileFormat::Cockatrice) {
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, LoadedDeck::getFormatFromName(filePath), false); deckLoader->loadFromFileAsync(filePath, DeckFileFormat::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, LoadedDeck::getFormatFromName(filePath)); deckLoader->saveToFile(filePath, DeckFileFormat::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, LoadedDeck::CockatriceFormat); deckLoader->saveToFile(filePath, DeckFileFormat::Cockatrice);
} }
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, LoadedDeck::getFormatFromName(filePath)); deckLoader->saveToFile(filePath, DeckFileFormat::getFormatFromName(filePath));
// update VDS // update VDS
refreshBannerCardText(); refreshBannerCardText();