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());
61 bool QTorrentHandle::operator==(QTorrentHandle const& h)
63 return torrentHandle_ == h.torrentHandle_;
67 bool QTorrentHandle::operator<(QTorrentHandle const& h)
69 return torrentHandle_ < h.torrentHandle_;
72 size_t QTorrentHandle::getTotalSize() const
74 TorrentInfo info = getTorrentInfo();
75 return static_cast<size_t> (info.total_size());
78 QString QTorrentHandle::state() const
80 return GetStatusString(status());
83 float QTorrentHandle::progress() const
85 TorrentStatus statusTmp = status();
86 return statusTmp.progress;
89 float QTorrentHandle::uploadRate() const
91 TorrentStatus statusTmp = status();
92 return statusTmp.upload_rate;
96 float QTorrentHandle::downloadRate() const
98 TorrentStatus statusTmp = status();
99 return statusTmp.download_rate;
102 qint32 QTorrentHandle::numSeeds() const
104 TorrentStatus statusTmp = status();
105 return statusTmp.list_seeds;
108 qint32 QTorrentHandle::numLeeches() const
110 TorrentStatus statusTmp = status();
111 return (statusTmp.list_peers - statusTmp.list_seeds);
114 qint32 QTorrentHandle::ratio() const
116 TorrentStatus statusTmp = status();
118 if (statusTmp.total_payload_download == 0) {
121 ratio = static_cast<size_t> (statusTmp.total_payload_upload / statusTmp.total_payload_download);
128 QString QTorrentHandle::GetStatusString(TorrentStatus const& status) const
130 switch (status.state) {
131 case TorrentStatus::queued_for_checking :
133 case TorrentStatus::checking_files :
135 case TorrentStatus::downloading_metadata :
137 case TorrentStatus::downloading :
139 case TorrentStatus::finished :
141 case TorrentStatus::seeding :
143 case TorrentStatus::allocating :