qt4runconfiguration.cpp 27.9 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 "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"
Tobias Hunger's avatar
Tobias Hunger committed
36
#include "qt4target.h"
37
#include "qt4buildconfiguration.h"
38
#include "qt4projectmanagerconstants.h"
dt's avatar
dt committed
39
#include "qtoutputformatter.h"
con's avatar
con committed
40

41
#include <coreplugin/coreconstants.h>
con's avatar
con committed
42
43
44
#include <coreplugin/icore.h>
#include <coreplugin/messagemanager.h>
#include <coreplugin/variablemanager.h>
45
#include <coreplugin/ifile.h>
con's avatar
con committed
46
#include <projectexplorer/buildstep.h>
47
#include <projectexplorer/environmenteditmodel.h>
48
#include <projectexplorer/persistentsettings.h>
hjk's avatar
hjk committed
49
#include <utils/qtcassert.h>
50
#include <utils/qtcprocess.h>
51
52
#include <utils/pathchooser.h>
#include <utils/detailswidget.h>
53
#include <utils/debuggerlanguagechooser.h>
con's avatar
con committed
54
55
56

#include <QtGui/QFormLayout>
#include <QtGui/QInputDialog>
57
#include <QtGui/QLabel>
58
#include <QtGui/QLineEdit>
59
#include <QtGui/QCheckBox>
60
#include <QtGui/QToolButton>
61
#include <QtGui/QComboBox>
con's avatar
con committed
62
63
64

using namespace Qt4ProjectManager::Internal;
using namespace Qt4ProjectManager;
65
using ProjectExplorer::LocalApplicationRunConfiguration;
con's avatar
con committed
66
67
68
using ProjectExplorer::PersistentSettingsReader;
using ProjectExplorer::PersistentSettingsWriter;

69
70
71
72
73
74
75
76
77
78
79
80
81
namespace {
const char * const QT4_RC_ID("Qt4ProjectManager.Qt4RunConfiguration");
const char * const QT4_RC_PREFIX("Qt4ProjectManager.Qt4RunConfiguration.");

const char * const COMMAND_LINE_ARGUMENTS_KEY("Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments");
const char * const PRO_FILE_KEY("Qt4ProjectManager.Qt4RunConfiguration.ProFile");
const char * const USE_TERMINAL_KEY("Qt4ProjectManager.Qt4RunConfiguration.UseTerminal");
const char * const USE_DYLD_IMAGE_SUFFIX_KEY("Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix");
const char * const USER_ENVIRONMENT_CHANGES_KEY("Qt4ProjectManager.Qt4RunConfiguration.UserEnvironmentChanges");
const char * const BASE_ENVIRONMENT_BASE_KEY("Qt4ProjectManager.Qt4RunConfiguration.BaseEnvironmentBase");
const char * const USER_WORKING_DIRECTORY_KEY("Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory");

QString pathFromId(const QString &id)
con's avatar
con committed
82
{
83
84
85
86
    if (!id.startsWith(QLatin1String(QT4_RC_PREFIX)))
        return QString();
    return id.mid(QString::fromLatin1(QT4_RC_PREFIX).size());
}
87

88
89
90
91
QString pathToId(const QString &path)
{
    return QString::fromLatin1(QT4_RC_PREFIX) + path;
}
92

93
} // namespace
94

95
96
97
98
//
// Qt4RunConfiguration
//

Tobias Hunger's avatar
Tobias Hunger committed
99
Qt4RunConfiguration::Qt4RunConfiguration(Qt4Target *parent, const QString &proFilePath) :
100
101
102
103
    LocalApplicationRunConfiguration(parent, QLatin1String(QT4_RC_ID)),
    m_proFilePath(proFilePath),
    m_runMode(Gui),
    m_isUsingDyldImageSuffix(false),
104
    m_baseEnvironmentBase(Qt4RunConfiguration::BuildEnvironmentBase),
105
    m_parseSuccess(parent->qt4Project()->validParse(m_proFilePath))
106
107
{
    ctor();
con's avatar
con committed
108
109
}

Tobias Hunger's avatar
Tobias Hunger committed
110
Qt4RunConfiguration::Qt4RunConfiguration(Qt4Target *parent, Qt4RunConfiguration *source) :
111
112
113
114
115
116
117
    LocalApplicationRunConfiguration(parent, source),
    m_commandLineArguments(source->m_commandLineArguments),
    m_proFilePath(source->m_proFilePath),
    m_runMode(source->m_runMode),
    m_isUsingDyldImageSuffix(source->m_isUsingDyldImageSuffix),
    m_userWorkingDirectory(source->m_userWorkingDirectory),
    m_userEnvironmentChanges(source->m_userEnvironmentChanges),
118
119
    m_baseEnvironmentBase(source->m_baseEnvironmentBase),
    m_parseSuccess(source->m_parseSuccess)
con's avatar
con committed
120
{
121
    ctor();
con's avatar
con committed
122
123
}

124
Qt4RunConfiguration::~Qt4RunConfiguration()
dt's avatar
dt committed
125
126
127
{
}

Tobias Hunger's avatar
Tobias Hunger committed
128
Qt4Target *Qt4RunConfiguration::qt4Target() const
con's avatar
con committed
129
{
Tobias Hunger's avatar
Tobias Hunger committed
130
    return static_cast<Qt4Target *>(target());
con's avatar
con committed
131
132
}

133
bool Qt4RunConfiguration::isEnabled(ProjectExplorer::BuildConfiguration *configuration) const
134
{
135
136
    if (!m_parseSuccess)
        return false;
137
    return true;
138
}
139

140
void Qt4RunConfiguration::handleParseState(bool success)
141
{
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
    bool enabled = isEnabled();
    m_parseSuccess = success;
    if (enabled != isEnabled())
        emit isEnabledChanged(!enabled);
}

void Qt4RunConfiguration::proFileUpdated(Qt4ProjectManager::Internal::Qt4ProFileNode *pro, bool success)
{
    if (m_proFilePath != pro->path())
        return;
    handleParseState(success);
    emit effectiveTargetInformationChanged();
}

void Qt4RunConfiguration::proFileInvalidated(Qt4ProjectManager::Internal::Qt4ProFileNode *pro)
{
Tobias Hunger's avatar
Tobias Hunger committed
158
    Q_UNUSED(pro);
159
    handleParseState(false);
160
161
}

162
163
void Qt4RunConfiguration::ctor()
{
164
    setDefaultDisplayName(defaultDisplayName());
165

Tobias Hunger's avatar
Tobias Hunger committed
166
    connect(qt4Target(), SIGNAL(environmentChanged()),
167
            this, SIGNAL(baseEnvironmentChanged()));
168
169
    connect(qt4Target()->qt4Project(), SIGNAL(proFileUpdated(Qt4ProjectManager::Internal::Qt4ProFileNode*,bool)),
            this, SLOT(proFileUpdated(Qt4ProjectManager::Internal::Qt4ProFileNode*,bool)));
170

171
172
    connect(qt4Target()->qt4Project(), SIGNAL(proFileInvalidated(Qt4ProjectManager::Internal::Qt4ProFileNode*)),
            this, SLOT(proFileInvalidated(Qt4ProjectManager::Internal::Qt4ProFileNode*)));
173
174
}

175
176
177
178
179
//////
/// Qt4RunConfigurationWidget
/////

Qt4RunConfigurationWidget::Qt4RunConfigurationWidget(Qt4RunConfiguration *qt4RunConfiguration, QWidget *parent)
180
181
182
    : QWidget(parent),
    m_qt4RunConfiguration(qt4RunConfiguration),
    m_ignoreChange(false),
mae's avatar
mae committed
183
184
    m_usingDyldImageSuffix(0),
    m_isShown(false)
con's avatar
con committed
185
{
dt's avatar
dt committed
186
187
188
189
    QVBoxLayout *vboxTopLayout = new QVBoxLayout(this);
    vboxTopLayout->setMargin(0);

    m_detailsContainer = new Utils::DetailsWidget(this);
190
    m_detailsContainer->setState(Utils::DetailsWidget::NoSummary);
dt's avatar
dt committed
191
192
193
194
    vboxTopLayout->addWidget(m_detailsContainer);
    QWidget *detailsWidget = new QWidget(m_detailsContainer);
    m_detailsContainer->setWidget(detailsWidget);
    QFormLayout *toplayout = new QFormLayout(detailsWidget);
con's avatar
con committed
195
    toplayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
con's avatar
con committed
196
197
    toplayout->setMargin(0);

198
199
200
    m_executableLineEdit = new QLineEdit(m_qt4RunConfiguration->executable(), this);
    m_executableLineEdit->setEnabled(false);
    toplayout->addRow(tr("Executable:"), m_executableLineEdit);
con's avatar
con committed
201

Tobias Hunger's avatar
Tobias Hunger committed
202
    QLabel *argumentsLabel = new QLabel(tr("Arguments:"), this);
203
    m_argumentsLineEdit = new QLineEdit(qt4RunConfiguration->rawCommandLineArguments(), this);
204
205
206
    argumentsLabel->setBuddy(m_argumentsLineEdit);
    toplayout->addRow(argumentsLabel, m_argumentsLineEdit);

Tobias Hunger's avatar
Tobias Hunger committed
207
    m_workingDirectoryEdit = new Utils::PathChooser(this);
208
    m_workingDirectoryEdit->setPath(m_qt4RunConfiguration->baseWorkingDirectory());
209
    m_workingDirectoryEdit->setBaseDirectory(m_qt4RunConfiguration->target()->project()->projectDirectory());
210
    m_workingDirectoryEdit->setExpectedKind(Utils::PathChooser::Directory);
211
    m_workingDirectoryEdit->setEnvironment(m_qt4RunConfiguration->environment());
212
    m_workingDirectoryEdit->setPromptDialogTitle(tr("Select Working Directory"));
213

Tobias Hunger's avatar
Tobias Hunger committed
214
    QToolButton *resetButton = new QToolButton(this);
215
    resetButton->setToolTip(tr("Reset to default"));
216
    resetButton->setIcon(QIcon(QLatin1String(Core::Constants::ICON_RESET)));
217
218

    QHBoxLayout *boxlayout = new QHBoxLayout();
219
    boxlayout->setMargin(0);
220
221
    boxlayout->addWidget(m_workingDirectoryEdit);
    boxlayout->addWidget(resetButton);
222
    toplayout->addRow(tr("Working directory:"), boxlayout);
con's avatar
con committed
223

224
    m_useTerminalCheck = new QCheckBox(tr("Run in terminal"), this);
225
    m_useTerminalCheck->setChecked(m_qt4RunConfiguration->runMode() == ProjectExplorer::LocalApplicationRunConfiguration::Console);
226
227
    toplayout->addRow(QString(), m_useTerminalCheck);

228
229
230
231
232
    QWidget *debuggerLabelWidget = new QWidget(this);
    QVBoxLayout *debuggerLabelLayout = new QVBoxLayout(debuggerLabelWidget);
    debuggerLabelLayout->setMargin(0);
    debuggerLabelLayout->setSpacing(0);
    debuggerLabelWidget->setLayout(debuggerLabelLayout);
233
    QLabel *debuggerLabel = new QLabel(tr("Debugger:"), this);
234
235
236
    debuggerLabelLayout->addWidget(debuggerLabel);
    debuggerLabelLayout->addStretch(10);

237
    m_debuggerLanguageChooser = new Utils::DebuggerLanguageChooser(this);
238
    toplayout->addRow(debuggerLabelWidget, m_debuggerLanguageChooser);
239
240
241

    m_debuggerLanguageChooser->setCppChecked(m_qt4RunConfiguration->useCppDebugger());
    m_debuggerLanguageChooser->setQmlChecked(m_qt4RunConfiguration->useQmlDebugger());
242
    m_debuggerLanguageChooser->setQmlDebugServerPort(m_qt4RunConfiguration->qmlDebugServerPort());
243

244
#ifdef Q_OS_MAC
Tobias Hunger's avatar
Tobias Hunger committed
245
    m_usingDyldImageSuffix = new QCheckBox(tr("Use debug version of frameworks (DYLD_IMAGE_SUFFIX=_debug)"), this);
246
247
248
249
250
251
    m_usingDyldImageSuffix->setChecked(m_qt4RunConfiguration->isUsingDyldImageSuffix());
    toplayout->addRow(QString(), m_usingDyldImageSuffix);
    connect(m_usingDyldImageSuffix, SIGNAL(toggled(bool)),
            this, SLOT(usingDyldImageSuffixToggled(bool)));
#endif

252
253
254
255
256
257
    QLabel *environmentLabel = new QLabel(this);
    environmentLabel->setText(tr("Run Environment"));
    QFont f = environmentLabel->font();
    f.setBold(true);
    f.setPointSizeF(f.pointSizeF() *1.2);
    environmentLabel->setFont(f);
dt's avatar
dt committed
258
    vboxTopLayout->addWidget(environmentLabel);
259

Tobias Hunger's avatar
Tobias Hunger committed
260
    QWidget *baseEnvironmentWidget = new QWidget(this);
261
262
    QHBoxLayout *baseEnvironmentLayout = new QHBoxLayout(baseEnvironmentWidget);
    baseEnvironmentLayout->setMargin(0);
263
    QLabel *label = new QLabel(tr("Base environment for this runconfiguration:"), this);
264
    baseEnvironmentLayout->addWidget(label);
265
    m_baseEnvironmentComboBox = new QComboBox(this);
266
267
268
269
270
271
    m_baseEnvironmentComboBox->addItems(QStringList()
                                        << tr("Clean Environment")
                                        << tr("System Environment")
                                        << tr("Build Environment"));
    m_baseEnvironmentComboBox->setCurrentIndex(qt4RunConfiguration->baseEnvironmentBase());
    connect(m_baseEnvironmentComboBox, SIGNAL(currentIndexChanged(int)),
272
            this, SLOT(baseEnvironmentSelected(int)));
273
274
    baseEnvironmentLayout->addWidget(m_baseEnvironmentComboBox);
    baseEnvironmentLayout->addStretch(10);
dt's avatar
dt committed
275

276
    m_environmentWidget = new ProjectExplorer::EnvironmentWidget(this, baseEnvironmentWidget);
277
    m_environmentWidget->setBaseEnvironment(m_qt4RunConfiguration->baseEnvironment());
278
    m_environmentWidget->setBaseEnvironmentText(m_qt4RunConfiguration->baseEnvironmentText());
279
    m_environmentWidget->setUserChanges(m_qt4RunConfiguration->userEnvironmentChanges());
dt's avatar
dt committed
280
    m_environmentWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
dt's avatar
dt committed
281
    vboxTopLayout->addWidget(m_environmentWidget);
282

283
284
    setEnabled(m_qt4RunConfiguration->isEnabled());

con's avatar
con committed
285
    connect(m_workingDirectoryEdit, SIGNAL(changed(QString)),
286
            this, SLOT(workDirectoryEdited()));
287
288

    connect(resetButton, SIGNAL(clicked()),
289
            this, SLOT(workingDirectoryReseted()));
290

291
    connect(m_argumentsLineEdit, SIGNAL(textEdited(QString)),
292
            this, SLOT(argumentsEdited(QString)));
293
294
295
    connect(m_useTerminalCheck, SIGNAL(toggled(bool)),
            this, SLOT(termToggled(bool)));

296
297
298
299
    connect(m_debuggerLanguageChooser, SIGNAL(cppLanguageToggled(bool)),
            this, SLOT(useCppDebuggerToggled(bool)));
    connect(m_debuggerLanguageChooser, SIGNAL(qmlLanguageToggled(bool)),
            this, SLOT(useQmlDebuggerToggled(bool)));
300
301
    connect(m_debuggerLanguageChooser, SIGNAL(qmlDebugServerPortChanged(uint)),
            this, SLOT(qmlDebugServerPortChanged(uint)));
302

303
304
    connect(m_environmentWidget, SIGNAL(userChangesChanged()),
            this, SLOT(userChangesEdited()));
305

306
    connect(qt4RunConfiguration, SIGNAL(baseWorkingDirectoryChanged(QString)),
307
308
            this, SLOT(workingDirectoryChanged(QString)));

309
    connect(qt4RunConfiguration, SIGNAL(commandLineArgumentsChanged(QString)),
310
            this, SLOT(commandLineArgumentsChanged(QString)));
311
312
    connect(qt4RunConfiguration, SIGNAL(runModeChanged(ProjectExplorer::LocalApplicationRunConfiguration::RunMode)),
            this, SLOT(runModeChanged(ProjectExplorer::LocalApplicationRunConfiguration::RunMode)));
313
314
    connect(qt4RunConfiguration, SIGNAL(usingDyldImageSuffixChanged(bool)),
            this, SLOT(usingDyldImageSuffixChanged(bool)));
315
316
    connect(qt4RunConfiguration, SIGNAL(effectiveTargetInformationChanged()),
            this, SLOT(effectiveTargetInformationChanged()), Qt::QueuedConnection);
317

318
319
    connect(qt4RunConfiguration, SIGNAL(userEnvironmentChangesChanged(QList<Utils::EnvironmentItem>)),
            this, SLOT(userEnvironmentChangesChanged(QList<Utils::EnvironmentItem>)));
320

321
322
    connect(qt4RunConfiguration, SIGNAL(baseEnvironmentChanged()),
            this, SLOT(baseEnvironmentChanged()));
323
324
325

    connect(qt4RunConfiguration, SIGNAL(isEnabledChanged(bool)),
            this, SLOT(runConfigurationEnabledChange(bool)));
326
327

    setEnabled(qt4RunConfiguration->isEnabled());
328
329
}

