Files
qt-creator/src/plugins/genericprojectmanager/genericprojectwizard.cpp

242 lines
8.5 KiB
C++
Raw Normal View History

2009-03-20 14:57:12 +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).
2009-03-20 14:57:12 +01:00
**
2011-04-13 08:42:33 +02:00
** Contact: Nokia Corporation (info@qt.nokia.com)
2009-03-20 14:57:12 +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.
2009-03-20 14:57:12 +01:00
**
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.
2009-03-20 14:57:12 +01:00
**
**************************************************************************/
2009-03-12 17:53:25 +01:00
#include "genericprojectwizard.h"
2009-03-13 15:12:54 +01:00
#include <coreplugin/icore.h>
#include <coreplugin/mimedatabase.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/customwizard/customwizard.h>
2009-03-12 18:31:50 +01:00
#include <utils/filewizardpage.h>
2009-03-12 17:53:25 +01:00
#include <QtGui/QIcon>
2010-05-14 11:03:30 +02:00
#include <QtGui/QApplication>
#include <QtGui/QStyle>
#include <QtGui/QPainter>
#include <QtGui/QPixmap>
2009-03-12 18:31:50 +01:00
#include <QtCore/QDir>
#include <QtCore/QFileInfo>
2009-03-12 17:53:25 +01:00
#include <QtCore/QtDebug>
#include <QtCore/QCoreApplication>
2009-03-13 15:12:54 +01:00
2009-03-12 17:53:25 +01:00
using namespace GenericProjectManager::Internal;
using namespace Utils;
2009-03-12 17:53:25 +01:00
2009-03-13 15:12:54 +01:00
//////////////////////////////////////////////////////////////////////////////
// GenericProjectWizardDialog
//////////////////////////////////////////////////////////////////////////////
GenericProjectWizardDialog::GenericProjectWizardDialog(QWidget *parent)
2010-03-31 14:48:08 +02:00
: Utils::Wizard(parent)
2009-03-12 17:53:25 +01:00
{
setWindowTitle(tr("Import Existing Project"));
2009-03-13 15:12:54 +01:00
// first page
m_firstPage = new FileWizardPage;
m_firstPage->setTitle(tr("Project Name and Location"));
m_firstPage->setFileNameLabel(tr("Project name:"));
m_firstPage->setPathLabel(tr("Location:"));
2009-03-13 15:12:54 +01:00
2010-03-31 14:48:08 +02:00
const int firstPageId = addPage(m_firstPage);
wizardProgress()->item(firstPageId)->setTitle(tr("Location"));
2009-03-12 17:53:25 +01:00
}
2009-03-13 15:12:54 +01:00
GenericProjectWizardDialog::~GenericProjectWizardDialog()
{ }
QString GenericProjectWizardDialog::path() const
{
return m_firstPage->path();
}
void GenericProjectWizardDialog::setPath(const QString &path)
{
m_firstPage->setPath(path);
}
QString GenericProjectWizardDialog::projectName() const
{
return m_firstPage->fileName();
}
2009-03-13 15:12:54 +01:00
GenericProjectWizard::GenericProjectWizard()
: Core::BaseFileWizard(parameters())
{ }
GenericProjectWizard::~GenericProjectWizard()
{ }
2009-03-12 17:53:25 +01:00
Core::BaseFileWizardParameters GenericProjectWizard::parameters()
{
Core::BaseFileWizardParameters parameters(ProjectWizard);
2010-05-14 11:03:30 +02:00
// TODO do something about the ugliness of standard icons in sizes different than 16, 32, 64, 128
{
QPixmap icon(22, 22);
icon.fill(Qt::transparent);
QPainter p(&icon);
p.drawPixmap(3, 3, 16, 16, qApp->style()->standardIcon(QStyle::SP_DirIcon).pixmap(16));
parameters.setIcon(icon);
}
parameters.setDisplayName(tr("Import Existing Project"));
parameters.setId(QLatin1String("Z.Makefile"));
parameters.setDescription(tr("Imports existing projects that do not use qmake or CMake. "
"This allows you to use Qt Creator as a code editor."));
parameters.setCategory(QLatin1String(ProjectExplorer::Constants::PROJECT_WIZARD_CATEGORY));
parameters.setDisplayCategory(QCoreApplication::translate("ProjectExplorer", ProjectExplorer::Constants::PROJECT_WIZARD_TR_CATEGORY));
2009-03-12 17:53:25 +01:00
return parameters;
}
QWizard *GenericProjectWizard::createWizardDialog(QWidget *parent,
const QString &defaultPath,
const WizardPageList &extensionPages) const
{
2009-03-13 15:12:54 +01:00
GenericProjectWizardDialog *wizard = new GenericProjectWizardDialog(parent);
2009-03-12 17:53:25 +01:00
setupWizard(wizard);
wizard->setPath(defaultPath);
2009-03-13 15:12:54 +01:00
foreach (QWizardPage *p, extensionPages)
2010-03-31 14:48:08 +02:00
BaseFileWizard::applyExtensionPageShortTitle(wizard, wizard->addPage(p));
2009-03-12 17:53:25 +01:00
2009-03-13 15:12:54 +01:00
return wizard;
}
2009-03-12 17:53:25 +01:00
2009-03-13 15:12:54 +01:00
void GenericProjectWizard::getFileList(const QDir &dir, const QString &projectRoot,
const QStringList &suffixes,
QStringList *files, QStringList *paths) const
{
const QFileInfoList fileInfoList = dir.entryInfoList(QDir::Files |
QDir::Dirs |
QDir::NoDotAndDotDot |
QDir::NoSymLinks);
2009-03-12 17:53:25 +01:00
2009-03-13 15:12:54 +01:00
foreach (const QFileInfo &fileInfo, fileInfoList) {
QString filePath = fileInfo.absoluteFilePath();
filePath = filePath.mid(projectRoot.length() + 1);
2009-03-12 17:53:25 +01:00
2009-03-13 15:12:54 +01:00
if (fileInfo.isDir() && isValidDir(fileInfo)) {
getFileList(QDir(fileInfo.absoluteFilePath()), projectRoot,
suffixes, files, paths);
2009-03-12 17:53:25 +01:00
2009-03-13 15:12:54 +01:00
if (! paths->contains(filePath))
paths->append(filePath);
}
else if (suffixes.contains(fileInfo.suffix()))
files->append(filePath);
}
}
bool GenericProjectWizard::isValidDir(const QFileInfo &fileInfo) const
{
const QString fileName = fileInfo.fileName();
const QString suffix = fileInfo.suffix();
if (fileName.startsWith(QLatin1Char('.')))
return false;
else if (fileName == QLatin1String("CVS"))
return false;
2009-03-13 15:12:54 +01:00
// ### user include/exclude
return true;
2009-03-12 17:53:25 +01:00
}
Core::GeneratedFiles GenericProjectWizard::generateFiles(const QWizard *w,
QString *errorMessage) const
{
Q_UNUSED(errorMessage)
2009-03-13 15:12:54 +01:00
const GenericProjectWizardDialog *wizard = qobject_cast<const GenericProjectWizardDialog *>(w);
const QString projectPath = wizard->path();
const QDir dir(projectPath);
const QString projectName = wizard->projectName();
const QString creatorFileName = QFileInfo(dir, projectName + QLatin1String(".creator")).absoluteFilePath();
const QString filesFileName = QFileInfo(dir, projectName + QLatin1String(".files")).absoluteFilePath();
const QString includesFileName = QFileInfo(dir, projectName + QLatin1String(".includes")).absoluteFilePath();
const QString configFileName = QFileInfo(dir, projectName + QLatin1String(".config")).absoluteFilePath();
2009-03-13 15:12:54 +01:00
Core::ICore *core = Core::ICore::instance();
Core::MimeDatabase *mimeDatabase = core->mimeDatabase();
const QStringList suffixes = mimeDatabase->suffixes();
2009-03-12 18:31:50 +01:00
2009-03-13 15:12:54 +01:00
QStringList sources, paths;
getFileList(dir, projectPath, suffixes, &sources, &paths);
Core::MimeType headerTy = mimeDatabase->findByType(QLatin1String("text/x-chdr"));
QStringList nameFilters;
foreach (const Core::MimeGlobPattern &gp, headerTy.globPatterns())
nameFilters.append(gp.regExp().pattern());
2009-03-13 15:12:54 +01:00
QStringList includePaths;
foreach (const QString &path, paths) {
QFileInfo fileInfo(dir, path);
QDir thisDir(fileInfo.absoluteFilePath());
if (! thisDir.entryList(nameFilters, QDir::Files).isEmpty())
includePaths.append(path);
}
2009-03-12 18:31:50 +01:00
Core::GeneratedFile generatedCreatorFile(creatorFileName);
generatedCreatorFile.setContents(QLatin1String("[General]\n"));
generatedCreatorFile.setAttributes(Core::GeneratedFile::OpenProjectAttribute);
2009-03-12 18:31:50 +01:00
Core::GeneratedFile generatedFilesFile(filesFileName);
generatedFilesFile.setContents(sources.join(QLatin1String("\n")));
Core::GeneratedFile generatedIncludesFile(includesFileName);
generatedIncludesFile.setContents(includePaths.join(QLatin1String("\n")));
Core::GeneratedFile generatedConfigFile(configFileName);
generatedConfigFile.setContents(QLatin1String("// ADD PREDEFINED MACROS HERE!\n"));
2009-03-12 17:53:25 +01:00
2009-03-12 18:31:50 +01:00
Core::GeneratedFiles files;
files.append(generatedFilesFile);
files.append(generatedIncludesFile);
files.append(generatedConfigFile);
files.append(generatedCreatorFile);
2009-03-12 18:31:50 +01:00
return files;
}
bool GenericProjectWizard::postGenerateFiles(const QWizard *w, const Core::GeneratedFiles &l, QString *errorMessage)
2009-03-12 18:31:50 +01:00
{
Q_UNUSED(w);
return ProjectExplorer::CustomProjectWizard::postGenerateOpen(l, errorMessage);
2009-03-12 17:53:25 +01:00
}