- Implementde server process termination from client UI
[qtrapids] / src / server / TorrentSession.hpp
1 #ifndef _TEST_HPP_
2 #define _TEST_HPP_
3
4 #include "TorrentHandle.hpp"
5 #include "server.h"
6
7 #include <QObject>
8 #include <QString>
9 #include <QSharedPointer>
10 #include <QWeakPointer>
11
12 #include <qtrapids/dbus.hpp>
13
14 #include <libtorrent/session.hpp>
15 #include <libtorrent/torrent_info.hpp>
16 #include <libtorrent/alert_types.hpp>
17 #include <libtorrent/error_code.hpp>
18
19 #include <utility>
20
21 class QSettings;
22
23 namespace qtrapids
24 {
25
26 typedef QWeakPointer<QSettings> settings_weak_ptr;
27
28 class AlertWaiterThread;
29 typedef libtorrent::session session_t;
30 typedef libtorrent::session const* session_cptr;
31 typedef libtorrent::session_settings session_settings_t;
32
33 typedef libtorrent::add_torrent_params add_torrent_params_t;
34 typedef libtorrent::alert alert_t;
35 //    typedef libtorrent::alert const* alert_cptr;
36 typedef libtorrent::torrent_alert torrent_alert_t;
37 typedef libtorrent::libtorrent_exception torrent_exception_t;
38
39 typedef QSharedPointer<TorrentHandle> TorrentHandlePtr;
40 typedef QHash<QString, TorrentHandlePtr > torrents_t;
41 typedef std::pair<int, int> ports_range_t;
42
43 class ServerDb;
44 class ServerSettings;
45
46 class TorrentSession : public QObject
47 {
48
49         Q_OBJECT;
50         Q_CLASSINFO("D-Bus Interface", "com.ixonos.qtrapids");
51
52 public:
53         TorrentSession(QObject *parent, QSettings *);
54
55 public slots:
56         void getState();
57         void addTorrent(const QString &path, const QString &save_path
58                         , qtrapids::ParamsMap_t other_params);
59         void removeTorrent(const QString &hash);
60         void setOptions(qtrapids::ParamsMap_t options);
61         qtrapids::ParamsMap_t getOptions();
62         void terminateSession();
63         
64 signals:
65         void alert(qtrapids::TorrentState info, qtrapids::ParamsMap_t other_info);
66         void terminate();
67         
68 private slots:
69         void on_alert();
70
71 private:
72
73         void loadState();
74         void addTorrent_(const QString &, const QString &, const qtrapids::ParamsMap_t &, bool);
75
76         session_t btSession_;
77         AlertWaiterThread *alertWaiter_;
78         torrents_t torrents_;
79         std::auto_ptr<ServerSettings> settings_;
80         std::auto_ptr<ServerDb> db_;
81 };
82
83 } // namespace qtrapids
84
85 #endif // _TEST_HPP_