qt4runconfiguration.cpp 28.1 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2 3 4
**
** This file is part of Qt Creator
**
con's avatar
con committed
5
** Copyright (c) 2011 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
**
con's avatar
con committed
9
** No Commercial Usage
10
**
con's avatar
con committed
11 12 13 14
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
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
**
con's avatar
con committed
25 26 27 28 29 30
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
con's avatar
con committed
31
**
32
**************************************************************************/
hjk's avatar
hjk committed
33

con's avatar
con committed
34
#include "qt4runconfiguration.h"
hjk's avatar
hjk committed
35

hjk's avatar
hjk committed
36
#include "makestep.h"
con's avatar
con committed
37 38
#include "profilereader.h"
#include "qt4nodes.h"
hjk's avatar
hjk committed
39
#include "qt4project.h"
Tobias Hunger's avatar
Tobias Hunger committed
40
#include "qt4target.h"
41
#include "qt4buildconfiguration.h"
42
#include "qt4projectmanagerconstants.h"
dt's avatar
dt committed
43
#include "qtoutputformatter.h"
44
#include "qt4desktoptarget.h"
45
#include "qmakestep.h"
con's avatar
con committed
46

47
#include <coreplugin/coreconstants.h>
con's avatar
con committed
48 49 50
#include <coreplugin/icore.h>
#include <coreplugin/messagemanager.h>
#include <coreplugin/variablemanager.h>
51
#include <coreplugin/ifile.h>
con's avatar
con committed
52
#include <projectexplorer/buildstep.h>
53
#include <projectexplorer/environmentwidget.h>
54
#include <projectexplorer/persistentsettings.h>
55
#include <projectexplorer/toolchain.h>
hjk's avatar
hjk committed
56
#include <utils/qtcassert.h>
57
#include <utils/qtcprocess.h>
58 59
#include <utils/pathchooser.h>
#include <utils/detailswidget.h>
60
#include <utils/debuggerlanguagechooser.h>
con's avatar
con committed
61 62 63

#include <QtGui/QFormLayout>
#include <QtGui/QInputDialog>
64
#include <QtGui/QLabel>
65
#include <QtGui/QLineEdit>
66
#include <QtGui/QCheckBox>
67
#include <QtGui/QToolButton>
68
#include <QtGui/QComboBox>
con's avatar
con committed
69 70 71

using namespace Qt4ProjectManager::Internal;
using namespace Qt4ProjectManager;
72
using ProjectExplorer::LocalApplicationRunConfiguration;
con's avatar
con committed
73 74 75
using ProjectExplorer::PersistentSettingsReader;
using ProjectExplorer::PersistentSettingsWriter;

76 77 78 79 80 81 82 83 84 85 86 87 88
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
89
{
90 91 92 93
    if (!id.startsWith(QLatin1String(QT4_RC_PREFIX)))
        return QString();
    return id.mid(QString::fromLatin1(QT4_RC_PREFIX).size());
}
94

95 96 97 98
QString pathToId(const QString &path)
{
    return QString::fromLatin1(QT4_RC_PREFIX) + path;
}
99

100
} // namespace
101

102 103 104 105
//
// Qt4RunConfiguration
//

106
Qt4RunConfiguration::Qt4RunConfiguration(Qt4BaseTarget *parent, const QString &proFilePath) :
107 108 109 110
    LocalApplicationRunConfiguration(parent, QLatin1String(QT4_RC_ID)),
    m_proFilePath(proFilePath),
    m_runMode(Gui),
    m_isUsingDyldImageSuffix(false),
111
    m_baseEnvironmentBase(Qt4RunConfiguration::BuildEnvironmentBase),
112
    m_parseSuccess(parent->qt4Project()->validParse(m_proFilePath))
113 114
{
    ctor();
con's avatar
con committed
115 116
}

117
Qt4RunConfiguration::Qt4RunConfiguration(Qt4BaseTarget *parent, Qt4RunConfiguration *source) :
118 119 120 121 122 123 124
    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),
125 126
    m_baseEnvironmentBase(source->m_baseEnvironmentBase),
    m_parseSuccess(source->m_parseSuccess)
con's avatar
con committed
127
{
128
    ctor();
con's avatar
con committed
129 130
}

131
Qt4RunConfiguration::~Qt4RunConfiguration()
dt's avatar
dt committed
132 133 134
{
}

