qt4target.cpp 42.5 KB
Newer Older
Tobias Hunger's avatar
Tobias Hunger committed
1
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).
Tobias Hunger's avatar
Tobias Hunger committed
6
**
hjk's avatar
hjk committed
7
** Contact: Nokia Corporation (info@qt.nokia.com)
Tobias Hunger's avatar
Tobias Hunger committed
8
9
10
11
**
**
** GNU Lesser General Public License Usage
**
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.
Tobias Hunger's avatar
Tobias Hunger committed
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.
Tobias Hunger's avatar
Tobias Hunger committed
30
31
32
33
**
**************************************************************************/

#include "qt4target.h"
34
#include "buildconfigurationinfo.h"
Tobias Hunger's avatar
Tobias Hunger committed
35
36
37
38

#include "makestep.h"
#include "qmakestep.h"
#include "qt4project.h"
39
#include "qt4basetargetfactory.h"
40
#include "qt4projectconfigwidget.h"
41
#include "qt4projectmanagerconstants.h"
Tobias Hunger's avatar
Tobias Hunger committed
42

dt's avatar
dt committed
43
#include <coreplugin/icore.h>
44
#include <extensionsystem/pluginmanager.h>
Tobias Hunger's avatar
Tobias Hunger committed
45
#include <projectexplorer/buildsteplist.h>
46
#include <projectexplorer/runconfiguration.h>
47
#include <projectexplorer/customexecutablerunconfiguration.h>
48
#include <projectexplorer/toolchainmanager.h>
Tobias Hunger's avatar
Tobias Hunger committed
49
#include <projectexplorer/projectexplorerconstants.h>
dt's avatar
dt committed
50
#include <projectexplorer/task.h>
51
52
#include <qtsupport/qtversionfactory.h>
#include <qtsupport/baseqtversion.h>
dt's avatar
dt committed
53
54
55
#include <utils/pathchooser.h>
#include <utils/detailswidget.h>

56
#include <QtCore/QCoreApplication>
dt's avatar
dt committed
57
58
59
#include <QtGui/QPushButton>
#include <QtGui/QMessageBox>
#include <QtGui/QCheckBox>
60
#include <QtGui/QComboBox>
61
62
#include <QtGui/QHBoxLayout>
#include <QtGui/QLabel>
dt's avatar
dt committed
63
#include <QtGui/QMainWindow>
64
#include <QtGui/QVBoxLayout>
Tobias Hunger's avatar
Tobias Hunger committed
65

66
67
#include <algorithm>

Tobias Hunger's avatar
Tobias Hunger committed
68
69
70
71
using namespace Qt4ProjectManager;
using namespace Qt4ProjectManager::Internal;

// -------------------------------------------------------------------------
72
// Qt4BaseTargetFactory
Tobias Hunger's avatar
Tobias Hunger committed
73
74
// -------------------------------------------------------------------------

75
Qt4BaseTargetFactory::Qt4BaseTargetFactory(QObject *parent) :
Tobias Hunger's avatar
Tobias Hunger committed
76
77
78
79
80
    ITargetFactory(parent)
{

}

81
Qt4BaseTargetFactory::~Qt4BaseTargetFactory()
Tobias Hunger's avatar
Tobias Hunger committed
82
83
{

84
85
}

dt's avatar
dt committed
86
87
Qt4TargetSetupWidget *Qt4BaseTargetFactory::createTargetSetupWidget(const QString &id,
                                                                    const QString &proFilePath,
88
                                                                    const QtSupport::QtVersionNumber &number,
dt's avatar
dt committed
89
90
91
                                                                    bool importEnabled,
                                                                    QList<BuildConfigurationInfo> importInfos)
{
92
93
94
    QList<BuildConfigurationInfo> infos = this->availableBuildConfigurations(id, proFilePath, number);
    if (infos.isEmpty())
        return 0;
95
96
97
98
99
100
101
102
    const bool supportsShadowBuilds
            = targetFeatures(id).contains(Constants::SHADOWBUILD_TARGETFEATURE_ID);
    Qt4DefaultTargetSetupWidget *widget
            = new Qt4DefaultTargetSetupWidget(this, id, proFilePath, infos, number,
                                              importEnabled && supportsShadowBuilds, importInfos,
                                              (supportsShadowBuilds
                                               ? Qt4DefaultTargetSetupWidget::ENABLE
                                               : Qt4DefaultTargetSetupWidget::DISABLE));
103
    return widget;
dt's avatar
dt committed
104
105
}

106
ProjectExplorer::Target *Qt4BaseTargetFactory::create(ProjectExplorer::Project *parent, const QString &id, Qt4TargetSetupWidget *widget)
dt's avatar
dt committed
107
108
109
110
111
{
    if (!widget->isTargetSelected())
        return 0;
    Q_ASSERT(qobject_cast<Qt4DefaultTargetSetupWidget *>(widget));
    Qt4DefaultTargetSetupWidget *w = static_cast<Qt4DefaultTargetSetupWidget *>(widget);
112
    w->storeSettings();
dt's avatar
dt committed
113
114
115
    return create(parent, id, w->buildConfigurationInfos());
}

116
QList<BuildConfigurationInfo> Qt4BaseTargetFactory::availableBuildConfigurations(const QString &id, const QString &proFilePath, const QtSupport::QtVersionNumber &minimumQtVersion)
117
118
{
    QList<BuildConfigurationInfo> infoList;
119
    QList<QtSupport::BaseQtVersion *> knownVersions = QtSupport::QtVersionManager::instance()->versionsForTargetId(id, minimumQtVersion);
120

121
    foreach (QtSupport::BaseQtVersion *version, knownVersions) {
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
122
        if (!version->isValid() || !version->toolChainAvailable(id))
123
            continue;
124
        QtSupport::BaseQtVersion::QmakeBuildConfigs config = version->defaultBuildConfig();
125
126
127
128
        BuildConfigurationInfo info = BuildConfigurationInfo(version, config, QString(), QString());
        info.directory = shadowBuildDirectory(proFilePath, id, msgBuildConfigurationName(info));
        infoList.append(info);

129
        info.buildConfig = config ^ QtSupport::BaseQtVersion::DebugBuild;
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
        info.directory = shadowBuildDirectory(proFilePath, id, msgBuildConfigurationName(info));
        infoList.append(info);
    }
    return infoList;
}

QString sanitize(const QString &input)
{
    QString result;
    result.reserve(input.size());
    foreach (const QChar &c, input) {
        if ((c >= 'a' && c <='z')
                || (c >= 'A' && c <= 'Z')
                || (c >= '0' && c <= '9')
                || c == '-'
                || c == '_')
            result.append(c);
        else
            result.append('_');
    }
    return result;
}

QString projectDirectory(const QString &proFile)
{
    if (proFile.isEmpty())
        return QString();
    QFileInfo info(proFile);
    return info.absoluteDir().path();
}

QString Qt4BaseTargetFactory::shadowBuildDirectory(const QString &profilePath, const QString &id, const QString &suffix)
{
    if (profilePath.isEmpty())
        return QString();
    QFileInfo info(profilePath);

    QString base = QDir::cleanPath(projectDirectory(profilePath) + QLatin1String("/../") + info.baseName() + QLatin1String("-build-"));
    return base + buildNameForId(id) + QLatin1String("-") + sanitize(suffix);
}

QString Qt4BaseTargetFactory::buildNameForId(const QString &id) const
{
    Q_UNUSED(id);
    return QString();
}

177
Qt4BaseTargetFactory *Qt4BaseTargetFactory::qt4BaseTargetFactoryForId(const QString &id)
178
{
179
180
181
182
    QList<Qt4BaseTargetFactory *> factories = ExtensionSystem::PluginManager::instance()->getObjects<Qt4BaseTargetFactory>();
    foreach (Qt4BaseTargetFactory *fac, factories) {
        if (fac->supportsTargetId(id))
            return fac;
183
    }
Tobias Hunger's avatar
Tobias Hunger committed
184
185
186
    return 0;
}

187
188
189
190
191
192
193
194
195
196
197
198
QList<Qt4BaseTargetFactory *> Qt4BaseTargetFactory::qt4BaseTargetFactoriesForIds(const QStringList &ids)
{
    QList<Qt4BaseTargetFactory *> factories;
    foreach (const QString &id, ids)
        if (Qt4BaseTargetFactory *factory = qt4BaseTargetFactoryForId(id))
            factories << factory;

    qSort(factories);
    factories.erase(std::unique(factories.begin(), factories.end()), factories.end());
    return factories;
}

199
200
201
202
// Return name of a build configuration.
QString Qt4BaseTargetFactory::msgBuildConfigurationName(const BuildConfigurationInfo &info)
{
    const QString qtVersionName = info.version->displayName();
203
    return (info.buildConfig & QtSupport::BaseQtVersion::DebugBuild) ?
204
205
        //: Name of a debug build configuration to created by a project wizard, %1 being the Qt version name. We recommend not translating it.
        tr("%1 Debug").arg(qtVersionName) :
206
        //: Name of a release build configuration to be created by a project wizard, %1 being the Qt version name. We recommend not translating it.
207
208
209
        tr("%1 Release").arg(qtVersionName);
}

210
211
QList<ProjectExplorer::Task> Qt4BaseTargetFactory::reportIssues(const QString &proFile)
{
Tobias Hunger's avatar
Tobias Hunger committed
212
    Q_UNUSED(proFile);
213
214
215
    return QList<ProjectExplorer::Task>();
}

216
217
218
219
220
221
bool Qt4BaseTargetFactory::selectByDefault(const QString &id) const
{
    Q_UNUSED(id);
    return true;
}

Tobias Hunger's avatar
Tobias Hunger committed
222
// -------------------------------------------------------------------------
223
// Qt4BaseTarget
Tobias Hunger's avatar
Tobias Hunger committed
224
225
// -------------------------------------------------------------------------

226
227
Qt4BaseTarget::Qt4BaseTarget(Qt4Project *parent, const QString &id) :
    ProjectExplorer::Target(parent, id)
Tobias Hunger's avatar
Tobias Hunger committed
228
229
{
    connect(this, SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)),
dt's avatar
dt committed
230
            this, SLOT(emitProFileEvaluateNeeded()));
Tobias Hunger's avatar
Tobias Hunger committed
231
232
    connect(this, SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)),
            this, SIGNAL(environmentChanged()));
233
234
    connect(this, SIGNAL(addedBuildConfiguration(ProjectExplorer::BuildConfiguration*)),
            this, SLOT(onAddedBuildConfiguration(ProjectExplorer::BuildConfiguration*)));
Tobias Hunger's avatar
Tobias Hunger committed
235
236
}

237
Qt4BaseTarget::~Qt4BaseTarget()
Tobias Hunger's avatar
Tobias Hunger committed
238
239
240
{
}

241
ProjectExplorer::BuildConfigWidget *Qt4BaseTarget::createConfigWidget()
242
243
244
245
{
    return new Qt4ProjectConfigWidget(this);
}

246
Qt4BuildConfiguration *Qt4BaseTarget::activeBuildConfiguration() const
Tobias Hunger's avatar
Tobias Hunger committed
247
248
249
250
{
    return static_cast<Qt4BuildConfiguration *>(Target::activeBuildConfiguration());
}

251
Qt4Project *Qt4BaseTarget::qt4Project() const
Tobias Hunger's avatar
Tobias Hunger committed
252
253
254
255
{
    return static_cast<Qt4Project *>(project());
}

256
QList<ProjectExplorer::ToolChain *> Qt4BaseTarget::possibleToolChains(ProjectExplorer::BuildConfiguration *bc) const
257
{
258
259
    QList<ProjectExplorer::ToolChain *> tmp;
    QList<ProjectExplorer::ToolChain *> result;
260

261
    Qt4BuildConfiguration *qt4bc = qobject_cast<Qt4BuildConfiguration *>(bc);
dt's avatar
dt committed
262
    if (!qt4bc || !qt4bc->qtVersion() || !qt4bc->qtVersion()->isValid())
263
264
265
266
267
268
269
270
271
272
273
274
275
        return tmp;

    QList<ProjectExplorer::Abi> abiList = qt4bc->qtVersion()->qtAbis();
    foreach (const ProjectExplorer::Abi &abi, abiList)
        tmp.append(ProjectExplorer::ToolChainManager::instance()->findToolChains(abi));

    foreach (ProjectExplorer::ToolChain *tc, tmp) {
        if (result.contains(tc))
            continue;
        if (tc->restrictedToTargets().isEmpty() || tc->restrictedToTargets().contains(id()))
            result.append(tc);
    }
    return result;
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
}

void Qt4BaseTarget::removeUnconfiguredCustomExectutableRunConfigurations()
{
    if (runConfigurations().count()) {
        // Remove all run configurations which the new project wizard created
        QList<ProjectExplorer::RunConfiguration*> toRemove;
        foreach (ProjectExplorer::RunConfiguration * rc, runConfigurations()) {
            ProjectExplorer::CustomExecutableRunConfiguration *cerc
                    = qobject_cast<ProjectExplorer::CustomExecutableRunConfiguration *>(rc);
            if (cerc && !cerc->isConfigured())
                toRemove.append(rc);
        }
        foreach (ProjectExplorer::RunConfiguration *rc, toRemove)
            removeRunConfiguration(rc);
    }
}

294
295
Qt4BuildConfiguration *Qt4BaseTarget::addQt4BuildConfiguration(QString defaultDisplayName,
                                                           QString displayName, QtSupport::BaseQtVersion *qtversion,
296
                                                           QtSupport::BaseQtVersion::QmakeBuildConfigs qmakeBuildConfiguration,
297
                                                           QString additionalArguments,
298
                                                           QString directory)
Tobias Hunger's avatar
Tobias Hunger committed
299
300
{
    Q_ASSERT(qtversion);
301
    bool debug = qmakeBuildConfiguration & QtSupport::BaseQtVersion::DebugBuild;
Tobias Hunger's avatar
Tobias Hunger committed
302
303
304

    // Add the buildconfiguration
    Qt4BuildConfiguration *bc = new Qt4BuildConfiguration(this);
305
306
    bc->setDefaultDisplayName(defaultDisplayName);
    bc->setDisplayName(displayName);
Tobias Hunger's avatar
Tobias Hunger committed
307

308
309
    ProjectExplorer::BuildStepList *buildSteps = bc->stepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
    ProjectExplorer::BuildStepList *cleanSteps = bc->stepList(ProjectExplorer::Constants::BUILDSTEPS_CLEAN);
Tobias Hunger's avatar
Tobias Hunger committed
310
311
312
313
314
315
316
317
    Q_ASSERT(buildSteps);
    Q_ASSERT(cleanSteps);

    QMakeStep *qmakeStep = new QMakeStep(buildSteps);
    buildSteps->insertStep(0, qmakeStep);

    MakeStep *makeStep = new MakeStep(buildSteps);
    buildSteps->insertStep(1, makeStep);
318

Tobias Hunger's avatar
Tobias Hunger committed
319
    MakeStep* cleanStep = new MakeStep(cleanSteps);
Tobias Hunger's avatar
Tobias Hunger committed
320
    cleanStep->setClean(true);
321
    cleanStep->setUserArguments("clean");
Tobias Hunger's avatar
Tobias Hunger committed
322
    cleanSteps->insertStep(0, cleanStep);
Tobias Hunger's avatar
Tobias Hunger committed
323
324
325
326
    if (!additionalArguments.isEmpty())
        qmakeStep->setUserArguments(additionalArguments);

    // set some options for qmake and make
327
    if (qmakeBuildConfiguration & QtSupport::BaseQtVersion::BuildAll) // debug_and_release => explicit targets
328
        makeStep->setUserArguments(debug ? "debug" : "release");
Tobias Hunger's avatar
Tobias Hunger committed
329
330
331

    bc->setQMakeBuildConfiguration(qmakeBuildConfiguration);

332
    // Finally set the qt version & tool chain
Tobias Hunger's avatar
Tobias Hunger committed
333
    bc->setQtVersion(qtversion);
334
335
    if (!directory.isEmpty())
        bc->setShadowBuildAndDirectory(directory != project()->projectDirectory(), directory);
Tobias Hunger's avatar
Tobias Hunger committed
336
337
338
339
340
    addBuildConfiguration(bc);

    return bc;
}

341
void Qt4BaseTarget::onAddedBuildConfiguration(ProjectExplorer::BuildConfiguration *bc)
342
343
344
345
346
347
{
    Q_ASSERT(bc);
    Qt4BuildConfiguration *qt4bc = qobject_cast<Qt4BuildConfiguration *>(bc);
    Q_ASSERT(qt4bc);
    connect(qt4bc, SIGNAL(buildDirectoryInitialized()),
            this, SIGNAL(buildDirectoryInitialized()));
348
349
    connect(qt4bc, SIGNAL(proFileEvaluateNeeded(Qt4ProjectManager::Qt4BuildConfiguration *)),
            this, SLOT(onProFileEvaluateNeeded(Qt4ProjectManager::Qt4BuildConfiguration *)));
350
351
}

352
void Qt4BaseTarget::onProFileEvaluateNeeded(Qt4ProjectManager::Qt4BuildConfiguration *bc)
353
354
{
    if (bc && bc == activeBuildConfiguration())
dt's avatar
dt committed
355
356
357
        emit proFileEvaluateNeeded(this);
}

358
void Qt4BaseTarget::emitProFileEvaluateNeeded()
dt's avatar
dt committed
359
360
{
    emit proFileEvaluateNeeded(this);
361
}
dt's avatar
dt committed
362
363
364
365
366

// -------------------------------------------------------------------------
// Qt4TargetSetupWidget
// -------------------------------------------------------------------------

367
368
Qt4TargetSetupWidget::Qt4TargetSetupWidget(QWidget *parent)
    : QWidget(parent)
dt's avatar
dt committed
369
370
371
372
373
374
375
376
377
378
379
380
381
{

}

Qt4TargetSetupWidget::~Qt4TargetSetupWidget()
{

}

// -------------------------------------------------------------------------
// Qt4DefaultTargetSetupWidget
// -------------------------------------------------------------------------

dt's avatar
dt committed
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
QString issuesListToString(const QList<ProjectExplorer::Task> &issues)
{
    QStringList lines;
    foreach (const ProjectExplorer::Task &t, issues) {
        // set severity:
        QString severity;
        if (t.type == ProjectExplorer::Task::Error)
            severity = QCoreApplication::translate("Qt4DefaultTargetSetupWidget", "<b>Error:</b> ", "Severity is Task::Error");
        else if (t.type == ProjectExplorer::Task::Warning)
            severity = QCoreApplication::translate("Qt4DefaultTargetSetupWidget", "<b>Warning:</b> ", "Severity is Task::Warning");
        lines.append(severity + t.description);
    }
    return lines.join("<br>");
}

dt's avatar
dt committed
397
398
399
Qt4DefaultTargetSetupWidget::Qt4DefaultTargetSetupWidget(Qt4BaseTargetFactory *factory,
                                                         const QString &id,
                                                         const QString &proFilePath,
400
                                                         const QList<BuildConfigurationInfo> &infos,
401
                                                         const QtSupport::QtVersionNumber &minimumQtVersion,
dt's avatar
dt committed
402
                                                         bool importEnabled,
403
404
                                                         const QList<BuildConfigurationInfo> &importInfos,
                                                         ShadowBuildOption shadowBuild)
dt's avatar
dt committed
405
406
407
408
409
410
411
412
413
414
    : Qt4TargetSetupWidget(),
      m_id(id),
      m_factory(factory),
      m_proFilePath(proFilePath),
      m_minimumQtVersion(minimumQtVersion),
      m_importInfos(importInfos),
      m_directoriesEnabled(true),
      m_hasInSourceBuild(false),
      m_ignoreChange(false),
      m_showImport(importEnabled),
415
      m_buildConfigurationTemplateUnchanged(true),
416
      m_shadowBuildCheckBoxVisible(false),
417
418
      m_selected(0),
      m_qtVersionId(-1)