Tobias Hunger's avatar
Tobias Hunger committed
330
331
332
333
Qt4RunConfigurationWidget::~Qt4RunConfigurationWidget()
{
}

334
335
336
337
338
339
340
341
342
343
void Qt4RunConfigurationWidget::useCppDebuggerToggled(bool toggled)
{
    m_qt4RunConfiguration->setUseCppDebugger(toggled);
}

void Qt4RunConfigurationWidget::useQmlDebuggerToggled(bool toggled)
{
    m_qt4RunConfiguration->setUseQmlDebugger(toggled);
}

344
345
346
347
348
void Qt4RunConfigurationWidget::qmlDebugServerPortChanged(uint port)
{
    m_qt4RunConfiguration->setQmlDebugServerPort(port);
}

349
void Qt4RunConfigurationWidget::baseEnvironmentSelected(int index)
350
351
{
    m_ignoreChange = true;
352
    m_qt4RunConfiguration->setBaseEnvironmentBase(Qt4RunConfiguration::BaseEnvironmentBase(index));
353
354

    m_environmentWidget->setBaseEnvironment(m_qt4RunConfiguration->baseEnvironment());
355
    m_environmentWidget->setBaseEnvironmentText(m_qt4RunConfiguration->baseEnvironmentText());
356
357
358
    m_ignoreChange = false;
}

359
360
void Qt4RunConfigurationWidget::baseEnvironmentChanged()
{
361
362
363
    if (m_ignoreChange)
        return;

364
    m_baseEnvironmentComboBox->setCurrentIndex(m_qt4RunConfiguration->baseEnvironmentBase());
365
    m_environmentWidget->setBaseEnvironment(m_qt4RunConfiguration->baseEnvironment());
366
    m_environmentWidget->setBaseEnvironmentText(m_qt4RunConfiguration->baseEnvironmentText());
367
368
}

