- Added daemon start functionality
[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         virtual ~TorrentSession();
55         
56 public slots:
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         void terminateSession();
64         
65 signals:
66         void alert(qtrapids::TorrentState info, qtrapids::ParamsMap_t other_info);
67         void terminate();
68         void sessionTerminated();
69         
70 private slots:
71         void on_alert();
72
73 private:
74
75         void loadState();
76         void addTorrent_(const QString &, const QString &, const qtrapids::ParamsMap_t &, bool);
77
78         session_t btSession_;
79         AlertWaiterThread *alertWaiter_;
80         torrents_t torrents_;
81         std::auto_ptr<ServerSettings> settings_;
82         std::auto_ptr<ServerDb> db_;
83 };
84
85 } // namespace qtrapids
86
87 #endif // _TEST_HPP_