cmakerunconfiguration.cpp 9.76 KB
Newer Older
1
/**************************************************************************
dt's avatar
dt committed
2
3
4
**
** This file is part of Qt Creator
**
5
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
dt's avatar
dt committed
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
dt's avatar
dt committed
8
**
9
** Commercial Usage
dt's avatar
dt committed
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.
dt's avatar
dt committed
15
**
16
** GNU Lesser General Public License Usage
dt's avatar
dt committed
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.
dt's avatar
dt committed
24
**
25
** If you are unsure which license is appropriate for your use, please
26
** contact the sales department at http://www.qtsoftware.com/contact.
dt's avatar
dt committed
27
**
28
**************************************************************************/
dt's avatar
dt committed
29
30

#include "cmakerunconfiguration.h"
hjk's avatar
hjk committed
31

dt's avatar
dt committed
32
#include "cmakeproject.h"
hjk's avatar
hjk committed
33
#include "cmakeprojectconstants.h"
dt's avatar
dt committed
34
35

#include <projectexplorer/environment.h>
36
#include <projectexplorer/debugginghelper.h>
hjk's avatar
hjk committed
37
#include <utils/qtcassert.h>
38
39
#include <QtGui/QFormLayout>
#include <QtGui/QLineEdit>
dt's avatar
dt committed
40
41
42
43

using namespace CMakeProjectManager;
using namespace CMakeProjectManager::Internal;

dt's avatar
dt committed
44
CMakeRunConfiguration::CMakeRunConfiguration(CMakeProject *pro, const QString &target, const QString &workingDirectory, const QString &title)
45
46
47
48
49
    : ProjectExplorer::ApplicationRunConfiguration(pro)
    , m_runMode(Gui)
    , m_target(target)
    , m_workingDirectory(workingDirectory)
    , m_title(title)
dt's avatar
dt committed
50
{
dt's avatar
dt committed
51
    setName(title);
52
53
54
55
56
57

    connect(pro, SIGNAL(activeBuildConfigurationChanged()),
            this, SIGNAL(baseEnvironmentChanged()));

    connect(pro, SIGNAL(environmentChanged(QString)),
            this, SIGNAL(baseEnvironmentChanged()));
dt's avatar
dt committed
58
}
hjk's avatar
hjk committed
59

dt's avatar
dt committed
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
CMakeRunConfiguration::~CMakeRunConfiguration()
{
}

QString CMakeRunConfiguration::type() const
{
    return Constants::CMAKERUNCONFIGURATION;
}

QString CMakeRunConfiguration::executable() const
{
    return m_target;
}

ProjectExplorer::ApplicationRunConfiguration::RunMode CMakeRunConfiguration::runMode() const
{
76
    return m_runMode;
dt's avatar
dt committed
77
78
79
80
81
82
83
84
85
}

QString CMakeRunConfiguration::workingDirectory() const
{
    return m_workingDirectory;
}

QStringList CMakeRunConfiguration::commandLineArguments() const
{
86
    return ProjectExplorer::Environment::parseCombinedArgString(m_arguments);
dt's avatar
dt committed
87
88
}

dt's avatar
dt committed
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
QString CMakeRunConfiguration::title() const
{
    return m_title;
}

void CMakeRunConfiguration::setExecutable(const QString &executable)
{
    m_target = executable;
}

void CMakeRunConfiguration::setWorkingDirectory(const QString &workingDirectory)
{
    m_workingDirectory = workingDirectory;
}

dt's avatar
dt committed
104
105
106
void CMakeRunConfiguration::save(ProjectExplorer::PersistentSettingsWriter &writer) const
{
    ProjectExplorer::ApplicationRunConfiguration::save(writer);
107
108
    writer.saveValue("CMakeRunConfiguration.Target", m_target);
    writer.saveValue("CMakeRunConfiguration.WorkingDirectory", m_workingDirectory);
109
    writer.saveValue("CMakeRunConfiguration.UseTerminal", m_runMode == Console);
dt's avatar
dt committed
110
    writer.saveValue("CMakeRunConfiguation.Title", m_title);
111
    writer.saveValue("CMakeRunConfiguration.Arguments", m_arguments);
112
    writer.saveValue("CMakeRunConfiguration.UserEnvironmentChanges", ProjectExplorer::EnvironmentItem::toStringList(m_userEnvironmentChanges));
dt's avatar
dt committed
113
114
115
116
117
}

void CMakeRunConfiguration::restore(const ProjectExplorer::PersistentSettingsReader &reader)
{
    ProjectExplorer::ApplicationRunConfiguration::restore(reader);
118
119
    m_target = reader.restoreValue("CMakeRunConfiguration.Target").toString();
    m_workingDirectory = reader.restoreValue("CMakeRunConfiguration.WorkingDirectory").toString();
120
    m_runMode = reader.restoreValue("CMakeRunConfiguration.UseTerminal").toBool() ? Console : Gui;
dt's avatar
dt committed
121
    m_title = reader.restoreValue("CMakeRunConfiguation.Title").toString();
122
    m_arguments = reader.restoreValue("CMakeRunConfiguration.Arguments").toString();
123
    m_userEnvironmentChanges = ProjectExplorer::EnvironmentItem::fromStringList(reader.restoreValue("CMakeRunConfiguration.UserEnvironmentChanges").toStringList());
dt's avatar
dt committed
124
125
126
127
}

QWidget *CMakeRunConfiguration::configurationWidget()
{
128
    return new CMakeRunConfigurationWidget(this);
129
130
131
132
133
}

void CMakeRunConfiguration::setArguments(const QString &newText)
{
    m_arguments = newText;
dt's avatar
dt committed
134
135
}

136
137
QString CMakeRunConfiguration::dumperLibrary() const
{
138
139
    QString qmakePath = ProjectExplorer::DebuggingHelperLibrary::findSystemQt(environment());
    QString dhl = ProjectExplorer::DebuggingHelperLibrary::debuggingHelperLibrary(qmakePath);
140
    return dhl;
141
142
}

143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
ProjectExplorer::Environment CMakeRunConfiguration::baseEnvironment() const
{
    // TODO use either System Environment
    // build environment
    // or empty
    //Environment env = Environment(QProcess::systemEnvironment());

    QString config = project()->activeBuildConfiguration();
    ProjectExplorer::Environment env = project()->environment(project()->activeBuildConfiguration());
    return env;
}

ProjectExplorer::Environment CMakeRunConfiguration::environment() const
{
    ProjectExplorer::Environment env = baseEnvironment();
    env.modify(userEnvironmentChanges());
    return env;
}

QList<ProjectExplorer::EnvironmentItem> CMakeRunConfiguration::userEnvironmentChanges() const
{
    return m_userEnvironmentChanges;
}

void CMakeRunConfiguration::setUserEnvironmentChanges(const QList<ProjectExplorer::EnvironmentItem> &diff)
{
    if (m_userEnvironmentChanges != diff) {
        m_userEnvironmentChanges = diff;
        emit userEnvironmentChangesChanged(diff);
    }
}

// Configuration widget


CMakeRunConfigurationWidget::CMakeRunConfigurationWidget(CMakeRunConfiguration *cmakeRunConfiguration, QWidget *parent)
    : QWidget(parent), m_cmakeRunConfiguration(cmakeRunConfiguration)
{

    QFormLayout *fl = new QFormLayout();
    QLineEdit *argumentsLineEdit = new QLineEdit();
    argumentsLineEdit->setText(ProjectExplorer::Environment::joinArgumentList(cmakeRunConfiguration->commandLineArguments()));
    connect(argumentsLineEdit, SIGNAL(textChanged(QString)),
            this, SLOT(setArguments(QString)));
    fl->addRow(tr("Arguments:"), argumentsLineEdit);

    QVBoxLayout *vbx = new QVBoxLayout(this);
    vbx->addLayout(fl);
    m_environmentWidget = new ProjectExplorer::EnvironmentWidget(this);
    vbx->addWidget(m_environmentWidget);
    m_environmentWidget->setBaseEnvironment(m_cmakeRunConfiguration->baseEnvironment());
    m_environmentWidget->setUserChanges(m_cmakeRunConfiguration->userEnvironmentChanges());

    connect(m_environmentWidget, SIGNAL(userChangesUpdated()),
            this, SLOT(userChangesUpdated()));

    connect(m_cmakeRunConfiguration, SIGNAL(baseEnvironmentChanged()),
            this, SLOT(baseEnvironmentChanged()));
    connect(m_cmakeRunConfiguration, SIGNAL(userEnvironmentChangesChanged(QList<ProjectExplorer::EnvironmentItem>)),
            this, SLOT(userEnvironmentChangesChanged()));
}

