- Torrent can be now opened and download starts
[qtrapids] / src / engine / QTorrentHandle.cpp
index 1be0bf1..c69162c 100644 (file)
@@ -31,9 +31,120 @@ QTorrentHandle::~QTorrentHandle()
 {
 }
 
+
+TorrentStatus QTorrentHandle::status() const
+{
+       return torrentHandle_.status();
+}
+
+
+TorrentInfo const& QTorrentHandle::getTorrentInfo() const
+{
+       return torrentHandle_.get_torrent_info();
+}
+
+
 bool QTorrentHandle::isValid() const
 {
        return torrentHandle_.is_valid();
 }
 
 
+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<size_t> (info.total_size());
+}
+
+QString QTorrentHandle::state() const
+{
+       return GetStatusString(status());
+}
+
+float QTorrentHandle::progress() const
+{
+       TorrentStatus statusTmp = status();
+       return statusTmp.progress;
+}
+
+float QTorrentHandle::uploadRate() const
+{
+       TorrentStatus statusTmp = status();
+       return statusTmp.upload_rate;
+}
+
+
+float QTorrentHandle::downloadRate() const
+{
+       TorrentStatus statusTmp = status();
+       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; 
+       if (statusTmp.total_payload_download == 0) {
+               ratio = 0;
+       } else {
+               ratio = static_cast<size_t> (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";
+       }
+}
+
+                               
\ No newline at end of file