Skip to content

Commit cdd1250

Browse files
committed
gui: add a "Yes to all" button when resolving multiple conflicts at once
Fixes #7446 Signed-off-by: Jyrki Gadinger <nilsding@nilsding.org>
1 parent b5c3b08 commit cdd1250

3 files changed

Lines changed: 78 additions & 7 deletions

File tree

src/gui/conflictsolver.cpp

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ QString ConflictSolver::remoteVersionFilename() const
4040
return _remoteVersionFilename;
4141
}
4242

43+
bool ConflictSolver::isBulkSolution() const
44+
{
45+
return _isBulkSolution;
46+
}
47+
48+
bool ConflictSolver::yesToAllRequested() const
49+
{
50+
return _yesToAllRequested;
51+
}
52+
4353
bool ConflictSolver::exec(ConflictSolver::Solution solution)
4454
{
4555
switch (solution) {
@@ -74,6 +84,26 @@ void ConflictSolver::setRemoteVersionFilename(const QString &remoteVersionFilena
7484
emit remoteVersionFilenameChanged();
7585
}
7686

87+
void ConflictSolver::setIsBulkSolution(bool isBulkSolution)
88+
{
89+
if (_isBulkSolution == isBulkSolution) {
90+
return;
91+
}
92+
93+
_isBulkSolution = isBulkSolution;
94+
emit isBulkSolutionChanged();
95+
}
96+
97+
void ConflictSolver::setYesToAllRequested(bool yesToAllRequested)
98+
{
99+
if (_yesToAllRequested == yesToAllRequested) {
100+
return;
101+
}
102+
103+
_yesToAllRequested = yesToAllRequested;
104+
emit yesToAllRequestedChanged();
105+
}
106+
77107
bool ConflictSolver::deleteLocalVersion()
78108
{
79109
if (_localVersionFilename.isEmpty()) {
@@ -84,13 +114,9 @@ bool ConflictSolver::deleteLocalVersion()
84114
return false;
85115
}
86116

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

95121
if (FileSystem::isDir(_localVersionFilename)) {
96122
return FileSystem::removeRecursively(_localVersionFilename);
@@ -161,4 +187,31 @@ bool ConflictSolver::overwriteRemoteVersion()
161187
}
162188
}
163189

190+
bool ConflictSolver::confirmDeletion()
191+
{
192+
if (_yesToAllRequested) {
193+
return true;
194+
}
195+
196+
QMessageBox::StandardButton yesToAllButton = _isBulkSolution ? QMessageBox::YesToAll : QMessageBox::NoButton;
197+
198+
QFileInfo info(_localVersionFilename);
199+
const auto message = FileSystem::isDir(_localVersionFilename)
200+
? tr("Do you want to delete the directory <i>%1</i> and all its contents permanently?").arg(info.dir().dirName())
201+
: tr("Do you want to delete the file <i>%1</i> permanently?").arg(info.fileName());
202+
const auto result = QMessageBox::question(_parentWidget, tr("Confirm deletion"), message, QMessageBox::Yes, QMessageBox::No, yesToAllButton);
203+
switch (result)
204+
{
205+
case QMessageBox::YesToAll:
206+
setYesToAllRequested(true);
207+
return true;
208+
case QMessageBox::Yes:
209+
return true;
210+
default:
211+
// any other button pressed
212+
return false;
213+
}
214+
return false;
215+
}
216+
164217
} // namespace OCC

src/gui/conflictsolver.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class ConflictSolver : public QObject
2626
Q_OBJECT
2727
Q_PROPERTY(QString localVersionFilename READ localVersionFilename WRITE setLocalVersionFilename NOTIFY localVersionFilenameChanged)
2828
Q_PROPERTY(QString remoteVersionFilename READ remoteVersionFilename WRITE setRemoteVersionFilename NOTIFY remoteVersionFilenameChanged)
29+
Q_PROPERTY(bool isBulkSolution READ isBulkSolution WRITE setIsBulkSolution NOTIFY isBulkSolutionChanged)
30+
Q_PROPERTY(bool yesToAllRequested READ yesToAllRequested WRITE setYesToAllRequested NOTIFY yesToAllRequestedChanged)
31+
2932
public:
3033
enum Solution {
3134
KeepLocalVersion,
@@ -38,25 +41,34 @@ class ConflictSolver : public QObject
3841

3942
[[nodiscard]] QString localVersionFilename() const;
4043
[[nodiscard]] QString remoteVersionFilename() const;
44+
[[nodiscard]] bool isBulkSolution() const;
45+
[[nodiscard]] bool yesToAllRequested() const;
4146

4247
bool exec(Solution solution);
4348

4449
public slots:
4550
void setLocalVersionFilename(const QString &localVersionFilename);
4651
void setRemoteVersionFilename(const QString &remoteVersionFilename);
52+
void setIsBulkSolution(bool isBulkSolution);
53+
void setYesToAllRequested(bool yesToAllRequested);
4754

4855
signals:
4956
void localVersionFilenameChanged();
5057
void remoteVersionFilenameChanged();
58+
void isBulkSolutionChanged();
59+
void yesToAllRequestedChanged();
5160

5261
private:
5362
bool deleteLocalVersion();
5463
bool renameLocalVersion();
5564
bool overwriteRemoteVersion();
65+
bool confirmDeletion();
5666

5767
QWidget *_parentWidget;
5868
QString _localVersionFilename;
5969
QString _remoteVersionFilename;
70+
bool _isBulkSolution = false;
71+
bool _yesToAllRequested = false;
6072
};
6173

6274
} // namespace OCC

src/gui/syncconflictsmodel.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,19 @@ void SyncConflictsModel::selectAllConflicting(bool selected)
224224

225225
void SyncConflictsModel::applySolution()
226226
{
227-
for(const auto &syncConflict : std::as_const(_conflictData)) {
227+
bool yesToAllRequested = false;
228+
bool isBulkSolution = _conflictData.size() > 1; // no need to display the "Yes for all" button if only one file is affected
229+
230+
for (const auto &syncConflict : std::as_const(_conflictData)) {
228231
if (syncConflict.isValid()) {
229232
qCInfo(lcSyncConflictsModel) << syncConflict.mExistingFilePath << syncConflict.mConflictingFilePath << syncConflict.solution();
230233
ConflictSolver solver;
234+
solver.setIsBulkSolution(isBulkSolution);
235+
solver.setYesToAllRequested(yesToAllRequested);
231236
solver.setLocalVersionFilename(syncConflict.mConflictingFilePath);
232237
solver.setRemoteVersionFilename(syncConflict.mExistingFilePath);
233238
solver.exec(syncConflict.solution());
239+
yesToAllRequested = solver.yesToAllRequested();
234240
}
235241
}
236242
}

0 commit comments

Comments
 (0)