135
Qt4DesktopTarget *Qt4RunConfiguration::qt4Target() const
con's avatar
con committed
136
{
137
    return static_cast<Qt4DesktopTarget *>(target());
con's avatar
con committed
138 139
}

Friedemann Kleint's avatar
Friedemann Kleint committed
140
bool Qt4RunConfiguration::isEnabled(ProjectExplorer::BuildConfiguration * /* configuration */) const
141
{
142 143
    if (!m_parseSuccess)
        return false;
144
    return true;
145
}
146

147
void Qt4RunConfiguration::handleParseState(bool success)
148
{
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
    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)
{
165 166
    if (pro->path() != m_proFilePath)
        return;
167
    handleParseState(false);
168 169
}

170 171
void Qt4RunConfiguration::ctor()
{
172
    setDefaultDisplayName(defaultDisplayName());
173

Tobias Hunger's avatar
Tobias Hunger committed
174
    connect(qt4Target(), SIGNAL(environmentChanged()),
175
            this, SIGNAL(baseEnvironmentChanged()));
176 177
    connect(qt4Target()->qt4Project(), SIGNAL(proFileUpdated(Qt4ProjectManager::Internal::Qt4ProFileNode*,bool)),
            this, SLOT(proFileUpdated(Qt4ProjectManager::Internal::Qt4ProFileNode*,bool)));
178

179 180
    connect(qt4Target()->qt4Project(), SIGNAL(proFileInvalidated(Qt4ProjectManager::Internal::Qt4ProFileNode*)),
            this, SLOT(proFileInvalidated(Qt4ProjectManager::Internal::Qt4ProFileNode*)));
181 182
}

183 184 185 186 187
//////
/// Qt4RunConfigurationWidget
/////

Qt4RunConfigurationWidget::Qt4RunConfigurationWidget(Qt4RunConfiguration *qt4RunConfiguration, QWidget *parent)
188 189 190
    : QWidget(parent),
    m_qt4RunConfiguration(qt4RunConfiguration),
    m_ignoreChange(false),
mae's avatar
mae committed
191 192
    m_usingDyldImageSuffix(0),
    m_isShown(false)
