diff --git a/applet/contents/ui/ListItemBase.qml b/applet/contents/ui/ListItemBase.qml --- a/applet/contents/ui/ListItemBase.qml +++ b/applet/contents/ui/ListItemBase.qml @@ -300,6 +300,16 @@ }); contextMenu.addMenuItem(menuItem); + // Switch all streams of the relevant kind to this device + if (type == "sink" || type == "source") { + menuItem = newMenuItem(); + menuItem.text = i18n("Play all audio using this device"); + menuItem.clicked.connect(function() { + PulseObject.switchStreams(); + }); + contextMenu.addMenuItem(menuItem); + } + // Ports if (PulseObject.ports && PulseObject.ports.length > 0) { contextMenu.addMenuItem(newSeperator()); diff --git a/src/device.h b/src/device.h --- a/src/device.h +++ b/src/device.h @@ -123,6 +123,8 @@ virtual void setDefault(bool enable) = 0; bool isVirtualDevice() const; + virtual Q_INVOKABLE void switchStreams() = 0; + Q_SIGNALS: void stateChanged(); void nameChanged(); diff --git a/src/sink.h b/src/sink.h --- a/src/sink.h +++ b/src/sink.h @@ -44,6 +44,8 @@ bool isDefault() const override; void setDefault(bool enable) override; + void switchStreams() override; + public Q_SLOTS: void testChannel(const QString &name); }; diff --git a/src/sink.cpp b/src/sink.cpp --- a/src/sink.cpp +++ b/src/sink.cpp @@ -22,6 +22,7 @@ #include "context.h" #include "server.h" +#include "sinkinput.h" #include "canberracontext.h" #include @@ -116,4 +117,12 @@ 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 diff --git a/src/source.h b/src/source.h --- a/src/source.h +++ b/src/source.h @@ -40,6 +40,8 @@ bool isDefault() const override; void setDefault(bool enable) override; + + void switchStreams() override; }; } // QPulseAudio diff --git a/src/source.cpp b/src/source.cpp --- a/src/source.cpp +++ b/src/source.cpp @@ -22,6 +22,7 @@ #include "context.h" #include "server.h" +#include "sourceoutput.h" namespace QPulseAudio { @@ -74,4 +75,12 @@ } } +void Source::switchStreams() +{ + auto data = context()->sourceOutputs().data(); + std::for_each(data.begin(), data.end(), [this](SourceOutput* paObj) { + paObj->setDeviceIndex(m_index); + }); +} + } // QPulseAudio