From a15beba02f95e56d1fe50eaf13b59b95b23d0e2c Mon Sep 17 00:00:00 2001 From: Samuli Piippo Date: Mon, 26 Oct 2020 09:25:26 +0200 Subject: startupscreen: show IP addresses Fetch all IPv4 networks and show them to the user. Qt6 has removed APIs for getting signals of network changes, need to poll the network periodically. Task-number: QTBUG-87028 Change-Id: I3953e5c6ecff7a463cb14354fd5302b04b554157 Reviewed-by: Rami Potinkara --- startupscreen/MainView.qml | 11 +++++++++-- startupscreen/settingsmanager.cpp | 27 +++++++++++++++++++++++++++ startupscreen/settingsmanager.h | 3 +++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/startupscreen/MainView.qml b/startupscreen/MainView.qml index 4e0a234..fb79df3 100644 --- a/startupscreen/MainView.qml +++ b/startupscreen/MainView.qml @@ -200,7 +200,7 @@ Item { Text { id: ipLabel color: "grey" - text: "Network" + text: "Networks:" anchors.bottom: ipAddress.top anchors.horizontalCenter: ipAddress.horizontalCenter font.pixelSize: textNormal @@ -209,13 +209,20 @@ Item { Text { id: ipAddress color: "grey" - text: "eth0: 255.255.255.255\nusb0: 0:0.0.0.0" + text: SettingsManager.networks anchors.bottom: root.bottom anchors.right: root.right anchors.rightMargin: 5 font.pixelSize: textNormal font.bold: true font.family: "Titillium Web" + + Timer { + interval: 3000 + onTriggered: ipAddress.text = SettingsManager.networks + running: true + repeat: true + } } UsbModeDialog { diff --git a/startupscreen/settingsmanager.cpp b/startupscreen/settingsmanager.cpp index 4f5f217..0608f86 100644 --- a/startupscreen/settingsmanager.cpp +++ b/startupscreen/settingsmanager.cpp @@ -54,6 +54,7 @@ #include #include #include +#include #include #include @@ -124,3 +125,29 @@ void SettingsManager::reboot() ::reboot(RB_AUTOBOOT); qWarning("reboot failed"); } + +QString SettingsManager::networks() +{ + QString networks; + networks.reserve(100); + + const auto interfaceList = QNetworkInterface::allInterfaces(); + for (const auto &interface : interfaceList) { + if (interface.name() == QLatin1String("lo")) + continue; + + if (interface.flags().testFlag(QNetworkInterface::IsUp)) { + for (QNetworkAddressEntry &entry : interface.addressEntries()) { + if (entry.ip().protocol() == QAbstractSocket::IPv4Protocol) { + if (!networks.isEmpty()) + networks += QLatin1String("\n"); + + networks += interface.name(); + networks += QLatin1String(": "); + networks += entry.ip().toString(); + } + } + } + } + return networks; +} diff --git a/startupscreen/settingsmanager.h b/startupscreen/settingsmanager.h index 1801812..fa6c066 100644 --- a/startupscreen/settingsmanager.h +++ b/startupscreen/settingsmanager.h @@ -60,6 +60,7 @@ class SettingsManager : public QObject Q_PROPERTY(QString usbMode READ usbMode WRITE setUsbMode) Q_PROPERTY(bool hasQdb READ hasQdb CONSTANT) + Q_PROPERTY(QString networks READ networks CONSTANT) public: explicit SettingsManager(QObject *parent = nullptr); @@ -69,6 +70,8 @@ public: bool hasQdb(); Q_INVOKABLE void reboot(); + QString networks(); + private: QString m_usbMode; }; -- cgit v1.2.3