Skip to content

Commit

Permalink
Fix crash when multiple share dialogs were shown
Browse files Browse the repository at this point in the history
Fixes: #11673
  • Loading branch information
erikjv committed Sep 27, 2024
1 parent c41e9de commit fd0593c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 30 deletions.
42 changes: 15 additions & 27 deletions src/gui/owncloudgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QString, QPointer<ShareDialog>> 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);
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/gui/owncloudgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ public Q_SLOTS:
*/
void slotShowShareDialog(const QString &sharePath, const QString &localPath, ShareDialogStartPage startPage);

void slotRemoveDestroyedShareDialogs();

private:
void setPauseOnAllFoldersHelper(const QList<AccountStatePtr> &accounts, bool pause);
void setupActions();
Expand All @@ -135,7 +133,7 @@ public Q_SLOTS:
bool _workaroundFakeDoubleClick = false;
bool _workaroundManualVisibility = false;
QTimer _delayedTrayUpdateTimer;
QMap<QString, QPointer<ShareDialog>> _shareDialogs;
QPointer<ShareDialog> _shareDialog;

QAction *_actionStatus;

Expand Down
2 changes: 2 additions & 0 deletions src/gui/sharedialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<QString, QString> &result);
void slotPropfindError();
Expand Down

0 comments on commit fd0593c

Please sign in to comment.