Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 62 additions & 6 deletions src/gui/conflictsolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ QString ConflictSolver::remoteVersionFilename() const
return _remoteVersionFilename;
}

bool ConflictSolver::isBulkSolution() const
{
return _isBulkSolution;
}

bool ConflictSolver::yesToAllRequested() const
{
return _yesToAllRequested;
}

bool ConflictSolver::exec(ConflictSolver::Solution solution)
{
switch (solution) {
Expand Down Expand Up @@ -65,6 +75,26 @@ void ConflictSolver::setRemoteVersionFilename(const QString &remoteVersionFilena
emit remoteVersionFilenameChanged();
}

void ConflictSolver::setIsBulkSolution(bool isBulkSolution)
{
if (_isBulkSolution == isBulkSolution) {
return;
}

_isBulkSolution = isBulkSolution;
emit isBulkSolutionChanged();
}

void ConflictSolver::setYesToAllRequested(bool yesToAllRequested)
{
if (_yesToAllRequested == yesToAllRequested) {
return;
}

_yesToAllRequested = yesToAllRequested;
emit yesToAllRequestedChanged();
}

bool ConflictSolver::deleteLocalVersion()
{
if (_localVersionFilename.isEmpty()) {
Expand All @@ -75,13 +105,9 @@ bool ConflictSolver::deleteLocalVersion()
return false;
}

QFileInfo info(_localVersionFilename);
const auto message = FileSystem::isDir(_localVersionFilename)
? tr("Do you want to delete the directory <i>%1</i> and all its contents permanently?").arg(info.dir().dirName())
: tr("Do you want to delete the file <i>%1</i> permanently?").arg(info.fileName());
const auto result = QMessageBox::question(_parentWidget, tr("Confirm deletion"), message, QMessageBox::Yes, QMessageBox::No);
if (result != QMessageBox::Yes)
if (!confirmDeletion()) {
return false;
}

if (FileSystem::isDir(_localVersionFilename)) {
return FileSystem::removeRecursively(_localVersionFilename);
Expand Down Expand Up @@ -152,4 +178,34 @@ bool ConflictSolver::overwriteRemoteVersion()
}
}

bool ConflictSolver::confirmDeletion()
{
if (_yesToAllRequested) {
return true;
}

QMessageBox::StandardButtons buttons = QMessageBox::Yes | QMessageBox::No;
if (_isBulkSolution) {
buttons |= QMessageBox::YesToAll;
}

QFileInfo info(_localVersionFilename);
const auto message = FileSystem::isDir(_localVersionFilename)
? tr("Do you want to delete the directory <i>%1</i> and all its contents permanently?").arg(info.dir().dirName())
: tr("Do you want to delete the file <i>%1</i> permanently?").arg(info.fileName());
const auto result = QMessageBox::question(_parentWidget, tr("Confirm deletion"), message, buttons);
switch (result)
{
case QMessageBox::YesToAll:
setYesToAllRequested(true);
return true;
case QMessageBox::Yes:
return true;
default:
// any other button pressed
return false;
}
return false;
}

} // namespace OCC
12 changes: 12 additions & 0 deletions src/gui/conflictsolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class ConflictSolver : public QObject
Q_OBJECT
Q_PROPERTY(QString localVersionFilename READ localVersionFilename WRITE setLocalVersionFilename NOTIFY localVersionFilenameChanged)
Q_PROPERTY(QString remoteVersionFilename READ remoteVersionFilename WRITE setRemoteVersionFilename NOTIFY remoteVersionFilenameChanged)
Q_PROPERTY(bool isBulkSolution READ isBulkSolution WRITE setIsBulkSolution NOTIFY isBulkSolutionChanged)
Q_PROPERTY(bool yesToAllRequested READ yesToAllRequested WRITE setYesToAllRequested NOTIFY yesToAllRequestedChanged)

public:
enum Solution {
KeepLocalVersion,
Expand All @@ -29,25 +32,34 @@ class ConflictSolver : public QObject

[[nodiscard]] QString localVersionFilename() const;
[[nodiscard]] QString remoteVersionFilename() const;
[[nodiscard]] bool isBulkSolution() const;
[[nodiscard]] bool yesToAllRequested() const;

bool exec(Solution solution);

public slots:
void setLocalVersionFilename(const QString &localVersionFilename);
void setRemoteVersionFilename(const QString &remoteVersionFilename);
void setIsBulkSolution(bool isBulkSolution);
void setYesToAllRequested(bool yesToAllRequested);

signals:
void localVersionFilenameChanged();
void remoteVersionFilenameChanged();
void isBulkSolutionChanged();
void yesToAllRequestedChanged();

private:
bool deleteLocalVersion();
bool renameLocalVersion();
bool overwriteRemoteVersion();
bool confirmDeletion();

QWidget *_parentWidget;
QString _localVersionFilename;
QString _remoteVersionFilename;
bool _isBulkSolution = false;
bool _yesToAllRequested = false;
};

} // namespace OCC
Expand Down
8 changes: 7 additions & 1 deletion src/gui/syncconflictsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,19 @@ void SyncConflictsModel::selectAllConflicting(bool selected)

void SyncConflictsModel::applySolution()
{
for(const auto &syncConflict : std::as_const(_conflictData)) {
bool yesToAllRequested = false;
bool isBulkSolution = _conflictData.size() > 1; // no need to display the "Yes for all" button if only one file is affected

for (const auto &syncConflict : std::as_const(_conflictData)) {
if (syncConflict.isValid()) {
qCInfo(lcSyncConflictsModel) << syncConflict.mExistingFilePath << syncConflict.mConflictingFilePath << syncConflict.solution();
ConflictSolver solver;
solver.setIsBulkSolution(isBulkSolution);
solver.setYesToAllRequested(yesToAllRequested);
solver.setLocalVersionFilename(syncConflict.mConflictingFilePath);
solver.setRemoteVersionFilename(syncConflict.mExistingFilePath);
solver.exec(syncConflict.solution());
yesToAllRequested = solver.yesToAllRequested();
}
}
}
Expand Down