Handle QProcess::errorOccurred
This commit is contained in:
parent
4c760a2c08
commit
61716687c9
|
@ -20,6 +20,7 @@ SyncthingLauncher::SyncthingLauncher(QObject *parent)
|
||||||
connect(&m_process, &SyncthingProcess::readyRead, this, &SyncthingLauncher::handleProcessReadyRead);
|
connect(&m_process, &SyncthingProcess::readyRead, this, &SyncthingLauncher::handleProcessReadyRead);
|
||||||
connect(&m_process, static_cast<void (SyncthingProcess::*)(int exitCode, QProcess::ExitStatus exitStatus)>(&SyncthingProcess::finished), this,
|
connect(&m_process, static_cast<void (SyncthingProcess::*)(int exitCode, QProcess::ExitStatus exitStatus)>(&SyncthingProcess::finished), this,
|
||||||
&SyncthingLauncher::handleProcessFinished);
|
&SyncthingLauncher::handleProcessFinished);
|
||||||
|
connect(&m_process, &SyncthingProcess::errorOccurred, this, &SyncthingLauncher::errorOccurred);
|
||||||
connect(&m_process, &SyncthingProcess::confirmKill, this, &SyncthingLauncher::confirmKill);
|
connect(&m_process, &SyncthingProcess::confirmKill, this, &SyncthingLauncher::confirmKill);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@ Q_SIGNALS:
|
||||||
void runningChanged(bool isRunning);
|
void runningChanged(bool isRunning);
|
||||||
void outputAvailable(const QByteArray &data);
|
void outputAvailable(const QByteArray &data);
|
||||||
void exited(int exitCode, QProcess::ExitStatus exitStatus);
|
void exited(int exitCode, QProcess::ExitStatus exitStatus);
|
||||||
|
void errorOccurred(QProcess::ProcessError error);
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void setUseLibSyncthing(bool useLibSyncthing);
|
void setUseLibSyncthing(bool useLibSyncthing);
|
||||||
|
|
|
@ -51,6 +51,7 @@
|
||||||
#include <QFontDatabase>
|
#include <QFontDatabase>
|
||||||
#include <QStringBuilder>
|
#include <QStringBuilder>
|
||||||
#include <QStyle>
|
#include <QStyle>
|
||||||
|
#include <QTextBlock>
|
||||||
#include <QTextCursor>
|
#include <QTextCursor>
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
@ -793,10 +794,13 @@ QWidget *LauncherOptionPage::setupWidget()
|
||||||
m_connections << connect(m_process,
|
m_connections << connect(m_process,
|
||||||
static_cast<void (SyncthingProcess::*)(int exitCode, QProcess::ExitStatus exitStatus)>(&SyncthingProcess::finished), this,
|
static_cast<void (SyncthingProcess::*)(int exitCode, QProcess::ExitStatus exitStatus)>(&SyncthingProcess::finished), this,
|
||||||
&LauncherOptionPage::handleSyncthingExited, Qt::QueuedConnection);
|
&LauncherOptionPage::handleSyncthingExited, Qt::QueuedConnection);
|
||||||
|
m_connections << connect(m_process, &SyncthingProcess::errorOccurred, this, &LauncherOptionPage::handleSyncthingError, Qt::QueuedConnection);
|
||||||
} else if (m_launcher) {
|
} else if (m_launcher) {
|
||||||
m_connections << connect(
|
m_connections << connect(
|
||||||
m_launcher, &SyncthingLauncher::outputAvailable, this, &LauncherOptionPage::handleSyncthingOutputAvailable, Qt::QueuedConnection);
|
m_launcher, &SyncthingLauncher::outputAvailable, this, &LauncherOptionPage::handleSyncthingOutputAvailable, Qt::QueuedConnection);
|
||||||
m_connections << connect(m_launcher, &SyncthingLauncher::exited, this, &LauncherOptionPage::handleSyncthingExited, Qt::QueuedConnection);
|
m_connections << connect(m_launcher, &SyncthingLauncher::exited, this, &LauncherOptionPage::handleSyncthingExited, Qt::QueuedConnection);
|
||||||
|
m_connections << connect(
|
||||||
|
m_launcher, &SyncthingLauncher::errorOccurred, this, &LauncherOptionPage::handleSyncthingError, Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
QObject::connect(ui()->launchNowPushButton, &QPushButton::clicked, this, &LauncherOptionPage::launch);
|
QObject::connect(ui()->launchNowPushButton, &QPushButton::clicked, this, &LauncherOptionPage::launch);
|
||||||
QObject::connect(ui()->stopPushButton, &QPushButton::clicked, this, &LauncherOptionPage::stop);
|
QObject::connect(ui()->stopPushButton, &QPushButton::clicked, this, &LauncherOptionPage::stop);
|
||||||
|
@ -856,6 +860,7 @@ void LauncherOptionPage::handleSyncthingOutputAvailable(const QByteArray &output
|
||||||
cursor.movePosition(QTextCursor::End);
|
cursor.movePosition(QTextCursor::End);
|
||||||
cursor.insertText(QString::fromUtf8(output));
|
cursor.insertText(QString::fromUtf8(output));
|
||||||
if (ui()->ensureCursorVisibleCheckBox->isChecked()) {
|
if (ui()->ensureCursorVisibleCheckBox->isChecked()) {
|
||||||
|
ui()->logTextEdit->moveCursor(QTextCursor::End);
|
||||||
ui()->logTextEdit->ensureCursorVisible();
|
ui()->logTextEdit->ensureCursorVisible();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -865,25 +870,73 @@ void LauncherOptionPage::handleSyncthingExited(int exitCode, QProcess::ExitStatu
|
||||||
if (!hasBeenShown()) {
|
if (!hasBeenShown()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QTextCursor cursor(ui()->logTextEdit->textCursor());
|
QTextCursor cursor(ui()->logTextEdit->textCursor());
|
||||||
cursor.movePosition(QTextCursor::End);
|
cursor.movePosition(QTextCursor::End);
|
||||||
if (cursor.positionInBlock()) {
|
cursor.insertBlock();
|
||||||
cursor.insertBlock();
|
|
||||||
}
|
|
||||||
switch (exitStatus) {
|
switch (exitStatus) {
|
||||||
case QProcess::NormalExit:
|
case QProcess::NormalExit:
|
||||||
cursor.insertText(QCoreApplication::translate("QtGui::LauncherOptionPage", "%1 exited with exit code %2\n")
|
cursor.insertText(QCoreApplication::translate("QtGui::LauncherOptionPage", "%1 exited with exit code %2")
|
||||||
.arg(m_tool.isEmpty() ? QStringLiteral("Syncthing") : m_tool, QString::number(exitCode)));
|
.arg(m_tool.isEmpty() ? QStringLiteral("Syncthing") : m_tool, QString::number(exitCode)));
|
||||||
break;
|
break;
|
||||||
case QProcess::CrashExit:
|
case QProcess::CrashExit:
|
||||||
cursor.insertText(QCoreApplication::translate("QtGui::LauncherOptionPage", "%1 crashed with exit code %2\n")
|
cursor.insertText(QCoreApplication::translate("QtGui::LauncherOptionPage", "%1 crashed with exit code %2")
|
||||||
.arg(m_tool.isEmpty() ? QStringLiteral("Syncthing") : m_tool, QString::number(exitCode)));
|
.arg(m_tool.isEmpty() ? QStringLiteral("Syncthing") : m_tool, QString::number(exitCode)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
cursor.insertBlock();
|
||||||
|
|
||||||
|
if (ui()->ensureCursorVisibleCheckBox->isChecked()) {
|
||||||
|
ui()->logTextEdit->moveCursor(QTextCursor::End);
|
||||||
|
ui()->logTextEdit->ensureCursorVisible();
|
||||||
|
}
|
||||||
|
|
||||||
ui()->stopPushButton->hide();
|
ui()->stopPushButton->hide();
|
||||||
ui()->launchNowPushButton->show();
|
ui()->launchNowPushButton->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LauncherOptionPage::handleSyncthingError(QProcess::ProcessError error)
|
||||||
|
{
|
||||||
|
if (!hasBeenShown()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QTextCursor cursor(ui()->logTextEdit->textCursor());
|
||||||
|
cursor.movePosition(QTextCursor::End);
|
||||||
|
cursor.insertBlock();
|
||||||
|
|
||||||
|
QString errorString;
|
||||||
|
switch (error) {
|
||||||
|
case QProcess::FailedToStart:
|
||||||
|
errorString
|
||||||
|
= QCoreApplication::translate("QtGui::LauncherOptionPage", "failed to start (e.g. executable does not exist or not permission error)");
|
||||||
|
break;
|
||||||
|
case QProcess::Crashed:
|
||||||
|
errorString = QCoreApplication::translate("QtGui::LauncherOptionPage", "process crashed");
|
||||||
|
break;
|
||||||
|
case QProcess::Timedout:
|
||||||
|
errorString = QCoreApplication::translate("QtGui::LauncherOptionPage", "timeout error");
|
||||||
|
break;
|
||||||
|
case QProcess::ReadError:
|
||||||
|
errorString = QCoreApplication::translate("QtGui::LauncherOptionPage", "read error");
|
||||||
|
break;
|
||||||
|
case QProcess::WriteError:
|
||||||
|
errorString = QCoreApplication::translate("QtGui::LauncherOptionPage", "write error");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
errorString = QCoreApplication::translate("QtGui::LauncherOptionPage", "unknown process error");
|
||||||
|
}
|
||||||
|
cursor.insertText(QCoreApplication::translate("QtGui::LauncherOptionPage", "An error occurred when running %1: %2")
|
||||||
|
.arg(m_tool.isEmpty() ? QStringLiteral("Syncthing") : m_tool, errorString));
|
||||||
|
cursor.insertBlock();
|
||||||
|
|
||||||
|
if ((m_launcher && !m_launcher->isRunning()) || (m_process && !m_process->isRunning())) {
|
||||||
|
ui()->stopPushButton->hide();
|
||||||
|
ui()->launchNowPushButton->show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool LauncherOptionPage::isRunning() const
|
bool LauncherOptionPage::isRunning() const
|
||||||
{
|
{
|
||||||
return (m_process && m_process->isRunning()) || (m_launcher && m_launcher->isRunning());
|
return (m_process && m_process->isRunning()) || (m_launcher && m_launcher->isRunning());
|
||||||
|
|
|
@ -109,6 +109,7 @@ private slots:
|
||||||
void handleSyncthingReadyRead();
|
void handleSyncthingReadyRead();
|
||||||
void handleSyncthingOutputAvailable(const QByteArray &output);
|
void handleSyncthingOutputAvailable(const QByteArray &output);
|
||||||
void handleSyncthingExited(int exitCode, QProcess::ExitStatus exitStatus);
|
void handleSyncthingExited(int exitCode, QProcess::ExitStatus exitStatus);
|
||||||
|
void handleSyncthingError(QProcess::ProcessError error);
|
||||||
bool isRunning() const;
|
bool isRunning() const;
|
||||||
void launch();
|
void launch();
|
||||||
void stop();
|
void stop();
|
||||||
|
|
Loading…
Reference in New Issue