Serial-Studio/app/qml/Dialogs/MQTTConfiguration.qml

662 lines
18 KiB
QML
Raw Normal View History

2021-11-10 02:57:41 -06:00
/*
* Serial Studio - https://serial-studio.github.io/
2021-11-10 02:57:41 -06:00
*
* Copyright (C) 2020-2025 Alex Spataru <https://aspatru.com>
2021-11-10 02:57:41 -06:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
2021-11-10 02:57:41 -06:00
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later OR Commercial
2021-11-10 02:57:41 -06:00
*/
2024-04-01 02:42:21 -05:00
import QtCore
2022-05-02 04:31:32 -05:00
import QtQuick
import QtQuick.Window
import QtQuick.Layouts
import QtQuick.Controls
2021-11-11 22:28:42 -06:00
2024-08-10 12:58:21 -05:00
Window {
id: root
//
// Custom properties
//
readonly property int year: new Date().getFullYear()
//
// Window options
//
width: minimumWidth
height: minimumHeight
2024-08-11 18:20:03 -05:00
title: qsTr("MQTT Setup")
2024-09-23 02:44:59 -05:00
minimumWidth: column.implicitWidth + 32
maximumWidth: column.implicitWidth + 32
minimumHeight: column.implicitHeight + root.titlebarHeight + 32
maximumHeight: column.implicitHeight + root.titlebarHeight + 32
//
// Make window stay on top
//
Component.onCompleted: {
root.flags = Qt.Dialog |
Qt.WindowTitleHint |
2024-11-13 17:20:42 -05:00
Qt.WindowStaysOnTopHint |
Qt.WindowCloseButtonHint
}
//
// Native window registration
//
property real titlebarHeight: 0
onVisibleChanged: {
if (visible) {
2024-09-26 11:03:49 -05:00
Cpp_NativeWindow.addWindow(root, Cpp_ThemeManager.colors["base"])
root.titlebarHeight = Cpp_NativeWindow.titlebarHeight(root)
}
else {
root.titlebarHeight = 0
Cpp_NativeWindow.removeWindow(root)
}
}
//
// Background + window title on macOS
//
Rectangle {
anchors.fill: parent
color: Cpp_ThemeManager.colors["window"]
//
// Drag the window anywhere
//
DragHandler {
target: null
onActiveChanged: {
if (active)
root.startSystemMove()
}
}
//
// Titlebar text
//
Label {
text: root.title
visible: root.titlebarHeight > 0
color: Cpp_ThemeManager.colors["text"]
font: Cpp_Misc_CommonFonts.customUiFont(1.07, true)
anchors {
topMargin: 6
top: parent.top
horizontalCenter: parent.horizontalCenter
}
}
2024-08-11 18:20:03 -05:00
}
//
// Save settings
//
Settings {
property alias version: _version.currentIndex
property alias mode: _mode.currentIndex
property alias host: _host.text
property alias port: _port.text
property alias qos: _qos.currentIndex
property alias keepAlive: _keepAlive.text
property alias topic: _topic.text
property alias retain: _retain.checked
property alias user: _user.text
property alias password: _password.text
2024-10-11 04:24:41 -05:00
property alias clientId: _clientId.text
property alias ssl: _ssl.checked
property alias certificate: _certificateMode.currentIndex
property alias protocol: _protocols.currentIndex
}
2024-09-18 21:48:57 -05:00
//
// Close shortcut
//
Shortcut {
sequences: [StandardKey.Close]
onActivated: root.close()
}
//
// Use page item to set application palette
//
Page {
2024-08-11 18:20:03 -05:00
anchors.fill: parent
anchors.topMargin: root.titlebarHeight
2024-09-19 16:51:27 -05:00
palette.mid: Cpp_ThemeManager.colors["mid"]
palette.dark: Cpp_ThemeManager.colors["dark"]
2024-08-11 18:20:03 -05:00
palette.text: Cpp_ThemeManager.colors["text"]
2024-09-19 16:51:27 -05:00
palette.base: Cpp_ThemeManager.colors["base"]
palette.link: Cpp_ThemeManager.colors["link"]
palette.light: Cpp_ThemeManager.colors["light"]
2024-08-11 18:20:03 -05:00
palette.window: Cpp_ThemeManager.colors["window"]
2024-09-19 16:51:27 -05:00
palette.shadow: Cpp_ThemeManager.colors["shadow"]
palette.accent: Cpp_ThemeManager.colors["accent"]
palette.button: Cpp_ThemeManager.colors["button"]
palette.midlight: Cpp_ThemeManager.colors["midlight"]
palette.highlight: Cpp_ThemeManager.colors["highlight"]
palette.windowText: Cpp_ThemeManager.colors["window_text"]
palette.brightText: Cpp_ThemeManager.colors["bright_text"]
2024-08-11 18:20:03 -05:00
palette.buttonText: Cpp_ThemeManager.colors["button_text"]
2024-09-19 16:51:27 -05:00
palette.toolTipBase: Cpp_ThemeManager.colors["tooltip_base"]
palette.toolTipText: Cpp_ThemeManager.colors["tooltip_text"]
palette.linkVisited: Cpp_ThemeManager.colors["link_visited"]
palette.alternateBase: Cpp_ThemeManager.colors["alternate_base"]
2024-08-11 18:20:03 -05:00
palette.placeholderText: Cpp_ThemeManager.colors["placeholder_text"]
palette.highlightedText: Cpp_ThemeManager.colors["highlighted_text"]
2021-11-10 02:57:41 -06:00
//
// Window controls
2021-11-10 02:57:41 -06:00
//
ColumnLayout {
id: column
2024-08-11 18:20:03 -05:00
spacing: 8
anchors.centerIn: parent
2021-11-10 02:57:41 -06:00
2024-08-11 18:20:03 -05:00
GroupBox {
Layout.fillWidth: true
2021-11-10 02:57:41 -06:00
2024-08-11 18:20:03 -05:00
background: Rectangle {
radius: 2
border.width: 1
color: Cpp_ThemeManager.colors["groupbox_background"]
border.color: Cpp_ThemeManager.colors["groupbox_border"]
2021-11-10 02:57:41 -06:00
}
2024-08-11 18:20:03 -05:00
GridLayout {
columns: 2
rowSpacing: 0
Layout.fillWidth: true
2024-08-11 18:20:03 -05:00
columnSpacing: 8
//
// Version & mode titles
//
Label {
text: qsTr("Version") + ":"
} Label {
text: qsTr("Mode") + ":"
}
2021-11-10 02:57:41 -06:00
2024-08-11 18:20:03 -05:00
//
// MQTT version
//
ComboBox {
id: _version
Layout.fillWidth: true
Layout.minimumWidth: 256
model: Cpp_MQTT_Client.mqttVersions
currentIndex: Cpp_MQTT_Client.mqttVersion
onCurrentIndexChanged: {
if (Cpp_MQTT_Client.mqttVersion !== currentIndex)
Cpp_MQTT_Client.mqttVersion = currentIndex
}
}
2024-08-11 18:20:03 -05:00
//
// Client mode version
//
ComboBox {
id: _mode
Layout.fillWidth: true
Layout.minimumWidth: 256
model: Cpp_MQTT_Client.clientModes
currentIndex: Cpp_MQTT_Client.clientMode
onCurrentIndexChanged: {
if (Cpp_MQTT_Client.clientMode !== currentIndex)
Cpp_MQTT_Client.clientMode = currentIndex
}
}
2024-08-11 18:20:03 -05:00
//
// Spacers
//
Item {
2024-10-14 15:10:00 -05:00
implicitHeight: 8
2024-08-11 18:20:03 -05:00
} Item {
2024-10-14 15:10:00 -05:00
implicitHeight: 8
}
2024-08-11 18:20:03 -05:00
//
// QOS Level & Keep Alive
//
Label {
opacity: enabled ? 1 : 0.5
text: qsTr("QOS Level") + ":"
enabled: !Cpp_MQTT_Client.isConnectedToHost
} Label {
opacity: enabled ? 1 : 0.5
text: qsTr("Keep Alive (s)") + ":"
enabled: !Cpp_MQTT_Client.isConnectedToHost
}
2024-08-11 18:20:03 -05:00
//
// QOS
//
ComboBox {
id: _qos
Layout.fillWidth: true
opacity: enabled ? 1 : 0.5
model: Cpp_MQTT_Client.qosLevels
currentIndex: Cpp_MQTT_Client.qos
enabled: !Cpp_MQTT_Client.isConnectedToHost
2024-08-11 18:20:03 -05:00
onCurrentIndexChanged: {
if (Cpp_MQTT_Client.qos !== currentIndex)
Cpp_MQTT_Client.qos = currentIndex
}
}
2024-08-11 18:20:03 -05:00
//
// Keep alive
//
TextField {
id: _keepAlive
Layout.fillWidth: true
opacity: enabled ? 1 : 0.5
placeholderText: Cpp_MQTT_Client.keepAlive
enabled: !Cpp_MQTT_Client.isConnectedToHost
Component.onCompleted: text = Cpp_MQTT_Client.keepAlive
2024-08-11 18:20:03 -05:00
onTextChanged: {
if (Cpp_MQTT_Client.keepAlive !== text && text.length > 0)
Cpp_MQTT_Client.keepAlive = text
2024-08-11 18:20:03 -05:00
if (text.length === 0)
Cpp_MQTT_Client.keepAlive = 1
}
2024-08-11 18:20:03 -05:00
validator: IntValidator {
bottom: 1
top: 65535
}
}
2024-08-11 18:20:03 -05:00
//
// Spacers
//
Item {
2024-10-14 15:10:00 -05:00
implicitHeight: 8
2024-08-11 18:20:03 -05:00
} Item {
2024-10-14 15:10:00 -05:00
implicitHeight: 8
2024-08-11 18:20:03 -05:00
}
2024-08-11 18:20:03 -05:00
//
// Host & port titles
//
Label {
text: qsTr("Host") + ":"
opacity: enabled ? 1 : 0.5
enabled: !Cpp_MQTT_Client.isConnectedToHost
} Label {
text: qsTr("Port") + ":"
opacity: enabled ? 1 : 0.5
enabled: !Cpp_MQTT_Client.isConnectedToHost
}
2024-08-11 18:20:03 -05:00
//
// Host
//
TextField {
id: _host
Layout.fillWidth: true
opacity: enabled ? 1 : 0.5
enabled: !Cpp_MQTT_Client.isConnectedToHost
placeholderText: Cpp_MQTT_Client.defaultHost
2024-08-11 18:20:03 -05:00
onTextChanged: {
if (Cpp_MQTT_Client.host !== text && text.length > 0)
Cpp_MQTT_Client.host = text
2024-08-11 18:20:03 -05:00
else if (text.length === 0)
Cpp_MQTT_Client.host = Cpp_MQTT_Client.defaultHost
}
}
2024-08-11 18:20:03 -05:00
//
// Port
//
TextField {
id: _port
Layout.fillWidth: true
opacity: enabled ? 1 : 0.5
enabled: !Cpp_MQTT_Client.isConnectedToHost
placeholderText: Cpp_MQTT_Client.defaultPort
Component.onCompleted: text = Cpp_MQTT_Client.port
2024-08-11 18:20:03 -05:00
onTextChanged: {
if (Cpp_MQTT_Client.port !== text && text.length > 0)
Cpp_MQTT_Client.port = text
2024-08-11 18:20:03 -05:00
if (text.length === 0)
Cpp_MQTT_Client.port = Cpp_MQTT_Client.defaultPort
}
2024-08-11 18:20:03 -05:00
validator: IntValidator {
bottom: 0
top: 65535
}
}
2024-08-11 18:20:03 -05:00
//
// Spacers
//
Item {
2024-10-14 15:10:00 -05:00
implicitHeight: 8
2024-08-11 18:20:03 -05:00
} Item {
2024-10-14 15:10:00 -05:00
implicitHeight: 8
}
2024-08-11 18:20:03 -05:00
//
// Topic & retain labels
//
Label {
text: qsTr("Topic") + ":"
opacity: enabled ? 1 : 0.5
enabled: !Cpp_MQTT_Client.isConnectedToHost
} Label {
text: qsTr("Retain") + ":"
opacity: enabled ? 1 : 0.5
enabled: !Cpp_MQTT_Client.isConnectedToHost
}
2024-08-11 18:20:03 -05:00
//
// Topic
//
TextField {
2024-08-11 18:20:03 -05:00
id: _topic
Layout.fillWidth: true
opacity: enabled ? 1 : 0.5
2024-08-11 18:20:03 -05:00
text: Cpp_MQTT_Client.topic
placeholderText: qsTr("MQTT Topic")
enabled: !Cpp_MQTT_Client.isConnectedToHost
onTextChanged: {
2024-08-11 18:20:03 -05:00
if (Cpp_MQTT_Client.topic !== text)
Cpp_MQTT_Client.topic = text
2021-11-10 02:57:41 -06:00
}
}
2024-08-11 18:20:03 -05:00
//
// Retain checkbox
//
CheckBox {
id: _retain
Layout.leftMargin: -6
Layout.fillWidth: true
opacity: enabled ? 1 : 0.5
text: qsTr("Add Retain Flag")
checked: Cpp_MQTT_Client.retain
enabled: !Cpp_MQTT_Client.isConnectedToHost
2024-08-11 18:20:03 -05:00
onCheckedChanged: {
if (Cpp_MQTT_Client.retain != checked)
Cpp_MQTT_Client.retain = checked
}
}
2021-11-10 02:57:41 -06:00
2024-08-11 18:20:03 -05:00
//
// Spacers
//
Item {
2024-10-14 15:10:00 -05:00
implicitHeight: 8
2024-08-11 18:20:03 -05:00
} Item {
2024-10-14 15:10:00 -05:00
implicitHeight: 8
}
2024-08-11 18:20:03 -05:00
//
// Username & password titles
//
Label {
text: qsTr("User") + ":"
opacity: enabled ? 1 : 0.5
enabled: !Cpp_MQTT_Client.isConnectedToHost
} Label {
text: qsTr("Password") + ":"
opacity: enabled ? 1 : 0.5
enabled: !Cpp_MQTT_Client.isConnectedToHost
}
2024-08-11 18:20:03 -05:00
//
// Username
//
TextField {
id: _user
Layout.fillWidth: true
opacity: enabled ? 1 : 0.5
2024-08-11 18:20:03 -05:00
text: Cpp_MQTT_Client.username
placeholderText: qsTr("MQTT Username")
enabled: !Cpp_MQTT_Client.isConnectedToHost
2024-08-11 18:20:03 -05:00
onTextChanged: {
if (Cpp_MQTT_Client.username !== text)
Cpp_MQTT_Client.username = text
2021-11-10 02:57:41 -06:00
}
}
2024-08-11 18:20:03 -05:00
//
// Password
//
RowLayout {
Layout.fillWidth: true
spacing: 8
TextField {
id: _password
Layout.fillWidth: true
opacity: enabled ? 1 : 0.5
echoMode: TextField.Password
text: Cpp_MQTT_Client.password
placeholderText: qsTr("MQTT Password")
enabled: !Cpp_MQTT_Client.isConnectedToHost
onTextChanged: {
if (Cpp_MQTT_Client.password !== text)
Cpp_MQTT_Client.password = text
}
}
Button {
checkable: true
icon.color: palette.text
Layout.maximumWidth: height
Layout.alignment: Qt.AlignVCenter
icon.source: "qrc:/rcc/icons/buttons/visibility.svg"
2024-08-11 18:20:03 -05:00
onCheckedChanged: _password.echoMode = (checked ? TextField.Normal :
TextField.Password)
}
}
2024-10-11 04:24:41 -05:00
//
2024-08-11 18:20:03 -05:00
// Spacers
//
Item {
2024-10-14 15:10:00 -05:00
implicitHeight: 8
2024-08-11 18:20:03 -05:00
} Item {
2024-10-14 15:10:00 -05:00
implicitHeight: 8
2024-08-11 18:20:03 -05:00
}
//
2024-10-11 04:24:41 -05:00
// Client ID + SSL Switch
2024-08-11 18:20:03 -05:00
//
Label {
2024-10-11 04:24:41 -05:00
text: qsTr("Client ID:")
2024-08-11 18:20:03 -05:00
opacity: enabled ? 1 : 0.5
enabled: !Cpp_MQTT_Client.isConnectedToHost
} Label {
2024-10-11 04:24:41 -05:00
text: qsTr("Enable SSL/TLS:")
opacity: enabled ? 1 : 0.5
2024-10-11 04:24:41 -05:00
enabled: !Cpp_MQTT_Client.isConnectedToHost
}
//
// Client ID
//
TextField {
id: _clientId
Layout.fillWidth: true
opacity: enabled ? 1 : 0.5
text: Cpp_MQTT_Client.clientId
placeholderText: qsTr("MQTT Client ID")
enabled: !Cpp_MQTT_Client.isConnectedToHost
onTextChanged: {
if (Cpp_MQTT_Client.clientId !== text)
Cpp_MQTT_Client.clientId = text
}
}
2024-08-11 18:20:03 -05:00
//
// SSL/TLS switch
//
Switch {
id: _ssl
opacity: enabled ? 1 : 0.5
Layout.leftMargin: -8
checked: Cpp_MQTT_Client.sslEnabled
enabled: !Cpp_MQTT_Client.isConnectedToHost
2024-08-11 18:20:03 -05:00
onCheckedChanged: {
if (Cpp_MQTT_Client.sslEnabled !== checked)
Cpp_MQTT_Client.sslEnabled = checked
}
}
2024-10-11 04:24:41 -05:00
//
// Spacers
//
Item {
2024-10-14 15:10:00 -05:00
implicitHeight: 8
2024-10-11 04:24:41 -05:00
} Item {
2024-10-14 15:10:00 -05:00
implicitHeight: 8
2024-10-11 04:24:41 -05:00
}
//
// SSL Protocol & certificate titles
//
Label {
text: qsTr("Protocol:")
opacity: enabled ? 1 : 0.5
enabled: !Cpp_MQTT_Client.isConnectedToHost && _ssl.checked
} Label {
text: qsTr("Certificate:")
opacity: enabled ? 1 : 0.5
enabled: !Cpp_MQTT_Client.isConnectedToHost && _ssl.checked
}
//
// SSL/TLS protocol selection
//
ComboBox {
id: _protocols
Layout.fillWidth: true
opacity: enabled ? 1 : 0.5
model: Cpp_MQTT_Client.sslProtocols
enabled: !Cpp_MQTT_Client.isConnectedToHost && _ssl.checked
onCurrentIndexChanged: {
if (currentIndex !== Cpp_MQTT_Client.sslProtocol)
Cpp_MQTT_Client.sslProtocol = currentIndex
}
}
2024-08-11 18:20:03 -05:00
//
// Certificate selection
//
RowLayout {
spacing: 8
Layout.fillWidth: true
ComboBox {
id: _certificateMode
Layout.fillWidth: true
opacity: enabled ? 1 : 0.5
enabled: !Cpp_MQTT_Client.isConnectedToHost && _ssl.checked
model: [
qsTr("Use System Database"),
qsTr("Custom CA File")
]
onCurrentIndexChanged: {
if (currentIndex === 0)
Cpp_MQTT_Client.loadCaFile("")
}
}
2024-08-11 18:20:03 -05:00
Button {
icon.color: palette.text
opacity: enabled ? 1 : 0.5
Layout.maximumWidth: height
Layout.alignment: Qt.AlignVCenter
onClicked: Cpp_MQTT_Client.loadCaFile()
icon.source: "qrc:/rcc/icons/buttons/open.svg"
2024-08-11 18:20:03 -05:00
enabled: _certificateMode.currentIndex === 1 && _ssl.checked
}
}
2024-08-11 18:20:03 -05:00
//
// Spacers
//
Item {
2024-10-14 15:10:00 -05:00
implicitHeight: 8
2024-08-11 18:20:03 -05:00
} Item {
2024-10-14 15:10:00 -05:00
implicitHeight: 8
2024-08-11 18:20:03 -05:00
}
}
}
//
// Buttons
//
RowLayout {
2024-08-11 18:20:03 -05:00
spacing: 4
Layout.fillWidth: true
Button {
2024-08-11 18:20:03 -05:00
icon.width: 18
icon.height: 18
onClicked: root.close()
text: qsTr("Close") + " "
Layout.alignment: Qt.AlignVCenter
icon.source: "qrc:/rcc/icons/buttons/close.svg"
2024-08-11 18:20:03 -05:00
icon.color: Cpp_ThemeManager.colors["button_text"]
}
Item {
Layout.fillWidth: true
}
Button {
2024-08-11 18:20:03 -05:00
icon.width: 18
icon.height: 18
highlighted: true
Layout.alignment: Qt.AlignVCenter
checked: Cpp_MQTT_Client.isConnectedToHost
onClicked: Cpp_MQTT_Client.toggleConnection()
icon.color: Cpp_ThemeManager.colors["button_text"]
text: (checked ? qsTr("Disconnect") : qsTr("Connect")) + " "
icon.source: checked ? "qrc:/rcc/icons/buttons/connected.svg" :
"qrc:/rcc/icons/buttons/disconnected.svg"
2021-11-10 02:57:41 -06:00
}
}
2021-11-10 02:57:41 -06:00
}
}
2021-11-10 02:57:41 -06:00
}