2009-03-20 14:57:12 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2010-03-05 11:25:49 +01:00
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
2009-03-20 14:57:12 +01:00
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2009-03-20 14:57:12 +01:00
|
|
|
**
|
|
|
|
|
** 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
|
2009-08-14 09:30:56 +02:00
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
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>
|
2009-11-27 10:33:24 +01:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2010-04-16 15:55:32 +02:00
|
|
|
#include <projectexplorer/customwizard/customwizard.h>
|
2009-03-12 18:31:50 +01:00
|
|
|
|
2009-03-19 16:33:44 +01:00
|
|
|
#include <utils/filewizardpage.h>
|
2009-03-12 17:53:25 +01:00
|
|
|
|
2010-03-18 10:59:06 +01:00
|
|
|
#include <QtGui/QIcon>
|
|
|
|
|
|
2009-03-12 18:31:50 +01:00
|
|
|
#include <QtCore/QDir>
|
2009-11-27 10:33:24 +01:00
|
|
|
#include <QtCore/QFileInfo>
|
2009-03-12 17:53:25 +01:00
|
|
|
#include <QtCore/QtDebug>
|
2009-11-27 10:33:24 +01:00
|
|
|
#include <QtCore/QCoreApplication>
|
2009-03-13 15:12:54 +01:00
|
|
|
|
2009-03-12 17:53:25 +01:00
|
|
|
using namespace GenericProjectManager::Internal;
|
2009-10-05 11:06:05 +02:00
|
|
|
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
|
|
|
{
|
2010-02-18 16:02:28 +01:00
|
|
|
setWindowTitle(tr("Import Existing Project"));
|
2009-03-13 15:12:54 +01:00
|
|
|
|
|
|
|
|
// first page
|
2009-03-19 16:33:44 +01:00
|
|
|
m_firstPage = new FileWizardPage;
|
2010-02-18 16:02:28 +01:00
|
|
|
m_firstPage->setTitle(tr("Project Name and Location"));
|
2010-01-07 18:17:24 +01:00
|
|
|
m_firstPage->setFileNameLabel(tr("Project name:"));
|
2009-03-19 16:33:44 +01:00
|
|
|
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
|
2009-03-19 16:33:44 +01:00
|
|
|
{
|
|
|
|
|
return m_firstPage->path();
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-07 16:39:51 +02:00
|
|
|
void GenericProjectWizardDialog::setPath(const QString &path)
|
|
|
|
|
{
|
|
|
|
|
m_firstPage->setPath(path);
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-19 16:33:44 +01:00
|
|
|
QString GenericProjectWizardDialog::projectName() const
|
|
|
|
|
{
|
2010-01-07 18:17:24 +01:00
|
|
|
return m_firstPage->fileName();
|
2009-03-19 16:33:44 +01:00
|
|
|
}
|
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()
|
|
|
|
|
{
|
2010-02-15 11:07:45 +01:00
|
|
|
Core::BaseFileWizardParameters parameters(ProjectWizard);
|
|
|
|
|
parameters.setIcon(QIcon(QLatin1String(":/wizards/images/console.png")));
|
2010-02-18 16:02:28 +01:00
|
|
|
parameters.setDisplayName(tr("Import Existing Project"));
|
2009-11-27 10:33:24 +01:00
|
|
|
parameters.setId(QLatin1String("Z.Makefile"));
|
2009-04-08 16:29:18 +02:00
|
|
|
parameters.setDescription(tr("Creates a generic project, supporting any build system."));
|
2009-11-27 10:33:24 +01:00
|
|
|
parameters.setCategory(QLatin1String(ProjectExplorer::Constants::PROJECT_WIZARD_CATEGORY));
|
2010-01-07 18:17:24 +01:00
|
|
|
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);
|
|
|
|
|
|
2009-04-07 16:39:51 +02:00
|
|
|
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"))
|
2010-01-29 21:33:57 +01:00
|
|
|
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
|
|
|
|
|
{
|
2009-04-07 16:39:51 +02:00
|
|
|
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);
|
2009-03-19 16:33:44 +01:00
|
|
|
const QString projectName = wizard->projectName();
|
2009-03-16 12:11:52 +01:00
|
|
|
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 QRegExp &rx, headerTy.globPatterns())
|
|
|
|
|
nameFilters.append(rx.pattern());
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2009-03-16 12:11:52 +01:00
|
|
|
Core::GeneratedFile generatedCreatorFile(creatorFileName);
|
|
|
|
|
generatedCreatorFile.setContents(QLatin1String("[General]\n"));
|
2010-04-16 15:55:32 +02:00
|
|
|
generatedCreatorFile.setAttributes(Core::GeneratedFile::OpenProjectAttribute);
|
2009-03-12 18:31:50 +01:00
|
|
|
|
2009-03-16 12:11:52 +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;
|
2009-03-16 12:11:52 +01:00
|
|
|
files.append(generatedFilesFile);
|
|
|
|
|
files.append(generatedIncludesFile);
|
|
|
|
|
files.append(generatedConfigFile);
|
|
|
|
|
files.append(generatedCreatorFile);
|
2009-03-12 18:31:50 +01:00
|
|
|
|
|
|
|
|
return files;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-18 16:10:56 +01:00
|
|
|
bool GenericProjectWizard::postGenerateFiles(const QWizard *w, const Core::GeneratedFiles &l, QString *errorMessage)
|
2009-03-12 18:31:50 +01:00
|
|
|
{
|
2010-02-18 16:10:56 +01:00
|
|
|
Q_UNUSED(w);
|
2010-04-16 15:55:32 +02:00
|
|
|
return ProjectExplorer::CustomProjectWizard::postGenerateOpen(l, errorMessage);
|
2009-03-12 17:53:25 +01:00
|
|
|
}
|