Skip to content
Snippets Groups Projects
Verified Commit 7ea8da7f authored by Burak Hançerli's avatar Burak Hançerli :headphones:
Browse files

add: connector for design studio

parent e46387e7
No related branches found
No related tags found
2 merge requests!22QDS-11332 Implement better qmlproject handling,!21Design studio connector
Pipeline #64451 passed
......@@ -34,6 +34,7 @@ qt_add_executable(${PROJECT_NAME}
src/backend.cpp src/backend.h
src/serviceConnector.cpp src/serviceConnector.h
src/projectManager.cpp src/projectManager.h
src/dsConnector.cpp src/dsConnector.h
ui/main.qml
ui/resources.qrc
)
......
......@@ -79,6 +79,13 @@ void Backend::initialize()
&ProjectManager::projectStateChanged,
this,
&Backend::popupTextChanged);
connect(&m_designStudioConnector,
&DesignStudioConnector::networkStatusUpdated,
this,
&Backend::networkUpdated);
m_designStudioConnector.initialize();
qDebug("Initialization complete");
}
......
......@@ -26,6 +26,7 @@
#ifndef DV_ANDROID_H
#define DV_ANDROID_H
#include "dsConnector.h"
#include "projectManager.h"
#include "serviceConnector.h"
......@@ -57,6 +58,7 @@ private:
QString m_userHash;
ServiceConnector m_serviceConnector;
ProjectManager m_projectManager;
DesignStudioConnector m_designStudioConnector;
// member functions
void showWarning(const QString &message);
......@@ -74,6 +76,7 @@ signals:
void popupOpen();
void popupClose();
void userRegistered();
void networkUpdated(QString);
public slots:
void runUserProject(const QString &url);
......
/****************************************************************************
**
** Copyright (C) 2023 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Design Viewer of the Qt Toolkit.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "dsConnector.h"
#include <QNetworkInterface>
DesignStudioConnector::DesignStudioConnector(QObject *parent)
: QObject(parent)
, m_socket(this)
, m_broadcastTimer(this)
{}
bool DesignStudioConnector::initialize()
{
// const bool retVal = m_socket.bind(39000);
// if (!retVal) {
// qDebug() << "Failed to bind socket";
// emit networkStatusUpdated("Failed to bind socket on port 39000");
// return false;
// }
// get ipv4 address
QString ipv4Addr;
const QList<QHostAddress> list = QNetworkInterface::allAddresses();
for (const QHostAddress &address : list) {
if (address.protocol() == QAbstractSocket::IPv4Protocol
&& address != QHostAddress::LocalHost) {
qDebug() << "Found IPv4 address:" << address.toString();
ipv4Addr = address.toString();
break;
}
}
// connect(&m_socket, &QUdpSocket::readyRead, this, &DesignStudioConnector::readPendingDatagrams);
qDebug() << "Advertising from" << ipv4Addr;
emit networkStatusUpdated("\nLocal IP: " + ipv4Addr
+ "\nWaiting for Design Studio to connect...");
// Broadcast a message to the network in each 2 seconds
// to let the Design Studio know that we are here
connect(&m_broadcastTimer, &QTimer::timeout, this, [this]() {
QByteArray datagram = "Qt Design Viewer";
m_socket.writeDatagram(datagram.data(), datagram.size(), QHostAddress::Broadcast, 39000);
qDebug() << "Broadcasting datagram:" << datagram;
});
m_broadcastTimer.setSingleShot(false);
m_broadcastTimer.start(2000);
return true;
}
void DesignStudioConnector::readPendingDatagrams()
{
while (m_socket.hasPendingDatagrams()) {
QByteArray datagram;
datagram.resize(m_socket.pendingDatagramSize());
m_socket.readDatagram(datagram.data(), datagram.size());
qDebug() << "Received datagram:" << datagram;
}
}
/****************************************************************************
**
** Copyright (C) 2023 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Design Viewer of the Qt Toolkit.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#ifndef DSCONNECTOR_H
#define DSCONNECTOR_H
#include <QObject>
#include <QTimer>
#include <QUdpSocket>
class DesignStudioConnector : public QObject
{
Q_OBJECT
public:
explicit DesignStudioConnector(QObject *parent = nullptr);
bool initialize();
private slots:
void readPendingDatagrams();
private:
QUdpSocket m_socket;
QTimer m_broadcastTimer;
signals:
void networkStatusUpdated(QString);
};
#endif // DSCONNECTOR_H
......@@ -114,4 +114,6 @@ Project {
supportedLanguages: ["en"]
primaryLanguage: "en"
mainUiFile: "main.qml"
}
import QtQuick
import QtQuick.Controls 6.4
import QtQuick.Layouts
Item {
id: header
ColumnLayout {
anchors.fill: parent
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
Item {
id: item2
width: 200
height: 200
Layout.preferredHeight: 10
Layout.fillWidth: true
}
Label {
id: infoHeader
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
horizontalAlignment: "AlignHCenter"
text: qsTr("Design Studio connection")
}
Label {
id: status
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
horizontalAlignment: "AlignHCenter"
Connections {
target: backend
function onNetworkUpdated(newStatus){
status.text = newStatus
}
}
}
Item {
id: item1
Layout.fillHeight: true
Layout.fillWidth: true
}
}
}
......@@ -105,6 +105,12 @@ Rectangle {
id: logsPage
Layout.fillWidth: true
}
Network {
id: networkPage
Layout.fillWidth: true
}
AboutHeader {
id: headerPage
Layout.fillWidth: true
......@@ -186,6 +192,21 @@ Rectangle {
}
}
TabButton {
id: network
text: qsTr("Network")
Layout.fillWidth: true
checkable: true
autoExclusive: true
Connections {
target: network
function onClicked(){
stackLayout.currentIndex = 3
}
}
}
TabButton {
id: about
......@@ -197,7 +218,7 @@ Rectangle {
Connections {
target: about
function onClicked(){
stackLayout.currentIndex = 3
stackLayout.currentIndex = 4
}
}
}
......
......@@ -4,6 +4,7 @@
<file>main.qml</file>
<file>HomePage.qml</file>
<file>Logs.qml</file>
<file>Network.qml</file>
<file>ExamplesPage.qml</file>
<file>AboutHeader.qml</file>
</qresource>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment