From 365c52613acf755834ddb4358c85fe25246303f4 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sat, 26 Jan 2019 01:24:47 +0100 Subject: [PATCH] Audio setup component deferred init, because in a distributed swift system it takes a moment until the settings are sychronized this is leading to undesired "save settings" messages and played sounds --- .../components/audiosetupcomponent.cpp | 18 ++++++++++++++++-- src/blackgui/components/audiosetupcomponent.h | 3 +++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/blackgui/components/audiosetupcomponent.cpp b/src/blackgui/components/audiosetupcomponent.cpp index aa6785303..7a1117862 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; @@ -38,6 +39,19 @@ namespace BlackGui { ui->setupUi(this); + // deferred init, because in a distributed swift system + // it takes a moment until the settings are sychronized + // this is leading to undesired "save settings" messages and played sounds + QPointer myself(this); + QTimer::singleShot(2500, this, [ = ] + { + if (!myself || !sGui || sGui->isShuttingDown()) { return; } + this->init(); + }); + } + + void CAudioSetupComponent::init() + { Q_ASSERT_X(sGui, Q_FUNC_INFO, "Missing sGui"); Q_ASSERT_X(sGui->getIContextAudio(), Q_FUNC_INFO, "Missing Audio context"); @@ -141,14 +155,14 @@ namespace BlackGui const QObject *sender = QObject::sender(); if (sender == ui->cb_SetupAudioInputDevice) { - CAudioDeviceInfoList inputDevices = devices.getInputDevices(); + const CAudioDeviceInfoList inputDevices = devices.getInputDevices(); if (index >= inputDevices.size()) { return; } selectedDevice = inputDevices[index]; sGui->getIContextAudio()->setCurrentAudioDevice(selectedDevice); } else if (sender == ui->cb_SetupAudioOutputDevice) { - CAudioDeviceInfoList outputDevices = devices.getOutputDevices(); + const CAudioDeviceInfoList outputDevices = devices.getOutputDevices(); if (index >= outputDevices.size()) { return; } selectedDevice = outputDevices[index]; sGui->getIContextAudio()->setCurrentAudioDevice(selectedDevice); diff --git a/src/blackgui/components/audiosetupcomponent.h b/src/blackgui/components/audiosetupcomponent.h index 275b79299..906d89468 100644 --- a/src/blackgui/components/audiosetupcomponent.h +++ b/src/blackgui/components/audiosetupcomponent.h @@ -43,6 +43,9 @@ namespace BlackGui bool playNotificationSounds() const; private: + //! Init + void init(); + //! Reload settings void reloadSettings();