File indexing completed on 2024-05-19 05:37:51
0001 /* 0002 SPDX-FileCopyrightText: 2008 Dmitry Suzdalev <dimsuz@gmail.com> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <Plasma5Support/DataEngine> 0010 #include <QHash> 0011 #include <QSet> 0012 0013 namespace NotificationManager 0014 { 0015 class Notification; 0016 } 0017 0018 struct NotificationInhibiton { 0019 QString hint; 0020 QString value; 0021 }; 0022 0023 using NotificationInhibitonPtr = std::shared_ptr<NotificationInhibiton>; 0024 0025 /** 0026 * Engine which provides data sources for notifications. 0027 * Each notification is represented by one source. 0028 */ 0029 class NotificationsEngine : public Plasma5Support::DataEngine 0030 { 0031 Q_OBJECT 0032 0033 public: 0034 NotificationsEngine(QObject *parent); 0035 ~NotificationsEngine() override; 0036 0037 virtual void init(); 0038 0039 /** 0040 * This function implements part of Notifications DBus interface. 0041 * Once called, will add notification source to the engine 0042 */ 0043 uint Notify(const QString &app_name, 0044 uint replaces_id, 0045 const QString &app_icon, 0046 const QString &summary, 0047 const QString &body, 0048 const QStringList &actions, 0049 const QVariantMap &hints, 0050 int timeout); 0051 0052 Plasma5Support::Service *serviceForSource(const QString &source) override; 0053 0054 int createNotification(const QString &appName, 0055 const QString &appIcon, 0056 const QString &summary, 0057 const QString &body, 0058 int timeout, 0059 const QStringList &actions, 0060 const QVariantMap &hints); 0061 0062 void configureNotification(const QString &appName, const QString &eventId = QString()); 0063 0064 /* 0065 * Block all notification where a given notification hint matches a given value. 0066 * 0067 * Inhibition is dropped when dereferenced. 0068 */ 0069 NotificationInhibitonPtr createInhibition(const QString &hint, const QString &value); 0070 0071 public Q_SLOTS: 0072 void removeNotification(uint id, uint closeReason); 0073 0074 private: 0075 void notificationAdded(const NotificationManager::Notification ¬ification); 0076 0077 QHash<QString, QString> m_activeNotifications; 0078 0079 QList<NotificationInhibiton *> m_inhibitions; 0080 0081 friend class NotificationAction; 0082 };