From e9eeb76578b7024c827e80c7773875feaaf08a97 Mon Sep 17 00:00:00 2001 From: Martchus Date: Mon, 9 Jan 2023 16:01:37 +0100 Subject: [PATCH] Fix displaying QR-code in wizard when built-in launcher is used In this case the connection from the setup detection is not the correct one. The connection used to apply the settings should generally be used for querying the QR-code. --- plasmoid/lib/syncthingapplet.cpp | 2 +- tray/gui/traywidget.cpp | 4 ++-- widgets/settings/wizard.cpp | 9 +++++++-- widgets/settings/wizard.h | 13 ++++++++++++- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/plasmoid/lib/syncthingapplet.cpp b/plasmoid/lib/syncthingapplet.cpp index a7dcad1..be58685 100644 --- a/plasmoid/lib/syncthingapplet.cpp +++ b/plasmoid/lib/syncthingapplet.cpp @@ -388,7 +388,7 @@ void SyncthingApplet::concludeWizard(const QString &errorMessage) } m_applyingSettingsForWizard = false; if (m_wizard) { - m_wizard->handleConfigurationApplied(errorMessage); + m_wizard->handleConfigurationApplied(errorMessage, &m_connection); } } diff --git a/tray/gui/traywidget.cpp b/tray/gui/traywidget.cpp index bc62780..37c58ae 100644 --- a/tray/gui/traywidget.cpp +++ b/tray/gui/traywidget.cpp @@ -297,7 +297,7 @@ void TrayWidget::applySettingsChangesFromWizard() // consider the settings applied instantly if there's no tray widget instance if (s_instances.empty()) { if (s_wizard) { - s_wizard->handleConfigurationApplied(); + s_wizard->handleConfigurationApplied(QString(), &m_connection); } return; } @@ -926,7 +926,7 @@ void TrayWidget::concludeWizard(const QString &errorMessage) } m_applyingSettingsForWizard = false; if (s_wizard) { - s_wizard->handleConfigurationApplied(errorMessage); + s_wizard->handleConfigurationApplied(errorMessage, &m_connection); } } diff --git a/widgets/settings/wizard.cpp b/widgets/settings/wizard.cpp index a7017a0..14573f7 100644 --- a/widgets/settings/wizard.cpp +++ b/widgets/settings/wizard.cpp @@ -394,12 +394,15 @@ QString Wizard::hintAboutSyncthingLog() const return res; } -void Wizard::handleConfigurationApplied(const QString &configError) +void Wizard::handleConfigurationApplied(const QString &configError, Data::SyncthingConnection *connection) { m_configApplied = true; if (m_configError.isEmpty()) { m_configError = configError; } + if ((m_appliedConnection = connection)) { + connect(connection, &Data::SyncthingConnection::destroyed, this, [this] { m_appliedConnection = nullptr; }); + } emit configApplied(); } @@ -1005,7 +1008,9 @@ void QtGui::FinalWizardPage::showResults() "Syncthing to pair remote devices and add folders for sharing. If you need further help, read the " "documentation to get started.

" "

To initiate the pairing from another device, the device ID of this Syncthing device is displayed below.

")); - m_layout->addWidget(m_ownDeviceIdWidget = ownDeviceIdWidget(wizard->setupDetection().connection, 256)); + if (wizard->appliedConnection()) { + m_layout->addWidget(m_ownDeviceIdWidget = ownDeviceIdWidget(*(wizard->appliedConnection()), 256)); + } } else { setSubTitle(tr("Not all changes could be applied")); m_label->setText( diff --git a/widgets/settings/wizard.h b/widgets/settings/wizard.h index b65fa07..4db535a 100644 --- a/widgets/settings/wizard.h +++ b/widgets/settings/wizard.h @@ -14,6 +14,10 @@ QT_FORWARD_DECLARE_CLASS(QLabel) QT_FORWARD_DECLARE_CLASS(QProgressBar) QT_FORWARD_DECLARE_CLASS(QVBoxLayout) +namespace Data { +class SyncthingConnection; +} + namespace QtGui { class SetupDetection; @@ -54,10 +58,11 @@ public: bool autoStart() const; bool isConfigApplied() const; const QString &configError() const; + Data::SyncthingConnection *appliedConnection(); public Q_SLOTS: bool changeSettings(); - void handleConfigurationApplied(const QString &configError = QString()); + void handleConfigurationApplied(const QString &configError = QString(), Data::SyncthingConnection *connection = nullptr); Q_SIGNALS: void settingsDialogRequested(); @@ -82,6 +87,7 @@ private: bool m_autoStart = false; bool m_configApplied = false; QString m_configError; + Data::SyncthingConnection *m_appliedConnection = nullptr; int m_elapsedPollTime; }; @@ -115,6 +121,11 @@ inline const QString &Wizard::configError() const return m_configError; } +inline Data::SyncthingConnection *Wizard::appliedConnection() +{ + return m_appliedConnection; +} + class SYNCTHINGWIDGETS_EXPORT WelcomeWizardPage final : public QWizardPage { Q_OBJECT