qt4projectconfigwidget.cpp 12.9 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
26
** contact the sales department at http://www.qtsoftware.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 "ui_qt4projectconfigwidget.h"
38

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

#include <QtGui/QFileDialog>

namespace {
bool debug = false;
}

using namespace Qt4ProjectManager;
using namespace Qt4ProjectManager::Internal;

53
Qt4ProjectConfigWidget::Qt4ProjectConfigWidget(Qt4Project *project)
con's avatar
con committed
54
55
56
    : BuildStepConfigWidget(),
      m_pro(project)
{
57
    m_ui = new Ui::Qt4ProjectConfigWidget();
con's avatar
con committed
58
    m_ui->setupUi(this);
59
60
    m_ui->shadowBuildDirEdit->setPromptDialogTitle(tr("Shadow Build Directory"));
    m_ui->shadowBuildDirEdit->setExpectedKind(Core::Utils::PathChooser::Directory);
con's avatar
con committed
61
62
63
64
65
66
67
68
    m_ui->invalidQtWarningLabel->setVisible(false);

    connect(m_ui->nameLineEdit, SIGNAL(textEdited(QString)),
            this, SLOT(changeConfigName(QString)));

    connect(m_ui->shadowBuildCheckBox, SIGNAL(clicked(bool)),
            this, SLOT(shadowBuildCheckBoxClicked(bool)));

69
70
    connect(m_ui->shadowBuildDirEdit, SIGNAL(beforeBrowsing()),
            this, SLOT(onBeforeBeforeShadowBuildDirBrowsed()));
con's avatar
con committed
71

con's avatar
con committed
72
    connect(m_ui->shadowBuildDirEdit, SIGNAL(changed(QString)),
con's avatar
con committed
73
74
75
76
77
            this, SLOT(shadowBuildLineEditTextChanged()));

    connect(m_ui->qtVersionComboBox, SIGNAL(currentIndexChanged(QString)),
            this, SLOT(qtVersionComboBoxCurrentIndexChanged(QString)));

78
79
80
    connect(m_ui->toolChainComboBox, SIGNAL(activated(int)),
            this, SLOT(selectToolChain(int)));

con's avatar
con committed
81
82
83
    connect(m_ui->importLabel, SIGNAL(linkActivated(QString)),
            this, SLOT(importLabelClicked()));

84
85
86
    connect(m_ui->manageQtVersionPushButtons, SIGNAL(clicked()),
            this, SLOT(manageQtVersions()));

87
    QtVersionManager *vm = QtVersionManager::instance();
88
89

    connect(vm, SIGNAL(qtVersionsChanged()),
con's avatar
con committed
90
91
92
            this, SLOT(setupQtVersionsComboBox()));
}

93
Qt4ProjectConfigWidget::~Qt4ProjectConfigWidget()
con's avatar
con committed
94
95
96
97
{
    delete m_ui;
}

98
void Qt4ProjectConfigWidget::manageQtVersions()
99
{
100
    Core::ICore *core = Core::ICore::instance();
101
    core->showOptionsDialog(Constants::QT_CATEGORY, Constants::QTVERSION_PAGE);
102
103
104
}


105
QString Qt4ProjectConfigWidget::displayName() const
con's avatar
con committed
106
107
108
109
{
    return tr("General");
}

110
void Qt4ProjectConfigWidget::init(const QString &buildConfiguration)
con's avatar
con committed
111
112
{
    if (debug)
113
        qDebug() << "Qt4ProjectConfigWidget::init()";
con's avatar
con committed
114
115
116
117
118
119
120
121
122

    m_buildConfiguration = buildConfiguration;

    m_ui->nameLineEdit->setText(m_pro->displayNameFor(m_buildConfiguration));

    setupQtVersionsComboBox();

    bool shadowBuild = m_pro->value(buildConfiguration, "useShadowBuild").toBool();
    m_ui->shadowBuildCheckBox->setChecked(shadowBuild);
123
124
    m_ui->shadowBuildDirEdit->setEnabled(shadowBuild);
    m_ui->shadowBuildDirEdit->setPath(m_pro->buildDirectory(buildConfiguration));
125
    updateImportLabel();
126
    updateToolChainCombo();
con's avatar
con committed
127
128
}

