From c830b862bed17fe4109023404dbc375603114407 Mon Sep 17 00:00:00 2001 From: Lars Toenning Date: Sun, 16 Nov 2025 23:39:49 +0100 Subject: [PATCH] feat: Allow to tune STBY frequency from context menu Fixes #274 --- src/core/context/contextownaircraft.h | 7 +++++- src/core/context/contextownaircraftempty.h | 12 ++++++++++ src/core/context/contextownaircraftimpl.cpp | 20 ++++++++++++++++ src/core/context/contextownaircraftimpl.h | 5 ++++ src/core/context/contextownaircraftproxy.cpp | 8 +++++++ src/core/context/contextownaircraftproxy.h | 5 ++++ src/gui/components/atcstationcomponent.cpp | 5 ++-- src/gui/components/atcstationcomponent.h | 2 +- src/gui/views/atcstationtreeview.cpp | 18 ++++++++++----- src/gui/views/atcstationtreeview.h | 4 ++-- src/gui/views/atcstationview.cpp | 24 ++++++++++++-------- src/gui/views/atcstationview.h | 4 ++-- 12 files changed, 91 insertions(+), 23 deletions(-) diff --git a/src/core/context/contextownaircraft.h b/src/core/context/contextownaircraft.h index 121a94c14..36afaf3cd 100644 --- a/src/core/context/contextownaircraft.h +++ b/src/core/context/contextownaircraft.h @@ -135,11 +135,16 @@ namespace swift::core::context //! Set XPDR mode virtual bool setTransponderMode(swift::misc::aviation::CTransponder::TransponderMode mode) = 0; - //! Tune in a COM frequency + //! Tune in a COM frequency (active) virtual bool updateActiveComFrequency(const swift::misc::physical_quantities::CFrequency &frequency, swift::misc::aviation::CComSystem::ComUnit comUnit, const swift::misc::CIdentifier &originator) = 0; + //! Tune in a COM frequency (standby) + virtual bool updateStandbyComFrequency(const swift::misc::physical_quantities::CFrequency &frequency, + swift::misc::aviation::CComSystem::ComUnit comUnit, + const swift::misc::CIdentifier &originator) = 0; + //! Set current pilot virtual bool updateOwnAircraftPilot(const swift::misc::network::CUser &pilot) = 0; diff --git a/src/core/context/contextownaircraftempty.h b/src/core/context/contextownaircraftempty.h index 4b0f6c219..18ca8ed32 100644 --- a/src/core/context/contextownaircraftempty.h +++ b/src/core/context/contextownaircraftempty.h @@ -100,6 +100,18 @@ namespace swift::core::context return false; } + //! \copydoc IContextOwnAircraft::updateStandbyComFrequency + bool updateStandbyComFrequency(const swift::misc::physical_quantities::CFrequency &frequency, + swift::misc::aviation::CComSystem::ComUnit comUnit, + const swift::misc::CIdentifier &originator) override + { + Q_UNUSED(frequency); + Q_UNUSED(comUnit); + Q_UNUSED(originator); + logEmptyContextWarning(Q_FUNC_INFO); + return false; + } + //! \copydoc IContextOwnAircraft::updateOwnAircraftPilot bool updateOwnAircraftPilot(const swift::misc::network::CUser &pilot) override { diff --git a/src/core/context/contextownaircraftimpl.cpp b/src/core/context/contextownaircraftimpl.cpp index 4dff42282..68bb2b7d1 100644 --- a/src/core/context/contextownaircraftimpl.cpp +++ b/src/core/context/contextownaircraftimpl.cpp @@ -330,6 +330,26 @@ namespace swift::core::context return changed; } + bool CContextOwnAircraft::updateStandbyComFrequency(const CFrequency &frequency, CComSystem::ComUnit unit, + const CIdentifier &originator) + { + if (unit != CComSystem::Com1 && unit != CComSystem::Com2) { return false; } + if (!CComSystem::isValidComFrequency(frequency)) { return false; } + CComSystem com1, com2; + CTransponder xpdr; + { + QReadLocker l(&m_lockAircraft); + com1 = m_ownAircraft.getCom1System(); + com2 = m_ownAircraft.getCom2System(); + xpdr = m_ownAircraft.getTransponder(); + } + if (unit == CComSystem::Com1) { com1.setFrequencyStandby(frequency); } + else { com2.setFrequencyStandby(frequency); } + + const bool changed = this->updateCockpit(com1, com2, xpdr, originator); + return changed; + } + bool CContextOwnAircraft::updateOwnAircraftPilot(const CUser &pilot) { { diff --git a/src/core/context/contextownaircraftimpl.h b/src/core/context/contextownaircraftimpl.h index dcc5bb849..bb760560f 100644 --- a/src/core/context/contextownaircraftimpl.h +++ b/src/core/context/contextownaircraftimpl.h @@ -175,6 +175,11 @@ namespace swift::core swift::misc::aviation::CComSystem::ComUnit comUnit, const swift::misc::CIdentifier &originator) override; + //! \copydoc IContextOwnAircraft::updateStandbyComFrequency + bool updateStandbyComFrequency(const swift::misc::physical_quantities::CFrequency &frequency, + swift::misc::aviation::CComSystem::ComUnit comUnit, + const swift::misc::CIdentifier &originator) override; + //! \copydoc IContextOwnAircraft::updateOwnAircraftPilot bool updateOwnAircraftPilot(const swift::misc::network::CUser &pilot) override; diff --git a/src/core/context/contextownaircraftproxy.cpp b/src/core/context/contextownaircraftproxy.cpp index 02bc2e5bf..264644561 100644 --- a/src/core/context/contextownaircraftproxy.cpp +++ b/src/core/context/contextownaircraftproxy.cpp @@ -111,6 +111,14 @@ namespace swift::core::context originator); } + bool CContextOwnAircraftProxy::updateStandbyComFrequency(const physical_quantities::CFrequency &frequency, + swift::misc::aviation::CComSystem::ComUnit comUnit, + const CIdentifier &originator) + { + return m_dBusInterface->callDBusRet(QLatin1String("updateStandbyComFrequency"), frequency, comUnit, + originator); + } + bool CContextOwnAircraftProxy::updateOwnAircraftPilot(const swift::misc::network::CUser &pilot) { return m_dBusInterface->callDBusRet(QLatin1String("updateOwnAircraftPilot"), pilot); diff --git a/src/core/context/contextownaircraftproxy.h b/src/core/context/contextownaircraftproxy.h index f318b281b..329c267d9 100644 --- a/src/core/context/contextownaircraftproxy.h +++ b/src/core/context/contextownaircraftproxy.h @@ -89,6 +89,11 @@ namespace swift::core swift::misc::aviation::CComSystem::ComUnit comUnit, const swift::misc::CIdentifier &originator) override; + //! \copydoc swift::core::context::IContextOwnAircraft::updateStandbyComFrequency + bool updateStandbyComFrequency(const swift::misc::physical_quantities::CFrequency &frequency, + swift::misc::aviation::CComSystem::ComUnit comUnit, + const swift::misc::CIdentifier &originator) override; + //! \copydoc swift::core::context::IContextOwnAircraft::updateOwnAircraftPilot bool updateOwnAircraftPilot(const swift::misc::network::CUser &pilot) override; diff --git a/src/gui/components/atcstationcomponent.cpp b/src/gui/components/atcstationcomponent.cpp index cf18baaf8..9c27d777e 100644 --- a/src/gui/components/atcstationcomponent.cpp +++ b/src/gui/components/atcstationcomponent.cpp @@ -330,11 +330,12 @@ namespace swift::gui::components } void CAtcStationComponent::setComFrequency(const physical_quantities::CFrequency &frequency, - CComSystem::ComUnit unit) + CComSystem::ComUnit unit, bool active) { if (unit != CComSystem::Com1 && unit != CComSystem::Com2) { return; } if (!CComSystem::isValidComFrequency(frequency)) { return; } - sGui->getIContextOwnAircraft()->updateActiveComFrequency(frequency, unit, identifier()); + if (active) { sGui->getIContextOwnAircraft()->updateActiveComFrequency(frequency, unit, identifier()); } + else { sGui->getIContextOwnAircraft()->updateStandbyComFrequency(frequency, unit, identifier()); } } void CAtcStationComponent::settingsChanged() diff --git a/src/gui/components/atcstationcomponent.h b/src/gui/components/atcstationcomponent.h index 3e36c6b3e..2608141f9 100644 --- a/src/gui/components/atcstationcomponent.h +++ b/src/gui/components/atcstationcomponent.h @@ -122,7 +122,7 @@ namespace swift::gui //! Set COM frequency void setComFrequency(const swift::misc::physical_quantities::CFrequency &frequency, - swift::misc::aviation::CComSystem::ComUnit unit); + swift::misc::aviation::CComSystem::ComUnit unit, bool active); //! Airports read from web readers void airportsRead(); diff --git a/src/gui/views/atcstationtreeview.cpp b/src/gui/views/atcstationtreeview.cpp index 78aa98afb..ee6f57332 100644 --- a/src/gui/views/atcstationtreeview.cpp +++ b/src/gui/views/atcstationtreeview.cpp @@ -118,18 +118,24 @@ namespace swift::gui::views auto *menu = new QMenu(this); // menu - auto *com1 = new QAction(CIcons::appCockpit16(), "Tune in COM1", this); - auto *com2 = new QAction(CIcons::appCockpit16(), "Tune in COM2", this); + auto *com1 = new QAction(CIcons::appCockpit16(), "Tune in COM1 (active)", this); + auto *com2 = new QAction(CIcons::appCockpit16(), "Tune in COM2 (active)", this); + auto *com1_stby = new QAction(CIcons::appCockpit16(), "Tune in COM1 (standby)", this); + auto *com2_stby = new QAction(CIcons::appCockpit16(), "Tune in COM2 (standby)", this); auto *text = new QAction(CIcons::appTextMessages16(), "Show text messages", this); auto *resize = new QAction(CIcons::resize16(), "Resize", this); - connect(com1, &QAction::triggered, this, [this]() { tuneInAtc(CComSystem::Com1); }); - connect(com2, &QAction::triggered, this, [this]() { tuneInAtc(CComSystem::Com2); }); + connect(com1, &QAction::triggered, this, [this]() { tuneInAtc(CComSystem::Com1, true); }); + connect(com2, &QAction::triggered, this, [this]() { tuneInAtc(CComSystem::Com2, true); }); + connect(com1_stby, &QAction::triggered, this, [this]() { tuneInAtc(CComSystem::Com1, false); }); + connect(com2_stby, &QAction::triggered, this, [this]() { tuneInAtc(CComSystem::Com2, false); }); connect(text, &QAction::triggered, this, &CAtcStationTreeView::requestTextMessage); connect(resize, &QAction::triggered, this, &CAtcStationTreeView::fullResizeToContentsImpl); menu->addAction(com1); menu->addAction(com2); + menu->addAction(com1_stby); + menu->addAction(com2_stby); menu->addAction(text); menu->addSeparator(); menu->addAction(resize); @@ -160,11 +166,11 @@ namespace swift::gui::views } } - void CAtcStationTreeView::tuneInAtc(const misc::aviation::CComSystem::ComUnit unit) + void CAtcStationTreeView::tuneInAtc(const misc::aviation::CComSystem::ComUnit unit, const bool active) { const CAtcStation s(this->selectedObject()); if (s.getCallsign().isEmpty()) { return; } - emit this->requestComFrequency(s.getFrequency(), unit); + emit this->requestComFrequency(s.getFrequency(), unit, active); } void CAtcStationTreeView::requestTextMessage() diff --git a/src/gui/views/atcstationtreeview.h b/src/gui/views/atcstationtreeview.h index 80e146a53..c37be5b32 100644 --- a/src/gui/views/atcstationtreeview.h +++ b/src/gui/views/atcstationtreeview.h @@ -63,7 +63,7 @@ namespace swift::gui //! Request COM frequency void requestComFrequency(const swift::misc::physical_quantities::CFrequency &frequency, - swift::misc::aviation::CComSystem::ComUnit unit); + swift::misc::aviation::CComSystem::ComUnit unit, bool active); //! Request a text message to void requestTextMessageWidget(const swift::misc::aviation::CCallsign &callsign); @@ -107,7 +107,7 @@ namespace swift::gui //! @{ //! Tune in/invoke - void tuneInAtc(misc::aviation::CComSystem::ComUnit unit); + void tuneInAtc(misc::aviation::CComSystem::ComUnit unit, bool active); void requestTextMessage(); //! @} diff --git a/src/gui/views/atcstationview.cpp b/src/gui/views/atcstationview.cpp index 1f9032672..8947f0b05 100644 --- a/src/gui/views/atcstationview.cpp +++ b/src/gui/views/atcstationview.cpp @@ -57,26 +57,32 @@ namespace swift::gui::views if (this->hasSelection()) { - if (m_actions.isEmpty()) { m_actions = QList({ nullptr, nullptr, nullptr }); } + if (m_actions.isEmpty()) { m_actions = QList({ nullptr, nullptr, nullptr, nullptr, nullptr }); } - m_actions[0] = menuActions.addAction(m_actions[0], CIcons::appCockpit16(), "Tune in COM1", + m_actions[0] = menuActions.addAction(m_actions[0], CIcons::appCockpit16(), "Tune in COM1 (active)", CMenuAction::pathClientCom(), - { this, [this]() { tuneInAtc(CComSystem::Com1); } }); - m_actions[1] = menuActions.addAction(m_actions[1], CIcons::appCockpit16(), "Tune in COM2", + { this, [this]() { tuneInAtc(CComSystem::Com1, true); } }); + m_actions[1] = menuActions.addAction(m_actions[1], CIcons::appCockpit16(), "Tune in COM2 (active)", CMenuAction::pathClientCom(), - { this, [this]() { tuneInAtc(CComSystem::Com2); } }); - m_actions[2] = - menuActions.addAction(m_actions[2], CIcons::appTextMessages16(), "Show text messages", + { this, [this]() { tuneInAtc(CComSystem::Com2, true); } }); + m_actions[2] = menuActions.addAction(m_actions[2], CIcons::appCockpit16(), "Tune in COM1 (standby)", + CMenuAction::pathClientCom(), + { this, [this]() { tuneInAtc(CComSystem::Com1, false); } }); + m_actions[3] = menuActions.addAction(m_actions[3], CIcons::appCockpit16(), "Tune in COM2 (standby)", + CMenuAction::pathClientCom(), + { this, [this]() { tuneInAtc(CComSystem::Com2, false); } }); + m_actions[4] = + menuActions.addAction(m_actions[4], CIcons::appTextMessages16(), "Show text messages", CMenuAction::pathClientCom(), { this, &CAtcStationView::requestTextMessage }); } CViewBase::customMenu(menuActions); } - void CAtcStationView::tuneInAtc(const misc::aviation::CComSystem::ComUnit unit) + void CAtcStationView::tuneInAtc(const misc::aviation::CComSystem::ComUnit unit, const bool active) { const CAtcStation s(this->selectedObject()); if (s.getCallsign().isEmpty()) { return; } - emit this->requestComFrequency(s.getFrequency(), unit); + emit this->requestComFrequency(s.getFrequency(), unit, active); } void CAtcStationView::requestTextMessage() diff --git a/src/gui/views/atcstationview.h b/src/gui/views/atcstationview.h index 8c06f69d7..b9e3936b7 100644 --- a/src/gui/views/atcstationview.h +++ b/src/gui/views/atcstationview.h @@ -52,7 +52,7 @@ namespace swift::gui //! Request COM frequency void requestComFrequency(const swift::misc::physical_quantities::CFrequency &frequency, - swift::misc::aviation::CComSystem::ComUnit unit); + swift::misc::aviation::CComSystem::ComUnit unit, bool active); //! Request a text message to void requestTextMessageWidget(const swift::misc::aviation::CCallsign &callsign); @@ -64,7 +64,7 @@ namespace swift::gui private: void emitTestRequest1kAtcOnlineDummies() { emit this->testRequestDummyAtcOnlineStations(1000); } void emitTestRequest3kAtcOnlineDummies() { emit this->testRequestDummyAtcOnlineStations(3000); } - void tuneInAtc(misc::aviation::CComSystem::ComUnit unit); + void tuneInAtc(misc::aviation::CComSystem::ComUnit unit, bool active); void requestTextMessage(); QList m_actions; //!< real actions