con's avatar
con committed
193
{
dt's avatar
dt committed
194 195 196 197
    QVBoxLayout *vboxTopLayout = new QVBoxLayout(this);
    vboxTopLayout->setMargin(0);

    m_detailsContainer = new Utils::DetailsWidget(this);
198
    m_detailsContainer->setState(Utils::DetailsWidget::NoSummary);
dt's avatar
dt committed
199 200 201 202
    vboxTopLayout->addWidget(m_detailsContainer);
    QWidget *detailsWidget = new QWidget(m_detailsContainer);
    m_detailsContainer->setWidget(detailsWidget);
    QFormLayout *toplayout = new QFormLayout(detailsWidget);
con's avatar
con committed
203
    toplayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
con's avatar
con committed
204 205
    toplayout->setMargin(0);

206 207 208
    m_executableLineEdit = new QLineEdit(m_qt4RunConfiguration->executable(), this);
    m_executableLineEdit->setEnabled(false);
    toplayout->addRow(tr("Executable:"), m_executableLineEdit);
con's avatar
con committed
209

Tobias Hunger's avatar
Tobias Hunger committed
210
    QLabel *argumentsLabel = new QLabel(tr("Arguments:"), this);
211
    m_argumentsLineEdit = new QLineEdit(qt4RunConfiguration->rawCommandLineArguments(), this);
212 213 214
    argumentsLabel->setBuddy(m_argumentsLineEdit);
    toplayout->addRow(argumentsLabel, m_argumentsLineEdit);

Tobias Hunger's avatar
Tobias Hunger committed
215
    m_workingDirectoryEdit = new Utils::PathChooser(this);
216
    m_workingDirectoryEdit->setPath(m_qt4RunConfiguration->baseWorkingDirectory());
217
    m_workingDirectoryEdit->setBaseDirectory(m_qt4RunConfiguration->target()->project()->projectDirectory());
218
    m_workingDirectoryEdit->setExpectedKind(Utils::PathChooser::ExistingDirectory);
219
    m_workingDirectoryEdit->setEnvironment(m_qt4RunConfiguration->environment());
220
    m_workingDirectoryEdit->setPromptDialogTitle(tr("Select Working Directory"));
221

Tobias Hunger's avatar
Tobias Hunger committed
222
    QToolButton *resetButton = new QToolButton(this);
223
    resetButton->setToolTip(tr("Reset to default"));
224
    resetButton->setIcon(QIcon(QLatin1String(Core::Constants::ICON_RESET)));
225 226

    QHBoxLayout *boxlayout = new QHBoxLayout();
227
    boxlayout->setMargin(0);
228 229
    boxlayout->addWidget(m_workingDirectoryEdit);
    boxlayout->addWidget(resetButton);
230
    toplayout->addRow(tr("Working directory:"), boxlayout);
con's avatar
con committed
231

232
    m_useTerminalCheck = new QCheckBox(tr("Run in terminal"), this);
233
    m_useTerminalCheck->setChecked(m_qt4RunConfiguration->runMode() == ProjectExplorer::LocalApplicationRunConfiguration::Console);
234 235
    toplayout->addRow(QString(), m_useTerminalCheck);

236 237 238 239 240
    QWidget *debuggerLabelWidget = new QWidget(this);
    QVBoxLayout *debuggerLabelLayout = new QVBoxLayout(debuggerLabelWidget);
    debuggerLabelLayout->setMargin(0);
    debuggerLabelLayout->setSpacing(0);
    debuggerLabelWidget->setLayout(debuggerLabelLayout);
241
    QLabel *debuggerLabel = new QLabel(tr("Debugger:"), this);
242 243 244
    debuggerLabelLayout->addWidget(debuggerLabel);
    debuggerLabelLayout->addStretch(10);

245
    m_debuggerLanguageChooser = new Utils::DebuggerLanguageChooser(this);
246
    toplayout->addRow(debuggerLabelWidget, m_debuggerLanguageChooser);
247 248 249

    m_debuggerLanguageChooser->setCppChecked(m_qt4RunConfiguration->useCppDebugger());
    m_debuggerLanguageChooser->setQmlChecked(m_qt4RunConfiguration->useQmlDebugger());
250
    m_debuggerLanguageChooser->setQmlDebugServerPort(m_qt4RunConfiguration->qmlDebugServerPort());
251

252
#ifdef Q_OS_MAC
Tobias Hunger's avatar
Tobias Hunger committed
253
    m_usingDyldImageSuffix = new QCheckBox(tr("Use debug version of frameworks (DYLD_IMAGE_SUFFIX=_debug)"), this);
254 255 256 257 258 259
    m_usingDyldImageSuffix->setChecked(m_qt4RunConfiguration->isUsingDyldImageSuffix());
    toplayout->addRow(QString(), m_usingDyldImageSuffix);
    connect(m_usingDyldImageSuffix, SIGNAL(toggled(bool)),
            this, SLOT(usingDyldImageSuffixToggled(bool)));
#endif

260 261 262 263 264 265
    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
266
    vboxTopLayout->addWidget(environmentLabel);
267

Tobias Hunger's avatar
Tobias Hunger committed
268
    QWidget *baseEnvironmentWidget = new QWidget(this);
269 270
    QHBoxLayout *baseEnvironmentLayout = new QHBoxLayout(baseEnvironmentWidget);
    baseEnvironmentLayout->setMargin(0);
271
    QLabel *label = new QLabel(tr("Base environment for this runconfiguration:"), this);
272
    baseEnvironmentLayout->addWidget(label);
273
    m_baseEnvironmentComboBox = new QComboBox(this);
274 275 276 277 278 279
    m_baseEnvironmentComboBox->addItems(QStringList()
                                        << tr("Clean Environment")
                                        << tr("System Environment")
                                        << tr("Build Environment"));
    m_baseEnvironmentComboBox->setCurrentIndex(qt4RunConfiguration->baseEnvironmentBase());
    connect(m_baseEnvironmentComboBox, SIGNAL(currentIndexChanged(int)),
280
            this, SLOT(baseEnvironmentSelected(int)));
281 282
    baseEnvironmentLayout->addWidget(m_baseEnvironmentComboBox);
    baseEnvironmentLayout->addStretch(10);
dt's avatar
dt committed
283

284
    m_environmentWidget = new ProjectExplorer::EnvironmentWidget(this, baseEnvironmentWidget);
285
    m_environmentWidget->setBaseEnvironment(m_qt4RunConfiguration->baseEnvironment());
286
    m_environmentWidget->setBaseEnvironmentText(m_qt4RunConfiguration->baseEnvironmentText());
287
    m_environmentWidget->setUserChanges(m_qt4RunConfiguration->userEnvironmentChanges());
dt's avatar
dt committed
288
    m_environmentWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
dt's avatar
dt committed
289
    vboxTopLayout->addWidget(m_environmentWidget);
290

291 292
    setEnabled(m_qt4RunConfiguration->isEnabled());

con's avatar
con committed
293
    connect(m_workingDirectoryEdit, SIGNAL(changed(QString)),
294
            this, SLOT(workDirectoryEdited()));
295 296

    connect(resetButton, SIGNAL(clicked()),
297
            this, SLOT(workingDirectoryReseted()));
298

299
    connect(m_argumentsLineEdit, SIGNAL(textEdited(QString)),
300
            this, SLOT(argumentsEdited(QString)));
301 302 303
    connect(m_useTerminalCheck, SIGNAL(toggled(bool)),
            this, SLOT(termToggled(bool)));

304 305 306 307
    connect(m_debuggerLanguageChooser, SIGNAL(cppLanguageToggled(bool)),
            this, SLOT(useCppDebuggerToggled(bool)));
    connect(m_debuggerLanguageChooser, SIGNAL(qmlLanguageToggled(bool)),
            this, SLOT(useQmlDebuggerToggled(bool)));
308 309
    connect(m_debuggerLanguageChooser, SIGNAL(qmlDebugServerPortChanged(uint)),
            this, SLOT(qmlDebugServerPortChanged(uint)));
310

311 312
    connect(m_environmentWidget, SIGNAL(userChangesChanged()),
            this, SLOT(userChangesEdited()));
313

314
    connect(qt4RunConfiguration, SIGNAL(baseWorkingDirectoryChanged(QString)),
315 316
            this, SLOT(workingDirectoryChanged(QString)));

317
    connect(qt4RunConfiguration, SIGNAL(commandLineArgumentsChanged(QString)),
318
            this, SLOT(commandLineArgumentsChanged(QString)));
319 320
    connect(qt4RunConfiguration, SIGNAL(runModeChanged(ProjectExplorer::LocalApplicationRunConfiguration::RunMode)),
            this, SLOT(runModeChanged(ProjectExplorer::LocalApplicationRunConfiguration::RunMode)));
321 322
    connect(qt4RunConfiguration, SIGNAL(usingDyldImageSuffixChanged(bool)),
            this, SLOT(usingDyldImageSuffixChanged(bool)));
323 324
    connect(qt4RunConfiguration, SIGNAL(effectiveTargetInformationChanged()),
            this, SLOT(effectiveTargetInformationChanged()), Qt::QueuedConnection);
325

326 327
    connect(qt4RunConfiguration, SIGNAL(userEnvironmentChangesChanged(QList<Utils::EnvironmentItem>)),
            this, SLOT(userEnvironmentChangesChanged(QList<Utils::EnvironmentItem>)));
328

329 330
    connect(qt4RunConfiguration, SIGNAL(baseEnvironmentChanged()),
            this, SLOT(baseEnvironmentChanged()));
331 332 333

    connect(qt4RunConfiguration, SIGNAL(isEnabledChanged(bool)),
            this, SLOT(runConfigurationEnabledChange(bool)));
334 335

    setEnabled(qt4RunConfiguration->isEnabled());
336 337
}

