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);
|
||||
}
|
||||
|
||||
void RemoteSystemVolumePlugin::connected()
|
||||
{
|
||||
NetworkPacket np(PACKET_TYPE_SYSTEMVOLUME_REQUEST);
|
||||
np.set<bool>(QStringLiteral("requestSinks"), true);
|
||||
sendPacket(np);
|
||||
}
|
||||
|
||||
QByteArray RemoteSystemVolumePlugin::sinks()
|
||||
{
|
||||
return m_sinks;
|
||||
|
|
|
@ -24,7 +24,6 @@ public:
|
|||
using KdeConnectPlugin::KdeConnectPlugin;
|
||||
|
||||
void receivePacket(const NetworkPacket &np) override;
|
||||
void connected() override;
|
||||
QString dbusPath() const override;
|
||||
|
||||
QString deviceId() const
|
||||
|
|
|
@ -221,21 +221,17 @@ SystemvolumePlugin::~SystemvolumePlugin()
|
|||
|
||||
void SystemvolumePlugin::receivePacket(const NetworkPacket &np)
|
||||
{
|
||||
if (np.has(QStringLiteral("requestSinks"))) {
|
||||
sendSinkList();
|
||||
} else {
|
||||
QString name = np.get<QString>(QStringLiteral("name"));
|
||||
QString name = np.get<QString>(QStringLiteral("name"));
|
||||
|
||||
if (m_sinksMap.contains(name)) {
|
||||
if (np.has(QStringLiteral("volume"))) {
|
||||
m_sinksMap[name]->setVolume(np.get<int>(QStringLiteral("volume")) / 100.0);
|
||||
}
|
||||
if (np.has(QStringLiteral("muted"))) {
|
||||
m_sinksMap[name]->setMuted(np.get<bool>(QStringLiteral("muted")));
|
||||
}
|
||||
if (np.has(QStringLiteral("enabled"))) {
|
||||
m_sinksMap[name]->setDefault(np.get<bool>(QStringLiteral("enabled")));
|
||||
}
|
||||
if (m_sinksMap.contains(name)) {
|
||||
if (np.has(QStringLiteral("volume"))) {
|
||||
m_sinksMap[name]->setVolume(np.get<int>(QStringLiteral("volume")) / 100.0);
|
||||
}
|
||||
if (np.has(QStringLiteral("muted"))) {
|
||||
m_sinksMap[name]->setMuted(np.get<bool>(QStringLiteral("muted")));
|
||||
}
|
||||
if (np.has(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())
|
||||
return;
|
||||
|
||||
if (np.has(QStringLiteral("requestSinks"))) {
|
||||
sendSinkList();
|
||||
} else {
|
||||
QString name = np.get<QString>(QStringLiteral("name"));
|
||||
QString name = np.get<QString>(QStringLiteral("name"));
|
||||
|
||||
PulseAudioQt::Sink *sink = sinksMap.value(name);
|
||||
if (sink) {
|
||||
if (np.has(QStringLiteral("volume"))) {
|
||||
int volume = np.get<int>(QStringLiteral("volume"));
|
||||
sink->setVolume(volume);
|
||||
sink->setMuted(false);
|
||||
}
|
||||
if (np.has(QStringLiteral("muted"))) {
|
||||
sink->setMuted(np.get<bool>(QStringLiteral("muted")));
|
||||
}
|
||||
if (np.has(QStringLiteral("enabled"))) {
|
||||
sink->setDefault(np.get<bool>(QStringLiteral("enabled")));
|
||||
}
|
||||
PulseAudioQt::Sink *sink = sinksMap.value(name);
|
||||
if (sink) {
|
||||
if (np.has(QStringLiteral("volume"))) {
|
||||
int volume = np.get<int>(QStringLiteral("volume"));
|
||||
sink->setVolume(volume);
|
||||
sink->setMuted(false);
|
||||
}
|
||||
if (np.has(QStringLiteral("muted"))) {
|
||||
sink->setMuted(np.get<bool>(QStringLiteral("muted")));
|
||||
}
|
||||
if (np.has(QStringLiteral("enabled"))) {
|
||||
sink->setDefault(np.get<bool>(QStringLiteral("enabled")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -404,38 +404,34 @@ void SystemvolumePlugin::receivePacket(const NetworkPacket &np)
|
|||
if (!valid)
|
||||
return;
|
||||
|
||||
if (np.has(QStringLiteral("requestSinks"))) {
|
||||
sendSinkList();
|
||||
} else {
|
||||
QString name = np.get<QString>(QStringLiteral("name"));
|
||||
QString name = np.get<QString>(QStringLiteral("name"));
|
||||
|
||||
auto sinkListIterator = this->sinkList.find(name);
|
||||
if (sinkListIterator != this->sinkList.end()) {
|
||||
auto &sink = sinkListIterator.value();
|
||||
auto sinkListIterator = this->sinkList.find(name);
|
||||
if (sinkListIterator != this->sinkList.end()) {
|
||||
auto &sink = sinkListIterator.value();
|
||||
|
||||
if (np.has(QStringLiteral("volume"))) {
|
||||
float requestedVolume = (float)np.get<int>(QStringLiteral("volume"), 100) / 100;
|
||||
sinkList[name].first->SetMasterVolumeLevelScalar(requestedVolume, NULL);
|
||||
}
|
||||
if (np.has(QStringLiteral("volume"))) {
|
||||
float requestedVolume = (float)np.get<int>(QStringLiteral("volume"), 100) / 100;
|
||||
sinkList[name].first->SetMasterVolumeLevelScalar(requestedVolume, NULL);
|
||||
}
|
||||
|
||||
if (np.has(QStringLiteral("muted"))) {
|
||||
BOOL requestedMuteStatus = np.get<bool>(QStringLiteral("muted"), false);
|
||||
sinkList[name].first->SetMute(requestedMuteStatus, NULL);
|
||||
}
|
||||
if (np.has(QStringLiteral("muted"))) {
|
||||
BOOL requestedMuteStatus = np.get<bool>(QStringLiteral("muted"), false);
|
||||
sinkList[name].first->SetMute(requestedMuteStatus, NULL);
|
||||
}
|
||||
|
||||
if (np.has(QStringLiteral("enabled"))) {
|
||||
// get the current default device ID
|
||||
IMMDevice *defaultDevice = nullptr;
|
||||
deviceEnumerator->GetDefaultAudioEndpoint(eRender, eMultimedia, &defaultDevice);
|
||||
LPWSTR defaultId = NULL;
|
||||
defaultDevice->GetId(&defaultId);
|
||||
defaultDevice->Release();
|
||||
// get current sink's device ID
|
||||
QString qDefaultId = QString::fromWCharArray(defaultId);
|
||||
QString currentDeviceId = idToNameMap.key(name);
|
||||
if (qDefaultId != currentDeviceId) {
|
||||
setDefaultAudioPlaybackDevice(name, np.get<bool>(QStringLiteral("enabled")));
|
||||
}
|
||||
if (np.has(QStringLiteral("enabled"))) {
|
||||
// get the current default device ID
|
||||
IMMDevice *defaultDevice = nullptr;
|
||||
deviceEnumerator->GetDefaultAudioEndpoint(eRender, eMultimedia, &defaultDevice);
|
||||
LPWSTR defaultId = NULL;
|
||||
defaultDevice->GetId(&defaultId);
|
||||
defaultDevice->Release();
|
||||
// get current sink's device ID
|
||||
QString qDefaultId = QString::fromWCharArray(defaultId);
|
||||
QString currentDeviceId = idToNameMap.key(name);
|
||||
if (qDefaultId != currentDeviceId) {
|
||||
setDefaultAudioPlaybackDevice(name, np.get<bool>(QStringLiteral("enabled")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue