From: James Turner Date: Sat, 5 Mar 2016 09:35:02 +0000 (+0000) Subject: Improve UI around adding aircraft dirs X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=43b4db7ef7ad16bfaaeb06d5b4a5b0f71b7617c6;p=flightgear.git Improve UI around adding aircraft dirs - Check if the selected path, or an ‘Aircraft’ subdir, contains some -set.xml files, and if not, warn the user. --- diff --git a/src/GUI/AircraftModel.cxx b/src/GUI/AircraftModel.cxx index 16e015c7c..18f9e1383 100644 --- a/src/GUI/AircraftModel.cxx +++ b/src/GUI/AircraftModel.cxx @@ -851,4 +851,28 @@ bool AircraftItemModel::isIndexRunnable(const QModelIndex& index) const return !ex->isDownloading(); } +bool AircraftItemModel::isCandidateAircraftPath(QString path) +{ + QStringList filters; + filters << "*-set.xml"; + int dirCount = 0, + setXmlCount = 0; + + QDir d(path); + Q_FOREACH(QFileInfo child, d.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot)) { + QDir childDir(child.absoluteFilePath()); + ++dirCount; + Q_FOREACH(QFileInfo xmlChild, childDir.entryInfoList(filters, QDir::Files)) { + ++setXmlCount; + } + + if ((setXmlCount > 0) || (dirCount > 10)) { + break; + } + } + + return (setXmlCount > 0); +} + + #include "AircraftModel.moc" diff --git a/src/GUI/AircraftModel.hxx b/src/GUI/AircraftModel.hxx index b49527ed8..967f974a3 100644 --- a/src/GUI/AircraftModel.hxx +++ b/src/GUI/AircraftModel.hxx @@ -127,7 +127,13 @@ public: * are not installed, or are downloading, are not runnable. */ bool isIndexRunnable(const QModelIndex& index) const; - + + /** + * @helper to determine if a particular path is likely to contain + * aircraft or not. Checks for -set.xml files one level down in the tree. + * + */ + static bool isCandidateAircraftPath(QString path); signals: void aircraftInstallFailed(QModelIndex index, QString errorMessage); diff --git a/src/GUI/PathsDialog.cxx b/src/GUI/PathsDialog.cxx index 3770733c9..c68cc1ecf 100644 --- a/src/GUI/PathsDialog.cxx +++ b/src/GUI/PathsDialog.cxx @@ -7,6 +7,7 @@ #include "CatalogListModel.hxx" #include "AddCatalogDialog.hxx" +#include "AircraftModel.hxx" #include
#include
@@ -125,7 +126,36 @@ void PathsDialog::onAddAircraftPath() { QString path = QFileDialog::getExistingDirectory(this, tr("Choose aircraft folder")); if (!path.isEmpty()) { - m_ui->aircraftPathsList->addItem(path); + // the user might add a directory containing an 'Aircraft' subdir. Let's attempt + // to check for that case and handle it gracefully. + bool pathOk = false; + + if (AircraftItemModel::isCandidateAircraftPath(path)) { + m_ui->aircraftPathsList->addItem(path); + pathOk = true; + } else { + // no aircraft in speciied path, look for Aircraft/ subdir + QDir d(path); + if (d.exists("Aircraft")) { + QString p2 = d.filePath("Aircraft"); + if (AircraftItemModel::isCandidateAircraftPath(p2)) { + m_ui->aircraftPathsList->addItem(p2); + pathOk = true; + } + } + } + + if (!pathOk) { + QMessageBox mb; + mb.setText(QString("No aircraft found in the folder '%1' - add anyway?").arg(path)); + mb.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + mb.setDefaultButton(QMessageBox::No); + mb.exec(); + + if (mb.result() == QMessageBox::Yes) { + m_ui->aircraftPathsList->addItem(path); + } + } } // work around a Qt OS-X bug - this dialog is ending ordered // behind the main settings dialog (consequence of modal-dialog