add more spacing
[personal-kdebase.git] / runtime / phonon / kded-module / audiodevice.h
blob8d823c6b13f15274584fd7004cbca65374bb1f71
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.
21 #ifndef AUDIODEVICE_H
22 #define AUDIODEVICE_H
24 namespace PS
26 struct AudioDeviceKey;
27 struct AudioDevice;
28 } // namespace PS
30 #include <QtCore/QDebug>
31 #include <QtCore/QHash>
32 #include <QtCore/QList>
33 #include <QtCore/QString>
34 #include "audiodeviceaccess.h"
35 #include <ksharedconfig.h>
37 namespace PS
39 class AudioDeviceAccess;
40 struct AudioDeviceKey
42 QString uniqueId;
43 int cardNumber;
44 int deviceNumber;
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;
52 class AudioDevice
54 public:
55 AudioDevice();
56 AudioDevice(const QString &cardName, const QString &icon, const AudioDeviceKey &key,
57 int pref, bool adv);
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; }
64 /**
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; }
73 /**
74 * Valid indexes are negative
76 inline int index() const { return m_index; }
78 /**
79 * UDI to identify which device was removed
81 //inline const QString &udi() const { return m_udi; }
83 /**
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; }
101 private:
102 void applyHardwareDatabaseOverrides();
103 friend uint qHash(const AudioDevice &);
104 friend QDebug operator<<(QDebug &, const AudioDevice &);
106 QList<AudioDeviceAccess> m_accessList;
107 QString m_cardName;
108 QString m_icon;
110 AudioDeviceKey m_key;
111 int m_index;
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;
124 return s;
127 inline QDebug operator<<(QDebug &s, const PS::AudioDevice &a)
129 s.nospace() << "\n- " << a.m_cardName
130 << ", icon: " << a.m_icon
131 << a.m_key
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;
139 return s;
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);
152 } // namespace PS
154 //X inline uint qHash(const PS::AudioDeviceKey &k)
155 //X {
156 //X return PS::qHash(k);
157 //X }
158 //X
159 //X inline uint qHash(const PS::AudioDevice &a)
160 //X {
161 //X return PS::qHash(a);
162 //X }
164 #endif // AUDIODEVICE_H