KNotifications

knotificationqmlplugin.cpp
1/*
2 SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "knotificationqmlplugin.h"
8
9NotificationWrapper::NotificationWrapper(QObject *parent)
10 : KNotification(QString(), KNotification::CloseOnTimeout, parent)
11{
12 setAutoDelete(false);
13
14 m_actionsProperty = QQmlListProperty<KNotificationAction>(this,
15 nullptr,
16 &NotificationWrapper::appendAction,
17 &NotificationWrapper::actionsCount,
18 &NotificationWrapper::actionAt,
20}
21
22KNotificationReplyAction *NotificationWrapper::replyActionFactory()
23{
24 if (!replyAction()) {
25 setReplyAction(std::make_unique<KNotificationReplyAction>(QString()));
26 }
27 return replyAction();
28}
29
30int NotificationWrapper::actionCount() const
31{
32 return actions().count();
33}
34
35KNotificationAction *NotificationWrapper::actionAt(qsizetype index)
36{
37 return actions().at(index);
38}
39
40QQmlListProperty<KNotificationAction> NotificationWrapper::actionsProperty() const
41{
42 return m_actionsProperty;
43}
44
45qsizetype NotificationWrapper::actionsCount(QQmlListProperty<KNotificationAction> *list)
46{
47 return static_cast<NotificationWrapper *>(list->object)->actionCount();
48}
49
50void NotificationWrapper::appendAction(QQmlListProperty<KNotificationAction> *list, KNotificationAction *value)
51{
52 auto notification = static_cast<NotificationWrapper *>(list->object);
53 auto actions = notification->actions();
54 actions << value;
55 notification->setActionsQml(actions);
56}
57
58KNotificationAction *NotificationWrapper::actionAt(QQmlListProperty<KNotificationAction> *list, qsizetype index)
59{
60 return static_cast<NotificationWrapper *>(list->object)->actionAt(index);
61}
62
64{
65 auto notification = static_cast<KNotification *>(list->object);
66 notification->clearActions();
67}
68
69#include "moc_knotificationqmlplugin.cpp"
This class represents a notification.
KNotification is the main class for creating notifications.
void clearActions()
Removes all actions previously added by addAction() from the notification.
void setReplyAction(std::unique_ptr< KNotificationReplyAction > replyAction)
Add an inline reply action to the notification.
KIOCORE_EXPORT QStringList list(const QString &fileClass)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:12:53 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.