diff --git a/src/cardport.cpp b/src/cardport.cpp index 1d83947..4b6503a 100644 --- a/src/cardport.cpp +++ b/src/cardport.cpp @@ -1,60 +1,61 @@ /* 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 . */ #include "cardport.h" #include "port_p.h" namespace PulseAudioQt { CardPort::CardPort(QObject *parent) : Port(parent) { } CardPort::~CardPort() { } void CardPort::update(const pa_card_port_info *info) { + Port::d->setInfo(info); 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_EMIT propertiesChanged(); } QVariantMap CardPort::properties() const { return m_properties; } } //PulseAudioQt diff --git a/src/port_p.h b/src/port_p.h index 9811244..1b1d731 100644 --- a/src/port_p.h +++ b/src/port_p.h @@ -1,46 +1,55 @@ /* 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 . */ #pragma once #include "port.h" #include "profile_p.h" +#include namespace PulseAudioQt { class PortPrivate { public: explicit PortPrivate(Port *q); virtual ~PortPrivate(); + Port *q; + template void setInfo(const PAInfo *info) { - q->Profile::d->setInfo(info); + Profile::Availability newAvailability; + switch (info->available) { + case PA_PORT_AVAILABLE_NO: + newAvailability = Profile::Unavailable; + break; + case PA_PORT_AVAILABLE_YES: + newAvailability = Profile::Available; + break; + default: + newAvailability = Profile::Unknown; + } + q->Profile::d->setCommonInfo(info, newAvailability); } - - Port *q; }; - - } - diff --git a/src/profile_p.h b/src/profile_p.h index 44167ee..e68de26 100644 --- a/src/profile_p.h +++ b/src/profile_p.h @@ -1,72 +1,76 @@ /* 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 . */ #pragma once #include "profile.h" namespace PulseAudioQt { class ProfilePrivate { public: explicit ProfilePrivate(Profile *q); virtual ~ProfilePrivate(); Profile *q; QString m_name; QString m_description; quint32 m_priority; Profile::Availability m_availability; template void setInfo(const PAInfo *info) + { + setCommonInfo(info, info->available ? Profile::Available : Profile::Unavailable); + } + + template + void setCommonInfo(const PAInfo *info, Profile::Availability newAvailability) { // 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(); } - Profile::Availability newAvailability = info->available ? Profile::Available : Profile::Unavailable; if (m_availability != newAvailability) { m_availability = newAvailability; Q_EMIT q->availabilityChanged(); } } }; - }