qt4runconfiguration.cpp 28.6 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 109
    m_parseSuccess(parent->qt4Project()->validParse(m_proFilePath)),
    m_parseInProgress(parent->qt4Project()->parseInProgress(m_proFilePath))
110 111
{
    ctor();
con's avatar
con committed
112 113
}

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

129
Qt4RunConfiguration::~Qt4RunConfiguration()
dt's avatar
dt committed
130 131 132
{
}

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

138
bool Qt4RunConfiguration::isEnabled() const
139
{
140
    return m_parseSuccess && !m_parseInProgress;
141
}
142

dt_'s avatar
dt_ committed
143 144
QString Qt4RunConfiguration::disabledReason() const
{
145 146
    if (m_parseInProgress)
        return tr("The .pro file is currently being parsed.");
dt_'s avatar
dt_ committed
147
    if (!m_parseSuccess)
148
        return tr("The .pro file could not be parsed.");
dt_'s avatar
dt_ committed
149 150 151
    return QString();
}

152
void Qt4RunConfiguration::proFileUpdated(Qt4ProjectManager::Qt4ProFileNode *pro, bool success, bool parseInProgress)
153
{
154 155 156
    if (m_proFilePath != pro->path())
        return;

157 158
    bool enabled = isEnabled();
    m_parseSuccess = success;
159
    m_parseInProgress = parseInProgress;
160 161 162
    if (enabled != isEnabled())
        emit isEnabledChanged(!enabled);

163 164 165 166
    if (!parseInProgress) {
        emit effectiveTargetInformationChanged();
        emit baseEnvironmentChanged();
    }
167 168
}

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

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

179 180 181 182 183
//////
/// Qt4RunConfigurationWidget
/////

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

193 194 195 196 197 198 199 200 201 202 203
    QHBoxLayout *hl = new QHBoxLayout();
    hl->addStretch();
    m_disabledIcon = new QLabel(this);
    m_disabledIcon->setPixmap(QPixmap(QString::fromUtf8(":/projectexplorer/images/compile_warning.png")));
    hl->addWidget(m_disabledIcon);
    m_disabledReason = new QLabel(this);
    m_disabledReason->setVisible(false);
    hl->addWidget(m_disabledReason);
    hl->addStretch();
    vboxTopLayout->addLayout(hl);

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

213 214 215
    m_executableLineEdit = new QLineEdit(m_qt4RunConfiguration->executable(), this);
    m_executableLineEdit->setEnabled(false);
    toplayout->addRow(tr("Executable:"), m_executableLineEdit);
con's avatar
con committed
216

Tobias Hunger's avatar
Tobias Hunger committed
217
    QLabel *argumentsLabel = new QLabel(tr("Arguments:"), this);
218
    m_argumentsLineEdit = new QLineEdit(qt4RunConfiguration->rawCommandLineArguments(), this);
219 220 221
    argumentsLabel->setBuddy(m_argumentsLineEdit);
    toplayout->addRow(argumentsLabel, m_argumentsLineEdit);

Tobias Hunger's avatar
Tobias Hunger committed
222
    m_workingDirectoryEdit = new Utils::PathChooser(this);
223
    m_workingDirectoryEdit->setExpectedKind(Utils::PathChooser::Directory);
224
    m_workingDirectoryEdit->setPath(m_qt4RunConfiguration->baseWorkingDirectory());
225
    m_workingDirectoryEdit->setBaseDirectory(m_qt4RunConfiguration->target()->project()->projectDirectory());
226
    m_workingDirectoryEdit->setEnvironment(m_qt4RunConfiguration->environment());
227
    m_workingDirectoryEdit->setPromptDialogTitle(tr("Select Working Directory"));
228

Tobias Hunger's avatar
Tobias Hunger committed
229
    QToolButton *resetButton = new QToolButton(this);
230
    resetButton->setToolTip(tr("Reset to default"));
231
    resetButton->setIcon(QIcon(QLatin1String(Core::Constants::ICON_RESET)));
232 233

    QHBoxLayout *boxlayout = new QHBoxLayout();
234
    boxlayout->setMargin(0);
235 236
    boxlayout->addWidget(m_workingDirectoryEdit);
    boxlayout->addWidget(resetButton);
237
    toplayout->addRow(tr("Working directory:"), boxlayout);
con's avatar
con committed
238

239
    m_useTerminalCheck = new QCheckBox(tr("Run in terminal"), this);
240
    m_useTerminalCheck->setChecked(m_qt4RunConfiguration->runMode() == ProjectExplorer::LocalApplicationRunConfiguration::Console);
241
    toplayout->addRow(QString(), m_useTerminalCheck);
242
    m_useTerminalCheck->setVisible(qt4RunConfiguration->target()->id() != Constants::QT_SIMULATOR_TARGET_ID);
243

244
    QLabel *debuggerLabel = new QLabel(tr("Debugger:"), this);
245
    debuggerLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::MinimumExpanding);
246

247
    m_debuggerLanguageChooser = new Utils::DebuggerLanguageChooser(this);
248
    toplayout->addRow(debuggerLabel, m_debuggerLanguageChooser);
249 250 251

    m_debuggerLanguageChooser->setCppChecked(m_qt4RunConfiguration->useCppDebugger());
    m_debuggerLanguageChooser->setQmlChecked(m_qt4RunConfiguration->useQmlDebugger());
252
    m_debuggerLanguageChooser->setQmlDebugServerPort(m_qt4RunConfiguration->qmlDebugServerPort());
253

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

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

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

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

293
    runConfigurationEnabledChange(m_qt4RunConfiguration->isEnabled());
294

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

    connect(resetButton, SIGNAL(clicked()),
299
            this, SLOT(workingDirectoryReseted()));
300

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

306 307 308 309
    connect(m_debuggerLanguageChooser, SIGNAL(cppLanguageToggled(bool)),
            this, SLOT(useCppDebuggerToggled(bool)));
    connect(m_debuggerLanguageChooser, SIGNAL(qmlLanguageToggled(bool)),
            this, SLOT(useQmlDebuggerToggled(bool)));
310 311
    connect(m_debuggerLanguageChooser, SIGNAL(qmlDebugServerPortChanged(uint)),
            this, SLOT(qmlDebugServerPortChanged(uint)));
312 313
    connect(m_debuggerLanguageChooser, SIGNAL(openHelpUrl(QString)),
            Core::HelpManager::instance(), SLOT(handleHelpRequest(QString)));
314

315 316
    connect(m_environmentWidget, SIGNAL(userChangesChanged()),
            this, SLOT(userChangesEdited()));
317

318
    connect(qt4RunConfiguration, SIGNAL(baseWorkingDirectoryChanged(QString)),
319 320
            this, SLOT(workingDirectoryChanged(QString)));

321
    connect(qt4RunConfiguration, SIGNAL(commandLineArgumentsChanged(QString)),
322
            this, SLOT(commandLineArgumentsChanged(QString)));
323 324
    connect(qt4RunConfiguration, SIGNAL(runModeChanged(ProjectExplorer::LocalApplicationRunConfiguration::RunMode)),
            this, SLOT(runModeChanged(ProjectExplorer::LocalApplicationRunConfiguration::RunMode)));
325 326
    connect(qt4RunConfiguration, SIGNAL(usingDyldImageSuffixChanged(bool)),
            this, SLOT(usingDyldImageSuffixChanged(bool)));
327 328
    connect(qt4RunConfiguration, SIGNAL(effectiveTargetInformationChanged()),
            this, SLOT(effectiveTargetInformationChanged()), Qt::QueuedConnection);
329

330 331
    connect(qt4RunConfiguration, SIGNAL(userEnvironmentChangesChanged(QList<Utils::EnvironmentItem>)),
            this, SLOT(userEnvironmentChangesChanged(QList<Utils::EnvironmentItem>)));
332

333 334
    connect(qt4RunConfiguration, SIGNAL(baseEnvironmentChanged()),
            this, SLOT(baseEnvironmentChanged()));
335 336 337

    connect(qt4RunConfiguration, SIGNAL(isEnabledChanged(bool)),
            this, SLOT(runConfigurationEnabledChange(bool)));
338 339
}

