diff --git a/src/blackcore/context_audio_impl.cpp b/src/blackcore/context_audio_impl.cpp index 5d4435f21..12e2cfd9b 100644 --- a/src/blackcore/context_audio_impl.cpp +++ b/src/blackcore/context_audio_impl.cpp @@ -25,7 +25,8 @@ namespace BlackCore CContextAudio::CContextAudio(QObject *parent) : IContextAudio(parent), m_voice(nullptr), - m_keyboard(nullptr) + m_keyboard(nullptr), + m_contextSettings(nullptr) { // 1. Init by "voice driver" this->m_voice = new CVoiceVatlib(this); @@ -44,6 +45,12 @@ namespace BlackCore this->leaveAllVoiceRooms(); } + void CContextAudio::init() + { + m_contextSettings = getRuntime()->getIContextSettings(); + connect(m_contextSettings, &IContextSettings::changedSettings, this, &CContextAudio::settingsChanged); + } + /* * Own aircraft */ @@ -281,4 +288,15 @@ namespace BlackCore return static_cast(this->m_voice->inputSquelch()); } + void CContextAudio::settingsChanged(IContextSettings::SettingsType type) + { + if (type == IContextSettings::SettingsHotKeys) + { + CKeyboardKeyList hotKeys = m_contextSettings->getHotkeys(); + CKeyboardKey pttKey = hotKeys.findBy(&BlackMisc::Hardware::CKeyboardKey::getFunction, BlackMisc::Hardware::CKeyboardKey::HotkeyPtt).front(); + m_keyboard->unregisterHotkey(m_handlePtt); + m_handlePtt = m_keyboard->registerHotkey(pttKey, m_voice, &CVoiceVatlib::handlePushToTalk); + } + } + } // namespace diff --git a/src/blackcore/context_audio_impl.h b/src/blackcore/context_audio_impl.h index f31d97106..e3bd210bd 100644 --- a/src/blackcore/context_audio_impl.h +++ b/src/blackcore/context_audio_impl.h @@ -7,9 +7,11 @@ #define BLACKCORE_CONTEXTAUDIO_IMPL_H #include "context_audio.h" +#include "context_settings.h" #include "coreruntime.h" #include "dbus_server.h" #include "voice_vatlib.h" +#include "blackcore/keyboard.h" namespace BlackCore { @@ -52,6 +54,9 @@ namespace BlackCore //! \copydoc IContextAudio::usingLocalObjects() virtual bool usingLocalObjects() const override { return true; } + //! \brief Initialize voice context + void init(); + public slots: //! \copydoc IContextAudio::setOwnAircraft() virtual void setOwnAircraft(const BlackMisc::Aviation::CAircraft &ownAircraft) override; @@ -119,6 +124,9 @@ namespace BlackCore //! \copydoc IContextAudio::getSquelchValue() virtual double getSquelchValue() const override; + private slots: + void settingsChanged(IContextSettings::SettingsType type); + private: CVoiceVatlib *m_voice; //!< underlying voice lib IKeyboard *m_keyboard; diff --git a/src/blackcore/context_settings.h b/src/blackcore/context_settings.h index 6b168d09b..1652900a2 100644 --- a/src/blackcore/context_settings.h +++ b/src/blackcore/context_settings.h @@ -6,10 +6,14 @@ #ifndef BLACKCORE_CONTEXTSETTINGS_H #define BLACKCORE_CONTEXTSETTINGS_H +#include "blackcore/coreruntime.h" +#include "blackcore/dbus_server.h" +#include "blackcore/keyboard.h" +#include "blackmisc/hwkeyboardkeylist.h" #include "blackmisc/statusmessagelist.h" #include "blackmisc/settingutilities.h" #include "blackmisc/setnetwork.h" -#include "blackmisc/hwkeyboardkeylist.h" + #include #include @@ -30,6 +34,12 @@ namespace BlackCore public: + enum SettingsType + { + SettingsHotKeys, + SettingsNetwork + }; + /*! * \brief Service name */ @@ -103,7 +113,7 @@ namespace BlackCore signals: //! \brief Settings have been changed - void changedSettings(); + void changedSettings(SettingsType type); //! \brief Network settings have been changed void changedNetworkSettings(); diff --git a/src/blackcore/context_settings_impl.cpp b/src/blackcore/context_settings_impl.cpp index 98f8e4fb7..074965094 100644 --- a/src/blackcore/context_settings_impl.cpp +++ b/src/blackcore/context_settings_impl.cpp @@ -68,7 +68,8 @@ namespace BlackCore { BlackMisc::Hardware::CKeyboardKeyList hotkeys = value.value(); this->m_hotkeys = hotkeys; - emit this->changedSettings(); + emit this->changedSettings(SettingsHotKeys); + msgs.push_back(CStatusMessage::getInfoMessage("set hotkeys")); return msgs; } @@ -84,7 +85,7 @@ namespace BlackCore if (changed) { emit this->changedNetworkSettings(); - emit this->changedSettings(); + emit this->changedSettings(SettingsNetwork); } } else diff --git a/src/blackcore/coreruntime.cpp b/src/blackcore/coreruntime.cpp index 90c746d6d..eb2885cce 100644 --- a/src/blackcore/coreruntime.cpp +++ b/src/blackcore/coreruntime.cpp @@ -52,6 +52,8 @@ void CCoreRuntime::init(bool withDbus) this->m_contextSimulator = new CContextSimulator(this); if (withDbus) this->m_contextSimulator->registerWithDBus(this->m_dbusServer); + m_contextAudio->init(); + // flag m_init = true; }