diff --git a/src/device.cpp b/src/device.cpp index 9b2d15e..bc65d2b 100644 --- a/src/device.cpp +++ b/src/device.cpp @@ -1,92 +1,92 @@ /* Copyright 2014-2015 Harald Sitter This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "device.h" #include "device_p.h" namespace PulseAudioQt { Device::State Device::state() const { return d->m_state; } QString Device::name() const { return d->m_name; } QString Device::description() const { return d->m_description; } QString Device::formFactor() const { return d->m_formFactor; } quint32 Device::cardIndex() const { return d->m_cardIndex; } QVector Device::ports() const { return d->m_ports; } quint32 Device::activePortIndex() const { return d->m_activePortIndex; } Device::Device(QObject *parent) : VolumeObject(parent) , d(new DevicePrivate(this)) { } DevicePrivate::DevicePrivate(Device *q) : q(q) { } -Device::State Device::stateFromPaState(int value) const +Device::State DevicePrivate::stateFromPaState(int value) const { switch (value) { case -1: // PA_X_INVALID_STATE - return InvalidState; + return Device::InvalidState; case 0: // PA_X_RUNNING - return RunningState; + return Device::RunningState; case 1: // PA_X_IDLE - return IdleState; + return Device::IdleState; case 2: // PA_X_SUSPENDED - return SuspendedState; + return Device::SuspendedState; default: - return UnknownState; + return Device::UnknownState; } } Device::~Device(){ delete d; } } // namespace PulseAudioQt diff --git a/src/device.h b/src/device.h index a3abf73..7838ad4 100644 --- a/src/device.h +++ b/src/device.h @@ -1,92 +1,90 @@ /* Copyright 2014-2015 Harald Sitter This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef PA_DEVICE_H #define PA_DEVICE_H #include #include "volumeobject.h" namespace PulseAudioQt { class Port; class DevicePrivate; class KF5PULSEAUDIOQT_EXPORT Device : public VolumeObject { Q_OBJECT Q_PROPERTY(State state READ state NOTIFY stateChanged) Q_PROPERTY(QString name READ name NOTIFY nameChanged) Q_PROPERTY(QString description READ description NOTIFY descriptionChanged) Q_PROPERTY(QString formFactor READ formFactor NOTIFY formFactorChanged) Q_PROPERTY(quint32 cardIndex READ cardIndex NOTIFY cardIndexChanged) Q_PROPERTY(QVector ports READ ports NOTIFY portsChanged) Q_PROPERTY(quint32 activePortIndex READ activePortIndex WRITE setActivePortIndex NOTIFY activePortIndexChanged) Q_PROPERTY(bool default READ isDefault WRITE setDefault NOTIFY defaultChanged) public: enum State { InvalidState = 0, RunningState, IdleState, SuspendedState, UnknownState }; Q_ENUMS(State); ~Device(); State state() const; QString name() const; QString description() const; QString formFactor() const; quint32 cardIndex() const; QVector ports() const; quint32 activePortIndex() const; virtual void setActivePortIndex(quint32 port_index) = 0; virtual bool isDefault() const = 0; virtual void setDefault(bool enable) = 0; - template - void updateDevice(const PAInfo *info); - Q_SIGNALS: void stateChanged(); void nameChanged(); void descriptionChanged(); void formFactorChanged(); void cardIndexChanged(); void portsChanged(); void activePortIndexChanged(); void defaultChanged(); protected: explicit Device(QObject *parent); DevicePrivate *d; private: - State stateFromPaState(int value) const; + friend class SinkPrivate; + friend class SourcePrivate; }; } // PulseAudioQt #endif // DEVICE_H diff --git a/src/device_p.h b/src/device_p.h index a2da345..0b51637 100644 --- a/src/device_p.h +++ b/src/device_p.h @@ -1,103 +1,105 @@ /* Copyright 2018 Nicolas Fella This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef DEVICE_P_H #define DEVICE_P_H #include #include #include "device.h" #include "port.h" #include "port_p.h" namespace PulseAudioQt { class DevicePrivate { public: explicit DevicePrivate(Device *q); Device *q; QString m_name; QString m_description; QString m_formFactor; quint32 m_cardIndex = -1; QVector m_ports; quint32 m_activePortIndex = -1; Device::State m_state = Device::UnknownState; -}; + Device::State stateFromPaState(int value) const; -template -void Device::updateDevice(const PAInfo *info) -{ - updateVolumeObject(info); + template + void updateDevice(const PAInfo *info) + { + q->updateVolumeObject(info); - if (d->m_name != info->name) { - d->m_name = info->name; - Q_EMIT nameChanged(); - } - if (d->m_description != info->description) { - d->m_description = info->description; - Q_EMIT descriptionChanged(); - } - const char *form_factor = pa_proplist_gets(info->proplist, PA_PROP_DEVICE_FORM_FACTOR); - if (form_factor) { - QString formFactor = QString::fromUtf8(form_factor); - if (d->m_formFactor != formFactor) { - d->m_formFactor = formFactor; - Q_EMIT formFactorChanged(); + if (m_name != info->name) { + m_name = info->name; + Q_EMIT q->nameChanged(); + } + if (m_description != info->description) { + m_description = info->description; + Q_EMIT q->descriptionChanged(); + } + const char *form_factor = pa_proplist_gets(info->proplist, PA_PROP_DEVICE_FORM_FACTOR); + if (form_factor) { + QString formFactor = QString::fromUtf8(form_factor); + if (m_formFactor != formFactor) { + m_formFactor = formFactor; + Q_EMIT q->formFactorChanged(); + } } - } - d->m_cardIndex = info->card; - Q_EMIT cardIndexChanged(); - - // TODO: this rebuilds the entire port list on every update. would be - // nicer if it actually removed what needs removing updates what needs - // updating and adds what needs adding. Alas, this is a tad more - // involved. - qDeleteAll(d->m_ports); - d->m_ports.clear(); - for (auto **ports = info->ports; ports && *ports != nullptr; ++ports) { - Port *port = new Port(this); - port->setInfo(*ports); - d->m_ports.append(port); - if (info->active_port == *ports) { - d->m_activePortIndex = d->m_ports.length() - 1; + m_cardIndex = info->card; + Q_EMIT q->cardIndexChanged(); + + // TODO: this rebuilds the entire port list on every update. would be + // nicer if it actually removed what needs removing updates what needs + // updating and adds what needs adding. Alas, this is a tad more + // involved. + qDeleteAll(m_ports); + m_ports.clear(); + for (auto **ports = info->ports; ports && *ports != nullptr; ++ports) { + Port *port = new Port(q); + port->setInfo(*ports); + m_ports.append(port); + if (info->active_port == *ports) { + m_activePortIndex = m_ports.length() - 1; + } } - } - Q_EMIT portsChanged(); - Q_EMIT activePortIndexChanged(); + Q_EMIT q->portsChanged(); + Q_EMIT q->activePortIndexChanged(); - State infoState = stateFromPaState(info->state); - if (infoState != d->m_state) { - d->m_state = infoState; - Q_EMIT stateChanged(); + Device::State infoState = stateFromPaState(info->state); + if (infoState != m_state) { + m_state = infoState; + Q_EMIT q->stateChanged(); + } } -} + + }; } // namespace PulseAudioQt #endif diff --git a/src/port.h b/src/port.h index df08a00..0d8ab6e 100644 --- a/src/port.h +++ b/src/port.h @@ -1,49 +1,49 @@ /* Copyright 2014-2015 Harald Sitter This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef PORT_H #define PORT_H #include "profile.h" #include "kf5pulseaudioqt_export.h" namespace PulseAudioQt { class KF5PULSEAUDIOQT_EXPORT Port : public Profile { Q_OBJECT public: ~Port(); template void setInfo(const PAInfo *info); protected: explicit Port(QObject *parent); class PortPrivate *const d; - friend class Device; + friend class DevicePrivate; }; } // PulseAudioQt #endif // PORT_H diff --git a/src/sink.cpp b/src/sink.cpp index 565a99d..86b277f 100644 --- a/src/sink.cpp +++ b/src/sink.cpp @@ -1,93 +1,93 @@ /* Copyright 2014-2015 Harald Sitter This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "sink.h" #include "sink_p.h" #include "context.h" #include "context_p.h" #include "server.h" #include "device_p.h" #include "volumeobject_p.h" namespace PulseAudioQt { Sink::Sink(QObject *parent) : Device(parent) , d(new SinkPrivate(this)) { connect(context()->server(), &Server::defaultSinkChanged, this, &Sink::defaultChanged); } SinkPrivate::SinkPrivate(Sink *q) : q(q) { } Sink::~Sink() { delete d; } void SinkPrivate::update(const pa_sink_info *info) { - q->updateDevice(info); + q->Device::d->updateDevice(info); } void Sink::setVolume(qint64 volume) { context()->d->setGenericVolume(index(), -1, volume, VolumeObject::d->cvolume(), &pa_context_set_sink_volume_by_index); } void Sink::setMuted(bool muted) { context()->d->setGenericMute(index(), muted, &pa_context_set_sink_mute_by_index); } void Sink::setActivePortIndex(quint32 port_index) { Port *port = qobject_cast(ports().at(port_index)); if (!port) { qCWarning(PULSEAUDIOQT) << "invalid port set request" << port_index; return; } context()->d->setGenericPort(index(), port->name(), &pa_context_set_sink_port_by_index); } void Sink::setChannelVolume(int channel, qint64 volume) { context()->d->setGenericVolume(index(), channel, volume, VolumeObject::d->cvolume(), &pa_context_set_sink_volume_by_index); } bool Sink::isDefault() const { return context()->server()->defaultSink() == this; } void Sink::setDefault(bool enable) { if (!isDefault() && enable) { context()->server()->setDefaultSink(this); } } } // PulseAudioQt diff --git a/src/source.cpp b/src/source.cpp index 332f443..e6dbe91 100644 --- a/src/source.cpp +++ b/src/source.cpp @@ -1,91 +1,91 @@ /* Copyright 2014-2015 Harald Sitter This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "source.h" #include "source_p.h" #include "context.h" #include "context_p.h" #include "server.h" #include "device_p.h" #include "volumeobject_p.h" namespace PulseAudioQt { Source::Source(QObject *parent) : Device(parent) , d(new SourcePrivate(this)) { connect(context()->server(), &Server::defaultSourceChanged, this, &Source::defaultChanged); } SourcePrivate::SourcePrivate(Source *q) :q(q) { } void SourcePrivate::update(const pa_source_info *info) { - q->updateDevice(info); + q->Device::d->updateDevice(info); } void Source::setVolume(qint64 volume) { context()->d->setGenericVolume(index(), -1, volume, VolumeObject::d->cvolume(), &pa_context_set_source_volume_by_index); } void Source::setMuted(bool muted) { context()->d->setGenericMute(index(), muted, &pa_context_set_source_mute_by_index); } void Source::setActivePortIndex(quint32 port_index) { Port *port = qobject_cast(ports().at(port_index)); if (!port) { qCWarning(PULSEAUDIOQT) << "invalid port set request" << port_index; return; } context()->d->setGenericPort(index(), port->name(), &pa_context_set_source_port_by_index); } void Source::setChannelVolume(int channel, qint64 volume) { context()->d->setGenericVolume(index(), channel, volume, VolumeObject::d->cvolume(), &pa_context_set_source_volume_by_index); } bool Source::isDefault() const { return context()->server()->defaultSource() == this; } void Source::setDefault(bool enable) { if (!isDefault() && enable) { context()->server()->setDefaultSource(this); } } Source::~Source() { delete d; } } // PulseAudioQt diff --git a/src/volumeobject.h b/src/volumeobject.h index 997bd5e..a89cbef 100644 --- a/src/volumeobject.h +++ b/src/volumeobject.h @@ -1,74 +1,75 @@ /* Copyright 2014-2015 Harald Sitter This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef VOLUMEOBJECT_H #define VOLUMEOBJECT_H #include "pulseobject.h" namespace PulseAudioQt { class KF5PULSEAUDIOQT_EXPORT VolumeObject : public PulseObject { Q_OBJECT Q_PROPERTY(qint64 volume READ volume WRITE setVolume NOTIFY volumeChanged) Q_PROPERTY(bool muted READ isMuted WRITE setMuted NOTIFY mutedChanged) Q_PROPERTY(bool hasVolume READ hasVolume NOTIFY hasVolumeChanged) Q_PROPERTY(bool volumeWritable READ isVolumeWritable NOTIFY isVolumeWritableChanged) Q_PROPERTY(QVector channels READ channels NOTIFY channelsChanged) Q_PROPERTY(QVector channelVolumes READ channelVolumes NOTIFY channelVolumesChanged) public: ~VolumeObject(); qint64 volume() const; virtual void setVolume(qint64 volume) = 0; bool isMuted() const; virtual void setMuted(bool muted) = 0; bool hasVolume() const; bool isVolumeWritable() const; QVector channels() const; QVector channelVolumes() const; virtual void setChannelVolume(int channel, qint64 volume) = 0; Q_SIGNALS: void volumeChanged(); void mutedChanged(); void hasVolumeChanged(); void isVolumeWritableChanged(); void channelsChanged(); void channelVolumesChanged(); protected: explicit VolumeObject(QObject *parent); template void updateVolumeObject(PAInfo *info); class VolumeObjectPrivate *const d; + friend class DevicePrivate; }; } // PulseAudioQt #endif // VOLUMEOBJECT_H