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"
28 QTorrentHandle::QTorrentHandle(libtorrent::torrent_handle handle) :
29 torrentHandle_(handle)
34 QTorrentHandle::~QTorrentHandle()
39 TorrentStatus QTorrentHandle::status() const
41 return torrentHandle_.status();
45 TorrentInfo const& QTorrentHandle::getTorrentInfo() const
47 return torrentHandle_.get_torrent_info();
51 bool QTorrentHandle::isValid() const
53 return torrentHandle_.is_valid();
57 QString QTorrentHandle::name() const
59 return QString::fromStdString(torrentHandle_.name());
62 size_t QTorrentHandle::getTotalSize() const
64 TorrentInfo info = getTorrentInfo();
65 return static_cast<size_t> (info.total_size());
69 QTorrentHandle::State QTorrentHandle::state() const
71 TorrentStatus statusTmp = status();
73 switch (statusTmp.state)
75 case TorrentStatus::queued_for_checking :
76 return QTorrentHandle::QUEUED_FOR_CHECKING;
77 case TorrentStatus::checking_files :
78 return QTorrentHandle::CHECKING_FILES;
79 case TorrentStatus::downloading_metadata :
80 return QTorrentHandle::DOWNLOADING_METADATA;
81 case TorrentStatus::downloading :
82 return QTorrentHandle::DOWNLOADING;
83 case TorrentStatus::finished :
84 return QTorrentHandle::FINISHED;
85 case TorrentStatus::seeding :
86 return QTorrentHandle::SEEDING;
87 case TorrentStatus::allocating :
88 return QTorrentHandle::ALLOCATING;
90 return QTorrentHandle::UNSPECIFIED;
96 float QTorrentHandle::progress() const
98 TorrentStatus statusTmp = status();
99 return statusTmp.progress;
102 float QTorrentHandle::uploadRate() const
104 TorrentStatus statusTmp = status();
105 return statusTmp.upload_rate;
109 float QTorrentHandle::downloadRate() const
111 TorrentStatus statusTmp = status();
112 return statusTmp.download_rate;
116 qint32 QTorrentHandle::numSeeds() const
118 TorrentStatus statusTmp = status();
119 return statusTmp.list_seeds;
123 qint32 QTorrentHandle::numLeeches() const
125 TorrentStatus statusTmp = status();
126 return (statusTmp.list_peers - statusTmp.list_seeds);
130 qint32 QTorrentHandle::ratio() const
132 TorrentStatus statusTmp = status();
134 if (statusTmp.total_payload_download == 0)
140 ratio = static_cast<size_t> (statusTmp.total_payload_upload / statusTmp.total_payload_download);
147 TorrentHandle QTorrentHandle::getHandle() const
149 return torrentHandle_;
153 bool QTorrentHandle::operator==(QTorrentHandle const& h) const
155 return torrentHandle_ == h.torrentHandle_;
159 bool QTorrentHandle::operator<(QTorrentHandle const& h) const
161 return torrentHandle_ < h.torrentHandle_;
164 } // namespace qtrapids