Files
qt-creator/src/plugins/qt4projectmanager/wizards/consoleappwizard.cpp

113 lines
4.4 KiB
C++
Raw Normal View History

/**************************************************************************
2008-12-02 12:01:29 +01:00
**
** This file is part of Qt Creator
**
2011-01-11 16:28:15 +01:00
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
2008-12-02 12:01:29 +01:00
**
2011-04-13 08:42:33 +02:00
** Contact: Nokia Corporation (info@qt.nokia.com)
2008-12-02 12:01:29 +01:00
**
**
** GNU Lesser General Public License Usage
**
2011-04-13 08:42:33 +02:00
** 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.
**
2010-12-17 16:01:08 +01:00
** In addition, as a special exception, Nokia gives you certain additional
2011-04-13 08:42:33 +02:00
** rights. These rights are described in the Nokia Qt LGPL Exception
2010-12-17 16:01:08 +01:00
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
2011-04-13 08:42:33 +02:00
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
2010-12-17 16:01:08 +01:00
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
2008-12-02 12:01:29 +01:00
**
**************************************************************************/
2008-12-02 16:19:05 +01:00
2008-12-02 12:01:29 +01:00
#include "consoleappwizard.h"
2008-12-02 16:19:05 +01:00
2008-12-02 12:01:29 +01:00
#include "consoleappwizarddialog.h"
#include "qt4projectmanagerconstants.h"
#include <projectexplorer/projectexplorerconstants.h>
#include <cpptools/abstracteditorsupport.h>
2008-12-02 12:01:29 +01:00
#include <QtGui/QIcon>
2011-01-20 14:03:07 +01:00
#include <QtCore/QFileInfo>
2008-12-02 12:01:29 +01:00
#include <QtCore/QTextStream>
static const char *mainCppC =
"#include <QtCore/QCoreApplication>\n\n"
"int main(int argc, char *argv[])\n"
"{\n"
" QCoreApplication a(argc, argv);\n\n"
" return a.exec();\n"
"}\n";
2011-04-19 15:42:14 +02:00
static const char mainSourceFileC[] = "main";
2008-12-02 12:01:29 +01:00
namespace Qt4ProjectManager {
namespace Internal {
ConsoleAppWizard::ConsoleAppWizard()
2010-01-13 18:44:15 +01:00
: QtWizard(QLatin1String("E.Qt4Core"),
QLatin1String(ProjectExplorer::Constants::PROJECT_WIZARD_CATEGORY),
QLatin1String(ProjectExplorer::Constants::PROJECT_WIZARD_TR_SCOPE),
QLatin1String(ProjectExplorer::Constants::PROJECT_WIZARD_TR_CATEGORY),
2010-01-13 18:44:15 +01:00
tr("Qt Console Application"),
tr("Creates a project containing a single main.cpp file with a stub implementation.\n\n"
"Preselects a desktop Qt for building the application if available."),
QIcon(QLatin1String(":/wizards/images/console.png")))
2008-12-02 12:01:29 +01:00
{
}
QWizard *ConsoleAppWizard::createWizardDialog(QWidget *parent,
const QString &defaultPath,
const WizardPageList &extensionPages) const
{
ConsoleAppWizardDialog *dialog = new ConsoleAppWizardDialog(displayName(), icon(), extensionPages,
showModulesPageForApplications(), parent);
dialog->setPath(defaultPath);
dialog->setProjectName(ConsoleAppWizardDialog::uniqueProjectName(defaultPath));
2008-12-02 12:01:29 +01:00
return dialog;
}
Core::GeneratedFiles
ConsoleAppWizard::generateFiles(const QWizard *w,
QString * /*errorMessage*/) const
{
const ConsoleAppWizardDialog *wizard = qobject_cast< const ConsoleAppWizardDialog *>(w);
const QtProjectParameters params = wizard->parameters();
const QString projectPath = params.projectPath();
// Create files: Source
const QString sourceFileName = Core::BaseFileWizard::buildFileName(projectPath, QLatin1String(mainSourceFileC), sourceSuffix());
Core::GeneratedFile source(sourceFileName);
source.setContents(CppTools::AbstractEditorSupport::licenseTemplate(sourceFileName) + QLatin1String(mainCppC));
source.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
2008-12-02 12:01:29 +01:00
// Create files: Profile
const QString profileName = Core::BaseFileWizard::buildFileName(projectPath, params.fileName, profileSuffix());
2008-12-02 12:01:29 +01:00
Core::GeneratedFile profile(profileName);
profile.setAttributes(Core::GeneratedFile::OpenProjectAttribute);
2008-12-02 12:01:29 +01:00
QString contents;
{
QTextStream proStr(&contents);
QtProjectParameters::writeProFileHeader(proStr);
params.writeProFile(proStr);
proStr << "\n\nSOURCES += " << QFileInfo(sourceFileName).fileName() << '\n';
}
profile.setContents(contents);
return Core::GeneratedFiles() << source << profile;
}
2008-12-02 16:19:05 +01:00
} // namespace Internal
} // namespace Qt4ProjectManager