diff --git a/src/plugins/git/gitorious/gitorioushostwidget.cpp b/src/plugins/git/gitorious/gitorioushostwidget.cpp index c01cd4c94cb2ab60ce2de6d18c95ffbff9b5eeaf..8243b8211210c91c5d48686a7c64633e9fa6ec70 100644 --- a/src/plugins/git/gitorious/gitorioushostwidget.cpp +++ b/src/plugins/git/gitorious/gitorioushostwidget.cpp @@ -46,8 +46,6 @@ enum { debug = 0 }; -enum { NewDummyEntryRole = Qt::UserRole + 1 }; - namespace Gitorious { namespace Internal { @@ -164,9 +162,7 @@ void GitoriousHostWidget::selectRow(int r) void GitoriousHostWidget::appendNewDummyEntry() { // Append a new entry where a host name is editable - const QList<QStandardItem *> dummyRow = hostEntry(m_newHost, 0, QString(), true); - dummyRow.front()->setData(QVariant(true), NewDummyEntryRole); - m_model->appendRow(dummyRow); + m_model->appendRow(hostEntry(m_newHost, 0, QString(), true)); } void GitoriousHostWidget::slotItemEdited(QStandardItem *item) @@ -180,7 +176,6 @@ void GitoriousHostWidget::slotItemEdited(QStandardItem *item) case HostNameColumn: if (isDummyEntry) { Gitorious::instance().addHost(item->text(), m_model->item(row, DescriptionColumn)->text()); - item->setData(QVariant(false), NewDummyEntryRole); m_isHostListDirty = true; appendNewDummyEntry(); selectRow(row); diff --git a/src/plugins/git/gitorious/gitoriousprojectwizardpage.cpp b/src/plugins/git/gitorious/gitoriousprojectwizardpage.cpp index c36915d4fe0ef8614ff571a36200b6088bb6224e..15cfcc6cf233d4e85bb4ecfa43f84acfc5848275 100644 --- a/src/plugins/git/gitorious/gitoriousprojectwizardpage.cpp +++ b/src/plugins/git/gitorious/gitoriousprojectwizardpage.cpp @@ -68,11 +68,12 @@ void GitoriousProjectWizardPage::initializePage() { // Try to find the page by hostindex 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 if (existingStackIndex != -1) { m_stackedWidget->setCurrentIndex(existingStackIndex); - setSubTitle(msgChooseProject(selectedHostName())); + setSubTitle(msgChooseProject(hostName)); return; } // Add a new page @@ -119,12 +120,12 @@ GitoriousProjectWidget *GitoriousProjectWizardPage::currentProjectWidget() const return projectWidgetAt(index); } -// Convert a host index to a stack index. -int GitoriousProjectWizardPage::hostIndexToStackIndex(int hostIndex) const +// Convert a host name to a stack index. +int GitoriousProjectWizardPage::stackIndexOf(const QString &hostName) const { const int count = m_stackedWidget->count(); for(int i = 0; i < count; i++) - if (projectWidgetAt(i)->hostIndex() == hostIndex) + if (projectWidgetAt(i)->hostName() == hostName) return i; return -1; } diff --git a/src/plugins/git/gitorious/gitoriousprojectwizardpage.h b/src/plugins/git/gitorious/gitoriousprojectwizardpage.h index abe4b3f2d25ed2d51622580e7eaa29eb30e9fc72..b26e4e0a4da89f4718ad4c9ba28e0600e662d16e 100644 --- a/src/plugins/git/gitorious/gitoriousprojectwizardpage.h +++ b/src/plugins/git/gitorious/gitoriousprojectwizardpage.h @@ -74,7 +74,7 @@ private slots: private: GitoriousProjectWidget *projectWidgetAt(int index) const; GitoriousProjectWidget *currentProjectWidget() const; - int hostIndexToStackIndex(int hostIndex) const; + int stackIndexOf(const QString &hostName) const; const GitoriousHostWizardPage *m_hostPage; QStackedWidget *m_stackedWidget; diff --git a/src/plugins/vcsbase/basecheckoutwizard.cpp b/src/plugins/vcsbase/basecheckoutwizard.cpp index 208983eb5fda502ad122d07139bb9f1f0e3ec12d..e53b90524de61c237d69a732a789dfa0eb2166c1 100644 --- a/src/plugins/vcsbase/basecheckoutwizard.cpp +++ b/src/plugins/vcsbase/basecheckoutwizard.cpp @@ -109,6 +109,36 @@ QStringList BaseCheckoutWizard::runWizard(const QString &path, QWidget *parent) 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) { 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 return QString(); } - // Hardcoded: Find *.pro/Cmakefiles - QStringList patterns; - 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(", "))); + QFileInfoList projectFiles = findProjectFiles(dir, errorMessage); + if (projectFiles.empty()) return QString(); - } - // Open! + // Open. Do not use a busy cursor here as additional wizards might pop up const QString projectFile = projectFiles.front().absoluteFilePath(); if (!pe->openProject(projectFile)) { *errorMessage = tr("Unable to open the project '%1'.").arg(projectFile);