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"
* 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);
#include "CatalogListModel.hxx"
#include "AddCatalogDialog.hxx"
+#include "AircraftModel.hxx"
#include <Main/options.hxx>
#include <Main/globals.hxx>
{
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