228 lines
7.1 KiB
QML
228 lines
7.1 KiB
QML
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
*
|
|
* Copyright (C) 2013 - 2024, nymea GmbH
|
|
* Copyright (C) 2024 - 2025, chargebyte austria GmbH
|
|
*
|
|
* This file is part of nymea-app.
|
|
*
|
|
* nymea-app 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.
|
|
*
|
|
* nymea-app 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 nymea-app. If not, see <https://www.gnu.org/licenses/>.
|
|
*
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
import QtQuick
|
|
import QtQuick.Controls
|
|
import QtQuick.Controls.Material
|
|
import QtQuick.Layouts
|
|
import Nymea
|
|
|
|
import "../components"
|
|
|
|
SettingsPageBase {
|
|
id: root
|
|
header: NymeaHeader {
|
|
text: qsTr("Mqtt permission")
|
|
onBackPressed: {
|
|
root.rejected();
|
|
pageStack.pop();
|
|
}
|
|
HeaderButton {
|
|
imageSource: "qrc:/icons/tick.svg"
|
|
enabled: clientIdTextField.isValid
|
|
onClicked: {
|
|
root.accepted();
|
|
pageStack.pop();
|
|
}
|
|
}
|
|
}
|
|
property MqttPolicy policy: null
|
|
|
|
signal accepted();
|
|
signal rejected()
|
|
|
|
Label {
|
|
Layout.fillWidth: true
|
|
Layout.margins: app.margins
|
|
text: qsTr("Client info")
|
|
color: Style.accentColor
|
|
}
|
|
|
|
RowLayout {
|
|
Layout.leftMargin: app.margins
|
|
Layout.rightMargin: app.margins
|
|
spacing: app.margins
|
|
Label {
|
|
text: qsTr("Client ID:")
|
|
Layout.fillWidth: true
|
|
}
|
|
TextField {
|
|
id: clientIdTextField
|
|
Layout.fillWidth: true
|
|
text: root.policy ? root.policy.clientId : ""
|
|
onEditingFinished: root.policy.clientId = text
|
|
placeholderText: qsTr("E.g. Sensor_1")
|
|
property bool isEmpty: displayText.length === 0
|
|
property bool isDuplicate: clientIdTextField.displayText != root.policy.clientId && engine.nymeaConfiguration.mqttPolicies.getPolicy(clientIdTextField.displayText) !== null
|
|
property bool isValid: !isEmpty && !isDuplicate
|
|
}
|
|
}
|
|
|
|
Label {
|
|
Layout.leftMargin: app.margins
|
|
Layout.rightMargin: app.margins
|
|
text: clientIdTextField.isDuplicate ? qsTr("%1 is already used").arg(clientIdTextField.displayText) : qsTr("Can't be blank")
|
|
font.pixelSize: app.smallFont
|
|
Layout.alignment: Qt.AlignRight
|
|
color: "red"
|
|
visible: !clientIdTextField.isValid
|
|
}
|
|
|
|
RowLayout {
|
|
Layout.leftMargin: app.margins
|
|
Layout.rightMargin: app.margins
|
|
Label {
|
|
text: qsTr("Username:")
|
|
Layout.fillWidth: true
|
|
}
|
|
TextField {
|
|
id: usernameTextField
|
|
Layout.fillWidth: true
|
|
text: root.policy ? root.policy.username : ""
|
|
onEditingFinished: root.policy.username = text
|
|
placeholderText: qsTr("Optional")
|
|
}
|
|
}
|
|
|
|
RowLayout {
|
|
Layout.leftMargin: app.margins
|
|
Layout.rightMargin: app.margins
|
|
Label {
|
|
text: qsTr("Password:")
|
|
Layout.fillWidth: true
|
|
}
|
|
RowLayout {
|
|
TextField {
|
|
id: passwordTextField
|
|
Layout.fillWidth: true
|
|
text: root.policy ? root.policy.password : ""
|
|
onEditingFinished: root.policy.password = text
|
|
placeholderText: qsTr("Optional")
|
|
echoMode: hiddenPassword ? TextInput.Password : TextInput.Normal
|
|
property bool hiddenPassword: true
|
|
}
|
|
ColorIcon {
|
|
Layout.preferredHeight: Style.iconSize
|
|
Layout.preferredWidth: height
|
|
name: "qrc:/icons/eye.svg"
|
|
color: passwordTextField.hiddenPassword ? Style.iconColor : Style.accentColor
|
|
MouseArea {
|
|
anchors.fill: parent
|
|
onClicked: passwordTextField.hiddenPassword = !passwordTextField.hiddenPassword
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
Label {
|
|
Layout.fillWidth: true
|
|
Layout.margins: app.margins
|
|
text: qsTr("Allowed publish topics")
|
|
color: Style.accentColor
|
|
}
|
|
|
|
Repeater {
|
|
model: root.policy.allowedPublishTopicFilters
|
|
delegate: NymeaSwipeDelegate {
|
|
Layout.fillWidth: true
|
|
text: modelData
|
|
canDelete: true
|
|
progressive: false
|
|
onDeleteClicked: {
|
|
root.policy.allowedPublishTopicFilters.splice(index, 1)
|
|
}
|
|
}
|
|
}
|
|
|
|
RowLayout {
|
|
Layout.fillWidth: true
|
|
Layout.leftMargin: app.margins
|
|
Layout.rightMargin: app.margins
|
|
property bool add: false
|
|
TextField {
|
|
id: pubField
|
|
Layout.fillWidth: parent.add
|
|
Layout.preferredWidth: parent.add ? undefined : 0
|
|
Behavior on width {
|
|
NumberAnimation {}
|
|
}
|
|
}
|
|
Button {
|
|
Layout.fillWidth: !parent.add
|
|
text: parent.add ? qsTr("OK") : qsTr("Add")
|
|
enabled: !parent.add || pubField.displayText.length > 0
|
|
onClicked: {
|
|
if (parent.add) {
|
|
root.policy.allowedPublishTopicFilters.push(pubField.displayText)
|
|
pubField.clear();
|
|
}
|
|
parent.add = !parent.add;
|
|
}
|
|
}
|
|
}
|
|
|
|
Label {
|
|
Layout.fillWidth: true
|
|
Layout.margins: app.margins
|
|
text: qsTr("Allowed subscribe filters")
|
|
color: Style.accentColor
|
|
}
|
|
Repeater {
|
|
model: root.policy.allowedSubscribeTopicFilters
|
|
delegate: NymeaSwipeDelegate {
|
|
Layout.fillWidth: true
|
|
text: modelData
|
|
canDelete: true
|
|
progressive: false
|
|
onDeleteClicked: {
|
|
root.policy.allowedSubscribeTopicFilters.splice(index, 1)
|
|
}
|
|
}
|
|
}
|
|
|
|
RowLayout {
|
|
Layout.fillWidth: true
|
|
Layout.leftMargin: app.margins; Layout.rightMargin: app.margins
|
|
property bool add: false
|
|
TextField {
|
|
id: subField
|
|
Layout.fillWidth: parent.add
|
|
Layout.preferredWidth: parent.add ? undefined : 0
|
|
}
|
|
Button {
|
|
Layout.fillWidth: !parent.add;
|
|
Behavior on width { NumberAnimation {} }
|
|
text: parent.add ? qsTr("OK") : qsTr("Add")
|
|
enabled: !parent.add || subField.displayText.length > 0
|
|
onClicked: {
|
|
if (parent.add) {
|
|
root.policy.allowedSubscribeTopicFilters.push(subField.displayText)
|
|
subField.clear();
|
|
}
|
|
parent.add = !parent.add;
|
|
}
|
|
}
|
|
}
|
|
}
|