- License texts modified to GPLv2
[qtrapids] / src / server / TorrentHandle.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 QTORRENTHANDLE_H
19 #define QTORRENTHANDLE_H
20
21 #include <QtGlobal>
22 #include <QString>
23
24 #include <qtrapids/info.hpp>
25 #include <libtorrent/torrent_handle.hpp>
26
27 namespace qtrapids
28 {
29
30 typedef libtorrent::torrent_info const& torrent_info_cref;
31 typedef libtorrent::torrent_handle torrent_handle_t;
32 typedef libtorrent::sha1_hash Sha1Hash;
33
34
35 inline QString Hash2QStr(Sha1Hash const& hash)
36 {
37         return QString(hash.to_string().c_str());
38 }
39
40 /**
41    @author Lassi Väätämöinen <lassi.vaatamoinen@ixonos.com>
42 */
43 class TorrentHandle
44 {
45 public:
46
47         TorrentHandle(libtorrent::torrent_handle handle);
48         ~TorrentHandle();
49
50
51
52         torrent_info_cref getTorrentInfo() const;
53
54         bool isValid() const;
55
56         Sha1Hash hash() const {
57                 return torrentHandle_.info_hash();
58         }
59
60         QString name() const;
61         size_t getTotalSize() const;
62         size_t getTotalDone() const;
63         TorrentStatus::Id state() const;
64         float progress() const;
65         float uploadRate() const;
66         float downloadRate() const;
67         qint32 numSeeds() const;
68         qint32 numLeeches() const;
69         qint32 ratio() const;
70
71         torrent_handle_t getHandle() const;
72         bool operator==(TorrentHandle const& h) const;
73         bool operator<(TorrentHandle const& h) const;
74
75 private:
76         TorrentHandle(); // Prevent default construct.
77         torrent_handle_t torrentHandle_;
78
79         TorrentStatus_t status() const;
80
81 };
82
83 }
84
85 #endif