mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-08 11:03:25 -08:00
[DeckSync] Address conflict review nits: enum class and designated initializers
This commit is contained in:
parent
9d93a39980
commit
f8c2e1105a
4 changed files with 38 additions and 41 deletions
|
|
@ -9,13 +9,13 @@
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
/** @brief How a both-sides-changed deck is resolved. */
|
/** @brief How a both-sides-changed deck is resolved. */
|
||||||
enum DeckSyncResolutionAction
|
enum class DeckSyncResolutionAction
|
||||||
{
|
{
|
||||||
DeckSyncKeepMine, ///< Upload the local deck, discarding the server version.
|
KeepMine, ///< Upload the local deck, discarding the server version.
|
||||||
DeckSyncKeepServer, ///< Download the server deck, discarding local changes.
|
KeepServer, ///< Download the server deck, discarding local changes.
|
||||||
DeckSyncKeepBoth, ///< Keep the local deck and store the server version aside.
|
KeepBoth, ///< Keep the local deck and store the server version aside.
|
||||||
DeckSyncUseMerge, ///< Upload the auto-merged deck (only when mergeable).
|
UseMerge, ///< Upload the auto-merged deck (only when mergeable).
|
||||||
DeckSyncSkipConflict, ///< Leave both sides untouched for this run.
|
SkipConflict, ///< Leave both sides untouched for this run.
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @brief Sync direction for one run. */
|
/** @brief Sync direction for one run. */
|
||||||
|
|
@ -42,7 +42,7 @@ struct DeckSyncConflict
|
||||||
/** @brief The dialog verdict for one DeckSyncConflict. */
|
/** @brief The dialog verdict for one DeckSyncConflict. */
|
||||||
struct DeckSyncResolution
|
struct DeckSyncResolution
|
||||||
{
|
{
|
||||||
DeckSyncResolutionAction action = DeckSyncKeepMine;
|
DeckSyncResolutionAction action = DeckSyncResolutionAction::KeepMine;
|
||||||
bool rememberSession = false; ///< Reuse this verdict for later conflicts this run.
|
bool rememberSession = false; ///< Reuse this verdict for later conflicts this run.
|
||||||
bool rememberAlways = false; ///< Store this verdict as the conflict default setting.
|
bool rememberAlways = false; ///< Store this verdict as the conflict default setting.
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -551,11 +551,8 @@ void DeckSyncManager::applyUpload(const QString &relativePath,
|
||||||
int deckId,
|
int deckId,
|
||||||
const QString &guid)
|
const QString &guid)
|
||||||
{
|
{
|
||||||
UploadOp op;
|
const UploadOp op{
|
||||||
op.relativePath = relativePath;
|
.relativePath = relativePath, .serverPath = serverPath, .serverDir = {}, .deckId = deckId, .guid = guid};
|
||||||
op.serverPath = serverPath;
|
|
||||||
op.deckId = deckId;
|
|
||||||
op.guid = guid;
|
|
||||||
pendingUploads.append(op);
|
pendingUploads.append(op);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -565,12 +562,11 @@ void DeckSyncManager::applyDownload(const QString &relativePath,
|
||||||
const QString &hash,
|
const QString &hash,
|
||||||
qint64 lastModifiedSecs)
|
qint64 lastModifiedSecs)
|
||||||
{
|
{
|
||||||
DownloadOp op;
|
const DownloadOp op{.relativePath = relativePath,
|
||||||
op.relativePath = relativePath;
|
.deckId = deckId,
|
||||||
op.deckId = deckId;
|
.guid = guid,
|
||||||
op.guid = guid;
|
.hash = hash,
|
||||||
op.hash = hash;
|
.lastModifiedSecs = lastModifiedSecs};
|
||||||
op.lastModifiedSecs = lastModifiedSecs;
|
|
||||||
pendingDownloads.append(op);
|
pendingDownloads.append(op);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -606,12 +602,11 @@ void DeckSyncManager::queueConflict(const QString &relativePath,
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ConflictDownload ctx;
|
const ConflictDownload ctx{.serverPath = serverPath,
|
||||||
ctx.serverPath = serverPath;
|
.deckId = deckId,
|
||||||
ctx.deckId = deckId;
|
.guid = serverGuid,
|
||||||
ctx.guid = serverGuid;
|
.hash = serverHash,
|
||||||
ctx.hash = serverHash;
|
.lastModifiedSecs = serverLastModifiedSecs};
|
||||||
ctx.lastModifiedSecs = serverLastModifiedSecs;
|
|
||||||
pendingConflicts.insert(relativePath, ctx);
|
pendingConflicts.insert(relativePath, ctx);
|
||||||
conflictPaths.insert(relativePath);
|
conflictPaths.insert(relativePath);
|
||||||
applyDownload(relativePath, deckId, serverGuid, serverHash, serverLastModifiedSecs);
|
applyDownload(relativePath, deckId, serverGuid, serverHash, serverLastModifiedSecs);
|
||||||
|
|
@ -667,22 +662,23 @@ void DeckSyncManager::resolveConflict(const DeckSyncResolution &resolution)
|
||||||
if (!syncing || !activeConflict.active) {
|
if (!syncing || !activeConflict.active) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (resolution.rememberSession &&
|
if (resolution.rememberSession && (resolution.action == DeckSyncResolutionAction::KeepMine ||
|
||||||
(resolution.action == DeckSyncKeepMine || resolution.action == DeckSyncKeepServer)) {
|
resolution.action == DeckSyncResolutionAction::KeepServer)) {
|
||||||
sessionDefault = resolution.action == DeckSyncKeepMine ? DeckSyncConflictKeepMine : DeckSyncConflictKeepServer;
|
sessionDefault = resolution.action == DeckSyncResolutionAction::KeepMine ? DeckSyncConflictKeepMine
|
||||||
|
: DeckSyncConflictKeepServer;
|
||||||
}
|
}
|
||||||
const ActiveConflict conflict = activeConflict;
|
const ActiveConflict conflict = activeConflict;
|
||||||
activeConflict.active = false;
|
activeConflict.active = false;
|
||||||
|
|
||||||
switch (resolution.action) {
|
switch (resolution.action) {
|
||||||
case DeckSyncKeepMine:
|
case DeckSyncResolutionAction::KeepMine:
|
||||||
applyUpload(conflict.relativePath, conflict.serverPath, conflict.deckId, conflict.serverGuid);
|
applyUpload(conflict.relativePath, conflict.serverPath, conflict.deckId, conflict.serverGuid);
|
||||||
break;
|
break;
|
||||||
case DeckSyncKeepServer:
|
case DeckSyncResolutionAction::KeepServer:
|
||||||
applyDownload(conflict.relativePath, conflict.deckId, conflict.serverGuid, conflict.serverHash,
|
applyDownload(conflict.relativePath, conflict.deckId, conflict.serverGuid, conflict.serverHash,
|
||||||
conflict.serverLastModifiedSecs);
|
conflict.serverLastModifiedSecs);
|
||||||
break;
|
break;
|
||||||
case DeckSyncKeepBoth: {
|
case DeckSyncResolutionAction::KeepBoth: {
|
||||||
// Persist the already-fetched server bytes synchronously: queuing a
|
// Persist the already-fetched server bytes synchronously: queuing a
|
||||||
// download here would race the upload below and fetch back Mine.
|
// 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
|
// The aside copy is a new local file, so it gets a fresh guid and
|
||||||
|
|
@ -716,7 +712,7 @@ void DeckSyncManager::resolveConflict(const DeckSyncResolution &resolution)
|
||||||
applyUpload(conflict.relativePath, conflict.serverPath, conflict.deckId, conflict.serverGuid);
|
applyUpload(conflict.relativePath, conflict.serverPath, conflict.deckId, conflict.serverGuid);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DeckSyncUseMerge: {
|
case DeckSyncResolutionAction::UseMerge: {
|
||||||
DeckSyncSidecar sidecar(sidecarPath);
|
DeckSyncSidecar sidecar(sidecarPath);
|
||||||
sidecar.load();
|
sidecar.load();
|
||||||
const QString guid =
|
const QString guid =
|
||||||
|
|
@ -753,7 +749,7 @@ void DeckSyncManager::resolveConflict(const DeckSyncResolution &resolution)
|
||||||
applyUpload(conflict.relativePath, conflict.serverPath, conflict.deckId, conflict.serverGuid);
|
applyUpload(conflict.relativePath, conflict.serverPath, conflict.deckId, conflict.serverGuid);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DeckSyncSkipConflict:
|
case DeckSyncResolutionAction::SkipConflict:
|
||||||
++skippedCount;
|
++skippedCount;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -157,15 +157,15 @@ void DlgSyncConflict::updateRememberBoxes()
|
||||||
DeckSyncResolutionAction DlgSyncConflict::selectedAction() const
|
DeckSyncResolutionAction DlgSyncConflict::selectedAction() const
|
||||||
{
|
{
|
||||||
if (keepServerRadio->isChecked()) {
|
if (keepServerRadio->isChecked()) {
|
||||||
return DeckSyncKeepServer;
|
return DeckSyncResolutionAction::KeepServer;
|
||||||
}
|
}
|
||||||
if (keepBothRadio->isChecked()) {
|
if (keepBothRadio->isChecked()) {
|
||||||
return DeckSyncKeepBoth;
|
return DeckSyncResolutionAction::KeepBoth;
|
||||||
}
|
}
|
||||||
if (mergeRadio->isChecked()) {
|
if (mergeRadio->isChecked()) {
|
||||||
return DeckSyncUseMerge;
|
return DeckSyncResolutionAction::UseMerge;
|
||||||
}
|
}
|
||||||
return DeckSyncKeepMine;
|
return DeckSyncResolutionAction::KeepMine;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeckSyncResolution DlgSyncConflict::resolution() const
|
DeckSyncResolution DlgSyncConflict::resolution() const
|
||||||
|
|
|
||||||
|
|
@ -583,15 +583,16 @@ void TabDeckStorage::onConflictRequest(const DeckSyncConflict &conflict)
|
||||||
DlgSyncConflict dialog(conflict, this);
|
DlgSyncConflict dialog(conflict, this);
|
||||||
if (dialog.exec() != QDialog::Accepted) {
|
if (dialog.exec() != QDialog::Accepted) {
|
||||||
DeckSyncResolution skip;
|
DeckSyncResolution skip;
|
||||||
skip.action = DeckSyncSkipConflict;
|
skip.action = DeckSyncResolutionAction::SkipConflict;
|
||||||
syncManager->resolveConflict(skip);
|
syncManager->resolveConflict(skip);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const DeckSyncResolution resolution = dialog.resolution();
|
const DeckSyncResolution resolution = dialog.resolution();
|
||||||
if (resolution.rememberAlways &&
|
if (resolution.rememberAlways && (resolution.action == DeckSyncResolutionAction::KeepMine ||
|
||||||
(resolution.action == DeckSyncKeepMine || resolution.action == DeckSyncKeepServer)) {
|
resolution.action == DeckSyncResolutionAction::KeepServer)) {
|
||||||
SettingsCache::instance().deckSync().setConflictDefault(
|
SettingsCache::instance().deckSync().setConflictDefault(resolution.action == DeckSyncResolutionAction::KeepMine
|
||||||
resolution.action == DeckSyncKeepMine ? DeckSyncConflictKeepMine : DeckSyncConflictKeepServer);
|
? DeckSyncConflictKeepMine
|
||||||
|
: DeckSyncConflictKeepServer);
|
||||||
}
|
}
|
||||||
syncManager->resolveConflict(resolution);
|
syncManager->resolveConflict(resolution);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue