qt4projectconfigwidget.cpp 16.3 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2
3
4
**
** This file is part of Qt Creator
**
5
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
con's avatar
con committed
8
**
9
** Commercial Usage
10
**
11
12
13
14
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
15
**
16
** GNU Lesser General Public License Usage
17
**
18
19
20
21
22
23
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24
**
25
** If you are unsure which license is appropriate for your use, please
hjk's avatar
hjk committed
26
** contact the sales department at http://qt.nokia.com/contact.
con's avatar
con committed
27
**
28
**************************************************************************/
hjk's avatar
hjk committed
29

30
#include "qt4projectconfigwidget.h"
hjk's avatar
hjk committed
31
32
33

#include "makestep.h"
#include "qmakestep.h"
con's avatar
con committed
34
#include "qt4project.h"
35
#include "qt4projectmanagerconstants.h"
con's avatar
con committed
36
#include "qt4projectmanager.h"
37
#include "qt4buildconfiguration.h"
38
#include "ui_qt4projectconfigwidget.h"
39

40
#include <coreplugin/icore.h>
41
#include <coreplugin/mainwindow.h>
42
#include <projectexplorer/projectexplorerconstants.h>
43
#include <projectexplorer/buildconfiguration.h>
Tobias Hunger's avatar
Tobias Hunger committed
44
#include <utils/qtcassert.h>
45
#include <extensionsystem/pluginmanager.h>
con's avatar
con committed
46
47
48
49
50
51
52
53
54

#include <QtGui/QFileDialog>

namespace {
bool debug = false;
}

using namespace Qt4ProjectManager;
using namespace Qt4ProjectManager::Internal;
55
using ProjectExplorer::ToolChain;
con's avatar
con committed
56

57
Qt4ProjectConfigWidget::Qt4ProjectConfigWidget(Qt4Project *project)
dt's avatar
dt committed
58
    : BuildConfigWidget(),
59
60
      m_buildConfiguration(0),
      m_ignoreChange(false)
con's avatar
con committed
61
{
62
    Q_UNUSED(project);
dt's avatar
dt committed
63
64
65
    QVBoxLayout *vbox = new QVBoxLayout(this);
    vbox->setMargin(0);
    m_detailsContainer = new Utils::DetailsWidget(this);
66
    m_detailsContainer->setState(Utils::DetailsWidget::NoSummary);
dt's avatar
dt committed
67
68
69
    vbox->addWidget(m_detailsContainer);
    QWidget *details = new QWidget(m_detailsContainer);
    m_detailsContainer->setWidget(details);
70
    m_ui = new Ui::Qt4ProjectConfigWidget();
dt's avatar
dt committed
71
72
    m_ui->setupUi(details);

con's avatar
con committed
73

74
    m_browseButton = m_ui->shadowBuildDirEdit->buttonAtIndex(0);
dt's avatar
dt committed
75
    // TODO refix the layout
con's avatar
con committed
76

77
    m_ui->shadowBuildDirEdit->setPromptDialogTitle(tr("Shadow Build Directory"));
78
    m_ui->shadowBuildDirEdit->setExpectedKind(Utils::PathChooser::Directory);
con's avatar
con committed
79
80
81
    m_ui->invalidQtWarningLabel->setVisible(false);

    connect(m_ui->nameLineEdit, SIGNAL(textEdited(QString)),
82
            this, SLOT(configNameEdited(QString)));
con's avatar
con committed
83
84

    connect(m_ui->shadowBuildCheckBox, SIGNAL(clicked(bool)),
85
            this, SLOT(shadowBuildClicked(bool)));
con's avatar
con committed
86

87
88
    connect(m_ui->shadowBuildDirEdit, SIGNAL(beforeBrowsing()),
            this, SLOT(onBeforeBeforeShadowBuildDirBrowsed()));
con's avatar
con committed
89

con's avatar
con committed
90
    connect(m_ui->shadowBuildDirEdit, SIGNAL(changed(QString)),
91
            this, SLOT(shadowBuildEdited()));
con's avatar
con committed
92
93

    connect(m_ui->qtVersionComboBox, SIGNAL(currentIndexChanged(QString)),
94
            this, SLOT(qtVersionSelected(QString)));
con's avatar
con committed
95

96
    connect(m_ui->toolChainComboBox, SIGNAL(activated(int)),
97
            this, SLOT(toolChainSelected(int)));
98

con's avatar
con committed
99
100
101
    connect(m_ui->importLabel, SIGNAL(linkActivated(QString)),
            this, SLOT(importLabelClicked()));

102
103
104
    connect(m_ui->manageQtVersionPushButtons, SIGNAL(clicked()),
            this, SLOT(manageQtVersions()));

105

106
107
108
    QtVersionManager *vm = QtVersionManager::instance();
    connect(vm, SIGNAL(qtVersionsChanged(QList<int>)),
            this, SLOT(qtVersionsChanged()));
con's avatar
con committed
109
110
}

