From 304d6f90d1685096d09b68d1106b4b6ab1f8e9ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Han=C3=A7erli?= <burak.hancerli@qt.io> Date: Tue, 29 Oct 2024 19:04:01 +0000 Subject: [PATCH] QDS-13458 Show ip addresses on the home page --- src/HomePage.qml | 122 ++++++---------------------------------- src/backend/backend.cpp | 19 +++++++ src/backend/backend.h | 2 + 3 files changed, 37 insertions(+), 106 deletions(-) diff --git a/src/HomePage.qml b/src/HomePage.qml index c24cf59..7d5f144 100644 --- a/src/HomePage.qml +++ b/src/HomePage.qml @@ -137,117 +137,27 @@ Flickable { spacing: 10 - Rectangle { + Label { Layout.fillWidth: true - Layout.preferredHeight: optionLayout1.height - - color: Constants.boxBackgroundColor - radius: Material.MediumScale - border { - width: 1 - color: Constants.boxBorderColor - } - - ColumnLayout { - id: optionLayout1 - width: parent.width - spacing: 20 - - Label { - Layout.fillWidth: true - Layout.topMargin: 20 - - horizontalAlignment: Qt.AlignHCenter - text: qsTr("Option 1") - font.pixelSize: Constants.lgTextSize - font.bold: true - wrapMode: Text.WordWrap - } - - Label { - Layout.fillWidth: true - Layout.leftMargin: 20 - Layout.rightMargin: 20 - - horizontalAlignment: Qt.AlignHCenter - text: qsTr("Click to scan the QR code in Qt Design Studio") - font.pixelSize: Constants.mdTextSize - wrapMode: Text.WordWrap - } - - QrButton { - Layout.alignment: Qt.AlignHCenter - Layout.bottomMargin: 20 - - onClicked: backend.scanQrCode() - } - } + text: qsTr("This device can be reached at the following IP addresses:") + font.pixelSize: Constants.lgTextSize + font.bold: true + wrapMode: Text.WordWrap } - Rectangle { + Label { + id: ipAddress Layout.fillWidth: true - Layout.preferredHeight: optionLayout2.height - - color: Constants.boxBackgroundColor - radius: Material.MediumScale - border { - width: 1 - color: Constants.boxBorderColor - } - - ColumnLayout { - id: optionLayout2 - width: parent.width - spacing: 20 - - Label { - Layout.fillWidth: true - Layout.topMargin: 20 - - horizontalAlignment: Qt.AlignHCenter - text: qsTr("Option 2") - font.pixelSize: Constants.lgTextSize - font.bold: true - - wrapMode: Text.WordWrap - } - - TextField { - id: ipAddress - - Layout.fillWidth: true - Layout.leftMargin: 20 - Layout.rightMargin: 20 - Layout.alignment: Qt.AlignHCenter - - placeholderText: qsTr("IP Address") - text: backend.lastDesignStudioIp() - validator: RegularExpressionValidator { - regularExpression: /^(\d{1,3}\.){3}\d{1,3}$/ - } - - Connections { - target: backend - - function onConnectedChanged(isConnected, ip) { - ipAddress.text = ip; - } - } - } - - Button { - id: downloadUserProject - - Layout.fillWidth: true - Layout.leftMargin: 20 - Layout.rightMargin: 20 - Layout.bottomMargin: 20 - Layout.alignment: Qt.AlignHCenter - - text: qsTr("Connect Design Studio") - enabled: true + text: qsTr("xxx.xxx.xxx.xxx") + font.pixelSize: Constants.lgTextSize + font.bold: true + wrapMode: Text.WordWrap - onClicked: backend.connectDesignStudio(ipAddress.text) + Component.onCompleted: { + ipAddress.text = ''; + var val = backend.getIpAddresses(); + for(var i = 0; i < val.length; i++) { + ipAddress.text += val[i].interface + ': ' + val[i].ip + '\n'; } } } diff --git a/src/backend/backend.cpp b/src/backend/backend.cpp index c9b6b2b..cd9ccce 100644 --- a/src/backend/backend.cpp +++ b/src/backend/backend.cpp @@ -26,6 +26,7 @@ #include "backend.h" #include <QDesktopServices> +#include <QNetworkInterface> #include "logger.h" @@ -253,3 +254,21 @@ QString Backend::lastDesignStudioIp() const { return m_dsManager ? m_dsManager->getDesignStudioIp({}) : QString(); } + +QJsonArray Backend::getIpAddresses() const +{ + QNetworkInterface networkInterface; + QJsonArray ipAddresses; + + for (const auto &interface : networkInterface.allInterfaces()) { + for (const auto &entry : interface.addressEntries()) { + if (entry.ip().protocol() == QAbstractSocket::IPv4Protocol && !entry.ip().isLoopback()) { + qDebug() << "Interface:" << interface.name() << "IP:" << entry.ip().toString(); + ipAddresses.append( + QJsonObject{{"interface", interface.name()}, {"ip", entry.ip().toString()}}); + } + } + } + + return ipAddresses; +} diff --git a/src/backend/backend.h b/src/backend/backend.h index 0908b56..fa90207 100644 --- a/src/backend/backend.h +++ b/src/backend/backend.h @@ -26,6 +26,7 @@ #ifndef DV_ANDROID_H #define DV_ANDROID_H +#include <QJsonArray> #include <QThread> #include "dsconnector/dsmanager.h" @@ -81,6 +82,7 @@ public slots: void connectDesignStudio(const QString &ipAddr); void parseDesignViewerUrl(const QUrl &url); void popupInterrupted(); + QJsonArray getIpAddresses() const; bool autoScaleProject() const; void setAutoScaleProject(bool autoScaleProject); -- GitLab