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>
|
|
|
|
#include <QMenu>
|
2018-03-22 12:24:57 +00:00
|
|
|
|
2018-03-11 11:49:38 +00:00
|
|
|
#include <QPushButton>
|
|
|
|
#include <QStandardItemModel>
|
|
|
|
#include <QDesktopServices>
|
2017-02-21 11:01:06 +00:00
|
|
|
|
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-02-20 00:19:13 +00:00
|
|
|
// simgear headers
|
|
|
|
#include <simgear/package/Install.hxx>
|
2017-05-18 08:17:27 +00:00
|
|
|
#include <simgear/environment/metar.hxx>
|
|
|
|
#include <simgear/structure/exception.hxx>
|
2017-02-20 00:19:13 +00:00
|
|
|
|
|
|
|
// FlightGear headers
|
|
|
|
#include <Network/HTTPClient.hxx>
|
|
|
|
#include <Main/globals.hxx>
|
|
|
|
#include <Airports/airport.hxx>
|
|
|
|
#include <Main/options.hxx>
|
|
|
|
#include <Main/fg_init.hxx>
|
|
|
|
#include <Main/fg_props.hxx>
|
2017-05-16 12:25:33 +00:00
|
|
|
#include "version.h"
|
2017-02-20 00:19:13 +00:00
|
|
|
|
|
|
|
// launcher headers
|
|
|
|
#include "QtLauncher.hxx"
|
|
|
|
#include "PathsDialog.hxx"
|
2018-03-22 12:24:57 +00:00
|
|
|
|
2017-02-21 11:01:06 +00:00
|
|
|
#include "ViewCommandLinePage.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"
|
|
|
|
#include "DefaultAircraftLocator.hxx"
|
2017-02-20 00:19:13 +00:00
|
|
|
|
|
|
|
#include "ui_Launcher.h"
|
|
|
|
|
|
|
|
|
|
|
|
extern void restartTheApp(QStringList fgArgs);
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
LauncherMainWindow::LauncherMainWindow() :
|
|
|
|
QMainWindow(),
|
2017-02-21 11:01:06 +00:00
|
|
|
m_subsystemIdleTimer(NULL)
|
2017-02-20 00:19:13 +00:00
|
|
|
{
|
|
|
|
m_ui.reset(new Ui::Launcher);
|
|
|
|
m_ui->setupUi(this);
|
|
|
|
|
2017-02-21 11:01:06 +00:00
|
|
|
QMenuBar* mb = menuBar();
|
2017-04-13 12:01:29 +00:00
|
|
|
|
|
|
|
#if !defined(Q_OS_MAC)
|
|
|
|
QMenu* fileMenu = mb->addMenu(tr("File"));
|
|
|
|
QAction* quitAction = fileMenu->addAction(tr("Exit"));
|
|
|
|
connect(quitAction, &QAction::triggered,
|
|
|
|
this, &LauncherMainWindow::onQuit);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2018-03-22 12:24:57 +00:00
|
|
|
m_controller = new LauncherController(this, m_ui->location);
|
|
|
|
m_controller->initQML();
|
|
|
|
|
|
|
|
connect(m_controller, &LauncherController::canFlyChanged,
|
|
|
|
this, &LauncherMainWindow::onCanFlyChanged);
|
|
|
|
|
|
|
|
m_ui->location->setLaunchConfig(m_controller->config());
|
|
|
|
|
2017-02-21 11:01:06 +00:00
|
|
|
QMenu* toolsMenu = mb->addMenu(tr("Tools"));
|
|
|
|
QAction* restoreDefaultsAction = toolsMenu->addAction(tr("Restore defaults..."));
|
|
|
|
connect(restoreDefaultsAction, &QAction::triggered,
|
|
|
|
this, &LauncherMainWindow::onRestoreDefaults);
|
|
|
|
|
|
|
|
QAction* changeDataAction = toolsMenu->addAction(tr("Select data files location..."));
|
|
|
|
connect(changeDataAction, &QAction::triggered,
|
|
|
|
this, &LauncherMainWindow::onChangeDataDir);
|
|
|
|
|
|
|
|
QAction* viewCommandLineAction = toolsMenu->addAction(tr("View command-line"));
|
|
|
|
connect(viewCommandLineAction, &QAction::triggered,
|
|
|
|
this, &LauncherMainWindow::onViewCommandLine);
|
2017-02-20 00:19:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
m_subsystemIdleTimer = new QTimer(this);
|
|
|
|
m_subsystemIdleTimer->setInterval(0);
|
|
|
|
connect(m_subsystemIdleTimer, &QTimer::timeout,
|
|
|
|
this, &LauncherMainWindow::onSubsytemIdleTimeout);
|
|
|
|
m_subsystemIdleTimer->start();
|
|
|
|
|
|
|
|
connect(m_ui->flyButton, SIGNAL(clicked()), this, SLOT(onRun()));
|
|
|
|
connect(m_ui->summaryButton, &QAbstractButton::clicked, this, &LauncherMainWindow::onClickToolboxButton);
|
|
|
|
connect(m_ui->aircraftButton, &QAbstractButton::clicked, this, &LauncherMainWindow::onClickToolboxButton);
|
|
|
|
connect(m_ui->locationButton, &QAbstractButton::clicked, this, &LauncherMainWindow::onClickToolboxButton);
|
|
|
|
connect(m_ui->environmentButton, &QAbstractButton::clicked, this, &LauncherMainWindow::onClickToolboxButton);
|
|
|
|
connect(m_ui->settingsButton, &QAbstractButton::clicked, this, &LauncherMainWindow::onClickToolboxButton);
|
2017-02-21 11:01:06 +00:00
|
|
|
connect(m_ui->addOnsButton, &QAbstractButton::clicked, this, &LauncherMainWindow::onClickToolboxButton);
|
2017-02-20 00:19:13 +00:00
|
|
|
|
|
|
|
QAction* qa = new QAction(this);
|
|
|
|
qa->setShortcut(QKeySequence("Ctrl+Q"));
|
|
|
|
connect(qa, &QAction::triggered, this, &LauncherMainWindow::onQuit);
|
|
|
|
addAction(qa);
|
|
|
|
|
|
|
|
|
|
|
|
AddOnsPage* addOnsPage = new AddOnsPage(NULL, globals->packageRoot());
|
|
|
|
connect(addOnsPage, &AddOnsPage::sceneryPathsChanged,
|
2018-03-22 12:24:57 +00:00
|
|
|
m_controller, &LauncherController::setSceneryPaths);
|
2017-02-21 11:01:06 +00:00
|
|
|
connect(addOnsPage, &AddOnsPage::aircraftPathsChanged,
|
2018-03-22 12:24:57 +00:00
|
|
|
m_controller, &LauncherController::onAircraftPathsChanged);
|
2017-02-21 11:01:06 +00:00
|
|
|
m_ui->stack->addWidget(addOnsPage);
|
2017-02-20 00:19:13 +00:00
|
|
|
|
2018-03-22 12:24:57 +00:00
|
|
|
connect(m_controller->baseAircraftModel(), &AircraftItemModel::catalogsRefreshed,
|
2018-02-28 17:56:40 +00:00
|
|
|
addOnsPage, &AddOnsPage::onCatalogsRefreshed);
|
|
|
|
|
2017-02-20 00:19:13 +00:00
|
|
|
|
2017-02-21 11:01:06 +00:00
|
|
|
m_viewCommandLinePage = new ViewCommandLinePage;
|
2018-03-22 12:24:57 +00:00
|
|
|
m_viewCommandLinePage->setLaunchConfig(m_controller->config());
|
2017-02-21 11:01:06 +00:00
|
|
|
m_ui->stack->addWidget(m_viewCommandLinePage);
|
|
|
|
|
2018-03-22 12:24:57 +00:00
|
|
|
QSettings settings;
|
|
|
|
restoreGeometry(settings.value("window-geometry").toByteArray());
|
|
|
|
|
|
|
|
m_controller->restoreSettings();
|
2017-02-20 00:19:13 +00:00
|
|
|
restoreSettings();
|
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
|
|
|
|
|
|
|
/////////////
|
|
|
|
// aircraft
|
|
|
|
m_ui->aircraftList->setResizeMode(QQuickWidget::SizeRootObjectToView);
|
|
|
|
|
|
|
|
m_ui->aircraftList->engine()->addImportPath("qrc:///");
|
2018-03-22 12:24:57 +00:00
|
|
|
m_ui->aircraftList->engine()->rootContext()->setContextProperty("_launcher", m_controller);
|
2018-03-20 16:32:31 +00:00
|
|
|
|
|
|
|
connect( m_ui->aircraftList, &QQuickWidget::statusChanged,
|
|
|
|
this, &LauncherMainWindow::onQuickStatusChanged);
|
2018-03-11 11:49:38 +00:00
|
|
|
m_ui->aircraftList->setSource(QUrl("qrc:///qml/AircraftList.qml"));
|
|
|
|
|
|
|
|
// settings
|
|
|
|
m_ui->settings->engine()->addImportPath("qrc:///");
|
2018-03-22 12:24:57 +00:00
|
|
|
QQmlContext* settingsContext = m_ui->settings->engine()->rootContext();
|
|
|
|
settingsContext->setContextProperty("_launcher", m_controller);
|
|
|
|
settingsContext->setContextProperty("_osName", osName);
|
|
|
|
settingsContext->setContextProperty("_config", m_controller->config());
|
|
|
|
|
2018-03-11 11:49:38 +00:00
|
|
|
m_ui->settings->setResizeMode(QQuickWidget::SizeRootObjectToView);
|
2018-03-20 16:32:31 +00:00
|
|
|
connect( m_ui->settings, &QQuickWidget::statusChanged,
|
|
|
|
this, &LauncherMainWindow::onQuickStatusChanged);
|
2018-03-11 11:49:38 +00:00
|
|
|
m_ui->settings->setSource(QUrl("qrc:///qml/Settings.qml"));
|
|
|
|
|
|
|
|
// environemnt
|
|
|
|
m_ui->environmentPage->engine()->addImportPath("qrc:///");
|
2018-03-22 12:24:57 +00:00
|
|
|
m_ui->environmentPage->engine()->rootContext()->setContextProperty("_launcher", m_controller);
|
2018-03-11 11:49:38 +00:00
|
|
|
auto weatherScenariosModel = new flightgear::WeatherScenariosModel(this);
|
|
|
|
m_ui->environmentPage->engine()->rootContext()->setContextProperty("_weatherScenarios", weatherScenariosModel);
|
2018-03-22 12:24:57 +00:00
|
|
|
m_ui->environmentPage->engine()->rootContext()->setContextProperty("_config", m_controller->config());
|
2018-03-11 11:49:38 +00:00
|
|
|
|
|
|
|
m_ui->environmentPage->setResizeMode(QQuickWidget::SizeRootObjectToView);
|
2018-03-20 16:32:31 +00:00
|
|
|
|
|
|
|
connect( m_ui->environmentPage, &QQuickWidget::statusChanged,
|
|
|
|
this, &LauncherMainWindow::onQuickStatusChanged);
|
2018-03-11 11:49:38 +00:00
|
|
|
m_ui->environmentPage->setSource(QUrl("qrc:///qml/Environment.qml"));
|
|
|
|
|
|
|
|
// summary
|
|
|
|
m_ui->summary->engine()->addImportPath("qrc:///");
|
2018-03-22 12:24:57 +00:00
|
|
|
m_ui->summary->engine()->rootContext()->setContextProperty("_launcher", m_controller);
|
|
|
|
m_ui->summary->engine()->rootContext()->setContextProperty("_config", m_controller->config());
|
|
|
|
|
2018-03-11 11:49:38 +00:00
|
|
|
m_ui->summary->setResizeMode(QQuickWidget::SizeRootObjectToView);
|
2018-03-20 16:32:31 +00:00
|
|
|
|
|
|
|
connect( m_ui->summary, &QQuickWidget::statusChanged,
|
|
|
|
this, &LauncherMainWindow::onQuickStatusChanged);
|
2018-03-11 11:49:38 +00:00
|
|
|
m_ui->summary->setSource(QUrl("qrc:///qml/Summary.qml"));
|
|
|
|
//////////////////////////
|
|
|
|
|
2017-02-21 11:01:06 +00:00
|
|
|
}
|
2017-02-20 00:19:13 +00:00
|
|
|
|
2018-03-22 12:24:57 +00:00
|
|
|
void LauncherMainWindow::restoreSettings()
|
2017-02-21 11:01:06 +00:00
|
|
|
{
|
2018-03-22 12:24:57 +00:00
|
|
|
if (!m_inAppMode) {
|
|
|
|
m_controller->setSceneryPaths();
|
|
|
|
}
|
|
|
|
}
|
2017-10-13 15:48:24 +00:00
|
|
|
|
2018-03-22 12:24:57 +00:00
|
|
|
void LauncherMainWindow::saveSettings()
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
settings.setValue("window-geometry", saveGeometry());
|
2017-02-21 11:01:06 +00:00
|
|
|
}
|
2017-02-20 00:19:13 +00:00
|
|
|
|
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-03-22 12:24:57 +00:00
|
|
|
void LauncherMainWindow::onCanFlyChanged()
|
2017-02-20 00:19:13 +00:00
|
|
|
{
|
2018-03-22 12:24:57 +00:00
|
|
|
m_ui->flyButton->setEnabled(m_controller->canFly());
|
|
|
|
}
|
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()
|
|
|
|
{
|
2017-02-21 11:01:06 +00:00
|
|
|
m_inAppMode = true;
|
|
|
|
m_ui->addOnsButton->hide();
|
|
|
|
m_ui->settingsButton->hide();
|
|
|
|
disconnect(m_ui->flyButton, SIGNAL(clicked()), this, SLOT(onRun()));
|
|
|
|
connect(m_ui->flyButton, SIGNAL(clicked()), this, SLOT(onApply()));
|
2017-02-20 00:19:13 +00:00
|
|
|
m_runInApp = true;
|
|
|
|
|
|
|
|
show();
|
|
|
|
|
|
|
|
while (m_runInApp) {
|
|
|
|
qApp->processEvents();
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_accepted;
|
|
|
|
}
|
|
|
|
|
2018-03-11 11:49:38 +00:00
|
|
|
|
2017-02-20 00:19:13 +00:00
|
|
|
|
|
|
|
void LauncherMainWindow::closeEvent(QCloseEvent *event)
|
|
|
|
{
|
|
|
|
qApp->exit(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-21 11:01:06 +00:00
|
|
|
void LauncherMainWindow::onRun()
|
|
|
|
{
|
2018-03-22 12:24:57 +00:00
|
|
|
m_controller->doRun();
|
2017-02-20 00:19:13 +00:00
|
|
|
saveSettings();
|
|
|
|
qApp->exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LauncherMainWindow::onApply()
|
|
|
|
{
|
2018-03-22 12:24:57 +00:00
|
|
|
m_controller->doApply();
|
2017-02-20 00:19:13 +00:00
|
|
|
saveSettings();
|
|
|
|
m_accepted = true;
|
|
|
|
m_runInApp = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LauncherMainWindow::onQuit()
|
|
|
|
{
|
|
|
|
if (m_inAppMode) {
|
|
|
|
m_runInApp = false;
|
|
|
|
} else {
|
|
|
|
qApp->exit(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LauncherMainWindow::onRestoreDefaults()
|
|
|
|
{
|
|
|
|
QMessageBox mbox(this);
|
|
|
|
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::onViewCommandLine()
|
|
|
|
{
|
|
|
|
m_ui->stack->setCurrentIndex(6);
|
|
|
|
Q_FOREACH (ToolboxButton* tb, findChildren<ToolboxButton*>()) {
|
|
|
|
tb->setChecked(false);
|
|
|
|
}
|
|
|
|
m_viewCommandLinePage->update();
|
|
|
|
}
|
|
|
|
|
2017-02-20 00:19:13 +00:00
|
|
|
|
|
|
|
void LauncherMainWindow::onClickToolboxButton()
|
|
|
|
{
|
|
|
|
int pageIndex = sender()->property("pageIndex").toInt();
|
|
|
|
m_ui->stack->setCurrentIndex(pageIndex);
|
|
|
|
Q_FOREACH (ToolboxButton* tb, findChildren<ToolboxButton*>()) {
|
|
|
|
tb->setChecked(tb->property("pageIndex").toInt() == pageIndex);
|
|
|
|
}
|
2017-02-21 11:01:06 +00:00
|
|
|
saveSettings();
|
2017-02-20 00:19:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LauncherMainWindow::onSubsytemIdleTimeout()
|
|
|
|
{
|
|
|
|
globals->get_subsystem_mgr()->update(0.0);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
QMessageBox mbox(this);
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2017-05-18 08:17:27 +00:00
|
|
|
|
2017-06-22 09:45:47 +00:00
|
|
|
|