OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / projectexplorer / applicationlauncher_win.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
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
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
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.
24 **
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.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #include "applicationlauncher.h"
35 #include "consoleprocess.h"
36 #include "winguiprocess.h"
37
38 #include <QtCore/QDebug>
39
40 namespace ProjectExplorer {
41
42 struct ApplicationLauncherPrivate {
43     ApplicationLauncherPrivate() : m_currentMode(ApplicationLauncher::Gui) {}
44
45     Utils::ConsoleProcess m_consoleProcess;
46     ApplicationLauncher::Mode m_currentMode;
47     Internal::WinGuiProcess m_winGuiProcess;
48 };
49
50 ApplicationLauncher::ApplicationLauncher(QObject *parent)
51     : QObject(parent), d(new ApplicationLauncherPrivate)
52 {
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()));
57
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)));
64 }
65
66 ApplicationLauncher::~ApplicationLauncher()
67 {
68 }
69
70 void ApplicationLauncher::setWorkingDirectory(const QString &dir)
71 {
72     d->m_winGuiProcess.setWorkingDirectory(dir);
73     d->m_consoleProcess.setWorkingDirectory(dir);
74 }
75
76 void ApplicationLauncher::setEnvironment(const Utils::Environment &env)
77 {
78     d->m_winGuiProcess.setEnvironment(env);
79     d->m_consoleProcess.setEnvironment(env);
80 }
81
82 void ApplicationLauncher::start(Mode mode, const QString &program, const QString &args)
83 {
84     d->m_currentMode = mode;
85     if (mode == Gui) {
86         d->m_winGuiProcess.start(program, args);
87     } else {
88         d->m_consoleProcess.start(program, args);
89     }
90 }
91
92 void ApplicationLauncher::stop()
93 {
94     if (!isRunning())
95         return;
96     if (d->m_currentMode == Gui) {
97         d->m_winGuiProcess.stop();
98     } else {
99         d->m_consoleProcess.stop();
100         processStopped();
101     }
102 }
103
104 bool ApplicationLauncher::isRunning() const
105 {
106     if (d->m_currentMode == Gui)
107         return d->m_winGuiProcess.isRunning();
108     else
109         return d->m_consoleProcess.isRunning();
110 }
111
112 qint64 ApplicationLauncher::applicationPID() const
113 {
114     qint64 result = 0;
115     if (!isRunning())
116         return result;
117
118     if (d->m_currentMode == Console) {
119         result = d->m_consoleProcess.applicationPID();
120     } else {
121         result = d->m_winGuiProcess.applicationPID();
122     }
123     return result;
124 }
125
126 void ApplicationLauncher::appendProcessMessage(const QString &output, bool onStdErr)
127 {
128     emit appendMessage(output, onStdErr ? ErrorMessageFormat : NormalMessageFormat);
129 }
130
131 void ApplicationLauncher::readWinDebugOutput(const QString &output,
132                                              bool onStdErr)
133 {
134     emit appendMessage(output, onStdErr ? StdErrFormat : StdOutFormat);
135 }
136
137 void ApplicationLauncher::processStopped()
138 {
139     emit processExited(0);
140 }
141
142 void ApplicationLauncher::processFinished(int exitCode)
143 {
144     emit processExited(exitCode);
145 }
146
147 void ApplicationLauncher::bringToForeground()
148 {
149 }
150
151 } // namespace ProjectExplorer