OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qt4projectmanager / wizards / consoleappwizard.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 "consoleappwizard.h"
35
36 #include "consoleappwizarddialog.h"
37 #include "qt4projectmanagerconstants.h"
38
39 #include <cpptools/abstracteditorsupport.h>
40
41 #include <QtGui/QIcon>
42
43 #include <QtCore/QTextStream>
44
45 static const char *mainCppC =
46 "#include <QtCore/QCoreApplication>\n\n"
47 "int main(int argc, char *argv[])\n"
48 "{\n"
49 "    QCoreApplication a(argc, argv);\n\n"
50 "    return a.exec();\n"
51 "}\n";
52
53 static const char *mainSourceFileC = "main";
54
55 namespace Qt4ProjectManager {
56 namespace Internal {
57
58 ConsoleAppWizard::ConsoleAppWizard()
59   : QtWizard(QLatin1String("E.Qt4Core"),
60              QLatin1String(Constants::QT_APP_WIZARD_CATEGORY),
61              QLatin1String(Constants::QT_APP_WIZARD_TR_SCOPE),
62              QLatin1String(Constants::QT_APP_WIZARD_TR_CATEGORY),
63              tr("Qt Console Application"),
64              tr("Creates a project containing a single main.cpp file with a stub implementation.\n\n"
65                 "Preselects a desktop Qt for building the application if available."),
66              QIcon(QLatin1String(":/wizards/images/console.png")))
67 {
68 }
69
70 QWizard *ConsoleAppWizard::createWizardDialog(QWidget *parent,
71                                               const QString &defaultPath,
72                                               const WizardPageList &extensionPages) const
73 {
74     ConsoleAppWizardDialog *dialog = new ConsoleAppWizardDialog(displayName(), icon(), extensionPages,
75                                                                 showModulesPageForApplications(), parent);
76     dialog->setPath(defaultPath);
77     dialog->setProjectName(ConsoleAppWizardDialog::uniqueProjectName(defaultPath));
78     return dialog;
79 }
80
81 Core::GeneratedFiles
82         ConsoleAppWizard::generateFiles(const QWizard *w,
83                                         QString * /*errorMessage*/) const
84 {
85     const ConsoleAppWizardDialog *wizard = qobject_cast< const ConsoleAppWizardDialog *>(w);
86     const QtProjectParameters params = wizard->parameters();
87     const QString projectPath = params.projectPath();
88
89     // Create files: Source
90
91     const QString sourceFileName = Core::BaseFileWizard::buildFileName(projectPath, QLatin1String(mainSourceFileC), sourceSuffix());
92     Core::GeneratedFile source(sourceFileName);
93     source.setContents(CppTools::AbstractEditorSupport::licenseTemplate(sourceFileName) + QLatin1String(mainCppC));
94     source.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
95     // Create files: Profile
96     const QString profileName = Core::BaseFileWizard::buildFileName(projectPath, params.fileName, profileSuffix());
97
98     Core::GeneratedFile profile(profileName);
99     profile.setAttributes(Core::GeneratedFile::OpenProjectAttribute);
100     QString contents;
101     {
102         QTextStream proStr(&contents);
103         QtProjectParameters::writeProFileHeader(proStr);
104         params.writeProFile(proStr);
105         proStr << "\n\nSOURCES += " << QFileInfo(sourceFileName).fileName() << '\n';
106     }
107     profile.setContents(contents);
108     return Core::GeneratedFiles() <<  source << profile;
109 }
110
111 } // namespace Internal
112 } // namespace Qt4ProjectManager