applicationrunconfiguration.cpp 5.11 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2
3
4
**
** This file is part of Qt Creator
**
5
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
con's avatar
con committed
8
**
9
** Commercial Usage
10
**
11
12
13
14
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
15
**
16
** GNU Lesser General Public License Usage
17
**
18
19
20
21
22
23
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24
**
25
** If you are unsure which license is appropriate for your use, please
hjk's avatar
hjk committed
26
** contact the sales department at http://qt.nokia.com/contact.
con's avatar
con committed
27
**
28
**************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30
31
32
#include "applicationrunconfiguration.h"
#include "persistentsettings.h"
#include "environment.h"
hjk's avatar
hjk committed
33

con's avatar
con committed
34
#include <projectexplorer/projectexplorerconstants.h>
hjk's avatar
hjk committed
35
#include <utils/qtcassert.h>
con's avatar
con committed
36

37
#include <QtCore/QDir>
con's avatar
con committed
38
#include <QtGui/QLabel>
39
#include <QtGui/QTextDocument>
con's avatar
con committed
40
41
42
43
44
#include <QDebug>

using namespace ProjectExplorer;
using namespace ProjectExplorer::Internal;

45
/// LocalApplicationRunConfiguration
con's avatar
con committed
46

47
LocalApplicationRunConfiguration::LocalApplicationRunConfiguration(Project *pro)
con's avatar
con committed
48
49
50
51
    : RunConfiguration(pro)
{
}

52
LocalApplicationRunConfiguration::~LocalApplicationRunConfiguration()
con's avatar
con committed
53
54
55
{
}

56
QString LocalApplicationRunConfiguration::id() const
con's avatar
con committed
57
{
58
    return "ProjectExplorer.LocalApplicationRunConfiguration";
con's avatar
con committed
59
60
}

61
void LocalApplicationRunConfiguration::save(PersistentSettingsWriter &writer) const
con's avatar
con committed
62
63
64
65
{
    RunConfiguration::save(writer);
}

66
void LocalApplicationRunConfiguration::restore(const PersistentSettingsReader &reader)
con's avatar
con committed
67
68
69
70
{
    RunConfiguration::restore(reader);
}

71
/// LocalApplicationRunControlFactory
con's avatar
con committed
72

73
LocalApplicationRunControlFactory::LocalApplicationRunControlFactory()
con's avatar
con committed
74
75
76
{
}

77
LocalApplicationRunControlFactory::~LocalApplicationRunControlFactory()
con's avatar
con committed
78
79
80
{
}

81
bool LocalApplicationRunControlFactory::canRun(ProjectExplorer::RunConfiguration *runConfiguration, const QString &mode) const
con's avatar
con committed
82
83
{
    return (mode == ProjectExplorer::Constants::RUNMODE)
84
            && (qobject_cast<LocalApplicationRunConfiguration *>(runConfiguration) != 0);
con's avatar
con committed
85
86
}

87
QString LocalApplicationRunControlFactory::displayName() const
con's avatar
con committed
88
{
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
89
    return tr("Run");
con's avatar
con committed
90
91
}

92
RunControl *LocalApplicationRunControlFactory::create(ProjectExplorer::RunConfiguration *runConfiguration, const QString &mode)
con's avatar
con committed
93
{
94
    QTC_ASSERT(canRun(runConfiguration, mode), return 0);
95
    return new LocalApplicationRunControl(qobject_cast<LocalApplicationRunConfiguration *>(runConfiguration));
con's avatar
con committed
96
97
}

98
QWidget *LocalApplicationRunControlFactory::configurationWidget(RunConfiguration *runConfiguration)
con's avatar
con committed
99
{
100
    Q_UNUSED(runConfiguration)
con's avatar
con committed
101
102
103
104
105
    return new QLabel("TODO add Configuration widget");
}

// ApplicationRunControl

106
LocalApplicationRunControl::LocalApplicationRunControl(LocalApplicationRunConfiguration *runConfiguration)
107
    : RunControl(runConfiguration)
con's avatar
con committed
108
{
109
110
111
112
113
114
115
    m_applicationLauncher.setEnvironment(runConfiguration->environment().toStringList());
    m_applicationLauncher.setWorkingDirectory(runConfiguration->workingDirectory());

    m_executable = runConfiguration->executable();
    m_runMode = static_cast<ApplicationLauncher::Mode>(runConfiguration->runMode());
    m_commandLineArguments = runConfiguration->commandLineArguments();

hjk's avatar
hjk committed
116
117
118
119
    connect(&m_applicationLauncher, SIGNAL(applicationError(QString)),
            this, SLOT(slotError(QString)));
    connect(&m_applicationLauncher, SIGNAL(appendOutput(QString)),
            this, SLOT(slotAddToOutputWindow(QString)));
con's avatar
con committed
120
121
122
123
124
125
    connect(&m_applicationLauncher, SIGNAL(processExited(int)),
            this, SLOT(processExited(int)));
    connect(&m_applicationLauncher, SIGNAL(bringToForegroundRequested(qint64)),
            this, SLOT(bringApplicationToForeground(qint64)));
}

126
LocalApplicationRunControl::~LocalApplicationRunControl()
con's avatar
con committed
127
128
129
{
}

130
void LocalApplicationRunControl::start()
con's avatar
con committed
131
{
132
    m_applicationLauncher.start(m_runMode, m_executable, m_commandLineArguments);
con's avatar
con committed
133
134
    emit started();

135
    emit addToOutputWindow(this, tr("Starting %1...").arg(QDir::toNativeSeparators(m_executable)));
con's avatar
con committed
136
137
}

138
void LocalApplicationRunControl::stop()
con's avatar
con committed
139
140
141
142
{
    m_applicationLauncher.stop();
}

143
bool LocalApplicationRunControl::isRunning() const
con's avatar
con committed
144
145
146
147
{
    return m_applicationLauncher.isRunning();
}

148
void LocalApplicationRunControl::slotError(const QString & err)
con's avatar
con committed
149
150
151
152
153
{
    emit error(this, err);
    emit finished();
}

154
void LocalApplicationRunControl::slotAddToOutputWindow(const QString &line)
con's avatar
con committed
155
{
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
156
    emit addToOutputWindowInline(this, line);
con's avatar
con committed
157
158
}

159
void LocalApplicationRunControl::processExited(int exitCode)
con's avatar
con committed
160
{
161
    emit addToOutputWindow(this, tr("%1 exited with code %2").arg(QDir::toNativeSeparators(m_executable)).arg(exitCode));
con's avatar
con committed
162
163
164
    emit finished();
}