129
void Qt4ProjectConfigWidget::changeConfigName(const QString &newName)
con's avatar
con committed
130
131
132
133
{
    m_pro->setDisplayNameFor(m_buildConfiguration, newName);
}

134
void Qt4ProjectConfigWidget::setupQtVersionsComboBox()
con's avatar
con committed
135
136
137
138
{
    if (m_buildConfiguration.isEmpty()) // not yet initialized
        return;

hjk's avatar
hjk committed
139
140
    disconnect(m_ui->qtVersionComboBox, SIGNAL(currentIndexChanged(QString)),
        this, SLOT(qtVersionComboBoxCurrentIndexChanged(QString)));
con's avatar
con committed
141
142
143
144

    m_ui->qtVersionComboBox->clear();
    m_ui->qtVersionComboBox->addItem(tr("Default Qt Version"), 0);

hjk's avatar
hjk committed
145
    if (m_pro->qtVersionId(m_buildConfiguration) == 0) {
con's avatar
con committed
146
147
148
149
        m_ui->qtVersionComboBox->setCurrentIndex(0);
        m_ui->invalidQtWarningLabel->setVisible(false);
    }
    // Add Qt Versions to the combo box
150
    QtVersionManager *vm = QtVersionManager::instance();
con's avatar
con committed
151
    const QList<QtVersion *> &versions = vm->versions();
hjk's avatar
hjk committed
152
    for (int i = 0; i < versions.size(); ++i) {
con's avatar
con committed
153
154
        m_ui->qtVersionComboBox->addItem(versions.at(i)->name(), versions.at(i)->uniqueId());

hjk's avatar
hjk committed
155
156
        if (versions.at(i)->uniqueId() == m_pro->qtVersionId(m_buildConfiguration)) {
            m_ui->qtVersionComboBox->setCurrentIndex(i + 1);
con's avatar
con committed
157
158
159
160
161
            m_ui->invalidQtWarningLabel->setVisible(!versions.at(i)->isValid());
        }
    }

    // And connect again
hjk's avatar
hjk committed
162
163
    connect(m_ui->qtVersionComboBox, SIGNAL(currentIndexChanged(QString)),
        this, SLOT(qtVersionComboBoxCurrentIndexChanged(QString)));
con's avatar
con committed
164
165
}

166
void Qt4ProjectConfigWidget::onBeforeBeforeShadowBuildDirBrowsed()
con's avatar
con committed
167
{
168
169
170
    QString initialDirectory = QFileInfo(m_pro->file()->fileName()).absolutePath();
    if (!initialDirectory.isEmpty())
        m_ui->shadowBuildDirEdit->setInitialBrowsePathBackup(initialDirectory);
con's avatar
con committed
171
172
}

173
void Qt4ProjectConfigWidget::shadowBuildCheckBoxClicked(bool checked)
con's avatar
con committed
174
{
175
    m_ui->shadowBuildDirEdit->setEnabled(checked);
con's avatar
con committed
176
177
178
    bool b = m_ui->shadowBuildCheckBox->isChecked();
    m_pro->setValue(m_buildConfiguration, "useShadowBuild", b);
    if (b)
179
        m_pro->setValue(m_buildConfiguration, "buildDirectory", m_ui->shadowBuildDirEdit->path());
con's avatar
con committed
180
181
182
183
    else
        m_pro->setValue(m_buildConfiguration, "buildDirectory", QVariant(QString::null));
}

