qt4runconfiguration.cpp 25.6 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
26
** contact the sales department at http://www.qtsoftware.com/contact.
con's avatar
con committed
27
**
28
**************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30
#include "qt4runconfiguration.h"
hjk's avatar
hjk committed
31

hjk's avatar
hjk committed
32
#include "makestep.h"
con's avatar
con committed
33
34
#include "profilereader.h"
#include "qt4nodes.h"
hjk's avatar
hjk committed
35
#include "qt4project.h"
con's avatar
con committed
36
37
38
39

#include <coreplugin/icore.h>
#include <coreplugin/messagemanager.h>
#include <coreplugin/variablemanager.h>
40
#include <coreplugin/ifile.h>
con's avatar
con committed
41
#include <projectexplorer/buildstep.h>
42
#include <projectexplorer/environmenteditmodel.h>
hjk's avatar
hjk committed
43
#include <utils/qtcassert.h>
con's avatar
con committed
44
45
46

#include <QtGui/QFormLayout>
#include <QtGui/QInputDialog>
47
#include <QtGui/QLabel>
48
#include <QtGui/QCheckBox>
49
#include <QtGui/QToolButton>
50
51
#include <QtGui/QGroupBox>
#include <QtGui/QRadioButton>
con's avatar
con committed
52
53
54
55
56
57
58

using namespace Qt4ProjectManager::Internal;
using namespace Qt4ProjectManager;
using ProjectExplorer::ApplicationRunConfiguration;
using ProjectExplorer::PersistentSettingsReader;
using ProjectExplorer::PersistentSettingsWriter;

59
Qt4RunConfiguration::Qt4RunConfiguration(Qt4Project *pro, const QString &proFilePath)
60
61
    : ApplicationRunConfiguration(pro),
      m_proFilePath(proFilePath),
62
      m_runMode(Gui),
63
64
      m_userSetName(false),
      m_configWidget(0),
65
      m_cachedTargetInformationValid(false),
66
      m_isUsingDyldImageSuffix(false),
67
68
      m_userSetWokingDirectory(false),
      m_baseEnvironmentBase(Qt4RunConfiguration::BuildEnvironmentBase)
con's avatar
con committed
69
{
70
71
72
73
    if (!m_proFilePath.isEmpty())
        setName(QFileInfo(m_proFilePath).completeBaseName());
    else
        setName(tr("Qt4RunConfiguration"));
74

75
    connect(pro, SIGNAL(activeBuildConfigurationChanged()),
76
            this, SLOT(invalidateCachedTargetInformation()));
77
78
79
80
81
82

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

    connect(pro, SIGNAL(environmentChanged(QString)),
            this, SIGNAL(baseEnvironmentChanged()));
con's avatar
con committed
83
84
85
86
87
88
89
90
91
92
93
}

Qt4RunConfiguration::~Qt4RunConfiguration()
{
}

QString Qt4RunConfiguration::type() const
{
    return "Qt4ProjectManager.Qt4RunConfiguration";
}

94
95
96
97
98
99

//////
/// Qt4RunConfigurationWidget
/////

Qt4RunConfigurationWidget::Qt4RunConfigurationWidget(Qt4RunConfiguration *qt4RunConfiguration, QWidget *parent)
100
101
102
    : QWidget(parent),
    m_qt4RunConfiguration(qt4RunConfiguration),
    m_ignoreChange(false),
mae's avatar
mae committed
103
104
    m_usingDyldImageSuffix(0),
    m_isShown(false)
con's avatar
con committed
105
{
dt's avatar
dt committed
106
    QFormLayout *toplayout = new QFormLayout();
con's avatar
con committed
107
108
109
    toplayout->setMargin(0);

    QLabel *nameLabel = new QLabel(tr("Name:"));
110
111
112
    m_nameLineEdit = new QLineEdit(m_qt4RunConfiguration->name());
    nameLabel->setBuddy(m_nameLineEdit);
    toplayout->addRow(nameLabel, m_nameLineEdit);
con's avatar
con committed
113

114
115
    m_executableLabel = new QLabel(m_qt4RunConfiguration->executable());
    toplayout->addRow(tr("Executable:"), m_executableLabel);
con's avatar
con committed
116

117
118
119
120
121
122
123
124
125
126
127
128
129
    m_workingDirectoryEdit = new Core::Utils::PathChooser();
    m_workingDirectoryEdit->setPath(m_qt4RunConfiguration->workingDirectory());
    m_workingDirectoryEdit->setExpectedKind(Core::Utils::PathChooser::Directory);
    m_workingDirectoryEdit->setPromptDialogTitle(tr("Select the working directory"));

    QToolButton *resetButton = new QToolButton();
    resetButton->setToolTip(tr("Reset to default"));
    resetButton->setIcon(QIcon(":/core/images/reset.png"));

    QHBoxLayout *boxlayout = new QHBoxLayout();
    boxlayout->addWidget(m_workingDirectoryEdit);
    boxlayout->addWidget(resetButton);
    toplayout->addRow(tr("Working Directory:"), boxlayout);
con's avatar
con committed
130
131

    QLabel *argumentsLabel = new QLabel(tr("&Arguments:"));
132
133
134
    m_argumentsLineEdit = new QLineEdit(ProjectExplorer::Environment::joinArgumentList(qt4RunConfiguration->commandLineArguments()));
    argumentsLabel->setBuddy(m_argumentsLineEdit);
    toplayout->addRow(argumentsLabel, m_argumentsLineEdit);
con's avatar
con committed
135

136
137
138
139
    m_useTerminalCheck = new QCheckBox(tr("Run in &Terminal"));
    m_useTerminalCheck->setChecked(m_qt4RunConfiguration->runMode() == ProjectExplorer::ApplicationRunConfiguration::Console);
    toplayout->addRow(QString(), m_useTerminalCheck);

140
141
142
143
144
145
146
147
#ifdef Q_OS_MAC
    m_usingDyldImageSuffix = new QCheckBox(tr("Use debug version of frameworks (DYLD_IMAGE_SUFFIX=_debug)"));
    m_usingDyldImageSuffix->setChecked(m_qt4RunConfiguration->isUsingDyldImageSuffix());
    toplayout->addRow(QString(), m_usingDyldImageSuffix);
    connect(m_usingDyldImageSuffix, SIGNAL(toggled(bool)),
            this, SLOT(usingDyldImageSuffixToggled(bool)));
#endif

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


    QGroupBox *box = new QGroupBox(tr("Environment"),this);
    QVBoxLayout *boxLayout = new QVBoxLayout();
    box->setLayout(boxLayout);
    box->setFlat(true);

    QLabel *label = new QLabel(tr("Base environment for this runconfiguration:"), this);
    boxLayout->addWidget(label);

    m_cleanEnvironmentRadioButton = new QRadioButton("Clean Environment", box);
    m_systemEnvironmentRadioButton = new QRadioButton("System Environment", box);
    m_buildEnvironmentRadioButton = new QRadioButton("Build Environment", box);
    boxLayout->addWidget(m_cleanEnvironmentRadioButton);
    boxLayout->addWidget(m_systemEnvironmentRadioButton);
    boxLayout->addWidget(m_buildEnvironmentRadioButton);

    if (qt4RunConfiguration->baseEnvironmentBase() == Qt4RunConfiguration::CleanEnvironmentBase)
        m_cleanEnvironmentRadioButton->setChecked(true);
    else if (qt4RunConfiguration->baseEnvironmentBase() == Qt4RunConfiguration::SystemEnvironmentBase)
        m_systemEnvironmentRadioButton->setChecked(true);
    else if (qt4RunConfiguration->baseEnvironmentBase() == Qt4RunConfiguration::BuildEnvironmentBase)
        m_buildEnvironmentRadioButton->setChecked(true);

    connect(m_cleanEnvironmentRadioButton, SIGNAL(toggled(bool)),
            this, SLOT(baseEnvironmentRadioButtonChanged()));
    connect(m_systemEnvironmentRadioButton, SIGNAL(toggled(bool)),
            this, SLOT(baseEnvironmentRadioButtonChanged()));
    connect(m_buildEnvironmentRadioButton, SIGNAL(toggled(bool)),
            this, SLOT(baseEnvironmentRadioButtonChanged()));
dt's avatar
dt committed
178

179
180
181
    m_environmentWidget = new ProjectExplorer::EnvironmentWidget(this);
    m_environmentWidget->setBaseEnvironment(m_qt4RunConfiguration->baseEnvironment());
    m_environmentWidget->setUserChanges(m_qt4RunConfiguration->userEnvironmentChanges());
dt's avatar
dt committed
182
    m_environmentWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
183
184
185
186
187
    boxLayout->addWidget(m_environmentWidget);

    QVBoxLayout *vbox = new QVBoxLayout(this);
    vbox->addLayout(toplayout);
    vbox->addWidget(box);
188

189
190
191
192
193
194
    connect(m_workingDirectoryEdit, SIGNAL(changed()),
            this, SLOT(setWorkingDirectory()));

    connect(resetButton, SIGNAL(clicked()),
            this, SLOT(resetWorkingDirectory()));

195
196
197
198
    connect(m_argumentsLineEdit, SIGNAL(textEdited(QString)),
            this, SLOT(setCommandLineArguments(QString)));
    connect(m_nameLineEdit, SIGNAL(textEdited(QString)),
            this, SLOT(nameEdited(QString)));
199
200
201
    connect(m_useTerminalCheck, SIGNAL(toggled(bool)),
            this, SLOT(termToggled(bool)));

202
203
204
    connect(m_environmentWidget, SIGNAL(userChangesUpdated()),
            this, SLOT(userChangesUpdated()));

205
206
207
    connect(qt4RunConfiguration, SIGNAL(workingDirectoryChanged(QString)),
            this, SLOT(workingDirectoryChanged(QString)));

208
209
210
211
    connect(qt4RunConfiguration, SIGNAL(commandLineArgumentsChanged(QString)),
            this, SLOT(commandLineArgumentsChanged(QString)));
    connect(qt4RunConfiguration, SIGNAL(nameChanged(QString)),
            this, SLOT(nameChanged(QString)));
212
213
    connect(qt4RunConfiguration, SIGNAL(runModeChanged(ProjectExplorer::ApplicationRunConfiguration::RunMode)),
            this, SLOT(runModeChanged(ProjectExplorer::ApplicationRunConfiguration::RunMode)));
214
215
    connect(qt4RunConfiguration, SIGNAL(usingDyldImageSuffixChanged(bool)),
            this, SLOT(usingDyldImageSuffixChanged(bool)));
216
217
    connect(qt4RunConfiguration, SIGNAL(effectiveTargetInformationChanged()),
            this, SLOT(effectiveTargetInformationChanged()), Qt::QueuedConnection);
218
219
220
221

    connect(qt4RunConfiguration, SIGNAL(userEnvironmentChangesChanged(QList<ProjectExplorer::EnvironmentItem>)),
            this, SLOT(userEnvironmentChangesChanged(QList<ProjectExplorer::EnvironmentItem>)));

222
223
224
225
    connect(qt4RunConfiguration, SIGNAL(baseEnvironmentChanged()),
            this, SLOT(baseEnvironmentChanged()));
}

226
227
228
229
230
231
232
233
234
235
236
237
238
239
void Qt4RunConfigurationWidget::baseEnvironmentRadioButtonChanged()
{
    m_ignoreChange = true;
    if (m_cleanEnvironmentRadioButton->isChecked())
        m_qt4RunConfiguration->setBaseEnvironmentBase(Qt4RunConfiguration::CleanEnvironmentBase);
    else if (m_systemEnvironmentRadioButton->isChecked())
        m_qt4RunConfiguration->setBaseEnvironmentBase(Qt4RunConfiguration::SystemEnvironmentBase);
    else if (m_buildEnvironmentRadioButton->isChecked())
        m_qt4RunConfiguration->setBaseEnvironmentBase(Qt4RunConfiguration::BuildEnvironmentBase);

    m_environmentWidget->setBaseEnvironment(m_qt4RunConfiguration->baseEnvironment());
    m_ignoreChange = false;
}

240
241
void Qt4RunConfigurationWidget::baseEnvironmentChanged()
{
242
243
244
245
246
247
248
249
250
251
    if (m_ignoreChange)
        return;

    if (m_qt4RunConfiguration->baseEnvironmentBase() == Qt4RunConfiguration::CleanEnvironmentBase)
        m_cleanEnvironmentRadioButton->setChecked(true);
    else if (m_qt4RunConfiguration->baseEnvironmentBase() == Qt4RunConfiguration::SystemEnvironmentBase)
        m_systemEnvironmentRadioButton->setChecked(true);
    else if (m_qt4RunConfiguration->baseEnvironmentBase() == Qt4RunConfiguration::BuildEnvironmentBase)
        m_buildEnvironmentRadioButton->setChecked(true);

252
    m_environmentWidget->setBaseEnvironment(m_qt4RunConfiguration->baseEnvironment());
253
254
255
256
257
258
259
260
261
262
263
264
265
266
}

void Qt4RunConfigurationWidget::userEnvironmentChangesChanged(const QList<ProjectExplorer::EnvironmentItem> &userChanges)
{
    if (m_ignoreChange)
        return;
    m_environmentWidget->setUserChanges(userChanges);
}

void Qt4RunConfigurationWidget::userChangesUpdated()
{
    m_ignoreChange = true;
    m_qt4RunConfiguration->setUserEnvironmentChanges(m_environmentWidget->userChanges());
    m_ignoreChange = false;
267
268
}

269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
void Qt4RunConfigurationWidget::setWorkingDirectory()
{
    if (m_ignoreChange)
        return;
    m_ignoreChange = true;
    m_qt4RunConfiguration->setWorkingDirectory(m_workingDirectoryEdit->path());
    m_ignoreChange = false;
}

void Qt4RunConfigurationWidget::resetWorkingDirectory()
{
    // This emits a signal connected to workingDirectoryChanged()
    // that sets the m_workingDirectoryEdit
    m_qt4RunConfiguration->setWorkingDirectory("");
}

285
286
287
288
289
290
291
292
293
294
295
296
297
298
void Qt4RunConfigurationWidget::setCommandLineArguments(const QString &args)
{
    m_ignoreChange = true;
    m_qt4RunConfiguration->setCommandLineArguments(args);
    m_ignoreChange = false;
}

void Qt4RunConfigurationWidget::nameEdited(const QString &name)
{
    m_ignoreChange = true;
    m_qt4RunConfiguration->nameEdited(name);
    m_ignoreChange = false;
}

299
300
301
302
303
304
305
306
void Qt4RunConfigurationWidget::termToggled(bool on)
{
    m_ignoreChange = true;
    m_qt4RunConfiguration->setRunMode(on ? ApplicationRunConfiguration::Console
                                         : ApplicationRunConfiguration::Gui);
    m_ignoreChange = false;
}

307
308
309
310
311
312
313
void Qt4RunConfigurationWidget::usingDyldImageSuffixToggled(bool state)
{
    m_ignoreChange = true;
    m_qt4RunConfiguration->setUsingDyldImageSuffix(state);
    m_ignoreChange = false;
}

314
315
316
317
318
319
void Qt4RunConfigurationWidget::workingDirectoryChanged(const QString &workingDirectory)
{
    if (!m_ignoreChange)
        m_workingDirectoryEdit->setPath(workingDirectory);
}

320
321
322
323
324
325
326
327
328
329
330
331
void Qt4RunConfigurationWidget::commandLineArgumentsChanged(const QString &args)
{
    if (!m_ignoreChange)
        m_argumentsLineEdit->setText(args);
}

void Qt4RunConfigurationWidget::nameChanged(const QString &name)
{
    if (!m_ignoreChange)
        m_nameLineEdit->setText(name);
}

332
333
334
335
336
337
void Qt4RunConfigurationWidget::runModeChanged(ApplicationRunConfiguration::RunMode runMode)
{
    if (!m_ignoreChange)
        m_useTerminalCheck->setChecked(runMode == ApplicationRunConfiguration::Console);
}

338
339
340
341
342
343
void Qt4RunConfigurationWidget::usingDyldImageSuffixChanged(bool state)
{
    if (!m_ignoreChange && m_usingDyldImageSuffix)
        m_usingDyldImageSuffix->setChecked(state);
}

344
void Qt4RunConfigurationWidget::effectiveTargetInformationChanged()
345
{
346
    if (m_isShown) {
347
        m_executableLabel->setText(QDir::toNativeSeparators(m_qt4RunConfiguration->executable()));
348
349
350
        m_ignoreChange = true;
        m_workingDirectoryEdit->setPath(QDir::toNativeSeparators(m_qt4RunConfiguration->workingDirectory()));
        m_ignoreChange = false;
351
    }
352
353
}

