mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 09:33:25 -08:00
[DeckSync] Pass the sync summary through the signal and tidy the manager API
- Emit SyncSummary from syncFinished() instead of four positional ints, and build it from a single currentSummary() helper, so the counts cannot drift between the status message and the signal. - Use a designated initializer for LocalFile, like the other records. - Drop setClient() and setColorIdentityProvider(): both fields are already constructor parameters and the setters had no callers. setProfile() and setDeckPath() stay, since the tab re-reads them before every run. - Fix the include paths in tab_deck_storage.h and the narrowing conversion of the tree item id, so the branch builds again.
This commit is contained in:
parent
c0a62a2486
commit
ad0da98a86
4 changed files with 31 additions and 33 deletions
|
|
@ -47,11 +47,6 @@ DeckSyncManager::DeckSyncManager(AbstractClient *_client, ColorIdentityProvider
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckSyncManager::setClient(AbstractClient *_client)
|
|
||||||
{
|
|
||||||
client = _client;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeckSyncManager::setProfile(const DeckSyncProfile &_profile)
|
void DeckSyncManager::setProfile(const DeckSyncProfile &_profile)
|
||||||
{
|
{
|
||||||
profile = _profile;
|
profile = _profile;
|
||||||
|
|
@ -62,11 +57,6 @@ void DeckSyncManager::setDeckPath(const QString &path)
|
||||||
deckPath = path;
|
deckPath = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckSyncManager::setColorIdentityProvider(ColorIdentityProvider provider)
|
|
||||||
{
|
|
||||||
colorIdentityProvider = std::move(provider);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DeckSyncManager::isSyncing() const
|
bool DeckSyncManager::isSyncing() const
|
||||||
{
|
{
|
||||||
return syncing;
|
return syncing;
|
||||||
|
|
@ -78,12 +68,12 @@ void DeckSyncManager::syncNow()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (client == nullptr || !profile.isValid() || deckPath.isEmpty()) {
|
if (client == nullptr || !profile.isValid() || deckPath.isEmpty()) {
|
||||||
emit syncFinished(0, 0, 0, 0, tr("Not connected to a server."));
|
emit syncFinished(SyncSummary{}, tr("Not connected to a server."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QDir deckDir(deckPath);
|
QDir deckDir(deckPath);
|
||||||
if (!deckDir.exists()) {
|
if (!deckDir.exists()) {
|
||||||
emit syncFinished(0, 0, 0, 0, tr("Deck folder not found."));
|
emit syncFinished(SyncSummary{}, tr("Deck folder not found."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -120,11 +110,9 @@ void DeckSyncManager::syncNow()
|
||||||
++skippedCount;
|
++skippedCount;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
LocalFile file;
|
localFiles.insert(relativePath, LocalFile{.absolutePath = absolutePath,
|
||||||
file.absolutePath = absolutePath;
|
.hash = loaded->deckList.getDeckHash(),
|
||||||
file.hash = loaded->deckList.getDeckHash();
|
.modified = QFileInfo(absolutePath).lastModified()});
|
||||||
file.modified = QFileInfo(absolutePath).lastModified();
|
|
||||||
localFiles.insert(relativePath, file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Command_DeckList cmd;
|
Command_DeckList cmd;
|
||||||
|
|
@ -151,7 +139,7 @@ void DeckSyncManager::collectServerFiles(const ServerInfo_DeckStorage_Folder &fo
|
||||||
const QString path = prefix.isEmpty() ? name : prefix + "/" + name;
|
const QString path = prefix.isEmpty() ? name : prefix + "/" + name;
|
||||||
const ServerInfo_DeckStorage_File &file = item.file();
|
const ServerInfo_DeckStorage_File &file = item.file();
|
||||||
ServerFile entry{
|
ServerFile entry{
|
||||||
.id = item.id(),
|
.id = static_cast<int>(item.id()),
|
||||||
.guid = QString::fromStdString(file.guid()),
|
.guid = QString::fromStdString(file.guid()),
|
||||||
.hash = QString::fromStdString(file.hash()),
|
.hash = QString::fromStdString(file.hash()),
|
||||||
.lastModifiedSecs = file.has_last_modified() ? static_cast<qint64>(file.last_modified()) : 0,
|
.lastModifiedSecs = file.has_last_modified() ? static_cast<qint64>(file.last_modified()) : 0,
|
||||||
|
|
@ -543,16 +531,27 @@ void DeckSyncManager::onDownloadFinished(const Response &response,
|
||||||
void DeckSyncManager::failSync(const QString &error)
|
void DeckSyncManager::failSync(const QString &error)
|
||||||
{
|
{
|
||||||
syncing = false;
|
syncing = false;
|
||||||
emit syncFinished(uploadedCount, downloadedCount, unchangedCount, skippedCount, error);
|
emit syncFinished(currentSummary(), error);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckSyncManager::finishSync()
|
void DeckSyncManager::finishSync()
|
||||||
{
|
{
|
||||||
syncing = false;
|
syncing = false;
|
||||||
|
const SyncSummary summary = currentSummary();
|
||||||
emit statusMessage(tr("Sync complete: %1 uploaded, %2 downloaded, %3 unchanged, %4 skipped.")
|
emit statusMessage(tr("Sync complete: %1 uploaded, %2 downloaded, %3 unchanged, %4 skipped.")
|
||||||
.arg(uploadedCount)
|
.arg(summary.uploaded)
|
||||||
.arg(downloadedCount)
|
.arg(summary.downloaded)
|
||||||
.arg(unchangedCount)
|
.arg(summary.unchanged)
|
||||||
.arg(skippedCount));
|
.arg(summary.skipped));
|
||||||
emit syncFinished(uploadedCount, downloadedCount, unchangedCount, skippedCount, QString());
|
emit syncFinished(summary, QString());
|
||||||
|
}
|
||||||
|
|
||||||
|
DeckSyncManager::SyncSummary DeckSyncManager::currentSummary() const
|
||||||
|
{
|
||||||
|
return SyncSummary{
|
||||||
|
.uploaded = uploadedCount,
|
||||||
|
.downloaded = downloadedCount,
|
||||||
|
.unchanged = unchangedCount,
|
||||||
|
.skipped = skippedCount,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ public:
|
||||||
/** @brief Computes the color identity string uploaded alongside a deck. May be empty. */
|
/** @brief Computes the color identity string uploaded alongside a deck. May be empty. */
|
||||||
using ColorIdentityProvider = std::function<QString(const DeckList &)>;
|
using ColorIdentityProvider = std::function<QString(const DeckList &)>;
|
||||||
|
|
||||||
/** @brief Outcome counts for a finished sync run; mirrors syncFinished() parameters. */
|
/** @brief Outcome counts for a finished sync run, carried by syncFinished(). */
|
||||||
struct SyncSummary
|
struct SyncSummary
|
||||||
{
|
{
|
||||||
int uploaded = 0;
|
int uploaded = 0;
|
||||||
|
|
@ -56,10 +56,8 @@ public:
|
||||||
explicit DeckSyncManager(QObject *parent = nullptr);
|
explicit DeckSyncManager(QObject *parent = nullptr);
|
||||||
DeckSyncManager(AbstractClient *client, ColorIdentityProvider provider, QObject *parent = nullptr);
|
DeckSyncManager(AbstractClient *client, ColorIdentityProvider provider, QObject *parent = nullptr);
|
||||||
|
|
||||||
void setClient(AbstractClient *_client);
|
|
||||||
void setProfile(const DeckSyncProfile &_profile);
|
void setProfile(const DeckSyncProfile &_profile);
|
||||||
void setDeckPath(const QString &path);
|
void setDeckPath(const QString &path);
|
||||||
void setColorIdentityProvider(ColorIdentityProvider provider);
|
|
||||||
[[nodiscard]] bool isSyncing() const;
|
[[nodiscard]] bool isSyncing() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
@ -68,7 +66,7 @@ public slots:
|
||||||
signals:
|
signals:
|
||||||
void syncStarted();
|
void syncStarted();
|
||||||
void statusMessage(const QString &message);
|
void statusMessage(const QString &message);
|
||||||
void syncFinished(int uploaded, int downloaded, int unchanged, int skipped, const QString &error);
|
void syncFinished(const SyncSummary &summary, const QString &error);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onListFinished(const Response &response, const CommandContainer &commandContainer);
|
void onListFinished(const Response &response, const CommandContainer &commandContainer);
|
||||||
|
|
@ -111,6 +109,7 @@ private:
|
||||||
|
|
||||||
void failSync(const QString &error);
|
void failSync(const QString &error);
|
||||||
void finishSync();
|
void finishSync();
|
||||||
|
[[nodiscard]] SyncSummary currentSummary() const;
|
||||||
void collectServerFiles(const ServerInfo_DeckStorage_Folder &folder,
|
void collectServerFiles(const ServerInfo_DeckStorage_Folder &folder,
|
||||||
const QString &prefix,
|
const QString &prefix,
|
||||||
QMap<QString, ServerFile> &files,
|
QMap<QString, ServerFile> &files,
|
||||||
|
|
|
||||||
|
|
@ -565,7 +565,7 @@ void TabDeckStorage::onSyncStatusMessage(const QString &message)
|
||||||
renderSyncStatus();
|
renderSyncStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabDeckStorage::onSyncFinished(int uploaded, int downloaded, int unchanged, int skipped, const QString &error)
|
void TabDeckStorage::onSyncFinished(const SyncSummary &summary, const QString &error)
|
||||||
{
|
{
|
||||||
aSyncNow->setEnabled(remoteEnabled);
|
aSyncNow->setEnabled(remoteEnabled);
|
||||||
if (!error.isEmpty()) {
|
if (!error.isEmpty()) {
|
||||||
|
|
@ -574,7 +574,7 @@ void TabDeckStorage::onSyncFinished(int uploaded, int downloaded, int unchanged,
|
||||||
} else {
|
} else {
|
||||||
syncStatusType = SyncStatusType::Finished;
|
syncStatusType = SyncStatusType::Finished;
|
||||||
syncStatusDetail.clear();
|
syncStatusDetail.clear();
|
||||||
lastSyncSummary = {uploaded, downloaded, unchanged, skipped};
|
lastSyncSummary = summary;
|
||||||
}
|
}
|
||||||
renderSyncStatus();
|
renderSyncStatus();
|
||||||
if (error.isEmpty()) {
|
if (error.isEmpty()) {
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@
|
||||||
#ifndef TAB_DECK_STORAGE_H
|
#ifndef TAB_DECK_STORAGE_H
|
||||||
#define TAB_DECK_STORAGE_H
|
#define TAB_DECK_STORAGE_H
|
||||||
|
|
||||||
#include "../deck_sync/deck_sync_manager.h"
|
#include "../../deck_sync/deck_sync_manager.h"
|
||||||
#include "../interface/widgets/server/remote/remote_decklist_tree_widget.h"
|
#include "../server/remote/remote_decklist_tree_widget.h"
|
||||||
#include "tab.h"
|
#include "tab.h"
|
||||||
|
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
|
@ -129,7 +129,7 @@ private slots:
|
||||||
|
|
||||||
void actSyncNow();
|
void actSyncNow();
|
||||||
void onSyncStatusMessage(const QString &message);
|
void onSyncStatusMessage(const QString &message);
|
||||||
void onSyncFinished(int uploaded, int downloaded, int unchanged, int skipped, const QString &error);
|
void onSyncFinished(const SyncSummary &summary, const QString &error);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TabDeckStorage(TabSupervisor *_tabSupervisor, AbstractClient *_client, const ServerInfo_User *currentUserInfo);
|
TabDeckStorage(TabSupervisor *_tabSupervisor, AbstractClient *_client, const ServerInfo_User *currentUserInfo);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue