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 authored and TheOneRing committed Oct 1, 2024
1 parent 1801822 commit a9dc932
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 30 deletions.
43 changes: 16 additions & 27 deletions src/gui/owncloudgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,7 @@ void ownCloudGui::slotShowShareDialog(const QString &sharePath, const QString &l
Utility::openBrowser(queryUrl, nullptr);
});
} else {
// oC10 code path
const auto accountState = folder->accountState();

SyncJournalFileRecord fileRecord;
Expand All @@ -1063,34 +1064,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
7 changes: 7 additions & 0 deletions src/gui/sharedialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ namespace Ui {
class ShareLinkWidget;
class ShareUserGroupWidget;

/**
* @brief The ShareDialog for oC10.
*
* (OCIS sharing is done by showing the web page.)
*/
class ShareDialog : public QDialog
{
Q_OBJECT
Expand All @@ -49,6 +54,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 a9dc932

Please sign in to comment.