Remove requestSinks
from SystemVolume plugin
Sinks are sent at connect time and updated as necessary, so drop the request command. See: https://invent.kde.org/network/kdeconnect-meta/-/merge_requests/8
This commit is contained in:
parent
daf09c61d8
commit
ad7d3dd964
5 changed files with 47 additions and 67 deletions
|
@ -56,13 +56,6 @@ void RemoteSystemVolumePlugin::sendMuted(const QString &name, bool muted)
|
||||||
sendPacket(np);
|
sendPacket(np);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteSystemVolumePlugin::connected()
|
|
||||||
{
|
|
||||||
NetworkPacket np(PACKET_TYPE_SYSTEMVOLUME_REQUEST);
|
|
||||||
np.set<bool>(QStringLiteral("requestSinks"), true);
|
|
||||||
sendPacket(np);
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray RemoteSystemVolumePlugin::sinks()
|
QByteArray RemoteSystemVolumePlugin::sinks()
|
||||||
{
|
{
|
||||||
return m_sinks;
|
return m_sinks;
|
||||||
|
|
|
@ -24,7 +24,6 @@ public:
|
||||||
using KdeConnectPlugin::KdeConnectPlugin;
|
using KdeConnectPlugin::KdeConnectPlugin;
|
||||||
|
|
||||||
void receivePacket(const NetworkPacket &np) override;
|
void receivePacket(const NetworkPacket &np) override;
|
||||||
void connected() override;
|
|
||||||
QString dbusPath() const override;
|
QString dbusPath() const override;
|
||||||
|
|
||||||
QString deviceId() const
|
QString deviceId() const
|
||||||
|
|
|
@ -221,21 +221,17 @@ SystemvolumePlugin::~SystemvolumePlugin()
|
||||||
|
|
||||||
void SystemvolumePlugin::receivePacket(const NetworkPacket &np)
|
void SystemvolumePlugin::receivePacket(const NetworkPacket &np)
|
||||||
{
|
{
|
||||||
if (np.has(QStringLiteral("requestSinks"))) {
|
QString name = np.get<QString>(QStringLiteral("name"));
|
||||||
sendSinkList();
|
|
||||||
} else {
|
|
||||||
QString name = np.get<QString>(QStringLiteral("name"));
|
|
||||||
|
|
||||||
if (m_sinksMap.contains(name)) {
|
if (m_sinksMap.contains(name)) {
|
||||||
if (np.has(QStringLiteral("volume"))) {
|
if (np.has(QStringLiteral("volume"))) {
|
||||||
m_sinksMap[name]->setVolume(np.get<int>(QStringLiteral("volume")) / 100.0);
|
m_sinksMap[name]->setVolume(np.get<int>(QStringLiteral("volume")) / 100.0);
|
||||||
}
|
}
|
||||||
if (np.has(QStringLiteral("muted"))) {
|
if (np.has(QStringLiteral("muted"))) {
|
||||||
m_sinksMap[name]->setMuted(np.get<bool>(QStringLiteral("muted")));
|
m_sinksMap[name]->setMuted(np.get<bool>(QStringLiteral("muted")));
|
||||||
}
|
}
|
||||||
if (np.has(QStringLiteral("enabled"))) {
|
if (np.has(QStringLiteral("enabled"))) {
|
||||||
m_sinksMap[name]->setDefault(np.get<bool>(QStringLiteral("enabled")));
|
m_sinksMap[name]->setDefault(np.get<bool>(QStringLiteral("enabled")));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,24 +33,20 @@ void SystemvolumePlugin::receivePacket(const NetworkPacket &np)
|
||||||
if (!PulseAudioQt::Context::instance()->isValid())
|
if (!PulseAudioQt::Context::instance()->isValid())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (np.has(QStringLiteral("requestSinks"))) {
|
QString name = np.get<QString>(QStringLiteral("name"));
|
||||||
sendSinkList();
|
|
||||||
} else {
|
|
||||||
QString name = np.get<QString>(QStringLiteral("name"));
|
|
||||||
|
|
||||||
PulseAudioQt::Sink *sink = sinksMap.value(name);
|
PulseAudioQt::Sink *sink = sinksMap.value(name);
|
||||||
if (sink) {
|
if (sink) {
|
||||||
if (np.has(QStringLiteral("volume"))) {
|
if (np.has(QStringLiteral("volume"))) {
|
||||||
int volume = np.get<int>(QStringLiteral("volume"));
|
int volume = np.get<int>(QStringLiteral("volume"));
|
||||||
sink->setVolume(volume);
|
sink->setVolume(volume);
|
||||||
sink->setMuted(false);
|
sink->setMuted(false);
|
||||||
}
|
}
|
||||||
if (np.has(QStringLiteral("muted"))) {
|
if (np.has(QStringLiteral("muted"))) {
|
||||||
sink->setMuted(np.get<bool>(QStringLiteral("muted")));
|
sink->setMuted(np.get<bool>(QStringLiteral("muted")));
|
||||||
}
|
}
|
||||||
if (np.has(QStringLiteral("enabled"))) {
|
if (np.has(QStringLiteral("enabled"))) {
|
||||||
sink->setDefault(np.get<bool>(QStringLiteral("enabled")));
|
sink->setDefault(np.get<bool>(QStringLiteral("enabled")));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -404,38 +404,34 @@ void SystemvolumePlugin::receivePacket(const NetworkPacket &np)
|
||||||
if (!valid)
|
if (!valid)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (np.has(QStringLiteral("requestSinks"))) {
|
QString name = np.get<QString>(QStringLiteral("name"));
|
||||||
sendSinkList();
|
|
||||||
} else {
|
|
||||||
QString name = np.get<QString>(QStringLiteral("name"));
|
|
||||||
|
|
||||||
auto sinkListIterator = this->sinkList.find(name);
|
auto sinkListIterator = this->sinkList.find(name);
|
||||||
if (sinkListIterator != this->sinkList.end()) {
|
if (sinkListIterator != this->sinkList.end()) {
|
||||||
auto &sink = sinkListIterator.value();
|
auto &sink = sinkListIterator.value();
|
||||||
|
|
||||||
if (np.has(QStringLiteral("volume"))) {
|
if (np.has(QStringLiteral("volume"))) {
|
||||||
float requestedVolume = (float)np.get<int>(QStringLiteral("volume"), 100) / 100;
|
float requestedVolume = (float)np.get<int>(QStringLiteral("volume"), 100) / 100;
|
||||||
sinkList[name].first->SetMasterVolumeLevelScalar(requestedVolume, NULL);
|
sinkList[name].first->SetMasterVolumeLevelScalar(requestedVolume, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (np.has(QStringLiteral("muted"))) {
|
if (np.has(QStringLiteral("muted"))) {
|
||||||
BOOL requestedMuteStatus = np.get<bool>(QStringLiteral("muted"), false);
|
BOOL requestedMuteStatus = np.get<bool>(QStringLiteral("muted"), false);
|
||||||
sinkList[name].first->SetMute(requestedMuteStatus, NULL);
|
sinkList[name].first->SetMute(requestedMuteStatus, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (np.has(QStringLiteral("enabled"))) {
|
if (np.has(QStringLiteral("enabled"))) {
|
||||||
// get the current default device ID
|
// get the current default device ID
|
||||||
IMMDevice *defaultDevice = nullptr;
|
IMMDevice *defaultDevice = nullptr;
|
||||||
deviceEnumerator->GetDefaultAudioEndpoint(eRender, eMultimedia, &defaultDevice);
|
deviceEnumerator->GetDefaultAudioEndpoint(eRender, eMultimedia, &defaultDevice);
|
||||||
LPWSTR defaultId = NULL;
|
LPWSTR defaultId = NULL;
|
||||||
defaultDevice->GetId(&defaultId);
|
defaultDevice->GetId(&defaultId);
|
||||||
defaultDevice->Release();
|
defaultDevice->Release();
|
||||||
// get current sink's device ID
|
// get current sink's device ID
|
||||||
QString qDefaultId = QString::fromWCharArray(defaultId);
|
QString qDefaultId = QString::fromWCharArray(defaultId);
|
||||||
QString currentDeviceId = idToNameMap.key(name);
|
QString currentDeviceId = idToNameMap.key(name);
|
||||||
if (qDefaultId != currentDeviceId) {
|
if (qDefaultId != currentDeviceId) {
|
||||||
setDefaultAudioPlaybackDevice(name, np.get<bool>(QStringLiteral("enabled")));
|
setDefaultAudioPlaybackDevice(name, np.get<bool>(QStringLiteral("enabled")));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue