From c30d18b51a21194260f18a28d28d38fde973432d Mon Sep 17 00:00:00 2001
From: Tobias Hunger <tobias.hunger@nokia.com>
Date: Tue, 30 Mar 2010 15:55:45 +0200
Subject: [PATCH] Add mobile Qt gui wizard

---
 .../qt4projectmanager/qt4projectmanager.pro   |  2 +
 .../qt4projectmanagerplugin.cpp               |  4 ++
 .../wizards/guiappwizard.cpp                  | 18 ++++++-
 .../qt4projectmanager/wizards/guiappwizard.h  | 10 ++++
 .../wizards/guiappwizarddialog.cpp            |  3 +-
 .../wizards/guiappwizarddialog.h              |  1 +
 .../wizards/mobileguiappwizard.cpp            | 52 +++++++++++++++++++
 .../wizards/mobileguiappwizard.h              | 49 +++++++++++++++++
 .../qt4projectmanager/wizards/qtwizard.cpp    |  5 +-
 .../qt4projectmanager/wizards/qtwizard.h      |  2 +-
 .../wizards/targetsetuppage.cpp               | 19 ++++---
 .../wizards/targetsetuppage.h                 |  2 +
 12 files changed, 156 insertions(+), 11 deletions(-)
 create mode 100644 src/plugins/qt4projectmanager/wizards/mobileguiappwizard.cpp
 create mode 100644 src/plugins/qt4projectmanager/wizards/mobileguiappwizard.h

diff --git a/src/plugins/qt4projectmanager/qt4projectmanager.pro b/src/plugins/qt4projectmanager/qt4projectmanager.pro
index b78f585a998..c9bab49f48d 100644
--- a/src/plugins/qt4projectmanager/qt4projectmanager.pro
+++ b/src/plugins/qt4projectmanager/qt4projectmanager.pro
@@ -13,6 +13,7 @@ HEADERS += qt4projectmanagerplugin.h \
     profilereader.h \
     wizards/qtprojectparameters.h \
     wizards/guiappwizard.h \
+    wizards/mobileguiappwizard.h \
     wizards/consoleappwizard.h \
     wizards/consoleappwizarddialog.h \
     wizards/libraryparameters.h \
@@ -54,6 +55,7 @@ SOURCES += qt4projectmanagerplugin.cpp \
     profilereader.cpp \
     wizards/qtprojectparameters.cpp \
     wizards/guiappwizard.cpp \
+    wizards/mobileguiappwizard.cpp \
     wizards/consoleappwizard.cpp \
     wizards/consoleappwizarddialog.cpp \
     wizards/libraryparameters.cpp \
diff --git a/src/plugins/qt4projectmanager/qt4projectmanagerplugin.cpp b/src/plugins/qt4projectmanager/qt4projectmanagerplugin.cpp
index 674fb048559..8339febd582 100644
--- a/src/plugins/qt4projectmanager/qt4projectmanagerplugin.cpp
+++ b/src/plugins/qt4projectmanager/qt4projectmanagerplugin.cpp
@@ -34,6 +34,7 @@
 #include "makestep.h"
 #include "wizards/consoleappwizard.h"
 #include "wizards/guiappwizard.h"
+#include "wizards/mobileguiappwizard.h"
 #include "wizards/librarywizard.h"
 #include "wizards/testwizard.h"
 #include "wizards/emptyprojectwizard.h"
@@ -129,6 +130,9 @@ bool Qt4ProjectManagerPlugin::initialize(const QStringList &arguments, QString *
     ConsoleAppWizard *consoleWizard = new ConsoleAppWizard;
     addAutoReleasedObject(consoleWizard);
 
+    MobileGuiAppWizard *mobileGuiWizard = new MobileGuiAppWizard();
+    addAutoReleasedObject(mobileGuiWizard);
+
     LibraryWizard *libWizard = new LibraryWizard;
     addAutoReleasedObject(libWizard);
     addAutoReleasedObject(new TestWizard);
diff --git a/src/plugins/qt4projectmanager/wizards/guiappwizard.cpp b/src/plugins/qt4projectmanager/wizards/guiappwizard.cpp
index e5ba0bc58d2..24f8cf0d4af 100644
--- a/src/plugins/qt4projectmanager/wizards/guiappwizard.cpp
+++ b/src/plugins/qt4projectmanager/wizards/guiappwizard.cpp
@@ -75,7 +75,22 @@ GuiAppWizard::GuiAppWizard()
                QLatin1String(Constants::QT_APP_WIZARD_TR_CATEGORY),
                tr("Qt Gui Application"),
                tr("Creates a Qt Gui Application with one form."),
-               QIcon(QLatin1String(":/wizards/images/gui.png")))
+               QIcon(QLatin1String(":/wizards/images/gui.png"))),
+      m_createMobileProject(false)
+{
+}
+
+GuiAppWizard::GuiAppWizard(const QString &id,
+                           const QString &category,
+                           const QString &categoryTranslationScope,
+                           const QString &displayCategory,
+                           const QString &name,
+                           const QString &description,
+                           const QIcon &icon,
+                           bool createMobile)
+    : QtWizard(id, category, categoryTranslationScope,
+               displayCategory, name, description, icon),
+      m_createMobileProject(createMobile)
 {
 }
 