Tobias Hunger's avatar
Tobias Hunger committed
338 339 340 341
Qt4RunConfigurationWidget::~Qt4RunConfigurationWidget()
{
}

342 343 344 345 346 347 348 349 350 351
void Qt4RunConfigurationWidget::useCppDebuggerToggled(bool toggled)
{
    m_qt4RunConfiguration->setUseCppDebugger(toggled);
}

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

352 353 354 355 356
void Qt4RunConfigurationWidget::qmlDebugServerPortChanged(uint port)
{
    m_qt4RunConfiguration->setQmlDebugServerPort(port);
}

357
void Qt4RunConfigurationWidget::baseEnvironmentSelected(int index)
358 359
{
    m_ignoreChange = true;
360
    m_qt4RunConfiguration->setBaseEnvironmentBase(Qt4RunConfiguration::BaseEnvironmentBase(index));
361 362

    m_environmentWidget->setBaseEnvironment(m_qt4RunConfiguration->baseEnvironment());
363
    m_environmentWidget->setBaseEnvironmentText(m_qt4RunConfiguration->baseEnvironmentText());
364 365 366
    m_ignoreChange = false;
}

367 368
void Qt4RunConfigurationWidget::baseEnvironmentChanged()
{
369 370 371
    if (m_ignoreChange)
        return;

372
    m_baseEnvironmentComboBox->setCurrentIndex(m_qt4RunConfiguration->baseEnvironmentBase());
373
    m_environmentWidget->setBaseEnvironment(m_qt4RunConfiguration->baseEnvironment());
374
    m_environmentWidget->setBaseEnvironmentText(m_qt4RunConfiguration->baseEnvironmentText());
375 376
}

377
void Qt4RunConfigurationWidget::userEnvironmentChangesChanged(const QList<Utils::EnvironmentItem> &userChanges)
378 379 380 381 382 383
{
    if (m_ignoreChange)
        return;
    m_environmentWidget->setUserChanges(userChanges);
}

384
void Qt4RunConfigurationWidget::userChangesEdited()
385 386 387 388
{
    m_ignoreChange = true;
    m_qt4RunConfiguration->setUserEnvironmentChanges(m_environmentWidget->userChanges());
    m_ignoreChange = false;
389 390
}

391 392 393 394 395
void Qt4RunConfigurationWidget::runConfigurationEnabledChange(bool enabled)
{
    setEnabled(enabled);
}

396
void Qt4RunConfigurationWidget::workDirectoryEdited()
397 398 399 400
{
    if (m_ignoreChange)
        return;
    m_ignoreChange = true;
401
    m_qt4RunConfiguration->setBaseWorkingDirectory(m_workingDirectoryEdit->rawPath());
402 403 404
    m_ignoreChange = false;
}

405
void Qt4RunConfigurationWidget::workingDirectoryReseted()
406 407 408
{
    // This emits a signal connected to workingDirectoryChanged()
    // that sets the m_workingDirectoryEdit
409
    m_qt4RunConfiguration->setBaseWorkingDirectory("");
410 411
}

412
void Qt4RunConfigurationWidget::argumentsEdited(const QString &args)
413 414
{
    m_ignoreChange = true;
415
    m_qt4RunConfiguration->setCommandLineArguments(args);
416 417 418
    m_ignoreChange = false;
}

419 420 421
void Qt4RunConfigurationWidget::termToggled(bool on)
{
    m_ignoreChange = true;
422 423
    m_qt4RunConfiguration->setRunMode(on ? LocalApplicationRunConfiguration::Console
                                         : LocalApplicationRunConfiguration::Gui);
424 425 426
    m_ignoreChange = false;
}

427 428 429 430 431 432 433
void Qt4RunConfigurationWidget::usingDyldImageSuffixToggled(bool state)
{
    m_ignoreChange = true;
    m_qt4RunConfiguration->setUsingDyldImageSuffix(state);
    m_ignoreChange = false;
}

434 435 436 437 438 439
void Qt4RunConfigurationWidget::workingDirectoryChanged(const QString &workingDirectory)
{
    if (!m_ignoreChange)
        m_workingDirectoryEdit->setPath(workingDirectory);
}

440 441
void Qt4RunConfigurationWidget::commandLineArgumentsChanged(const QString &args)
{
dt's avatar
dt committed
442 443 444
    if (m_ignoreChange)
        return;
    m_argumentsLineEdit->setText(args);
445 446
}

447
void Qt4RunConfigurationWidget::runModeChanged(LocalApplicationRunConfiguration::RunMode runMode)
448 449
{
    if (!m_ignoreChange)
450
        m_useTerminalCheck->setChecked(runMode == LocalApplicationRunConfiguration::Console);
451 452
}

453 454 455 456 457 458
void Qt4RunConfigurationWidget::usingDyldImageSuffixChanged(bool state)
{
    if (!m_ignoreChange && m_usingDyldImageSuffix)
        m_usingDyldImageSuffix->setChecked(state);
}

459
void Qt4RunConfigurationWidget::effectiveTargetInformationChanged()
460
{
461
    if (m_isShown) {
462
        m_executableLineEdit->setText(QDir::toNativeSeparators(m_qt4RunConfiguration->executable()));
463
        m_ignoreChange = true;
464
        m_workingDirectoryEdit->setPath(QDir::toNativeSeparators(m_qt4RunConfiguration->baseWorkingDirectory()));
465
        m_ignoreChange = false;
466
    }
467 468
}

