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

KDE's Doxygen guidelines are available online.