@@ -85,6 +100,7 @@ QWizard *GuiAppWizard::createWizardDialog(QWidget *parent,
 {
     GuiAppWizardDialog *dialog = new GuiAppWizardDialog(displayName(), icon(), extensionPages,
                                                         showModulesPageForApplications(),
+                                                        m_createMobileProject,
                                                         parent);
     dialog->setPath(defaultPath);
     dialog->setProjectName(GuiAppWizardDialog::uniqueProjectName(defaultPath));
diff --git a/src/plugins/qt4projectmanager/wizards/guiappwizard.h b/src/plugins/qt4projectmanager/wizards/guiappwizard.h
index 2efee872187..ae47a4c4904 100644
--- a/src/plugins/qt4projectmanager/wizards/guiappwizard.h
+++ b/src/plugins/qt4projectmanager/wizards/guiappwizard.h
@@ -46,6 +46,14 @@ public:
     GuiAppWizard();
 
 protected:
+    GuiAppWizard(const QString &id,
+                 const QString &category,
+                 const QString &categoryTranslationScope,
+                 const QString &displayCategory,
+                 const QString &name,
+                 const QString &description,
+                 const QIcon &icon,
+                 bool createMobile);
     virtual QWizard *createWizardDialog(QWidget *parent,
                                         const QString &defaultPath,
                                         const WizardPageList &extensionPages) const;
@@ -57,6 +65,8 @@ private:
     static bool parametrizeTemplate(const QString &templatePath, const QString &templateName,
                                     const GuiAppParameters &params,
                                     QString *target, QString *errorMessage);
+
+    bool m_createMobileProject;
 };
 
 } // namespace Internal
diff --git a/src/plugins/qt4projectmanager/wizards/guiappwizarddialog.cpp b/src/plugins/qt4projectmanager/wizards/guiappwizarddialog.cpp
index 2155af9da43..7cbb6ed42f5 100644
--- a/src/plugins/qt4projectmanager/wizards/guiappwizarddialog.cpp
+++ b/src/plugins/qt4projectmanager/wizards/guiappwizarddialog.cpp
@@ -49,6 +49,7 @@ GuiAppWizardDialog::GuiAppWizardDialog(const QString &templateName,
                                        const QIcon &icon,
                                        const QList<QWizardPage*> &extensionPages,
                                        bool showModulesPage,
+                                       bool isMobile,
                                        QWidget *parent) :
     BaseQt4ProjectWizardDialog(showModulesPage, parent),
     m_filesPage(new FilesPage)
@@ -62,7 +63,7 @@ GuiAppWizardDialog::GuiAppWizardDialog(const QString &templateName,
          "and includes an empty widget."));
 
     addModulesPage();
-    addTargetSetupPage();
+    addTargetSetupPage(QSet<QString>(), isMobile);
 
     m_filesPage->setFormInputCheckable(true);
     m_filesPage->setClassTypeComboVisible(false);
diff --git a/src/plugins/qt4projectmanager/wizards/guiappwizarddialog.h b/src/plugins/qt4projectmanager/wizards/guiappwizarddialog.h
index 77976279503..b74fb44e1eb 100644
--- a/src/plugins/qt4projectmanager/wizards/guiappwizarddialog.h
+++ b/src/plugins/qt4projectmanager/wizards/guiappwizarddialog.h
@@ -62,6 +62,7 @@ public:
                                 const QIcon &icon,
                                 const QList<QWizardPage*> &extensionPages,
                                 bool showModulesPage = false,
+                                bool mobile = false,
                                 QWidget *parent = 0);
 
     void setBaseClasses(const QStringList &baseClasses);
diff --git a/src/plugins/qt4projectmanager/wizards/mobileguiappwizard.cpp b/src/plugins/qt4projectmanager/wizards/mobileguiappwizard.cpp
new file mode 100644
index 00000000000..e5815ec1395
--- /dev/null
+++ b/src/plugins/qt4projectmanager/wizards/mobileguiappwizard.cpp
@@ -0,0 +1,52 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** Commercial Usage
+**
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+**
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+**
+**************************************************************************/
+
+#include "mobileguiappwizard.h"
+
+#include "qt4projectmanagerconstants.h"
+
+#include <QtGui/QIcon>
+
+namespace Qt4ProjectManager {
+namespace Internal {
+
+MobileGuiAppWizard::MobileGuiAppWizard() :
+    GuiAppWizard(QLatin1String("C.Qt4GuiMobile"),
+                 QLatin1String(Constants::QT_APP_WIZARD_CATEGORY),
+                 QLatin1String(Constants::QT_APP_WIZARD_TR_SCOPE),
+                 QLatin1String(Constants::QT_APP_WIZARD_TR_CATEGORY),
+                 tr("Mobile Qt Application"),
+                 tr("Creates a mobile Qt Gui Application with one form."),
+                 QIcon(QLatin1String(":/projectexplorer/images/SymbianDevice.png")),
+                 true)
+{
+}
+
+} // namespace Internal
+} // namespace Qt4ProjectManager
diff --git a/src/plugins/qt4projectmanager/wizards/mobileguiappwizard.h b/src/plugins/qt4projectmanager/wizards/mobileguiappwizard.h
new file mode 100644
index 00000000000..0ab1711d541
--- /dev/null
+++ b/src/plugins/qt4projectmanager/wizards/mobileguiappwizard.h
@@ -0,0 +1,49 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** Commercial Usage
+**
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+**
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+**
+**************************************************************************/
+
+#ifndef MOBILEGUIAPPWIZARD_H
+#define MOBILEGUIAPPWIZARD_H
+
+#include "guiappwizard.h"
+
+namespace Qt4ProjectManager {
+namespace Internal {
+
+class MobileGuiAppWizard : public GuiAppWizard
+{
+    Q_OBJECT
+
+public:
+    MobileGuiAppWizard();
+};
+
+} // namespace Internal
+} // namespace Qt4ProjectManager
+
+#endif // GUIAPPWIZARD_H
diff --git a/src/plugins/qt4projectmanager/wizards/qtwizard.cpp b/src/plugins/qt4projectmanager/wizards/qtwizard.cpp
index 3e84b864c99..07d768dbf6e 100644
--- a/src/plugins/qt4projectmanager/wizards/qtwizard.cpp
+++ b/src/plugins/qt4projectmanager/wizards/qtwizard.cpp
@@ -165,7 +165,7 @@ QWizard *CustomQt4ProjectWizard::createWizardDialog(QWidget *parent,
     initProjectWizardDialog(wizard, defaultPath, extensionPages);
     if (wizard->pageIds().contains(targetPageId))
         qWarning("CustomQt4ProjectWizard: Unable to insert target page at %d", int(targetPageId));
-    wizard->addTargetSetupPage(QSet<QString>(), targetPageId);
+    wizard->addTargetSetupPage(QSet<QString>(), false, targetPageId);
     return wizard;
 }
 
@@ -223,7 +223,7 @@ int BaseQt4ProjectWizardDialog::addModulesPage(int id)
     return addPage(m_modulesPage);
 }
 
-int BaseQt4ProjectWizardDialog::addTargetSetupPage(QSet<QString> targets, int id)
+int BaseQt4ProjectWizardDialog::addTargetSetupPage(QSet<QString> targets, bool mobile, int id)
 {
     m_targetSetupPage = new TargetSetupPage;
     QList<TargetSetupPage::ImportInfo> infos = TargetSetupPage::importInfosForKnownQtVersions(0);
@@ -231,6 +231,7 @@ int BaseQt4ProjectWizardDialog::addTargetSetupPage(QSet<QString> targets, int id
         infos = TargetSetupPage::filterImportInfos(targets, infos);
     m_targetSetupPage->setImportDirectoryBrowsingEnabled(false);
     m_targetSetupPage->setShowLocationInformation(false);
+    m_targetSetupPage->setPreferMobile(mobile);
 
     if (infos.count() <= 1)
         return -1;
diff --git a/src/plugins/qt4projectmanager/wizards/qtwizard.h b/src/plugins/qt4projectmanager/wizards/qtwizard.h
index c5e0d9a72c1..feaf2dfa153 100644
--- a/src/plugins/qt4projectmanager/wizards/qtwizard.h
+++ b/src/plugins/qt4projectmanager/wizards/qtwizard.h
@@ -128,7 +128,7 @@ public:
     virtual ~BaseQt4ProjectWizardDialog();
 
     int addModulesPage(int id = -1);
-    int addTargetSetupPage(QSet<QString> targets = QSet<QString>(), int id = -1);
+    int addTargetSetupPage(QSet<QString> targets = QSet<QString>(), bool mobile = false, int id = -1);
 
     static QSet<QString> desktopTarget();
 
diff --git a/src/plugins/qt4projectmanager/wizards/targetsetuppage.cpp b/src/plugins/qt4projectmanager/wizards/targetsetuppage.cpp
index 9cbd8a5fb53..be7e9e856d5 100644
--- a/src/plugins/qt4projectmanager/wizards/targetsetuppage.cpp
+++ b/src/plugins/qt4projectmanager/wizards/targetsetuppage.cpp
@@ -30,6 +30,7 @@
 #include "targetsetuppage.h"
 
 #include "qt4project.h"
+#include "qt4projectmanagerconstants.h"
 #include "qt4target.h"
 
 #include <utils/pathchooser.h>
@@ -42,7 +43,8 @@
 using namespace Qt4ProjectManager::Internal;
 
 TargetSetupPage::TargetSetupPage(QWidget *parent) :
-    QWizardPage(parent)
+    QWizardPage(parent),
+    m_preferMobile(false)
 {
     resize(500, 400);
     setTitle(tr("Set up targets for your project"));
@@ -136,18 +138,18 @@ void TargetSetupPage::setImportInfos(const QList<ImportInfo> &infos)
             versionItem->setData(0, Qt::UserRole, pos);
             // Prefer imports to creating new builds, but precheck any
             // Qt that exists (if there is no import with that version)
+            bool shouldCheck = true;
             if (!i.isExistingBuild) {
-                bool haveExistingBuildForQtVersion = false;
                 foreach (const ImportInfo &j, m_infos) {
                     if (j.isExistingBuild && j.version == i.version) {
-                        haveExistingBuildForQtVersion = true;
+                        shouldCheck = false;
                         break;
                     }
                 }
-                versionItem->setCheckState(0, haveExistingBuildForQtVersion ? Qt::Unchecked : Qt::Checked);
-            } else {
-                versionItem->setCheckState(0, Qt::Checked);
             }
+            shouldCheck = shouldCheck && (m_preferMobile == i.version->supportsMobileTarget());
+            shouldCheck = shouldCheck || i.isExistingBuild; // always check imports
+            versionItem->setCheckState(0, shouldCheck ? Qt::Checked : Qt::Unchecked);
 
             // Column 1 (status):
             versionItem->setText(1, i.isExistingBuild ? tr("Import", "Is this an import of an existing build or a new one?") :
@@ -265,6 +267,11 @@ void TargetSetupPage::setShowLocationInformation(bool location)
     m_treeWidget->setColumnCount(location ? 3 : 1);
 }
 
+void TargetSetupPage::setPreferMobile(bool mobile)
+{
+    m_preferMobile = mobile;
+}
+
 QList<TargetSetupPage::ImportInfo>
 TargetSetupPage::importInfosForKnownQtVersions(Qt4ProjectManager::Qt4Project *project)
 {
diff --git a/src/plugins/qt4projectmanager/wizards/targetsetuppage.h b/src/plugins/qt4projectmanager/wizards/targetsetuppage.h
index 3b6da83290c..cec4c2cfa11 100644
--- a/src/plugins/qt4projectmanager/wizards/targetsetuppage.h
+++ b/src/plugins/qt4projectmanager/wizards/targetsetuppage.h
@@ -94,6 +94,7 @@ public:
     void setImportDirectoryBrowsingEnabled(bool browsing);
     void setImportDirectoryBrowsingLocation(const QString &directory);
     void setShowLocationInformation(bool location);
+    void setPreferMobile(bool mobile);
 
     static QList<ImportInfo> importInfosForKnownQtVersions(Qt4ProjectManager::Qt4Project *project);
     static QList<ImportInfo> filterImportInfos(const QSet<QString> &validTargets,
@@ -118,6 +119,7 @@ private:
     QTreeWidget *m_treeWidget;
     Utils::PathChooser *m_directoryChooser;
     QLabel *m_directoryLabel;
+    bool m_preferMobile;
 };
 
 } // namespace Internal
-- 
GitLab