111
Qt4ProjectConfigWidget::~Qt4ProjectConfigWidget()
con's avatar
con committed
112
113
114
115
{
    delete m_ui;
}

dt's avatar
dt committed
116
117
void Qt4ProjectConfigWidget::updateDetails()
{
118
    QtVersion *version = m_buildConfiguration->qtVersion();
119

dt's avatar
dt committed
120
    QString versionString;
Tobias Hunger's avatar
Tobias Hunger committed
121
122
123
124
125
126
127
128
129
    versionString = version->displayName();

    if (!version || !version->isValid()) {
        // Not a valid qt version
        m_detailsContainer->setSummaryText(
                tr("using <font color=\"#ff0000\">invalid</font> Qt Version: <b>%1</b><br>"
                   "%2")
                .arg(versionString,
                     version ? version->invalidReason() : tr("No Qt Version found.")));
130
    } else {
Tobias Hunger's avatar
Tobias Hunger committed
131
132
133
134
135
136
137
138
        // Qt Version, Build Directory and Toolchain
        m_detailsContainer->setSummaryText(
                tr("using Qt version: <b>%1</b><br>"
                   "with tool chain <b>%2</b><br>"
                   "building in <b>%3</b>")
                .arg(versionString,
                     ProjectExplorer::ToolChain::toolChainName(m_buildConfiguration->toolChainType()),
                     QDir::toNativeSeparators(m_buildConfiguration->buildDirectory())));
dt's avatar
dt committed
139
140
141
    }
}

142
void Qt4ProjectConfigWidget::manageQtVersions()
143
{
144
    Core::ICore *core = Core::ICore::instance();
145
    core->showOptionsDialog(Constants::QT_SETTINGS_CATEGORY, Constants::QTVERSION_SETTINGS_PAGE_ID);
146
147
148
}


149
QString Qt4ProjectConfigWidget::displayName() const
con's avatar
con committed
150
151
152
153
{
    return tr("General");
}

dt's avatar
dt committed
154
void Qt4ProjectConfigWidget::init(ProjectExplorer::BuildConfiguration *bc)
con's avatar
con committed
155
{
Tobias Hunger's avatar
Tobias Hunger committed
156
157
    QTC_ASSERT(bc, return);

con's avatar
con committed
158
    if (debug)
dt's avatar
dt committed
159
        qDebug() << "Qt4ProjectConfigWidget::init() for"<<bc->displayName();
con's avatar
con committed
160

161
162
163
164
165
    if (m_buildConfiguration) {
        disconnect(m_buildConfiguration, SIGNAL(buildDirectoryChanged()),
                   this, SLOT(buildDirectoryChanged()));
        disconnect(m_buildConfiguration, SIGNAL(qtVersionChanged()),
                   this, SLOT(qtVersionChanged()));
dt's avatar
dt committed
166
167
        disconnect(m_buildConfiguration, SIGNAL(qmakeBuildConfigurationChanged()),
                   this, SLOT(updateImportLabel()));
168
    }
169
    m_buildConfiguration = static_cast<Qt4BuildConfiguration *>(bc);
170
171
172
173
174

    connect(m_buildConfiguration, SIGNAL(buildDirectoryChanged()),
            this, SLOT(buildDirectoryChanged()));
    connect(m_buildConfiguration, SIGNAL(qtVersionChanged()),
            this, SLOT(qtVersionChanged()));
dt's avatar
dt committed
175
176
    connect(m_buildConfiguration, SIGNAL(qmakeBuildConfigurationChanged()),
            this, SLOT(updateImportLabel()));
177

dt's avatar
dt committed
178
    m_ui->nameLineEdit->setText(m_buildConfiguration->displayName());
con's avatar
con committed
179

180
    qtVersionsChanged();
con's avatar
con committed
181

182
    bool shadowBuild = m_buildConfiguration->shadowBuild();
con's avatar
con committed
183
    m_ui->shadowBuildCheckBox->setChecked(shadowBuild);
184
    m_ui->shadowBuildDirEdit->setEnabled(shadowBuild);
185
    m_browseButton->setEnabled(shadowBuild);
186
    m_ui->shadowBuildDirEdit->setPath(m_buildConfiguration->buildDirectory());
187
    updateImportLabel();
188
    updateToolChainCombo();
dt's avatar
dt committed
189
    updateDetails();
con's avatar
con committed
190
191
}

192
193
194
195
196
197
198
199
void Qt4ProjectConfigWidget::qtVersionChanged()
{
    updateImportLabel();
    updateToolChainCombo();
    updateDetails();
}

void Qt4ProjectConfigWidget::configNameEdited(const QString &newName)
con's avatar
con committed
200
{
201
    m_buildConfiguration->setDisplayName(newName);
con's avatar
con committed
202
203
}

204
void Qt4ProjectConfigWidget::qtVersionsChanged()
con's avatar
con committed
205
{
dt's avatar
dt committed
206
    if (!m_buildConfiguration) // not yet initialized
con's avatar
con committed
207
208
        return;

hjk's avatar
hjk committed
209
    disconnect(m_ui->qtVersionComboBox, SIGNAL(currentIndexChanged(QString)),
210
        this, SLOT(qtVersionSelected(QString)));
con's avatar
con committed
211

212
213
    QtVersionManager *vm = QtVersionManager::instance();

con's avatar
con committed
214
    m_ui->qtVersionComboBox->clear();
Tobias Hunger's avatar
Tobias Hunger committed
215
    QtVersion * qtVersion = m_buildConfiguration->qtVersion();
con's avatar
con committed
216

Tobias Hunger's avatar
Tobias Hunger committed
217
218
219
220
    const QList<QtVersion *> validVersions(vm->versionsForTargetId(m_buildConfiguration->target()->id()));
    if (validVersions.isEmpty()) {
        m_ui->invalidQtWarningLabel->setVisible(true);
    } else {
con's avatar
con committed
221
        m_ui->invalidQtWarningLabel->setVisible(false);
Tobias Hunger's avatar
Tobias Hunger committed
222
223
224
225
226
227
228
229
        for (int i = 0; i < validVersions.size(); ++i) {
            m_ui->qtVersionComboBox->addItem(validVersions.at(i)->displayName(),
                                             validVersions.at(i)->uniqueId());

            if (validVersions.at(i) == qtVersion) {
                m_ui->qtVersionComboBox->setCurrentIndex(i);
                m_ui->invalidQtWarningLabel->setVisible(!validVersions.at(i)->isValid());
            }
con's avatar
con committed
230
        }
Tobias Hunger's avatar
Tobias Hunger committed
231
        m_ui->qtVersionComboBox->setEnabled(validVersions.count() > 1);
con's avatar
con committed
232
233
234
    }

    // And connect again
hjk's avatar
hjk committed
235
    connect(m_ui->qtVersionComboBox, SIGNAL(currentIndexChanged(QString)),
236
237
238
239
240
        this, SLOT(qtVersionSelected(QString)));
}

void Qt4ProjectConfigWidget::buildDirectoryChanged()
{
241
242
    if (m_ignoreChange)
        return;
243
    m_ui->shadowBuildDirEdit->setPath(m_buildConfiguration->shadowBuildDirectory());
244
245
    updateDetails();
    updateImportLabel();
con's avatar
con committed
246
247
}

248
void Qt4ProjectConfigWidget::onBeforeBeforeShadowBuildDirBrowsed()
con's avatar
con committed
249
{
Tobias Hunger's avatar
Tobias Hunger committed
250
    QString initialDirectory = QFileInfo(m_buildConfiguration->target()->project()->file()->fileName()).absolutePath();
251
252
    if (!initialDirectory.isEmpty())
        m_ui->shadowBuildDirEdit->setInitialBrowsePathBackup(initialDirectory);
con's avatar
con committed
253
254
}

255
void Qt4ProjectConfigWidget::shadowBuildClicked(bool checked)
con's avatar
con committed
256
{
257
    m_ui->shadowBuildDirEdit->setEnabled(checked);
258
    m_browseButton->setEnabled(checked);
con's avatar
con committed
259
    bool b = m_ui->shadowBuildCheckBox->isChecked();
260
261

    m_ignoreChange = true;
262
    m_buildConfiguration->setShadowBuildAndDirectory(b, m_ui->shadowBuildDirEdit->path());
263
264
    m_ignoreChange = false;

dt's avatar
dt committed
265
    updateDetails();
dt's avatar
dt committed
266
    updateImportLabel();
con's avatar
con committed
267
268
}

