Plasma-workspace

abstractnotificationsmodel.h
1/*
2 SPDX-FileCopyrightText: 2018-2019 Kai Uwe Broulik <kde@privat.broulik.de>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#pragma once
8
9#include <QAbstractListModel>
10#include <QDateTime>
11#include <QWindow>
12
13#include <memory>
14
15#include "notification.h"
16#include "notifications.h"
17#include "server.h"
18
19#include "notificationmanager_export.h"
20
21namespace NotificationManager
22{
23class NOTIFICATIONMANAGER_EXPORT AbstractNotificationsModel : public QAbstractListModel
24{
25 Q_OBJECT
26 Q_PROPERTY(QWindow *window READ window WRITE setWindow NOTIFY windowChanged)
27
28public:
29 ~AbstractNotificationsModel() override;
30
31 QDateTime lastRead() const;
32 void setLastRead(const QDateTime &lastRead);
33
34 QWindow *window() const;
35 void setWindow(QWindow *window);
36
37 QVariant data(const QModelIndex &index, int role) const override;
38 bool setData(const QModelIndex &index, const QVariant &value, int role) override;
39 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
40 QHash<int, QByteArray> roleNames() const override;
41
42 virtual void expire(uint notificationId) = 0;
43 virtual void close(uint notificationId) = 0;
44
45 // Currently configure actions are not exposed in AbstractNotificationsModel to keep it very minimal
46 // if usecase for this comes up in future, we can revisit it.
47
48 virtual void invokeDefaultAction(uint notificationId, Notifications::InvokeBehavior behavior) = 0;
49 virtual void invokeAction(uint notificationId, const QString &actionName, Notifications::InvokeBehavior behavior) = 0;
50 virtual void reply(uint notificationId, const QString &text, Notifications::InvokeBehavior behavior) = 0;
51
52 void startTimeout(uint notificationId);
53 void stopTimeout(uint notificationId);
54
55 void clear(Notifications::ClearFlags flags);
56
57Q_SIGNALS:
58 void lastReadChanged();
59 void windowChanged(QWindow *window);
60
61protected:
62 AbstractNotificationsModel();
63 void onNotificationAdded(const Notification &notification);
64 void onNotificationReplaced(uint replacedId, const Notification &notification);
65 void onNotificationRemoved(uint notificationId, Server::CloseReason reason);
66
67 void setupNotificationTimeout(const Notification &notification);
68 const QList<Notification> &notifications();
69 int rowOfNotification(uint id) const;
70
71private:
72 friend class NotificationTest;
73
74 class Private;
75 std::unique_ptr<Private> d;
76
77 Q_DISABLE_COPY(AbstractNotificationsModel)
78};
79
80} // namespace NotificationManager
void setWindow(QObject *job, QWidget *widget)
QWidget * window(QObject *job)
KGuiItem clear()
const QList< QKeySequence > & close()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:14:59 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.