File indexing completed on 2024-11-03 05:04:11
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 #include "card.h" 0008 0009 #include "debug.h" 0010 0011 #include "context.h" 0012 0013 namespace QPulseAudio 0014 { 0015 Card::Card(QObject *parent) 0016 : PulseObject(parent) 0017 { 0018 } 0019 0020 void Card::update(const pa_card_info *info) 0021 { 0022 updatePulseObject(info); 0023 0024 QString infoName = QString::fromUtf8(info->name); 0025 if (m_name != infoName) { 0026 m_name = infoName; 0027 Q_EMIT nameChanged(); 0028 } 0029 0030 const quint32 oldActiveProfileIndex = m_activeProfileIndex; 0031 bool profilesHaveChanged = false; 0032 int i = 0; 0033 for (auto **it = info->profiles2; it && *it != nullptr; ++it) { 0034 if (i < m_profiles.count()) { 0035 auto *profile = static_cast<Profile *>(m_profiles.at(i)); 0036 profilesHaveChanged |= profile->setInfo(*it); 0037 } else { 0038 auto *profile = new Profile(this); 0039 profile->setInfo(*it); 0040 m_profiles.append(profile); 0041 profilesHaveChanged = true; 0042 } 0043 if (info->active_profile2 == *it) { 0044 m_activeProfileIndex = i; 0045 } 0046 ++i; 0047 } 0048 0049 while (m_profiles.count() > i) { 0050 delete m_profiles.takeLast(); 0051 profilesHaveChanged = true; 0052 } 0053 0054 if (profilesHaveChanged) { 0055 Q_EMIT profilesChanged(); 0056 } 0057 if (profilesHaveChanged || m_activeProfileIndex != oldActiveProfileIndex) { 0058 Q_EMIT activeProfileIndexChanged(); 0059 } 0060 0061 bool portsHaveChanged = false; 0062 i = 0; 0063 for (auto **ports = info->ports; ports && *ports != nullptr; ++ports) { 0064 if (i < m_ports.count()) { 0065 Port *port = static_cast<Port *>(m_ports.at(i)); 0066 portsHaveChanged |= port->setInfo(*ports); 0067 } else { 0068 Port *port = new Port(this); 0069 port->setInfo(*ports); 0070 m_ports.append(port); 0071 portsHaveChanged = true; 0072 } 0073 ++i; 0074 } 0075 0076 while (m_ports.count() > i) { 0077 delete m_ports.takeLast(); 0078 portsHaveChanged = true; 0079 } 0080 0081 if (portsHaveChanged) { 0082 Q_EMIT portsChanged(); 0083 } 0084 } 0085 0086 QString Card::name() const 0087 { 0088 return m_name; 0089 } 0090 0091 QList<QObject *> Card::profiles() const 0092 { 0093 return m_profiles; 0094 } 0095 0096 quint32 Card::activeProfileIndex() const 0097 { 0098 return m_activeProfileIndex; 0099 } 0100 0101 void Card::setActiveProfileIndex(quint32 profileIndex) 0102 { 0103 const Profile *profile = qobject_cast<Profile *>(profiles().at(profileIndex)); 0104 context()->setCardProfile(index(), profile->name()); 0105 } 0106 0107 QList<QObject *> Card::ports() const 0108 { 0109 return m_ports; 0110 } 0111 0112 } // QPulseAudio