OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qt4projectmanager / wizards / abstractmobileappwizard.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
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
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
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.
24 **
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.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #include "abstractmobileappwizard.h"
35
36 #include "abstractmobileapp.h"
37 #include "mobileappwizardpages.h"
38 #include "targetsetuppage.h"
39
40 #include <extensionsystem/pluginmanager.h>
41 #include <qt4projectmanager/qt4project.h>
42 #include <qt4projectmanager/qt4projectmanager.h>
43 #include <qt4projectmanager/qt4projectmanagerconstants.h>
44
45 #include <QtGui/QIcon>
46
47 namespace Qt4ProjectManager {
48 namespace Internal {
49
50 AbstractMobileAppWizardDialog::AbstractMobileAppWizardDialog(QWidget *parent)
51     : ProjectExplorer::BaseProjectWizardDialog(parent)
52 {
53     m_targetsPage = new TargetSetupPage;
54     resize(900, 450);
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"));
66
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);
71
72     m_targetItem->setNextShownItem(0);
73     m_genericItem->setNextShownItem(0);
74     m_symbianItem->setNextShownItem(0);
75 }
76
77 int AbstractMobileAppWizardDialog::addPageWithTitle(QWizardPage *page, const QString &title)
78 {
79     const int pageId = addPage(page);
80     wizardProgress()->item(pageId)->setTitle(title);
81     return pageId;
82 }
83
84 int AbstractMobileAppWizardDialog::nextId() const
85 {
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));
91
92     if (currentPage() == m_targetsPage) {
93         if (symbianTargetSelected || maemoTargetSelected)
94             return m_genericOptionsPageId;
95         else
96             return idOfNextGenericPage();
97     } else if (currentPage() == m_genericOptionsPage) {
98         if (symbianTargetSelected)
99             return m_symbianOptionsPageId;
100         else
101             return m_maemoOptionsPageId;
102     } else if (currentPage() == m_symbianOptionsPage) {
103         if (maemoTargetSelected)
104             return m_maemoOptionsPageId;
105         else
106             return idOfNextGenericPage();
107     } else {
108         return BaseProjectWizardDialog::nextId();
109     }
110 }
111
112 void AbstractMobileAppWizardDialog::initializePage(int id)
113 {
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));
124
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();
132
133         for (int i = 0; i < order.count() - 1; i++)
134             order.at(i)->setNextShownItem(order.at(i + 1));
135     }
136     BaseProjectWizardDialog::initializePage(id);
137 }
138
139 void AbstractMobileAppWizardDialog::cleanupPage(int id)
140 {
141     if (id == m_genericOptionsPageId) {
142         m_genericItem->setNextShownItem(0);
143         m_symbianItem->setNextShownItem(0);
144     }
145     BaseProjectWizardDialog::cleanupPage(id);
146 }
147
148 int AbstractMobileAppWizardDialog::idOfNextGenericPage() const
149 {
150     return pageIds().at(pageIds().indexOf(m_maemoOptionsPageId) + 1);
151 }
152
153 Utils::WizardProgressItem *AbstractMobileAppWizardDialog::itemOfNextGenericPage() const
154 {
155     return wizardProgress()->item(idOfNextGenericPage());
156 }
157
158 AbstractMobileAppWizard::AbstractMobileAppWizard(const Core::BaseFileWizardParameters &params,
159     QObject *parent) : Core::BaseFileWizard(params, parent)
160 {
161 }
162
163 QWizard *AbstractMobileAppWizard::createWizardDialog(QWidget *parent,
164     const QString &defaultPath, const WizardPageList &extensionPages) const
165 {
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));
178     return wdlg;
179 }
180
181 Core::GeneratedFiles AbstractMobileAppWizard::generateFiles(const QWizard *wizard,
182     QString *errorMessage) const
183 {
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);
193 }
194
195 bool AbstractMobileAppWizard::postGenerateFiles(const QWizard *w,
196     const Core::GeneratedFiles &l, QString *errorMessage)
197 {
198     Q_UNUSED(w);
199     Qt4Manager * const manager
200         = ExtensionSystem::PluginManager::instance()->getObject<Qt4Manager>();
201     Q_ASSERT(manager);
202     Qt4Project project(manager, app()->path(AbstractMobileApp::AppPro));
203     bool success = wizardDialog()->m_targetsPage->setupProject(&project);
204     if (success) {
205         project.saveSettings();
206         success = postGenerateFilesInternal(l, errorMessage);
207     }
208     return success;
209 }
210
211 void AbstractMobileAppWizard::useProjectPath(const QString &projectName,
212     const QString &projectPath)
213 {
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));
218 }
219
220 } // end of namespace Internal
221 } // end of namespace Qt4ProjectManager