qt4runconfiguration.cpp 28 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
**
hjk's avatar
hjk committed
7
** Contact: Nokia Corporation (info@qt.nokia.com)
con's avatar
con committed
8
**
9
**
10
** GNU Lesser General Public License Usage
11
**
hjk's avatar
hjk committed
12 13 14 15 16 17
** 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.
18
**
con's avatar
con committed
19
** In addition, as a special exception, Nokia gives you certain additional
hjk's avatar
hjk committed
20
** rights. These rights are described in the Nokia Qt LGPL Exception
con's avatar
con committed
21 22
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
23 24 25 26 27
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
con's avatar
con committed
28
** If you have questions regarding the use of this file, please contact
Tobias Hunger's avatar
Tobias Hunger committed
29
** Nokia at info@qt.nokia.com.
con's avatar
con committed
30
**
31
**************************************************************************/
hjk's avatar
hjk committed
32

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

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

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

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

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

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

96
} // namespace
97

98 99 100 101
//
// Qt4RunConfiguration
//

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

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

127
Qt4RunConfiguration::~Qt4RunConfiguration()
dt's avatar
dt committed
128 129 130
{
}

131
Qt4DesktopTarget *Qt4RunConfiguration::qt4Target() const
con's avatar
con committed
132
{
133
    return static_cast<Qt4DesktopTarget *>(target());
con's avatar
con committed
134 135
}

136
bool Qt4RunConfiguration::isEnabled() const
137
{
138
    return m_parseSuccess;
139
}
140

dt_'s avatar
dt_ committed
141 142 143 144 145 146 147
QString Qt4RunConfiguration::disabledReason() const
{
    if (!m_parseSuccess)
        return tr("The .pro file could not be parsed");
    return QString();
}

148
void Qt4RunConfiguration::handleParseState(bool success)
149
{
150 151 152 153 154 155
    bool enabled = isEnabled();
    m_parseSuccess = success;
    if (enabled != isEnabled())
        emit isEnabledChanged(!enabled);
}

156
void Qt4RunConfiguration::proFileUpdated(Qt4ProjectManager::Qt4ProFileNode *pro, bool success)
157 158 159 160 161
{
    if (m_proFilePath != pro->path())
        return;
    handleParseState(success);
    emit effectiveTargetInformationChanged();
162
    emit baseEnvironmentChanged();
163 164
}

165
void Qt4RunConfiguration::proFileInvalidated(Qt4ProjectManager::Qt4ProFileNode *pro)
166
{
167 168
    if (pro->path() != m_proFilePath)
        return;
169
    handleParseState(false);
170 171
}

172 173
void Qt4RunConfiguration::ctor()
{
174
    setDefaultDisplayName(defaultDisplayName());
175

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

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

185 186 187 188 189
//////
/// Qt4RunConfigurationWidget
/////

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

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

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

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

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

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

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

234
    m_useTerminalCheck = new QCheckBox(tr("Run in terminal"), this);
235
    m_useTerminalCheck->setChecked(m_qt4RunConfiguration->runMode() == ProjectExplorer::LocalApplicationRunConfiguration::Console);
236
    toplayout->addRow(QString(), m_useTerminalCheck);
237
    m_useTerminalCheck->setVisible(qt4RunConfiguration->target()->id() != Constants::QT_SIMULATOR_TARGET_ID);
238

239
    QLabel *debuggerLabel = new QLabel(tr("Debugger:"), this);
240
    debuggerLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::MinimumExpanding);
241

242
    m_debuggerLanguageChooser = new Utils::DebuggerLanguageChooser(this);
243
    toplayout->addRow(debuggerLabel, m_debuggerLanguageChooser);
244 245 246

    m_debuggerLanguageChooser->setCppChecked(m_qt4RunConfiguration->useCppDebugger());
    m_debuggerLanguageChooser->setQmlChecked(m_qt4RunConfiguration->useQmlDebugger());
247
    m_debuggerLanguageChooser->setQmlDebugServerPort(m_qt4RunConfiguration->qmlDebugServerPort());
248

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

257 258 259 260 261 262
    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
263
    vboxTopLayout->addWidget(environmentLabel);
264

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

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

288 289
    setEnabled(m_qt4RunConfiguration->isEnabled());

con's avatar
con committed
290
    connect(m_workingDirectoryEdit, SIGNAL(changed(QString)),
291
            this, SLOT(workDirectoryEdited()));
292 293

    connect(resetButton, SIGNAL(clicked()),
294
            this, SLOT(workingDirectoryReseted()));
295

296
    connect(m_argumentsLineEdit, SIGNAL(textEdited(QString)),
297
            this, SLOT(argumentsEdited(QString)));
298 299 300
    connect(m_useTerminalCheck, SIGNAL(toggled(bool)),
            this, SLOT(termToggled(bool)));

301 302 303 304
    connect(m_debuggerLanguageChooser, SIGNAL(cppLanguageToggled(bool)),
            this, SLOT(useCppDebuggerToggled(bool)));
    connect(m_debuggerLanguageChooser, SIGNAL(qmlLanguageToggled(bool)),
            this, SLOT(useQmlDebuggerToggled(bool)));
305 306
    connect(m_debuggerLanguageChooser, SIGNAL(qmlDebugServerPortChanged(uint)),
            this, SLOT(qmlDebugServerPortChanged(uint)));
307 308
    connect(m_debuggerLanguageChooser, SIGNAL(openHelpUrl(QString)),
            Core::HelpManager::instance(), SLOT(handleHelpRequest(QString)));
309

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

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

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

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

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

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

Tobias Hunger's avatar
Tobias Hunger committed
335 336 337 338
Qt4RunConfigurationWidget::~Qt4RunConfigurationWidget()
{
}

339 340 341 342 343 344 345 346 347 348
void Qt4RunConfigurationWidget::useCppDebuggerToggled(bool toggled)
{
    m_qt4RunConfiguration->setUseCppDebugger(toggled);
}

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

349 350 351 352 353
void Qt4RunConfigurationWidget::qmlDebugServerPortChanged(uint port)
{
    m_qt4RunConfiguration->setQmlDebugServerPort(port);
}

354
void Qt4RunConfigurationWidget::baseEnvironmentSelected(int index)
355 356
{
    m_ignoreChange = true;
357
    m_qt4RunConfiguration->setBaseEnvironmentBase(Qt4RunConfiguration::BaseEnvironmentBase(index));
358 359

    m_environmentWidget->setBaseEnvironment(m_qt4RunConfiguration->baseEnvironment());
360
    m_environmentWidget->setBaseEnvironmentText(m_qt4RunConfiguration->baseEnvironmentText());
361 362 363
    m_ignoreChange = false;
}

364 365
void Qt4RunConfigurationWidget::baseEnvironmentChanged()
{
366 367 368
    if (m_ignoreChange)
        return;

369
    m_baseEnvironmentComboBox->setCurrentIndex(m_qt4RunConfiguration->baseEnvironmentBase());
370
    m_environmentWidget->setBaseEnvironment(m_qt4RunConfiguration->baseEnvironment());
371
    m_environmentWidget->setBaseEnvironmentText(m_qt4RunConfiguration->baseEnvironmentText());
372 373
}

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

381
void Qt4RunConfigurationWidget::userChangesEdited()
382 383 384 385
{
    m_ignoreChange = true;
    m_qt4RunConfiguration->setUserEnvironmentChanges(m_environmentWidget->userChanges());
    m_ignoreChange = false;
386 387
}

388 389 390 391 392
void Qt4RunConfigurationWidget::runConfigurationEnabledChange(bool enabled)
{
    setEnabled(enabled);
}

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

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

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

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

424 425 426 427 428 429 430
void Qt4RunConfigurationWidget::usingDyldImageSuffixToggled(bool state)
{
    m_ignoreChange = true;
    m_qt4RunConfiguration->setUsingDyldImageSuffix(state);
    m_ignoreChange = false;
}

431 432 433 434 435 436
void Qt4RunConfigurationWidget::workingDirectoryChanged(const QString &workingDirectory)
{
    if (!m_ignoreChange)
        m_workingDirectoryEdit->setPath(workingDirectory);
}

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

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

450 451 452 453 454 455
void Qt4RunConfigurationWidget::usingDyldImageSuffixChanged(bool state)
{
    if (!m_ignoreChange && m_usingDyldImageSuffix)
        m_usingDyldImageSuffix->setChecked(state);
}

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

466
void Qt4RunConfigurationWidget::showEvent(QShowEvent *event)
467
{
468 469 470
    m_isShown = true;
    effectiveTargetInformationChanged();
    QWidget::showEvent(event);
471 472
}

473 474 475 476 477
void Qt4RunConfigurationWidget::hideEvent(QHideEvent *event)
{
    m_isShown = false;
    QWidget::hideEvent(event);
}
478

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

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

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

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

512 513
    m_parseSuccess = qt4Target()->qt4Project()->validParse(m_proFilePath);

514
    return RunConfiguration::fromMap(map);
con's avatar
con committed
515 516 517 518
}

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

526
LocalApplicationRunConfiguration::RunMode Qt4RunConfiguration::runMode() const
con's avatar
con committed
527 528 529 530
{
    return m_runMode;
}

531 532 533 534 535 536 537 538 539 540 541
bool Qt4RunConfiguration::isUsingDyldImageSuffix() const
{
    return m_isUsingDyldImageSuffix;
}

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

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

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

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

562
QString Qt4RunConfiguration::commandLineArguments() const
563 564 565 566 567
{
    return Utils::QtcProcess::expandMacros(m_commandLineArguments, macroExpander());
}

QString Qt4RunConfiguration::rawCommandLineArguments() const
con's avatar
con committed
568 569 570 571
{
    return m_commandLineArguments;
}

572 573 574 575 576 577 578 579
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");
580
    return QString();
581 582
}

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

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

607
Utils::Environment Qt4RunConfiguration::environment() const
608
{
609
    Utils::Environment env = baseEnvironment();
610 611 612 613
    env.modify(userEnvironmentChanges());
    return env;
}

614
QList<Utils::EnvironmentItem> Qt4RunConfiguration::userEnvironmentChanges() const
615 616 617 618
{
    return m_userEnvironmentChanges;
}

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

627
void Qt4RunConfiguration::setBaseWorkingDirectory(const QString &wd)
628
{
629 630 631 632 633 634 635
    const QString &oldWorkingDirectory = workingDirectory();

    m_userWorkingDirectory = wd;

    const QString &newWorkingDirectory = workingDirectory();
    if (oldWorkingDirectory != newWorkingDirectory)
        emit baseWorkingDirectoryChanged(newWorkingDirectory);
636 637
}

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

644 645 646 647 648 649
void Qt4RunConfiguration::setRunMode(RunMode runMode)
{
    m_runMode = runMode;
    emit runModeChanged(runMode);
}

con's avatar
con committed
650 651 652 653 654
QString Qt4RunConfiguration::proFilePath() const
{
    return m_proFilePath;
}

655 656
QString Qt4RunConfiguration::dumperLibrary() const
{
657
    QtSupport::BaseQtVersion *version = qt4Target()->activeBuildConfiguration()->qtVersion();
Tobias Hunger's avatar
Tobias Hunger committed
658
    if (version)
659
        return version->gdbDebuggingHelperLibrary();
660
    return QString();
661 662
}

663 664
QStringList Qt4RunConfiguration::dumperLibraryLocations() const
{
665
    QtSupport::BaseQtVersion *version = qt4Target()->activeBuildConfiguration()->qtVersion();
Tobias Hunger's avatar
Tobias Hunger committed
666
    if (version)
667
        return version->debuggingHelperLibraryLocations();
668
    return QStringList();
669 670
}

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

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

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

con's avatar
con committed
694
Utils::OutputFormatter *Qt4RunConfiguration::createOutputFormatter() const
dt's avatar
dt committed
695
{
696
    return new QtSupport::QtOutputFormatter(qt4Target()->qt4Project());
dt's avatar
dt committed
697 698
}

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

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

Qt4RunConfigurationFactory::~Qt4RunConfigurationFactory()
{
}

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

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

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

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

    delete rc;
    return 0;
}

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

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

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