]> git.mxchange.org Git - flightgear.git/commitdiff
Start wiring package manager into the launcher.
authorJames Turner <zakalawe@mac.com>
Tue, 10 Mar 2015 08:30:55 +0000 (08:30 +0000)
committerJames Turner <zakalawe@mac.com>
Wed, 11 Mar 2015 17:09:59 +0000 (17:09 +0000)
src/GUI/AircraftModel.cxx
src/GUI/AircraftModel.hxx
src/GUI/QtLauncher.cxx
src/GUI/QtLauncher.hxx
src/Main/fg_init.cxx
src/Main/fg_init.hxx
src/Network/HTTPClient.cxx
src/Network/HTTPClient.hxx

index c39c400236e25be7658f47cd4e3c367a632e2497..a5cac436a8216455dc3b7f0a948ab19672388856 100644 (file)
@@ -281,8 +281,9 @@ private:
     bool m_done;
 };
 
-AircraftItemModel::AircraftItemModel(QObject* pr) :
-    QAbstractListModel(pr)
+AircraftItemModel::AircraftItemModel(QObject* pr, simgear::pkg::RootRef& rootRef) :
+    QAbstractListModel(pr),
+    m_packageRoot(rootRef)
 {
     QStringList dirs;
     Q_FOREACH(std::string ap, globals->get_aircraft_paths()) {
index 894a4f31534ba02409e135ffeae21f9d607537ca..61322b09a1eed7038413cd748c753ab903a1507c 100644 (file)
 #ifndef FG_GUI_AIRCRAFT_MODEL
 #define FG_GUI_AIRCRAFT_MODEL
 
-#include <QThread>
 #include <QAbstractListModel>
 #include <QDateTime>
 #include <QDir>
 #include <QPixmap>
 
+#include <simgear/package/Root.hxx>
+
 const int AircraftPathRole = Qt::UserRole + 1;
 const int AircraftAuthorsRole = Qt::UserRole + 2;
 const int AircraftVariantRole = Qt::UserRole + 3;
@@ -68,7 +69,7 @@ class AircraftItemModel : public QAbstractListModel
 {
     Q_OBJECT
 public:
-    AircraftItemModel(QObject* pr);
+    AircraftItemModel(QObject* pr, simgear::pkg::RootRef& root);
 
     ~AircraftItemModel();
 
@@ -92,6 +93,7 @@ private:
     AircraftScanThread* m_scanThread;
     QList<AircraftItem*> m_items;
     QList<quint32> m_activeVariant;
+    simgear::pkg::RootRef m_packageRoot;
 };
 
 #endif // of FG_GUI_AIRCRAFT_MODEL
index 1bd515e3c7aad341c1f47b9aec84283433425a9e..b1fd032eede4a7b0bb5889797354cafa8cbfcd8f 100644 (file)
@@ -46,6 +46,7 @@
 #include <simgear/timing/timestamp.hxx>
 #include <simgear/props/props_io.hxx>
 #include <simgear/structure/exception.hxx>
+#include <simgear/structure/subsystem_mgr.hxx>
 #include <simgear/misc/sg_path.hxx>
 
 #include "ui_Launcher.h"
@@ -58,7 +59,9 @@
 #include <Airports/airport.hxx>
 #include <Airports/dynamics.hxx> // for parking
 #include <Main/options.hxx>
+#include <Main/fg_init.hxx>
 #include <Viewer/WindowBuilder.hxx>
+#include <Network/HTTPClient.hxx>
 
 using namespace flightgear;
 
@@ -374,6 +377,12 @@ QtLauncher::QtLauncher() :
         m_ratingFilters[i] = 3;
     }
 
+    m_subsystemIdleTimer = new QTimer(this);
+    m_subsystemIdleTimer->setInterval(0);
+    connect(m_subsystemIdleTimer, &QTimer::timeout,
+            this, &QtLauncher::onSubsytemIdleTimeout);
+    m_subsystemIdleTimer->start();
+
     m_airportsModel = new AirportSearchModel;
     m_ui->searchList->setModel(m_airportsModel);
     connect(m_ui->searchList, &QListView::clicked,
@@ -391,7 +400,18 @@ QtLauncher::QtLauncher() :
 
     // create and configure the proxy model
     m_aircraftProxy = new AircraftProxyModel(this);
-    m_aircraftProxy->setSourceModel(new AircraftItemModel(this));
+
+    fgInitPackageRoot();
+    simgear::pkg::RootRef r(globals->packageRoot());
+
+    FGHTTPClient* http = new FGHTTPClient;
+    globals->add_subsystem("http", http);
+
+    // we guard against re-init in the global phase; bind and postinit
+    // will happen as normal
+    http->init();
+
+    m_aircraftProxy->setSourceModel(new AircraftItemModel(this, r));
 
     m_aircraftProxy->setFilterCaseSensitivity(Qt::CaseInsensitive);
     m_aircraftProxy->setSortCaseSensitivity(Qt::CaseInsensitive);
@@ -1029,5 +1049,10 @@ void QtLauncher::onRembrandtToggled(bool b)
     m_ui->msaaCheckbox->setEnabled(!b);
 }
 
+void QtLauncher::onSubsytemIdleTimeout()
+{
+    globals->get_subsystem_mgr()->update(0.0);
+}
+
 #include "QtLauncher.moc"
 
index c8cd53a535c6832a7189672eaeb3fa9f469c642d..e4557cb54f87a8be7567ba47966086f56ac52370 100644 (file)
@@ -25,6 +25,7 @@
 #include <QScopedPointer>
 #include <QStringList>
 #include <QModelIndex>
+#include <QTimer>
 
 #include <Airports/airport.hxx>
 
@@ -76,6 +77,8 @@ private slots:
     void onRemoveSceneryPath();
 
     void onRembrandtToggled(bool b);
+
+    void onSubsytemIdleTimeout();
 private:
     void setAirport(FGAirportRef ref);
     void updateSelectedAircraft();
@@ -98,6 +101,7 @@ private:
     QStringList m_recentAircraft,
         m_recentAirports;
     QString m_customAircraftDir;
+    QTimer* m_subsystemIdleTimer;
 
     int m_ratingFilters[4];
 };
