OSDN Git Service

a36e0c4ffc5d37a10be4f03989de336715c4850f
[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 #include <projectexplorer/projectexplorer.h>
45 #include <projectexplorer/customwizard/customwizard.h>
46 #include <coreplugin/editormanager/editormanager.h>
47
48 #include <QtGui/QIcon>
49
50 namespace Qt4ProjectManager {
51
52 AbstractMobileAppWizardDialog::AbstractMobileAppWizardDialog(QWidget *parent, const QtVersionNumber &minimumQtVersionNumber)
53     : ProjectExplorer::BaseProjectWizardDialog(parent)
54 {
55     m_targetsPage = new TargetSetupPage;
56     m_targetsPage->setPreferMobile(true);
57     m_targetsPage->setMinimumQtVersion(minimumQtVersionNumber);
58     resize(900, 450);
59     m_targetsPageId = addPageWithTitle(m_targetsPage, tr("Qt Versions"));
60     m_genericOptionsPage = new Internal::MobileAppWizardGenericOptionsPage;
61     m_genericOptionsPageId = addPageWithTitle(m_genericOptionsPage,
62         tr("Mobile Options"));
63     m_symbianOptionsPage = new Internal::MobileAppWizardSymbianOptionsPage;
64     m_symbianOptionsPageId = addPageWithTitle(m_symbianOptionsPage,
65         QLatin1String("    ") + tr("Symbian Specific"));
66     m_maemoOptionsPage = new Internal::MobileAppWizardMaemoOptionsPage;
67     m_maemoOptionsPageId = addPageWithTitle(m_maemoOptionsPage,
68         QLatin1String("    ") + tr("Maemo Specific"));
69
70     m_targetItem = wizardProgress()->item(m_targetsPageId);
71     m_genericItem = wizardProgress()->item(m_genericOptionsPageId);
72     m_symbianItem = wizardProgress()->item(m_symbianOptionsPageId);
73     m_maemoItem = wizardProgress()->item(m_maemoOptionsPageId);
74
75     m_targetItem->setNextShownItem(0);
76     m_genericItem->setNextShownItem(0);
77     m_symbianItem->setNextShownItem(0);
78 }
79
80 TargetSetupPage *AbstractMobileAppWizardDialog::targetsPage() const
81 {
82     return m_targetsPage;
83 }
84
85 int AbstractMobileAppWizardDialog::addPageWithTitle(QWizardPage *page, const QString &title)
86 {
87     const int pageId = addPage(page);
88     wizardProgress()->item(pageId)->setTitle(title);
89     return pageId;
90 }
91
92 int AbstractMobileAppWizardDialog::nextId() const
93 {
94     const bool symbianTargetSelected =
95         m_targetsPage->isTargetSelected(QLatin1String(Constants::S60_EMULATOR_TARGET_ID))
96         || m_targetsPage->isTargetSelected(QLatin1String(Constants::S60_DEVICE_TARGET_ID));
97     const bool fremantleTargetSelected
98         = m_targetsPage->isTargetSelected(QLatin1String(Constants::MAEMO5_DEVICE_TARGET_ID));
99     const bool maemoTargetSelected = fremantleTargetSelected
100             || m_targetsPage->isTargetSelected(QLatin1String(Constants::HARMATTAN_DEVICE_TARGET_ID))
101             || m_targetsPage->isTargetSelected(QLatin1String(Constants::MEEGO_DEVICE_TARGET_ID));
102
103     if (currentPage() == m_targetsPage) {
104         if (symbianTargetSelected || fremantleTargetSelected)
105             return m_genericOptionsPageId;
106         else if (maemoTargetSelected)
107             return m_maemoOptionsPageId;
108         else
109             return idOfNextGenericPage();
110     } else if (currentPage() == m_genericOptionsPage) {
111         if (symbianTargetSelected)
112             return m_symbianOptionsPageId;
113         else
114             return m_maemoOptionsPageId;
115     } else if (currentPage() == m_symbianOptionsPage) {
116         if (maemoTargetSelected)
117             return m_maemoOptionsPageId;
118         else
119             return idOfNextGenericPage();
120     } else {
121         return BaseProjectWizardDialog::nextId();
122     }
123 }
124
125 void AbstractMobileAppWizardDialog::initializePage(int id)
126 {
127     if (id == startId()) {
128         m_targetItem->setNextItems(QList<Utils::WizardProgressItem *>() << m_genericItem << m_maemoItem << itemOfNextGenericPage());
129         m_genericItem->setNextItems(QList<Utils::WizardProgressItem *>() << m_symbianItem << m_maemoItem);
130         m_symbianItem->setNextItems(QList<Utils::WizardProgressItem *>() << m_maemoItem << itemOfNextGenericPage());
131     } else if (id == m_genericOptionsPageId) {
132         const bool symbianTargetSelected =
133             m_targetsPage->isTargetSelected(QLatin1String(Constants::S60_EMULATOR_TARGET_ID))
134             || m_targetsPage->isTargetSelected(QLatin1String(Constants::S60_DEVICE_TARGET_ID));
135         const bool maemoTargetSelected =
136             m_targetsPage->isTargetSelected(QLatin1String(Constants::MAEMO5_DEVICE_TARGET_ID))
137                 || m_targetsPage->isTargetSelected(QLatin1String(Constants::HARMATTAN_DEVICE_TARGET_ID))
138                 || m_targetsPage->isTargetSelected(QLatin1String(Constants::MEEGO_DEVICE_TARGET_ID));
139
140         QList<Utils::WizardProgressItem *> order;
141         order << m_genericItem;
142         if (symbianTargetSelected)
143             order << m_symbianItem;
144         if (maemoTargetSelected)
145             order << m_maemoItem;
146         order << itemOfNextGenericPage();
147
148         for (int i = 0; i < order.count() - 1; i++)
149             order.at(i)->setNextShownItem(order.at(i + 1));
150     }
151     BaseProjectWizardDialog::initializePage(id);
152 }
153
154 void AbstractMobileAppWizardDialog::cleanupPage(int id)
155 {
156     if (id == m_genericOptionsPageId) {
157         m_genericItem->setNextShownItem(0);
158         m_symbianItem->setNextShownItem(0);
159     }
160     BaseProjectWizardDialog::cleanupPage(id);
161 }
162
163 int AbstractMobileAppWizardDialog::idOfNextGenericPage() const
164 {
165     return pageIds().at(pageIds().indexOf(m_maemoOptionsPageId) + 1);
166 }
167
168 Utils::WizardProgressItem *AbstractMobileAppWizardDialog::itemOfNextGenericPage() const
169 {
170     return wizardProgress()->item(idOfNextGenericPage());
171 }
172
173 AbstractMobileAppWizard::AbstractMobileAppWizard(const Core::BaseFileWizardParameters &params,
174     QObject *parent) : Core::BaseFileWizard(params, parent)
175 {
176 }
177
178 QWizard *AbstractMobileAppWizard::createWizardDialog(QWidget *parent,
179     const QString &defaultPath, const WizardPageList &extensionPages) const
180 {
181     AbstractMobileAppWizardDialog * const wdlg
182         = createWizardDialogInternal(parent);
183     wdlg->setPath(defaultPath);
184     wdlg->setProjectName(ProjectExplorer::BaseProjectWizardDialog::uniqueProjectName(defaultPath));
185     wdlg->m_genericOptionsPage->setOrientation(app()->orientation());
186     wdlg->m_symbianOptionsPage->setSvgIcon(app()->symbianSvgIcon());
187     wdlg->m_symbianOptionsPage->setNetworkEnabled(app()->networkEnabled());
188     wdlg->m_maemoOptionsPage->setPngIcon(app()->maemoPngIcon());
189     connect(wdlg, SIGNAL(projectParametersChanged(QString, QString)),
190         SLOT(useProjectPath(QString, QString)));
191     foreach (QWizardPage *p, extensionPages)
192         BaseFileWizard::applyExtensionPageShortTitle(wdlg, wdlg->addPage(p));
193     return wdlg;
194 }
195
196 Core::GeneratedFiles AbstractMobileAppWizard::generateFiles(const QWizard *wizard,
197     QString *errorMessage) const
198 {
199     prepareGenerateFiles(wizard, errorMessage);
200     const AbstractMobileAppWizardDialog *wdlg
201         = qobject_cast<const AbstractMobileAppWizardDialog*>(wizard);
202     app()->setOrientation(wdlg->m_genericOptionsPage->orientation());
203     app()->setSymbianTargetUid(wdlg->m_symbianOptionsPage->symbianUid());
204     app()->setSymbianSvgIcon(wdlg->m_symbianOptionsPage->svgIcon());
205     app()->setNetworkEnabled(wdlg->m_symbianOptionsPage->networkEnabled());
206     app()->setMaemoPngIcon(wdlg->m_maemoOptionsPage->pngIcon());
207     return app()->generateFiles(errorMessage);
208 }
209
210 // TODO remove this workaround:
211 // SessionManager::projectContainsFile() incorrectly returns false if the
212 // file name in the .pro file (and thus also in m_projectFileCache)
213 // contains relative path segments ("../").
214 inline static QString fileInCurrentProject(const QString &file)
215 {
216     const QStringList filesInProject =
217             ProjectExplorer::ProjectExplorerPlugin::instance()->currentProject()->files(
218                 ProjectExplorer::Project::ExcludeGeneratedFiles);
219     foreach (const QString &uncleanFile, filesInProject)
220         if (QDir::cleanPath(uncleanFile) == file)
221             return uncleanFile;
222     return QString();
223 }
224
225 bool AbstractMobileAppWizard::postGenerateFiles(const QWizard *w,
226     const Core::GeneratedFiles &l, QString *errorMessage)
227 {
228     Q_UNUSED(w)
229     Q_UNUSED(l)
230     Q_UNUSED(errorMessage)
231     Qt4Manager * const manager
232         = ExtensionSystem::PluginManager::instance()->getObject<Qt4Manager>();
233     Q_ASSERT(manager);
234     Qt4Project project(manager, app()->path(AbstractMobileApp::AppPro));
235     bool success = wizardDialog()->m_targetsPage->setupProject(&project);
236     if (success) {
237         project.saveSettings();
238         success = ProjectExplorer::CustomProjectWizard::postGenerateOpen(l, errorMessage);
239         if (success) {
240             const QString fileToOpen = fileInCurrentProject(fileToOpenPostGeneration());
241             if (!fileToOpen.isEmpty()) {
242                 Core::EditorManager::instance()->openEditor(fileToOpen, QString(), Core::EditorManager::ModeSwitch);
243                 ProjectExplorer::ProjectExplorerPlugin::instance()->setCurrentFile(0, fileToOpen);
244             }
245         }
246     }
247     return success;
248 }
249
250 void AbstractMobileAppWizard::useProjectPath(const QString &projectName,
251     const QString &projectPath)
252 {
253     wizardDialog()->m_symbianOptionsPage->setSymbianUid(app()->symbianUidForPath(projectPath + projectName));
254     app()->setProjectName(projectName);
255     app()->setProjectPath(projectPath);
256     wizardDialog()->m_targetsPage->setProFilePath(app()->path(AbstractMobileApp::AppPro));
257     projectPathChanged(app()->path(AbstractMobileApp::AppPro));
258 }
259
260 } // namespace Qt4ProjectManager