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 <KPluginFactory>
14 
15 #include "knotifications_export.h"
16 
17 #include <memory>
18 
19 class KNotification;
20 class KNotificationPluginPrivate;
21 class KNotifyConfig;
22 
23 /**
24  * @class KNotificationPlugin knotificationplugin.h KNotificationPlugin
25  *
26  * @brief abstract class for KNotification actions
27  *
28  * A KNotificationPlugin is responsible of notification presentation.
29  * You can subclass it to have your own presentation of a notification.
30  *
31  * You should reimplement the KNotificationPlugin::notify method to display the notification.
32  *
33  * @author Olivier Goffart <ogoffart at kde.org>
34  */
35 class KNOTIFICATIONS_EXPORT KNotificationPlugin : public QObject
36 {
37  Q_OBJECT
38 
39 public:
40  KNotificationPlugin(QObject *parent = nullptr, const QVariantList &args = QVariantList());
41  ~KNotificationPlugin() override;
42 
43  /**
44  * @brief return the name of this plugin.
45  *
46  * this is the name that should appear in the .notifyrc file,
47  * in the field Action=... if a notification is set to use this plugin
48  */
49  virtual QString optionName() = 0;
50 
51  // TODO KF6 make notifyConfig const reference
52  /**
53  * This function is called when the notification is sent.
54  * (or re-sent)
55  * You should implement this function to display a notification
56  *
57  * for each call to this function (even for re-notification), you MUST call finish(KNotification*)
58  *
59  * @param notification is the KNotification object
60  * @param notifyConfig is the configuration of the notification
61  */
62  virtual void notify(KNotification *notification, KNotifyConfig *notifyConfig) = 0;
63 
64  // TODO KF6 make config const reference
65  /**
66  * This function is called when the notification has changed (such as the text or the icon)
67  */
68  virtual void update(KNotification *notification, KNotifyConfig *config);
69 
70  /**
71  * This function is called when the notification has been closed
72  */
73  virtual void close(KNotification *notification);
74 
75 protected:
76  /**
77  * emit the finished signal
78  * you MUST call this function for each call to notify(), even if you do nothing there
79  *
80  * call it when the presentation is finished (because the user closed the popup or the sound is finished)
81  *
82  * If your presentation is synchronous, you can even call this function from the notify() call itself
83  */
84  void finish(KNotification *notification);
85 
86  static inline QString stripRichText(const QString &s)
87  {
89  }
90 
91 Q_SIGNALS:
92  /**
93  * the presentation is finished.
94  */
95  void finished(KNotification *notification);
96  /**
97  * emit this signal if one action was invoked
98  * @param id is the id of the notification
99  * @param action is the action number. zero for the default action
100  */
101  void actionInvoked(int id, int action);
102 
103  void xdgActivationTokenReceived(int id, const QString &token);
104 
105  void replied(int id, const QString &text);
106 
107 private:
108  std::unique_ptr<KNotificationPluginPrivate> const d;
109 };
110 
111 #endif
QTextDocumentFragment fromHtml(const QString &text)
QString toPlainText() const const
Q_SIGNALSQ_SIGNALS
abstract class for KNotification actions
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon May 8 2023 03:49:15 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.