-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtorrentstream.h
More file actions
77 lines (67 loc) · 1.65 KB
/
torrentstream.h
File metadata and controls
77 lines (67 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifndef TORRENTSTREAM_H
#define TORRENTSTREAM_H
#include <libtorrent/torrent_handle.hpp>
#include <QObject>
#include <QTimer>
class TorrentStream : public QObject
{
Q_OBJECT
public:
enum state {
STATE_IDLE,
STATE_ADDING_TORRENT,
STATE_RETRIEVING_METADATA,
STATE_BUFFERING,
STATE_READY
};
enum errorCode {
ERR_READING_TORRENT_FILE,
ERR_ADDING_TORRENT,
ERR_TORRENT_NOT_VIDEO,
ERR_TIMEOUT,
ERR_DOWNLOAD,
ERR_UNKNOWN
};
struct Error {
errorCode errorType;
QString errorString;
};
struct Stats {
QString name;
qint64 bytes_done;
float progress;
float dSpeed;
};
explicit TorrentStream(QString savePath, int incomingPort, QObject *parent = 0);
~TorrentStream();
void start(QString t);
Stats getStats();
state getStatus();
Error getError();
QString getFilePath();
quint64 getFileOffset();
bool hasPiece(int i);
bool hasBytes(quint64 from, quint64 to);
void prioritizeBytes(quint64 from, quint64 len);
quint64 getPieceLength();
quint64 getFileSize();
private:
void setState(state s);
void setError(errorCode e, QString s);
libtorrent::session *s;
libtorrent::torrent_handle h;
QTimer timerUpdate;
state status;
Error error;
libtorrent::file_entry targetFile;
boost::intrusive_ptr<libtorrent::torrent_info const> torrentInfo;
QString savePath;
int incomingPort;
signals:
void statusChange(TorrentStream::state s);
void errored(Error e);
public slots:
private slots:
void update();
};
#endif // TORRENTSTREAM_H