Tobias Hunger's avatar
Tobias Hunger committed
340 341 342 343
Qt4RunConfigurationWidget::~Qt4RunConfigurationWidget()
{
}

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

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

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

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

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

369 370
void Qt4RunConfigurationWidget::baseEnvironmentChanged()
{
371 372 373
    if (m_ignoreChange)
        return;

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

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

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

393 394
void Qt4RunConfigurationWidget::runConfigurationEnabledChange(bool enabled)
{
395 396 397 398 399
    m_detailsContainer->setEnabled(enabled);
    m_environmentWidget->setEnabled(enabled);
    m_disabledIcon->setVisible(!enabled);
    m_disabledReason->setVisible(!enabled);
    m_disabledReason->setText(m_qt4RunConfiguration->disabledReason());
400 401
}

402
void Qt4RunConfigurationWidget::workDirectoryEdited()
403 404 405 406
{
    if (m_ignoreChange)
        return;
    m_ignoreChange = true;
407
    m_qt4RunConfiguration->setBaseWorkingDirectory(m_workingDirectoryEdit->rawPath());
408 409 410
    m_ignoreChange = false;
}

411
void Qt4RunConfigurationWidget::workingDirectoryReseted()
412 413 414
{
    // This emits a signal connected to workingDirectoryChanged()
    // that sets the m_workingDirectoryEdit
415
    m_qt4RunConfiguration->setBaseWorkingDirectory("");
416 417
}

418
void Qt4RunConfigurationWidget::argumentsEdited(const QString &args)
419 420
{
    m_ignoreChange = true;
421
    m_qt4RunConfiguration->setCommandLineArguments(args);
422 423 424
    m_ignoreChange = false;
}

425 426 427
void Qt4RunConfigurationWidget::termToggled(bool on)
{
    m_ignoreChange = true;
428 429
    m_qt4RunConfiguration->setRunMode(on ? LocalApplicationRunConfiguration::Console
                                         : LocalApplicationRunConfiguration::Gui);
430 431 432
    m_ignoreChange = false;
}

433 434 435 436 437 438 439
void Qt4RunConfigurationWidget::usingDyldImageSuffixToggled(bool state)
{
    m_ignoreChange = true;
    m_qt4RunConfiguration->setUsingDyldImageSuffix(state);
    m_ignoreChange = false;
}

440 441 442 443 444 445
void Qt4RunConfigurationWidget::workingDirectoryChanged(const QString &workingDirectory)
{
    if (!m_ignoreChange)
        m_workingDirectoryEdit->setPath(workingDirectory);
}

446 447
void Qt4RunConfigurationWidget::commandLineArgumentsChanged(const QString &args)
{
dt's avatar
dt committed
448 449 450
    if (m_ignoreChange)
        return;
    m_argumentsLineEdit->setText(args);
451 452
}

453
void Qt4RunConfigurationWidget::runModeChanged(LocalApplicationRunConfiguration::RunMode runMode)
454 455
{
    if (!m_ignoreChange)
456
        m_useTerminalCheck->setChecked(runMode == LocalApplicationRunConfiguration::Console);
457 458
}

459 460 461 462 463 464
void Qt4RunConfigurationWidget::usingDyldImageSuffixChanged(bool state)
{
    if (!m_ignoreChange && m_usingDyldImageSuffix)
        m_usingDyldImageSuffix->setChecked(state);
}

465
void Qt4RunConfigurationWidget::effectiveTargetInformationChanged()
466
{
467
    if (m_isShown) {
468
        m_executableLineEdit->setText(QDir::toNativeSeparators(m_qt4RunConfiguration->executable()));
469
        m_ignoreChange = true;
470
        m_workingDirectoryEdit->setPath(QDir::toNativeSeparators(m_qt4RunConfiguration->baseWorkingDirectory()));
471
        m_ignoreChange = false;
472
    }
473 474
}

475
void Qt4RunConfigurationWidget::showEvent(QShowEvent *event)
476
{
477 478 479
    m_isShown = true;
    effectiveTargetInformationChanged();
    QWidget::showEvent(event);
480 481
}

482 483 484 485 486
void Qt4RunConfigurationWidget::hideEvent(QHideEvent *event)
{
    m_isShown = false;
    QWidget::hideEvent(event);
}
487

488
////// TODO c&p above
489
QWidget *Qt4RunConfiguration::createConfigurationWidget()
490 491
{
    return new Qt4RunConfigurationWidget(this, 0);
con's avatar
con committed
492 493
}

494
QVariantMap Qt4RunConfiguration::toMap() const
con's avatar
con committed
495
{
496
    const QDir projectDir = QDir(target()->project()->projectDirectory());
497 498 499 500 501
    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);
502
    map.insert(QLatin1String(USER_ENVIRONMENT_CHANGES_KEY), Utils::EnvironmentItem::toStringList(m_userEnvironmentChanges));
503 504 505
    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
506 507
}

