diff options
| -rw-r--r-- | lib/downloader.cpp | 31 | ||||
| -rw-r--r-- | lib/downloader.h | 6 | ||||
| -rw-r--r-- | lib/filetag.h | 1 | ||||
| -rw-r--r-- | lib/soundcore.cpp | 14 | ||||
| -rw-r--r-- | lib/soundcore.h | 8 | ||||
| -rw-r--r-- | lib/streamreader.cpp | 76 | ||||
| -rw-r--r-- | lib/streamreader.h | 14 | ||||
| -rw-r--r-- | src/mainwindow.cpp | 8 | ||||
| -rw-r--r-- | src/mainwindow.h | 7 | ||||
| -rw-r--r-- | src/mediafile.cpp | 6 | ||||
| -rw-r--r-- | src/mediafile.h | 1 |
11 files changed, 79 insertions, 93 deletions
diff --git a/lib/downloader.cpp b/lib/downloader.cpp index 56564419c..e025e4f52 100644 --- a/lib/downloader.cpp +++ b/lib/downloader.cpp @@ -19,7 +19,7 @@ ***************************************************************************/ #include <QApplication> - +#include <QStringList> #include "downloader.h" @@ -261,15 +261,18 @@ qint64 Downloader::readBuffer(char* data, qint64 maxlen) return 0; } +const QString &Downloader::title() const +{ + return m_title; +} + void Downloader::readICYMetaData() { uint8_t packet_size; m_metacount = 0; m_mutex.lock(); readBuffer((char *)&packet_size, sizeof(packet_size)); - if (packet_size == 0) - qDebug("zero"); - else + if (packet_size != 0) { int size = packet_size * 16; char packet[size]; @@ -280,9 +283,25 @@ void Downloader::readICYMetaData() m_mutex.lock(); } readBuffer(packet, size); - qDebug(packet); - + qDebug("Downloader: ICY metadata: %s", packet); + parseICYMetaData(packet); } m_mutex.unlock(); } + +void Downloader::parseICYMetaData(char *data) +{ + QString str(data); + QStringList list(str.split(";", QString::SkipEmptyParts)); + foreach(QString line, list) + { + if (line.contains("StreamTitle=")) + { + line = line.right(line.size() - line.indexOf("=") - 1).trimmed(); + m_title = line.remove("'"); + emit titleChanged (); + break; + } + } +} diff --git a/lib/downloader.h b/lib/downloader.h index 308fca83a..13be0121e 100644 --- a/lib/downloader.h +++ b/lib/downloader.h @@ -56,15 +56,21 @@ public: QString contentType(); void abort(); int bytesAvailable(); + const QString& title() const; + +signals: + void titleChanged (); private: qint64 readBuffer(char* data, qint64 maxlen); void readICYMetaData(); + void parseICYMetaData(char *data); CURL *m_handle; QMutex m_mutex; Stream m_stream; QString m_url; int m_metacount; + QString m_title; protected: void run(); diff --git a/lib/filetag.h b/lib/filetag.h index c2d36a842..f75facfa0 100644 --- a/lib/filetag.h +++ b/lib/filetag.h @@ -62,7 +62,6 @@ public: private: QMap <uint, QString> m_strValues; QMap <uint, uint> m_numValues; - }; #endif diff --git a/lib/soundcore.cpp b/lib/soundcore.cpp index afa03d61f..8c59d015b 100644 --- a/lib/soundcore.cpp +++ b/lib/soundcore.cpp @@ -54,11 +54,11 @@ SoundCore::SoundCore(QObject *parent) QList<OutputFactory*> *outputFactories = Output::outputFactories(); foreach(OutputFactory* of, *outputFactories) - qApp->installTranslator(of->createTranslator(this)); + qApp->installTranslator(of->createTranslator(this)); QList<DecoderFactory*> *decoderFactories = Decoder::decoderFactories(); foreach(DecoderFactory* df, *decoderFactories) - qApp->installTranslator(df->createTranslator(this)); + qApp->installTranslator(df->createTranslator(this)); } @@ -73,9 +73,11 @@ bool SoundCore::play(const QString &source) m_error = DecoderError; return FALSE; } - if(source.left(4) == "http") + if (source.left(4) == "http") { m_input = new StreamReader(source, this); + connect(m_input, SIGNAL(titleChanged(const QString&)), + SIGNAL(titleChanged(const QString&))); } else m_input = new QFile(source); @@ -97,7 +99,7 @@ bool SoundCore::play(const QString &source) m_error = DecoderError; - if(m_vis) + if (m_vis) { m_vis->setOutput(m_output); m_output->addVisual(m_vis); @@ -146,7 +148,7 @@ uint SoundCore::error() void SoundCore::stop() { - if(m_block) + if (m_block) return; m_paused = FALSE; if (m_decoder && m_decoder->isRunning()) @@ -188,7 +190,7 @@ void SoundCore::stop() { m_output->uninitialize(); } - + //display->setTime(0); if (m_decoder) { diff --git a/lib/soundcore.h b/lib/soundcore.h index 7e9d7369f..7e88942f7 100644 --- a/lib/soundcore.h +++ b/lib/soundcore.h @@ -150,6 +150,14 @@ signals: */ void outputStateChanged(const OutputState& state); + /*! + * This signal is emited when the title of the stream changes. + * The argument \b title is the new title of the stream. + * Signal emits with the shoutcast server stream only. + * For another servers use decoderStateChanged() + */ + void titleChanged(const QString& title); + private: Decoder* m_decoder; Output* m_output; diff --git a/lib/streamreader.cpp b/lib/streamreader.cpp index e1af3201f..914846335 100644 --- a/lib/streamreader.cpp +++ b/lib/streamreader.cpp @@ -27,11 +27,13 @@ StreamReader::StreamReader(const QString &name, QObject *parent) : QIODevice(parent) { m_downloader = new Downloader(this, name); + connect(m_downloader, SIGNAL(titleChanged()),SLOT(updateTitle())); } StreamReader::~StreamReader() { m_downloader->abort(); + qDebug("StreamReader::~StreamReader()"); } bool StreamReader::atEnd () const @@ -56,8 +58,6 @@ bool StreamReader::canReadLine () const void StreamReader::close () { - //m_httpRequestAborted = TRUE; - //m_http->close(); m_downloader->abort(); } @@ -71,17 +71,13 @@ bool StreamReader::open ( OpenMode mode ) if (mode != QIODevice::ReadOnly) return FALSE; downloadFile(); - //if (m_httpRequestAborted) - //return TRUE; setOpenMode(QIODevice::ReadOnly); - return TRUE; + if (m_downloader->isRunning()) + return TRUE; + else + return FALSE; } -/*qint64 StreamReader::pos () const -{ - return m_pos; -}*/ - bool StreamReader::reset () { QIODevice::reset(); @@ -123,73 +119,19 @@ qint64 StreamReader::writeData(const char*, qint64) void StreamReader::downloadFile() { - m_httpRequestAborted = FALSE; - //qDebug("StreamReader: connecting..."); - //m_httpGetId = m_http->get(m_url.path(), 0); qDebug("StreamReader: buffering..."); - /*while (m_http->bytesAvailable () < BUFFER_SIZE*0.5 && !m_httpRequestAborted) - { - qApp->processEvents(); - }*/ m_downloader->start(); - while (m_downloader->bytesAvailable () < BUFFER_SIZE*0.5 && - m_downloader->isRunning()) + while (m_downloader->bytesAvailable () < BUFFER_SIZE*0.5 && m_downloader->isRunning ()) { qApp->processEvents(); - //qDebug("StreamReader: bytes: %d",m_downloader->bytesAvailable ()); //sleep(1); } qDebug("StreamReader: ready"); } -void StreamReader::cancelDownload() +void StreamReader::updateTitle() { - m_httpRequestAborted = true; - //&& !m_httpRequestAborted->abort(); -} - -void StreamReader::httpRequestFinished(int requestId, bool error) -{ - if (m_httpRequestAborted) - { - return; - } - - if (requestId != m_httpGetId) - return; - - if (error) - { - //qDebug(qPrintable(QString("StreamReader: %1").arg(m_http->errorString()))); - m_httpRequestAborted = TRUE; - } - else - { - qDebug("StreamReader: end of file"); - } - -} - -void StreamReader::updateDataReadProgress(int bytesRead, int totalBytes) -{ - m_pos = bytesRead; - m_size = totalBytes; - fillBuffer(); -} - -void StreamReader::fillBuffer() -{ - /*if (m_http->bytesAvailable () > BUFFER_SIZE && !m_httpRequestAborted) - { - while (m_http->bytesAvailable () > BUFFER_SIZE*0.75 && !m_httpRequestAborted) - { - qDebug("StreamReader: skipping data..."); - char *data = new char[BUFFER_SIZE/20]; - m_http->read (data, BUFFER_SIZE/20); - qApp->processEvents(); - delete data; - } - }*/ + emit titleChanged(m_downloader->title()); } const QString &StreamReader::contentType() diff --git a/lib/streamreader.h b/lib/streamreader.h index 9b0af5df7..906ddd2ac 100644 --- a/lib/streamreader.h +++ b/lib/streamreader.h @@ -23,6 +23,7 @@ #include <QObject> #include <QIODevice> #include <QUrl> + #define BUFFER_SIZE 524288 class QFileInfo; @@ -62,24 +63,21 @@ public: */ const QString &contentType(); +signals: + void titleChanged(const QString&); + protected: qint64 readData(char*, qint64); qint64 writeData(const char*, qint64); private slots: - void downloadFile(); - void cancelDownload(); - void httpRequestFinished(int, bool); - void updateDataReadProgress(int bytesRead, int totalBytes); + void updateTitle(); private: + void downloadFile(); void fillBuffer(); QUrl m_url; - bool m_httpRequestAborted; - int m_httpGetId; - int m_pos; - int m_size; QString m_contentType; Downloader *m_downloader; }; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 2d13f7000..36d672175 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -131,6 +131,8 @@ MainWindow::MainWindow(const QStringList& args, QWidget *parent) SLOT(showOutputState(const OutputState&))); connect(m_core, SIGNAL(decoderStateChanged(const DecoderState&)), SLOT(showDecoderState(const DecoderState&))); + connect(m_core, SIGNAL(titleChanged(const QString&)), + SLOT(changeTitle(const QString&))); connect ( m_skin, SIGNAL ( skinChanged() ), this, SLOT ( updateSkin() ) ); updateEQ(); @@ -369,6 +371,12 @@ void MainWindow::showDecoderState(const DecoderState &st) } } +void MainWindow::changeTitle(const QString &title) +{ + m_playlist->currentItem()->changeTitle(title); + m_playlist->listWidget()->updateList(); +} + void MainWindow::closeEvent ( QCloseEvent *) { writeSettings(); diff --git a/src/mainwindow.h b/src/mainwindow.h index 54b98f6e3..0647f09a6 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -88,6 +88,7 @@ protected: private slots: void showOutputState(const OutputState&); void showDecoderState(const DecoderState&); + void changeTitle(const QString&); void clear(); void startSeek(); void endSeek(); @@ -98,17 +99,13 @@ private slots: void updateEQ(); void updatePreset(); void updateSkin(); - void forward(); void backward(); - void jumpToFile(); - void toggleVisibility(); void trayActivated(QSystemTrayIcon::ActivationReason); void about(); - - void handleCloseRequest(); + void handleCloseRequest(); private: void readSettings(); diff --git a/src/mediafile.cpp b/src/mediafile.cpp index 8d309dffb..9f2908685 100644 --- a/src/mediafile.cpp +++ b/src/mediafile.cpp @@ -130,3 +130,9 @@ void MediaFile::readMetadata() else m_title = m_path.startsWith("http://") ? m_path: m_path.section('/',-1); } + +void MediaFile::changeTitle(const QString &newtitle) +{ + m_title = newtitle; +} + diff --git a/src/mediafile.h b/src/mediafile.h index 3e6fb9f43..78fbd620f 100644 --- a/src/mediafile.h +++ b/src/mediafile.h @@ -48,6 +48,7 @@ public: bool isCurrent(); void setCurrent(bool); void updateTags(const FileTag*); + void changeTitle(const QString&); private: |
