]> git.mxchange.org Git - flightgear.git/commitdiff
Improve download-dir behaviour.
authorJames Turner <zakalawe@mac.com>
Thu, 24 Mar 2016 15:10:06 +0000 (15:10 +0000)
committerJames Turner <zakalawe@mac.com>
Thu, 24 Mar 2016 15:10:06 +0000 (15:10 +0000)
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
src/GUI/AircraftModel.hxx
src/GUI/QtLauncher.cxx
src/Main/fg_init.cxx
src/Main/main.cxx

index 18f9e13836d6bc6b8cc53017164e90813d862169..92934790fcb6b5d2b19c95a50637d06263318948 100644 (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;
index 967f974a39b63f407e848794ead7e8462543862e..90c243ceb41a06df2b422cd8b35209a088ed7ed3 100644 (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();
index c95fc907a46e6b2e813950d8e9dc08e976255e0c..0d32aa9f024d2c7375a8df7f3e70cf05f1288e28 100644 (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();
 
index 0c47e860b5962d0b53c06caf05d09e9dada1728d..e7c681f485048fe9f7e3139262303bf9ca585fb7 100644 (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);
index 0e683a69af66c6602a9ef379b4a630210bee4116..791fecd4bf46d982ad7f270d8f01ec19ef9605ed 100644 (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) {