KNotifications

knotificationqmlplugin.h
1/*
2 SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#ifndef KNOTIFICATIONQMLPLUGIN_H
8#define KNOTIFICATIONQMLPLUGIN_H
9
10#include <QQmlEngine>
11
12#include <KNotification>
13#include <KNotificationPermission>
14#include <KNotificationReplyAction>
15
16struct NotificationActionForeign {
17 Q_GADGET
18 QML_NAMED_ELEMENT(NotificationAction)
19 QML_FOREIGN(KNotificationAction);
20};
21
22struct NotificationReplyActionForeign {
23 Q_GADGET
24 QML_NAMED_ELEMENT(NotificationReplyAction)
25 QML_UNCREATABLE("")
26 QML_FOREIGN(KNotificationReplyAction);
27};
28
29class NotificationWrapper : public KNotification
30{
31 Q_OBJECT
32 QML_NAMED_ELEMENT(Notification)
33 Q_PROPERTY(KNotificationReplyAction *replyAction READ replyActionFactory CONSTANT)
34 Q_PROPERTY(QQmlListProperty<KNotificationAction> actions READ actionsProperty NOTIFY actionsChanged)
35 Q_PROPERTY(KNotificationAction *defaultAction READ defaultAction WRITE setDefaultActionQml NOTIFY defaultActionChanged)
36public:
37 explicit NotificationWrapper(QObject *parent = nullptr);
38
39 KNotificationReplyAction *replyActionFactory();
40
41 int actionCount() const;
42
43 KNotificationAction *actionAt(qsizetype index);
44
45 QQmlListProperty<KNotificationAction> actionsProperty() const;
46
47 static qsizetype actionsCount(QQmlListProperty<KNotificationAction> *list);
48
49 static void appendAction(QQmlListProperty<KNotificationAction> *list, KNotificationAction *value);
50
51 static KNotificationAction *actionAt(QQmlListProperty<KNotificationAction> *list, qsizetype index);
52
53 static void clearActions(QQmlListProperty<KNotificationAction> *list);
54
55private:
57};
58
59class NotificationPermissionWrapper : public QObject
60{
61 Q_OBJECT
62 QML_NAMED_ELEMENT(NotificationPermission)
63 QML_SINGLETON
64public:
65 Q_INVOKABLE bool checkPermission()
66 {
67 return KNotificationPermission::checkPermission() == Qt::PermissionStatus::Granted;
68 }
69
70 Q_INVOKABLE void requestPermission(const QJSValue &callback)
71 {
73 callback.call({status == Qt::PermissionStatus::Granted});
74 });
75 }
76};
77
78#endif // KNOTIFICATIONQMLPLUGIN_H
This class represents a notification.
KNotification is the main class for creating notifications.
Q_SCRIPTABLE CaptureState status()
KNOTIFICATIONS_EXPORT void requestPermission(QObject *context, const std::function< void(Qt::PermissionStatus)> &callback)
Request notification permissions.
KNOTIFICATIONS_EXPORT Qt::PermissionStatus checkPermission()
Check if the current application has permissions to show notifications.
QJSValue call(const QJSValueList &args) const const
PermissionStatus
QFuture< QtAndroidPrivate::PermissionResult > checkPermission(const QString &permission)
QFuture< QtAndroidPrivate::PermissionResult > requestPermission(const QString &permission)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 14 2024 11:50:24 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.