Gitorious wizard: Import CMake projects, look in src directory.

Remove unused code.
This commit is contained in:
Friedemann Kleint
2009-07-27 09:22:26 +02:00
parent f3a04e7ef6
commit 96940fa949
4 changed files with 41 additions and 20 deletions

View File

@@ -46,8 +46,6 @@
enum { debug = 0 }; enum { debug = 0 };
enum { NewDummyEntryRole = Qt::UserRole + 1 };
namespace Gitorious { namespace Gitorious {
namespace Internal { namespace Internal {
@@ -164,9 +162,7 @@ void GitoriousHostWidget::selectRow(int r)
void GitoriousHostWidget::appendNewDummyEntry() void GitoriousHostWidget::appendNewDummyEntry()
{ {
// Append a new entry where a host name is editable // Append a new entry where a host name is editable
const QList<QStandardItem *> dummyRow = hostEntry(m_newHost, 0, QString(), true); m_model->appendRow(hostEntry(m_newHost, 0, QString(), true));
dummyRow.front()->setData(QVariant(true), NewDummyEntryRole);
m_model->appendRow(dummyRow);
} }
void GitoriousHostWidget::slotItemEdited(QStandardItem *item) void GitoriousHostWidget::slotItemEdited(QStandardItem *item)
@@ -180,7 +176,6 @@ void GitoriousHostWidget::slotItemEdited(QStandardItem *item)
case HostNameColumn: case HostNameColumn:
if (isDummyEntry) { if (isDummyEntry) {
Gitorious::instance().addHost(item->text(), m_model->item(row, DescriptionColumn)->text()); Gitorious::instance().addHost(item->text(), m_model->item(row, DescriptionColumn)->text());
item->setData(QVariant(false), NewDummyEntryRole);
m_isHostListDirty = true; m_isHostListDirty = true;
appendNewDummyEntry(); appendNewDummyEntry();
selectRow(row); selectRow(row);

View File

@@ -68,11 +68,12 @@ void GitoriousProjectWizardPage::initializePage()
{ {
// Try to find the page by hostindex // Try to find the page by hostindex
const int hostIndex = m_hostPage->selectedHostIndex(); const int hostIndex = m_hostPage->selectedHostIndex();
const int existingStackIndex = hostIndexToStackIndex(hostIndex); const QString hostName = Gitorious::instance().hostName(hostIndex);
const int existingStackIndex = stackIndexOf(hostName);
// Found? - pop up that page // Found? - pop up that page
if (existingStackIndex != -1) { if (existingStackIndex != -1) {
m_stackedWidget->setCurrentIndex(existingStackIndex); m_stackedWidget->setCurrentIndex(existingStackIndex);
setSubTitle(msgChooseProject(selectedHostName())); setSubTitle(msgChooseProject(hostName));
return; return;
} }
// Add a new page // Add a new page
@@ -119,12 +120,12 @@ GitoriousProjectWidget *GitoriousProjectWizardPage::currentProjectWidget() const
return projectWidgetAt(index); return projectWidgetAt(index);
} }
// Convert a host index to a stack index. // Convert a host name to a stack index.
int GitoriousProjectWizardPage::hostIndexToStackIndex(int hostIndex) const int GitoriousProjectWizardPage::stackIndexOf(const QString &hostName) const
{ {
const int count = m_stackedWidget->count(); const int count = m_stackedWidget->count();
for(int i = 0; i < count; i++) for(int i = 0; i < count; i++)
if (projectWidgetAt(i)->hostIndex() == hostIndex) if (projectWidgetAt(i)->hostName() == hostName)
return i; return i;
return -1; return -1;
} }

View File

@@ -74,7 +74,7 @@ private slots:
private: private:
GitoriousProjectWidget *projectWidgetAt(int index) const; GitoriousProjectWidget *projectWidgetAt(int index) const;
GitoriousProjectWidget *currentProjectWidget() const; GitoriousProjectWidget *currentProjectWidget() const;
int hostIndexToStackIndex(int hostIndex) const; int stackIndexOf(const QString &hostName) const;
const GitoriousHostWizardPage *m_hostPage; const GitoriousHostWizardPage *m_hostPage;
QStackedWidget *m_stackedWidget; QStackedWidget *m_stackedWidget;

View File

@@ -109,6 +109,36 @@ QStringList BaseCheckoutWizard::runWizard(const QString &path, QWidget *parent)
return QStringList(projectFile); return QStringList(projectFile);
} }
static inline QString msgNoProjectFiles(const QDir &dir, const QStringList &patterns)
{
return BaseCheckoutWizard::tr("Could not find any project files matching (%1) in the directory '%2'.").arg(patterns.join(QLatin1String(", ")), dir.absolutePath());
}
// Try to find the project files in a project directory with some smartness
static QFileInfoList findProjectFiles(const QDir &projectDir, QString *errorMessage)
{
// Hardcoded: Find *.pro/Cmakefiles
QStringList projectFilePatterns;
projectFilePatterns << QLatin1String("*.pro") << QLatin1String("CMakeLists.txt");
// Project directory
QFileInfoList projectFiles = projectDir.entryInfoList(projectFilePatterns, QDir::Files|QDir::NoDotAndDotDot|QDir::Readable);
if (!projectFiles.empty())
return projectFiles;
// Try a 'src' directory
QFileInfoList srcDirs = projectDir.entryInfoList(QStringList(QLatin1String("src")), QDir::Dirs|QDir::NoDotAndDotDot|QDir::Readable);
if (srcDirs.empty()) {
*errorMessage = msgNoProjectFiles(projectDir, projectFilePatterns);
return QFileInfoList();
}
const QDir srcDir = QDir(srcDirs.front().absoluteFilePath());
projectFiles = srcDir.entryInfoList(projectFilePatterns, QDir::Files|QDir::NoDotAndDotDot|QDir::Readable);
if (projectFiles.empty()) {
*errorMessage = msgNoProjectFiles(srcDir, projectFilePatterns);
return QFileInfoList();
}
return projectFiles;;
}
QString BaseCheckoutWizard::openProject(const QString &path, QString *errorMessage) QString BaseCheckoutWizard::openProject(const QString &path, QString *errorMessage)
{ {
ProjectExplorer::ProjectExplorerPlugin *pe = ProjectExplorer::ProjectExplorerPlugin::instance(); ProjectExplorer::ProjectExplorerPlugin *pe = ProjectExplorer::ProjectExplorerPlugin::instance();
@@ -123,15 +153,10 @@ QString BaseCheckoutWizard::openProject(const QString &path, QString *errorMessa
*errorMessage = tr("'%1' does not exist.").arg(path); // Should not happen *errorMessage = tr("'%1' does not exist.").arg(path); // Should not happen
return QString(); return QString();
} }
// Hardcoded: Find *.pro/Cmakefiles QFileInfoList projectFiles = findProjectFiles(dir, errorMessage);
QStringList patterns; if (projectFiles.empty())
patterns << QLatin1String("*.pro") << QLatin1String("CMakeList.txt");
QFileInfoList projectFiles = dir.entryInfoList(patterns, QDir::Files|QDir::NoDotAndDotDot|QDir::Readable);
if (projectFiles.empty()) {
*errorMessage = tr("No project files could be found (%1).").arg(patterns.join(QLatin1String(", ")));
return QString(); return QString();
} // Open. Do not use a busy cursor here as additional wizards might pop up
// Open!
const QString projectFile = projectFiles.front().absoluteFilePath(); const QString projectFile = projectFiles.front().absoluteFilePath();
if (!pe->openProject(projectFile)) { if (!pe->openProject(projectFile)) {
*errorMessage = tr("Unable to open the project '%1'.").arg(projectFile); *errorMessage = tr("Unable to open the project '%1'.").arg(projectFile);