Ref T494, audio settings for notification

* use new sounds
* fixed bug that changes of notifications were never set in settings
* play sound if box is checked (how hoes it sound?)
This commit is contained in:
Klaus Basan
2018-12-31 06:47:15 +01:00
committed by Mat Sutcliffe
parent 3137af30bb
commit 3be93ab753
3 changed files with 97 additions and 23 deletions

View File

@@ -24,7 +24,6 @@
using namespace BlackCore; using namespace BlackCore;
using namespace BlackCore::Context; using namespace BlackCore::Context;
using namespace BlackMisc; using namespace BlackMisc;
using namespace BlackGui;
using namespace BlackMisc::Aviation; using namespace BlackMisc::Aviation;
using namespace BlackMisc::Audio; using namespace BlackMisc::Audio;
using namespace BlackMisc::PhysicalQuantities; using namespace BlackMisc::PhysicalQuantities;
@@ -45,6 +44,7 @@ namespace BlackGui
// audio is optional // audio is optional
const bool audio = this->hasAudio(); const bool audio = this->hasAudio();
this->setEnabled(audio); this->setEnabled(audio);
this->reloadSettings();
bool c = connect(ui->cb_SetupAudioLoopback, &QCheckBox::toggled, this, &CAudioSetupComponent::onLoopbackToggled); bool c = connect(ui->cb_SetupAudioLoopback, &QCheckBox::toggled, this, &CAudioSetupComponent::onLoopbackToggled);
Q_ASSERT(c); Q_ASSERT(c);
@@ -69,20 +69,41 @@ namespace BlackGui
Q_ASSERT(c); Q_ASSERT(c);
c = connect(sGui->getIContextAudio(), &IContextAudio::changedSelectedAudioDevices, this, &CAudioSetupComponent::onCurrentAudioDevicesChanged, Qt::QueuedConnection); c = connect(sGui->getIContextAudio(), &IContextAudio::changedSelectedAudioDevices, this, &CAudioSetupComponent::onCurrentAudioDevicesChanged, Qt::QueuedConnection);
Q_ASSERT(c); Q_ASSERT(c);
// checkboxes for notifications
c = connect(ui->cb_SetupAudioPTTClick, &QCheckBox::toggled, this, &CAudioSetupComponent::onNotificationsToggled);
Q_ASSERT(c);
c = connect(ui->cb_SetupAudioNotificationVoiceRoomLeft, &QCheckBox::toggled, this, &CAudioSetupComponent::onNotificationsToggled);
Q_ASSERT(c);
c = connect(ui->cb_SetupAudioNotificationVoiceRoomJoined, &QCheckBox::toggled, this, &CAudioSetupComponent::onNotificationsToggled);
Q_ASSERT(c);
c = connect(ui->cb_SetupAudioNotificationTextMessagePrivate, &QCheckBox::toggled, this, &CAudioSetupComponent::onNotificationsToggled);
Q_ASSERT(c);
c = connect(ui->cb_SetupAudioNotificationTextCallsignMentioned, &QCheckBox::toggled, this, &CAudioSetupComponent::onNotificationsToggled);
Q_ASSERT(c);
} }
this->reloadSettings();
Q_UNUSED(c); Q_UNUSED(c);
} }
CAudioSetupComponent::~CAudioSetupComponent() CAudioSetupComponent::~CAudioSetupComponent()
{ } { }
bool CAudioSetupComponent::playNotificationSounds() const
{
if (!this->hasAudio()) { return false; }
return ui->cb_SetupAudioPTTClick->isChecked() || ui->cb_SetupAudioNotificationTextMessagePrivate->isChecked() ||
ui->cb_SetupAudioNotificationVoiceRoomLeft->isChecked() || ui->cb_SetupAudioNotificationVoiceRoomJoined->isChecked() ||
ui->cb_SetupAudioNotificationTextCallsignMentioned->isChecked();
}
void CAudioSetupComponent::reloadSettings() void CAudioSetupComponent::reloadSettings()
{ {
CSettings as(m_audioSettings.getThreadLocal()); const CSettings as(m_audioSettings.getThreadLocal());
ui->cb_SetupAudioPlayNotificationSounds->setChecked(true); ui->cb_SetupAudioPTTClick->setChecked(as.isNotificationFlagSet(CNotificationSounds::PTTClick));
ui->cb_SetupAudioNotificationTextMessage->setChecked(as.getNotificationFlag(CNotificationSounds::NotificationTextMessagePrivate)); ui->cb_SetupAudioNotificationVoiceRoomLeft->setChecked(as.isNotificationFlagSet(CNotificationSounds::NotificationVoiceRoomLeft));
ui->cb_SetupAudioNotificationVoiceRoom->setChecked(as.getNotificationFlag(CNotificationSounds::NotificationVoiceRoomJoined)); ui->cb_SetupAudioNotificationVoiceRoomJoined->setChecked(as.isNotificationFlagSet(CNotificationSounds::NotificationVoiceRoomJoined));
ui->cb_SetupAudioNotificationTextMessagePrivate->setChecked(as.isNotificationFlagSet(CNotificationSounds::NotificationTextMessagePrivate));
ui->cb_SetupAudioNotificationTextCallsignMentioned->setChecked(as.isNotificationFlagSet(CNotificationSounds::NotificationTextCallsignMentioned));
} }
void CAudioSetupComponent::initAudioDeviceLists() void CAudioSetupComponent::initAudioDeviceLists()
@@ -97,9 +118,16 @@ namespace BlackGui
return sGui && sGui->getIContextAudio() && !sGui->getIContextAudio()->isEmptyObject(); return sGui && sGui->getIContextAudio() && !sGui->getIContextAudio()->isEmptyObject();
} }
bool CAudioSetupComponent::playNotificationSounds() const CNotificationSounds::NotificationFlag CAudioSetupComponent::checkBoxToFlag(const QCheckBox *cb) const
{ {
return ui->cb_SetupAudioPlayNotificationSounds->isChecked(); if (!cb) { return CNotificationSounds::NoNotifications; }
if (cb == ui->cb_SetupAudioPTTClick) { return CNotificationSounds::PTTClick; }
if (cb == ui->cb_SetupAudioNotificationVoiceRoomJoined) { return CNotificationSounds::NotificationVoiceRoomJoined; }
if (cb == ui->cb_SetupAudioNotificationVoiceRoomLeft) { return CNotificationSounds::NotificationVoiceRoomLeft; }
if (cb == ui->cb_SetupAudioNotificationTextCallsignMentioned) { return CNotificationSounds::NotificationTextCallsignMentioned; }
if (cb == ui->cb_SetupAudioNotificationTextMessagePrivate) { return CNotificationSounds::NotificationTextMessagePrivate; }
return CNotificationSounds::NoNotifications;
} }
void CAudioSetupComponent::onAudioDeviceSelected(int index) void CAudioSetupComponent::onAudioDeviceSelected(int index)
@@ -110,7 +138,7 @@ namespace BlackGui
CAudioDeviceInfoList devices = sGui->getIContextAudio()->getAudioDevices(); CAudioDeviceInfoList devices = sGui->getIContextAudio()->getAudioDevices();
if (devices.isEmpty()) { return; } if (devices.isEmpty()) { return; }
CAudioDeviceInfo selectedDevice; CAudioDeviceInfo selectedDevice;
QObject *sender = QObject::sender(); const QObject *sender = QObject::sender();
if (sender == ui->cb_SetupAudioInputDevice) if (sender == ui->cb_SetupAudioInputDevice)
{ {
CAudioDeviceInfoList inputDevices = devices.getInputDevices(); CAudioDeviceInfoList inputDevices = devices.getInputDevices();
@@ -166,5 +194,24 @@ namespace BlackGui
if (sGui->getIContextAudio()->isAudioLoopbackEnabled() == loopback) { return; } if (sGui->getIContextAudio()->isAudioLoopbackEnabled() == loopback) { return; }
sGui->getIContextAudio()->enableAudioLoopback(loopback); sGui->getIContextAudio()->enableAudioLoopback(loopback);
} }
void CAudioSetupComponent::onNotificationsToggled(bool checked)
{
CSettings as(m_audioSettings.getThreadLocal());
as.setNotificationFlag(CNotificationSounds::PTTClick, ui->cb_SetupAudioPTTClick->isChecked());
as.setNotificationFlag(CNotificationSounds::NotificationVoiceRoomLeft, ui->cb_SetupAudioNotificationVoiceRoomLeft->isChecked());
as.setNotificationFlag(CNotificationSounds::NotificationVoiceRoomJoined, ui->cb_SetupAudioNotificationVoiceRoomJoined->isChecked());
as.setNotificationFlag(CNotificationSounds::NotificationTextMessagePrivate, ui->cb_SetupAudioNotificationTextMessagePrivate->isChecked());
as.setNotificationFlag(CNotificationSounds::NotificationTextCallsignMentioned, ui->cb_SetupAudioNotificationTextCallsignMentioned->isChecked());
const CStatusMessage msg = m_audioSettings.set(as);
CLogMessage(this).preformatted(msg);
const QCheckBox *sender = qobject_cast<const QCheckBox *>(QObject::sender());
if (checked && this->hasAudio() && sender)
{
const CNotificationSounds::NotificationFlag f = this->checkBoxToFlag(sender);
sGui->getIContextAudio()->playNotification(f, false);
}
}
} // namespace } // namespace
} // namespace } // namespace