369
void Qt4RunConfigurationWidget::userEnvironmentChangesChanged(const QList<Utils::EnvironmentItem> &userChanges)
370
371
372
373
374
375
{
    if (m_ignoreChange)
        return;
    m_environmentWidget->setUserChanges(userChanges);
}

376
void Qt4RunConfigurationWidget::userChangesEdited()
377
378
379
380
{
    m_ignoreChange = true;
    m_qt4RunConfiguration->setUserEnvironmentChanges(m_environmentWidget->userChanges());
    m_ignoreChange = false;
381
382
}

383
384
385
386
387
void Qt4RunConfigurationWidget::runConfigurationEnabledChange(bool enabled)
{
    setEnabled(enabled);
}

388
void Qt4RunConfigurationWidget::workDirectoryEdited()
389
390
391
392
{
    if (m_ignoreChange)
        return;
    m_ignoreChange = true;
393
    m_qt4RunConfiguration->setBaseWorkingDirectory(m_workingDirectoryEdit->rawPath());
394
395
396
    m_ignoreChange = false;
}

397
void Qt4RunConfigurationWidget::workingDirectoryReseted()
398
399
400
{
    // This emits a signal connected to workingDirectoryChanged()
    // that sets the m_workingDirectoryEdit
401
    m_qt4RunConfiguration->setBaseWorkingDirectory("");
402
403
}

404
void Qt4RunConfigurationWidget::argumentsEdited(const QString &args)
405
406
{
    m_ignoreChange = true;
407
    m_qt4RunConfiguration->setCommandLineArguments(args);
408
409
410
    m_ignoreChange = false;
}

411
412
413
void Qt4RunConfigurationWidget::termToggled(bool on)
{
    m_ignoreChange = true;
414
415
    m_qt4RunConfiguration->setRunMode(on ? LocalApplicationRunConfiguration::Console
                                         : LocalApplicationRunConfiguration::Gui);
416
417
418
    m_ignoreChange = false;
}

419
420
421
422
423
424
425
void Qt4RunConfigurationWidget::usingDyldImageSuffixToggled(bool state)
{
    m_ignoreChange = true;
    m_qt4RunConfiguration->setUsingDyldImageSuffix(state);
    m_ignoreChange = false;
}

426
427
428
429
430
431
void Qt4RunConfigurationWidget::workingDirectoryChanged(const QString &workingDirectory)
{
    if (!m_ignoreChange)
        m_workingDirectoryEdit->setPath(workingDirectory);
}

432
433
void Qt4RunConfigurationWidget::commandLineArgumentsChanged(const QString &args)
{
dt's avatar
dt committed
434
435
436
    if (m_ignoreChange)
        return;
    m_argumentsLineEdit->setText(args);
437
438
}

439
void Qt4RunConfigurationWidget::runModeChanged(LocalApplicationRunConfiguration::RunMode runMode)
440
441
{
    if (!m_ignoreChange)
442
        m_useTerminalCheck->setChecked(runMode == LocalApplicationRunConfiguration::Console);
443
444
}

445
446
447
448
449
450
void Qt4RunConfigurationWidget::usingDyldImageSuffixChanged(bool state)
{
    if (!m_ignoreChange && m_usingDyldImageSuffix)
        m_usingDyldImageSuffix->setChecked(state);
}

451
void Qt4RunConfigurationWidget::effectiveTargetInformationChanged()
452
{
453
    if (m_isShown) {
454
        m_executableLineEdit->setText(QDir::toNativeSeparators(m_qt4RunConfiguration->executable()));
455
        m_ignoreChange = true;
456
        m_workingDirectoryEdit->setPath(QDir::toNativeSeparators(m_qt4RunConfiguration->baseWorkingDirectory()));
457
        m_ignoreChange = false;
458
    }
459
460
}

461
void Qt4RunConfigurationWidget::showEvent(QShowEvent *event)
462
{
463
464
465
    m_isShown = true;
    effectiveTargetInformationChanged();
    QWidget::showEvent(event);
466
467
}

468
469
470
471
472
void Qt4RunConfigurationWidget::hideEvent(QHideEvent *event)
{
    m_isShown = false;
    QWidget::hideEvent(event);
}
473

474
////// TODO c&p above
475
QWidget *Qt4RunConfiguration::createConfigurationWidget()
476
477
{
    return new Qt4RunConfigurationWidget(this, 0);
con's avatar
con committed
478
479
}

