File indexing completed on 2024-04-14 14:55:43

0001 /*
0002     SPDX-FileCopyrightText: 2018 Nicolas Fella <nicolas.fella@gmx.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #pragma once
0008 
0009 #include "profile.h"
0010 #include "pulseobject_p.h"
0011 
0012 namespace PulseAudioQt
0013 {
0014 class ProfilePrivate
0015 {
0016 public:
0017     explicit ProfilePrivate(Profile *q);
0018     virtual ~ProfilePrivate();
0019 
0020     Profile *q;
0021 
0022     QString m_description;
0023     quint32 m_priority = 0;
0024     Profile::Availability m_availability = Profile::Unknown;
0025     quint32 m_sinkCount = 0;
0026     quint32 m_sourceCount = 0;
0027 
0028     template<typename PAInfo>
0029     void setInfo(const PAInfo *info)
0030     {
0031         setCommonInfo(info, info->available ? Profile::Available : Profile::Unavailable);
0032 
0033         if (m_sinkCount != info->n_sinks) {
0034             m_sinkCount = info->n_sinks;
0035             Q_EMIT q->sinkCountChanged();
0036         }
0037 
0038         if (m_sourceCount != info->n_sources) {
0039             m_sourceCount = info->n_sources;
0040             Q_EMIT q->sourceCountChanged();
0041         }
0042     }
0043 
0044     template<typename PAInfo>
0045     void setCommonInfo(const PAInfo *info, Profile::Availability newAvailability)
0046     {
0047         if (info->description) {
0048             QString infoDescription = QString::fromUtf8(info->description);
0049             if (m_description != infoDescription) {
0050                 m_description = infoDescription;
0051                 Q_EMIT q->descriptionChanged();
0052             }
0053         }
0054         if (m_priority != info->priority) {
0055             m_priority = info->priority;
0056             Q_EMIT q->priorityChanged();
0057         }
0058 
0059         if (m_availability != newAvailability) {
0060             m_availability = newAvailability;
0061             Q_EMIT q->availabilityChanged();
0062         }
0063 
0064         q->PulseObject::d->updatePulseObject(info);
0065     }
0066 };
0067 }