2017-02-20 00:19:13 +00:00
|
|
|
#include "LauncherMainWindow.hxx"
|
|
|
|
|
|
|
|
// Qt headers
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QSettings>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QMenu>
|
2017-02-21 11:01:06 +00:00
|
|
|
#include <QMenuBar>
|
|
|
|
|
2017-10-13 15:48:24 +00:00
|
|
|
#include <QQuickItem>
|
2017-02-21 11:01:06 +00:00
|
|
|
#include <QQmlEngine>
|
|
|
|
#include <QQmlComponent>
|
|
|
|
#include <QQmlContext>
|
2018-03-20 16:32:31 +00:00
|
|
|
#include <QQmlError>
|
2017-02-21 11:01:06 +00:00
|
|
|
|
2017-05-16 12:25:33 +00:00
|
|
|
#include "version.h"
|
2017-02-20 00:19:13 +00:00
|
|
|
|
|
|
|
// launcher headers
|
|
|
|
#include "QtLauncher.hxx"
|
2018-03-16 22:01:21 +00:00
|
|
|
#include "DefaultAircraftLocator.hxx"
|
|
|
|
#include "LaunchConfig.hxx"
|
2018-03-22 12:24:57 +00:00
|
|
|
#include "AircraftModel.hxx"
|
2017-10-09 20:53:26 +00:00
|
|
|
#include "LocalAircraftCache.hxx"
|
2018-03-22 12:24:57 +00:00
|
|
|
#include "LauncherController.hxx"
|
2018-03-16 22:01:21 +00:00
|
|
|
#include "AddOnsController.hxx"
|
2018-05-07 15:41:10 +00:00
|
|
|
#include "LocationController.hxx"
|
2017-02-20 00:19:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
LauncherMainWindow::LauncherMainWindow() :
|
2018-06-22 11:09:35 +00:00
|
|
|
QQuickView()
|
2017-02-20 00:19:13 +00:00
|
|
|
{
|
2018-06-22 11:09:35 +00:00
|
|
|
setTitle("FlightGear " FLIGHTGEAR_VERSION);
|
2017-04-13 12:01:29 +00:00
|
|
|
|
2018-06-22 11:09:35 +00:00
|
|
|
m_controller = new LauncherController(this, this);
|
2018-03-22 12:24:57 +00:00
|
|
|
m_controller->initQML();
|
|
|
|
|
2018-06-22 11:09:35 +00:00
|
|
|
#if defined(Q_OS_MAC)
|
|
|
|
QMenuBar* mb = new QMenuBar();
|
2017-02-21 11:01:06 +00:00
|
|
|
|
2018-06-27 22:06:39 +00:00
|
|
|
QMenu* fileMenu = mb->addMenu(tr("File"));
|
|
|
|
QAction* openAction = fileMenu->addAction(tr("Open saved configuration..."));
|
|
|
|
connect(openAction, &QAction::triggered,
|
|
|
|
m_controller, &LauncherController::openConfig);
|
|
|
|
|
|
|
|
QAction* saveAction = fileMenu->addAction(tr("Save configuration as..."));
|
|
|
|
connect(saveAction, &QAction::triggered,
|
|
|
|
m_controller, &LauncherController::saveConfigAs);
|
|
|
|
|
2018-06-22 11:09:35 +00:00
|
|
|
QMenu* toolsMenu = mb->addMenu(tr("Tools"));
|
|
|
|
QAction* restoreDefaultsAction = toolsMenu->addAction(tr("Restore defaults..."));
|
|
|
|
connect(restoreDefaultsAction, &QAction::triggered,
|
2018-06-26 16:13:28 +00:00
|
|
|
m_controller, &LauncherController::requestRestoreDefaults);
|
2017-02-20 00:19:13 +00:00
|
|
|
|
2018-06-22 11:09:35 +00:00
|
|
|
QAction* changeDataAction = toolsMenu->addAction(tr("Select data files location..."));
|
|
|
|
connect(changeDataAction, &QAction::triggered,
|
2018-06-26 16:13:28 +00:00
|
|
|
m_controller, &LauncherController::requestChangeDataPath);
|
2017-02-20 00:19:13 +00:00
|
|
|
|
2018-06-22 11:09:35 +00:00
|
|
|
QAction* viewCommandLineAction = toolsMenu->addAction(tr("View command-line"));
|
|
|
|
connect(viewCommandLineAction, &QAction::triggered,
|
|
|
|
m_controller, &LauncherController::viewCommandLine);
|
|
|
|
#endif
|
2017-02-20 00:19:13 +00:00
|
|
|
|
|
|
|
QAction* qa = new QAction(this);
|
|
|
|
qa->setShortcut(QKeySequence("Ctrl+Q"));
|
2018-06-26 16:13:28 +00:00
|
|
|
connect(qa, &QAction::triggered, m_controller, &LauncherController::quit);
|
2018-03-22 12:24:57 +00:00
|
|
|
|
2018-06-27 22:06:39 +00:00
|
|
|
m_controller->initialRestoreSettings();
|
2018-03-16 22:01:21 +00:00
|
|
|
flightgear::launcherSetSceneryPaths();
|
|
|
|
|
|
|
|
auto addOnsCtl = new AddOnsController(this);
|
2018-03-11 11:49:38 +00:00
|
|
|
|
2018-03-22 12:24:57 +00:00
|
|
|
////////////
|
|
|
|
#if defined(Q_OS_WIN)
|
|
|
|
const QString osName("win");
|
|
|
|
#elif defined(Q_OS_MAC)
|
|
|
|
const QString osName("mac");
|
|
|
|
#else
|
|
|
|
const QString osName("unix");
|
|
|
|
#endif
|
2018-03-11 11:49:38 +00:00
|
|
|
|
2018-06-22 11:09:35 +00:00
|
|
|
setResizeMode(QQuickView::SizeRootObjectToView);
|
|
|
|
engine()->addImportPath("qrc:///");
|
2018-03-20 16:32:31 +00:00
|
|
|
|
2018-06-22 11:09:35 +00:00
|
|
|
QQmlContext* ctx = rootContext();
|
|
|
|
ctx->setContextProperty("_launcher", m_controller);
|
|
|
|
ctx->setContextProperty("_addOns", addOnsCtl);
|
|
|
|
ctx->setContextProperty("_config", m_controller->config());
|
|
|
|
ctx->setContextProperty("_location", m_controller->location());
|
|
|
|
ctx->setContextProperty("_osName", osName);
|
2018-03-11 11:49:38 +00:00
|
|
|
|
2018-06-22 11:09:35 +00:00
|
|
|
auto weatherScenariosModel = new flightgear::WeatherScenariosModel(this);
|
|
|
|
ctx->setContextProperty("_weatherScenarios", weatherScenariosModel);
|
2017-02-20 00:19:13 +00:00
|
|
|
|
2018-06-22 11:09:35 +00:00
|
|
|
setSource(QUrl("qrc:///qml/Launcher.qml"));
|
2018-06-26 16:13:28 +00:00
|
|
|
|
|
|
|
setMinimumSize(QSize(300, 400));
|
2017-02-21 11:01:06 +00:00
|
|
|
}
|
2017-02-20 00:19:13 +00:00
|
|
|
|
2018-06-22 11:09:35 +00:00
|
|
|
#if 0
|
2018-03-20 16:32:31 +00:00
|
|
|
void LauncherMainWindow::onQuickStatusChanged(QQuickWidget::Status status)
|
|
|
|
{
|
|
|
|
if (status == QQuickWidget::Error) {
|
|
|
|
QQuickWidget* qw = qobject_cast<QQuickWidget*>(sender());
|
|
|
|
QString errorString;
|
|
|
|
|
|
|
|
Q_FOREACH(auto err, qw->errors()) {
|
|
|
|
errorString.append("\n" + err.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
QMessageBox::critical(this, "UI loading failures.",
|
|
|
|
tr("Problems occurred loading the user interface. This is often due to missing modules on your system. "
|
|
|
|
"Please report this error to the FlightGear developer list or forum, and take care to mention your system "
|
|
|
|
"distribution, etc. Please also include the information provided below.\n")
|
|
|
|
+ errorString);
|
|
|
|
}
|
|
|
|
}
|
2018-06-22 11:09:35 +00:00
|
|
|
#endif
|
2018-03-22 09:32:30 +00:00
|
|
|
|
2018-03-22 12:24:57 +00:00
|
|
|
LauncherMainWindow::~LauncherMainWindow()
|
|
|
|
{
|
2017-02-20 00:19:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool LauncherMainWindow::execInApp()
|
|
|
|
{
|
2018-06-23 16:55:39 +00:00
|
|
|
m_controller->setInAppMode();
|
|
|
|
|
2017-02-20 00:19:13 +00:00
|
|
|
show();
|
|
|
|
|
2018-06-23 16:55:39 +00:00
|
|
|
while (m_controller->keepRunningInAppMode()) {
|
2017-02-20 00:19:13 +00:00
|
|
|
qApp->processEvents();
|
|
|
|
}
|
|
|
|
|
2018-06-23 16:55:39 +00:00
|
|
|
return m_controller->inAppResult();
|
2017-02-20 00:19:13 +00:00
|
|
|
}
|
|
|
|
|