File indexing completed on 2024-03-24 03:59:18
0001 /* 0002 SPDX-FileCopyrightText: 2005-2006 Olivier Goffart <ogoffart at kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #ifndef KNOTIFICATIONPLUGIN_H 0008 #define KNOTIFICATIONPLUGIN_H 0009 0010 #include <QObject> 0011 #include <QTextDocumentFragment> 0012 0013 #include <memory> 0014 0015 class KNotification; 0016 class KNotificationPluginPrivate; 0017 class KNotifyConfig; 0018 0019 /** 0020 * @class KNotificationPlugin knotificationplugin.h KNotificationPlugin 0021 * 0022 * @brief abstract class for KNotification actions 0023 * 0024 * A KNotificationPlugin is responsible of notification presentation. 0025 * You can subclass it to have your own presentation of a notification. 0026 * 0027 * You should reimplement the KNotificationPlugin::notify method to display the notification. 0028 * 0029 * Porting from KF5 to KF6: 0030 * 0031 * The signature of the virtual method 0032 * KNotificationPlugin::notify(KNotification *notification, KNotifyConfig *) 0033 * was changed to 0034 * KNotificationPlugin::notify(KNotification *notification, const KNotifyConfig &). 0035 * 0036 * The signature of the virtual method 0037 * KNotificationPlugin::update(KNotification *notification, KNotifyConfig *) 0038 * was changed to 0039 * KNotificationPlugin::update(KNotification *notification, const KNotifyConfig &). 0040 * 0041 * @author Olivier Goffart <ogoffart at kde.org> 0042 */ 0043 class KNotificationPlugin : public QObject 0044 { 0045 Q_OBJECT 0046 0047 public: 0048 KNotificationPlugin(QObject *parent = nullptr, const QVariantList &args = QVariantList()); 0049 ~KNotificationPlugin() override; 0050 0051 /** 0052 * @brief return the name of this plugin. 0053 * 0054 * this is the name that should appear in the .notifyrc file, 0055 * in the field Action=... if a notification is set to use this plugin 0056 */ 0057 virtual QString optionName() = 0; 0058 0059 /** 0060 * This function is called when the notification is sent. 0061 * (or re-sent) 0062 * You should implement this function to display a notification 0063 * 0064 * for each call to this function (even for re-notification), you MUST call finish(KNotification*) 0065 * 0066 * @param notification is the KNotification object 0067 * @param notifyConfig is the configuration of the notification 0068 */ 0069 virtual void notify(KNotification *notification, const KNotifyConfig ¬ifyConfig) = 0; 0070 0071 /** 0072 * This function is called when the notification has changed (such as the text or the icon) 0073 */ 0074 virtual void update(KNotification *notification, const KNotifyConfig ¬ifyConfig); 0075 0076 /** 0077 * This function is called when the notification has been closed 0078 */ 0079 virtual void close(KNotification *notification); 0080 0081 protected: 0082 /** 0083 * emit the finished signal 0084 * you MUST call this function for each call to notify(), even if you do nothing there 0085 * 0086 * call it when the presentation is finished (because the user closed the popup or the sound is finished) 0087 * 0088 * If your presentation is synchronous, you can even call this function from the notify() call itself 0089 */ 0090 void finish(KNotification *notification); 0091 0092 static inline QString stripRichText(const QString &s) 0093 { 0094 return QTextDocumentFragment::fromHtml(s).toPlainText(); 0095 } 0096 0097 Q_SIGNALS: 0098 /** 0099 * the presentation is finished. 0100 */ 0101 void finished(KNotification *notification); 0102 /** 0103 * emit this signal if one action was invoked 0104 * @param id is the id of the notification 0105 * @param action is the action number. zero for the default action 0106 */ 0107 void actionInvoked(int id, const QString &action); 0108 0109 void xdgActivationTokenReceived(int id, const QString &token); 0110 0111 void replied(int id, const QString &text); 0112 0113 private: 0114 std::unique_ptr<KNotificationPluginPrivate> const d; 0115 }; 0116 0117 #endif