1 /***************************************************************************
2 * Copyright (C) 2009 by Lassi Väätämöinen *
3 * lassi.vaatamoinen@ixonos.com *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "TorrentHandle.hpp"
28 TorrentHandle::TorrentHandle(libtorrent::torrent_handle handle) :
29 torrentHandle_(handle)
34 TorrentHandle::~TorrentHandle()
39 TorrentStatus_t TorrentHandle::status() const
41 return torrentHandle_.status();
45 torrent_info_cref TorrentHandle::getTorrentInfo() const
47 return torrentHandle_.get_torrent_info();
51 bool TorrentHandle::isValid() const
53 return torrentHandle_.is_valid();
57 QString TorrentHandle::name() const
59 return QString::fromStdString(torrentHandle_.name());
62 size_t TorrentHandle::getTotalSize() const
64 torrent_info_cref info = getTorrentInfo();
65 return static_cast<size_t> (info.total_size());
69 TorrentStatus::Id TorrentHandle::state() const
71 TorrentStatus::Id s = (TorrentStatus::Id)(status().state);
72 return ( (s < TorrentStatus::UNSPECIFIED)
73 ? s : TorrentStatus::UNSPECIFIED );
77 float TorrentHandle::progress() const
79 TorrentStatus_t statusTmp = status();
80 return statusTmp.progress;
83 float TorrentHandle::uploadRate() const
85 TorrentStatus_t statusTmp = status();
86 return statusTmp.upload_rate;
90 float TorrentHandle::downloadRate() const
92 TorrentStatus_t statusTmp = status();
93 return statusTmp.download_rate;
97 qint32 TorrentHandle::numSeeds() const
99 TorrentStatus_t statusTmp = status();
100 return statusTmp.list_seeds;
104 qint32 TorrentHandle::numLeeches() const
106 TorrentStatus_t statusTmp = status();
107 return (statusTmp.list_peers - statusTmp.list_seeds);
111 qint32 TorrentHandle::ratio() const
113 TorrentStatus_t statusTmp = status();
115 if (statusTmp.total_payload_download == 0) {
118 ratio = static_cast<size_t> (statusTmp.total_payload_upload / statusTmp.total_payload_download);
125 torrent_handle_t TorrentHandle::getHandle() const
127 return torrentHandle_;
131 bool TorrentHandle::operator==(TorrentHandle const& h) const
133 return torrentHandle_ == h.torrentHandle_;
137 bool TorrentHandle::operator<(TorrentHandle const& h) const
139 return torrentHandle_ < h.torrentHandle_;