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 ***************************************************************************/
20 #include "QTorrentHandle.h"
26 QTorrentHandle::QTorrentHandle(libtorrent::torrent_handle handle) :
27 torrentHandle_(handle)
32 QTorrentHandle::~QTorrentHandle()
37 TorrentStatus QTorrentHandle::status() const
39 return torrentHandle_.status();
43 TorrentInfo const& QTorrentHandle::getTorrentInfo() const
45 return torrentHandle_.get_torrent_info();
49 bool QTorrentHandle::isValid() const
51 return torrentHandle_.is_valid();
55 QString QTorrentHandle::name() const
57 return QString::fromStdString(torrentHandle_.name());
60 size_t QTorrentHandle::getTotalSize() const
62 TorrentInfo info = getTorrentInfo();
63 return static_cast<size_t> (info.total_size());
67 QTorrentHandle::State QTorrentHandle::state() const
69 TorrentStatus statusTmp = status();
71 switch (statusTmp.state) {
72 case TorrentStatus::queued_for_checking :
73 return QTorrentHandle::QUEUED_FOR_CHECKING;
74 case TorrentStatus::checking_files :
75 return QTorrentHandle::CHECKING_FILES;
76 case TorrentStatus::downloading_metadata :
77 return QTorrentHandle::DOWNLOADING_METADATA;
78 case TorrentStatus::downloading :
79 return QTorrentHandle::DOWNLOADING;
80 case TorrentStatus::finished :
81 return QTorrentHandle::FINISHED;
82 case TorrentStatus::seeding :
83 return QTorrentHandle::SEEDING;
84 case TorrentStatus::allocating :
85 return QTorrentHandle::ALLOCATING;
87 return QTorrentHandle::UNSPECIFIED;
93 float QTorrentHandle::progress() const
95 TorrentStatus statusTmp = status();
96 return statusTmp.progress;
99 float QTorrentHandle::uploadRate() const
101 TorrentStatus statusTmp = status();
102 return statusTmp.upload_rate;
106 float QTorrentHandle::downloadRate() const
108 TorrentStatus statusTmp = status();
109 return statusTmp.download_rate;
113 qint32 QTorrentHandle::numSeeds() const
115 TorrentStatus statusTmp = status();
116 return statusTmp.list_seeds;
120 qint32 QTorrentHandle::numLeeches() const
122 TorrentStatus statusTmp = status();
123 return (statusTmp.list_peers - statusTmp.list_seeds);
127 qint32 QTorrentHandle::ratio() const
129 TorrentStatus statusTmp = status();
131 if (statusTmp.total_payload_download == 0) {
134 ratio = static_cast<size_t> (statusTmp.total_payload_upload / statusTmp.total_payload_download);
141 TorrentHandle QTorrentHandle::getHandle() const
143 return torrentHandle_;
147 bool QTorrentHandle::operator==(QTorrentHandle const& h) const
149 return torrentHandle_ == h.torrentHandle_;
153 bool QTorrentHandle::operator<(QTorrentHandle const& h) const
155 return torrentHandle_ < h.torrentHandle_;
158 } // namespace qtrapids