Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when multiple share dialogs were shown #11908

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
erikjv marked this conversation as resolved.
Show resolved Hide resolved
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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should also work if we stack them, so should add another one?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, just 1 sharing dialog for the latest. If a user requested one before but never used it to copy the link, then 🤷, apparently it wasn't important.

}
_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