KUnifiedPush

abstractpushprovider.h
1/*
2 SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org>
3 SPDX-License-Identifier: LGPL-2.0-or-later
4*/
5
6#ifndef KUNIFIEDPUSH_ABSTRACTPUSHPROVIDER_H
7#define KUNIFIEDPUSH_ABSTRACTPUSHPROVIDER_H
8
9#include "../shared/urgency_p.h"
10
11#include <QObject>
12
14class QSettings;
15
16namespace KUnifiedPush {
17
18class Client;
19class Message;
20
21/** Base class for push provider protocol implementations.
22 * Needed to support different push providers as that part of the
23 * protocol is not part of the UnifiedPush spec.
24 */
25class AbstractPushProvider : public QObject
26{
28public:
29 ~AbstractPushProvider();
30
31 enum Error {
32 NoError, ///< operation succeeded
33 ProviderRejected, ///< communication worked, but the provider refused to complete the operation
34 TransientNetworkError, ///< temporary network error, try again
35 };
37
38 /** Load connection settings.
39 * @param settings can be read on the top level, the correct group is already selected.
40 * @returns @c true if the settings are valid, @c false otherwise.
41 */
42 virtual bool loadSettings(const QSettings &settings) = 0;
43
44 /** Reset any internal state for a fresh setup connecting to
45 * a different push server instance.
46 * The default implementation does nothing.
47 */
48 virtual void resetSettings(QSettings &settings);
49
50 /** Attempt to establish a connection to the push provider. */
51 virtual void connectToProvider(Urgency urgency) = 0;
52
53 /** Disconnect and existing connection to the push provider. */
54 virtual void disconnectFromProvider() = 0;
55
56 /** Register a new client with the provider. */
57 virtual void registerClient(const Client &client) = 0;
58
59 /** Unregister a client from the provider. */
60 virtual void unregisterClient(const Client &client) = 0;
61
62 /** Acknowledge a message.
63 * The default implementation does nothing apart from indicating successful completion.
64 */
65 virtual void acknowledgeMessage(const Client &client, const QString &messageIdentifier);
66
67 /** Change urgency level as needed.
68 * Reimplement doChangeUrgency if your provider does this as a separate command.
69 */
70 void changeUrgency(Urgency urgency);
71
72 /** Provider id used e.g. in settings. */
73 [[nodiscard]] QLatin1StringView providerId() const;
74
75 /** The urgency level currently used by this provider.
76 * This might not yet be the requested one if changing that is an asynchronous operation.
77 */
78 [[nodiscard]] Urgency urgency() const;
79
81 /** Inform about a received push notification. */
83
84 /** Emitted after successful client registration. */
85 void clientRegistered(const KUnifiedPush::Client &client, KUnifiedPush::AbstractPushProvider::Error error = NoError, const QString &errorMsg = {});
86
87 /** Emitted after successful client unregistration. */
89
90 /** Emitted after the connection to the push provider has been established successfully. */
91 void connected();
92
93 /** Emitted after the connection to the push provider disconnected or failed to be established. */
95
96 /** Emitted after a message reception has been acknowledge to the push server. */
97 void messageAcknowledged(const KUnifiedPush::Client &client, const QString &messageIdentifier);
98
99 /** Emitted when the urgency level change request has been executed. */
101
102protected:
103 /** Re-implement if urgency leve changes are done as a separate command.
104 * The default implementation assumes urgency levels aren't supported by this provider.
105 */
106 virtual void doChangeUrgency(Urgency urgency);
107 inline void setUrgency(Urgency urgency) { m_currentUrgency = urgency; }
108
111
112private:
113 const QLatin1StringView m_providerId;
114 QNetworkAccessManager *m_nam = nullptr;
115 Urgency m_currentUrgency = AllUrgencies;
116};
117
118}
119
120#endif // KUNIFIEDPUSH_ABSTRACTPUSHPROVIDER_H
Base class for push provider protocol implementations.
virtual bool loadSettings(const QSettings &settings)=0
Load connection settings.
virtual void acknowledgeMessage(const Client &client, const QString &messageIdentifier)
Acknowledge a message.
void changeUrgency(Urgency urgency)
Change urgency level as needed.
void messageReceived(const KUnifiedPush::Message &msg)
Inform about a received push notification.
virtual void doChangeUrgency(Urgency urgency)
Re-implement if urgency leve changes are done as a separate command.
virtual void connectToProvider(Urgency urgency)=0
Attempt to establish a connection to the push provider.
void connected()
Emitted after the connection to the push provider has been established successfully.
Urgency urgency() const
The urgency level currently used by this provider.
void clientUnregistered(const KUnifiedPush::Client &client, KUnifiedPush::AbstractPushProvider::Error error=NoError)
Emitted after successful client unregistration.
void disconnected(KUnifiedPush::AbstractPushProvider::Error error, const QString &errorMsg={})
Emitted after the connection to the push provider disconnected or failed to be established.
void urgencyChanged()
Emitted when the urgency level change request has been executed.
virtual void disconnectFromProvider()=0
Disconnect and existing connection to the push provider.
virtual void unregisterClient(const Client &client)=0
Unregister a client from the provider.
virtual void registerClient(const Client &client)=0
Register a new client with the provider.
void clientRegistered(const KUnifiedPush::Client &client, KUnifiedPush::AbstractPushProvider::Error error=NoError, const QString &errorMsg={})
Emitted after successful client registration.
@ ProviderRejected
communication worked, but the provider refused to complete the operation
@ TransientNetworkError
temporary network error, try again
QLatin1StringView providerId() const
Provider id used e.g.
void messageAcknowledged(const KUnifiedPush::Client &client, const QString &messageIdentifier)
Emitted after a message reception has been acknowledge to the push server.
virtual void resetSettings(QSettings &settings)
Reset any internal state for a fresh setup connecting to a different push server instance.
Information about a registered client.
Definition client.h:20
A received push notification message.
Definition message.h:15
Client-side integration with UnifiedPush.
Definition connector.h:14
QObject(QObject *parent)
Q_ENUM(...)
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Apr 25 2025 12:05:39 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.