fix: update the file

This commit is contained in:
x-tools-author 2025-08-01 22:59:14 +08:00
parent 9307afcdc5
commit 5189d426c2
12 changed files with 207 additions and 148 deletions

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 7.0 KiB

After

Width:  |  Height:  |  Size: 7.0 KiB

View File

@ -884,6 +884,7 @@ QVariantMap saveSocketItem(const SocketItem &context)
obj.insert(keys.enableMulticast, context.enableMulticast);
obj.insert(keys.justMulticast, context.justMulticast);
obj.insert(keys.path, context.path);
obj.insert(keys.secureMode, context.secureMode);
return obj;
}
@ -902,6 +903,7 @@ SocketItem loadSocketItem(const QVariantMap &obj)
ctx.enableMulticast = obj.value(keys.enableMulticast).toBool();
ctx.justMulticast = obj.value(keys.justMulticast).toBool();
ctx.path = obj.value(keys.path).toString();
ctx.secureMode = obj.value(keys.secureMode).toBool();
return ctx;
}

View File

@ -243,6 +243,7 @@ struct SocketItem
bool enableMulticast;
bool justMulticast;
QString path; // For WebSocket
bool secureMode; // For WebSocket
};
struct SocketItemKeys
{
@ -257,6 +258,7 @@ struct SocketItemKeys
const QString enableMulticast{"enableMulticast"};
const QString justMulticast{"justMulticast"};
const QString path{"path"}; // For WebSocket
const QString secureMode{"secureMode"}; // For WebSocket
};
SocketItem defaultSocketItem();
QVariantMap saveSocketItem(const SocketItem &context);

View File

@ -32,6 +32,11 @@ void Socket::load(const QVariantMap &parameters)
m_enableMulticast = item.enableMulticast;
m_justMulticast = item.justMulticast;
m_path = item.path;
#if 0
m_secureMode = item.secureMode;
#else
m_secureMode = false;
#endif
}
void Socket::setDataChannel(int channel)

View File

@ -35,6 +35,7 @@ protected:
bool m_justMulticast{false};
QString m_path{""}; // For WebSocket
bool m_secureMode{false};
protected:
QString makeFlag(const QString &address, quint16 port) const;

View File

@ -37,6 +37,7 @@ SocketUi::SocketUi(QWidget *parent)
});
setPathWidgetsVisible(false);
setSecureModeWidgetsVisible(false);
}
SocketUi::~SocketUi() {}
@ -54,7 +55,10 @@ QVariantMap SocketUi::save() const
item.multicastPort = ui->spinBoxMulticastPort->value();
item.enableMulticast = ui->checkBoxEnableMulticast->isChecked();
item.justMulticast = ui->checkBoxJustMulticast->isChecked();
#if 0
item.path = ui->lineEditPath->text();
#endif
item.secureMode = ui->checkBoxSecureMode->isChecked();
return saveSocketItem(item);
}
@ -77,7 +81,10 @@ void SocketUi::load(const QVariantMap &parameters)
ui->spinBoxMulticastPort->setValue(item.multicastPort);
ui->checkBoxEnableMulticast->setChecked(item.enableMulticast);
ui->checkBoxJustMulticast->setChecked(item.justMulticast);
#if 0
ui->lineEditPath->setText(item.path);
#endif
ui->checkBoxSecureMode->setChecked(item.secureMode);
}
void SocketUi::setServerWidgetsVisible(bool visible)
@ -126,6 +133,11 @@ void SocketUi::setPathWidgetsVisible(bool visible)
ui->lineEditPath->setVisible(visible);
}
void SocketUi::setSecureModeWidgetsVisible(bool visible)
{
ui->checkBoxSecureMode->setVisible(visible);
}
void SocketUi::setServerWidgetsEnabled(bool enabled)
{
ui->labelServerIp->setEnabled(enabled);
@ -175,6 +187,11 @@ void SocketUi::setPathWidgetsEnabled(bool enabled)
ui->lineEditPath->setEnabled(enabled);
}
void SocketUi::setSecureWidgetsEnabled(bool enabled)
{
ui->checkBoxSecureMode->setEnabled(enabled);
}
void SocketUi::setupClients(const QStringList &clients)
{
QString current = ui->comboBoxWriteTo->currentData().toString();

View File

@ -41,6 +41,7 @@ protected:
void setWriteToWidgetsVisible(bool visible);
void setMulticastWidgetsVisible(bool visible);
void setPathWidgetsVisible(bool visible);
void setSecureModeWidgetsVisible(bool visible);
void setServerWidgetsEnabled(bool enabled);
void setChannelWidgetsEnabled(bool enabled);
@ -48,6 +49,7 @@ protected:
void setWriteToWidgetsEnabled(bool enabled);
void setMulticastWidgetsEnabled(bool enabled);
void setPathWidgetsEnabled(bool enabled);
void setSecureWidgetsEnabled(bool enabled);
void setupClients(const QStringList &clients);

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>232</width>
<height>296</height>
<height>326</height>
</rect>
</property>
<property name="windowTitle">
@ -26,135 +26,9 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item row="5" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QCheckBox" name="checkBoxEnableMulticast">
<property name="text">
<string>Enable multicast</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxJustMulticast">
<property name="text">
<string>Just multicast</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="8" column="0">
<widget class="QLabel" name="labelChannel">
<property name="text">
<string>Channel</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="labelServerIp">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Server IP</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="labelWriteTo">
<property name="text">
<string>Write to</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QSpinBox" name="spinBoxMulticastPort">
<property name="maximum">
<number>65535</number>
</property>
<property name="value">
<number>1024</number>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QComboBox" name="comboBoxChannel"/>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="lineEditMulticastIp">
<property name="text">
<string notr="true">239.168.3.255</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="labelMulticastPort">
<property name="text">
<string>Multicast Port</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="spinBoxServerPort">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>65535</number>
</property>
</widget>
</item>
<item row="10" column="0">
<widget class="QLabel" name="labelUser">
<property name="text">
<string>User name</string>
</property>
</widget>
</item>
<item row="11" column="1">
<widget class="QLineEdit" name="lineEditPassword"/>
</item>
<item row="10" column="1">
<item row="12" column="1">
<widget class="QLineEdit" name="lineEditUser"/>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="comboBoxServerIp">
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="9" column="0" colspan="2">
<widget class="QCheckBox" name="checkBoxAuthentication">
<property name="text">
<string>Authentication</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelServerPort">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Server port</string>
</property>
</widget>
</item>
<item row="11" column="0">
<widget class="QLabel" name="labelPassword">
<property name="text">
<string>Password</string>
</property>
</widget>
</item>
<item row="7" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
@ -175,17 +49,34 @@
</item>
</layout>
</item>
<item row="3" column="0">
<widget class="QLabel" name="labelMulticastIp">
<item row="7" column="0">
<widget class="QLabel" name="labelWriteTo">
<property name="text">
<string>Multicast IP</string>
<string>Write to</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelPath">
<item row="4" column="0">
<widget class="QLabel" name="labelMulticastPort">
<property name="text">
<string>Path</string>
<string>Multicast Port</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QSpinBox" name="spinBoxMulticastPort">
<property name="maximum">
<number>65535</number>
</property>
<property name="value">
<number>1024</number>
</property>
</widget>
</item>
<item row="11" column="0" colspan="2">
<widget class="QCheckBox" name="checkBoxAuthentication">
<property name="text">
<string>Authentication</string>
</property>
</widget>
</item>
@ -196,6 +87,122 @@
</property>
</widget>
</item>
<item row="13" column="1">
<widget class="QLineEdit" name="lineEditPassword"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelServerPort">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Server port</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelPath">
<property name="text">
<string>Path</string>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QCheckBox" name="checkBoxEnableMulticast">
<property name="text">
<string>Enable multicast</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxJustMulticast">
<property name="text">
<string>Just multicast</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="13" column="0">
<widget class="QLabel" name="labelPassword">
<property name="text">
<string>Password</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="lineEditMulticastIp">
<property name="text">
<string notr="true">239.168.3.255</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="labelMulticastIp">
<property name="text">
<string>Multicast IP</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="spinBoxServerPort">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>65535</number>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="labelServerIp">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Server IP</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="comboBoxServerIp">
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="9" column="1">
<widget class="QComboBox" name="comboBoxChannel"/>
</item>
<item row="12" column="0">
<widget class="QLabel" name="labelUser">
<property name="text">
<string>User name</string>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QLabel" name="labelChannel">
<property name="text">
<string>Channel</string>
</property>
</widget>
</item>
<item row="10" column="0" colspan="2">
<widget class="QCheckBox" name="checkBoxSecureMode">
<property name="text">
<string>Secure Mode</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>

View File

@ -28,13 +28,19 @@ QObject *WebSocketClient::initDevice()
m_webSocket,
[this](const QByteArray &message) { onBinaryMessageReceived(message); });
connect(m_webSocket, &QWebSocket::disconnected, m_webSocket, [this]() {
qInfo() << "WebSocketClient disconnected:" << m_webSocket->errorString();
emit errorOccurred("");
});
connect(m_webSocket, xWebSocketErrorOccurred, m_webSocket, [this]() {
emit errorOccurred(m_webSocket->errorString());
});
QString url = QString("ws://%1:%2/%3").arg(m_serverAddress).arg(m_serverPort).arg(m_path);
QString flag = m_secureMode ? "wss" : "ws";
QString url = flag + QString("://%2:%3/%4").arg(m_serverAddress).arg(m_serverPort).arg(m_path);
if (url.lastIndexOf('/') == url.length() - 1) {
url.chop(1); // Remove trailing slash if present
}
if (m_authentication) {
QNetworkRequest request(url);
QString username = m_username;

View File

@ -15,7 +15,9 @@ WebSocketClientUi::WebSocketClientUi(QWidget *parent)
{
setWriteToWidgetsVisible(false);
setMulticastWidgetsVisible(false);
setPathWidgetsVisible(true);
#if 0
setSecureModeWidgetsVisible(true);
#endif
}
WebSocketClientUi::~WebSocketClientUi() {}

View File

@ -8,6 +8,7 @@
**************************************************************************************************/
#include "websocketserver.h"
#include <QSslConfiguration>
#include <QWebSocket>
#include "common/xtools.h"
@ -20,8 +21,18 @@ WebSocketServer::~WebSocketServer() {}
QObject *WebSocketServer::initDevice()
{
if (m_secureMode) {
m_webSocketServer = new QWebSocketServer(QStringLiteral("WebSocket Server"),
QWebSocketServer::SecureMode);
QSslConfiguration sslConfig = QSslConfiguration::defaultConfiguration();
sslConfig.setPeerVerifyMode(QSslSocket::VerifyNone);
m_webSocketServer->setSslConfiguration(sslConfig);
qInfo() << "WebSocketServer: using secure mode";
} else {
m_webSocketServer = new QWebSocketServer(QStringLiteral("WebSocket Server"),
QWebSocketServer::NonSecureMode);
}
connect(m_webSocketServer, &QWebSocketServer::acceptError, m_webSocketServer, [this]() {
emit errorOccurred(m_webSocketServer->errorString());
});
@ -32,21 +43,23 @@ QObject *WebSocketServer::initDevice()
m_sockets.append(socket);
this->setupSocket(socket);
});
connect(m_webSocketServer, &QWebSocketServer::serverError, m_webSocketServer, [this]() {
qInfo() << "WebSocketServer: server error occurred:" << m_webSocketServer->errorString();
});
connect(m_webSocketServer,
&QWebSocketServer::sslErrors,
m_webSocketServer,
[this](QList<QSslError> errors) { qInfo() << "SSL errors:" << errors; });
if (!m_webSocketServer->listen(QHostAddress(m_serverAddress), m_serverPort)) {
m_webSocketServer->deleteLater();
m_webSocketServer = nullptr;
qWarning() << "WebSocketServer: listen failed";
return nullptr;
}
qInfo("Web socket server info: %s:%d/%s",
m_serverAddress.toLatin1().data(),
m_serverPort,
m_path.toLatin1().data());
qInfo("Web socket server info: %s:%d", m_serverAddress.toLatin1().data(), m_serverPort);
return m_webSocketServer;
}

View File

@ -15,7 +15,9 @@ WebSocketServerUi::WebSocketServerUi(QWidget *parent)
{
setAuthenticationWidgetsVisible(false);
setMulticastWidgetsVisible(false);
setPathWidgetsVisible(true);
#if 0
setSecureModeWidgetsVisible(true);
#endif
}
WebSocketServerUi::~WebSocketServerUi() {}