diff --git a/cockatrice/src/interface/deck_sync/deck_sync_conflict.h b/cockatrice/src/interface/deck_sync/deck_sync_conflict.h index a5b272ecd..215a7acd3 100644 --- a/cockatrice/src/interface/deck_sync/deck_sync_conflict.h +++ b/cockatrice/src/interface/deck_sync/deck_sync_conflict.h @@ -9,13 +9,13 @@ #include /** @brief How a both-sides-changed deck is resolved. */ -enum DeckSyncResolutionAction +enum class DeckSyncResolutionAction { - DeckSyncKeepMine, ///< Upload the local deck, discarding the server version. - DeckSyncKeepServer, ///< Download the server deck, discarding local changes. - DeckSyncKeepBoth, ///< Keep the local deck and store the server version aside. - DeckSyncUseMerge, ///< Upload the auto-merged deck (only when mergeable). - DeckSyncSkipConflict, ///< Leave both sides untouched for this run. + KeepMine, ///< Upload the local deck, discarding the server version. + KeepServer, ///< Download the server deck, discarding local changes. + KeepBoth, ///< Keep the local deck and store the server version aside. + UseMerge, ///< Upload the auto-merged deck (only when mergeable). + SkipConflict, ///< Leave both sides untouched for this run. }; /** @brief Sync direction for one run. */ @@ -42,7 +42,7 @@ struct DeckSyncConflict /** @brief The dialog verdict for one DeckSyncConflict. */ struct DeckSyncResolution { - DeckSyncResolutionAction action = DeckSyncKeepMine; + DeckSyncResolutionAction action = DeckSyncResolutionAction::KeepMine; bool rememberSession = false; ///< Reuse this verdict for later conflicts this run. bool rememberAlways = false; ///< Store this verdict as the conflict default setting. }; diff --git a/cockatrice/src/interface/deck_sync/deck_sync_manager.cpp b/cockatrice/src/interface/deck_sync/deck_sync_manager.cpp index 227902bbe..157908f92 100644 --- a/cockatrice/src/interface/deck_sync/deck_sync_manager.cpp +++ b/cockatrice/src/interface/deck_sync/deck_sync_manager.cpp @@ -483,11 +483,8 @@ void DeckSyncManager::applyUpload(const QString &relativePath, int deckId, const QString &guid) { - UploadOp op; - op.relativePath = relativePath; - op.serverPath = serverPath; - op.deckId = deckId; - op.guid = guid; + const UploadOp op{ + .relativePath = relativePath, .serverPath = serverPath, .serverDir = {}, .deckId = deckId, .guid = guid}; pendingUploads.append(op); } @@ -497,12 +494,11 @@ void DeckSyncManager::applyDownload(const QString &relativePath, const QString &hash, qint64 lastModifiedSecs) { - DownloadOp op; - op.relativePath = relativePath; - op.deckId = deckId; - op.guid = guid; - op.hash = hash; - op.lastModifiedSecs = lastModifiedSecs; + const DownloadOp op{.relativePath = relativePath, + .deckId = deckId, + .guid = guid, + .hash = hash, + .lastModifiedSecs = lastModifiedSecs}; pendingDownloads.append(op); } @@ -538,12 +534,11 @@ void DeckSyncManager::queueConflict(const QString &relativePath, } return; } - ConflictDownload ctx; - ctx.serverPath = serverPath; - ctx.deckId = deckId; - ctx.guid = serverGuid; - ctx.hash = serverHash; - ctx.lastModifiedSecs = serverLastModifiedSecs; + const ConflictDownload ctx{.serverPath = serverPath, + .deckId = deckId, + .guid = serverGuid, + .hash = serverHash, + .lastModifiedSecs = serverLastModifiedSecs}; pendingConflicts.insert(relativePath, ctx); conflictPaths.insert(relativePath); applyDownload(relativePath, deckId, serverGuid, serverHash, serverLastModifiedSecs); @@ -599,22 +594,23 @@ void DeckSyncManager::resolveConflict(const DeckSyncResolution &resolution) if (!syncing || !activeConflict.active) { return; } - if (resolution.rememberSession && - (resolution.action == DeckSyncKeepMine || resolution.action == DeckSyncKeepServer)) { - sessionDefault = resolution.action == DeckSyncKeepMine ? DeckSyncConflictKeepMine : DeckSyncConflictKeepServer; + if (resolution.rememberSession && (resolution.action == DeckSyncResolutionAction::KeepMine || + resolution.action == DeckSyncResolutionAction::KeepServer)) { + sessionDefault = resolution.action == DeckSyncResolutionAction::KeepMine ? DeckSyncConflictKeepMine + : DeckSyncConflictKeepServer; } const ActiveConflict conflict = activeConflict; activeConflict.active = false; switch (resolution.action) { - case DeckSyncKeepMine: + case DeckSyncResolutionAction::KeepMine: applyUpload(conflict.relativePath, conflict.serverPath, conflict.deckId, conflict.serverGuid); break; - case DeckSyncKeepServer: + case DeckSyncResolutionAction::KeepServer: applyDownload(conflict.relativePath, conflict.deckId, conflict.serverGuid, conflict.serverHash, conflict.serverLastModifiedSecs); break; - case DeckSyncKeepBoth: { + case DeckSyncResolutionAction::KeepBoth: { // Persist the already-fetched server bytes synchronously: queuing a // download here would race the upload below and fetch back Mine. // The aside copy is a new local file, so it gets a fresh guid and @@ -648,7 +644,7 @@ void DeckSyncManager::resolveConflict(const DeckSyncResolution &resolution) applyUpload(conflict.relativePath, conflict.serverPath, conflict.deckId, conflict.serverGuid); break; } - case DeckSyncUseMerge: { + case DeckSyncResolutionAction::UseMerge: { DeckSyncSidecar sidecar(sidecarPath); sidecar.load(); const QString guid = @@ -685,7 +681,7 @@ void DeckSyncManager::resolveConflict(const DeckSyncResolution &resolution) applyUpload(conflict.relativePath, conflict.serverPath, conflict.deckId, conflict.serverGuid); break; } - case DeckSyncSkipConflict: + case DeckSyncResolutionAction::SkipConflict: ++skippedCount; break; } diff --git a/cockatrice/src/interface/widgets/dialogs/dlg_sync_conflict.cpp b/cockatrice/src/interface/widgets/dialogs/dlg_sync_conflict.cpp index 7d548993d..9264544f6 100644 --- a/cockatrice/src/interface/widgets/dialogs/dlg_sync_conflict.cpp +++ b/cockatrice/src/interface/widgets/dialogs/dlg_sync_conflict.cpp @@ -157,15 +157,15 @@ void DlgSyncConflict::updateRememberBoxes() DeckSyncResolutionAction DlgSyncConflict::selectedAction() const { if (keepServerRadio->isChecked()) { - return DeckSyncKeepServer; + return DeckSyncResolutionAction::KeepServer; } if (keepBothRadio->isChecked()) { - return DeckSyncKeepBoth; + return DeckSyncResolutionAction::KeepBoth; } if (mergeRadio->isChecked()) { - return DeckSyncUseMerge; + return DeckSyncResolutionAction::UseMerge; } - return DeckSyncKeepMine; + return DeckSyncResolutionAction::KeepMine; } DeckSyncResolution DlgSyncConflict::resolution() const diff --git a/cockatrice/src/interface/widgets/tabs/tab_deck_storage.cpp b/cockatrice/src/interface/widgets/tabs/tab_deck_storage.cpp index cc68f9fc1..195ed84aa 100644 --- a/cockatrice/src/interface/widgets/tabs/tab_deck_storage.cpp +++ b/cockatrice/src/interface/widgets/tabs/tab_deck_storage.cpp @@ -583,15 +583,16 @@ void TabDeckStorage::onConflictRequest(const DeckSyncConflict &conflict) DlgSyncConflict dialog(conflict, this); if (dialog.exec() != QDialog::Accepted) { DeckSyncResolution skip; - skip.action = DeckSyncSkipConflict; + skip.action = DeckSyncResolutionAction::SkipConflict; syncManager->resolveConflict(skip); return; } const DeckSyncResolution resolution = dialog.resolution(); - if (resolution.rememberAlways && - (resolution.action == DeckSyncKeepMine || resolution.action == DeckSyncKeepServer)) { - SettingsCache::instance().deckSync().setConflictDefault( - resolution.action == DeckSyncKeepMine ? DeckSyncConflictKeepMine : DeckSyncConflictKeepServer); + if (resolution.rememberAlways && (resolution.action == DeckSyncResolutionAction::KeepMine || + resolution.action == DeckSyncResolutionAction::KeepServer)) { + SettingsCache::instance().deckSync().setConflictDefault(resolution.action == DeckSyncResolutionAction::KeepMine + ? DeckSyncConflictKeepMine + : DeckSyncConflictKeepServer); } syncManager->resolveConflict(resolution); }