1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "applicationlauncher.h"
35 #include "consoleprocess.h"
36 #include "winguiprocess.h"
38 #include <QtCore/QDebug>
40 namespace ProjectExplorer {
42 struct ApplicationLauncherPrivate {
43 ApplicationLauncherPrivate() : m_currentMode(ApplicationLauncher::Gui) {}
45 Utils::ConsoleProcess m_consoleProcess;
46 ApplicationLauncher::Mode m_currentMode;
47 Internal::WinGuiProcess m_winGuiProcess;
50 ApplicationLauncher::ApplicationLauncher(QObject *parent)
51 : QObject(parent), d(new ApplicationLauncherPrivate)
53 connect(&d->m_consoleProcess, SIGNAL(processMessage(QString,bool)),
54 this, SLOT(appendProcessMessage(QString,bool)));
55 connect(&d->m_consoleProcess, SIGNAL(processStopped()),
56 this, SLOT(processStopped()));
58 connect(&d->m_winGuiProcess, SIGNAL(processMessage(QString, bool)),
59 this, SIGNAL(appendProcessMessage(QString,bool)));
60 connect(&d->m_winGuiProcess, SIGNAL(receivedDebugOutput(QString, bool)),
61 this, SLOT(readWinDebugOutput(QString, bool)));
62 connect(&d->m_winGuiProcess, SIGNAL(processFinished(int)),
63 this, SLOT(processFinished(int)));
66 ApplicationLauncher::~ApplicationLauncher()
70 void ApplicationLauncher::setWorkingDirectory(const QString &dir)
72 d->m_winGuiProcess.setWorkingDirectory(dir);
73 d->m_consoleProcess.setWorkingDirectory(dir);
76 void ApplicationLauncher::setEnvironment(const Utils::Environment &env)
78 d->m_winGuiProcess.setEnvironment(env);
79 d->m_consoleProcess.setEnvironment(env);
82 void ApplicationLauncher::start(Mode mode, const QString &program, const QString &args)
84 d->m_currentMode = mode;
86 d->m_winGuiProcess.start(program, args);
88 d->m_consoleProcess.start(program, args);
92 void ApplicationLauncher::stop()
96 if (d->m_currentMode == Gui) {
97 d->m_winGuiProcess.stop();
99 d->m_consoleProcess.stop();
104 bool ApplicationLauncher::isRunning() const
106 if (d->m_currentMode == Gui)
107 return d->m_winGuiProcess.isRunning();
109 return d->m_consoleProcess.isRunning();
112 qint64 ApplicationLauncher::applicationPID() const
118 if (d->m_currentMode == Console) {
119 result = d->m_consoleProcess.applicationPID();
121 result = d->m_winGuiProcess.applicationPID();
126 void ApplicationLauncher::appendProcessMessage(const QString &output, bool onStdErr)
128 emit appendMessage(output, onStdErr ? ErrorMessageFormat : NormalMessageFormat);
131 void ApplicationLauncher::readWinDebugOutput(const QString &output,
134 emit appendMessage(output, onStdErr ? StdErrFormat : StdOutFormat);
137 void ApplicationLauncher::processStopped()
139 emit processExited(0);
142 void ApplicationLauncher::processFinished(int exitCode)
144 emit processExited(exitCode);
147 void ApplicationLauncher::bringToForeground()
151 } // namespace ProjectExplorer