dt's avatar
dt committed
419
{
420
    QSettings *s = Core::ICore::instance()->settings();
dt's avatar
dt committed
421
422
423
424
425
    QString sourceDir = QFileInfo(m_proFilePath).absolutePath();

    setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
    QVBoxLayout *vboxLayout = new QVBoxLayout();
    setLayout(vboxLayout);
con's avatar
con committed
426
    vboxLayout->setContentsMargins(0, 0, 0, 0);
dt's avatar
dt committed
427
428
    m_detailsWidget = new Utils::DetailsWidget(this);
    m_detailsWidget->setUseCheckBox(true);
429
    m_detailsWidget->setSummaryText(factory->displayNameForId(id));
dt's avatar
dt committed
430
    m_detailsWidget->setChecked(false);
dt's avatar
dt committed
431
432
    m_detailsWidget->setSummaryFontBold(true);
    m_detailsWidget->setIcon(factory->iconForId(id));
dt's avatar
dt committed
433
    m_detailsWidget->setAdditionalSummaryText(issuesListToString(factory->reportIssues(m_proFilePath)));
dt's avatar
dt committed
434
435
436
437
438
    vboxLayout->addWidget(m_detailsWidget);

    QWidget *widget = new QWidget;
    QVBoxLayout *layout = new QVBoxLayout;
    widget->setLayout(layout);
con's avatar
con committed
439
    layout->setContentsMargins(0, 0, 0, 0);
dt's avatar
dt committed
440

con's avatar
con committed
441
    QWidget *w = new QWidget;
dt's avatar
dt committed
442
443
    m_importLayout = new QGridLayout;
    m_importLayout->setMargin(0);
con's avatar
con committed
444
445
    w->setLayout(m_importLayout);
    layout->addWidget(w);
dt's avatar
dt committed
446

con's avatar
con committed
447
    w = new QWidget;
dt's avatar
dt committed
448
    m_importLineLayout = new QHBoxLayout();
con's avatar
con committed
449
450
    m_importLineLayout->setContentsMargins(0, 0, 0, 0);
    w->setLayout(m_importLineLayout);
dt's avatar
dt committed
451
    m_importLineLabel = new QLabel();
dt's avatar
dt committed
452
    m_importLineLabel->setText(tr("Add build from:"));
dt's avatar
dt committed
453
454
455
456
457
458
459
460
461
    m_importLineLayout->addWidget(m_importLineLabel);

    m_importLinePath = new Utils::PathChooser();
    m_importLinePath->setExpectedKind(Utils::PathChooser::ExistingDirectory);
    m_importLinePath->setPath(sourceDir);
    m_importLineLayout->addWidget(m_importLinePath);

    m_importLineButton = new QPushButton;
    m_importLineButton->setText(tr("Add Build"));
con's avatar
con committed
462
463
464
    m_importLineButton->setAttribute(Qt::WA_MacSmallSize);
    // make it in line with import path chooser button on mac
    m_importLineButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
dt's avatar
dt committed
465
    m_importLineLayout->addWidget(m_importLineButton);
466
    m_importLineLayout->addStretch();
con's avatar
con committed
467
    layout->addWidget(w);
dt's avatar
dt committed
468

469
470
471
    m_importLineLabel->setVisible(false);
    m_importLinePath->setVisible(false);
    m_importLineButton->setVisible(m_showImport);
dt's avatar
dt committed
472

473
    m_buildConfigurationLabel = new QLabel;
dt's avatar
dt committed
474
    m_buildConfigurationLabel->setText("Create Build Configurations:");
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
    m_buildConfigurationLabel->setVisible(false);

    m_buildConfigurationComboBox = new QComboBox;
    m_buildConfigurationComboBox->addItem("per Qt Version a Debug and Release", PERQT);
    m_buildConfigurationComboBox->addItem("for one Qt Version a Debug and Release", ONEQT);
    m_buildConfigurationComboBox->addItem("manually", MANUALLY);
    m_buildConfigurationComboBox->addItem("none", NONE);

    if (m_importInfos.isEmpty())
        m_buildConfigurationComboBox->setCurrentIndex(s->value("Qt4ProjectManager.TargetSetupPage.BuildTemplate", 0).toInt());
    else
        m_buildConfigurationComboBox->setCurrentIndex(3); // NONE

    m_buildConfigurationComboBox->setVisible(false);

    QHBoxLayout *hbox = new QHBoxLayout();
    hbox->addWidget(m_buildConfigurationLabel);
    hbox->addWidget(m_buildConfigurationComboBox);
    hbox->addStretch();
    layout->addLayout(hbox);

dt's avatar
dt committed
496
497
    m_shadowBuildEnabled = new QCheckBox;
    m_shadowBuildEnabled->setText(tr("Use Shadow Building"));
498
    m_shadowBuildCheckBoxVisible = shadowBuild == USER;
499

dt's avatar
dt committed
500
    layout->addWidget(m_shadowBuildEnabled);
dt's avatar
dt committed
501
    m_shadowBuildEnabled->setVisible(m_shadowBuildCheckBoxVisible);
dt's avatar
dt committed
502

503
504
505
506
507
508
509
510
511
512
513
    m_versionLabel = new QLabel;
    m_versionLabel->setText("Qt Version:");
    m_versionLabel->setVisible(false);
    m_versionComboBox = new QComboBox;
    m_versionComboBox->setVisible(false);
    hbox = new QHBoxLayout();
    hbox->addWidget(m_versionLabel);
    hbox->addWidget(m_versionComboBox);
    hbox->addStretch();
    layout->addLayout(hbox);

con's avatar
con committed
514
    w = new QWidget;
dt's avatar
dt committed
515
516
    m_newBuildsLayout = new QGridLayout;
    m_newBuildsLayout->setMargin(0);
con's avatar
con committed
517
518
519
520
521
#ifdef Q_WS_MAC
    m_newBuildsLayout->setSpacing(0);
#endif
    w->setLayout(m_newBuildsLayout);
    layout->addWidget(w);
dt's avatar
dt committed
522

dt's avatar
dt committed
523
    widget->setEnabled(false);
dt's avatar
dt committed
524
525
526
527
528
529
530
531
    m_detailsWidget->setWidget(widget);

    for (int i = 0; i < m_importInfos.size(); ++i) {
        if (m_importInfos.at(i).directory == sourceDir)
            m_hasInSourceBuild = true;
        m_importEnabled << true;
    }

532
    if (m_hasInSourceBuild || shadowBuild == DISABLE) {
533
        m_shadowBuildEnabled->setChecked(false);
534
535
536
537
538
539
540
541
        m_directoriesEnabled = false;
    } else if (shadowBuild == ENABLE) {
        m_shadowBuildEnabled->setChecked(true);
        m_directoriesEnabled = true;
    } else {
        m_directoriesEnabled = s->value("Qt4ProjectManager.TargetSetupPage.ShadowBuilding", true).toBool();
        m_shadowBuildEnabled->setChecked(m_directoriesEnabled);
    }
542

dt's avatar
dt committed
543
544
545
546
    m_selected += m_importInfos.size();

    setupImportWidgets();

547
    setBuildConfigurationInfos(infos);
dt's avatar
dt committed
548

549
550
551
552
553
554
    int qtVersionId = s->value("Qt4ProjectManager.TargetSetupPage.QtVersionId", -1).toInt();
    int index = m_versionComboBox->findData(qtVersionId);
    if (index != -1)
        m_versionComboBox->setCurrentIndex(index);
    qtVersionChanged();

dt's avatar
dt committed
555
556
557
558
559
560
561
    if (!m_importInfos.isEmpty())
        m_detailsWidget->setState(Utils::DetailsWidget::Expanded);

    connect(m_importLineButton, SIGNAL(clicked()),
            this, SLOT(addImportClicked()));

    connect(m_detailsWidget, SIGNAL(checked(bool)),
562
            this, SLOT(targetCheckBoxToggled(bool)));
dt's avatar
dt committed
563
564
    connect(m_shadowBuildEnabled, SIGNAL(toggled(bool)),
            this, SLOT(shadowBuildingToggled()));
565
566
567
568
    connect(m_buildConfigurationComboBox, SIGNAL(currentIndexChanged(int)),
            this, SLOT(buildConfigurationComboBoxChanged()));
    connect(m_versionComboBox, SIGNAL(currentIndexChanged(int)),
            this, SLOT(qtVersionChanged()));
dt's avatar
dt committed
569
570
571
572
}

