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"
27 QTorrentHandle::QTorrentHandle(libtorrent::torrent_handle handle) :
28 torrentHandle_(handle)
33 QTorrentHandle::~QTorrentHandle()
38 TorrentStatus QTorrentHandle::status() const
40 return torrentHandle_.status();
44 TorrentInfo const& QTorrentHandle::getTorrentInfo() const
46 return torrentHandle_.get_torrent_info();
50 bool QTorrentHandle::isValid() const
52 return torrentHandle_.is_valid();
56 QString QTorrentHandle::name() const
58 return QString::fromStdString(torrentHandle_.name());
61 size_t QTorrentHandle::getTotalSize() const
63 TorrentInfo info = getTorrentInfo();
64 return static_cast<size_t> (info.total_size());
68 QTorrentHandle::State QTorrentHandle::state() const
70 TorrentStatus statusTmp = status();
72 switch (statusTmp.state) {
73 case TorrentStatus::queued_for_checking :
74 return QTorrentHandle::QUEUED_FOR_CHECKING;
75 case TorrentStatus::checking_files :
76 return QTorrentHandle::CHECKING_FILES;
77 case TorrentStatus::downloading_metadata :
78 return QTorrentHandle::DOWNLOADING_METADATA;
79 case TorrentStatus::downloading :
80 return QTorrentHandle::DOWNLOADING;
81 case TorrentStatus::finished :
82 return QTorrentHandle::FINISHED;
83 case TorrentStatus::seeding :
84 return QTorrentHandle::SEEDING;
85 case TorrentStatus::allocating :
86 return QTorrentHandle::ALLOCATING;
88 return QTorrentHandle::UNSPECIFIED;
94 float QTorrentHandle::progress() const
96 TorrentStatus statusTmp = status();
97 return statusTmp.progress;
100 float QTorrentHandle::uploadRate() const
102 TorrentStatus statusTmp = status();
103 return statusTmp.upload_rate;
107 float QTorrentHandle::downloadRate() const
109 TorrentStatus statusTmp = status();
110 return statusTmp.download_rate;
114 qint32 QTorrentHandle::numSeeds() const
116 TorrentStatus statusTmp = status();
117 return statusTmp.list_seeds;
121 qint32 QTorrentHandle::numLeeches() const
123 TorrentStatus statusTmp = status();
124 return (statusTmp.list_peers - statusTmp.list_seeds);
128 qint32 QTorrentHandle::ratio() const
130 TorrentStatus statusTmp = status();
132 if (statusTmp.total_payload_download == 0) {
135 ratio = static_cast<size_t> (statusTmp.total_payload_upload / statusTmp.total_payload_download);
142 TorrentHandle QTorrentHandle::getHandle() const
144 return torrentHandle_;
148 bool QTorrentHandle::operator==(QTorrentHandle const& h) const
150 return torrentHandle_ == h.torrentHandle_;
154 bool QTorrentHandle::operator<(QTorrentHandle const& h) const
156 return torrentHandle_ < h.torrentHandle_;
159 } // namespace qtrapids