From 1e213201cf4180603e2ff745e8c1195849238480 Mon Sep 17 00:00:00 2001 From: James Turner Date: Thu, 15 Oct 2015 20:05:17 -0500 Subject: [PATCH] Work on the launcher --- src/GUI/AircraftModel.cxx | 2 +- src/GUI/AircraftModel.hxx | 2 +- src/GUI/CMakeLists.txt | 81 +++++------ src/GUI/Launcher.ui | 132 ++++++++++++++---- src/GUI/QtLauncher.cxx | 244 +++++++++++++++++++++++++++------ src/GUI/QtLauncher.hxx | 104 +------------- src/GUI/QtLauncher_private.hxx | 136 ++++++++++++++++++ src/Main/fg_commands.cxx | 20 +++ src/Main/main.cxx | 4 +- src/Main/options.cxx | 2 +- src/Navaids/NavDataCache.cxx | 16 +-- src/Navaids/NavDataCache.hxx | 10 +- 12 files changed, 528 insertions(+), 225 deletions(-) create mode 100644 src/GUI/QtLauncher_private.hxx diff --git a/src/GUI/AircraftModel.cxx b/src/GUI/AircraftModel.cxx index 943bbe76c..2b424e5d7 100644 --- a/src/GUI/AircraftModel.cxx +++ b/src/GUI/AircraftModel.cxx @@ -402,7 +402,7 @@ private: AircraftItemModel* m_model; }; -AircraftItemModel::AircraftItemModel(QObject* pr, simgear::pkg::RootRef& rootRef) : +AircraftItemModel::AircraftItemModel(QObject* pr, const simgear::pkg::RootRef& rootRef) : QAbstractListModel(pr), m_scanThread(NULL), m_packageRoot(rootRef) diff --git a/src/GUI/AircraftModel.hxx b/src/GUI/AircraftModel.hxx index e717ea115..975e6808c 100644 --- a/src/GUI/AircraftModel.hxx +++ b/src/GUI/AircraftModel.hxx @@ -97,7 +97,7 @@ class AircraftItemModel : public QAbstractListModel { Q_OBJECT public: - AircraftItemModel(QObject* pr, simgear::pkg::RootRef& root); + AircraftItemModel(QObject* pr, const simgear::pkg::RootRef& root); ~AircraftItemModel(); diff --git a/src/GUI/CMakeLists.txt b/src/GUI/CMakeLists.txt index 74b7bd960..b8475f81c 100644 --- a/src/GUI/CMakeLists.txt +++ b/src/GUI/CMakeLists.txt @@ -1,57 +1,57 @@ include(FlightGearComponent) set(SOURCES - AirportList.cxx - CanvasWidget.cxx - MapWidget.cxx - WaypointList.cxx - dialog.cxx - FGPUIDialog.cxx - fonts.cxx - gui.cxx - gui_funcs.cxx - layout-props.cxx - layout.cxx - menubar.cxx - FGPUIMenuBar.cxx - new_gui.cxx - property_list.cxx - FGFontCache.cxx - FGColor.cxx + AirportList.cxx + CanvasWidget.cxx + MapWidget.cxx + WaypointList.cxx + dialog.cxx + FGPUIDialog.cxx + fonts.cxx + gui.cxx + gui_funcs.cxx + layout-props.cxx + layout.cxx + menubar.cxx + FGPUIMenuBar.cxx + new_gui.cxx + property_list.cxx + FGFontCache.cxx + FGColor.cxx FileDialog.cxx PUIFileDialog.cxx MouseCursor.cxx MessageBox.cxx - ) + ) set(HEADERS - AirportList.hxx - CanvasWidget.hxx - MapWidget.hxx - WaypointList.hxx - dialog.hxx - FGPUIDialog.hxx - gui.h - layout.hxx - menubar.hxx - FGPUIMenuBar.hxx - new_gui.hxx - property_list.hxx - FGFontCache.hxx - FGColor.hxx + AirportList.hxx + CanvasWidget.hxx + MapWidget.hxx + WaypointList.hxx + dialog.hxx + FGPUIDialog.hxx + gui.h + layout.hxx + menubar.hxx + FGPUIMenuBar.hxx + new_gui.hxx + property_list.hxx + FGFontCache.hxx + FGColor.hxx FileDialog.hxx PUIFileDialog.hxx MouseCursor.hxx MessageBox.hxx - ) + ) if(WIN32) - list(APPEND HEADERS WindowsMouseCursor.hxx - FGWindowsMenuBar.hxx - WindowsFileDialog.hxx) - list(APPEND SOURCES WindowsMouseCursor.cxx - FGWindowsMenuBar.cxx - WindowsFileDialog.cxx) + list(APPEND HEADERS WindowsMouseCursor.hxx + FGWindowsMenuBar.hxx + WindowsFileDialog.hxx) + list(APPEND SOURCES WindowsMouseCursor.cxx + FGWindowsMenuBar.cxx + WindowsFileDialog.cxx) endif() if (APPLE) @@ -70,7 +70,7 @@ endif() if (HAVE_QT) - qt5_wrap_ui(uic_sources Launcher.ui + qt5_wrap_ui(uic_sources Launcher.ui EditRatingsFilterDialog.ui SetupRootDialog.ui AddCatalogDialog.ui @@ -81,6 +81,7 @@ if (HAVE_QT) add_library(fglauncher QtLauncher.cxx QtLauncher.hxx + QtLauncher_private.hxx AirportDiagram.cxx AirportDiagram.hxx EditRatingsFilterDialog.cxx diff --git a/src/GUI/Launcher.ui b/src/GUI/Launcher.ui index e19a135d1..1eb885204 100644 --- a/src/GUI/Launcher.ui +++ b/src/GUI/Launcher.ui @@ -6,8 +6,8 @@ 0 0 - 700 - 700 + 800 + 800 @@ -128,9 +128,9 @@ - 2 + 0 - + Aircraft @@ -216,7 +216,7 @@ - + Location @@ -242,7 +242,7 @@ - Enter an ICAO code or search by name + Enter an ICAO code, navaid or search by name @@ -270,7 +270,7 @@ 0 - + 0 @@ -283,13 +283,17 @@ 0 - - - - - 0 - 0 - + + + + Parking: + + + + + + + On 10-mile final @@ -300,25 +304,87 @@ - + + + + true + + + 359 + + + 5 + + + + + + + - - + + - Parking: + True - - + + + + true + - On 10-mile final + Bearing: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + Bearing and distance offset: + + + + + + + Distance: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + nm + + + 1 + + + 10000.000000000000000 + + + 10.000000000000000 + + + + + + + + 0 + 0 + + + @@ -369,7 +435,7 @@ - + Settings @@ -446,6 +512,9 @@ Enable deferred rendering (Rembrandt) + + true + @@ -453,6 +522,9 @@ Start full-screen + + true + @@ -467,6 +539,9 @@ Enable Multi-sample anti-aliasing + + true + @@ -474,6 +549,9 @@ Start paused + + true + @@ -549,6 +627,9 @@ Additional options + + true + @@ -587,6 +668,9 @@ Configure add-on aircraft and scenery + + true + diff --git a/src/GUI/QtLauncher.cxx b/src/GUI/QtLauncher.cxx index d16479e83..a96ed7abb 100644 --- a/src/GUI/QtLauncher.cxx +++ b/src/GUI/QtLauncher.cxx @@ -19,6 +19,7 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "QtLauncher.hxx" +#include "QtLauncher_private.hxx" // Qt #include @@ -41,6 +42,8 @@ #include #include #include +#include +#include // Simgear #include @@ -62,6 +65,8 @@ #include #include #include // for parking +#include + #include
#include
#include @@ -92,7 +97,7 @@ void initNavCache() // sleep to give the rebuild thread more time SGTimeStamp::sleepForMSec(50); phase = cache->rebuild(); - + switch (phase) { case NavDataCache::REBUILD_AIRPORTS: rebuildProgress.setLabelText(QT_TR_NOOP("Loading airport data")); @@ -249,16 +254,17 @@ public: std::string term(t.toUpper().toStdString()); // try ICAO lookup first FGAirportRef ref = FGAirport::findByIdent(term); + if (ref) { m_ids.push_back(ref->guid()); m_airports.push_back(ref); - } else { - m_search.reset(new NavDataCache::ThreadedAirportSearch(term)); - QTimer::singleShot(100, this, SLOT(onSearchResultsPoll())); - m_searchActive = true; + endResetModel(); + return; } - endResetModel(); + m_search.reset(new NavDataCache::ThreadedGUISearch(term)); + QTimer::singleShot(100, this, SLOT(onSearchResultsPoll())); + m_searchActive = true; } bool isSearchActive() const @@ -276,7 +282,7 @@ public: { if (!index.isValid()) return QVariant(); - + FGAirportRef apt = m_airports[index.row()]; if (!apt.valid()) { apt = FGPositioned::loadById(m_ids[index.row()]); @@ -318,7 +324,7 @@ private slots: void onSearchResultsPoll() { PositionedIDVec newIds = m_search->results(); - + beginInsertRows(QModelIndex(), m_ids.size(), newIds.size() - 1); for (unsigned int i=m_ids.size(); i < newIds.size(); ++i) { m_ids.push_back(newIds[i]); @@ -339,7 +345,7 @@ private: PositionedIDVec m_ids; mutable std::vector m_airports; bool m_searchActive; - QScopedPointer m_search; + QScopedPointer m_search; }; class AircraftProxyModel : public QSortFilterProxyModel @@ -396,9 +402,97 @@ private: int m_ratings[4]; }; +static void initQtResources() +{ + Q_INIT_RESOURCE(resources); +} + +namespace flightgear +{ + +void initApp(int& argc, char** argv) +{ + static bool qtInitDone = false; + if (!qtInitDone) { + qtInitDone = true; + + QApplication* app = new QApplication(argc, argv); + app->setOrganizationName("FlightGear"); + app->setApplicationName("FlightGear"); + app->setOrganizationDomain("flightgear.org"); + + // avoid double Apple menu and other weirdness if both Qt and OSG + // try to initialise various Cocoa structures. + flightgear::WindowBuilder::setPoseAsStandaloneApp(false); + + Qt::KeyboardModifiers mods = app->queryKeyboardModifiers(); + if (mods & Qt::AltModifier) { + qWarning() << "Alt pressed during launch"; + + // wipe out our settings + QSettings settings; + settings.clear(); + + + Options::sharedInstance()->addOption("restore-defaults", ""); + } + } +} + +bool runLauncherDialog() +{ + sglog().setLogLevels( SG_ALL, SG_INFO ); + + + initQtResources(); // can't be called inside a namespaceb + + // startup the nav-cache now. This pre-empts normal startup of + // the cache, but no harm done. (Providing scenery paths are consistent) + + initNavCache(); + + + fgInitPackageRoot(); + + // startup the HTTP system now since packages needs it + 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(); + + + // setup scenery paths now, especially TerraSync path for airport + // parking locations (after they're downloaded) + + QtLauncher dlg; + dlg.exec(); + if (dlg.result() != QDialog::Accepted) { + return false; + } + + return true; +} + +bool runInAppLauncherDialog() +{ + QtLauncher dlg; + dlg.setInAppMode(); + dlg.exec(); + if (dlg.result() != QDialog::Accepted) { + return false; + } + + return true; +} + +} // of namespace flightgear + QtLauncher::QtLauncher() : QDialog(), - m_ui(NULL) + m_ui(NULL), + m_subsystemIdleTimer(NULL), + m_inAppMode(false) { m_ui.reset(new Ui::Launcher); m_ui->setupUi(this); @@ -447,7 +541,7 @@ QtLauncher::QtLauncher() : connect(m_ui->onFinalCheckbox, SIGNAL(toggled(bool)), this, SLOT(updateAirportDescription())); - + connect(m_ui->airportDiagram, &AirportDiagram::clickedRunway, this, &QtLauncher::onAirportDiagramClicked); @@ -496,17 +590,7 @@ QtLauncher::QtLauncher() : this, &QtLauncher::onToggleTerrasync); updateSettingsSummary(); - fgInitPackageRoot(); - 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_aircraftModel = new AircraftItemModel(this, r); + m_aircraftModel = new AircraftItemModel(this, RootRef(globals->packageRoot())); m_aircraftProxy->setSourceModel(m_aircraftModel); m_aircraftProxy->setFilterCaseSensitivity(Qt::CaseInsensitive); @@ -532,10 +616,19 @@ QtLauncher::QtLauncher() : this, &QtLauncher::onAircraftInstalledCompleted); connect(m_aircraftModel, &AircraftItemModel::aircraftInstallFailed, this, &QtLauncher::onAircraftInstallFailed); - + connect(m_ui->pathsButton, &QPushButton::clicked, this, &QtLauncher::onEditPaths); + + connect(m_ui->trueBearing, &QCheckBox::toggled, this, &QtLauncher::onOffsetBearingTrueChanged); + connect(m_ui->offsetRadioButton, &QRadioButton::toggled, + this, &QtLauncher::onOffsetRadioToggled); + connect(m_ui->trueBearing, &QCheckBox::toggled, this, &QtLauncher::onOffsetDataChanged); + connect(m_ui->offsetBearingSpinbox, SIGNAL(valueChanged(int)), this, SLOT(onOffsetDataChanged())); + connect(m_ui->offsetNmSpinbox, SIGNAL(valueChanged(double)), + this, SLOT(onOffsetDataChanged())); + restoreSettings(); QSettings settings; @@ -545,11 +638,25 @@ QtLauncher::QtLauncher() : QtLauncher::~QtLauncher() { - + +} + +void QtLauncher::setInAppMode() +{ + m_inAppMode = true; + m_ui->tabWidget->removeTab(2); + m_ui->runButton->setText(tr("Apply")); + m_ui->quitButton->setText(tr("Cancel")); + + disconnect(m_ui->runButton, SIGNAL(clicked()), this, SLOT(onRun())); + connect(m_ui->runButton, SIGNAL(clicked()), this, SLOT(onApply())); } -void QtLauncher::initApp(int& argc, char** argv) +bool QtLauncher::runLauncherDialog() { + sglog().setLogLevels( SG_ALL, SG_INFO ); + Q_INIT_RESOURCE(resources); + static bool qtInitDone = false; static int s_argc; if (!qtInitDone) { @@ -575,18 +682,11 @@ void QtLauncher::initApp(int& argc, char** argv) QSettings settings; settings.clear(); - Options::sharedInstance()->addOption("restore-defaults", ""); } } -} - -bool QtLauncher::runLauncherDialog() -{ - sglog().setLogLevels( SG_ALL, SG_INFO ); - Q_INIT_RESOURCE(resources); - // startup the nav-cache now. This pre-empts normal startup of + // startup the nav-cache now. This preempts normal startup of // the cache, but no harm done. (Providing scenery paths are consistent) initNavCache(); @@ -599,8 +699,6 @@ bool QtLauncher::runLauncherDialog() if (dlg.result() != QDialog::Accepted) { return false; } - - return true; } void QtLauncher::restoreSettings() @@ -712,7 +810,7 @@ void QtLauncher::onRun() } else { qWarning() << "unsupported aircraft launch URL" << m_selectedAircraft; } - + // manage aircraft history if (m_recentAircraft.contains(m_selectedAircraft)) m_recentAircraft.removeOne(m_selectedAircraft); @@ -799,6 +897,46 @@ void QtLauncher::onRun() saveSettings(); } +void QtLauncher::onApply() +{ + accept(); + + // aircraft + if (!m_selectedAircraft.isEmpty()) { + std::string aircraftPropValue, + aircraftDir; + + if (m_selectedAircraft.isLocalFile()) { + QFileInfo setFileInfo(m_selectedAircraft.toLocalFile()); + QString setFile = setFileInfo.fileName(); + Q_ASSERT(setFile.endsWith("-set.xml")); + setFile.truncate(setFile.count() - 8); // drop the '-set.xml' portion + aircraftDir = setFileInfo.dir().absolutePath().toStdString(); + aircraftPropValue = setFile.toStdString(); + } else if (m_selectedAircraft.scheme() == "package") { + PackageRef pkg = packageForAircraftURI(m_selectedAircraft); + // no need to set aircraft-dir, handled by the corresponding code + // in fgInitAircraft + aircraftPropValue = pkg->qualifiedId(); + } else { + qWarning() << "unsupported aircraft launch URL" << m_selectedAircraft; + } + + // manage aircraft history + if (m_recentAircraft.contains(m_selectedAircraft)) + m_recentAircraft.removeOne(m_selectedAircraft); + m_recentAircraft.prepend(m_selectedAircraft); + if (m_recentAircraft.size() > MAX_RECENT_AIRCRAFT) + m_recentAircraft.pop_back(); + + globals->get_props()->setStringValue("/sim/aircraft", aircraftPropValue); + globals->get_props()->setStringValue("/sim/aircraft-dir", aircraftDir); + } + + + saveSettings(); +} + void QtLauncher::onQuit() { reject(); @@ -881,6 +1019,15 @@ void QtLauncher::onAirportChanged() } } +void QtLauncher::onOffsetRadioToggled(bool on) +{ + m_ui->offsetNmSpinbox->setEnabled(on); + m_ui->offsetBearingSpinbox->setEnabled(on); + m_ui->trueBearing->setEnabled(on); + m_ui->offsetBearingLabel->setEnabled(on); + m_ui->offsetDistanceLabel->setEnabled(on); +} + void QtLauncher::onAirportDiagramClicked(FGRunwayRef rwy) { if (rwy) { @@ -888,7 +1035,7 @@ void QtLauncher::onAirportDiagramClicked(FGRunwayRef rwy) int rwyIndex = m_ui->runwayCombo->findText(QString::fromStdString(rwy->ident())); m_ui->runwayCombo->setCurrentIndex(rwyIndex); } - + updateAirportDescription(); } @@ -912,7 +1059,7 @@ void QtLauncher::onToggleTerrasync(bool enabled) msg.addButton(QMessageBox::Cancel); msg.addButton(tr("Change location"), QMessageBox::ActionRole); int result = msg.exec(); - + if (result == QMessageBox::Cancel) { m_ui->terrasyncCheck->setChecked(false); return; @@ -937,7 +1084,7 @@ void QtLauncher::onAircraftInstalledCompleted(QModelIndex index) void QtLauncher::onAircraftInstallFailed(QModelIndex index, QString errorMessage) { qWarning() << Q_FUNC_INFO << index.data(AircraftURIRole) << errorMessage; - + QMessageBox msg; msg.setWindowTitle(tr("Aircraft installation failed")); msg.setText(tr("An error occurred installing the aircraft %1: %2"). @@ -970,7 +1117,7 @@ void QtLauncher::updateAirportDescription() } else { locationOnAirport = QString("on %1").arg(runwayName); } - + int runwayIndex = m_ui->runwayCombo->itemData(comboIndex).toInt(); FGRunwayRef rwy = (runwayIndex >= 0) ? m_selectedAirport->getRunwayByIndex(runwayIndex) : FGRunwayRef(); @@ -988,6 +1135,12 @@ void QtLauncher::onAirportChoiceSelected(const QModelIndex& index) setAirport(FGPositioned::loadById(index.data(Qt::UserRole).toULongLong())); } +void QtLauncher::onOffsetBearingTrueChanged(bool on) +{ + m_ui->offsetBearingLabel->setText(on ? tr("True bearing:") : + tr("Magnetic bearing:")); +} + void QtLauncher::onAircraftSelected(const QModelIndex& index) { m_selectedAircraft = index.data(AircraftURIRole).toUrl(); @@ -1011,7 +1164,6 @@ void QtLauncher::onRequestPackageInstall(const QModelIndex& index) void QtLauncher::onCancelDownload(const QModelIndex& index) { QString pkg = index.data(AircraftPackageIdRole).toString(); - qDebug() << "cancel download of" << pkg; simgear::pkg::PackageRef pref = globals->packageRoot()->getPackageById(pkg.toStdString()); simgear::pkg::InstallRef i = pref->existingInstall(); i->cancelDownload(); @@ -1033,7 +1185,7 @@ void QtLauncher::updateSelectedAircraft() QPixmap pm = index.data(Qt::DecorationRole).value(); m_ui->thumbnail->setPixmap(pm); m_ui->aircraftDescription->setText(index.data(Qt::DisplayRole).toString()); - + int status = index.data(AircraftPackageStatusRole).toInt(); bool canRun = (status == PackageInstalled); m_ui->runButton->setEnabled(canRun); @@ -1218,10 +1370,14 @@ simgear::pkg::PackageRef QtLauncher::packageForAircraftURI(QUrl uri) const qWarning() << "invalid URL scheme:" << uri; return simgear::pkg::PackageRef(); } - + QString ident = uri.path(); return globals->packageRoot()->getPackageById(ident.toStdString()); } -#include "QtLauncher.moc" +void QtLauncher::onOffsetDataChanged() +{ + qDebug() << "implement me"; +} +#include "QtLauncher.moc" diff --git a/src/GUI/QtLauncher.hxx b/src/GUI/QtLauncher.hxx index c0412bf40..bc9d844df 100644 --- a/src/GUI/QtLauncher.hxx +++ b/src/GUI/QtLauncher.hxx @@ -21,107 +21,13 @@ #ifndef FG_QTLAUNCHER_HXX #define FG_QTLAUNCHER_HXX -#include -#include -#include -#include -#include -#include - - -#include -#include -#include - -namespace Ui -{ - class Launcher; -} - -class AirportSearchModel; -class QModelIndex; -class AircraftProxyModel; -class AircraftItemModel; -class QCheckBox; -class CatalogListModel; - -class QtLauncher : public QDialog +namespace flightgear { - Q_OBJECT -public: - QtLauncher(); - virtual ~QtLauncher(); - - static void initApp(int& argc, char** argv); - - static bool runLauncherDialog(); - -private slots: - void onRun(); - void onQuit(); - - void onSearchAirports(); - - void onAirportChanged(); - - void onAirportChoiceSelected(const QModelIndex& index); - void onAircraftSelected(const QModelIndex& index); - void onRequestPackageInstall(const QModelIndex& index); - void onCancelDownload(const QModelIndex& index); - - void onPopupAirportHistory(); - void onPopupAircraftHistory(); + void initApp(int& argc, char** argv); - void onEditRatingsFilter(); + bool runLauncherDialog(); - void updateAirportDescription(); - void updateSettingsSummary(); - - void onAirportSearchComplete(); - - void onRembrandtToggled(bool b); - void onToggleTerrasync(bool enabled); - - void onSubsytemIdleTimeout(); - - void onEditPaths(); - - void onAirportDiagramClicked(FGRunwayRef rwy); - - void onAircraftInstalledCompleted(QModelIndex index); - void onAircraftInstallFailed(QModelIndex index, QString errorMessage); -private: - void setAirport(FGAirportRef ref); - - /** - * Check if the passed index is the selected aircraft, and if so, refresh - * the associated UI data - */ - void maybeUpdateSelectedAircraft(QModelIndex index); - void updateSelectedAircraft(); - - void restoreSettings(); - void saveSettings(); - - QModelIndex proxyIndexForAircraftURI(QUrl uri) const; - QModelIndex sourceIndexForAircraftURI(QUrl uri) const; - - void setEnableDisableOptionFromCheckbox(QCheckBox* cbox, QString name) const; - - simgear::pkg::PackageRef packageForAircraftURI(QUrl uri) const; - - QScopedPointer m_ui; - AirportSearchModel* m_airportsModel; - AircraftProxyModel* m_aircraftProxy; - AircraftItemModel* m_aircraftModel; - FGAirportRef m_selectedAirport; - - QUrl m_selectedAircraft; - QList m_recentAircraft; - QStringList m_recentAirports; - QTimer* m_subsystemIdleTimer; - - int m_ratingFilters[4]; -}; + bool runInAppLauncherDialog(); +} #endif // of FG_QTLAUNCHER_HXX diff --git a/src/GUI/QtLauncher_private.hxx b/src/GUI/QtLauncher_private.hxx new file mode 100644 index 000000000..17f7a1c4c --- /dev/null +++ b/src/GUI/QtLauncher_private.hxx @@ -0,0 +1,136 @@ +// QtLauncher_private.hxx - GUI launcher dialog using Qt5 +// +// Written by James Turner, started October 2015. +// +// Copyright (C) 2015 James Turner +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// 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 + +#include +#include +#include +#include +#include +#include + + +#include +#include +#include + +namespace Ui +{ + class Launcher; +} + +class AirportSearchModel; +class QModelIndex; +class AircraftProxyModel; +class AircraftItemModel; +class QCheckBox; +class CatalogListModel; + +class QtLauncher : public QDialog +{ + Q_OBJECT +public: + QtLauncher(); + virtual ~QtLauncher(); + + void setInAppMode(); +private slots: + // run is used when the launcher is invoked before the main app is + // started + void onRun(); + + // apply is used in-app, where we must set properties and trigger + // a reset; setting command line options won't help us. + void onApply(); + + void onQuit(); + + void onSearchAirports(); + + void onAirportChanged(); + + void onAirportChoiceSelected(const QModelIndex& index); + void onAircraftSelected(const QModelIndex& index); + void onRequestPackageInstall(const QModelIndex& index); + void onCancelDownload(const QModelIndex& index); + + void onPopupAirportHistory(); + void onPopupAircraftHistory(); + + void onEditRatingsFilter(); + + void updateAirportDescription(); + void updateSettingsSummary(); + + void onAirportSearchComplete(); + + void onRembrandtToggled(bool b); + void onToggleTerrasync(bool enabled); + + void onSubsytemIdleTimeout(); + + void onEditPaths(); + + void onAirportDiagramClicked(FGRunwayRef rwy); + void onOffsetBearingTrueChanged(bool on); + + void onOffsetDataChanged(); + void onOffsetRadioToggled(bool on); + + void onAircraftInstalledCompleted(QModelIndex index); + void onAircraftInstallFailed(QModelIndex index, QString errorMessage); +private: + void setAirport(FGAirportRef ref); + + /** + * Check if the passed index is the selected aircraft, and if so, refresh + * the associated UI data + */ + void maybeUpdateSelectedAircraft(QModelIndex index); + void updateSelectedAircraft(); + + void restoreSettings(); + void saveSettings(); + + QModelIndex proxyIndexForAircraftURI(QUrl uri) const; + QModelIndex sourceIndexForAircraftURI(QUrl uri) const; + + void setEnableDisableOptionFromCheckbox(QCheckBox* cbox, QString name) const; + + simgear::pkg::PackageRef packageForAircraftURI(QUrl uri) const; + + QScopedPointer m_ui; + AirportSearchModel* m_airportsModel; + AircraftProxyModel* m_aircraftProxy; + AircraftItemModel* m_aircraftModel; + FGAirportRef m_selectedAirport; + + QUrl m_selectedAircraft; + QList m_recentAircraft; + QStringList m_recentAirports; + QTimer* m_subsystemIdleTimer; + bool m_inAppMode; + + int m_ratingFilters[4]; +}; + +#endif // of FG_QTLAUNCHER_PRIVATE_HXX diff --git a/src/Main/fg_commands.cxx b/src/Main/fg_commands.cxx index 1eb518562..f0b8de09b 100644 --- a/src/Main/fg_commands.cxx +++ b/src/Main/fg_commands.cxx @@ -58,6 +58,10 @@ # include #endif +#if defined(HAVE_QT) +#include +#endif + using std::string; using std::ifstream; using std::ofstream; @@ -992,6 +996,21 @@ do_open_browser (const SGPropertyNode * arg) return openBrowser(path); } +static bool +do_open_launcher(const SGPropertyNode *) +{ +#if defined(HAVE_QT) + bool ok = flightgear::runInAppLauncherDialog(); + if (ok) { + // start a full reset + fgResetIdleState(); + } + return ok; +#else + return false; +#endif +} + /** * Apply a value in the active XML-configured dialog. * @@ -1472,6 +1491,7 @@ static struct { { "presets-commit", do_presets_commit }, { "log-level", do_log_level }, { "replay", do_replay }, + { "open-launcher", do_open_launcher }, /* { "decrease-visibility", do_decrease_visibility }, { "increase-visibility", do_increase_visibility }, diff --git a/src/Main/main.cxx b/src/Main/main.cxx index c19881438..2434d2058 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -449,8 +449,8 @@ int fgMainInit( int argc, char **argv ) showLauncher |= (::getenv("FG_LAUNCHER") != 0); if (showLauncher) { - QtLauncher::initApp(argc, argv); - if (!QtLauncher::runLauncherDialog()) { + flightgear::initApp(argc, argv); + if (!flightgear::runLauncherDialog()) { return EXIT_SUCCESS; } } diff --git a/src/Main/options.cxx b/src/Main/options.cxx index 00f2352a1..e4f1b212a 100644 --- a/src/Main/options.cxx +++ b/src/Main/options.cxx @@ -2512,7 +2512,7 @@ void Options::setupRoot(int argc, char **argv) #if defined(HAVE_QT) if (base_version != required_version) { - QtLauncher::initApp(argc, argv); + flightgear::initApp(argc, argv); if (SetupRootDialog::restoreUserSelectedRoot()) { SG_LOG(SG_GENERAL, SG_INFO, "restored user selected fg_root = " << globals->get_fg_root() ); return; diff --git a/src/Navaids/NavDataCache.cxx b/src/Navaids/NavDataCache.cxx index 1746ece4e..e18c382bc 100644 --- a/src/Navaids/NavDataCache.cxx +++ b/src/Navaids/NavDataCache.cxx @@ -2276,10 +2276,10 @@ void NavDataCache::Transaction::commit() ///////////////////////////////////////////////////////////////////////////// -class NavDataCache::ThreadedAirportSearch::ThreadedAirportSearchPrivate : public SGThread +class NavDataCache::ThreadedGUISearch::ThreadedGUISearchPrivate : public SGThread { public: - ThreadedAirportSearchPrivate() : + ThreadedGUISearchPrivate() : db(NULL), isComplete(false), quit(false) @@ -2300,7 +2300,7 @@ public: SGTimeStamp::sleepForMSec(1); } else { std::string errMsg = sqlite3_errmsg(db); - SG_LOG(SG_NAVCACHE, SG_ALERT, "Sqlite error:" << errMsg << " running threaded airport query"); + SG_LOG(SG_NAVCACHE, SG_ALERT, "Sqlite error:" << errMsg << " running threaded search query"); } } @@ -2316,8 +2316,8 @@ public: bool quit; }; -NavDataCache::ThreadedAirportSearch::ThreadedAirportSearch(const std::string& term) : - d(new ThreadedAirportSearchPrivate) +NavDataCache::ThreadedGUISearch::ThreadedGUISearch(const std::string& term) : + d(new ThreadedGUISearchPrivate) { SGPath p = NavDataCache::instance()->path(); int openFlags = SQLITE_OPEN_READONLY; @@ -2331,7 +2331,7 @@ NavDataCache::ThreadedAirportSearch::ThreadedAirportSearch(const std::string& te d->start(); } -NavDataCache::ThreadedAirportSearch::~ThreadedAirportSearch() +NavDataCache::ThreadedGUISearch::~ThreadedGUISearch() { { SGGuard g(d->lock); @@ -2343,7 +2343,7 @@ NavDataCache::ThreadedAirportSearch::~ThreadedAirportSearch() sqlite3_close_v2(d->db); } -PositionedIDVec NavDataCache::ThreadedAirportSearch::results() const +PositionedIDVec NavDataCache::ThreadedGUISearch::results() const { PositionedIDVec r; { @@ -2353,7 +2353,7 @@ PositionedIDVec NavDataCache::ThreadedAirportSearch::results() const return r; } -bool NavDataCache::ThreadedAirportSearch::isComplete() const +bool NavDataCache::ThreadedGUISearch::isComplete() const { SGGuard g(d->lock); return d->isComplete; diff --git a/src/Navaids/NavDataCache.hxx b/src/Navaids/NavDataCache.hxx index 5c8bbbc8a..a59257848 100644 --- a/src/Navaids/NavDataCache.hxx +++ b/src/Navaids/NavDataCache.hxx @@ -295,18 +295,18 @@ public: bool isReadOnly() const; - class ThreadedAirportSearch + class ThreadedGUISearch { public: - ThreadedAirportSearch(const std::string& term); - ~ThreadedAirportSearch(); + ThreadedGUISearch(const std::string& term); + ~ThreadedGUISearch(); PositionedIDVec results() const; bool isComplete() const; private: - class ThreadedAirportSearchPrivate; - std::auto_ptr d; + class ThreadedGUISearchPrivate; + std::auto_ptr d; }; private: NavDataCache(); -- 2.39.5