~bzoltan/kubuntu-packaging/decouple_cmake_plugin

« back to all changes in this revision

Viewing changes to src/plugins/qt4projectmanager/qt4projectconfigwidget.cpp

  • Committer: Timo Jyrinki
  • Date: 2013-11-15 12:25:23 UTC
  • mfrom: (1.1.28)
  • Revision ID: timo.jyrinki@canonical.com-20131115122523-i2kyamsu4gs2mu1m
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/****************************************************************************
2
 
**
3
 
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
4
 
** Contact: http://www.qt-project.org/legal
5
 
**
6
 
** This file is part of Qt Creator.
7
 
**
8
 
** Commercial License Usage
9
 
** Licensees holding valid commercial Qt licenses may use this file in
10
 
** accordance with the commercial license agreement provided with the
11
 
** Software or, alternatively, in accordance with the terms contained in
12
 
** a written agreement between you and Digia.  For licensing terms and
13
 
** conditions see http://qt.digia.com/licensing.  For further information
14
 
** use the contact form at http://qt.digia.com/contact-us.
15
 
**
16
 
** GNU Lesser General Public License Usage
17
 
** Alternatively, this file may be used under the terms of the GNU Lesser
18
 
** General Public License version 2.1 as published by the Free Software
19
 
** Foundation and appearing in the file LICENSE.LGPL included in the
20
 
** packaging of this file.  Please review the following information to
21
 
** ensure the GNU Lesser General Public License version 2.1 requirements
22
 
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23
 
**
24
 
** In addition, as a special exception, Digia gives you certain additional
25
 
** rights.  These rights are described in the Digia Qt LGPL Exception
26
 
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27
 
**
28
 
****************************************************************************/
29
 
 
30
 
#include "qt4projectconfigwidget.h"
31
 
 
32
 
#include "qt4project.h"
33
 
#include "qt4buildconfiguration.h"
34
 
#include "qt4nodes.h"
35
 
#include "ui_qt4projectconfigwidget.h"
36
 
 
37
 
#include <projectexplorer/target.h>
38
 
#include <qtsupport/qtkitinformation.h>
39
 
 
40
 
#include <utils/detailswidget.h>
41
 
 
42
 
using namespace Qt4ProjectManager;
43
 
using namespace Qt4ProjectManager::Internal;
44
 
using namespace ProjectExplorer;
45
 
 
46
 
Qt4ProjectConfigWidget::Qt4ProjectConfigWidget(Qt4BuildConfiguration *bc)
47
 
    : NamedWidget(),
48
 
      m_buildConfiguration(bc),
49
 
      m_ignoreChange(false)
50
 
{
51
 
    QVBoxLayout *vbox = new QVBoxLayout(this);
52
 
    vbox->setMargin(0);
53
 
    m_detailsContainer = new Utils::DetailsWidget(this);
54
 
    m_detailsContainer->setState(Utils::DetailsWidget::NoSummary);
55
 
    vbox->addWidget(m_detailsContainer);
56
 
    QWidget *details = new QWidget(m_detailsContainer);
57
 
    m_detailsContainer->setWidget(details);
58
 
    m_ui = new Ui::Qt4ProjectConfigWidget();
59
 
    m_ui->setupUi(details);
60
 
 
61
 
    m_browseButton = m_ui->shadowBuildDirEdit->buttonAtIndex(0);
62
 
 
63
 
    m_ui->shadowBuildDirEdit->setPromptDialogTitle(tr("Shadow Build Directory"));
64
 
    m_ui->shadowBuildDirEdit->setExpectedKind(Utils::PathChooser::ExistingDirectory);
65
 
 
66
 
    connect(m_ui->shadowBuildCheckBox, SIGNAL(clicked(bool)),
67
 
            this, SLOT(shadowBuildClicked(bool)));
68
 
 
69
 
    connect(m_ui->shadowBuildDirEdit, SIGNAL(beforeBrowsing()),
70
 
            this, SLOT(onBeforeBeforeShadowBuildDirBrowsed()));
71
 
 
72
 
    connect(m_ui->shadowBuildDirEdit, SIGNAL(changed(QString)),
73
 
            this, SLOT(shadowBuildEdited()));
74
 
 
75
 
    Qt4Project *project = static_cast<Qt4Project *>(bc->target()->project());
76
 
    connect(project, SIGNAL(environmentChanged()), this, SLOT(environmentChanged()));
77
 
    connect(project, SIGNAL(buildDirectoryInitialized()), this, SLOT(updateProblemLabel()));
78
 
    connect(project, SIGNAL(proFilesEvaluated()), this, SLOT(updateProblemLabel()));
79
 
 
80
 
    connect(bc->target(), SIGNAL(kitChanged()), this, SLOT(updateProblemLabel()));
81
 
 
82
 
    m_ui->shadowBuildDirEdit->setEnvironment(m_buildConfiguration->environment());
83
 
 
84
 
    connect(m_buildConfiguration, SIGNAL(buildDirectoryChanged()),
85
 
            this, SLOT(buildDirectoryChanged()));
86
 
    connect(m_buildConfiguration, SIGNAL(qmakeBuildConfigurationChanged()),
87
 
            this, SLOT(updateProblemLabel()));
88
 
 
89
 
    m_ui->shadowBuildDirEdit->setBaseDirectory(m_buildConfiguration->target()->project()->projectDirectory());
90
 
 
91
 
    buildDirectoryChanged();
92
 
 
93
 
    setDisplayName(tr("General"));
94
 
}
95
 
 
96
 
Qt4ProjectConfigWidget::~Qt4ProjectConfigWidget()
97
 
{
98
 
    delete m_ui;
99
 
}
100
 
 
101
 
void Qt4ProjectConfigWidget::updateDetails()
102
 
{
103
 
    m_detailsContainer->setSummaryText(
104
 
                tr("building in <b>%1</b>")
105
 
                .arg(QDir::toNativeSeparators(m_buildConfiguration->buildDirectory())));
106
 
}
107
 
 
108
 
void Qt4ProjectConfigWidget::setProblemLabel(const QString &text)
109
 
{
110
 
    m_ui->warningLabel->setVisible(!text.isEmpty());
111
 
    m_ui->problemLabel->setVisible(!text.isEmpty());
112
 
    m_ui->problemLabel->setText(text);
113
 
}
114
 
 
115
 
void Qt4ProjectConfigWidget::environmentChanged()
116
 
{
117
 
    m_ui->shadowBuildDirEdit->setEnvironment(m_buildConfiguration->environment());
118
 
}
119
 
 
120
 
void Qt4ProjectConfigWidget::buildDirectoryChanged()
121
 
{
122
 
    if (m_ignoreChange)
123
 
        return;
124
 
    m_ui->shadowBuildDirEdit->setPath(m_buildConfiguration->shadowBuildDirectory());
125
 
    bool shadowBuild = m_buildConfiguration->shadowBuild();
126
 
    m_ui->shadowBuildCheckBox->setChecked(shadowBuild);
127
 
    m_ui->shadowBuildDirEdit->setEnabled(shadowBuild);
128
 
    m_browseButton->setEnabled(shadowBuild);
129
 
 
130
 
    updateDetails();
131
 
    updateProblemLabel();
132
 
}
133
 
 
134
 
void Qt4ProjectConfigWidget::onBeforeBeforeShadowBuildDirBrowsed()
135
 
{
136
 
    QString initialDirectory = m_buildConfiguration->target()->project()->projectDirectory();
137
 
    if (!initialDirectory.isEmpty())
138
 
        m_ui->shadowBuildDirEdit->setInitialBrowsePathBackup(initialDirectory);
139
 
}
140
 
 
141
 
void Qt4ProjectConfigWidget::shadowBuildClicked(bool checked)
142
 
{
143
 
    m_ui->shadowBuildDirEdit->setEnabled(checked);
144
 
    m_browseButton->setEnabled(checked);
145
 
    bool b = m_ui->shadowBuildCheckBox->isChecked();
146
 
 
147
 
    m_ignoreChange = true;
148
 
    m_buildConfiguration->setShadowBuildAndDirectory(b, m_ui->shadowBuildDirEdit->rawPath());
149
 
    m_ignoreChange = false;
150
 
 
151
 
    updateDetails();
152
 
    updateProblemLabel();
153
 
}
154
 
 
155
 
void Qt4ProjectConfigWidget::shadowBuildEdited()
156
 
{
157
 
    if (m_buildConfiguration->shadowBuildDirectory() == m_ui->shadowBuildDirEdit->rawPath())
158
 
        return;
159
 
    m_ignoreChange = true;
160
 
    m_buildConfiguration->setShadowBuildAndDirectory(m_buildConfiguration->shadowBuild(), m_ui->shadowBuildDirEdit->rawPath());
161
 
    m_ignoreChange = false;
162
 
 
163
 
    // if the directory already exists
164
 
    // check if we have a build in there and
165
 
    // offer to import it
166
 
    updateProblemLabel();
167
 
    updateDetails();
168
 
}
169
 
 
170
 
void Qt4ProjectConfigWidget::updateProblemLabel()
171
 
{
172
 
    m_ui->shadowBuildDirEdit->triggerChanged();
173
 
    ProjectExplorer::Kit *k = m_buildConfiguration->target()->kit();
174
 
    const QString proFileName = m_buildConfiguration->target()->project()->document()->fileName();
175
 
 
176
 
    // Check for Qt version:
177
 
    QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(k);
178
 
    if (!version) {
179
 
        setProblemLabel(tr("This kit cannot build this project since it does not define a Qt version."));
180
 
        return;
181
 
    }
182
 
 
183
 
    Qt4Project *p = static_cast<Qt4Project *>(m_buildConfiguration->target()->project());
184
 
    if (p->rootQt4ProjectNode()->parseInProgress() || !p->rootQt4ProjectNode()->validParse()) {
185
 
        setProblemLabel(QString());
186
 
        return;
187
 
    }
188
 
 
189
 
    bool targetMismatch = false;
190
 
    bool incompatibleBuild = false;
191
 
    bool allGood = false;
192
 
    // we only show if we actually have a qmake and makestep
193
 
    if (m_buildConfiguration->qmakeStep() && m_buildConfiguration->makeStep()) {
194
 
        QString makefile = m_buildConfiguration->buildDirectory() + QLatin1Char('/');
195
 
        if (m_buildConfiguration->makefile().isEmpty())
196
 
            makefile.append(QLatin1String("Makefile"));
197
 
        else
198
 
            makefile.append(m_buildConfiguration->makefile());
199
 
 
200
 
        switch (m_buildConfiguration->compareToImportFrom(makefile)) {
201
 
        case Qt4BuildConfiguration::MakefileMatches:
202
 
            allGood = true;
203
 
            break;
204
 
        case Qt4BuildConfiguration::MakefileMissing:
205
 
            allGood = true;
206
 
            break;
207
 
        case Qt4BuildConfiguration::MakefileIncompatible:
208
 
            incompatibleBuild = true;
209
 
            break;
210
 
        case Qt4BuildConfiguration::MakefileForWrongProject:
211
 
            targetMismatch = true;
212
 
            break;
213
 
        }
214
 
    }
215
 
 
216
 
    QString shadowBuildWarning;
217
 
    if (!version->supportsShadowBuilds() && m_buildConfiguration->shadowBuild()) {
218
 
        shadowBuildWarning = tr("The Qt version %1 does not support shadow builds, building might fail.")
219
 
                .arg(version->displayName())
220
 
                + QLatin1String("<br>");
221
 
    }
222
 
 
223
 
    if (allGood) {
224
 
        QString buildDirectory = m_buildConfiguration->target()->project()->projectDirectory();;
225
 
        if (m_buildConfiguration->shadowBuild())
226
 
            buildDirectory = m_buildConfiguration->buildDirectory();
227
 
        QList<ProjectExplorer::Task> issues;
228
 
        issues = version->reportIssues(proFileName, buildDirectory);
229
 
        qSort(issues);
230
 
 
231
 
        if (!issues.isEmpty() || !shadowBuildWarning.isEmpty()) {
232
 
            QString text = QLatin1String("<nobr>") + shadowBuildWarning;
233
 
            foreach (const ProjectExplorer::Task &task, issues) {
234
 
                QString type;
235
 
                switch (task.type) {
236
 
                case ProjectExplorer::Task::Error:
237
 
                    type = tr("Error:");
238
 
                    type += QLatin1Char(' ');
239
 
                    break;
240
 
                case ProjectExplorer::Task::Warning:
241
 
                    type = tr("Warning:");
242
 
                    type += QLatin1Char(' ');
243
 
                    break;
244
 
                case ProjectExplorer::Task::Unknown:
245
 
                default:
246
 
                    break;
247
 
                }
248
 
                if (!text.endsWith(QLatin1String("br>")))
249
 
                    text.append(QLatin1String("<br>"));
250
 
                text.append(type + task.description);
251
 
            }
252
 
            setProblemLabel(text);
253
 
            return;
254
 
        }
255
 
    } else if (targetMismatch) {
256
 
        setProblemLabel(shadowBuildWarning + tr("A build for a different project exists in %1, which will be overwritten.",
257
 
                                                "%1 build directory")
258
 
                        .arg(QDir::toNativeSeparators(m_buildConfiguration->buildDirectory())));
259
 
        return;
260
 
    } else if (incompatibleBuild) {
261
 
        setProblemLabel(shadowBuildWarning +tr("An incompatible build exists in %1, which will be overwritten.",
262
 
                                               "%1 build directory")
263
 
                        .arg(QDir::toNativeSeparators(m_buildConfiguration->buildDirectory())));
264
 
        return;
265
 
    } else if (!shadowBuildWarning.isEmpty()) {
266
 
        setProblemLabel(shadowBuildWarning);
267
 
        return;
268
 
    }
269
 
 
270
 
    setProblemLabel(QString());
271
 
}