index c18e2d75de07eaaaaddd4c109aa9cc9a70669696..cfb31f25b1b86764be60415942dcb9eabff12ea2 100644 (file)
@@ -503,17 +503,8 @@ static void initAircraftDirsNasalSecurity()
 
 void fgInitAircraftPaths(bool reinit)
 {
-  if (!reinit) {
-      // there is some debate if we should be using FG_HOME here (hidden
-      // location) vs a user-visible location inside Documents (especially on
-      // Windows and Mac). Really this location should be managed by FG, not
-      // the user, but it can potentially grow large.
-      SGPath packageAircraftDir = globals->get_fg_home();
-      packageAircraftDir.append("Aircraft");
-
-      SGSharedPtr<Root> pkgRoot(new Root(packageAircraftDir, FLIGHTGEAR_VERSION));
-      // set the http client later (too early in startup right now)
-      globals->setPackageRoot(pkgRoot);
+  if (!globals->packageRoot()) {
+      fgInitPackageRoot();
   }
 
   SGSharedPtr<Root> pkgRoot(globals->packageRoot());
@@ -724,9 +715,12 @@ void fgCreateSubsystems(bool duringReset) {
             globals->get_props()) ) {
        throw sg_io_exception("Error loading materials file", mpath);
     }
-    
-    globals->add_subsystem( "http", new FGHTTPClient );
-    
+
+    // may exist already due to GUI startup
+    if (!globals->get_subsystem("http")) {
+        globals->add_subsystem( "http", new FGHTTPClient );
+    }
+
     ////////////////////////////////////////////////////////////////////
     // Initialize the scenery management subsystem.
     ////////////////////////////////////////////////////////////////////
@@ -1115,3 +1109,21 @@ void fgStartNewReset()
     fgSetBool("/sim/sceneryloaded",false);
 }
 
+void fgInitPackageRoot()
+{
+    if (globals->packageRoot()) {
+        return;
+    }
+    
+    // there is some debate if we should be using FG_HOME here (hidden
+    // location) vs a user-visible location inside Documents (especially on
+    // Windows and Mac). Really this location should be managed by FG, not
+    // the user, but it can potentially grow large.
+    SGPath packageAircraftDir = globals->get_fg_home();
+    packageAircraftDir.append("Aircraft");
+
+    SGSharedPtr<Root> pkgRoot(new Root(packageAircraftDir, FLIGHTGEAR_VERSION));
+    // set the http client later (too early in startup right now)
+    globals->setPackageRoot(pkgRoot);
+
+}
index 4162af9aafcddf0e6db2e6054a159ddb8faa4e47..8b741c26136ca131d833df2238277e95bdffa487 100644 (file)
@@ -71,6 +71,9 @@ void fgStartReposition();
 
 void fgStartNewReset();
 
+// setup the package system including the global root
+void fgInitPackageRoot();
+
 #endif // _FG_INIT_HXX
 
 
index 8cac7361cc51f82fbcce69cfdd466e09a151ee67..f60817877fa7018995dccb722039d5d79059ffda 100644 (file)
@@ -110,7 +110,8 @@ public:
 
 } // of anonymous namespace
 
-FGHTTPClient::FGHTTPClient()
+FGHTTPClient::FGHTTPClient() :
+    _inited(false)
 {
 }
 
@@ -120,6 +121,12 @@ FGHTTPClient::~FGHTTPClient()
 
 void FGHTTPClient::init()
 {
+    // launcher may need to setup HTTP access abnormally early, so
+    // guard against duplicate inits
+    if (_inited) {
+        return;
+    }
+
   _http.reset(new simgear::HTTP::Client);
   
   std::string proxyHost(fgGetString("/sim/presets/proxy/host"));
@@ -152,6 +159,8 @@ void FGHTTPClient::init()
     // start a refresh now
     packageRoot->refresh();
   }
+
+    _inited = true;
 }
 
 static naRef f_package_existingInstall( pkg::Package& pkg,
index c20fe7f9e283e81e645b56a62d5583c72f729ceb..262a2e40b9daa00574d4cb5d9d5808762bcb098c 100644 (file)
@@ -42,6 +42,7 @@ public:
     virtual void update(double);
 
 private:
+    bool _inited;
     std::auto_ptr<simgear::HTTP::Client> _http;
 };