KUnifiedPush

main.qml
1/*
2 SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org>
3 SPDX-License-Identifier: LGPL-2.0-or-later
4*/
5
6import QtQuick
7import QtQuick.Layouts
8import QtQuick.Controls as QQC2
9import org.kde.kirigami as Kirigami
10import org.kde.kirigami.delegates as KirigamiDelegates
11import org.kde.kcmutils as KCM
12import org.kde.kunifiedpush.kcm
13
14KCM.ScrollViewKCM {
15 id: root
16 readonly property var pushProviderConfig: kcm.pushProviderConfiguration(pushProviderBox.currentText)
17
18 header: QQC2.Control {
19 padding: Kirigami.Units.largeSpacing
20
21 background: Rectangle {
22 Kirigami.Theme.colorSet: Kirigami.Theme.Window
23 Kirigami.Theme.inherit: false
24
25 color: Kirigami.Theme.backgroundColor
26 }
27
28 contentItem: ColumnLayout {
29 id: headerColumn
30
31 // type of distributor, and if it is our own one, distributor status information
32 Kirigami.InlineMessage {
33 Layout.fillWidth: true
34 showCloseButton: false
35 type: Kirigami.MessageType.Error
36 text: i18n("There is no push notification service running!")
37 icon.name: "dialog-error"
38 visible: !kcm.hasDistributor
39 }
41 Layout.fillWidth: true
42 showCloseButton: false
43 type: Kirigami.MessageType.Information
44 text: i18n("There is a 3rd party push notification service running. Push notifications are available, but cannot be configured here.")
45 icon.name: "dialog-information"
46 visible: !kcm.hasKDEDistributor && kcm.hasDistributor
47 }
49 Layout.fillWidth: true
50 showCloseButton: false
51 type: Kirigami.MessageType.Positive
52 text: i18n("<b>Online</b><br>Connected to the push notification server and operational.")
53 icon.name: "media-playback-playing"
54 visible: kcm.hasKDEDistributor && kcm.distributorStatus == DistributorStatus.Connected
55 }
57 Layout.fillWidth: true
58 showCloseButton: false
59 type: Kirigami.MessageType.Information
60 text: i18n("<b>Idle</b><br>There are no applications using push notifications.")
61 icon.name: "media-playback-paused"
62 visible: kcm.hasKDEDistributor && kcm.distributorStatus == DistributorStatus.Idle
63 }
65 Layout.fillWidth: true
66 showCloseButton: false
67 type: Kirigami.MessageType.Warning
68 text: i18n("<b>Offline</b><br>Network connection to the server could not be established.")
69 icon.name: "network-disconnect"
70 visible: kcm.hasKDEDistributor && kcm.distributorStatus == DistributorStatus.NoNetwork
71 }
73 Layout.fillWidth: true
74 showCloseButton: false
75 type: Kirigami.MessageType.Error
76 text: i18n("<b>Offline</b><br>Could not authenticate at the server.")
77 icon.name: "dialog-error"
78 visible: kcm.hasKDEDistributor && kcm.distributorStatus == DistributorStatus.AuthenticationError
79 }
81 Layout.fillWidth: true
82 showCloseButton: false
83 type: Kirigami.MessageType.Warning
84 text: i18n("<b>Offline</b><br>Push notifications are not set up yet.")
85 icon.name: "configure"
86 visible: kcm.hasKDEDistributor && kcm.distributorStatus == DistributorStatus.NoSetup
87 }
88
89 // push provider configuration
91 id: topForm
92 visible: kcm.hasKDEDistributor
93 Layout.fillWidth: true
94 QQC2.ComboBox {
95 id: pushProviderBox
96 Kirigami.FormData.label: i18n("Push provider:")
97 model: ["Gotify", "NextPush", "Ntfy"]
98 currentIndex: find(kcm.pushProviderId)
99 Component.onCompleted: currentIndex = find(kcm.pushProviderId)
100 }
101 }
102
103 Component {
104 id: gotifyForm
106 readonly property bool dirty: urlField.text != root.pushProviderConfig['Url'] || tokenField.text != root.pushProviderConfig['ClientToken']
107
108 function config() {
109 let c = root.pushProviderConfig;
110 c['Url'] = urlField.text;
111 c['ClientToken'] = tokenField.text;
112 return c;
113 }
114
115 twinFormLayouts: [topForm]
116 QQC2.TextField {
117 id: urlField
118 Kirigami.FormData.label: i18n("Url:")
119 text: root.pushProviderConfig['Url']
120 }
121 QQC2.TextField {
122 id: tokenField
123 Kirigami.FormData.label: i18n("Client token:")
124 text: root.pushProviderConfig['ClientToken']
125 }
126 }
127 }
128 Component {
129 id: nextpushForm
130 Kirigami.FormLayout {
131 id: nextpushConfig
132 readonly property bool dirty: urlField.text != root.pushProviderConfig['Url'] || userField.text != root.pushProviderConfig['Username'] || appPassword != root.pushProviderConfig['AppPassword']
133 property string appPassword: root.pushProviderConfig['AppPassword'];
134 function config() {
135 let c = root.pushProviderConfig;
136 c['Url'] = urlField.text;
137 c['Username'] = userField.text;
138 c['AppPassword'] = appPassword;
139 return c;
140 }
141
142 twinFormLayouts: [topForm]
143 QQC2.TextField {
144 id: urlField
145 Kirigami.FormData.label: i18n("Url:")
146 text: root.pushProviderConfig['Url']
147 }
148 QQC2.Label {
149 id: userField
150 Kirigami.FormData.label: i18n("User name:")
151 text: root.pushProviderConfig['Username']
152 }
153 RowLayout {
154 QQC2.Button {
155 enabled: urlField.text != ""
156 text: i18n("Authenticate")
157 onClicked: {
158 authBusy.running = true;
159 kcm.nextcloudAuthenticate(urlField.text);
160 }
161
162 }
163 QQC2.BusyIndicator {
164 id: authBusy
165 running: false
166 }
167 }
168 Connections {
169 target: kcm
170
171 function onNextcloudAuthenticated(loginName, appPassword) {
172 userField.text = loginName;
173 nextpushConfig.appPassword = appPassword
174 authBusy.running = false;
175 }
176 }
177 }
178 }
179 Component {
180 id: ntfyForm
181 Kirigami.FormLayout {
182 id: ntfyConfig
183 readonly property bool dirty: urlField.text != root.pushProviderConfig['Url']
184
185 function config() {
186 let c = root.pushProviderConfig;
187 c['Url'] = urlField.text;
188 return c;
189 }
190
191 twinFormLayouts: [topForm]
192 QQC2.TextField {
193 id: urlField
194 Kirigami.FormData.label: i18n("Url:")
195 text: root.pushProviderConfig['Url']
196 }
197 }
198 }
199
200 Loader {
201 id: providerFormLoader
202 Layout.fillWidth: true
203 visible: kcm.hasKDEDistributor
204 sourceComponent: {
205 switch (pushProviderBox.currentIndex) {
206 case 0:
207 return gotifyForm;
208 case 1:
209 return nextpushForm;
210 case 2:
211 return ntfyForm;
212 }
213 return undefined;
214 }
215 }
216
217 Connections {
218 target: kcm
219
220 function onSaveRequested() {
221 kcm.setPushProviderConfiguration(pushProviderBox.currentText, providerFormLoader.item.config());
222 }
223 }
224 Binding {
225 target: kcm
226 property: "needsSave"
227 value: providerFormLoader.item.dirty || pushProviderBox.currentText != kcm.pushProviderId
228 }
229 }
230 }
231
232 // registered clients
233 view: ListView {
234 model: kcm.clientModel
235 header: Kirigami.InlineViewHeader {
236 width: ListView.view.width
237 text: i18n("Applications")
238 }
239 visible: count > 0
240
241 delegate: QQC2.ItemDelegate {
242 width: ListView.view.width
243
244 text: model.display
245
246 down: false
247 highlighted: false
248 hoverEnabled: false
249
250 Kirigami.Theme.useAlternateBackgroundColor: true
251
252 contentItem: RowLayout {
253 spacing: 0
254 KirigamiDelegates.IconTitleSubtitle {
255 title: model.name
256 subtitle: model.description
257 icon.source: model.iconName
258 }
259 Item {
260 Layout.fillWidth: true
261 }
262 QQC2.ToolButton {
263 icon.name: "edit-delete"
264
265 onClicked: removePrompt.open()
266
267 QQC2.ToolTip.text: i18n("Unregister application from push notifications")
268
270 id: removePrompt
271
272 parent: QQC2.Overlay.overlay
273
274 title: i18nc("@title:window", "Unregister Application")
275 subtitle: i18nc("%1 is an application name", "Are you sure you want to unregister '%1'?", model.name)
276 standardButtons: Kirigami.Dialog.Ok | Kirigami.Dialog.Cancel
277
278 onAccepted: kcm.forceUnregister(model.token)
279 }
280 }
281 }
282 }
283 }
284}
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
Type type(const QSqlDatabase &db)
QString name(StandardAction id)
QAction * find(const QObject *recvr, const char *slot, QObject *parent)
QString label(StandardShortcut id)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 24 2024 12:02:24 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.