forked from qt-creator/qt-creator
ProjectExplorer: Use one function for done() in application launcher
This only shifts the 'if' down one level. Change-Id: I2c049d9a38d786698c728e88d15b0129eba35aed Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -75,16 +75,15 @@ public:
|
|||||||
|
|
||||||
void handleStandardOutput();
|
void handleStandardOutput();
|
||||||
void handleStandardError();
|
void handleStandardError();
|
||||||
|
void handleDone();
|
||||||
|
|
||||||
// Local
|
// Local
|
||||||
void handleLocalDone();
|
|
||||||
void cannotRetrieveLocalDebugOutput();
|
void cannotRetrieveLocalDebugOutput();
|
||||||
void checkLocalDebugOutput(qint64 pid, const QString &message);
|
void checkLocalDebugOutput(qint64 pid, const QString &message);
|
||||||
qint64 applicationPID() const;
|
qint64 applicationPID() const;
|
||||||
bool isRunning() const;
|
bool isRunning() const;
|
||||||
|
|
||||||
// Remote
|
// Remote
|
||||||
void handleRemoteDone();
|
|
||||||
void doReportError(const QString &message,
|
void doReportError(const QString &message,
|
||||||
QProcess::ProcessError error = QProcess::FailedToStart);
|
QProcess::ProcessError error = QProcess::FailedToStart);
|
||||||
void setFinished();
|
void setFinished();
|
||||||
@@ -240,44 +239,57 @@ QProcess::ProcessError ApplicationLauncher::error() const
|
|||||||
return d->m_remoteError;
|
return d->m_remoteError;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApplicationLauncherPrivate::handleLocalDone()
|
void ApplicationLauncherPrivate::handleDone()
|
||||||
{
|
{
|
||||||
const QProcess::ProcessError error = m_process->error();
|
const QProcess::ProcessError error = m_process->error();
|
||||||
if (error == QProcess::UnknownError) {
|
|
||||||
m_exitCode = m_process->exitCode();
|
if (m_isLocal) {
|
||||||
m_exitStatus = m_process->exitStatus();
|
if (error == QProcess::UnknownError) {
|
||||||
emit q->finished();
|
m_exitCode = m_process->exitCode();
|
||||||
return;
|
m_exitStatus = m_process->exitStatus();
|
||||||
}
|
|
||||||
// TODO: why below handlings are different?
|
|
||||||
if (m_useTerminal) {
|
|
||||||
emit q->appendMessage(m_process->errorString(), ErrorMessageFormat);
|
|
||||||
if (m_processRunning && m_process->processId() == 0) {
|
|
||||||
m_processRunning = false;
|
|
||||||
m_exitCode = -1;
|
|
||||||
emit q->finished();
|
emit q->finished();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
// TODO: why below handlings are different?
|
||||||
|
if (m_useTerminal) {
|
||||||
|
emit q->appendMessage(m_process->errorString(), ErrorMessageFormat);
|
||||||
|
if (m_processRunning && m_process->processId() == 0) {
|
||||||
|
m_processRunning = false;
|
||||||
|
m_exitCode = -1;
|
||||||
|
emit q->finished();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
QString errorString;
|
||||||
|
switch (error) {
|
||||||
|
case QProcess::FailedToStart:
|
||||||
|
errorString = ApplicationLauncher::tr("Failed to start program. Path or permissions wrong?");
|
||||||
|
break;
|
||||||
|
case QProcess::Crashed:
|
||||||
|
m_exitStatus = QProcess::CrashExit;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
errorString = ApplicationLauncher::tr("Some error has occurred while running the program.");
|
||||||
|
}
|
||||||
|
if (!errorString.isEmpty())
|
||||||
|
emit q->appendMessage(errorString, ErrorMessageFormat);
|
||||||
|
if (m_processRunning && !isRunning()) {
|
||||||
|
m_processRunning = false;
|
||||||
|
m_exitCode = -1;
|
||||||
|
emit q->finished();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
emit q->errorOccurred(error);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
QString errorString;
|
QTC_ASSERT(m_state == Run, return);
|
||||||
switch (m_process->error()) {
|
if (error == QProcess::FailedToStart) {
|
||||||
case QProcess::FailedToStart:
|
doReportError(ApplicationLauncher::tr("Application failed to start: %1")
|
||||||
errorString = ApplicationLauncher::tr("Failed to start program. Path or permissions wrong?");
|
.arg(m_process->errorString()));
|
||||||
break;
|
} else if (m_process->exitStatus() == QProcess::CrashExit) {
|
||||||
case QProcess::Crashed:
|
doReportError(m_process->errorString(), QProcess::Crashed);
|
||||||
m_exitStatus = QProcess::CrashExit;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
errorString = ApplicationLauncher::tr("Some error has occurred while running the program.");
|
|
||||||
}
|
|
||||||
if (!errorString.isEmpty())
|
|
||||||
emit q->appendMessage(errorString, ErrorMessageFormat);
|
|
||||||
if (m_processRunning && !isRunning()) {
|
|
||||||
m_processRunning = false;
|
|
||||||
m_exitCode = -1;
|
|
||||||
emit q->finished();
|
|
||||||
}
|
}
|
||||||
|
setFinished();
|
||||||
}
|
}
|
||||||
emit q->errorOccurred(error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApplicationLauncherPrivate::handleStandardOutput()
|
void ApplicationLauncherPrivate::handleStandardOutput()
|
||||||
@@ -336,9 +348,6 @@ void ApplicationLauncherPrivate::start()
|
|||||||
if (m_isLocal) {
|
if (m_isLocal) {
|
||||||
m_process.reset(new QtcProcess(this));
|
m_process.reset(new QtcProcess(this));
|
||||||
|
|
||||||
connect(m_process.get(), &QtcProcess::done,
|
|
||||||
this, &ApplicationLauncherPrivate::handleLocalDone);
|
|
||||||
|
|
||||||
// Work around QTBUG-17529 (QtDeclarative fails with 'File name case mismatch' ...)
|
// Work around QTBUG-17529 (QtDeclarative fails with 'File name case mismatch' ...)
|
||||||
const FilePath fixedPath = m_runnable.workingDirectory.normalizedPathName();
|
const FilePath fixedPath = m_runnable.workingDirectory.normalizedPathName();
|
||||||
m_process->setWorkingDirectory(fixedPath);
|
m_process->setWorkingDirectory(fixedPath);
|
||||||
@@ -390,8 +399,6 @@ void ApplicationLauncherPrivate::start()
|
|||||||
m_stopRequested = false;
|
m_stopRequested = false;
|
||||||
|
|
||||||
m_process.reset(m_runnable.device->createProcess(this));
|
m_process.reset(m_runnable.device->createProcess(this));
|
||||||
connect(m_process.get(), &QtcProcess::done,
|
|
||||||
this, &ApplicationLauncherPrivate::handleRemoteDone);
|
|
||||||
m_process->setCommand(m_runnable.command);
|
m_process->setCommand(m_runnable.command);
|
||||||
m_process->setWorkingDirectory(m_runnable.workingDirectory);
|
m_process->setWorkingDirectory(m_runnable.workingDirectory);
|
||||||
m_process->setRemoteEnvironment(m_runnable.environment);
|
m_process->setRemoteEnvironment(m_runnable.environment);
|
||||||
@@ -404,6 +411,7 @@ void ApplicationLauncherPrivate::start()
|
|||||||
m_outputCodec = QTextCodec::codecForName("utf8");
|
m_outputCodec = QTextCodec::codecForName("utf8");
|
||||||
|
|
||||||
connect(m_process.get(), &QtcProcess::started, q, &ApplicationLauncher::started);
|
connect(m_process.get(), &QtcProcess::started, q, &ApplicationLauncher::started);
|
||||||
|
connect(m_process.get(), &QtcProcess::done, this, &ApplicationLauncherPrivate::handleDone);
|
||||||
|
|
||||||
m_process->setProcessChannelMode(m_processChannelMode);
|
m_process->setProcessChannelMode(m_processChannelMode);
|
||||||
if (m_processChannelMode == QProcess::SeparateChannels) {
|
if (m_processChannelMode == QProcess::SeparateChannels) {
|
||||||
@@ -430,18 +438,6 @@ void ApplicationLauncherPrivate::setFinished()
|
|||||||
emit q->finished();
|
emit q->finished();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApplicationLauncherPrivate::handleRemoteDone()
|
|
||||||
{
|
|
||||||
QTC_ASSERT(m_state == Run, return);
|
|
||||||
if (m_process->error() == QProcess::FailedToStart) {
|
|
||||||
doReportError(ApplicationLauncher::tr("Application failed to start: %1")
|
|
||||||
.arg(m_process->errorString()));
|
|
||||||
} else if (m_process->exitStatus() == QProcess::CrashExit) {
|
|
||||||
doReportError(m_process->errorString(), QProcess::Crashed);
|
|
||||||
}
|
|
||||||
setFinished();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ApplicationLauncherPrivate::doReportError(const QString &message, QProcess::ProcessError error)
|
void ApplicationLauncherPrivate::doReportError(const QString &message, QProcess::ProcessError error)
|
||||||
{
|
{
|
||||||
m_remoteErrorString = message;
|
m_remoteErrorString = message;
|
||||||
|
Reference in New Issue
Block a user