Skip to content

Commit

Permalink
feat: allow set pausePlayer availablity
Browse files Browse the repository at this point in the history
Log:
  • Loading branch information
Decodetalkers authored and deepin-bot[bot] committed Oct 17, 2023
1 parent 2ea09c2 commit dddcd05
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/plugin-sound/operation/sounddbusproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ void SoundDBusProxy::setReduceNoise(bool value)
m_audioInter->setProperty("ReduceNoise", QVariant::fromValue(value));
}

bool SoundDBusProxy::pausePlayer()
{
return qvariant_cast<bool>(m_audioInter->property("PausePlayer"));
}

void SoundDBusProxy::setPausePlayer(bool value)
{
m_audioInter->setProperty("PausePlayer", QVariant::fromValue(value));
}

void SoundDBusProxy::SetPortEnabled(uint in0, const QString &in1, bool in2)
{
QList<QVariant> argumentList;
Expand Down
7 changes: 7 additions & 0 deletions src/plugin-sound/operation/sounddbusproxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,15 @@ class SoundDBusProxy : public QObject
Q_PROPERTY(bool IncreaseVolume READ increaseVolume WRITE setIncreaseVolume NOTIFY IncreaseVolumeChanged)
bool increaseVolume();
void setIncreaseVolume(bool value);

Q_PROPERTY(bool ReduceNoise READ reduceNoise WRITE setReduceNoise NOTIFY ReduceNoiseChanged)
bool reduceNoise();
void setReduceNoise(bool value);

Q_PROPERTY(bool PausePlayer READ pausePlayer WRITE setPausePlayer NOTIFY PausePlayerChanged)
bool pausePlayer();
void setPausePlayer(bool value);

Q_PROPERTY(QString BluetoothAudioMode READ bluetoothAudioMode NOTIFY BluetoothAudioModeChanged)
QString bluetoothAudioMode();
Q_PROPERTY(QStringList BluetoothAudioModeOpts READ bluetoothAudioModeOpts NOTIFY BluetoothAudioModeOptsChanged)
Expand Down Expand Up @@ -131,6 +137,7 @@ class SoundDBusProxy : public QObject
void IncreaseVolumeChanged(bool value) const;
void MaxUIVolumeChanged(double value) const;
void ReduceNoiseChanged(bool value) const;
void PausePlayerChanged(bool value) const;
void SinkInputsChanged(const QList<QDBusObjectPath> &value) const;
void SinksChanged(const QList<QDBusObjectPath> &value) const;
void SourcesChanged(const QList<QDBusObjectPath> &value) const;
Expand Down
8 changes: 8 additions & 0 deletions src/plugin-sound/operation/soundmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ void SoundModel::setReduceNoise(bool reduceNoise)
}
}

void SoundModel::setPausePlayer(bool pausePlayer)
{
if (pausePlayer != m_pausePlayer) {
m_pausePlayer = pausePlayer;
Q_EMIT pausePlayerChanged(pausePlayer);
}
}


void SoundModel::setMicrophoneOn(bool microphoneOn)
{
Expand Down
5 changes: 5 additions & 0 deletions src/plugin-sound/operation/soundmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ class SoundModel : public QObject
inline bool reduceNoise() const { return m_reduceNoise; }
void setReduceNoise(bool reduceNoise);

inline bool pausePlayer() const { return m_pausePlayer; }
void setPausePlayer(bool reduceNoise);

inline bool microphoneOn() const { return m_microphoneOn; }
void setMicrophoneOn(bool microphoneOn);

Expand Down Expand Up @@ -200,6 +203,7 @@ class SoundModel : public QObject
void maxUIVolumeChanged(double value) const;
void increaseVolumeChanged(bool value) const;
void reduceNoiseChanged(bool reduceNoise) const;
void pausePlayerChanged(bool pausePlayer) const;
void isPortEnableChanged(bool enable) const;
void bluetoothModeOptsChanged(const QStringList &modeOpts) const;
void bluetoothModeChanged(const QString &mode);
Expand Down Expand Up @@ -230,6 +234,7 @@ class SoundModel : public QObject
bool m_isLaptop;
bool m_increaseVolume{false};
bool m_reduceNoise{true};
bool m_pausePlayer{true};
bool m_portEnable{false};
double m_speakerVolume;
double m_speakerBalance;
Expand Down
7 changes: 7 additions & 0 deletions src/plugin-sound/operation/soundworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ void SoundWorker::initConnect()
connect(m_soundDBusInter, &SoundDBusProxy::IncreaseVolumeChanged, m_model, &SoundModel::setIncreaseVolume);
connect(m_soundDBusInter, &SoundDBusProxy::CardsWithoutUnavailableChanged, m_model, &SoundModel::setAudioCards);
connect(m_soundDBusInter, &SoundDBusProxy::ReduceNoiseChanged, m_model, &SoundModel::setReduceNoise);
connect(m_soundDBusInter, &SoundDBusProxy::PausePlayerChanged, m_model, &SoundModel::setPausePlayer);
connect(m_soundDBusInter, &SoundDBusProxy::BluetoothAudioModeOptsChanged, m_model, &SoundModel::setBluetoothAudioModeOpts);
connect(m_soundDBusInter, &SoundDBusProxy::BluetoothAudioModeChanged, m_model, &SoundModel::setCurrentBluetoothAudioMode);

Expand All @@ -60,6 +61,7 @@ void SoundWorker::activate()
m_model->setMaxUIVolume(m_soundDBusInter->maxUIVolume());
m_model->setIncreaseVolume(m_soundDBusInter->increaseVolume());
m_model->setReduceNoise(m_soundDBusInter->reduceNoise());
m_model->setPausePlayer(m_soundDBusInter->pausePlayer());
m_model->setBluetoothAudioModeOpts(m_soundDBusInter->bluetoothAudioModeOpts());
m_model->setCurrentBluetoothAudioMode(m_soundDBusInter->bluetoothAudioMode());
m_model->setEnableSoundEffect(m_soundDBusInter->enabled());
Expand Down Expand Up @@ -151,6 +153,11 @@ void SoundWorker::setReduceNoise(bool value)
m_soundDBusInter->setReduceNoise(value);
}

void SoundWorker::setPausePlayer(bool value)
{
m_soundDBusInter->setPausePlayer(value);
}

void SoundWorker::setPort(const Port *port)
{
m_soundDBusInter->SetPort(port->cardId(), port->id(), int(port->direction()));
Expand Down
1 change: 1 addition & 0 deletions src/plugin-sound/operation/soundworker.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public Q_SLOTS:
void setSinkMute(bool flag = true);
void setIncreaseVolume(bool value);
void setReduceNoise(bool value);
void setPausePlayer(bool value);

void setPort(const Port *port);
void setEffectEnable(DDesktopServices::SystemSoundEffect effect, bool enable);
Expand Down
36 changes: 36 additions & 0 deletions src/plugin-sound/window/soundplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@
#include <QApplication>
#include <DFontSizeManager>
#include <DIconTheme>
#include <DSwitchButton>
#include <DTipLabel>

#include "widgets/titlelabel.h"
#include "widgets/itemmodule.h"
#include "widgets/widgetmodule.h"
#include "interface/pagemodule.h"

#include "soundplugin.h"
#include "soundmodel.h"
#include "soundworker.h"
Expand Down Expand Up @@ -34,6 +39,37 @@ ModuleObject *SoundPlugin::module()
ModuleObject *moduleOutput = new PageModule("output", tr("Output"));
OutputModule *outputPage = new OutputModule(soundInterface->model(), soundInterface->work(), moduleOutput);
moduleOutput->appendChild(outputPage);
ItemModule* pauseAudio = new ItemModule("PauseAudio",
tr("Auto pause"),
[soundInterface](ModuleObject *module) -> QWidget * {
Q_UNUSED(module)
DSwitchButton *pluginControl = new DSwitchButton;
auto model = soundInterface->model();
auto work = soundInterface->work();
pluginControl->setChecked(model->pausePlayer());
connect(model,
&SoundModel::pausePlayerChanged,
pluginControl,
&DSwitchButton::setChecked);
connect(pluginControl,
&DSwitchButton::checkedChanged,
work,
&SoundWorker::setPausePlayer);
return pluginControl;
});
pauseAudio->setBackground(true);
moduleOutput->appendChild(pauseAudio);
auto autoLoginTip = new WidgetModule<DTipLabel>(
"plugcontroltip",
tr(""),
[](DTipLabel *plugcontrollabel) {
plugcontrollabel->setWordWrap(true);
plugcontrollabel->setAlignment(Qt::AlignLeft);
plugcontrollabel->setContentsMargins(10, 0, 10, 0);
plugcontrollabel->setText(tr("Whether the audio will be automatically paused when the current audio device is unplugged"));
});
moduleOutput->appendChild(autoLoginTip);

soundInterface->appendChild(moduleOutput);

// 二级 -- 输入
Expand Down
8 changes: 8 additions & 0 deletions translations/dde-control-center_en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3231,6 +3231,14 @@ UnionTech Software is committed to research and improve the security, accuracy a
<source>Output</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Auto pause</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Whether the audio will be automatically paused when the current audio device is unplugged</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Input</source>
<translation type="unfinished"></translation>
Expand Down
8 changes: 8 additions & 0 deletions translations/dde-control-center_zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3243,6 +3243,14 @@ UnionTech Software is committed to research and improve the security, accuracy a
<source>Output</source>
<translation>输出</translation>
</message>
<message>
<source>Auto pause</source>
<translation>插拔管理</translation>
</message>
<message>
<source>Whether the audio will be automatically paused when the current audio device is unplugged</source>
<translation>外设插拔时音频输出是否自动暂停</translation>
</message>
<message>
<source>Input</source>
<translation>输入</translation>
Expand Down

0 comments on commit dddcd05

Please sign in to comment.