listensupport.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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 setIsPlaying(false);
00032 media = new Phonon::MediaObject(this);
00033 audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
00034 createPath(media, audioOutput);
00035 connect(media, SIGNAL(stateChanged(Phonon::State, Phonon::State )),
00036 this, SLOT(processNewState(Phonon::State)));
00037 }
00038
00039 listenSupport::~listenSupport()
00040 {
00041 delete audioOutput;
00042 delete media;
00043 }
00044
00045 void listenSupport::setStation(radioStation *newStation)
00046 {
00047 if (newStation != station) {
00048 if (station) {
00049 disconnect(station, 0, this, 0);
00050 };
00051
00052 station = newStation;
00053
00054 if (station) {
00055 connect(station,
00056 SIGNAL(relayPortChanged(qlonglong, PropertyValue)),
00057 this,
00058 SLOT(setNoStation()));
00059 setRelayPort(0, station->relayPort());
00060 connect(station,
00061 SIGNAL(destroyed(QObject *)),
00062 this,
00063 SLOT(setNoStation()));
00064 } else {
00065 setRelayPort(0, PropertyValue());
00066 };
00067 };
00068 };
00069
00070 void listenSupport::setNoStation()
00071 {
00072 setStation(0);
00073 }
00074
00075 void listenSupport::setRelayPort(qlonglong, PropertyValue value)
00076 {
00077 if (value.type == PropertyValue::value) {
00078 const qlonglong newPort = value.internalValue.toLongLong();
00079 if (relayPort != newPort) {
00080 relayPort = newPort;
00081 reloadListening();
00082 };
00083 } else {
00084 if (relayPort >= 0) {
00085 relayPort = -1;
00086 reloadListening();
00087 };
00088 };
00089 }
00090
00091 void listenSupport::reloadListening()
00092 {
00093 if (relayPort >= 0) {
00094 media->setCurrentSource(QString("http://localhost:%1").arg(relayPort));
00095 media->play();
00096 } else {
00097 media->stop();
00098 };
00099 }
00100
00101 bool listenSupport::isPlaying() const
00102 {
00103 return internal_isPlaying;
00104 }
00105
00106 void listenSupport::setIsPlaying(bool newValue)
00107 {
00108 if (newValue != internal_isPlaying) {
00109 internal_isPlaying = newValue;
00110 emit isPlayingChanged(newValue);
00111 };
00112 }
00113
00114 void listenSupport::processNewState(Phonon::State newstate)
00115 {
00116 setIsPlaying(newstate == Phonon::LoadingState ||
00117 newstate == Phonon::PlayingState ||
00118 newstate == Phonon::BufferingState);
00119 }