From 5baca8598f484874235a037fc5db5eb0f9bdfa4a Mon Sep 17 00:00:00 2001 From: James Turner Date: Thu, 24 Mar 2016 15:10:06 +0000 Subject: [PATCH] Improve download-dir behaviour. When set on the command line, will be used for aircraft packages. When set in the Qt launcher, will also be used for aircraft downloads at all times. When changing the path in the launcher, the set of aircraft catalogs is refresh automatically. Note the default catalog may need to be re-installed. --- src/GUI/AircraftModel.cxx | 24 +++++++++++++++++------ src/GUI/AircraftModel.hxx | 4 +++- src/GUI/QtLauncher.cxx | 40 ++++++++++++++++++++++++++++++++++----- src/Main/fg_init.cxx | 11 +++++++++-- src/Main/main.cxx | 4 +--- 5 files changed, 66 insertions(+), 17 deletions(-) diff --git a/src/GUI/AircraftModel.cxx b/src/GUI/AircraftModel.cxx index 18f9e1383..92934790f 100644 --- a/src/GUI/AircraftModel.cxx +++ b/src/GUI/AircraftModel.cxx @@ -432,14 +432,10 @@ private: AircraftItemModel* m_model; }; -AircraftItemModel::AircraftItemModel(QObject* pr, const simgear::pkg::RootRef& rootRef) : +AircraftItemModel::AircraftItemModel(QObject* pr ) : QAbstractListModel(pr), - m_scanThread(NULL), - m_packageRoot(rootRef) + m_scanThread(NULL) { - m_delegate = new PackageDelegate(this); - // packages may already be refreshed, so pull now - refreshPackages(); } AircraftItemModel::~AircraftItemModel() @@ -448,6 +444,22 @@ AircraftItemModel::~AircraftItemModel() delete m_delegate; } +void AircraftItemModel::setPackageRoot(const simgear::pkg::RootRef& root) +{ + if (m_packageRoot) { + delete m_delegate; + m_delegate = NULL; + } + + m_packageRoot = root; + + if (m_packageRoot) { + m_delegate = new PackageDelegate(this); + // packages may already be refreshed, so pull now + refreshPackages(); + } +} + void AircraftItemModel::setPaths(QStringList paths) { m_paths = paths; diff --git a/src/GUI/AircraftModel.hxx b/src/GUI/AircraftModel.hxx index 967f974a3..90c243ceb 100644 --- a/src/GUI/AircraftModel.hxx +++ b/src/GUI/AircraftModel.hxx @@ -101,10 +101,12 @@ class AircraftItemModel : public QAbstractListModel { Q_OBJECT public: - AircraftItemModel(QObject* pr, const simgear::pkg::RootRef& root); + AircraftItemModel(QObject* pr); ~AircraftItemModel(); + void setPackageRoot(const simgear::pkg::RootRef& root); + void setPaths(QStringList paths); void scanDirs(); diff --git a/src/GUI/QtLauncher.cxx b/src/GUI/QtLauncher.cxx index c95fc907a..0d32aa9f0 100644 --- a/src/GUI/QtLauncher.cxx +++ b/src/GUI/QtLauncher.cxx @@ -412,6 +412,12 @@ bool runLauncherDialog() initNavCache(); + QSettings settings; + QString downloadDir = settings.value("download-dir").toString(); + if (!downloadDir.isEmpty()) { + flightgear::Options::sharedInstance()->setOption("download-dir", downloadDir.toStdString()); + } + fgInitPackageRoot(); // startup the HTTP system now since packages needs it @@ -431,7 +437,6 @@ bool runLauncherDialog() dlg.show(); int appResult = qApp->exec(); - qDebug() << "App result:" << appResult; if (appResult < 0) { return false; // quit } @@ -541,7 +546,7 @@ QtLauncher::QtLauncher() : this, &QtLauncher::onToggleTerrasync); updateSettingsSummary(); - m_aircraftModel = new AircraftItemModel(this, RootRef(globals->packageRoot())); + m_aircraftModel = new AircraftItemModel(this); m_aircraftProxy->setSourceModel(m_aircraftModel); m_aircraftProxy->setFilterCaseSensitivity(Qt::CaseInsensitive); @@ -579,11 +584,12 @@ QtLauncher::QtLauncher() : connect(m_aircraftProxy, &AircraftProxyModel::modelReset, this, &QtLauncher::delayedAircraftModelReset); - restoreSettings(); - QSettings settings; m_aircraftModel->setPaths(settings.value("aircraft-paths").toStringList()); + m_aircraftModel->setPackageRoot(globals->packageRoot()); m_aircraftModel->scanDirs(); + + restoreSettings(); } QtLauncher::~QtLauncher() @@ -1132,11 +1138,35 @@ void QtLauncher::onSubsytemIdleTimeout() void QtLauncher::onEditPaths() { + QSettings settings; + QString previousDownloadDir = settings.value("download-dir").toString(); + PathsDialog dlg(this, globals->packageRoot()); dlg.exec(); if (dlg.result() == QDialog::Accepted) { + QString dd = settings.value("download-dir").toString(); + bool downloadDirChanged = (previousDownloadDir != dd); + if (downloadDirChanged) { + qDebug() << "download dir changed, resetting package root"; + + if (dd.isEmpty()) { + flightgear::Options::sharedInstance()->clearOption("download-dir"); + } else { + flightgear::Options::sharedInstance()->setOption("download-dir", dd.toStdString()); + } + + // replace existing package root + globals->get_subsystem()->shutdown(); + globals->setPackageRoot(simgear::pkg::RootRef()); + + // create new root with updated download-dir value + fgInitPackageRoot(); + + globals->get_subsystem()->init(); + } + // re-scan the aircraft list - QSettings settings; + m_aircraftModel->setPackageRoot(globals->packageRoot()); m_aircraftModel->setPaths(settings.value("aircraft-paths").toStringList()); m_aircraftModel->scanDirs(); diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 0c47e860b..e7c681f48 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -1126,10 +1126,17 @@ void fgInitPackageRoot() if (globals->packageRoot()) { return; } - - SGPath packageAircraftDir = flightgear::defaultDownloadDir(); + + SGPath packageAircraftDir = flightgear::Options::sharedInstance()->valueForOption("download-dir"); + if (packageAircraftDir.isNull()) { + packageAircraftDir = flightgear::defaultDownloadDir(); + } + packageAircraftDir.append("Aircraft"); + SG_LOG(SG_GENERAL, SG_INFO, "init package root at:" << packageAircraftDir.str()); + + SGSharedPtr pkgRoot(new Root(packageAircraftDir, FLIGHTGEAR_VERSION)); // set the http client later (too early in startup right now) globals->setPackageRoot(pkgRoot); diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 0e683a69a..791fecd4b 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -481,9 +481,6 @@ int fgMainInit( int argc, char **argv ) return EXIT_SUCCESS; } - // launcher needs to know the aircraft paths in use - fgInitAircraftPaths(false); - #if defined(HAVE_QT) bool showLauncher = flightgear::Options::checkForArg(argc, argv, "launcher"); // an Info.plist bundle can't define command line arguments, but it can set @@ -497,6 +494,7 @@ int fgMainInit( int argc, char **argv ) } } #endif + fgInitAircraftPaths(false); configResult = fgInitAircraft(false); if (configResult == flightgear::FG_OPTIONS_ERROR) { -- 2.39.5