KNotifications

knotificationplugin.h
1/*
2 SPDX-FileCopyrightText: 2005-2006 Olivier Goffart <ogoffart at kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#ifndef KNOTIFICATIONPLUGIN_H
8#define KNOTIFICATIONPLUGIN_H
9
10#include <QObject>
11#include <QTextDocumentFragment>
12
13#include <memory>
14
15class KNotification;
16class KNotificationPluginPrivate;
17class KNotifyConfig;
18
19/**
20 * @class KNotificationPlugin knotificationplugin.h KNotificationPlugin
21 *
22 * @brief abstract class for KNotification actions
23 *
24 * A KNotificationPlugin is responsible of notification presentation.
25 * You can subclass it to have your own presentation of a notification.
26 *
27 * You should reimplement the KNotificationPlugin::notify method to display the notification.
28 *
29 * Porting from KF5 to KF6:
30 *
31 * The signature of the virtual method
32 * KNotificationPlugin::notify(KNotification *notification, KNotifyConfig *)
33 * was changed to
34 * KNotificationPlugin::notify(KNotification *notification, const KNotifyConfig &).
35 *
36 * The signature of the virtual method
37 * KNotificationPlugin::update(KNotification *notification, KNotifyConfig *)
38 * was changed to
39 * KNotificationPlugin::update(KNotification *notification, const KNotifyConfig &).
40 *
41 * @author Olivier Goffart <ogoffart at kde.org>
42 */
44{
46
47public:
48 KNotificationPlugin(QObject *parent = nullptr, const QVariantList &args = QVariantList());
49 ~KNotificationPlugin() override;
50
51 /**
52 * @brief return the name of this plugin.
53 *
54 * this is the name that should appear in the .notifyrc file,
55 * in the field Action=... if a notification is set to use this plugin
56 */
57 virtual QString optionName() = 0;
58
59 /**
60 * This function is called when the notification is sent.
61 * (or re-sent)
62 * You should implement this function to display a notification
63 *
64 * for each call to this function (even for re-notification), you MUST call finish(KNotification*)
65 *
66 * @param notification is the KNotification object
67 * @param notifyConfig is the configuration of the notification
68 */
69 virtual void notify(KNotification *notification, const KNotifyConfig &notifyConfig) = 0;
70
71 /**
72 * This function is called when the notification has changed (such as the text or the icon)
73 */
74 virtual void update(KNotification *notification, const KNotifyConfig &notifyConfig);
75
76 /**
77 * This function is called when the notification has been closed
78 */
79 virtual void close(KNotification *notification);
80
81protected:
82 /**
83 * emit the finished signal
84 * you MUST call this function for each call to notify(), even if you do nothing there
85 *
86 * call it when the presentation is finished (because the user closed the popup or the sound is finished)
87 *
88 * If your presentation is synchronous, you can even call this function from the notify() call itself
89 */
90 void finish(KNotification *notification);
91
92 static inline QString stripRichText(const QString &s)
93 {
95 }
96
98 /**
99 * the presentation is finished.
100 */
101 void finished(KNotification *notification);
102 /**
103 * emit this signal if one action was invoked
104 * @param id is the id of the notification
105 * @param action is the action number. zero for the default action
106 */
107 void actionInvoked(int id, const QString &action);
108
109 void xdgActivationTokenReceived(int id, const QString &token);
110
111 void replied(int id, const QString &text);
112
113private:
114 std::unique_ptr<KNotificationPluginPrivate> const d;
115};
116
117#endif
abstract class for KNotification actions
virtual void update(KNotification *notification, const KNotifyConfig &notifyConfig)
This function is called when the notification has changed (such as the text or the icon)
virtual QString optionName()=0
return the name of this plugin.
virtual void notify(KNotification *notification, const KNotifyConfig &notifyConfig)=0
This function is called when the notification is sent.
virtual void close(KNotification *notification)
This function is called when the notification has been closed.
void actionInvoked(int id, const QString &action)
emit this signal if one action was invoked
void finished(KNotification *notification)
the presentation is finished.
void finish(KNotification *notification)
emit the finished signal you MUST call this function for each call to notify(), even if you do nothin...
KNotification is the main class for creating notifications.
Represent the configuration for an event.
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
QObject * parent() const const
QTextDocumentFragment fromHtml(const QString &text, const QTextDocument *resourceProvider)
QString toPlainText() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:53:13 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.