mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-21 07:57:22 -06:00
Display External IP Address in status bar
This change displays the last detected IPv4 and/or IPv6 address(es) in the GUI and WebUI's status bar. This does not yet handle systems with multiple addresses of the same type (e.g. multiple IPv6 addresses). PR #21383. --------- Co-authored-by: Odin Vex <44311901+OdinVex@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
fb9b3c0f34
commit
f89c4c32ed
@@ -38,6 +38,7 @@
|
||||
|
||||
#include "base/bittorrent/session.h"
|
||||
#include "base/bittorrent/sessionstatus.h"
|
||||
#include "base/preferences.h"
|
||||
#include "base/utils/misc.h"
|
||||
#include "speedlimitdialog.h"
|
||||
#include "uithememanager.h"
|
||||
@@ -86,6 +87,9 @@ StatusBar::StatusBar(QWidget *parent)
|
||||
m_upSpeedLbl->setStyleSheet(u"text-align:left;"_s);
|
||||
m_upSpeedLbl->setMinimumWidth(200);
|
||||
|
||||
m_lastExternalIPsLbl = new QLabel(tr("External IP: N/A"));
|
||||
m_lastExternalIPsLbl->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
|
||||
|
||||
m_DHTLbl = new QLabel(tr("DHT: %1 nodes").arg(0), this);
|
||||
m_DHTLbl->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
|
||||
|
||||
@@ -129,24 +133,33 @@ StatusBar::StatusBar(QWidget *parent)
|
||||
#ifndef Q_OS_MACOS
|
||||
statusSep4->setFrameShadow(QFrame::Raised);
|
||||
#endif
|
||||
layout->addWidget(m_DHTLbl);
|
||||
QFrame *statusSep5 = new QFrame(this);
|
||||
statusSep5->setFrameStyle(QFrame::VLine);
|
||||
#ifndef Q_OS_MACOS
|
||||
statusSep5->setFrameShadow(QFrame::Raised);
|
||||
#endif
|
||||
layout->addWidget(m_lastExternalIPsLbl);
|
||||
layout->addWidget(statusSep1);
|
||||
layout->addWidget(m_connecStatusLblIcon);
|
||||
layout->addWidget(m_DHTLbl);
|
||||
layout->addWidget(statusSep2);
|
||||
layout->addWidget(m_connecStatusLblIcon);
|
||||
layout->addWidget(statusSep3);
|
||||
layout->addWidget(m_altSpeedsBtn);
|
||||
layout->addWidget(statusSep4);
|
||||
layout->addWidget(m_dlSpeedLbl);
|
||||
layout->addWidget(statusSep3);
|
||||
layout->addWidget(statusSep5);
|
||||
layout->addWidget(m_upSpeedLbl);
|
||||
|
||||
addPermanentWidget(container);
|
||||
setStyleSheet(u"QWidget {margin: 0;}"_s);
|
||||
container->adjustSize();
|
||||
adjustSize();
|
||||
updateExternalAddressesVisibility();
|
||||
// Is DHT enabled
|
||||
m_DHTLbl->setVisible(session->isDHTEnabled());
|
||||
refresh();
|
||||
connect(session, &BitTorrent::Session::statsUpdated, this, &StatusBar::refresh);
|
||||
connect(Preferences::instance(), &Preferences::changed, this, &StatusBar::optionsSaved);
|
||||
}
|
||||
|
||||
StatusBar::~StatusBar()
|
||||
@@ -212,6 +225,28 @@ void StatusBar::updateDHTNodesNumber()
|
||||
}
|
||||
}
|
||||
|
||||
void StatusBar::updateExternalAddressesLabel()
|
||||
{
|
||||
const QString lastExternalIPv4Address = BitTorrent::Session::instance()->lastExternalIPv4Address();
|
||||
const QString lastExternalIPv6Address = BitTorrent::Session::instance()->lastExternalIPv6Address();
|
||||
QString addressText = tr("External IP: N/A");
|
||||
|
||||
const bool hasIPv4Address = !lastExternalIPv4Address.isEmpty();
|
||||
const bool hasIPv6Address = !lastExternalIPv6Address.isEmpty();
|
||||
|
||||
if (hasIPv4Address && hasIPv6Address)
|
||||
addressText = tr("External IPs: %1, %2").arg(lastExternalIPv4Address, lastExternalIPv6Address);
|
||||
else if (hasIPv4Address || hasIPv6Address)
|
||||
addressText = tr("External IP: %1%2").arg(lastExternalIPv4Address, lastExternalIPv6Address);
|
||||
|
||||
m_lastExternalIPsLbl->setText(addressText);
|
||||
}
|
||||
|
||||
void StatusBar::updateExternalAddressesVisibility()
|
||||
{
|
||||
m_lastExternalIPsLbl->setVisible(Preferences::instance()->isStatusbarExternalIPDisplayed());
|
||||
}
|
||||
|
||||
void StatusBar::updateSpeedLabels()
|
||||
{
|
||||
const BitTorrent::SessionStatus &sessionStatus = BitTorrent::Session::instance()->status();
|
||||
@@ -235,6 +270,7 @@ void StatusBar::refresh()
|
||||
{
|
||||
updateConnectionStatus();
|
||||
updateDHTNodesNumber();
|
||||
updateExternalAddressesLabel();
|
||||
updateSpeedLabels();
|
||||
}
|
||||
|
||||
@@ -261,3 +297,8 @@ void StatusBar::capSpeed()
|
||||
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||
dialog->open();
|
||||
}
|
||||
|
||||
void StatusBar::optionsSaved()
|
||||
{
|
||||
updateExternalAddressesVisibility();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user