469
void Qt4RunConfigurationWidget::showEvent(QShowEvent *event)
470
{
471 472 473
    m_isShown = true;
    effectiveTargetInformationChanged();
    QWidget::showEvent(event);
474 475
}

476 477 478 479 480
void Qt4RunConfigurationWidget::hideEvent(QHideEvent *event)
{
    m_isShown = false;
    QWidget::hideEvent(event);
}
481

482
////// TODO c&p above
483
QWidget *Qt4RunConfiguration::createConfigurationWidget()
484 485
{
    return new Qt4RunConfigurationWidget(this, 0);
con's avatar
con committed
486 487
}

488
QVariantMap Qt4RunConfiguration::toMap() const
con's avatar
con committed
489
{
490
    const QDir projectDir = QDir(target()->project()->projectDirectory());
491 492 493 494 495
    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);
496
    map.insert(QLatin1String(USER_ENVIRONMENT_CHANGES_KEY), Utils::EnvironmentItem::toStringList(m_userEnvironmentChanges));
497 498 499
    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
500 501
}

502
bool Qt4RunConfiguration::fromMap(const QVariantMap &map)
503
{
504
    const QDir projectDir = QDir(target()->project()->projectDirectory());
505
    m_commandLineArguments = map.value(QLatin1String(COMMAND_LINE_ARGUMENTS_KEY)).toString();
506 507 508 509 510 511
    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();

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

515 516
    m_parseSuccess = qt4Target()->qt4Project()->validParse(m_proFilePath);

517
    return RunConfiguration::fromMap(map);
con's avatar
con committed
518 519 520 521
}

QString Qt4RunConfiguration::executable() const
{
dt's avatar
dt committed
522 523 524 525 526
    Qt4Project *pro = qt4Target()->qt4Project();
    TargetInformation ti = pro->rootProjectNode()->targetInformation(m_proFilePath);
    if (!ti.valid)
        return QString();
    return ti.executable;
con's avatar
con committed
527 528
}

529
LocalApplicationRunConfiguration::RunMode Qt4RunConfiguration::runMode() const
con's avatar
con committed
530 531 532 533
{
    return m_runMode;
}

534 535 536 537 538 539 540 541 542 543 544
bool Qt4RunConfiguration::isUsingDyldImageSuffix() const
{
    return m_isUsingDyldImageSuffix;
}

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

con's avatar
con committed
545
QString Qt4RunConfiguration::workingDirectory() const
546
{
547 548
    return QDir::cleanPath(environment().expandVariables(
                Utils::expandMacros(baseWorkingDirectory(), macroExpander())));
549 550 551
}

QString Qt4RunConfiguration::baseWorkingDirectory() const
con's avatar
con committed
552
{
553
    // if the user overrode us, then return his working directory
554
    if (!m_userWorkingDirectory.isEmpty())
555 556 557
        return m_userWorkingDirectory;

    // else what the pro file reader tells us
dt's avatar
dt committed
558 559 560 561 562
    Qt4Project *pro = qt4Target()->qt4Project();
    TargetInformation ti = pro->rootProjectNode()->targetInformation(m_proFilePath);
    if(!ti.valid)
        return QString();
    return ti.workingDir;
con's avatar
con committed
563 564
}

565
QString Qt4RunConfiguration::commandLineArguments() const
566 567 568 569 570
{
    return Utils::QtcProcess::expandMacros(m_commandLineArguments, macroExpander());
}

QString Qt4RunConfiguration::rawCommandLineArguments() const
con's avatar
con committed
571 572 573 574
{
    return m_commandLineArguments;
}

575 576 577 578 579 580 581 582
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");
583
    return QString();
584 585
}