View File

@@ -12,17 +12,16 @@
#ifndef BLACKGUI_AUDIOSETUPCOMPONENT_H #ifndef BLACKGUI_AUDIOSETUPCOMPONENT_H
#define BLACKGUI_AUDIOSETUPCOMPONENT_H #define BLACKGUI_AUDIOSETUPCOMPONENT_H
#include "blackcore/audio/audiosettings.h"
#include "blackgui/blackguiexport.h" #include "blackgui/blackguiexport.h"
#include "blackcore/audio/audiosettings.h"
#include "blackmisc/audio/audiodeviceinfolist.h" #include "blackmisc/audio/audiodeviceinfolist.h"
#include "blackmisc/settingscache.h" #include "blackmisc/settingscache.h"
#include <QFrame> #include <QFrame>
#include <QCheckBox>
#include <QObject> #include <QObject>
#include <QScopedPointer> #include <QScopedPointer>
class QWidget;
namespace Ui { class CAudioSetupComponent; } namespace Ui { class CAudioSetupComponent; }
namespace BlackGui namespace BlackGui
{ {
@@ -40,7 +39,7 @@ namespace BlackGui
//! Destructor //! Destructor
virtual ~CAudioSetupComponent(); virtual ~CAudioSetupComponent();
//! Play notification sounds (at all) //! Play any sounds?
bool playNotificationSounds() const; bool playNotificationSounds() const;
private: private:
@@ -60,12 +59,18 @@ namespace BlackGui
//! Loopback toggled //! Loopback toggled
void onLoopbackToggled(bool loopback); void onLoopbackToggled(bool loopback);
//! Notification flags toggled
void onNotificationsToggled(bool checked);
//! Audio device lists from settings //! Audio device lists from settings
void initAudioDeviceLists(); void initAudioDeviceLists();
//! Audio is optional, check if available //! Audio is optional, check if available
bool hasAudio() const; bool hasAudio() const;
//! CheckBox to flag
BlackMisc::Audio::CNotificationSounds::NotificationFlag checkBoxToFlag(const QCheckBox *cb) const;
QScopedPointer<Ui::CAudioSetupComponent> ui; QScopedPointer<Ui::CAudioSetupComponent> ui;
BlackMisc::CSetting<BlackCore::Audio::TSettings> m_audioSettings { this, &CAudioSetupComponent::reloadSettings }; BlackMisc::CSetting<BlackCore::Audio::TSettings> m_audioSettings { this, &CAudioSetupComponent::reloadSettings };
}; };

View File

@@ -6,7 +6,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>200</width> <width>216</width>
<height>322</height> <height>322</height>
</rect> </rect>
</property> </property>
@@ -128,26 +128,37 @@
</widget> </widget>
</item> </item>
<item row="4" column="1"> <item row="4" column="1">
<widget class="QCheckBox" name="cb_SetupAudioPlayNotificationSounds"> <widget class="QCheckBox" name="cb_SetupAudioNotificationTextMessagePrivate">
<property name="text"> <property name="text">
<string>play notification sounds</string> <string>notification for private text messages</string>
</property>
<property name="checked">
<bool>false</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item row="5" column="1"> <item row="5" column="1">
<widget class="QCheckBox" name="cb_SetupAudioNotificationTextMessage"> <widget class="QCheckBox" name="cb_SetupAudioNotificationTextCallsignMentioned">
<property name="text"> <property name="text">
<string>notification for text messages</string> <string>notfication for text msg. with my callsign</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="6" column="1"> <item row="6" column="1">
<widget class="QCheckBox" name="cb_SetupAudioNotificationVoiceRoom"> <widget class="QCheckBox" name="cb_SetupAudioNotificationVoiceRoomJoined">
<property name="text"> <property name="text">
<string>notification for join/leave voice room</string> <string>notification joining a voice room</string>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QCheckBox" name="cb_SetupAudioPTTClick">
<property name="text">
<string>PTT click</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QCheckBox" name="cb_SetupAudioNotificationVoiceRoomLeft">
<property name="text">
<string>notification leaving a voice room</string>
</property> </property>
</widget> </widget>
</item> </item>
@@ -168,6 +179,17 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<tabstops>
<tabstop>le_ExtraInfo</tabstop>
<tabstop>cb_SetupAudioInputDevice</tabstop>
<tabstop>cb_SetupAudioOutputDevice</tabstop>
<tabstop>cb_SetupAudioLoopback</tabstop>
<tabstop>cb_SetupAudioNotificationTextMessagePrivate</tabstop>
<tabstop>cb_SetupAudioNotificationTextCallsignMentioned</tabstop>
<tabstop>cb_SetupAudioNotificationVoiceRoomJoined</tabstop>
<tabstop>cb_SetupAudioNotificationVoiceRoomLeft</tabstop>
<tabstop>cb_SetupAudioPTTClick</tabstop>
</tabstops>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>