508
bool Qt4RunConfiguration::fromMap(const QVariantMap &map)
509
{
510
    const QDir projectDir = QDir(target()->project()->projectDirectory());
511
    m_commandLineArguments = map.value(QLatin1String(COMMAND_LINE_ARGUMENTS_KEY)).toString();
512 513 514 515 516 517
    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();

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

521
    m_parseSuccess = qt4Target()->qt4Project()->validParse(m_proFilePath);
522
    m_parseInProgress = qt4Target()->qt4Project()->parseInProgress(m_proFilePath);
523

524
    return RunConfiguration::fromMap(map);
con's avatar
con committed
525 526 527 528
}

QString Qt4RunConfiguration::executable() const
{
dt's avatar
dt committed
529 530 531 532 533
    Qt4Project *pro = qt4Target()->qt4Project();
    TargetInformation ti = pro->rootProjectNode()->targetInformation(m_proFilePath);
    if (!ti.valid)
        return QString();
    return ti.executable;
con's avatar
con committed
534 535
}

536
LocalApplicationRunConfiguration::RunMode Qt4RunConfiguration::runMode() const
con's avatar
con committed
537 538 539 540
{
    return m_runMode;
}

541 542 543 544 545 546 547 548 549 550 551
bool Qt4RunConfiguration::isUsingDyldImageSuffix() const
{
    return m_isUsingDyldImageSuffix;
}

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

con's avatar
con committed
552
QString Qt4RunConfiguration::workingDirectory() const
553
{
554 555
    return QDir::cleanPath(environment().expandVariables(
                Utils::expandMacros(baseWorkingDirectory(), macroExpander())));
556 557 558
}

QString Qt4RunConfiguration::baseWorkingDirectory() const
con's avatar
con committed
559
{
560
    // if the user overrode us, then return his working directory
561
    if (!m_userWorkingDirectory.isEmpty())
562 563 564
        return m_userWorkingDirectory;

    // else what the pro file reader tells us
dt's avatar
dt committed
565 566 567 568 569
    Qt4Project *pro = qt4Target()->qt4Project();
    TargetInformation ti = pro->rootProjectNode()->targetInformation(m_proFilePath);
    if(!ti.valid)
        return QString();
    return ti.workingDir;
con's avatar
con committed
570 571
}

572
QString Qt4RunConfiguration::commandLineArguments() const
573 574 575 576 577
{
    return Utils::QtcProcess::expandMacros(m_commandLineArguments, macroExpander());
}

QString Qt4RunConfiguration::rawCommandLineArguments() const
con's avatar
con committed
578 579 580 581
{
    return m_commandLineArguments;
}

582 583 584 585 586 587 588 589
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");
590
    return QString();
591 592
}

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

607
    // The user could be linking to a library found via a -L/some/dir switch
608
    // to find those libraries while actually running we explicitly prepend those
609
    // dirs to the library search path
610
    const Qt4ProFileNode *node = qt4Target()->qt4Project()->rootProjectNode()->findProFileFor(m_proFilePath);
611
    if (node)
612 613
        foreach(const QString &dir, node->variableValue(LibDirectoriesVar))
            env.prependOrSetLibrarySearchPath(dir);
614
    return env;
con's avatar
con committed
615 616
}

617
Utils::Environment Qt4RunConfiguration::environment() const
618
{
619
    Utils::Environment env = baseEnvironment();
620 621 622 623
    env.modify(userEnvironmentChanges());
    return env;
}

