applicationrunconfiguration.cpp 5.1 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2
3
4
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
5
** Copyright (c) 2010 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
#include "applicationrunconfiguration.h"
31

con's avatar
con committed
32
#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
39
40
41
42
#include <QtGui/QLabel>

using namespace ProjectExplorer;
using namespace ProjectExplorer::Internal;

43
/// LocalApplicationRunConfiguration
con's avatar
con committed
44

Tobias Hunger's avatar
Tobias Hunger committed
45
46
LocalApplicationRunConfiguration::LocalApplicationRunConfiguration(Target *target, const QString &id) :
    RunConfiguration(target, id)
con's avatar
con committed
47
48
49
{
}

Tobias Hunger's avatar
Tobias Hunger committed
50
51
LocalApplicationRunConfiguration::LocalApplicationRunConfiguration(Target *target, LocalApplicationRunConfiguration *rc) :
    RunConfiguration(target, rc)
con's avatar
con committed
52
53
54
{
}

55
LocalApplicationRunConfiguration::~LocalApplicationRunConfiguration()
con's avatar
con committed
56
57
58
{
}

59
/// LocalApplicationRunControlFactory
con's avatar
con committed
60

61
LocalApplicationRunControlFactory::LocalApplicationRunControlFactory()
con's avatar
con committed
62
63
64
{
}

65
LocalApplicationRunControlFactory::~LocalApplicationRunControlFactory()
con's avatar
con committed
66
67
68
{
}

69
bool LocalApplicationRunControlFactory::canRun(ProjectExplorer::RunConfiguration *runConfiguration, const QString &mode) const
con's avatar
con committed
70
71
{
    return (mode == ProjectExplorer::Constants::RUNMODE)
72
            && (qobject_cast<LocalApplicationRunConfiguration *>(runConfiguration) != 0);
con's avatar
con committed
73
74
}

75
QString LocalApplicationRunControlFactory::displayName() const
con's avatar
con committed
76
{
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
77
    return tr("Run");
con's avatar
con committed
78
79
}

80
RunControl *LocalApplicationRunControlFactory::create(ProjectExplorer::RunConfiguration *runConfiguration, const QString &mode)
con's avatar
con committed
81
{
82
    QTC_ASSERT(canRun(runConfiguration, mode), return 0);
dt's avatar
dt committed
83
    return new LocalApplicationRunControl(qobject_cast<LocalApplicationRunConfiguration *>(runConfiguration), mode);
con's avatar
con committed
84
85
}

86
QWidget *LocalApplicationRunControlFactory::createConfigurationWidget(RunConfiguration *runConfiguration)
con's avatar
con committed
87
{
88
    Q_UNUSED(runConfiguration)
con's avatar
con committed
89
90
91
92
93
    return new QLabel("TODO add Configuration widget");
}

// ApplicationRunControl

94
95
LocalApplicationRunControl::LocalApplicationRunControl(LocalApplicationRunConfiguration *rc, QString mode)
    : RunControl(rc, mode)
con's avatar
con committed
96
{
97
    Utils::Environment env = rc->environment();
98
    QString dir = rc->workingDirectory();
99
100
101
    m_applicationLauncher.setEnvironment(env.toStringList());
    m_applicationLauncher.setWorkingDirectory(dir);

102
    m_executable = rc->executable();
103
    m_runMode = static_cast<ApplicationLauncher::Mode>(rc->runMode());
104
    m_commandLineArguments = rc->commandLineArguments();
105

106
107
108
109
    connect(&m_applicationLauncher, SIGNAL(appendMessage(QString,bool)),
            this, SLOT(slotAppendMessage(QString,bool)));
    connect(&m_applicationLauncher, SIGNAL(appendOutput(QString, bool)),
            this, SLOT(slotAddToOutputWindow(QString, bool)));
con's avatar
con committed
110
111
112
113
114
115
    connect(&m_applicationLauncher, SIGNAL(processExited(int)),
            this, SLOT(processExited(int)));
    connect(&m_applicationLauncher, SIGNAL(bringToForegroundRequested(qint64)),
            this, SLOT(bringApplicationToForeground(qint64)));
}

116
LocalApplicationRunControl::~LocalApplicationRunControl()
con's avatar
con committed
117
118
119
{
}

120
void LocalApplicationRunControl::start()
con's avatar
con committed
121
{
122
    m_applicationLauncher.start(m_runMode, m_executable, m_commandLineArguments);
con's avatar
con committed
123
124
    emit started();

125
    emit appendMessage(this, tr("Starting %1...").arg(QDir::toNativeSeparators(m_executable)), false);
con's avatar
con committed
126
127
}

128
LocalApplicationRunControl::StopResult LocalApplicationRunControl::stop()
con's avatar
con committed
129
130
{
    m_applicationLauncher.stop();
131
    return StoppedSynchronously;
con's avatar
con committed
132
133
}

134
bool LocalApplicationRunControl::isRunning() const
con's avatar
con committed
135
136
137
138
{
    return m_applicationLauncher.isRunning();
}

139
140
void LocalApplicationRunControl::slotAppendMessage(const QString &err,
                                                   bool isError)
con's avatar
con committed
141
{
142
    emit appendMessage(this, err, isError);
con's avatar
con committed
143
144
145
    emit finished();
}

146
void LocalApplicationRunControl::slotAddToOutputWindow(const QString &line,
147
                                                       bool isError)
con's avatar
con committed
148
{
149
    emit addToOutputWindowInline(this, line, isError);
con's avatar
con committed
150
151
}

152
void LocalApplicationRunControl::processExited(int exitCode)
con's avatar
con committed
153
{
154
    emit appendMessage(this, tr("%1 exited with code %2").arg(QDir::toNativeSeparators(m_executable)).arg(exitCode), false);
con's avatar
con committed
155
156
157
    emit finished();
}