File indexing completed on 2024-12-08 08:02:47
0001 /* 0002 SPDX-FileCopyrightText: 2014-2015 Harald Sitter <sitter@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #ifndef PROFILE_H 0008 #define PROFILE_H 0009 0010 #include <QObject> 0011 #include <QString> 0012 0013 namespace QPulseAudio 0014 { 0015 class Profile : public QObject 0016 { 0017 Q_OBJECT 0018 Q_PROPERTY(QString name READ name NOTIFY nameChanged) 0019 Q_PROPERTY(QString description READ description NOTIFY descriptionChanged) 0020 Q_PROPERTY(quint32 priority READ priority NOTIFY priorityChanged) 0021 Q_PROPERTY(Availability availability READ availability NOTIFY availabilityChanged) 0022 public: 0023 enum Availability { 0024 Unknown, 0025 Available, 0026 Unavailable, 0027 }; 0028 Q_ENUM(Availability) 0029 0030 explicit Profile(QObject *parent); 0031 ~Profile() override; 0032 0033 template<typename PAInfo> 0034 bool setInfo(const PAInfo *info) 0035 { 0036 return setCommonInfo(info, info->available ? Available : Unavailable); 0037 } 0038 0039 QString name() const; 0040 QString description() const; 0041 quint32 priority() const; 0042 Availability availability() const; 0043 0044 Q_SIGNALS: 0045 void nameChanged(); 0046 void descriptionChanged(); 0047 void priorityChanged(); 0048 void availabilityChanged(); 0049 0050 protected: 0051 template<typename PAInfo> 0052 bool setCommonInfo(const PAInfo *info, Availability newAvailability) 0053 { 0054 bool changed = false; 0055 0056 // Description is optional. Name not so much as we need some ID. 0057 Q_ASSERT(info->name); 0058 QString infoName = QString::fromUtf8(info->name); 0059 if (m_name != infoName) { 0060 m_name = infoName; 0061 Q_EMIT nameChanged(); 0062 changed = true; 0063 } 0064 if (info->description) { 0065 QString infoDescription = QString::fromUtf8(info->description); 0066 if (m_description != infoDescription) { 0067 m_description = infoDescription; 0068 Q_EMIT descriptionChanged(); 0069 changed = true; 0070 } 0071 } 0072 if (m_priority != info->priority) { 0073 m_priority = info->priority; 0074 Q_EMIT priorityChanged(); 0075 changed = true; 0076 } 0077 0078 if (m_availability != newAvailability) { 0079 m_availability = newAvailability; 0080 Q_EMIT availabilityChanged(); 0081 changed = true; 0082 } 0083 0084 return changed; 0085 } 0086 0087 private: 0088 QString m_name; 0089 QString m_description; 0090 quint32 m_priority; 0091 Availability m_availability; 0092 }; 0093 0094 } // QPulseAudio 0095 0096 #endif // PROFILE_H