From efed388402e15b3c3445b3271816fa8d793cd41e Mon Sep 17 00:00:00 2001 From: Eugene Shalygin Date: Tue, 8 Dec 2015 14:11:58 +0100 Subject: [PATCH 1/3] Revert "Remove unused parameter." This reverts commit 87347cf0e53756f6e1a2e4984e167e4be5bbd06f. --- src/gui/properties/peerlistwidget.cpp | 8 ++++---- src/gui/properties/peerlistwidget.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/gui/properties/peerlistwidget.cpp b/src/gui/properties/peerlistwidget.cpp index 96fefa3b4..14729cb38 100644 --- a/src/gui/properties/peerlistwidget.cpp +++ b/src/gui/properties/peerlistwidget.cpp @@ -282,14 +282,14 @@ void PeerListWidget::loadPeers(BitTorrent::TorrentHandle *const torrent, bool fo QString peerIp = addr.ip.toString(); if (m_peerItems.contains(peerIp)) { // Update existing peer - updatePeer(peerIp, peer); + updatePeer(peerIp, torrent, peer); oldeersSet.remove(peerIp); if (forceHostnameResolution && m_resolver) m_resolver->resolve(peerIp); } else { // Add new peer - m_peerItems[peerIp] = addPeer(peerIp, peer); + m_peerItems[peerIp] = addPeer(peerIp, torrent, peer); m_peerAddresses[peerIp] = addr; // Resolve peer host name is asked if (m_resolver) @@ -307,7 +307,7 @@ void PeerListWidget::loadPeers(BitTorrent::TorrentHandle *const torrent, bool fo } } -QStandardItem* PeerListWidget::addPeer(const QString &ip, const BitTorrent::PeerInfo &peer) +QStandardItem* PeerListWidget::addPeer(const QString& ip, BitTorrent::TorrentHandle *const torrent, const BitTorrent::PeerInfo &peer) { int row = m_listModel->rowCount(); // Adding Peer to peer list @@ -340,7 +340,7 @@ QStandardItem* PeerListWidget::addPeer(const QString &ip, const BitTorrent::Peer return m_listModel->item(row, PeerListDelegate::IP); } -void PeerListWidget::updatePeer(const QString &ip, const BitTorrent::PeerInfo &peer) +void PeerListWidget::updatePeer(const QString &ip, BitTorrent::TorrentHandle *const torrent, const BitTorrent::PeerInfo &peer) { QStandardItem *item = m_peerItems.value(ip); int row = item->row(); diff --git a/src/gui/properties/peerlistwidget.h b/src/gui/properties/peerlistwidget.h index 7ec0669fe..d73037b34 100644 --- a/src/gui/properties/peerlistwidget.h +++ b/src/gui/properties/peerlistwidget.h @@ -68,8 +68,8 @@ public: ~PeerListWidget(); void loadPeers(BitTorrent::TorrentHandle *const torrent, bool forceHostnameResolution = false); - QStandardItem *addPeer(const QString &ip, const BitTorrent::PeerInfo &peer); - void updatePeer(const QString &ip, const BitTorrent::PeerInfo &peer); + QStandardItem *addPeer(const QString &ip, BitTorrent::TorrentHandle *const torrent, const BitTorrent::PeerInfo &peer); + void updatePeer(const QString &ip, BitTorrent::TorrentHandle *const torrent, const BitTorrent::PeerInfo &peer); void updatePeerHostNameResolutionState(); void updatePeerCountryResolutionState(); void clear(); From 0a92cb74a5b4339a8f9079d79a79691e65ae7de8 Mon Sep 17 00:00:00 2001 From: Eugene Shalygin Date: Wed, 21 Oct 2015 17:12:19 +0200 Subject: [PATCH 2/3] functions for retrieving list of currently downloading files --- src/base/bittorrent/peerinfo.cpp | 5 +++++ src/base/bittorrent/peerinfo.h | 1 + src/base/bittorrent/torrentinfo.cpp | 14 ++++++++++++++ src/base/bittorrent/torrentinfo.h | 1 + 4 files changed, 21 insertions(+) diff --git a/src/base/bittorrent/peerinfo.cpp b/src/base/bittorrent/peerinfo.cpp index 857424aee..4ea3f9f10 100644 --- a/src/base/bittorrent/peerinfo.cpp +++ b/src/base/bittorrent/peerinfo.cpp @@ -408,3 +408,8 @@ QString PeerInfo::flagsDescription() const { return m_flagsDescription; } + +int PeerInfo::downloadingPieceIndex() const +{ + return m_nativeInfo.downloading_piece_index; +} diff --git a/src/base/bittorrent/peerinfo.h b/src/base/bittorrent/peerinfo.h index ae63e2d54..0c7a06570 100644 --- a/src/base/bittorrent/peerinfo.h +++ b/src/base/bittorrent/peerinfo.h @@ -100,6 +100,7 @@ namespace BitTorrent #ifndef DISABLE_COUNTRIES_RESOLUTION QString country() const; #endif + int downloadingPieceIndex() const; private: void calcRelevance(const TorrentHandle *torrent); diff --git a/src/base/bittorrent/torrentinfo.cpp b/src/base/bittorrent/torrentinfo.cpp index d7da2f517..3eea6ab03 100644 --- a/src/base/bittorrent/torrentinfo.cpp +++ b/src/base/bittorrent/torrentinfo.cpp @@ -211,6 +211,20 @@ QByteArray TorrentInfo::metadata() const return QByteArray(m_nativeInfo->metadata().get(), m_nativeInfo->metadata_size()); } +QStringList TorrentInfo::filesForPiece(int pieceIndex) const +{ + if (pieceIndex < 0) + return QStringList(); + + std::vector files( + nativeInfo()->map_block(pieceIndex, 0, nativeInfo()->piece_length())); + QStringList res; + for (const libtorrent::file_slice& s: files) { + res.append(filePath(s.file_index)); + } + return res; +} + void TorrentInfo::renameFile(uint index, const QString &newPath) { if (!isValid()) return; diff --git a/src/base/bittorrent/torrentinfo.h b/src/base/bittorrent/torrentinfo.h index 392fa8b46..802e9882d 100644 --- a/src/base/bittorrent/torrentinfo.h +++ b/src/base/bittorrent/torrentinfo.h @@ -75,6 +75,7 @@ namespace BitTorrent QList trackers() const; QList urlSeeds() const; QByteArray metadata() const; + QStringList filesForPiece(int pieceIndex) const; void renameFile(uint index, const QString &newPath); boost::intrusive_ptr nativeInfo() const; From 768b67d2751334c90d553386b312eb8844fde66a Mon Sep 17 00:00:00 2001 From: Eugene Shalygin Date: Fri, 17 Apr 2015 15:00:29 +0200 Subject: [PATCH 3/3] Add column with list of currently downloading files Add a new column to peers list that shows list of files which are downloaded right now from a peer. The column is empty if we do not download anything from the given peer. --- src/gui/properties/peerlistdelegate.h | 2 +- src/gui/properties/peerlistwidget.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/gui/properties/peerlistdelegate.h b/src/gui/properties/peerlistdelegate.h index 1c5be0cb5..864a6f424 100644 --- a/src/gui/properties/peerlistdelegate.h +++ b/src/gui/properties/peerlistdelegate.h @@ -41,7 +41,7 @@ class PeerListDelegate: public QItemDelegate { public: enum PeerListColumns {COUNTRY, IP, PORT, CONNECTION, FLAGS, CLIENT, PROGRESS, DOWN_SPEED, UP_SPEED, - TOT_DOWN, TOT_UP, RELEVANCE, IP_HIDDEN, COL_COUNT}; + TOT_DOWN, TOT_UP, RELEVANCE, DOWNLOADING_PIECE, IP_HIDDEN, COL_COUNT}; public: PeerListDelegate(QObject *parent) : QItemDelegate(parent) {} diff --git a/src/gui/properties/peerlistwidget.cpp b/src/gui/properties/peerlistwidget.cpp index 14729cb38..cf9606cf4 100644 --- a/src/gui/properties/peerlistwidget.cpp +++ b/src/gui/properties/peerlistwidget.cpp @@ -78,6 +78,7 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent) m_listModel->setHeaderData(PeerListDelegate::TOT_DOWN, Qt::Horizontal, tr("Downloaded", "i.e: total data downloaded")); m_listModel->setHeaderData(PeerListDelegate::TOT_UP, Qt::Horizontal, tr("Uploaded", "i.e: total data uploaded")); m_listModel->setHeaderData(PeerListDelegate::RELEVANCE, Qt::Horizontal, tr("Relevance", "i.e: How relevant this peer is to us. How many pieces it has that we don't.")); + m_listModel->setHeaderData(PeerListDelegate::DOWNLOADING_PIECE, Qt::Horizontal, tr("Files", "i.e. files that are being downloaded right now")); // Proxy model to support sorting without actually altering the underlying model m_proxyModel = new PeerListSortModel(); m_proxyModel->setDynamicSortFilter(true); @@ -337,6 +338,10 @@ QStandardItem* PeerListWidget::addPeer(const QString& ip, BitTorrent::TorrentHan m_listModel->setData(m_listModel->index(row, PeerListDelegate::TOT_DOWN), peer.totalDownload()); m_listModel->setData(m_listModel->index(row, PeerListDelegate::TOT_UP), peer.totalUpload()); m_listModel->setData(m_listModel->index(row, PeerListDelegate::RELEVANCE), peer.relevance()); + QStringList downloadingFiles(torrent->info().filesForPiece(peer.downloadingPieceIndex())); + m_listModel->setData(m_listModel->index(row, PeerListDelegate::DOWNLOADING_PIECE), downloadingFiles.join(QLatin1String(";"))); + m_listModel->setData(m_listModel->index(row, PeerListDelegate::DOWNLOADING_PIECE), downloadingFiles.join(QLatin1String("\n")), Qt::ToolTipRole); + return m_listModel->item(row, PeerListDelegate::IP); } @@ -364,6 +369,9 @@ void PeerListWidget::updatePeer(const QString &ip, BitTorrent::TorrentHandle *co m_listModel->setData(m_listModel->index(row, PeerListDelegate::TOT_DOWN), peer.totalDownload()); m_listModel->setData(m_listModel->index(row, PeerListDelegate::TOT_UP), peer.totalUpload()); m_listModel->setData(m_listModel->index(row, PeerListDelegate::RELEVANCE), peer.relevance()); + QStringList downloadingFiles(torrent->info().filesForPiece(peer.downloadingPieceIndex())); + m_listModel->setData(m_listModel->index(row, PeerListDelegate::DOWNLOADING_PIECE), downloadingFiles.join(QLatin1String(";"))); + m_listModel->setData(m_listModel->index(row, PeerListDelegate::DOWNLOADING_PIECE), downloadingFiles.join(QLatin1String("\n")), Qt::ToolTipRole); } void PeerListWidget::handleResolved(const QString &ip, const QString &hostname)