2017-02-19 16:19:13 -08:00
|
|
|
#include "LauncherMainWindow.hxx"
|
|
|
|
|
|
|
|
// Qt headers
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QSettings>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QMenu>
|
2017-02-21 11:01:06 +00:00
|
|
|
#include <QMenuBar>
|
2018-03-11 11:49:38 +00:00
|
|
|
#include <QPushButton>
|
2017-02-21 11:01:06 +00:00
|
|
|
|
2017-10-13 17:48:24 +02: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 13:25:33 +01:00
|
|
|
#include "version.h"
|
2017-02-19 16:19:13 -08: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 22:53:26 +02: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 16:41:10 +01:00
|
|
|
#include "LocationController.hxx"
|
2017-02-19 16:19:13 -08:00
|
|
|
|
|
|
|
|
|
|
|
extern void restartTheApp(QStringList fgArgs);
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
LauncherMainWindow::LauncherMainWindow() :
|
2018-06-22 12:09:35 +01:00
|
|
|
QQuickView()
|
2017-02-19 16:19:13 -08:00
|
|
|
{
|
2018-06-22 12:09:35 +01:00
|
|
|
setTitle("FlightGear " FLIGHTGEAR_VERSION);
|
2017-04-13 13:01:29 +01:00
|
|
|
|
2018-06-22 12:09:35 +01:00
|
|
|
m_controller = new LauncherController(this, this);
|
2018-03-22 12:24:57 +00:00
|
|
|
m_controller->initQML();
|
|
|
|
|
2018-06-22 12:09:35 +01:00
|
|
|
#if defined(Q_OS_MAC)
|
|
|
|
QMenuBar* mb = new QMenuBar();
|
2017-02-21 11:01:06 +00:00
|
|
|
|
2018-06-22 12:09:35 +01:00
|
|
|
QMenu* toolsMenu = mb->addMenu(tr("Tools"));
|
|
|
|
QAction* restoreDefaultsAction = toolsMenu->addAction(tr("Restore defaults..."));
|
|
|
|
connect(restoreDefaultsAction, &QAction::triggered,
|
|
|
|
this, &LauncherMainWindow::onRestoreDefaults);
|
2017-02-19 16:19:13 -08:00
|
|
|
|
2018-06-22 12:09:35 +01:00
|
|
|
QAction* changeDataAction = toolsMenu->addAction(tr("Select data files location..."));
|
|
|
|
connect(changeDataAction, &QAction::triggered,
|
|
|
|
this, &LauncherMainWindow::onChangeDataDir);
|
2017-02-19 16:19:13 -08:00
|
|
|
|
2018-06-22 12:09:35 +01:00
|
|
|
QAction* viewCommandLineAction = toolsMenu->addAction(tr("View command-line"));
|
|
|
|
connect(viewCommandLineAction, &QAction::triggered,
|
|
|
|
m_controller, &LauncherController::viewCommandLine);
|
|
|
|
#endif
|
2017-02-19 16:19:13 -08:00
|
|
|
|
|
|
|
QAction* qa = new QAction(this);
|
|
|
|
qa->setShortcut(QKeySequence("Ctrl+Q"));
|
|
|
|
connect(qa, &QAction::triggered, this, &LauncherMainWindow::onQuit);
|
2018-03-22 12:24:57 +00:00
|
|
|
|
|
|
|
m_controller->restoreSettings();
|
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 12:09:35 +01:00
|
|
|
setResizeMode(QQuickView::SizeRootObjectToView);
|
|
|
|
engine()->addImportPath("qrc:///");
|
2018-03-20 16:32:31 +00:00
|
|
|
|
2018-06-22 12:09:35 +01: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 12:09:35 +01:00
|
|
|
auto weatherScenariosModel = new flightgear::WeatherScenariosModel(this);
|
|
|
|
ctx->setContextProperty("_weatherScenarios", weatherScenariosModel);
|
2017-02-19 16:19:13 -08:00
|
|
|
|
2018-06-22 12:09:35 +01:00
|
|
|
setSource(QUrl("qrc:///qml/Launcher.qml"));
|
2017-02-21 11:01:06 +00:00
|
|
|
}
|
2017-02-19 16:19:13 -08:00
|
|
|
|
2018-06-22 12:09:35 +01: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 12:09:35 +01:00
|
|
|
#endif
|
2018-03-22 09:32:30 +00:00
|
|
|
|
2018-03-22 12:24:57 +00:00
|
|
|
LauncherMainWindow::~LauncherMainWindow()
|
|
|
|
{
|
2017-02-19 16:19:13 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool LauncherMainWindow::execInApp()
|
|
|
|
{
|
2018-06-23 17:55:39 +01:00
|
|
|
m_controller->setInAppMode();
|
|
|
|
|
2017-02-19 16:19:13 -08:00
|
|
|
show();
|
|
|
|
|
2018-06-23 17:55:39 +01:00
|
|
|
while (m_controller->keepRunningInAppMode()) {
|
2017-02-19 16:19:13 -08:00
|
|
|
qApp->processEvents();
|
|
|
|
}
|
|
|
|
|
2018-06-23 17:55:39 +01:00
|
|
|
return m_controller->inAppResult();
|
2017-02-19 16:19:13 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void LauncherMainWindow::onQuit()
|
|
|
|
{
|
2018-06-23 17:55:39 +01:00
|
|
|
qApp->exit(-1);
|
2017-02-19 16:19:13 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void LauncherMainWindow::onRestoreDefaults()
|
|
|
|
{
|
2018-06-22 12:09:35 +01:00
|
|
|
QMessageBox mbox;
|
2017-02-19 16:19:13 -08:00
|
|
|
mbox.setText(tr("Restore all settings to defaults?"));
|
|
|
|
mbox.setInformativeText(tr("Restoring settings to their defaults may affect available add-ons such as scenery or aircraft."));
|
|
|
|
QPushButton* quitButton = mbox.addButton(tr("Restore and restart now"), QMessageBox::YesRole);
|
|
|
|
mbox.addButton(QMessageBox::Cancel);
|
|
|
|
mbox.setDefaultButton(QMessageBox::Cancel);
|
|
|
|
mbox.setIconPixmap(QPixmap(":/app-icon-large"));
|
|
|
|
|
|
|
|
mbox.exec();
|
|
|
|
if (mbox.clickedButton() != quitButton) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
settings.clear();
|
|
|
|
settings.setValue("restore-defaults-on-run", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
flightgear::restartTheApp();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-21 11:01:06 +00:00
|
|
|
void LauncherMainWindow::onChangeDataDir()
|
|
|
|
{
|
|
|
|
QString currentLocText;
|
|
|
|
QSettings settings;
|
|
|
|
QString root = settings.value("fg-root").toString();
|
|
|
|
if (root.isNull()) {
|
|
|
|
currentLocText = tr("Currently the built-in data files are being used");
|
|
|
|
} else {
|
|
|
|
currentLocText = tr("Currently using location: %1").arg(root);
|
|
|
|
}
|
|
|
|
|
2018-06-22 12:09:35 +01:00
|
|
|
QMessageBox mbox;
|
2017-02-21 11:01:06 +00:00
|
|
|
mbox.setText(tr("Change the data files used by FlightGear?"));
|
|
|
|
mbox.setInformativeText(tr("FlightGear requires additional files to operate. "
|
|
|
|
"(Also called the base package, or fg-data) "
|
|
|
|
"You can restart FlightGear and choose a "
|
|
|
|
"different data files location, or restore the default setting. %1").arg(currentLocText));
|
|
|
|
QPushButton* quitButton = mbox.addButton(tr("Restart FlightGear now"), QMessageBox::YesRole);
|
|
|
|
mbox.addButton(QMessageBox::Cancel);
|
|
|
|
mbox.setDefaultButton(QMessageBox::Cancel);
|
|
|
|
mbox.setIconPixmap(QPixmap(":/app-icon-large"));
|
|
|
|
|
|
|
|
mbox.exec();
|
|
|
|
if (mbox.clickedButton() != quitButton) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
// set the option to the magic marker value
|
|
|
|
settings.setValue("fg-root", "!ask");
|
|
|
|
} // scope the ensure settings are written nicely
|
|
|
|
|
|
|
|
flightgear::restartTheApp();
|
|
|
|
}
|
|
|
|
|