diff --git a/src/card.h b/src/card.h --- a/src/card.h +++ b/src/card.h @@ -82,6 +82,7 @@ Q_PROPERTY(QList profiles READ profiles NOTIFY profilesChanged) Q_PROPERTY(quint32 activeProfileIndex READ activeProfileIndex WRITE setActiveProfileIndex NOTIFY activeProfileIndexChanged) Q_PROPERTY(QList ports READ ports NOTIFY portsChanged) + Q_PROPERTY(QList availableProfiles READ availableProfiles NOTIFY availableProfilesChanged) public: Card(QObject *parent); @@ -92,18 +93,21 @@ quint32 activeProfileIndex() const; void setActiveProfileIndex(quint32 profileIndex); QList ports() const; + QList availableProfiles() const; signals: void nameChanged(); void profilesChanged(); void activeProfileIndexChanged(); void portsChanged(); + void availableProfilesChanged(); private: QString m_name; QList m_profiles; quint32 m_activeProfileIndex; QList m_ports; + QList m_availableProfiles; }; } // QPulseAudio diff --git a/src/card.cpp b/src/card.cpp --- a/src/card.cpp +++ b/src/card.cpp @@ -55,6 +55,14 @@ emit profilesChanged(); emit activeProfileIndexChanged(); + m_availableProfiles.clear(); + for (QObject * profile: qAsConst(m_profiles)) { + if (static_cast(profile)->availability() == Port::Available) { + m_availableProfiles.append(profile); + } + } + emit availableProfilesChanged(); + qDeleteAll(m_ports); m_ports.clear(); for (auto **it = info->ports; it && *it != nullptr; ++it) { @@ -91,4 +99,9 @@ return m_ports; } +QList Card::availableProfiles() const +{ + return m_availableProfiles; +} + } // QPulseAudio diff --git a/src/kcm/package/contents/ui/CardListItem.qml b/src/kcm/package/contents/ui/CardListItem.qml --- a/src/kcm/package/contents/ui/CardListItem.qml +++ b/src/kcm/package/contents/ui/CardListItem.qml @@ -53,7 +53,7 @@ } ComboBox { Layout.fillWidth: true - model: Profiles + model: AvailableProfiles // NOTE: model resets (i.e. profiles property changes) will reset // the currentIndex, so force it to be set on model changes, otherwise // it would eventually become 0 when it shouldn't be. diff --git a/src/port.h b/src/port.h --- a/src/port.h +++ b/src/port.h @@ -31,14 +31,8 @@ class Port : public Profile { Q_OBJECT - Q_PROPERTY(Availability availability READ availability NOTIFY availabilityChanged) + public: - enum Availability { - Unknown, - Available, - Unavailable - }; - Q_ENUM(Availability) Port(QObject *parent); virtual ~Port(); @@ -64,14 +58,6 @@ emit availabilityChanged(); } } - - Availability availability() const; - -signals: - void availabilityChanged(); - -private: - Availability m_availability; }; } // QPulseAudio diff --git a/src/port.cpp b/src/port.cpp --- a/src/port.cpp +++ b/src/port.cpp @@ -25,17 +25,11 @@ Port::Port(QObject *parent) : Profile(parent) - , m_availability(Unknown) { } Port::~Port() { } -Port::Availability Port::availability() const -{ - return m_availability; -} - } // QPulseAudio diff --git a/src/profile.h b/src/profile.h --- a/src/profile.h +++ b/src/profile.h @@ -33,7 +33,16 @@ Q_PROPERTY(QString name READ name NOTIFY nameChanged) Q_PROPERTY(QString description READ description NOTIFY descriptionChanged) Q_PROPERTY(quint32 priority READ priority NOTIFY priorityChanged) + Q_PROPERTY(Availability availability READ availability NOTIFY availabilityChanged) public: + + enum Availability { + Unknown, + Available, + Unavailable + }; + Q_ENUM(Availability) + Profile(QObject *parent); virtual ~Profile(); @@ -58,21 +67,38 @@ m_priority = info->priority; emit priorityChanged(); } + + Availability newAvailability; + if (info->available) { + newAvailability = Available; + } else { + newAvailability = Unavailable; + } + + if (m_availability != newAvailability) { + m_availability = newAvailability; + emit availabilityChanged(); + } } QString name() const; QString description() const; quint32 priority() const; + Availability availability() const; signals: void nameChanged(); void descriptionChanged(); void priorityChanged(); + void availabilityChanged(); private: QString m_name; QString m_description; quint32 m_priority; + +protected: + Availability m_availability; }; } // QPulseAudio diff --git a/src/profile.cpp b/src/profile.cpp --- a/src/profile.cpp +++ b/src/profile.cpp @@ -28,6 +28,7 @@ , m_name() , m_description() , m_priority(0) + , m_availability(Unknown) { } @@ -50,4 +51,9 @@ return m_priority; } +Profile::Availability Profile::availability() const +{ + return m_availability; +} + } // QPulseAudio