1
0
Fork 0

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.
This commit is contained in:
James Turner 2016-03-24 15:10:06 +00:00
parent 733e3b3f0c
commit 5baca8598f
5 changed files with 66 additions and 17 deletions

View file

@ -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;

View file

@ -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();

View file

@ -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<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();

View file

@ -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<Root> pkgRoot(new Root(packageAircraftDir, FLIGHTGEAR_VERSION));
// set the http client later (too early in startup right now)
globals->setPackageRoot(pkgRoot);

View file

@ -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) {