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 ***************************************************************************/
22 #include "QTorrentHandle.h"
24 QTorrentHandle::QTorrentHandle(libtorrent::torrent_handle handle) :
25 torrentHandle_(handle)
30 QTorrentHandle::~QTorrentHandle()
35 TorrentStatus QTorrentHandle::status() const
37 return torrentHandle_.status();
41 TorrentInfo const& QTorrentHandle::getTorrentInfo() const
43 return torrentHandle_.get_torrent_info();
47 bool QTorrentHandle::isValid() const
49 return torrentHandle_.is_valid();
53 QString QTorrentHandle::name() const
55 return QString::fromStdString(torrentHandle_.name());
58 size_t QTorrentHandle::getTotalSize() const
60 TorrentInfo info = getTorrentInfo();
61 return static_cast<size_t> (info.total_size());
64 QString QTorrentHandle::state() const
66 return GetStatusString(status());
69 float QTorrentHandle::progress() const
71 TorrentStatus statusTmp = status();
72 return statusTmp.progress;
75 float QTorrentHandle::uploadRate() const
77 TorrentStatus statusTmp = status();
78 return statusTmp.upload_rate;
82 float QTorrentHandle::downloadRate() const
84 TorrentStatus statusTmp = status();
85 return statusTmp.download_rate;
89 qint32 QTorrentHandle::numSeeds() const
91 TorrentStatus statusTmp = status();
92 return statusTmp.list_seeds;
96 qint32 QTorrentHandle::numLeeches() const
98 TorrentStatus statusTmp = status();
99 return (statusTmp.list_peers - statusTmp.list_seeds);
103 qint32 QTorrentHandle::ratio() const
105 TorrentStatus statusTmp = status();
107 if (statusTmp.total_payload_download == 0) {
110 ratio = static_cast<size_t> (statusTmp.total_payload_upload / statusTmp.total_payload_download);
117 TorrentHandle QTorrentHandle::getHandle() const
119 return torrentHandle_;
123 bool QTorrentHandle::operator==(QTorrentHandle const& h) const
125 return torrentHandle_ == h.torrentHandle_;
129 bool QTorrentHandle::operator<(QTorrentHandle const& h) const
131 return torrentHandle_ < h.torrentHandle_;
136 QString QTorrentHandle::GetStatusString(TorrentStatus const& status) const
138 switch (status.state) {
139 case TorrentStatus::queued_for_checking :
141 case TorrentStatus::checking_files :
143 case TorrentStatus::downloading_metadata :
145 case TorrentStatus::downloading :
147 case TorrentStatus::finished :
149 case TorrentStatus::seeding :
151 case TorrentStatus::allocating :