From b76b6548a1876156d82184c914b041d2c3ce88f9 Mon Sep 17 00:00:00 2001 From: James Turner Date: Wed, 17 Mar 2021 12:42:54 +0000 Subject: [PATCH] Launcher: detect user-entered aircraft args Avoid double-setting or conflicting aircraft arguments being passed: when the user enters an aircraft related argument manually, disable the launcher setting them. --- src/GUI/LauncherArgumentTokenizer.cxx | 7 +++++++ src/GUI/LauncherArgumentTokenizer.hxx | 2 ++ src/GUI/LauncherController.cxx | 3 +++ src/GUI/LauncherController.hxx | 4 ++++ src/GUI/qml/Launcher.qml | 5 +++++ src/GUI/qml/SettingExtraArguments.qml | 15 +++++++++++++++ src/GUI/qml/Summary.qml | 16 +++++++++++----- 7 files changed, 47 insertions(+), 5 deletions(-) diff --git a/src/GUI/LauncherArgumentTokenizer.cxx b/src/GUI/LauncherArgumentTokenizer.cxx index dff0e5540..2530bf141 100644 --- a/src/GUI/LauncherArgumentTokenizer.cxx +++ b/src/GUI/LauncherArgumentTokenizer.cxx @@ -170,3 +170,10 @@ bool LauncherArgumentTokenizer::havePositionalArgs() const { return haveArgsIn(positionalArgs); } + +const std::set aircraftArgs({"state", "aircraft", "aircraft-dir", "vehicle"}); + +bool LauncherArgumentTokenizer::haveAircraftArgs() const +{ + return haveArgsIn(aircraftArgs); +} diff --git a/src/GUI/LauncherArgumentTokenizer.hxx b/src/GUI/LauncherArgumentTokenizer.hxx index c5b1e8dcf..98b6074df 100644 --- a/src/GUI/LauncherArgumentTokenizer.hxx +++ b/src/GUI/LauncherArgumentTokenizer.hxx @@ -27,6 +27,7 @@ class LauncherArgumentTokenizer : public QObject Q_PROPERTY(bool valid READ isValid NOTIFY argStringChanged) Q_PROPERTY(bool havePositionalArgs READ havePositionalArgs NOTIFY argStringChanged) Q_PROPERTY(bool haveUnsupportedArgs READ haveUnsupportedArgs NOTIFY argStringChanged) + Q_PROPERTY(bool haveAircraftArgs READ haveAircraftArgs NOTIFY argStringChanged) public: LauncherArgumentTokenizer(); @@ -43,6 +44,7 @@ public: bool haveUnsupportedArgs() const; bool havePositionalArgs() const; + bool haveAircraftArgs() const; public slots: void setArgString(QString argString); diff --git a/src/GUI/LauncherController.cxx b/src/GUI/LauncherController.cxx index 5cb1cd062..7769393c4 100644 --- a/src/GUI/LauncherController.cxx +++ b/src/GUI/LauncherController.cxx @@ -288,6 +288,9 @@ void LauncherController::saveSettings() void LauncherController::collectAircraftArgs() { + if (m_skipAircraftFromArgs) + return; + // aircraft if (!m_selectedAircraft.isEmpty()) { if (m_selectedAircraft.isLocalFile()) { diff --git a/src/GUI/LauncherController.hxx b/src/GUI/LauncherController.hxx index 1cc23d2b1..2c4510235 100644 --- a/src/GUI/LauncherController.hxx +++ b/src/GUI/LauncherController.hxx @@ -96,6 +96,8 @@ class LauncherController : public QObject Q_PROPERTY(int launchCount READ launchCount CONSTANT); Q_PROPERTY(int versionLaunchCount READ versionLaunchCount CONSTANT); + // property to indicate if we're disabling the aircraft selection because the user entered it manuall + Q_PROPERTY(bool skipAircraftFromArgs MEMBER m_skipAircraftFromArgs NOTIFY skipAircraftFromArgsChanged) public: explicit LauncherController(QObject *parent, QWindow* win); @@ -244,6 +246,7 @@ signals: void installedAircraftCountChanged(int installedAircraftCount); void didResetGettingStartedTips(); + void skipAircraftFromArgsChanged(); public slots: void setSelectedAircraft(QUrl selectedAircraft); @@ -330,6 +333,7 @@ private: int m_launchCount = 0; int m_versionLaunchCount = 0; bool m_flyRequested = false; + bool m_skipAircraftFromArgs = false; }; #endif // LAUNCHERCONTROLLER_HXX diff --git a/src/GUI/qml/Launcher.qml b/src/GUI/qml/Launcher.qml index 66d1bfbe8..a47ca59e5 100644 --- a/src/GUI/qml/Launcher.qml +++ b/src/GUI/qml/Launcher.qml @@ -64,6 +64,11 @@ Item { onSkipFromArgsChanged: startupPagesModel.setProperty(2, "buttonDisabled", _location.skipFromArgs) } + Connections { + target: _launcher + onSkipAircraftFromArgsChanged: startupPagesModel.setProperty(1, "buttonDisabled", _launcher.skipAircraftFromArgs) + } + state: "loader" states: [ State { diff --git a/src/GUI/qml/SettingExtraArguments.qml b/src/GUI/qml/SettingExtraArguments.qml index 13f9a4de9..f99c3c836 100644 --- a/src/GUI/qml/SettingExtraArguments.qml +++ b/src/GUI/qml/SettingExtraArguments.qml @@ -60,6 +60,15 @@ SettingControl { "page (for example, airport or altitude) will be ignored."); } + SettingDescription { + id: aircraftArgsText + enabled: root.enabled + visible: tokenizer.haveAircraftArgs + width: parent.width + text: qsTr("Note: you have entered arguments relating to the selected aircraft. " + + "To prevent problems caused by conflicting settings, the aircraft page will be ignored."); + } + PlainTextEditBox { id: edit @@ -88,6 +97,12 @@ SettingControl { value: tokenizer.havePositionalArgs } + Binding { + target: _launcher + property: "skipAircraftFromArgs" + value: tokenizer.haveAircraftArgs + } + ArgumentTokenizer { id: tokenizer argString: edit.text diff --git a/src/GUI/qml/Summary.qml b/src/GUI/qml/Summary.qml index 09fbb0c43..0aa8eeaa6 100644 --- a/src/GUI/qml/Summary.qml +++ b/src/GUI/qml/Summary.qml @@ -155,9 +155,12 @@ Item { } ClickableText { - text: _launcher.selectedAircraftInfo.name === "" ? - qsTr("No aircraft selected") : _launcher.selectedAircraftInfo.name - enabled: _launcher.selectedAircraftInfo.name !== "" + text: { + if (_launcher.skipAircraftFromArgs) return qsTr("set from user arguments (in Settings)"); + if (_launcher.selectedAircraftInfo.name === "") return qsTr("No aircraft selected"); + return _launcher.selectedAircraftInfo.name; + } + enabled: _launcher.selectedAircraftInfo.name !== "" && !_launcher.skipAircraftFromArgs font.pixelSize: Style.headingFontPixelSize onClicked: root.showSelectedAircraft(); @@ -166,7 +169,7 @@ Item { HistoryPopup { id: aircraftHistoryPopup model: _launcher.aircraftHistory - enabled: !_launcher.aircraftHistory.isEmpty + enabled: !_launcher.aircraftHistory.isEmpty && !_launcher.skipAircraftFromArgs onSelected: { _launcher.selectedAircraft = _launcher.aircraftHistory.uriAt(index) } @@ -187,12 +190,14 @@ Item { // empty space in next row (thumbnail, long aircraft description) Item { width: 1; height: 1 + visible: aircraftDetailsRow.visible } Item { id: aircraftDetailsRow width: summaryGrid.middleColumnWidth height: Math.max(thumbnail.height, aircraftDescriptionText.height) + visible: !_launcher.skipAircraftFromArgs ThumbnailImage { id: thumbnail @@ -219,6 +224,7 @@ Item { Item { width: 1; height: 1 + visible: aircraftDetailsRow.visible } // aircraft state row, if enabled @@ -229,7 +235,7 @@ Item { Column { id: stateSelectionGroup - visible: _launcher.selectedAircraftInfo.hasStates + visible: _launcher.selectedAircraftInfo.hasStates && !_launcher.skipAircraftFromArgs width: summaryGrid.middleColumnWidth spacing: Style.margin