1 /* This file is part of the KDE project
2 Copyright (C) 2008 Matthias Kretz <kretz@kde.org>
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) version 3.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
26 struct AudioDeviceKey
;
30 #include <QtCore/QDebug>
31 #include <QtCore/QHash>
32 #include <QtCore/QList>
33 #include <QtCore/QString>
34 #include "audiodeviceaccess.h"
35 #include <ksharedconfig.h>
39 class AudioDeviceAccess
;
45 inline bool operator==(const AudioDeviceKey
&rhs
) const {
46 if (uniqueId
.isNull() || rhs
.uniqueId
.isNull()) {
47 return cardNumber
== rhs
.cardNumber
&& deviceNumber
== rhs
.deviceNumber
;
49 return uniqueId
== rhs
.uniqueId
&& cardNumber
== rhs
.cardNumber
&& deviceNumber
== rhs
.deviceNumber
;
56 AudioDevice(const QString
&cardName
, const QString
&icon
, const AudioDeviceKey
&key
,
58 void addAccess(const PS::AudioDeviceAccess
&access
);
60 inline bool operator<(const AudioDevice
&rhs
) const
61 { return m_initialPreference
> rhs
.m_initialPreference
; }
62 inline bool operator==(const AudioDevice
&rhs
) const { return m_key
== rhs
.m_key
; }
65 * Returns the user visible name of the device
67 inline const QString
&name() const { return m_cardName
; }
69 inline void setPreferredName(const QString
&name
) { if (!m_dbNameOverrideFound
) { m_cardName
= name
; } }
71 //inline void setUseCache(bool c) { m_useCache = c; }
74 * Valid indexes are negative
76 inline int index() const { return m_index
; }
79 * UDI to identify which device was removed
81 //inline const QString &udi() const { return m_udi; }
84 * User visible string to describe the device in detail
86 const QString
description() const;
88 const QString
&icon() const { return m_icon
; }
90 inline bool isAvailable() const { return m_isAvailable
; }
91 inline bool isAdvanced() const { return m_isAdvanced
; }
92 inline int initialPreference() const { return m_initialPreference
; }
93 inline int deviceNumber() const { return m_key
.deviceNumber
; }
94 inline const QList
<AudioDeviceAccess
> &accessList() const { return m_accessList
; }
96 void removeFromCache(const KSharedConfigPtr
&config
) const;
97 void syncWithCache(const KSharedConfigPtr
&config
);
99 inline const AudioDeviceKey
&key() const { return m_key
; }
102 void applyHardwareDatabaseOverrides();
103 friend uint
qHash(const AudioDevice
&);
104 friend QDebug
operator<<(QDebug
&, const AudioDevice
&);
106 QList
<AudioDeviceAccess
> m_accessList
;
110 AudioDeviceKey m_key
;
112 int m_initialPreference
;
113 bool m_isAvailable
: 1;
114 bool m_isAdvanced
: 1;
115 bool m_dbNameOverrideFound
: 1;
116 //bool m_useCache : 1;
119 inline QDebug
operator<<(QDebug
&s
, const PS::AudioDeviceKey
&k
)
121 s
.nospace() << "\n uniqueId: " << k
.uniqueId
122 << ", card: " << k
.cardNumber
123 << ", device: " << k
.deviceNumber
;
127 inline QDebug
operator<<(QDebug
&s
, const PS::AudioDevice
&a
)
129 s
.nospace() << "\n- " << a
.m_cardName
130 << ", icon: " << a
.m_icon
132 << "\n index: " << a
.m_index
133 << ", initialPreference: " << a
.m_initialPreference
134 << ", available: " << a
.m_isAvailable
135 << ", advanced: " << a
.m_isAdvanced
136 << ", DB name override: " << a
.m_dbNameOverrideFound
137 << "\n description: " << a
.description()
138 << "\n access: " << a
.m_accessList
;
142 inline uint
qHash(const AudioDeviceKey
&k
)
144 return ::qHash(k
.uniqueId
) + k
.cardNumber
+ 101 * k
.deviceNumber
;
147 inline uint
qHash(const AudioDevice
&a
)
149 return qHash(a
.m_key
);
154 //X inline uint qHash(const PS::AudioDeviceKey &k)
156 //X return PS::qHash(k);
159 //X inline uint qHash(const PS::AudioDevice &a)
161 //X return PS::qHash(a);
164 #endif // AUDIODEVICE_H