Fix usage of QMessageBox
authorHannah von Reth <hannah.vonreth@owncloud.com>
Tue, 26 May 2020 09:51:35 +0000 (11:51 +0200)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:59:12 +0000 (10:59 +0100)
Fixes: #7874
src/gui/accountsettings.cpp
src/gui/generalsettings.cpp
src/gui/wizard/owncloudwizard.cpp

index 8501ad347038a9a8dc936a885383becdab95d79f..6839c9b48550919dbf77db1bb45fe20705f32983 100644 (file)
@@ -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.
index bb98f1db175ebb5c1481fd6818aaa20fe74485ce..f164a19365d30d0a3781cdb6ed1551b5aaac153b 100644 (file)
@@ -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<OCUpdater *>(Updater::instance())) {
                 updater->setUpdateUrl(Updater::updateUrl());
index c5a6119a0f304111a9ec11c603bad8e407a63b1b..06a88fc744da8cd2f0ccc31977b78fd57e393dda 100644 (file)
@@ -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();