forked from qt-creator/qt-creator
ConsoleProcess: Uniform the common interface of QtcProcess
This is a preliminary step before merging ConsoleProcess into QtcProcess. Don't return bool from start(), all callers ignored it. Rename stop() to stopProcess(). Change-Id: I2fda1337e6f490685669fbd7ad6987a97866fdbe Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -181,7 +181,7 @@ ConsoleProcess::ConsoleProcess(QObject *parent) :
|
|||||||
|
|
||||||
ConsoleProcess::~ConsoleProcess()
|
ConsoleProcess::~ConsoleProcess()
|
||||||
{
|
{
|
||||||
stop();
|
stopProcess();
|
||||||
delete d;
|
delete d;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -430,10 +430,10 @@ qint64 ConsoleProcess::applicationMainThreadID() const
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConsoleProcess::start()
|
void ConsoleProcess::start()
|
||||||
{
|
{
|
||||||
if (isRunning())
|
if (isRunning())
|
||||||
return false;
|
return;
|
||||||
|
|
||||||
d->m_errorString.clear();
|
d->m_errorString.clear();
|
||||||
d->m_error = QProcess::UnknownError;
|
d->m_error = QProcess::UnknownError;
|
||||||
@@ -455,7 +455,7 @@ bool ConsoleProcess::start()
|
|||||||
const QString err = stubServerListen();
|
const QString err = stubServerListen();
|
||||||
if (!err.isEmpty()) {
|
if (!err.isEmpty()) {
|
||||||
emitError(QProcess::FailedToStart, msgCommChannelFailed(err));
|
emitError(QProcess::FailedToStart, msgCommChannelFailed(err));
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList env = d->m_environment.toStringList();
|
QStringList env = d->m_environment.toStringList();
|
||||||
@@ -463,7 +463,7 @@ bool ConsoleProcess::start()
|
|||||||
d->m_tempFile = new QTemporaryFile();
|
d->m_tempFile = new QTemporaryFile();
|
||||||
if (!d->m_tempFile->open()) {
|
if (!d->m_tempFile->open()) {
|
||||||
cleanupAfterStartFailure(msgCannotCreateTempFile(d->m_tempFile->errorString()));
|
cleanupAfterStartFailure(msgCannotCreateTempFile(d->m_tempFile->errorString()));
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
QString outString;
|
QString outString;
|
||||||
QTextStream out(&outString);
|
QTextStream out(&outString);
|
||||||
@@ -493,7 +493,7 @@ bool ConsoleProcess::start()
|
|||||||
const QByteArray outBytes = textCodec ? textCodec->fromUnicode(outString) : QByteArray();
|
const QByteArray outBytes = textCodec ? textCodec->fromUnicode(outString) : QByteArray();
|
||||||
if (!textCodec || d->m_tempFile->write(outBytes) < 0) {
|
if (!textCodec || d->m_tempFile->write(outBytes) < 0) {
|
||||||
cleanupAfterStartFailure(msgCannotWriteTempFile());
|
cleanupAfterStartFailure(msgCannotWriteTempFile());
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
d->m_tempFile->flush();
|
d->m_tempFile->flush();
|
||||||
}
|
}
|
||||||
@@ -531,7 +531,7 @@ bool ConsoleProcess::start()
|
|||||||
const QString msg = tr("The process \"%1\" could not be started: %2")
|
const QString msg = tr("The process \"%1\" could not be started: %2")
|
||||||
.arg(cmdLine, winErrorMessage(GetLastError()));
|
.arg(cmdLine, winErrorMessage(GetLastError()));
|
||||||
cleanupAfterStartFailure(msg);
|
cleanupAfterStartFailure(msg);
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
d->processFinishedNotifier = new QWinEventNotifier(d->m_pid->hProcess, this);
|
d->processFinishedNotifier = new QWinEventNotifier(d->m_pid->hProcess, this);
|
||||||
@@ -554,13 +554,13 @@ bool ConsoleProcess::start()
|
|||||||
} else {
|
} else {
|
||||||
if (perr != ProcessArgs::FoundMeta) {
|
if (perr != ProcessArgs::FoundMeta) {
|
||||||
emitError(QProcess::FailedToStart, tr("Quoting error in command."));
|
emitError(QProcess::FailedToStart, tr("Quoting error in command."));
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
if (d->m_mode == Debug) {
|
if (d->m_mode == Debug) {
|
||||||
// FIXME: QTCREATORBUG-2809
|
// FIXME: QTCREATORBUG-2809
|
||||||
emitError(QProcess::FailedToStart, tr("Debugging complex shell commands in a terminal"
|
emitError(QProcess::FailedToStart, tr("Debugging complex shell commands in a terminal"
|
||||||
" is currently not supported."));
|
" is currently not supported."));
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
pcmd = qEnvironmentVariable("SHELL", "/bin/sh");
|
pcmd = qEnvironmentVariable("SHELL", "/bin/sh");
|
||||||
pargs = ProcessArgs::createUnixArgs(
|
pargs = ProcessArgs::createUnixArgs(
|
||||||
@@ -579,13 +579,13 @@ bool ConsoleProcess::start()
|
|||||||
emitError(QProcess::FailedToStart, qerr == ProcessArgs::BadQuoting
|
emitError(QProcess::FailedToStart, qerr == ProcessArgs::BadQuoting
|
||||||
? tr("Quoting error in terminal command.")
|
? tr("Quoting error in terminal command.")
|
||||||
: tr("Terminal command may not be a shell command."));
|
: tr("Terminal command may not be a shell command."));
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString err = stubServerListen();
|
const QString err = stubServerListen();
|
||||||
if (!err.isEmpty()) {
|
if (!err.isEmpty()) {
|
||||||
emitError(QProcess::FailedToStart, msgCommChannelFailed(err));
|
emitError(QProcess::FailedToStart, msgCommChannelFailed(err));
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
d->m_environment.unset(QLatin1String("TERM"));
|
d->m_environment.unset(QLatin1String("TERM"));
|
||||||
@@ -595,7 +595,7 @@ bool ConsoleProcess::start()
|
|||||||
d->m_tempFile = new QTemporaryFile();
|
d->m_tempFile = new QTemporaryFile();
|
||||||
if (!d->m_tempFile->open()) {
|
if (!d->m_tempFile->open()) {
|
||||||
cleanupAfterStartFailure(msgCannotCreateTempFile(d->m_tempFile->errorString()));
|
cleanupAfterStartFailure(msgCannotCreateTempFile(d->m_tempFile->errorString()));
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
QByteArray contents;
|
QByteArray contents;
|
||||||
for (const QString &var : env) {
|
for (const QString &var : env) {
|
||||||
@@ -604,7 +604,7 @@ bool ConsoleProcess::start()
|
|||||||
}
|
}
|
||||||
if (d->m_tempFile->write(contents) != contents.size() || !d->m_tempFile->flush()) {
|
if (d->m_tempFile->write(contents) != contents.size() || !d->m_tempFile->flush()) {
|
||||||
cleanupAfterStartFailure(msgCannotWriteTempFile());
|
cleanupAfterStartFailure(msgCannotWriteTempFile());
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -635,16 +635,14 @@ bool ConsoleProcess::start()
|
|||||||
const QString msg = tr("Cannot start the terminal emulator \"%1\", change the setting in the "
|
const QString msg = tr("Cannot start the terminal emulator \"%1\", change the setting in the "
|
||||||
"Environment options.").arg(terminal.command);
|
"Environment options.").arg(terminal.command);
|
||||||
cleanupAfterStartFailure(msg);
|
cleanupAfterStartFailure(msg);
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
d->m_stubConnectTimer = new QTimer(this);
|
d->m_stubConnectTimer = new QTimer(this);
|
||||||
connect(d->m_stubConnectTimer, &QTimer::timeout, this, &ConsoleProcess::stop);
|
connect(d->m_stubConnectTimer, &QTimer::timeout, this, &ConsoleProcess::stopProcess);
|
||||||
d->m_stubConnectTimer->setSingleShot(true);
|
d->m_stubConnectTimer->setSingleShot(true);
|
||||||
d->m_stubConnectTimer->start(10000);
|
d->m_stubConnectTimer->start(10000);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConsoleProcess::cleanupAfterStartFailure(const QString &errorMessage)
|
void ConsoleProcess::cleanupAfterStartFailure(const QString &errorMessage)
|
||||||
@@ -720,7 +718,7 @@ void ConsoleProcess::killStub()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConsoleProcess::stop()
|
void ConsoleProcess::stopProcess()
|
||||||
{
|
{
|
||||||
killProcess();
|
killProcess();
|
||||||
killStub();
|
killStub();
|
||||||
|
@@ -81,8 +81,8 @@ public:
|
|||||||
QProcess::ProcessError error() const;
|
QProcess::ProcessError error() const;
|
||||||
QString errorString() const;
|
QString errorString() const;
|
||||||
|
|
||||||
bool start();
|
void start();
|
||||||
void stop();
|
void stopProcess();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void setMode(Mode m);
|
void setMode(Mode m);
|
||||||
|
@@ -224,7 +224,7 @@ void TerminalRunner::start()
|
|||||||
|
|
||||||
void TerminalRunner::stop()
|
void TerminalRunner::stop()
|
||||||
{
|
{
|
||||||
m_stubProc.stop();
|
m_stubProc.stopProcess();
|
||||||
reportStopped();
|
reportStopped();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -199,7 +199,7 @@ void ApplicationLauncherPrivate::stop()
|
|||||||
if (!isRunning())
|
if (!isRunning())
|
||||||
return;
|
return;
|
||||||
if (m_useTerminal) {
|
if (m_useTerminal) {
|
||||||
m_consoleProcess.stop();
|
m_consoleProcess.stopProcess();
|
||||||
localProcessDone(0, QProcess::CrashExit);
|
localProcessDone(0, QProcess::CrashExit);
|
||||||
} else {
|
} else {
|
||||||
m_guiProcess.terminate();
|
m_guiProcess.terminate();
|
||||||
|
@@ -358,7 +358,7 @@ void SshDeviceProcess::SshDeviceProcessPrivate::setState(SshDeviceProcess::SshDe
|
|||||||
killOperation->disconnect(q);
|
killOperation->disconnect(q);
|
||||||
killOperation.clear();
|
killOperation.clear();
|
||||||
if (q->runInTerminal())
|
if (q->runInTerminal())
|
||||||
QMetaObject::invokeMethod(&consoleProcess, &ConsoleProcess::stop, Qt::QueuedConnection);
|
QMetaObject::invokeMethod(&consoleProcess, &ConsoleProcess::stopProcess, Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
killTimer.stop();
|
killTimer.stop();
|
||||||
consoleProcess.disconnect();
|
consoleProcess.disconnect();
|
||||||
|
Reference in New Issue
Block a user