Qt4DefaultTargetSetupWidget::~Qt4DefaultTargetSetupWidget()
{
573

dt's avatar
dt committed
574
575
576
577
}

bool Qt4DefaultTargetSetupWidget::isTargetSelected() const
{
578
579
580
581
    if (!m_detailsWidget->isChecked())
        return false;

    return !buildConfigurationInfos().isEmpty();
dt's avatar
dt committed
582
583
584
585
586
}

void Qt4DefaultTargetSetupWidget::setTargetSelected(bool b)
{
    // Only check target if there are build configurations possible
587
    b &= !buildConfigurationInfos().isEmpty();
588
    m_ignoreChange = true;
dt's avatar
dt committed
589
    m_detailsWidget->setChecked(b);
dt's avatar
dt committed
590
    m_detailsWidget->widget()->setEnabled(b);
591
    m_ignoreChange = false;
dt's avatar
dt committed
592
    // We want the shadow build option to be visible
593
594
    if (b && (m_shadowBuildEnabled->isVisibleTo(m_shadowBuildEnabled->parentWidget())
              || m_buildConfigurationComboBox->isVisibleTo(m_buildConfigurationComboBox->parentWidget())))
dt's avatar
dt committed
595
596
597
        m_detailsWidget->setState(Utils::DetailsWidget::Expanded);
}

598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
void Qt4DefaultTargetSetupWidget::targetCheckBoxToggled(bool b)
{
    if (m_ignoreChange)
        return;
    m_detailsWidget->widget()->setEnabled(b);
    if (b) {
        foreach (bool error, m_issues) {
            if (error) {
                m_detailsWidget->setState(Utils::DetailsWidget::Expanded);
                break;
            }
        }
    }
    emit selectedToggled();
}

dt's avatar
dt committed
614
615
616
QString Qt4DefaultTargetSetupWidget::displayNameFrom(const BuildConfigurationInfo &info)
{
    QString buildType;
617
618
    if ((info.buildConfig & QtSupport::BaseQtVersion::BuildAll) == 0) {
        if (info.buildConfig & QtSupport::BaseQtVersion::DebugBuild)
dt's avatar
dt committed
619
620
621
622
623
624
            //: Debug build
            buildType = tr("debug");
        else
            //: release build
            buildType = tr("release");
    }
625
    return info.version->displayName() + ' ' + buildType;
dt's avatar
dt committed
626
627
628
629
630
}

void Qt4DefaultTargetSetupWidget::setProFilePath(const QString &proFilePath)
{
    m_proFilePath = proFilePath;
dt's avatar
dt committed
631
    m_detailsWidget->setAdditionalSummaryText(issuesListToString(m_factory->reportIssues(m_proFilePath)));
dt's avatar
dt committed
632
633
634
    setBuildConfigurationInfos(m_factory->availableBuildConfigurations(m_id, proFilePath, m_minimumQtVersion), false);
}

635
636
void Qt4DefaultTargetSetupWidget::setBuildConfiguraionComboBoxVisible(bool b)
{
637
638
    m_buildConfigurationLabel->setVisible(b);
    m_buildConfigurationComboBox->setVisible(b);
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
    updateWidgetVisibility();
}


Qt4DefaultTargetSetupWidget::BuildConfigurationTemplate Qt4DefaultTargetSetupWidget::buildConfigurationTemplate() const
{
    if (!m_buildConfigurationComboBox->isVisibleTo(m_buildConfigurationComboBox->parentWidget()))
        return MANUALLY; // the default
    return static_cast<BuildConfigurationTemplate>(m_buildConfigurationComboBox->itemData(m_buildConfigurationComboBox->currentIndex()).toInt());
}

void Qt4DefaultTargetSetupWidget::setBuildConfigurationTemplate(Qt4DefaultTargetSetupWidget::BuildConfigurationTemplate value)
{
    int index = m_buildConfigurationComboBox->findData(QVariant::fromValue(int(value)));
    m_buildConfigurationComboBox->setCurrentIndex(index);
}

void Qt4DefaultTargetSetupWidget::storeSettings() const
{
    bool importing = false;
    for (int i=0; i < m_importEnabled.size(); ++i) {
        if (m_importEnabled.at(i)) {
            importing = true;
            break;
        }
    }

    QSettings *s = Core::ICore::instance()->settings();
    s->setValue("Qt4ProjectManager.TargetSetupPage.ShadowBuilding", m_shadowBuildEnabled->isChecked());
    int id = -1;
    int ci = m_versionComboBox->currentIndex();
    if (ci != -1)
        id = m_versionComboBox->itemData(ci).toInt();
    s->setValue("Qt4ProjectManager.TargetSetupPage.QtVersionId", id);

    // if we are importing we don't save the template setting
    // essentially we assume that the settings apply for the new project case
    // and for the importing case "None" is likely the most sensible
    if (!importing)
        s->setValue("Qt4ProjectManager.TargetSetupPage.BuildTemplate", m_buildConfigurationComboBox->currentIndex());
dt's avatar
dt committed
679
680
681
682
683
684
685
686
687
688
}

QList<BuildConfigurationInfo> Qt4DefaultTargetSetupWidget::buildConfigurationInfos() const
{
    QList<BuildConfigurationInfo> infos;
    for (int i = 0; i < m_importInfos.size(); ++i) {
        if (m_importEnabled.at(i))
            infos << m_importInfos.at(i);
    }

689
690
691
    BuildConfigurationTemplate state = buildConfigurationTemplate();
    if (state == NONE)
        return infos;
dt's avatar
dt committed
692

693
694
695
696
697
    int qtVersionId = -1;
    if (state == ONEQT && m_versionComboBox->currentIndex() != -1)
        qtVersionId = m_versionComboBox->itemData(m_versionComboBox->currentIndex()).toInt();

    QString sourceDir = QFileInfo(m_proFilePath).absolutePath();
dt's avatar
dt committed
698
699
    int size = m_infos.size();
    for (int i=0; i < size; ++i) {
700
        if (state == PERQT || (m_enabled.at(i)  && (state == MANUALLY || (state == ONEQT && m_infos.at(i).version->uniqueId() == qtVersionId)))) {
dt's avatar
dt committed
701
            BuildConfigurationInfo info = m_infos.at(i);
702
            if (!m_shadowBuildEnabled->isChecked())
dt's avatar
dt committed
703
704
705
706
707
708
709
710
711
                info.directory = sourceDir;
            infos << info;
        }
    }
    return infos;
}

