X-Git-Url: http://git.maemo.org/git/?p=qtrapids;a=blobdiff_plain;f=src%2Fengine%2FQTorrentHandle.cpp;h=677341e5a6bdc56b8924dc0bd85ef605adb346a8;hp=c69162ceefcee1aafe7a3e3eb8c9a55c9a86abda;hb=HEAD;hpb=45e692ff47151854cc149c514d3a53285f0f195a diff --git a/src/engine/QTorrentHandle.cpp b/src/engine/QTorrentHandle.cpp index c69162c..677341e 100644 --- a/src/engine/QTorrentHandle.cpp +++ b/src/engine/QTorrentHandle.cpp @@ -1,11 +1,9 @@ /*************************************************************************** - * Copyright (C) 2009 by Lassi Väätämöinen * - * lassi.vaatamoinen@ixonos.com * + * Copyright (C) 2010 by Ixonos Plc * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * + * the Free Software Foundation; version 2 of the License. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * @@ -21,7 +19,11 @@ #include "QTorrentHandle.h" -QTorrentHandle::QTorrentHandle(libtorrent::torrent_handle handle) : +namespace qtrapids +{ + + +QTorrentHandle::QTorrentHandle(libtorrent::torrent_handle handle) : torrentHandle_(handle) { } @@ -55,31 +57,39 @@ QString QTorrentHandle::name() const return QString::fromStdString(torrentHandle_.name()); } - - - -bool QTorrentHandle::operator==(QTorrentHandle const& h) -{ - return torrentHandle_ == h.torrentHandle_; -} - - -bool QTorrentHandle::operator<(QTorrentHandle const& h) -{ - return torrentHandle_ < h.torrentHandle_; -} - size_t QTorrentHandle::getTotalSize() const { TorrentInfo info = getTorrentInfo(); return static_cast (info.total_size()); } -QString QTorrentHandle::state() const + +QTorrentHandle::State QTorrentHandle::state() const { - return GetStatusString(status()); + TorrentStatus statusTmp = status(); + + switch (statusTmp.state) { + case TorrentStatus::queued_for_checking : + return QTorrentHandle::QUEUED_FOR_CHECKING; + case TorrentStatus::checking_files : + return QTorrentHandle::CHECKING_FILES; + case TorrentStatus::downloading_metadata : + return QTorrentHandle::DOWNLOADING_METADATA; + case TorrentStatus::downloading : + return QTorrentHandle::DOWNLOADING; + case TorrentStatus::finished : + return QTorrentHandle::FINISHED; + case TorrentStatus::seeding : + return QTorrentHandle::SEEDING; + case TorrentStatus::allocating : + return QTorrentHandle::ALLOCATING; + default: + return QTorrentHandle::UNSPECIFIED; + } + } + float QTorrentHandle::progress() const { TorrentStatus statusTmp = status(); @@ -99,52 +109,52 @@ float QTorrentHandle::downloadRate() const return statusTmp.download_rate; } + qint32 QTorrentHandle::numSeeds() const { TorrentStatus statusTmp = status(); return statusTmp.list_seeds; } + qint32 QTorrentHandle::numLeeches() const { TorrentStatus statusTmp = status(); return (statusTmp.list_peers - statusTmp.list_seeds); } + qint32 QTorrentHandle::ratio() const { TorrentStatus statusTmp = status(); - size_t ratio; + size_t ratio; if (statusTmp.total_payload_download == 0) { ratio = 0; } else { ratio = static_cast (statusTmp.total_payload_upload / statusTmp.total_payload_download); } - + return ratio; } -QString QTorrentHandle::GetStatusString(TorrentStatus const& status) const -{ - switch (status.state) { - case TorrentStatus::queued_for_checking : - return "Queued"; - case TorrentStatus::checking_files : - return "Checking"; - case TorrentStatus::downloading_metadata : - return "DL meta"; - case TorrentStatus::downloading : - return "DL"; - case TorrentStatus::finished : - return "Finished"; - case TorrentStatus::seeding : - return "Seeding"; - case TorrentStatus::allocating : - return "Allocating"; - default: - return "N/A"; - } +TorrentHandle QTorrentHandle::getHandle() const +{ + return torrentHandle_; } - \ No newline at end of file + +bool QTorrentHandle::operator==(QTorrentHandle const& h) const +{ + return torrentHandle_ == h.torrentHandle_; +} + + +bool QTorrentHandle::operator<(QTorrentHandle const& h) const +{ + return torrentHandle_ < h.torrentHandle_; +} + +} // namespace qtrapids + +