qtwizard.cpp 8.48 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2
3
4
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
5
** Copyright (c) 2010 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

con's avatar
con committed
30
#include "qtwizard.h"
Tobias Hunger's avatar
Tobias Hunger committed
31

con's avatar
con committed
32
#include "qt4project.h"
Tobias Hunger's avatar
Tobias Hunger committed
33
#include "qt4projectmanager.h"
con's avatar
con committed
34
#include "qt4projectmanagerconstants.h"
35
#include "qt4target.h"
36
#include "modulespage.h"
37
#include "targetspage.h"
con's avatar
con committed
38

39
#include <coreplugin/icore.h>
40
#include <cpptools/cpptoolsconstants.h>
41
#include <extensionsystem/pluginmanager.h>
con's avatar
con committed
42
43

#include <QtCore/QCoreApplication>
44
#include <QtCore/QVariant>
con's avatar
con committed
45
46
47
48
49

using namespace Qt4ProjectManager;
using namespace Qt4ProjectManager::Internal;

static inline Core::BaseFileWizardParameters
Friedemann Kleint's avatar
Friedemann Kleint committed
50
    wizardParameters(const QString &id,
con's avatar
con committed
51
52
53
                     const QString &category,
                     const QString &categoryTranslationScope,
                     const QString &displayCategory,
Friedemann Kleint's avatar
Friedemann Kleint committed
54
                     const QString &name,
con's avatar
con committed
55
56
57
58
                     const QString &description,
                     const QIcon &icon)
{
    Core::BaseFileWizardParameters rc(Core::IWizard::ProjectWizard);
con's avatar
con committed
59
60
61
    rc.setCategory(category);
    rc.setDisplayCategory(QCoreApplication::translate(categoryTranslationScope.toLatin1(),
                                                      displayCategory.toLatin1()));
con's avatar
con committed
62
    rc.setIcon(icon);
63
    rc.setDisplayName(name);
Friedemann Kleint's avatar
Friedemann Kleint committed
64
    rc.setId(id);
con's avatar
con committed
65
66
67
68
69
    rc.setDescription(description);
    return rc;
}

// -------------------- QtWizard
con's avatar
con committed
70
71
72
73
74
QtWizard::QtWizard(const QString &id,
                   const QString &category,
                   const QString &categoryTranslationScope,
                   const QString &displayCategory,
                   const QString &name,
Friedemann Kleint's avatar
Friedemann Kleint committed
75
                   const QString &description, const QIcon &icon) :
con's avatar
con committed
76
77
78
79
80
81
82
    Core::BaseFileWizard(wizardParameters(id,
                                          category,
                                          categoryTranslationScope,
                                          displayCategory,
                                          name,
                                          description,
                                          icon))
con's avatar
con committed
83
84
85
{
}

86
QString QtWizard::sourceSuffix()
con's avatar
con committed
87
88
89
90
{
    return preferredSuffix(QLatin1String(Constants::CPP_SOURCE_MIMETYPE));
}

91
QString QtWizard::headerSuffix()
con's avatar
con committed
92
93
94
95
{
    return preferredSuffix(QLatin1String(Constants::CPP_HEADER_MIMETYPE));
}

96
QString QtWizard::formSuffix()
con's avatar
con committed
97
98
99
100
{
    return preferredSuffix(QLatin1String(Constants::FORM_MIMETYPE));
}

101
QString QtWizard::profileSuffix()
con's avatar
con committed
102
103
104
105
{
    return preferredSuffix(QLatin1String(Constants::PROFILE_MIMETYPE));
}

106
bool QtWizard::postGenerateFiles(const QWizard *w, const Core::GeneratedFiles &l, QString *errorMessage)
con's avatar
con committed
107
108
{
    const QString proFileName = l.back().path();
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
    const BaseQt4ProjectWizardDialog *dialog = qobject_cast<const BaseQt4ProjectWizardDialog *>(w);

    // Generate user settings:
    QSet<QString> targets;
    if (dialog)
        targets = dialog->selectedTargets();
    if (!targets.isEmpty()) {
        Qt4Manager *manager = ExtensionSystem::PluginManager::instance()->getObject<Qt4Manager>();
        Q_ASSERT(manager);
        QtVersionManager *vm = QtVersionManager::instance();

        Qt4Project *pro = new Qt4Project(manager, proFileName);
        foreach (const QString &targetId, targets) {
            QList<int> versionIds = dialog->selectedQtVersionIdsForTarget(targetId);
            QList<QtVersion *> versions;
            foreach (int id, versionIds)
                versions.append(vm->version(id));
            Qt4Target * target = pro->targetFactory()->create(pro, targetId, versions);
            pro->addTarget(target);
        }
        pro->saveSettings();
130
        delete pro;
131
132
133
    }

    // Post-Generate: Open the project
134
    if (!ProjectExplorer::ProjectExplorerPlugin::instance()->openProject(proFileName)) {
con's avatar
con committed
135
136
137
138
139
140
        *errorMessage = tr("The project %1 could not be opened.").arg(proFileName);
        return false;
    }
    return true;
}

141
QString QtWizard::templateDir()
con's avatar
con committed
142
{
143
    QString rc = Core::ICore::instance()->resourcePath();
con's avatar
con committed
144
145
146
    rc += QLatin1String("/templates/qt4project");
    return rc;
}
147
148
149
150
151
152
153
154
155
156

bool QtWizard::lowerCaseFiles()
{
    QString lowerCaseSettingsKey = QLatin1String(CppTools::Constants::CPPTOOLS_SETTINGSGROUP);
    lowerCaseSettingsKey += QLatin1Char('/');
    lowerCaseSettingsKey += QLatin1String(CppTools::Constants::LOWERCASE_CPPFILES_KEY);
    const bool lowerCaseDefault = CppTools::Constants::lowerCaseFilesDefault;
    return Core::ICore::instance()->settings()->value(lowerCaseSettingsKey, QVariant(lowerCaseDefault)).toBool();
}

157
158
159
160
161
162
163
164
165
166
167
168
169
bool QtWizard::showModulesPageForApplications()
{
    return false;
}

bool QtWizard::showModulesPageForLibraries()
{
    return true;
}

// ----------------- BaseQt4ProjectWizardDialog
BaseQt4ProjectWizardDialog::BaseQt4ProjectWizardDialog(bool showModulesPage, QWidget *parent) :
    ProjectExplorer::BaseProjectWizardDialog(parent),
170
171
    m_modulesPage(0),
    m_targetsPage(0)
172
173
174
175
176
177
178
179
{
    init(showModulesPage);
}

BaseQt4ProjectWizardDialog::BaseQt4ProjectWizardDialog(bool showModulesPage,
                                                       Utils::ProjectIntroPage *introPage,
                                                       int introId, QWidget *parent) :
    ProjectExplorer::BaseProjectWizardDialog(introPage, introId, parent),
180
181
    m_modulesPage(0),
    m_targetsPage(0)
182
183
184
185
186
187
{
    init(showModulesPage);
}

void BaseQt4ProjectWizardDialog::init(bool showModulesPage)
{
188
    QtVersionManager *vm = QtVersionManager::instance();
189
190
    if (showModulesPage)
        m_modulesPage = new ModulesPage;
Tobias Hunger's avatar
Tobias Hunger committed
191
    m_targetsPage = new TargetsPage;
192
}
193

194
int BaseQt4ProjectWizardDialog::addModulesPage(int id)
195
{
196
197
198
199
200
    if (!m_modulesPage)
        return -1;
    if (id >= 0) {
        setPage(id, m_modulesPage);
        return id;
201
    }
202
    return addPage(m_modulesPage);
203
204
}

205
int BaseQt4ProjectWizardDialog::addTargetsPage(QSet<QString> targets, int id)
206
{
207
208
209
    m_targetsPage->setValidTargets(targets);

    if (!m_targetsPage->needToDisplayPage())
210
        return -1;
211

212
    if (id >= 0) {
213
        setPage(id, m_targetsPage);
214
215
216
        return id;
    }
    return addPage(m_targetsPage);
217
218
}

219
220
221
222
QString BaseQt4ProjectWizardDialog::selectedModules() const
{
    return m_modulesPage ? m_modulesPage->selectedModules() : m_selectedModules;
}
223

224
void BaseQt4ProjectWizardDialog::setSelectedModules(const QString &modules, bool lock)
225
{
226
227
228
229
230
231
232
233
234
    if (m_modulesPage) {
        foreach(const QString &module, modules.split(QLatin1Char(' '))) {
            m_modulesPage->setModuleSelected(module, true);
            m_modulesPage->setModuleEnabled(module, !lock);
        }
    } else {
        m_selectedModules = modules;
    }
}
235

236
237
238
239
QString BaseQt4ProjectWizardDialog::deselectedModules() const
{
    return m_modulesPage ? m_modulesPage->deselectedModules() : m_deselectedModules;
}
240

241
242
243
244
245
246
247
248
249
void BaseQt4ProjectWizardDialog::setDeselectedModules(const QString &modules)
{
    if (m_modulesPage) {
        foreach(const QString &module, modules.split(QLatin1Char(' ')))
            m_modulesPage->setModuleSelected(module, false);
    } else {
        m_deselectedModules = modules;
    }
}
250

251
252
253
254
255
256
257
258
259
260
261
262
263
QSet<QString> BaseQt4ProjectWizardDialog::selectedTargets() const
{
    if (!m_targetsPage)
        return QSet<QString>();
    return m_targetsPage->selectedTargets();
}

QList<int> BaseQt4ProjectWizardDialog::selectedQtVersionIdsForTarget(const QString &target) const
{
    if (!m_targetsPage)
        return QList<int>();
    return m_targetsPage->selectedVersionIdsForTarget(target);
}
264
265
266
267
268
269
270

QSet<QString> BaseQt4ProjectWizardDialog::desktopTarget()
{
    QSet<QString> rc;
    rc.insert(QLatin1String(DESKTOP_TARGET_ID));
    return rc;
}