Browse Source

Implement `Peer ID Client` column for `Peers` tab

PR #17940.
adaptive-webui-19844
Hanabishi 2 years ago committed by GitHub
parent
commit
6a560016dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 25
      src/base/bittorrent/peerinfo.cpp
  2. 1
      src/base/bittorrent/peerinfo.h
  3. 17
      src/gui/properties/peerlistwidget.cpp
  4. 3
      src/gui/properties/peerlistwidget.h
  5. 2
      src/webui/api/synccontroller.cpp
  6. 2
      src/webui/webapplication.h
  7. 1
      src/webui/www/private/scripts/dynamicTable.js

25
src/base/bittorrent/peerinfo.cpp

@ -181,6 +181,31 @@ QString PeerInfo::client() const
return QString::fromStdString(m_nativeInfo.client); return QString::fromStdString(m_nativeInfo.client);
} }
QString PeerInfo::peerIdClient() const
{
// when peer ID is not known yet it contains only zero bytes,
// do not create string in such case, return empty string instead
if (m_nativeInfo.pid.is_all_zeros())
return {};
QString result;
// interesting part of a typical peer ID is first 8 chars
for (int i = 0; i < 8; ++i)
{
const std::uint8_t c = m_nativeInfo.pid[i];
// ensure that the peer ID slice consists only of printable ASCII characters,
// this should filter out most of the improper IDs
if ((c < 32) || (c > 126))
return tr("Unknown");
result += QChar::fromLatin1(c);
}
return result;
}
qreal PeerInfo::progress() const qreal PeerInfo::progress() const
{ {
return m_nativeInfo.progress; return m_nativeInfo.progress;

1
src/base/bittorrent/peerinfo.h

@ -78,6 +78,7 @@ namespace BitTorrent
PeerAddress address() const; PeerAddress address() const;
QString client() const; QString client() const;
QString peerIdClient() const;
qreal progress() const; qreal progress() const;
int payloadUpSpeed() const; int payloadUpSpeed() const;
int payloadDownSpeed() const; int payloadDownSpeed() const;

17
src/gui/properties/peerlistwidget.cpp

@ -89,7 +89,7 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent)
, m_properties(parent) , m_properties(parent)
{ {
// Load settings // Load settings
loadSettings(); const bool columnLoaded = loadSettings();
// Visual settings // Visual settings
setUniformRowHeights(true); setUniformRowHeights(true);
setRootIsDecorated(false); setRootIsDecorated(false);
@ -109,6 +109,7 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent)
m_listModel->setHeaderData(PeerListColumns::FLAGS, Qt::Horizontal, tr("Flags")); m_listModel->setHeaderData(PeerListColumns::FLAGS, Qt::Horizontal, tr("Flags"));
m_listModel->setHeaderData(PeerListColumns::CONNECTION, Qt::Horizontal, tr("Connection")); m_listModel->setHeaderData(PeerListColumns::CONNECTION, Qt::Horizontal, tr("Connection"));
m_listModel->setHeaderData(PeerListColumns::CLIENT, Qt::Horizontal, tr("Client", "i.e.: Client application")); m_listModel->setHeaderData(PeerListColumns::CLIENT, Qt::Horizontal, tr("Client", "i.e.: Client application"));
m_listModel->setHeaderData(PeerListColumns::PEERID_CLIENT, Qt::Horizontal, tr("Peer ID Client", "i.e.: Client resolved from Peer ID"));
m_listModel->setHeaderData(PeerListColumns::PROGRESS, Qt::Horizontal, tr("Progress", "i.e: % downloaded")); m_listModel->setHeaderData(PeerListColumns::PROGRESS, Qt::Horizontal, tr("Progress", "i.e: % downloaded"));
m_listModel->setHeaderData(PeerListColumns::DOWN_SPEED, Qt::Horizontal, tr("Down Speed", "i.e: Download speed")); m_listModel->setHeaderData(PeerListColumns::DOWN_SPEED, Qt::Horizontal, tr("Down Speed", "i.e: Download speed"));
m_listModel->setHeaderData(PeerListColumns::UP_SPEED, Qt::Horizontal, tr("Up Speed", "i.e: Upload speed")); m_listModel->setHeaderData(PeerListColumns::UP_SPEED, Qt::Horizontal, tr("Up Speed", "i.e: Upload speed"));
@ -130,8 +131,16 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent)
m_proxyModel->setSourceModel(m_listModel); m_proxyModel->setSourceModel(m_listModel);
m_proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); m_proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
setModel(m_proxyModel); setModel(m_proxyModel);
hideColumn(PeerListColumns::IP_HIDDEN); hideColumn(PeerListColumns::IP_HIDDEN);
hideColumn(PeerListColumns::COL_COUNT); hideColumn(PeerListColumns::COL_COUNT);
// Default hidden columns
if (!columnLoaded)
{
hideColumn(PeerListColumns::PEERID_CLIENT);
}
m_resolveCountries = Preferences::instance()->resolvePeerCountries(); m_resolveCountries = Preferences::instance()->resolvePeerCountries();
if (!m_resolveCountries) if (!m_resolveCountries)
hideColumn(PeerListColumns::COUNTRY); hideColumn(PeerListColumns::COUNTRY);
@ -371,9 +380,9 @@ void PeerListWidget::clear()
m_listModel->removeRows(0, nbrows); m_listModel->removeRows(0, nbrows);
} }
void PeerListWidget::loadSettings() bool PeerListWidget::loadSettings()
{ {
header()->restoreState(Preferences::instance()->getPeerListState()); return header()->restoreState(Preferences::instance()->getPeerListState());
} }
void PeerListWidget::saveSettings() const void PeerListWidget::saveSettings() const
@ -461,6 +470,8 @@ void PeerListWidget::updatePeer(const BitTorrent::Torrent *torrent, const BitTor
setModelData(row, PeerListColumns::FLAGS, peer.flags(), peer.flags(), {}, peer.flagsDescription()); setModelData(row, PeerListColumns::FLAGS, peer.flags(), peer.flags(), {}, peer.flagsDescription());
const QString client = peer.client().toHtmlEscaped(); const QString client = peer.client().toHtmlEscaped();
setModelData(row, PeerListColumns::CLIENT, client, client, {}, client); setModelData(row, PeerListColumns::CLIENT, client, client, {}, client);
const QString peerIdClient = peer.peerIdClient().toHtmlEscaped();
setModelData(row, PeerListColumns::PEERID_CLIENT, peerIdClient, peerIdClient);
setModelData(row, PeerListColumns::PROGRESS, (Utils::String::fromDouble(peer.progress() * 100, 1) + u'%'), peer.progress(), intDataTextAlignment); setModelData(row, PeerListColumns::PROGRESS, (Utils::String::fromDouble(peer.progress() * 100, 1) + u'%'), peer.progress(), intDataTextAlignment);
const QString downSpeed = (hideValues && (peer.payloadDownSpeed() <= 0)) ? QString {} : Utils::Misc::friendlyUnit(peer.payloadDownSpeed(), true); const QString downSpeed = (hideValues && (peer.payloadDownSpeed() <= 0)) ? QString {} : Utils::Misc::friendlyUnit(peer.payloadDownSpeed(), true);
setModelData(row, PeerListColumns::DOWN_SPEED, downSpeed, peer.payloadDownSpeed(), intDataTextAlignment); setModelData(row, PeerListColumns::DOWN_SPEED, downSpeed, peer.payloadDownSpeed(), intDataTextAlignment);

3
src/gui/properties/peerlistwidget.h

@ -66,6 +66,7 @@ public:
CONNECTION, CONNECTION,
FLAGS, FLAGS,
CLIENT, CLIENT,
PEERID_CLIENT,
PROGRESS, PROGRESS,
DOWN_SPEED, DOWN_SPEED,
UP_SPEED, UP_SPEED,
@ -87,7 +88,7 @@ public:
void clear(); void clear();
private slots: private slots:
void loadSettings(); bool loadSettings();
void saveSettings() const; void saveSettings() const;
void displayColumnHeaderMenu(); void displayColumnHeaderMenu();
void showPeerListMenu(); void showPeerListMenu();

2
src/webui/api/synccontroller.cpp

@ -66,6 +66,7 @@ namespace
// Peer keys // Peer keys
const QString KEY_PEER_CLIENT = u"client"_qs; const QString KEY_PEER_CLIENT = u"client"_qs;
const QString KEY_PEER_ID_CLIENT = u"peer_id_client"_qs;
const QString KEY_PEER_CONNECTION_TYPE = u"connection"_qs; const QString KEY_PEER_CONNECTION_TYPE = u"connection"_qs;
const QString KEY_PEER_COUNTRY = u"country"_qs; const QString KEY_PEER_COUNTRY = u"country"_qs;
const QString KEY_PEER_COUNTRY_CODE = u"country_code"_qs; const QString KEY_PEER_COUNTRY_CODE = u"country_code"_qs;
@ -561,6 +562,7 @@ void SyncController::torrentPeersAction()
{KEY_PEER_IP, pi.address().ip.toString()}, {KEY_PEER_IP, pi.address().ip.toString()},
{KEY_PEER_PORT, pi.address().port}, {KEY_PEER_PORT, pi.address().port},
{KEY_PEER_CLIENT, pi.client()}, {KEY_PEER_CLIENT, pi.client()},
{KEY_PEER_ID_CLIENT, pi.peerIdClient()},
{KEY_PEER_PROGRESS, pi.progress()}, {KEY_PEER_PROGRESS, pi.progress()},
{KEY_PEER_DOWN_SPEED, pi.payloadDownSpeed()}, {KEY_PEER_DOWN_SPEED, pi.payloadDownSpeed()},
{KEY_PEER_UP_SPEED, pi.payloadUpSpeed()}, {KEY_PEER_UP_SPEED, pi.payloadUpSpeed()},

2
src/webui/webapplication.h

@ -52,7 +52,7 @@
#include "base/utils/version.h" #include "base/utils/version.h"
#include "api/isessionmanager.h" #include "api/isessionmanager.h"
inline const Utils::Version<3, 2> API_VERSION {2, 8, 16}; inline const Utils::Version<3, 2> API_VERSION {2, 8, 17};
class APIController; class APIController;
class AuthController; class AuthController;

1
src/webui/www/private/scripts/dynamicTable.js

@ -1498,6 +1498,7 @@ window.qBittorrent.DynamicTable = (function() {
this.newColumn('connection', '', 'QBT_TR(Connection)QBT_TR[CONTEXT=PeerListWidget]', 50, true); this.newColumn('connection', '', 'QBT_TR(Connection)QBT_TR[CONTEXT=PeerListWidget]', 50, true);
this.newColumn('flags', '', 'QBT_TR(Flags)QBT_TR[CONTEXT=PeerListWidget]', 50, true); this.newColumn('flags', '', 'QBT_TR(Flags)QBT_TR[CONTEXT=PeerListWidget]', 50, true);
this.newColumn('client', '', 'QBT_TR(Client)QBT_TR[CONTEXT=PeerListWidget]', 140, true); this.newColumn('client', '', 'QBT_TR(Client)QBT_TR[CONTEXT=PeerListWidget]', 140, true);
this.newColumn('peer_id_client', '', 'QBT_TR(Peer ID Client)QBT_TR[CONTEXT=PeerListWidget]', 60, false);
this.newColumn('progress', '', 'QBT_TR(Progress)QBT_TR[CONTEXT=PeerListWidget]', 50, true); this.newColumn('progress', '', 'QBT_TR(Progress)QBT_TR[CONTEXT=PeerListWidget]', 50, true);
this.newColumn('dl_speed', '', 'QBT_TR(Down Speed)QBT_TR[CONTEXT=PeerListWidget]', 50, true); this.newColumn('dl_speed', '', 'QBT_TR(Down Speed)QBT_TR[CONTEXT=PeerListWidget]', 50, true);
this.newColumn('up_speed', '', 'QBT_TR(Up Speed)QBT_TR[CONTEXT=PeerListWidget]', 50, true); this.newColumn('up_speed', '', 'QBT_TR(Up Speed)QBT_TR[CONTEXT=PeerListWidget]', 50, true);

Loading…
Cancel
Save