PageRenderTime 29ms CodeModel.GetById 18ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/src/libtomahawk/utils/qnr_iodevicestream.cpp

http://github.com/tomahawk-player/tomahawk
C++ | 86 lines | 38 code | 12 blank | 36 comment | 4 complexity | da8d1c1d143375be46b8d8da875aa51b MD5 | raw file
 1/*  This file is part of the KDE project
 2    Copyright (C) 2007 Matthias Kretz <kretz@kde.org>
 3
 4    This library is free software; you can redistribute it and/or
 5    modify it under the terms of the GNU Lesser General Public
 6    License as published by the Free Software Foundation; either
 7    version 2.1 of the License, or (at your option) version 3, or any
 8    later version accepted by the membership of KDE e.V. (or its
 9    successor approved by the membership of KDE e.V.), Nokia Corporation
10    (or its successors, if any) and the KDE Free Qt Foundation, which shall
11    act as a proxy defined in Section 6 of version 3 of the license.
12
13    This library is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    Lesser General Public License for more details.
17
18    You should have received a copy of the GNU Lesser General Public
19    License along with this library.  If not, see <http://www.gnu.org/licenses/>.
20
21*/
22
23#include "Qnr_IoDeviceStream.h"
24
25#include <QtNetwork/QNetworkReply>
26
27using namespace Tomahawk;
28
29QNR_IODeviceStream::QNR_IODeviceStream(QIODevice* ioDevice, QObject* parent)
30    : Phonon::AbstractMediaStream( parent ),
31      _ioDevice(ioDevice),
32      _networkReply(0)
33{
34    _ioDevice->reset();
35    if (!_ioDevice->isOpen()) {
36        _ioDevice->open(QIODevice::ReadOnly);
37    }
38
39    Q_ASSERT(ioDevice->isOpen());
40    Q_ASSERT(ioDevice->isReadable());
41//     streamSize = ioDevice->size();
42//     streamSeekable = !ioDevice->isSequential();
43//
44    // Allow handling of QNetworkReplies WRT its isFinished() function..
45    _networkReply = qobject_cast<QNetworkReply *>(_ioDevice);
46}
47
48
49QNR_IODeviceStream::~QNR_IODeviceStream()
50{
51}
52
53void QNR_IODeviceStream::reset()
54{
55    _ioDevice->reset();
56    //resetDone();
57}
58
59void QNR_IODeviceStream::needData()
60{
61    quint32 size = 4096;
62    const QByteArray data = _ioDevice->read(size);
63// #ifdef __GNUC__
64// #warning TODO 4.5 - make sure we do not break anything without this, it is preventing IODs from working when they did not yet emit readyRead()
65// #endif
66//    if (data.isEmpty() && !d->ioDevice->atEnd()) {
67//        error(Phonon::NormalError, d->ioDevice->errorString());
68//    }
69    writeData(data);
70    if (_ioDevice->atEnd()) {
71        // If the IO device was identified as QNetworkReply also take its
72        // isFinished() into account, when triggering EOD.
73        if (!_networkReply || _networkReply->isFinished()) {
74            endOfData();
75        }
76    }
77}
78
79void QNR_IODeviceStream::seekStream(qint64 offset)
80{
81    _ioDevice->seek(offset);
82    //seekStreamDone();
83}
84
85
86// vim: sw=4 sts=4 et tw=100