diff --git a/src/GUI/AircraftModel.cxx b/src/GUI/AircraftModel.cxx index c39c40023..a5cac436a 100644 --- a/src/GUI/AircraftModel.cxx +++ b/src/GUI/AircraftModel.cxx @@ -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()) { diff --git a/src/GUI/AircraftModel.hxx b/src/GUI/AircraftModel.hxx index 894a4f315..61322b09a 100644 --- a/src/GUI/AircraftModel.hxx +++ b/src/GUI/AircraftModel.hxx @@ -21,12 +21,13 @@ #ifndef FG_GUI_AIRCRAFT_MODEL #define FG_GUI_AIRCRAFT_MODEL -#include #include #include #include #include +#include + 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 m_items; QList m_activeVariant; + simgear::pkg::RootRef m_packageRoot; }; #endif // of FG_GUI_AIRCRAFT_MODEL diff --git a/src/GUI/QtLauncher.cxx b/src/GUI/QtLauncher.cxx index 1bd515e3c..b1fd032ee 100644 --- a/src/GUI/QtLauncher.cxx +++ b/src/GUI/QtLauncher.cxx @@ -46,6 +46,7 @@ #include #include #include +#include #include #include "ui_Launcher.h" @@ -58,7 +59,9 @@ #include #include // for parking #include
+#include
#include +#include 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" diff --git a/src/GUI/QtLauncher.hxx b/src/GUI/QtLauncher.hxx index c8cd53a53..e4557cb54 100644 --- a/src/GUI/QtLauncher.hxx +++ b/src/GUI/QtLauncher.hxx @@ -25,6 +25,7 @@ #include #include #include +#include #include @@ -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]; }; diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index c18e2d75d..cfb31f25b 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -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 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 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 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/fg_init.hxx b/src/Main/fg_init.hxx index 4162af9aa..8b741c261 100644 --- a/src/Main/fg_init.hxx +++ b/src/Main/fg_init.hxx @@ -71,6 +71,9 @@ void fgStartReposition(); void fgStartNewReset(); +// setup the package system including the global root +void fgInitPackageRoot(); + #endif // _FG_INIT_HXX diff --git a/src/Network/HTTPClient.cxx b/src/Network/HTTPClient.cxx index 8cac7361c..f60817877 100644 --- a/src/Network/HTTPClient.cxx +++ b/src/Network/HTTPClient.cxx @@ -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, diff --git a/src/Network/HTTPClient.hxx b/src/Network/HTTPClient.hxx index c20fe7f9e..262a2e40b 100644 --- a/src/Network/HTTPClient.hxx +++ b/src/Network/HTTPClient.hxx @@ -42,6 +42,7 @@ public: virtual void update(double); private: + bool _inited; std::auto_ptr _http; };