1 /***************************************************************************
2 * Copyright (C) 2010 by Ixonos Plc *
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. *
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. *
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 ***************************************************************************/
19 #include "TorrentHandle.hpp"
26 TorrentHandle::TorrentHandle(libtorrent::torrent_handle handle) :
27 torrentHandle_(handle)
32 TorrentHandle::~TorrentHandle()
37 TorrentStatus_t TorrentHandle::status() const
39 return torrentHandle_.status();
43 torrent_info_cref TorrentHandle::getTorrentInfo() const
45 return torrentHandle_.get_torrent_info();
49 bool TorrentHandle::isValid() const
51 return torrentHandle_.is_valid();
55 QString TorrentHandle::name() const
57 return QString::fromStdString(torrentHandle_.name());
60 size_t TorrentHandle::getTotalSize() const
62 torrent_info_cref info = getTorrentInfo();
63 return static_cast<size_t> (info.total_size());
66 size_t TorrentHandle::getTotalDone() const
68 TorrentStatus_t statusTmp = status();
69 return static_cast<size_t> (statusTmp.total_done);
72 TorrentStatus::Id TorrentHandle::state() const
74 TorrentStatus::Id s = (TorrentStatus::Id)(status().state);
75 return ( (s < TorrentStatus::UNSPECIFIED)
76 ? s : TorrentStatus::UNSPECIFIED );
80 float TorrentHandle::progress() const
82 TorrentStatus_t statusTmp = status();
83 return statusTmp.progress;
86 float TorrentHandle::uploadRate() const
88 TorrentStatus_t statusTmp = status();
89 return statusTmp.upload_rate;
93 float TorrentHandle::downloadRate() const
95 TorrentStatus_t statusTmp = status();
96 return statusTmp.download_rate;
100 qint32 TorrentHandle::numSeeds() const
102 TorrentStatus_t statusTmp = status();
103 return statusTmp.list_seeds;
107 qint32 TorrentHandle::numLeeches() const
109 TorrentStatus_t statusTmp = status();
110 return (statusTmp.list_peers - statusTmp.list_seeds);
114 qint32 TorrentHandle::ratio() const
116 TorrentStatus_t statusTmp = status();
118 if (statusTmp.total_payload_download == 0) {
121 ratio = static_cast<size_t> (statusTmp.total_payload_upload / statusTmp.total_payload_download);
128 torrent_handle_t TorrentHandle::getHandle() const
130 return torrentHandle_;
134 bool TorrentHandle::operator==(TorrentHandle const& h) const
136 return torrentHandle_ == h.torrentHandle_;
140 bool TorrentHandle::operator<(TorrentHandle const& h) const
142 return torrentHandle_ < h.torrentHandle_;