1
0
Fork 0

Split the launcher main window into its own file.

Reduces QtLauncher.cxx down to the public API and the static helper
methods; the main window lives in its own file.
This commit is contained in:
James Turner 2017-02-19 16:19:13 -08:00
parent 4234876789
commit 5c713a6b55
9 changed files with 1402 additions and 1356 deletions

View file

@ -92,7 +92,8 @@ if (HAVE_QT)
add_library(fglauncher QtLauncher.cxx
QtLauncher.hxx
QtLauncher_private.hxx
LauncherMainWindow.hxx
LauncherMainWindow.cxx
BaseDiagram.cxx
BaseDiagram.hxx
AirportDiagram.cxx
@ -147,6 +148,8 @@ if (HAVE_QT)
LauncherArgumentTokenizer.hxx
AircraftSearchFilterModel.cxx
AircraftSearchFilterModel.hxx
DefaultAircraftLocator.cxx
DefaultAircraftLocator.hxx
${uic_sources}
${qrc_sources})

View file

@ -0,0 +1,68 @@
#include "DefaultAircraftLocator.hxx"
#include <simgear/props/props_io.hxx>
#include <simgear/debug/logstream.hxx>
#include <Main/globals.hxx>
static SGPropertyNode_ptr loadXMLDefaults()
{
SGPropertyNode_ptr root(new SGPropertyNode);
const SGPath defaultsXML = globals->get_fg_root() / "defaults.xml";
readProperties(defaultsXML, root);
if (!root->hasChild("sim")) {
SG_LOG(SG_GUI, SG_POPUP, "Failed to find /sim node in defaults.xml, broken");
return SGPropertyNode_ptr();
}
return root;
}
namespace flightgear
{
std::string defaultAirportICAO()
{
SGPropertyNode_ptr root = loadXMLDefaults();
if (!root) {
return std::string();
}
std::string airportCode = root->getStringValue("/sim/presets/airport-id");
return airportCode;
}
DefaultAircraftLocator::DefaultAircraftLocator()
{
SGPropertyNode_ptr root = loadXMLDefaults();
if (root) {
_aircraftId = root->getStringValue("/sim/aircraft");
} else {
SG_LOG(SG_GUI, SG_WARN, "failed to load default aircraft identifier");
_aircraftId = "ufo"; // last ditch fallback
}
_aircraftId += "-set.xml";
const SGPath rootAircraft = globals->get_fg_root() / "Aircraft";
visitDir(rootAircraft, 0);
}
SGPath DefaultAircraftLocator::foundPath() const
{
return _foundPath;
}
AircraftDirVistorBase::VisitResult
DefaultAircraftLocator::visit(const SGPath& p)
{
if (p.file() == _aircraftId) {
_foundPath = p;
return VISIT_DONE;
}
return VISIT_CONTINUE;
}
} // of namespace flightgear

View file

@ -0,0 +1,35 @@
#ifndef DEFAULTAIRCRAFTLOCATOR_HXX
#define DEFAULTAIRCRAFTLOCATOR_HXX
#include <string>
#include <simgear/misc/sg_path.hxx>
#include <Main/AircraftDirVisitorBase.hxx>
namespace flightgear
{
std::string defaultAirportICAO();
/**
* we don't want to rely on the main AircraftModel threaded scan, to find the
* default aircraft, so we do a synchronous scan here, on the assumption that
* FG_DATA/Aircraft only contains a handful of entries.
*/
class DefaultAircraftLocator : public AircraftDirVistorBase
{
public:
DefaultAircraftLocator();
SGPath foundPath() const;
private:
virtual VisitResult visit(const SGPath& p) override;
std::string _aircraftId;
SGPath _foundPath;
};
}
#endif // DEFAULTAIRCRAFTLOCATOR_HXX

View file

@ -1,4 +1,4 @@
// QtLauncher_private.hxx - GUI launcher dialog using Qt5
// LauncherMainWindow.hxx - GUI launcher dialog using Qt5
//
// Written by James Turner, started October 2015.
//
@ -18,8 +18,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#ifndef FG_QTLAUNCHER_PRIVATE_HXX
#define FG_QTLAUNCHER_PRIVATE_HXX
#ifndef LAUNCHER_MAIN_WINDOW_HXX
#define LAUNCHER_MAIN_WINDOW_HXX
#include <QMainWindow>
#include <QScopedPointer>
@ -43,19 +43,15 @@ class QCheckBox;
class CatalogListModel;
class RemoteXMLRequest;
class QtLauncher : public QMainWindow
class LauncherMainWindow : public QMainWindow
{
Q_OBJECT
public:
QtLauncher();
virtual ~QtLauncher();
LauncherMainWindow();
virtual ~LauncherMainWindow();
bool execInApp();
static void setSceneryPaths();
static void restartTheApp(QStringList fgArgs);
bool wasRejected();
protected:
virtual void closeEvent(QCloseEvent *event) override;
@ -110,6 +106,8 @@ private slots:
void onPackagesNeedUpdate(bool yes);
void onClickToolboxButton();
void setSceneryPaths();
void onAircraftPathsChanged();
private:
@ -167,4 +165,4 @@ private:
QVariantList m_recentLocations;
};
#endif // of FG_QTLAUNCHER_PRIVATE_HXX
#endif // of LAUNCHER_MAIN_WINDOW_HXX

View file

@ -10,8 +10,8 @@
#include "CatalogListModel.hxx"
#include "AddCatalogDialog.hxx"
#include "AircraftModel.hxx"
#include "QtLauncher_private.hxx"
#include "InstallSceneryDialog.hxx"
#include "QtLauncher.hxx"
#include <Main/options.hxx>
#include <Main/globals.hxx>
@ -358,7 +358,7 @@ void AddOnsPage::onChangeDataDir()
settings.setValue("fg-root", "!ask");
} // scope the ensure settings are written nicely
QtLauncher::restartTheApp(QStringList());
flightgear::restartTheApp();
}
void AddOnsPage::onInstallScenery()

File diff suppressed because it is too large Load diff

View file

@ -36,6 +36,14 @@ namespace flightgear
bool runLauncherDialog();
bool runInAppLauncherDialog();
/**
* @brief restartTheApp quit the application and relaunch it, passing the
* --launcher flag explicitly.
*/
void restartTheApp();
void launcherSetSceneryPaths();
}
#endif // of FG_QTLAUNCHER_HXX

File diff suppressed because it is too large Load diff

View file

@ -24,6 +24,11 @@
#ifndef FG_MAIN_AIRCRAFT_DIR_VISITOR_HXX
#define FG_MAIN_AIRCRAFT_DIR_VISITOR_HXX
#include <simgear/misc/sg_dir.hxx>
#include <simgear/misc/sg_path.hxx>
#include <Main/globals.hxx>
class AircraftDirVistorBase
{
public:
@ -43,8 +48,8 @@ protected:
VisitResult visitAircraftPaths()
{
const PathList& paths(globals->get_aircraft_paths());
PathList::const_iterator it = paths.begin();
const simgear::PathList& paths(globals->get_aircraft_paths());
simgear::PathList::const_iterator it = paths.begin();
for (; it != paths.end(); ++it) {
VisitResult vr = visitDir(*it, 0);
if (vr != VISIT_CONTINUE) {