354
void Qt4RunConfigurationWidget::showEvent(QShowEvent *event)
355
{
356
357
358
    m_isShown = true;
    effectiveTargetInformationChanged();
    QWidget::showEvent(event);
359
360
}

361
362
363
364
365
void Qt4RunConfigurationWidget::hideEvent(QHideEvent *event)
{
    m_isShown = false;
    QWidget::hideEvent(event);
}
366

367
////// TODO c&p above
368
369
370
QWidget *Qt4RunConfiguration::configurationWidget()
{
    return new Qt4RunConfigurationWidget(this, 0);
con's avatar
con committed
371
372
373
374
}

void Qt4RunConfiguration::save(PersistentSettingsWriter &writer) const
{
375
    const QDir projectDir = QFileInfo(project()->file()->fileName()).absoluteDir();
con's avatar
con committed
376
    writer.saveValue("CommandLineArguments", m_commandLineArguments);
377
    writer.saveValue("ProFile", projectDir.relativeFilePath(m_proFilePath));
con's avatar
con committed
378
    writer.saveValue("UserSetName", m_userSetName);
379
    writer.saveValue("UseTerminal", m_runMode == Console);
380
    writer.saveValue("UseDyldImageSuffix", m_isUsingDyldImageSuffix);
381
    writer.saveValue("UserEnvironmentChanges", ProjectExplorer::EnvironmentItem::toStringList(m_userEnvironmentChanges));
382
    writer.saveValue("BaseEnvironmentBase", m_baseEnvironmentBase);
con's avatar
con committed
383
384
385
386
    ApplicationRunConfiguration::save(writer);
}

void Qt4RunConfiguration::restore(const PersistentSettingsReader &reader)
387
{    
con's avatar
con committed
388
    ApplicationRunConfiguration::restore(reader);
389
    const QDir projectDir = QFileInfo(project()->file()->fileName()).absoluteDir();
con's avatar
con committed
390
    m_commandLineArguments = reader.restoreValue("CommandLineArguments").toStringList();
391
    m_proFilePath = projectDir.filePath(reader.restoreValue("ProFile").toString());
con's avatar
con committed
392
    m_userSetName = reader.restoreValue("UserSetName").toBool();
393
    m_runMode = reader.restoreValue("UseTerminal").toBool() ? Console : Gui;
394
    m_isUsingDyldImageSuffix = reader.restoreValue("UseDyldImageSuffix").toBool();
con's avatar
con committed
395
    if (!m_proFilePath.isEmpty()) {
396
        m_cachedTargetInformationValid = false;
con's avatar
con committed
397
        if (!m_userSetName)
398
            setName(QFileInfo(m_proFilePath).completeBaseName());
con's avatar
con committed
399
    }
400
    m_userEnvironmentChanges = ProjectExplorer::EnvironmentItem::fromStringList(reader.restoreValue("UserEnvironmentChanges").toStringList());
401
402
    QVariant tmp = reader.restoreValue("BaseEnvironmentBase");
    m_baseEnvironmentBase = tmp.isValid() ? BaseEnvironmentBase(tmp.toInt()) : Qt4RunConfiguration::BuildEnvironmentBase;
con's avatar
con committed
403
404
405
406
}

QString Qt4RunConfiguration::executable() const
{
407
408
    const_cast<Qt4RunConfiguration *>(this)->updateTarget();
    return m_executable;
con's avatar
con committed
409
410
411
412
413
414
415
}

ApplicationRunConfiguration::RunMode Qt4RunConfiguration::runMode() const
{
    return m_runMode;
}

416
417
418
419
420
421
422
423
424
425
426
bool Qt4RunConfiguration::isUsingDyldImageSuffix() const
{
    return m_isUsingDyldImageSuffix;
}

void Qt4RunConfiguration::setUsingDyldImageSuffix(bool state)
{
    m_isUsingDyldImageSuffix = state;
    emit usingDyldImageSuffixChanged(state);
}

con's avatar
con committed
427
428
QString Qt4RunConfiguration::workingDirectory() const
{
429
430
431
432
433
    // if the user overrode us, then return his working directory
    if (m_userSetWokingDirectory)
        return m_userWorkingDirectory;

    // else what the pro file reader tells us
434
435
    const_cast<Qt4RunConfiguration *>(this)->updateTarget();
    return m_workingDir;
con's avatar
con committed
436
437
438
439
440
441
442
}

QStringList Qt4RunConfiguration::commandLineArguments() const
{
    return m_commandLineArguments;
}

443
ProjectExplorer::Environment Qt4RunConfiguration::baseEnvironment() const
con's avatar
con committed
444
{
445
446
447
448
449
450
451
452
453
    ProjectExplorer::Environment env;
    if (m_baseEnvironmentBase == Qt4RunConfiguration::CleanEnvironmentBase) {
        // Nothing
    } else  if (m_baseEnvironmentBase == Qt4RunConfiguration::SystemEnvironmentBase) {
        env = ProjectExplorer::Environment::systemEnvironment();
    } else  if (m_baseEnvironmentBase == Qt4RunConfiguration::BuildEnvironmentBase) {
        QString config = project()->activeBuildConfiguration();
        env = project()->environment(project()->activeBuildConfiguration());
    }
454
455
456
457
    if (m_isUsingDyldImageSuffix) {
        env.set("DYLD_IMAGE_SUFFIX", "_debug");
    }
    return env;
con's avatar
con committed
458
459
}

460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
ProjectExplorer::Environment Qt4RunConfiguration::environment() const
{
    ProjectExplorer::Environment env = baseEnvironment();
    env.modify(userEnvironmentChanges());
    return env;
}

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

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

480
481
482
483
484
485
486
487
488
489
490
491
492
void Qt4RunConfiguration::setWorkingDirectory(const QString &wd)
{
    if (wd== "") {
        m_userSetWokingDirectory = false;
        m_userWorkingDirectory = QString::null;
        emit workingDirectoryChanged(workingDirectory());
    } else {
        m_userSetWokingDirectory = true;
        m_userWorkingDirectory = wd;
        emit workingDirectoryChanged(m_userWorkingDirectory);
    }
}

con's avatar
con committed
493
494
495
void Qt4RunConfiguration::setCommandLineArguments(const QString &argumentsString)
{
    m_commandLineArguments = ProjectExplorer::Environment::parseCombinedArgString(argumentsString);
496
    emit commandLineArgumentsChanged(argumentsString);
con's avatar
con committed
497
498
}

499
500
501
502
503
504
void Qt4RunConfiguration::setRunMode(RunMode runMode)
{
    m_runMode = runMode;
    emit runModeChanged(runMode);
}

con's avatar
con committed
505
506
507
508
509
510
511
512
513
void Qt4RunConfiguration::nameEdited(const QString &name)
{
    if (name == "") {
        setName(tr("Qt4RunConfiguration"));
        m_userSetName = false;
    } else {
        setName(name);
        m_userSetName = true;
    }
514
    emit nameChanged(name);
con's avatar
con committed
515
516
517
518
519
520
521
}

QString Qt4RunConfiguration::proFilePath() const
{
    return m_proFilePath;
}

522
void Qt4RunConfiguration::updateTarget()
con's avatar
con committed
523
{
524
525
526
527
    if (m_cachedTargetInformationValid)
        return;
    //qDebug()<<"updateTarget";
    Qt4Project *pro = static_cast<Qt4Project *>(project());
528
    Qt4PriFileNode * priFileNode = static_cast<Qt4Project *>(project())->rootProjectNode()->findProFileFor(m_proFilePath);
529
530
531
532
533
534
535
    if (!priFileNode) {
        m_workingDir = QString::null;
        m_executable = QString::null;
        m_cachedTargetInformationValid = true;
        emit effectiveTargetInformationChanged();
        return;
    }
536
    ProFileReader *reader = priFileNode->createProFileReader();
537
    reader->setCumulative(false);
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
    reader->setQtVersion(pro->qtVersion(pro->activeBuildConfiguration()));

    // Find out what flags we pass on to qmake, this code is duplicated in the qmake step
    QtVersion::QmakeBuildConfig defaultBuildConfiguration = pro->qtVersion(pro->activeBuildConfiguration())->defaultBuildConfig();
    QtVersion::QmakeBuildConfig projectBuildConfiguration = QtVersion::QmakeBuildConfig(pro->qmakeStep()->value(pro->activeBuildConfiguration(), "buildConfiguration").toInt());
    QStringList addedUserConfigArguments;
    QStringList removedUserConfigArguments;
    if ((defaultBuildConfiguration & QtVersion::BuildAll) && !(projectBuildConfiguration & QtVersion::BuildAll))
        removedUserConfigArguments << "debug_and_release";
    if (!(defaultBuildConfiguration & QtVersion::BuildAll) && (projectBuildConfiguration & QtVersion::BuildAll))
        addedUserConfigArguments << "debug_and_release";
    if ((defaultBuildConfiguration & QtVersion::DebugBuild) && !(projectBuildConfiguration & QtVersion::DebugBuild))
        addedUserConfigArguments << "release";
    if (!(defaultBuildConfiguration & QtVersion::DebugBuild) && (projectBuildConfiguration & QtVersion::DebugBuild))
        addedUserConfigArguments << "debug";

    reader->setUserConfigCmdArgs(addedUserConfigArguments, removedUserConfigArguments);

con's avatar
con committed
556
557
    if (!reader->readProFile(m_proFilePath)) {
        delete reader;
558
        Core::ICore::instance()->messageManager()->printToOutputPane(tr("Could not parse %1. The Qt4 run configuration %2 can not be started.").arg(m_proFilePath).arg(name()));
con's avatar
con committed
559
560
561
        return;
    }

562
    // Extract data
563
564
565
566
    QDir baseProjectDirectory = QFileInfo(project()->file()->fileName()).absoluteDir();
    QString relSubDir = baseProjectDirectory.relativeFilePath(QFileInfo(m_proFilePath).path());
    QDir baseBuildDirectory = project()->buildDirectory(project()->activeBuildConfiguration());
    QString baseDir = baseBuildDirectory.absoluteFilePath(relSubDir);
con's avatar
con committed
567

568
569
570
    //qDebug()<<relSubDir<<baseDir;

    // Working Directory
con's avatar
con committed
571
    if (reader->contains("DESTDIR")) {
572
573
574
575
576
        //qDebug()<<"reader contains destdir:"<<reader->value("DESTDIR");
        m_workingDir = reader->value("DESTDIR");
        if (QDir::isRelativePath(m_workingDir)) {
            m_workingDir = baseDir + QLatin1Char('/') + m_workingDir;
            //qDebug()<<"was relative and expanded to"<<m_workingDir;
con's avatar
con committed
577
578
        }
    } else {
579
580
        //qDebug()<<"reader didn't contain DESTDIR, setting to "<<baseDir;
        m_workingDir = baseDir;
581
582
583
584
585
586
587
        if (reader->values("CONFIG").contains("debug_and_release")) {
            QString qmakeBuildConfig = "release";
            if (projectBuildConfiguration & QtVersion::DebugBuild)
                qmakeBuildConfig = "debug";
            if (!reader->contains("DESTDIR"))
                m_workingDir += QLatin1Char('/') + qmakeBuildConfig;
        }
con's avatar
con committed
588
589
590
    }

#if defined (Q_OS_MAC)
con's avatar
con committed
591
    if (reader->values("CONFIG").contains("app_bundle")) {
dt's avatar
dt committed
592
        m_workingDir += QLatin1Char('/')
con's avatar
con committed
593
                   + reader->value("TARGET")
con's avatar
con committed
594
595
596
                   + QLatin1String(".app/Contents/MacOS");
    }
#endif
597
598
599
600

    m_workingDir = QDir::cleanPath(m_workingDir);
    m_executable = QDir::cleanPath(m_workingDir + QLatin1Char('/') + reader->value("TARGET"));
    //qDebug()<<"##### updateTarget sets:"<<m_workingDir<<m_executable;
con's avatar
con committed
601
602
603
604
605
606

#if defined (Q_OS_WIN)
    m_executable += QLatin1String(".exe");
#endif

    delete reader;
607

608
    m_cachedTargetInformationValid = true;
con's avatar
con committed
609

610
    emit effectiveTargetInformationChanged();
con's avatar
con committed
611
612
}

