2009-03-12 17:53:25 +01:00
|
|
|
#include "genericprojectwizard.h"
|
2009-03-12 18:31:50 +01:00
|
|
|
#include <projectexplorer/projectexplorer.h>
|
|
|
|
|
|
2009-03-12 17:53:25 +01:00
|
|
|
#include <utils/pathchooser.h>
|
|
|
|
|
|
|
|
|
|
#include <QtGui/QWizard>
|
|
|
|
|
#include <QtGui/QFormLayout>
|
2009-03-12 18:31:50 +01:00
|
|
|
#include <QtCore/QDir>
|
2009-03-12 17:53:25 +01:00
|
|
|
#include <QtCore/QtDebug>
|
|
|
|
|
|
|
|
|
|
using namespace GenericProjectManager::Internal;
|
|
|
|
|
using namespace Core::Utils;
|
|
|
|
|
|
|
|
|
|
GenericProjectWizard::GenericProjectWizard()
|
|
|
|
|
: Core::BaseFileWizard(parameters())
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GenericProjectWizard::~GenericProjectWizard()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Core::BaseFileWizardParameters GenericProjectWizard::parameters()
|
|
|
|
|
{
|
|
|
|
|
static Core::BaseFileWizardParameters parameters(ProjectWizard);
|
2009-03-12 18:31:50 +01:00
|
|
|
parameters.setIcon(QIcon(":/wizards/images/console.png"));
|
2009-03-12 17:53:25 +01:00
|
|
|
parameters.setName(tr("Existing Project"));
|
|
|
|
|
parameters.setDescription(tr("Import Existing Project"));
|
2009-03-12 18:31:50 +01:00
|
|
|
parameters.setCategory(QLatin1String("Projects"));
|
|
|
|
|
parameters.setTrCategory(tr("Projects"));
|
2009-03-12 17:53:25 +01:00
|
|
|
return parameters;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWizard *GenericProjectWizard::createWizardDialog(QWidget *parent,
|
|
|
|
|
const QString &defaultPath,
|
|
|
|
|
const WizardPageList &extensionPages) const
|
|
|
|
|
{
|
|
|
|
|
QWizard *wizard = new QWizard(parent);
|
|
|
|
|
wizard->setWindowTitle(tr("Import Existing Project"));
|
|
|
|
|
setupWizard(wizard);
|
|
|
|
|
|
|
|
|
|
QWizardPage *firstPage = new QWizardPage;
|
2009-03-12 18:31:50 +01:00
|
|
|
firstPage->setTitle(tr("Project"));
|
2009-03-12 17:53:25 +01:00
|
|
|
|
|
|
|
|
QFormLayout *layout = new QFormLayout(firstPage);
|
|
|
|
|
|
|
|
|
|
PathChooser *pathChooser = new PathChooser;
|
|
|
|
|
pathChooser->setObjectName("pathChooser");
|
|
|
|
|
layout->addRow(tr("Source Directory:"), pathChooser);
|
|
|
|
|
|
|
|
|
|
wizard->addPage(firstPage);
|
|
|
|
|
|
|
|
|
|
foreach (QWizardPage *p, extensionPages)
|
|
|
|
|
wizard->addPage(p);
|
|
|
|
|
|
|
|
|
|
return wizard;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Core::GeneratedFiles GenericProjectWizard::generateFiles(const QWizard *w,
|
|
|
|
|
QString *errorMessage) const
|
|
|
|
|
{
|
|
|
|
|
PathChooser *pathChooser = w->findChild<PathChooser *>("pathChooser");
|
2009-03-12 18:31:50 +01:00
|
|
|
const QString projectName = QFileInfo(pathChooser->path()).baseName() + QLatin1String(".creator");
|
|
|
|
|
const QDir dir(pathChooser->path());
|
|
|
|
|
|
|
|
|
|
// ### FIXME: use the mimetype database.
|
|
|
|
|
// ### FIXME: import nested folders.
|
|
|
|
|
const QStringList sources = dir.entryList(QStringList() << "Makefile" << "*.c" << "*.cpp" << "*.h", QDir::Files);
|
|
|
|
|
|
|
|
|
|
QString projectContents;
|
|
|
|
|
QTextStream stream(&projectContents);
|
|
|
|
|
stream << "files=" << sources.join(",");
|
|
|
|
|
stream << endl;
|
|
|
|
|
|
|
|
|
|
Core::GeneratedFile file(QFileInfo(dir, projectName).absoluteFilePath()); // ### fixme
|
|
|
|
|
file.setContents(projectContents);
|
2009-03-12 17:53:25 +01:00
|
|
|
|
2009-03-12 18:31:50 +01:00
|
|
|
Core::GeneratedFiles files;
|
|
|
|
|
files.append(file);
|
|
|
|
|
|
|
|
|
|
return files;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool GenericProjectWizard::postGenerateFiles(const Core::GeneratedFiles &l, QString *errorMessage)
|
|
|
|
|
{
|
|
|
|
|
// Post-Generate: Open the project
|
|
|
|
|
const QString proFileName = l.back().path();
|
|
|
|
|
if (!ProjectExplorer::ProjectExplorerPlugin::instance()->openProject(proFileName)) {
|
|
|
|
|
*errorMessage = tr("The project %1 could not be opened.").arg(proFileName);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2009-03-12 17:53:25 +01:00
|
|
|
}
|
|
|
|
|
|