1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #include "librarywizarddialog.h"
34 #include "filespage.h"
35 #include "libraryparameters.h"
36 #include "modulespage.h"
37 #include "mobilelibrarywizardoptionpage.h"
38 #include "mobilelibraryparameters.h"
39 #include "abstractmobileapp.h"
40 #include "qt4projectmanagerconstants.h"
42 #include <utils/projectintropage.h>
44 #include <QtCore/QDebug>
45 #include <QtCore/QDir>
47 #include <QtGui/QComboBox>
48 #include <QtGui/QLabel>
50 enum { debugLibWizard = 0 };
52 namespace Qt4ProjectManager {
55 struct PluginBaseClasses {
58 // blank separated list or 0
59 const char *dependentModules;
60 const char *targetDirectory;
63 static const PluginBaseClasses pluginBaseClasses[] =
65 { "QAccessiblePlugin", "QtGui", "QtCore", "accessible" },
66 { "QDecorationPlugin", "QtGui", "QtCore", 0},
67 { "QIconEnginePluginV2", "QtGui", "QtCore", "imageformats" },
68 { "QImageIOPlugin", "QtGui", "QtCore", "imageformats" },
69 { "QScriptExtensionPlugin", "QtScript", "QtCore", 0 },
70 { "QSqlDriverPlugin", "QtSql", "QtCore", "sqldrivers" },
71 { "QStylePlugin", "QtGui", "QtCore", "styles" },
72 { "QTextCodecPlugin", "QtCore", 0, "codecs" }
75 enum { defaultPluginBaseClass = 6 };
77 static const PluginBaseClasses *findPluginBaseClass(const QString &name)
79 const int pluginBaseClassCount = sizeof(pluginBaseClasses)/sizeof(PluginBaseClasses);
80 for (int i = 0; i < pluginBaseClassCount; i++)
81 if (name == QLatin1String(pluginBaseClasses[i].name))
82 return pluginBaseClasses + i;
86 // return dependencies of a plugin as a line ready for the 'QT=' line in a pro
88 static QString pluginDependencies(const PluginBaseClasses *plb)
91 const QChar blank = QLatin1Char(' ');
92 // Find the module names and convert to ids
93 QStringList pluginModules= plb->dependentModules ?
94 QString(QLatin1String(plb->dependentModules)).split(blank) :
96 pluginModules.push_back(QLatin1String(plb->module));
97 foreach (const QString &module, pluginModules) {
98 if (!dependencies.isEmpty())
99 dependencies += blank;
100 dependencies += ModulesPage::idOfModule(module);
105 // A Project intro page with an additional type chooser.
106 class LibraryIntroPage : public Utils::ProjectIntroPage
108 Q_DISABLE_COPY(LibraryIntroPage)
110 explicit LibraryIntroPage(QWidget *parent = 0);
112 QtProjectParameters::Type type() const;
115 QComboBox *m_typeCombo;
118 LibraryIntroPage::LibraryIntroPage(QWidget *parent) :
119 Utils::ProjectIntroPage(parent),
120 m_typeCombo(new QComboBox)
122 m_typeCombo->setEditable(false);
123 m_typeCombo->addItem(LibraryWizardDialog::tr("Shared Library"),
124 QVariant(QtProjectParameters::SharedLibrary));
125 m_typeCombo->addItem(LibraryWizardDialog::tr("Statically Linked Library"),
126 QVariant(QtProjectParameters::StaticLibrary));
127 m_typeCombo->addItem(LibraryWizardDialog::tr("Qt 4 Plugin"),
128 QVariant(QtProjectParameters::Qt4Plugin));
129 insertControl(0, new QLabel(LibraryWizardDialog::tr("Type")), m_typeCombo);
132 QtProjectParameters::Type LibraryIntroPage::type() const
134 return static_cast<QtProjectParameters::Type>(m_typeCombo->itemData(m_typeCombo->currentIndex()).toInt());
137 // ------------------- LibraryWizardDialog
138 LibraryWizardDialog::LibraryWizardDialog(const QString &templateName,
140 const QList<QWizardPage*> &extensionPages,
141 bool showModulesPage,
143 BaseQt4ProjectWizardDialog(showModulesPage, new LibraryIntroPage, -1, parent),
144 m_filesPage(new FilesPage),
145 m_mobilePage(new MobileLibraryWizardOptionPage),
146 m_pluginBaseClassesInitialized(false),
147 m_filesPageId(-1), m_modulesPageId(-1), m_targetPageId(-1),
151 setWindowTitle(templateName);
152 setSelectedModules(QLatin1String("core"));
154 // Note that QWizard::currentIdChanged() is emitted at strange times.
155 // Use the intro page instead, set up initially
156 setIntroDescription(tr("This wizard generates a C++ library project."));
158 m_targetPageId = addTargetSetupPage();
160 if (m_targetPageId != -1)
161 m_mobilePageId = addPage(m_mobilePage);
163 m_modulesPageId = addModulesPage();
165 m_filesPage->setNamespacesEnabled(true);
166 m_filesPage->setFormFileInputVisible(false);
167 m_filesPage->setClassTypeComboVisible(false);
169 m_filesPageId = addPage(m_filesPage);
171 Utils::WizardProgressItem *introItem = wizardProgress()->item(startId());
172 Utils::WizardProgressItem *targetItem;
173 if (m_targetPageId != -1)
174 targetItem = wizardProgress()->item(m_targetPageId);
175 Utils::WizardProgressItem *mobileItem = wizardProgress()->item(m_mobilePageId);
176 mobileItem->setTitle(QLatin1String(" ") + tr("Symbian Specific"));
177 Utils::WizardProgressItem *modulesItem = wizardProgress()->item(m_modulesPageId);
178 Utils::WizardProgressItem *filesItem = wizardProgress()->item(m_filesPageId);
179 filesItem->setTitle(tr("Details"));
181 if (m_targetPageId != -1) {
182 targetItem->setNextItems(QList<Utils::WizardProgressItem *>()
183 << mobileItem << modulesItem << filesItem);
184 targetItem->setNextShownItem(0);
185 mobileItem->setNextItems(QList<Utils::WizardProgressItem *>()
186 << modulesItem << filesItem);
187 mobileItem->setNextShownItem(0);
189 introItem->setNextItems(QList<Utils::WizardProgressItem *>()
190 << modulesItem << filesItem);
191 introItem->setNextShownItem(0);
195 connect(this, SIGNAL(currentIdChanged(int)), this, SLOT(slotCurrentIdChanged(int)));
197 foreach (QWizardPage *p, extensionPages)
198 Core::BaseFileWizard::applyExtensionPageShortTitle(this, addPage(p));
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 void LibraryWizardDialog::setSymbianUid(const QString &uid)
213 m_mobilePage->setSymbianUid(uid);
216 QtProjectParameters::Type LibraryWizardDialog::type() const
218 return static_cast<const LibraryIntroPage*>(introPage())->type();
221 bool LibraryWizardDialog::isModulesPageSkipped() const
223 // When leaving the intro, target or mobile page, the modules page is skipped
224 // in the case of a plugin since it knows its dependencies by itself.
225 return type() == QtProjectParameters::Qt4Plugin;
228 int LibraryWizardDialog::skipModulesPageIfNeeded() const
230 if (isModulesPageSkipped())
231 return m_filesPageId;
232 return m_modulesPageId;
235 int LibraryWizardDialog::nextId() const
237 if (m_targetPageId != -1) {
238 if (currentId() == m_targetPageId) {
240 int next = m_modulesPageId;
242 const bool symbianTargetEnabled = isTargetSelected(QLatin1String(Constants::S60_DEVICE_TARGET_ID))
243 || isTargetSelected(QLatin1String(Constants::S60_EMULATOR_TARGET_ID));
245 // If there was no Symbian target defined we omit "Symbian specific" step
246 // We also omit this step if the library type is not dll
247 if (symbianTargetEnabled
248 && (type() == QtProjectParameters::SharedLibrary
249 || type() == QtProjectParameters::Qt4Plugin))
250 next = m_mobilePageId;
252 if (next == m_modulesPageId)
253 return skipModulesPageIfNeeded();
256 } else if (currentId() == m_mobilePageId) {
257 return skipModulesPageIfNeeded();
259 } else if (currentId() == startId()) {
260 return skipModulesPageIfNeeded();
263 return BaseQt4ProjectWizardDialog::nextId();
266 void LibraryWizardDialog::initializePage(int id)
268 if (m_targetPageId != -1 && id == m_targetPageId) {
269 Utils::WizardProgressItem *mobileItem = wizardProgress()->item(m_mobilePageId);
270 Utils::WizardProgressItem *modulesItem = wizardProgress()->item(m_modulesPageId);
271 Utils::WizardProgressItem *filesItem = wizardProgress()->item(m_filesPageId);
272 if (isModulesPageSkipped())
273 mobileItem->setNextShownItem(filesItem);
275 mobileItem->setNextShownItem(modulesItem);
278 BaseQt4ProjectWizardDialog::initializePage(id);
281 void LibraryWizardDialog::cleanupPage(int id)
283 if (m_targetPageId != -1 && id == m_targetPageId) {
284 Utils::WizardProgressItem *mobileItem = wizardProgress()->item(m_mobilePageId);
285 mobileItem->setNextShownItem(0);
287 BaseQt4ProjectWizardDialog::cleanupPage(id);
290 QtProjectParameters LibraryWizardDialog::parameters() const
292 QtProjectParameters rc;
294 rc.fileName = projectName();
296 if (rc.type == QtProjectParameters::Qt4Plugin) {
297 // Plugin: Dependencies & Target directory
298 if (const PluginBaseClasses *plb = findPluginBaseClass(m_filesPage->baseClassName())) {
299 rc.selectedModules = pluginDependencies(plb);
300 if (plb->targetDirectory) {
301 rc.targetDirectory = QLatin1String("$$[QT_INSTALL_PLUGINS]/");
302 rc.targetDirectory += QLatin1String(plb->targetDirectory);
306 // Modules from modules page
307 rc.selectedModules = selectedModules();
308 rc.deselectedModules = deselectedModules();
313 void LibraryWizardDialog::slotCurrentIdChanged(int id)
316 qDebug() << Q_FUNC_INFO << id;
317 if (id == m_filesPageId)
318 setupFilesPage();// Switching to files page: Set up base class accordingly (plugin)
319 else if (id == m_mobilePageId
320 || (m_mobilePage->symbianUid().isEmpty()
321 && currentPage() && currentPage()->isFinalPage()))
325 void LibraryWizardDialog::setupFilesPage()
328 case QtProjectParameters::Qt4Plugin:
329 if (!m_pluginBaseClassesInitialized) {
331 qDebug("initializing for plugins");
332 QStringList baseClasses;
333 const int pluginBaseClassCount = sizeof(pluginBaseClasses)/sizeof(PluginBaseClasses);
334 Q_ASSERT(defaultPluginBaseClass < pluginBaseClassCount);
335 for (int i = 0; i < pluginBaseClassCount; i++)
336 baseClasses.push_back(QLatin1String(pluginBaseClasses[i].name));
337 m_filesPage->setBaseClassChoices(baseClasses);
338 m_filesPage->setBaseClassName(baseClasses.at(defaultPluginBaseClass));
339 m_pluginBaseClassesInitialized = true;
341 m_filesPage->setBaseClassInputVisible(true);
344 // Urrm, figure out a good class name. Use project name this time
345 QString className = projectName();
346 if (!className.isEmpty())
347 className[0] = className.at(0).toUpper();
348 m_filesPage->setClassName(className);
349 m_filesPage->setBaseClassInputVisible(false);
355 void LibraryWizardDialog::setupMobilePage()
357 m_mobilePage->setSymbianUid(AbstractMobileApp::symbianUidForPath(path()+projectName()));
359 if (type() == QtProjectParameters::Qt4Plugin)
360 m_mobilePage->setQtPluginDirectory(projectName());
361 m_mobilePage->setLibraryType(type());
364 LibraryParameters LibraryWizardDialog::libraryParameters() const
366 LibraryParameters rc;
367 rc.className = m_filesPage->className();
368 rc.baseClassName = m_filesPage->baseClassName();
369 rc.sourceFileName = m_filesPage->sourceFileName();
370 rc.headerFileName = m_filesPage->headerFileName();
371 if (!rc.baseClassName.isEmpty())
372 if (const PluginBaseClasses *plb = findPluginBaseClass(rc.baseClassName)) {
373 rc.baseClassModule = QLatin1String(plb->module);
378 MobileLibraryParameters LibraryWizardDialog::mobileLibraryParameters() const
380 MobileLibraryParameters mlp;
381 mlp.libraryType = type();
382 mlp.fileName = projectName();
384 //Symbian and Maemo stuff should always be added to pro file. Even if no mobile target is specified
385 mlp.type |= MobileLibraryParameters::Symbian|MobileLibraryParameters::Maemo;
387 if (mlp.type & MobileLibraryParameters::Symbian) {
388 mlp.symbianUid = m_mobilePage->symbianUid();
389 mlp.qtPluginDirectory = m_mobilePage->qtPluginDirectory();
390 mlp.symbianCapabilities |= m_mobilePage->networkEnabled()?MobileLibraryParameters::NetworkServices:0;
396 } // namespace Internal
397 } // namespace Qt4ProjectManager