diff --git a/src/card.cpp b/src/card.cpp --- a/src/card.cpp +++ b/src/card.cpp @@ -52,7 +52,7 @@ void CardPrivate::update(const pa_card_info *info) { - q->updatePulseObject(info); + q->PulseObject::d->updatePulseObject(info); QString infoName = QString::fromUtf8(info->name); if (m_name != infoName) { @@ -64,7 +64,7 @@ m_profiles.clear(); for (auto **it = info->profiles2; it && *it != nullptr; ++it) { Profile *profile = new Profile(q); - profile->setInfo(*it); + profile->d->setInfo(*it); m_profiles.append(profile); if (info->active_profile2 == *it) { m_activeProfileIndex = m_profiles.length() - 1; diff --git a/src/cardport.cpp b/src/cardport.cpp --- a/src/cardport.cpp +++ b/src/cardport.cpp @@ -34,7 +34,7 @@ void CardPort::update(const pa_card_port_info *info) { - setInfo(info); + Port::d->setInfo(info); m_properties.clear(); void *it = nullptr; diff --git a/src/client.cpp b/src/client.cpp --- a/src/client.cpp +++ b/src/client.cpp @@ -45,7 +45,7 @@ void ClientPrivate::update(const pa_client_info *info) { - q->updatePulseObject(info); + q->PulseObject::d->updatePulseObject(info); QString infoName = QString::fromUtf8(info->name); if (m_name != infoName) { diff --git a/src/device_p.h b/src/device_p.h --- a/src/device_p.h +++ b/src/device_p.h @@ -27,6 +27,7 @@ #include "device.h" #include "port.h" #include "port_p.h" +#include "volumeobject_p.h" namespace PulseAudioQt { @@ -52,7 +53,7 @@ template void updateDevice(const PAInfo *info) { - q->updateVolumeObject(info); + q->VolumeObject::d->updateVolumeObject(info); if (m_name != info->name) { m_name = info->name; @@ -82,7 +83,7 @@ m_ports.clear(); for (auto **ports = info->ports; ports && *ports != nullptr; ++ports) { Port *port = new Port(q); - port->setInfo(*ports); + port->d->setInfo(*ports); m_ports.append(port); if (info->active_port == *ports) { m_activePortIndex = m_ports.length() - 1; diff --git a/src/module.cpp b/src/module.cpp --- a/src/module.cpp +++ b/src/module.cpp @@ -45,7 +45,7 @@ void ModulePrivate::update(const pa_module_info *info) { - q->updatePulseObject(info); + q->PulseObject::d->updatePulseObject(info); const QString infoName = QString::fromUtf8(info->name); if (m_name != infoName) { diff --git a/src/port.h b/src/port.h --- a/src/port.h +++ b/src/port.h @@ -34,9 +34,6 @@ public: ~Port(); - template - void setInfo(const PAInfo *info); - protected: explicit Port(QObject *parent); class PortPrivate *const d; diff --git a/src/port_p.h b/src/port_p.h --- a/src/port_p.h +++ b/src/port_p.h @@ -32,14 +32,15 @@ explicit PortPrivate(Port *q); virtual ~PortPrivate(); + template + void setInfo(const PAInfo *info) + { + q->Profile::d->setInfo(info); + } + Port *q; }; -template -void Port::setInfo(const PAInfo *info) -{ - Profile::setInfo(info); -} } diff --git a/src/profile.h b/src/profile.h --- a/src/profile.h +++ b/src/profile.h @@ -47,9 +47,6 @@ ~Profile(); - template - void setInfo(const PAInfo *info); - QString name() const; QString description() const; quint32 priority() const; @@ -67,6 +64,7 @@ friend class Device; friend class CardPrivate; + friend class PortPrivate; }; } // PulseAudioQt diff --git a/src/profile_p.h b/src/profile_p.h --- a/src/profile_p.h +++ b/src/profile_p.h @@ -38,34 +38,35 @@ QString m_description; quint32 m_priority; Profile::Availability m_availability; -}; -template -void Profile::setInfo(const PAInfo *info) -{ - // Description is optional. Name not so much as we need some ID. - Q_ASSERT(info->name); - QString infoName = QString::fromUtf8(info->name); - if (d->m_name != infoName) { - d->m_name = infoName; - Q_EMIT nameChanged(); - } - if (info->description) { - QString infoDescription = QString::fromUtf8(info->description); - if (d->m_description != infoDescription) { - d->m_description = infoDescription; - Q_EMIT descriptionChanged(); + template + void setInfo(const PAInfo *info) + { + // Description is optional. Name not so much as we need some ID. + Q_ASSERT(info->name); + QString infoName = QString::fromUtf8(info->name); + if (m_name != infoName) { + m_name = infoName; + Q_EMIT q->nameChanged(); + } + if (info->description) { + QString infoDescription = QString::fromUtf8(info->description); + if (m_description != infoDescription) { + m_description = infoDescription; + Q_EMIT q->descriptionChanged(); + } + } + if (m_priority != info->priority) { + m_priority = info->priority; + Q_EMIT q->priorityChanged(); } - } - if (d->m_priority != info->priority) { - d->m_priority = info->priority; - Q_EMIT priorityChanged(); - } - Availability newAvailability = info->available ? Available : Unavailable; - if (d->m_availability != newAvailability) { - d->m_availability = newAvailability; - Q_EMIT availabilityChanged(); + Profile::Availability newAvailability = info->available ? Profile::Available : Profile::Unavailable; + if (m_availability != newAvailability) { + m_availability = newAvailability; + Q_EMIT q->availabilityChanged(); + } } -} +}; + } diff --git a/src/pulseobject.h b/src/pulseobject.h --- a/src/pulseobject.h +++ b/src/pulseobject.h @@ -46,9 +46,6 @@ QString iconName() const; QVariantMap properties() const; - template - void updatePulseObject(PAInfo *info); - Context *context() const; Q_SIGNALS: @@ -62,6 +59,10 @@ private: // Ensure that we get properly parented. PulseObject(); + friend class ClientPrivate; + friend class CardPrivate; + friend class ModulePrivate; + friend class VolumeObjectPrivate; }; } // PulseAudioQt diff --git a/src/pulseobject_p.h b/src/pulseobject_p.h --- a/src/pulseobject_p.h +++ b/src/pulseobject_p.h @@ -41,26 +41,25 @@ quint32 m_index; QVariantMap m_properties; -}; - -template -void PulseObject::updatePulseObject(PAInfo *info) -{ - d->m_index = info->index; + template + void updatePulseObject(PAInfo *info) + { + m_index = info->index; - d->m_properties.clear(); - void *it = nullptr; - while (const char *key = pa_proplist_iterate(info->proplist, &it)) { - Q_ASSERT(key); - const char *value = pa_proplist_gets(info->proplist, key); - if (!value) { - qCDebug(PULSEAUDIOQT) << "property" << key << "not a string"; - continue; + m_properties.clear(); + void *it = nullptr; + while (const char *key = pa_proplist_iterate(info->proplist, &it)) { + Q_ASSERT(key); + const char *value = pa_proplist_gets(info->proplist, key); + if (!value) { + qCDebug(PULSEAUDIOQT) << "property" << key << "not a string"; + continue; + } + Q_ASSERT(value); + m_properties.insert(QString::fromUtf8(key), QString::fromUtf8(value)); } - Q_ASSERT(value); - d->m_properties.insert(QString::fromUtf8(key), QString::fromUtf8(value)); + Q_EMIT q->propertiesChanged(); } - Q_EMIT propertiesChanged(); -} +}; } #endif diff --git a/src/server.h b/src/server.h --- a/src/server.h +++ b/src/server.h @@ -44,15 +44,15 @@ Source *defaultSource() const; void setDefaultSource(Source *source); - void reset(); Q_SIGNALS: void defaultSinkChanged(Sink *sink); void defaultSourceChanged(Source *source); private: explicit Server(Context *context); + void reset(); void updateDefaultDevices(); class ServerPrivate *const d; diff --git a/src/sinkinput.cpp b/src/sinkinput.cpp --- a/src/sinkinput.cpp +++ b/src/sinkinput.cpp @@ -46,7 +46,7 @@ void SinkInputPrivate::update(const pa_sink_input_info *info) { - q->updateStream(info); + q->Stream::d->updateStream(info); if (q->Stream::d->m_deviceIndex != info->sink) { q->Stream::d->m_deviceIndex = info->sink; Q_EMIT q->deviceIndexChanged(); diff --git a/src/sourceoutput.cpp b/src/sourceoutput.cpp --- a/src/sourceoutput.cpp +++ b/src/sourceoutput.cpp @@ -45,7 +45,7 @@ void SourceOutputPrivate::update(const pa_source_output_info *info) { - q->updateStream(info); + q->Stream::d->updateStream(info); if (q->Stream::d->m_deviceIndex != info->source) { q->Stream::d->m_deviceIndex = info->source; Q_EMIT q->deviceIndexChanged(); diff --git a/src/stream.h b/src/stream.h --- a/src/stream.h +++ b/src/stream.h @@ -53,9 +53,6 @@ virtual void setDeviceIndex(quint32 deviceIndex) = 0; - template - void updateStream(const PAInfo *info); - Q_SIGNALS: void nameChanged(); void clientChanged(); diff --git a/src/stream_p.h b/src/stream_p.h --- a/src/stream_p.h +++ b/src/stream_p.h @@ -40,38 +40,38 @@ bool m_virtualStream; bool m_corked; -}; -template -void Stream::updateStream(const PAInfo *info) -{ - updateVolumeObject(info); + template + void updateStream(const PAInfo *info) + { + q->VolumeObject::d->updateVolumeObject(info); - if (d->m_name != QString::fromUtf8(info->name)) { - d->m_name = QString::fromUtf8(info->name); - Q_EMIT nameChanged(); - } - if (VolumeObject::d->m_hasVolume != info->has_volume) { - VolumeObject::d->m_hasVolume = info->has_volume; - Q_EMIT hasVolumeChanged(); - } - if (VolumeObject::d->m_volumeWritable != info->volume_writable) { - VolumeObject::d->m_volumeWritable = info->volume_writable; - Q_EMIT isVolumeWritableChanged(); - } - if (d->m_clientIndex != info->client) { - d->m_clientIndex = info->client; - Q_EMIT clientChanged(); + if (m_name != QString::fromUtf8(info->name)) { + m_name = QString::fromUtf8(info->name); + Q_EMIT q->nameChanged(); + } + if (q->VolumeObject::d->m_hasVolume != info->has_volume) { + q->VolumeObject::d->m_hasVolume = info->has_volume; + Q_EMIT q->hasVolumeChanged(); + } + if (q->VolumeObject::d->m_volumeWritable != info->volume_writable) { + q->VolumeObject::d->m_volumeWritable = info->volume_writable; + Q_EMIT q->isVolumeWritableChanged(); + } + if (m_clientIndex != info->client) { + m_clientIndex = info->client; + Q_EMIT q->clientChanged(); + } + if (m_virtualStream != (info->client == PA_INVALID_INDEX)) { + m_virtualStream = info->client == PA_INVALID_INDEX; + Q_EMIT q->virtualStreamChanged(); + } + if (m_corked != info->corked) { + m_corked = info->corked; + Q_EMIT q->corkedChanged(); + } } - if (d->m_virtualStream != (info->client == PA_INVALID_INDEX)) { - d->m_virtualStream = info->client == PA_INVALID_INDEX; - Q_EMIT virtualStreamChanged(); - } - if (d->m_corked != info->corked) { - d->m_corked = info->corked; - Q_EMIT corkedChanged(); - } -} +}; } #endif diff --git a/src/volumeobject.h b/src/volumeobject.h --- a/src/volumeobject.h +++ b/src/volumeobject.h @@ -63,11 +63,9 @@ protected: explicit VolumeObject(QObject *parent); - template - void updateVolumeObject(PAInfo *info); - class VolumeObjectPrivate *const d; friend class DevicePrivate; + friend class StreamPrivate; }; } // PulseAudioQt diff --git a/src/volumeobject_p.h b/src/volumeobject_p.h --- a/src/volumeobject_p.h +++ b/src/volumeobject_p.h @@ -40,31 +40,31 @@ QVector m_channels; pa_cvolume cvolume() const; -}; -template -void VolumeObject::updateVolumeObject(PAInfo *info) -{ - updatePulseObject(info); - if (d->m_muted != info->mute) { - d->m_muted = info->mute; - Q_EMIT mutedChanged(); - } - if (!pa_cvolume_equal(&d->m_volume, &info->volume)) { - d->m_volume = info->volume; - Q_EMIT volumeChanged(); - Q_EMIT channelVolumesChanged(); - } - QVector infoChannels; - infoChannels.reserve(info->channel_map.channels); - for (int i = 0; i < info->channel_map.channels; ++i) { - infoChannels << QString::fromUtf8(pa_channel_position_to_pretty_string(info->channel_map.map[i])); + template + void updateVolumeObject(PAInfo *info) + { + q->PulseObject::d->updatePulseObject(info); + if (m_muted != info->mute) { + m_muted = info->mute; + Q_EMIT q->mutedChanged(); + } + if (!pa_cvolume_equal(&m_volume, &info->volume)) { + m_volume = info->volume; + Q_EMIT q->volumeChanged(); + Q_EMIT q->channelVolumesChanged(); + } + QVector infoChannels; + infoChannels.reserve(info->channel_map.channels); + for (int i = 0; i < info->channel_map.channels; ++i) { + infoChannels << QString::fromUtf8(pa_channel_position_to_pretty_string(info->channel_map.map[i])); + } + if (m_channels != infoChannels) { + m_channels = infoChannels; + Q_EMIT q->channelsChanged(); + } } - if (d->m_channels != infoChannels) { - d->m_channels = infoChannels; - Q_EMIT channelsChanged(); - } -} +}; } #endif