add more spacing
[personal-kdebase.git] / runtime / phonon / platform_kde / devicelisting.cpp
blob74c4bd3766c95a5dfbc9dc10136017143a84a815
1 /* This file is part of the KDE project
2 Copyright (C) 2006-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 "devicelisting.h"
23 #include <QtCore/QFile>
24 #include <QtDBus/QDBusReply>
25 #include <QtCore/QMutableHashIterator>
26 #include <QtCore/QTimerEvent>
27 #include <kconfiggroup.h>
28 #include <kdebug.h>
29 #include <klocale.h>
30 #include <ksharedconfig.h>
32 #include <../config-alsa.h>
33 #ifdef HAVE_ALSA_ASOUNDLIB_H
34 #include <alsa/asoundlib.h>
35 #endif // HAVE_ALSA_ASOUNDLIB_H
37 typedef QList<QPair<QByteArray, QString> > PhononDeviceAccessList;
38 Q_DECLARE_METATYPE(PhononDeviceAccessList)
40 static void installAlsaPhononDeviceHandle()
42 #ifdef HAVE_LIBASOUND2
43 // after recreating the global configuration we can go and install custom configuration
44 snd_config_update_free_global();
45 snd_config_update();
46 Q_ASSERT(snd_config);
48 // x-phonon: device
49 QFile phononDefinition(":/phonon/phonondevice.alsa");
50 phononDefinition.open(QIODevice::ReadOnly);
51 const QByteArray &phononDefinitionData = phononDefinition.readAll();
53 snd_input_t *sndInput = 0;
54 if (0 == snd_input_buffer_open(&sndInput, phononDefinitionData.constData(), phononDefinitionData.size())) {
55 Q_ASSERT(sndInput);
56 snd_config_load(snd_config, sndInput);
57 snd_input_close(sndInput);
60 #if 0
61 // phonon_softvol: device
62 QFile softvolDefinition(":/phonon/softvol.alsa");
63 softvolDefinition.open(QIODevice::ReadOnly);
64 const QByteArray softvolDefinitionData = softvolDefinition.readAll();
66 sndInput = 0;
67 if (0 == snd_input_buffer_open(&sndInput, softvolDefinitionData.constData(), softvolDefinitionData.size())) {
68 Q_ASSERT(sndInput);
69 snd_config_load(snd_config, sndInput);
70 snd_input_close(sndInput);
72 #endif
73 #endif // HAVE_LIBASOUND2
76 namespace Phonon
79 QList<int> DeviceListing::objectDescriptionIndexes(Phonon::ObjectDescriptionType type)
81 QList<int> r;
82 if (type != Phonon::AudioOutputDeviceType && type != Phonon::AudioCaptureDeviceType) {
83 return r;
85 QDBusReply<QByteArray> reply = m_phononServer.call(QLatin1String("audioDevicesIndexes"), static_cast<int>(type));
86 if (!reply.isValid()) {
87 kError(600) << reply.error();
88 return r;
90 QDataStream stream(reply.value());
91 stream >> r;
92 return r;
95 QHash<QByteArray, QVariant> DeviceListing::objectDescriptionProperties(Phonon::ObjectDescriptionType type, int index)
97 QHash<QByteArray, QVariant> r;
98 if (type != Phonon::AudioOutputDeviceType && type != Phonon::AudioCaptureDeviceType) {
99 return r;
101 QDBusReply<QByteArray> reply = m_phononServer.call(QLatin1String("audioDevicesProperties"), index);
102 if (!reply.isValid()) {
103 kError(600) << reply.error();
104 return r;
106 QDataStream stream(reply.value());
107 stream >> r;
108 return r;
111 DeviceListing::DeviceListing()
112 : m_phononServer(
113 QLatin1String("org.kde.kded"),
114 QLatin1String("/modules/phononserver"),
115 QLatin1String("org.kde.PhononServer"))
117 qRegisterMetaType<PhononDeviceAccessList>();
118 qRegisterMetaTypeStreamOperators<PhononDeviceAccessList>("PhononDeviceAccessList");
120 KSharedConfigPtr config;
121 config = KSharedConfig::openConfig("phonon_platform_kde");
122 installAlsaPhononDeviceHandle();
124 QDBusConnection::sessionBus().connect(QLatin1String("org.kde.kded"), QLatin1String("/modules/phononserver"), QLatin1String("org.kde.PhononServer"),
125 QLatin1String("audioDevicesChanged"), QString(), this, SLOT(audioDevicesChanged()));
128 DeviceListing::~DeviceListing()
132 void DeviceListing::audioDevicesChanged()
134 kDebug(600);
135 m_signalTimer.start(0, this);
138 void DeviceListing::timerEvent(QTimerEvent *e)
140 if (e->timerId() == m_signalTimer.timerId()) {
141 m_signalTimer.stop();
142 kDebug(600) << "emitting objectDescriptionChanged for AudioOutputDeviceType and AudioCaptureDeviceType";
143 emit objectDescriptionChanged(Phonon::AudioOutputDeviceType);
144 emit objectDescriptionChanged(Phonon::AudioCaptureDeviceType);
148 } // namespace Phonon