mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
[DeckLoader] Refactor last load info into struct (#6366)
* [DeckLoader] Refactor last load info into struct * Use constant * [[nodiscard]] * do discard, I guess. --------- Co-authored-by: Brübach, Lukas <lukas.bruebach@student.fhws.de>
This commit is contained in:
parent
9ece4bfd9b
commit
858361e6d3
5 changed files with 60 additions and 44 deletions
|
|
@ -25,13 +25,11 @@ const QStringList DeckLoader::ACCEPTED_FILE_EXTENSIONS = {"*.cod", "*.dec", "*.d
|
|||
const QStringList DeckLoader::FILE_NAME_FILTERS = {
|
||||
tr("Common deck formats (%1)").arg(ACCEPTED_FILE_EXTENSIONS.join(" ")), tr("All files (*.*)")};
|
||||
|
||||
DeckLoader::DeckLoader(QObject *parent)
|
||||
: QObject(parent), deckList(new DeckList()), lastFileFormat(CockatriceFormat), lastRemoteDeckId(-1)
|
||||
DeckLoader::DeckLoader(QObject *parent) : QObject(parent), deckList(new DeckList())
|
||||
{
|
||||
}
|
||||
|
||||
DeckLoader::DeckLoader(QObject *parent, DeckList *_deckList)
|
||||
: QObject(parent), deckList(_deckList), lastFileFormat(CockatriceFormat), lastRemoteDeckId(-1)
|
||||
DeckLoader::DeckLoader(QObject *parent, DeckList *_deckList) : QObject(parent), deckList(_deckList)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -64,8 +62,10 @@ bool DeckLoader::loadFromFile(const QString &fileName, FileFormat fmt, bool user
|
|||
}
|
||||
|
||||
if (result) {
|
||||
lastFileName = fileName;
|
||||
lastFileFormat = fmt;
|
||||
lastLoadInfo = {
|
||||
.fileName = fileName,
|
||||
.fileFormat = fmt,
|
||||
};
|
||||
if (userRequest) {
|
||||
updateLastLoadedTimestamp(fileName, fmt);
|
||||
}
|
||||
|
|
@ -86,8 +86,10 @@ bool DeckLoader::loadFromFileAsync(const QString &fileName, FileFormat fmt, bool
|
|||
watcher->deleteLater();
|
||||
|
||||
if (result) {
|
||||
lastFileName = fileName;
|
||||
lastFileFormat = fmt;
|
||||
lastLoadInfo = {
|
||||
.fileName = fileName,
|
||||
.fileFormat = fmt,
|
||||
};
|
||||
if (userRequest) {
|
||||
updateLastLoadedTimestamp(fileName, fmt);
|
||||
}
|
||||
|
|
@ -129,9 +131,9 @@ bool DeckLoader::loadFromRemote(const QString &nativeString, int remoteDeckId)
|
|||
{
|
||||
bool result = deckList->loadFromString_Native(nativeString);
|
||||
if (result) {
|
||||
lastFileName = QString();
|
||||
lastFileFormat = CockatriceFormat;
|
||||
lastRemoteDeckId = remoteDeckId;
|
||||
lastLoadInfo = {
|
||||
.remoteDeckId = remoteDeckId,
|
||||
};
|
||||
|
||||
emit deckLoaded();
|
||||
}
|
||||
|
|
@ -157,8 +159,10 @@ bool DeckLoader::saveToFile(const QString &fileName, FileFormat fmt)
|
|||
}
|
||||
|
||||
if (result) {
|
||||
lastFileName = fileName;
|
||||
lastFileFormat = fmt;
|
||||
lastLoadInfo = {
|
||||
.fileName = fileName,
|
||||
.fileFormat = fmt,
|
||||
};
|
||||
qCInfo(DeckLoaderLog) << "Deck was saved -" << result;
|
||||
}
|
||||
|
||||
|
|
@ -201,8 +205,10 @@ bool DeckLoader::updateLastLoadedTimestamp(const QString &fileName, FileFormat f
|
|||
file.close(); // Close the file to ensure changes are flushed
|
||||
|
||||
if (result) {
|
||||
lastFileName = fileName;
|
||||
lastFileFormat = fmt;
|
||||
lastLoadInfo = {
|
||||
.fileName = fileName,
|
||||
.fileFormat = fmt,
|
||||
};
|
||||
|
||||
// Re-open the file and set the original timestamp
|
||||
if (!file.open(QIODevice::ReadWrite)) {
|
||||
|
|
@ -582,8 +588,10 @@ bool DeckLoader::convertToCockatriceFormat(QString fileName)
|
|||
} else {
|
||||
qCInfo(DeckLoaderLog) << "Original file deleted successfully:" << fileName;
|
||||
}
|
||||
lastFileName = newFileName;
|
||||
lastFileFormat = CockatriceFormat;
|
||||
lastLoadInfo = {
|
||||
.fileName = newFileName,
|
||||
.fileFormat = CockatriceFormat,
|
||||
};
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue