qt4projectconfigwidget.cpp 14.5 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>
44
#include <extensionsystem/pluginmanager.h>
con's avatar
con committed
45
46
47
48
49
50
51
52
53

#include <QtGui/QFileDialog>

namespace {
bool debug = false;
}

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

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

con's avatar
con committed
72

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

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

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

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

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

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

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

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

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

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

104

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

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

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


dt's avatar
dt committed
120
    QString versionString;
121
    if (m_buildConfiguration->qtVersionId() == 0) {
122
        versionString = tr("Default Qt Version (%1)").arg(version->displayName());
123
    } else if(version){
124
        versionString = version->displayName();
125
126
    } else {
        versionString = tr("No Qt Version set");
dt's avatar
dt committed
127
128
129
    }
}

130
void Qt4ProjectConfigWidget::manageQtVersions()
131
{
132
    Core::ICore *core = Core::ICore::instance();
133
    core->showOptionsDialog(Constants::QT_SETTINGS_CATEGORY, Constants::QTVERSION_SETTINGS_PAGE_ID);
134
135
136
}


137
QString Qt4ProjectConfigWidget::displayName() const
con's avatar
con committed
138
139
140
141
{
    return tr("General");
}

dt's avatar
dt committed
142
void Qt4ProjectConfigWidget::init(ProjectExplorer::BuildConfiguration *bc)
con's avatar
con committed
143
144
{
    if (debug)
dt's avatar
dt committed
145
        qDebug() << "Qt4ProjectConfigWidget::init() for"<<bc->displayName();
con's avatar
con committed
146

147
148
149
150
151
    if (m_buildConfiguration) {
        disconnect(m_buildConfiguration, SIGNAL(buildDirectoryChanged()),
                   this, SLOT(buildDirectoryChanged()));
        disconnect(m_buildConfiguration, SIGNAL(qtVersionChanged()),
                   this, SLOT(qtVersionChanged()));
dt's avatar
dt committed
152
153
        disconnect(m_buildConfiguration, SIGNAL(qmakeBuildConfigurationChanged()),
                   this, SLOT(updateImportLabel()));
154
155
    }

156
    m_buildConfiguration = static_cast<Qt4BuildConfiguration *>(bc);
157
158
159
160
161

    connect(m_buildConfiguration, SIGNAL(buildDirectoryChanged()),
            this, SLOT(buildDirectoryChanged()));
    connect(m_buildConfiguration, SIGNAL(qtVersionChanged()),
            this, SLOT(qtVersionChanged()));
dt's avatar
dt committed
162
163
    connect(m_buildConfiguration, SIGNAL(qmakeBuildConfigurationChanged()),
            this, SLOT(updateImportLabel()));
164

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

167
    qtVersionsChanged();
con's avatar
con committed
168

169
    bool shadowBuild = m_buildConfiguration->shadowBuild();
con's avatar
con committed
170
    m_ui->shadowBuildCheckBox->setChecked(shadowBuild);
171
    m_ui->shadowBuildDirEdit->setEnabled(shadowBuild);
172
    m_browseButton->setEnabled(shadowBuild);
173
    m_ui->shadowBuildDirEdit->setPath(m_buildConfiguration->buildDirectory());
174
    updateImportLabel();
175
    updateToolChainCombo();
dt's avatar
dt committed
176
    updateDetails();
con's avatar
con committed
177
178
}

179
180
181
182
183
184
185
186
void Qt4ProjectConfigWidget::qtVersionChanged()
{
    updateImportLabel();
    updateToolChainCombo();
    updateDetails();
}

void Qt4ProjectConfigWidget::configNameEdited(const QString &newName)
con's avatar
con committed
187
{
188
    m_buildConfiguration->setDisplayName(newName);
con's avatar
con committed
189
190
}

191
void Qt4ProjectConfigWidget::qtVersionsChanged()
con's avatar
con committed
192
{
dt's avatar
dt committed
193
    if (!m_buildConfiguration) // not yet initialized
con's avatar
con committed
194
195
        return;

hjk's avatar
hjk committed
196
    disconnect(m_ui->qtVersionComboBox, SIGNAL(currentIndexChanged(QString)),
197
        this, SLOT(qtVersionSelected(QString)));
con's avatar
con committed
198

199
200
    QtVersionManager *vm = QtVersionManager::instance();

con's avatar
con committed
201
    m_ui->qtVersionComboBox->clear();
202
    m_ui->qtVersionComboBox->addItem(tr("Default Qt Version (%1)").arg(vm->defaultVersion()->displayName()), 0);
con's avatar
con committed
203

204
    int qtVersionId = m_buildConfiguration->qtVersionId();
205

206
    if (qtVersionId == 0) {
con's avatar
con committed
207
208
209
210
211
        m_ui->qtVersionComboBox->setCurrentIndex(0);
        m_ui->invalidQtWarningLabel->setVisible(false);
    }
    // Add Qt Versions to the combo box
    const QList<QtVersion *> &versions = vm->versions();
hjk's avatar
hjk committed
212
    for (int i = 0; i < versions.size(); ++i) {
213
        m_ui->qtVersionComboBox->addItem(versions.at(i)->displayName(), versions.at(i)->uniqueId());
con's avatar
con committed
214

215
        if (versions.at(i)->uniqueId() == qtVersionId) {
hjk's avatar
hjk committed
216
            m_ui->qtVersionComboBox->setCurrentIndex(i + 1);
con's avatar
con committed
217
218
219
220
221
            m_ui->invalidQtWarningLabel->setVisible(!versions.at(i)->isValid());
        }
    }

    // And connect again
hjk's avatar
hjk committed
222
    connect(m_ui->qtVersionComboBox, SIGNAL(currentIndexChanged(QString)),
223
224
225
226
227
        this, SLOT(qtVersionSelected(QString)));
}

void Qt4ProjectConfigWidget::buildDirectoryChanged()
{
228
229
    if (m_ignoreChange)
        return;
230
    m_ui->shadowBuildDirEdit->setPath(m_buildConfiguration->shadowBuildDirectory());
231
232
    updateDetails();
    updateImportLabel();
con's avatar
con committed
233
234
}

235
void Qt4ProjectConfigWidget::onBeforeBeforeShadowBuildDirBrowsed()
con's avatar
con committed
236
{
237
    QString initialDirectory = QFileInfo(m_buildConfiguration->project()->file()->fileName()).absolutePath();
238
239
    if (!initialDirectory.isEmpty())
        m_ui->shadowBuildDirEdit->setInitialBrowsePathBackup(initialDirectory);
con's avatar
con committed
240
241
}

242
void Qt4ProjectConfigWidget::shadowBuildClicked(bool checked)
con's avatar
con committed
243
{
244
    m_ui->shadowBuildDirEdit->setEnabled(checked);
245
    m_browseButton->setEnabled(checked);
con's avatar
con committed
246
    bool b = m_ui->shadowBuildCheckBox->isChecked();
247
248

    m_ignoreChange = true;
249
    m_buildConfiguration->setShadowBuildAndDirectory(b, m_ui->shadowBuildDirEdit->path());
250
251
    m_ignoreChange = false;

dt's avatar
dt committed
252
    updateDetails();
dt's avatar
dt committed
253
    updateImportLabel();
con's avatar
con committed
254
255
}

256
257
void Qt4ProjectConfigWidget::shadowBuildEdited()
{
258
    if (m_buildConfiguration->shadowBuildDirectory() == m_ui->shadowBuildDirEdit->path())
259
260
261
262
263
264
265
266
267
268
269
270
        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();
}

271
void Qt4ProjectConfigWidget::updateImportLabel()
con's avatar
con committed
272
{
273
274
    bool visible = false;

275
    // we only show if we actually have a qmake and makestep
276
277
278
    if (m_buildConfiguration->qmakeStep() && m_buildConfiguration->makeStep()) {
        QString qmakePath = QtVersionManager::findQMakeBinaryFromMakefile(m_buildConfiguration->buildDirectory());
        QtVersion *version = m_buildConfiguration->qtVersion();
279
        // check that there's a makefile
280
281
282
        if (!qmakePath.isEmpty()) {
            // and that the qmake path is different from the current version
            if (qmakePath != (version ? version->qmakeCommand() : QString())) {
283
284
285
286
                // import enable
                visible = true;
            } else {
                // check that the qmake flags, arguments match
287
                visible = !m_buildConfiguration->compareToImportFrom(m_buildConfiguration->buildDirectory());
288
            }
289
        } else {
290
            visible = false;
con's avatar
con committed
291
292
        }
    }
293
294

    m_ui->importLabel->setVisible(visible);
295
296
}

