File indexing completed on 2024-05-05 05:38:27
0001 /* 0002 SPDX-FileCopyrightText: 2018-2019 Kai Uwe Broulik <kde@privat.broulik.de> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #pragma once 0008 0009 #include <QAbstractListModel> 0010 #include <QDateTime> 0011 #include <QWindow> 0012 0013 #include <memory> 0014 0015 #include "notification.h" 0016 #include "notifications.h" 0017 #include "server.h" 0018 0019 #include "notificationmanager_export.h" 0020 0021 namespace NotificationManager 0022 { 0023 class NOTIFICATIONMANAGER_EXPORT AbstractNotificationsModel : public QAbstractListModel 0024 { 0025 Q_OBJECT 0026 Q_PROPERTY(QWindow *window READ window WRITE setWindow NOTIFY windowChanged) 0027 0028 public: 0029 ~AbstractNotificationsModel() override; 0030 0031 QDateTime lastRead() const; 0032 void setLastRead(const QDateTime &lastRead); 0033 0034 QWindow *window() const; 0035 void setWindow(QWindow *window); 0036 0037 QVariant data(const QModelIndex &index, int role) const override; 0038 bool setData(const QModelIndex &index, const QVariant &value, int role) override; 0039 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0040 QHash<int, QByteArray> roleNames() const override; 0041 0042 virtual void expire(uint notificationId) = 0; 0043 virtual void close(uint notificationId) = 0; 0044 0045 // Currently configure actions are not exposed in AbstractNotificationsModel to keep it very minimal 0046 // if usecase for this comes up in future, we can revisit it. 0047 0048 virtual void invokeDefaultAction(uint notificationId, Notifications::InvokeBehavior behavior) = 0; 0049 virtual void invokeAction(uint notificationId, const QString &actionName, Notifications::InvokeBehavior behavior) = 0; 0050 virtual void reply(uint notificationId, const QString &text, Notifications::InvokeBehavior behavior) = 0; 0051 0052 void startTimeout(uint notificationId); 0053 void stopTimeout(uint notificationId); 0054 0055 void clear(Notifications::ClearFlags flags); 0056 0057 Q_SIGNALS: 0058 void lastReadChanged(); 0059 void windowChanged(QWindow *window); 0060 0061 protected: 0062 AbstractNotificationsModel(); 0063 void onNotificationAdded(const Notification ¬ification); 0064 void onNotificationReplaced(uint replacedId, const Notification ¬ification); 0065 void onNotificationRemoved(uint notificationId, Server::CloseReason reason); 0066 0067 void setupNotificationTimeout(const Notification ¬ification); 0068 const QList<Notification> ¬ifications(); 0069 int rowOfNotification(uint id) const; 0070 0071 private: 0072 friend class NotificationTest; 0073 0074 class Private; 0075 std::unique_ptr<Private> d; 0076 0077 Q_DISABLE_COPY(AbstractNotificationsModel) 0078 }; 0079 0080 } // namespace NotificationManager