From 291b477d448aaeda830725204ca5fbbeebe289f7 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Mon, 29 Apr 2019 02:17:51 +0200 Subject: [PATCH] Ref T644, allow to set notification sounds directory --- .../components/audiosetupcomponent.cpp | 49 +++++-- src/blackgui/components/audiosetupcomponent.h | 8 +- .../components/audiosetupcomponent.ui | 121 ++++++++++++------ 3 files changed, 127 insertions(+), 51 deletions(-) diff --git a/src/blackgui/components/audiosetupcomponent.cpp b/src/blackgui/components/audiosetupcomponent.cpp index 4ea2df206..8eba824cf 100644 --- a/src/blackgui/components/audiosetupcomponent.cpp +++ b/src/blackgui/components/audiosetupcomponent.cpp @@ -20,6 +20,7 @@ #include #include #include +#include using namespace BlackCore; using namespace BlackCore::Context; @@ -51,8 +52,7 @@ namespace BlackGui void CAudioSetupComponent::init() { - Q_ASSERT_X(sGui, Q_FUNC_INFO, "Missing sGui"); - Q_ASSERT_X(sGui->getIContextAudio(), Q_FUNC_INFO, "Missing Audio context"); + if (!sGui || sGui->isShuttingDown() || !sGui->getIContextAudio()) { return; } // audio is optional const bool audio = this->hasAudio(); @@ -84,21 +84,25 @@ namespace BlackGui Q_ASSERT(c); // checkboxes for notifications - c = connect(ui->cb_SetupAudioPTTClickDown, &QCheckBox::toggled, this, &CAudioSetupComponent::onNotificationsToggled); + c = connect(ui->cb_SetupAudioPTTClickDown, &QCheckBox::toggled, this, &CAudioSetupComponent::onNotificationsToggled, Qt::QueuedConnection); Q_ASSERT(c); - c = connect(ui->cb_SetupAudioPTTClickUp, &QCheckBox::toggled, this, &CAudioSetupComponent::onNotificationsToggled); + c = connect(ui->cb_SetupAudioPTTClickUp, &QCheckBox::toggled, this, &CAudioSetupComponent::onNotificationsToggled, Qt::QueuedConnection); Q_ASSERT(c); - c = connect(ui->cb_SetupAudioNotificationVoiceRoomLeft, &QCheckBox::toggled, this, &CAudioSetupComponent::onNotificationsToggled); + c = connect(ui->cb_SetupAudioNotificationVoiceRoomLeft, &QCheckBox::toggled, this, &CAudioSetupComponent::onNotificationsToggled, Qt::QueuedConnection); Q_ASSERT(c); - c = connect(ui->cb_SetupAudioNotificationVoiceRoomJoined, &QCheckBox::toggled, this, &CAudioSetupComponent::onNotificationsToggled); + c = connect(ui->cb_SetupAudioNotificationVoiceRoomJoined, &QCheckBox::toggled, this, &CAudioSetupComponent::onNotificationsToggled, Qt::QueuedConnection); Q_ASSERT(c); - c = connect(ui->cb_SetupAudioNotificationTextMessagePrivate, &QCheckBox::toggled, this, &CAudioSetupComponent::onNotificationsToggled); + c = connect(ui->cb_SetupAudioNotificationTextMessagePrivate, &QCheckBox::toggled, this, &CAudioSetupComponent::onNotificationsToggled, Qt::QueuedConnection); Q_ASSERT(c); - c = connect(ui->cb_SetupAudioNotificationTextMessageSupervisor, &QCheckBox::toggled, this, &CAudioSetupComponent::onNotificationsToggled); + c = connect(ui->cb_SetupAudioNotificationTextMessageSupervisor, &QCheckBox::toggled, this, &CAudioSetupComponent::onNotificationsToggled, Qt::QueuedConnection); Q_ASSERT(c); - c = connect(ui->cb_SetupAudioNotificationTextCallsignMentioned, &QCheckBox::toggled, this, &CAudioSetupComponent::onNotificationsToggled); + c = connect(ui->cb_SetupAudioNotificationTextCallsignMentioned, &QCheckBox::toggled, this, &CAudioSetupComponent::onNotificationsToggled, Qt::QueuedConnection); Q_ASSERT(c); - c = connect(ui->cb_SetupAudioNoTransmission, &QCheckBox::toggled, this, &CAudioSetupComponent::onNotificationsToggled); + c = connect(ui->cb_SetupAudioNoTransmission, &QCheckBox::toggled, this, &CAudioSetupComponent::onNotificationsToggled, Qt::QueuedConnection); + Q_ASSERT(c); + c = connect(ui->pb_SoundReset, &QPushButton::released, this, &CAudioSetupComponent::resetNotificationSoundsDir, Qt::QueuedConnection); + Q_ASSERT(c); + c = connect(ui->pb_SoundDir, &QPushButton::released, this, &CAudioSetupComponent::selectNotificationSoundsDir, Qt::QueuedConnection); Q_ASSERT(c); } Q_UNUSED(c); @@ -129,6 +133,8 @@ namespace BlackGui ui->cb_SetupAudioNotificationTextMessageSupervisor->setChecked(as.isNotificationFlagSet(CNotificationSounds::NotificationTextMessageSupervisor)); ui->cb_SetupAudioNotificationTextCallsignMentioned->setChecked(as.isNotificationFlagSet(CNotificationSounds::NotificationTextCallsignMentioned)); ui->cb_SetupAudioNoTransmission->setChecked(as.isNotificationFlagSet(CNotificationSounds::NotificationNoAudioTransmission)); + + ui->le_SoundDir->setText(as.getNotificationSoundDirectory()); } void CAudioSetupComponent::initAudioDeviceLists() @@ -249,5 +255,28 @@ namespace BlackGui sGui->getIContextAudio()->playNotification(f, false); } } + + void CAudioSetupComponent::selectNotificationSoundsDir() + { + CSettings s = m_audioSettings.get(); + const QString dir = QFileDialog::getExistingDirectory(this, QStringLiteral("Open directory"), s.getNotificationSoundDirectory(), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); + const QDir d(dir); + if (d.exists()) + { + s.setNotificationSoundDirectory(dir); + ui->le_SoundDir->setText(s.getNotificationSoundDirectory()); + const CStatusMessage m = m_audioSettings.setAndSave(s); + CLogMessage::preformatted(m); + } + } + + void CAudioSetupComponent::resetNotificationSoundsDir() + { + CSettings s = m_audioSettings.get(); + s.setNotificationSoundDirectory(""); + const CStatusMessage m = m_audioSettings.setAndSave(s); + CLogMessage::preformatted(m); + ui->le_SoundDir->clear(); + } } // namespace } // namespace diff --git a/src/blackgui/components/audiosetupcomponent.h b/src/blackgui/components/audiosetupcomponent.h index d7a861f5f..c14625b09 100644 --- a/src/blackgui/components/audiosetupcomponent.h +++ b/src/blackgui/components/audiosetupcomponent.h @@ -36,7 +36,7 @@ namespace BlackGui explicit CAudioSetupComponent(QWidget *parent = nullptr); //! Destructor - virtual ~CAudioSetupComponent(); + virtual ~CAudioSetupComponent() override; //! Play any sounds? bool playNotificationSounds() const; @@ -64,6 +64,12 @@ namespace BlackGui //! Notification flags toggled void onNotificationsToggled(bool checked); + //! Notification sounds dir + void selectNotificationSoundsDir(); + + //! Notification sounds dir + void resetNotificationSoundsDir(); + //! Audio device lists from settings void initAudioDeviceLists(); diff --git a/src/blackgui/components/audiosetupcomponent.ui b/src/blackgui/components/audiosetupcomponent.ui index be8511b28..95c5091f0 100644 --- a/src/blackgui/components/audiosetupcomponent.ui +++ b/src/blackgui/components/audiosetupcomponent.ui @@ -6,22 +6,13 @@ 0 0 - 216 - 322 + 277 + 464 Audio setup - - QFrame::NoFrame - - - QFrame::Plain - - - 0 - 2 @@ -118,6 +109,52 @@ + + + Dir.: + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + your private sound directory + + + + + + + reset + + + + + + + [...] + + + + + + + Notifications @@ -127,7 +164,7 @@ - + notification for private text messages @@ -135,41 +172,34 @@ - - - notfication for text msg. with my callsign - - - - - - - notification joining a voice room - - - - - - - PTT click (key down) - - - - - - - notification leaving a voice room - - - - supervisor messages + + + + notfication for text msg. with my callsign + + + + + + + notification joining a voice room + + + + + + notification leaving a voice room + + + + No audio transmission warning @@ -177,6 +207,13 @@ + + + PTT click (key down) + + + + PTT click (key up) @@ -205,6 +242,9 @@ cb_SetupAudioInputDevice cb_SetupAudioOutputDevice cb_SetupAudioLoopback + le_SoundDir + pb_SoundReset + pb_SoundDir cb_SetupAudioNotificationTextMessagePrivate cb_SetupAudioNotificationTextMessageSupervisor cb_SetupAudioNotificationTextCallsignMentioned @@ -212,6 +252,7 @@ cb_SetupAudioNotificationVoiceRoomLeft cb_SetupAudioNoTransmission cb_SetupAudioPTTClickDown + cb_SetupAudioPTTClickUp