]> git.mxchange.org Git - flightgear.git/commitdiff
Improve UI around adding aircraft dirs
authorJames Turner <zakalawe@mac.com>
Sat, 5 Mar 2016 09:35:02 +0000 (09:35 +0000)
committerJames Turner <zakalawe@mac.com>
Sat, 5 Mar 2016 09:35:02 +0000 (09:35 +0000)
- Check if the selected path, or an ‘Aircraft’ subdir,  contains
some -set.xml files, and if not, warn the user.

src/GUI/AircraftModel.cxx
src/GUI/AircraftModel.hxx
src/GUI/PathsDialog.cxx

index 16e015c7c34604ceaa4504099310ccff5489bf38..18f9e13836d6bc6b8cc53017164e90813d862169 100644 (file)
@@ -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"
index b49527ed80bea3c630ec4eec3339ce6ab9ef4694..967f974a39b63f407e848794ead7e8462543862e 100644 (file)
@@ -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);
     
index 3770733c9eca510e24c87dc7874e56d52d793e66..c68cc1ecfb6dbf72917c9200e3d9f739a2ad4738 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "CatalogListModel.hxx"
 #include "AddCatalogDialog.hxx"
+#include "AircraftModel.hxx"
 
 #include <Main/options.hxx>
 #include <Main/globals.hxx>
@@ -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