480
QVariantMap Qt4RunConfiguration::toMap() const
con's avatar
con committed
481
{
482
    const QDir projectDir = QDir(target()->project()->projectDirectory());
483
484
485
486
487
    QVariantMap map(LocalApplicationRunConfiguration::toMap());
    map.insert(QLatin1String(COMMAND_LINE_ARGUMENTS_KEY), m_commandLineArguments);
    map.insert(QLatin1String(PRO_FILE_KEY), projectDir.relativeFilePath(m_proFilePath));
    map.insert(QLatin1String(USE_TERMINAL_KEY), m_runMode == Console);
    map.insert(QLatin1String(USE_DYLD_IMAGE_SUFFIX_KEY), m_isUsingDyldImageSuffix);
488
    map.insert(QLatin1String(USER_ENVIRONMENT_CHANGES_KEY), Utils::EnvironmentItem::toStringList(m_userEnvironmentChanges));
489
490
491
    map.insert(QLatin1String(BASE_ENVIRONMENT_BASE_KEY), m_baseEnvironmentBase);
    map.insert(QLatin1String(USER_WORKING_DIRECTORY_KEY), m_userWorkingDirectory);
    return map;
con's avatar
con committed
492
493
}

494
bool Qt4RunConfiguration::fromMap(const QVariantMap &map)
495
{
496
    const QDir projectDir = QDir(target()->project()->projectDirectory());
497
    m_commandLineArguments = map.value(QLatin1String(COMMAND_LINE_ARGUMENTS_KEY)).toString();
498
499
500
501
502
503
    m_proFilePath = projectDir.filePath(map.value(QLatin1String(PRO_FILE_KEY)).toString());
    m_runMode = map.value(QLatin1String(USE_TERMINAL_KEY), false).toBool() ? Console : Gui;
    m_isUsingDyldImageSuffix = map.value(QLatin1String(USE_DYLD_IMAGE_SUFFIX_KEY), false).toBool();

    m_userWorkingDirectory = map.value(QLatin1String(USER_WORKING_DIRECTORY_KEY)).toString();

504
    m_userEnvironmentChanges = Utils::EnvironmentItem::fromStringList(map.value(QLatin1String(USER_ENVIRONMENT_CHANGES_KEY)).toStringList());
505
506
    m_baseEnvironmentBase = static_cast<BaseEnvironmentBase>(map.value(QLatin1String(BASE_ENVIRONMENT_BASE_KEY), static_cast<int>(Qt4RunConfiguration::BuildEnvironmentBase)).toInt());

507
508
    m_parseSuccess = qt4Target()->qt4Project()->validParse(m_proFilePath);

509
    return RunConfiguration::fromMap(map);
con's avatar
con committed
510
511
512
513
}

QString Qt4RunConfiguration::executable() const
{
dt's avatar
dt committed
514
515
516
517
518
    Qt4Project *pro = qt4Target()->qt4Project();
    TargetInformation ti = pro->rootProjectNode()->targetInformation(m_proFilePath);
    if (!ti.valid)
        return QString();
    return ti.executable;
con's avatar
con committed
519
520
}

521
LocalApplicationRunConfiguration::RunMode Qt4RunConfiguration::runMode() const
con's avatar
con committed
522
523
524
525
{
    return m_runMode;
}

526
527
528
529
530
531
532
533
534
535
536
bool Qt4RunConfiguration::isUsingDyldImageSuffix() const
{
    return m_isUsingDyldImageSuffix;
}

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

con's avatar
con committed
537
QString Qt4RunConfiguration::workingDirectory() const
538
{
539
540
    return QDir::cleanPath(environment().expandVariables(
                Utils::expandMacros(baseWorkingDirectory(), macroExpander())));
541
542
543
}

QString Qt4RunConfiguration::baseWorkingDirectory() const
con's avatar
con committed
544
{
545
    // if the user overrode us, then return his working directory
546
    if (!m_userWorkingDirectory.isEmpty())
547
548
549
        return m_userWorkingDirectory;

    // else what the pro file reader tells us
dt's avatar
dt committed
550
551
552
553
554
    Qt4Project *pro = qt4Target()->qt4Project();
    TargetInformation ti = pro->rootProjectNode()->targetInformation(m_proFilePath);
    if(!ti.valid)
        return QString();
    return ti.workingDir;
con's avatar
con committed
555
556
}

557
QString Qt4RunConfiguration::commandLineArguments() const
558
559
560
561
562
{
    return Utils::QtcProcess::expandMacros(m_commandLineArguments, macroExpander());
}

QString Qt4RunConfiguration::rawCommandLineArguments() const
con's avatar
con committed
563
564
565
566
{
    return m_commandLineArguments;
}

567
568
569
570
571
572
573
574
QString Qt4RunConfiguration::baseEnvironmentText() const
{
    if (m_baseEnvironmentBase == Qt4RunConfiguration::CleanEnvironmentBase)
        return tr("Clean Environment");
    else  if (m_baseEnvironmentBase == Qt4RunConfiguration::SystemEnvironmentBase)
        return tr("System Environment");
    else  if (m_baseEnvironmentBase == Qt4RunConfiguration::BuildEnvironmentBase)
        return tr("Build Environment");
575
    return QString();
576
577
}

578
Utils::Environment Qt4RunConfiguration::baseEnvironment() const
con's avatar
con committed
579
{
580
    Utils::Environment env;
581
582
583
    if (m_baseEnvironmentBase == Qt4RunConfiguration::CleanEnvironmentBase) {
        // Nothing
    } else  if (m_baseEnvironmentBase == Qt4RunConfiguration::SystemEnvironmentBase) {
584
        env = Utils::Environment::systemEnvironment();
585
    } else  if (m_baseEnvironmentBase == Qt4RunConfiguration::BuildEnvironmentBase) {
Tobias Hunger's avatar
Tobias Hunger committed
586
        env = target()->activeBuildConfiguration()->environment();
587
    }
588
589
590
    if (m_isUsingDyldImageSuffix) {
        env.set("DYLD_IMAGE_SUFFIX", "_debug");
    }
591
592
593
594
595

#ifdef Q_OS_WIN
    // On windows the user could be linking to a library found via a -L/some/dir switch
    // to find those libraries while actually running we explicitly prepend those
    // dirs to the path
596
    const Qt4ProFileNode *node = qt4Target()->qt4Project()->rootProjectNode()->findProFileFor(m_proFilePath);
597
598
599
600
    if (node)
        foreach(const QString dir, node->variableValue(LibDirectoriesVar))
            env.prependOrSetPath(dir);
#endif
601
    return env;
con's avatar
con committed
602
603
}

604
Utils::Environment Qt4RunConfiguration::environment() const
605
{
606
    Utils::Environment env = baseEnvironment();
607
608
609
610
    env.modify(userEnvironmentChanges());
    return env;
}

611
QList<Utils::EnvironmentItem> Qt4RunConfiguration::userEnvironmentChanges() const
612
613
614
615
{
    return m_userEnvironmentChanges;
}

616
void Qt4RunConfiguration::setUserEnvironmentChanges(const QList<Utils::EnvironmentItem> &diff)
617
618
619
620
621
622
623
{
    if (m_userEnvironmentChanges != diff) {
        m_userEnvironmentChanges = diff;
        emit userEnvironmentChangesChanged(diff);
    }
}

624
void Qt4RunConfiguration::setBaseWorkingDirectory(const QString &wd)
625
{
626
627
628
629
630
631
632
    const QString &oldWorkingDirectory = workingDirectory();

    m_userWorkingDirectory = wd;

    const QString &newWorkingDirectory = workingDirectory();
    if (oldWorkingDirectory != newWorkingDirectory)
        emit baseWorkingDirectoryChanged(newWorkingDirectory);
633
634
}

635
void Qt4RunConfiguration::setCommandLineArguments(const QString &argumentsString)
con's avatar
con committed
636
{
637
638
    m_commandLineArguments = argumentsString;
    emit commandLineArgumentsChanged(argumentsString);
con's avatar
con committed
639
640
}

641
642
643
644
645
646
void Qt4RunConfiguration::setRunMode(RunMode runMode)
{
    m_runMode = runMode;
    emit runModeChanged(runMode);
}

con's avatar
con committed
647
648
649
650
651
QString Qt4RunConfiguration::proFilePath() const
{
    return m_proFilePath;
}

652
653
QString Qt4RunConfiguration::dumperLibrary() const
{
Tobias Hunger's avatar
Tobias Hunger committed
654
655
    QtVersion *version = qt4Target()->activeBuildConfiguration()->qtVersion();
    if (version)
656
        return version->debuggingHelperLibrary();
657
    return QString();
658
659
}

660
661
QStringList Qt4RunConfiguration::dumperLibraryLocations() const
{
Tobias Hunger's avatar
Tobias Hunger committed
662
663
    QtVersion *version = qt4Target()->activeBuildConfiguration()->qtVersion();
    if (version)
664
        return version->debuggingHelperLibraryLocations();
665
    return QStringList();
666
667
}

668
QString Qt4RunConfiguration::defaultDisplayName()
669
{
670
    QString defaultName;
671
    if (!m_proFilePath.isEmpty())
672
        defaultName = QFileInfo(m_proFilePath).completeBaseName();
673
    else
674
675
        defaultName = tr("Qt4 RunConfiguration");
    return defaultName;
676
677
}

678
679
680
681
682
683
684
685
686
687
688
689
void Qt4RunConfiguration::setBaseEnvironmentBase(BaseEnvironmentBase env)
{
    if (m_baseEnvironmentBase == env)
        return;
    m_baseEnvironmentBase = env;
    emit baseEnvironmentChanged();
}

Qt4RunConfiguration::BaseEnvironmentBase Qt4RunConfiguration::baseEnvironmentBase() const
{
    return m_baseEnvironmentBase;
}
690
ProjectExplorer::ToolChainType Qt4RunConfiguration::toolChainType() const
691
{
Tobias Hunger's avatar
Tobias Hunger committed
692
    Qt4BuildConfiguration *qt4bc = qt4Target()->activeBuildConfiguration();
693
    return qt4bc->toolChainType();
694
}
695

dt's avatar
dt committed
696
697
698
699
700
ProjectExplorer::OutputFormatter *Qt4RunConfiguration::createOutputFormatter() const
{
    return new QtOutputFormatter(qt4Target()->qt4Project());
}

