File indexing completed on 2024-11-24 04:17:00

0001 /*
0002     SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org>
0003     SPDX-License-Identifier: LGPL-2.0-or-later
0004 */
0005 
0006 #ifndef KCMPUSHNOTIFICATIONS_H
0007 #define KCMPUSHNOTIFICATIONS_H
0008 
0009 #include "clientmodel.h"
0010 
0011 #include <KQuickConfigModule>
0012 
0013 #include <QDBusServiceWatcher>
0014 #include <QNetworkAccessManager>
0015 
0016 #include <memory>
0017 
0018 class NextcloudAuthenticator;
0019 class OrgKdeKunifiedpushManagementInterface;
0020 
0021 /** KCM to configure push notifications. */
0022 class KCMPushNotifications : public KQuickConfigModule
0023 {
0024     Q_OBJECT
0025     Q_PROPERTY(bool hasDistributor READ hasDistributor NOTIFY distributorChanged)
0026     Q_PROPERTY(bool hasKDEDistributor READ hasKDEDistributor NOTIFY distributorChanged)
0027     Q_PROPERTY(int distributorStatus READ distributorStatus NOTIFY distributorStatusChanged)
0028     Q_PROPERTY(QString pushProviderId READ pushProviderId NOTIFY pushProviderChanged)
0029     Q_PROPERTY(ClientModel* clientModel READ clientModel CONSTANT)
0030 public:
0031     explicit KCMPushNotifications(QObject *parent, const KPluginMetaData &data, const QVariantList &args);
0032     ~KCMPushNotifications();
0033 
0034     bool hasDistributor() const;
0035     bool hasKDEDistributor() const;
0036     int distributorStatus() const;
0037     QString pushProviderId() const;
0038     ClientModel *clientModel() const;
0039 
0040     Q_INVOKABLE QVariantMap pushProviderConfiguration(const QString &pushProviderId) const;
0041 
0042     Q_INVOKABLE void nextcloudAuthenticate(const QUrl &url);
0043 
0044     void save() override;
0045 
0046 public Q_SLOTS:
0047     void forceUnregister(const QString &token);
0048     void setPushProviderConfiguration(const QString &pushProviderId, const QVariantMap &config);
0049 
0050 Q_SIGNALS:
0051     void distributorChanged();
0052     void distributorStatusChanged();
0053     void pushProviderChanged();
0054 
0055     void nextcloudAuthenticated(const QString &loginName, const QString &appPassword);
0056 
0057     void saveRequested();
0058 
0059 private:
0060     OrgKdeKunifiedpushManagementInterface *m_mgmtIface = nullptr;
0061     ClientModel *m_clientModel = nullptr;
0062     QDBusServiceWatcher m_serviceWatcher;
0063 
0064     QNetworkAccessManager m_nam;
0065     std::unique_ptr<NextcloudAuthenticator> m_nextcloudAuthenticator;
0066 };
0067 
0068 #endif // KCMPUSHNOTIFICATIONS_H