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,
19 &NotificationWrapper::clearActions);
20}
21
22KNotificationReplyAction *NotificationWrapper::replyActionFactory()
23{
24 if (!replyAction()) {
25 setReplyAction(std::make_unique<KNotificationReplyAction>(args: 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(i: 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
63void NotificationWrapper::clearActions(QQmlListProperty<KNotificationAction> *list)
64{
65 auto notification = static_cast<KNotification *>(list->object);
66 notification->clearActions();
67}
68
69#include "moc_knotificationqmlplugin.cpp"
70

source code of knotifications/src/qml/knotificationqmlplugin.cpp