269
270
void Qt4ProjectConfigWidget::shadowBuildEdited()
{
271
    if (m_buildConfiguration->shadowBuildDirectory() == m_ui->shadowBuildDirEdit->path())
272
273
274
275
276
277
278
279
280
281
282
283
        return;
    m_ignoreChange = true;
    m_buildConfiguration->setShadowBuildAndDirectory(true, m_ui->shadowBuildDirEdit->path());
    m_ignoreChange = false;

    // if the directory already exists
    // check if we have a build in there and
    // offer to import it
    updateImportLabel();
    updateDetails();
}

284
void Qt4ProjectConfigWidget::updateImportLabel()
con's avatar
con committed
285
{
286
    bool visible = false;
287
    bool targetMatches = false;
288

289
    QtVersionManager *vm = QtVersionManager::instance();
290
    // we only show if we actually have a qmake and makestep
291
292
293
    if (m_buildConfiguration->qmakeStep() && m_buildConfiguration->makeStep()) {
        QString qmakePath = QtVersionManager::findQMakeBinaryFromMakefile(m_buildConfiguration->buildDirectory());
        QtVersion *version = m_buildConfiguration->qtVersion();
294
        // check that there's a makefile
295
296
297
        if (!qmakePath.isEmpty()) {
            // and that the qmake path is different from the current version
            if (qmakePath != (version ? version->qmakeCommand() : QString())) {
298
299
                // import enable
                visible = true;
300
301
302
303
304
305
306
307
308
                QtVersion *newVersion = vm->qtVersionForQMakeBinary(qmakePath);
                bool mustDelete(false);
                if (!newVersion) {
                    newVersion = new QtVersion(qmakePath);
                    mustDelete = true;
                }
                targetMatches = newVersion->supportsTargetId(m_buildConfiguration->target()->id());
                if (mustDelete)
                    delete newVersion;
309
310
            } else {
                // check that the qmake flags, arguments match
311
                visible = !m_buildConfiguration->compareToImportFrom(m_buildConfiguration->buildDirectory());
312
            }
313
        } else {
314
            visible = false;
con's avatar
con committed
315
316
        }
    }
317

318
319
320
321
322
323
324
    if (targetMatches) {
        m_ui->importProblemLabel->setVisible(false);
        m_ui->importWarningLabel->setVisible(false);
        m_ui->importLabel->setVisible(visible);
    } else {
        m_ui->importWarningLabel->setVisible(visible);
        m_ui->importProblemLabel->setVisible(visible);
Tobias Hunger's avatar
Tobias Hunger committed
325
        m_ui->importProblemLabel->setText(tr("An incompatible build exists in %1 and will be overwritten!",
Tobias Hunger's avatar
Tobias Hunger committed
326
327
                                             "%1 build directory").
                                          arg(m_ui->shadowBuildDirEdit->path()));
328
329
        m_ui->importLabel->setVisible(false);
    }
330
331
}

332
void Qt4ProjectConfigWidget::importLabelClicked()
con's avatar
con committed
333
{
334
    if (!m_buildConfiguration->qmakeStep() || !m_buildConfiguration->makeStep())
335
        return;
336
    QString directory = m_buildConfiguration->buildDirectory();
dt's avatar
dt committed
337
    if (!directory.isEmpty()) {
338
339
        QString qmakePath = QtVersionManager::findQMakeBinaryFromMakefile(directory);
        if (!qmakePath.isEmpty()) {
dt's avatar
dt committed
340
            QtVersionManager *vm = QtVersionManager::instance();
341
            QtVersion *version = vm->qtVersionForQMakeBinary(qmakePath);
dt's avatar
dt committed
342
            if (!version) {
343
                version = new QtVersion(qmakePath);
dt's avatar
dt committed
344
                vm->addVersion(version);
con's avatar
con committed
345
            }
dt's avatar
dt committed
346

347
            QPair<QtVersion::QmakeBuildConfigs, QStringList> result =
dt's avatar
dt committed
348
                    QtVersionManager::scanMakeFile(directory, version->defaultBuildConfig());
349
            QtVersion::QmakeBuildConfigs qmakeBuildConfig = result.first;
350
351
            QStringList additionalArguments = Qt4BuildConfiguration::removeSpecFromArgumentList(result.second);
            QString parsedSpec = Qt4BuildConfiguration::extractSpecFromArgumentList(result.second, directory, version);
352
            QString versionSpec = version->mkspec();
dt's avatar
dt committed
353
354
355
356
357
358
            if (parsedSpec.isEmpty() || parsedSpec == versionSpec || parsedSpec == "default") {
                // using the default spec, don't modify additional arguments
            } else {
                additionalArguments.prepend(parsedSpec);
                additionalArguments.prepend("-spec");
            }
dt's avatar
dt committed
359
360

            // So we got all the information now apply it...
Tobias Hunger's avatar
Tobias Hunger committed
361
            m_buildConfiguration->setQtVersion(version);
dt's avatar
dt committed
362
363
            // Combo box will be updated at the end

364
            QMakeStep *qmakeStep = m_buildConfiguration->qmakeStep();
365
            qmakeStep->setUserArguments(additionalArguments);
366
            MakeStep *makeStep = m_buildConfiguration->makeStep();
dt's avatar
dt committed
367

368
            m_buildConfiguration->setQMakeBuildConfiguration(qmakeBuildConfig);
dt's avatar
dt committed
369
370
371
372
            // Adjust command line arguments, this is ugly as hell
            // If we are switching to BuildAll we want "release" in there and no "debug"
            // or "debug" in there and no "release"
            // If we are switching to not BuildAl we want neither "release" nor "debug" in there
373
            QStringList makeCmdArguments = makeStep->userArguments();
dt's avatar
dt committed
374
375
376
377
378
379
380
381
382
            bool debug = qmakeBuildConfig & QtVersion::DebugBuild;
            if (qmakeBuildConfig & QtVersion::BuildAll) {
                makeCmdArguments.removeAll(debug ? "release" : "debug");
                if (!makeCmdArguments.contains(debug ? "debug" : "release"))
                    makeCmdArguments.append(debug ? "debug" : "release");
            } else {
                makeCmdArguments.removeAll("debug");
                makeCmdArguments.removeAll("release");
            }
383
            makeStep->setUserArguments(makeCmdArguments);
con's avatar
con committed
384
385
        }
    }
386
387
388
    // All our widgets are updated by signals from the buildconfiguration
    // if not, there's either a signal missing
    // or we don't respond to it correctly
con's avatar
con committed
389
390
}

