mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-25 22:14:32 +00:00
Implement peer relevance column. Closes #1630.
This commit is contained in:
parent
dc04ff511f
commit
35e964f66d
@ -40,7 +40,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, IP_HIDDEN, COL_COUNT};
|
TOT_DOWN, TOT_UP, RELEVANCE, IP_HIDDEN, COL_COUNT};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PeerListDelegate(QObject *parent) : QItemDelegate(parent) {}
|
PeerListDelegate(QObject *parent) : QItemDelegate(parent) {}
|
||||||
@ -64,7 +64,8 @@ public:
|
|||||||
QItemDelegate::drawDisplay(painter, opt, opt.rect, misc::friendlyUnit(speed)+tr("/s", "/second (i.e. per second)"));
|
QItemDelegate::drawDisplay(painter, opt, opt.rect, misc::friendlyUnit(speed)+tr("/s", "/second (i.e. per second)"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PROGRESS:{
|
case PROGRESS:
|
||||||
|
case RELEVANCE:{
|
||||||
QItemDelegate::drawBackground(painter, opt, index);
|
QItemDelegate::drawBackground(painter, opt, index);
|
||||||
qreal progress = index.data().toDouble();
|
qreal progress = index.data().toDouble();
|
||||||
QItemDelegate::drawDisplay(painter, opt, opt.rect, misc::accurateDoubleToString(progress*100.0, 1)+"%");
|
QItemDelegate::drawDisplay(painter, opt, opt.rect, misc::accurateDoubleToString(progress*100.0, 1)+"%");
|
||||||
|
@ -71,6 +71,7 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent):
|
|||||||
m_listModel->setHeaderData(PeerListDelegate::UP_SPEED, Qt::Horizontal, tr("Up Speed", "i.e: Upload speed"));
|
m_listModel->setHeaderData(PeerListDelegate::UP_SPEED, Qt::Horizontal, tr("Up Speed", "i.e: Upload speed"));
|
||||||
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."));
|
||||||
// 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);
|
||||||
@ -327,6 +328,7 @@ void PeerListWidget::loadPeers(const QTorrentHandle &h, bool force_hostname_reso
|
|||||||
if (!h.is_valid())
|
if (!h.is_valid())
|
||||||
return;
|
return;
|
||||||
boost::system::error_code ec;
|
boost::system::error_code ec;
|
||||||
|
libtorrent::torrent_status status = h.status(torrent_handle::query_pieces);
|
||||||
std::vector<peer_info> peers;
|
std::vector<peer_info> peers;
|
||||||
h.get_peer_info(peers);
|
h.get_peer_info(peers);
|
||||||
QSet<QString> old_peers_set = m_peerItems.keys().toSet();
|
QSet<QString> old_peers_set = m_peerItems.keys().toSet();
|
||||||
@ -341,14 +343,14 @@ void PeerListWidget::loadPeers(const QTorrentHandle &h, bool force_hostname_reso
|
|||||||
QString peer_ip = misc::toQString(ip_str);
|
QString peer_ip = misc::toQString(ip_str);
|
||||||
if (m_peerItems.contains(peer_ip)) {
|
if (m_peerItems.contains(peer_ip)) {
|
||||||
// Update existing peer
|
// Update existing peer
|
||||||
updatePeer(peer_ip, peer);
|
updatePeer(peer_ip, status, peer);
|
||||||
old_peers_set.remove(peer_ip);
|
old_peers_set.remove(peer_ip);
|
||||||
if (force_hostname_resolution && m_resolver) {
|
if (force_hostname_resolution && m_resolver) {
|
||||||
m_resolver->resolve(peer_ip);
|
m_resolver->resolve(peer_ip);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Add new peer
|
// Add new peer
|
||||||
m_peerItems[peer_ip] = addPeer(peer_ip, peer);
|
m_peerItems[peer_ip] = addPeer(peer_ip, status, peer);
|
||||||
m_peerEndpoints[peer_ip] = peer.ip;
|
m_peerEndpoints[peer_ip] = peer.ip;
|
||||||
// Resolve peer host name is asked
|
// Resolve peer host name is asked
|
||||||
if (m_resolver)
|
if (m_resolver)
|
||||||
@ -366,7 +368,7 @@ void PeerListWidget::loadPeers(const QTorrentHandle &h, bool force_hostname_reso
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QStandardItem* PeerListWidget::addPeer(const QString& ip, const peer_info& peer) {
|
QStandardItem* PeerListWidget::addPeer(const QString& ip, const libtorrent::torrent_status &status, const peer_info& peer) {
|
||||||
int row = m_listModel->rowCount();
|
int row = m_listModel->rowCount();
|
||||||
// Adding Peer to peer list
|
// Adding Peer to peer list
|
||||||
m_listModel->insertRow(row);
|
m_listModel->insertRow(row);
|
||||||
@ -395,10 +397,11 @@ QStandardItem* PeerListWidget::addPeer(const QString& ip, const peer_info& peer)
|
|||||||
m_listModel->setData(m_listModel->index(row, PeerListDelegate::UP_SPEED), peer.payload_up_speed);
|
m_listModel->setData(m_listModel->index(row, PeerListDelegate::UP_SPEED), peer.payload_up_speed);
|
||||||
m_listModel->setData(m_listModel->index(row, PeerListDelegate::TOT_DOWN), (qulonglong)peer.total_download);
|
m_listModel->setData(m_listModel->index(row, PeerListDelegate::TOT_DOWN), (qulonglong)peer.total_download);
|
||||||
m_listModel->setData(m_listModel->index(row, PeerListDelegate::TOT_UP), (qulonglong)peer.total_upload);
|
m_listModel->setData(m_listModel->index(row, PeerListDelegate::TOT_UP), (qulonglong)peer.total_upload);
|
||||||
|
m_listModel->setData(m_listModel->index(row, PeerListDelegate::RELEVANCE), getPeerRelevance(status, peer));
|
||||||
return m_listModel->item(row, PeerListDelegate::IP);
|
return m_listModel->item(row, PeerListDelegate::IP);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerListWidget::updatePeer(const QString& ip, const peer_info& peer) {
|
void PeerListWidget::updatePeer(const QString& ip, const libtorrent::torrent_status &status, const peer_info& peer) {
|
||||||
QStandardItem *item = m_peerItems.value(ip);
|
QStandardItem *item = m_peerItems.value(ip);
|
||||||
int row = item->row();
|
int row = item->row();
|
||||||
if (m_displayFlags) {
|
if (m_displayFlags) {
|
||||||
@ -422,6 +425,7 @@ void PeerListWidget::updatePeer(const QString& ip, const peer_info& peer) {
|
|||||||
m_listModel->setData(m_listModel->index(row, PeerListDelegate::UP_SPEED), peer.payload_up_speed);
|
m_listModel->setData(m_listModel->index(row, PeerListDelegate::UP_SPEED), peer.payload_up_speed);
|
||||||
m_listModel->setData(m_listModel->index(row, PeerListDelegate::TOT_DOWN), (qulonglong)peer.total_download);
|
m_listModel->setData(m_listModel->index(row, PeerListDelegate::TOT_DOWN), (qulonglong)peer.total_download);
|
||||||
m_listModel->setData(m_listModel->index(row, PeerListDelegate::TOT_UP), (qulonglong)peer.total_upload);
|
m_listModel->setData(m_listModel->index(row, PeerListDelegate::TOT_UP), (qulonglong)peer.total_upload);
|
||||||
|
m_listModel->setData(m_listModel->index(row, PeerListDelegate::RELEVANCE), getPeerRelevance(status, peer));
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerListWidget::handleResolved(const QString &ip, const QString &hostname) {
|
void PeerListWidget::handleResolved(const QString &ip, const QString &hostname) {
|
||||||
@ -582,3 +586,24 @@ void PeerListWidget::getFlags(const peer_info& peer, QString& flags, QString& to
|
|||||||
if (tooltip.endsWith(',', Qt::CaseInsensitive))
|
if (tooltip.endsWith(',', Qt::CaseInsensitive))
|
||||||
tooltip.chop(1);
|
tooltip.chop(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double PeerListWidget::getPeerRelevance(const torrent_status& status, const libtorrent::peer_info &peer)
|
||||||
|
{
|
||||||
|
int localMissing = 0;
|
||||||
|
int remoteHaves = 0;
|
||||||
|
libtorrent::bitfield local = status.pieces;
|
||||||
|
libtorrent::bitfield remote = peer.pieces;
|
||||||
|
|
||||||
|
for (int i=0; i<local.size(); ++i) {
|
||||||
|
if (!local[i]) {
|
||||||
|
++localMissing;
|
||||||
|
if (remote[i])
|
||||||
|
++remoteHaves;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (localMissing == 0)
|
||||||
|
return -1.0;
|
||||||
|
|
||||||
|
return (double)remoteHaves/localMissing;
|
||||||
|
}
|
||||||
|
@ -66,8 +66,8 @@ public:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void loadPeers(const QTorrentHandle &h, bool force_hostname_resolution = false);
|
void loadPeers(const QTorrentHandle &h, bool force_hostname_resolution = false);
|
||||||
QStandardItem* addPeer(const QString& ip, const libtorrent::peer_info& peer);
|
QStandardItem* addPeer(const QString& ip, const libtorrent::torrent_status &status, const libtorrent::peer_info& peer);
|
||||||
void updatePeer(const QString& ip, const libtorrent::peer_info& peer);
|
void updatePeer(const QString& ip, const libtorrent::torrent_status &status, const libtorrent::peer_info& peer);
|
||||||
void handleResolved(const QString &ip, const QString &hostname);
|
void handleResolved(const QString &ip, const QString &hostname);
|
||||||
void updatePeerHostNameResolutionState();
|
void updatePeerHostNameResolutionState();
|
||||||
void updatePeerCountryResolutionState();
|
void updatePeerCountryResolutionState();
|
||||||
@ -89,6 +89,7 @@ protected slots:
|
|||||||
private:
|
private:
|
||||||
static QString getConnectionString(const libtorrent::peer_info &peer);
|
static QString getConnectionString(const libtorrent::peer_info &peer);
|
||||||
static void getFlags(const libtorrent::peer_info& peer, QString& flags, QString& tooltip);
|
static void getFlags(const libtorrent::peer_info& peer, QString& flags, QString& tooltip);
|
||||||
|
double getPeerRelevance(const libtorrent::torrent_status &status, const libtorrent::peer_info &peer);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QStandardItemModel *m_listModel;
|
QStandardItemModel *m_listModel;
|
||||||
|
@ -318,11 +318,12 @@ void PropertiesWidget::loadDynamicData() {
|
|||||||
// Refresh only if the torrent handle is valid and if visible
|
// Refresh only if the torrent handle is valid and if visible
|
||||||
if (!h.is_valid() || main_window->getCurrentTabWidget() != transferList || state != VISIBLE) return;
|
if (!h.is_valid() || main_window->getCurrentTabWidget() != transferList || state != VISIBLE) return;
|
||||||
try {
|
try {
|
||||||
libtorrent::torrent_status status = h.status(torrent_handle::query_accurate_download_counters
|
|
||||||
| torrent_handle::query_distributed_copies
|
|
||||||
| torrent_handle::query_pieces);
|
|
||||||
// Transfer infos
|
// Transfer infos
|
||||||
if (stackedProperties->currentIndex() == PropTabBar::MAIN_TAB) {
|
if (stackedProperties->currentIndex() == PropTabBar::MAIN_TAB) {
|
||||||
|
libtorrent::torrent_status status = h.status(torrent_handle::query_accurate_download_counters
|
||||||
|
| torrent_handle::query_distributed_copies
|
||||||
|
| torrent_handle::query_pieces);
|
||||||
|
|
||||||
wasted->setText(misc::friendlyUnit(status.total_failed_bytes+status.total_redundant_bytes));
|
wasted->setText(misc::friendlyUnit(status.total_failed_bytes+status.total_redundant_bytes));
|
||||||
upTotal->setText(misc::friendlyUnit(status.all_time_upload) + " ("+misc::friendlyUnit(status.total_payload_upload)+" "+tr("this session")+")");
|
upTotal->setText(misc::friendlyUnit(status.all_time_upload) + " ("+misc::friendlyUnit(status.total_payload_upload)+" "+tr("this session")+")");
|
||||||
dlTotal->setText(misc::friendlyUnit(status.all_time_download) + " ("+misc::friendlyUnit(status.total_payload_download)+" "+tr("this session")+")");
|
dlTotal->setText(misc::friendlyUnit(status.all_time_download) + " ("+misc::friendlyUnit(status.total_payload_download)+" "+tr("this session")+")");
|
||||||
@ -382,6 +383,9 @@ void PropertiesWidget::loadDynamicData() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (stackedProperties->currentIndex() == PropTabBar::FILES_TAB) {
|
if (stackedProperties->currentIndex() == PropTabBar::FILES_TAB) {
|
||||||
|
libtorrent::torrent_status status = h.status(torrent_handle::query_accurate_download_counters
|
||||||
|
| torrent_handle::query_distributed_copies
|
||||||
|
| torrent_handle::query_pieces);
|
||||||
// Files progress
|
// Files progress
|
||||||
if (h.is_valid() && status.has_metadata) {
|
if (h.is_valid() && status.has_metadata) {
|
||||||
qDebug("Updating priorities in files tab");
|
qDebug("Updating priorities in files tab");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user