184
void Qt4ProjectConfigWidget::updateImportLabel()
con's avatar
con committed
185
186
187
{
    m_ui->importLabel->setVisible(false);
    if (m_ui->shadowBuildCheckBox->isChecked()) {
188
        QString qtPath = QtVersionManager::findQtVersionFromMakefile(m_ui->shadowBuildDirEdit->path());
hjk's avatar
hjk committed
189
        if (!qtPath.isEmpty()) {
con's avatar
con committed
190
191
192
            m_ui->importLabel->setVisible(true);
        }
    }
193
194
}

195
void Qt4ProjectConfigWidget::shadowBuildLineEditTextChanged()
196
197
{
    if (m_pro->value(m_buildConfiguration, "buildDirectory").toString() == m_ui->shadowBuildDirEdit->path())
198
        return;
199
200
201
202
203
204
205
    m_pro->setValue(m_buildConfiguration, "buildDirectory", m_ui->shadowBuildDirEdit->path());
    // if the directory already exists
    // check if we have a build in there and
    // offer to import it
    updateImportLabel();

    m_pro->invalidateCachedTargetInformation();
con's avatar
con committed
206

207
//    QFileInfo fi(m_ui->shadowBuildDirEdit->path());
con's avatar
con committed
208
209
210
211
212
213
214
215
216
//    if (fi.exists()) {
//        m_ui->shadowBuildLineEdit->setStyleSheet("");
//        m_ui->shadowBuildLineEdit->setToolTip("");
//    } else {
//        m_ui->shadowBuildLineEdit->setStyleSheet("background: red;");
//        m_ui->shadowBuildLineEdit->setToolTip(tr("Directory does not exist."));
//    }
}

217
void Qt4ProjectConfigWidget::importLabelClicked()
con's avatar
con committed
218
219
{
    if (m_ui->shadowBuildCheckBox->isChecked()) {
220
        QString directory = m_ui->shadowBuildDirEdit->path();
con's avatar
con committed
221
        if (!directory.isEmpty()) {
222
            QString qtPath = QtVersionManager::findQtVersionFromMakefile(directory);
con's avatar
con committed
223
            if (!qtPath.isEmpty()) {
224
                QtVersionManager *vm = QtVersionManager::instance();
con's avatar
con committed
225
226
227
228
229
230
                QtVersion *version = vm->qtVersionForDirectory(qtPath);
                if (!version) {
                    version = new QtVersion(QFileInfo(qtPath).baseName(), qtPath);
                    vm->addVersion(version);
                }
                QtVersion::QmakeBuildConfig qmakeBuildConfig = version->defaultBuildConfig();
231
                qmakeBuildConfig = QtVersionManager::scanMakefileForQmakeConfig(directory, qmakeBuildConfig);
con's avatar
con committed
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253

                // So we got all the information now apply it...
                m_pro->setQtVersion(m_buildConfiguration, version->uniqueId());
                // Combo box will be updated at the end

                // Find qmakestep...
                QMakeStep *qmakeStep = m_pro->qmakeStep();
                MakeStep *makeStep = m_pro->makeStep();

                qmakeStep->setValue(m_buildConfiguration, "buildConfiguration", int(qmakeBuildConfig));
                // 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
                QStringList makeCmdArguments = makeStep->value(m_buildConfiguration, "makeargs").toStringList();
                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");
Michael Karcher's avatar
Michael Karcher committed
254
                    makeCmdArguments.removeAll("release");
con's avatar
con committed
255
256
257
258
259
260
261
262
                }
                makeStep->setValue(m_buildConfiguration, "makeargs", makeCmdArguments);
            }
        }
    }
    setupQtVersionsComboBox();
}

263
void Qt4ProjectConfigWidget::qtVersionComboBoxCurrentIndexChanged(const QString &)
con's avatar
con committed
264
265
266
267
268
269
270
271
{
    //Qt Version
    int newQtVersion;
    if (m_ui->qtVersionComboBox->currentIndex() == 0) {
        newQtVersion = 0;
    } else {
        newQtVersion = m_ui->qtVersionComboBox->itemData(m_ui->qtVersionComboBox->currentIndex()).toInt();
    }
272
    QtVersionManager *vm = QtVersionManager::instance();
273
    bool isValid = vm->version(newQtVersion)->isValid();
con's avatar
con committed
274
    m_ui->invalidQtWarningLabel->setVisible(!isValid);
hjk's avatar
hjk committed
275
    if (newQtVersion != m_pro->qtVersionId(m_buildConfiguration)) {
con's avatar
con committed
276
        m_pro->setQtVersion(m_buildConfiguration, newQtVersion);
277
        updateToolChainCombo();
con's avatar
con committed
278
        m_pro->update();
con's avatar
con committed
279
280
    }
}
281
282
283
284
285
286
287
288

void Qt4ProjectConfigWidget::updateToolChainCombo()
{
    m_ui->toolChainComboBox->clear();
    QList<ProjectExplorer::ToolChain::ToolChainType> toolchains = m_pro->qtVersion(m_buildConfiguration)->possibleToolChainTypes();
    foreach (ProjectExplorer::ToolChain::ToolChainType toolchain, toolchains) {
        switch (toolchain) {
        case ProjectExplorer::ToolChain::GCC:
289
            m_ui->toolChainComboBox->addItem(tr("gcc"), qVariantFromValue(ProjectExplorer::ToolChain::GCC));
290
291
            break;
        case ProjectExplorer::ToolChain::LinuxICC:
292
            m_ui->toolChainComboBox->addItem(tr("icc"), qVariantFromValue(ProjectExplorer::ToolChain::LinuxICC));
293
294
            break;
        case ProjectExplorer::ToolChain::MinGW:
295
            m_ui->toolChainComboBox->addItem(tr("mingw"), qVariantFromValue(ProjectExplorer::ToolChain::MinGW));
296
297
            break;
        case ProjectExplorer::ToolChain::MSVC:
298
            m_ui->toolChainComboBox->addItem(tr("msvc"), qVariantFromValue(ProjectExplorer::ToolChain::MSVC));
299
300
            break;
        case ProjectExplorer::ToolChain::WINCE:
301
            m_ui->toolChainComboBox->addItem(tr("wince"), qVariantFromValue(ProjectExplorer::ToolChain::WINCE));
302
303
304
            break;
#ifdef QTCREATOR_WITH_S60
        case ProjectExplorer::ToolChain::WINSCW:
305
            m_ui->toolChainComboBox->addItem(tr("winscw"), qVariantFromValue(ProjectExplorer::ToolChain::WINSCW));
306
307
            break;
        case ProjectExplorer::ToolChain::GCCE:
308
            m_ui->toolChainComboBox->addItem(tr("gcce"), qVariantFromValue(ProjectExplorer::ToolChain::GCCE));
309
310
            break;
#endif
311
312
313
314
        case ProjectExplorer::ToolChain::OTHER:
        case ProjectExplorer::ToolChain::INVALID:
        case ProjectExplorer::ToolChain::UNKNOWN:
            break;
315
316
317
        }
    }
    m_ui->toolChainComboBox->setEnabled(toolchains.size() > 1);
con's avatar
con committed
318
    setToolChain(toolchains.indexOf(m_pro->toolChainType(m_buildConfiguration)));
319
320
321
322
}

void Qt4ProjectConfigWidget::selectToolChain(int index)
{
con's avatar
con committed
323
324
325
326
327
328
329
330
331
    setToolChain(index);
    m_pro->update();
}

void Qt4ProjectConfigWidget::setToolChain(int index)
{
    ProjectExplorer::ToolChain::ToolChainType selectedToolChainType =
        m_ui->toolChainComboBox->itemData(index,
            Qt::UserRole).value<ProjectExplorer::ToolChain::ToolChainType>();
con's avatar
con committed
332
    m_pro->setToolChainType(m_buildConfiguration, selectedToolChainType);
333
334
    if (m_ui->toolChainComboBox->currentIndex() != index)
        m_ui->toolChainComboBox->setCurrentIndex(index);
335
}