391
void Qt4ProjectConfigWidget::qtVersionSelected(const QString &)
con's avatar
con committed
392
393
{
    //Qt Version
Tobias Hunger's avatar
Tobias Hunger committed
394
    int newQtVersionId = m_ui->qtVersionComboBox->itemData(m_ui->qtVersionComboBox->currentIndex()).toInt();
395
    QtVersionManager *vm = QtVersionManager::instance();
Tobias Hunger's avatar
Tobias Hunger committed
396
397
    QtVersion *newQtVersion = vm->version(newQtVersionId);
    bool isValid = newQtVersion->isValid();
con's avatar
con committed
398
    m_ui->invalidQtWarningLabel->setVisible(!isValid);
Tobias Hunger's avatar
Tobias Hunger committed
399
    if (newQtVersion != m_buildConfiguration->qtVersion()) {
400
        m_ignoreChange = true;
401
        m_buildConfiguration->setQtVersion(newQtVersion);
402
        m_ignoreChange = false;
403
        updateToolChainCombo();
con's avatar
con committed
404
    }
dt's avatar
dt committed
405
    updateDetails();
con's avatar
con committed
406
}
407
408
409
410

void Qt4ProjectConfigWidget::updateToolChainCombo()
{
    m_ui->toolChainComboBox->clear();
Tobias Hunger's avatar
Tobias Hunger committed
411
412
413
    QList<ProjectExplorer::ToolChain::ToolChainType> toolchains(m_buildConfiguration->qtVersion()->possibleToolChainTypes());
    toolchains = m_buildConfiguration->qt4Target()->filterToolChainTypes(toolchains);
    foreach (ToolChain::ToolChainType toolchain, toolchains)
414
        m_ui->toolChainComboBox->addItem(ToolChain::toolChainName(toolchain), qVariantFromValue(toolchain));
415
    m_ui->toolChainComboBox->setEnabled(toolchains.size() > 1);
Tobias Hunger's avatar
Tobias Hunger committed
416
    m_ui->toolChainComboBox->setCurrentIndex(toolchains.indexOf(m_buildConfiguration->qt4Target()->preferredToolChainType(toolchains)));
417
    updateDetails();
con's avatar
con committed
418
419
}

420
void Qt4ProjectConfigWidget::toolChainSelected(int index)
con's avatar
con committed
421
422
423
424
{
    ProjectExplorer::ToolChain::ToolChainType selectedToolChainType =
        m_ui->toolChainComboBox->itemData(index,
            Qt::UserRole).value<ProjectExplorer::ToolChain::ToolChainType>();
425
    m_ignoreChange = true;
426
    m_buildConfiguration->setToolChainType(selectedToolChainType);
427
    m_ignoreChange = false;
dt's avatar
dt committed
428
    updateDetails();
429
}