-
Notifications
You must be signed in to change notification settings - Fork 0
/
torrent.h
138 lines (118 loc) · 3.16 KB
/
torrent.h
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#ifndef TORRENT_H
#define TORRENT_H
#include <QString>
#include <memory>
#include <QDebug>
#include <xmlrpc-c/base.hpp>
class Torrent {
public:
enum {
HASH,
NAME,
BYTES_DONE,
SIZE_BYTES,
UP_RATE,
UP_TOTAL,
DOWN_RATE,
DOWN_TOTAL,
CREATION_DATE,
TAGS,
ADDTIME,
RATIO,
IS_ACTIVE,
IS_HASH_CHECKING,
IS_OPEN,
COMPLETE,
STATE,
NB_COLUMNS
};
enum State {
Checking,
Downloading,
Stopped,
Seeding
};
const QString hash;
const QString name;
const qint64 bytes_done;
const qint64 size_bytes;
const qint64 upRate;
const qint64 upTotal;
const qint64 downRate;
const qint64 downTotal;
const qint64 creation_date;
const qint64 addtime;
const qint64 ratio;
const bool is_active;
const bool is_hash_checking;
const bool is_open;
const bool complete;
const bool state;
State display_state;
private:
Torrent(const xmlrpc_c::carray &);
public:
static xmlrpc_c::paramList params(){
xmlrpc_c::paramList params;
params.addc("").addc("name").
addc("d.hash=").
addc("d.name=").
addc("d.bytes_done=").
addc("d.size_bytes=").
addc("d.up.rate=").
addc("d.up.total=").
addc("d.down.rate=").
addc("d.down.total=").
addc("d.creation_date=").
addc("d.custom1=").
addc("d.custom=addtime").
addc("d.ratio=").
addc("d.is_active=").
addc("d.is_hash_checking=").
addc("d.is_open=").
addc("d.complete=").
addc("d.state=");
Q_ASSERT(params.size() == NB_COLUMNS+2);
return params;
}
Torrent(const xmlrpc_c::value &v):
Torrent(xmlrpc_c::value_array(v).vectorValueValue())
{}
friend QDebug &operator<<(QDebug &d, const Torrent &t){
d << t.hash << ":" << t.name;
return d;
}
bool hasChanged(const Torrent &o) const {
Q_ASSERT(o.hash == hash);
return o.name != name ||
o.bytes_done != bytes_done ||
size_bytes != o.size_bytes ||
upRate != o.upRate || upTotal != o.upTotal ||
downRate != o.downRate || downTotal != o.downTotal ||
is_active != o.is_active ||
is_hash_checking != o.is_hash_checking ||
is_open != o.is_open ||
complete != o.complete ||
state != o.state;
}
int percent() const {
return (bytes_done/(double) size_bytes) * 100;
}
float calc_ratio() const {
return upTotal/(float)downTotal;
}
float reported_ratio() const {
return ratio/1000.;
}
bool operator<(const Torrent &other) const {
return hash < other.hash;
}
bool operator>(const Torrent &other) const {
return hash > other.hash;
}
bool operator==(const Torrent &other) const {
return hash == other.hash;
}
};
typedef std::vector<std::shared_ptr<Torrent> > Torrents;
#endif // TORRENT_H