From 8c8e9753f23d97ba529ea9ae1962370a68044636 Mon Sep 17 00:00:00 2001
From: Alessandro Portale <alessandro.portale@nokia.com>
Date: Thu, 7 May 2009 20:31:12 +0200
Subject: [PATCH] EmptyProjectWizard allows us to create an empty project.

---
 .../qt4projectmanager/qt4projectmanager.pro   |  4 +
 .../qt4projectmanagerplugin.cpp               |  3 +
 .../qt4projectmanagerplugin.h                 |  1 +
 .../wizards/emptyprojectwizard.cpp            | 69 ++++++++++++++++
 .../wizards/emptyprojectwizard.h              | 57 +++++++++++++
 .../wizards/emptyprojectwizarddialog.cpp      | 80 +++++++++++++++++++
 .../wizards/emptyprojectwizarddialog.h        | 69 ++++++++++++++++
 .../wizards/qtprojectparameters.cpp           |  2 +
 .../wizards/qtprojectparameters.h             |  2 +-
 9 files changed, 286 insertions(+), 1 deletion(-)
 create mode 100644 src/plugins/qt4projectmanager/wizards/emptyprojectwizard.cpp
 create mode 100644 src/plugins/qt4projectmanager/wizards/emptyprojectwizard.h
 create mode 100644 src/plugins/qt4projectmanager/wizards/emptyprojectwizarddialog.cpp
 create mode 100644 src/plugins/qt4projectmanager/wizards/emptyprojectwizarddialog.h

diff --git a/src/plugins/qt4projectmanager/qt4projectmanager.pro b/src/plugins/qt4projectmanager/qt4projectmanager.pro
index 7df7e44bded..c5e12b5efac 100644
--- a/src/plugins/qt4projectmanager/qt4projectmanager.pro
+++ b/src/plugins/qt4projectmanager/qt4projectmanager.pro
@@ -20,6 +20,8 @@ HEADERS = qt4projectmanagerplugin.h \
     wizards/librarywizard.h \
     wizards/librarywizarddialog.h \
     wizards/guiappwizarddialog.h \
+    wizards/emptyprojectwizard.h \
+    wizards/emptyprojectwizarddialog.h \
     wizards/modulespage.h \
     wizards/filespage.h \
     wizards/qtwizard.h \
@@ -51,6 +53,8 @@ SOURCES = qt4projectmanagerplugin.cpp \
     wizards/librarywizard.cpp \
     wizards/librarywizarddialog.cpp \
     wizards/guiappwizarddialog.cpp \
+    wizards/emptyprojectwizard.cpp \
+    wizards/emptyprojectwizarddialog.cpp \
     wizards/modulespage.cpp \
     wizards/filespage.cpp \
     wizards/qtwizard.cpp \
diff --git a/src/plugins/qt4projectmanager/qt4projectmanagerplugin.cpp b/src/plugins/qt4projectmanager/qt4projectmanagerplugin.cpp
index a199b43c731..8fcf5011ed4 100644
--- a/src/plugins/qt4projectmanager/qt4projectmanagerplugin.cpp
+++ b/src/plugins/qt4projectmanager/qt4projectmanagerplugin.cpp
@@ -33,6 +33,7 @@
 #include "wizards/consoleappwizard.h"
 #include "wizards/guiappwizard.h"
 #include "wizards/librarywizard.h"
+#include "wizards/emptyprojectwizard.h"
 #include "profileeditorfactory.h"
 #include "qt4projectmanagerconstants.h"
 #include "qt4project.h"
@@ -115,6 +116,8 @@ bool Qt4ProjectManagerPlugin::initialize(const QStringList &arguments, QString *
     m_proFileEditorFactory = new ProFileEditorFactory(m_qt4ProjectManager, editorHandler);
     addObject(m_proFileEditorFactory);
 
+    addAutoReleasedObject(new EmptyProjectWizard);
+
     GuiAppWizard *guiWizard = new GuiAppWizard;
     addAutoReleasedObject(guiWizard);
 
diff --git a/src/plugins/qt4projectmanager/qt4projectmanagerplugin.h b/src/plugins/qt4projectmanager/qt4projectmanagerplugin.h
index febde6bb135..7b894b369d5 100644
--- a/src/plugins/qt4projectmanager/qt4projectmanagerplugin.h
+++ b/src/plugins/qt4projectmanager/qt4projectmanagerplugin.h
@@ -43,6 +43,7 @@ namespace Internal {
 class ProFileEditorFactory;
 class ConsoleAppWizard;
 class GuiAppWizard;
+class EmptyProjectWizard;
 class QMakeStepFactory;
 class MakeStepFactory;
 class GccParserFactory;
diff --git a/src/plugins/qt4projectmanager/wizards/emptyprojectwizard.cpp b/src/plugins/qt4projectmanager/wizards/emptyprojectwizard.cpp
new file mode 100644
index 00000000000..c7cdc2abdeb
--- /dev/null
+++ b/src/plugins/qt4projectmanager/wizards/emptyprojectwizard.cpp
@@ -0,0 +1,69 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact:  Qt Software Information (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 qt-sales@nokia.com.
+**
+**************************************************************************/
+
+#include "emptyprojectwizard.h"
+
+#include "emptyprojectwizarddialog.h"
+
+#include <utils/pathchooser.h>
+
+namespace Qt4ProjectManager {
+namespace Internal {
+
+EmptyProjectWizard::EmptyProjectWizard()
+  : QtWizard(tr("Empty Qt4 Project"),
+             tr("Creates an empty Qt project."),
+             QIcon(":/wizards/images/gui.png"))
+{
+}
+
+QWizard *EmptyProjectWizard::createWizardDialog(QWidget *parent,
+                                              const QString &defaultPath,
+                                              const WizardPageList &extensionPages) const
+{
+    EmptyProjectWizardDialog *dialog = new EmptyProjectWizardDialog(name(), icon(), extensionPages, parent);
+    dialog->setPath(defaultPath.isEmpty() ? Core::Utils::PathChooser::homePath() : defaultPath);
+    return dialog;
+}
+
+Core::GeneratedFiles
+        EmptyProjectWizard::generateFiles(const QWizard *w,
+                                        QString * /*errorMessage*/) const
+{
+    const EmptyProjectWizardDialog *wizard = qobject_cast< const EmptyProjectWizardDialog *>(w);
+    const QtProjectParameters params = wizard->parameters();
+    const QString projectPath = params.projectPath();
+    const QString profileName = Core::BaseFileWizard::buildFileName(projectPath, params.name, profileSuffix());
+
+    Core::GeneratedFile profile(profileName);
+    return Core::GeneratedFiles() << profile;
+}
+
+} // namespace Internal
+} // namespace Qt4ProjectManager
diff --git a/src/plugins/qt4projectmanager/wizards/emptyprojectwizard.h b/src/plugins/qt4projectmanager/wizards/emptyprojectwizard.h
new file mode 100644
index 00000000000..289fe91af61
--- /dev/null
+++ b/src/plugins/qt4projectmanager/wizards/emptyprojectwizard.h
@@ -0,0 +1,57 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact:  Qt Software Information (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 qt-sales@nokia.com.
+**
+**************************************************************************/
+
+#ifndef EMPTYPROJECTWIZARD_H
+#define EMPTYPROJECTWIZARD_H
+
+#include "qtwizard.h"
+
+namespace Qt4ProjectManager {
+namespace Internal {
+
+class EmptyProjectWizard : public QtWizard
+{
+    Q_OBJECT
+
+public:
+    EmptyProjectWizard();
+
+protected:
+    virtual QWizard *createWizardDialog(QWidget *parent,
+                                        const QString &defaultPath,
+                                        const WizardPageList &extensionPages) const;
+
+    virtual Core::GeneratedFiles generateFiles(const QWizard *w,
+                                               QString *errorMessage) const;
+};
+
+} // namespace Internal
+} // namespace Qt4ProjectManager
+
+#endif // EMPTYPROJECTWIZARD_H
diff --git a/src/plugins/qt4projectmanager/wizards/emptyprojectwizarddialog.cpp b/src/plugins/qt4projectmanager/wizards/emptyprojectwizarddialog.cpp
new file mode 100644
index 00000000000..685973adc8b
--- /dev/null
+++ b/src/plugins/qt4projectmanager/wizards/emptyprojectwizarddialog.cpp
@@ -0,0 +1,80 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact:  Qt Software Information (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 qt-sales@nokia.com.
+**
+**************************************************************************/
+
+#include "emptyprojectwizarddialog.h"
+
+#include "emptyprojectwizard.h"
+
+#include <utils/projectintropage.h>
+
+namespace Qt4ProjectManager {
+namespace Internal {
+
+EmptyProjectWizardDialog::EmptyProjectWizardDialog(const QString &templateName,
+                                               const QIcon &icon,
+                                               const QList<QWizardPage*> &extensionPages,
+                                               QWidget *parent) :
+    QWizard(parent),
+    m_introPage(new Core::Utils::ProjectIntroPage)
+{
+    setWindowIcon(icon);
+    setWindowTitle(templateName);
+    Core::BaseFileWizard::setupWizard(this);
+
+    m_introPage->setDescription(tr("This wizard generates an empty Qt4 project. "
+                          "Add files to it later on by using the other wizards. "
+                          "You can press 'Finish' at any point in time."));
+
+    addPage(m_introPage);
+
+    foreach (QWizardPage *p, extensionPages)
+        addPage(p);
+}
+
+void EmptyProjectWizardDialog::setPath(const QString &path)
+{
+    m_introPage->setPath(path);
+}
+
+void  EmptyProjectWizardDialog::setName(const QString &name)
+{
+    m_introPage->setName(name);
+}
+
+QtProjectParameters EmptyProjectWizardDialog::parameters() const
+{
+    QtProjectParameters rc;
+    rc.type = QtProjectParameters::EmptyProject;
+    rc.name = m_introPage->name();
+    rc.path = m_introPage->path();
+    return rc;
+}
+
+} // namespace Internal
+} // namespace Qt4ProjectManager
diff --git a/src/plugins/qt4projectmanager/wizards/emptyprojectwizarddialog.h b/src/plugins/qt4projectmanager/wizards/emptyprojectwizarddialog.h
new file mode 100644
index 00000000000..8e6f38a408e
--- /dev/null
+++ b/src/plugins/qt4projectmanager/wizards/emptyprojectwizarddialog.h
@@ -0,0 +1,69 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact:  Qt Software Information (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 qt-sales@nokia.com.
+**
+**************************************************************************/
+
+#ifndef EMPTYPROJECTWIZARDDIALOG_H
+#define EMPTYPROJECTWIZARDDIALOG_H
+
+#include <QtGui/QWizard>
+
+namespace Core {
+    namespace Utils {
+        class ProjectIntroPage;
+    }
+}
+
+namespace Qt4ProjectManager {
+namespace Internal {
+
+struct QtProjectParameters;
+
+class EmptyProjectWizardDialog : public QWizard
+{
+    Q_OBJECT
+
+public:
+    explicit EmptyProjectWizardDialog(const QString &templateName,
+                                    const QIcon &icon,
+                                    const QList<QWizardPage*> &extensionPages,
+                                    QWidget *parent = 0);
+
+    QtProjectParameters parameters() const;
+
+public slots:
+    void setPath(const QString &path);
+    void setName(const QString &name);
+
+private:
+    Core::Utils::ProjectIntroPage *m_introPage;
+};
+
+} // namespace Internal
+} // namespace Qt4ProjectManager
+
+#endif // EMPTYPROJECTWIZARDDIALOG_H
diff --git a/src/plugins/qt4projectmanager/wizards/qtprojectparameters.cpp b/src/plugins/qt4projectmanager/wizards/qtprojectparameters.cpp
index 11c0d9d5e7c..965da165228 100644
--- a/src/plugins/qt4projectmanager/wizards/qtprojectparameters.cpp
+++ b/src/plugins/qt4projectmanager/wizards/qtprojectparameters.cpp
@@ -77,6 +77,8 @@ void QtProjectParameters::writeProFile(QTextStream &str) const
     case Qt4Plugin:
         str << "TEMPLATE = lib\nCONFIG += plugin\n";
         break;
+    default:
+        break;
     }
 
     if (!targetDirectory.isEmpty())
diff --git a/src/plugins/qt4projectmanager/wizards/qtprojectparameters.h b/src/plugins/qt4projectmanager/wizards/qtprojectparameters.h
index b992591d715..0f07071149a 100644
--- a/src/plugins/qt4projectmanager/wizards/qtprojectparameters.h
+++ b/src/plugins/qt4projectmanager/wizards/qtprojectparameters.h
@@ -47,7 +47,7 @@ QString createMacro(const QString &name, const QString &suffix);
 // write a .pro-file section.
 
 struct QtProjectParameters {
-    enum Type { ConsoleApp, GuiApp, StaticLibrary, SharedLibrary, Qt4Plugin };
+    enum Type { ConsoleApp, GuiApp, StaticLibrary, SharedLibrary, Qt4Plugin, EmptyProject };
 
     QtProjectParameters();
     // Return project path as "path/name"
-- 
GitLab