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 | |
15 | class KNotification; |
16 | class KNotificationPluginPrivate; |
17 | class 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 | */ |
43 | class KNotificationPlugin : public QObject |
44 | { |
45 | Q_OBJECT |
46 | |
47 | public: |
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 ¬ifyConfig) = 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 ¬ifyConfig); |
75 | |
76 | /** |
77 | * This function is called when the notification has been closed |
78 | */ |
79 | virtual void close(KNotification *notification); |
80 | |
81 | protected: |
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 | { |
94 | return QTextDocumentFragment::fromHtml(html: s).toPlainText(); |
95 | } |
96 | |
97 | Q_SIGNALS: |
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 | |
113 | private: |
114 | std::unique_ptr<KNotificationPluginPrivate> const d; |
115 | }; |
116 | |
117 | #endif |
118 | |