add more spacing
[personal-kdebase.git] / runtime / phonon / kded-module / audiodevice.cpp
blob3fb57792b840fca351107bfddf494c2bb295a8fd
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 #include "audiodevice.h"
22 #include "hardwaredatabase.h"
24 #include <kconfiggroup.h>
25 #include <kdebug.h>
26 #include <klocale.h>
28 PS::AudioDevice::AudioDevice()
29 : m_index(0), m_initialPreference(0), m_isAvailable(false), m_isAdvanced(true),
30 m_dbNameOverrideFound(false)//, m_useCache(true)
34 PS::AudioDevice::AudioDevice(const QString &cardName, const QString &icon,
35 const AudioDeviceKey &key, int pref, bool adv)
36 : m_cardName(cardName),
37 m_icon(icon),
38 m_key(key),
39 m_index(0),
40 m_initialPreference(pref),
41 m_isAvailable(false),
42 m_isAdvanced(adv),
43 m_dbNameOverrideFound(false)
44 //m_useCache(true)
46 applyHardwareDatabaseOverrides();
49 void PS::AudioDevice::addAccess(const AudioDeviceAccess &access)
51 m_isAvailable |= !access.deviceIds().isEmpty();
53 m_accessList << access;
54 qSort(m_accessList); // FIXME: do sorted insert
57 const QString PS::AudioDevice::description() const
59 if (!m_isAvailable) {
60 return i18n("<html>This device is currently not available (either it is unplugged or the "
61 "driver is not loaded).</html>");
63 QString list;
64 foreach (const AudioDeviceAccess &a, m_accessList) {
65 foreach (const QString &id, a.deviceIds()) {
66 list += i18nc("The first argument is name of the driver/sound subsystem. "
67 "The second argument is the device identifier", "<li>%1: %2</li>",
68 a.driverName(), id);
71 return i18n("<html>This will try the following devices and use the first that works: "
72 "<ol>%1</ol></html>", list);
75 void PS::AudioDevice::applyHardwareDatabaseOverrides()
77 // now let's take a look at the hardware database whether we have to override something
78 kDebug(601) << "looking for" << m_key.uniqueId;
79 if (HardwareDatabase::contains(m_key.uniqueId)) {
80 const HardwareDatabase::Entry &e = HardwareDatabase::entryFor(m_key.uniqueId);
81 kDebug(601) << " found it:" << e.name << e.iconName << e.initialPreference << e.isAdvanced;
82 if (!e.name.isEmpty()) {
83 m_dbNameOverrideFound = true;
84 m_cardName = e.name;
86 if (!e.iconName.isEmpty()) {
87 m_icon = e.iconName;
89 if (e.isAdvanced != 2) {
90 m_isAdvanced = e.isAdvanced;
92 m_initialPreference = e.initialPreference;
96 void PS::AudioDevice::removeFromCache(const KSharedConfigPtr &config) const
98 //if (m_useCache) {
99 KConfigGroup cGroup(config, QLatin1String("AudioDevice_") + m_key.uniqueId);
100 cGroup.writeEntry("deleted", true);
104 void PS::AudioDevice::syncWithCache(const KSharedConfigPtr &config)
106 //if (!m_useCache) {
107 //return;
109 KConfigGroup cGroup(config, QLatin1String("AudioDevice_") + m_key.uniqueId);
110 if (cGroup.exists()) {
111 m_index = cGroup.readEntry("index", 0);
113 if (m_index >= 0) {
114 KConfigGroup globalGroup(config, "Globals");
115 m_index = -globalGroup.readEntry("nextIndex", 1);
116 globalGroup.writeEntry("nextIndex", 1 - m_index);
117 Q_ASSERT(m_index < 0);
119 cGroup.writeEntry("index", m_index);
121 cGroup.writeEntry("cardName", m_cardName);
122 cGroup.writeEntry("iconName", m_icon);
123 //cGroup.writeEntry("udi", m_udi);
124 cGroup.writeEntry("initialPreference", m_initialPreference);
125 cGroup.writeEntry("isAdvanced", m_isAdvanced);
126 cGroup.writeEntry("deviceNumber", m_key.deviceNumber);
127 cGroup.writeEntry("deleted", false);
128 // hack: only internal soundcards should get the icon audio-card. All others, we assume, are
129 // hotpluggable
130 cGroup.writeEntry("hotpluggable", m_icon != QLatin1String("audio-card"));