1
0
Fork 0

Start wiring package manager into the launcher.

This commit is contained in:
James Turner 2015-03-10 08:30:55 +00:00
parent 68efa84b3a
commit 11c2623dec
8 changed files with 77 additions and 20 deletions

View 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()) {

View file

@ -21,12 +21,13 @@
#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

View 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"

View 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];
};

View 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);
}

View file

@ -71,6 +71,9 @@ void fgStartReposition();
void fgStartNewReset();
// setup the package system including the global root
void fgInitPackageRoot();
#endif // _FG_INIT_HXX

View 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,

View file

@ -42,6 +42,7 @@ public:
virtual void update(double);
private:
bool _inited;
std::auto_ptr<simgear::HTTP::Client> _http;
};