Added build script of Debian
[qtrapids] / src / server / TorrentSession.hpp
1 /***************************************************************************
2  *   Copyright (C) 2010 by Ixonos Plc   *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; version 2 of the License.               *
7  *                                                                         *
8  *   This program is distributed in the hope that it will be useful,       *
9  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
10  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
11  *   GNU General Public License for more details.                          *
12  *                                                                         *
13  *   You should have received a copy of the GNU General Public License     *
14  *   along with this program; if not, write to the                         *
15  *   Free Software Foundation, Inc.,                                       *
16  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
17  ***************************************************************************/
18 #ifndef _TEST_HPP_
19 #define _TEST_HPP_
20
21 #include "TorrentHandle.hpp"
22 #include "server.h"
23
24 #include <QObject>
25 #include <QString>
26 #include <QSharedPointer>
27 #include <QWeakPointer>
28
29 #include <qtrapids/dbus.hpp>
30
31 #include <libtorrent/session.hpp>
32 #include <libtorrent/torrent_info.hpp>
33 #include <libtorrent/alert_types.hpp>
34 #include <libtorrent/error_code.hpp>
35
36 #include <utility>
37
38 class QSettings;
39
40 namespace qtrapids
41 {
42
43 typedef QWeakPointer<QSettings> settings_weak_ptr;
44
45 class AlertWaiterThread;
46 typedef libtorrent::session session_t;
47 typedef libtorrent::session const* session_cptr;
48 typedef libtorrent::session_settings session_settings_t;
49
50 typedef libtorrent::add_torrent_params add_torrent_params_t;
51 typedef libtorrent::alert alert_t;
52 //    typedef libtorrent::alert const* alert_cptr;
53 typedef libtorrent::torrent_alert torrent_alert_t;
54 typedef libtorrent::libtorrent_exception torrent_exception_t;
55
56 typedef QSharedPointer<TorrentHandle> TorrentHandlePtr;
57 typedef QHash<QString, TorrentHandlePtr > torrents_t;
58 typedef std::pair<int, int> ports_range_t;
59
60 class ServerDb;
61 class ServerSettings;
62
63 class TorrentSession : public QObject
64 {
65
66         Q_OBJECT;
67         Q_CLASSINFO("D-Bus Interface", "com.ixonos.qtrapids");
68
69 public:
70         TorrentSession(QObject *parent, QSettings *);
71         virtual ~TorrentSession();
72         
73 public slots:
74         void getState();
75         void addTorrent(const QString &path, const QString &save_path
76                         , qtrapids::ParamsMap_t other_params);
77         void removeTorrent(const QString &hash);
78         void setOptions(qtrapids::ParamsMap_t options);
79         qtrapids::ParamsMap_t getOptions();
80         void terminateSession();
81         
82 signals:
83         void alert(qtrapids::TorrentState info, qtrapids::ParamsMap_t other_info);
84         void terminate();
85         void sessionTerminated();
86         
87 private slots:
88         void on_alert();
89
90 private:
91
92         void loadState();
93         void addTorrent_(const QString &, const QString &, const qtrapids::ParamsMap_t &, bool);
94
95         session_t btSession_;
96         AlertWaiterThread *alertWaiter_;
97         torrents_t torrents_;
98         std::auto_ptr<ServerSettings> settings_;
99         std::auto_ptr<ServerDb> db_;
100 };
101
102 } // namespace qtrapids
103
104 #endif // _TEST_HPP_