From 89889c1493c139ea69c1549463f140632ae21d94 Mon Sep 17 00:00:00 2001 From: Martchus Date: Sun, 7 Jul 2019 13:52:07 +0200 Subject: [PATCH] Ensure handler of LauncherOptionPage are called in main thread --- widgets/settings/settingsdialog.cpp | 26 +++++++++-------- widgets/settings/settingsdialog.h | 45 +++++++++++++++++------------ 2 files changed, 41 insertions(+), 30 deletions(-) diff --git a/widgets/settings/settingsdialog.cpp b/widgets/settings/settingsdialog.cpp index 7f46a63..62e6a72 100644 --- a/widgets/settings/settingsdialog.cpp +++ b/widgets/settings/settingsdialog.cpp @@ -728,7 +728,8 @@ void AutostartOptionPage::reset() // LauncherOptionPage LauncherOptionPage::LauncherOptionPage(QWidget *parentWidget) - : LauncherOptionPageBase(parentWidget) + : QObject(parentWidget) + , LauncherOptionPageBase(parentWidget) , m_process(nullptr) , m_launcher(SyncthingLauncher::mainInstance()) , m_kill(false) @@ -736,7 +737,8 @@ LauncherOptionPage::LauncherOptionPage(QWidget *parentWidget) } LauncherOptionPage::LauncherOptionPage(const QString &tool, QWidget *parentWidget) - : LauncherOptionPageBase(parentWidget) + : QObject(parentWidget) + , LauncherOptionPageBase(parentWidget) , m_process(&Launcher::toolProcess(tool)) , m_launcher(nullptr) , m_restoreArgsButton(nullptr) @@ -773,7 +775,7 @@ QWidget *LauncherOptionPage::setupWidget() m_restoreArgsButton->setPixmap( QIcon::fromTheme(QStringLiteral("edit-undo"), QIcon(QStringLiteral(":/icons/hicolor/scalable/actions/edit-paste.svg"))).pixmap(16)); m_restoreArgsButton->setToolTip(QCoreApplication::translate("QtGui::LauncherOptionPage", "Restore default")); - QObject::connect(m_restoreArgsButton, &IconButton::clicked, bind(&LauncherOptionPage::restoreDefaultArguments, this)); + QObject::connect(m_restoreArgsButton, &IconButton::clicked, this, &LauncherOptionPage::restoreDefaultArguments); ui()->argumentsLineEdit->insertCustomButton(0, m_restoreArgsButton); } @@ -787,17 +789,17 @@ QWidget *LauncherOptionPage::setupWidget() // connect signals & slots if (m_process) { - m_connections << QObject::connect(m_process, &SyncthingProcess::readyRead, bind(&LauncherOptionPage::handleSyncthingReadyRead, this)); - m_connections << QObject::connect(m_process, - static_cast(&SyncthingProcess::finished), - bind(&LauncherOptionPage::handleSyncthingExited, this, _1, _2)); + m_connections << connect(m_process, &SyncthingProcess::readyRead, this, &LauncherOptionPage::handleSyncthingReadyRead, Qt::QueuedConnection); + m_connections << connect(m_process, + static_cast(&SyncthingProcess::finished), this, + &LauncherOptionPage::handleSyncthingExited, Qt::QueuedConnection); } else if (m_launcher) { - m_connections << QObject::connect(m_launcher, &SyncthingLauncher::outputAvailable, ui()->logTextEdit, - bind(&LauncherOptionPage::handleSyncthingOutputAvailable, this, _1), Qt::QueuedConnection); - m_connections << QObject::connect(m_launcher, &SyncthingLauncher::exited, bind(&LauncherOptionPage::handleSyncthingExited, this, _1, _2)); + m_connections << connect( + m_launcher, &SyncthingLauncher::outputAvailable, this, &LauncherOptionPage::handleSyncthingOutputAvailable, Qt::QueuedConnection); + m_connections << connect(m_launcher, &SyncthingLauncher::exited, this, &LauncherOptionPage::handleSyncthingExited, Qt::QueuedConnection); } - QObject::connect(ui()->launchNowPushButton, &QPushButton::clicked, bind(&LauncherOptionPage::launch, this)); - QObject::connect(ui()->stopPushButton, &QPushButton::clicked, bind(&LauncherOptionPage::stop, this)); + QObject::connect(ui()->launchNowPushButton, &QPushButton::clicked, this, &LauncherOptionPage::launch); + QObject::connect(ui()->stopPushButton, &QPushButton::clicked, this, &LauncherOptionPage::stop); return widget; } diff --git a/widgets/settings/settingsdialog.h b/widgets/settings/settingsdialog.h index c2e1275..3ec6687 100644 --- a/widgets/settings/settingsdialog.h +++ b/widgets/settings/settingsdialog.h @@ -94,27 +94,36 @@ END_DECLARE_OPTION_PAGE DECLARE_UI_FILE_BASED_OPTION_PAGE_CUSTOM_SETUP(AutostartOptionPage) -BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE_CUSTOM_CTOR(LauncherOptionPage) +BEGIN_DECLARE_TYPEDEF_UI_FILE_BASED_OPTION_PAGE(LauncherOptionPage) +class QT_UTILITIES_EXPORT LauncherOptionPage : public QObject, public ::QtUtilities::UiFileBasedOptionPage { + Q_OBJECT + public: -LauncherOptionPage(QWidget *parentWidget = nullptr); -LauncherOptionPage(const QString &tool, QWidget *parentWidget = nullptr); + LauncherOptionPage(QWidget *parentWidget = nullptr); + LauncherOptionPage(const QString &tool, QWidget *parentWidget = nullptr); + ~LauncherOptionPage() override; + bool apply() override; + void reset() override; + +private slots: + void handleSyncthingReadyRead(); + void handleSyncthingOutputAvailable(const QByteArray &output); + void handleSyncthingExited(int exitCode, QProcess::ExitStatus exitStatus); + bool isRunning() const; + void launch(); + void stop(); + void restoreDefaultArguments(); private: -DECLARE_SETUP_WIDGETS -void handleSyncthingReadyRead(); -void handleSyncthingOutputAvailable(const QByteArray &output); -void handleSyncthingExited(int exitCode, QProcess::ExitStatus exitStatus); -bool isRunning() const; -void launch(); -void stop(); -void restoreDefaultArguments(); -Data::SyncthingProcess *const m_process; -Data::SyncthingLauncher *const m_launcher; -QtUtilities::IconButton *m_restoreArgsButton; -QList m_connections; -bool m_kill; -QString m_tool; -END_DECLARE_OPTION_PAGE + DECLARE_SETUP_WIDGETS + + Data::SyncthingProcess *const m_process; + Data::SyncthingLauncher *const m_launcher; + QtUtilities::IconButton *m_restoreArgsButton; + QList m_connections; + bool m_kill; + QString m_tool; +}; #ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE(SystemdOptionPage)