Ensure handler of LauncherOptionPage are called in main thread

This commit is contained in:
Martchus 2019-07-07 13:52:07 +02:00
parent 3d5869f8e1
commit 89889c1493
2 changed files with 41 additions and 30 deletions

View File

@ -728,7 +728,8 @@ void AutostartOptionPage::reset()
// LauncherOptionPage // LauncherOptionPage
LauncherOptionPage::LauncherOptionPage(QWidget *parentWidget) LauncherOptionPage::LauncherOptionPage(QWidget *parentWidget)
: LauncherOptionPageBase(parentWidget) : QObject(parentWidget)
, LauncherOptionPageBase(parentWidget)
, m_process(nullptr) , m_process(nullptr)
, m_launcher(SyncthingLauncher::mainInstance()) , m_launcher(SyncthingLauncher::mainInstance())
, m_kill(false) , m_kill(false)
@ -736,7 +737,8 @@ LauncherOptionPage::LauncherOptionPage(QWidget *parentWidget)
} }
LauncherOptionPage::LauncherOptionPage(const QString &tool, QWidget *parentWidget) LauncherOptionPage::LauncherOptionPage(const QString &tool, QWidget *parentWidget)
: LauncherOptionPageBase(parentWidget) : QObject(parentWidget)
, LauncherOptionPageBase(parentWidget)
, m_process(&Launcher::toolProcess(tool)) , m_process(&Launcher::toolProcess(tool))
, m_launcher(nullptr) , m_launcher(nullptr)
, m_restoreArgsButton(nullptr) , m_restoreArgsButton(nullptr)
@ -773,7 +775,7 @@ QWidget *LauncherOptionPage::setupWidget()
m_restoreArgsButton->setPixmap( m_restoreArgsButton->setPixmap(
QIcon::fromTheme(QStringLiteral("edit-undo"), QIcon(QStringLiteral(":/icons/hicolor/scalable/actions/edit-paste.svg"))).pixmap(16)); 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")); 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); ui()->argumentsLineEdit->insertCustomButton(0, m_restoreArgsButton);
} }
@ -787,17 +789,17 @@ QWidget *LauncherOptionPage::setupWidget()
// connect signals & slots // connect signals & slots
if (m_process) { if (m_process) {
m_connections << QObject::connect(m_process, &SyncthingProcess::readyRead, bind(&LauncherOptionPage::handleSyncthingReadyRead, this)); m_connections << connect(m_process, &SyncthingProcess::readyRead, this, &LauncherOptionPage::handleSyncthingReadyRead, Qt::QueuedConnection);
m_connections << QObject::connect(m_process, m_connections << connect(m_process,
static_cast<void (SyncthingProcess::*)(int exitCode, QProcess::ExitStatus exitStatus)>(&SyncthingProcess::finished), static_cast<void (SyncthingProcess::*)(int exitCode, QProcess::ExitStatus exitStatus)>(&SyncthingProcess::finished), this,
bind(&LauncherOptionPage::handleSyncthingExited, this, _1, _2)); &LauncherOptionPage::handleSyncthingExited, Qt::QueuedConnection);
} else if (m_launcher) { } else if (m_launcher) {
m_connections << QObject::connect(m_launcher, &SyncthingLauncher::outputAvailable, ui()->logTextEdit, m_connections << connect(
bind(&LauncherOptionPage::handleSyncthingOutputAvailable, this, _1), Qt::QueuedConnection); m_launcher, &SyncthingLauncher::outputAvailable, this, &LauncherOptionPage::handleSyncthingOutputAvailable, Qt::QueuedConnection);
m_connections << QObject::connect(m_launcher, &SyncthingLauncher::exited, bind(&LauncherOptionPage::handleSyncthingExited, this, _1, _2)); 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()->launchNowPushButton, &QPushButton::clicked, this, &LauncherOptionPage::launch);
QObject::connect(ui()->stopPushButton, &QPushButton::clicked, bind(&LauncherOptionPage::stop, this)); QObject::connect(ui()->stopPushButton, &QPushButton::clicked, this, &LauncherOptionPage::stop);
return widget; return widget;
} }

View File

@ -94,27 +94,36 @@ END_DECLARE_OPTION_PAGE
DECLARE_UI_FILE_BASED_OPTION_PAGE_CUSTOM_SETUP(AutostartOptionPage) 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<Ui::LauncherOptionPage> {
Q_OBJECT
public: public:
LauncherOptionPage(QWidget *parentWidget = nullptr); LauncherOptionPage(QWidget *parentWidget = nullptr);
LauncherOptionPage(const QString &tool, 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: private:
DECLARE_SETUP_WIDGETS DECLARE_SETUP_WIDGETS
void handleSyncthingReadyRead();
void handleSyncthingOutputAvailable(const QByteArray &output); Data::SyncthingProcess *const m_process;
void handleSyncthingExited(int exitCode, QProcess::ExitStatus exitStatus); Data::SyncthingLauncher *const m_launcher;
bool isRunning() const; QtUtilities::IconButton *m_restoreArgsButton;
void launch(); QList<QMetaObject::Connection> m_connections;
void stop(); bool m_kill;
void restoreDefaultArguments(); QString m_tool;
Data::SyncthingProcess *const m_process; };
Data::SyncthingLauncher *const m_launcher;
QtUtilities::IconButton *m_restoreArgsButton;
QList<QMetaObject::Connection> m_connections;
bool m_kill;
QString m_tool;
END_DECLARE_OPTION_PAGE
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD #ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE(SystemdOptionPage) BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE(SystemdOptionPage)