From fd0593cb66eb9d0803f1779771182a716cb2f1b2 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Thu, 26 Sep 2024 14:40:48 +0200 Subject: [PATCH] Fix crash when multiple share dialogs were shown Fixes: #11673 --- src/gui/owncloudgui.cpp | 42 +++++++++++++++-------------------------- src/gui/owncloudgui.h | 4 +--- src/gui/sharedialog.h | 2 ++ 3 files changed, 18 insertions(+), 30 deletions(-) diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp index 17ef8fe62b5..d03baf48388 100644 --- a/src/gui/owncloudgui.cpp +++ b/src/gui/owncloudgui.cpp @@ -1063,34 +1063,22 @@ void ownCloudGui::slotShowShareDialog(const QString &sharePath, const QString &l maxSharingPermissions = SharePermission(0); } - - ShareDialog *w = nullptr; - if (_shareDialogs.contains(localPath) && _shareDialogs[localPath]) { - qCInfo(lcApplication) << "Raising share dialog" << sharePath << localPath; - w = _shareDialogs[localPath]; + if (_shareDialog && _shareDialog->localPath() == localPath) { + qCInfo(lcApplication) << "A share dialog for this path already exists" << sharePath << localPath; + // There might be another modal dialog on top, but that is usually more important (e.g. a login dialog). + raise(); } else { - qCInfo(lcApplication) << "Opening share dialog" << sharePath << localPath << maxSharingPermissions; - w = new ShareDialog(accountState, folder->webDavUrl(), sharePath, localPath, maxSharingPermissions, startPage, settingsDialog()); - w->setAttribute(Qt::WA_DeleteOnClose, true); - - _shareDialogs[localPath] = w; - connect(w, &QObject::destroyed, this, &ownCloudGui::slotRemoveDestroyedShareDialogs); - } - ocApp() - ->gui() - ->settingsDialog() - ->accountSettings(accountState->account().get()) - ->addModalLegacyDialog(w, AccountSettings::ModalWidgetSizePolicy::Expanding); - } -} - -void ownCloudGui::slotRemoveDestroyedShareDialogs() -{ - QMutableMapIterator> it(_shareDialogs); - while (it.hasNext()) { - it.next(); - if (!it.value() || it.value() == sender()) { - it.remove(); + qCInfo(lcApplication) << "Opening new share dialog" << sharePath << localPath << maxSharingPermissions; + if (_shareDialog) { + _shareDialog->close(); + } + _shareDialog = new ShareDialog(accountState, folder->webDavUrl(), sharePath, localPath, maxSharingPermissions, startPage, settingsDialog()); + _shareDialog->setAttribute(Qt::WA_DeleteOnClose, true); + ocApp() + ->gui() + ->settingsDialog() + ->accountSettings(accountState->account().get()) + ->addModalLegacyDialog(_shareDialog, AccountSettings::ModalWidgetSizePolicy::Expanding); } } } diff --git a/src/gui/owncloudgui.h b/src/gui/owncloudgui.h index 7dd7970e848..7e90fa6d62d 100644 --- a/src/gui/owncloudgui.h +++ b/src/gui/owncloudgui.h @@ -110,8 +110,6 @@ public Q_SLOTS: */ void slotShowShareDialog(const QString &sharePath, const QString &localPath, ShareDialogStartPage startPage); - void slotRemoveDestroyedShareDialogs(); - private: void setPauseOnAllFoldersHelper(const QList &accounts, bool pause); void setupActions(); @@ -135,7 +133,7 @@ public Q_SLOTS: bool _workaroundFakeDoubleClick = false; bool _workaroundManualVisibility = false; QTimer _delayedTrayUpdateTimer; - QMap> _shareDialogs; + QPointer _shareDialog; QAction *_actionStatus; diff --git a/src/gui/sharedialog.h b/src/gui/sharedialog.h index 838d6ff1a98..888a2eb1366 100644 --- a/src/gui/sharedialog.h +++ b/src/gui/sharedialog.h @@ -49,6 +49,8 @@ class ShareDialog : public QDialog QWidget *parent); ~ShareDialog() override; + QString localPath() const { return _localPath; } + private Q_SLOTS: void slotPropfindReceived(const QString &, const QMap &result); void slotPropfindError();