targetsetuppage.cpp 8.7 KB
Newer Older
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).
6
**
hjk's avatar
hjk committed
7
** Contact: Nokia Corporation (info@qt.nokia.com)
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.
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.
30
31
32
33
34
**
**************************************************************************/

#include "targetsetuppage.h"

Tobias Hunger's avatar
Tobias Hunger committed
35
#include "ui_targetsetuppage.h"
36
#include "buildconfigurationinfo.h"
37
#include "qt4project.h"
Tobias Hunger's avatar
Tobias Hunger committed
38
#include "qt4projectmanagerconstants.h"
39
#include "qt4target.h"
40
#include "qt4basetargetfactory.h"
41

42
#include <extensionsystem/pluginmanager.h>
43
#include <projectexplorer/task.h>
dt's avatar
dt committed
44
#include <projectexplorer/taskhub.h>
45
#include <qtsupport/qtversionfactory.h>
46
#include <utils/qtcassert.h>
47
#include <utils/qtcprocess.h>
48

49
50
51
#include <QtGui/QLabel>
#include <QtGui/QLayout>

52
using namespace Qt4ProjectManager;
53
54

TargetSetupPage::TargetSetupPage(QWidget *parent) :
Tobias Hunger's avatar
Tobias Hunger committed
55
    QWizardPage(parent),
dt's avatar
dt committed
56
57
    m_importSearch(false),
    m_spacer(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding)),
58
    m_ui(new Internal::Ui::TargetSetupPage)
59
{
Tobias Hunger's avatar
Tobias Hunger committed
60
    m_ui->setupUi(this);
dt's avatar
dt committed
61
62
63
64
65
    QWidget *centralWidget = new QWidget(this);
    m_ui->scrollArea->setWidget(centralWidget);
    m_layout = new QVBoxLayout;
    centralWidget->setLayout(m_layout);
    m_layout->addSpacerItem(m_spacer);
66

Leena Miettinen's avatar
Leena Miettinen committed
67
    setTitle(tr("Target Setup"));
68
69
}

70
71
void TargetSetupPage::initializePage()
{
dt's avatar
dt committed
72
73
74
75
76
    cleanupImportInfos();
    deleteWidgets();

    setupImportInfos();
    setupWidgets();
77
78
}

79
80
TargetSetupPage::~TargetSetupPage()
{
dt's avatar
dt committed
81
    deleteWidgets();
Tobias Hunger's avatar
Tobias Hunger committed
82
    delete m_ui;
dt's avatar
dt committed
83
    cleanupImportInfos();
84
85
}

dt's avatar
dt committed
86
bool TargetSetupPage::isTargetSelected(const QString &id) const
87
{
dt's avatar
dt committed
88
89
90
    Qt4TargetSetupWidget *widget = m_widgets.value(id);
    return widget && widget->isTargetSelected();
}
91

dt's avatar
dt committed
92
93
94
95
96
97
98
bool TargetSetupPage::isComplete() const
{
    foreach (Qt4TargetSetupWidget *widget, m_widgets)
        if (widget->isTargetSelected())
            return true;
    return false;
}
99

100
void TargetSetupPage::setPreferredFeatures(const QSet<QString> &featureIds)
dt's avatar
dt committed
101
{
102
    m_preferredFeatures = featureIds;
dt's avatar
dt committed
103
}
104

105
106
107
108
109
void TargetSetupPage::setRequiredFeatures(const QSet<QString> &featureIds)
{
    m_requiredFeatures = featureIds;
}

110
void TargetSetupPage::setMinimumQtVersion(const QtSupport::QtVersionNumber &number)
dt's avatar
dt committed
111
112
113
{
    m_minimumQtVersionNumber = number;
}
114

dt's avatar
dt committed
115
116
117
118
void TargetSetupPage::setImportSearch(bool b)
{
    m_importSearch = b;
}
119

dt's avatar
dt committed
120
121
122
void TargetSetupPage::setupWidgets()
{
    QList<Qt4BaseTargetFactory *> factories = ExtensionSystem::PluginManager::instance()->getObjects<Qt4BaseTargetFactory>();
123
    bool atLeastOneTargetSelected = false;
dt's avatar
dt committed
124
125
126
    foreach (Qt4BaseTargetFactory *factory, factories) {
        QStringList ids = factory->supportedTargetIds(0);
        foreach (const QString &id, ids) {
127
128
129
            if (!factory->targetFeatures(id).contains(m_requiredFeatures))
                continue;

dt's avatar
dt committed
130
131
132
133
            QList<BuildConfigurationInfo> infos = BuildConfigurationInfo::filterBuildConfigurationInfos(m_importInfos, id);
            Qt4TargetSetupWidget *widget =
                    factory->createTargetSetupWidget(id, m_proFilePath, m_minimumQtVersionNumber, m_importSearch, infos);
            if (widget) {
134
135
136
137
138
                bool selectTarget = false;
                if (!m_importInfos.isEmpty()) {
                    selectTarget = !infos.isEmpty();
                } else {
                    if (!m_preferredFeatures.isEmpty()) {
139
140
                        selectTarget = factory->targetFeatures(id).contains(m_preferredFeatures)
                                && factory->selectByDefault(id);
141
142
143
                    }
                }
                widget->setTargetSelected(selectTarget);
144
                atLeastOneTargetSelected |= selectTarget;
dt's avatar
dt committed
145
146
147
148
149
150
151
                m_widgets.insert(id, widget);
                m_factories.insert(widget, factory);
                m_layout->addWidget(widget);
                connect(widget, SIGNAL(selectedToggled()),
                        this, SIGNAL(completeChanged()));
                connect(widget, SIGNAL(newImportBuildConfiguration(BuildConfigurationInfo)),
                        this, SLOT(newImportBuildConfiguration(BuildConfigurationInfo)));
152
153
            }
        }
154
155
156
157
158
    }
    if (!atLeastOneTargetSelected) {
        Qt4TargetSetupWidget *widget = m_widgets.value(Constants::DESKTOP_TARGET_ID);
        if (widget)
            widget->setTargetSelected(true);
dt's avatar
dt committed
159
    }
160
161


dt's avatar
dt committed
162
    m_layout->addSpacerItem(m_spacer);
163
164
165
166
167
168
169
170
171
172
    if (m_widgets.isEmpty()) {
        // Oh no one can create any targets
        m_ui->scrollArea->setVisible(false);
        m_ui->descriptionLabel->setVisible(false);
        m_ui->noValidQtVersionsLabel->setVisible(true);
    } else {
        m_ui->scrollArea->setVisible(true);
        m_ui->descriptionLabel->setVisible(true);
        m_ui->noValidQtVersionsLabel->setVisible(false);
    }
dt's avatar
dt committed
173
}
174

dt's avatar
dt committed
175
176
177
178
179
180
181
182
void TargetSetupPage::deleteWidgets()
{
    foreach (Qt4TargetSetupWidget *widget, m_widgets)
        delete widget;
    m_widgets.clear();
    m_factories.clear();
    m_layout->removeItem(m_spacer);
}
183

dt's avatar
dt committed
184
185
186
187
188
189
void TargetSetupPage::setProFilePath(const QString &path)
{
    m_proFilePath = path;
    if (!m_proFilePath.isEmpty()) {
        m_ui->descriptionLabel->setText(tr("Qt Creator can set up the following targets for project <b>%1</b>:",
                                           "%1: Project name").arg(QFileInfo(m_proFilePath).baseName()));
190
191
    }

dt's avatar
dt committed
192
193
    deleteWidgets();
    setupWidgets();
194
195
}

dt's avatar
dt committed
196
void TargetSetupPage::setupImportInfos()
197
{
dt's avatar
dt committed
198
199
    if (m_importSearch)
        m_importInfos = BuildConfigurationInfo::importBuildConfigurations(m_proFilePath);
200
201
}

dt's avatar
dt committed
202
void TargetSetupPage::cleanupImportInfos()
203
{
dt's avatar
dt committed
204
205
206
    foreach (const BuildConfigurationInfo &info, m_importInfos) {
        if (info.temporaryQtVersion)
            delete info.version;
207
208
209
    }
}

dt's avatar
dt committed
210
void TargetSetupPage::newImportBuildConfiguration(const BuildConfigurationInfo &info)
211
{
dt's avatar
dt committed
212
    m_importInfos.append(info);
213
214
215
216
}

bool TargetSetupPage::setupProject(Qt4ProjectManager::Qt4Project *project)
{
dt's avatar
dt committed
217
218
219
220
221
222
223
    QMap<QString, Qt4TargetSetupWidget *>::const_iterator it, end;
    end = m_widgets.constEnd();
    it = m_widgets.constBegin();
    for ( ; it != end; ++it) {
        Qt4BaseTargetFactory *factory = m_factories.value(it.value());

        foreach (const BuildConfigurationInfo &info, it.value()->usedImportInfos()) {
224
            QtSupport::BaseQtVersion *version = info.version;
dt's avatar
dt committed
225
226
227
            for (int i=0; i < m_importInfos.size(); ++i) {
                if (m_importInfos.at(i).version == version) {
                    if (m_importInfos[i].temporaryQtVersion) {
228
                        QtSupport::QtVersionManager::instance()->addVersion(m_importInfos[i].version);
dt's avatar
dt committed
229
230
                        m_importInfos[i].temporaryQtVersion = false;
                    }
231
232
                }
            }
233
234
        }

235
        if (ProjectExplorer::Target *target = factory->create(project, it.key(), it.value()))
dt's avatar
dt committed
236
237
            project->addTarget(target);
    }
238

239
240
    // Create a desktop target if nothing else was set up:
    if (project->targets().isEmpty()) {
241
242
        if (Qt4BaseTargetFactory *tf = Qt4BaseTargetFactory::qt4BaseTargetFactoryForId(Constants::DESKTOP_TARGET_ID))
            if (ProjectExplorer::Target *target = tf->create(project, Constants::DESKTOP_TARGET_ID))
243
                project->addTarget(target);
244
245
    }

246
247
248
249
250
251
252
253
254
255
256
    // Select active target
    // a) Simulator target
    // b) Desktop target
    // c) the first target
    ProjectExplorer::Target *activeTarget = 0;
    QList<ProjectExplorer::Target *> targets = project->targets();
    foreach (ProjectExplorer::Target *t, targets) {
        if (t->id() == Constants::QT_SIMULATOR_TARGET_ID)
            activeTarget = t;
        else if (!activeTarget && t->id() == Constants::DESKTOP_TARGET_ID)
            activeTarget = t;
257
    }
258
259
260
261
    if (!activeTarget && !targets.isEmpty())
        activeTarget = targets.first();
    if (activeTarget)
        project->setActiveTarget(activeTarget);
262

263
264
    return !project->targets().isEmpty();
}