mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-24 21:44:25 +00:00
Merge pull request #4867 from evsh/peers-show-files
Show downloading files in peers list. Attempt #2
This commit is contained in:
commit
8c36f753f9
@ -408,3 +408,8 @@ QString PeerInfo::flagsDescription() const
|
|||||||
{
|
{
|
||||||
return m_flagsDescription;
|
return m_flagsDescription;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int PeerInfo::downloadingPieceIndex() const
|
||||||
|
{
|
||||||
|
return m_nativeInfo.downloading_piece_index;
|
||||||
|
}
|
||||||
|
@ -100,6 +100,7 @@ namespace BitTorrent
|
|||||||
#ifndef DISABLE_COUNTRIES_RESOLUTION
|
#ifndef DISABLE_COUNTRIES_RESOLUTION
|
||||||
QString country() const;
|
QString country() const;
|
||||||
#endif
|
#endif
|
||||||
|
int downloadingPieceIndex() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void calcRelevance(const TorrentHandle *torrent);
|
void calcRelevance(const TorrentHandle *torrent);
|
||||||
|
@ -211,6 +211,20 @@ QByteArray TorrentInfo::metadata() const
|
|||||||
return QByteArray(m_nativeInfo->metadata().get(), m_nativeInfo->metadata_size());
|
return QByteArray(m_nativeInfo->metadata().get(), m_nativeInfo->metadata_size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList TorrentInfo::filesForPiece(int pieceIndex) const
|
||||||
|
{
|
||||||
|
if (pieceIndex < 0)
|
||||||
|
return QStringList();
|
||||||
|
|
||||||
|
std::vector<libtorrent::file_slice> files(
|
||||||
|
nativeInfo()->map_block(pieceIndex, 0, nativeInfo()->piece_size(pieceIndex)));
|
||||||
|
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)
|
void TorrentInfo::renameFile(uint index, const QString &newPath)
|
||||||
{
|
{
|
||||||
if (!isValid()) return;
|
if (!isValid()) return;
|
||||||
|
@ -85,6 +85,7 @@ namespace BitTorrent
|
|||||||
QList<TrackerEntry> trackers() const;
|
QList<TrackerEntry> trackers() const;
|
||||||
QList<QUrl> urlSeeds() const;
|
QList<QUrl> urlSeeds() const;
|
||||||
QByteArray metadata() const;
|
QByteArray metadata() const;
|
||||||
|
QStringList filesForPiece(int pieceIndex) const;
|
||||||
|
|
||||||
void renameFile(uint index, const QString &newPath);
|
void renameFile(uint index, const QString &newPath);
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ class PeerListDelegate: public QItemDelegate {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
enum PeerListColumns {COUNTRY, IP, PORT, CONNECTION, FLAGS, CLIENT, PROGRESS, DOWN_SPEED, UP_SPEED,
|
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:
|
public:
|
||||||
PeerListDelegate(QObject *parent) : QItemDelegate(parent) {}
|
PeerListDelegate(QObject *parent) : QItemDelegate(parent) {}
|
||||||
|
@ -82,6 +82,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_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::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::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
|
// Proxy model to support sorting without actually altering the underlying model
|
||||||
m_proxyModel = new PeerListSortModel();
|
m_proxyModel = new PeerListSortModel();
|
||||||
m_proxyModel->setDynamicSortFilter(true);
|
m_proxyModel->setDynamicSortFilter(true);
|
||||||
@ -346,14 +347,14 @@ void PeerListWidget::loadPeers(BitTorrent::TorrentHandle *const torrent, bool fo
|
|||||||
QString peerIp = addr.ip.toString();
|
QString peerIp = addr.ip.toString();
|
||||||
if (m_peerItems.contains(peerIp)) {
|
if (m_peerItems.contains(peerIp)) {
|
||||||
// Update existing peer
|
// Update existing peer
|
||||||
updatePeer(peerIp, peer);
|
updatePeer(peerIp, torrent, peer);
|
||||||
oldeersSet.remove(peerIp);
|
oldeersSet.remove(peerIp);
|
||||||
if (forceHostnameResolution && m_resolver)
|
if (forceHostnameResolution && m_resolver)
|
||||||
m_resolver->resolve(peerIp);
|
m_resolver->resolve(peerIp);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Add new peer
|
// Add new peer
|
||||||
m_peerItems[peerIp] = addPeer(peerIp, peer);
|
m_peerItems[peerIp] = addPeer(peerIp, torrent, peer);
|
||||||
m_peerAddresses[peerIp] = addr;
|
m_peerAddresses[peerIp] = addr;
|
||||||
// Resolve peer host name is asked
|
// Resolve peer host name is asked
|
||||||
if (m_resolver)
|
if (m_resolver)
|
||||||
@ -371,7 +372,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();
|
int row = m_listModel->rowCount();
|
||||||
// Adding Peer to peer list
|
// Adding Peer to peer list
|
||||||
@ -401,10 +402,14 @@ QStandardItem* PeerListWidget::addPeer(const QString &ip, const BitTorrent::Peer
|
|||||||
m_listModel->setData(m_listModel->index(row, PeerListDelegate::TOT_DOWN), peer.totalDownload());
|
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::TOT_UP), peer.totalUpload());
|
||||||
m_listModel->setData(m_listModel->index(row, PeerListDelegate::RELEVANCE), peer.relevance());
|
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);
|
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);
|
QStandardItem *item = m_peerItems.value(ip);
|
||||||
int row = item->row();
|
int row = item->row();
|
||||||
@ -428,6 +433,9 @@ void PeerListWidget::updatePeer(const QString &ip, const BitTorrent::PeerInfo &p
|
|||||||
m_listModel->setData(m_listModel->index(row, PeerListDelegate::TOT_DOWN), peer.totalDownload());
|
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::TOT_UP), peer.totalUpload());
|
||||||
m_listModel->setData(m_listModel->index(row, PeerListDelegate::RELEVANCE), peer.relevance());
|
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)
|
void PeerListWidget::handleResolved(const QString &ip, const QString &hostname)
|
||||||
|
@ -68,8 +68,8 @@ public:
|
|||||||
~PeerListWidget();
|
~PeerListWidget();
|
||||||
|
|
||||||
void loadPeers(BitTorrent::TorrentHandle *const torrent, bool forceHostnameResolution = false);
|
void loadPeers(BitTorrent::TorrentHandle *const torrent, bool forceHostnameResolution = false);
|
||||||
QStandardItem *addPeer(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, const BitTorrent::PeerInfo &peer);
|
void updatePeer(const QString &ip, BitTorrent::TorrentHandle *const torrent, const BitTorrent::PeerInfo &peer);
|
||||||
void updatePeerHostNameResolutionState();
|
void updatePeerHostNameResolutionState();
|
||||||
void updatePeerCountryResolutionState();
|
void updatePeerCountryResolutionState();
|
||||||
void clear();
|
void clear();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user