1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
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
16 ** GNU Lesser General Public License Usage
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.
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.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "consoleappwizard.h"
36 #include "consoleappwizarddialog.h"
37 #include "qt4projectmanagerconstants.h"
39 #include <cpptools/abstracteditorsupport.h>
41 #include <QtGui/QIcon>
43 #include <QtCore/QTextStream>
45 static const char *mainCppC =
46 "#include <QtCore/QCoreApplication>\n\n"
47 "int main(int argc, char *argv[])\n"
49 " QCoreApplication a(argc, argv);\n\n"
53 static const char *mainSourceFileC = "main";
55 namespace Qt4ProjectManager {
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")))
70 QWizard *ConsoleAppWizard::createWizardDialog(QWidget *parent,
71 const QString &defaultPath,
72 const WizardPageList &extensionPages) const
74 ConsoleAppWizardDialog *dialog = new ConsoleAppWizardDialog(displayName(), icon(), extensionPages,
75 showModulesPageForApplications(), parent);
76 dialog->setPath(defaultPath);
77 dialog->setProjectName(ConsoleAppWizardDialog::uniqueProjectName(defaultPath));
82 ConsoleAppWizard::generateFiles(const QWizard *w,
83 QString * /*errorMessage*/) const
85 const ConsoleAppWizardDialog *wizard = qobject_cast< const ConsoleAppWizardDialog *>(w);
86 const QtProjectParameters params = wizard->parameters();
87 const QString projectPath = params.projectPath();
89 // Create files: Source
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());
98 Core::GeneratedFile profile(profileName);
99 profile.setAttributes(Core::GeneratedFile::OpenProjectAttribute);
102 QTextStream proStr(&contents);
103 QtProjectParameters::writeProFileHeader(proStr);
104 params.writeProFile(proStr);
105 proStr << "\n\nSOURCES += " << QFileInfo(sourceFileName).fileName() << '\n';
107 profile.setContents(contents);
108 return Core::GeneratedFiles() << source << profile;
111 } // namespace Internal
112 } // namespace Qt4ProjectManager