From ac690c6ef39a1a2cca83c1b9d93ea69a3faefdeb Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Fri, 25 Feb 2011 19:50:26 +0000 Subject: mms plugin refactoring, fixed some regressions git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@2076 90c681e8-e032-0410-971d-27865f9a5e38 --- src/plugins/Input/ffmpeg/decoder_ffmpeg.cpp | 3 + src/plugins/Transports/http/httpinputsource.cpp | 10 +- src/plugins/Transports/http/httpinputsource.h | 3 + src/plugins/Transports/mms/CMakeLists.txt | 10 +- src/plugins/Transports/mms/downloader.cpp | 163 ----------------- src/plugins/Transports/mms/downloader.h | 69 -------- src/plugins/Transports/mms/mms.pro | 12 +- src/plugins/Transports/mms/mmsinputsource.cpp | 13 +- src/plugins/Transports/mms/mmsinputsource.h | 11 +- src/plugins/Transports/mms/mmsstreamreader.cpp | 222 ++++++++++++++++++++++++ src/plugins/Transports/mms/mmsstreamreader.h | 98 +++++++++++ src/plugins/Transports/mms/streamreader.cpp | 91 ---------- src/plugins/Transports/mms/streamreader.h | 71 -------- 13 files changed, 360 insertions(+), 416 deletions(-) delete mode 100644 src/plugins/Transports/mms/downloader.cpp delete mode 100644 src/plugins/Transports/mms/downloader.h create mode 100644 src/plugins/Transports/mms/mmsstreamreader.cpp create mode 100644 src/plugins/Transports/mms/mmsstreamreader.h delete mode 100644 src/plugins/Transports/mms/streamreader.cpp delete mode 100644 src/plugins/Transports/mms/streamreader.h (limited to 'src') diff --git a/src/plugins/Input/ffmpeg/decoder_ffmpeg.cpp b/src/plugins/Input/ffmpeg/decoder_ffmpeg.cpp index cdf772643..0a2e734fa 100644 --- a/src/plugins/Input/ffmpeg/decoder_ffmpeg.cpp +++ b/src/plugins/Input/ffmpeg/decoder_ffmpeg.cpp @@ -107,7 +107,10 @@ bool DecoderFFmpeg::initialize() pd.buf_size = input()->peek((char*)buf, sizeof(buf) - AVPROBE_PADDING_SIZE); pd.buf = buf; if(pd.buf_size < 8192) + { + qWarning("DecoderFFmpeg: too small buffer size: %d bytes", pd.buf_size); return false; + } AVInputFormat *fmt = av_probe_input_format(&pd, 1); if(!fmt) { diff --git a/src/plugins/Transports/http/httpinputsource.cpp b/src/plugins/Transports/http/httpinputsource.cpp index 5ded88078..64e18406c 100644 --- a/src/plugins/Transports/http/httpinputsource.cpp +++ b/src/plugins/Transports/http/httpinputsource.cpp @@ -24,7 +24,7 @@ HTTPInputSource::HTTPInputSource(const QString &url, QObject *parent) : InputSource(url,parent) { m_reader = new HttpStreamReader(url, this); - connect(m_reader, SIGNAL(ready()),SIGNAL(ready())); + connect(m_reader, SIGNAL(ready()),SLOT(activate())); } QIODevice *HTTPInputSource::ioDevice() @@ -43,8 +43,14 @@ bool HTTPInputSource::isReady() return m_reader->isOpen(); } -QString HTTPInputSource::contentType() const +QString HTTPInputSource::contentType() const { return m_reader->contentType(); } +void HTTPInputSource::activate() +{ + m_reader->open(QIODevice::ReadOnly); + emit ready(); +} + diff --git a/src/plugins/Transports/http/httpinputsource.h b/src/plugins/Transports/http/httpinputsource.h index a41c615f1..3b41f3eba 100644 --- a/src/plugins/Transports/http/httpinputsource.h +++ b/src/plugins/Transports/http/httpinputsource.h @@ -39,6 +39,9 @@ public: bool isReady(); QString contentType() const; +private slots: + void activate(); + private: HttpStreamReader *m_reader; diff --git a/src/plugins/Transports/mms/CMakeLists.txt b/src/plugins/Transports/mms/CMakeLists.txt index f4e6314d3..b0682e31c 100644 --- a/src/plugins/Transports/mms/CMakeLists.txt +++ b/src/plugins/Transports/mms/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 2.4.7) if(COMMAND cmake_policy) cmake_policy(SET CMP0003 NEW) cmake_policy(SET CMP0005 NEW) -endif(COMMAND cmake_policy) +endif(COMMAND cmake_policy) # qt plugin ADD_DEFINITIONS( -Wall ) @@ -33,18 +33,16 @@ link_directories(${MMS_LIBRARY_DIRS}) SET(libmms_SRCS - streamreader.cpp - downloader.cpp + mmsstreamreader.cpp mmsinputfactory.cpp mmsinputsource.cpp settingsdialog.cpp ) -SET(libmms_MOC_HDRS - downloader.h +SET(libmms_MOC_HDRS mmsinputfactory.h mmsinputsource.h - streamreader.h + mmsstreamreader.h settingsdialog.h ) diff --git a/src/plugins/Transports/mms/downloader.cpp b/src/plugins/Transports/mms/downloader.cpp deleted file mode 100644 index 9acdcb813..000000000 --- a/src/plugins/Transports/mms/downloader.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Ilya Kotov * - * forkotov02@hotmail.ru * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "downloader.h" - -Downloader::Downloader(QObject *parent, const QString &url) - : QThread(parent) -{ - m_url = url; - m_handle = 0; - m_aborted = false; - QSettings settings(Qmmp::configFile(), QSettings::IniFormat); - m_prebuf_size = settings.value("MMS/buffer_size",128).toInt() * 1024; - m_buffer_size = m_prebuf_size; - m_buffer = (char *)malloc(m_buffer_size); - m_ready = false; - m_buffer_at = 0; -} - - -Downloader::~Downloader() -{ - abort(); - free(m_buffer); - m_buffer = 0; - m_buffer_at = 0; - m_buffer_size = 0; -} - -qint64 Downloader::read(char* data, qint64 maxlen) -{ - m_mutex.lock(); - qint64 len = qMin(m_buffer_at, maxlen); - memmove(data, m_buffer, len); - m_buffer_at -= len; - memmove(m_buffer, m_buffer + len, m_buffer_at); - m_mutex.unlock(); - return len; -} - -QMutex *Downloader::mutex() -{ - return &m_mutex; -} - -void Downloader::abort() -{ - m_mutex.lock(); - if (m_aborted) - { - m_mutex.unlock(); - return; - } - m_aborted = true; - m_ready = false; - m_mutex.unlock(); - wait(); - if (m_handle) - mmsx_close(m_handle); - m_handle = 0; -} - -qint64 Downloader::bytesAvailable() -{ - m_mutex.lock(); - qint64 b = m_buffer_at; - m_mutex.unlock(); - return b; -} - -void Downloader::run() -{ - m_handle = mmsx_connect (0, 0, m_url.toLocal8Bit().constData(), 128 * 1024); - if(!m_handle) - { - qWarning("Downloader: connection failed"); - return; - } - m_mutex.lock(); - if(m_aborted) - { - m_mutex.unlock(); - qDebug("Downloader: aborted"); - return; - } - m_mutex.unlock(); - qint64 len = 0; - forever - { - m_mutex.lock(); - int to_read = 1024; - if(m_buffer_at + to_read > m_buffer_size) - { - m_buffer_size = m_buffer_at + to_read; - m_buffer = (char *)realloc(m_buffer, m_buffer_size); - } - len = mmsx_read (0, m_handle, m_buffer + m_buffer_at, to_read); - if(len < 0) - { - qWarning("Downloader: error: %s", strerror(len)); - m_mutex.unlock(); - break; - } - m_buffer_at += len; - if(!m_ready) - checkBuffer(); - m_mutex.unlock(); - if(m_aborted) - break; - usleep(5000); - } -} - -void Downloader::checkBuffer() -{ - if (m_buffer_at > m_prebuf_size && !m_ready) - { - m_ready = true; - qDebug("Downloader: ready"); - QMap metaData; - metaData.insert(Qmmp::URL, m_url); - StateHandler::instance()->dispatch(metaData); - emit ready(); - } - else if (!m_ready) - { - StateHandler::instance()->dispatchBuffer(100 * m_buffer_at / m_buffer_size); - qApp->processEvents(); - } -} - -bool Downloader::isReady() -{ - return m_ready; -} diff --git a/src/plugins/Transports/mms/downloader.h b/src/plugins/Transports/mms/downloader.h deleted file mode 100644 index bfab9e24b..000000000 --- a/src/plugins/Transports/mms/downloader.h +++ /dev/null @@ -1,69 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Ilya Kotov * - * forkotov02@hotmail.ru * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef DOWNLOADER_H -#define DOWNLOADER_H - -#include -#include -#include -#include -#define this var -#include -#undef this - - - -/*! @internal - * @author Ilya Kotov - */ -class Downloader : public QThread -{ - Q_OBJECT -public: - Downloader(QObject *parent, const QString &url); - - ~Downloader(); - - qint64 read(char* data, qint64 maxlen); - QMutex *mutex(); - void abort(); - qint64 bytesAvailable(); - void checkBuffer(); - bool isReady(); - -signals: - void ready(); - -private: - QMutex m_mutex; - QString m_url; - mmsx_t *m_handle; - bool m_aborted; - qint64 m_buffer_size, m_prebuf_size; - char *m_buffer; - qint64 m_buffer_at; - bool m_ready; - -protected: - void run(); - -}; - -#endif diff --git a/src/plugins/Transports/mms/mms.pro b/src/plugins/Transports/mms/mms.pro index ee93d9bbd..f732df71b 100644 --- a/src/plugins/Transports/mms/mms.pro +++ b/src/plugins/Transports/mms/mms.pro @@ -1,14 +1,14 @@ include(../../plugins.pri) -HEADERS += downloader.h \ - streamreader.h \ +HEADERS += \ mmsinputfactory.h \ mmsinputsource.h \ - settingsdialog.h -SOURCES += downloader.cpp \ - streamreader.cpp \ + settingsdialog.h \ + mmsstreamreader.h +SOURCES += \ mmsinputfactory.cpp \ mmsinputsource.cpp \ - settingsdialog.cpp + settingsdialog.cpp \ + mmsstreamreader.cpp win32:HEADERS += ../../../../src/qmmp/inputsource.h \ ../../../../src/qmmp/inputsourcefactory.h TARGET = $$PLUGINS_PREFIX/Transports/mms diff --git a/src/plugins/Transports/mms/mmsinputsource.cpp b/src/plugins/Transports/mms/mmsinputsource.cpp index 10f9e6983..b734555dc 100644 --- a/src/plugins/Transports/mms/mmsinputsource.cpp +++ b/src/plugins/Transports/mms/mmsinputsource.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2009 by Ilya Kotov * + * Copyright (C) 2009-2011 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -18,13 +18,13 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include "streamreader.h" +#include "mmsstreamreader.h" #include "mmsinputsource.h" MMSInputSource::MMSInputSource(const QString &url, QObject *parent) : InputSource(url,parent) { - m_reader = new StreamReader(url, this); - connect(m_reader, SIGNAL(ready()),SLOT(ready())); + m_reader = new MMSStreamReader(url, this); + connect(m_reader, SIGNAL(ready()),SLOT(activate())); } QIODevice *MMSInputSource::ioDevice() @@ -48,3 +48,8 @@ QString MMSInputSource::contentType() const return "audio/x-ms-wma"; } +void MMSInputSource::activate() +{ + m_reader->open(QIODevice::ReadOnly); + emit ready(); +} diff --git a/src/plugins/Transports/mms/mmsinputsource.h b/src/plugins/Transports/mms/mmsinputsource.h index c4e7bce67..710bb708a 100644 --- a/src/plugins/Transports/mms/mmsinputsource.h +++ b/src/plugins/Transports/mms/mmsinputsource.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2009 by Ilya Kotov * + * Copyright (C) 2009-2011 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -23,7 +23,7 @@ #include -class StreamReader; +class MMSStreamReader; /** @author Ilya Kotov @@ -39,9 +39,12 @@ public: bool isReady(); QString contentType() const; +private slots: + void activate(); + private: - StreamReader *m_reader; + MMSStreamReader *m_reader; }; -#endif // HTTPINPUTSOURCE_H +#endif // MMSINPUTSOURCE_H diff --git a/src/plugins/Transports/mms/mmsstreamreader.cpp b/src/plugins/Transports/mms/mmsstreamreader.cpp new file mode 100644 index 000000000..f48209a51 --- /dev/null +++ b/src/plugins/Transports/mms/mmsstreamreader.cpp @@ -0,0 +1,222 @@ +/*************************************************************************** + * Copyright (C) 2006-2008 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include +#include +#include +#include +#include +#include +#include "mmsstreamreader.h" + +MMSStreamReader::MMSStreamReader(const QString &url, QObject *parent) + : QIODevice(parent) +{ + qDebug("%s", Q_FUNC_INFO); + m_url = url; + m_handle = 0; + m_aborted = false; + QSettings settings(Qmmp::configFile(), QSettings::IniFormat); + m_prebuf_size = settings.value("MMS/buffer_size",128).toInt() * 1024; + m_buffer_size = m_prebuf_size; + m_buffer = (char *)malloc(m_buffer_size); + m_ready = false; + m_buffer_at = 0; + m_thread = new DownloadThread(this); +} + +MMSStreamReader::~MMSStreamReader() +{ + qDebug("%s", Q_FUNC_INFO); + abort(); + free(m_buffer); + m_buffer = 0; + m_buffer_at = 0; + m_buffer_size = 0; +} + +bool MMSStreamReader::atEnd () const +{ + qDebug("%s", Q_FUNC_INFO); + return false; +} + +qint64 MMSStreamReader::bytesToWrite () const +{ + qDebug("%s", Q_FUNC_INFO); + return -1; +} + +void MMSStreamReader::close () +{ + qDebug("%s", Q_FUNC_INFO); + abort(); + QIODevice::close(); +} + +bool MMSStreamReader::isSequential () const +{ + qDebug("%s", Q_FUNC_INFO); + return true; +} + +bool MMSStreamReader::open (OpenMode mode) +{ + qDebug("%s", Q_FUNC_INFO); + if (mode != QIODevice::ReadOnly) + return false; + QIODevice::open(mode); + return m_ready; +} + +bool MMSStreamReader::seek (qint64 pos) +{ + qDebug("%s", Q_FUNC_INFO); + Q_UNUSED(pos); + return false; +} + +qint64 MMSStreamReader::writeData(const char*, qint64) +{ + qDebug("%s", Q_FUNC_INFO); + return -1; +} + +qint64 MMSStreamReader::readData(char* data, qint64 maxlen) +{ + qDebug("%s", Q_FUNC_INFO); + m_mutex.lock(); + qint64 len = qMin(m_buffer_at, maxlen); + memmove(data, m_buffer, len); + m_buffer_at -= len; + memmove(m_buffer, m_buffer + len, m_buffer_at); + m_mutex.unlock(); + qDebug("read=%lld", len); + return len; +} + +void MMSStreamReader::downloadFile() +{ + qDebug("%s", Q_FUNC_INFO); + m_thread->start(); +} + +QMutex *MMSStreamReader::mutex() +{ + return &m_mutex; +} + +void MMSStreamReader::abort() +{ + qDebug("%s", Q_FUNC_INFO); + m_mutex.lock(); + if (m_aborted) + { + m_mutex.unlock(); + return; + } + m_aborted = true; + m_mutex.unlock(); + m_thread->wait(); + m_ready = false; + if (m_handle) + mmsx_close(m_handle); + m_handle = 0; +} + +qint64 MMSStreamReader::bytesAvailable() const +{ + qDebug("+++%lld",QIODevice::bytesAvailable() + m_buffer_at); + return QIODevice::bytesAvailable() + m_buffer_at; +} + +void MMSStreamReader::run() +{ + qDebug("%s", Q_FUNC_INFO); + m_handle = mmsx_connect (0, 0, m_url.toLocal8Bit().constData(), 128 * 1024); + if(!m_handle) + { + qWarning("MMSStreamReader: connection failed"); + return; + } + m_mutex.lock(); + if(m_aborted) + { + m_mutex.unlock(); + qDebug("MMSStreamReader: aborted"); + return; + } + m_mutex.unlock(); + qint64 len = 0; + forever + { + m_mutex.lock(); + int to_read = 1024; + if(m_buffer_at + to_read > m_buffer_size) + { + m_buffer_size = m_buffer_at + to_read; + m_buffer = (char *)realloc(m_buffer, m_buffer_size); + } + len = mmsx_read (0, m_handle, m_buffer + m_buffer_at, to_read); + if(len < 0) + { + qWarning("MMSStreamReader: error: %s", strerror(len)); + m_mutex.unlock(); + break; + } + m_buffer_at += len; + if(!m_ready) + checkBuffer(); + m_mutex.unlock(); + if(m_aborted) + break; + usleep(5000); + } +} + +void MMSStreamReader::checkBuffer() +{ + qDebug("%s", Q_FUNC_INFO); + if (m_buffer_at > m_prebuf_size && !m_ready) + { + m_ready = true; + qDebug("MMSStreamReader: ready"); + QMap metaData; + metaData.insert(Qmmp::URL, m_url); + StateHandler::instance()->dispatch(metaData); + emit ready(); + } + else if (!m_ready) + { + StateHandler::instance()->dispatchBuffer(100 * m_buffer_at / m_buffer_size); + qApp->processEvents(); + } +} + +DownloadThread::DownloadThread(MMSStreamReader *parent) : QThread(parent) +{ + m_parent = parent; +} + +DownloadThread::~DownloadThread (){} + +void DownloadThread::run() +{ + m_parent->run(); +} diff --git a/src/plugins/Transports/mms/mmsstreamreader.h b/src/plugins/Transports/mms/mmsstreamreader.h new file mode 100644 index 000000000..206685937 --- /dev/null +++ b/src/plugins/Transports/mms/mmsstreamreader.h @@ -0,0 +1,98 @@ +/*************************************************************************** + * Copyright (C) 2006-2011 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef MMSSTREAMREADER_H +#define MMSSTREAMREADER_H + +#include +#include +#include +#include +#include +#define this var +#include +#undef this + +class QFileInfo; +class DownloadThread; + +/*! @internal + * @author Ilya Kotov + */ +class MMSStreamReader : public QIODevice +{ + Q_OBJECT +public: + MMSStreamReader(const QString &url, QObject *parent = 0); + + ~MMSStreamReader(); + + /** + * QIODevice API + */ + bool atEnd () const; + qint64 bytesAvailable () const; + qint64 bytesToWrite () const; + void close (); + bool isSequential () const; + bool open (OpenMode mode); + bool seek (qint64 pos); + /** + * helper functions + */ + void downloadFile(); + + + QMutex *mutex(); + void abort(); + void checkBuffer(); + void run(); + +signals: + void ready(); + void error(); + +private: + virtual qint64 readData(char*, qint64); + virtual qint64 writeData(const char*, qint64); + + QMutex m_mutex; + QString m_url; + mmsx_t *m_handle; + bool m_aborted; + qint64 m_buffer_size, m_prebuf_size; + char *m_buffer; + qint64 m_buffer_at; + bool m_ready; + DownloadThread *m_thread; +}; + +class DownloadThread : public QThread +{ + Q_OBJECT +public: + DownloadThread(MMSStreamReader *parent); + virtual ~DownloadThread (); + +private: + virtual void run(); + MMSStreamReader *m_parent; +}; + +#endif diff --git a/src/plugins/Transports/mms/streamreader.cpp b/src/plugins/Transports/mms/streamreader.cpp deleted file mode 100644 index 951238e0e..000000000 --- a/src/plugins/Transports/mms/streamreader.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006-2008 by Ilya Kotov * - * forkotov02@hotmail.ru * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#include -#include -#include "downloader.h" -#include "streamreader.h" - -StreamReader::StreamReader(const QString &name, QObject *parent) - : QIODevice(parent) -{ - m_downloader = new Downloader(this, name); - connect(m_downloader, SIGNAL(ready()), SIGNAL(ready())); -} - -StreamReader::~StreamReader() -{ - m_downloader->abort(); - qDebug("%s", Q_FUNC_INFO); -} - -bool StreamReader::atEnd () const -{ - return false; -} - -qint64 StreamReader::bytesAvailable () const -{ - return m_downloader->bytesAvailable (); -} - -qint64 StreamReader::bytesToWrite () const -{ - return -1; -} - -void StreamReader::close () -{ - m_downloader->abort(); - QIODevice::close(); -} - -bool StreamReader::isSequential () const -{ - return true; -} - -bool StreamReader::open (OpenMode mode) -{ - if (mode != QIODevice::ReadOnly) - return false; - QIODevice::open(mode); - return m_downloader->isReady(); -} - -bool StreamReader::seek (qint64 pos) -{ - Q_UNUSED(pos); - return false; -} - -qint64 StreamReader::readData(char* data, qint64 maxlen) -{ - return m_downloader->read (data, maxlen); -} - -qint64 StreamReader::writeData(const char*, qint64) -{ - return -1; -} - -void StreamReader::downloadFile() -{ - m_downloader->start(); -} diff --git a/src/plugins/Transports/mms/streamreader.h b/src/plugins/Transports/mms/streamreader.h deleted file mode 100644 index a0c18119c..000000000 --- a/src/plugins/Transports/mms/streamreader.h +++ /dev/null @@ -1,71 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006-2008 by Ilya Kotov * - * forkotov02@hotmail.ru * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef STREAMREADER_H -#define STREAMREADER_H - -#include -#include -#include - -class QFileInfo; - -class Downloader; - -/*! @internal - * @author Ilya Kotov - */ -class StreamReader : public QIODevice -{ - Q_OBJECT -public: - StreamReader(const QString &name, QObject *parent = 0); - - ~StreamReader(); - - /** - * QIODevice API - */ - bool atEnd () const; - qint64 bytesAvailable () const; - qint64 bytesToWrite () const; - void close (); - bool isSequential () const; - bool open (OpenMode mode); - bool seek (qint64 pos); - /** - * helper functions - */ - void downloadFile(); - -signals: - void ready(); - void error(); - -protected: - qint64 readData(char*, qint64); - qint64 writeData(const char*, qint64); - -private: - QUrl m_url; - QString m_contentType; - Downloader *m_downloader; -}; - -#endif -- cgit v1.2.3-13-gbd6f