Skip to content

Commit d2712e8

Browse files
authored
Merge pull request #8044 from nextcloud/feature/yes-to-all-conflictsdialog
gui: add a "Yes to all" button when resolving multiple conflicts at once
2 parents e21861f + e75defd commit d2712e8

3 files changed

Lines changed: 81 additions & 7 deletions

File tree

src/gui/conflictsolver.cpp

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ QString ConflictSolver::remoteVersionFilename() const
3131
return _remoteVersionFilename;
3232
}
3333

34+
bool ConflictSolver::isBulkSolution() const
35+
{
36+
return _isBulkSolution;
37+
}
38+
39+
bool ConflictSolver::yesToAllRequested() const
40+
{
41+
return _yesToAllRequested;
42+
}
43+
3444
bool ConflictSolver::exec(ConflictSolver::Solution solution)
3545
{
3646
switch (solution) {
@@ -65,6 +75,26 @@ void ConflictSolver::setRemoteVersionFilename(const QString &remoteVersionFilena
6575
emit remoteVersionFilenameChanged();
6676
}
6777

78+
void ConflictSolver::setIsBulkSolution(bool isBulkSolution)
79+
{
80+
if (_isBulkSolution == isBulkSolution) {
81+
return;
82+
}
83+
84+
_isBulkSolution = isBulkSolution;
85+
emit isBulkSolutionChanged();
86+
}
87+
88+
void ConflictSolver::setYesToAllRequested(bool yesToAllRequested)
89+
{
90+
if (_yesToAllRequested == yesToAllRequested) {
91+
return;
92+
}
93+
94+
_yesToAllRequested = yesToAllRequested;
95+
emit yesToAllRequestedChanged();
96+
}
97+
6898
bool ConflictSolver::deleteLocalVersion()
6999
{
70100
if (_localVersionFilename.isEmpty()) {
@@ -75,13 +105,9 @@ bool ConflictSolver::deleteLocalVersion()
75105
return false;
76106
}
77107

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

86112
if (FileSystem::isDir(_localVersionFilename)) {
87113
return FileSystem::removeRecursively(_localVersionFilename);
@@ -152,4 +178,34 @@ bool ConflictSolver::overwriteRemoteVersion()
152178
}
153179
}
154180

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

src/gui/conflictsolver.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class ConflictSolver : public QObject
1717
Q_OBJECT
1818
Q_PROPERTY(QString localVersionFilename READ localVersionFilename WRITE setLocalVersionFilename NOTIFY localVersionFilenameChanged)
1919
Q_PROPERTY(QString remoteVersionFilename READ remoteVersionFilename WRITE setRemoteVersionFilename NOTIFY remoteVersionFilenameChanged)
20+
Q_PROPERTY(bool isBulkSolution READ isBulkSolution WRITE setIsBulkSolution NOTIFY isBulkSolutionChanged)
21+
Q_PROPERTY(bool yesToAllRequested READ yesToAllRequested WRITE setYesToAllRequested NOTIFY yesToAllRequestedChanged)
22+
2023
public:
2124
enum Solution {
2225
KeepLocalVersion,
@@ -29,25 +32,34 @@ class ConflictSolver : public QObject
2932

3033
[[nodiscard]] QString localVersionFilename() const;
3134
[[nodiscard]] QString remoteVersionFilename() const;
35+
[[nodiscard]] bool isBulkSolution() const;
36+
[[nodiscard]] bool yesToAllRequested() const;
3237

3338
bool exec(Solution solution);
3439

3540
public slots:
3641
void setLocalVersionFilename(const QString &localVersionFilename);
3742
void setRemoteVersionFilename(const QString &remoteVersionFilename);
43+
void setIsBulkSolution(bool isBulkSolution);
44+
void setYesToAllRequested(bool yesToAllRequested);
3845

3946
signals:
4047
void localVersionFilenameChanged();
4148
void remoteVersionFilenameChanged();
49+
void isBulkSolutionChanged();
50+
void yesToAllRequestedChanged();
4251

4352
private:
4453
bool deleteLocalVersion();
4554
bool renameLocalVersion();
4655
bool overwriteRemoteVersion();
56+
bool confirmDeletion();
4757

4858
QWidget *_parentWidget;
4959
QString _localVersionFilename;
5060
QString _remoteVersionFilename;
61+
bool _isBulkSolution = false;
62+
bool _yesToAllRequested = false;
5163
};
5264

5365
} // namespace OCC

src/gui/syncconflictsmodel.cpp

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

216216
void SyncConflictsModel::applySolution()
217217
{
218-
for(const auto &syncConflict : std::as_const(_conflictData)) {
218+
bool yesToAllRequested = false;
219+
bool isBulkSolution = _conflictData.size() > 1; // no need to display the "Yes for all" button if only one file is affected
220+
221+
for (const auto &syncConflict : std::as_const(_conflictData)) {
219222
if (syncConflict.isValid()) {
220223
qCInfo(lcSyncConflictsModel) << syncConflict.mExistingFilePath << syncConflict.mConflictingFilePath << syncConflict.solution();
221224
ConflictSolver solver;
225+
solver.setIsBulkSolution(isBulkSolution);
226+
solver.setYesToAllRequested(yesToAllRequested);
222227
solver.setLocalVersionFilename(syncConflict.mConflictingFilePath);
223228
solver.setRemoteVersionFilename(syncConflict.mExistingFilePath);
224229
solver.exec(syncConflict.solution());
230+
yesToAllRequested = solver.yesToAllRequested();
225231
}
226232
}
227233
}

0 commit comments

Comments
 (0)