624
QList<Utils::EnvironmentItem> Qt4RunConfiguration::userEnvironmentChanges() const
625 626 627 628
{
    return m_userEnvironmentChanges;
}

629
void Qt4RunConfiguration::setUserEnvironmentChanges(const QList<Utils::EnvironmentItem> &diff)
630 631 632 633 634 635 636
{
    if (m_userEnvironmentChanges != diff) {
        m_userEnvironmentChanges = diff;
        emit userEnvironmentChangesChanged(diff);
    }
}

637
void Qt4RunConfiguration::setBaseWorkingDirectory(const QString &wd)
638
{
639 640 641 642 643 644 645
    const QString &oldWorkingDirectory = workingDirectory();

    m_userWorkingDirectory = wd;

    const QString &newWorkingDirectory = workingDirectory();
    if (oldWorkingDirectory != newWorkingDirectory)
        emit baseWorkingDirectoryChanged(newWorkingDirectory);
646 647
}

648
void Qt4RunConfiguration::setCommandLineArguments(const QString &argumentsString)
con's avatar
con committed
649
{
650 651
    m_commandLineArguments = argumentsString;
    emit commandLineArgumentsChanged(argumentsString);
con's avatar
con committed
652 653
}

654 655 656 657 658 659
void Qt4RunConfiguration::setRunMode(RunMode runMode)
{
    m_runMode = runMode;
    emit runModeChanged(runMode);
}

con's avatar
con committed
660 661 662 663 664
QString Qt4RunConfiguration::proFilePath() const
{
    return m_proFilePath;
}

665 666
QString Qt4RunConfiguration::dumperLibrary() const
{
667
    QtSupport::BaseQtVersion *version = qt4Target()->activeBuildConfiguration()->qtVersion();
Tobias Hunger's avatar
Tobias Hunger committed
668
    if (version)
669
        return version->gdbDebuggingHelperLibrary();
670
    return QString();
671 672
}

673 674
QStringList Qt4RunConfiguration::dumperLibraryLocations() const
{
675
    QtSupport::BaseQtVersion *version = qt4Target()->activeBuildConfiguration()->qtVersion();
Tobias Hunger's avatar
Tobias Hunger committed
676
    if (version)
677
        return version->debuggingHelperLibraryLocations();
678
    return QStringList();
679 680
}

681
QString Qt4RunConfiguration::defaultDisplayName()
682
{
683
    QString defaultName;
684
    if (!m_proFilePath.isEmpty())
685
        defaultName = QFileInfo(m_proFilePath).completeBaseName();
686
    else
687 688
        defaultName = tr("Qt4 RunConfiguration");
    return defaultName;
689 690
}

691 692 693 694 695 696 697 698 699 700 701 702
void Qt4RunConfiguration::setBaseEnvironmentBase(BaseEnvironmentBase env)
{
    if (m_baseEnvironmentBase == env)
        return;
    m_baseEnvironmentBase = env;
    emit baseEnvironmentChanged();
}

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

con's avatar
con committed
704
Utils::OutputFormatter *Qt4RunConfiguration::createOutputFormatter() const
dt's avatar
dt committed
705
{
706
    return new QtSupport::QtOutputFormatter(qt4Target()->qt4Project());
dt's avatar
dt committed
707 708
}

con's avatar
con committed
709 710 711 712 713
///
/// Qt4RunConfigurationFactory
/// This class is used to restore run settings (saved in .user files)
///

714 715
Qt4RunConfigurationFactory::Qt4RunConfigurationFactory(QObject *parent) :
    ProjectExplorer::IRunConfigurationFactory(parent)
con's avatar
con committed
716 717 718 719 720 721 722
{
}

Qt4RunConfigurationFactory::~Qt4RunConfigurationFactory()
{
}

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

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

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

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

    delete rc;
    return 0;
}

Tobias Hunger's avatar
Tobias Hunger committed
764
bool Qt4RunConfigurationFactory::canClone(ProjectExplorer::Target *parent, ProjectExplorer::RunConfiguration *source) const
765
{
Tobias Hunger's avatar
Tobias Hunger committed
766
    return canCreate(parent, source->id());
767 768
}

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