2
* KMix -- KDE's full featured mini mixer
4
* Copyright 2006-2007 Christian Esken <esken@kde.org>
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Library General Public
8
* License as published by the Free Software Foundation; either
9
* version 2 of the License, or (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* Library General Public License for more details.
16
* You should have received a copy of the GNU Library General Public
17
* License along with this program; if not, write to the Free
18
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
#include "core/kmixdevicemanager.h"
30
#include <solid/device.h>
31
#include <solid/devicenotifier.h>
32
#include <solid/audiointerface.h>
34
KMixDeviceManager* KMixDeviceManager::s_KMixDeviceManager = 0;
36
KMixDeviceManager::KMixDeviceManager()
40
KMixDeviceManager::~KMixDeviceManager()
44
KMixDeviceManager* KMixDeviceManager::instance()
46
if ( s_KMixDeviceManager == 0 ) {
47
s_KMixDeviceManager = new KMixDeviceManager();
49
return s_KMixDeviceManager;
52
void KMixDeviceManager::initHotplug()
54
connect (Solid::DeviceNotifier::instance(), SIGNAL(deviceAdded(const QString&)), SLOT(pluggedSlot(const QString&)) );
55
connect (Solid::DeviceNotifier::instance(), SIGNAL(deviceRemoved(const QString&)), SLOT(unpluggedSlot(const QString&)) );
58
QString KMixDeviceManager::getUDI_ALSA(int num)
60
QList<Solid::Device> dl = Solid::Device::listFromType(Solid::DeviceInterface::AudioInterface);
63
numString.setNum(num);
67
foreach ( const Solid::Device &device, dl )
69
// std::cout << "Coldplug udi = '" << device.udi().toUtf8().data() << "'\n";
70
const Solid::AudioInterface *audiohw = device.as<Solid::AudioInterface>();
71
if (audiohw && (audiohw->deviceType() & ( Solid::AudioInterface::AudioControl))) {
72
switch (audiohw->driver()) {
73
case Solid::AudioInterface::Alsa:
74
devHandle = audiohw->driverHandle().toList().first().toString();
75
// std::cout << ">>> Coldplugged ALSA ='" << devHandle.toUtf8().data() << "'\n";
76
if ( numString == devHandle ) {
78
// std::cout << ">>> Match!!! Coldplugged ALSA ='" << devHandle.toUtf8().data() << "'\n";
85
} // is an audio control
91
QString KMixDeviceManager::getUDI_OSS(const QString& devname)
93
QList<Solid::Device> dl = Solid::Device::listFromType(Solid::DeviceInterface::AudioInterface);
98
foreach ( const Solid::Device &device, dl )
100
// std::cout << "Coldplug udi = '" << device.udi().toUtf8().data() << "'\n";
101
const Solid::AudioInterface *audiohw = device.as<Solid::AudioInterface>();
102
if (audiohw && (audiohw->deviceType() & ( Solid::AudioInterface::AudioControl))) {
103
switch (audiohw->driver()) {
104
case Solid::AudioInterface::OpenSoundSystem:
105
devHandle = audiohw->driverHandle().toString();
106
// std::cout << ">>> Coldplugged OSS ='" << devHandle.toUtf8().data() << "'\n";
107
if ( devname == devHandle ) {
109
// std::cout << ">>> Match!!! Coldplugged OSS ='" << devHandle.toUtf8().data() << "'\n";
116
} // is an audio control
123
void KMixDeviceManager::pluggedSlot(const QString& udi) {
124
// std::cout << "Plugged udi='" << udi.toUtf8().data() << "'\n";
125
Solid::Device device(udi);
126
Solid::AudioInterface *audiohw = device.as<Solid::AudioInterface>();
127
if (audiohw && (audiohw->deviceType() & ( Solid::AudioInterface::AudioControl))) {
129
QRegExp devExpr( QLatin1String( "^\\D+(\\d+)$" ));
130
switch (audiohw->driver()) {
131
case Solid::AudioInterface::Alsa:
132
if ( _hotpluggingBackend == "ALSA" || _hotpluggingBackend == "*" ) {
133
dev = audiohw->driverHandle().toList().first().toString();
134
emit plugged("ALSA", udi, dev);
137
case Solid::AudioInterface::OpenSoundSystem:
138
if ( _hotpluggingBackend == "OSS" || _hotpluggingBackend == "*" ) {
139
dev = audiohw->driverHandle().toString();
140
if ( devExpr.indexIn(dev) > -1 ) {
141
dev = devExpr.cap(1); // Get device number from device name (e.g "/dev/mixer1" or "/dev/sound/mixer2")
144
dev = "0"; // "/dev/mixer" or "/dev/sound/mixer"
146
emit plugged("OSS", udi, dev);
150
kError(67100) << "Plugged UNKNOWN Audio device (ignored)";
157
void KMixDeviceManager::unpluggedSlot(const QString& udi) {
158
// std::cout << "Unplugged udi='" << udi.toUtf8().data() << "'\n";
159
Solid::Device device(udi);
160
// At this point the device has already been unplugged by the user. Solid doesn't know anything about the
161
// device except the UDI (not even device.as<Solid::AudioInterface>() is possible). Thus I'll forward any
162
// unplugging action (could e.g. also be HID or mass storage). The receiver of the signal as to deal with it,
163
// but a simple UDI matching is enough.
169
#include "kmixdevicemanager.moc"