libktorrent  2.2.0
torrentfilestream.h
1 /***************************************************************************
2  * Copyright (C) 2010 by Joris Guisson *
3  * joris.guisson@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19  ***************************************************************************/
20 
21 #ifndef BT_TORRENTFILESTREAM_H
22 #define BT_TORRENTFILESTREAM_H
23 
24 #include <QIODevice>
25 #include <QWeakPointer>
26 #include <QSharedPointer>
27 #include <ktorrent_export.h>
28 #include <util/constants.h>
29 
30 
31 namespace bt
32 {
33  class ChunkManager;
34  class TorrentControl;
35  class TorrentInterface;
36  class BitSet;
37 
38 
43  class KTORRENT_EXPORT TorrentFileStream : public QIODevice
44  {
45  Q_OBJECT
46  public:
47  TorrentFileStream(TorrentControl* tc,ChunkManager* cman,bool streaming_mode,QObject* parent);
48  TorrentFileStream(TorrentControl* tc,Uint32 file_index,ChunkManager* cman,bool streaming_mode,QObject* parent);
49  ~TorrentFileStream() override;
50 
52  bool open(QIODevice::OpenMode mode) override;
53 
55  void close() override;
56 
58  qint64 pos() const override;
59 
61  qint64 size() const override;
62 
64  bool seek(qint64 pos) override;
65 
67  bool atEnd() const override;
68 
70  bool reset() override;
71 
73  qint64 bytesAvailable() const override;
74 
76  bool isSequential() const override {return false;}
77 
79  QString path() const;
80 
82  const BitSet & chunksBitSet() const;
83 
85  Uint32 currentChunk() const;
86 
87  typedef QSharedPointer<TorrentFileStream> Ptr;
88  typedef QWeakPointer<TorrentFileStream> WPtr;
89 
90  protected:
91  qint64 writeData(const char* data, qint64 len) override;
92  qint64 readData(char* data, qint64 maxlen) override;
93  void emitReadChannelFinished();
94 
95  private Q_SLOTS:
96  void chunkDownloaded(bt::TorrentInterface* tc, bt::Uint32 chunk);
97 
98  private:
99  class Private;
100  Private* d;
101  };
102 
103 }
104 
105 #endif // BT_TORRENTFILESTREAM_H
bt::BitSet
Simple implementation of a BitSet.
Definition: bitset.h:37
bt::TorrentFileStream::open
bool open(QIODevice::OpenMode mode) override
Open the device (only readonly access will be allowed)
bt::TorrentFileStream::atEnd
bool atEnd() const override
Are we at the end of the file.
bt::TorrentFileStream::bytesAvailable
qint64 bytesAvailable() const override
How many bytes are there available.
bt::TorrentFileStream::currentChunk
Uint32 currentChunk() const
Get the current chunk relative to the first chunk of the file.
bt::ChunkManager
Definition: chunkmanager.h:61
bt::TorrentFileStream::close
void close() override
Close the device.
bt::TorrentFileStream::path
QString path() const
Get the path of the file.
bt::TorrentFileStream
Definition: torrentfilestream.h:44
bt::TorrentFileStream::chunksBitSet
const BitSet & chunksBitSet() const
Get a BitSet of all the chunks of this TorrentFileStream.
bt::TorrentFileStream::seek
bool seek(qint64 pos) override
Seek, will fail if attempting to seek to a point which is not downloaded yet.
bt::TorrentControl
Controls just about everything.
Definition: torrentcontrol.h:69
bt::TorrentFileStream::reset
bool reset() override
Reset the stream.
bt::TorrentFileStream::size
qint64 size() const override
Get the total size.
bt::TorrentFileStream::isSequential
bool isSequential() const override
The stream is not sequential.
Definition: torrentfilestream.h:76
bt::TorrentFileStream::pos
qint64 pos() const override
Get the current stream position.
bt::TorrentInterface
Interface for an object which controls one torrent.
Definition: torrentinterface.h:90