Warning, /libraries/kunifiedpush/src/kcm/ui/main.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org>
0003     SPDX-License-Identifier: LGPL-2.0-or-later
0004 */
0005 
0006 import QtQuick
0007 import QtQuick.Layouts
0008 import QtQuick.Controls as QQC2
0009 import org.kde.kirigami as Kirigami
0010 import org.kde.kirigami.delegates as KirigamiDelegates
0011 import org.kde.kcmutils as KCM
0012 import org.kde.kunifiedpush.kcm
0013 
0014 KCM.ScrollViewKCM {
0015     id: root
0016     readonly property var pushProviderConfig: kcm.pushProviderConfiguration(pushProviderBox.currentText)
0017 
0018     header: QQC2.Control {
0019         padding: Kirigami.Units.largeSpacing
0020 
0021         background: Rectangle {
0022             Kirigami.Theme.colorSet: Kirigami.Theme.Window
0023             Kirigami.Theme.inherit: false
0024 
0025             color: Kirigami.Theme.backgroundColor
0026         }
0027 
0028         contentItem: ColumnLayout {
0029             id: headerColumn
0030 
0031             // type of distributor, and if it is our own one, distributor status information
0032             Kirigami.InlineMessage {
0033                 Layout.fillWidth: true
0034                 showCloseButton: false
0035                 type: Kirigami.MessageType.Error
0036                 text: i18n("There is no push notification service running!")
0037                 icon.name: "dialog-error"
0038                 visible: !kcm.hasDistributor
0039             }
0040             Kirigami.InlineMessage {
0041                 Layout.fillWidth: true
0042                 showCloseButton: false
0043                 type: Kirigami.MessageType.Information
0044                 text: i18n("There is a 3rd party push notification service running. Push notifications are available, but cannot be configured here.")
0045                 icon.name: "dialog-information"
0046                 visible: !kcm.hasKDEDistributor && kcm.hasDistributor
0047             }
0048             Kirigami.InlineMessage {
0049                 Layout.fillWidth: true
0050                 showCloseButton: false
0051                 type: Kirigami.MessageType.Positive
0052                 text: i18n("<b>Online</b><br>Connected to the push notification server and operational.")
0053                 icon.name: "media-playback-playing"
0054                 visible: kcm.hasKDEDistributor && kcm.distributorStatus == DistributorStatus.Connected
0055             }
0056             Kirigami.InlineMessage {
0057                 Layout.fillWidth: true
0058                 showCloseButton: false
0059                 type: Kirigami.MessageType.Information
0060                 text: i18n("<b>Idle</b><br>There are no applications using push notifications.")
0061                 icon.name: "media-playback-paused"
0062                 visible: kcm.hasKDEDistributor && kcm.distributorStatus == DistributorStatus.Idle
0063             }
0064             Kirigami.InlineMessage {
0065                 Layout.fillWidth: true
0066                 showCloseButton: false
0067                 type: Kirigami.MessageType.Warning
0068                 text: i18n("<b>Offline</b><br>Network connection to the server could not be established.")
0069                 icon.name: "network-disconnect"
0070                 visible: kcm.hasKDEDistributor && kcm.distributorStatus == DistributorStatus.NoNetwork
0071             }
0072             Kirigami.InlineMessage {
0073                 Layout.fillWidth: true
0074                 showCloseButton: false
0075                 type: Kirigami.MessageType.Error
0076                 text: i18n("<b>Offline</b><br>Could not authenticate at the server.")
0077                 icon.name: "dialog-error"
0078                 visible: kcm.hasKDEDistributor && kcm.distributorStatus == DistributorStatus.AuthenticationError
0079             }
0080             Kirigami.InlineMessage {
0081                 Layout.fillWidth: true
0082                 showCloseButton: false
0083                 type: Kirigami.MessageType.Warning
0084                 text: i18n("<b>Offline</b><br>Push notifications are not set up yet.")
0085                 icon.name: "configure"
0086                 visible: kcm.hasKDEDistributor && kcm.distributorStatus == DistributorStatus.NoSetup
0087             }
0088 
0089             // push provider configuration
0090             Kirigami.FormLayout {
0091                 id: topForm
0092                 visible: kcm.hasKDEDistributor
0093                 Layout.fillWidth: true
0094                 QQC2.ComboBox {
0095                     id: pushProviderBox
0096                     Kirigami.FormData.label: i18n("Push provider:")
0097                     model: ["Gotify", "NextPush", "Ntfy"]
0098                     currentIndex: find(kcm.pushProviderId)
0099                     Component.onCompleted: currentIndex = find(kcm.pushProviderId)
0100                 }
0101             }
0102 
0103             Component {
0104                 id: gotifyForm
0105                 Kirigami.FormLayout {
0106                     readonly property bool dirty: urlField.text != root.pushProviderConfig['Url'] || tokenField.text != root.pushProviderConfig['ClientToken']
0107 
0108                     function config() {
0109                         let c = root.pushProviderConfig;
0110                         c['Url'] = urlField.text;
0111                         c['ClientToken'] = tokenField.text;
0112                         return c;
0113                     }
0114 
0115                     twinFormLayouts: [topForm]
0116                     QQC2.TextField {
0117                         id: urlField
0118                         Kirigami.FormData.label: i18n("Url:")
0119                         text: root.pushProviderConfig['Url']
0120                     }
0121                     QQC2.TextField {
0122                         id: tokenField
0123                         Kirigami.FormData.label: i18n("Client token:")
0124                         text: root.pushProviderConfig['ClientToken']
0125                     }
0126                 }
0127             }
0128             Component {
0129                 id: nextpushForm
0130                 Kirigami.FormLayout {
0131                     id: nextpushConfig
0132                     readonly property bool dirty: urlField.text != root.pushProviderConfig['Url'] || userField.text != root.pushProviderConfig['Username'] || appPassword != root.pushProviderConfig['AppPassword']
0133                     property string appPassword: root.pushProviderConfig['AppPassword'];
0134                     function config() {
0135                         let c = root.pushProviderConfig;
0136                         c['Url'] = urlField.text;
0137                         c['Username'] = userField.text;
0138                         c['AppPassword'] = appPassword;
0139                         return c;
0140                     }
0141 
0142                     twinFormLayouts: [topForm]
0143                     QQC2.TextField {
0144                         id: urlField
0145                         Kirigami.FormData.label: i18n("Url:")
0146                         text: root.pushProviderConfig['Url']
0147                     }
0148                     QQC2.Label {
0149                         id: userField
0150                         Kirigami.FormData.label: i18n("User name:")
0151                         text: root.pushProviderConfig['Username']
0152                     }
0153                     RowLayout {
0154                         QQC2.Button {
0155                             enabled: urlField.text != ""
0156                             text: i18n("Authenticate")
0157                             onClicked: {
0158                                 authBusy.running = true;
0159                                 kcm.nextcloudAuthenticate(urlField.text);
0160                             }
0161 
0162                         }
0163                         QQC2.BusyIndicator {
0164                             id: authBusy
0165                             running: false
0166                         }
0167                     }
0168                     Connections {
0169                         target: kcm
0170 
0171                         function onNextcloudAuthenticated(loginName, appPassword) {
0172                             userField.text = loginName;
0173                             nextpushConfig.appPassword = appPassword
0174                             authBusy.running = false;
0175                         }
0176                     }
0177                 }
0178             }
0179             Component {
0180                 id: ntfyForm
0181                 Kirigami.FormLayout {
0182                     id: ntfyConfig
0183                     readonly property bool dirty: urlField.text != root.pushProviderConfig['Url']
0184 
0185                     function config() {
0186                         let c = root.pushProviderConfig;
0187                         c['Url'] = urlField.text;
0188                         return c;
0189                     }
0190 
0191                     twinFormLayouts: [topForm]
0192                     QQC2.TextField {
0193                         id: urlField
0194                         Kirigami.FormData.label: i18n("Url:")
0195                         text: root.pushProviderConfig['Url']
0196                     }
0197                 }
0198             }
0199 
0200             Loader {
0201                 id: providerFormLoader
0202                 Layout.fillWidth: true
0203                 visible: kcm.hasKDEDistributor
0204                 sourceComponent: {
0205                     switch (pushProviderBox.currentIndex) {
0206                         case 0:
0207                             return gotifyForm;
0208                         case 1:
0209                             return nextpushForm;
0210                         case 2:
0211                             return ntfyForm;
0212                     }
0213                     return undefined;
0214                 }
0215             }
0216 
0217             Connections {
0218                 target: kcm
0219 
0220                 function onSaveRequested() {
0221                     kcm.setPushProviderConfiguration(pushProviderBox.currentText, providerFormLoader.item.config());
0222                 }
0223             }
0224             Binding {
0225                 target: kcm
0226                 property: "needsSave"
0227                 value: providerFormLoader.item.dirty || pushProviderBox.currentText != kcm.pushProviderId
0228             }
0229         }
0230     }
0231 
0232     // registered clients
0233     view: ListView {
0234         model: kcm.clientModel
0235         header: Kirigami.InlineViewHeader {
0236             width: ListView.view.width
0237             text: i18n("Applications")
0238         }
0239         visible: count > 0
0240 
0241         delegate: QQC2.ItemDelegate {
0242             width: ListView.view.width
0243 
0244             text: model.display
0245 
0246             down: false
0247             highlighted: false
0248             hoverEnabled: false
0249 
0250             Kirigami.Theme.useAlternateBackgroundColor: true
0251 
0252             contentItem: RowLayout {
0253                 spacing: 0
0254                 KirigamiDelegates.IconTitleSubtitle {
0255                     title: model.name
0256                     subtitle: model.description
0257                     icon.source: model.iconName
0258                 }
0259                 Item {
0260                     Layout.fillWidth: true
0261                 }
0262                 QQC2.ToolButton {
0263                     icon.name: "edit-delete"
0264 
0265                     onClicked: removePrompt.open()
0266 
0267                     QQC2.ToolTip.text: i18n("Unregister application from push notifications")
0268 
0269                     Kirigami.PromptDialog {
0270                         id: removePrompt
0271 
0272                         parent: QQC2.Overlay.overlay
0273 
0274                         title: i18nc("@title:window", "Unregister Application")
0275                         subtitle: i18nc("%1 is an application name", "Are you sure you want to unregister '%1'?", model.name)
0276                         standardButtons: Kirigami.Dialog.Ok | Kirigami.Dialog.Cancel
0277 
0278                         onAccepted: kcm.forceUnregister(model.token)
0279                     }
0280                 }
0281             }
0282         }
0283     }
0284 }