1
/****************************************************************************
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of Qt Creator.
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.
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.
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.
28
****************************************************************************/
30
#include "librarywizarddialog.h"
31
#include "filespage.h"
32
#include "libraryparameters.h"
33
#include "modulespage.h"
34
#include "mobilelibrarywizardoptionpage.h"
35
#include "mobilelibraryparameters.h"
37
#include <utils/projectintropage.h>
38
#include <projectexplorer/projectexplorerconstants.h>
45
enum { debugLibWizard = 0 };
47
namespace QmakeProjectManager {
50
struct PluginBaseClasses {
53
// blank separated list or 0
54
const char *dependentModules;
55
const char *targetDirectory;
56
const char *pluginInterface;
59
static const PluginBaseClasses pluginBaseClasses[] =
61
{ "QAccessiblePlugin", "QtGui", "QtCore", "accessible", "QAccessibleFactoryInterface" },
62
{ "QDecorationPlugin", "QtGui", "QtCore", 0, 0 }, // Qt 4 only.
63
{ "QGenericPlugin", "QtGui", "QtCore", "generic", "QGenericPluginFactoryInterface" },
64
{ "QIconEnginePluginV2", "QtGui", "QtCore", "imageformats", 0 }, // Qt 4 only.
65
{ "QIconEnginePlugin", "QtGui", "QtCore", "imageformats", "QIconEngineFactoryInterface" },
66
{ "QImageIOPlugin", "QtGui", "QtCore", "imageformats", "QImageIOHandlerFactoryInterface" },
67
{ "QScriptExtensionPlugin", "QtScript", "QtCore", 0, "QScriptExtensionInterface" },
68
{ "QSqlDriverPlugin", "QtSql", "QtCore", "sqldrivers", "QSqlDriverFactoryInterface" },
69
{ "QStylePlugin", "QtGui", "QtCore", "styles", "QStyleFactoryInterface" },
70
{ "QTextCodecPlugin", "QtCore", 0, "codecs", 0 } // Qt 4 only.
73
enum { defaultPluginBaseClass = 2 };
75
static const PluginBaseClasses *findPluginBaseClass(const QString &name)
77
const int pluginBaseClassCount = sizeof(pluginBaseClasses)/sizeof(PluginBaseClasses);
78
for (int i = 0; i < pluginBaseClassCount; i++)
79
if (name == QLatin1String(pluginBaseClasses[i].name))
80
return pluginBaseClasses + i;
84
// return dependencies of a plugin as a line ready for the 'QT=' line in a pro
86
static QStringList pluginDependencies(const PluginBaseClasses *plb)
88
QStringList dependencies;
89
const QChar blank = QLatin1Char(' ');
90
// Find the module names and convert to ids
91
QStringList pluginModules= plb->dependentModules ?
92
QString(QLatin1String(plb->dependentModules)).split(blank) :
94
pluginModules.push_back(QLatin1String(plb->module));
95
foreach (const QString &module, pluginModules) {
96
dependencies.append(ModulesPage::idOfModule(module));
101
// A Project intro page with an additional type chooser.
102
class LibraryIntroPage : public Utils::ProjectIntroPage
105
explicit LibraryIntroPage(QWidget *parent = 0);
107
QtProjectParameters::Type type() const;
110
QComboBox *m_typeCombo;
113
LibraryIntroPage::LibraryIntroPage(QWidget *parent) :
114
Utils::ProjectIntroPage(parent),
115
m_typeCombo(new QComboBox)
117
m_typeCombo->setEditable(false);
118
m_typeCombo->addItem(LibraryWizardDialog::tr("Shared Library"),
119
QVariant(QtProjectParameters::SharedLibrary));
120
m_typeCombo->addItem(LibraryWizardDialog::tr("Statically Linked Library"),
121
QVariant(QtProjectParameters::StaticLibrary));
122
m_typeCombo->addItem(LibraryWizardDialog::tr("Qt Plugin"),
123
QVariant(QtProjectParameters::Qt4Plugin));
124
insertControl(0, new QLabel(LibraryWizardDialog::tr("Type")), m_typeCombo);
127
QtProjectParameters::Type LibraryIntroPage::type() const
129
return static_cast<QtProjectParameters::Type>(m_typeCombo->itemData(m_typeCombo->currentIndex()).toInt());
132
// ------------------- LibraryWizardDialog
133
LibraryWizardDialog::LibraryWizardDialog(const QString &templateName,
135
bool showModulesPage,
137
const Core::WizardDialogParameters ¶meters) :
138
BaseQt4ProjectWizardDialog(showModulesPage, new LibraryIntroPage, -1, parent, parameters),
139
m_filesPage(new FilesPage),
140
m_mobilePage(new MobileLibraryWizardOptionPage),
141
m_pluginBaseClassesInitialized(false),
142
m_filesPageId(-1), m_modulesPageId(-1), m_targetPageId(-1),
146
setWindowTitle(templateName);
147
setSelectedModules(QLatin1String("core"));
149
// Note that QWizard::currentIdChanged() is emitted at strange times.
150
// Use the intro page instead, set up initially
151
setIntroDescription(tr("This wizard generates a C++ library project."));
153
if (!parameters.extraValues().contains(QLatin1String(ProjectExplorer::Constants::PROJECT_KIT_IDS))) {
154
m_targetPageId = addTargetSetupPage();
155
m_mobilePageId = addPage(m_mobilePage);
158
m_modulesPageId = addModulesPage();
160
m_filesPage->setNamespacesEnabled(true);
161
m_filesPage->setFormFileInputVisible(false);
162
m_filesPage->setClassTypeComboVisible(false);
164
m_filesPageId = addPage(m_filesPage);
166
Utils::WizardProgressItem *introItem = wizardProgress()->item(startId());
167
Utils::WizardProgressItem *targetItem = 0;
168
Utils::WizardProgressItem *mobileItem = 0;
169
if (m_targetPageId != -1)
170
targetItem = wizardProgress()->item(m_targetPageId);
171
if (m_mobilePageId != -1)
172
mobileItem = wizardProgress()->item(m_mobilePageId);
173
Utils::WizardProgressItem *modulesItem = wizardProgress()->item(m_modulesPageId);
174
Utils::WizardProgressItem *filesItem = wizardProgress()->item(m_filesPageId);
175
filesItem->setTitle(tr("Details"));
177
if (m_targetPageId != -1) {
178
targetItem->setNextItems(QList<Utils::WizardProgressItem *>()
179
<< mobileItem << modulesItem << filesItem);
180
targetItem->setNextShownItem(0);
181
mobileItem->setNextItems(QList<Utils::WizardProgressItem *>()
182
<< modulesItem << filesItem);
183
mobileItem->setNextShownItem(0);
184
} else if (m_mobilePageId != -1) {
185
introItem->setNextItems(QList<Utils::WizardProgressItem *>()
187
mobileItem->setNextItems(QList<Utils::WizardProgressItem *>()
188
<< modulesItem << filesItem);
189
mobileItem->setNextShownItem(0);
191
introItem->setNextItems(QList<Utils::WizardProgressItem *>()
192
<< modulesItem << filesItem);
193
introItem->setNextShownItem(0);
196
connect(this, SIGNAL(currentIdChanged(int)), this, SLOT(slotCurrentIdChanged(int)));
198
addExtensionPages(parameters.extensionPages());
201
void LibraryWizardDialog::setSuffixes(const QString &header, const QString &source, const QString &form)
203
m_filesPage->setSuffixes(header, source, form);
206
void LibraryWizardDialog::setLowerCaseFiles(bool l)
208
m_filesPage->setLowerCaseFiles(l);
211
QtProjectParameters::Type LibraryWizardDialog::type() const
213
return static_cast<const LibraryIntroPage*>(introPage())->type();
216
bool LibraryWizardDialog::isModulesPageSkipped() const
218
// When leaving the intro, target or mobile page, the modules page is skipped
219
// in the case of a plugin since it knows its dependencies by itself.
220
return type() == QtProjectParameters::Qt4Plugin;
223
int LibraryWizardDialog::skipModulesPageIfNeeded() const
225
if (isModulesPageSkipped())
226
return m_filesPageId;
227
return m_modulesPageId;
230
int LibraryWizardDialog::nextId() const
232
if (m_targetPageId != -1) {
233
if (currentId() == m_targetPageId) {
235
int next = m_modulesPageId;
237
if (next == m_modulesPageId)
238
return skipModulesPageIfNeeded();
241
} else if (currentId() == m_mobilePageId) {
242
return skipModulesPageIfNeeded();
244
} else if (currentId() == startId()) {
245
return skipModulesPageIfNeeded();
246
} else if (currentId() == m_mobilePageId) {
247
return skipModulesPageIfNeeded();
250
return BaseQt4ProjectWizardDialog::nextId();
253
void LibraryWizardDialog::initializePage(int id)
255
if (m_targetPageId != -1 && (id == m_targetPageId || id == m_mobilePageId)) {
256
Utils::WizardProgressItem *mobileItem = wizardProgress()->item(m_mobilePageId);
257
Utils::WizardProgressItem *modulesItem = wizardProgress()->item(m_modulesPageId);
258
Utils::WizardProgressItem *filesItem = wizardProgress()->item(m_filesPageId);
259
if (isModulesPageSkipped())
260
mobileItem->setNextShownItem(filesItem);
262
mobileItem->setNextShownItem(modulesItem);
265
BaseQt4ProjectWizardDialog::initializePage(id);
268
void LibraryWizardDialog::cleanupPage(int id)
270
if (m_targetPageId != -1 && (id == m_targetPageId || id == m_mobilePageId)) {
271
Utils::WizardProgressItem *mobileItem = wizardProgress()->item(m_mobilePageId);
272
mobileItem->setNextShownItem(0);
274
BaseQt4ProjectWizardDialog::cleanupPage(id);
277
QtProjectParameters LibraryWizardDialog::parameters() const
279
QtProjectParameters rc;
281
rc.fileName = projectName();
283
if (rc.type == QtProjectParameters::Qt4Plugin) {
284
// Plugin: Dependencies & Target directory
285
if (const PluginBaseClasses *plb = findPluginBaseClass(m_filesPage->baseClassName())) {
286
rc.selectedModules = pluginDependencies(plb);
287
if (plb->targetDirectory) {
288
rc.targetDirectory = QLatin1String("$$[QT_INSTALL_PLUGINS]/");
289
rc.targetDirectory += QLatin1String(plb->targetDirectory);
293
// Modules from modules page
294
rc.selectedModules = selectedModulesList();
295
rc.deselectedModules = deselectedModulesList();
300
void LibraryWizardDialog::slotCurrentIdChanged(int id)
303
qDebug() << Q_FUNC_INFO << id;
304
if (id == m_filesPageId)
305
setupFilesPage();// Switching to files page: Set up base class accordingly (plugin)
306
else if (id == m_mobilePageId
307
|| (currentPage() && currentPage()->isFinalPage()))
311
void LibraryWizardDialog::setupFilesPage()
314
case QtProjectParameters::Qt4Plugin:
315
if (!m_pluginBaseClassesInitialized) {
317
qDebug("initializing for plugins");
318
QStringList baseClasses;
319
const int pluginBaseClassCount = sizeof(pluginBaseClasses)/sizeof(PluginBaseClasses);
320
Q_ASSERT(defaultPluginBaseClass < pluginBaseClassCount);
321
for (int i = 0; i < pluginBaseClassCount; i++)
322
baseClasses.push_back(QLatin1String(pluginBaseClasses[i].name));
323
m_filesPage->setBaseClassChoices(baseClasses);
324
m_filesPage->setBaseClassName(baseClasses.at(defaultPluginBaseClass));
325
m_pluginBaseClassesInitialized = true;
327
m_filesPage->setBaseClassInputVisible(true);
330
// Urrm, figure out a good class name. Use project name this time
331
QString className = projectName();
332
if (!className.isEmpty())
333
className[0] = className.at(0).toUpper();
334
m_filesPage->setClassName(className);
335
m_filesPage->setBaseClassInputVisible(false);
341
void LibraryWizardDialog::setupMobilePage()
343
if (type() == QtProjectParameters::Qt4Plugin)
344
m_mobilePage->setQtPluginDirectory(projectName());
345
m_mobilePage->setLibraryType(type());
348
LibraryParameters LibraryWizardDialog::libraryParameters() const
350
LibraryParameters rc;
351
rc.className = m_filesPage->className();
352
rc.baseClassName = m_filesPage->baseClassName();
353
rc.sourceFileName = m_filesPage->sourceFileName();
354
rc.headerFileName = m_filesPage->headerFileName();
358
QString LibraryWizardDialog::pluginInterface(const QString &baseClass)
360
if (const PluginBaseClasses *plb = findPluginBaseClass(baseClass))
361
if (plb->pluginInterface)
362
return QLatin1String("org.qt-project.Qt.") + QLatin1String(plb->pluginInterface);
366
MobileLibraryParameters LibraryWizardDialog::mobileLibraryParameters() const
368
MobileLibraryParameters mlp;
369
mlp.libraryType = type();
370
mlp.fileName = projectName();
372
// Maemo stuff should always be added to pro file. Even if no mobile target is specified
373
mlp.type |= MobileLibraryParameters::Linux;
378
} // namespace Internal
379
} // namespace QmakeProjectManager