summaryrefslogtreecommitdiffstats
path: root/demo/Main.qml
blob: 6d1327d9fa98aef60137e91510d3a50434e998c9 (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import Bobink

ApplicationWindow {
    width: 600
    height: 600
    visible: true
    title: "Bobink Demo"

    Connections {
        target: BobinkClient
        function onServersChanged() {
            console.log("Discovered server list updated")
        }
        function onConnectedChanged() {
            console.log("Connected:", BobinkClient.connected)
        }
        function onConnectionError(message) {
            console.log("Connection error:", message)
        }
        function onDiscoveringChanged() {
            console.log("Discovering:", BobinkClient.discovering)
        }
    }

    ColumnLayout {
        anchors.fill: parent
        anchors.margins: 20
        spacing: 12

        Label { text: "Discovery URL"; font.bold: true }

        RowLayout {
            TextField {
                id: discoveryUrlField
                Layout.fillWidth: true
                text: "opc.tcp://localhost:4840"
            }
            Button {
                text: BobinkClient.discovering ? "Stop" : "Discover"
                onClicked: {
                    if (BobinkClient.discovering) {
                        BobinkClient.stopDiscovery()
                    } else {
                        BobinkClient.discoveryUrl = discoveryUrlField.text
                        BobinkClient.startDiscovery()
                    }
                }
            }
        }

        Label {
            text: BobinkClient.discovering
                  ? "Discovering... (" + BobinkClient.servers.length + " found)"
                  : BobinkClient.servers.length + " server(s)"
            font.italic: true
        }

        ListView {
            Layout.fillWidth: true
            Layout.preferredHeight: 100
            clip: true
            model: BobinkClient.servers
            delegate: ItemDelegate {
                width: ListView.view.width
                text: modelData.serverName + "  —  " + modelData.applicationUri
                onClicked: {
                    if (modelData.discoveryUrls.length > 0)
                        serverUrlField.text = modelData.discoveryUrls[0]
                }
            }
            ScrollBar.vertical: ScrollBar {}
        }

        Label { text: "PKI Directory"; font.bold: true }

        RowLayout {
            TextField {
                id: pkiDirField
                Layout.fillWidth: true
                text: BobinkClient.pkiDir
                onEditingFinished: BobinkClient.pkiDir = text
            }
            Button {
                text: "Apply PKI"
                onClicked: {
                    BobinkClient.pkiDir = pkiDirField.text
                    BobinkClient.applyPki()
                    console.log("PKI applied:", BobinkClient.pkiDir)
                }
            }
        }

        Label { text: "Server URL"; font.bold: true }

        RowLayout {
            TextField {
                id: serverUrlField
                Layout.fillWidth: true
                placeholderText: "opc.tcp://..."
            }
        }

        Label { text: "Authentication"; font.bold: true }

        BobinkAuth {
            id: auth
            mode: {
                switch (authModeCombo.currentIndex) {
                case 0: return BobinkAuth.Anonymous
                case 1: return BobinkAuth.UserPass
                case 2: return BobinkAuth.Certificate
                default: return BobinkAuth.Anonymous
                }
            }
            username: usernameField.text
            password: passwordField.text
            certPath: certPathField.text
            keyPath: keyPathField.text
        }

        ComboBox {
            id: authModeCombo
            Layout.fillWidth: true
            model: ["Anonymous", "Username / Password", "Certificate"]
        }

        GridLayout {
            columns: 2
            visible: authModeCombo.currentIndex === 1
            Layout.fillWidth: true

            Label { text: "Username:" }
            TextField {
                id: usernameField
                Layout.fillWidth: true
            }
            Label { text: "Password:" }
            TextField {
                id: passwordField
                Layout.fillWidth: true
                echoMode: TextInput.Password
            }
        }

        GridLayout {
            columns: 2
            visible: authModeCombo.currentIndex === 2
            Layout.fillWidth: true

            Label { text: "Certificate:" }
            TextField {
                id: certPathField
                Layout.fillWidth: true
                placeholderText: "/path/to/cert.pem"
            }
            Label { text: "Private key:" }
            TextField {
                id: keyPathField
                Layout.fillWidth: true
                placeholderText: "/path/to/key.pem"
            }
        }

        Button {
            text: BobinkClient.connected ? "Disconnect" : "Connect"
            Layout.fillWidth: true
            onClicked: {
                if (BobinkClient.connected) {
                    BobinkClient.disconnectFromServer()
                } else {
                    BobinkClient.auth = auth
                    BobinkClient.serverUrl = serverUrlField.text
                    BobinkClient.connectToServer()
                }
            }
        }

        Label {
            text: "Status: " + (BobinkClient.connected ? "Connected" : "Disconnected")
            color: BobinkClient.connected ? "green" : "red"
        }

        Item { Layout.fillHeight: true }
    }
}