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 | |
9 | NotificationWrapper::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 | |
22 | KNotificationReplyAction *NotificationWrapper::replyActionFactory() |
23 | { |
24 | if (!replyAction()) { |
25 | setReplyAction(std::make_unique<KNotificationReplyAction>(args: QString())); |
26 | } |
27 | return replyAction(); |
28 | } |
29 | |
30 | int NotificationWrapper::actionCount() const |
31 | { |
32 | return actions().count(); |
33 | } |
34 | |
35 | KNotificationAction *NotificationWrapper::actionAt(qsizetype index) |
36 | { |
37 | return actions().at(i: index); |
38 | } |
39 | |
40 | QQmlListProperty<KNotificationAction> NotificationWrapper::actionsProperty() const |
41 | { |
42 | return m_actionsProperty; |
43 | } |
44 | |
45 | qsizetype NotificationWrapper::actionsCount(QQmlListProperty<KNotificationAction> *list) |
46 | { |
47 | return static_cast<NotificationWrapper *>(list->object)->actionCount(); |
48 | } |
49 | |
50 | void 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 | |
58 | KNotificationAction *NotificationWrapper::actionAt(QQmlListProperty<KNotificationAction> *list, qsizetype index) |
59 | { |
60 | return static_cast<NotificationWrapper *>(list->object)->actionAt(index); |
61 | } |
62 | |
63 | void 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 |