void CMakeRunConfigurationWidget::userChangesUpdated()
{
    m_cmakeRunConfiguration->setUserEnvironmentChanges(m_environmentWidget->userChanges());
}

void CMakeRunConfigurationWidget::baseEnvironmentChanged()
{
    m_environmentWidget->setBaseEnvironment(m_cmakeRunConfiguration->baseEnvironment());
}

void CMakeRunConfigurationWidget::userEnvironmentChangesChanged()
{
    m_environmentWidget->setUserChanges(m_cmakeRunConfiguration->userEnvironmentChanges());
}

void CMakeRunConfigurationWidget::setArguments(const QString &args)
{
    m_cmakeRunConfiguration->setArguments(args);
}


dt's avatar
dt committed
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
// Factory
CMakeRunConfigurationFactory::CMakeRunConfigurationFactory()
{

}

CMakeRunConfigurationFactory::~CMakeRunConfigurationFactory()
{

}

// used to recreate the runConfigurations when restoring settings
bool CMakeRunConfigurationFactory::canCreate(const QString &type) const
{
    if (type.startsWith(Constants::CMAKERUNCONFIGURATION))
        return true;
    return false;
}

// used to show the list of possible additons to a project, returns a list of types
QStringList CMakeRunConfigurationFactory::canCreate(ProjectExplorer::Project *project) const
{
    CMakeProject *pro = qobject_cast<CMakeProject *>(project);
    if (!pro)
        return QStringList();
251
252
253
254
255
    QStringList allTargets = pro->targets();
    for (int i=0; i<allTargets.size(); ++i) {
        allTargets[i] = Constants::CMAKERUNCONFIGURATION + allTargets[i];
    }
    return allTargets;
dt's avatar
dt committed
256
257
258
259
260
}

// used to translate the types to names to display to the user
QString CMakeRunConfigurationFactory::nameForType(const QString &type) const
{
dt's avatar
dt committed
261
    Q_ASSERT(type.startsWith(Constants::CMAKERUNCONFIGURATION));
dt's avatar
dt committed
262
263
264
265
266
267
268
269
270
271

    if (type == Constants::CMAKERUNCONFIGURATION)
        return "CMake"; // Doesn't happen
    else
        return type.mid(QString(Constants::CMAKERUNCONFIGURATION).length());
}

QSharedPointer<ProjectExplorer::RunConfiguration> CMakeRunConfigurationFactory::create(ProjectExplorer::Project *project, const QString &type)
{
    CMakeProject *pro = qobject_cast<CMakeProject *>(project);
dt's avatar
dt committed
272
    Q_ASSERT(pro);
dt's avatar
dt committed
273
274
    if (type == Constants::CMAKERUNCONFIGURATION) {
        // Restoring, filename will be added by restoreSettings
dt's avatar
dt committed
275
        QSharedPointer<ProjectExplorer::RunConfiguration> rc(new CMakeRunConfiguration(pro, QString::null, QString::null, QString::null));
dt's avatar
dt committed
276
277
278
        return rc;
    } else {
        // Adding new
279
280
281
        const QString title = type.mid(QString(Constants::CMAKERUNCONFIGURATION).length());
        const CMakeTarget &ct = pro->targetForTitle(title);
        QSharedPointer<ProjectExplorer::RunConfiguration> rc(new CMakeRunConfiguration(pro, ct.executable, ct.workingDirectory, ct.title));
dt's avatar
dt committed
282
283
284
        return rc;
    }
}