diff --git a/src/device.h b/src/device.h --- a/src/device.h +++ b/src/device.h @@ -66,9 +66,6 @@ virtual bool isDefault() const = 0; virtual void setDefault(bool enable) = 0; - template - void updateDevice(const PAInfo *info); - Q_SIGNALS: void stateChanged(); void nameChanged(); @@ -84,7 +81,8 @@ DevicePrivate *d; private: - State stateFromPaState(int value) const; + friend class SinkPrivate; + friend class SourcePrivate; }; } // PulseAudioQt diff --git a/src/device.cpp b/src/device.cpp --- a/src/device.cpp +++ b/src/device.cpp @@ -69,19 +69,19 @@ { } -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; } } diff --git a/src/device_p.h b/src/device_p.h --- a/src/device_p.h +++ b/src/device_p.h @@ -47,56 +47,58 @@ 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 diff --git a/src/port.h b/src/port.h --- a/src/port.h +++ b/src/port.h @@ -41,7 +41,7 @@ explicit Port(QObject *parent); class PortPrivate *const d; - friend class Device; + friend class DevicePrivate; }; } // PulseAudioQt diff --git a/src/sink.cpp b/src/sink.cpp --- a/src/sink.cpp +++ b/src/sink.cpp @@ -50,7 +50,7 @@ void SinkPrivate::update(const pa_sink_info *info) { - q->updateDevice(info); + q->Device::d->updateDevice(info); } void Sink::setVolume(qint64 volume) diff --git a/src/source.cpp b/src/source.cpp --- a/src/source.cpp +++ b/src/source.cpp @@ -44,7 +44,7 @@ void SourcePrivate::update(const pa_source_info *info) { - q->updateDevice(info); + q->Device::d->updateDevice(info); } void Source::setVolume(qint64 volume) diff --git a/src/volumeobject.h b/src/volumeobject.h --- a/src/volumeobject.h +++ b/src/volumeobject.h @@ -67,6 +67,7 @@ void updateVolumeObject(PAInfo *info); class VolumeObjectPrivate *const d; + friend class DevicePrivate; }; } // PulseAudioQt