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 | * \internal |
21 | * |
22 | * 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 | */ |
30 | class KNotificationPlugin : public QObject |
31 | { |
32 | Q_OBJECT |
33 | |
34 | public: |
35 | KNotificationPlugin(QObject *parent = nullptr, const QVariantList &args = QVariantList()); |
36 | ~KNotificationPlugin() override; |
37 | |
38 | /*! |
39 | * return the name of this plugin. |
40 | * |
41 | * this is the name that should appear in the .notifyrc file, |
42 | * in the field Action=... if a notification is set to use this plugin |
43 | */ |
44 | virtual QString optionName() = 0; |
45 | |
46 | /*! |
47 | * This function is called when the notification is sent. |
48 | * (or re-sent) |
49 | * You should implement this function to display a notification |
50 | * |
51 | * for each call to this function (even for re-notification), you MUST call finish(KNotification*) |
52 | * |
53 | * \a notification is the KNotification object |
54 | * |
55 | * \a notifyConfig is the configuration of the notification |
56 | */ |
57 | virtual void notify(KNotification *notification, const KNotifyConfig ¬ifyConfig) = 0; |
58 | |
59 | /*! |
60 | * This function is called when the notification has changed (such as the text or the icon) |
61 | */ |
62 | virtual void update(KNotification *notification, const KNotifyConfig ¬ifyConfig); |
63 | |
64 | /*! |
65 | * This function is called when the notification has been closed |
66 | */ |
67 | virtual void close(KNotification *notification); |
68 | |
69 | protected: |
70 | /*! |
71 | * emit the finished signal |
72 | * you MUST call this function for each call to notify(), even if you do nothing there |
73 | * |
74 | * call it when the presentation is finished (because the user closed the popup or the sound is finished) |
75 | * |
76 | * If your presentation is synchronous, you can even call this function from the notify() call itself |
77 | */ |
78 | void finish(KNotification *notification); |
79 | |
80 | static inline QString stripRichText(const QString &s) |
81 | { |
82 | return QTextDocumentFragment::fromHtml(html: s).toPlainText(); |
83 | } |
84 | |
85 | Q_SIGNALS: |
86 | /*! |
87 | * the presentation is finished. |
88 | */ |
89 | void finished(KNotification *notification); |
90 | /*! |
91 | * emit this signal if one action was invoked |
92 | * |
93 | * \a id is the id of the notification |
94 | * |
95 | * \a action is the action number. zero for the default action |
96 | */ |
97 | void actionInvoked(int id, const QString &action); |
98 | |
99 | void xdgActivationTokenReceived(int id, const QString &token); |
100 | |
101 | void replied(int id, const QString &text); |
102 | |
103 | private: |
104 | std::unique_ptr<KNotificationPluginPrivate> const d; |
105 | }; |
106 | |
107 | #endif |
108 | |