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
f9cbeb2f21
commit
4fd03576e5
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)
|
||||
{
|
||||
profile = _profile;
|
||||
|
|
@ -62,11 +57,6 @@ void DeckSyncManager::setDeckPath(const QString &path)
|
|||
deckPath = path;
|
||||
}
|
||||
|
||||
void DeckSyncManager::setColorIdentityProvider(ColorIdentityProvider provider)
|
||||
{
|
||||
colorIdentityProvider = std::move(provider);
|
||||
}
|
||||
|
||||
bool DeckSyncManager::isSyncing() const
|
||||
{
|
||||
return syncing;
|
||||
|
|
@ -78,12 +68,12 @@ void DeckSyncManager::syncNow()
|
|||
return;
|
||||
}
|
||||
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;
|
||||
}
|
||||
QDir deckDir(deckPath);
|
||||
if (!deckDir.exists()) {
|
||||
emit syncFinished(0, 0, 0, 0, tr("Deck folder not found."));
|
||||
emit syncFinished(SyncSummary{}, tr("Deck folder not found."));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -120,11 +110,9 @@ void DeckSyncManager::syncNow()
|
|||
++skippedCount;
|
||||
continue;
|
||||
}
|
||||
LocalFile file;
|
||||
file.absolutePath = absolutePath;
|
||||
file.hash = loaded->deckList.getDeckHash();
|
||||
file.modified = QFileInfo(absolutePath).lastModified();
|
||||
localFiles.insert(relativePath, file);
|
||||
localFiles.insert(relativePath, LocalFile{.absolutePath = absolutePath,
|
||||
.hash = loaded->deckList.getDeckHash(),
|
||||
.modified = QFileInfo(absolutePath).lastModified()});
|
||||
}
|
||||
|
||||
Command_DeckList cmd;
|
||||
|
|
@ -151,7 +139,7 @@ void DeckSyncManager::collectServerFiles(const ServerInfo_DeckStorage_Folder &fo
|
|||
const QString path = prefix.isEmpty() ? name : prefix + "/" + name;
|
||||
const ServerInfo_DeckStorage_File &file = item.file();
|
||||
ServerFile entry{
|
||||
.id = item.id(),
|
||||
.id = static_cast<int>(item.id()),
|
||||
.guid = QString::fromStdString(file.guid()),
|
||||
.hash = QString::fromStdString(file.hash()),
|
||||
.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)
|
||||
{
|
||||
syncing = false;
|
||||
emit syncFinished(uploadedCount, downloadedCount, unchangedCount, skippedCount, error);
|
||||
emit syncFinished(currentSummary(), error);
|
||||
}
|
||||
|
||||
void DeckSyncManager::finishSync()
|
||||
{
|
||||
syncing = false;
|
||||
const SyncSummary summary = currentSummary();
|
||||
emit statusMessage(tr("Sync complete: %1 uploaded, %2 downloaded, %3 unchanged, %4 skipped.")
|
||||
.arg(uploadedCount)
|
||||
.arg(downloadedCount)
|
||||
.arg(unchangedCount)
|
||||
.arg(skippedCount));
|
||||
emit syncFinished(uploadedCount, downloadedCount, unchangedCount, skippedCount, QString());
|
||||
.arg(summary.uploaded)
|
||||
.arg(summary.downloaded)
|
||||
.arg(summary.unchanged)
|
||||
.arg(summary.skipped));
|
||||
emit syncFinished(summary, QString());
|
||||
}
|
||||
|
||||
DeckSyncManager::SyncSummary DeckSyncManager::currentSummary() const
|
||||
{
|
||||
return SyncSummary{
|
||||
.uploaded = uploadedCount,
|
||||
.downloaded = downloadedCount,
|
||||
.unchanged = unchangedCount,
|
||||
.skipped = skippedCount,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue