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.
This commit is contained in:
parent
688ae7d156
commit
43b4db7ef7
3 changed files with 62 additions and 2 deletions
|
@ -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"
|
||||
|
|
|
@ -128,6 +128,12 @@ public:
|
|||
*/
|
||||
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);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue