1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "abstractmobileappwizard.h"
36 #include "abstractmobileapp.h"
37 #include "mobileappwizardpages.h"
38 #include "targetsetuppage.h"
40 #include <extensionsystem/pluginmanager.h>
41 #include <qt4projectmanager/qt4project.h>
42 #include <qt4projectmanager/qt4projectmanager.h>
43 #include <qt4projectmanager/qt4projectmanagerconstants.h>
45 #include <QtGui/QIcon>
47 namespace Qt4ProjectManager {
50 AbstractMobileAppWizardDialog::AbstractMobileAppWizardDialog(QWidget *parent)
51 : ProjectExplorer::BaseProjectWizardDialog(parent)
53 m_targetsPage = new TargetSetupPage;
55 m_targetsPage->setImportDirectoryBrowsingEnabled(false);
56 m_targetsPageId = addPageWithTitle(m_targetsPage, tr("Qt Versions"));
57 m_genericOptionsPage = new MobileAppWizardGenericOptionsPage;
58 m_genericOptionsPageId = addPageWithTitle(m_genericOptionsPage,
59 tr("Mobile Options"));
60 m_symbianOptionsPage = new MobileAppWizardSymbianOptionsPage;
61 m_symbianOptionsPageId = addPageWithTitle(m_symbianOptionsPage,
62 QLatin1String(" ") + tr("Symbian Specific"));
63 m_maemoOptionsPage = new MobileAppWizardMaemoOptionsPage;
64 m_maemoOptionsPageId = addPageWithTitle(m_maemoOptionsPage,
65 QLatin1String(" ") + tr("Maemo Specific"));
67 m_targetItem = wizardProgress()->item(m_targetsPageId);
68 m_genericItem = wizardProgress()->item(m_genericOptionsPageId);
69 m_symbianItem = wizardProgress()->item(m_symbianOptionsPageId);
70 m_maemoItem = wizardProgress()->item(m_maemoOptionsPageId);
72 m_targetItem->setNextShownItem(0);
73 m_genericItem->setNextShownItem(0);
74 m_symbianItem->setNextShownItem(0);
77 int AbstractMobileAppWizardDialog::addPageWithTitle(QWizardPage *page, const QString &title)
79 const int pageId = addPage(page);
80 wizardProgress()->item(pageId)->setTitle(title);
84 int AbstractMobileAppWizardDialog::nextId() const
86 const bool symbianTargetSelected =
87 m_targetsPage->isTargetSelected(QLatin1String(Constants::S60_EMULATOR_TARGET_ID))
88 || m_targetsPage->isTargetSelected(QLatin1String(Constants::S60_DEVICE_TARGET_ID));
89 const bool maemoTargetSelected =
90 m_targetsPage->isTargetSelected(QLatin1String(Constants::MAEMO_DEVICE_TARGET_ID));
92 if (currentPage() == m_targetsPage) {
93 if (symbianTargetSelected || maemoTargetSelected)
94 return m_genericOptionsPageId;
96 return idOfNextGenericPage();
97 } else if (currentPage() == m_genericOptionsPage) {
98 if (symbianTargetSelected)
99 return m_symbianOptionsPageId;
101 return m_maemoOptionsPageId;
102 } else if (currentPage() == m_symbianOptionsPage) {
103 if (maemoTargetSelected)
104 return m_maemoOptionsPageId;
106 return idOfNextGenericPage();
108 return BaseProjectWizardDialog::nextId();
112 void AbstractMobileAppWizardDialog::initializePage(int id)
114 if (id == startId()) {
115 m_targetItem->setNextItems(QList<Utils::WizardProgressItem *>() << m_genericItem << itemOfNextGenericPage());
116 m_genericItem->setNextItems(QList<Utils::WizardProgressItem *>() << m_symbianItem << m_maemoItem);
117 m_symbianItem->setNextItems(QList<Utils::WizardProgressItem *>() << m_maemoItem << itemOfNextGenericPage());
118 } else if (id == m_genericOptionsPageId) {
119 const bool symbianTargetSelected =
120 m_targetsPage->isTargetSelected(QLatin1String(Constants::S60_EMULATOR_TARGET_ID))
121 || m_targetsPage->isTargetSelected(QLatin1String(Constants::S60_DEVICE_TARGET_ID));
122 const bool maemoTargetSelected =
123 m_targetsPage->isTargetSelected(QLatin1String(Constants::MAEMO_DEVICE_TARGET_ID));
125 QList<Utils::WizardProgressItem *> order;
126 order << m_genericItem;
127 if (symbianTargetSelected)
128 order << m_symbianItem;
129 if (maemoTargetSelected)
130 order << m_maemoItem;
131 order << itemOfNextGenericPage();
133 for (int i = 0; i < order.count() - 1; i++)
134 order.at(i)->setNextShownItem(order.at(i + 1));
136 BaseProjectWizardDialog::initializePage(id);
139 void AbstractMobileAppWizardDialog::cleanupPage(int id)
141 if (id == m_genericOptionsPageId) {
142 m_genericItem->setNextShownItem(0);
143 m_symbianItem->setNextShownItem(0);
145 BaseProjectWizardDialog::cleanupPage(id);
148 int AbstractMobileAppWizardDialog::idOfNextGenericPage() const
150 return pageIds().at(pageIds().indexOf(m_maemoOptionsPageId) + 1);
153 Utils::WizardProgressItem *AbstractMobileAppWizardDialog::itemOfNextGenericPage() const
155 return wizardProgress()->item(idOfNextGenericPage());
158 AbstractMobileAppWizard::AbstractMobileAppWizard(const Core::BaseFileWizardParameters ¶ms,
159 QObject *parent) : Core::BaseFileWizard(params, parent)
163 QWizard *AbstractMobileAppWizard::createWizardDialog(QWidget *parent,
164 const QString &defaultPath, const WizardPageList &extensionPages) const
166 AbstractMobileAppWizardDialog * const wdlg
167 = createWizardDialogInternal(parent);
168 wdlg->setPath(defaultPath);
169 wdlg->setProjectName(ProjectExplorer::BaseProjectWizardDialog::uniqueProjectName(defaultPath));
170 wdlg->m_genericOptionsPage->setOrientation(app()->orientation());
171 wdlg->m_symbianOptionsPage->setSvgIcon(app()->symbianSvgIcon());
172 wdlg->m_symbianOptionsPage->setNetworkEnabled(app()->networkEnabled());
173 wdlg->m_maemoOptionsPage->setPngIcon(app()->maemoPngIcon());
174 connect(wdlg, SIGNAL(projectParametersChanged(QString, QString)),
175 SLOT(useProjectPath(QString, QString)));
176 foreach (QWizardPage *p, extensionPages)
177 BaseFileWizard::applyExtensionPageShortTitle(wdlg, wdlg->addPage(p));
181 Core::GeneratedFiles AbstractMobileAppWizard::generateFiles(const QWizard *wizard,
182 QString *errorMessage) const
184 prepareGenerateFiles(wizard, errorMessage);
185 const AbstractMobileAppWizardDialog *wdlg
186 = qobject_cast<const AbstractMobileAppWizardDialog*>(wizard);
187 app()->setOrientation(wdlg->m_genericOptionsPage->orientation());
188 app()->setSymbianTargetUid(wdlg->m_symbianOptionsPage->symbianUid());
189 app()->setSymbianSvgIcon(wdlg->m_symbianOptionsPage->svgIcon());
190 app()->setNetworkEnabled(wdlg->m_symbianOptionsPage->networkEnabled());
191 app()->setMaemoPngIcon(wdlg->m_maemoOptionsPage->pngIcon());
192 return app()->generateFiles(errorMessage);
195 bool AbstractMobileAppWizard::postGenerateFiles(const QWizard *w,
196 const Core::GeneratedFiles &l, QString *errorMessage)
199 Qt4Manager * const manager
200 = ExtensionSystem::PluginManager::instance()->getObject<Qt4Manager>();
202 Qt4Project project(manager, app()->path(AbstractMobileApp::AppPro));
203 bool success = wizardDialog()->m_targetsPage->setupProject(&project);
205 project.saveSettings();
206 success = postGenerateFilesInternal(l, errorMessage);
211 void AbstractMobileAppWizard::useProjectPath(const QString &projectName,
212 const QString &projectPath)
214 wizardDialog()->m_symbianOptionsPage->setSymbianUid(app()->symbianUidForPath(projectPath + projectName));
215 app()->setProjectName(projectName);
216 app()->setProjectPath(projectPath);
217 wizardDialog()->m_targetsPage->setProFilePath(app()->path(AbstractMobileApp::AppPro));
220 } // end of namespace Internal
221 } // end of namespace Qt4ProjectManager