void Qt4DefaultTargetSetupWidget::addImportClicked()
{
712
713
714
    if (!m_importLineLabel->isVisible()) {
        m_importLineLabel->setVisible(true);
        m_importLinePath->setVisible(true);
con's avatar
con committed
715
        m_importLineButton->setAttribute(Qt::WA_MacNormalSize);
716
717
        return;
    }
dt's avatar
dt committed
718
719
    BuildConfigurationInfo info = BuildConfigurationInfo::checkForBuild(m_importLinePath->path(), m_proFilePath);
    if (!info.isValid()) {
dt's avatar
dt committed
720
        QMessageBox::critical(this,
dt's avatar
dt committed
721
                              tr("No build found"),
722
                              tr("No build found in %1 matching project %2.").arg(m_importLinePath->path()).arg(m_proFilePath));
dt's avatar
dt committed
723
724
725
726
        return;
    }

    if (!info.version->supportsTargetId(m_id)) {
727
        QMessageBox::critical(this,
dt's avatar
dt committed
728
                              tr("Incompatible build found"),
729
                              tr("The build found in %1 is incompatible with this target").arg(m_importLinePath->path()));
dt's avatar
dt committed
730
731
        return;
    }
732

733
734
735
    // We switch from to "NONE" on importing if the user has not changed it
    if (m_buildConfigurationTemplateUnchanged)
        setBuildConfigurationTemplate(NONE);
736

dt's avatar
dt committed
737
738
739
740
741
742
743
    ++m_selected;
    m_importEnabled << true;

    m_importInfos << info;

    createImportWidget(info, m_importEnabled.size() - 1);
    emit newImportBuildConfiguration(info);
744
    emit selectedToggled();
dt's avatar
dt committed
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
}

QList<BuildConfigurationInfo> Qt4DefaultTargetSetupWidget::usedImportInfos()
{
    QList<BuildConfigurationInfo> infos;
    for (int i = 0; i < m_importInfos.size(); ++i) {
        if (m_importEnabled.at(i))
            infos << m_importInfos.at(i);
    }
    return infos;
}

void Qt4DefaultTargetSetupWidget::setBuildConfigurationInfos(const QList<BuildConfigurationInfo> &infos, bool resetEnabled)
{
    m_infos = infos;
    if (resetEnabled || m_infos.size() != m_enabled.size()) {
        m_enabled.clear();
        m_selected = 0;
        QStringList existingBuilds;
        for (int i = 0; i < m_importInfos.size(); ++i) {
            const BuildConfigurationInfo &info = m_importInfos.at(i);
            existingBuilds << info.directory;
            if (m_importEnabled.at(i))
                ++m_selected;
        }

        // Default to importing existing builds and disable
        // builds that would overwrite imports
        for (int i=0; i < m_infos.size(); ++i) {
            if (existingBuilds.contains(m_infos.at(i).directory) || m_hasInSourceBuild) {
                m_enabled << false;
            } else {
                m_enabled << true;
                ++m_selected;
            }
        }

        clearWidgets();
        setupWidgets();
    } else {
785
        bool foundIssues = false;
dt's avatar
dt committed
786
787
788
789
790
791
792
793
794
795
        m_ignoreChange = true;
        QString sourceDir = QFileInfo(m_proFilePath).absolutePath();
        for (int i=0; i < m_checkboxes.size(); ++i) {
            const BuildConfigurationInfo &info = m_infos.at(i);

            m_checkboxes[i]->setText(displayNameFrom(info));
            if (m_shadowBuildEnabled->isChecked())
                m_pathChoosers[i]->setPath(info.directory);
            else
                m_pathChoosers[i]->setPath(sourceDir);
796
            foundIssues |= reportIssues(i);
dt's avatar
dt committed
797
798
        }
        m_ignoreChange = false;
799
        if (foundIssues && isTargetSelected())
800
            m_detailsWidget->setState(Utils::DetailsWidget::Expanded);
dt's avatar
dt committed
801
    }
802
803
804
805
806

    // update version combobox
    int oldQtVersionId = -1;
    if (m_versionComboBox->currentIndex() != -1)
        oldQtVersionId = m_versionComboBox->itemData(m_versionComboBox->currentIndex()).toInt();
807
    QList<QtSupport::BaseQtVersion *> list;
808
809
810
811
812
813
    foreach (const BuildConfigurationInfo &info, m_infos) {
        if (!list.contains(info.version))
            list << info.version;
    }
    m_ignoreChange = true;
    m_versionComboBox->clear();
814
    foreach (QtSupport::BaseQtVersion *v, list) {
815
816
817
818
819
820
        m_versionComboBox->addItem(v->displayName(), v->uniqueId());
        if (v->uniqueId() == oldQtVersionId)
            m_versionComboBox->setCurrentIndex(m_versionComboBox->count() - 1);
    }
    m_ignoreChange = false;
    updateWidgetVisibility();
dt's avatar
dt committed
821
822
823
824
825
826
827
828
829
830
831
}

void Qt4DefaultTargetSetupWidget::setupImportWidgets()
{
    for (int i = 0; i < m_importInfos.size(); ++i)
        createImportWidget(m_importInfos.at(i), i);
}

void Qt4DefaultTargetSetupWidget::createImportWidget(const BuildConfigurationInfo &info, int pos)
{
    QCheckBox *checkBox = new QCheckBox;
832
    checkBox->setText(tr("Import build from %1").arg(QDir::toNativeSeparators(info.directory)));
dt's avatar
dt committed
833
    checkBox->setChecked(m_importEnabled.at(pos));
834
835
    if (info.version)
        checkBox->setToolTip(info.version->toHtml(false));
dt's avatar
dt committed
836
837
838
839
840
841
842
843
844
845
846
847
    m_importLayout->addWidget(checkBox, pos, 0, 1, 2);

    connect(checkBox, SIGNAL(toggled(bool)),
            this, SLOT(importCheckBoxToggled(bool)));

    m_importCheckBoxes.append(checkBox);
}

