refs #313 Register hotkey functions instead keyboard keys

This commit is contained in:
Roland Winklmeier
2014-08-04 20:34:44 +02:00
parent 15e6a21fa7
commit 4ac6a673c1
5 changed files with 30 additions and 55 deletions

View File

@@ -11,6 +11,8 @@
#include "blacksound/soundgenerator.h"
#include "blackmisc/notificationsounds.h"
#include "blackmisc/voiceroomlist.h"
#include "blackmisc/hotkeyfunction.h"
#include <QTimer>
@@ -27,14 +29,16 @@ namespace BlackCore
* Init this context
*/
CContextAudio::CContextAudio(CRuntimeConfig::ContextMode mode, CRuntime *runtime) :
IContextAudio(mode, runtime), m_voice(nullptr), m_keyboard(nullptr)
IContextAudio(mode, runtime), m_voice(nullptr), m_inputManager(nullptr)
{
// 1. Init by "voice driver"
this->m_voice = new CVoiceVatlib();
m_voice->moveToThread(&m_threadVoice);
m_threadVoice.start();
m_keyboard = BlackInput::IKeyboard::getInstance();
// 2. Register PTT hotkey function
m_inputManager = CInputManager::getInstance();
m_handlePtt = m_inputManager->registerHotkeyFunc(CHotkeyFunction::Ptt(), m_voice, &CVoiceVatlib::handlePushToTalk);
// 3. own aircraft, if possible
//if (this->getIContextOwnAircraft()) m_voice->setMyAircraftCallsign(this->getIContextOwnAircraft()->getOwnAircraft().getCallsign());
@@ -366,28 +370,6 @@ namespace BlackCore
m_voice->enableAudioLoopback(enable);
}
/*
* Settings changed
*/
void CContextAudio::ps_settingsChanged(uint typeValue)
{
if (this->getIContextOwnAircraft())
{
m_channelCom1->setMyAircraftCallsign(this->getIContextOwnAircraft()->getOwnAircraft().getCallsign());
m_channelCom2->setMyAircraftCallsign(this->getIContextOwnAircraft()->getOwnAircraft().getCallsign());
}
if (!this->getIContextSettings()) return;
IContextSettings::SettingsType type = static_cast<IContextSettings::SettingsType>(typeValue);
if (type == IContextSettings::SettingsHotKeys)
{
CKeyboardKeyList hotKeys = this->getIContextSettings()->getHotkeys();
Q_ASSERT(!hotKeys.isEmpty());
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);
}
}
/*
* Connection status changed
*/

View File

@@ -12,6 +12,7 @@
#include "dbus_server.h"
#include "voice_vatlib.h"
#include "voice_channel.h"
#include "input_manager.h"
#include "blackinput/keyboard.h"
#include "blackmisc/voiceroomlist.h"
@@ -117,8 +118,6 @@ namespace BlackCore
}
private slots:
//! Settings have been changed
void ps_settingsChanged(uint typeValue);
//! \copydoc IVoice::connectionStatusChanged
//! \sa IContextAudio::changedVoiceRooms
@@ -136,8 +135,8 @@ namespace BlackCore
bool inTransitionState() const;
CVoiceVatlib *m_voice; //!< underlying voice lib
BlackInput::IKeyboard *m_keyboard;
BlackInput::IKeyboard::RegistrationHandle m_handlePtt;
CInputManager *m_inputManager;
CInputManager::RegistrationHandle m_handlePtt;
QThread m_threadVoice;
QPointer<IVoiceChannel> m_channelCom1;
QPointer<IVoiceChannel> m_channelCom2;