Ensure handler of LauncherOptionPage are called in main thread
This commit is contained in:
parent
3d5869f8e1
commit
89889c1493
|
@ -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<void (SyncthingProcess::*)(int exitCode, QProcess::ExitStatus exitStatus)>(&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<void (SyncthingProcess::*)(int exitCode, QProcess::ExitStatus exitStatus)>(&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;
|
||||
}
|
||||
|
|
|
@ -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<Ui::LauncherOptionPage> {
|
||||
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<QMetaObject::Connection> 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<QMetaObject::Connection> m_connections;
|
||||
bool m_kill;
|
||||
QString m_tool;
|
||||
};
|
||||
|
||||
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
||||
BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE(SystemdOptionPage)
|
||||
|
|
Loading…
Reference in New Issue