From 67f0c22f09ac23a68b14b12ecb5924888e83c795 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 22 Oct 2014 15:03:42 +0200 Subject: [PATCH] refs #335, added mute / volume functions for infobarstatus --- .../components/infobarstatuscomponent.cpp | 75 ++++++++++--------- .../components/infobarstatuscomponent.h | 16 ++-- 2 files changed, 49 insertions(+), 42 deletions(-) diff --git a/src/blackgui/components/infobarstatuscomponent.cpp b/src/blackgui/components/infobarstatuscomponent.cpp index 77e00d66d..4fa5b106a 100644 --- a/src/blackgui/components/infobarstatuscomponent.cpp +++ b/src/blackgui/components/infobarstatuscomponent.cpp @@ -9,10 +9,12 @@ #include "infobarstatuscomponent.h" #include "ui_infobarstatuscomponent.h" -#include "blackmisc/icons.h" #include "blackcore/context_simulator.h" #include "blackcore/context_network.h" #include "blackcore/context_application.h" +#include "blackcore/context_audio.h" +#include "blackmisc/project.h" +#include "blackmisc/icons.h" #include #include @@ -37,9 +39,7 @@ namespace BlackGui } CInfoBarStatusComponent::~CInfoBarStatusComponent() - { - delete ui; - } + { } void CInfoBarStatusComponent::initLeds() { @@ -63,53 +63,45 @@ namespace BlackGui this->ui->led_DBus->setOnToolTip(tooltip); } - void CInfoBarStatusComponent::setVolume(int volume) - { - if (volume < 1) - { - this->ui->led_Audio->setOn(false); - } - else - { - this->ui->led_Audio->setOn(true); - } - } - void CInfoBarStatusComponent::runtimeHasBeenSet() { + if (getIContextApplication()->isEmptyObject()) return; + + // TODO: remove checks when empty contexts are fully introduced Q_ASSERT(getIContextSimulator()); Q_ASSERT(getIContextAudio()); Q_ASSERT(getIContextNetwork()); if (this->getIContextSimulator()) { - connect(this->getIContextSimulator(), &IContextSimulator::connectionChanged, this, &CInfoBarStatusComponent::ps_simulatorConnectionChanged); + connect(this->getIContextSimulator(), &IContextSimulator::connectionChanged, this, &CInfoBarStatusComponent::ps_onSimulatorConnectionChanged); } if (this->getIContextNetwork()) { - connect(this->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CInfoBarStatusComponent::ps_networkConnectionChanged); + this->ui->led_Simulator->setOn(this->getIContextSimulator()->isConnected()); + connect(this->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CInfoBarStatusComponent::ps_onNetworkConnectionChanged); } if (this->getIContextApplication()) { - if (this->getIContextApplication()->isUsingImplementingObject()) - { - this->ui->led_DBus->setOn(false); - } - else - { - this->ui->led_DBus->setOn(true); - } + this->ui->led_DBus->setOn(this->getIContextApplication()->isUsingImplementingObject()); + } + + if (this->getIContextAudio()) + { + this->ui->led_Audio->setOn(!this->getIContextAudio()->isMuted()); + connect(getIContextAudio(), &IContextAudio::changedMute, this, &CInfoBarStatusComponent::ps_onMuteChanged); + connect(getIContextAudio(), &IContextAudio::changedAudioVolumes, this, &CInfoBarStatusComponent::ps_onVolumesChanged); } } - void CInfoBarStatusComponent::ps_simulatorConnectionChanged(bool connected) + void CInfoBarStatusComponent::ps_onSimulatorConnectionChanged(bool connected) { this->ui->led_Simulator->setOn(connected); } - void CInfoBarStatusComponent::ps_networkConnectionChanged(uint from, uint to, const QString &message) + void CInfoBarStatusComponent::ps_onNetworkConnectionChanged(uint from, uint to, const QString &message) { INetwork::ConnectionStatus fromStatus = static_cast(from); INetwork::ConnectionStatus toStatus = static_cast(to); @@ -145,13 +137,10 @@ namespace BlackGui QMenu menuAudio(this); menuAudio.addAction("Toogle mute"); -#if defined(Q_OS_WIN) - // QSysInfo::WindowsVersion only available on Win platforms - if (QSysInfo::WindowsVersion & QSysInfo::WV_NT_based) + if (CProject::isRunningOnWindowsNtPlatform()) { menuAudio.addAction("Mixer"); } -#endif QAction *selectedItem = menuAudio.exec(globalPosition); if (selectedItem) @@ -160,14 +149,28 @@ namespace BlackGui const QList actions = menuAudio.actions(); if (selectedItem == actions.at(0)) { - // TODO: toogle mute + this->getIContextAudio()->setMute(!this->getIContextAudio()->isMuted()); } else if (actions.size() > 1 && selectedItem == actions.at(1)) { - QStringList parameterlist; - QProcess::startDetached("SndVol.exe", parameterlist); + BlackMisc::Audio::startWindowsMixer(); } } - } // custom menu + } + + void CInfoBarStatusComponent::ps_onVolumesChanged(QList volumes) + { + Q_ASSERT(volumes.count() == 2); + if (volumes.count() != 2) { return; } + qint32 v1 = volumes.at(0); + qint32 v2 = volumes.at(1); + bool pseudoMute = (v1 < 1 && v2 < 1); + this->ps_onMuteChanged(pseudoMute); + } + + void CInfoBarStatusComponent::ps_onMuteChanged(bool muted) + { + this->ui->led_Audio->setOn(!muted); + } } } diff --git a/src/blackgui/components/infobarstatuscomponent.h b/src/blackgui/components/infobarstatuscomponent.h index e4fff2f61..38660bbaf 100644 --- a/src/blackgui/components/infobarstatuscomponent.h +++ b/src/blackgui/components/infobarstatuscomponent.h @@ -15,6 +15,7 @@ #include "enableforruntime.h" #include "../led.h" #include +#include namespace Ui { class CInfoBarStatusComponent; } namespace BlackGui @@ -44,25 +45,28 @@ namespace BlackGui //! Tooltip for DBus void setDBusTooltip(const QString &tooltip); - //! Volume 0.100 - void setVolume(int volume); - protected: //! \copydoc CRuntimeBasedComponent::runtimeHasBeenSet virtual void runtimeHasBeenSet() override; private: - Ui::CInfoBarStatusComponent *ui; + QScopedPointer ui; private slots: //! Simulator connection has been changed - void ps_simulatorConnectionChanged(bool connected); + void ps_onSimulatorConnectionChanged(bool connected); //! Network connection has been changed - void ps_networkConnectionChanged(uint from, uint to, const QString &message); + void ps_onNetworkConnectionChanged(uint from, uint to, const QString &message); //! Context menu requested void ps_customAudioContextMenuRequested(const QPoint &position); + + //! Volumes changed 0..100 + void ps_onVolumesChanged(QList volumes); + + //! Mute changed + void ps_onMuteChanged(bool muted); }; } }