void Qt4DefaultTargetSetupWidget::setupWidgets()
{
    m_ignoreChange = true;
    QString sourceDir = QFileInfo(m_proFilePath).absolutePath();
848
    bool foundIssues = false;
dt's avatar
dt committed
849
850
851
852
853
    for (int i = 0; i < m_infos.size(); ++i) {
        const BuildConfigurationInfo &info = m_infos.at(i);
        QCheckBox *checkbox = new QCheckBox;
        checkbox->setText(displayNameFrom(info));
        checkbox->setChecked(m_enabled.at(i));
con's avatar
con committed
854
        checkbox->setAttribute(Qt::WA_LayoutUsesWidgetRect);
855
856
        if (info.version)
            checkbox->setToolTip(info.version->toHtml(false));
dt's avatar
dt committed
857
858
859
860
861
862
863
864
865
866
867
868
869
870
        m_newBuildsLayout->addWidget(checkbox, i * 2, 0);

        Utils::PathChooser *pathChooser = new Utils::PathChooser();
        pathChooser->setExpectedKind(Utils::PathChooser::Directory);
        if (m_shadowBuildEnabled->isChecked())
            pathChooser->setPath(info.directory);
        else
            pathChooser->setPath(sourceDir);
        pathChooser->setReadOnly(!m_directoriesEnabled);
        m_newBuildsLayout->addWidget(pathChooser, i * 2, 1);

        QLabel *reportIssuesLabel = new QLabel;
        reportIssuesLabel->setIndent(32);
        m_newBuildsLayout->addWidget(reportIssuesLabel, i * 2 + 1, 0, 1, 2);
871
        reportIssuesLabel->setVisible(false);
dt's avatar
dt committed
872
873
874
875
876
877
878
879
880
881

        connect(checkbox, SIGNAL(toggled(bool)),
                this, SLOT(checkBoxToggled(bool)));

        connect(pathChooser, SIGNAL(changed(QString)),
                this, SLOT(pathChanged()));

        m_checkboxes.append(checkbox);
        m_pathChoosers.append(pathChooser);
        m_reportIssuesLabels.append(reportIssuesLabel);
882
883
884
        m_issues.append(false);
        bool issue = reportIssues(i);
        foundIssues |= issue;
dt's avatar
dt committed
885
    }
886
    if (foundIssues && isTargetSelected())
887
        m_detailsWidget->setState(Utils::DetailsWidget::Expanded);
dt's avatar
dt committed
888
889
890
891
892
893
894
895
896
897
898
    m_ignoreChange = false;
}

void Qt4DefaultTargetSetupWidget::clearWidgets()
{
    qDeleteAll(m_checkboxes);
    m_checkboxes.clear();
    qDeleteAll(m_pathChoosers);
    m_pathChoosers.clear();
    qDeleteAll(m_reportIssuesLabels);
    m_reportIssuesLabels.clear();
899
    m_issues.clear();
dt's avatar
dt committed
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
}

void Qt4DefaultTargetSetupWidget::checkBoxToggled(bool b)
{
    QCheckBox *box = qobject_cast<QCheckBox *>(sender());
    if (!box)
        return;
    int index = m_checkboxes.indexOf(box);
    if (index == -1)
        return;
    if (m_enabled[index] == b)
        return;
    m_selected += b ? 1 : -1;
    m_enabled[index] = b;
    if ((m_selected == 0 && !b) || (m_selected == 1 && b))
        emit selectedToggled();
}

void Qt4DefaultTargetSetupWidget::importCheckBoxToggled(bool b)
{
    QCheckBox *box = qobject_cast<QCheckBox *>(sender());
    if (!box)
        return;
    int index = m_importCheckBoxes.indexOf(box);
    if (index == -1)
        return;
    if (m_importEnabled[index] == b)
        return;
    m_selected += b ? 1 : -1;
    m_importEnabled[index] = b;
    if ((m_selected == 0 && !b) || (m_selected == 1 && b))
        emit selectedToggled();
}

void Qt4DefaultTargetSetupWidget::pathChanged()
{
    if (m_ignoreChange)
        return;
    Utils::PathChooser *pathChooser = qobject_cast<Utils::PathChooser *>(sender());
    if (!pathChooser)
        return;
    int index = m_pathChoosers.indexOf(pathChooser);
    if (index == -1)
        return;
    m_infos[index].directory = pathChooser->path();
    reportIssues(index);
}

void Qt4DefaultTargetSetupWidget::shadowBuildingToggled()
{
    m_ignoreChange = true;
    bool b = m_shadowBuildEnabled->isChecked();
    if (m_directoriesEnabled == b)
        return;
    m_directoriesEnabled = b;
    QString sourceDir = QFileInfo(m_proFilePath).absolutePath();
    for (int i = 0; i < m_pathChoosers.size(); ++i) {
        Utils::PathChooser *pathChooser = m_pathChoosers.at(i);
        pathChooser->setReadOnly(!b);
        if (b)
            pathChooser->setPath(m_infos.at(i).directory);
        else
            pathChooser->setPath(sourceDir);
        reportIssues(i);
    }
    m_ignoreChange = false;
}

968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
void Qt4DefaultTargetSetupWidget::buildConfigurationComboBoxChanged()
{
    m_buildConfigurationTemplateUnchanged = false;
    updateWidgetVisibility();
}

void Qt4DefaultTargetSetupWidget::updateWidgetVisibility()
{
    m_versionLabel->setVisible(false);
    m_versionComboBox->setVisible(false);
    BuildConfigurationTemplate state = buildConfigurationTemplate();
    if (state == NONE || state == PERQT) {
        foreach (QCheckBox *cb, m_checkboxes)
            cb->setVisible(false);
        foreach (Utils::PathChooser *pc, m_pathChoosers)
            pc->setVisible(false);
        foreach (QLabel *label, m_reportIssuesLabels)
            label->setVisible(false);
    } else if (state == MANUALLY) {
        foreach (QCheckBox *cb, m_checkboxes)
            cb->setVisible(true);
        foreach (Utils::PathChooser *pc, m_pathChoosers)
            pc->setVisible(true);
        for (int i = 0; i < m_reportIssuesLabels.count(); ++i)
            m_reportIssuesLabels.at(i)->setVisible(m_issues.at(i));
    } else if (state == ONEQT) {
        m_versionLabel->setVisible(true);
        m_versionComboBox->setVisible(true);
        qtVersionChanged();
    }
998
    m_shadowBuildEnabled->setVisible(m_shadowBuildCheckBoxVisible && (state != NONE));
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
    emit selectedToggled();
}

void Qt4DefaultTargetSetupWidget::qtVersionChanged()
{
    if (m_ignoreChange)
        return;
    int id = -1;
    if (m_versionComboBox->currentIndex() != -1)
        id = m_versionComboBox->itemData(m_versionComboBox->currentIndex()).toInt();
    if (buildConfigurationTemplate() != ONEQT)
        return;
    for (int i = 0; i < m_infos.size(); ++i) {
        bool visible = m_infos.at(i).version->uniqueId() == id;
        m_checkboxes.at(i)->setVisible(visible);
        m_pathChoosers.at(i)->setVisible(visible);
        m_reportIssuesLabels.at(i)->setVisible(m_issues.at(i));
    }
}

