Commit 6886d0ac authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh
Browse files

ProjectExplorer: Extend ApplicationLauncher



Implement some more QProcess functions

Change-Id: I1afe3fa5f5b353508cf300178cb50507b3dd4b3e
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
parent 28b512df
......@@ -97,6 +97,16 @@ Environment ConsoleProcess::environment() const
return d->m_environment;
}
QProcess::ProcessError ConsoleProcess::error() const
{
return d->m_error;
}
QString ConsoleProcess::errorString() const
{
return d->m_errorString;
}
QString ConsoleProcess::msgCommChannelFailed(const QString &error)
{
return tr("Cannot set up communication channel: %1").arg(error);
......@@ -139,6 +149,14 @@ QString ConsoleProcess::msgCannotExecute(const QString & p, const QString &why)
return tr("Cannot execute \"%1\": %2").arg(p, why);
}
void ConsoleProcess::emitError(QProcess::ProcessError err, const QString &errorString)
{
d->m_error = err;
d->m_errorString = errorString;
emit error(err);
emit processError(errorString);
}
QString ConsoleProcess::terminalEmulator(const QSettings *settings, bool nonEmpty)
{
if (settings) {
......
......@@ -57,6 +57,9 @@ public:
void setEnvironment(const Environment &env);
Environment environment() const;
QProcess::ProcessError error() const;
QString errorString() const;
bool start(const QString &program, const QString &args);
public slots:
void stop();
......@@ -95,7 +98,8 @@ public:
static void setTerminalEmulator(QSettings *settings, const QString &term);
signals:
void processError(const QString &error);
void error(QProcess::ProcessError error);
void processError(const QString &errorString);
// These reflect the state of the actual client process
void processStarted();
void processStopped(int, QProcess::ExitStatus);
......@@ -123,6 +127,7 @@ private:
static QString msgCannotChangeToWorkDir(const QString & dir, const QString &why);
static QString msgCannotExecute(const QString & p, const QString &why);
void emitError(QProcess::ProcessError err, const QString &errorString);
QString stubServerListen();
void stubServerShutdown();
#ifdef Q_OS_WIN
......
......@@ -67,6 +67,8 @@ struct ConsoleProcessPrivate {
QLocalServer m_stubServer;
QLocalSocket *m_stubSocket;
QTemporaryFile *m_tempFile;
QProcess::ProcessError m_error;
QString m_errorString;
#ifdef Q_OS_UNIX
QProcess m_process;
......
......@@ -50,6 +50,7 @@ ConsoleProcessPrivate::ConsoleProcessPrivate() :
m_appPid(0),
m_stubSocket(0),
m_tempFile(0),
m_error(QProcess::UnknownError),
m_settings(0),
m_stubConnected(false),
m_stubPid(0),
......@@ -80,6 +81,9 @@ bool ConsoleProcess::start(const QString &program, const QString &args)
if (isRunning())
return false;
d->m_errorString.clear();
d->m_error = QProcess::UnknownError;
QtcProcess::SplitError perr;
QtcProcess::Arguments pargs = QtcProcess::prepareArgs(args, &perr, HostOsInfo::hostOs(),
&d->m_environment, &d->m_workingDir);
......@@ -88,12 +92,12 @@ bool ConsoleProcess::start(const QString &program, const QString &args)
pcmd = program;
} else {
if (perr != QtcProcess::FoundMeta) {
emit processError(tr("Quoting error in command."));
emitError(QProcess::FailedToStart, tr("Quoting error in command."));
return false;
}
if (d->m_mode == Debug) {
// FIXME: QTCREATORBUG-2809
emit processError(tr("Debugging complex shell commands in a terminal"
emitError(QProcess::FailedToStart, tr("Debugging complex shell commands in a terminal"
" is currently not supported."));
return false;
}
......@@ -108,7 +112,7 @@ bool ConsoleProcess::start(const QString &program, const QString &args)
HostOsInfo::hostOs(),
&d->m_environment, &d->m_workingDir);
if (qerr != QtcProcess::SplitOk) {
emit processError(qerr == QtcProcess::BadQuoting
emitError(QProcess::FailedToStart, qerr == QtcProcess::BadQuoting
? tr("Quoting error in terminal command.")
: tr("Terminal command may not be a shell command."));
return false;
......@@ -116,7 +120,7 @@ bool ConsoleProcess::start(const QString &program, const QString &args)
const QString err = stubServerListen();
if (!err.isEmpty()) {
emit processError(msgCommChannelFailed(err));
emitError(QProcess::FailedToStart, msgCommChannelFailed(err));
return false;
}
......@@ -125,7 +129,7 @@ bool ConsoleProcess::start(const QString &program, const QString &args)
d->m_tempFile = new QTemporaryFile();
if (!d->m_tempFile->open()) {
stubServerShutdown();
emit processError(msgCannotCreateTempFile(d->m_tempFile->errorString()));
emitError(QProcess::FailedToStart, msgCannotCreateTempFile(d->m_tempFile->errorString()));
delete d->m_tempFile;
d->m_tempFile = 0;
return false;
......@@ -137,7 +141,7 @@ bool ConsoleProcess::start(const QString &program, const QString &args)
}
if (d->m_tempFile->write(contents) != contents.size() || !d->m_tempFile->flush()) {
stubServerShutdown();
emit processError(msgCannotWriteTempFile());
emitError(QProcess::FailedToStart, msgCannotWriteTempFile());
delete d->m_tempFile;
d->m_tempFile = 0;
return false;
......@@ -163,7 +167,7 @@ bool ConsoleProcess::start(const QString &program, const QString &args)
d->m_process.start(xterm, allArgs);
if (!d->m_process.waitForStarted()) {
stubServerShutdown();
emit processError(tr("Cannot start the terminal emulator \"%1\", change the setting in the "
emitError(QProcess::UnknownError, tr("Cannot start the terminal emulator \"%1\", change the setting in the "
"Environment options.").arg(xterm));
delete d->m_tempFile;
d->m_tempFile = 0;
......@@ -290,9 +294,9 @@ void ConsoleProcess::readStubOutput()
QByteArray out = d->m_stubSocket->readLine();
out.chop(1); // \n
if (out.startsWith("err:chdir ")) {
emit processError(msgCannotChangeToWorkDir(workingDirectory(), errorMsg(out.mid(10).toInt())));
emitError(QProcess::FailedToStart, msgCannotChangeToWorkDir(workingDirectory(), errorMsg(out.mid(10).toInt())));
} else if (out.startsWith("err:exec ")) {
emit processError(msgCannotExecute(d->m_executable, errorMsg(out.mid(9).toInt())));
emitError(QProcess::FailedToStart, msgCannotExecute(d->m_executable, errorMsg(out.mid(9).toInt())));
} else if (out.startsWith("spid ")) {
delete d->m_tempFile;
d->m_tempFile = 0;
......@@ -312,7 +316,7 @@ void ConsoleProcess::readStubOutput()
d->m_appPid = 0;
emit processStopped(d->m_appCode, d->m_appStatus);
} else {
emit processError(msgUnexpectedOutput(out));
emitError(QProcess::UnknownError, msgUnexpectedOutput(out));
d->m_stubPid = 0;
d->m_process.terminate();
break;
......
......@@ -45,6 +45,7 @@ ConsoleProcessPrivate::ConsoleProcessPrivate() :
m_appPid(0),
m_stubSocket(0),
m_tempFile(0),
m_error(QProcess::UnknownError),
m_appMainThreadId(0),
m_pid(0),
m_hInferior(NULL),
......@@ -69,6 +70,9 @@ bool ConsoleProcess::start(const QString &program, const QString &args)
if (isRunning())
return false;
d->m_errorString.clear();
d->m_error = QProcess::UnknownError;
QString pcmd;
QString pargs;
if (d->m_mode != Run) { // The debugger engines already pre-process the arguments.
......@@ -83,7 +87,7 @@ bool ConsoleProcess::start(const QString &program, const QString &args)
const QString err = stubServerListen();
if (!err.isEmpty()) {
emit processError(msgCommChannelFailed(err));
emitError(QProcess::FailedToStart, msgCommChannelFailed(err));
return false;
}
......@@ -92,7 +96,7 @@ bool ConsoleProcess::start(const QString &program, const QString &args)
d->m_tempFile = new QTemporaryFile();
if (!d->m_tempFile->open()) {
stubServerShutdown();
emit processError(msgCannotCreateTempFile(d->m_tempFile->errorString()));
emitError(QProcess::FailedToStart, msgCannotCreateTempFile(d->m_tempFile->errorString()));
delete d->m_tempFile;
d->m_tempFile = 0;
return false;
......@@ -106,7 +110,7 @@ bool ConsoleProcess::start(const QString &program, const QString &args)
out.flush();
if (out.status() != QTextStream::Ok) {
stubServerShutdown();
emit processError(msgCannotWriteTempFile());
emitError(QProcess::FailedToStart, msgCannotWriteTempFile());
delete d->m_tempFile;
d->m_tempFile = 0;
return false;
......@@ -146,7 +150,7 @@ bool ConsoleProcess::start(const QString &program, const QString &args)
delete d->m_tempFile;
d->m_tempFile = 0;
stubServerShutdown();
emit processError(tr("The process \"%1\" could not be started: %2").arg(cmdLine, winErrorMessage(GetLastError())));
emitError(QProcess::FailedToStart, tr("The process \"%1\" could not be started: %2").arg(cmdLine, winErrorMessage(GetLastError())));
return false;
}
......@@ -214,9 +218,9 @@ void ConsoleProcess::readStubOutput()
QByteArray out = d->m_stubSocket->readLine();
out.chop(2); // \r\n
if (out.startsWith("err:chdir ")) {
emit processError(msgCannotChangeToWorkDir(workingDirectory(), winErrorMessage(out.mid(10).toInt())));
emitError(QProcess::FailedToStart, msgCannotChangeToWorkDir(workingDirectory(), winErrorMessage(out.mid(10).toInt())));
} else if (out.startsWith("err:exec ")) {
emit processError(msgCannotExecute(d->m_executable, winErrorMessage(out.mid(9).toInt())));
emitError(QProcess::FailedToStart, msgCannotExecute(d->m_executable, winErrorMessage(out.mid(9).toInt())));
} else if (out.startsWith("thread ")) { // Windows only
d->m_appMainThreadId = out.mid(7).toLongLong();
} else if (out.startsWith("pid ")) {
......@@ -229,7 +233,7 @@ void ConsoleProcess::readStubOutput()
SYNCHRONIZE | PROCESS_QUERY_INFORMATION | PROCESS_TERMINATE,
FALSE, d->m_appPid);
if (d->m_hInferior == NULL) {
emit processError(tr("Cannot obtain a handle to the inferior: %1")
emitError(QProcess::FailedToStart, tr("Cannot obtain a handle to the inferior: %1")
.arg(winErrorMessage(GetLastError())));
// Uhm, and now what?
continue;
......@@ -238,7 +242,7 @@ void ConsoleProcess::readStubOutput()
connect(d->inferiorFinishedNotifier, SIGNAL(activated(HANDLE)), SLOT(inferiorExited()));
emit processStarted();
} else {
emit processError(msgUnexpectedOutput(out));
emitError(QProcess::UnknownError, msgUnexpectedOutput(out));
TerminateProcess(d->m_pid->hProcess, (unsigned)-1);
break;
}
......@@ -259,7 +263,7 @@ void ConsoleProcess::inferiorExited()
DWORD chldStatus;
if (!GetExitCodeProcess(d->m_hInferior, &chldStatus))
emit processError(tr("Cannot obtain exit status from inferior: %1")
emitError(QProcess::UnknownError, tr("Cannot obtain exit status from inferior: %1")
.arg(winErrorMessage(GetLastError())));
cleanupInferior();
d->m_appStatus = QProcess::NormalExit;
......
......@@ -103,6 +103,8 @@ ApplicationLauncher::ApplicationLauncher(QObject *parent)
this, SLOT(processDone(int,QProcess::ExitStatus)));
connect(&d->m_guiProcess, SIGNAL(started()),
this, SLOT(bringToForeground()));
connect(&d->m_guiProcess, SIGNAL(error(QProcess::ProcessError)),
this, SIGNAL(error(QProcess::ProcessError)));
#ifdef Q_OS_UNIX
d->m_consoleProcess.setSettings(Core::ICore::settings());
......@@ -113,6 +115,8 @@ ApplicationLauncher::ApplicationLauncher(QObject *parent)
this, SLOT(consoleProcessError(QString)));
connect(&d->m_consoleProcess, SIGNAL(processStopped(int,QProcess::ExitStatus)),
this, SLOT(processDone(int,QProcess::ExitStatus)));
connect(&d->m_consoleProcess, SIGNAL(error(QProcess::ProcessError)),
this, SIGNAL(error(QProcess::ProcessError)));
#ifdef Q_OS_WIN
connect(WinDebugInterface::instance(), SIGNAL(cannotRetrieveDebugOutput()),
......@@ -135,12 +139,22 @@ void ApplicationLauncher::setWorkingDirectory(const QString &dir)
d->m_consoleProcess.setWorkingDirectory(fixedPath);
}
QString ApplicationLauncher::workingDirectory() const
{
return d->m_guiProcess.workingDirectory();
}
void ApplicationLauncher::setEnvironment(const Utils::Environment &env)
{
d->m_guiProcess.setEnvironment(env);
d->m_consoleProcess.setEnvironment(env);
}
void ApplicationLauncher::setProcessChannelMode(QProcess::ProcessChannelMode mode)
{
d->m_guiProcess.setProcessChannelMode(mode);
}
void ApplicationLauncher::start(Mode mode, const QString &program, const QString &args)
{
d->m_processRunning = true;
......@@ -193,6 +207,22 @@ qint64 ApplicationLauncher::applicationPID() const
return Utils::qPidToPid(d->m_guiProcess.pid());
}
QString ApplicationLauncher::errorString() const
{
if (d->m_currentMode == Gui)
return d->m_guiProcess.errorString();
else
return d->m_consoleProcess.errorString();
}
QProcess::ProcessError ApplicationLauncher::error() const
{
if (d->m_currentMode == Gui)
return d->m_guiProcess.error();
else
return d->m_consoleProcess.error();
}
void ApplicationLauncher::guiProcessError()
{
QString error;
......
......@@ -56,14 +56,20 @@ public:
~ApplicationLauncher();
void setWorkingDirectory(const QString &dir);
QString workingDirectory() const;
void setEnvironment(const Utils::Environment &env);
void setProcessChannelMode(QProcess::ProcessChannelMode mode);
void start(Mode mode, const QString &program,
const QString &args = QString());
void stop();
bool isRunning() const;
qint64 applicationPID() const;
QString errorString() const;
QProcess::ProcessError error() const;
static QString msgWinCannotRetrieveDebuggingOutput();
signals:
......@@ -71,6 +77,7 @@ signals:
void processStarted();
void processExited(int exitCode, QProcess::ExitStatus);
void bringToForegroundRequested(qint64 pid);
void error(QProcess::ProcessError error);
private slots:
void guiProcessError();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment