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 media = new Phonon::MediaObject(this);
00032 audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
00033
00034
00035
00036
00037
00038
00039 createPath(media, audioOutput);
00040
00041
00042
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
00058 station = newStation;
00059
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
00112
00113
00114 if (relayPort >= 0) {
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134 qDebug() << "status:" << media->state() << "will change source...";
00135 media->setCurrentSource(QString("http://localhost:%1").arg(relayPort));
00136 qDebug() << "status:" << media->state() << "will call play()...";
00137 media->play();
00138 } else {
00139 qDebug() << "will call stop()";
00140 media->stop();
00141 };
00142 }