diff --git a/src/HomePage.qml b/src/HomePage.qml index c24cf59775db69335bf0b0eeac2e51980e4c7e6c..7d5f1441f00d7150ffa0cf6f494c2e3d41ddd72a 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 c9b6b2bfc1ee20c9335e9deef80c728eb461210c..cd9ccce1dba0ab0f4bf64355503be41a7161330d 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 0908b56b398732ad1fb02efc9d300a94d84ff73b..fa902072426f2257b26da5821974d009c420a025 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);