586
Utils::Environment Qt4RunConfiguration::baseEnvironment() const
con's avatar
con committed
587
{
588
    Utils::Environment env;
589 590 591
    if (m_baseEnvironmentBase == Qt4RunConfiguration::CleanEnvironmentBase) {
        // Nothing
    } else  if (m_baseEnvironmentBase == Qt4RunConfiguration::SystemEnvironmentBase) {
592
        env = Utils::Environment::systemEnvironment();
593
    } else  if (m_baseEnvironmentBase == Qt4RunConfiguration::BuildEnvironmentBase) {
Tobias Hunger's avatar
Tobias Hunger committed
594
        env = target()->activeBuildConfiguration()->environment();
595
    }
596 597 598
    if (m_isUsingDyldImageSuffix) {
        env.set("DYLD_IMAGE_SUFFIX", "_debug");
    }
599 600 601 602 603

#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
604
    const Qt4ProFileNode *node = qt4Target()->qt4Project()->rootProjectNode()->findProFileFor(m_proFilePath);
605 606 607 608
    if (node)
        foreach(const QString dir, node->variableValue(LibDirectoriesVar))
            env.prependOrSetPath(dir);
#endif
609
    return env;
con's avatar
con committed
610 611
}

612
Utils::Environment Qt4RunConfiguration::environment() const
613
{
614
    Utils::Environment env = baseEnvironment();
615 616 617 618
    env.modify(userEnvironmentChanges());
    return env;
}

619
QList<Utils::EnvironmentItem> Qt4RunConfiguration::userEnvironmentChanges() const
620 621 622 623
{
    return m_userEnvironmentChanges;
}

624
void Qt4RunConfiguration::setUserEnvironmentChanges(const QList<Utils::EnvironmentItem> &diff)
625 626 627 628 629 630 631
{
    if (m_userEnvironmentChanges != diff) {
        m_userEnvironmentChanges = diff;
        emit userEnvironmentChangesChanged(diff);
    }
}

632
void Qt4RunConfiguration::setBaseWorkingDirectory(const QString &wd)
633
{
634 635 636 637 638 639 640
    const QString &oldWorkingDirectory = workingDirectory();

    m_userWorkingDirectory = wd;

    const QString &newWorkingDirectory = workingDirectory();
    if (oldWorkingDirectory != newWorkingDirectory)
        emit baseWorkingDirectoryChanged(newWorkingDirectory);
641 642
}

643
void Qt4RunConfiguration::setCommandLineArguments(const QString &argumentsString)
con's avatar
con committed
644
{
645 646
    m_commandLineArguments = argumentsString;
    emit commandLineArgumentsChanged(argumentsString);
con's avatar
con committed
647 648
}

649 650 651 652 653 654
void Qt4RunConfiguration::setRunMode(RunMode runMode)
{
    m_runMode = runMode;
    emit runModeChanged(runMode);
}

con's avatar
con committed
655 656 657 658 659
QString Qt4RunConfiguration::proFilePath() const
{
    return m_proFilePath;
}

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

668 669
QStringList Qt4RunConfiguration::dumperLibraryLocations() const
{
Tobias Hunger's avatar
Tobias Hunger committed
670 671
    QtVersion *version = qt4Target()->activeBuildConfiguration()->qtVersion();
    if (version)
672
        return version->debuggingHelperLibraryLocations();
673
    return QStringList();
674 675
}

676
QString Qt4RunConfiguration::defaultDisplayName()
677
{
678
    QString defaultName;
679
    if (!m_proFilePath.isEmpty())
680
        defaultName = QFileInfo(m_proFilePath).completeBaseName();
681
    else
682 683
        defaultName = tr("Qt4 RunConfiguration");
    return defaultName;
684 685
}

686 687 688 689 690 691 692 693 694 695 696 697
void Qt4RunConfiguration::setBaseEnvironmentBase(BaseEnvironmentBase env)
{
    if (m_baseEnvironmentBase == env)
        return;
    m_baseEnvironmentBase = env;
    emit baseEnvironmentChanged();
}

Qt4RunConfiguration::BaseEnvironmentBase Qt4RunConfiguration::baseEnvironmentBase() const
{
    return m_baseEnvironmentBase;
}
698

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

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

709 710
Qt4RunConfigurationFactory::Qt4RunConfigurationFactory(QObject *parent) :
    ProjectExplorer::IRunConfigurationFactory(parent)
con's avatar
con committed
711 712 713 714 715 716 717
{
}

Qt4RunConfigurationFactory::~Qt4RunConfigurationFactory()
{
}

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

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

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

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

    delete rc;
    return 0;
}

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

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

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

783
QString Qt4RunConfigurationFactory::displayNameForId(const QString &id) const
con's avatar
con committed
784
{
785
    return QFileInfo(pathFromId(id)).completeBaseName();
con's avatar
con committed
786
}