listensupport.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2008  Tim Fechtner < urwald at users dot sourceforge dot net >
00003 
00004     This program is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU General Public License as
00006     published by the Free Software Foundation; either version 2 of
00007     the License or (at your option) version 3 or any later version
00008     accepted by the membership of KDE e.V. (or its successor approved
00009     by the membership of KDE e.V.), which shall act as a proxy
00010     defined in Section 14 of version 3 of the license.
00011 
00012     This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00019 */
00020 
00021 #include "listensupport.h"
00022 
00023 #include <QTimer>
00024 #include <QCoreApplication>
00025 #include <QEventLoop>
00026 
00027 listenSupport::listenSupport(QObject *parent) : QObject(parent)
00028 {
00029   relayPort = -1;
00030   station = 0;
00031   media = new Phonon::MediaObject(this);
00032   audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
00033 /*qDebug() << "backend name:" << audioOutput->outputDevice().name() << "description:" <<
00034     audioOutput->outputDevice().description();
00035   connect(media, SIGNAL(aboutToFinish ()), this, SLOT(info()));
00036   connect(media, SIGNAL(currentSourceChanged ( const Phonon::MediaSource & )), this, SLOT(info()));
00037   connect(media, SIGNAL(finished ()), this, SLOT(info()));
00038   connect(media, SIGNAL(stateChanged ( Phonon::State , Phonon::State )), this, SLOT(info()));*/
00039   createPath(media, audioOutput);
00040 /*QTimer *timer = new QTimer(this);
00041      connect(timer, SIGNAL(timeout()), this, SLOT(info()));
00042      timer->start(5000);*/
00043 }
00044 
00045 listenSupport::~listenSupport()
00046 {
00047   delete audioOutput;
00048   delete media;
00049 }
00050 
00051 void listenSupport::setStation(radioStation *newStation)
00052 {
00053   if (newStation != station) {
00054     if (station) {
00055       disconnect(station, 0, this, 0);
00056     };
00057     // change station
00058     station = newStation;
00059     // connect new station
00060     if (station) {
00061       connect(station,
00062               SIGNAL(relayPortChanged(qlonglong, PropertyValue)),
00063               this,
00064               SLOT(setRelayPort(qlonglong, PropertyValue)));
00065       setRelayPort(0, station->relayPort());
00066       connect(station,
00067               SIGNAL(destroyed(QObject *)),
00068               this,
00069               SLOT(setNoStation()));
00070     } else {
00071       setRelayPort(0, PropertyValue());
00072     };
00073   };
00074 };
00075 
00076 void listenSupport::setNoStation()
00077 {
00078   setStation(0);
00079 }
00080 
00081 void listenSupport::setRelayPort(qlonglong, PropertyValue value)
00082 {
00083   if (value.type == PropertyValue::value) {
00084     const qlonglong newPort = value.internalValue.toLongLong();
00085     if (relayPort != newPort) {
00086       relayPort = newPort;
00087       reloadListening();
00088     };
00089   } else {
00090     if (relayPort >= 0) {
00091       relayPort = -1;
00092       reloadListening();
00093     };
00094   };
00095 }
00109 void listenSupport::reloadListening()
00110 {
00111 /*qDebug() << "stopping...";
00112   media->stop();
00113 qDebug() << "... done stopping";*/
00114   if (relayPort >= 0) {
00115 /*qDebug() << "starting" << (QString("http://localhost:%1").arg(relayPort)) << "...";
00116   delete media;
00117   delete audioOutput;
00118   media = new Phonon::MediaObject(this);
00119   audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
00120   createPath(media, audioOutput);
00121 qDebug() << "old source:" << media->currentSource().url();
00122     media->setCurrentSource(QString("http://localhost:%1").arg(relayPort));
00123 qDebug() << "new source:" << media->currentSource().url();
00124 qDebug() << "will play()";
00125     media->play();
00126 qDebug() << "...done starting";*/
00127 
00128 /*    media->stop();
00129 
00130 QTime dieTime = QTime::currentTime().addSecs(2);
00131 while( QTime::currentTime() < dieTime )
00132        QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
00133 */
00134     qDebug() << "status:" << media->state() << "will change source...";  // TODO remove this line
00135     media->setCurrentSource(QString("http://localhost:%1").arg(relayPort));
00136     qDebug() << "status:" << media->state() << "will call play()...";  // TODO remove this line
00137     media->play();
00138   } else {
00139     qDebug() << "will call stop()";
00140     media->stop();
00141   };
00142 }

doxygen