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()
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;
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
dlg.show();
int appResult = qApp->exec();
- qDebug() << "App result:" << appResult;
if (appResult < 0) {
return false; // quit
}
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);
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()
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<FGHTTPClient>()->shutdown();
+ globals->setPackageRoot(simgear::pkg::RootRef());
+
+ // create new root with updated download-dir value
+ fgInitPackageRoot();
+
+ globals->get_subsystem<FGHTTPClient>()->init();
+ }
+
// re-scan the aircraft list
- QSettings settings;
+ m_aircraftModel->setPackageRoot(globals->packageRoot());
m_aircraftModel->setPaths(settings.value("aircraft-paths").toStringList());
m_aircraftModel->scanDirs();
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<Root> pkgRoot(new Root(packageAircraftDir, FLIGHTGEAR_VERSION));
// set the http client later (too early in startup right now)
globals->setPackageRoot(pkgRoot);
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
}
}
#endif
+ fgInitAircraftPaths(false);
configResult = fgInitAircraft(false);
if (configResult == flightgear::FG_OPTIONS_ERROR) {