con's avatar
con committed
701
702
703
704
705
///
/// Qt4RunConfigurationFactory
/// This class is used to restore run settings (saved in .user files)
///

706
707
Qt4RunConfigurationFactory::Qt4RunConfigurationFactory(QObject *parent) :
    ProjectExplorer::IRunConfigurationFactory(parent)
con's avatar
con committed
708
709
710
711
712
713
714
{
}

Qt4RunConfigurationFactory::~Qt4RunConfigurationFactory()
{
}

Tobias Hunger's avatar
Tobias Hunger committed
715
bool Qt4RunConfigurationFactory::canCreate(ProjectExplorer::Target *parent, const QString &id) const
con's avatar
con committed
716
{
Tobias Hunger's avatar
Tobias Hunger committed
717
718
719
    Qt4Target *t = qobject_cast<Qt4Target *>(parent);
    if (!t)
        return false;
720
    if (t->id() != QLatin1String(Constants::DESKTOP_TARGET_ID))
721
        return false;
Tobias Hunger's avatar
Tobias Hunger committed
722
    return t->qt4Project()->hasApplicationProFile(pathFromId(id));
con's avatar
con committed
723
724
}

Tobias Hunger's avatar
Tobias Hunger committed
725
ProjectExplorer::RunConfiguration *Qt4RunConfigurationFactory::create(ProjectExplorer::Target *parent, const QString &id)
con's avatar
con committed
726
{
727
728
    if (!canCreate(parent, id))
        return 0;
Tobias Hunger's avatar
Tobias Hunger committed
729
730
    Qt4Target *t(static_cast<Qt4Target *>(parent));
    return new Qt4RunConfiguration(t, pathFromId(id));
731
732
}

Tobias Hunger's avatar
Tobias Hunger committed
733
bool Qt4RunConfigurationFactory::canRestore(ProjectExplorer::Target *parent, const QVariantMap &map) const
734
{
Tobias Hunger's avatar
Tobias Hunger committed
735
736
    if (!qobject_cast<Qt4Target *>(parent))
        return false;
737
    if (parent->id() != QLatin1String(Constants::DESKTOP_TARGET_ID))
738
739
740
741
742
        return false;
    QString id(ProjectExplorer::idFromMap(map));
    return id.startsWith(QLatin1String(QT4_RC_ID));
}

Tobias Hunger's avatar
Tobias Hunger committed
743
ProjectExplorer::RunConfiguration *Qt4RunConfigurationFactory::restore(ProjectExplorer::Target *parent, const QVariantMap &map)
744
745
746
{
    if (!canRestore(parent, map))
        return 0;
Tobias Hunger's avatar
Tobias Hunger committed
747
748
    Qt4Target *t(static_cast<Qt4Target *>(parent));
    Qt4RunConfiguration *rc(new Qt4RunConfiguration(t, QString()));
749
750
751
752
753
754
755
    if (rc->fromMap(map))
        return rc;

    delete rc;
    return 0;
}

Tobias Hunger's avatar
Tobias Hunger committed
756
bool Qt4RunConfigurationFactory::canClone(ProjectExplorer::Target *parent, ProjectExplorer::RunConfiguration *source) const
757
{
Tobias Hunger's avatar
Tobias Hunger committed
758
    return canCreate(parent, source->id());
759
760
}

Tobias Hunger's avatar
Tobias Hunger committed
761
ProjectExplorer::RunConfiguration *Qt4RunConfigurationFactory::clone(ProjectExplorer::Target *parent, ProjectExplorer::RunConfiguration *source)
762
763
764
{
    if (!canClone(parent, source))
        return 0;
Tobias Hunger's avatar
Tobias Hunger committed
765
    Qt4Target *t(static_cast<Qt4Target *>(parent));
766
    Qt4RunConfiguration *old(static_cast<Qt4RunConfiguration *>(source));
Tobias Hunger's avatar
Tobias Hunger committed
767
    return new Qt4RunConfiguration(t, old);
con's avatar
con committed
768
769
}

Tobias Hunger's avatar
Tobias Hunger committed
770
QStringList Qt4RunConfigurationFactory::availableCreationIds(ProjectExplorer::Target *parent) const
con's avatar
con committed
771
{
Tobias Hunger's avatar
Tobias Hunger committed
772
773
774
    Qt4Target *t(qobject_cast<Qt4Target *>(parent));
    if (!t)
        return QStringList();
775
    if (t->id() != Constants::DESKTOP_TARGET_ID)
con's avatar
con committed
776
        return QStringList();
Tobias Hunger's avatar
Tobias Hunger committed
777
    return t->qt4Project()->applicationProFilePathes(QLatin1String(QT4_RC_PREFIX));
con's avatar
con committed
778
779
}

780
QString Qt4RunConfigurationFactory::displayNameForId(const QString &id) const
con's avatar
con committed
781
{
782
    return QFileInfo(pathFromId(id)).completeBaseName();
con's avatar
con committed
783
}