613
void Qt4RunConfiguration::invalidateCachedTargetInformation()
con's avatar
con committed
614
{
615
616
    m_cachedTargetInformationValid = false;
    emit effectiveTargetInformationChanged();
con's avatar
con committed
617
618
}

619
620
621
622
QString Qt4RunConfiguration::dumperLibrary() const
{
    Qt4Project *pro = qobject_cast<Qt4Project *>(project());
    QtVersion *version = pro->qtVersion(pro->activeBuildConfiguration());
623
    return version->debuggingHelperLibrary();
624
625
}

626
627
628
629
630
631
632
633
634
635
636
637
void Qt4RunConfiguration::setBaseEnvironmentBase(BaseEnvironmentBase env)
{
    if (m_baseEnvironmentBase == env)
        return;
    m_baseEnvironmentBase = env;
    emit baseEnvironmentChanged();
}

Qt4RunConfiguration::BaseEnvironmentBase Qt4RunConfiguration::baseEnvironmentBase() const
{
    return m_baseEnvironmentBase;
}
638
639
640
ProjectExplorer::ToolChain::ToolChainType Qt4RunConfiguration::toolChainType() const
{
    Qt4Project *pro = qobject_cast<Qt4Project *>(project());
con's avatar
con committed
641
    return pro->toolChainType(pro->activeBuildConfiguration());
642
}
643

con's avatar
con committed
644
645
646
647
648
649
650
651
652
653
654
655
656
657
///
/// Qt4RunConfigurationFactory
/// This class is used to restore run settings (saved in .user files)
///

Qt4RunConfigurationFactory::Qt4RunConfigurationFactory()
{
}

Qt4RunConfigurationFactory::~Qt4RunConfigurationFactory()
{
}

// used to recreate the runConfigurations when restoring settings
con's avatar
con committed
658
bool Qt4RunConfigurationFactory::canRestore(const QString &type) const
con's avatar
con committed
659
660
661
662
{
    return type == "Qt4ProjectManager.Qt4RunConfiguration";
}

hjk's avatar
hjk committed
663
664
QSharedPointer<ProjectExplorer::RunConfiguration> Qt4RunConfigurationFactory::create
    (ProjectExplorer::Project *project, const QString &type)
con's avatar
con committed
665
666
{
    Qt4Project *p = qobject_cast<Qt4Project *>(project);
dt's avatar
dt committed
667
    Q_ASSERT(p);
con's avatar
con committed
668
669
670
671
    if (type.startsWith("Qt4RunConfiguration.")) {
        QString fileName = type.mid(QString("Qt4RunConfiguration.").size());
        return QSharedPointer<ProjectExplorer::RunConfiguration>(new Qt4RunConfiguration(p, fileName));
    }
dt's avatar
dt committed
672
    Q_ASSERT(type == "Qt4ProjectManager.Qt4RunConfiguration");
con's avatar
con committed
673
674
675
676
677
    // The right path is set in restoreSettings
    QSharedPointer<ProjectExplorer::RunConfiguration> rc(new Qt4RunConfiguration(p, QString::null));
    return rc;
}

con's avatar
con committed
678
QStringList Qt4RunConfigurationFactory::availableCreationTypes(ProjectExplorer::Project *pro) const
con's avatar
con committed
679
680
681
682
683
{
    Qt4Project *qt4project = qobject_cast<Qt4Project *>(pro);
    if (qt4project) {
        QStringList applicationProFiles;
        QList<Qt4ProFileNode *> list = qt4project->applicationProFiles();
hjk's avatar
hjk committed
684
        foreach (Qt4ProFileNode * node, list) {
con's avatar
con committed
685
686
687
688
689
690
691
692
            applicationProFiles.append("Qt4RunConfiguration." + node->path());
        }
        return applicationProFiles;
    } else {
        return QStringList();
    }
}

con's avatar
con committed
693
QString Qt4RunConfigurationFactory::displayNameForType(const QString &type) const
con's avatar
con committed
694
695
{
    QString fileName = type.mid(QString("Qt4RunConfiguration.").size());
696
    return QFileInfo(fileName).completeBaseName();
con's avatar
con committed
697
}