2018-04-02 23:29:39 +02:00
|
|
|
#include "./syncthingkiller.h"
|
|
|
|
|
2021-01-25 19:48:11 +01:00
|
|
|
#include <syncthingconnector/syncthingprocess.h>
|
2018-04-02 23:29:39 +02:00
|
|
|
#define SYNCTHINGTESTHELPER_FOR_CLI
|
|
|
|
#include "../../testhelper/helper.h"
|
|
|
|
|
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace Data;
|
2019-06-10 22:48:26 +02:00
|
|
|
using namespace CppUtilities;
|
2018-04-02 23:29:39 +02:00
|
|
|
|
|
|
|
namespace QtGui {
|
|
|
|
|
2021-07-15 02:38:26 +02:00
|
|
|
SyncthingKiller::SyncthingKiller(std::vector<ProcessWithConnection> &&processes)
|
2018-04-02 23:29:39 +02:00
|
|
|
: m_processes(processes)
|
|
|
|
{
|
2021-07-15 02:38:26 +02:00
|
|
|
for (const auto [process, connection] : m_processes) {
|
|
|
|
process->stopSyncthing(connection);
|
2018-04-02 23:29:39 +02:00
|
|
|
connect(process, &SyncthingProcess::confirmKill, this, &SyncthingKiller::confirmKill);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SyncthingKiller::waitForFinished()
|
|
|
|
{
|
2021-07-15 02:38:26 +02:00
|
|
|
for (const auto [process, connection] : m_processes) {
|
2018-04-02 23:29:39 +02:00
|
|
|
if (!process->isRunning()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!waitForSignalsOrFail(noop, 0, signalInfo(this, &SyncthingKiller::ignored),
|
2019-06-25 13:49:53 +02:00
|
|
|
signalInfo(process,
|
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0) || QT_DEPRECATED_SINCE(5, 13)
|
2019-07-27 15:07:26 +02:00
|
|
|
static_cast<void (SyncthingProcess::*)(int, QProcess::ExitStatus)>(
|
2019-06-25 13:49:53 +02:00
|
|
|
#endif
|
2019-07-07 12:16:34 +02:00
|
|
|
&SyncthingProcess::finished
|
2019-06-25 13:49:53 +02:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0) || QT_DEPRECATED_SINCE(5, 13)
|
2019-07-07 12:16:34 +02:00
|
|
|
)
|
2019-06-25 13:49:53 +02:00
|
|
|
#endif
|
2019-07-07 12:16:34 +02:00
|
|
|
))) {
|
2018-04-02 23:29:39 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SyncthingKiller::confirmKill() const
|
|
|
|
{
|
|
|
|
auto *const process = static_cast<SyncthingProcess *>(sender());
|
|
|
|
if (!process->isRunning()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto msg(tr("The process %1 (PID: %2) has been requested to terminate but hasn't reacted yet. "
|
|
|
|
"Kill the process?\n\n"
|
|
|
|
"This dialog closes automatically when the process finally terminates.")
|
|
|
|
.arg(process->program(), QString::number(process->processId())));
|
|
|
|
auto *const msgBox = new QMessageBox(QMessageBox::Critical, QCoreApplication::applicationName(), msg);
|
|
|
|
msgBox->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
msgBox->addButton(tr("Keep running"), QMessageBox::RejectRole);
|
|
|
|
msgBox->addButton(tr("Kill process"), QMessageBox::AcceptRole);
|
2019-06-25 13:49:53 +02:00
|
|
|
connect(process,
|
2021-06-09 20:59:09 +02:00
|
|
|
#if !defined(LIB_SYNCTHING_CONNECTOR_BOOST_PROCESS) && (QT_VERSION < QT_VERSION_CHECK(5, 13, 0) || QT_DEPRECATED_SINCE(5, 13))
|
2019-07-27 15:07:26 +02:00
|
|
|
static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(
|
2019-06-25 13:49:53 +02:00
|
|
|
#endif
|
|
|
|
&SyncthingProcess::finished
|
2021-06-09 20:59:09 +02:00
|
|
|
#if !defined(LIB_SYNCTHING_CONNECTOR_BOOST_PROCESS) && (QT_VERSION < QT_VERSION_CHECK(5, 13, 0) || QT_DEPRECATED_SINCE(5, 13))
|
2019-06-25 13:49:53 +02:00
|
|
|
)
|
|
|
|
#endif
|
2019-07-07 12:16:34 +02:00
|
|
|
,
|
|
|
|
msgBox, &QMessageBox::close);
|
2018-04-02 23:29:39 +02:00
|
|
|
connect(msgBox, &QMessageBox::accepted, process, &SyncthingProcess::killSyncthing);
|
|
|
|
// FIXME: can not really ignore, just keep the process running
|
|
|
|
//connect(msgBox, &QMessageBox::rejected, this, &SyncthingKiller::ignored);
|
|
|
|
msgBox->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace QtGui
|