297
void Qt4ProjectConfigWidget::importLabelClicked()
con's avatar
con committed
298
{
299
    if (!m_buildConfiguration->qmakeStep() || !m_buildConfiguration->makeStep())
300
        return;
301
    QString directory = m_buildConfiguration->buildDirectory();
dt's avatar
dt committed
302
    if (!directory.isEmpty()) {
303
304
        QString qmakePath = QtVersionManager::findQMakeBinaryFromMakefile(directory);
        if (!qmakePath.isEmpty()) {
dt's avatar
dt committed
305
            QtVersionManager *vm = QtVersionManager::instance();
306
            QtVersion *version = vm->qtVersionForQMakeBinary(qmakePath);
dt's avatar
dt committed
307
            if (!version) {
308
                version = new QtVersion(qmakePath);
dt's avatar
dt committed
309
                vm->addVersion(version);
con's avatar
con committed
310
            }
dt's avatar
dt committed
311

312
            QPair<QtVersion::QmakeBuildConfigs, QStringList> result =
dt's avatar
dt committed
313
                    QtVersionManager::scanMakeFile(directory, version->defaultBuildConfig());
314
            QtVersion::QmakeBuildConfigs qmakeBuildConfig = result.first;
315
316
            QStringList additionalArguments = Qt4BuildConfiguration::removeSpecFromArgumentList(result.second);
            QString parsedSpec = Qt4BuildConfiguration::extractSpecFromArgumentList(result.second, directory, version);
317
            QString versionSpec = version->mkspec();
dt's avatar
dt committed
318
319
320
321
322
323
            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
324
325

            // So we got all the information now apply it...
326
            m_buildConfiguration->setQtVersion(version->uniqueId());
dt's avatar
dt committed
327
328
            // Combo box will be updated at the end

329
            QMakeStep *qmakeStep = m_buildConfiguration->qmakeStep();
330
            qmakeStep->setUserArguments(additionalArguments);
331
            MakeStep *makeStep = m_buildConfiguration->makeStep();
dt's avatar
dt committed
332

333
            m_buildConfiguration->setQMakeBuildConfiguration(qmakeBuildConfig);
dt's avatar
dt committed
334
335
336
337
            // 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
338
            QStringList makeCmdArguments = makeStep->userArguments();
dt's avatar
dt committed
339
340
341
342
343
344
345
346
347
            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");
            }
348
            makeStep->setUserArguments(makeCmdArguments);
con's avatar
con committed
349
350
        }
    }
351
352
353
    // 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
354
355
}

356
void Qt4ProjectConfigWidget::qtVersionSelected(const QString &)
con's avatar
con committed
357
358
359
360
361
362
363
364
{
    //Qt Version
    int newQtVersion;
    if (m_ui->qtVersionComboBox->currentIndex() == 0) {
        newQtVersion = 0;
    } else {
        newQtVersion = m_ui->qtVersionComboBox->itemData(m_ui->qtVersionComboBox->currentIndex()).toInt();
    }
365
    QtVersionManager *vm = QtVersionManager::instance();
366
    bool isValid = vm->version(newQtVersion)->isValid();
con's avatar
con committed
367
    m_ui->invalidQtWarningLabel->setVisible(!isValid);
368
    if (newQtVersion != m_buildConfiguration->qtVersionId()) {
369
        m_ignoreChange = true;
370
        m_buildConfiguration->setQtVersion(newQtVersion);
371
        m_ignoreChange = false;
372
        updateToolChainCombo();
con's avatar
con committed
373
    }
dt's avatar
dt committed
374
    updateDetails();
con's avatar
con committed
375
}
376
377
378
379

void Qt4ProjectConfigWidget::updateToolChainCombo()
{
    m_ui->toolChainComboBox->clear();
380
    QList<ProjectExplorer::ToolChain::ToolChainType> toolchains = m_buildConfiguration->qtVersion()->possibleToolChainTypes();
381
382
    foreach (ToolChain::ToolChainType toolchain, toolchains) {
        m_ui->toolChainComboBox->addItem(ToolChain::toolChainName(toolchain), qVariantFromValue(toolchain));
383
384
    }
    m_ui->toolChainComboBox->setEnabled(toolchains.size() > 1);
385
386
    m_ui->toolChainComboBox->setCurrentIndex(toolchains.indexOf(m_buildConfiguration->toolChainType()));
    updateDetails();
con's avatar
con committed
387
388
}

389
void Qt4ProjectConfigWidget::toolChainSelected(int index)
con's avatar
con committed
390
391
392
393
{
    ProjectExplorer::ToolChain::ToolChainType selectedToolChainType =
        m_ui->toolChainComboBox->itemData(index,
            Qt::UserRole).value<ProjectExplorer::ToolChain::ToolChainType>();
394
    m_ignoreChange = true;
395
    m_buildConfiguration->setToolChainType(selectedToolChainType);
396
    m_ignoreChange = false;
dt's avatar
dt committed
397
    updateDetails();
398
}