summaryrefslogtreecommitdiff
path: root/package/contents/ui/ConfigGeneral.qml
blob: 9428ed0f652735e40930f01a46ea33178df18514 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import QtQuick 6.0
import QtQuick.Layouts 1.15
import QtQuick.Controls 6.0 as Controls
import org.kde.kirigami as Kirigami
import org.kde.kcmutils as KCM
import org.kde.plasma.workspace.dbus as DBus

KCM.SimpleKCM {
    id: page

    // KCM properties that will be automatically managed
    property alias cfg_mqttClientId: mqttClientIdField.text
    property alias cfg_mqttHosts: mqttHostsField.text
    property alias cfg_mqttUsername: mqttUsernameField.text
    property alias cfg_mqttPassword: mqttPasswordField.text
    property alias cfg_refreshIntervalSeconds: refreshIntervalField.value

    // Default values for KCM system
    property string cfg_mqttClientIdDefault: "camper-widget-refresh"
    property string cfg_mqttHostsDefault: "127.0.0.1:1883"
    property string cfg_mqttUsernameDefault: ""
    property string cfg_mqttPasswordDefault: ""
    property int cfg_refreshIntervalSecondsDefault: 60

    Kirigami.FormLayout {
        anchors.fill: parent

        Controls.TextField {
            id: mqttClientIdField
            Kirigami.FormData.label: i18n("MQTT client ID")
            placeholderText: "camper-widget-refresh"
        }

        Controls.TextField {
            id: mqttHostsField
            Kirigami.FormData.label: i18n("MQTT hosts")
            placeholderText: "127.0.0.1:1883"
            Controls.ToolTip.visible: hovered
            Controls.ToolTip.text: i18n("Comma separated list, e.g. 127.0.0.1 or 127.0.0.1,192.168.1.111 or 127.0.0.1:1883,192.168.1.111:1883")
        }

        Controls.TextField {
            id: mqttUsernameField
            Kirigami.FormData.label: i18n("MQTT username")
            placeholderText: ""
        }

        Controls.TextField {
            id: mqttPasswordField
            Kirigami.FormData.label: i18n("MQTT password")
            echoMode: Controls.TextField.Password
            placeholderText: ""
        }

        Controls.SpinBox {
            id: refreshIntervalField
            Kirigami.FormData.label: i18n("Refresh interval (seconds)")
            from: 1
            to: 86400
            stepSize: 1
        }
    }

    // Notify config changes when KCM properties change
    onCfg_mqttClientIdChanged: notifyConfigChanged()
    onCfg_mqttHostsChanged: notifyConfigChanged()
    onCfg_mqttUsernameChanged: notifyConfigChanged()
    onCfg_mqttPasswordChanged: notifyConfigChanged()
    onCfg_refreshIntervalSecondsChanged: notifyConfigChanged()

    function notifyConfigChanged() {
        DBus.SessionBus.asyncCall({
            service: "org.craftknight.CamperWidget",
            path: "/org/craftknight/camper_widget",
            iface: "org.craftknight.CamperWidget.Config",
            member: "Reload",
            signature: ""
        })
    }
}