Commit 61259acd authored by Valerio Pilo's avatar Valerio Pilo

[plasma-pa] Add command to switch all applications to the selected device

Summary:
If you have many applications running (e.g. browser tabs) it's very annoying to manually switch them all to another device. With this context menu option, it's now very easy.

Screenshot: {F6615058}

Reviewers: #plasma, broulik, drosca, #vdg, ngraham

Reviewed By: #vdg, ngraham

Subscribers: filipf, ngraham, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D19014
parent 25de7eb8
......@@ -300,6 +300,25 @@ PlasmaComponents.ListItem {
});
contextMenu.addMenuItem(menuItem);
// Switch all streams of the relevant kind to this device
if (type == "source") {
menuItem = newMenuItem();
menuItem.text = i18n("Record all audio via this device");
menuItem.icon = "mic-on" // or "mic-ready" // or "audio-input-microphone-symbolic"
menuItem.clicked.connect(function() {
PulseObject.switchStreams();
});
contextMenu.addMenuItem(menuItem);
} else if (type == "sink") {
menuItem = newMenuItem();
menuItem.text = i18n("Play all audio via this device");
menuItem.icon = "audio-on" // or "audio-ready" // or "audio-speakers-symbolic"
menuItem.clicked.connect(function() {
PulseObject.switchStreams();
});
contextMenu.addMenuItem(menuItem);
}
// Ports
if (PulseObject.ports && PulseObject.ports.length > 0) {
contextMenu.addMenuItem(newSeperator());
......
......@@ -123,6 +123,8 @@ public:
virtual void setDefault(bool enable) = 0;
bool isVirtualDevice() const;
virtual Q_INVOKABLE void switchStreams() = 0;
Q_SIGNALS:
void stateChanged();
void nameChanged();
......
......@@ -22,6 +22,7 @@
#include "context.h"
#include "server.h"
#include "sinkinput.h"
#include "canberracontext.h"
#include <pulse/channelmap.h>
......@@ -116,4 +117,12 @@ void Sink::testChannel(const QString &name)
ca_proplist_destroy(proplist);
}
void Sink::switchStreams()
{
auto data = context()->sinkInputs().data();
std::for_each(data.begin(), data.end(), [this](SinkInput* paObj) {
paObj->setDeviceIndex(m_index);
});
}
} // QPulseAudio
......@@ -44,6 +44,8 @@ public:
bool isDefault() const override;
void setDefault(bool enable) override;
void switchStreams() override;
public Q_SLOTS:
void testChannel(const QString &name);
};
......
......@@ -22,6 +22,7 @@
#include "context.h"
#include "server.h"
#include "sourceoutput.h"
namespace QPulseAudio
{
......@@ -74,4 +75,12 @@ void Source::setDefault(bool enable)
}
}
void Source::switchStreams()
{
auto data = context()->sourceOutputs().data();
std::for_each(data.begin(), data.end(), [this](SourceOutput* paObj) {
paObj->setDeviceIndex(m_index);
});
}
} // QPulseAudio
......@@ -40,6 +40,8 @@ public:
bool isDefault() const override;
void setDefault(bool enable) override;
void switchStreams() override;
};
} // QPulseAudio
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment