00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "kalphonon.h"
00020 #include "kalengine.h"
00021
00022 #include <QtCore/QCoreApplication>
00023 #include <QtCore/QStringList>
00024 #include <QtCore/QtGlobal>
00025 #include <QtCore/QDebug>
00026
00027 class KALPhononPrivate
00028 {
00029 public:
00030 KALPhononPrivate() :
00031 phononOutput( 0 ),
00032 parentheses( QRegExp::escape( " (" ) + ".*" + QRegExp::escape( ")" ) ) {}
00033
00034 virtual ~KALPhononPrivate() {}
00035
00036 QString alDevice;
00037 Phonon::AudioOutput* phononOutput;
00038 Phonon::Category category;
00039 QRegExp parentheses;
00040
00041 };
00042
00043 KALPhonon::KALPhonon( QObject* parent )
00044 : QObject( parent ),
00045 d( new KALPhononPrivate )
00046 {
00047 }
00048
00049 KALPhonon::~KALPhonon()
00050 {
00051 delete d;
00052 }
00053
00054 bool KALPhonon::setDevice( const Phonon::AudioOutputDevice& device )
00055 {
00056
00057 QString phononDevice = device.name().remove( d->parentheses );
00058
00059 QStringList alDeviceList = KALEngine::deviceList().filter( phononDevice );
00060
00061 if( alDeviceList.isEmpty() )
00062 {
00063 qWarning() << "Could not find any OpenAL device that matches current Phonon device";
00064 return false;
00065 }
00066
00067 d->alDevice = alDeviceList.first();
00068
00069 emit( deviceChanged( d->alDevice ) );
00070
00071 return true;
00072 }
00073
00074 bool KALPhonon::setCategory( Phonon::Category category )
00075 {
00076 resetOutput();
00077
00078
00079 if( !QCoreApplication::instance() )
00080 {
00081 qWarning() << "Could not get current Phonon device because QCoreApplication is not running";
00082 return false;
00083 }
00084
00085 d->phononOutput = new Phonon::AudioOutput( category, this );
00086 if( !setDevice( d->phononOutput->outputDevice() ) )
00087 {
00088 return false;
00089 }
00090
00091 d->category = category;
00092 connect( d->phononOutput, SIGNAL( outputDeviceChanged( Phonon::AudioOutputDevice ) ), this, SLOT( setDevice( Phonon::AudioOutputDevice ) ) );
00093
00094 return true;
00095 }
00096
00097 void KALPhonon::resetOutput()
00098 {
00099 if( !d->phononOutput )
00100 {
00101 return;
00102 }
00103
00104 d->phononOutput->disconnect( this );
00105 d->phononOutput->deleteLater();
00106 d->phononOutput = 0;
00107 }
00108
00109 Phonon::AudioOutput* KALPhonon::phononOutput() const
00110 {
00111 return d->phononOutput;
00112 }
00113
00114 QString KALPhonon::alDevice() const
00115 {
00116 return d->alDevice;
00117 }
00118
00119 Phonon::Category KALPhonon::category() const
00120 {
00121 return d->category;
00122 }
00123
00124 #include "kalphonon.moc"