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());
65 QTorrentHandle::State QTorrentHandle::state() const
67 TorrentStatus statusTmp = status();
69 switch (statusTmp.state) {
70 case TorrentStatus::queued_for_checking :
71 return QTorrentHandle::QUEUED_FOR_CHECKING;
72 case TorrentStatus::checking_files :
73 return QTorrentHandle::CHECKING_FILES;
74 case TorrentStatus::downloading_metadata :
75 return QTorrentHandle::DOWNLOADING_METADATA;
76 case TorrentStatus::downloading :
77 return QTorrentHandle::DOWNLOADING;
78 case TorrentStatus::finished :
79 return QTorrentHandle::FINISHED;
80 case TorrentStatus::seeding :
81 return QTorrentHandle::SEEDING;
82 case TorrentStatus::allocating :
83 return QTorrentHandle::ALLOCATING;
85 return QTorrentHandle::UNSPECIFIED;
91 float QTorrentHandle::progress() const
93 TorrentStatus statusTmp = status();
94 return statusTmp.progress;
97 float QTorrentHandle::uploadRate() const
99 TorrentStatus statusTmp = status();
100 return statusTmp.upload_rate;
104 float QTorrentHandle::downloadRate() const
106 TorrentStatus statusTmp = status();
107 return statusTmp.download_rate;
111 qint32 QTorrentHandle::numSeeds() const
113 TorrentStatus statusTmp = status();
114 return statusTmp.list_seeds;
118 qint32 QTorrentHandle::numLeeches() const
120 TorrentStatus statusTmp = status();
121 return (statusTmp.list_peers - statusTmp.list_seeds);
125 qint32 QTorrentHandle::ratio() const
127 TorrentStatus statusTmp = status();
129 if (statusTmp.total_payload_download == 0) {
132 ratio = static_cast<size_t> (statusTmp.total_payload_upload / statusTmp.total_payload_download);
139 TorrentHandle QTorrentHandle::getHandle() const
141 return torrentHandle_;
145 bool QTorrentHandle::operator==(QTorrentHandle const& h) const
147 return torrentHandle_ == h.torrentHandle_;
151 bool QTorrentHandle::operator<(QTorrentHandle const& h) const
153 return torrentHandle_ < h.torrentHandle_;