1019
bool Qt4DefaultTargetSetupWidget::reportIssues(int index)
dt's avatar
dt committed
1020
1021
1022
1023
{
    QPair<ProjectExplorer::Task::TaskType, QString> issues = findIssues(m_infos.at(index));
    QLabel *reportIssuesLabel = m_reportIssuesLabels.at(index);
    reportIssuesLabel->setText(issues.second);
1024
1025
1026
1027
    bool error = issues.first != ProjectExplorer::Task::Unknown;
    reportIssuesLabel->setVisible(error);
    m_issues[index] = error;
    return error;
dt's avatar
dt committed
1028
1029
1030
1031
1032
1033
1034
1035
}

QPair<ProjectExplorer::Task::TaskType, QString> Qt4DefaultTargetSetupWidget::findIssues(const BuildConfigurationInfo &info)
{
    if (m_proFilePath.isEmpty())
        return qMakePair(ProjectExplorer::Task::Unknown, QString());

    QString buildDir = info.directory;
dt's avatar
dt committed
1036
1037
    if (!m_shadowBuildEnabled->isChecked())
        buildDir = QFileInfo(m_proFilePath).absolutePath();
1038
    QtSupport::BaseQtVersion *version = info.version;
dt's avatar
dt committed
1039

1040
    QList<ProjectExplorer::Task> issues = version->reportIssues(m_proFilePath, buildDir);
dt's avatar
dt committed
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082

    QString text;
    ProjectExplorer::Task::TaskType highestType = ProjectExplorer::Task::Unknown;
    foreach (const ProjectExplorer::Task &t, issues) {
        if (!text.isEmpty())
            text.append(QLatin1String("<br>"));
        // set severity:
        QString severity;
        if (t.type == ProjectExplorer::Task::Error) {
            highestType = ProjectExplorer::Task::Error;
            severity = tr("<b>Error:</b> ", "Severity is Task::Error");
        } else if (t.type == ProjectExplorer::Task::Warning) {
            if (highestType == ProjectExplorer::Task::Unknown)
                highestType = ProjectExplorer::Task::Warning;
            severity = tr("<b>Warning:</b> ", "Severity is Task::Warning");
        }
        text.append(severity + t.description);
    }
    if (!text.isEmpty())
        text = QLatin1String("<nobr>") + text;
    return qMakePair(highestType, text);
}

// -----------------------
// BuildConfigurationInfo
// -----------------------

QList<BuildConfigurationInfo> BuildConfigurationInfo::filterBuildConfigurationInfos(const QList<BuildConfigurationInfo> &infos, const QString &id)
{
    QList<BuildConfigurationInfo> result;
    foreach (const BuildConfigurationInfo &info, infos)
        if (info.version->supportsTargetId(id))
            result.append(info);
    return result;
}

QList<BuildConfigurationInfo> BuildConfigurationInfo::importBuildConfigurations(const QString &proFilePath)
{
    QList<BuildConfigurationInfo> result;

    // Check for in source build first
    QString sourceDir = QFileInfo(proFilePath).absolutePath();
1083
1084
1085
    BuildConfigurationInfo info = checkForBuild(sourceDir, proFilePath);
    if (info.isValid())
        result.append(info);
dt's avatar
dt committed
1086
1087
1088
1089
1090

    // If we found a in source build, we do not search for out of source builds
    if (!result.isEmpty())
        return result;

1091
    // Check for builds in build directory
dt's avatar
dt committed
1092
1093
1094
1095
    QList<Qt4BaseTargetFactory *> factories =
            ExtensionSystem::PluginManager::instance()->getObjects<Qt4BaseTargetFactory>();
    foreach (Qt4BaseTargetFactory *factory, factories) {
        foreach (const QString &id, factory->supportedTargetIds(0)) {
1096
1097
1098
1099
1100
1101
1102
1103
1104
            QString expectedBuildprefix = factory->shadowBuildDirectory(proFilePath, id, "");
            QString baseDir = QFileInfo(expectedBuildprefix).absolutePath();
            foreach (const QString &dir, QDir(baseDir).entryList()) {
                if (dir.startsWith(expectedBuildprefix)) {
                    BuildConfigurationInfo info = checkForBuild(dir, proFilePath);
                    if (info.isValid())
                        result.append(info);
                }
            }
dt's avatar
dt committed
1105
1106
1107
1108
1109
1110
1111
1112
        }
    }
    return result;
}

BuildConfigurationInfo BuildConfigurationInfo::checkForBuild(const QString &directory, const QString &proFilePath)
{
    QString makefile = directory + "/Makefile";
1113
    QString qmakeBinary = QtSupport::QtVersionManager::findQMakeBinaryFromMakefile(makefile);
dt's avatar
dt committed
1114
1115
    if (qmakeBinary.isEmpty())
        return BuildConfigurationInfo();
1116
    if (QtSupport::QtVersionManager::makefileIsFor(makefile, proFilePath) != QtSupport::QtVersionManager::SameProject)
dt's avatar
dt committed
1117
1118
1119
        return BuildConfigurationInfo();

    bool temporaryQtVersion = false;
1120
    QtSupport::BaseQtVersion *version = QtSupport::QtVersionManager::instance()->qtVersionForQMakeBinary(qmakeBinary);
dt's avatar
dt committed
1121
    if (!version) {
1122
        version = QtSupport::QtVersionFactory::createQtVersionFromQMakePath(qmakeBinary);
dt's avatar
dt committed
1123
        temporaryQtVersion = true;
dt's avatar
dt committed
1124
1125
        if (!version)
            return BuildConfigurationInfo();
dt's avatar
dt committed
1126
1127
    }

1128
1129
    QPair<QtSupport::BaseQtVersion::QmakeBuildConfigs, QString> makefileBuildConfig =
            QtSupport::QtVersionManager::scanMakeFile(makefile, version->defaultBuildConfig());
dt's avatar
dt committed
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142

    QString additionalArguments = makefileBuildConfig.second;
    QString parsedSpec = Qt4BuildConfiguration::extractSpecFromArguments(&additionalArguments, directory, version);
    QString versionSpec = version->mkspec();

    QString specArgument;
    // Compare mkspecs and add to additional arguments
    if (parsedSpec.isEmpty() || parsedSpec == versionSpec || parsedSpec == "default") {
        // using the default spec, don't modify additional arguments
    } else {
        specArgument = "-spec " + Utils::QtcProcess::quoteArg(parsedSpec);
    }
    Utils::QtcProcess::addArgs(&specArgument, additionalArguments);
1143
    Qt4BuildConfiguration::removeQMLInspectorFromArguments(&specArgument);
dt's avatar
dt committed
1144
1145
1146
1147
1148
1149
1150
1151
1152

    BuildConfigurationInfo info = BuildConfigurationInfo(version,
                                                         makefileBuildConfig.first,
                                                         specArgument,
                                                         directory,
                                                         true,
                                                         temporaryQtVersion);
    return info;
}