Skip to content

Commit

Permalink
Fix multiple remove all files dialog popups
Browse files Browse the repository at this point in the history
Fixes: #11102
  • Loading branch information
TheOneRing committed Sep 1, 2023
1 parent 1239b02 commit 979569f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 16 deletions.
39 changes: 25 additions & 14 deletions src/gui/folder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,12 @@ void Folder::startSync()
Q_ASSERT(_folderWatcher);

if (!OC_ENSURE(!isSyncRunning())) {
qCCritical(lcFolder) << "ERROR csync is still running and new sync requested.";
qCCritical(lcFolder) << "ERROR sync is still running and new sync requested.";
return;
}

if (!OC_ENSURE(canSync())) {
qCCritical(lcFolder) << "ERROR folder is currently not sync able.";
return;
}

Expand Down Expand Up @@ -1243,6 +1248,10 @@ bool Folder::virtualFilesEnabled() const

void Folder::slotAboutToRemoveAllFiles(SyncFileItem::Direction direction)
{
if (_removeAllFilesDialog) {
ocApp()->gui()->raiseDialog(_removeAllFilesDialog);
return;
}
const QString msg = [direction] {
if (direction == SyncFileItem::Down) {
return tr("All files in the sync folder '%1' folder were deleted on the server.\n"
Expand All @@ -1257,16 +1266,16 @@ void Folder::slotAboutToRemoveAllFiles(SyncFileItem::Direction direction)
"If this was an accident and you decide to keep your files, they will be re-synced from the server.");
}
}();
auto msgBox = new QMessageBox(QMessageBox::Warning, tr("Remove All Files?"),
msg.arg(shortGuiLocalPath()), QMessageBox::NoButton, ocApp()->gui()->settingsDialog());
msgBox->setAttribute(Qt::WA_DeleteOnClose);
msgBox->setWindowFlags(msgBox->windowFlags() | Qt::WindowStaysOnTopHint);
msgBox->addButton(tr("Remove all files"), QMessageBox::DestructiveRole);
QPushButton *keepBtn = msgBox->addButton(tr("Keep files"), QMessageBox::AcceptRole);
msgBox->setDefaultButton(keepBtn);
_removeAllFilesDialog =
new QMessageBox(QMessageBox::Warning, tr("Remove All Files?"), msg.arg(shortGuiLocalPath()), QMessageBox::NoButton, ocApp()->gui()->settingsDialog());
_removeAllFilesDialog->setAttribute(Qt::WA_DeleteOnClose);
_removeAllFilesDialog->setWindowFlags(_removeAllFilesDialog->windowFlags() | Qt::WindowStaysOnTopHint);
_removeAllFilesDialog->addButton(tr("Remove all files"), QMessageBox::DestructiveRole);
QPushButton *keepBtn = _removeAllFilesDialog->addButton(tr("Keep files"), QMessageBox::AcceptRole);
_removeAllFilesDialog->setDefaultButton(keepBtn);
setSyncPaused(true);
connect(msgBox, &QMessageBox::finished, this, [msgBox, keepBtn, this] {
if (msgBox->clickedButton() == keepBtn) {
connect(_removeAllFilesDialog, &QMessageBox::finished, this, [keepBtn, this] {
if (_removeAllFilesDialog->clickedButton() == keepBtn) {
// reset the db upload all local files or download all remote files
FileSystem::setFolderMinimumPermissions(path());
// will remove placeholders in the next sync
Expand All @@ -1278,11 +1287,13 @@ void Folder::slotAboutToRemoveAllFiles(SyncFileItem::Direction direction)
_allowRemoveAllOnce = true;
// the only way we end up in here is that the folder was not paused
setSyncPaused(false);
FolderMan::instance()->scheduler()->enqueueFolder(this);
if (canSync()) {
FolderMan::instance()->scheduler()->enqueueFolder(this);
}
});
connect(this, &Folder::destroyed, msgBox, &QMessageBox::deleteLater);
msgBox->open();
ownCloudGui::raiseDialog(msgBox);
connect(this, &Folder::destroyed, _removeAllFilesDialog, &QMessageBox::deleteLater);
_removeAllFilesDialog->open();
ownCloudGui::raiseDialog(_removeAllFilesDialog);
}

FolderDefinition::FolderDefinition(const QByteArray &id, const QUrl &davUrl, const QString &spaceId, const QString &displayName)
Expand Down
2 changes: 2 additions & 0 deletions src/gui/folder.h
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,8 @@ private slots:
*/
QSharedPointer<Vfs> _vfs;

QPointer<QMessageBox> _removeAllFilesDialog;

// allow that all files are removed in the next run
bool _allowRemoveAllOnce = false;

Expand Down
2 changes: 1 addition & 1 deletion src/gui/scheduling/etagwatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void ETagWatcher::updateEtag(Folder *f, const QString &etag)
// https://github.com/owncloud/ocis/issues/7160
if (OC_ENSURE_NOT(etag.isEmpty())) {
auto &info = _lastEtagJob[f];
if (info.etag != etag) {
if (f->canSync() && info.etag != etag) {
info.etag = etag;
_folderMan->scheduler()->enqueueFolder(f);
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/scheduling/syncscheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ void SyncScheduler::startNext()
[this](const SyncResult &result) {
if (result.status() != SyncResult::Success) {
// Retry a couple of times after failure; or regularly if requested
if ((_currentSync->consecutiveFailingSyncs() > 0 && _currentSync->consecutiveFailingSyncs() < 3)
if (_currentSync->canSync() && (_currentSync->consecutiveFailingSyncs() > 0 && _currentSync->consecutiveFailingSyncs() < 3)
|| _currentSync->syncEngine().isAnotherSyncNeeded() == AnotherSyncNeeded::DelayedFollowUp) {
QTimer::singleShot(SyncEngine::minimumFileAgeForUpload, this, [folder = _currentSync, this] { enqueueFolder(folder); });
}
Expand Down

0 comments on commit 979569f

Please sign in to comment.