diff options
author | Samuli Piippo <samuli.piippo@qt.io> | 2020-10-26 09:25:26 +0200 |
---|---|---|
committer | Samuli Piippo <samuli.piippo@qt.io> | 2020-10-29 05:44:00 +0000 |
commit | a15beba02f95e56d1fe50eaf13b59b95b23d0e2c (patch) | |
tree | 36b59dc932afc30c024acfe86def22a9e33d915f /startupscreen | |
parent | 31a633bc93eb2eaff4d50596c69db0ad83a3e6cf (diff) |
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 <rami.potinkara@qt.io>
Diffstat (limited to 'startupscreen')
-rw-r--r-- | startupscreen/MainView.qml | 11 | ||||
-rw-r--r-- | startupscreen/settingsmanager.cpp | 27 | ||||
-rw-r--r-- | 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 <QDir> #include <QFile> #include <QTemporaryFile> +#include <QNetworkInterface> #include <sys/reboot.h> #include <unistd.h> @@ -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; }; |