add more spacing
[personal-kdebase.git] / runtime / phonon / kcm / devicepreference_update.cpp
blob5463e1423306b97f86950b95620bfb999290b673
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 <QtCore/QMutableListIterator>
23 #include <QtCore/QList>
24 #include "qsettingsgroup_p.h"
25 #include <kcomponentdata.h>
26 #include <kconfig.h>
27 #include <kconfiggroup.h>
29 using Phonon::QSettingsGroup;
31 Q_DECLARE_METATYPE(QList<int>)
33 int main(int argc, char **argv)
35 QCoreApplication app(argc, argv);
36 KComponentData cData("phonon device preference update");
38 KConfig kconfig("phonondevicesrc", KConfig::NoGlobals);
39 KConfigGroup globalGroup(&kconfig, "Globals");
40 int newIndexForZero = 0;
42 foreach (const QString &group, kconfig.groupList()) {
43 KConfigGroup configGroup(&kconfig, group);
44 int index = configGroup.readEntry("index", -1);
45 if (index == 0) {
46 newIndexForZero = globalGroup.readEntry("nextIndex", 0);
47 configGroup.writeEntry("index", newIndexForZero);
48 globalGroup.writeEntry("nextIndex", newIndexForZero + 1);
49 break;
53 qRegisterMetaTypeStreamOperators<QList<int> >("QList<int>");
55 QSettings qconfig(QLatin1String("kde.org"), QLatin1String("libphonon"));
56 QSettingsGroup outputGroup(&qconfig, QLatin1String("AudioOutputDevice"));
57 for (int i = -1; i < 10; ++i) {
58 const QString oldKey = QLatin1String("Category") + QString::number(i);
59 const QString newKey = QLatin1String("Category_") + QString::number(i);
60 if (outputGroup.hasKey(oldKey) && !outputGroup.hasKey(newKey)) {
61 QList<int> deviceIndexes = outputGroup.value(oldKey, QList<int>());
62 QMutableListIterator<int> index(deviceIndexes);
63 while (index.hasNext()) {
64 index.next();
65 if (index.value() < 10000 && index.value() >= 0) {
66 if (index.value() == 0) {
67 Q_ASSERT(newIndexForZero);
68 index.setValue(-newIndexForZero);
69 } else {
70 index.setValue(-index.value());
74 outputGroup.setValue(newKey, deviceIndexes);
75 outputGroup.removeEntry(oldKey);
79 return 0;