OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qt4projectmanager / wizards / qmlstandaloneappwizard.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 "mobileappwizardpages.h"
35
36 #include "qmlstandaloneapp.h"
37 #include "qmlstandaloneappwizard.h"
38 #include "qmlstandaloneappwizardpages.h"
39 #include "targetsetuppage.h"
40
41 #include "qt4projectmanagerconstants.h"
42
43 #include <projectexplorer/baseprojectwizarddialog.h>
44 #include <projectexplorer/customwizard/customwizard.h>
45 #include <projectexplorer/projectexplorer.h>
46 #include <coreplugin/editormanager/editormanager.h>
47
48 #include <QtCore/QCoreApplication>
49 #include <QtGui/QIcon>
50
51 namespace Qt4ProjectManager {
52 namespace Internal {
53
54 class QmlStandaloneAppWizardDialog : public AbstractMobileAppWizardDialog
55 {
56     Q_OBJECT
57
58 public:
59     explicit QmlStandaloneAppWizardDialog(QWidget *parent = 0);
60
61 private:
62     class QmlStandaloneAppWizardSourcesPage *m_qmlSourcesPage;
63     friend class QmlStandaloneAppWizard;
64 };
65
66 QmlStandaloneAppWizardDialog::QmlStandaloneAppWizardDialog(QWidget *parent)
67     : AbstractMobileAppWizardDialog(parent)
68     , m_qmlSourcesPage(0)
69 {
70     setWindowTitle(tr("New Qt Quick Application"));
71     setIntroDescription(tr("This wizard generates a Qt Quick application project."));
72
73     m_qmlSourcesPage = new QmlStandaloneAppWizardSourcesPage;
74     addPageWithTitle(m_qmlSourcesPage, tr("QML Sources"));
75 }
76
77
78 class QmlStandaloneAppWizardPrivate
79 {
80     class QmlStandaloneApp *standaloneApp;
81     class QmlStandaloneAppWizardDialog *wizardDialog;
82     friend class QmlStandaloneAppWizard;
83 };
84
85 QmlStandaloneAppWizard::QmlStandaloneAppWizard()
86     : AbstractMobileAppWizard(parameters())
87     , m_d(new QmlStandaloneAppWizardPrivate)
88 {
89     m_d->standaloneApp = new QmlStandaloneApp;
90     m_d->wizardDialog = 0;
91 }
92
93 QmlStandaloneAppWizard::~QmlStandaloneAppWizard()
94 {
95     delete m_d->standaloneApp;
96     delete m_d;
97 }
98
99 Core::BaseFileWizardParameters QmlStandaloneAppWizard::parameters()
100 {
101     Core::BaseFileWizardParameters parameters(ProjectWizard);
102     parameters.setIcon(QIcon(QLatin1String(Constants::ICON_QML_STANDALONE)));
103     parameters.setDisplayName(tr("Qt Quick Application"));
104     parameters.setId(QLatin1String("QA.QMLA Application"));
105     parameters.setDescription(tr("Creates a Qt Quick application project that can contain "
106                                  "both QML and C++ code and includes a QDeclarativeView.\n\n"
107                                  "You can build the application and deploy it on desktop and "
108                                  "mobile target platforms. For example, you can create signed "
109                                  "Symbian Installation System (SIS) packages for this type of "
110                                  "projects."));
111     parameters.setCategory(QLatin1String(Constants::QML_WIZARD_CATEGORY));
112     parameters.setDisplayCategory(QCoreApplication::translate(Constants::QML_WIZARD_TR_SCOPE,
113                                                               Constants::QML_WIZARD_TR_CATEGORY));
114     return parameters;
115 }
116
117 AbstractMobileAppWizardDialog *QmlStandaloneAppWizard::createWizardDialogInternal(QWidget *parent) const
118 {
119     m_d->wizardDialog = new QmlStandaloneAppWizardDialog(parent);
120     const QList<TargetSetupPage::ImportInfo> &qtVersions
121         = TargetSetupPage::importInfosForKnownQtVersions();
122     QList<TargetSetupPage::ImportInfo> qmlQtVersions;
123     foreach (const TargetSetupPage::ImportInfo &qtVersion, qtVersions) {
124         const QString versionString = qtVersion.version->qtVersionString();
125         bool isNumber;
126         const int majorVersion = versionString.mid(0, 1).toInt(&isNumber);
127         if (!isNumber || majorVersion < 4)
128             continue;
129         const int minorVersion = versionString.mid(2, 1).toInt(&isNumber);
130         if (!isNumber || (majorVersion == 4 && minorVersion < 7))
131             continue;
132         qmlQtVersions << qtVersion;
133     }
134     m_d->wizardDialog->m_targetsPage->setImportInfos(qmlQtVersions);
135
136     return m_d->wizardDialog;
137 }
138
139 void QmlStandaloneAppWizard::prepareGenerateFiles(const QWizard *w,
140     QString *errorMessage) const
141 {
142     Q_UNUSED(errorMessage)
143     const QmlStandaloneAppWizardDialog *wizard = qobject_cast<const QmlStandaloneAppWizardDialog*>(w);
144     const QString mainQmlFile = wizard->m_qmlSourcesPage->mainQmlFile();
145     if (!mainQmlFile.isEmpty())
146         m_d->standaloneApp->setMainQmlFile(mainQmlFile);
147 }
148
149 bool QmlStandaloneAppWizard::postGenerateFilesInternal(const Core::GeneratedFiles &l,
150     QString *errorMessage)
151 {
152     const bool success = ProjectExplorer::CustomProjectWizard::postGenerateOpen(l, errorMessage);
153     if (success && !m_d->standaloneApp->mainQmlFile().isEmpty()) {
154         ProjectExplorer::ProjectExplorerPlugin::instance()->setCurrentFile(0, m_d->standaloneApp->mainQmlFile());
155         Core::EditorManager::instance()->openEditor(m_d->standaloneApp->mainQmlFile(),
156                                                     QString(), Core::EditorManager::ModeSwitch);
157     }
158     return success;
159 }
160
161 AbstractMobileApp *QmlStandaloneAppWizard::app() const
162 {
163     return m_d->standaloneApp;
164 }
165
166 AbstractMobileAppWizardDialog *QmlStandaloneAppWizard::wizardDialog() const
167 {
168     return m_d->wizardDialog;
169 }
170
171 } // namespace Internal
172 } // namespace Qt4ProjectManager
173
174 #include "qmlstandaloneappwizard.moc"