-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtorrents_daemon.h
87 lines (67 loc) · 2 KB
/
torrents_daemon.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
#ifndef RTORRENT_WORKER
#define RTORRENT_WORKER
#include <vector>
#include <QObject>
#include <QDebug>
#include <QTimerEvent>
#include "rtor/rtorrent.h"
#include "rtor/torrent_list.h"
#include "rtor/torrent_list.cc"
#include "torrent.h"
class torrents_daemon : public QObject {
Q_OBJECT
public:
rtor::client_ptr client;
rtor::torrent_list<torrents_daemon, Torrent> list;
private:
int timer_id;
public:
torrents_daemon(rtor::client_ptr rtor):
client(rtor),
list(client, *this)
{}
public slots:
void fetch_all(){
try {
list.fetch_all();
} catch(std::exception &e){
emit failure(QString("Can't fetch torrent list: %1").arg(e.what()));
}
}
void swap_client(rtor::client_ptr new_client){
list.swap_client(new_client);
}
void move_downloads(std::vector<std::string> hashes, std::string dest, bool start){
client->move_downloads(hashes, dest, start);
}
void start_torrents(std::vector<std::string> hashes){
client->start_torrents(hashes);
}
void stop_torrents(std::vector<std::string> hashes){
client->stop_torrents(hashes);
}
void remove_torrents(std::vector<std::string> hashes){
client->delete_torrents(hashes);
}
void add_torrents(QString dest_path, std::vector<std::string> filenames, bool start){
client->add_files(filenames, dest_path.toStdString(), start);
}
void timerEvent(QTimerEvent *e) override {
Q_ASSERT(e->timerId() == timer_id);
fetch_all();
}
void start(int interval){
timer_id = startTimer(interval);
Q_ASSERT(timer_id != 0);
}
void stop(){
killTimer(timer_id);
}
signals:
// rtor::torrent_list subscriber type
void torrent_changed(int, std::shared_ptr<Torrent> t);
void torrents_inserted(int, std::vector<std::shared_ptr<Torrent> >);
void torrents_removed(int, int);
void failure(const QString &error);
};
#endif // RTORRENT_WORKER