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 <QtCore/QCoreApplication>
22 #include <kcomponentdata.h>
25 #include <kconfiggroup.h>
27 int main(int argc
, char **argv
)
29 QCoreApplication
app(argc
, argv
);
30 KComponentData
cData("phonon device uids update");
33 // 1. change group names from
34 // Audio{Capture,Output}Device_<bus>:<numbers>:{capture,playback}:{alsa,oss}:<devicenum>
36 // AudioDevice_<bus>:<numbers>:<devicenum>:{capture,playback}
37 // 2. make indexes negative
38 // 3. remove playbackDevice/captureDevice keys
40 // 5. remove driver key
41 // 6. add deviceNumber key
42 KConfig
kconfig("phonondevicesrc", KConfig::SimpleConfig
);
43 KConfigGroup
globalGroup(&kconfig
, "Globals");
44 int nextIndex
= globalGroup
.readEntry("nextIndex", 1);
46 const QStringList
&oldGroupList
= kconfig
.groupList();
47 foreach (const QString
&group
, oldGroupList
) {
48 if (group
== "Globals") {
51 if (group
.startsWith(QLatin1String("front:")) || group
.startsWith(QLatin1String("iec958:"))) {
52 kconfig
.deleteGroup(group
);
56 KConfigGroup
configGroup(&kconfig
, group
);
58 const QString
&cardName
= configGroup
.readEntry("cardName", QString());
59 const QString
&icon
= configGroup
.readEntry("icon", QString());
60 const int initialPreference
= configGroup
.readEntry("initialPreference", 0);
61 const bool isAdvanced
= configGroup
.readEntry("isAdvanced", true);
63 int index
= configGroup
.readEntry("index", 0);
65 kError() << "invalid old index found";
70 int deviceNumber
= -1;
72 if (group
.startsWith(QLatin1String("AudioOutputDevice_"))) {
73 const QString
&deviceNumberString
= group
.right(group
.length() - group
.lastIndexOf(QLatin1Char(':')) - 1);
75 deviceNumber
= deviceNumberString
.toInt(&ok
);
77 // It's probably a fallback UniqueID. Let's get rid of it.
78 kconfig
.deleteGroup(group
);
81 newGroup
= QLatin1String("AudioDevice_") +
82 group
.mid(18, group
.indexOf(QLatin1String(":playback")) - 17) +
83 deviceNumberString
+ QLatin1String(":playback");
84 } else if (group
.startsWith(QLatin1String("AudioCaptureDevice_"))) {
85 const QString
&deviceNumberString
= group
.right(group
.length() - group
.lastIndexOf(QLatin1Char(':')) - 1);
87 deviceNumber
= deviceNumberString
.toInt(&ok
);
89 // It's probably a fallback UniqueID. Let's get rid of it.
90 kconfig
.deleteGroup(group
);
93 newGroup
= QLatin1String("AudioDevice_") +
94 group
.mid(19, group
.indexOf(QLatin1String(":capture")) - 18) +
95 deviceNumberString
+ QLatin1String(":capture");
96 } else if (group
.startsWith(QLatin1String("AudioIODevice_"))) {
98 * OSS Device entry, on Linux already covered by ALSA, so we skip it if an ALSA device
101 if (oldGroupList
.indexOf(QRegExp(QLatin1String("^Audio(Capture|Output)Device_") +
102 group
.mid(14, group
.indexOf(QLatin1String(":both")) - 14) +
103 QLatin1String(":(capture|playback):alsa:\\d+$"))) > -1) {
104 kconfig
.deleteGroup(group
);
107 const QString
&deviceNumberString
= group
.right(group
.length() - group
.lastIndexOf(QLatin1Char(':')) - 1);
109 deviceNumber
= deviceNumberString
.toInt(&ok
);
111 // It's probably a fallback UniqueID. Let's get rid of it.
112 kconfig
.deleteGroup(group
);
115 newGroup
= QLatin1String("AudioDevice_") +
116 group
.mid(19, group
.indexOf(QLatin1String(":both")) - 18) + deviceNumberString
;
119 KConfigGroup
newConfigGroup(&kconfig
, newGroup
+ QLatin1String(":playback"));
120 newConfigGroup
.writeEntry("cardName", cardName
);
121 newConfigGroup
.writeEntry("iconName", icon
);
122 newConfigGroup
.writeEntry("initialPreference", initialPreference
);
123 newConfigGroup
.writeEntry("isAdvanced", isAdvanced
);
124 newConfigGroup
.writeEntry("index", index
);
125 newConfigGroup
.writeEntry("deviceNumber", deviceNumber
);
127 KConfigGroup
newConfigGroup(&kconfig
, newGroup
+ QLatin1String(":capture"));
128 newConfigGroup
.writeEntry("cardName", cardName
);
129 newConfigGroup
.writeEntry("iconName", icon
);
130 newConfigGroup
.writeEntry("initialPreference", initialPreference
);
131 newConfigGroup
.writeEntry("isAdvanced", isAdvanced
);
132 newConfigGroup
.writeEntry("index", -(nextIndex
++));
133 newConfigGroup
.writeEntry("deviceNumber", deviceNumber
);
135 kconfig
.deleteGroup(group
);
138 kWarning() << "found unknown/unhandled group:" << group
<< ". Removing.";
139 kconfig
.deleteGroup(group
);
142 KConfigGroup
newConfigGroup(&kconfig
, newGroup
);
143 newConfigGroup
.writeEntry("cardName", cardName
);
144 newConfigGroup
.writeEntry("iconName", icon
);
145 newConfigGroup
.writeEntry("initialPreference", initialPreference
);
146 newConfigGroup
.writeEntry("isAdvanced", isAdvanced
);
147 newConfigGroup
.writeEntry("index", index
);
148 newConfigGroup
.writeEntry("deviceNumber", deviceNumber
);
149 kconfig
.deleteGroup(group
);
152 globalGroup
.writeEntry("nextIndex", nextIndex
);