Server methods to store/get options
[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
32 typedef libtorrent::add_torrent_params add_torrent_params_t;
33 typedef libtorrent::alert alert_t;
34 //    typedef libtorrent::alert const* alert_cptr;
35 typedef libtorrent::torrent_alert torrent_alert_t;
36 typedef libtorrent::libtorrent_exception torrent_exception_t;
37
38 typedef QSharedPointer<TorrentHandle> TorrentHandlePtr;
39 typedef QHash<QString, TorrentHandlePtr > torrents_t;
40 typedef std::pair<int, int> ports_range_t;
41
42 class ServerDb;
43 class ServerSettings;
44
45 class TorrentSession : public QObject
46 {
47
48         Q_OBJECT;
49         Q_CLASSINFO("D-Bus Interface", "com.ixonos.qtrapids");
50
51 public:
52
53         TorrentSession(QObject *parent, QSettings *);
54
55 public slots:
56
57         void getState();
58         void addTorrent(const QString &path, const QString &save_path
59                         , qtrapids::ParamsMap_t other_params);
60         void removeTorrent(const QString &hash);
61         void setOptions(qtrapids::ParamsMap_t options);
62         qtrapids::ParamsMap_t getOptions();
63
64 signals:
65         void alert(qtrapids::TorrentState info, qtrapids::ParamsMap_t other_info);
66
67 private slots:
68         void on_alert();
69
70 private:
71
72         void loadState();
73         void addTorrent_(const QString &, const QString &, const qtrapids::ParamsMap_t &, bool);
74
75         session_t btSession_;
76         AlertWaiterThread *alertWaiter_;
77         torrents_t torrents_;
78         std::auto_ptr<ServerSettings> settings_;
79         std::auto_ptr<ServerDb> db_;
80 };
81
82 } // namespace qtrapids
83
84 #endif // _TEST_HPP_