From fa87b899fb0de58513b2b18646018e8ddd8cd5be Mon Sep 17 00:00:00 2001 From: Hannah von Reth Date: Tue, 26 May 2020 11:51:35 +0200 Subject: [PATCH] Fix usage of QMessageBox Fixes: #7874 --- src/gui/accountsettings.cpp | 6 +++--- src/gui/generalsettings.cpp | 6 +++--- src/gui/wizard/owncloudwizard.cpp | 13 +++++-------- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index 8501ad347..6839c9b48 100644 --- a/src/gui/accountsettings.cpp +++ b/src/gui/accountsettings.cpp @@ -731,11 +731,11 @@ void AccountSettings::slotDisableVfsCurrentFolder() "will become available again." "\n\n" "This action will abort any currently running synchronization.")); - msgBox->addButton(tr("Disable support"), QMessageBox::AcceptRole); + auto acceptButton = msgBox->addButton(tr("Disable support"), QMessageBox::AcceptRole); msgBox->addButton(tr("Cancel"), QMessageBox::RejectRole); - connect(msgBox, &QMessageBox::finished, msgBox, [this, msgBox, folder](int result) { + connect(msgBox, &QMessageBox::finished, msgBox, [this, msgBox, folder, acceptButton] { msgBox->deleteLater(); - if (result != QMessageBox::AcceptRole || !folder) + if (msgBox->clickedButton() == acceptButton|| !folder) return; // It is unsafe to switch off vfs while a sync is running - wait if necessary. diff --git a/src/gui/generalsettings.cpp b/src/gui/generalsettings.cpp index bb98f1db1..f164a1936 100644 --- a/src/gui/generalsettings.cpp +++ b/src/gui/generalsettings.cpp @@ -320,11 +320,11 @@ void GeneralSettings::slotUpdateChannelChanged(const QString &channel) "version."), QMessageBox::NoButton, this); - msgBox->addButton(tr("Change update channel"), QMessageBox::AcceptRole); + auto acceptButton = msgBox->addButton(tr("Change update channel"), QMessageBox::AcceptRole); msgBox->addButton(tr("Cancel"), QMessageBox::RejectRole); - connect(msgBox, &QMessageBox::finished, msgBox, [this, channel, msgBox](int result) { + connect(msgBox, &QMessageBox::finished, msgBox, [this, channel, msgBox, acceptButton] { msgBox->deleteLater(); - if (result == QMessageBox::AcceptRole) { + if (msgBox->clickedButton() == acceptButton) { ConfigFile().setUpdateChannel(channel); if (auto updater = qobject_cast(Updater::instance())) { updater->setUpdateUrl(Updater::updateUrl()); diff --git a/src/gui/wizard/owncloudwizard.cpp b/src/gui/wizard/owncloudwizard.cpp index c5a6119a0..06a88fc74 100644 --- a/src/gui/wizard/owncloudwizard.cpp +++ b/src/gui/wizard/owncloudwizard.cpp @@ -336,6 +336,7 @@ void OwncloudWizard::askExperimentalVirtualFilesFeature(QWidget *receiver, const { const auto bestVfsMode = bestAvailableVfsMode(); QMessageBox *msgBox = nullptr; + QPushButton *acceptButton = nullptr; switch (bestVfsMode) { case Vfs::WindowsCfApi: @@ -350,7 +351,7 @@ void OwncloudWizard::askExperimentalVirtualFilesFeature(QWidget *receiver, const "The virtual files mode is mutually exclusive with selective sync. " "Currently unselected folders will be translated to online-only folders " "and your selective sync settings will be reset."), QMessageBox::NoButton, receiver); - msgBox->addButton(tr("Enable virtual files"), QMessageBox::AcceptRole); + acceptButton = msgBox->addButton(tr("Enable virtual files"), QMessageBox::AcceptRole); msgBox->addButton(tr("Continue to use selective sync"), QMessageBox::RejectRole); break; case Vfs::WithSuffix: @@ -370,19 +371,15 @@ void OwncloudWizard::askExperimentalVirtualFilesFeature(QWidget *receiver, const "This is a new, experimental mode. If you decide to use it, please report any " "issues that come up.") .arg(APPLICATION_DOTVIRTUALFILE_SUFFIX), QMessageBox::NoButton, receiver); - msgBox->addButton(tr("Enable experimental placeholder mode"), QMessageBox::AcceptRole); + acceptButton = msgBox->addButton(tr("Enable experimental placeholder mode"), QMessageBox::AcceptRole); msgBox->addButton(tr("Stay safe"), QMessageBox::RejectRole); break; case Vfs::Off: Q_UNREACHABLE(); } - connect(msgBox, &QMessageBox::accepted, receiver, [callback, msgBox] { - callback(true); - msgBox->deleteLater(); - }); - connect(msgBox, &QMessageBox::reject, receiver, [callback, msgBox]{ - callback(false); + connect(msgBox, &QMessageBox::accepted, receiver, [callback, msgBox, acceptButton] { + callback(msgBox->clickedButton() == acceptButton); msgBox->deleteLater(); }); msgBox->open(); -- 2.30.2