mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-21 04:45:31 +08:00
refs #875, renamed to getKnownLocalIpV4Addresses()
This commit is contained in:
committed by
Mathew Sutcliffe
parent
e28056ac2f
commit
9beb6c79e1
@@ -48,7 +48,7 @@ namespace BlackMisc
|
|||||||
bool CNetworkUtils::hasConnectedInterface(bool withDebugOutput)
|
bool CNetworkUtils::hasConnectedInterface(bool withDebugOutput)
|
||||||
{
|
{
|
||||||
// http://stackoverflow.com/questions/2475266/verfiying-the-network-connection-using-qt-4-4
|
// http://stackoverflow.com/questions/2475266/verfiying-the-network-connection-using-qt-4-4
|
||||||
QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces();
|
const QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces();
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
for (int i = 0; i < interfaces.count(); i++)
|
for (int i = 0; i < interfaces.count(); i++)
|
||||||
@@ -77,17 +77,20 @@ namespace BlackMisc
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList CNetworkUtils::getKnownIpAddresses()
|
QStringList CNetworkUtils::getKnownLocalIpV4Addresses()
|
||||||
{
|
{
|
||||||
QStringList ips;
|
QStringList ips;
|
||||||
if (!CNetworkUtils::hasConnectedInterface(false)) return ips;
|
if (!CNetworkUtils::hasConnectedInterface(false)) {return ips; }
|
||||||
foreach (const QHostAddress &address, QNetworkInterface::allAddresses())
|
for (const QHostAddress &address : QNetworkInterface::allAddresses())
|
||||||
{
|
{
|
||||||
if (address.isLoopback() || address.isNull()) continue;
|
if (address.isLoopback() || address.isNull()) continue;
|
||||||
if (address.protocol() == QAbstractSocket::IPv4Protocol && address != QHostAddress(QHostAddress::LocalHost))
|
if (address.protocol() == QAbstractSocket::IPv4Protocol && address != QHostAddress(QHostAddress::LocalHost))
|
||||||
{
|
{
|
||||||
QString a = address.toString();
|
QString a = address.toString();
|
||||||
if (CNetworkUtils::isValidIPv4Address(a)) ips.append(a);
|
if (CNetworkUtils::isValidIPv4Address(a))
|
||||||
|
{
|
||||||
|
ips.append(a);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ips;
|
return ips;
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ namespace BlackMisc
|
|||||||
static bool canConnect(const BlackMisc::Network::CUrl &url, int timeoutMs = getTimeoutMs());
|
static bool canConnect(const BlackMisc::Network::CUrl &url, int timeoutMs = getTimeoutMs());
|
||||||
|
|
||||||
//! Find out my IPv4 address, empty if not possible
|
//! Find out my IPv4 address, empty if not possible
|
||||||
static QStringList getKnownIpAddresses();
|
static QStringList getKnownLocalIpV4Addresses();
|
||||||
|
|
||||||
//! Valid IPv4 address
|
//! Valid IPv4 address
|
||||||
static bool isValidIPv4Address(const QString &candidate);
|
static bool isValidIPv4Address(const QString &candidate);
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ void CSwiftLauncher::loadLatestNews()
|
|||||||
void CSwiftLauncher::initDBusGui()
|
void CSwiftLauncher::initDBusGui()
|
||||||
{
|
{
|
||||||
ui->cb_DBusServerAddress->addItem("127.0.0.1");
|
ui->cb_DBusServerAddress->addItem("127.0.0.1");
|
||||||
ui->cb_DBusServerAddress->addItems(CNetworkUtils::getKnownIpAddresses());
|
ui->cb_DBusServerAddress->addItems(CNetworkUtils::getKnownLocalIpV4Addresses());
|
||||||
ui->cb_DBusServerAddress->setCurrentIndex(0);
|
ui->cb_DBusServerAddress->setCurrentIndex(0);
|
||||||
|
|
||||||
connect(ui->cb_DBusServerAddress, &QComboBox::currentTextChanged, this, &CSwiftLauncher::ps_dbusServerAddressSelectionChanged);
|
connect(ui->cb_DBusServerAddress, &QComboBox::currentTextChanged, this, &CSwiftLauncher::ps_dbusServerAddressSelectionChanged);
|
||||||
|
|||||||
Reference in New Issue
Block a user