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