--- /dev/null
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (info@qt.nokia.com)
+**
+**
+** GNU Lesser General Public License Usage
+**
+** 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.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at info@qt.nokia.com.
+**
+**************************************************************************/
+
+#include "filesselectionwizardpage.h"
+
+#include "genericprojectwizard.h"
+#include "selectablefilesmodel.h"
+
+#include <coreplugin/mimedatabase.h>
+#include <coreplugin/icore.h>
+#include <QtGui/QVBoxLayout>
+
+using namespace GenericProjectManager;
+using namespace GenericProjectManager::Internal;
+
+FilesSelectionWizardPage::FilesSelectionWizardPage(GenericProjectWizardDialog *genericProjectWizard, QWidget *parent)
+ : QWizardPage(parent), m_genericProjectWizardDialog(genericProjectWizard), m_model(0), m_finished(false)
+{
+ QVBoxLayout *layout = new QVBoxLayout(this);
+
+ m_view = new QTreeView;
+ m_view->setMinimumSize(500, 400);
+ m_view->setHeaderHidden(true);
+ m_view->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
+ m_label = new QLabel;
+ m_label->setMaximumWidth(500);
+
+ layout->addWidget(m_view);
+ layout->addWidget(m_label);
+}
+
+void FilesSelectionWizardPage::initializePage()
+{
+ m_view->setModel(0);
+ delete m_model;
+ Core::MimeDatabase *mimeDatabase = Core::ICore::instance()->mimeDatabase();
+ m_model = new SelectableFilesModel(m_genericProjectWizardDialog->path(), this);
+ m_model->setSuffixes(mimeDatabase->suffixes().toSet());
+ connect(m_model, SIGNAL(parsingProgress(QString)),
+ this, SLOT(parsingProgress(QString)));
+ connect(m_model, SIGNAL(parsingFinished()),
+ this, SLOT(parsingFinished()));
+ m_model->startParsing();
+ m_view->setVisible(false);
+ m_label->setVisible(true);
+ m_view->setModel(m_model);
+}
+
+void FilesSelectionWizardPage::cleanupPage()
+{
+ m_model->cancel();
+ m_model->waitForFinished();
+}
+
+void FilesSelectionWizardPage::parsingProgress(const QString &text)
+{
+ m_label->setText(tr("Generating file list...\n\n%1").arg(text));
+}
+
+void FilesSelectionWizardPage::parsingFinished()
+{
+ m_finished = true;
+ m_view->setVisible(true);
+ m_label->setVisible(false);
+ m_view->expand(m_view->model()->index(0,0, QModelIndex()));
+ emit completeChanged();
+ // work around qt
+ m_genericProjectWizardDialog->setTitleFormat(m_genericProjectWizardDialog->titleFormat());
+}
+
+bool FilesSelectionWizardPage::isComplete() const
+{
+ return m_finished;
+}
+
+QStringList FilesSelectionWizardPage::selectedPaths() const
+{
+ return m_model ? m_model->selectedPaths() : QStringList();
+}
+
+QStringList FilesSelectionWizardPage::selectedFiles() const
+{
+ return m_model ? m_model->selectedFiles() : QStringList();
+}
--- /dev/null
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (info@qt.nokia.com)
+**
+**
+** GNU Lesser General Public License Usage
+**
+** 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.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at info@qt.nokia.com.
+**
+**************************************************************************/
+
+#ifndef FILESSELECTIONWIZARDPAGE_H
+#define FILESSELECTIONWIZARDPAGE_H
+
+#include <QtGui/QWizardPage>
+#include <QtGui/QLabel>
+#include <QtGui/QTreeView>
+
+namespace GenericProjectManager {
+namespace Internal {
+class GenericProjectWizardDialog;
+class SelectableFilesModel;
+
+class FilesSelectionWizardPage : public QWizardPage
+{
+ Q_OBJECT
+public:
+ FilesSelectionWizardPage(GenericProjectWizardDialog *genericProjectWizard, QWidget *parent = 0);
+ virtual bool isComplete() const;
+ virtual void initializePage();
+ virtual void cleanupPage();
+ QStringList selectedFiles() const;
+ QStringList selectedPaths() const;
+private slots:
+ void parsingProgress(const QString &text);
+ void parsingFinished();
+private:
+ GenericProjectWizardDialog *m_genericProjectWizardDialog;
+ SelectableFilesModel *m_model;
+ QTreeView *m_view;
+ QLabel *m_label;
+ bool m_finished;
+};
+
+}
+}
+#endif // FILESSELECTIONWIZARDPAGE_H
pkgconfigtool.h \
genericmakestep.h \
genericbuildconfiguration.h \
- selectablefilesmodel.h
+ selectablefilesmodel.h \
+ filesselectionwizardpage.h
SOURCES = genericproject.cpp \
genericprojectplugin.cpp \
generictarget.cpp \
pkgconfigtool.cpp \
genericmakestep.cpp \
genericbuildconfiguration.cpp \
- selectablefilesmodel.cpp
+ selectablefilesmodel.cpp \
+ filesselectionwizardpage.cpp
RESOURCES += genericproject.qrc
FORMS += genericmakestep.ui
+
+
**************************************************************************/
#include "genericprojectwizard.h"
+#include "filesselectionwizardpage.h"
#include <coreplugin/icore.h>
#include <coreplugin/mimedatabase.h>
m_firstPage->setFileNameLabel(tr("Project name:"));
m_firstPage->setPathLabel(tr("Location:"));
+ // second page
+ m_secondPage = new FilesSelectionWizardPage(this);
+ m_secondPage->setTitle(tr("File Selection"));
+
const int firstPageId = addPage(m_firstPage);
wizardProgress()->item(firstPageId)->setTitle(tr("Location"));
+
+ const int secondPageId = addPage(m_secondPage);
+ wizardProgress()->item(secondPageId)->setTitle(tr("Files"));
}
GenericProjectWizardDialog::~GenericProjectWizardDialog()
return m_firstPage->path();
}
+QStringList GenericProjectWizardDialog::selectedPaths() const
+{
+ return m_secondPage->selectedPaths();
+}
+
+QStringList GenericProjectWizardDialog::selectedFiles() const
+{
+ return m_secondPage->selectedFiles();
+}
+
void GenericProjectWizardDialog::setPath(const QString &path)
{
m_firstPage->setPath(path);
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();
+ const QStringList sources = wizard->selectedFiles();
+ const QStringList paths = wizard->selectedPaths();
Core::ICore *core = Core::ICore::instance();
Core::MimeDatabase *mimeDatabase = core->mimeDatabase();
- const QStringList suffixes = mimeDatabase->suffixes();
-
- QStringList sources, paths;
- getFileList(dir, projectPath, suffixes, &sources, &paths);
-
Core::MimeType headerTy = mimeDatabase->findByType(QLatin1String("text/x-chdr"));
QStringList nameFilters;
namespace GenericProjectManager {
namespace Internal {
- class GenericProjectWizardDialog : public Utils::Wizard
+class FilesSelectionWizardPage;
+
+class GenericProjectWizardDialog : public Utils::Wizard
{
Q_OBJECT
QString path() const;
void setPath(const QString &path);
+ QStringList selectedFiles() const;
+ QStringList selectedPaths() const;
QString projectName() const;
Utils::FileWizardPage *m_firstPage;
+ FilesSelectionWizardPage *m_secondPage;
};
class GenericProjectWizard : public Core::BaseFileWizard
#include "selectablefilesmodel.h"
+#include <coreplugin/fileiconprovider.h>
+
+#include <qtconcurrent/QtConcurrentTools>
#include <QtGui/QHBoxLayout>
#include <QtGui/QDialogButtonBox>
#include <QtGui/QTreeView>
using namespace GenericProjectManager;
using namespace GenericProjectManager::Internal;
-SelectableFilesModel::SelectableFilesModel(const QString &baseDir, const QStringList &files, const QSet<QString> &suffixes, QObject *parent)
- : QAbstractItemModel(parent), m_baseDir(baseDir), m_suffixes(suffixes), m_root(0)
+SelectableFilesModel::SelectableFilesModel(const QString &baseDir, QObject *parent)
+ : QAbstractItemModel(parent), m_root(0), m_baseDir(baseDir), m_allFiles(true)
{
- m_files = files.toSet();
-
- // Build a tree
+ // Dummy tree
m_root = new Tree;
m_root->name = "/";
m_root->parent = 0;
- m_root->isDir = true;
+}
+
+void SelectableFilesModel::setInitialMarkedFiles(const QStringList &files)
+{
+ m_files = files.toSet();
+ m_allFiles = false;
+}
- buildTree(baseDir, m_root);
+void SelectableFilesModel::setSuffixes(QSet<QString> suffixes)
+{
+ m_suffixes = suffixes;
+}
+
+void SelectableFilesModel::init()
+{
+}
+
+void SelectableFilesModel::startParsing()
+{
+ // Build a tree in a future
+ m_rootForFuture = new Tree;
+ m_rootForFuture->name = "/";
+ m_rootForFuture->parent = 0;
+
+ connect(&m_watcher, SIGNAL(finished()), this, SLOT(buildTreeFinished()));
+ m_watcher.setFuture(QtConcurrent::run(&SelectableFilesModel::run, this));
+}
+
+void SelectableFilesModel::run(QFutureInterface<void> &fi)
+{
+ m_futureCount = 0;
+ buildTree(m_baseDir, m_rootForFuture, fi);
+}
+
+void SelectableFilesModel::buildTreeFinished()
+{
+ beginResetModel();
+ deleteTree(m_root);
+ m_root = m_rootForFuture;
+ m_rootForFuture = 0;
+ endResetModel();
+ emit parsingFinished();
+}
+
+void SelectableFilesModel::waitForFinished()
+{
+ m_watcher.waitForFinished();
+}
+
+void SelectableFilesModel::cancel()
+{
+ m_watcher.cancel();
}
-void SelectableFilesModel::buildTree(const QString &baseDir, Tree *tree)
+void SelectableFilesModel::buildTree(const QString &baseDir, Tree *tree, QFutureInterface<void> &fi)
{
const QFileInfoList fileInfoList = QDir(baseDir).entryInfoList(QDir::Files |
QDir::Dirs |
bool allChecked = true;
bool allUnchecked = true;
foreach (const QFileInfo &fileInfo, fileInfoList) {
+ if (m_futureCount % 100) {
+ emit parsingProgress(fileInfo.absoluteFilePath());
+ if (fi.isCanceled())
+ return;
+ }
+ ++m_futureCount;
if (fileInfo.isDir()) {
Tree *t = new Tree;
t->parent = tree;
t->name = fileInfo.fileName();
- t->isDir = true;
- buildTree(fileInfo.filePath(), t);
+ t->fullPath = fileInfo.filePath();
+ buildTree(fileInfo.filePath(), t, fi);
allChecked &= t->checked == Qt::Checked;
allUnchecked &= t->checked == Qt::Unchecked;
tree->childDirectories.append(t);
Tree *t = new Tree;
t->parent = tree;
t->name = fileInfo.fileName();
- t->isDir = false;
- t->icon = m_iconProvider.icon(fileInfo);
- t->checked = m_files.contains(fileInfo.absoluteFilePath()) ? Qt::Checked : Qt::Unchecked;
+ t->checked = m_allFiles || m_files.contains(fileInfo.absoluteFilePath()) ? Qt::Checked : Qt::Unchecked;
t->fullPath = fileInfo.filePath();
allChecked &= t->checked == Qt::Checked;
allUnchecked &= t->checked == Qt::Unchecked;
tree->files.append(t);
}
}
- if (allChecked)
+ if (tree->childDirectories.isEmpty() && tree->files.isEmpty())
+ tree->checked = Qt::Unchecked;
+ else if (allChecked)
tree->checked = Qt::Checked;
else if (allUnchecked)
tree->checked = Qt::Unchecked;
if (role == Qt::CheckStateRole)
return t->checked;
if (role == Qt::DecorationRole) {
- if (t->isDir)
- return m_iconProvider.icon(QFileIconProvider::Folder);
- else
- return t->icon;
+ if (t->icon.isNull())
+ t->icon = Core::FileIconProvider::instance()->icon(QFileInfo(t->fullPath));
+ return t->icon;
}
return QVariant();
}
return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
}
+QStringList SelectableFilesModel::selectedPaths() const
+{
+ QStringList result;
+ collectPaths(m_root, &result);
+ return result;
+}
+
+void SelectableFilesModel::collectPaths(Tree *root, QStringList *result) const
+{
+ if (root->checked == Qt::Unchecked)
+ return;
+ result->append(root->fullPath);
+ foreach (Tree *t, root->childDirectories)
+ collectPaths(t, result);
+}
+
QStringList SelectableFilesModel::selectedFiles() const
{
QStringList result;
setLayout(layout);
setWindowTitle(tr("Edit Files"));
- QTreeView *view = new QTreeView(this);
- layout->addWidget(view);
+ m_view = new QTreeView(this);
+
+ m_selectableFilesModel = new SelectableFilesModel(path, this);
+ m_selectableFilesModel->setInitialMarkedFiles(files);
+ m_selectableFilesModel->setSuffixes(suffixes);
+ m_view->setModel(m_selectableFilesModel);
+ m_view->setMinimumSize(500, 400);
+ m_view->setHeaderHidden(true);
+ m_view->hide();
+ layout->addWidget(m_view);
+
+ m_progressLabel = new QLabel(this);
+ m_progressLabel->setMaximumWidth(500);
+ layout->addWidget(m_progressLabel);
+
QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Horizontal, this);
buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
connect(buttonBox, SIGNAL(accepted()),
this, SLOT(reject()));
layout->addWidget(buttonBox);
- m_selectableFilesModel = new SelectableFilesModel(path, files, suffixes, this);
- view->setModel(m_selectableFilesModel);
- view->setMinimumSize(400, 300);
- view->setHeaderHidden(true);
- view->expand(QModelIndex());
- smartExpand(view, m_selectableFilesModel->index(0,0, QModelIndex()));
+ connect(m_selectableFilesModel, SIGNAL(parsingProgress(QString)),
+ this, SLOT(parsingProgress(QString)));
+ connect(m_selectableFilesModel, SIGNAL(parsingFinished()),
+ this, SLOT(parsingFinished()));
+
+ m_selectableFilesModel->startParsing();
+}
+
+SelectableFilesDialog::~SelectableFilesDialog()
+{
+ m_selectableFilesModel->cancel();
+ m_selectableFilesModel->waitForFinished();
+}
+
+void SelectableFilesDialog::parsingProgress(const QString &fileName)
+{
+ m_progressLabel->setText(tr("Generating file list...\n\n%1").arg(fileName));
+}
+
+void SelectableFilesDialog::parsingFinished()
+{
+ m_view->show();
+ m_progressLabel->hide();
+ m_view->expand(QModelIndex());
+ smartExpand(m_selectableFilesModel->index(0,0, QModelIndex()));
}
-void SelectableFilesDialog::smartExpand(QTreeView *view, const QModelIndex &index)
+void SelectableFilesDialog::smartExpand(const QModelIndex &index)
{
- if (view->model()->data(index, Qt::CheckStateRole) == Qt::PartiallyChecked) {
- view->expand(index);
- int rows = view->model()->rowCount(index);
+ if (m_view->model()->data(index, Qt::CheckStateRole) == Qt::PartiallyChecked) {
+ m_view->expand(index);
+ int rows = m_view->model()->rowCount(index);
for (int i = 0; i < rows; ++i)
- smartExpand(view, index.child(i, 0));
+ smartExpand(index.child(i, 0));
}
}
#include <QtCore/QAbstractItemModel>
#include <QtCore/QSet>
+#include <QtCore/QFutureInterface>
+#include <QtCore/QFutureWatcher>
#include <QtGui/QFileSystemModel>
-#include <QtGui/QFileIconProvider>
#include <QtGui/QDialog>
#include <QtGui/QTreeView>
+#include <QtGui/QLabel>
namespace GenericProjectManager {
namespace Internal {
Qt::CheckState checked;
QList<Tree *> childDirectories;
QList<Tree *> files;
- bool isDir;
QIcon icon;
QString fullPath;
Tree *parent;
{
Q_OBJECT
public:
- SelectableFilesModel(const QString &baseDir, const QStringList &files, const QSet<QString> &suffixes, QObject *parent);
+ SelectableFilesModel(const QString &baseDir, QObject *parent);
~SelectableFilesModel();
+ void setSuffixes(QSet<QString> suffixes);
+ void setInitialMarkedFiles(const QStringList &files);
+
int columnCount(const QModelIndex &parent) const;
int rowCount(const QModelIndex &parent) const;
QModelIndex index(int row, int column, const QModelIndex &parent) const;
Qt::ItemFlags flags(const QModelIndex &index) const;
QStringList selectedFiles() const;
+ QStringList selectedPaths() const;
+
+ // only call this once
+ void startParsing();
+ void waitForFinished();
+ void cancel();
+signals:
+ void parsingFinished();
+ void parsingProgress(const QString &filename);
+private slots:
+ void buildTreeFinished();
private:
+ void init();
+ void run(QFutureInterface<void> &fi);
void collectFiles(Tree *root, QStringList *result) const;
- void buildTree(const QString &baseDir, Tree *tree);
+ void collectPaths(Tree *root, QStringList *result) const;
+ void buildTree(const QString &baseDir, Tree *tree, QFutureInterface<void> &fi);
void deleteTree(Tree *tree);
void propagateUp(const QModelIndex &index);
void propagateDown(const QModelIndex &index);
+ Tree *m_root;
+ // Used in the future thread need to all not used after calling startParsing
QString m_baseDir;
QSet<QString> m_files;
QSet<QString> m_suffixes;
- Tree *m_root;
- QFileIconProvider m_iconProvider;
+ QFutureWatcher<void> m_watcher;
+ Tree *m_rootForFuture;
+ int m_futureCount;
+ bool m_allFiles;
};
class SelectableFilesDialog : public QDialog
Q_OBJECT
public:
SelectableFilesDialog(const QString &path, const QStringList files, const QSet<QString> &suffixes, QWidget *parent);
+ ~SelectableFilesDialog();
QStringList selectedFiles() const;
+
+private slots:
+ void parsingProgress(const QString &fileName);
+ void parsingFinished();
+
private:
- void smartExpand(QTreeView *view, const QModelIndex &index);
+ void smartExpand(const QModelIndex &index);
SelectableFilesModel *m_selectableFilesModel;
+ QTreeView *m_view;
+ QLabel *m_progressLabel;
};
}