KUnifiedPush

kcmpushnotifications.cpp
1/*
2 SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org>
3 SPDX-License-Identifier: LGPL-2.0-or-later
4*/
5
6#include "kcmpushnotifications.h"
7#include "managementinterface.h"
8#include "nextcloudauthenticator.h"
9
10#include "../shared/clientinfo_p.h"
11#include "../shared/connectorutils_p.h"
12#include "../shared/distributorstatus_p.h"
13#include "../shared/unifiedpush-constants.h"
14
15#include <KPluginFactory>
16
17#include <QHostInfo>
18#include <QStandardPaths>
19
20K_PLUGIN_CLASS_WITH_JSON(KCMPushNotifications, "kcm_push_notifications.json")
21
22using namespace KUnifiedPush;
23
24KCMPushNotifications::KCMPushNotifications(QObject *parent, const KPluginMetaData &data, const QVariantList &args)
25 : KQuickConfigModule(parent, data)
26{
27 qDBusRegisterMetaType<KUnifiedPush::ClientInfo>();
28 qDBusRegisterMetaType<QList<KUnifiedPush::ClientInfo>>();
29
30 m_nam.setRedirectPolicy(QNetworkRequest::NoLessSafeRedirectPolicy);
31 m_nam.setStrictTransportSecurityEnabled(true);
32 m_nam.enableStrictTransportSecurityStore(true, QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + QLatin1String("/org.kde.kunifiedpush/hsts/"));
33
34 // TODO do this only when we are using the KDE distributor
35 m_mgmtIface = new OrgKdeKunifiedpushManagementInterface(QLatin1String(KDE_DISTRIBUTOR_SERVICE_NAME), QLatin1String(KDE_DISTRIBUTOR_MANAGEMENT_PATH), QDBusConnection::sessionBus(), this);
36 connect(m_mgmtIface, &OrgKdeKunifiedpushManagementInterface::statusChanged, this, &KCMPushNotifications::distributorStatusChanged);
37 connect(m_mgmtIface, &OrgKdeKunifiedpushManagementInterface::pushProviderChanged, this, &KCMPushNotifications::pushProviderChanged);
38
39 m_clientModel = new ClientModel(m_mgmtIface, this);
40 connect(this, &KCMPushNotifications::distributorChanged, m_clientModel, &ClientModel::reload);
41
42 connect(&m_serviceWatcher, &QDBusServiceWatcher::serviceRegistered, this, &KCMPushNotifications::distributorChanged);
43 connect(&m_serviceWatcher, &QDBusServiceWatcher::serviceUnregistered, this, &KCMPushNotifications::distributorChanged);
44 m_serviceWatcher.setConnection(QDBusConnection::sessionBus());
46 m_serviceWatcher.addWatchedService(QLatin1String(UP_DISTRIBUTOR_SERVICE_NAME_FILTER));
47 connect(this, &KCMPushNotifications::distributorChanged, this, &KCMPushNotifications::distributorStatusChanged);
48 connect(this, &KCMPushNotifications::distributorChanged, this, &KCMPushNotifications::pushProviderChanged);
49
50 qmlRegisterUncreatableMetaObject(DistributorStatus::staticMetaObject, "org.kde.kunifiedpush.kcm", 1, 0, "DistributorStatus", {});
51}
52
53KCMPushNotifications::~KCMPushNotifications() = default;
54
55bool KCMPushNotifications::hasDistributor() const
56{
57 return !ConnectorUtils::selectDistributor().isEmpty();
58}
59
60bool KCMPushNotifications::hasKDEDistributor() const
61{
62 return ConnectorUtils::selectDistributor() == QLatin1String(KDE_DISTRIBUTOR_SERVICE_NAME);
63}
64
65int KCMPushNotifications::distributorStatus() const
66{
67 return m_mgmtIface->status();
68}
69
70QString KCMPushNotifications::pushProviderId() const
71{
72 return m_mgmtIface->pushProviderId();
73}
74
75ClientModel* KCMPushNotifications::clientModel() const
76{
77 return m_clientModel;
78}
79
80QVariantMap KCMPushNotifications::pushProviderConfiguration(const QString &pushProviderId) const
81{
82 return m_mgmtIface->pushProviderConfiguration(pushProviderId);
83}
84
85void KCMPushNotifications::setPushProviderConfiguration(const QString &pushProviderId, const QVariantMap &config)
86{
87 m_mgmtIface->setPushProvider(pushProviderId, config);
88}
89
90void KCMPushNotifications::forceUnregister(const QString &token)
91{
92 m_mgmtIface->forceUnregisterClient(token);
93}
94
95void KCMPushNotifications::nextcloudAuthenticate(const QUrl &url)
96{
97 if (!url.isValid()) {
98 return;
99 }
100
101 m_nextcloudAuthenticator.reset(new NextcloudAuthenticator);
102 connect(m_nextcloudAuthenticator.get(), &NextcloudAuthenticator::authenticated, this, &KCMPushNotifications::nextcloudAuthenticated);
103 m_nextcloudAuthenticator->setNetworkAccessManager(&m_nam);
104 m_nextcloudAuthenticator->authenticate(url, QStringLiteral("KUnifiedPush Distributor (%1)").arg(QHostInfo::localHostName()));
105}
106
107void KCMPushNotifications::save()
108{
109 Q_EMIT saveRequested();
111}
112
113#include "kcmpushnotifications.moc"
114#include "../shared/moc_distributorstatus_p.cpp"
Model for all registered push notification client.
Definition clientmodel.h:15
virtual void save()
KCM to configure push notifications.
#define K_PLUGIN_CLASS_WITH_JSON(classname, jsonFile)
Implementation of https://docs.nextcloud.com/server/latest/developer_manual/client_apis/LoginFlow/ind...
Client-side integration with UnifiedPush.
Definition connector.h:16
QDBusConnection sessionBus()
void serviceRegistered(const QString &serviceName)
void serviceUnregistered(const QString &serviceName)
QString localHostName()
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QString writableLocation(StandardLocation type)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
bool isValid() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:21:15 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.